From dineshmishra.patil at gmail.com Sun May 1 00:37:35 2011 From: dineshmishra.patil at gmail.com (DINESH PATIL) Date: Sat, 30 Apr 2011 21:37:35 -0700 (PDT) Subject: click Message-ID: http://123maza.com/65/born511/ From harpreet442 at yahoo.co.in Sun May 1 02:43:35 2011 From: harpreet442 at yahoo.co.in (harryjatt) Date: Sat, 30 Apr 2011 23:43:35 -0700 (PDT) Subject: Zope with mySQL In-Reply-To: <00or88-n7n.ln1@hawthorn.home> References: <31499628.post@talk.nabble.com> <00or88-n7n.ln1@hawthorn.home> Message-ID: <31515759.post@talk.nabble.com> SORRY, i think that you are not happy with my elaboration. I am trying to generate a code for uploading and downloading the pdf files to mysql by web application through zope. but i can not make it right. I want your assistance in this. Tony Middleton wrote: > > Could you provide more details of what you are trying to do and what > help you need? > > On 28/04/11 20:19, harryjatt wrote: >> >> Hi, i am doing web development with Zope. My connected database is mySQL. >> I >> am new to this combination.I have to upload the files to mySQL with >> programming in zope and then downloading them via zope.Can you help me in >> this regard? I will be very thankfull to you. >> Regards, Harry > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://old.nabble.com/Zope-with-mySQL-tp31499628p31515759.html Sent from the Python - python-list mailing list archive at Nabble.com. From pmilin at gmail.com Sun May 1 04:17:11 2011 From: pmilin at gmail.com (neocortex) Date: Sun, 1 May 2011 01:17:11 -0700 (PDT) Subject: Getting number of hits from Google Message-ID: <2a808127-4e81-4746-9eaf-d96a3cee70b4@w24g2000yqb.googlegroups.com> Hello! For quite some time, I am looking for a solution to the problem of getting number of hits for a list of, let say, 200-300 words, from a search engine. I would prefer Google, but this seems not possible. I tried with the PyGoogle (from http://code.google.com/p/pygoogle/), but it stops delivering number of hits after 20-50 words. Please, can anyone help me with this. I am starting to be desperate. Sincerely, PM From hg at schaathun.net Sun May 1 04:18:36 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Sun, 1 May 2011 09:18:36 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> Message-ID: On Sat, 30 Apr 2011 15:40:24 +0100, Paul Rudin wrote: : Anytime you have enough data... there are plenty of things that are natural to : represent as recursive data structures, and often you don't know in : advance how much data your code is going to have to deal with. Sure, but one would think that if you can fit the data in memory, then you can also fit the call stack. I can also /imagine/ that one might run into a limit, but I cannot see any concrete examples where it is likely. -- :-- Hans Georg From steve+comp.lang.python at pearwood.info Sun May 1 04:45:51 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2011 08:45:51 GMT Subject: What other languages use the same data model as Python? Message-ID: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Python uses a data model of "name binding" and "call by object" (also known as "call by sharing"). I trust I don't need to define my terms, but just in case: http://effbot.org/zone/call-by-object.htm http://effbot.org/zone/python-objects.htm Now, this is different from languages like C and Pascal, which is based on variables, or Forth, which explicitly manipulates a stack. Quite often, when people want to impress upon others that Python is not C, they will say: "Python's data model is different from other languages" which is perfectly correct, if you think of C as "other languages". But it's equally correct to say that Python's data model is the same as other languages. As I understand it, Python and Ruby have the same data model. So does Java, so long as you only consider objects and ignore unboxed native values. I believe (but could be wrong) that another language of about the same vintage as Python, Emerald, also uses the same model. That's not surprising, because I believe that Emerald (just like Python) was strongly influenced by CLU. What other languages use the same, or mostly similar, data model as Python? -- Steven From PointedEars at web.de Sun May 1 04:59:37 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 01 May 2011 10:59:37 +0200 Subject: Python competitions and learnings References: Message-ID: <1922818.XAFRqVoOGU@PointedEars.de> harrismh777 wrote: > Terry Reedy wrote: >>> And Im looking for feedback from peoples who best in python. Here I >>> make some video tutorial about this service http://checkio.blip.tv/ >>> >>> What do you think about it? >> >> Pretty impressive. My main disappointment is that you are using 2.7 >> instead of 3.2, as I feel that beginners should learn Py 3 now. Also, >> that is what I routinely use ;-). >> >> In any case, the home page should say Python 2.7, not just Python, > > I agree on all points, as well I would offer the suggestion to have > parallel examples (in some cases) to help those trying to merge over to > Python3. > > But the most important point is that new users should start with 3.x, > and should be encouraged to in that direction alone. I am finding it > very frustrating trying to make all of the details changes solid in my > mind for 3.x because there are so many of them for one, and for another > because the details are so similar all at the same time. *Do not* > confuse new learners with 2.x unless there is a point to it... for > instance in our previous discussion of iterables-- noting that next() is > the same for both versions, but in 2.x next(N) means N.next() and in > version 3.x next(N) means N.__next__(). > > Otherwise, have new students hit 3.x running and never look back. A more down-to-earth recommendation can be found at The bottom line of this for me is that while Python 3 has its advantages, at this point not only you cannot use Py3 everywhere, but also you still cannot do everything in Py3 that you can do in Py2 (most notably, you cannot create or process images, as PIL? is not yet Py3-ready). Meaning that it would be a mistake to exclude Python 2 from education at this point. _____ ? -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From alec.taylor6 at gmail.com Sun May 1 04:59:52 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 1 May 2011 18:59:52 +1000 Subject: Deditor In-Reply-To: References: <74a2f743-aa0a-4beb-8c62-3e32b6ac7489@k22g2000yqh.googlegroups.com> <75a7cd73-50c9-4dc0-a88d-68051f1e3795@k22g2000yqh.googlegroups.com> <761080e3-bbda-4c3b-a38b-f9e0b1e4dcad@a10g2000vbz.googlegroups.com> <2cc05cc3-2c8a-42ba-bb7b-348206546378@k11g2000yqc.googlegroups.com> <35348319-4042-4929-a81c-2e1cec7de3f3@b19g2000yqg.googlegroups.com> Message-ID: Maybe I'm missing something, but I downloaded the zip file and ran each .py and .pyc file in turn, but none brought up the nice deditor GUI I've seen screenshots of... On the other subject, did you have a preference to what installer I should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi) From alec.taylor6 at gmail.com Sun May 1 05:00:27 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 1 May 2011 19:00:27 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: I think ruby does On Sun, May 1, 2011 at 6:45 PM, Steven D'Aprano wrote: > Python uses a data model of "name binding" and "call by object" (also > known as "call by sharing"). I trust I don't need to define my terms, but > just in case: > > http://effbot.org/zone/call-by-object.htm > http://effbot.org/zone/python-objects.htm > > > Now, this is different from languages like C and Pascal, which is based > on variables, or Forth, which explicitly manipulates a stack. Quite > often, when people want to impress upon others that Python is not C, they > will say: > > "Python's data model is different from other languages" > > which is perfectly correct, if you think of C as "other languages". But > it's equally correct to say that Python's data model is the same as other > languages. As I understand it, Python and Ruby have the same data model. > So does Java, so long as you only consider objects and ignore unboxed > native values. I believe (but could be wrong) that another language of > about the same vintage as Python, Emerald, also uses the same model. > That's not surprising, because I believe that Emerald (just like Python) > was strongly influenced by CLU. > > What other languages use the same, or mostly similar, data model as > Python? > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From clp2 at rebertia.com Sun May 1 05:04:20 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 1 May 2011 02:04:20 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 1, 2011 at 1:45 AM, Steven D'Aprano wrote: > Python uses a data model of "name binding" and "call by object" (also > known as "call by sharing"). > As I understand it, Python and Ruby have the same data model. > So does Java, so long as you only consider objects and ignore unboxed > native values. I believe (but could be wrong) that another language of > about the same vintage as Python, Emerald, also uses the same model. > That's not surprising, because I believe that Emerald (just like Python) > was strongly influenced by CLU. > > What other languages use the same, or mostly similar, data model as > Python? According to http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing , besides those you already listed: Scheme, OCaml, AppleScript, and possibly VB, among "many other languages". I can't personally vouch for the accuracy of this. Cheers, Chris From steve+comp.lang.python at pearwood.info Sun May 1 05:04:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2011 09:04:27 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> Message-ID: <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 May 2011 09:18:36 +0100, Hans Georg Schaathun wrote: > On Sat, 30 Apr 2011 15:40:24 +0100, Paul Rudin > wrote: > : Anytime you have enough data... there are plenty of things that are > natural to : represent as recursive data structures, and often you > don't know in : advance how much data your code is going to have to > deal with. > > Sure, but one would think that if you can fit the data in memory, then > you can also fit the call stack. I can also /imagine/ that one might > run into a limit, but I cannot see any concrete examples where it is > likely. Why? You might have 4000 MB of main memory, and only 2 MB (say?) of call stack allocated. The call stack can't grow indefinitely. If it does, you get a stack overflow: http://www.ehow.com/list_6572027_reasons-stack-overflow.html which, if you're lucky, will just crash the process. If you're unlucky, it will lead to an exploit that malware can use to compromise your machine. In Python, the virtual machine protects you against stack overflow. Before the stack overflows, Python raises RecursionError. You can experiment by using sys.getrecursionlimit and sys.setrecursionlimit, but be careful, if you increase the limit too high, a deeply recursive function will overflow the stack. -- Steven From hg at schaathun.net Sun May 1 05:27:14 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Sun, 1 May 2011 10:27:14 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01 May 2011 09:04:27 GMT, Steven D'Aprano wrote: : Why? You might have 4000 MB of main memory, and only 2 MB (say?) of call : stack allocated. The call stack can't grow indefinitely. If it does, you : get a stack overflow: Of course you do, but you are still only saying that there might be an application where this might happen because of excessive although logically correct recursion. You have not given a single example where it actually happened. : In Python, the virtual machine protects you against stack overflow. : Before the stack overflows, Python raises RecursionError. You can : experiment by using sys.getrecursionlimit and sys.setrecursionlimit, but : be careful, if you increase the limit too high, a deeply recursive : function will overflow the stack. But the recursion limit is mainly there to protect you against faulty base cases. Obviously, since it measures the number of items on the stack and not their size. -- :-- Hans Georg From bthate at gmail.com Sun May 1 07:43:10 2011 From: bthate at gmail.com (Bart Thate) Date: Sun, 1 May 2011 04:43:10 -0700 (PDT) Subject: JSONBOT 0.7 RELEASED Message-ID: 0.7 RELEASE NOTES ================= Hello world, greetings to all and everybody on this little planet ;] Today I am releasing version 0.7 of JSONBOT, hope you like it. I want to dedicate this release to Annemiek, Kirsten, Danny and Doscha, i would not have a live without you. changes in this release ----------------------- * we got jsonbot.org running .. see http://jsonbot.org ;] * convore support * refactored core * reloadable config files * revamped web console * resource files (contain commands the bot can execute) * file change detection for myplugs plugins * rebooting is fixed * fixed relaying in jabber conference rooms * added color.py plugin to color certain words * added geo.py, googletranslate.py and imdb.py (thnx melmoth) * chatlog plugin now uses the logging module .. log file rotates every day * many other bugfixes If you have programmed your own plugin see http://jsonbot.org/handbook/UPGRADE.html for upgrade notes. Todo ---- 1) fix runtime setting of loglevel 2) add flood control 3) docs docs docs docs docs 4) fix bugs see http://code.google.com/p/jsonbot/issues/list Source ------ * tarball - http://jsonbot.googlecode.com * mercurial - http://jsonbot.googlecode.com/hg * github - https://github.com/jsonbot Demo ---- * webconsole - http://jsonbot.appspot.com * xmpp - jsonbot at jsonbot.org (shell) and jsonbot at appspot.com (GAE) * IRC - jsonbot on irc.freenode.net * Convore - https://convore.com/convore-8/welcome-to-convore/ relaying with #convore on irc.freenode.net Docs ---- * new jsonbot.org site .. http://jsonbot.org * GAE backup docs .. http://jsonbot.appspot.com/docs Contact ------- * twitter: https://twitter.com/#!/jsonbot * facebook: http://tinyurl.com/jsonbot * email: bthate at gmail.com * IRC: dunker in channel #dunkbots / irc.freenode.net* xmpp: bthate at gmail.com and bart at jsonbot.org About ----- 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 and Convore 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 shell Convore 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 Install ------- You dont need to run the bot on GAE when you just want to use the shell bots of JSONBOT. JSONBOT can best be run from the bot dir, the bot is self contained and has all the dependancies that are needed: * "hg clone http://jsonbot.googlecode.com/hg mybot" or download and untar the tarball. * cd into the bot dir and run "./bin/jsb" .. if the bot is working correctly you will get the console version of JSONBOT * same can be done for "./bin/jsb-xmpp", "./bin/jsb-convore" etc. .. check the bin dir for programs you can start * try the --help option to a program to see what command line options are available. * you DONT need root for this Ofcourse you can always run "python setup.py install" or "easy_install -U jsb" when you do want to install the bot globaly. Debian packages are on their way, but might still take time as the ftpmeisters need to approve ;] Thats it ! hope you enjoy this version of JSONBOT ;] Bart From steve+comp.lang.python at pearwood.info Sun May 1 07:56:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2011 11:56:57 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 May 2011 10:27:14 +0100, Hans Georg Schaathun wrote: > On 01 May 2011 09:04:27 GMT, Steven D'Aprano > wrote: > : Why? You might have 4000 MB of main memory, and only 2 MB (say?) of > call : stack allocated. The call stack can't grow indefinitely. If it > does, you : get a stack overflow: > > Of course you do, but you are still only saying that there might be an > application where this might happen because of excessive although > logically correct recursion. You have not given a single example where > it actually happened. Just google on "stack overflow crash". > : In Python, the virtual machine protects you against stack overflow. : > Before the stack overflows, Python raises RecursionError. You can : > experiment by using sys.getrecursionlimit and sys.setrecursionlimit, but > : be careful, if you increase the limit too high, a deeply recursive : > function will overflow the stack. > > But the recursion limit is mainly there to protect you against faulty > base cases. Obviously, since it measures the number of items on the > stack and not their size. The Python virtual machine knows how big each entry on the stack needs to be. (I don't, but it's got to be at least the size of a pointer.) So "number of items" is just a multiplication away from "size of the items". In practice the main reason that stacks overflow is because of faulty base cases in recursion. That's obvious. But in principle, any sufficiently large number of function calls could overflow the stack. If the call stack is (say) 1 MB (chosen only to make the maths easier), and each function call requires (say) a single four-byte entry on the stack, then you can have a maximum of 250000 function calls before overflowing the stack. If you don't like my numbers -- and you probably shouldn't, since I made them up -- choose your own. But whatever numbers you choose, there *must* be a maximum number of function calls before the stack overflows. Not necessarily recursive function calls either: any nested function call will do. However, it's generally only in recursion that you have more than a few hundred calls on the stack. So even if the base case is correct, you can overflow the stack. Given the naive recursive factorial function: def fact(n): if n <= 1: return 1 return n*fact(n-1) and the theoretical limit above, then fact(250001) will overflow the stack even though the base case is correct. -- Steven From martin at v.loewis.de Sun May 1 08:49:13 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 01 May 2011 14:49:13 +0200 Subject: minimal python27.dll? In-Reply-To: References: <4DB8774C.9080400@v.loewis.de> Message-ID: <4DBD56C9.6070300@v.loewis.de> > I have vague recollections that pythonXY.dll could not be statically > linked on Windows, or that doing so causes some serious loss of > functionality. Was this ever true, and is it still? You'll have to rebuild Python to make use of static linkage, of course, but then: it is certainly possible. The main functionality that you lose is the ability to load extension modules (.pyd files). Whether that's a serious loss or not depends on your application - in cases where you want static linkage, you can often accept not being able to do dynamic linkage. Regards, Martin From martin at v.loewis.de Sun May 1 08:49:13 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 01 May 2011 14:49:13 +0200 Subject: minimal python27.dll? In-Reply-To: References: <4DB8774C.9080400@v.loewis.de> Message-ID: <4DBD56C9.6070300@v.loewis.de> > I have vague recollections that pythonXY.dll could not be statically > linked on Windows, or that doing so causes some serious loss of > functionality. Was this ever true, and is it still? You'll have to rebuild Python to make use of static linkage, of course, but then: it is certainly possible. The main functionality that you lose is the ability to load extension modules (.pyd files). Whether that's a serious loss or not depends on your application - in cases where you want static linkage, you can often accept not being able to do dynamic linkage. Regards, Martin From martin at v.loewis.de Sun May 1 08:51:42 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 01 May 2011 14:51:42 +0200 Subject: minimal python27.dll? In-Reply-To: References: <4DB8774C.9080400@v.loewis.de> Message-ID: > On the CJK issue, why python ship its own codec, not using OS builtin? The OS doesn't provide all the codecs that Python provides. For the one it does provide, it behaves semantically different in border cases from the ones that come with Python. > If I don't need the full Unicode5.1 can I just map python's unicode > functions to some Win32 unicode API? That should be possible - but I doubt it's a matter of "just". Regards, Martin From hg at schaathun.net Sun May 1 09:15:35 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Sun, 1 May 2011 14:15:35 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01 May 2011 11:56:57 GMT, Steven D'Aprano wrote: : Just google on "stack overflow crash". And I get loads of examples of stack overflows, but I could not see anybody linking this to logically correct recursion. Wikipedia, for instance, mentions two common causes, neither of which has anything to do with logically correct recursion. : The Python virtual machine knows how big each entry on the stack needs to : be. (I don't, but it's got to be at least the size of a pointer.) So : "number of items" is just a multiplication away from "size of the items". Does it? In a conventional stack you need to store all the local variables for the function as well. Thus, there is no limit to how much space a single element on the stack may require. : But in principle, any : sufficiently large number of function calls could overflow the stack. : (...) : If you don't like my numbers -- and you probably shouldn't, since I made : them up -- choose your own. But whatever numbers you choose, there *must* : be a maximum number of function calls before the stack overflows. But all of this is in principle, and does not constitute any valid reason to avoid recursion in practice. If you want to argue that recursion is a bad thing in /practice/ you need a /practical/ argument. There is also a limit to how far you can usefully recurse over a limited data structure. : def fact(n): : if n <= 1: return 1 : return n*fact(n-1) : : and the theoretical limit above, then fact(250001) will overflow the : stack even though the base case is correct. Of course that will overflow, but you are now trying to calculate an integer of several /million/ bits. Please suggest me a current-day application where you would want to have and also be able to use such a number. There are many ways to crash a system if you want to. But if you don't deliberately try to crash it, you are much more likely to crash it because you allocate to much memory in each step than because the recursion gets to deep. Consequently, because recursion is usually a clearer form of expression than iterative loops, recursion may actually be /less/ dangerous. -- :-- Hans Georg From roy at panix.com Sun May 1 10:13:50 2011 From: roy at panix.com (Roy Smith) Date: Sun, 01 May 2011 10:13:50 -0400 Subject: skipping one unittest assertion? Message-ID: Is there any way to skip a single assertion in a unittest test method? I know I can @skip or @expectedFailure the method, but I'm looking for something finer-grain than that. There's one particular assertion in a test method which depends on production code that hasn't been written yet. I could factor that out into its own test methods and @skip that, but it would be cleaner to be able to mark the particular assertion. (using python 2.6, but importing unittest2 from 2.7) From ben+python at benfinney.id.au Sun May 1 10:31:35 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 May 2011 00:31:35 +1000 Subject: skipping one unittest assertion? References: Message-ID: <87wriah4qg.fsf@benfinney.id.au> Roy Smith writes: > There's one particular assertion in a test method which depends on > production code that hasn't been written yet. I could factor that out > into its own test methods and @skip that, but it would be cleaner to be > able to mark the particular assertion. I think that's backward. If there are multiple conditions to assert, then it's much cleaner to put them in distinct test case methods. Each test case should be testing one thing: if it fails, it should be for exactly one reason. -- \ ?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 darragh.ssa at gmail.com Sun May 1 10:33:33 2011 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 1 May 2011 07:33:33 -0700 (PDT) Subject: Deditor References: <74a2f743-aa0a-4beb-8c62-3e32b6ac7489@k22g2000yqh.googlegroups.com> <75a7cd73-50c9-4dc0-a88d-68051f1e3795@k22g2000yqh.googlegroups.com> <761080e3-bbda-4c3b-a38b-f9e0b1e4dcad@a10g2000vbz.googlegroups.com> <2cc05cc3-2c8a-42ba-bb7b-348206546378@k11g2000yqc.googlegroups.com> <35348319-4042-4929-a81c-2e1cec7de3f3@b19g2000yqg.googlegroups.com> Message-ID: <7d8e78d2-8a90-431e-8a5d-d9f81d393e40@j26g2000yqa.googlegroups.com> On 1 mei, 10:59, Alec Taylor wrote: > Maybe I'm missing something, but I downloaded the zip file and ran > each .py and .pyc file in turn, but none brought up the nice deditor > GUI I've seen screenshots of... > > On the other subject, did you have a preference to what installer I > should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi) not a msi, for the rest it doesn't matter :), on my windows if you run deditor.py it should launch however you need to have the wxpython-2.8 package installed, what happens if you run deditor.py from console? From mrmakent at gmail.com Sun May 1 11:07:40 2011 From: mrmakent at gmail.com (Michael Kent) Date: Sun, 1 May 2011 08:07:40 -0700 (PDT) Subject: skipping one unittest assertion? In-Reply-To: <87wriah4qg.fsf@benfinney.id.au> Message-ID: I agree that each test should test only one 'thing', but it's also true that testing one 'thing' sometimes/often involves multiple assertions. But in the OP's case, it does sound like the assertion he wants to skip should be broken out into its own test. From trevita2048 at gmail.com Sun May 1 11:39:00 2011 From: trevita2048 at gmail.com (Yico Gaga) Date: Sun, 1 May 2011 23:39:00 +0800 Subject: Python IDE/text-editor In-Reply-To: References: Message-ID: foolDE :)!!! 2011/4/29 Alec Taylor > Your probably right. > > I suppose I'll just wait till I finish my fooIDE project > > > On Fri, Apr 29, 2011 at 2:21 AM, Albert van der Horst > > wrote: > >> In article , > >> Alec Taylor wrote: > >>>Geany I've tried in the past, it's really buggy on my home computer > >>>and at Uni... however from my phone it works wonderfully! (Use it for > >>>C++ projects on Rhobuntu) > >>> > >>>Eric 4 was suggested to me on the #python channel on Freenode... > >>>however I've never been able to get it compiled/working. Too many > >>>dependencies I'm guessing... > >>> > >>>PTK looks great, and does everything I want (from screenshots). > >>>Unfortunately, it doesn't run on my system; Win7 x64, Python 2.7.1 > >>>x64, WxPython 2.8 x64. Install ran as admin. > >>> > >>>Emacs and vim still seem like good alternatives, when I get the time. > >>>However, currently have 3 assignments to start and finish so would > >>>like a simple Notepad2 with python interpreter attached (and keyboard > >>>shortcut to run script) type program. > >>> > >>>Please continue recommending > >>> > >>>Thanks, > >>> > >>>Alec Taylor > >> > >> You will never be satisfied, until you've written something yourself. > >> Start writing now. A friend of mine started writing in 1983, > >> and since 1985 I'm a happy user. The only language that is a candidate > >> to write in is C, however. > >> > >> Groetjes Albert > >> > >> -- > >> -- > >> Albert van der Horst, UTRECHT,THE NETHERLANDS > >> Economic growth -- being exponential -- ultimately falters. > >> albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst > >> > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Sun May 1 11:47:40 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 2 May 2011 01:47:40 +1000 Subject: Python IDE/text-editor In-Reply-To: References: Message-ID: !!! =] http://code.google.com/p/fooide Contact me if you'd like to join the project :D On Mon, May 2, 2011 at 1:39 AM, Yico Gaga wrote: > ? foolDE :)!!! > > 2011/4/29 Alec Taylor >> >> Your probably right. >> >> I suppose I'll just wait till I finish my fooIDE project >> >> > On Fri, Apr 29, 2011 at 2:21 AM, Albert van der Horst >> > wrote: >> >> In article , >> >> Alec Taylor ? wrote: >> >>>Geany I've tried in the past, it's really buggy on my home computer >> >>>and at Uni... however from my phone it works wonderfully! (Use it for >> >>>C++ projects on Rhobuntu) >> >>> >> >>>Eric 4 was suggested to me on the #python channel on Freenode... >> >>>however I've never been able to get it compiled/working. Too many >> >>>dependencies I'm guessing... >> >>> >> >>>PTK looks great, and does everything I want (from screenshots). >> >>>Unfortunately, it doesn't run on my system; Win7 x64, Python 2.7.1 >> >>>x64, WxPython 2.8 x64. Install ran as admin. >> >>> >> >>>Emacs and vim still seem like good alternatives, when I get the time. >> >>>However, currently have 3 assignments to start and finish so would >> >>>like a simple Notepad2 with python interpreter attached (and keyboard >> >>>shortcut to run script) type program. >> >>> >> >>>Please continue recommending >> >>> >> >>>Thanks, >> >>> >> >>>Alec Taylor >> >> >> >> You will never be satisfied, until you've written something yourself. >> >> Start writing now. A friend of mine started writing in 1983, >> >> and since 1985 I'm a happy user. The only language that is a candidate >> >> to write in is C, however. >> >> >> >> Groetjes Albert >> >> >> >> -- >> >> -- >> >> Albert van der Horst, UTRECHT,THE NETHERLANDS >> >> Economic growth -- being exponential -- ultimately falters. >> >> albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst >> >> >> >> -- >> >> http://mail.python.org/mailman/listinfo/python-list >> >> >> > >> -- >> http://mail.python.org/mailman/listinfo/python-list > > From alec.taylor6 at gmail.com Sun May 1 11:50:07 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 2 May 2011 01:50:07 +1000 Subject: Deditor In-Reply-To: <7d8e78d2-8a90-431e-8a5d-d9f81d393e40@j26g2000yqa.googlegroups.com> References: <74a2f743-aa0a-4beb-8c62-3e32b6ac7489@k22g2000yqh.googlegroups.com> <75a7cd73-50c9-4dc0-a88d-68051f1e3795@k22g2000yqh.googlegroups.com> <761080e3-bbda-4c3b-a38b-f9e0b1e4dcad@a10g2000vbz.googlegroups.com> <2cc05cc3-2c8a-42ba-bb7b-348206546378@k11g2000yqc.googlegroups.com> <35348319-4042-4929-a81c-2e1cec7de3f3@b19g2000yqg.googlegroups.com> <7d8e78d2-8a90-431e-8a5d-d9f81d393e40@j26g2000yqa.googlegroups.com> Message-ID: Traceback (most recent call last): File "O:\deditor\deditor\deditor.py", line 7, in import wx, os, datetime, sys, ConfigParser, wx.aui, wx.lib.scrolledpanel File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4 5, in from wx._core import * File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i n import _core_ ImportError: DLL load failed: %1 is not a valid Win32 application. On Mon, May 2, 2011 at 12:33 AM, Kruptein wrote: > On 1 mei, 10:59, Alec Taylor wrote: >> Maybe I'm missing something, but I downloaded the zip file and ran >> each .py and .pyc file in turn, but none brought up the nice deditor >> GUI I've seen screenshots of... >> >> On the other subject, did you have a preference to what installer I >> should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi) > > not a msi, for the rest it doesn't matter :), ?on my windows if you > run deditor.py ? it should launch however you need to have the > wxpython-2.8 package installed, ? what happens if you run deditor.py > from console? > -- > http://mail.python.org/mailman/listinfo/python-list > From roy at panix.com Sun May 1 11:55:29 2011 From: roy at panix.com (Roy Smith) Date: Sun, 01 May 2011 11:55:29 -0400 Subject: skipping one unittest assertion? References: <87wriah4qg.fsf@benfinney.id.au> Message-ID: In article <87wriah4qg.fsf at benfinney.id.au>, Ben Finney wrote: > Roy Smith writes: > > > There's one particular assertion in a test method which depends on > > production code that hasn't been written yet. I could factor that out > > into its own test methods and @skip that, but it would be cleaner to be > > able to mark the particular assertion. > > I think that's backward. If there are multiple conditions to assert, > then it's much cleaner to put them in distinct test case methods. > > Each test case should be testing one thing: if it fails, it should be > for exactly one reason. Well, yeah, that's certainly the XP/unit-test doctrine. In practice however, tests often get written as "do a bunch of stuff to get some result, then make a bunch of assertions about that result". Sure, you could make each of those assertions a distinct method, and factor the "do a bunch of stuff" into setUp(). Which probably means factoring those methods out into a new TestCase subclass. At some point, however practicality trumps doctrine. I notice the Python internal tests adopt exactly the same attitude. Here's an example from 3.2's test_urllib.py: def test_fileno(self): file_num = self.returned_obj.fileno() self.assertIsInstance(file_num, int, "fileno() did not return an int") self.assertEqual(os.read(file_num, len(self.text)), self.text, "Reading on the file descriptor returned by fileno() " "did not return the expected text") I've got a remote API which at some point returns a URL (wrapped up in a larger JSON-ized object). I want to make several assertions about the object. It should be valid JSON. It should unpack to yield an object (well, dict in python) with certain attributes. Those values of those attributes should be of the correct types, etc. So: self.assertIsInstance(station['id'], int) self.assertIsInstance(station['name'], unicode) self.assertIsInstance(station['cover_url'], unicode) The next assertion (the one that I know will fail because the server code hasn't been written yet) is that cover_url refers to a get-able jpeg image. It would be convenient and useful to write the assertion now and mark that I expect it to fail until the server code catches up. Breaking all this up into distinct test methods would be silly. In fact, it would be wrong. If they were different methods, they would not be making multiple assertions against one object retrieved from the external service, they would be making a series of assertions against a series of different objects. And, unlike pure unit-test doctrine would like to believe, external services have state. And per-interaction cost (in our case, real cost; some queries result in us paying a few mili-cents to a third-party data provider :-)) I guess I'll just mark the whole method @expectedFailure and let it go at that. From news at schwertberger.de Sun May 1 12:11:23 2011 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sun, 01 May 2011 18:11:23 +0200 Subject: Development tools and practices for Pythonistas In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> Message-ID: Am 01.05.2011 02:47, schrieb Shawn Milochik: > Look at the big two sites for open-source repositories -- github and > bitbucket. One's git, the other Mercurial. I don't think you can go > wrong picking either one. Can any of those be used from Python as a library, i.e. something like import Hg r = Hg.open(path) When I had a look at Mercurial, which is implemented in Python, it was implemented in a way that I could not do that. It was implemented as rather monolithic program which could be used from os.system(...) only. With a good API, I could easily have integrated it into my development flow. I have a codebase which is shared between different projects and there are many small changes on many different PCs. In theory a distributed VCS is good at supporting that, but in practice I went back to my lightweight synchronization scripts and file storage again. With the API, I could have best of both worlds. Regards, Dietmar From darragh.ssa at gmail.com Sun May 1 12:12:21 2011 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 1 May 2011 09:12:21 -0700 (PDT) Subject: Deditor References: <74a2f743-aa0a-4beb-8c62-3e32b6ac7489@k22g2000yqh.googlegroups.com> <75a7cd73-50c9-4dc0-a88d-68051f1e3795@k22g2000yqh.googlegroups.com> <761080e3-bbda-4c3b-a38b-f9e0b1e4dcad@a10g2000vbz.googlegroups.com> <2cc05cc3-2c8a-42ba-bb7b-348206546378@k11g2000yqc.googlegroups.com> <35348319-4042-4929-a81c-2e1cec7de3f3@b19g2000yqg.googlegroups.com> <7d8e78d2-8a90-431e-8a5d-d9f81d393e40@j26g2000yqa.googlegroups.com> Message-ID: On 1 mei, 17:50, Alec Taylor wrote: > Traceback (most recent call last): > ?File "O:\deditor\deditor\deditor.py", line 7, in e> > ? ?import wx, os, datetime, sys, ConfigParser, wx.aui, wx.lib.scrolledpanel > ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4 > 5, in > ? ?from wx._core import * > ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i > n > ? ?import _core_ > ImportError: DLL load failed: %1 is not a valid Win32 application. > > > > On Mon, May 2, 2011 at 12:33 AM, Kruptein wrote: > > On 1 mei, 10:59, Alec Taylor wrote: > >> Maybe I'm missing something, but I downloaded the zip file and ran > >> each .py and .pyc file in turn, but none brought up the nicededitor > >> GUI I've seen screenshots of... > > >> On the other subject, did you have a preference to what installer I > >> should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi) > > > not a msi, for the rest it doesn't matter :), ?on my windows if you > > rundeditor.py ? it should launch however you need to have the > > wxpython-2.8 package installed, ? what happens if you rundeditor.py > > from console? > > -- > >http://mail.python.org/mailman/listinfo/python-list that looks like you have installed the wxpython module wrongly. Have you downloaded the version that matches your python version? From alexander at lyabah.com Sun May 1 12:15:48 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Sun, 1 May 2011 09:15:48 -0700 (PDT) Subject: Python competitions and learnings References: Message-ID: <51bb0f8c-e789-4c14-8190-0f6b0de038fc@bl1g2000vbb.googlegroups.com> On May 1, 12:29?am, Terry Reedy wrote: > On 4/30/2011 3:22 PM, Alexander Lyabah wrote: > > > I spend a lot of time in writing a new service checkio.org > > > It's all about python, learn python, find the best solution in > > python. > > > And Im looking for feedback from peoples who best in python. Here I > > make some video tutorial about this servicehttp://checkio.blip.tv/ > > > What do you think about it? > > Pretty impressive. My main disappointment is that you are using 2.7 > instead of 3.2, as I feel that beginners should learn Py 3 now. Also, > that is what I routinely use ;-). > > In any case, the home page should say Python 2.7, not just Python, I had > to think to click Console Learn in order to find out what would be legal > when I tried out one of the tasks. > > You might consider offering 3.2 as an alternative. Solutions will be > similar, but details differ. For instance, I noticed that one solution > to 'string split' *depends* on the 2.x leaking of listcomp loop variables. > > > I'm also have a not a very good English, so I need help with it too, > > because some parts of checkio.org ?not in very well English > > Home page: "In the descriptions of this tasks there is always > information from manuals and tutorials," 'these tasks' > > "game.Choice a game " => "game. Choose a game " > "users. Choice a game" => again, 'Choose' > > "and fall into the top " I think you mean "and climb into the top " > > "programs on arena. " => "program in the arena. " > > "By the result of competition formed top of the game. " > This is unclear. perhaps "The best will be chosen by the result of the > competition." > > I see a mailto: link at the bottom of the page, so I will report > anything else I see later. > > -- > Terry Jan Reedy thanks for your translation. It's already published on site. And I will wait for your mail From alexander at lyabah.com Sun May 1 12:22:46 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Sun, 1 May 2011 09:22:46 -0700 (PDT) Subject: Python competitions and learnings References: <2N1vp.21945$vC5.16209@newsfe01.iad> Message-ID: <5e4ec696-4d50-4b88-9fa5-229f293c0639@q21g2000vbs.googlegroups.com> On May 1, 3:26?am, harrismh777 wrote: > Alexander Lyabah wrote: > > What do you think about it? > > > I'm also have a not a very good English, so I need help with it too, > > Alexander, your site is very interesting. I spent some time this > afternoon appreciating your work. Nice job. > > Be encouraged, your English is much better than my Russian! I also > looked over the orphanage site and I appreciate how much you are doing > there in Ukraine for the children. Keep up the good work. > > I too am a little disappointed that Python3 is not being used. I want to > encourage you to work in that direction as well. I may have some time to > volunteer to checkio.org; for help with the English, and maybe with some > help as a tester. We'll see... I have a lot of my own fish to fry here, > as we say in America. > > Blessings on your work, friend. > > m harris I spend a lot of time to make a almost full support of python 2.7 from sandbox. If somebody help me this sandboxed python 3.* i will add support of it on checkio.org with big pleasure. From alexander at lyabah.com Sun May 1 12:49:14 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Sun, 1 May 2011 09:49:14 -0700 (PDT) Subject: Python competitions and learnings References: <2N1vp.21945$vC5.16209@newsfe01.iad> <5e4ec696-4d50-4b88-9fa5-229f293c0639@q21g2000vbs.googlegroups.com> Message-ID: And what do you think about Score Games and competitions? From brenNOSPAMbarn at NObrenSPAMbarn.net Sun May 1 14:14:11 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sun, 1 May 2011 18:14:11 +0000 (UTC) Subject: skipping one unittest assertion? References: Message-ID: Roy Smith wrote: > Is there any way to skip a single assertion in a unittest test > method? I know I can @skip or @expectedFailure the method, but I'm > looking for something finer-grain than that. > > There's one particular assertion in a test method which depends on > production code that hasn't been written yet. I could factor that > out into its own test methods and @skip that, but it would be > cleaner to be able to mark the particular assertion. > > (using python 2.6, but importing unittest2 from 2.7) Can't you just comment out that line? -- --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 roy at panix.com Sun May 1 14:16:24 2011 From: roy at panix.com (Roy Smith) Date: Sun, 01 May 2011 14:16:24 -0400 Subject: skipping one unittest assertion? References: Message-ID: In article , "OKB (not okblacke)" wrote: > Roy Smith wrote: > > > Is there any way to skip a single assertion in a unittest test > > method? I know I can @skip or @expectedFailure the method, but I'm > > looking for something finer-grain than that. > > > > There's one particular assertion in a test method which depends on > > production code that hasn't been written yet. I could factor that > > out into its own test methods and @skip that, but it would be > > cleaner to be able to mark the particular assertion. > > > > (using python 2.6, but importing unittest2 from 2.7) > > Can't you just comment out that line? Sure, but the point of @skip and @expectFailure is that they leave a visible trail in the test output that you need to go back and fix something. From gandalf at shopzeus.com Sun May 1 14:36:13 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sun, 01 May 2011 20:36:13 +0200 Subject: wxGrid, PyGridTableBase, strange SWIG error message! Message-ID: <4DBDA81D.10002@shopzeus.com> I'm trying to create a special widget that is a wx.Grid and also a PyGridTableBase. In my special case of application, I really need to have a grid that uses itself for getting cell data and cell attributes. Here is a test program, demonstrating my problem: import wx from wx.grid import Grid,PyGridTableBase class SpecialGrid(Grid,PyGridTableBase): def __init__(self,*args,**kwargs): PyGridTableBase.__init__(self) Grid.__init__(self,*args,**kwargs) self.SetTable(self) def SetTable(self,table): if table is not self: raise Exception("Grid must be its own table!") else: PyGridTableBase.SetTable(self,self,takeOwnership=False) app=wx.App(redirect=None) frame=wx.Frame(None) g = SpecialGrid(parent=frame) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(g,1,wx.EXPAND) frame.SetSizer(sizer) frame.Show() frame.Maximize() app.MainLoop() This program throws: Traceback (most recent call last): File "test.py", line 18, in g = SpecialGrid(parent=frame) File "test.py", line 6, in __init__ PyGridTableBase.__init__(self) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/grid.py", line 910, in __init__ self._setOORInfo(self);PyGridTableBase._setCallbackInfo(self, self, PyGridTableBase) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 3886, in _setOORInfo val = _core_.EvtHandler__setOORInfo(*args, **kwargs) TypeError: in method 'EvtHandler__setOORInfo', expected argument 1 of type 'wxEvtHandler *' This makes no sense to me. If I swap the constructor calls: def __init__(self,*args,**kwargs): Grid.__init__(self,*args,**kwargs) PyGridTableBase.__init__(self) self.SetTable(self) Then I get this: Traceback (most recent call last): File "test.py", line 18, in g = SpecialGrid(parent=frame) File "test.py", line 7, in __init__ PyGridTableBase.__init__(self) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/grid.py", line 910, in __init__ self._setOORInfo(self);PyGridTableBase._setCallbackInfo(self, self, PyGridTableBase) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 3887, in _setOORInfo args[0].this.own(False) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 14586, in __getattr__ raise PyDeadObjectError(self.attrStr % self._name) wx._core.PyDeadObjectError: The C++ part of the SpecialGrid object has been deleted, attribute access no longer allowed. What the heck? Thanks, Laszlo From tjreedy at udel.edu Sun May 1 15:10:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 15:10:11 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/1/2011 4:45 AM, Steven D'Aprano wrote: > Python uses a data model of "name binding" and "call by object" > (also known as "call by sharing"). I trust I don't need to define my > terms, but just in case: > > http://effbot.org/zone/call-by-object.htm > http://effbot.org/zone/python-objects.htm > > > Now, this is different from languages like C and Pascal, which is > based on variables, Or Fortran or Basic (and I suspect, but do not know, Algol) and other descendents: Ada?, PL/1?). In statistical languages, user-defined names typically refer to typed data columns (eash a set of storage locations) or user-defined functions. > "Python's data model is different from other languages" > > which is perfectly correct, if you think of C as "other languages". > But it's equally correct to say that Python's data model is the same > as other languages. You defined Python's 'data model' as having two aspects: 'name binding' and 'call by object'. A language could match one but not the other. I believe Lisps have name-binding, but I know not all only have call-object. Macro calls (and earlier predecessors) are call-by-code-text. As I understand it, Python and Ruby have the same > data model. So does Java, so long as you only consider objects and > ignore unboxed native values. I believe (but could be wrong) that > another language of about the same vintage as Python, Emerald, also > uses the same model. That's not surprising, because I believe that > Emerald (just like Python) was strongly influenced by CLU. While Guido does not, that I know of, credit CLU as Python's direct inspiration, I think it (and Barbara Liskov) as the originator of Python's data model. I believe she thought of the call-by-object semantics as something of an innovation. > What other languages use the same, or mostly similar, data model as > Python? Natural languages. That is why I think it is better to think of Python as an algorithm language or information-object manipulation language rather than as just a linear-memory machine language. A linear memory with bytes addressed from 0 to max-int or max-long is an explicit part of the definition of assembly languages and C. It is no part of the definition of Python. Nice begin-a-thread post. -- Terry Jan Reedy From martin.schoon at gmail.com Sun May 1 15:53:08 2011 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 1 May 2011 19:53:08 GMT Subject: [OT] VCS for non-text (was Development tools and practices for Pythonistas) References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <5qqs88-9e7.ln1@svn.schaathun.net> <9222afFmqjU1@mid.individual.net> Message-ID: <925s14FokqU1@mid.individual.net> On 2011-04-30, Tim Chase wrote: > On 04/30/2011 04:15 AM, Martin Sch??n wrote: >> You guys are very code focused, which is natural given where we are. >> >> Having absorbed what I have seen here, looked a little at Mercurial, >> read a little on the webs of Fossil and Bazaar I start to think there >> is great merit in all this VCS stuff for other types of projects. >> >> At work my projects contain very little coding (some Python, some >> matlab/scilab perhaps) but a fair amount of CAD/CAE, written >> reports, presentations (OpenOffice and that other Office), >> spread sheets etc etc. A mixture of ascii-files and various >> proprietary formats most of which is stored in binary form. >> Some of the CAE-work generate pretty big files stored >> in dynamically created subdirectories. > > For non-text blobs, it takes a little bit of insight to get the > most out of them. For OpenDocument (Open/Libre Office > documents), they're zipped files containing text/XML which can be > diff'ed with more meaning. Usually there are custom filters for > git[1], Mercurial[2] and Bazaar[3] which will unpack the zipped > file contents before committing and give you more sensible diffs. > Likewise, for images (gif/jpg/tiff/raw/etc), there are > particular image-diff programs which make it easier to tell what > happened, as the textual diff of binary files is pretty useless. > However some images (such as .svg files) are XML/text inside, > and diff pretty nicely without extra effort. > > I can't speak to CAD/CAE, but it would have to be addressed on a > per-format basis in your given VCS. That said, you *can* store > the binary blobs in each, it's just not as useful without > meaningful comparisons. > > -tkc > > [1] > http://kerneltrap.org/mailarchive/git/2008/9/15/3305014 > > [2] > http://mercurial.selenic.com/wiki/HandlingOpenDocumentFiles > > [3] > http://doc.bazaar.canonical.com/plugins/en/oodiff.html > All very useful information. Thank you for that Tim. /Martin From airween at gmail.com Sun May 1 16:00:36 2011 From: airween at gmail.com (=?utf-8?Q?Heged=C3=BCs?= Ervin) Date: Sun, 1 May 2011 22:00:36 +0200 Subject: Py_INCREF() incomprehension In-Reply-To: References: Message-ID: <20110501200035.GA6310@arxnet.hu> hello, On Wed, Apr 27, 2011 at 11:58:18AM +0200, Thomas Rachel wrote: > Am 26.04.2011 20:44, schrieb Heged?s Ervin: > > >and (maybe) final question: :) > > > >I defined many exceptions: > > > >static PyObject *cibcrypt_error_nokey; > >static PyObject *cibcrypt_error_nofile; > >static PyObject *cibcrypt_error_badpad; > >... > > > >void handle_err(int errcode) { > > switch(errcode) { > > case -1: PyErr_SetString(cibcrypt_error_nokey, "Can't find key."); > > break; > >... > >} > >... > > cibcrypt_error_nokey = PyErr_NewException("cibcrypt.error_nokey", NULL, NULL); > >... > > PyModule_AddObject(o, "error", cibcrypt_error_nokey); > > Then I would not use the name "error" here, but maybe "error_nokey" > or even better "NoKeyException". > > Oops: there is an inconsistency in the docu: on the one hand, it says > > There are exactly two important exceptions to this rule: > PyTuple_SetItem() and PyList_SetItem(). > > stating these are the only ones who take over ownership. > > But PyModule_AddObject() claims to "steal" a reference as well... > > > >I am right, here also no need any Py_INCREF()/Py_DECREF() action, > >based on this doc: > >http://docs.python.org/c-api/arg.html > > I'm not sure: On one hand, you pass ownership of the error objects > to the module. There - one could think - they are until the module > is unloaded. > > But what if someone does "del module.NoKeyException"? In this case, > the object could have been destroyed, and you are using it -> BANG. > > On the other hand, if you keep one instance internally, it is not > possible any longer to unload the module without a memory leak... > > > As already stated - you might want to have a look at some other C > modules and mimic their behaviour... (and hope they are doing it > right...) so, I've checked it - there wasn't any Py_INCREF(), I just calmed down. But. :) My module contains just 4 functions (in C), which translate 3rd party lib to Python. The name would be _mycrypt.so example. I wrapped it a pure Python module, its name is mycrypt.py. Then, I've import pure Python module in a main program, like this: =%= mycrypt.py: import _mycrypt ... =%= =%= userapp.py: import mycrypt ... =%= I've missed out something, and then I didn't get exception, instead there were a segfault. :( I've put it a Py_INCREF() after every PyModule_AddObject(), eg.: PyModule_AddObject(o, "error", cibcrypt_error_nokey); Py_INCREF(cibcrypt_error_nokey); and now if there is some expected exception, I get it. Any explanation? Thanks: a. ps: this is just for my passion, but I would like to understand it very-very much :) From airween at gmail.com Sun May 1 16:14:14 2011 From: airween at gmail.com (=?utf-8?Q?Heged=C3=BCs?= Ervin) Date: Sun, 1 May 2011 22:14:14 +0200 Subject: Compile 32bit C-lib on 64 bit Message-ID: <20110501201413.GB6310@arxnet.hu> Hello, this is not a "clear" Python question - I've wrote a module in C, which uses a 3rd-party lib - it's a closed source, I just get the .so, .a and a header file. Looks like it works on 32bit (on my desktop), but it must be run on 64bit servers. When I'm compiling it on 64bit, gcc says: /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when searching for -l3rdpartyCrypt There _is_ the .so in /lib32 directory: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, stripped What is the correct solution? thank you: a. From rosuav at gmail.com Sun May 1 16:49:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 06:49:41 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 1, 2011 at 11:15 PM, Hans Georg Schaathun wrote: > : ?The Python virtual machine knows how big each entry on the stack needs to > : ?be. (I don't, but it's got to be at least the size of a pointer.) So > : ?"number of items" is just a multiplication away from "size of the items". > > Does it? ?In a conventional stack you need to store all the local > variables for the function as well. ?Thus, there is no limit to how > much space a single element on the stack may require. In anything less than a useless and trivial demo of recursion, there's going to be some kind of local state for each call (in the case of a fibonacci or factorial, that would be the number(s) being multiplied). Whether they go on the stack or elsewhere, that's additional storage that gets multiplied out. > There is also a limit to how far you can usefully recurse over a limited > data structure. Sure. Serialize this Python object in a way that can be given to, say, PHP: foo={"asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo] Recurse from self into the list, recurse from there into a dictionary... Okay, that's a rather naive recursion and fraught with risk, but there are more complex examples. And watching for cyclic references would be O(N*N) as you'd need to maintain a full list of every PyObject* that you've sighted (talking here from the C API, but the same consideration applies whichever way you do it). > There are many ways to crash a system if you want to. > > But if you don't deliberately try to crash it, you are much more > likely to crash it because you allocate to much memory in each step > than because the recursion gets to deep. ?Consequently, because recursion > is usually a clearer form of expression than iterative loops, recursion > may actually be /less/ dangerous. I'm not sure that recursion is clearer. Recursion is a way of expressing the two rules: 1! = 1 n! = n * (n-1)! But iteration is a way of expressing this equivalent rule: n! = 1 * 2 * 3 * ... * n-1 * n It really depends what you're trying to say. Chris Angelico From ryan.morrone at gmail.com Sun May 1 16:50:56 2011 From: ryan.morrone at gmail.com (PyNewbie) Date: Sun, 1 May 2011 13:50:56 -0700 (PDT) Subject: PIL Question Message-ID: Hi, I'm new with Python and PIL. I have a very simple question regarding an image capture function I'm attempting. Here is the code: >>> from PIL import ImageGrab >>> ImageGrab.grab().save("screen_capture.jpg", "JPEG") Question: I can't seem to find the captured image, where does it go? The python Shell IDE does not display an error, and the code appears to have been processed. Additional Info: I'm using Python 2.6, and PIL 1.1.7 for Python 2.6 Windows. From rosuav at gmail.com Sun May 1 16:51:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 06:51:45 +1000 Subject: skipping one unittest assertion? In-Reply-To: References: Message-ID: On Mon, May 2, 2011 at 4:16 AM, Roy Smith wrote: >> ? ? ? Can't you just comment out that line? > > Sure, but the point of @skip and @expectFailure is that they leave a > visible trail in the test output that you need to go back and fix > something. Comment it out and add a line of output manually? Make everything as simple as possible (but no simpler). Chris Angelico From jearl at notengoamigos.org Sun May 1 16:51:56 2011 From: jearl at notengoamigos.org (Jason Earl) Date: Sun, 01 May 2011 14:51:56 -0600 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> Message-ID: <87mxj6kutv.fsf@notengoamigos.org> On Sun, May 01 2011, Dietmar Schwertberger wrote: > Am 01.05.2011 02:47, schrieb Shawn Milochik: >> Look at the big two sites for open-source repositories -- github and >> bitbucket. One's git, the other Mercurial. I don't think you can go >> wrong picking either one. > > Can any of those be used from Python as a library, i.e. something like > import Hg > r = Hg.open(path) > > When I had a look at Mercurial, which is implemented in Python, it was > implemented in a way that I could not do that. It was implemented as > rather monolithic program which could be used from os.system(...) > only. > > With a good API, I could easily have integrated it into my development > flow. I have a codebase which is shared between different projects and > there are many small changes on many different PCs. In theory a > distributed VCS is good at supporting that, but in practice I went > back to my lightweight synchronization scripts and file storage > again. With the API, I could have best of both worlds. You should take a look at Bazaar. I found it fairly easy to use bzrlib from my own Python scripts. http://people.canonical.com/~mwh/bzrlibapi/ Jason From ben+python at benfinney.id.au Sun May 1 17:45:26 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 May 2011 07:45:26 +1000 Subject: skipping one unittest assertion? References: <87wriah4qg.fsf@benfinney.id.au> Message-ID: <87k4eagknd.fsf@benfinney.id.au> Roy Smith writes: > Ben Finney wrote: > > > Each test case should be testing one thing: if it fails, it should be > > for exactly one reason. > > Well, yeah, that's certainly the XP/unit-test doctrine. In practice > however, tests often get written as "do a bunch of stuff to get some > result, then make a bunch of assertions about that result". And the result is an increasingly-difficult maintenance burden for the test suite, as you've discovered. > Sure, you could make each of those assertions a distinct method, and > factor the "do a bunch of stuff" into setUp(). Which probably means > factoring those methods out into a new TestCase subclass. At some > point, however practicality trumps doctrine. Yet practicality, i.e. making your test cases manageable, is exactly what you don't have with your current approach. I'm not quoting doctrine at you; I'm saying that *because of problems like you're encountering*, you should refactor your test cases to do one test per case. -- \ ?Absurdity, n. A statement or belief manifestly inconsistent | `\ with one's own opinion.? ?Ambrose Bierce, _The Devil's | _o__) Dictionary_, 1906 | Ben Finney From ben+python at benfinney.id.au Sun May 1 17:49:40 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 May 2011 07:49:40 +1000 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> Message-ID: <87d3k2gkgb.fsf@benfinney.id.au> Dietmar Schwertberger writes: > Am 01.05.2011 02:47, schrieb Shawn Milochik: > > Look at the big two sites for open-source repositories -- github and > > bitbucket. Note that there are three: Launchpad (backed by Bazaar) is the other ?big site? for free-software project hosting. > Can any of those be used from Python as a library, i.e. something like > import Hg > r = Hg.open(path) I haven't used it, but Launchpad (the Canonical project hosting which uses Bazaar for the VCS) is of course well-supported in the Bazaar libraries. Access to the hosting site is eminently programmable with a good API, by all accounts. -- \ ?It is seldom that liberty of any kind is lost all at once.? | `\ ?David Hume | _o__) | Ben Finney From tjreedy at udel.edu Sun May 1 18:24:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 18:24:30 -0400 Subject: Fibonacci series recursion error In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/1/2011 5:27 AM, Hans Georg Schaathun wrote: > Of course you do, but you are still only saying that there might be > an application where this might happen because of excessive although > logically correct recursion. You have not given a single example where > it actually happened. I will. Stack overflow *can* happen with a bad base case. It *will* happen with correct linear recursion* applied to a large enough collection on a finite-memory machine (as opposed to an 'infinite' memory Turing machine). def count_popable_collection(pop_col): try: pop_col.pop() return count_popable_collection(pop_col) + 1 except (KeyError,IndexError): return 0 print(count_popable_collection({1,2,3})) print(count_popable_collection([1,2,3])) Both calls correctly print 3, but will fail for large enough sets or lists. I call the above body recursion*. A tail-recursive version def count_popable_collection2(pop_col, cnt=0): try: pop_col.pop() return count_popable_collection2(pop_col, cnt + 1) except (KeyError,IndexError): return cnt print(count_popable_collection2({1,2,3})) print(count_popable_collection2([1,2,3])) is less clear to most people, I think, and, executed as written, fails at the same point with the same memory error. Try either of the above with list(range(bignum)) (I am using 3.2). This does not make linear recursion 'bad', just impractical for general use on finite-memory machines. While I consider it very useful for learning, it is unnecessary because it is easy to write an iterative version. So called tail-recursion optimization saves memory by REMOVING RECURSION and replacing it with iteration. def count_popable_collection3(pop_col): cnt = 0 while True: try: pop_col.pop() cnt += 1 except (KeyError,IndexError): return cnt print(count_popable_collection3({1,2,3})) print(count_popable_collection3([1,2,3])) Python does not do this automatically because 1) it can be a semantic change under some circumstances; 2) one who wants the iterative version can just as easily write it directly; and 3) Python has a better way to process collections that removes essentially all the boilerplate in the recursive-call and while-loop versions: def count_popable_collection4(pop_col): cnt = 0 for item in pop_col: cnt += 1 return cnt print(count_popable_collection4({1,2,3})) print(count_popable_collection4([1,2,3])) Binary recursion* is a different case because the exponential growth in leaf number and hence time limits the useful depth of recursion to well below the default of 1000. * linear recursion: usually and at most one recursive call per call * binary recursion: usually and at most two recursive calls per call Fib is the best known example. * tail recursion: base cases return completed calculations * body recursion: base cases return starting values, often constants -- Terry Jan Reedy From tjreedy at udel.edu Sun May 1 18:33:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 18:33:02 -0400 Subject: Python competitions and learnings In-Reply-To: References: <2N1vp.21945$vC5.16209@newsfe01.iad> <5e4ec696-4d50-4b88-9fa5-229f293c0639@q21g2000vbs.googlegroups.com> Message-ID: On 5/1/2011 12:49 PM, Alexander Lyabah wrote: > And what do you think about Score Games and competitions? The rules of the first score game were not clear to me. I could not figure out how to play it interactively myself so I could see how it actually played. -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Sun May 1 18:33:08 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 02 May 2011 10:33:08 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9265d8FtkqU1@mid.individual.net> Steven D'Aprano wrote: > Python uses a data model of "name binding" and "call by object" (also > known as "call by sharing"). It can be summed up in a less jargony way by saying that all data is stored in heap-allocated objects, and variables refer to objects rather than containing them directly. Everything else follows from that. > What other languages use the same, or mostly similar, data model as > Python? Pretty much any dynamically-typed language: Lisp, Scheme, Smalltalk, Snobol, Icon, Postscript, Ruby, Lua, ... Some languages have it for some data types but not others. Java, VB, Objective-C come to mind. -- Greg From greg.ewing at canterbury.ac.nz Sun May 1 18:37:17 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 02 May 2011 10:37:17 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9265kvFv8gU1@mid.individual.net> Terry Reedy wrote: > While Guido does not, that I know of, credit CLU as Python's direct > inspiration, I think it (and Barbara Liskov) as the originator of > Python's data model. I believe she thought of the call-by-object > semantics as something of an innovation. I don't think she can claim credit for that, seeing as as Lisp was built around it. She may have invented the *term* "call by object" (unnecessarily, in my opinion) but the idea wasn't new. -- Greg From greg.ewing at canterbury.ac.nz Sun May 1 18:48:58 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 02 May 2011 10:48:58 +1200 Subject: Py_INCREF() incomprehension In-Reply-To: References: Message-ID: <9266atF3vrU1@mid.individual.net> Heged?s Ervin wrote: > I've put it a Py_INCREF() after every PyModule_AddObject(), eg.: > > PyModule_AddObject(o, "error", cibcrypt_error_nokey); > Py_INCREF(cibcrypt_error_nokey); That looks correct, because PyModule_AddObject is documented as stealing a reference to the object. By the way, it probably doesn't make a difference here, but it's better style to do the Py_INCREF *before* calling a function that steals a reference, to be sure that the object can't get spuriously deallocated. -- Greg From bc at freeuk.com Sun May 1 19:16:08 2011 From: bc at freeuk.com (BartC) Date: Mon, 2 May 2011 00:16:08 +0100 Subject: Fibonacci series recursion error In-Reply-To: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4dbbb7b6$0$29991$c3e8da3$5496439d at news.astraweb.com... > On Sat, 30 Apr 2011 08:32:55 +0200, Peter Otten wrote: > >> harrismh777 wrote: >> >>> Ian Kelly wrote: >>>> since the fact is that if >>>> the function were properly coded, the call stack for fib(20) would >>>> never be more than 20 entries deep at any one time. >>>> >>>> >>> Not so much... and much more !.... >>> >>> >>> ... because each recursion level 'return' calls fib() twice, and each >>> of those calls fib() twice, and you get the point... >> >> I don't understand what you are trying to say -- but it's wrong ;) > > > I don't know what M Harris thinks he is trying to say either, but the > *naive* Fibonacci recursive algorithm is particularly badly performing > and should be avoided. It's ironic that of the two classic algorithms > used for teaching beginner programmers about recursion, neither is useful > in practice. Yes, it generates lots of calls. About 22000 for fib(20), and 330 million for fib(40). That's why it's popular for benchmarks that measure performance of function calls. Using an iterative algorithm wouldn't work quite so well... -- Bartc From david at boddie.org.uk Sun May 1 19:33:00 2011 From: david at boddie.org.uk (David Boddie) Date: Mon, 02 May 2011 01:33:00 +0200 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> Message-ID: On Sunday 01 May 2011 18:11, Dietmar Schwertberger wrote: > Am 01.05.2011 02:47, schrieb Shawn Milochik: >> Look at the big two sites for open-source repositories -- github and >> bitbucket. One's git, the other Mercurial. I don't think you can go >> wrong picking either one. > > Can any of those be used from Python as a library, i.e. something like > import Hg > r = Hg.open(path) > > When I had a look at Mercurial, which is implemented in Python, > it was implemented in a way that I could not do that. It was implemented > as rather monolithic program which could be used from os.system(...) > only. After noting the warnings it contains, see the following page for a description of the Python API for Mercurial: http://mercurial.selenic.com/wiki/MercurialApi Git also has a Python API, which is fairly reasonable to use, though a bit different to the Mercurial one: http://www.samba.org/~jelmer/dulwich/ I've used both with some success. David From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sun May 1 20:59:55 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 02 May 2011 02:59:55 +0200 Subject: Py_INCREF() incomprehension In-Reply-To: References: Message-ID: Am 01.05.2011 22:00, schrieb Heged?s Ervin: > My module contains just 4 functions (in C), which translate 3rd > party lib to Python. The name would be _mycrypt.so example. > > I wrapped it a pure Python module, its name is mycrypt.py. > > Then, I've import pure Python module in a main program, like > this: > > =%= > mycrypt.py: > > import _mycrypt > ... > =%= > > =%= > userapp.py: > > import mycrypt > ... > =%= AFAICS, it looks ok. > I've missed out something, and then I didn't get exception, > instead there were a segfault. :( I guess this is the point where yo should start printf programing. * What happens during module initialization? * What happens n the functions? * Where does the stuff fail? * What are the reference counts of the involved objects? etc. > I've put it a Py_INCREF() after every PyModule_AddObject(), eg.: > > PyModule_AddObject(o, "error", cibcrypt_error_nokey); > Py_INCREF(cibcrypt_error_nokey); > > and now if there is some expected exception, I get it. > Any explanation? I don't have one - I would think that if the module object exists for all the time, it would be enough to have one reference there. But obviously it is not enough - did you at any time del something related to here? The module or one of its attributes? Anyway, it seems safer to do INCREF here - so do it. (As Gregory already stated - it looks cleaner if you do INCREF before AddObject.) > ps: this is just for my passion, but I would like to understand > it very-very much :) Understandable. That's that the printf debugging of the refcounts can be good for - even if you don't really have a problem. Thomas From clp2 at rebertia.com Sun May 1 21:00:26 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 1 May 2011 18:00:26 -0700 Subject: PIL Question In-Reply-To: References: Message-ID: On Sun, May 1, 2011 at 1:50 PM, PyNewbie wrote: > Hi, > > I'm new with Python and PIL. I have a very simple question regarding an image capture function I'm attempting. > > Here is the code: > > >>>> from PIL import ImageGrab >>>> ImageGrab.grab().save("screen_capture.jpg", "JPEG") > > Question: I can't seem to find the captured image, where does it go? ?The python Shell IDE does not display an error, and the code appears to have been processed. > > Additional Info: I'm using Python 2.6, and PIL 1.1.7 for Python 2.6 Windows. I would think to a file named "screen_capture.jpg" in the current working directory. What that is for IDLE, I don't know. You can determine what folder that is by running this in your Python shell: from os import getcwd print(getcwd()) Also, I would suggest using absolute file paths in the future, rather than relative ones; e.g. "C:/Documents and Settings/Your username/Desktop/screen_capture.jpg" rather than just "screen_capture.jpg". Cheers, Chris From steve+comp.lang.python at pearwood.info Sun May 1 21:09:21 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2011 01:09:21 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dbe0440$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 May 2011 14:15:35 +0100, Hans Georg Schaathun wrote: > On 01 May 2011 11:56:57 GMT, Steven D'Aprano > wrote: > : Just google on "stack overflow crash". > > And I get loads of examples of stack overflows, but I could not see > anybody linking this to logically correct recursion. Wikipedia, for > instance, mentions two common causes, neither of which has anything to > do with logically correct recursion. Ah, I see where you're coming from now! You think I'm arguing *against* the use of recursion. Not at all. Earlier in this thread, I said: "Consequently, the naive recursive function is ridiculously slow and memory-hungry. This seems to have give rise to a myth that recursion should be avoided. What needs to be avoided is *badly thought out* recursion." [Emphasis in original.] > : The Python virtual machine knows how big each entry on the stack > needs to : be. (I don't, but it's got to be at least the size of a > pointer.) So : "number of items" is just a multiplication away from > "size of the items". > > Does it? In a conventional stack you need to store all the local > variables for the function as well. Thus, there is no limit to how much > space a single element on the stack may require. To be honest, I don't know what Python does with local variables. But I *guess* it uses a constant-sized record which points to the locals, because that's how I'd do it :) I do know that objects in CPython all live in the heap, not on the stack, so even if local variables are placed directly on the stack, that's only a pointer to the object, not the entire object. [...] > But all of this is in principle, and does not constitute any valid > reason to avoid recursion in practice. If you want to argue that > recursion is a bad thing in /practice/ you need a /practical/ argument. Okay. In *practice*, all else being equal, recursion is less efficient than iteration, especially in Python which doesn't optimize tail- recursion. So if you have a choice between two algorithms which are equally simple and clear, and one is recursive and the other uses iteration, the one with iteration will be more efficient. However, and equally in practice, it's unusual to have two equally simple algorithms. Usually one or the other will be much simpler than the other, and you should avoid "optimizing" code based on hypothetical considerations and instead prefer simple code over complicated, unless absolutely necessary. Given a choice between a complicated iterative algorithm and a simple recursive version, there's no prima facie reason to expect the recursive version to *necessarily* be slower than iteration in Python *merely* because it uses recursion. As always, if speed is an issue, profile and identify the bottlenecks before deciding how to fix them. -- Steven From tjreedy at udel.edu Sun May 1 21:42:45 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 21:42:45 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <9265d8FtkqU1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <9265d8FtkqU1@mid.individual.net> Message-ID: On 5/1/2011 6:33 PM, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> Python uses a data model of "name binding" and "call by object" (also >> known as "call by sharing"). > > It can be summed up in a less jargony way by saying that all > data is stored in heap-allocated objects, This is incomprehensible jargon to some; is only (partly) true of (typical) machine-implementations; and seems not to be true of all objects. I believe that for CPython, builtin objects, including the fixed arrray of ints from -5 to 256, are allocated in another data segment (more CS jargon, which is irrelavant to human interpreters). Evidence 1: >>> id(int) 505285072 >>> id(str) 505233232 >>> id(1) 505493792 >>> id(-5) 505493696 This appears to be initialized data segment. (Someone else could take a white box approach and look at the source. ;-) >>> id(333333) 16512288 >>> id('a') 11227616 This is heap. Evidence 2: Some error messages use 'heap type' to mean 'Python-coded class' >>> 1 .__class__ = str Traceback (most recent call last): File "", line 1, in 1 .__class__ = str TypeError: __class__ assignment: only for heap types http://bugs.python.org/issue4600 > and variables refer to objects rather than containing them directly. > Everything else follows from that. Would you say 'names refer to objects rather than containing them directly'? Surely not. Using 'name' rather than the hugely overloaded tern 'variable' automatically avoids certain misunderstandings. A good summary might be "Python manipulates objects that are accessed through literals, names, and expressions." -- Terry Jan Reedy From benjamin.kaplan at case.edu Sun May 1 22:15:20 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 1 May 2011 22:15:20 -0400 Subject: Compile 32bit C-lib on 64 bit In-Reply-To: <20110501201413.GB6310@arxnet.hu> References: <20110501201413.GB6310@arxnet.hu> Message-ID: On Sun, May 1, 2011 at 4:14 PM, Heged?s Ervin wrote: > Hello, > > this is not a "clear" Python question - I've wrote a module in C, > which uses a 3rd-party lib - it's a closed source, I just get the > .so, .a and a header file. > > Looks like it works on 32bit (on my desktop), but it must be run > on 64bit servers. > > > When I'm compiling it on 64bit, gcc says: > > /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when searching for -l3rdpartyCrypt > > There _is_ the .so in /lib32 directory: > > ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), > dynamically linked, stripped > > > What is the correct solution? > > > thank you: > > > a. You cannot link a 64-bit binary against a 32- bit library. It just won't work. If you can't get a 64-bit copy of that library, you'll have to compile everything (including Python and all its dependencies) as 32-bit. > > -- > http://mail.python.org/mailman/listinfo/python-list > From nobody at nowhere.com Sun May 1 22:20:40 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 02 May 2011 03:20:40 +0100 Subject: Compile 32bit C-lib on 64 bit References: Message-ID: On Sun, 01 May 2011 22:14:14 +0200, Heged?s Ervin wrote: > When I'm compiling it on 64bit, gcc says: > > /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when > searching for -l3rdpartyCrypt > > There _is_ the .so in /lib32 directory: > > ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically > linked, stripped > > > What is the correct solution? You need to build your module for a 32-bit version of Python. On a 64-bit system, each process is either 32-bit or 64-bit process. You can't mix 32-bit code and 64-bit code in a single process. If you have to use that library and you only have a 32-bit version of it, then everything else must also be 32-bit: the Python interpreter, your binary module, and all of the libraries which it uses. From tjreedy at udel.edu Sun May 1 22:30:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 22:30:02 -0400 Subject: Fibonacci series recursion error In-Reply-To: References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/1/2011 7:16 PM, BartC wrote: > Yes, it generates lots of calls. > > About 22000 for fib(20), and 330 million for fib(40). Using the standard double recursion implementation of fib, ncf(n) (number of calls to fib() for fib(n)) requires ncf(n-2) + ncf(n+1) + 1 calls. The +1 is for the call to fib(n) itself). So it grows a bit faster than fib(n). Fib(n) is actually calculated as the sum of fib(n) 1s: 1+1+1....+1 fib(n) times as 1 is the only non-0 base case and there is nothing else added or multiplied in non-base cases. To put it another way, there are fib(n) leaf nodes labeled 1 in the unbalanced tree generated by the recursion. -- Terry Jan Reedy From no.email at nospam.invalid Sun May 1 22:37:26 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 01 May 2011 19:37:26 -0700 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> <87d3k2gkgb.fsf@benfinney.id.au> Message-ID: <7xei4hsu8p.fsf@ruckus.brouhaha.com> >> > Look at the big two sites for open-source repositories -- github and >> > bitbucket. > Note that there are three: Launchpad (backed by Bazaar) is the other > ?big site? for free-software project hosting. There is also patch-tag.com (using darcs) though it is smaller. From tjreedy at udel.edu Sun May 1 22:50:52 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 22:50:52 -0400 Subject: PIL Question In-Reply-To: References: Message-ID: On 5/1/2011 9:00 PM, Chris Rebert wrote: > I would think to a file named "screen_capture.jpg" in the current > working directory. What that is for IDLE, I don't know. At least on windows with 3.2, if one just starts up the shell, it is in the Pythonxy directory. If one runs a file from an edit window, it changes to the directory of the file, so it operates much as if one had run with the command python -i file.py in the directory of file.py. > You can > determine what folder that is by running this in your Python shell: > > from os import getcwd; print(getcwd()) Yes, this gives two different answers in the two cases noted above. -- Terry Jan Reedy From rustompmody at gmail.com Sun May 1 23:06:40 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 1 May 2011 20:06:40 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> Message-ID: <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> On Apr 30, 8:21?am, CM wrote: > > A lone developer using such a VCS reaps the benefits of this by getting > > good merging support. > > While we're on the topic, when should a lone developer bother to start > using a VCS? ?At what point in the complexity of a project (say a hobby > project, but > a somewhat seriousish one, around ~5-9k LOC) is the added > complexity of bringing a VCS into it worth it? When you hit your first bug? Ok seriously, when you hit your first serious bug maybe? I am a bit surprised that no one has mentioned rcs so far Not an option if you are not on a *ix system and not something I am specifically recommending. [I grew up on rcs 15 years ago but not used it much of late] You may want to look at rcs if you are in the space where you want: -- something better than tarballs -- no pretensions beyond single-user, single-machine, (almost)single- file usage (ie small scale) -- something that integrates nicely with emacs From ben+python at benfinney.id.au Sun May 1 23:22:44 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 May 2011 13:22:44 +1000 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> Message-ID: <878vuphjln.fsf@benfinney.id.au> rusi writes: > You may want to look at rcs if you are in the space where you want: > -- something better than tarballs > -- no pretensions beyond single-user, single-machine, (almost)single- > file usage (ie small scale) > -- something that integrates nicely with emacs I might have agreed ten years ago; compared to CVS or Subversion, RCS is simpler to use and set up and had lower workflow overhead. But today, Bazaar or Mercurial fill that role just as well: quick simple set up, good tool support (yes, even in Emacs using VC mode), and easy to use for easy things. I really don't see any benefit to using RCS for even a lone hacker tracking files; Bazaar or Mercurial fill that role just as well, and continue to work well as your needs grow. -- \ ?Philosophy is questions that may never be answered. Religion | `\ is answers that may never be questioned.? ?anonymous | _o__) | Ben Finney From rustompmody at gmail.com Sun May 1 23:45:10 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 1 May 2011 20:45:10 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> <878vuphjln.fsf@benfinney.id.au> Message-ID: <5bb8f29f-077c-48f0-a047-ff0977ae0e01@j13g2000pro.googlegroups.com> On May 2, 8:22?am, Ben Finney wrote: > rusi writes: > > You may want to look at rcs if you are in the space where you want: > > -- something better than tarballs > > -- no pretensions beyond single-user, single-machine, (almost)single- > > file usage (ie small scale) > > -- something that integrates nicely with emacs > > I might have agreed ten years ago; compared to CVS or Subversion, RCS is > simpler to use and set up and had lower workflow overhead. > > But today, Bazaar or Mercurial fill that role just as well: quick simple > set up, good tool support (yes, even in Emacs using VC mode), and easy > to use for easy things. > > I really don't see any benefit to using RCS for even a lone hacker > tracking files; Bazaar or Mercurial fill that role just as well, and > continue to work well as your needs grow. In a word: single files. If you have a directory with a number of short unrelated scripts -- python, shell etc -- the philosophy: vcs-manages-projects-not-files is a nuisance not a help. And which is why things like zit http://git.oblomov.eu/zit have arisen: the need to go back from bzr/git/hg to (something like) rcs From drsalists at gmail.com Mon May 2 00:34:47 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 1 May 2011 21:34:47 -0700 Subject: Compile 32bit C-lib on 64 bit In-Reply-To: <20110501201413.GB6310@arxnet.hu> References: <20110501201413.GB6310@arxnet.hu> Message-ID: On Sun, May 1, 2011 at 1:14 PM, Heged?s Ervin wrote: > Hello, > > this is not a "clear" Python question - I've wrote a module in C, > which uses a 3rd-party lib - it's a closed source, I just get the > .so, .a and a header file. > > Looks like it works on 32bit (on my desktop), but it must be run > on 64bit servers. > > > When I'm compiling it on 64bit, gcc says: > > /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when > searching for -l3rdpartyCrypt > > There _is_ the .so in /lib32 directory: > > ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), > dynamically linked, stripped > > > What is the correct solution? > The best solution is to not use a closed source, binary-only, single-sourced (?) security library, especially if it has not been vetted by others from outside the organization from which it was obtained. It costs quite a bit for a company to get such software under enough eyeballs to make it mostly trustworthy, and it puts you at their mercy with regard to an upgrade path. The best security-related algorithms are published and studied by many researchers, and will have multiple interoperating implementations. Rebuilding everything as 32 bit on your 64 bit system (if it's one of those 64 bit systems that can also conveniently run 32 bit binaries - most, but not all, can) may be one of your better options. This of course carries a memory penalty, as you may end up with two copies of your python interpreter and relevant .so's in virtual memory, and hence experience a greater tendency to page. There is no theoretical reason why you cannot use a 32 bit library in a 64 bit application, however it is unlikely to be simple. You could experiment with accessing your 32 bit library via ctypes from a 64 bit interpreter and carefully converting pointers and integers to/from 32 bit and 64 bit (with a significant decrease in usable address space, and the possibility of 64 bit addresses that simply aren't convertible, especially, but not necessarily only, once your process gets large), if you find a way of setting up an appropriate 32 bit stack. You could also emulate a 32 bit CPU in your 64 bit process - this too, is perhaps mostly theoretical - see qemu for an example of something that can, EG, run x86 binaries on a sparc CPU. In short: "You probably could, but it might well be more trouble than it's worth". Another option would be to link your library into a small, 32 bit C program, and then establish some sort of protocol for it to communicate with your 64 bit python interpreter - via a pipe or socket, as examples. Without adequate vendor cooperation, and if you're truly locked in, this may actually be one of your better options for the medium term. Ultimately though, using something like KeyCzar or OpenSSL is probably your best bet. They've been scrutinized copiously, and have very low snake oil factors. That is, assuming KeyCzar or OpenSSL and your binary-only library have overlapping purposes. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon May 2 00:48:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 14:48:27 +1000 Subject: Compile 32bit C-lib on 64 bit In-Reply-To: References: <20110501201413.GB6310@arxnet.hu> Message-ID: On Mon, May 2, 2011 at 2:34 PM, Dan Stromberg wrote: > Another option would be to link your library into a small, 32 bit C program, > and then establish some sort of protocol for it to communicate with your 64 > bit python interpreter - via a pipe or socket, as examples. This is what I would recommend. A Unix socket or pipe or other pure memory IPC mechanism can give some pretty high bandwidth, and it keeps two processes happily isolated, plus it lets the OS handle any conversions necessary (as opposed to your glue code, which is what would happen if you link the 32-bit library to your 64-bit app). Let the operating system do my work for me? Don't mind if I do... Chris Angelico From hg at schaathun.net Mon May 2 01:36:06 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 2 May 2011 06:36:06 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6fs198-8lf.ln1@svn.schaathun.net> On Mon, 2 May 2011 06:49:41 +1000, Chris Angelico wrote: : Sure. Serialize this Python object in a way that can be given to, say, PHP: : foo={"asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo] : Recurse from self into the list, recurse from there into a : dictionary... Okay, that's a rather naive recursion and fraught with : risk, but there are more complex examples. And watching for cyclic : references would be O(N*N) as you'd need to maintain a full list of : every PyObject* that you've sighted (talking here from the C API, but : the same consideration applies whichever way you do it). Wouldn't cyclic references give infinite recursion? And remain infinitive if you recode it iteratively? : I'm not sure that recursion is clearer. Recursion is a way of : expressing the two rules: : : 1! = 1 : n! = n * (n-1)! : : But iteration is a way of expressing this equivalent rule: : : n! = 1 * 2 * 3 * ... * n-1 * n : : It really depends what you're trying to say. True. There is a place for everything. However, in the example above, you can map the recursive definition directly into python without further ado. In order to express the one-liner in python, as iteration, you need to introduce additional elements, namely a state (index variable). Hence, recursion is clearer by being close to the language you would normally use to describe the problem. -- :-- Hans Georg From rosuav at gmail.com Mon May 2 02:28:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 16:28:45 +1000 Subject: Fibonacci series recursion error In-Reply-To: <6fs198-8lf.ln1@svn.schaathun.net> References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> <6fs198-8lf.ln1@svn.schaathun.net> Message-ID: On Mon, May 2, 2011 at 3:36 PM, Hans Georg Schaathun wrote: > On Mon, 2 May 2011 06:49:41 +1000, Chris Angelico > ? wrote: > : ?Sure. Serialize this Python object in a way that can be given to, say, PHP: > : ?foo={"asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo] > > Wouldn't cyclic references give infinite recursion? ?And remain > infinitive if you recode it iteratively? Well, I don't know of a decent non-recursive way to process a recursive structure. Incidentally, this example is almost directly from some working code of ours; I have a C function that recurses over a Python dictionary and aborts as soon as it's found "too much" data (for a fairly arbitrary definition of "too much", but one that's deliberately designed to prevent infinite recursion). Since every element in the dictionary can be a list/dict, and every element of those can be too, there's no non-recursive way to do it, other than by doing the recursion yourself: # partly pseudocode searchme=[foo] while len(searchme): cur=get_next_elem(searchme[-1]) if cur==end_of_list: searchme[-1:]=[] else: if can_be_recursed_into(cur): searchme.append(cur) else: output(cur) This would work, more or less, but it merely trades "true" recursion for the searchme[] stack. Yes, it's iterative. No, it hasn't abolished recursion. > True. ?There is a place for everything. ?However, in the example > above, you can map the recursive definition directly into python > without further ado. ?In order to express the one-liner in python, > as iteration, you need to introduce additional elements, namely > a state (index variable). ?Hence, recursion is clearer by being > close to the language you would normally use to describe the > problem. True, and you could abolish a lot of temporary variables by turning them into parameters to recursive calls. But you've abolished nothing. The recursive factorial is very similar to: reduce(`*,range(1,n+1)) The iterative is very similar to: reduce(`*,xrange(1,n+1)) One of 'em stacks up all the numbers and the other gets 'em as it needs 'em. Fundamentally, there's really not a lot of difference. By piling up the numbers on your stack, you just change the format of your saved state, you don't actually save anything. Chris Angelico From rosuav at gmail.com Mon May 2 02:30:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 16:30:53 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> <6fs198-8lf.ln1@svn.schaathun.net> Message-ID: On Mon, May 2, 2011 at 4:28 PM, Chris Angelico wrote: > reduce(`*,range(1,n+1)) > reduce(`*,xrange(1,n+1)) Whoops, forgot which language I was using. Back-tick functions not being available, these need to be: reduce(operator.mul,range(1,n+1)) reduce(operator.mul,xrange(1,n+1)) Chris Angelico From airween at gmail.com Mon May 2 02:41:14 2011 From: airween at gmail.com (=?utf-8?B?SGVnZWTDvHMs?= Ervin) Date: Mon, 2 May 2011 08:41:14 +0200 Subject: Py_INCREF() incomprehension In-Reply-To: References: Message-ID: <20110502064113.GB2614@arxnet.hu> hello, Thomas, Gregory, thank you for your ansrwers, > I guess this is the point where yo should start printf programing. oh', already done :) > * What happens during module initialization? successfully initialized, > * What happens n the functions? > * Where does the stuff fail? > * What are the reference counts of the involved objects? sorry for the dumb question: how can I controll number of reference in C? > > PyModule_AddObject(o, "error", cibcrypt_error_nokey); > > Py_INCREF(cibcrypt_error_nokey); > > > >and now if there is some expected exception, I get it. > > >Any explanation? > > I don't have one - I would think that if the module object exists > for all the time, it would be enough to have one reference there. > > But obviously it is not enough - did you at any time del something > related to here? The module or one of its attributes? > > Anyway, it seems safer to do INCREF here - so do it. (As Gregory > already stated - it looks cleaner if you do INCREF before > AddObject.) ok, > > >ps: this is just for my passion, but I would like to understand > >it very-very much :) > > Understandable. That's that the printf debugging of the refcounts > can be good for - even if you don't really have a problem. thanks, I'll go to read the docs :) bye: a. From airween at gmail.com Mon May 2 02:43:39 2011 From: airween at gmail.com (=?utf-8?B?SGVnZWTDvHMs?= Ervin) Date: Mon, 2 May 2011 08:43:39 +0200 Subject: Compile 32bit C-lib on 64 bit In-Reply-To: References: Message-ID: <20110502064337.GC2614@arxnet.hu> Hello, thanks for all reply, On Mon, May 02, 2011 at 03:20:40AM +0100, Nobody wrote: > You need to build your module for a 32-bit version of Python. ok, I believed it, I was hoping there is another solution, > On a 64-bit system, each process is either 32-bit or 64-bit process. You > can't mix 32-bit code and 64-bit code in a single process. If you have to > use that library and you only have a 32-bit version of it, then everything > else must also be 32-bit: the Python interpreter, your binary module, and > all of the libraries which it uses. ok, thank you, a. From stefan_ml at behnel.de Mon May 2 03:07:31 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 02 May 2011 09:07:31 +0200 Subject: Py_INCREF() incomprehension In-Reply-To: <20110502064113.GB2614@arxnet.hu> References: <20110502064113.GB2614@arxnet.hu> Message-ID: Heged?s, Ervin, 02.05.2011 08:41: > Thomas, >> I guess this is the point where yo should start printf programing. > > oh', already done :) FWIW, Cython 0.14+ has special support for gdb now, so, in addition to print and printf debugging, you can also use gdb to explore the state of your application, be it at the Python, Cython or C level. http://docs.cython.org/src/userguide/debugging.html Stefan From akabaila at pcug.org.au Mon May 2 03:08:02 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Mon, 2 May 2011 17:08:02 +1000 Subject: Development tools and practices for Pythonistas In-Reply-To: <878vuphjln.fsf@benfinney.id.au> References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> <878vuphjln.fsf@benfinney.id.au> Message-ID: <201105021708.02806.akabaila@pcug.org.au> On Monday 02 May 2011 13:22:44 Ben Finney wrote: > rusi writes: > > You may want to look at rcs if you are in the space where > > But today, Bazaar or Mercurial fill that role just as well: > quick simple set up, good tool support (yes, even in Emacs > using VC mode), and easy to use for easy things. > Actually, Bazaar is more convenient than rcs for a single user, as the repository can be the working directory (with a "hidden" .bzr directory that stores diffs). I had to use git, too, because some projects use git for their version control (viz PySide, Nokia's tool to replace PyQt). IMHO there is not much to pick between git and Bazaar and hg is also rather similar. The remaining doubts are betwwed the Distributed Version Control and the more traditional Subversion, which is also quite nice, even for a single user. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf From rustompmody at gmail.com Mon May 2 03:08:26 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 00:08:26 -0700 (PDT) Subject: Fibonacci series recursion error References: <1zMup.12761$rB2.10164@newsfe21.iad> Message-ID: On Apr 30, 11:14?am, Peter Otten <__pete... at web.de> wrote: > For the record, the one true way to implement the Fibonacci series in Python > is > > >>> def fib(): > > ... ? ? a = b = 1 > ... ? ? while True: > ... ? ? ? ? ? ? yield a > ... ? ? ? ? ? ? a, b = b, a+b # look ma, no temporary variable Not any claim to 'the one true pythonic way' but fib can be written in a clean recursive way with linear space-time behavior asz follows: Dijkstra explained that fib is an 2nd order recurrence -- fib(n) defined in terms of fib (n-1) and fib(n-2) whereas programming loops and recursion are 1st order -- state at iteration n defines state at iteration n+1. Converting the 2nd order fib relation to a 1st order one trivially gives a linear program. The key insight from Dijkstra is that all we need to do is to move from a recursive function returning fibonacci nos to one returning pairs of adjacent ones. def fibpair(n): # returns (fib(n), fib(n+1)) if n==0: return (1,1) else: (a,b) = fibpair(n-1) return (b, a+b) After that fib is just this: def fib(n): a,b = fibpair(n) return a; From rustompmody at gmail.com Mon May 2 03:19:57 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 00:19:57 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> <878vuphjln.fsf@benfinney.id.au> Message-ID: On May 2, 12:08?pm, Algis Kabaila wrote: > > Actually, Bazaar is more convenient than rcs for a single user, > as the repository can be the working directory (with a "hidden" > .bzr directory that stores diffs). ? Dont exactly understand... Is it that you want it specifically hidden? Otherwise rcs will look inside an RCS directory just as bzr will with .bzr git will with .git and so on. From grahn+nntp at snipabacken.se Mon May 2 03:45:20 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 2 May 2011 07:45:20 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 2011-05-01, Terry Reedy wrote: > On 5/1/2011 4:45 AM, Steven D'Aprano wrote: ... >> What other languages use the same, or mostly similar, data model as >> Python? > > Natural languages. That is why I think it is better to think of Python > as an algorithm language or information-object manipulation language > rather than as just a linear-memory machine language.A linear memory > with bytes addressed from 0 to max-int or max-long is an explicit part > of the definition of assembly languages and C. It is no part of the > definition of Python. It's not part of the definition of C either -- C supports segmented memory (pre-386 Intel) and separate code/data address spaces. (Even if most C users tend not to think of it that way.) /Jorgen -- // Jorgen Grahn O o . From ozric at web.de Mon May 2 03:48:09 2011 From: ozric at web.de (christian) Date: Mon, 2 May 2011 00:48:09 -0700 (PDT) Subject: build the "sql where cause" dynamic Message-ID: Hi, from some radio buttons in a django app i concat string like that: But have no idea how i get the or when there different values for a specified p column (# is currently my intended splitter maybe i can concat a better input?). input: "p2=1#p2=2#p1=3#p1=1#p1=5#pc=1#py=1" output: "p2 in ('1','2') and p1 in ('3','1','5') and pc in ('1') and py in ('1')" Many thanks for any starting point Christian From akabaila at pcug.org.au Mon May 2 03:48:31 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Mon, 2 May 2011 17:48:31 +1000 Subject: Development tools and practices for Pythonistas In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <201105021748.31818.akabaila@pcug.org.au> On Monday 02 May 2011 17:19:57 rusi wrote: > On May 2, 12:08 pm, Algis Kabaila wrote: > > Actually, Bazaar is more convenient than rcs for a single > > user, as the repository can be the working directory (with > > a "hidden" .bzr directory that stores diffs). > > Dont exactly understand... > Is it that you want it specifically hidden? > Otherwise rcs will look inside an RCS directory just as bzr > will with .bzr git will with .git and so on. Sorry for not being clear - "ls" will not show directories that start with "." - in that sense these directories are "hidden". They are not really really hidden, as "ls -l" will show them. They simply are not in the way and keep the progressive versions of the program (in form of diffs). Does that make better sense?. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf From nirina.raseliarison at gmail.com Mon May 2 03:48:54 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Mon, 02 May 2011 10:48:54 +0300 Subject: PIL Question In-Reply-To: References: Message-ID: [PyNewbie] > Question: I can't seem to find the captured image, where does it go? for me, it just goes to the current working directory: $ python -i 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 PIL import ImageGrab >>> ImageGrab.grab().save("screen_capture.jpg", "JPEG") >>> import os >>> os.listdir(os.getcwd()) ['.appcfg_cookies', '.appcfg_nag', '.bash_history', '.idlerc', '.inputrc', '.povray', 'bootex.log', 'buildBasicDemo.txt', 'glsample.cpp', 'glsample.o', 'log.txt', 'screen_capture.jpg', 'test.c'] >>> -- nirinA From rosuav at gmail.com Mon May 2 04:13:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 18:13:06 +1000 Subject: build the "sql where cause" dynamic In-Reply-To: References: Message-ID: On Mon, May 2, 2011 at 5:48 PM, christian wrote: > Hi, > > from some radio buttons in a django app i concat ?string like that: > But have no idea how i get the or when there different values > for a specified p column (# is currently my intended splitter maybe i > can concat a better input?). > > input: "p2=1#p2=2#p1=3#p1=1#p1=5#pc=1#py=1" > > output: "p2 in ('1','2') and p1 in ('3','1','5') and pc in ('1') and > py in ('1')" Start by splitting the string and iterating: for el in input.split('#'): (obviously your variable won't want to be called 'input' but you knew that already) Then split on the = sign and add to a list or dictionary. Be wary of elements that don't have an equals sign in them. That looks like the querystring straight from the GET form, where you're using tickboxes. You could quite happily use '&' as your primary delimiter, if that's the case. Chris Angelico From anurag26 at kqinfotech.com Mon May 2 04:19:25 2011 From: anurag26 at kqinfotech.com (Anurag Agarwal) Date: Mon, 2 May 2011 01:19:25 -0700 (PDT) Subject: How to build an application in Django which will handle Multiple servers accross network References: <4eb9697f-6954-4cc0-b2c3-11f3746b049a@a19g2000prj.googlegroups.com> <1304071291.11695.1.camel@linux-yu4c.site> Message-ID: <4b79e1e0-2591-48f2-91f9-ca5c185bc61d@d26g2000prn.googlegroups.com> Hi All, Thanks for the resposes. I think I was not able to communicate my problem very well. Here I am not managing any network devices, what i am doing is getting some info from various servers on netowrk. I don't know how to explain what kind of info is needed, but for the time if you just assume that a driver for windows and linux is already written which has command line interface too which gets certain info about server. Now the information returned by this driver software from each server is to be shown at a common place. For this I am planning a web based application that can connect to each individual server and get the info and show it on UI. For this to happen i need some interface to which my web based application (to be developed in Django and Python) can connect to each server in network and call the driver methods on that server to get the info. I hope now i am clear with my thoughts. Please mail me back if still I am not clear. The solutions I got 1. Using WMI on windows but how it will work on Linux?. 2. Pyro which supports remote objects. 3. Open NMS - it is a java based open source project, we don't have any expertise in java... I want something that can be integrated with python and django. 4. ZenOSS - It is for managing some IP based devices on network.. I don't know how it will help me. Please give me some ideas on python even it needs some development effort. Regards, Anurag On Apr 29, 5:21?pm, Adam Tauno Williams wrote: > On Fri, 2011-04-29 at 13:24 +0200, Paul K?lle wrote: > > Am 29.04.2011 12:01, schrieb Adam Tauno Williams: > > >> 3. The web based application will be used internally in the network to > > >> moniter servers in that network only. > > > You mean like OpenNMS or ZenOSS? > > >> 4. Web based application will be a real time application with a > > >> Database. > > > Like OpenNMS or ZenOSS? > > How can they be realtime if they generate static images? > > All images are static regardless of how much they pretend not to be. > You can refresh as much as you like. ?But a graph shows a progression > over time so there is always an interval. > > > >> 5. Technology I am thingking for web based application is Django and > > >> Python as this web application can also be installed on Windows or > > >> Linux based OS. > > > If you want real-time monitoring you *must* build a service; a 'web app' > > > can *not* do that. > > Do you mean an agent? > > No, just use WMI over the wire. ?Agents are terrible, hard to develop, > unreliable, and everyone hates agents. ?The systems already provide you > access to the information you are talking about. > > > >> 6. Also please suggest which third party tool for chatrs and graphs I > > >> should use with Django (open source + paid) > > > ZenOSS and OpenNMS do graphs using RRD. > > I know this is the "standard" but IMO it's totally backward these days. > > Correlating or selecting/deselecting certain values is painful > >(you have to write a graph def) > > How is it painful? ?Of course you have to create a graph definition - in > your case you are creating a graph definition BY WRITING CODE! ?There > couldn't be a more painful way to just create a graph. > > Have you used recent versions of ZenOSS? ?Graph definitions can be > created right in the UI. > > > . With and modern JS libs like raphael > > there are better ways to do this. Just look at google analytics. > > I've seen it. ?I don't see how it is "better". ?It's a graph. > > > It looks like PCP (http://oss.sgi.com/projects/pcp/features.html) will > > gain a JSON interface shortly. That would be awesome because PCP is > > developed by real engineers and has a proper architecture and is NOT a > > CPU sucking monstrosity of PERL-line-noise + a few hacked-together PHP > > frontends. > > I have no idea where the "PERL-line-noise + a few hacked-together PHP > frontend" comment comes from. ?RRD is written in C. ?OpenNMS is Java and > ZenOSS is Python/ZOPE. > > And as for "CPU sucking monstrosity" that is what everyone says... until > they try to build a monitoring application... and thus create their own > "CPU sucking monstrosity". ?This is a case of > those-who-refuse-to-use-are-doomed-to-reinvent. From emakhmudow at gmail.com Mon May 2 04:21:45 2011 From: emakhmudow at gmail.com (anvar) Date: Mon, 2 May 2011 01:21:45 -0700 (PDT) Subject: HI Message-ID: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> Hello, Could you please help me with the modeling in Python the following problem: (e.g., g_t means g with index t) Min?_(i=1)^n??_(t=1)^l?[s_i (t)-min[s ?_i (t)??_t?exp(g_t ),C_i (t) ] ]^2 subject to s_i (t)=f_i (t)[S_i+f_(i-1) (t)[S_(i-1)+f_(i-2) (t)[S_(i-2)+?f_2 (t) [S_2+f_1 (t) S_1 ]?] ] ][1-f_(i+1) (t)] f_i (t)=F_i (t)-F_i (t-1) F_i (t)=(((1-e^(-(X_i (t)-X_i (0) )(p_i+q_i ) )))/(((q_i?p_i ) e^(- (X_i (t)-X_i (0) )(p_i+q_i ) )+1)), if t??_i and F_i (t)=0 if t0, ?i=1,2,?,n Where s ?_i (t)=p_i S_i +(q_i-p_i ) s_i (t-1)-(q_i/S_i ) [s_i (t-1) ]^2, S_i=?_i (t)M_i From emakhmudow at gmail.com Mon May 2 04:26:52 2011 From: emakhmudow at gmail.com (anvar) Date: Mon, 2 May 2011 01:26:52 -0700 (PDT) Subject: HI References: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> Message-ID: Here we need to estimate p_i, q_i, and ?. Thank you, > Min?_(i=1)^n??_(t=1)^l?[s_i (t)-min[s ?_i (t)??_t?exp(g_t ),C_i > (t) ] ]^2 > subject to > s_i (t)=f_i (t)[S_i+f_(i-1) (t)[S_(i-1)+f_(i-2) (t)[S_(i-2)+?f_2 (t) > [S_2+f_1 (t) S_1 ]?] ] ][1-f_(i+1) (t)] > f_i (t)=F_i (t)-F_i (t-1) > F_i (t)=(((1-e^(-(X_i (t)-X_i (0) )(p_i+q_i ) )))/(((q_i?p_i ) e^(- > (X_i (t)-X_i (0) )(p_i+q_i ) )+1)), if t??_i ? ? and F_i (t)=0 ?if > t X_i (t)=(t-?_i+1)+ln(?pr?_i (t)/?pr?_i (0))? > ?_t?0, ? ? ? g_t=const > 0 S_i>0, > ?i=1,2,?,n > Where > s ?_i (t)=p_i S_i ?+(q_i-p_i ) s_i (t-1)-(q_i/S_i ) [s_i (t-1) ]^2, > S_i=?_i (t)M_i From rustompmody at gmail.com Mon May 2 04:27:39 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 01:27:39 -0700 (PDT) Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 30, 12:18?pm, Steven D'Aprano wrote: > The number of calls is given by a recursive function with a similar form > as that of Fibonacci. As far as I know, it doesn't have a standard name, > but I'll call it R(n): > > R(n) = R(n-1) + R(n-2) + 1, where R(0) = R(1) = 1 Changing your definition slightly to the following: def r(n): if n==0 or n==1: return 0 else: return r(n-1) + r(n-2) + 1 This r counts the number of times the '+' is done in the original (naive) fib. We see it is the same as fib (off by 1) >>> [fib(n) for n in range(10)] [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] >>> [r(n) for n in range(10)] [0, 0, 1, 2, 4, 7, 12, 20, 33, 54] >>> So it does not need a new name :-) From grahn+nntp at snipabacken.se Mon May 2 04:31:37 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 2 May 2011 08:31:37 GMT Subject: Compile 32bit C-lib on 64 bit References: Message-ID: On Sun, 2011-05-01, Heged?s Ervin wrote: > Hello, > > this is not a "clear" Python question - I've wrote a module in C, > which uses a 3rd-party lib - it's a closed source, I just get the > .so, .a and a header file. > > Looks like it works on 32bit (on my desktop), but it must be run > on 64bit servers. > > > When I'm compiling it on 64bit, gcc says: > > /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when searching for -l3rdpartyCrypt A different angle: if you need to use closed-source, non-standard crypto, and the suppliers cannot even be bothered to compile it for the CPU architecture that has been standard for at least 6--7 years, start planning to replace it *now*. /Jorgen -- // Jorgen Grahn O o . From ulrich.eckhardt at dominolaser.com Mon May 2 04:34:11 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 02 May 2011 10:34:11 +0200 Subject: codec for UTF-8 with BOM Message-ID: Hi! I want to write a file starting with the BOM and using UTF-8, and stumbled across some problems: 1. I would have expected one of the codecs to be 'UTF-8 with BOM' or something like that, but I can't find the correct name. Also, I can't find a way to get a list of the supported codecs at all, which strikes me as odd. 2. I couldn't find a way to write the BOM either. Writing codecs.BOM doesn't work, as it is an already encoded byte string. Of course, I can write u'\ufeff', but I'd rather avoid such magic numbers in my code. 3. The docs mention encodings.utf_8_sig, available since 2.5, but I can't locate that thing there either. What's going on here? What would you do? Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From duncan.booth at invalid.invalid Mon May 2 04:43:47 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 2 May 2011 08:43:47 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Dennis Lee Bieber wrote: > As I recall from my programming language design class (only and > intro, it was so small we met in a meeting room rather than classroom), > ALGOL was described as "call by name"; It is true that Algol had 'call by name', but (at least the Algol-W that I learned) also supported 'call by value' and 'call by reference'. The danger of course was that call by name was the default mechanism so you could end up using it accidentally. I remember we had one class where we had to work out (by hand) the output of a program which used call by name to alias I and A[I] in some recursive calls. Not nice. Fortunately even at that time it was mostly being taught as an oddity; real programming was of course done in Algol 68C or BCPL. -- Duncan Booth http://kupuguy.blogspot.com From steve+comp.lang.python at pearwood.info Mon May 2 04:56:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2011 08:56:57 GMT Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 May 2011 01:27:39 -0700, rusi wrote: > On Apr 30, 12:18?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > >> The number of calls is given by a recursive function with a similar >> form as that of Fibonacci. As far as I know, it doesn't have a standard >> name, but I'll call it R(n): >> >> R(n) = R(n-1) + R(n-2) + 1, where R(0) = R(1) = 1 > > Changing your definition slightly to the following: > > def r(n): > if n==0 or n==1: return 0 > else: return r(n-1) + r(n-2) + 1 Except that's not the same as my "R(n)". The base cases should be 1, not 0. That makes rather a big difference to the value: by n = 35, you have R(35) = 29860703 fib(35) = 9227465 or nearly 2.25 times greater. And the difference just keeps getting bigger... > We see it is the same as fib (off by 1) [...] > So it does not need a new name :-) I see your smiley, but there are a number of similar series as Fibonacci, with the same recurrence but different starting values, or similar but slightly different recurrences. E.g. Lucas, primefree, Pell, Padovan and Perrin numbers. (The fact that most of those start with P is almost certainly a coincidence.) -- Steven From rosuav at gmail.com Mon May 2 05:03:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 19:03:40 +1000 Subject: Fibonacci series recursion error In-Reply-To: <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 2, 2011 at 6:56 PM, Steven D'Aprano wrote: > (The fact that most of those start with P is almost certainly a > coincidence.) > There's definitely something attractive about that letter. Lots of programming languages' names start with P. I smell a conspiracy. The word "programming" has been secretly attracting related words to its corner of the alphabet... and the government's *covering it up* and pretending there's nothing happening! Chris Angelico From jacek2v at gmail.com Mon May 2 05:09:38 2011 From: jacek2v at gmail.com (jacek2v) Date: Mon, 2 May 2011 02:09:38 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <3a93d484-ca0a-41d9-afdb-509cfdcc918b@e21g2000yqe.googlegroups.com> On May 2, 9:48?am, Algis Kabaila wrote: > On Monday 02 May 2011 17:19:57 rusi wrote: > > > On May 2, 12:08 pm, Algis Kabaila > wrote: > > > Actually, Bazaar is more convenient than rcs for a single > > > user, as the repository can be the working directory (with > > > a "hidden" .bzr directory that stores diffs). > > > Dont exactly understand... > > Is it that you want it specifically hidden? > > Otherwise rcs will look inside an RCS directory just as bzr > > will with .bzr git will with .git and so on. > > Sorry for not being clear - "ls" will not show directories that > start with "." - in that sense these directories are "hidden". ? > They are not really really hidden, as "ls ?-l" will show them. ? > They simply are not in the way and keep the progressive versions > of the program (in form of diffs). "ls -l will not show directories that start with ".". "ls -a" will. Regards Jacek From alec.taylor6 at gmail.com Mon May 2 05:33:30 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 2 May 2011 19:33:30 +1000 Subject: Deditor In-Reply-To: References: <74a2f743-aa0a-4beb-8c62-3e32b6ac7489@k22g2000yqh.googlegroups.com> <75a7cd73-50c9-4dc0-a88d-68051f1e3795@k22g2000yqh.googlegroups.com> <761080e3-bbda-4c3b-a38b-f9e0b1e4dcad@a10g2000vbz.googlegroups.com> <2cc05cc3-2c8a-42ba-bb7b-348206546378@k11g2000yqc.googlegroups.com> <35348319-4042-4929-a81c-2e1cec7de3f3@b19g2000yqg.googlegroups.com> <7d8e78d2-8a90-431e-8a5d-d9f81d393e40@j26g2000yqa.googlegroups.com> Message-ID: Yes On Mon, May 2, 2011 at 2:12 AM, Kruptein wrote: > On 1 mei, 17:50, Alec Taylor wrote: >> Traceback (most recent call last): >> ?File "O:\deditor\deditor\deditor.py", line 7, in > e> >> ? ?import wx, os, datetime, sys, ConfigParser, wx.aui, wx.lib.scrolledpanel >> ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4 >> 5, in >> ? ?from wx._core import * >> ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i >> n >> ? ?import _core_ >> ImportError: DLL load failed: %1 is not a valid Win32 application. >> >> >> >> On Mon, May 2, 2011 at 12:33 AM, Kruptein wrote: >> > On 1 mei, 10:59, Alec Taylor wrote: >> >> Maybe I'm missing something, but I downloaded the zip file and ran >> >> each .py and .pyc file in turn, but none brought up the nicededitor >> >> GUI I've seen screenshots of... >> >> >> On the other subject, did you have a preference to what installer I >> >> should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi) >> >> > not a msi, for the rest it doesn't matter :), ?on my windows if you >> > rundeditor.py ? it should launch however you need to have the >> > wxpython-2.8 package installed, ? what happens if you rundeditor.py >> > from console? >> > -- >> >http://mail.python.org/mailman/listinfo/python-list > > that looks like you have installed the wxpython module wrongly. ?Have > you downloaded the version that matches your python version? > -- > http://mail.python.org/mailman/listinfo/python-list > From hg at schaathun.net Mon May 2 05:41:48 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 2 May 2011 10:41:48 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe0440$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02 May 2011 01:09:21 GMT, Steven D'Aprano wrote: : Ah, I see where you're coming from now! You think I'm arguing *against* : the use of recursion. Not at all. Earlier in this thread, I said: Fair enough. Somebody said something about recursion mainly being a beginner's error. I don't think it was you, but I felt that your argument in context mainly served to reinforce such a view, whether intended or not. : "Consequently, the naive recursive function is ridiculously slow and : memory-hungry. : : This seems to have give rise to a myth that recursion should be avoided. : What needs to be avoided is *badly thought out* recursion." Then we agree. And badly thought-out iteration is as bad as badly thought-out recursion. : To be honest, I don't know what Python does with local variables. But I : *guess* it uses a constant-sized record which points to the locals, : because that's how I'd do it :) Maybe, but would it be able to treat specially C API functions with a large chunk of stack memory used for local variables? : Given a choice between a complicated iterative algorithm and a simple : recursive version, there's no prima facie reason to expect the recursive : version to *necessarily* be slower than iteration in Python *merely* : because it uses recursion. As always, if speed is an issue, profile and : identify the bottlenecks before deciding how to fix them. Then we are on the same page. And it is becoming increasingly clear how bizarre this discussion is in a python context. The overhead which may be caused by recursion in hardware is only one of many sources of overhead which one accepts when opting to use python in order to gain other benefits. -- :-- Hans Georg From clp2 at rebertia.com Mon May 2 05:47:45 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 May 2011 02:47:45 -0700 Subject: codec for UTF-8 with BOM In-Reply-To: References: Message-ID: On Mon, May 2, 2011 at 1:34 AM, Ulrich Eckhardt wrote: > Hi! > > I want to write a file starting with the BOM and using UTF-8, and stumbled > across some problems: > > 1. I would have expected one of the codecs to be 'UTF-8 with BOM' or > something like that, but I can't find the correct name. Also, I can't find a > way to get a list of the supported codecs at all, which strikes me as odd. If nothing else, there's http://docs.python.org/library/codecs.html#standard-encodings The correct name, as you found below and as is corroborated by the webpage, seems to be "utf_8_sig": >>> u"FO?bar".encode('utf_8_sig') '\xef\xbb\xbfFO\xc3\xb8bar' This could definitely be documented more straightforwardly. > 3. The docs mention encodings.utf_8_sig, available since 2.5, but I can't > locate that thing there either. What's going on here? Works for me?: Python 2.6.6 (r266:84292, Jan 12 2011, 13:35:00) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from encodings import utf_8_sig >>> Cheers, Chris -- http://rebertia.com From hg at schaathun.net Mon May 2 05:53:52 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 2 May 2011 10:53:52 +0100 Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02 May 2011 08:56:57 GMT, Steven D'Aprano wrote: : I see your smiley, but there are a number of similar series as Fibonacci, : with the same recurrence but different starting values, or similar but : slightly different recurrences. E.g. Lucas, primefree, Pell, Padovan and : Perrin numbers. Well, Fibonacci isn't one unique sequence. Any sequence satisfying f(n) = f(n-1) + f(n-2) is /a/ Fibonacci sequence. Regardless of starting values. At least according to some authors. Ian Andersen (A First Course in Combinatorial Mathematics) prefer the sequence 1,2,3,5 ... Cormen, Leiserson, Rivest (Introduction to Algorithms) prefer 0,1,1,2, ... (although they also start the indexing at 0). Penguin, Dict. of Mathematics prefer 1,1,2,3,5 but they also suggest 0,1,1,2,3, ... In short, don't assume that a person talking about Fibonacci numbers assume the same base cases as you do. -- :-- Hans Georg From sjmachin at lexicon.net Mon May 2 06:13:44 2011 From: sjmachin at lexicon.net (John Machin) Date: Mon, 2 May 2011 03:13:44 -0700 (PDT) Subject: codec for UTF-8 with BOM In-Reply-To: Message-ID: On Monday, 2 May 2011 19:47:45 UTC+10, Chris Rebert wrote: > On Mon, May 2, 2011 at 1:34 AM, Ulrich Eckhardt > wrote: > The correct name, as you found below and as is corroborated by the > webpage, seems to be "utf_8_sig": > >>> u"FO?bar".encode('utf_8_sig') > '\xef\xbb\xbfFO\xc3\xb8bar' To complete the picture, decoding swallows the BOM: >>> '\xef\xbb\xbfFO\xc3\xb8bar'.decode('utf_8_sig') u'FO\xf8bar' From ozric at web.de Mon May 2 06:13:44 2011 From: ozric at web.de (christian) Date: Mon, 2 May 2011 03:13:44 -0700 (PDT) Subject: build the "sql where cause" dynamic References: Message-ID: <707c9072-6bb5-47d7-8a07-14a4175a26cf@u15g2000vby.googlegroups.com> On 2 Mai, 10:13, Chris Angelico wrote: > On Mon, May 2, 2011 at 5:48 PM, christian wrote: > > Hi, > > > from some radio buttons in a django app i concat ?string like that: > > But have no idea how i get the or when there different values > > for a specified p column (# is currently my intended splitter maybe i > > can concat a better input?). > > > input: "p2=1#p2=2#p1=3#p1=1#p1=5#pc=1#py=1" > > > output: "p2 in ('1','2') and p1 in ('3','1','5') and pc in ('1') and > > py in ('1')" > > Start by splitting the string and iterating: > for el in input.split('#'): > > (obviously your variable won't want to be called 'input' but you knew > that already) > > Then split on the = sign and add to a list or dictionary. Be wary of > elements that don't have an equals sign in them. > > That looks like the querystring straight from the GET form, where > you're using tickboxes. You could quite happily use '&' as your > primary delimiter, if that's the case. > > Chris Angelico Many Thanks Christian From sjmachin at lexicon.net Mon May 2 06:13:44 2011 From: sjmachin at lexicon.net (John Machin) Date: Mon, 2 May 2011 03:13:44 -0700 (PDT) Subject: codec for UTF-8 with BOM In-Reply-To: Message-ID: On Monday, 2 May 2011 19:47:45 UTC+10, Chris Rebert wrote: > On Mon, May 2, 2011 at 1:34 AM, Ulrich Eckhardt > wrote: > The correct name, as you found below and as is corroborated by the > webpage, seems to be "utf_8_sig": > >>> u"FO?bar".encode('utf_8_sig') > '\xef\xbb\xbfFO\xc3\xb8bar' To complete the picture, decoding swallows the BOM: >>> '\xef\xbb\xbfFO\xc3\xb8bar'.decode('utf_8_sig') u'FO\xf8bar' From ulrich.eckhardt at dominolaser.com Mon May 2 06:30:46 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 02 May 2011 12:30:46 +0200 Subject: codec for UTF-8 with BOM References: Message-ID: Chris Rebert wrote: >> 3. The docs mention encodings.utf_8_sig, available since 2.5, but I can't >> locate that thing there either. What's going on here? > > Works for me?: > Python 2.6.6 (r266:84292, Jan 12 2011, 13:35:00) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> from encodings import utf_8_sig >>>> This works for me, too. What I tried and what failed was import encodings encodings.utf_8_sig which raises an AttributeError or dir(encodings), which doesn't show the according element. If I do it your way, the encoding then shows up in the content of the module. Apart from the encoding issue, I don't understand this behaviour. Is the module behaving badly or are my expectations simply flawed? Thanks! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From akabaila at pcug.org.au Mon May 2 06:38:48 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Mon, 2 May 2011 20:38:48 +1000 Subject: Development tools and practices for Pythonistas In-Reply-To: <3a93d484-ca0a-41d9-afdb-509cfdcc918b@e21g2000yqe.googlegroups.com> References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <3a93d484-ca0a-41d9-afdb-509cfdcc918b@e21g2000yqe.googlegroups.com> Message-ID: <201105022038.48171.akabaila@pcug.org.au> On Monday 02 May 2011 19:09:38 jacek2v wrote: > On May 2, 9:48 am, Algis Kabaila wrote: > > On Monday 02 May 2011 17:19:57 rusi wrote: > > > On May 2, 12:08 pm, Algis Kabaila > > > > wrote: > > > > Actually, Bazaar is more convenient than rcs for a > > > > single user, as the repository can be the working > > > > directory (with a "hidden" .bzr directory that stores > > > > diffs). > > > > > > Dont exactly understand... > > > Is it that you want it specifically hidden? > > > Otherwise rcs will look inside an RCS directory just as > > > bzr will with .bzr git will with .git and so on. > > > > Sorry for not being clear - "ls" will not show directories > > that start with "." - in that sense these directories are > > "hidden". They are not really really hidden, as "ls -l" > > will show them. They simply are not in the way and keep > > the progressive versions of the program (in form of > > diffs). > > "ls -l will not show directories that start with ".". > "ls -a" will. > > Regards > Jacek Thanks - you are right - pardon my absent mindedness. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf From ulrich.eckhardt at dominolaser.com Mon May 2 06:38:55 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 02 May 2011 12:38:55 +0200 Subject: HI References: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> Message-ID: <81e298-pd8.ln1@satorlaser.homedns.org> anvar wrote: > Could you please help me with the modeling in Python the following > problem: (e.g., g_t means g with index t) Typically, you would use either a list or a dict to simulate something like that: # list g = [1, 2, 4, 8, 16] print g[3] # dictionary h = {} h[0] = 1 h[1] = 2 h[2] = 4 h[3] = 8 h[4] = 16 print h[3] The difference is that a list needs elements starting at index 0 and without any gaps, while a dictionary can contain "holes". Please refer to any beginners' Python tutorial for info on these types. Concerning the other formulas you posted, those ended up as completely illegible here for the complete lack of formatting. Explaining things in plain English along with the mathematics would be a good idea, IMHO. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From rustompmody at gmail.com Mon May 2 06:40:31 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 03:40:31 -0700 (PDT) Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 2, 2:53?pm, Hans Georg Schaathun wrote: > On 02 May 2011 08:56:57 GMT, Steven D'Aprano? wrote: > > : ?I see your smiley, but there are a number of similar series as Fibonacci, > : ?with the same recurrence but different starting values, or similar but > : ?slightly different recurrences. E.g. Lucas, primefree, Pell, Padovan and > : ?Perrin numbers. > > Well, Fibonacci isn't one unique sequence. ?Any sequence satisfying > f(n) = f(n-1) + f(n-2) is /a/ Fibonacci sequence. ?Regardless of > starting values. ?At least according to some authors. And they all will, when expressed in closed form, be of the form f(n) = phi^n + something of a smaller order where phi = (1 + sqrt(5))/2 Since phi > 1 they are exponential, ignoring lower order terms. From __peter__ at web.de Mon May 2 07:42:55 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 May 2011 13:42:55 +0200 Subject: codec for UTF-8 with BOM References: Message-ID: Ulrich Eckhardt wrote: > Chris Rebert wrote: >>> 3. The docs mention encodings.utf_8_sig, available since 2.5, but I >>> can't locate that thing there either. What's going on here? >> >> Works for me?: >> Python 2.6.6 (r266:84292, Jan 12 2011, 13:35:00) >> [GCC 4.2.1 (Apple Inc. build 5664)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> from encodings import utf_8_sig >>>>> > > This works for me, too. What I tried and what failed was > > import encodings > encodings.utf_8_sig > > which raises an AttributeError or dir(encodings), which doesn't show the > according element. If I do it your way, the encoding then shows up in the > content of the module. > > Apart from the encoding issue, I don't understand this behaviour. Is the > module behaving badly or are my expectations simply flawed? This is standard python package behaviour: >>> import logging >>> logging.handlers Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'handlers' >>> import logging.handlers >>> logging.handlers You wouldn't see the AttributeError only if encodings/__init__.py contained a line from . import utf_8_sig or similar. The most notable package that acts this way is probably os which eagerly imports a suitable path module depending on the platform. As you cannot foresee which encodings are actually needed in a script it makes sense to omit a just-in-case import. From davea at ieee.org Mon May 2 08:50:39 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 02 May 2011 08:50:39 -0400 Subject: Fibonacci series recursion error (slightly OT) In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> <6fs198-8lf.ln1@svn.schaathun.net> Message-ID: <4DBEA89F.4050302@ieee.org> On 01/-10/-28163 02:59 PM, Chris Angelico wrote: > On Mon, May 2, 2011 at 3:36 PM, Hans Georg Schaathun wrote: >> On Mon, 2 May 2011 06:49:41 +1000, Chris Angelico >> wrote: >> : Sure. Serialize this Python object in a way that can be given to, say, PHP: >> : foo=asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo] >> >> Wouldn't cyclic references give infinite recursion? And remain >> infinitive if you recode it iteratively? > > Well, I don't know of a decent non-recursive way to process a > recursive structure. Incidentally, this example is almost directly > from some working code of ours; I have a C function that recurses over > a Python dictionary and aborts as soon as it's found "too much" data > (for a fairly arbitrary definition of "too much", but one that's > deliberately designed to prevent infinite recursion). > > > Chris Angelico > When iterating over a repeatable, potentially infinite sequence of distinguishable values, you can safely detect infinitude ;-) (cycles) with a linear overhead (rather than n-squared). Given a sequence, create two iterators for it. Start them both at the same point, but iterate the second one twice for every time you iterate the first one. If the two ever get the same value, you have a cycle. In the case of Python objects, you probably want to use an 'is' comparison, rather than comparing id() for equal. But the concept works, and easily. DaveA From jeanmichel at sequans.com Mon May 2 09:06:48 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 02 May 2011 15:06:48 +0200 Subject: HI In-Reply-To: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> References: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> Message-ID: <4DBEAC68.5060101@sequans.com> anvar wrote: > Hello, > > Could you please help me with the modeling in Python the following > problem: (e.g., g_t means g with index t) > > Min?_(i=1)^n??_(t=1)^l?[s_i (t)-min[s ?_i (t)??_t?exp(g_t ),C_i > (t) ] ]^2 > subject to > s_i (t)=f_i (t)[S_i+f_(i-1) (t)[S_(i-1)+f_(i-2) (t)[S_(i-2)+?f_2 (t) > [S_2+f_1 (t) S_1 ]?] ] ][1-f_(i+1) (t)] > f_i (t)=F_i (t)-F_i (t-1) > F_i (t)=(((1-e^(-(X_i (t)-X_i (0) )(p_i+q_i ) )))/(((q_i?p_i ) e^(- > (X_i (t)-X_i (0) )(p_i+q_i ) )+1)), if t??_i and F_i (t)=0 if > t X_i (t)=(t-?_i+1)+ln(?pr?_i (t)/?pr?_i (0))? > ?_t?0, g_t=const > 0 S_i>0, > ?i=1,2,?,n > Where > s ?_i (t)=p_i S_i +(q_i-p_i ) s_i (t-1)-(q_i/S_i ) [s_i (t-1) ]^2, > S_i=?_i (t)M_i > Hi, Nice joke. JM From invalid at invalid.invalid Mon May 2 09:12:45 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 2 May 2011 13:12:45 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-02, Jorgen Grahn wrote: > On Sun, 2011-05-01, Terry Reedy wrote: >> On 5/1/2011 4:45 AM, Steven D'Aprano wrote: > ... >>> What other languages use the same, or mostly similar, data model as >>> Python? >> >> Natural languages. That is why I think it is better to think of Python >> as an algorithm language or information-object manipulation language >> rather than as just a linear-memory machine language.A linear memory >> with bytes addressed from 0 to max-int or max-long is an explicit part >> of the definition of assembly languages and C. It is no part of the >> definition of Python. > > It's not part of the definition of C either -- C supports segmented > memory (pre-386 Intel) and separate code/data address spaces. (Even if > most C users tend not to think of it that way.) Indeed. All the C compilers I used for many years (on both PDP-11 and 80286 under Unix) assumed a segmented memory space with separate data and text addresses spaces. More recently, the same can be said for AVR and many other Harvard architecture machines. The "linear memory with bytes addressed from 0 to max-int or max-long" thing is merely an implicit assumption made by bad C programmers. -- Grant From hg at schaathun.net Mon May 2 09:14:20 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 2 May 2011 14:14:20 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 01 May 2011 18:24:30 -0400, Terry Reedy wrote: : This does not make linear recursion 'bad', just impractical for general : use on finite-memory machines. While I consider it very useful for : learning, it is unnecessary because it is easy to write an iterative : version. So called tail-recursion optimization saves memory by REMOVING : RECURSION and replacing it with iteration. : (...) : Python does not do this automatically because 1) it can be a semantic : change under some circumstances; 2) one who wants the iterative version : can just as easily write it directly; That's the silliest argument I ever heard. The programmer should write the code the way he and application domain experts think, i.e. very often recursively. The compiler should generate code the way the CPU thinks (most optimally), i.e. iteratively. Of course, I am not saying that one should always model problems recursively, and thus also not that one should implement them recursively. Just that when a model is agreed recursively between the stakeholders, one should get a compiler to do the optimisation, not a programmer. I always thought of python as a step forward, in the way it allows direct expression of so many alternative modes of thinking (imperative, functional, recursion, iterators, etc). If what you say is python philosophy, it is a step backward in requiring the programmer to think more about low-level technical matters which even C has managed to leave for the compiler. : and 3) Python has a better way to : process collections that removes essentially all the boilerplate in the : recursive-call and while-loop versions: -- :-- Hans Georg From emakhmudow at gmail.com Mon May 2 09:42:14 2011 From: emakhmudow at gmail.com (anvar) Date: Mon, 2 May 2011 06:42:14 -0700 (PDT) Subject: HI References: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> Message-ID: Dear Ulrich Eckhardt and Jean-Michel Pichavant! First of all thank you for your attention. I'have never expected to receive response. Actually, I am doing my internship in Marketing Division in small company., I got this assignment yesterday morning. My boss wants perfect technology diffusion based forecasting model. I found the required model, modified it..but cannot solve it (university friend suggested Python because it had special tools for optimization). I will appreciate if you help me to find right tools and give some more advises. Thank you for your precious time. As to problem, I should use nonlinear least-square estimation methodology (to estimate p_i, q_i, and ? parameters) where the objective of the estimation procedure is minimization of the sum of squared error. Here in problem: F_i (t) the cumulative density function at time t for technology generation i f_i (t) the probability density function at time t for technology generation i p_i the proportion of mass media communication for generation i q_i the proportion of word of mouth for generation i ?_i (t) the market share at time t for generation i (data exists) M_i total market potential for generation i, (data exists) S_i total sales potential for generation i, S_i=?_i (t)M_i ?_i the introduction time for generation i, ?_i?1 (data exists) s_i (t) the actual sales of products at time t for generation i (data exists) s ?_i (t) the estimated sales of products at time t for generation i X_i (t) the cumulative market effects ? the effectiveness of the price ?pr?_i (t) the price at time t for generation i (data exists) ?_t the seasonal factor at time t (data exists) g_t the growth rate at time t (data exists) n the number of generations (data exists) l the number of periods (data exists) C_i (t) the capacity restriction regarding the product at time t for generation i (data exists) From efrinut at gmail.com Mon May 2 11:23:21 2011 From: efrinut at gmail.com (Petey) Date: Mon, 2 May 2011 08:23:21 -0700 (PDT) Subject: Development software Message-ID: Hi! I'm new to programming. I started with php earlier and I dropped it for Python. I use Eclipse+PyDev for python, html and css. Which programmes should I start using because they might be useful in the future? Which functions of eclipse are useful but unused/unnoticed by beginners. What do you use and why :) ? From alexander at lyabah.com Mon May 2 12:23:40 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Mon, 2 May 2011 09:23:40 -0700 (PDT) Subject: Python competitions and learnings References: <2N1vp.21945$vC5.16209@newsfe01.iad> <5e4ec696-4d50-4b88-9fa5-229f293c0639@q21g2000vbs.googlegroups.com> Message-ID: <777e558e-2e84-4f6e-ac3f-e3e53346a467@x10g2000vbn.googlegroups.com> On May 1, 7:22?pm, Alexander Lyabah wrote: > On May 1, 3:26?am, harrismh777 wrote: > > > > > > > > > > > Alexander Lyabah wrote: > > > What do you think about it? > > > > I'm also have a not a very good English, so I need help with it too, > > > Alexander, your site is very interesting. I spent some time this > > afternoon appreciating your work. Nice job. > > > Be encouraged, your English is much better than my Russian! I also > > looked over the orphanage site and I appreciate how much you are doing > > there in Ukraine for the children. Keep up the good work. > > > I too am a little disappointed that Python3 is not being used. I want to > > encourage you to work in that direction as well. I may have some time to > > volunteer to checkio.org; for help with the English, and maybe with some > > help as a tester. We'll see... I have a lot of my own fish to fry here, > > as we say in America. > > > Blessings on your work, friend. > > > m harris > > I spend a lot of time to make a almost full support of python 2.7 from > sandbox. > > If somebody help me this sandboxed python 3.* i will add support of it > on checkio.org with big pleasure. Notice about the python 2.7 on main page was added. thanks for advice From steve+comp.lang.python at pearwood.info Mon May 2 12:24:07 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2011 16:24:07 GMT Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dbedaa6$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 May 2011 10:53:52 +0100, Hans Georg Schaathun wrote: > On 02 May 2011 08:56:57 GMT, Steven D'Aprano > wrote: > : I see your smiley, but there are a number of similar series as > Fibonacci, : with the same recurrence but different starting values, or > similar but : slightly different recurrences. E.g. Lucas, primefree, > Pell, Padovan and : Perrin numbers. > > Well, Fibonacci isn't one unique sequence. Any sequence satisfying f(n) > = f(n-1) + f(n-2) is /a/ Fibonacci sequence. Regardless of starting > values. At least according to some authors. According to the references I have, there is one and only one Fibonacci sequence, the usual one invented by Fibonacci to talk about rabbits. (Actually, we should talk about Fibonacci *numbers*, rather than sequence.) Wolfram Mathworld is typical, defining *the* Fibonacci numbers as those with starting conditions f(1)=1, f(2)=1 (or f(0)=0 if you prefer). http://mathworld.wolfram.com/FibonacciNumber.html The Collins Dictionary of Mathematics agrees with Mathworld. The Lucas numbers (related to, but not the same as, the Lucas sequence) obey the same recurrence as the Fibonacci numbers, but with a different set of starting values. So there is certainly precedent in the mathematical literature for giving different names to the same recurrence with different starting values. In any case, whatever you call them, what I call R(n) is not one, as the recurrence is different: R(n) = R(n-1) + R(n-2) + 1 > Penguin, Dict. of Mathematics prefer 1,1,2,3,5 but they also suggest > 0,1,1,2,3, ... This depends on whether you start counting from n=0 or n=1. Even the sequence you quote, from Anderson: 1,2,3,5... is just the usual Fibonacci numbers starting at n=2 instead of 1 or 0. (No matter how confusing something is, there's always at least one person who will try to make it *more* confusing.) > In short, don't assume that a person talking about Fibonacci numbers > assume the same base cases as you do. As far as I'm concerned, there are only two definitions of Fibonacci numbers that have widespread agreement in the mathematical community: 0,1,1,2,3 ... (starting from n=0) 1,1,2,3,5 ... (starting from n=1) Any other definition is rather, shall we say, idiosyncratic. -- Steven From alexander at lyabah.com Mon May 2 12:24:48 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Mon, 2 May 2011 09:24:48 -0700 (PDT) Subject: Python competitions and learnings References: <2N1vp.21945$vC5.16209@newsfe01.iad> <5e4ec696-4d50-4b88-9fa5-229f293c0639@q21g2000vbs.googlegroups.com> Message-ID: On May 2, 1:33?am, Terry Reedy wrote: > On 5/1/2011 12:49 PM, Alexander Lyabah wrote: > > > And what do you think about Score Games and competitions? > > The rules of the first score game were not clear to me. I could not > figure out how to play it interactively myself so I could see how it > actually played. > > -- > Terry Jan Reedy I will add a more detail information how competitions and score games goes. From steve+comp.lang.python at pearwood.info Mon May 2 12:41:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2011 16:41:37 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 May 2011 14:14:20 +0100, Hans Georg Schaathun wrote: > On Sun, 01 May 2011 18:24:30 -0400, Terry Reedy > wrote: > : This does not make linear recursion 'bad', just impractical for > general : use on finite-memory machines. While I consider it very > useful for : learning, it is unnecessary because it is easy to write an > iterative : version. So called tail-recursion optimization saves memory > by REMOVING : RECURSION and replacing it with iteration. : (...) > : Python does not do this automatically because 1) it can be a semantic > : change under some circumstances; 2) one who wants the iterative > version : can just as easily write it directly; > > That's the silliest argument I ever heard. You must be new to the Internet then :) > The programmer should write > the code the way he and application domain experts think, i.e. very > often recursively. The compiler should generate code the way the CPU > thinks (most optimally), i.e. iteratively. Perhaps so, but there can be a huge gulf between what "should" happen and what does happen. The CPython implementation is deliberately a naive, not- very clever compiler. (PyPy seems to be the implementation aiming at cutting-edge cleverness.) Even such simple optimizations as constant folding are very controversial among the CPython developers. They have good reasons for their caution: optimizing compilers are renowned for breaking code, especially floating point code, and there have been cases in Python's history where optimizations have broken existing code and needed to be backed out. The problem is, once you include side-effects, recursion and iteration are *not* identical. Specifically, the opposition to tail-recursion optimization in Python is that it plays havoc with the tracebacks you get in the event of an exception. The argument goes: * Debugging is harder than writing code in the first place, so it is more important to simplify debugging, even at the cost of making some code slightly harder to write. * Recursion doesn't just mean simple recursion where a function calls itself, but mutually recursive functions. You could have (say) five functions that mutually called each other recursively, and in the event of a traceback you need to see the exact calling chain, but that's precisely the information that is blown away by tail-recursion optimization. * Tail-recursion is only a special case of recursion, and not a very common special case either, so it is hardly worth the extra complexity of the compiler to treat it specially. Regardless of whether you agree with the arguments or not, they're hardly "silly". -- Steven From myeates at jpl.nasa.gov Mon May 2 12:45:26 2011 From: myeates at jpl.nasa.gov (Mathew) Date: Mon, 2 May 2011 09:45:26 -0700 Subject: setup.py rebuilds EVERYTHING on windows? Message-ID: Hi I'm trying to build an extension (spice-0.12) on windows. Whenever I change a single file, everything gets rebuilt. ?? Python2.7.1 Windows XP Visual Studio 9 setuptools 0.6c11 -Mathew From kmshafique at yahoo.com Mon May 2 13:21:31 2011 From: kmshafique at yahoo.com (Shafique, M. (UNU-MERIT)) Date: Mon, 2 May 2011 10:21:31 -0700 (PDT) Subject: Running a script with command line arguments Message-ID: <314543.11533.qm@web65402.mail.ac4.yahoo.com> Hi, I'm new to python and trying to run a borrowed script. The error I get suggests that I need to give a proper command to run it. The input file is "c26_1plus.csv" and the intended output file is "c26_1plus_backbone.csv". Can anyone help? BR, Shafique Error log: C:\Users\Shafique>extract_backbone.py c:\python26\c26_1plus.csv c:\python26\c26_1plus_backbone Traceback (most recent call last): File "C:\Python26\extract_backbone.py", line 31, in alpha = float(sys.argv[3]) IndexError: list index out of range Excerpts from code: #!/usr/bin/env python import sys, os import networkx def extract_backbone(G, weights, alpha): blablabla... if __name__ == '__main__': if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]: usage = """python %s input_file output_file backbone_alpha [file delimiter]""" sys.exit(usage) in_file = sys.argv[1] ot_file = sys.argv[2] alpha = float(sys.argv[3]) try: delimiter = sys.argv[4] except: delimiter = "\t" ...blablabla... # save the new edgelist: f = open(ot_file, 'w') for ni,nj in G_backbone.edges(): f.write("%s%s%s\n" % (ni,delimiter,nj) ) f.close() -------------- next part -------------- An HTML attachment was scrubbed... URL: From ms419 at freezone.co.uk Mon May 2 13:23:15 2011 From: ms419 at freezone.co.uk (Jack Bates) Date: Mon, 02 May 2011 10:23:15 -0700 Subject: "raise (type, value, traceback)" and "raise type, value, traceback" Message-ID: <1304356995.4335.2.camel@selene> Hi, anyone know why these two statements aren't equivalent? raise (type, value, traceback) raise type, value, traceback From ameyer2 at yahoo.com Mon May 2 13:30:02 2011 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 02 May 2011 13:30:02 -0400 Subject: Composition instead of inheritance In-Reply-To: References: Message-ID: <4DBEEA1A.6000004@yahoo.com> On 4/28/2011 1:15 PM, Ethan Furman wrote: > For anybody interested in composition instead of multiple inheritance, I > have posted this recipe on ActiveState (for python 2.6/7, not 3.x): > > http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/ > > > Comments welcome! > > ~Ethan~ That looks pretty clever. I tried adding this method to Spam: def test_eggs_02(self): print('testing eggs_02 from spam') and it did just what we wanted. I'm going to have to study this one. Thanks. Alan From python at rcn.com Mon May 2 13:33:31 2011 From: python at rcn.com (Raymond Hettinger) Date: Mon, 2 May 2011 10:33:31 -0700 (PDT) Subject: Coolest Python recipe of all time Message-ID: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> I think it is time to give some visibility to some of the instructive and very cool recipes in ActiveState's python cookbook. My vote for the coolest recipe of all time is: http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ What are your favorites? Raymond twitter: @raymondh From stefan_ml at behnel.de Mon May 2 13:37:19 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 02 May 2011 19:37:19 +0200 Subject: setup.py rebuilds EVERYTHING on windows? In-Reply-To: References: Message-ID: Mathew, 02.05.2011 18:45: > I'm trying to build an extension (spice-0.12) on windows. Whenever I change > a single file, everything gets rebuilt. Did you report this to the authors? I suppose there's a project mailing list? Stefan From news at schwertberger.de Mon May 2 13:40:04 2011 From: news at schwertberger.de (Dietmar Schwertberger) Date: Mon, 02 May 2011 19:40:04 +0200 Subject: Development tools and practices for Pythonistas In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> Message-ID: Am 02.05.2011 01:33, schrieb David Boddie: > After noting the warnings it contains, see the following page for a > description of the Python API for Mercurial: > > http://mercurial.selenic.com/wiki/MercurialApi Ah, yes, no need to use os.sytem(), but all in all not much difference from doing so (and usage of CLI is recommended instead of using the API). I had a look at this page in 2009 and came to the conclusion that it's no good idea to use Mercurial as library. Seems that this still holds true. > Git also has a Python API, which is fairly reasonable to use, though a bit > different to the Mercurial one: > > http://www.samba.org/~jelmer/dulwich/ That looks more promising to me. I think I will try this and Bazaar to find which fits my needs better. Regards, Dietmar From python at mrabarnett.plus.com Mon May 2 14:26:34 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 May 2011 19:26:34 +0100 Subject: Running a script with command line arguments In-Reply-To: <314543.11533.qm@web65402.mail.ac4.yahoo.com> References: <314543.11533.qm@web65402.mail.ac4.yahoo.com> Message-ID: <4DBEF75A.2000801@mrabarnett.plus.com> > Hi, > I'm new to python and trying to run a borrowed script. The error I > get suggests that I need to give a proper command to run it. The > input file is "c26_1plus.csv" and the intended output file is > "c26_1plus_backbone.csv". > > Can anyone help? > The usage string in the script says that the required arguments are: input_file output_file backbone_alpha [file delimiter] You're providing "input_file" and "output_file" but not "backbone_alpha". From tjreedy at udel.edu Mon May 2 14:56:13 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 May 2011 14:56:13 -0400 Subject: Fibonacci series recursion error In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/2/2011 9:14 AM, Hans Georg Schaathun wrote: > On Sun, 01 May 2011 18:24:30 -0400, Terry Reedy > : Python does not do this automatically because 1) it can be a semantic > : change under some circumstances; 2) one who wants the iterative version > : can just as easily write it directly; > > That's the silliest argument I ever heard. Calling something silly when you have not really read it and perhaps asked questions to really understand it is, to me, silly. If you want a compiler that can introduce bugs into your program by doing what it thinks you meant, rather than what you said, don't use CPython. > : and 3) Python has a better way to > : process collections that removes essentially all the boilerplate in the > : recursive-call and while-loop versions: To properly use modern Python, one should know and use for loops and iterators. -- Terry Jan Reedy From enleverLesX_XXmcX at XmclavXeauX.com.invalid Mon May 2 14:56:53 2011 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Mon, 02 May 2011 20:56:53 +0200 Subject: ctypes and twain_32.dll References: <844574c2-4ff4-41b8-8cdc-de103437d18f@j31g2000yqe.googlegroups.com> Message-ID: <4dbefe78$0$14685$ba4acef3@reader.news.orange.fr> Hi! On my system, thera are not "twain32.dll" or "twain_32.dll", but "twain.dll" @+ -- Michel Claveau From ian.g.kelly at gmail.com Mon May 2 15:32:45 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 May 2011 13:32:45 -0600 Subject: "raise (type, value, traceback)" and "raise type, value, traceback" In-Reply-To: <1304356995.4335.2.camel@selene> References: <1304356995.4335.2.camel@selene> Message-ID: On Mon, May 2, 2011 at 11:23 AM, Jack Bates wrote: > Hi, anyone know why these two statements aren't equivalent? > > raise (type, value, traceback) > > raise type, value, traceback The latter is the syntax of the raise statement: up to 3 expressions, separated by commas. The former has a single expression that evaluates to a tuple. It's equivalent to this: t = (type, value, traceback) raise t That it accepts the tuple and raises a value-less expression of type `type` surprises me. The docs don't say anything about this, and I would have expected a TypeError, but it appears to be extracting the first element of the tuple and using that as the value of the first expression. From john106henry at hotmail.com Mon May 2 15:48:55 2011 From: john106henry at hotmail.com (John Henry) Date: Mon, 2 May 2011 12:48:55 -0700 (PDT) Subject: Pushing for Pythoncard 1.0 Message-ID: <6d896b66-3933-4743-8eb5-b9754f1ec14f@t19g2000prd.googlegroups.com> Attempt to push Pythoncard to a 1.0 status is now underway. A temporary website has been created at: http://code.google.com/p/pythoncard-1-0/ The official website continues to be http://pythoncard.sourceforge.net/ Pythoncard is such a wonderful package that it would be a shame to allow development for the package to go stagnant. The Python community deserves to continue enjoying the simplicity of Pythoncard for creating a GUI Python application. In the last few years, I've added a number of widgets and functions to the package. The present effort is to simply incorporate all of the changes I've made to the package, create an installer, push it out the door and announce to the world that Pythoncard 1.0 is here, and is here to stay. Here's a partial list of widgets and functions added: Widgets: PDFWindow, FlashWindow, MatplotlibCanvasWindow, MultiSelectionList, Drag-&-drop enabled tree control, IEHTMLWindow Backgrounds: MDIParentWindow, MDIChildWindow, MDISashWindow, multi-panel Background Window, Tools: Updated layoutmanager supporting the newly added widgets, and a revived action manager (provide list of actions or events associated with widgets in a context-sensitive fashion - no more needs to memorize which widget can do what). and others. I realize that there are other GUI packages that enjoyed far more support from the Python community in the last few years and have, as a result, a more extensive feature list, and more modern looks. My hats off to those developers. So, please re-frame from responding to this message or send me emails regarding xyz package and how that one is "better", more "modern" than Pythoncard, or that xyz package had xxx feature already. I like Pythoncard because it's so simple for most GUI applications I build that it's almost laughable. I've benefited tremendously from having Pythoncard around and now it's my turn to chip in and repay a small debt to Pythoncard. For x-Pythoncard users (and particularly developers), if you are unable to lend a helping hand, please at least join or re-join the Pythoncard mailing list and let your voice be heard. From hg at schaathun.net Mon May 2 16:02:43 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 2 May 2011 21:02:43 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <38f398-14h.ln1@svn.schaathun.net> On 02 May 2011 16:41:37 GMT, Steven D'Aprano wrote: : You must be new to the Internet then :) OK. Maybe I heard something worse last time I was an active news users, years ago. Anyway, most of the silly things I hear do not qualify as arguments :-) : The problem is, once you include side-effects, recursion and iteration : are *not* identical. Specifically, the opposition to tail-recursion : optimization in Python is that it plays havoc with the tracebacks you get : in the event of an exception. The argument goes: Thanks for the comprehensive background. I can see the point that python may be harder to optimise correctly during compilation than many other languages. : Regardless of whether you agree with the arguments or not, they're hardly : "silly". I only called one argument silly, namely the one about iterative rewriting being so simple that it is not an issue. Sometimes it isn't, but sometimes it is. The other arguments are valid. And they make me lean more towards more static, compiled languages without the excessive run-time dynamism of python. -- :-- Hans Georg From monaghand.david at gmail.com Mon May 2 16:48:51 2011 From: monaghand.david at gmail.com (David Monaghan) Date: Mon, 02 May 2011 21:48:51 +0100 Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger wrote: >I think it is time to give some visibility to some of the instructive >and very cool recipes in ActiveState's python cookbook. > >My vote for the coolest recipe of all time is: > > http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ Really cool, but wrong. x = 3234.667, not 3236.0 DaveM From ian.g.kelly at gmail.com Mon May 2 16:58:50 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 May 2011 14:58:50 -0600 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: On Mon, May 2, 2011 at 2:48 PM, David Monaghan wrote: > On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger > wrote: > >>I think it is time to give some visibility to some of the instructive >>and very cool recipes in ActiveState's python cookbook. >> >>My vote for the coolest recipe of all time is: >> >> ? ?http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ > > Really cool, but wrong. x = 3234.667, not 3236.0 Nope, I get 3236. Maybe you made a mistake somewhere. From dickinsm at gmail.com Mon May 2 17:18:36 2011 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 2 May 2011 14:18:36 -0700 (PDT) Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> <4dbedaa6$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54067d04-7298-45b0-ab0e-ba22b0758317@w36g2000vbi.googlegroups.com> On May 2, 5:24?pm, Steven D'Aprano wrote: > As far as I'm concerned, there are only two definitions of Fibonacci > numbers that have widespread agreement in the mathematical community: > > 0,1,1,2,3 ... (starting from n=0) > 1,1,2,3,5 ... (starting from n=1) > > Any other definition is rather, shall we say, idiosyncratic. And a concrete reason for preferring the above definition (in either form) is that divisibility properties of the sequence are much neater with this choice: gcd(F_m, F_n) = F_{gcd(m, n)} -- Mark From monaghand.david at gmail.com Mon May 2 17:45:34 2011 From: monaghand.david at gmail.com (David Monaghan) Date: Mon, 02 May 2011 22:45:34 +0100 Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> On Mon, 2 May 2011 14:58:50 -0600, Ian Kelly wrote: >On Mon, May 2, 2011 at 2:48 PM, David Monaghan > wrote: >> On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger >> wrote: >> >>>I think it is time to give some visibility to some of the instructive >>>and very cool recipes in ActiveState's python cookbook. >>> >>>My vote for the coolest recipe of all time is: >>> >>> ? ?http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ >> >> Really cool, but wrong. x = 3234.667, not 3236.0 > >Nope, I get 3236. Maybe you made a mistake somewhere. Oops. What a plonker .Three times I checked and got the same result each time. Now it works fine. Sorry! DaveM From harrismh777 at charter.net Mon May 2 17:50:52 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 02 May 2011 16:50:52 -0500 Subject: Fibonacci series recursion error In-Reply-To: References: Message-ID: <0HFvp.18698$vT3.2042@newsfe06.iad> Thomas Rachel wrote: >> ... because each recursion level 'return' calls fib() twice, and each of >> those calls fib() twice, and you get the point... > > yes - but they are called one after the other, so the "twice" call > counts only for execution speed, not for recursion depth. >>> def fib(n): >>> if n == 1: >>> return(n) >>> else: >>> return (fib(n-1)+fib(n-2)) They *are not* called one after the other in the sense that there is ever only one level of recursion with each call (not at all). Take a closer look. Each call to fib() forces a double head, and each of those forces another double head (now four), and so on... the recursion depth exception of the OP testifies against your theory. The thing about this problem that puzzles me, is why we might consider recursion for a possible solution in the first place. In other words, normally we consider using recursion when we need information further down the stack then we have now... so that recursion is necessary because each head call will not have the information it needs for completion until the tail clean-up (coming back up the stack) provides that information. In the case of the fib() numbers (or the fib sequence) recursion is not necessary for correctly handling of the problem. The simple straight-forward obvious way to handle the problem is to calculate the sequence outright in a straight-forward way. On the other hand, Otten's use of yield (making a generator) makes some sense too, in the case that we want to get the fib numbers over time without taking the time to calculate the entire sequence up-front. Just saying... kind regards, m harris From rosuav at gmail.com Mon May 2 17:56:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 07:56:26 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 2, 2011 at 11:14 PM, Hans Georg Schaathun wrote: > That's the silliest argument I ever heard. ?The programmer should write > the code the way he and application domain experts think, i.e. very > often recursively. ?The compiler should generate code the way the CPU > thinks (most optimally), i.e. iteratively. The CPU can function iteratively or recursively. The main difference between the programmer and the CPU there is that the CPU is always imperative, while a programmer might want to think functionally, or in an event-driven model, and then "under the covers" the compiler translates that into imperative code. But in my opinion, the programmer and the interpreter/compiler are teammates. If you allow programmers to be stupid, you will get a lot of stupid programmers writing code. (I think that's one of PHP's biggest downsides.) If the human and the machine know each other well enough, the resulting code can be orders of magnitude more efficient to run, *without taking any more tme to code* because the programmer already knew the right things to do. Perhaps it will take you four hours to read through something, study it, maybe eyeball the compiler's source code, maybe do some disassembly. If you have a few years of career ahead of you, you'll benefit many times over from those few hours, and without spending extra time, you'll produce better code. THAT is what distinguishes the master from the novice. Chris Angelico From unknownmoss at gmail.com Mon May 2 18:04:58 2011 From: unknownmoss at gmail.com (Unknown Moss) Date: Mon, 2 May 2011 15:04:58 -0700 (PDT) Subject: (beginner question) ConfigParser nuances Message-ID: Hi - Beginner question here. I'm working with ConfigParser. I'd like to take a multiline variable and convert it directly to an array. Seems like a common problem, but I don't see how I can do it without doing a little parsing in my own code. Here's what I'm doing ... >>> import ConfigParser >>> import io >>> sample = """ ... [Example] ... fruit = apple ... orange ... pear ... """ >>> config = ConfigParser.RawConfigParser() >>> config.readfp(io.BytesIO(sample)) >>> config.get("Example", "fruit") 'apple\norange\npear' >>> temp = config.get("Example", "fruit") >>> temp.split() ['apple', 'orange', 'pear'] I'm thinking there's a way to avoid this intermediate temp.split() step. Is there not a way to move a multiline value straight into an array using ConfigParser? Thanks for the help. From rosuav at gmail.com Mon May 2 18:17:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 08:17:35 +1000 Subject: Fibonacci series recursion error In-Reply-To: <0HFvp.18698$vT3.2042@newsfe06.iad> References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Tue, May 3, 2011 at 7:50 AM, harrismh777 wrote: > They *are not* called one after the other in the sense that there is ever > only one level of recursion with each call (not at all). Take a closer look. > Each call to fib() forces a double head, and each of those forces another > double head (now four), and so on... ?the recursion depth exception of the > OP testifies against your theory. def fib(n): if n==1: return n return fib(n-1)+fib(n-2) dis.dis(fib) 2 0 LOAD_FAST 0 (n) 3 LOAD_CONST 1 (1) 6 COMPARE_OP 2 (==) 9 JUMP_IF_FALSE 5 (to 17) 12 POP_TOP 3 13 LOAD_FAST 0 (n) 16 RETURN_VALUE >> 17 POP_TOP 4 18 LOAD_GLOBAL 0 (fib) 21 LOAD_FAST 0 (n) 24 LOAD_CONST 1 (1) 27 BINARY_SUBTRACT 28 CALL_FUNCTION 1 31 LOAD_GLOBAL 0 (fib) 34 LOAD_FAST 0 (n) 37 LOAD_CONST 2 (2) 40 BINARY_SUBTRACT 41 CALL_FUNCTION 1 44 BINARY_ADD 45 RETURN_VALUE The recursion is in the last block. Note that it calls a function, then keeps going. It doesn't fork. There are two CALL_FUNCTION opcodes, called *sequentially*. In terms of the call stack, there is only ever one of those two calls active at any given time. Also, as earlier pointed out, the reason for the stack overflow is that fib(2) will call fib(1) and fib(0), and fib(0) will call fib(-1) and fib(-2), etc. Changing the operator from == to <= in the conditional return will solve this. Chris Angelico From ian.g.kelly at gmail.com Mon May 2 18:22:35 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 May 2011 16:22:35 -0600 Subject: Fibonacci series recursion error In-Reply-To: <0HFvp.18698$vT3.2042@newsfe06.iad> References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Mon, May 2, 2011 at 3:50 PM, harrismh777 wrote: > Thomas Rachel wrote: >>> >>> ... because each recursion level 'return' calls fib() twice, and each of >>> those calls fib() twice, and you get the point... >> >> yes - but they are called one after the other, so the "twice" call >> counts only for execution speed, not for recursion depth. > >>>> def fib(n): >>>> ? ? if n == 1: >>>> ? ? ? ? return(n) >>>> ? ? else: >>>> ? ? ? ? return (fib(n-1)+fib(n-2)) > > They *are not* called one after the other in the sense that there is ever > only one level of recursion with each call (not at all). Take a closer look. > Each call to fib() forces a double head, and each of those forces another > double head (now four), and so on... The branching factor has nothing to do with the maximum stack depth. If you don't believe me, consider this little script: import inspect def maxstack(n): if n <= 0: return len(inspect.stack()) else: return max(maxstack(n-1), maxstack(n-2)) print maxstack(15) This prints "17". Now consider this script, which is similar but singly-recursive: import inspect def maxstack(n): if n <= 0: return len(inspect.stack()) else: return maxstack(n-1) print maxstack(15) This also prints "17". Note: they're the same. > ?the recursion depth exception of the > OP testifies against your theory. The OP's recursion depth exception was because a malformed base case made the recursion infinite. It had nothing to do with the branching factor. From clp2 at rebertia.com Mon May 2 18:25:16 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 May 2011 15:25:16 -0700 Subject: (beginner question) ConfigParser nuances In-Reply-To: References: Message-ID: On Mon, May 2, 2011 at 3:04 PM, Unknown Moss wrote: > Hi - Beginner question here. I'm working with ConfigParser. I'd like > to take a multiline variable and convert it directly to an array. > Seems like a common ?problem, but I don't see how I can do it without > doing a little parsing in my own code. Here's what I'm doing ... > >>>> import ConfigParser >>>> import io >>>> sample = """ > ... [Example] > ... fruit = apple > ... ? ? orange > ... ? ? pear > ... """ >>>> config = ConfigParser.RawConfigParser() >>>> config.readfp(io.BytesIO(sample)) >>>> config.get("Example", "fruit") > 'apple\norange\npear' >>>> temp = config.get("Example", "fruit") >>>> temp.split() > ['apple', 'orange', 'pear'] > > I'm thinking there's a way to avoid this intermediate temp.split() > step. Is there not a way to move a multiline value straight into an > array using ConfigParser? Nope, there is not. I think some might instead use several numbered options to similar effect: # config file [Example] fruit1: apple fruit2: orange fruit3: pear # Python from itertools import count fruits = [] names = ("fruit" + str(i) for i in count(1)) for name in names: if not config.has_option("Example", name): break fruits.append(config.get("Example", name)) Cheers, Chris -- http://rebertia.com From rosuav at gmail.com Mon May 2 18:42:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 08:42:22 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Tue, May 3, 2011 at 8:22 AM, Ian Kelly wrote: >> They *are not* called one after the other in the sense that there is ever >> only one level of recursion with each call (not at all). Take a closer look. >> Each call to fib() forces a double head, and each of those forces another >> double head (now four), and so on... > > The branching factor has nothing to do with the maximum stack depth. > Side point: In a massively parallel environment, branching like this COULD be implemented as a fork. I just don't know of any implementations of Python that do so. (And of course, it works for fib() because it needs/uses no global state, which makes the recursions completely independent. Not all functions are so courteous, and the compiler can't necessarily know the difference.) Chris Angelico From rosuav at gmail.com Mon May 2 19:44:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 09:44:59 +1000 Subject: Development software In-Reply-To: References: Message-ID: On Tue, May 3, 2011 at 1:23 AM, Petey wrote: > Which programmes should I start using because they might be useful in the future? Which functions of eclipse are useful but unused/unnoticed by beginners. > > What do you use and why :) ? You're going to get some extremely disparate responses to that! I'll open with the disclaimer that will apply to everyone's posts: This is personal opinion, not Gospel truth. :) For my development (which is quite polyglot - at the moment, C++/Python/PHP/makefile/Pike/text all up in tabs), I use SciTE and a good makefile. I hit F7 and Scite runs make in the current file's directory. Is it an IDE or an editor? I'm not really sure; it's an editor that lets me scroll through compiler errors with F4/Shift-F4. A well-made makefile is an awesome tool. I strongly recommend getting familiar with your make utility (if you don't currently have one, get GNU make). My make will build either the production or debug version of my code, upload changed files to our deployment server, and in fact do everything except push changes into our git repo (I prefer to do that manually, as I usually want to build lots of times and only then commit the change in git). Chris Angelico From steve+comp.lang.python at pearwood.info Mon May 2 20:21:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 May 2011 00:21:45 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> Message-ID: <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 May 2011 21:02:43 +0100, Hans Georg Schaathun wrote: > The other arguments are valid. And they make me lean more towards more > static, compiled languages without the excessive run-time dynamism of > python. If you value runtime efficiency over development time, sure. There are plenty of languages which have made that decision: Pascal, C, Java, Lisp, Forth, and many more. Python aims at acceptable performance (between 10 and 100 times slower than C) and much easier development (between 10 and 100 times faster than C *wink*). If that tradeoff doesn't suit you, perhaps Python is not the language for you. -- Steven From ryan.morrone at gmail.com Mon May 2 20:23:23 2011 From: ryan.morrone at gmail.com (PyNewbie) Date: Mon, 2 May 2011 17:23:23 -0700 (PDT) Subject: Py / VNC Automation Message-ID: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> Hi, I'm looking for a python class or open source code that is tightly integrated with VNC protocols - any ideas? From rosuav at gmail.com Mon May 2 20:52:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 10:52:04 +1000 Subject: Py / VNC Automation In-Reply-To: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> References: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> Message-ID: On Tue, May 3, 2011 at 10:23 AM, PyNewbie wrote: > Hi, > I'm looking for a python class or open source code that is tightly integrated with VNC protocols - any ideas? It's not a complex protocol; you could fairly readily work it manually. The protocol itself is called RFB - see http://en.wikipedia.org/wiki/RFB_protocol which has links to the official protocol spec. Working it from Python is as simple as creating a socket (import socket; vnc=socket.socket(); vnc.connect(('address',5900))) and sending and receiving binary data. If you're setting things up as a test, I recommend playing around with authentication disabled - it's a lot easier to master the protocol in its simplest form. Chris Angelico From drsalists at gmail.com Mon May 2 21:33:18 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 May 2011 18:33:18 -0700 Subject: Py / VNC Automation In-Reply-To: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> References: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 2, 2011 at 5:23 PM, PyNewbie wrote: > Hi, > I'm looking for a python class or open source code that is tightly > integrated with VNC protocols - any ideas? > -- > http://mail.python.org/mailman/listinfo/python-list > I've not updated this in a while, but it's got a python vnc viewer in the list: http://stromberg.dnsalias.org/~dstromberg/vnc.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Mon May 2 21:48:25 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 18:48:25 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On May 3, 2:50?am, harrismh777 wrote: > The thing about this problem that puzzles me, is why we might consider > recursion for a possible solution in the first place.... This can be answered directly but a bit lengthily. Instead let me ask a seemingly unrelated (but actually much the same) question. Here are two power functions: def powI(x,n): result = 1 for i in range(0,n): result = result * x return result def powR(x,n): return 1 if (n==0) else (x * powR(x, n-1)) What are their space/time complexities? Which do you prefer? From rustompmody at gmail.com Mon May 2 22:04:49 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 19:04:49 -0700 (PDT) Subject: Development software References: Message-ID: On May 2, 8:23?pm, Petey wrote: > Hi! > > I'm new to programming. I started with php earlier and I dropped it for Python. > I use Eclipse+PyDev for python, html and css. > > Which programmes should I start using because they might be useful in the future? > Which functions of eclipse are useful but unused/unnoticed by beginners. > > What do you use and why :) ? Chris talked of a good make tool. Yes this is necessary for more 'in- the-large' programming. But for a beginner its very important to have tight development cycle -- viz. a. Write a function b. Check the function c. Change the definition d. Check that etc with a minimum of keystrokes If eclipse gives that its good... For me its emacs with python-mode: python in one window python file in other jump between the two with one keystroke. Ive heard very good things about ipython (especially for introspection) but not tried it extensively myself From rosuav at gmail.com Mon May 2 22:13:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 12:13:16 +1000 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Tue, May 3, 2011 at 11:48 AM, rusi wrote: > What are their space/time complexities? > Which do you prefer? They're pretty similar actually. If you rework the first one to not use range() but instead have a more classic C style of loop, they'll be almost identical: def powI(x,n): result = 1 while n > 0: result *= x n-=1 return result There's a subtle difference in that powR as you've coded it will infinite-loop if given a negative exponent, while powI in any form will simply return 1 (neither is technically correct, fwiw). Other than that, the only difference is that one keeps its state on the call stack, the other uses a temporary variable. Performance would probably benefit from a special syntax meaning "recurse", which would avoid the LOAD_GLOBAL for the function's name (plus, things break if you pass recursive functions around after compiling them - for instance, powR2=powR; def powR(x,n): os.exit() - but if you do that, then you should expect to see nice bullet-holes in your foot). However, I do not believe that Python would overall benefit from any such thing. Chris Angelico From rosuav at gmail.com Mon May 2 22:16:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 12:16:05 +1000 Subject: Development software In-Reply-To: References: Message-ID: On Tue, May 3, 2011 at 12:04 PM, rusi wrote: > Chris talked of a good make tool. Yes this is necessary for more 'in- > the-large' programming. > But for a beginner its very important to have tight development cycle > -- viz. > a. Write a function > b. Check the function > c. Change the definition > d. Check that > etc > with a minimum of keystrokes a. Write a code file b. Press F7 and see the output in the other window. c, d. Iterate. Most IDEs will give you some such facility. F7 happens to be SciTE's keystroke, others may use Ctrl-F9 or F5 or C-x M-x butterfly, but it's almost certainly going to be there. Chris Angelico From rmorgan466 at gmail.com Mon May 2 22:46:18 2011 From: rmorgan466 at gmail.com (Rita) Date: Mon, 2 May 2011 22:46:18 -0400 Subject: complex data structures in python Message-ID: Hello, I was wondering if anyone has any documentation/recipes for implementing complex data structures. For instance, if you had a dictionary with a list inside a list inside a set. -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From unknownmoss at gmail.com Mon May 2 22:56:06 2011 From: unknownmoss at gmail.com (Unknown Moss) Date: Mon, 2 May 2011 19:56:06 -0700 (PDT) Subject: (beginner question) ConfigParser nuances References: Message-ID: <7d0855fe-5371-4803-8683-366056528c54@z13g2000prk.googlegroups.com> On May 2, 3:25?pm, Chris Rebert wrote: > On Mon, May 2, 2011 at 3:04 PM, Unknown Moss wrote: > > Hi -Beginnerquestionhere. I'm working with ConfigParser. I'd like > > to take a multiline variable and convert it directly to an array. > > Seems like a common ?problem, but I don't see how I can do it without > > doing a little parsing in my own code. Here's what I'm doing ... > > >>>> import ConfigParser > >>>> import io > >>>> sample = """ > > ... [Example] > > ... fruit = apple > > ... ? ? orange > > ... ? ? pear > > ... """ > >>>> config = ConfigParser.RawConfigParser() > >>>> config.readfp(io.BytesIO(sample)) > >>>> config.get("Example", "fruit") > > 'apple\norange\npear' > >>>> temp = config.get("Example", "fruit") > >>>> temp.split() > > ['apple', 'orange', 'pear'] > > > I'm thinking there's a way to avoid this intermediate temp.split() > > step. Is there not a way to move a multiline value straight into an > > array using ConfigParser? > > Nope, there is not. I think some might instead use several numbered > options to similar effect: > > # config file > [Example] > fruit1: apple > fruit2: orange > fruit3: pear > > # Python > from itertools import count > fruits = [] > names = ("fruit" + str(i) for i in count(1)) > for name in names: > ? ? if not config.has_option("Example", name): > ? ? ? ? break > ? ? fruits.append(config.get("Example", name)) > > Cheers, > Chris > --http://rebertia.com Ok, thanks Chris. Maybe I'm getting too lazy in my old age. :-) From rustompmody at gmail.com Mon May 2 23:42:45 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 20:42:45 -0700 (PDT) Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 3, 5:21?am, Steven D'Aprano wrote: > On Mon, 02 May 2011 21:02:43 +0100, Hans Georg Schaathun wrote: > > The other arguments are valid. ?And they make me lean more towards more > > static, compiled languages without the excessive run-time dynamism of > > python. > > If you value runtime efficiency over development time, sure. There are > plenty of languages which have made that decision: Pascal, C, Java, Lisp, > Forth, and many more. Or Haskell: Succinctness like python Type safety better than C, C++, Java with a minimum of type declarations From clp2 at rebertia.com Mon May 2 23:58:24 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 May 2011 20:58:24 -0700 Subject: complex data structures in python In-Reply-To: References: Message-ID: On Mon, May 2, 2011 at 7:46 PM, Rita wrote: > Hello, > I was wondering if anyone has any documentation/recipes for implementing > complex data structures. For instance, if you had a dictionary with a list > inside a list inside a set. Er, there's no special magic. The datatypes just nest normally. Pretty much the only thing to look out for is immutability/hashability. Dictionary keys and set elements should typically be immutable (and thus sensibly hashable). For this reason, tuples and frozensets are used instead of lists and non-frozen sets (respectively) in those situations (and in other cases where mutability should be disallowed). When creating a custom immutable type, one should override the __eq__(), __ne__(), and __hash__() special methods so that the type's instances can be used as dict keys and set elements. Your particular example combination doesn't work since it violates the aforementioned immutability rule. One should also be aware of the datatypes in the `collections` module, particularly `defaultdict`: http://docs.python.org/library/collections.html Cheers, Chris -- http://rebertia.com From stefan_ml at behnel.de Tue May 3 01:04:47 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 03 May 2011 07:04:47 +0200 Subject: Coolest Python recipe of all time In-Reply-To: <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: David Monaghan, 02.05.2011 23:45: > On Mon, 2 May 2011 14:58:50 -0600, Ian Kelly wrote: > >> On Mon, May 2, 2011 at 2:48 PM, David Monaghan wrote: >>> On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger wrote: >>> >>>> I think it is time to give some visibility to some of the instructive >>>> and very cool recipes in ActiveState's python cookbook. >>>> >>>> My vote for the coolest recipe of all time is: >>>> >>>> http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ >>> >>> Really cool, but wrong. x = 3234.667, not 3236.0 >> >> Nope, I get 3236. Maybe you made a mistake somewhere. > > Oops. What a plonker .Three times I checked and got the same result each > time. Now it works fine. Sorry! The bad thing about this recipe is that it requires quite a bit of background knowledge in order to infer that the code the developer is looking at is actually correct. At first sight, it looks like an evil hack, and the lack of documentation doesn't help either. Stefan From hg at schaathun.net Tue May 3 01:13:07 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 3 May 2011 06:13:07 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3gf498-tuh.ln1@svn.schaathun.net> On 03 May 2011 00:21:45 GMT, Steven D'Aprano wrote: : Python aims at acceptable performance (between 10 and 100 times slower : than C) and much easier development (between 10 and 100 times faster than : C *wink*). If that tradeoff doesn't suit you, perhaps Python is not the : language for you. It isn't the trade-off per se which bothers me, but certain features which seem to make compilation harder without making development any easier. But then, it probably depeds on what kind of development you are doing. -- :-- Hans Georg From ian.g.kelly at gmail.com Tue May 3 01:17:21 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 May 2011 23:17:21 -0600 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On Mon, May 2, 2011 at 11:04 PM, Stefan Behnel wrote: > The bad thing about this recipe is that it requires quite a bit of > background knowledge in order to infer that the code the developer is > looking at is actually correct. At first sight, it looks like an evil hack, > and the lack of documentation doesn't help either. What do you mean, "looks like"? For crying out loud, it abuses complex numbers to represent 2-element vectors, and it passes unvalidated input to eval(). It is *absolutely* an evil hack! Albeit a clever one... From drsalists at gmail.com Tue May 3 01:27:52 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 May 2011 22:27:52 -0700 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Mon, May 2, 2011 at 7:13 PM, Chris Angelico wrote: > On Tue, May 3, 2011 at 11:48 AM, rusi wrote: > > What are their space/time complexities? > > Which do you prefer? > > They're pretty similar actually. If you rework the first one to not > use range() but instead have a more classic C style of loop, they'll > be almost identical: > > def powI(x,n): > result = 1 > while n > 0: > result *= x > n-=1 > return result > > There's a subtle difference in that powR as you've coded it will > infinite-loop if given a negative exponent, while powI in any form > will simply return 1 (neither is technically correct, fwiw). Other > than that, the only difference is that one keeps its state on the call > stack, the other uses a temporary variable. > The recursive solution uses more stack. That is true. But the recursive solution has time complexity of O(logn). The iterative solution has time complexity of O(n). That's a significant difference for large n - a significant benefit of the recursive version. However, an iterative version of a function can always be created from a recursive version. In this case, an iterative version can be constructed that is O(logn) time and O(1) stack. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 3 01:29:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 15:29:51 +1000 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Tue, May 3, 2011 at 3:27 PM, Dan Stromberg wrote: > > But the recursive solution has time complexity of O(logn).? The iterative > solution has time complexity of O(n).? That's a significant difference for > large n - a significant benefit of the recursive version. Are you sure? It will produce n function calls and n multiplications, how is that O(log n)? Chris Angelico From eaglebalti at gmail.com Tue May 3 01:42:16 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Mon, 2 May 2011 22:42:16 -0700 (PDT) Subject: Hello Friends Message-ID: <900970dc-a792-415d-84f9-a4afb1072140@bl1g2000vbb.googlegroups.com> What are you lookink for. Just visit to see what you want www.bollywoodhotactresswallpapers.blogspot.com www.bollywoodhotwallpaperz.blogspot.com www.bollywoodhotactresspicz.blogspot.com www.hottesthitsbollywood.blogspot.com www.bollywoodhotphotoz.blogspot.com From ian.g.kelly at gmail.com Tue May 3 01:46:58 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 May 2011 23:46:58 -0600 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Mon, May 2, 2011 at 11:27 PM, Dan Stromberg wrote: > But the recursive solution has time complexity of O(logn).? The iterative > solution has time complexity of O(n).? That's a significant difference for > large n - a significant benefit of the recursive version. It's linear as written. I think you're talking about an implementation like this one: def powR(x,n): if n < 0: return 1.0 / powR(x, -n) elif n == 0: return 1 else: half_n = n // 2 root = powR(x, half_n) result = root * root if half_n + half_n == n - 1: result = result * x return result That's O(log n), but it was harder to write, and it could just as easily be iterative. In fact it might actually have been a bit simpler to write it iteratively. From patrick.vrijlandt at gmail.com Tue May 3 01:50:13 2011 From: patrick.vrijlandt at gmail.com (Patrick Vrijlandt) Date: Mon, 2 May 2011 22:50:13 -0700 (PDT) Subject: ctypes and twain_32.dll References: <844574c2-4ff4-41b8-8cdc-de103437d18f@j31g2000yqe.googlegroups.com> <4dbefe78$0$14685$ba4acef3@reader.news.orange.fr> Message-ID: <88eb4d02-5273-4ea6-8c50-8f7bcb7e5224@w24g2000yqb.googlegroups.com> On 2 mei, 20:56, "Michel Claveau - MVP" wrote: > Hi! > > On my system, thera are not "twain32.dll" or "twain_32.dll", but "twain.dll" > > @+ > -- > Michel Claveau Hi, I have both. They are correctly installed and working. ctypes gives a different response if it cannot find the requested DLL. Patrick From drsalists at gmail.com Tue May 3 01:51:28 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 May 2011 22:51:28 -0700 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Mon, May 2, 2011 at 10:29 PM, Chris Angelico wrote: > On Tue, May 3, 2011 at 3:27 PM, Dan Stromberg wrote: > > > > But the recursive solution has time complexity of O(logn). The iterative > > solution has time complexity of O(n). That's a significant difference > for > > large n - a significant benefit of the recursive version. > > Are you sure? It will produce n function calls and n multiplications, > how is that O(log n)? > Doh. Usually when someone gives a recursive solution to this problem, it's O(logn), but not this time. Here's a logn one: def power(x, n): if n == 0: return 1 else: half, remainder = divmod(n, 2) if remainder == 1: return power(x, half) ** 2 * x else: return power(x, half) ** 2 -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue May 3 02:00:05 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 May 2011 02:00:05 -0400 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On 5/3/2011 1:04 AM, Stefan Behnel wrote: > The bad thing about this recipe is that it requires quite a bit of > background knowledge in order to infer that the code the developer is > looking at is actually correct. The main math knowledge needed is the trivial fact that if a*x + b = 0, then x = -b/a. The other math knowledge needed is that complex numbers add componentwise. The trick is that replacing x with j and evaluating therefore causes (in Python) all the coefficients of x (now j) to be added together separately from all the constant terms to reduce the linear equation to a*x+b (= 0 implied). -- Terry Jan Reedy From stefan_ml at behnel.de Tue May 3 02:23:58 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 03 May 2011 08:23:58 +0200 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: Terry Reedy, 03.05.2011 08:00: > On 5/3/2011 1:04 AM, Stefan Behnel wrote: > >> The bad thing about this recipe is that it requires quite a bit of >> background knowledge in order to infer that the code the developer is >> looking at is actually correct. > > The main math knowledge needed is the trivial fact that if a*x + b = 0, > then x = -b/a. The other math knowledge needed is that complex numbers add > componentwise. The trick is that replacing x with j and evaluating > therefore causes (in Python) all the coefficients of x (now j) to be added > together separately from all the constant terms to reduce the linear > equation to a*x+b (= 0 implied). As your above paragraph proves, it's the kind of implementation that requires three lines of executing code and at least 6 lines of additional comment. Hopefully accompanied by an excuse of the developer. Stefan From greg.ewing at canterbury.ac.nz Tue May 3 02:29:30 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 May 2011 18:29:30 +1200 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: <929lmdF59lU1@mid.individual.net> Terry Reedy wrote: > The trick is that replacing x with j and evaluating > therefore causes (in Python) all the coefficients of x (now j) to be > added together separately from all the constant terms to reduce the > linear equation to a*x+b (= 0 implied). Hmmm... so if we used quaternions, could we solve systems of linear equations in 3 variables? -- Greg From hg at schaathun.net Tue May 3 03:01:35 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 3 May 2011 08:01:35 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 3 May 2011 07:56:26 +1000, Chris Angelico wrote: : > often recursively. ?The compiler should generate code the way the CPU : > thinks (most optimally), i.e. iteratively. : : The CPU can function iteratively or recursively. I should have said 'hardware' rather than CPU. Iteratively it is not as optimal as the call contexts have to be stored. : But in my opinion, the programmer and the interpreter/compiler are : teammates. If you allow programmers to be stupid, you will get a lot : of stupid programmers writing code. (I think that's one of PHP's : biggest downsides.) If the human and the machine know each other well : enough, the resulting code can be orders of magnitude more efficient : to run, *without taking any more tme to code* because the programmer : already knew the right things to do. There are situations where that team is essential. However, in many more situation, the programmer has to team primarily with domain experts and work with a language in which the domain expert is fluent. The compiler and hardware are slaves of the engineers, and extra staff to team up with the compiler is an added cost and delay. : Perhaps it will take you four hours to read through something, study : it, maybe eyeball the compiler's source code, maybe do some : disassembly. If you have a few years of career ahead of you, you'll : benefit many times over from those few hours, and without spending : extra time, you'll produce better code. THAT is what distinguishes the : master from the novice. That depends on /what/ your career is, and what you need to master. -- :-- Hans Georg From rafadurancastaneda at gmail.com Tue May 3 03:08:02 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Tue, 3 May 2011 09:08:02 +0200 Subject: Py / VNC Automation In-Reply-To: References: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> Message-ID: You can check this https://github.com/kanaka/noVNC 2011/5/3 Dan Stromberg > > On Mon, May 2, 2011 at 5:23 PM, PyNewbie wrote: > >> Hi, >> I'm looking for a python class or open source code that is tightly >> integrated with VNC protocols - any ideas? >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > I've not updated this in a while, but it's got a python vnc viewer in the > list: > > http://stromberg.dnsalias.org/~dstromberg/vnc.html > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Tue May 3 03:52:15 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 3 May 2011 00:52:15 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> On May 3, 10:29?am, Chris Angelico wrote: > On Tue, May 3, 2011 at 3:27 PM, Dan Stromberg wrote: > Doh. > Usually when someone gives a recursive solution to this problem, it's > O(logn), but not this time. > Here's a logn one: :-) Ok so you beat me to it :D I was trying to arrive at an answer to the question (by M Harris) about why anyone would do something like fib recursively. I used power since that illustrates the case more easily, viz: A trivial power -- recursive or iterative -- is linear time -- O(n) A more clever power can be O(log(n)) This more clever power can be trivially derived from the recursive one as follows: The recursive O(n) function: def powR(x,n): return 1 if (n==0) else (x * powR(x, n-1)) is just python syntax for the school algebra (or Haskell) equations: x^0 = 1 x^(n+1) = x * x^n Adding one more equation: x^(2*n) = (x^2)^n = (x*x)^n Re-python-ifying we get: def pow(x,n): return 1 if (n==0) else pow(x*x, n/2) if even(n) else x*pow(x,n-1) def even(n): return n % 2 == 0 Can this be done iteratively? Of course but its not so trivial. [If you believe it is, then try writing a log(n) fib iteratively :D ] From duncan.booth at invalid.invalid Tue May 3 04:41:04 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 3 May 2011 08:41:04 GMT Subject: "raise (type, value, traceback)" and "raise type, value, traceback" References: <1304356995.4335.2.camel@selene> Message-ID: Ian Kelly wrote: > t = (type, value, traceback) > raise t > > That it accepts the tuple and raises a value-less expression of type > `type` surprises me. The docs don't say anything about this, and I > would have expected a TypeError, but it appears to be extracting the > first element of the tuple and using that as the value of the first > expression. > Not only that but you can nest tuples and it will drill down as far as necessary through the tuples until it finds something that isn't a tuple. It doesn't appear to be documented, but I think it may be intended to provide some kind of symmetry with 'try...except': when you catch an exception the expression used to catch the exception must be 'compatible' with the exception, i.e. the exception itself, one of its base classes, or a tuple which contains an item 'compatible' with the exception. So my guess would be that since it allows: MyExceptionSpec = (RuntimeError, ValueError) try: ... except MyExceptionSpec: ... the intent is to allow you to also throw 'MyExceptionSpec' from within the 'try'. I would also guess that it is a hangover from the days when exceptions were strings and you couldn't use inheritance to group exceptions. -- Duncan Booth http://kupuguy.blogspot.com From davea at ieee.org Tue May 3 06:32:06 2011 From: davea at ieee.org (Dave Angel) Date: Tue, 03 May 2011 06:32:06 -0400 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> Message-ID: <4DBFD9A6.1040803@ieee.org> On 01/-10/-28163 02:59 PM, rusi wrote: > On May 3, 10:29 am, Chris Angelico wrote: >> On Tue, May 3, 2011 at 3:27 PM, Dan Stromberg wrote: >> Doh. > >> Usually when someone gives a recursive solution to this problem, it's >> O(logn), but not this time. > >> Here's a logn one: > > :-) Ok so you beat me to it :D > > I was trying to arrive at an answer to the question (by M Harris) > about why anyone would do something like fib recursively. I used power > since that illustrates the case more easily, viz: > A trivial power -- recursive or iterative -- is linear time -- O(n) > A more clever power can be O(log(n)) > This more clever power can be trivially derived from the recursive one > as follows: > > The recursive O(n) function: > def powR(x,n): return 1 if (n=) else (x * powR(x, n-1)) > > is just python syntax for the school algebra (or Haskell) equations: > > x^0 = > x^(n+1) = * x^n > > Adding one more equation: > x^(2*n) =x^2)^n = (x*x)^n > Re-python-ifying we get: > > > def pow(x,n): > return 1 if (n=) else pow(x*x, n/2) if even(n) else x*pow(x,n-1) > > def even(n): return n % 2 =0 > > Can this be done iteratively? Of course but its not so trivial. > > [If you believe it is, then try writing a log(n) fib iteratively :D ] > What I'm surprised at is that nobody has pointed out that the logn version is also generally more accurate, given traditional floats. Usually getting the answer accurate (given the constraints of finite precision intermediates) is more important than performance, but in this case they go hand in hand. DaveA From jamesdnld730 at gmail.com Tue May 3 06:48:57 2011 From: jamesdnld730 at gmail.com (James A. Donald) Date: Tue, 3 May 2011 03:48:57 -0700 (PDT) Subject: Installing programs that depend on, or are, python extensions. References: <3d0dee08-e743-4f10-ae79-5d3052c3d0d9@h36g2000pro.googlegroups.com> Message-ID: <7142c2e5-5c54-4f85-a957-2797560fe97f@s41g2000prb.googlegroups.com> On Apr 30, 6:39?pm, David Cournapeau wrote: > On Sat, Apr 30, 2011 at 2:19 PM, James A. Donald wrote: > > > I have noticed that installingpythonprograms tends to be hell, > > particularly underwindows, and installingpythonprograms that rely > > on, or in large part are,pythonextensionswritten in C++ tends to be > > hell on wheels with large spiky knobs and scythes on the wheels. > > > Is this because suchinstallare inherently hard to do and hard to > > write, or is it becauseInstalltends to be done last, and therefore > > not done at all? > > Most likely both. > > Packaging complex application is hard, and I think few programmers > like doing it, so it is rarely done correctly. > > > > > Can anyone suggest any examples of such a program with a cleanwindows > >installthat shows how it was done? > > > Bywindowsinstall, I mean you run setup.exe, and get a program group, > > file types registered, and an entry in the add/remove programs list, I > > do not mean fourteen pages of direly incomplete notes which do not > > actually work for versions later than 1.01, and do not work for > > version 1.01 unless one has already installed the complete developer > > environment. > > Well,pythonitself is a reasonably good example I think. But if you > are interested in having onepythonprogram which is a one clickinstallwithout requiring the user to eveninstallpython, you will > need to look into tools like py2exe which can create all the files > necessary to do so from an existingpythonpackage. Then, you package > those files into a nice installer. I like nsis, which is open source > and relatively well documented, but there are other solutions as well. > > cheers, > > David py2exe would work, but a correct installer would install Python if not present, then install the program. From rustompmody at gmail.com Tue May 3 06:51:16 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 3 May 2011 03:51:16 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> Message-ID: On May 3, 3:32?pm, Dave Angel wrote: > What I'm surprised at is that nobody has pointed out that the logn > version is also generally more accurate, given traditional floats. > Usually getting the answer accurate (given the constraints of finite > precision intermediates) is more important than performance, but in this > case they go hand in hand. Well!! That's a slant that I was not aware of -- though fairly obvious on second thought. Thanks Dave. From rosuav at gmail.com Tue May 3 07:04:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 21:04:07 +1000 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <4DBFD9A6.1040803@ieee.org> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4DBFD9A6.1040803@ieee.org> Message-ID: On Tue, May 3, 2011 at 8:32 PM, Dave Angel wrote: > What I'm surprised at is that nobody has pointed out that the logn version > is also generally more accurate, given traditional floats. Usually getting > the answer accurate (given the constraints of finite precision > intermediates) is more important than performance, but in this case they go > hand in hand. And that, Your Honour, is why I prefer bignums (especially for integers) to floating point. Precision rather than performance. Chris Angelico From hg at schaathun.net Tue May 3 08:39:24 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 3 May 2011 13:39:24 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01 May 2011 08:45:51 GMT, Steven D'Aprano wrote: : Python uses a data model of "name binding" and "call by object" (also : known as "call by sharing"). I trust I don't need to define my terms, but : just in case: Without having the time to get my hand around exactly what this means: Simula has three ways of transmitting arguments, namely transmission by name, by value, and by reference. Is transmission by name the same as call by object? Anyway, I have never seen anyone counting more than three ways of doing this ... -- :-- Hans Georg From steve+comp.lang.python at pearwood.info Tue May 3 08:49:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 May 2011 12:49:50 GMT Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4DBFD9A6.1040803@ieee.org> Message-ID: <4dbff9ed$0$29991$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 May 2011 21:04:07 +1000, Chris Angelico wrote: > And that, Your Honour, is why I prefer bignums (especially for integers) > to floating point. Precision rather than performance. I'm intrigued by your comment "especially for integers", which implies that you might use bignums for non-integers. Out of curiosity, how would you calculate: sin(sqrt(7)*pi/31) using bignums? -- Steven From rosuav at gmail.com Tue May 3 09:02:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 23:02:29 +1000 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <4dbff9ed$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4DBFD9A6.1040803@ieee.org> <4dbff9ed$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 3, 2011 at 10:49 PM, Steven D'Aprano wrote: > On Tue, 03 May 2011 21:04:07 +1000, Chris Angelico wrote: > >> And that, Your Honour, is why I prefer bignums (especially for integers) >> to floating point. Precision rather than performance. > > I'm intrigued by your comment "especially for integers", which implies > that you might use bignums for non-integers. Out of curiosity, how would > you calculate: > > sin(sqrt(7)*pi/31) > > using bignums? REXX uses decimal bignums, although I don't have a high-performance math library (for sin) that uses anything more than IEEE double precision. If I coded my own sin algorithm in REXX, I could go to whatever precision memory (and patience) would allow. Chris Angelico From daniel.rentz at gmx.de Tue May 3 09:45:45 2011 From: daniel.rentz at gmx.de (Daniel Rentz) Date: Tue, 03 May 2011 15:45:45 +0200 Subject: Compiling Python 3.2 on Cygwin fails Message-ID: Hello, I've downloaded the 3.2 source tarball from python.org and tried to compile Python from scratch in a Cygwin 1.7.7 environment. Configure works as expected. Make fails with the following message: make: *** No rule to make target `libpython3.2m.dll.a', needed by `python.exe'. Stop. There is a suspicious line in Makefile.pre.in, line 509: $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) Changing that line to $(DLLLIBRARY) $(LDLIBRARY): $(LIBRARY_OBJS) lets make finish, but gives a bunch of other errors and warnings, such as: /usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lpython3.2 collect2: ld returned 1 exit status Python build finished, but the necessary bits to build these modules were not found: _tkinter nis ossaudiodev spwd To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _bisect _codecs_cn _codecs_hk _codecs_iso2022 _codecs_jp _codecs_kr _codecs_tw _csv _ctypes _ctypes_test _curses _curses_panel _datetime _elementtree _gdbm _hashlib _heapq _json _lsprof _multibytecodec _multiprocessing _pickle _posixsubprocess _random _socket _sqlite3 _ssl _struct _testcapi array atexit audioop binascii bz2 cmath crypt fcntl grp math mmap parser pyexpat readline resource select syslog termios time unicodedata zlib Is there something obvious I am missing here? Regards Daniel From hniksic at xemacs.org Tue May 3 09:50:55 2011 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 03 May 2011 15:50:55 +0200 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87aaf351vk.fsf@xemacs.org> Steven D'Aprano writes: > "Python's data model is different from other languages" > > which is perfectly correct, if you think of C as "other languages". But > it's equally correct to say that Python's data model is the same as other > languages. As I understand it, Python and Ruby have the same data model. > So does Java, so long as you only consider objects[...] > What other languages use the same, or mostly similar, data model as > Python? Count in Common Lisp and Scheme. I would say that, considering currently most popular languages and platforms, Python's data model is in the majority. It is only the people coming from a C++ background that tend to be confused by it. From miki.tebeka at gmail.com Tue May 3 09:54:25 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 3 May 2011 06:54:25 -0700 (PDT) Subject: Installing programs that depend on, or are, python extensions. In-Reply-To: <7142c2e5-5c54-4f85-a957-2797560fe97f@s41g2000prb.googlegroups.com> Message-ID: > py2exe would work, but a correct installer would install Python if not > present, then install the program. py2exe packs everything you need, including Python. A program created with py2exe does not depend on installed Python. From wim at go2people.nl Tue May 3 10:02:52 2011 From: wim at go2people.nl (Wim Feijen) Date: Tue, 3 May 2011 16:02:52 +0200 Subject: spf-records Message-ID: Dag mannen, Afgelopen week liepen we tegen het feit op dat Google e-mails afkomstig van onze server als spam markeerde en deze zonder bericht verwijderde. Ik vroeg me af of een van jullie hier wel eens tegenop is gelopen en wil bij deze even waarschuwen dat dat dus zomaar kan gebeuren. Wat voor ons werkte om dit op te lossen, is om een spf-record toe te voegen. In ons geval: v=spf1 a mx ip4:89.31.96.72 ip4:79.170.94.115 include=_spf.google.com ?all Neem dit maar niet over, want ik vraag me af of dit goed is? Voor een precieze uitleg van spf, zie: http://www.openspf.org/ Onze klant meldde dat hij geen mail meer kan ontvangen. Heeft iemand een idee hoe dit kan? Groeten van Wim -- Wim Feijen Algemeen directeur wim at go2people.nl 06 11113316 Go2People Websites Keizersgracht 8 1015 CN Amsterdam 020 7370378 www.go2people.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From listas.programacao at gmail.com Tue May 3 10:09:27 2011 From: listas.programacao at gmail.com (Jayme Proni Filho) Date: Tue, 3 May 2011 11:09:27 -0300 Subject: spf-records In-Reply-To: References: Message-ID: English man English. 2011/5/3 Wim Feijen > Dag mannen, > > Afgelopen week liepen we tegen het feit op dat Google e-mails afkomstig van > onze server als spam markeerde en deze zonder bericht verwijderde. Ik vroeg > me af of een van jullie hier wel eens tegenop is gelopen en wil bij deze > even waarschuwen dat dat dus zomaar kan gebeuren. > > Wat voor ons werkte om dit op te lossen, is om een spf-record toe te > voegen. In ons geval: > v=spf1 a mx ip4:89.31.96.72 ip4:79.170.94.115 include=_spf.google.com ?all > > Neem dit maar niet over, want ik vraag me af of dit goed is? > > Voor een precieze uitleg van spf, zie: http://www.openspf.org/ > > Onze klant meldde dat hij geen mail meer kan > ontvangen. Heeft iemand een idee hoe dit kan? > > Groeten van Wim > > -- > Wim Feijen > Algemeen directeur > wim at go2people.nl > 06 11113316 > > Go2People Websites > Keizersgracht 8 > 1015 CN Amsterdam > 020 7370378 > www.go2people.nl > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- --------------------------------------------------------------------------------------- Jayme Proni Filho Skype: jaymeproni Twitter: @jaymeproni Phone: +55 - 17 - 3631 - 6576 Mobile: +55 - 17 - 9605 - 3560 e-Mail: jaymeproni at yahoo dot com dot br Blogs (Em constru??o) Programandor: http://jaymeproni.wordpress.com Sociedade em A??o: http://sociedaemacao.wordpress.com --------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From listas.programacao at gmail.com Tue May 3 10:11:37 2011 From: listas.programacao at gmail.com (Jayme Proni Filho) Date: Tue, 3 May 2011 11:11:37 -0300 Subject: Hello Friends In-Reply-To: <900970dc-a792-415d-84f9-a4afb1072140@bl1g2000vbb.googlegroups.com> References: <900970dc-a792-415d-84f9-a4afb1072140@bl1g2000vbb.googlegroups.com> Message-ID: This is a place about python man! Python. 2011/5/3 Ashraf Ali > What are you lookink for. Just visit to see what you want > www.bollywoodhotactresswallpapers.blogspot.com > > www.bollywoodhotwallpaperz.blogspot.com > > www.bollywoodhotactresspicz.blogspot.com > > www.hottesthitsbollywood.blogspot.com > > www.bollywoodhotphotoz.blogspot.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- --------------------------------------------------------------------------------------- Jayme Proni Filho Skype: jaymeproni Twitter: @jaymeproni Phone: +55 - 17 - 3631 - 6576 Mobile: +55 - 17 - 9605 - 3560 e-Mail: jaymeproni at yahoo dot com dot br Blogs (Em constru??o) Programandor: http://jaymeproni.wordpress.com Sociedade em A??o: http://sociedaemacao.wordpress.com --------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From pari685 at gmail.com Tue May 3 10:15:18 2011 From: pari685 at gmail.com (Parikshit ..) Date: Tue, 3 May 2011 16:15:18 +0200 Subject: Installing programs that depend on, or are, python extensions. In-Reply-To: References: <7142c2e5-5c54-4f85-a957-2797560fe97f@s41g2000prb.googlegroups.com> Message-ID: Pyinstaller can also be used to create executables. It does not need python installed. We have been able to make executables for windows and mac as well with this. - Parikshit On Tue, May 3, 2011 at 3:54 PM, Miki Tebeka wrote: > > py2exe would work, but a correct installer would install Python if not > > present, then install the program. > py2exe packs everything you need, including Python. A program created with > py2exe does not depend on installed Python. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wim at go2people.nl Tue May 3 10:23:40 2011 From: wim at go2people.nl (Wim Feijen) Date: Tue, 3 May 2011 16:23:40 +0200 Subject: spf-records In-Reply-To: References: Message-ID: Excuse me, this message was sent to the wrong mailing list. Sorry, Wim 2011/5/3 Wim Feijen > Dag mannen, > > Afgelopen week liepen we tegen het feit op dat Google e-mails afkomstig van > onze server als spam markeerde en deze zonder bericht verwijderde. Ik vroeg > me af of een van jullie hier wel eens tegenop is gelopen en wil bij deze > even waarschuwen dat dat dus zomaar kan gebeuren. > > Wat voor ons werkte om dit op te lossen, is om een spf-record toe te > voegen. In ons geval: > v=spf1 a mx ip4:89.31.96.72 ip4:79.170.94.115 include=_spf.google.com ?all > > Neem dit maar niet over, want ik vraag me af of dit goed is? > > Voor een precieze uitleg van spf, zie: http://www.openspf.org/ > > Onze klant meldde dat hij geen mail meer kan > ontvangen. Heeft iemand een idee hoe dit kan? > > Groeten van Wim > > -- > Wim Feijen > Algemeen directeur > wim at go2people.nl > 06 11113316 > > Go2People Websites > Keizersgracht 8 > 1015 CN Amsterdam > 020 7370378 > www.go2people.nl > > -- Wim Feijen Algemeen directeur wim at go2people.nl 06 11113316 Go2People Websites Keizersgracht 8 1015 CN Amsterdam 020 7370378 www.go2people.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue May 3 10:49:04 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 3 May 2011 14:49:04 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-03, Hans Georg Schaathun wrote: > On 01 May 2011 08:45:51 GMT, Steven D'Aprano > wrote: >: Python uses a data model of "name binding" and "call by object" (also >: known as "call by sharing"). I trust I don't need to define my terms, but >: just in case: > > Without having the time to get my hand around exactly what this means: > Simula has three ways of transmitting arguments, namely transmission > by name, by value, and by reference. Is transmission by name the same > as call by object? No. For example, assume the argument is a[i]. In call by object, the expression a[i] is evaluated (i is evaluated, and then used as an index to determine the object that is the ith element of a). The callee's argument name is then bound to that object. In call by name, every time the callee references the argument name, the expression a[i] is evaluated anew. If the value of 'i' or the binding of 'a' has changed since the time of the function call, then the callee's argument now refers to a different object than it did at the time of the the function call. It's rather like a macro language (e.g. cpp) which merely performs a textual substitution of the argument name (the difference between pass-by-name and macro substitution is that the context of the argument evaluation is different). -- Grant Edwards grant.b.edwards Yow! Well, I'm INVISIBLE at AGAIN ... I might as well gmail.com pay a visit to the LADIES ROOM ... From jeanmichel at sequans.com Tue May 3 11:20:34 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 03 May 2011 17:20:34 +0200 Subject: spf-records In-Reply-To: References: Message-ID: <4DC01D42.5040907@sequans.com> Wim Feijen wrote: > Excuse me, this message was sent to the wrong mailing list. > > Sorry, Wim > > 2011/5/3 Wim Feijen > > > Dag mannen, > You're lucky that the native language of our Benevolent Dictator For Life is tolerated in this list. JM From steve+comp.lang.python at pearwood.info Tue May 3 11:20:42 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 May 2011 15:20:42 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc01d4a$0$29991$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 May 2011 13:39:24 +0100, Hans Georg Schaathun wrote: > On 01 May 2011 08:45:51 GMT, Steven D'Aprano > wrote: > : Python uses a data model of "name binding" and "call by object" (also > : known as "call by sharing"). I trust I don't need to define my terms, > but : just in case: > > Without having the time to get my hand around exactly what this means: > Simula has three ways of transmitting arguments, namely transmission by > name, by value, and by reference. Is transmission by name the same as > call by object? Anyway, I have never seen anyone counting more than > three ways of doing this ... You get credit for not falling into the trap of thinking there are only two, call by reference and call by value, but there are *many* more than just three. Wikipedia lists at least 13: http://en.wikipedia.org/wiki/Evaluation_strategy See also: http://effbot.org/zone/call-by-object.htm -- Steven From tjreedy at udel.edu Tue May 3 11:49:01 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 May 2011 11:49:01 -0400 Subject: Coolest Python recipe of all time In-Reply-To: <929lmdF59lU1@mid.individual.net> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> <929lmdF59lU1@mid.individual.net> Message-ID: On 5/3/2011 2:29 AM, Gregory Ewing wrote: > Terry Reedy wrote: >> The trick is that replacing x with j and evaluating therefore causes >> (in Python) all the coefficients of x (now j) to be added together >> separately from all the constant terms to reduce the linear equation >> to a*x+b (= 0 implied). > > Hmmm... so if we used quaternions, could we solve systems > of linear equations in 3 variables? Yes and no. The use of 1*j merely collected and added together all the multipliers of 'x' (and all the constant terms). That is a fairly trivial matter of constant folding. Systems of linear equations are usually presented in that form already. The actual solution to the simple equation is in the formula x = -a/b (where a and b are the sums). The solution formula for three variables would be far more complex. -- Terry Jan Reedy From drsalists at gmail.com Tue May 3 12:10:52 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 3 May 2011 09:10:52 -0700 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <4dbff9ed$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4DBFD9A6.1040803@ieee.org> <4dbff9ed$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 3, 2011 at 5:49 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Tue, 03 May 2011 21:04:07 +1000, Chris Angelico wrote: > > > And that, Your Honour, is why I prefer bignums (especially for integers) > > to floating point. Precision rather than performance. > > I'm intrigued by your comment "especially for integers", which implies > that you might use bignums for non-integers. Out of curiosity, how would > you calculate: > > sin(sqrt(7)*pi/31) > > using bignums? > It's a bit of a stretch, but you could wrap a fixed slash implementation around bignums to do this. http://portal.acm.org/citation.cfm?id=1309566 Fixed slash is like a rational, but you never let the numerator or denominator grow huge, instead reducing the precision of the fraction now and then to keep things manageable. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dunpealer at gmail.com Tue May 3 12:31:06 2011 From: dunpealer at gmail.com (Dun Peal) Date: Tue, 3 May 2011 09:31:06 -0700 (PDT) Subject: Why do directly imported variables behave differently than those attached to imported module? Message-ID: Hi! Here's the demonstrating code: # module foo.py var = 0 def set(): global var var = 1 Script using this module: import foo from foo import * print var, foo.var set() print var, foo.var Script output: 0 0 0 1 Apparently, the `var` we imported from `foo` never got set, but `foo.var` on the imported `foo` - did. Why? Thanks, D. From python at rcn.com Tue May 3 12:32:19 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 3 May 2011 09:32:19 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> <929lmdF59lU1@mid.individual.net> Message-ID: <5099131d-f60d-4c61-b69f-4666fb25c229@f15g2000pro.googlegroups.com> On May 2, 11:29?pm, Gregory Ewing wrote: > Terry Reedy wrote: > > The trick is that replacing x with j and evaluating > > therefore causes (in Python) all the coefficients of x (now j) to be > > added together separately from all the constant terms to reduce the > > linear equation to a*x+b (= 0 implied). > > Hmmm... so if we used quaternions, could we solve systems > of linear equations in 3 variables? Yes :-) The implementation of a Quanternion class and the Quartic equation is left as an exercise for the reader ;-) Raymond @raymondh From mwilson at the-wire.com Tue May 3 12:33:15 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 03 May 2011 12:33:15 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hans Georg Schaathun wrote: > On 01 May 2011 08:45:51 GMT, Steven D'Aprano > wrote: > : Python uses a data model of "name binding" and "call by object" (also > : known as "call by sharing"). I trust I don't need to define my terms, > : but just in case: > > Without having the time to get my hand around exactly what this means: > Simula has three ways of transmitting arguments, namely transmission > by name, by value, and by reference. Is transmission by name the same > as call by object? Anyway, I have never seen anyone counting more than > three ways of doing this ... To illustrate the neither-fish-nor-fowl nature of Python calls: mwilson at tecumseth:~$ python 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. >>> def identify_call (a_list): ... a_list[0] = "If you can see this, you don't have call-by-value" ... a_list = ["If you can see this, you have call-by-reference"] ... >>> my_list = [None] >>> identify_call (my_list) >>> my_list ["If you can see this, you don't have call-by-value"] so it's neither call-by-value nor call-by-reference as (e.g.) C or PL/I programming would have it (don't know about Simula, so I am off topic, actually.) It's not so wrong to think of Python's parameter handling as ordinary assignments from outer namespaces to an inner namespace. Mel. From python at rcn.com Tue May 3 12:43:41 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 3 May 2011 09:43:41 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On May 2, 10:04?pm, Stefan Behnel wrote: > The bad thing about this recipe is that it requires quite a bit of > background knowledge in order to infer that the code the developer is > looking at is actually correct. At first sight, it looks like an evil hack, > and the lack of documentation doesn't help either. The recipe is cool in the same way that a magic trick is cool. A practical recipe would use a more general purpose method (perhaps using finite differences or continued fractions); it would have documentation and tests; it would accept a regular python function instead of a string; and it would avoid an unsanitized eval(). But then it would completely lose its panache, its flourish, and the pleasant gratification that you get when solving the riddle of how it works. We should have a separate thread for the most practical, best documented, least surprising, and most boring recipe ;-) Raymond From stefan.kuzminski at gmail.com Tue May 3 12:48:27 2011 From: stefan.kuzminski at gmail.com (Stefan Kuzminski) Date: Tue, 3 May 2011 12:48:27 -0400 Subject: Pickling extension types Message-ID: Hi all, I have an extension type written in C, but I cannot get it to pickle, any insights would be greatly appreciated. I see in the docs that I should define a __reduce__ method and that does get called, but I don't know specifically the type of the 'callable object' that should be the first thing in the tuple returned by __reduce__. thx, S start listing.. #include "Python.h" static PyObject *mv_new(PyTypeObject *type, PyObject *args, PyObject *kw); static int mv_cmp(PyObject *self, PyObject *other); /* * print MV */ static PyObject *mv_repr(MV *mv){ PyObject *rtn; rtn = PyString_FromFormat("MV(%d)", mv->index); return rtn; } /* * get mv's index */ static PyObject *mv_idx(PyObject *self, PyObject *ags){ MV *mv; mv = (MV*)self; return PyInt_FromLong( (long)mv->index ); } /* * get mv's index as str */ static PyObject *mv_reduce(PyObject *self, PyObject *ags){ MV *mv; mv = (MV*)self; return PyString_FromString( "foo" ); } /* * get mv's index as str */ static PyObject *mv_reduce(PyObject *self, PyObject *ags){ MV *mv; mv = (MV*)self; PyObject *return_tuple; // build the return tuple return_tuple = PyTuple_New(5); // THIS IS THE QUESTION, what to set as "callable object??" // PyTuple_SetItem( return_tuple, 0, mv_new ); PyTuple_SetItem( return_tuple, 1 PyTuple_New()); return return_tuple; } static PyMethodDef mv_methods[] = { {"index", mv_idx, METH_VARARGS}, {"__reduce__", mv_reduce, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; PyTypeObject PyMV_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /* Number of items for varobject */ "MV", /* Name of this type */ sizeof(MV), /* Basic object size */ 0, /* Item size for varobject */ (destructor)PyObject_Del, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ mv_cmp, /* tp_compare */ (reprfunc)mv_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ mv_idx, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ PyObject_GenericSetAttr, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ 0, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ mv_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ mv_new, /* tp_new */ }; /* * cmp MV */ static int mv_cmp(PyObject *mv, PyObject *other){ if( other->ob_type == &PyMV_Type ) { if( ((MV*)mv)->index == ((MV*)other)->index ) { return 0; } else { return -1; } } return -1; } /* * new MV */ static PyObject *mv_new(PyTypeObject *type, PyObject *args, PyObject *kw){ MV *mv; int index; mv = PyObject_New(MV, &PyMV_Type); if (mv == NULL){ return NULL; } // get the args if( !PyArg_ParseTuple( args,(char *)"i:MV", &index )){ return NULL; } // store index mv->index = index; return (PyObject*)mv; } -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Tue May 3 12:51:20 2011 From: debatem1 at gmail.com (geremy condra) Date: Tue, 3 May 2011 09:51:20 -0700 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> <929lmdF59lU1@mid.individual.net> Message-ID: On Tue, May 3, 2011 at 8:49 AM, Terry Reedy wrote: > On 5/3/2011 2:29 AM, Gregory Ewing wrote: >> >> Terry Reedy wrote: >>> >>> The trick is that replacing x with j and evaluating therefore causes >>> (in Python) all the coefficients of x (now j) to be added together >>> separately from all the constant terms to reduce the linear equation >>> to a*x+b (= 0 implied). >> >> Hmmm... so if we used quaternions, could we solve systems >> of linear equations in 3 variables? > > Yes and no. The use of 1*j merely collected and added together all the > multipliers of 'x' (and all the constant terms). That is a fairly trivial > matter of constant folding. Systems of linear equations are usually > presented in that form already. The actual solution to the simple equation > is in the formula x = -a/b (where a and b are the sums). The solution > formula for three variables would be far more complex. Or just use a gauss-jordan solver, which has the advantage of being easy to explain and possible to verify by hand on small instances. Geremy Condra From invalid at invalid.invalid Tue May 3 12:52:26 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 3 May 2011 16:52:26 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-03, Mel wrote: > To illustrate the neither-fish-nor-fowl nature of Python calls: > > mwilson at tecumseth:~$ python > 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. >>>> def identify_call (a_list): > ... a_list[0] = "If you can see this, you don't have call-by-value" > ... a_list = ["If you can see this, you have call-by-reference"] > ... >>>> my_list = [None] >>>> identify_call (my_list) >>>> my_list > ["If you can see this, you don't have call-by-value"] > > so it's neither call-by-value nor call-by-reference as (e.g.) C or PL/I > programming would have it (don't know about Simula, so I am off topic, > actually.) It's not so wrong to think of Python's parameter handling as > ordinary assignments from outer namespaces to an inner namespace. As long as you think of "ordinary assignments" the Python way and not the C or PL/I way. :) -- Grant Edwards grant.b.edwards Yow! So this is what it at feels like to be potato gmail.com salad From dan.kluev at gmail.com Tue May 3 12:57:51 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Wed, 4 May 2011 03:57:51 +1100 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 3:31 AM, Dun Peal wrote: > Apparently, the `var` we imported from `foo` never got set, but > `foo.var` on the imported `foo` - did. Why? Because all names are references to some values, not other names (in CPython, it means all names are PyObject*, and point directly to the objects, not other pointers) When you do `from foo import bar` it assigns globals()['bar'] of current module to reference same value as `foo.bar`. Its now local namespace name, not `foo` namespace, and therefore functions in `foo` cannot modify this namespace. Since ints are immutable, when you do `var = 1` you create new object of type int, and re-assign `var` name to point to new object. `foo.var`, on other hand, is a way to access `foo`'s own namespace, so its exactly same name as globals()['var'] of `foo`. -- With best regards, Daniel Kluev From clp2 at rebertia.com Tue May 3 12:57:53 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 3 May 2011 09:57:53 -0700 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: On Tue, May 3, 2011 at 9:31 AM, Dun Peal wrote: > Hi! > > Here's the demonstrating code: > > ? ?# module foo.py > ? ?var = 0 > > ? ?def set(): > ? ? ? ?global var > ? ? ? ?var = 1 > > Script using this module: > > ? ?import foo > ? ?from foo import * > > ? ?print var, foo.var > ? ?set() > ? ?print var, foo.var > > Script output: > > ? ?0 0 > ? ?0 1 > > Apparently, the `var` we imported from `foo` never got set, but > `foo.var` on the imported `foo` - did. Why? Because imports (and assignments generally) bind names to values, they don't alias names to other names. from foo import * can be thought of as essentially doing: import foo set = foo.set var = foo.var del foo So the new, separate name __main__.var gets the current value of foo.var at import-time, which is the integer 0. You then call foo.set(), which re-binds foo.var to a new value (i.e. 1) rather than mutating the existing value (which would be impossible anyway since integers are immutable). This has absolutely no effect on __main__.var, which is an entirely separate binding. The behavior is comparable to that of function arguments. Values can be mutated, but re-binding names has only local effect: >>> a = 0 >>> def incr(b): ... b = 1 # rebinds local name b ... >>> incr(a) >>> a # outside name unaffected, just like in your example 0 >>> c = [7] >>> def mutate_then_rebind(b): ... b.append(99) # mutates passed-in value ... b = [42] # rebinds local name; has no outside effect ... >>> mutate_then_rebind(c) >>> c # name still references same obj, but that obj has been mutated [7, 99] Cheers, Chris -- http://rebertia.com From mwilson at the-wire.com Tue May 3 13:00:28 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 03 May 2011 13:00:28 -0400 Subject: Why do directly imported variables behave differently than those attached to imported module? References: Message-ID: Dun Peal wrote: > Hi! > > Here's the demonstrating code: > > # module foo.py > var = 0 > > def set(): > global var > var = 1 > > Script using this module: > > import foo > from foo import * > > print var, foo.var > set() > print var, foo.var > > Script output: > > 0 0 > 0 1 > > Apparently, the `var` we imported from `foo` never got set, but > `foo.var` on the imported `foo` - did. Why? They're different because -- they're different. `foo.var` is defined in the namespace of the foo module. Introspectively, you would access it as `foo.__dict__['var']` . Plain `var` is in your script's namespace so you could access it as `globals()['var']` . The values given to the vars are immutable integers, so assignment works by rebinding. The two different bindings in foo.__dict__ and globals() get bound to different integer objects. Note too the possible use of `globals()['foo'].__dict__['var'] . (Hope there are no typos in this post.) Mel. From harrismh777 at charter.net Tue May 3 13:10:04 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 03 May 2011 12:10:04 -0500 Subject: Fibonacci series recursion error In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: Chris Angelico wrote: > The recursion is in the last block. Note that it calls a function, > then keeps going. It doesn't fork. There are two CALL_FUNCTION > opcodes, called*sequentially*. In terms of the call stack, there is > only ever one of those two calls active at any given time. RuntimeError: maximum recursion depth exceeded in comparison [36355 refs] can any one help [ @ Ian, Chris, Thomas ] Thanks, guys, but I think y'all are still missing my point/question, as interesting as these discussions are... something is wrong (might be my understanding)... ... CPython must be making function calls by placing stack-frames on the call stack... which has a relatively small limit. Python does crappy tail optimization (one of the reasons to avoid recursion in Python) and yes, this is an infinite recursion... doh... but the main point for this part of the discussion is that the "maximum recursion depth exceeded in comparison" runtime error is posted because there are more stack-frames being posted to the call stack than there is call-stack to hold them! We might change this with sys.setrecursionlimit, but that's dangerous; but the bottom line is that in order for the recursion depth runtime error to be posted, somebody placed too many stack-frames on the call stack... in this case about 36,355 of them... yes, the base-case is coded wrong and the process is infinite, the point is that tail processing doesn't even get to run... the silly thing pummels the call stack with stack-frames (obviously exceeding 20) and the runtime error is posted. If your point is that the infinite process is the problem, I agree. But my point is that the cpu crunch and the rate at which the call stack is filled has to do with the double call (which never finds tail processing). What am I missing here>? From robert.kern at gmail.com Tue May 3 13:10:23 2011 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 May 2011 12:10:23 -0500 Subject: Pickling extension types In-Reply-To: References: Message-ID: On 5/3/11 11:48 AM, Stefan Kuzminski wrote: > Hi all, > > I have an extension type written in C, but I cannot get it to pickle, any > insights would be greatly appreciated. > > I see in the docs that I should define a __reduce__ method and that does get > called, but I don't know specifically the type of the 'callable object' that > should be the first thing in the tuple returned by __reduce__. It should be a callable PyObject* that takes the arguments given in the rest of the tuple. Often, this is just the type itself. So probably (PyObject*)PyMV_Type, if you give the right arguments in the rest of the tuple. -- 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 Tue May 3 13:13:12 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 May 2011 13:13:12 -0400 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: Your problem is reveal in the subject line. As discussed in many other threads, including a current one, Python does not have 'variables' in the way that many understand the term. Python binds names to objects. Binding statements (assignment, augmented assignment, import, def, class, and others with 'as' clauses) all bind names to objects. Suppose we both have address books. You copy all entries from my book to yours. Afterwards, I update an entry in my book. That does not change the now obsolete entry in your book. On 5/3/2011 12:31 PM, Dun Peal wrote: > # module foo.py > var = 0 > > def set(): > global var > var = 1 Module foo's dict now has two entries for 'var' and 'set' bound to int 0 and a function. Note that 'set' is a builtin class name so not the best choice. > > Script using this module: Script creates module '__main__' > import foo This binds 'foo' to module foo in __main_'s dict. > from foo import * This copies foo's dict to __main__'s dict. > print var, foo.var > set() This changes foo's dict, rebinding 'var' to int 1. It does not change __main__'s dict. How could it? In the same way, 'var = 2' would leave foo's dict unchanged. __main__.var. > print var, foo.var > > Script output: > > 0 0 > 0 1 If instead of 'from foo import *', you had written 'from foo import var as rav', then perhaps you would not have been so surprised that __main__.rav and foo.var have independent fates. You have discovered that using from x import * is a bad idea when module x has global names that get rebound. -- Terry Jan Reedy From harrismh777 at charter.net Tue May 3 13:24:43 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 03 May 2011 12:24:43 -0500 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: Dun Peal wrote: > # module foo.py > var = 0 > > def set(): > global var > var = 1 My two cents to add in addition to the correct accounts of [ Daniel, Chris, Mel] is that you might have a misunderstanding of var, generally. Python has no variables--- in the way you think of them in other languages. Python only has references. Var is not 'set' in the classical sense of the word... var is a 'reference' (think C pointer, sort-of) to an object... '0' and '1' are objects of type int and var=0 means create a reference to object int('0') called var. a=b=0 a is a reference to object '0' b is a reference to object '0' a does not reference b This rest of the discussion has to do with name spaces: See: http://docs.python.org/release/3.0.1/reference/datamodel.html?highlight=namespaces From nicolabranzolihc at gmail.com Tue May 3 13:33:39 2011 From: nicolabranzolihc at gmail.com (Nicola Branzoli) Date: Tue, 3 May 2011 10:33:39 -0700 (PDT) Subject: Python to accept terms and conditions of a website Message-ID: <1ce933c0-57be-44b0-884a-e20e1dae5773@d26g2000prn.googlegroups.com> Hey, I am writing a code in python to access public data online (using BeautifulSoup). The task is relatively easy but the code does not get to the page because I need to accept the terms and condition of the website first (by a standard click 'Accept' button). I need to tell python how to automatically accept the terms and condition and proceed to the web address specified. I am new in pyhton, my guess is that I have to use mechanize because cookielib is not good for this job. Am I right? What other resources can I use? Any link with an example similar to my problem would be super-duper... n From __peter__ at web.de Tue May 3 13:39:27 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 May 2011 19:39:27 +0200 Subject: Pickling extension types References: Message-ID: Stefan Kuzminski wrote: > I have an extension type written in C, but I cannot get it to pickle, any > insights would be greatly appreciated. > > I see in the docs that I should define a __reduce__ method and that does > get called, but I don't know specifically the type of the 'callable > object' that should be the first thing in the tuple returned by > __reduce__. I haven't written a python extension in C, but I would approach the problem by looking for prior art in the stdlib, preferably a simple class: >>> 1j.__reduce__() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/copy_reg.py", line 70, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle complex objects OK, complex does something else... * One grep through the source later: >>> slice(1,2,3).__reduce__() (, (1, 2, 3)) And the implementation seems straightforward: static PyObject * slice_reduce(PySliceObject* self) { return Py_BuildValue("O(OOO)", Py_TYPE(self), self->start, self->stop, self->step); } (*) it uses __getnewargs__ From as at sci.fi Tue May 3 14:19:06 2011 From: as at sci.fi (Anssi Saari) Date: Tue, 03 May 2011 21:19:06 +0300 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> Message-ID: rusi writes: > I am a bit surprised that no one has mentioned rcs so far > Not an option if you are not on a *ix system and not something I am > specifically recommending. I actually use rcs in Windows. Needs a little setup, but works great, from Emacs VC-mode too. From jacek2v at gmail.com Tue May 3 14:31:12 2011 From: jacek2v at gmail.com (jacek2v) Date: Tue, 3 May 2011 11:31:12 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <3a93d484-ca0a-41d9-afdb-509cfdcc918b@e21g2000yqe.googlegroups.com> Message-ID: <6f503249-5f94-4e1b-a966-5e0f2b6e32e6@a18g2000yqj.googlegroups.com> On May 2, 12:38?pm, Algis Kabaila wrote: > On Monday 02 May 2011 19:09:38 jacek2v wrote: > > > > > > > > > > > On May 2, 9:48 am, Algis Kabaila wrote: > > > On Monday 02 May 2011 17:19:57 rusi wrote: > > > > On May 2, 12:08 pm, Algis Kabaila > > > > wrote: > > > > > Actually, Bazaar is more convenient than rcs for a > > > > > single user, as the repository can be the working > > > > > directory (with a "hidden" .bzr directory that stores > > > > > diffs). > > > > > Dont exactly understand... > > > > Is it that you want it specifically hidden? > > > > Otherwise rcs will look inside an RCS directory just as > > > > bzr will with .bzr git will with .git and so on. > > > > Sorry for not being clear - "ls" will not show directories > > > that start with "." - in that sense these directories are > > > "hidden". They are not really really hidden, as "ls ?-l" > > > will show them. They simply are not in the way and keep > > > the progressive versions of the program (in form of > > > diffs). > > > "ls -l will not show directories that start with ".". > > "ls -a" will. > > > Regards > > Jacek > > Thanks - you are right - pardon my absent mindedness. > > -- > Algishttp://akabaila.pcug.org.au/StructuralAnalysis.pdf You're welcome :) From rustompmody at gmail.com Tue May 3 14:50:38 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 3 May 2011 11:50:38 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> Message-ID: On May 3, 11:19?pm, Anssi Saari wrote: > rusi writes: > > I am a bit surprised that no one has mentioned rcs so far > > Not an option if you are not on a *ix system and not something I am > > specifically recommending. > > I actually use rcs in Windows. Needs a little setup, but works great, > from Emacs VC-mode too. Where do you get it? [What google is showing seems to be about 10-15 years old] From dunpealer at gmail.com Tue May 3 14:51:03 2011 From: dunpealer at gmail.com (Dun Peal) Date: Tue, 3 May 2011 11:51:03 -0700 (PDT) Subject: Why do directly imported variables behave differently than those attached to imported module? References: Message-ID: OK, I understand now. `from foo import var` means "create a module-global name `var` inside the current module, and have it point at the object `foo.var` is pointing at (following its evaluation)". Naturally, regardless of whether `foo.var` ever changes, the global `var` of the current module still points at the original object `foo.var` was pointing to at the time of the `var = foo.var` assignment. Thanks, D. From roman.suzi at gmail.com Tue May 3 15:15:16 2011 From: roman.suzi at gmail.com (rnd) Date: Tue, 3 May 2011 12:15:16 -0700 (PDT) Subject: Pushing for Pythoncard 1.0 References: <6d896b66-3933-4743-8eb5-b9754f1ec14f@t19g2000prd.googlegroups.com> Message-ID: <5348cf4b-ffd2-41f0-a7a5-afedc00ed703@b35g2000yqn.googlegroups.com> On May 2, 10:48?pm, John Henry wrote: > Attempt to push Pythoncard to a 1.0 status is now underway. ?A > temporary website has been created at: > > http://code.google.com/p/pythoncard-1-0/ > > The official website continues to behttp://pythoncard.sourceforge.net/ > > Pythoncard is such a wonderful package that it would be a shame to > allow development for the package to go stagnant. ? The Python > community deserves to continue enjoying the simplicity of Pythoncard > for creating a GUI Python application. I was very positively surprised to hear someone talking about PythonCard these days. Even though I've not needed to develop GUI apps for years, I believe its still great idea to revive PythonCard even though everybody is busy developing for "iThings" right now. Regards, Roman Suzi From dunpealer at gmail.com Tue May 3 15:23:15 2011 From: dunpealer at gmail.com (Dun Peal) Date: Tue, 3 May 2011 12:23:15 -0700 (PDT) Subject: Why do directly imported variables behave differently than those attached to imported module? References: Message-ID: <5299438d-611f-4a63-b1d8-4abe039ad5d4@k3g2000prl.googlegroups.com> P.S. now I have to ask: is there a symbolic reference in Python, i.e. a name foo that points to "whatever bar.baz is pointing at"? Thanks, D. From zdoor at xs4all.nl Tue May 3 15:50:31 2011 From: zdoor at xs4all.nl (Alex van der Spek) Date: Tue, 3 May 2011 21:50:31 +0200 Subject: Appending to dictionary of lists Message-ID: <4dc05c8b$0$41117$e4fe514c@news.xs4all.nl> I open a csv file and create a DictReader object. Subsequently, reading lines from this file I try to update a dictionary of lists: csvf=open(os.path.join(root,fcsv),'rb') csvr=csv.DictReader(csvf) refd=dict.fromkeys(csvr.fieldnames,[]) for row in csvr: for (k,v) in row.items(): refd[k].append(v) I do not understand why this appends v to every key k each time. Thanks in advance for any tips you can pass on. Alex van der Spek From dan.kluev at gmail.com Tue May 3 15:55:04 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Wed, 4 May 2011 06:55:04 +1100 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: <5299438d-611f-4a63-b1d8-4abe039ad5d4@k3g2000prl.googlegroups.com> References: <5299438d-611f-4a63-b1d8-4abe039ad5d4@k3g2000prl.googlegroups.com> Message-ID: On Wed, May 4, 2011 at 6:23 AM, Dun Peal wrote: > P.S. now I have to ask: is there a symbolic reference in Python, i.e. > a name foo that points to "whatever bar.baz is pointing at"? Well, you could easily simulate that with proxy object, class SymbolicReference(object): def __init__(self, ns, name): self.__ns = ns self.__name = name def __get(self): return self.__ns[self.__name] def __getattribute__(self, attr): try: return object.__getattribute__(self, attr) except: return self.__get().__getattribute__(attr) def __repr__(self): return self.__get().__repr__() def __str__(self): return self.__get().__str__() >>> a = 1 >>> b = SymbolicReference(globals(), 'a') >>> b 1 >>> a = 10 >>> b 10 -- With best regards, Daniel Kluev From no.email at nospam.invalid Tue May 3 15:56:44 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 03 May 2011 12:56:44 -0700 Subject: Appending to dictionary of lists References: <4dc05c8b$0$41117$e4fe514c@news.xs4all.nl> Message-ID: <7x7ha75zib.fsf@ruckus.brouhaha.com> "Alex van der Spek" writes: > refd=dict.fromkeys(csvr.fieldnames,[]) ... > I do not understand why this appends v to every key k each time. You have initialized every element of refd to the same list. Try refd = dict((k,[]) for k in csvr.fieldnames) instead. From drsalists at gmail.com Tue May 3 16:16:09 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 3 May 2011 13:16:09 -0700 Subject: Appending to dictionary of lists In-Reply-To: <7x7ha75zib.fsf@ruckus.brouhaha.com> References: <4dc05c8b$0$41117$e4fe514c@news.xs4all.nl> <7x7ha75zib.fsf@ruckus.brouhaha.com> Message-ID: On Tue, May 3, 2011 at 12:56 PM, Paul Rubin wrote: > "Alex van der Spek" writes: > > refd=dict.fromkeys(csvr.fieldnames,[]) ... > > I do not understand why this appends v to every key k each time. > > You have initialized every element of refd to the same list. Try > > refd = dict((k,[]) for k in csvr.fieldnames) > > instead. > -- > http://mail.python.org/mailman/listinfo/python-list > Agreed. Here's another way: using a dictionary comprehension - a feature in 2.7 and up: #!/usr/local/cpython-2.7/bin/python import csv import pprint csvf=open('foo.csv','rb') csvr=csv.DictReader(csvf) #refd=dict.fromkeys(csvr.fieldnames, []) refd = { key: [] for key in csvr.fieldnames } for row in csvr: for (k,v) in row.items(): refd[k].append(v) pprint.pprint(refd) -------------- next part -------------- An HTML attachment was scrubbed... URL: From zdoor at xs4all.nl Tue May 3 16:20:00 2011 From: zdoor at xs4all.nl (Alex van der Spek) Date: Tue, 3 May 2011 22:20:00 +0200 Subject: Appending to dictionary of lists In-Reply-To: <7x7ha75zib.fsf@ruckus.brouhaha.com> References: <4dc05c8b$0$41117$e4fe514c@news.xs4all.nl> <7x7ha75zib.fsf@ruckus.brouhaha.com> Message-ID: <4dc06377$0$41110$e4fe514c@news.xs4all.nl> Thank you! Would never have found that by myself. "Paul Rubin" wrote in message news:7x7ha75zib.fsf at ruckus.brouhaha.com... > "Alex van der Spek" writes: >> refd=dict.fromkeys(csvr.fieldnames,[]) ... >> I do not understand why this appends v to every key k each time. > > You have initialized every element of refd to the same list. Try > > refd = dict((k,[]) for k in csvr.fieldnames) > > instead. From hg at schaathun.net Tue May 3 16:47:04 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 3 May 2011 21:47:04 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <876698-vjj.ln1@svn.schaathun.net> On Tue, 03 May 2011 12:33:15 -0400, Mel wrote: : mwilson at tecumseth:~$ python : 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. : >>> def identify_call (a_list): : ... a_list[0] = "If you can see this, you don't have call-by-value" : ... a_list = ["If you can see this, you have call-by-reference"] : ... : >>> my_list = [None] : >>> identify_call (my_list) : >>> my_list : ["If you can see this, you don't have call-by-value"] This looks like plain old transmission by reference to me. I.e. the functions get a reference to an object and make any change to the object. Since the caller and the callee refer to the same object, changes made by the callee are seen by the caller. However, the reference cannot be changed. With transmission by name, you would get what you call call-by-reference; i.e. the variable passed as an argument is changed to refer to a completely new object. In simula this is used for output parameters. And transmission by value is of course a copy of the data. : so it's neither call-by-value nor call-by-reference as (e.g.) C or PL/I I don't know PL/I; that's the sort of thing my mother deals with. Simula explicitely offerts all three. In C you can get each of the three, by using pointers explicitely in different ways. Whether you use C or Simula, transmission by reference, that is what python appears to be doing, seems to be the normal approach for any composite data type. Thus python does not seem to do anything out of the ordinary at all. -- :-- Hans Georg From hg at schaathun.net Tue May 3 17:10:52 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 3 May 2011 22:10:52 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc01d4a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03 May 2011 15:20:42 GMT, Steven D'Aprano wrote: : You get credit for not falling into the trap of thinking there are only : two, call by reference and call by value, but there are *many* more than : just three. Wikipedia lists at least 13: Ah. Those 13 approaches aren't all mutually exclusive though. -- :-- Hans Georg From stefan.kuzminski at gmail.com Tue May 3 17:34:06 2011 From: stefan.kuzminski at gmail.com (Stefan Kuzminski) Date: Tue, 3 May 2011 17:34:06 -0400 Subject: Pickling extension types Message-ID: Thanks for the clues, I made a modification so that reduce returns this.. return Py_BuildValue("O(OOOOO)", Py_TYPE(self), PyTuple_New(0), Py_None, Py_None, Py_None ); and now I get this different error when trying to pickle the type.. ---------------------------------------------------------------------- Traceback (most recent call last): File "test_missing.py", line 16, in test print cPickle.dumps( mv ) PicklingError: Can't pickle : attribute lookup __builtin__.MV failed thx, S One grep through the source later: > > >>> slice(1,2,3).__reduce__() > (, (1, 2, 3)) > > And the implementation seems straightforward: > > static PyObject * > slice_reduce(PySliceObject* self) > { > return Py_BuildValue("O(OOO)", Py_TYPE(self), self->start, self->stop, > self->step); > } > > > > (*) it uses __getnewargs__ > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 3 17:41:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 07:41:32 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Wed, May 4, 2011 at 3:10 AM, harrismh777 wrote: > If your point is that the infinite process is the problem, I agree. But my > point is that the cpu crunch and the rate at which the call stack is filled > has to do with the double call (which never finds tail processing). The double call _does not_ affect it. Failing to terminate recursion _does_. I don't know what you mean by "cpu crunch" but the call stack is going to get n entries. On the Python 2.6 on this system, sys.getrecursionlimit() returns 1000, meaning that you can calculate fib(1000) safely (okay, probably not quite as there'll be a few used for other things, but fib(900) would be safe). Chris Angelico From rosuav at gmail.com Tue May 3 17:47:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 07:47:17 +1000 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 2:57 AM, Chris Rebert wrote: > from foo import * > > can be thought of as essentially doing: > > import foo > set = foo.set > var = foo.var > del foo Here's a side point. What types will hold a reference to the enclosing module (or at least its dictionary)? Would it be possible to use a from import to load a module, then "lose" the module even though you're using objects from it? I am guessing that a function or class will hold such a reference, because otherwise it would be a bit awkward for them to use any sort of module-level state. Or do they not, and instead go look for their module in sys.modules? Chris Angelico From rosuav at gmail.com Tue May 3 17:54:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 07:54:12 +1000 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On Wed, May 4, 2011 at 2:43 AM, Raymond Hettinger wrote: > We should have a separate thread for the most practical, best > documented, least surprising, and most boring recipe ;-) a += b # Adds b to a in-place. Polymorphic - works on a wide variety of types. You didn't say it had to be complicated... Chris Angelico From rosuav at gmail.com Tue May 3 18:00:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 08:00:35 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <876698-vjj.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <876698-vjj.ln1@svn.schaathun.net> Message-ID: On Wed, May 4, 2011 at 6:47 AM, Hans Georg Schaathun wrote: > This looks like plain old transmission by reference to me. > I.e. the functions get a reference to an object and make any > change to the object. "Reference" being exactly what's passed around. There are now two references to that object. Since names always contain references (not objects), it's very easy to share mutable objects (lists/dictionaries/etc). There's an easy way for a caller or callee to guarantee that a mutable is safe - just slice it: identify_call(my_list[:]) That gives the called function a shallow copy of the list, which it can modify to its heart's content, but the original list isn't changed. Callee can do the same, with an assignment command at the top of the function (a_list=a_list[:]). Chris Angelico From robert.kern at gmail.com Tue May 3 18:05:23 2011 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 May 2011 17:05:23 -0500 Subject: Pickling extension types In-Reply-To: References: Message-ID: On 5/3/11 4:34 PM, Stefan Kuzminski wrote: > Thanks for the clues, I made a modification so that reduce returns this.. > > return Py_BuildValue("O(OOOOO)", Py_TYPE(self), PyTuple_New(0), Py_None, > Py_None, Py_None ); > > and now I get this different error when trying to pickle the type.. > > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "test_missing.py", line 16, in test > print cPickle.dumps( mv ) > PicklingError: Can't pickle : attribute lookup __builtin__.MV failed You need to do two things: 1. Set tp_name to something like "mymodule.MV" where "mymodule" is the name of your extension module. 2. Make sure that you add the type object to your module's namespace. PyMODINIT_FUNC initmymodule(void) { ... Py_INCREF(&PyMV_Type); PyModule_AddObject(m, "MV", (PyObject*)&PyMV_Type); } C.f. http://docs.python.org/extending/newtypes.html -- 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 jabba.laci at gmail.com Tue May 3 18:08:27 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 3 May 2011 18:08:27 -0400 Subject: vertical ordering of functions Message-ID: Hi, I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. 5 he says that a function that is called should be below a function that does the calling. This creates a nice flow down from top to bottom. However, when I write a Python script I do just the opposite. I start with the lines if __name__ == "__main__": main() Then I add main() above, which is a control function that contains some function calls that decompose the problem into subproblems. Then I add these functions above, etc. Is there a convention for this? Should main() be at the top and called function below? Thanks, Laszlo From ian.g.kelly at gmail.com Tue May 3 18:10:42 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 May 2011 16:10:42 -0600 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On Tue, May 3, 2011 at 3:54 PM, Chris Angelico wrote: > On Wed, May 4, 2011 at 2:43 AM, Raymond Hettinger wrote: >> We should have a separate thread for the most practical, best >> documented, least surprising, and most boring recipe ;-) > > a += b ? # Adds b to a in-place. Polymorphic - works on a wide variety of types. Too surprising to qualify. For some types it modifies a, while for others it replaces a. From clp2 at rebertia.com Tue May 3 18:11:48 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 3 May 2011 15:11:48 -0700 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: On Tue, May 3, 2011 at 2:47 PM, Chris Angelico wrote: > On Wed, May 4, 2011 at 2:57 AM, Chris Rebert wrote: >> from foo import * >> >> can be thought of as essentially doing: >> >> import foo >> set = foo.set >> var = foo.var >> del foo > > Here's a side point. What types will hold a reference to the enclosing > module (or at least its dictionary)? Would it be possible to use a > from import to load a module, then "lose" the module even though > you're using objects from it? > > I am guessing that a function or class will hold such a reference, > because otherwise it would be a bit awkward for them to use any sort > of module-level state. Or do they not, and instead go look for their > module in sys.modules? some_python_function.__globals__ is the exact reference you postulated. Classes don't seem to hold such references; their methods do though (by virtue of being function objects), which makes sense. Cheers, Chris -- http://rebertia.com From python at rcn.com Tue May 3 18:19:25 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 3 May 2011 15:19:25 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On May 2, 11:23?pm, Stefan Behnel wrote: > Terry Reedy, 03.05.2011 08:00: > > > On 5/3/2011 1:04 AM, Stefan Behnel wrote: > > >> The bad thing about this recipe is that it requires quite a bit of > >> background knowledge in order to infer that the code the developer is > >> looking at is actually correct. > > > The main math knowledge needed is the trivial fact that if a*x + b = 0, > > then x = -b/a. The other math knowledge needed is that complex numbers add > > componentwise. The trick is that replacing x with j and evaluating > > therefore causes (in Python) all the coefficients of x (now j) to be added > > together separately from all the constant terms to reduce the linear > > equation to a*x+b (= 0 implied). > > As your above paragraph proves, it's the kind of implementation that > requires three lines of executing code and at least 6 lines of additional > comment. Hopefully accompanied by an excuse of the developer. If you found nothing educational, interesting, or amusing about the three-line linear equation solver, then you're *really* going to hate this one: http://groups.google.com/group/comp.lang.python/browse_frm/thread/e46de4596e93188b/ Raymond @raymondh From rosuav at gmail.com Tue May 3 18:31:18 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 08:31:18 +1000 Subject: vertical ordering of functions In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 8:08 AM, Jabba Laci wrote: > Hi, > > I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. > 5 he says that a function that is called should be below a function > that does the calling. This creates a nice flow down from top to > bottom. I prefer to define my terms before I use them. Classes, functions, etc get defined at the top and called down below. It's a stylistic thing, but it ties in with what you would do in a debate or scholarly document; and if you're skimming such a document and you don't understand a term, you know to scan upwards for its definition. It's just a stylistic thing, you can do it whichever way you think best! Chris Angelico From ian.g.kelly at gmail.com Tue May 3 18:31:29 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 May 2011 16:31:29 -0600 Subject: Fibonacci series recursion error In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Tue, May 3, 2011 at 3:41 PM, Chris Angelico wrote: > On Wed, May 4, 2011 at 3:10 AM, harrismh777 wrote: >> If your point is that the infinite process is the problem, I agree. But my >> point is that the cpu crunch and the rate at which the call stack is filled >> has to do with the double call (which never finds tail processing). > > The double call _does not_ affect it. Failing to terminate recursion > _does_. I don't know what you mean by "cpu crunch" but the call stack > is going to get n entries. On the Python 2.6 on this system, > sys.getrecursionlimit() returns 1000, meaning that you can calculate > fib(1000) safely (okay, probably not quite as there'll be a few used > for other things, but fib(900) would be safe). Depends what you mean by "safe". A back-of-the-envelope calculation shows that with modern technology it would take more than 10 ** 257 years to complete. That puts it well into the Dark Era of the universe, long after the black holes will have decayed, when I suspect it will be difficult to find a continued power source for the computer to run. And even if it somehow is still running, the process memory will have been so thoroughly muddled by cosmic rays that the final result of the calculation will be utterly worthless. From python at mrabarnett.plus.com Tue May 3 18:46:59 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 03 May 2011 23:46:59 +0100 Subject: vertical ordering of functions In-Reply-To: References: Message-ID: <4DC085E3.8000807@mrabarnett.plus.com> On 03/05/2011 23:31, Chris Angelico wrote: > On Wed, May 4, 2011 at 8:08 AM, Jabba Laci wrote: >> Hi, >> >> I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. >> 5 he says that a function that is called should be below a function >> that does the calling. This creates a nice flow down from top to >> bottom. > > I prefer to define my terms before I use them. Classes, functions, etc > get defined at the top and called down below. It's a stylistic thing, > but it ties in with what you would do in a debate or scholarly > document; and if you're skimming such a document and you don't > understand a term, you know to scan upwards for its definition. > > It's just a stylistic thing, you can do it whichever way you think best! > You also need to remember that in Python, function and class definitions are _not_ declarations, but statements which have the effect of adding a name to the namespace. If you try to call a function before the flow of control has seen the function definition, you'll get a NameError. From rosuav at gmail.com Tue May 3 19:09:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 09:09:24 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Wed, May 4, 2011 at 8:31 AM, Ian Kelly wrote: > A back-of-the-envelope calculation > shows that with modern technology it would take more than 10 ** 257 > years to complete. Then I propose that Python be extended to allow for underlying hardware upgrades without terminating a script. This will be essential to the finding of answers to these vital questions. Chris Angelico From akabaila at pcug.org.au Tue May 3 19:25:57 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Wed, 4 May 2011 09:25:57 +1000 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: <201105040925.57912.akabaila@pcug.org.au> On Tuesday 03 May 2011 16:00:05 Terry Reedy wrote: > On 5/3/2011 1:04 AM, Stefan Behnel wrote: > > The bad thing about this recipe is that it requires quite a > > bit of background knowledge in order to infer that the > > code the developer is looking at is actually correct. > > The main math knowledge needed is the trivial fact that if > a*x + b = 0, then x = -b/a. The other math knowledge needed > is that complex numbers add componentwise. The trick is that > replacing x with j and evaluating therefore causes (in > Python) all the coefficients of x (now j) to be added > together separately from all the constant terms to reduce > the linear equation to a*x+b (= 0 implied). But the title of the project is wrong and misleading. In the description it says "linear equations solver" which suggests that it solves systems of linear equations - linalg. As has been pointed out, a "linear" equation can be solved by had in one line... OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Tue May 3 19:58:45 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 May 2011 09:58:45 +1000 Subject: vertical ordering of functions References: Message-ID: <87sjsvfia2.fsf@benfinney.id.au> Jabba Laci writes: > Is there a convention for this? Should main() be at the top and called > function below? No, it's Python convention for both of those to be at the end of the module. I follow the convention described by Guido van Rossum in . Essentially, the mainline code is all in a top-level function, which accepts command-line arguments in its ?argv? parameter, catches any ?SystemExit? exception, and returns the exit code for the program. The ?if __name__ == "__main__"? section does nothing but call that function, passing the ?sys.argv? value, then exit with the return value. This makes the whole behaviour of the program available for calling as a function, while the program works as expected when invoked as a program. Commonly I will name the function ?__main__?, but this is an artefact of my previously-held vain hope that this idiom would become special to Python and called automatically without the ?if __name__ ?? hack. Guido, and most others I've seen use this idiom, simply name the function ?main?. -- \ ?An idea isn't responsible for the people who believe in it.? | `\ ?Donald Robert Perry Marquis | _o__) | Ben Finney From robert.kern at gmail.com Tue May 3 20:17:49 2011 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 May 2011 19:17:49 -0500 Subject: vertical ordering of functions In-Reply-To: <4DC085E3.8000807@mrabarnett.plus.com> References: <4DC085E3.8000807@mrabarnett.plus.com> Message-ID: On 5/3/11 5:46 PM, MRAB wrote: > On 03/05/2011 23:31, Chris Angelico wrote: >> On Wed, May 4, 2011 at 8:08 AM, Jabba Laci wrote: >>> Hi, >>> >>> I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. >>> 5 he says that a function that is called should be below a function >>> that does the calling. This creates a nice flow down from top to >>> bottom. >> >> I prefer to define my terms before I use them. Classes, functions, etc >> get defined at the top and called down below. It's a stylistic thing, >> but it ties in with what you would do in a debate or scholarly >> document; and if you're skimming such a document and you don't >> understand a term, you know to scan upwards for its definition. >> >> It's just a stylistic thing, you can do it whichever way you think best! >> > You also need to remember that in Python, function and class > definitions are _not_ declarations, but statements which have the > effect of adding a name to the namespace. > > If you try to call a function before the flow of control has seen the > function definition, you'll get a NameError. That's not really the issue at hand. The advice is about how to order the definition of functions that call each other, not interspersing function calls at the top level. I'm willing to bet that there is no solid empirical evidence that one ordering would be preferred to another. I am further willing to bet that should any such study be done, the average effect would be much smaller than personal variation (while it may be statistically significant, it won't be clinically significant). My third bet would be that picking any consistent style would have a larger effect over a random arrangement than either one consistent style over the other, and that this effect would be significant in both the statistical and clinical senses. -- 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 Catherine.M.Moroney at jpl.nasa.gov Tue May 3 20:18:33 2011 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Tue, 03 May 2011 17:18:33 -0700 Subject: importing class objects from a pickled file Message-ID: Hello, I have an object of class X that I am writing to a pickled file. The pickling part goes fine, but I am having some problems reading the object back out, as I get complaints about "unable to import module X". The only way I have found around it is to run the read-file code out of the same directory that contains the X.py file, but this is obviously not a portable way of doing things. Even when I put statements into the code such as "from Y.X import X" where Y is the name of the python package that contains the X,py file, the import statement works, but I am still unable to read the object from the pickled file, running into the same "unable to import module X" error. Am I explaining myself properly? Why doesn't the code that loads the object from the pickled file work unless I am sitting in the same directory? The code that writes the pickled file has the statement "from Y.X import X" statement" at the top, as does the reading code, but even though that import statement succeeds, the read still fails with the import error. Thanks for any help, Catherine From roy at panix.com Tue May 3 20:27:38 2011 From: roy at panix.com (Roy Smith) Date: Tue, 03 May 2011 20:27:38 -0400 Subject: vertical ordering of functions References: Message-ID: In article , Jabba Laci wrote: > I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. > 5 he says that a function that is called should be below a function > that does the calling. This creates a nice flow down from top to > bottom. There may have been some logic to this when people read programs on stacks of green-bar or rolls of teletype paper. These days, we have better tools. When I'm reading some code and see a function call I want to explore, I search for the function name in my text editor. People who use an IDE can probably just click on the function name. In either case, the tool takes me where I need to go. I'm generally completely unaware whether it's taken be forward or backward in the file. From john at castleamber.com Tue May 3 20:44:41 2011 From: john at castleamber.com (John Bokma) Date: Tue, 03 May 2011 19:44:41 -0500 Subject: vertical ordering of functions References: <87sjsvfia2.fsf@benfinney.id.au> Message-ID: <87d3jzgupy.fsf@castleamber.com> Ben Finney writes: > Jabba Laci writes: > >> Is there a convention for this? Should main() be at the top and called >> function below? > > No, it's Python convention for both of those to be at the end of the > module. > > I follow the convention described by Guido van Rossum in > . Thanks Ben, very useful link. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From astan.chee at gmail.com Tue May 3 20:45:31 2011 From: astan.chee at gmail.com (Astan Chee) Date: Wed, 4 May 2011 10:45:31 +1000 Subject: Running and killing a process in python Message-ID: Hi, I'm trying to make a python script (in windows 7 x64 using python 2.5) to start a process, and kill it after x minutes/seconds and kill all the descendants of it. Whats the best way of doing this in python? which module is best suited to do this? subprocess? thanks for any help -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue May 3 21:09:39 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 01:09:39 +0000 (UTC) Subject: vertical ordering of functions References: Message-ID: On 2011-05-03, Jabba Laci wrote: > I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. > 5 he says that a function that is called should be below a function > that does the calling. This creates a nice flow down from top to > bottom. I generally expect the opposite: callees above, callers below, main at the bottom. However, that's mostly just a habit left over from C programming where such an ordering avoids having to litter the file with forward declarations for functions. -- Grant From stefan.kuzminski at gmail.com Tue May 3 22:28:51 2011 From: stefan.kuzminski at gmail.com (Stefan Kuzminski) Date: Tue, 3 May 2011 22:28:51 -0400 Subject: Pickling extension types In-Reply-To: References: Message-ID: closer I think 1) I changed tp_name to be 'observation.MV' ( module is named observation.c ) and now I get a new error.. PicklingError: Can't pickle : import of module observation failed 2) here is the init function, sorry I did not include it in the original listing void initobservation(void) { PyObject *m; m = Py_InitModule("observation", observation_methods); Py_INCREF(&PyMV_Type); PyModule_AddObject(m, "MV", (PyObject *)&PyMV_Type); } thx, S On Tue, May 3, 2011 at 6:05 PM, Robert Kern wrote: > On 5/3/11 4:34 PM, Stefan Kuzminski wrote: > >> Thanks for the clues, I made a modification so that reduce returns this.. >> >> return Py_BuildValue("O(OOOOO)", Py_TYPE(self), PyTuple_New(0), Py_None, >> Py_None, Py_None ); >> >> and now I get this different error when trying to pickle the type.. >> >> ---------------------------------------------------------------------- >> Traceback (most recent call last): >> File "test_missing.py", line 16, in test >> print cPickle.dumps( mv ) >> PicklingError: Can't pickle : attribute lookup __builtin__.MV >> failed >> > > You need to do two things: > > 1. Set tp_name to something like "mymodule.MV" where "mymodule" is the name > of your extension module. > > 2. Make sure that you add the type object to your module's namespace. > > PyMODINIT_FUNC > initmymodule(void) { > ... > Py_INCREF(&PyMV_Type); > PyModule_AddObject(m, "MV", (PyObject*)&PyMV_Type); > } > > C.f. > > http://docs.python.org/extending/newtypes.html > > -- > 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 > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Tue May 3 22:29:53 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 4 May 2011 12:29:53 +1000 Subject: importing class objects from a pickled file In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 10:18 AM, Catherine Moroney wrote: > Am I explaining myself properly? ?Why doesn't the code that loads the > object from the pickled file work unless I am sitting in the same directory? > ? The code that writes the pickled file has the statement > "from Y.X import X" statement" at the top, as does the reading code, but > even though that import statement succeeds, the read still fails with the > import error. pickled objects won't work this way unless you "customize" the way in which your class gets serialized. See: http://docs.python.org/library/pickle.html#the-pickle-protocol Any time you want to unpickle a user class, that class must be available. I suggest serializing to a more common format (say JSON) and re-create your class with the data. cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Tue May 3 22:31:06 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 4 May 2011 12:31:06 +1000 Subject: Running and killing a process in python In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 10:45 AM, Astan Chee wrote: > Hi, > I'm trying to make a python script (in windows 7 x64 using python 2.5) to > start a process, and kill it after x minutes/seconds and kill all the > descendants of it. > Whats the best way of doing this in python? which module is best suited to > do this? subprocess? Yes start with the subprocess module: http://docs.python.org/library/subprocess.html cheers James -- -- James Mills -- -- "Problems are solved by method" From angrybaldguy at gmail.com Wed May 4 01:29:11 2011 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Wed, 4 May 2011 01:29:11 -0400 Subject: importing class objects from a pickled file References: Message-ID: <2011050401291149357-angrybaldguy@gmailcom> On 2011-05-03 20:18:33 -0400, Catherine Moroney said: > Hello, > > I have an object of class X that I am writing to a pickled file. The > pickling part goes fine, but I am having some problems reading the > object back out, as I get complaints about "unable to import module X". > > The only way I have found around it is to run the read-file code out of > the same directory that contains the X.py file, but this is obviously > not a portable way of doing things. > > Even when I put statements into the code such as "from Y.X import X" > where Y is the name of the python package that contains the X,py file, > the import statement works, but I am still unable to read the object > from the pickled file, running into the same "unable to import module X" > error. > > Am I explaining myself properly? Why doesn't the code that loads the > object from the pickled file work unless I am sitting in the same directory? That's not the actual requirement. The pickled representation of an instance of a user-defined class contains: * the name of the class * the name of the class's module * the object's attributes, pickled recursively You can have a look at the representation using protocol zero, which is printable and not terribly hard to read. Here's an example, lightly annotated: >>> import pickle >>> class Example(object): ... def __init__(self, x): ... self.x = x ... >>> one = Example(1) >>> print pickle.dumps(one, 0) ccopy_reg _reconstructor p0 module name (c__main__ class name Example p1 c__builtin__ object p2 Ntp3 Rp4 (dp5 field name S'x' p6 field value I1 sb. >>> Obviously, since the pickled representation only contains the *name and location* of the class and not the class itself, you need to have the definition of the class handy when unpickling an object. This means that the module that defines the class must be on the module search path - either because it's in the current directory (or a package in the current directory, or..), or because it's in PYTHONPATH, or because it's somewhere else on sys.path. > The code that writes the pickled file has the statement > "from Y.X import X" statement" at the top, as does the reading code, but > even though that import statement succeeds, the read still fails with > the import error. The unpickle code uses something morally equivalent to __import__ to convert the module name in the pickled data stream into a module object. The symbols defined in the module you called pickle.load from don't matter at all, just like any other function defined in a separate module. Pickle isn't meant for transmitting data between two unrelated programs. It's designed to be a low-development-effort way to preserve and restore objects for a single program or a group of related programs that share libraries. If you want to share data between unrelated programs, use something a little more interoperable - json, xml, or some other program-agnostic representation. -o (And if you were thinking of using pickle over the internet, forget it: the pickle encoding is a small stack-based programming language in its own right, and can be used to invoke semi-arbitrary module-scoped funtions.) From amit.paunikar at gmail.com Wed May 4 02:12:01 2011 From: amit.paunikar at gmail.com (DonAmit) Date: Tue, 3 May 2011 23:12:01 -0700 (PDT) Subject: dll errors in compiled python program In-Reply-To: <56def94c-f0d8-4aa2-b46d-be06138ab5b0@q36g2000prg.googlegroups.com> References: <56def94c-f0d8-4aa2-b46d-be06138ab5b0@q36g2000prg.googlegroups.com> Message-ID: <31538796.post@talk.nabble.com> You can do this easy by adding this to the options dict in setup.py 'dll_excludes': [ "mswsock.dll", "powrprof.dll" ] source: http://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failed -Amit alex23 wrote: > > Alex Hall wrote: >> I am stumped. The compiled version of my project works on my pc, but >> when I put it on a thumb drive and try it on a laptop without python >> installed I get this: >> ImportError: DLL load failed: The specified procedure could not be found. > > Are you using py2exe? If so, are you including the necessary MS > runtime dll[1]? > > 1: http://www.py2exe.org/index.cgi/Tutorial#Step5 > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://old.nabble.com/dll-errors-in-compiled-python-program-tp28407640p31538796.html Sent from the Python - python-list mailing list archive at Nabble.com. From r1chardj0n3s at gmail.com Wed May 4 02:34:43 2011 From: r1chardj0n3s at gmail.com (Richard Jones) Date: Wed, 4 May 2011 16:34:43 +1000 Subject: PyCon Australia 2011 CFP still open Message-ID: Hi all, We're still waiting for some tardy presenters who haven't put in their proposals yet, and it's unfair to give just them an extension so we're leaving the submission system open until next Monday, the 9th of May. Thanks to everyone else who put in their proposals on time, and we'll be starting the review process in the next couple of days. Richard Jones PyCon Au 2011 Program Chair http://pycon-au.org/cfp From pratik.mehta at capgemini.com Wed May 4 03:45:51 2011 From: pratik.mehta at capgemini.com (Mehta, Pratik) Date: Wed, 4 May 2011 13:15:51 +0530 Subject: A very minute correction on PDF Message-ID: <073456261C486944897A62516989111CACBC52EE7D@IN-MUM-MAIL2.corp.capgemini.com> For tutorialPython.pdf Page 17 of the ebook (i.e. page 23 of pdf) under topic 3.2 First Steps towards programming Under while loop, there should be a "," after print b Print b, (a comma after 'b' is missing) Regards, ______________________________________________________________________ [cid:image001.gif at 01CC0988.41BD50B0]Pratik Mehta Associate Consultant | SOGETI - FR TeamPark Support Team Capgemini India | Mumbai II Tel.: +91 022 67 55 7000 - Mob: +91 9323054941 Extension: 225 1922 | www.capgemini.com pratik.mehta at capgemini.com People matter, results count. _______________________________________________________________________ This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.gif Type: image/gif Size: 1616 bytes Desc: image001.gif URL: From duncan.booth at invalid.invalid Wed May 4 04:44:36 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 May 2011 08:44:36 GMT Subject: Why do directly imported variables behave differently than those attached to imported module? References: Message-ID: Chris Angelico wrote: > Here's a side point. What types will hold a reference to the enclosing > module (or at least its dictionary)? Would it be possible to use a > from import to load a module, then "lose" the module even though > you're using objects from it? > > I am guessing that a function or class will hold such a reference, > because otherwise it would be a bit awkward for them to use any sort > of module-level state. Or do they not, and instead go look for their > module in sys.modules? A function object has a reference to the dictionary for the module in which it was defined; it needs this to access global variables. A class holds the name of the module but has no reference to the actual module itself. Yes, it is quite possible to delete a module object, but it won't generally matter since any classes that are still referenced will prevent their methods being deleted and any functions or methods that are still accessible will keep the globals alive as long as required. -- Duncan Booth http://kupuguy.blogspot.com From rosuav at gmail.com Wed May 4 05:02:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 19:02:40 +1000 Subject: Aborting Python from C code In-Reply-To: References: Message-ID: On Sat, Apr 30, 2011 at 7:29 PM, Dylan Evans wrote: > I think i see what you are trying to do but it depends on the environment > and your goals. > Generally i think you need to?separate?your code by forking (or perhaps you > have already done that?), > then you can run a check to see if the process died as expected. I don't > know though, this not much > information to go on, but if you are running untrusted code then you need to > be able to isolate and kill it. Well, I've gone with a slight variant on this. If the Python script doesn't terminate in a timely manner, the process will be killed with a longjmp straight from the signal handler (the setjmp having been done long long ago back when the process initialized itself). So Py_Finalize() will be called, but no other Python-related functions _at all_, and the process promptly terminates. I'm assuming that Python will flush out all its state on process termination (that is, it doesn't hang onto any system-global resources). Thanks for the advice! Chris Angelico From jeanmichel at sequans.com Wed May 4 05:47:37 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 04 May 2011 11:47:37 +0200 Subject: Running and killing a process in python In-Reply-To: References: Message-ID: <4DC120B9.3080902@sequans.com> James Mills wrote: > On Wed, May 4, 2011 at 10:45 AM, Astan Chee wrote: > >> Hi, >> I'm trying to make a python script (in windows 7 x64 using python 2.5) to >> start a process, and kill it after x minutes/seconds and kill all the >> descendants of it. >> Whats the best way of doing this in python? which module is best suited to >> do this? subprocess? >> > > Yes start with the subprocess module: > > http://docs.python.org/library/subprocess.html > > cheers > James > > As an alternative, you can have a look at http://codespeak.net/execnet/index.html This module is designed to execute processes on remote machines, but it works great on the local host as well. Among its features are: " - easy creation, handling and termination of multiple processes - fully interoperable between Windows and Unix-ish systems " While it has more feature than what you need, if you do simple things, it stays simple. (I never used subprocess with Windows, so I don't know if killing process is that easy. On *nix system, you should probably choose subprocess, execnet would be overkill) JM From jeanpierreda at gmail.com Wed May 4 05:56:28 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 4 May 2011 02:56:28 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> > To illustrate the neither-fish-nor-fowl nature of Python calls: > > mwilson at tecumseth:~$ python > 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.>>> def identify_call (a_list): > > ... ? a_list[0] = "If you can see this, you don't have call-by-value" > ... ? a_list = ["If you can see this, you have call-by-reference"] > ...>>> my_list = [None] > >>> identify_call (my_list) > >>> my_list > > ["If you can see this, you don't have call-by-value"] > > so it's neither call-by-value nor call-by-reference as (e.g.) C or PL/I > programming would have it (don't know about Simula, so I am off topic, > actually.) ?It's not so wrong to think of Python's parameter handling as > ordinary assignments from outer namespaces to an inner namespace. > > ? ? ? ? Mel. Eh, that example doesn't say what you think it does. It has the same behavior in C: http://ideone.com/Fq09N . Python is pass-by-value in a meaningful sense, it's just that by saying that we say that the values being passed are references/pointers. This is maybe one level of abstraction below what's ideal, but Scheme, Java, etc. share this terminology. (Ruby calls it pass-by-reference AFAIK. Whatever, a rose by any other name...) Devin Jeanpierre From steve+comp.lang.python at pearwood.info Wed May 4 06:51:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 May 2011 10:51:33 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 02:56:28 -0700, Devin Jeanpierre wrote: > Python is pass-by-value in a > meaningful sense, it's just that by saying that we say that the values > being passed are references/pointers. This is maybe one level of > abstraction below what's ideal, "Maybe"? Given the following statement of Python code: >>> x = "spam" what is the value of the variable x? Is it...? (1) The string "spam". (2) Some invisible, inaccessible, unknown data structure deep in the implementation of the Python virtual machine, which the coder cannot access in any way using pure Python code. (Possibly a pointer, but since it's an implementation detail, other implementations may make different choices.) (3) Something else. I argue that any answer except for (1) is (almost always) counter- productive: it adds more confusion than shedding light. It requires thinking at the wrong level, at the implementation level instead of the level of Python code. If we define "value" to mean the invisible, inaccessible reference, then that leaves no word to describe was the string "spam" is. (I say "almost always" counter-productive because abstractions leak, and sometimes you do need to think about implementation.) > but Scheme, Java, etc. share this > terminology. (Ruby calls it pass-by-reference AFAIK. The intellectual contortions that some people will go through to hammer the square peg of actual programming language behaviour into the two round holes of "pass by value" and "pass by reference" never cease to astonish me. > Whatever, a rose by any other name...) Do you really think that roses would be the symbol of romantic love if they were called "disgusting stink-weeds of perversion and death"? "How was the date last night?" "Oh, it was marvelous! He presented me with a single red stink-weed, and then we went to a disgusting little restaurant. I had the swill." When people cannot agree on the definition of words, how can they communicate? Pass by reference Ruby is completely different from the older usage in Pascal, VB and other languages. Likewise, pass by value in Java is completely different from that in older languages. Pass by reference in Ruby, and pass by value in Java, describe the same thing. What were these people thinking? -- Steven From leandrodsferreira at gmail.com Wed May 4 06:52:29 2011 From: leandrodsferreira at gmail.com (LehH Sdsk8) Date: Wed, 4 May 2011 03:52:29 -0700 (PDT) Subject: Handling the log in BaseHTTPServer Message-ID: First, i'm sorry for any inglish error! So, i use the BaseHTTPServer to create a page for monitoring purposes, someone now how to direct the event log to a file? From hg at schaathun.net Wed May 4 06:56:16 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 11:56:16 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On Wed, 4 May 2011 02:56:28 -0700 (PDT), Devin Jeanpierre wrote: : Eh, that example doesn't say what you think it does. It has the same : behavior in C: http://ideone.com/Fq09N . Python is pass-by-value in a : meaningful sense, it's just that by saying that we say that the values : being passed are references/pointers. No, Python is not pass-by-value, because the pointer is abstracted away. You transmit arguments by reference only and cannot access the value of the reference. In C it is pass by value, as the pointer is explicit and do whatever you want with the pointer value. So, even though you have the same mechanism in C and Python, they do not have the same name. In the low-level C you only have pass by value, but you can use the pointer syntax to do whatever you want within pass by value. In the higher-level python, you do not have the flexibility provided by explicit pointers, so you need to explain the semantics without having a pointer concept defined a priori. : This is maybe one level of : abstraction below what's ideal, but Scheme, Java, etc. share this : terminology. (Ruby calls it pass-by-reference AFAIK. Whatever, a rose : by any other name...) Now, this is confusing, because the terminology is not universal and hardly intuitive. What is called transmission by reference in a Simula context (Bj?rn Kirkerud's textbook on OO Programming with Simula for instance) is called object sharing in Wikipedia. What Wikipedia calls call by reference is transmission by name in the Simula context. -- :-- Hans Georg From no.email at nospam.invalid Wed May 4 06:58:51 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 04 May 2011 03:58:51 -0700 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7x62pqn34k.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >>>> x = "spam" > what is the value of the variable x? Is it...? > (1) The string "spam". Python works about the same way as Lisp or Scheme with regard to this sort of thing, and those languages have been described with quite a bit of mathematical formality. So if you want a precise theoretical treatment you might look at the Scheme report. It should be pretty clear how it carries over to Python. From johnroth1 at gmail.com Wed May 4 07:14:09 2011 From: johnroth1 at gmail.com (John Roth) Date: Wed, 4 May 2011 04:14:09 -0700 (PDT) Subject: vertical ordering of functions References: Message-ID: On May 3, 4:08?pm, Jabba Laci wrote: > Hi, > > I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. > 5 he says that a function that is called should be below a function > that does the calling. This creates a nice flow down from top to > bottom. > However, when I write a Python script I do just the opposite. I start > with the lines > > if __name__ == "__main__": > ? ? main() > > Then I add main() above, which is a control function that contains > some function calls that decompose the problem into subproblems. Then > I add these functions above, etc. > > Is there a convention for this? Should main() be at the top and called > function below? > > Thanks, > > Laszlo I order classes and methods as I'd expect someone approaching the program for the first time to want to read it. I think Robert Martin's recommendation of use before declaration makes it easier to read a program for the first time. Some compilers require declaration before use because they need to see the declaration before they see any uses. Python is in between: you can treat Python as if the order you write things doesn't matter, but there are cases where it really does matter. When it does, you have to have the definition before the use. John Roth From jeanpierreda at gmail.com Wed May 4 09:12:14 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 4 May 2011 06:12:14 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 4, 6:51?am, Steven D'Aprano wrote: > On Wed, 04 May 2011 02:56:28 -0700, Devin Jeanpierre wrote: > > Python is pass-by-value in a > > meaningful sense, it's just that by saying that we say that the values > > being passed are references/pointers. This is maybe one level of > > abstraction below what's ideal, > > "Maybe"? > > Given the following statement of Python code: > > >>> x = "spam" > > what is the value of the variable x? Is it...? > > (1) The string "spam". > > (2) Some invisible, inaccessible, unknowndatastructure deep in the > implementation of the Python virtual machine, which the coder cannot > access in any way using pure Python code. > > (Possibly a pointer, but since it's an implementation detail, other > implementations may make different choices.) > > (3) Something else. As I said, a pointer or reference. > I argue that any answer except for (1) is (almost always) counter- > productive: it adds more confusion than shedding light. It requires > thinking at the wrong level, at the implementation level instead of the > level of Python code. If we define "value" to mean the invisible, > inaccessible reference, then that leaves no word to describe was the > string "spam" is. > > (I say "almost always" counter-productive because abstractions leak, and > sometimes you do need to think about implementation.) I don't know why you want to argue that it's counter-productive when all I said was that it was meaningful / worked. I don't think of "pass-by-value" involving references as being an implementation-level thing. It's a way of thinking about Python's behavior: a model. There don't even need to be actual references or anything resembling them inside the implementation in order to apply the model (for example, we probably all accept that Python could be implemented using a turing machine, which lacks references/pointers). Also, the word you suspected did not exist is "object". So if we have var = "spam", var is a variable containing a reference to the object "spam". Alternatively, it's a handle for the object "spam". I think that's the call-by-sharing terminology, anyway. > > but Scheme, Java, etc. share this > > terminology. (Ruby calls it pass-by-reference AFAIK. > > The intellectual contortions that some people will go through to hammer > the square peg of actual programming language behaviour into the two > round holes of "pass by value" and "pass by reference" never cease to > astonish me. It isn't particularly contorted. I learned Python this way and it makes perfect sense. It's just perhaps one level of abstraction away from the ideal of what some programmers would think in. Python's "pass- by-value" conforms exactly to the "pass-by-value" of other languages such as C. The only twist is that you never get to dereference pointers in Python, but you can in C. Not much of a twist if you ask me, but then again, I've been thinking in this model for years. Maybe I'm brainwashed. :) > > Whatever, a rose by any other name...) > > Do you really think that roses would be the symbol of romantic love if > they were called "disgusting stink-weeds of perversion and death"? > > "How was the date last night?" > "Oh, it was marvelous! He presented me with a single red stink-weed, and > then we went to a disgusting little restaurant. I had the swill." Please don't argue with me in this manner. The point is that words don't matter, the meaning behind them does. As long as it's clear what's meant, and what's meant is internally-consistent, I don't have much problem with it. Of course, this is a rule of thumb and you could draw extreme scenarios where it just becomes a bother. Devin Jeanpierre From jeanpierreda at gmail.com Wed May 4 09:13:48 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 4 May 2011 06:13:48 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <1874cca8-1f1f-4d0a-b306-c32f2fa1d8c1@x3g2000yqj.googlegroups.com> On May 4, 6:56?am, Hans Georg Schaathun wrote: > On Wed, 4 May 2011 02:56:28 -0700 (PDT), Devin Jeanpierre? wrote: > > : ?Eh, that example doesn't say what you think it does. It has the same > : ?behavior in C:http://ideone.com/Fq09N. Python is pass-by-value in a > : ?meaningful sense, it's just that by saying that we say that the values > : ?being passed are references/pointers. > > No, Python is not pass-by-value, because the pointer is abstracted > away. ?You transmit arguments by reference only and cannot access the > value of the reference. ?In C it is pass by value, as the pointer > is explicit and do whatever you want with the pointer value. ? The same argument applies to every language I know but two, all of which describe themselves as pass-by-value. What you say certainly has a consistency to it, it's just at odds with how I generally see the term being applied. Forgive me if I don't share the same definition as you, even if I do appreciate its elegance. Devin Jeanpierre From hg at schaathun.net Wed May 4 09:44:07 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 14:44:07 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7q1898-f3l.ln1@svn.schaathun.net> On Wed, 4 May 2011 06:12:14 -0700 (PDT), Devin Jeanpierre wrote: : I don't think of "pass-by-value" involving references as being an : implementation-level thing. It's a way of thinking about Python's : behavior: a model. (...) : It isn't particularly contorted. I learned Python this way and it : makes perfect sense. It's just perhaps one level of abstraction away : from the ideal of what some programmers would think in. Python's "pass- : by-value" conforms exactly to the "pass-by-value" of other languages : such as C. It is contorted and implementation-level because it is one level below the abstraction assumed by the language. It only works by assuming knowledge of C, which is language which has proved unsuitable for complex and abstract data modelling. Digging down into C should be unnecessary to explain Python. By calling it pass-by-value you introduce a new data type which is unknown to Python, namely the pointer. : The only twist is that you never get to dereference : pointers in Python, but you can in C. Not much of a twist if you ask : me, but then again, I've been thinking in this model for years. Maybe : I'm brainwashed. :) You are. You explain Python in terms of C. That's useful when you talk to other speakers of C. If you want to explain the language to a broader audience, you should use terminology from the language's own level of abstraction. -- :-- Hans Georg From lkcl at lkcl.net Wed May 4 10:06:59 2011 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 4 May 2011 15:06:59 +0100 Subject: [ann] pyjamas 0.8alpha1 release Message-ID: after a long delay the pyjamas project - http://pyjs.org - has begun the 0.8 series of releases, beginning with alpha1: https://sourceforge.net/projects/pyjamas/files/pyjamas/0.8/ pyjamas is a suite of projects, including a python-to-javascript compiler with two modes of operation (roughly classified as "python strict" and "Optimised"); a GUI Framework almost identical to that of the GWT Project (1.5 to 1.7); and a "Desktop" version which is similar in concept to Adobe Air, allowing python applications to be run - unmodified - as stand-alone Desktop Applications. pyjamas can therefore be considered to be a Desktop GUI framework - a peer of GTK2 and QT4 - with the startling capability that applications can also be compiled to javascript and run in any modern web browser with absolutely no special plugins required, or it can be considered to be an AJAX Web Framework with the massive advantage that applications are written in python (not javascript) with a "Desktop" mode as well. both descriptions are accurate, making pyjamas the world's only free software python-based platform-independent, browser-independent, GUI-toolkit-independent and OS-independent "Holy Grail" GUI development environment [so there. nyer, nyer to the corporate big boys with access to $m who *still* haven't managed that one] also included are ports of GChart and GWTCanvas, each of which run under all web browsers and all desktop engines (with the exception at present of the python-webkit desktop engines, which presently do not support SVG Canvas). all pyjamas UI libraries are designed to be browser-independent as well as platform independent. the usual "browser foibles", tricks and gotchas are catered for with a transparent "Platform Override" mechanism which ensures that the published API of each UI Library is identical across all platforms (including the Desktop Engines). [no more "If Platform == IE or Platform == Opera...."] due to the sheer number of modern browsers as well as the number of pyjamas-desktop engines required to be supported, the 0.8 series will be ready declared "stable" when sufficient community-led testing has been done. bugreports are in for Opera 11, IE8 and Google Chrome: http://code.google.com/p/pyjamas/issues/detail?id=600 http://code.google.com/p/pyjamas/issues/detail?id=601 http://code.google.com/p/pyjamas/issues/detail?id=597 still requiring testing and confirmation is Opera 9 and 10; Firefox 2, 3, 3.1, 3.5, 3.6 and 4.0; IE6, 7 and 9; Safari 3 and 4, as well as mobile phone browsers Android, Symbian Series 60, iphone, ipad and blackberry OS 4. also requiring testing and confirmation is the Desktop Engines, of which there are now four variants: XulRunner (Firefox Engine), pywebkitgtk, MSHTML and the new addition pywebkitdfb (DirectFB). each browser and each engine requires each of the 70 examples to be run, and in the case of the pyjamas compiler (pyjs), compilation is required with both -O and --strict (with the exception of the LibTest example). the pywebkitdfb engine is a new addition, and merits a particular mention. some time last year, both GTK2 and QT4 independently announced that they were dropping support for DirectFB from future versions, and Enlightenment had not tested the DirectFB port for some considerable time. Webkit-GTK with the older GTK-DirectFB libraries simply would not compile. in the embedded space, where it can take 30 seconds to fire up Webkit-GTK on a 400mhz ARM9 and even longer to start up WebkitQT4, this was something of a disaster. To fix this, a new port of Webkit was created which uses DirectFB directly, using a tiny 50k Widget Toolkit called "Lite". This development coincided with the re-engineering of pywebkitgtk and the creation of the pythonwebkit project, http://www.gnu.org/software/pythonwebkit: pywebkitdfb was therefore also created at the same time. Cutting a long story short, pywebkitdfb now exists and has a startup time on 400mhz ARM9 processors of under 1.5 seconds. The startup time of both WebkitDFB and pywebkitdfb on Dual-Core 2ghz Intel systems is so quick that it's difficult to determine: an estimate is under 0.1 seconds (100ms). WebkitGTK. WebkitEFL and WebkitQT4 have approximately 20 times or longer startup times. So although WebkitDFB is still significantly experimental, it is definitely worthwhile considering, especially for Embedded Systems, but even for use on X-Windows, and even just as a plain (but modern) web browser for those people sick to the back teeth of long startup times on their web browser [and it has python bindings, too. yaay!] summary: developing applications in pyjamas means the application can be made to run just about anywhere, and it's an entirely python-based and a free software framework. it's a community-driven project, so requires *your* input to get it to a proven stable state. http://pyjs.org From rosuav at gmail.com Wed May 4 10:20:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 00:20:34 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <7q1898-f3l.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: On Wed, May 4, 2011 at 11:44 PM, Hans Georg Schaathun wrote: > It is contorted and implementation-level because it is one level below > the abstraction assumed by the language. ?It only works by assuming > knowledge of C, which is language which has proved unsuitable for > complex and abstract data modelling. ?Digging down into C should be > unnecessary to explain Python. Sometimes, to explain Python, you need to dig down to the underlying hardware - even deeper than C, if you like. And that's always going to be the way, because abstractions leak from time to time. Or I should say, they occasionally have confidential briefings with the press. Abstracting everything perfectly is neither possible nor desirable. Chris Angelico From sturla at molden.no Wed May 4 10:28:16 2011 From: sturla at molden.no (sturlamolden) Date: Wed, 4 May 2011 07:28:16 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <87aaf351vk.fsf@xemacs.org> Message-ID: On May 3, 3:50?pm, Hrvoje Niksic wrote: > I would say that, considering currently most popular languages and > platforms, Python's data model is in the majority. ?It is only the > people coming from a C++ background that tend to be confused by it. In C++, one will ususally put class variables (objects) on the stack or in STL containers, and use references instead of pointers. This way one gets deterministic clean-up, and operator overloading will work as expected. It is a common beginner mistake for people coming from Java to use "new" anywhere in C++ code, instead of inside constructors only. Used properly, C++ has a data model for class variables similar to Fortran (pass-by-reference). This is complicated by the ability of C ++ to pass-by-value for backwards compatibility with C, inclusing the use of raw pointers. This hybrid and convoluted data model of C++ is a common source of confusion and programming mistakes, both for programmers coming from C++ to Python or C# or vice versa. Java is somewhat between C and C#, in that it has C semantics for elementary types (e.g. int and float), but not for objects in general. In C# and Python, elementary types are immutable objects, byut thet have no special pass-by-value semantics. Python has the same data model as Scheme. This includes that code is an object in Python (in Python that is byte code not source code, thus no Lisp macros). Variables are names that bind to an object. Objects are passed as references, but names are not. "Dummy arguments" (to use Fortran termininology) are bound to the same objects with which the function was called, but this is not call-by-reference semantics in the style of Fortran and C++: In Python, the "=" operator will rebind in the local scope, as in C, Java and C#. It will not affect anything the the calling scope (as in C ++ and Fortran). Nevertheless, this is not pass-by-value, as no copy are made. A reference in C++ and Fortran is an alias for the variable in the calling scope. In Python it is a new variable pointing to the same value. This is a major difference, but a common source of error for those that don't understand it. ( for those confused about the claimed behavior of "=" in C++: The previous paragraph deals with reference variables in C++, not those passed with C-style pass-by-value sematics. C++ does not always behave as C, sometimes it behaves like Fortran and Pascal.) Thus, Python does not pass-by-value like C or C++, nor does it pass-by- reference like C++ or Fortran. The semantics of Python, C# and Lisp might be described as "pass-by- handle" if we need to put a name on it. From sturla at molden.no Wed May 4 10:44:38 2011 From: sturla at molden.no (sturlamolden) Date: Wed, 4 May 2011 07:44:38 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 3, 6:33?pm, Mel wrote: > def identify_call (a_list): > a_list[0] = "If you can see this, you don't have call-by-value" > a_list = ["If you can see this, you have call-by-reference"] The first one is a mistake. If it were pass-by-value, it would assign the string to a list unseen by the caller -- i.e. a copy of the caller's argument (same value, different object). But that does not happen. The string is assigned to the list seen by the caller. Thus we can exclude call-by-value. The second proposition is correct. This allows us to exclude pass-by-reference similar to C++, Pascal and Fortran. Thus: def identify_call (a_list): a_list[0] = "If you cannot see this, you have call-by-value" a_list = ["If you can see this, you have call-by-reference"] Clearly Python has neither call-by-value nor call-by-reference. Python uses a third mechanism. Sturla From robert.kern at gmail.com Wed May 4 11:06:51 2011 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 04 May 2011 10:06:51 -0500 Subject: Pickling extension types In-Reply-To: References: Message-ID: On 5/3/11 9:28 PM, Stefan Kuzminski wrote: > closer I think > > 1) I changed tp_name to be 'observation.MV' ( module is named observation.c ) > and now I get a new error.. > > PicklingError: Can't pickle : import of module > observation failed > > 2) here is the init function, sorry I did not include it in the original listing > > void initobservation(void) { > > PyObject *m; > m = Py_InitModule("observation", observation_methods); > > Py_INCREF(&PyMV_Type); > PyModule_AddObject(m, "MV", (PyObject *)&PyMV_Type); > > } Without seeing the whole C code, or the Python code you are trying, I can't help much more. -- 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 torriem at gmail.com Wed May 4 11:40:02 2011 From: torriem at gmail.com (Michael Torrie) Date: Wed, 04 May 2011 09:40:02 -0600 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DC17352.2080601@gmail.com> On 05/04/2011 08:44 AM, sturlamolden wrote: > On May 3, 6:33 pm, Mel wrote: > >> def identify_call (a_list): >> a_list[0] = "If you can see this, you don't have call-by-value" >> a_list = ["If you can see this, you have call-by-reference"] > > > The first one is a mistake. If it were pass-by-value, it would > assign the string to a list unseen by the caller -- i.e. a copy > of the caller's argument (same value, different object). > > Clearly Python has neither call-by-value nor call-by-reference. > > Python uses a third mechanism. Which is exactly what the code showed. The first one isn't a mistake. You just read it wrong. From stefan.kuzminski at gmail.com Wed May 4 11:45:50 2011 From: stefan.kuzminski at gmail.com (Stefan Kuzminski) Date: Wed, 4 May 2011 11:45:50 -0400 Subject: Pickling extension types In-Reply-To: References: Message-ID: I got this to work by returning from reduce just the args that the __init__ of the type being pickled requires ( rather than the 5 length tuple described in the pickling docs ), I am not going to argue with it though.. thank you *very* much for the help! S On Wed, May 4, 2011 at 11:06 AM, Robert Kern wrote: > On 5/3/11 9:28 PM, Stefan Kuzminski wrote: > >> closer I think >> >> 1) I changed tp_name to be 'observation.MV' ( module is named >> observation.c ) >> and now I get a new error.. >> >> PicklingError: Can't pickle : import of module >> observation failed >> >> 2) here is the init function, sorry I did not include it in the original >> listing >> >> void initobservation(void) { >> >> PyObject *m; >> m = Py_InitModule("observation", observation_methods); >> >> Py_INCREF(&PyMV_Type); >> PyModule_AddObject(m, "MV", (PyObject *)&PyMV_Type); >> >> } >> > > Without seeing the whole C code, or the Python code you are trying, I can't > help much more. > > > -- > 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 > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lkcl at lkcl.net Wed May 4 11:53:20 2011 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 4 May 2011 16:53:20 +0100 Subject: [ann] pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 3:06 PM, Luke Kenneth Casson Leighton wrote: > after a long delay the pyjamas project - http://pyjs.org - has begun the > 0.8 series of releases, beginning with alpha1: > > https://sourceforge.net/projects/pyjamas/files/pyjamas/0.8/ > > pyjamas is a suite of projects, including a python-to-javascript > compiler with two modes of operation (roughly classified as "python > strict" and "Optimised"); a GUI Framework almost identical to that of > the GWT Project (1.5 to 1.7); oh one other thing - for the 0.8 release, jim washington kindly added an HTML5-compliant "Drag-n-Drop" interface, which, on web engines that do not have HTML5, is emulated. and thus provides the exact same API, regardless of the web browser being used. cool, huh? if i was a java-lover, i'd look forward to that being added some day to GWT. btw - if anyone's at all curious [about GWT "Desktop" possibilities], there *does* exist a sort-of "Desktop" version [not really] - it's basically webkit, it requires execution under the eclipse IDE, and it's still javascript (not Java). i _did_ speak to the GWT Team, raising with them the possibility of doing Java bindings to Webkit [or XulRunner, or MSHTML] and providing a port of GWT that can run GWT applications REALLY as stand-alone Desktop applications, and they basically implied that that'll happen "when hell freezes over". i guess the idea of providing languages other than javascript with direct access to the full and incredible capabilities of DOM and HTML5 is just... too alien. which is funny, because pyjamas desktop shows what can be done: web browser engines can literally be turned into cross-platform GUI engines. l. From tapi at syskall.net Wed May 4 11:55:33 2011 From: tapi at syskall.net (Tapi) Date: Wed, 04 May 2011 16:55:33 +0100 Subject: Handling the log in BaseHTTPServer In-Reply-To: References: Message-ID: Hi, You may create a subclass of (or Mixin for) BaseHTTPRequestHandler to override its log_message() method. Here's a really simple example ; it's perfectible, but it should show you the way : class MyLoggingHTTPRequestHandler(BaseHTTPRequestHandler): def log_message(self, format, *args): open(LOGFILE, "a").write("%s - - [%s] %s\n" % (self.address_string(), self.log_date_time_string(), format%args)) httpd = HTTPServer(ADDR, MyLoggingHTTPRequestHandler) httpd.serve_forever() Simon On Wed, 4 May 2011 03:52:29 -0700 (PDT), LehH Sdsk8 wrote: > First, i'm sorry for any inglish error! > > So, i use the BaseHTTPServer to create a page for monitoring > purposes, > someone now how to direct the event log to a file? From leandrodsferreira at gmail.com Wed May 4 12:09:17 2011 From: leandrodsferreira at gmail.com (LehH Sdsk8) Date: Wed, 4 May 2011 09:09:17 -0700 (PDT) Subject: Handling the log in BaseHTTPServer References: Message-ID: On 4 maio, 12:55, Tapi wrote: > Hi, > > You may create a subclass of (or Mixin for) BaseHTTPRequestHandler to > override its log_message() method. > Here's a really simple example ; it's perfectible, but it should show > you the way : > > class MyLoggingHTTPRequestHandler(BaseHTTPRequestHandler): > ? ? ?def log_message(self, format, *args): > ? ? ? ? ?open(LOGFILE, "a").write("%s - - [%s] %s\n" % > ? ? ? ? ? ? ? ? ? ? ? ? ? (self.address_string(), > ? ? ? ? ? ? ? ? ? ? ? ? ? ?self.log_date_time_string(), > ? ? ? ? ? ? ? ? ? ? ? ? ? ?format%args)) > > httpd = HTTPServer(ADDR, MyLoggingHTTPRequestHandler) > httpd.serve_forever() > > Simon > > > > > > > > On Wed, 4 May 2011 03:52:29 -0700 (PDT), LehH Sdsk8 wrote: > > First, i'm sorry for any inglish error! > > > So, i use the BaseHTTPServer to create a page for monitoring > > purposes, > > someone now how to direct the event log to a file? Thanks dude, this really works, my class is a subclass of basehttprequesthandler, the only thing i have to do is put this function inside. Thanks. From jeanpierreda at gmail.com Wed May 4 12:18:56 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 4 May 2011 09:18:56 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: On May 4, 9:44 am, Hans Georg Schaathun wrote: > : The only twist is that you never get to dereference > : pointers in Python, but you can in C. Not much of a twist if you ask > : me, but then again, I've been thinking in thismodelfor years. Maybe > : I'm brainwashed. :) > > You are. You explain Python in terms of C. That's useful when you > talk to other speakers of C. > > If you want to explain the language to a broader audience, you should > use terminology from the language's own level of abstraction. No, I explained Python in terms of pointers/reference. I don't speak C or come from a C background, I'm primarily a Python programmer. Also, I don't agree with your notions of "should", I have seen it taught this way to plenty of undergraduate students learning Python as their first programming language, and they do fine. The precise notational difference between sharing an object and copying a reference doesn't matter, as long as you can draw a diagram of it and write/read code -- which they can, and they do fine. I'm a bit uncomfortable with the vibe here. It's one thing for me to self-deprecatingly suggest I'm brainwashed (with a smile), and another for you to agree in complete seriousness. Devin Jeanpierre From matthew.moorland at gmail.com Wed May 4 12:34:00 2011 From: matthew.moorland at gmail.com (ETP) Date: Wed, 4 May 2011 09:34:00 -0700 (PDT) Subject: Basic interaction with another program Message-ID: I have a dos program (run in a window) that I would like to control with a script. It needs only text input. For example, I only need to tell it: L u 100 u It will then wait for a file to be created, rename the file, then loop. Simple. I'd like to run this on Lucid Puppy Linux as it will be implemented on a very old laptop, but can probably deal with windows if needed. I only need direction on getting Python to interact with another program; how do I get it to direct text onto another window? From msarro at gmail.com Wed May 4 12:39:41 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 4 May 2011 12:39:41 -0400 Subject: Basic interaction with another program In-Reply-To: References: Message-ID: Look into the pexpect library, it'll make this easy as punch. http://www.noah.org/wiki/pexpect On Wed, May 4, 2011 at 12:34 PM, ETP wrote: > I have a dos program (run in a window) that I would like to control > with a script. ?It needs only text input. ?For example, I only need to > tell it: > > L > u > 100 > u > > It will then wait for a file to be created, rename the file, then > loop. ?Simple. > > I'd like to run this on Lucid Puppy Linux as it will be implemented on > a very old laptop, but can probably deal with windows if needed. > > I only need direction on getting Python to interact with another > program; how do I get it to direct text onto another window? > -- > http://mail.python.org/mailman/listinfo/python-list > From sturla at molden.no Wed May 4 12:40:12 2011 From: sturla at molden.no (sturlamolden) Date: Wed, 4 May 2011 09:40:12 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <29b1bdc8-7bff-445e-b660-53311ef1eb4d@p19g2000yqh.googlegroups.com> On May 4, 5:40?pm, Michael Torrie wrote: > Which is exactly what the code showed. ?The first one isn't a mistake. > You just read it wrong. No, I read "call-by-value" but it does not make a copy. Call-by-value dictates a deep copy or copy-on-write. Python does neither. Python pass a handle to the object, not a handle to a copy of the object. If you want to see call-by-value in practice, take a look at MATLAB, SciLab or Octave; or consider what C++ copy constructors do in function calls with value types. The first one is indeed a mistake. An object has a value. A name binds to an object, not to a value. If Python did pass-by-value, the string would be inserted in an object (here: a list) with the same value (e.g. empty list), it would not modify the same object by which you called the function. I think you understand what Python does, but not what call-by-value would do. C++ tells you the difference: // copy constructor is invoked // x is a copy of the argument's value // this is call-by-value void foobar1(Object x); // no copy is taken // x is a logical alias of the argument // this is call-by-reference void foobar2(Object &x); // x is a pointer, not an object // x is a copy of another pointer // this is similar to Python sematics // the pointer is passed by value, not the pointee // in C, this is sometimes called call-by-reference // as there are no reference types, but it's not void foobar3(Object *x); Sturla From ddneilson at gmail.com Wed May 4 12:51:39 2011 From: ddneilson at gmail.com (Daniel Neilson) Date: Wed, 04 May 2011 10:51:39 -0600 Subject: Hooking into Python's memory management Message-ID: <4DC1841B.2030601@gmail.com> Hello, I'm hoping that there will be someone here with sufficient expertise to answer a question on Python 3 for me. I work in the Computer Science department at a large Canadian University. We are currently doing a feasibility analysis for switching to using Python in our first year major-stream courses. Part of our first year curriculum requires that students be exposed to explicit dynamic memory allocation in the form of C++'s new/delete, C's malloc/free, etc. I realize that Python is garbage collected, and that there is never a need to explicitly allocate & deallocate objects. However, I am trying to determine whether or not it is possible to simulate that behaviour within Python via a module for the purposes of instruction. For these purposes, I would like to know whether it is possible within Python 3 to write a Python-only module that, essentially, hooks into the "constructor" and "destructor" of many of the Python built-in types (specifically list, dictionary, set, tuple, and string) so that the module can: 1) Maintain a list of object id()'s for objects that have been created. Ideally, this list would also contain the file & line number where the object was created. 2) Provide a "deallocate" function that will remove a given object's id() from the list from (1). 3) Print out an error message if the python script terminates with a non-empty list from (1). Preferably with a list of objects that are still "allocated." Baring a Python-only module, would this behaviour be possible to add via a C-language module? A module that hooked in to all memory allocation, and inspected the type of the object being allocated to conditionally add the object's id() to the list would also suffice. In either case, if such a module is possible, any pointers you could provide regarding how to implement such a module would be appreciated. Thank you for your time, Daniel From invalid at invalid.invalid Wed May 4 12:52:58 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 16:52:58 +0000 (UTC) Subject: Basic interaction with another program References: Message-ID: On 2011-05-04, Matty Sarro wrote: > On Wed, May 4, 2011 at 12:34 PM, ETP wrote: >> I have a dos program (run in a window) that I would like to control >> with a script. > Look into the pexpect library, it'll make this easy as punch. I don't think pexpect is going to do the OP much good. Quoting from the web page: "Pexpect does not currently work on the standard Windows Python" > http://www.noah.org/wiki/pexpect Seriously? Yellow on brown text? -- Grant Edwards grant.b.edwards Yow! When this load is at DONE I think I'll wash it gmail.com AGAIN ... From hg at schaathun.net Wed May 4 13:03:05 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 18:03:05 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: <9fd898-0el.ln1@svn.schaathun.net> On Wed, 4 May 2011 09:18:56 -0700 (PDT), Devin Jeanpierre wrote: : I'm a bit uncomfortable with the vibe here. It's one thing for me to : self-deprecatingly suggest I'm brainwashed (with a smile), and another : for you to agree in complete seriousness. I am sorry. It was not meant to be an insult. I do think that you sit tightly in a frame of reference which is obviously not the only one appropriate, and IMNHO not the optimal one for the purpose. "Brainwashed" was not a word I meant to take seriously. Apologies. I should have cut the C reference too; the same frame of reference could be adopted from any number of languages. Note that it was not the use of references as a concept I objected to, but that they might be passed by value. With the references being purely abstract entities and not data objects, the idea that they have values do not make sense. And pass-by-value where the value is a reference is just confusing. -- :-- Hans Georg From hg at schaathun.net Wed May 4 13:09:56 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 18:09:56 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: <4sd898-0el.ln1@svn.schaathun.net> On Thu, 5 May 2011 00:20:34 +1000, Chris Angelico wrote: : Sometimes, to explain Python, you need to dig down to the underlying : hardware - even deeper than C, if you like. Sometimes you may need to narrow down the scope and explain a particular implementation of python with its hardware, OS, and interpreter. However, explaining just python, you do not know what the underlying hardware/OS/interpreter is, and digging down into it is not possible. : And that's always going to : be the way, because abstractions leak from time to time. Or I should : say, they occasionally have confidential briefings with the press. : Abstracting everything perfectly is neither possible nor desirable. Sure, but every language assumes a certain level of abstraction, and when the abstraction breaks the language fails to be unambiguous and/or portable. -- :-- Hans Georg From sturla at molden.no Wed May 4 13:11:33 2011 From: sturla at molden.no (sturlamolden) Date: Wed, 4 May 2011 10:11:33 -0700 (PDT) Subject: Hooking into Python's memory management References: Message-ID: <7e324a8f-1eb8-4e4a-aa2c-f5ed741c7989@f2g2000yqf.googlegroups.com> On May 4, 6:51?pm, Daniel Neilson wrote: > ? In either case, if such a module is possible, any pointers you could > provide regarding how to implement such a module would be appreciated. The gc module will hook into the garbage collector. The del statement will remove an object from the current scope. (Delete the variable name and decrement the reference count.) Python (CPython that is) is reference counted. When the refcount drops to zero, the object is immediately garbage collected. Python is not like Java, where this happen in bouts. The __del__ method is executed deterministically, it's not like a finalizer in Java or C#. Only dead objects involved in reference circles may linger until they are spotted by the GC. And they may not have a __del__ method, or else the GC will ignore them. In fact, if you don't create circular references, the GC can safely be turned off. If you want volatile references, Python allows weak references as well. Sturla From benjamin.kaplan at case.edu Wed May 4 13:15:43 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 4 May 2011 13:15:43 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <29b1bdc8-7bff-445e-b660-53311ef1eb4d@p19g2000yqh.googlegroups.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <29b1bdc8-7bff-445e-b660-53311ef1eb4d@p19g2000yqh.googlegroups.com> Message-ID: On Wed, May 4, 2011 at 12:40 PM, sturlamolden wrote: > > On May 4, 5:40?pm, Michael Torrie wrote: > > > Which is exactly what the code showed. ?The first one isn't a mistake. > > You just read it wrong. > > No, I read "call-by-value" but it does not make a copy. Call-by-value > dictates a deep copy or copy-on-write. Python does neither. Python > pass a handle to the object, not a handle to a copy of the object. If > you want to see call-by-value in practice, take a look at MATLAB, > SciLab or Octave; or consider what C++ copy constructors do in > function calls with value types. You missed a word in the sentence. "If you can see this, you DON'T have call-by-value" From fred.sells at adventistcare.org Wed May 4 13:16:40 2011 From: fred.sells at adventistcare.org (Sells, Fred) Date: Wed, 4 May 2011 13:16:40 -0400 Subject: newbie needs help with cookielib In-Reply-To: References: Message-ID: I'm using Python 2.4 and 2.7 for different apps. I'm happy with a solution for either one. I've got to talk to a url that uses a session cookie. I only need to set this when I'm developing/debugging so I don't need a robust production solution and I'm somewhat confused by the docs on cookielib. I can use urllib2 without cookielib just fine, but need the cookie to add some security. I'm normally using Firefox 4.0 to login to the server and get the cookie. After that I need some way to set the same cookie in my python script. I can do this by editing my code, since I only need it while defeloping from my test W7 box. I was hoping to find something like ...set_cookie('mycookiename', 'myvalue', 'mydomain.org') I've googled this most of the morning and found everything but what I need, or I just don't understand the basic concept. Any pointers would be greatly appreciated. One of my false starts looks like this. But I get a ... File "C:\alltools\python26\lib\urllib2.py", line 518, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 500: Access Deinied def test1(): cj = cookielib.MozillaCookieJar() cj.load('C:/Users/myname/Desktop/cookies.txt') opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) r = opener.open("http://daffyduck.mydomain.org/wsgi/myapp.wsgi") print r.read() return From sturla at molden.no Wed May 4 13:19:50 2011 From: sturla at molden.no (sturlamolden) Date: Wed, 4 May 2011 10:19:50 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <29b1bdc8-7bff-445e-b660-53311ef1eb4d@p19g2000yqh.googlegroups.com> Message-ID: <4b8ec03d-ccec-4b20-86cc-1373fe5a46a6@p18g2000yqj.googlegroups.com> On May 4, 7:15?pm, Benjamin Kaplan wrote: > You missed a word in the sentence. > > "If you can see this, you DON'T have call-by-value" Indeed I did, sorry! Then we agree :) Sturla From ian.g.kelly at gmail.com Wed May 4 13:30:16 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 May 2011 11:30:16 -0600 Subject: Basic interaction with another program In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 10:52 AM, Grant Edwards wrote: > On 2011-05-04, Matty Sarro wrote: >> On Wed, May 4, 2011 at 12:34 PM, ETP wrote: >>> I have a dos program (run in a window) that I would like to control >>> with a script. > >> Look into the pexpect library, it'll make this easy as punch. > > I don't think pexpect is going to do the OP much good. Quoting from > the web page: > > ?"Pexpect does not currently work on the standard Windows Python" The OP said he was running Linux. I gather the DOS program is being run in DOSBox or something similar. From jjcpl.rpo at gmail.com Wed May 4 13:32:47 2011 From: jjcpl.rpo at gmail.com (Jerome jjcpl.rpo) Date: Wed, 4 May 2011 10:32:47 -0700 (PDT) Subject: Python Developers with 5 years of experience Message-ID: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> send resumes to jerome at jjcpl.net One of our client in New Jersey is looking for Python Developers with 5 years of experience. If you have any resumes please send it across. From tjreedy at udel.edu Wed May 4 13:57:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 13:57:02 -0400 Subject: A very minute correction on PDF In-Reply-To: <073456261C486944897A62516989111CACBC52EE7D@IN-MUM-MAIL2.corp.capgemini.com> References: <073456261C486944897A62516989111CACBC52EE7D@IN-MUM-MAIL2.corp.capgemini.com> Message-ID: <4DC1936E.3090304@udel.edu> On 5/4/2011 3:45 AM, Mehta, Pratik wrote: > For tutorialPython.pdf > Page 17 of the ebook (i.e. page 23 of pdf) under topic *3.2 First Steps > towards programming* > Under while loop, there should be a ?,? after print b > > Print b, > > (a comma after ?b? is missing) [You should mention versions when posting. Above is for 2.7] The example is consistent as it is. A trailing comma would suppress the newline after each output, resulting in a single line of output. 1 1 2 3 5 8 While you could argue that the combined change would be better, the author of the example did not think so. This introductory chapter only uses the simplest form of the print statement. -- Terry Jan Reedy From drsalists at gmail.com Wed May 4 14:06:37 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 4 May 2011 11:06:37 -0700 Subject: Hooking into Python's memory management In-Reply-To: <4DC1841B.2030601@gmail.com> References: <4DC1841B.2030601@gmail.com> Message-ID: Sturla had some great comments; I'll add, in no particular order: 1) You could use the ctypes module to call the real malloc and free from Python. 2) Yes, a Python "C extension module" can do explicit memory allocation. 3) Cython provides a language that is a hybrid of Python and C. It might be nice as a way of introducing explicit memory management. 4) You could also build a heap (not the tree kind, but the malloc kind) in pure Python, and give it alloc and destroy operations. Underneath it all, things would still be reference counted/garbage collected, but that wouldn't actually happen until you used your destroy. On Wed, May 4, 2011 at 9:51 AM, Daniel Neilson wrote: Part of our first year curriculum requires that students be exposed to > explicit dynamic memory allocation in the form of C++'s new/delete, C's > malloc/free, etc. I realize that Python is garbage collected, and that there > is never a need to explicitly allocate & deallocate objects. However, I am > trying to determine whether or not it is possible to simulate that behaviour > within Python via a module for the purposes of instruction. > > For these purposes, I would like to know whether it is possible within > Python 3 to write a Python-only module that, essentially, hooks into the > "constructor" and "destructor" of many of the Python built-in types > (specifically list, dictionary, set, tuple, and string) so that the module > can: > 1) Maintain a list of object id()'s for objects that have been created. > Ideally, this list would also contain the file & line number where the > object was created. > 2) Provide a "deallocate" function that will remove a given object's id() > from the list from (1). > 3) Print out an error message if the python script terminates with a > non-empty list from (1). Preferably with a list of objects that are still > "allocated." > > Baring a Python-only module, would this behaviour be possible to add via a > C-language module? > > A module that hooked in to all memory allocation, and inspected the type > of the object being allocated to conditionally add the object's id() to the > list would also suffice. > > In either case, if such a module is possible, any pointers you could > provide regarding how to implement such a module would be appreciated. > > Thank you for your time, > Daniel > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From as at sci.fi Wed May 4 14:06:49 2011 From: as at sci.fi (Anssi Saari) Date: Wed, 04 May 2011 21:06:49 +0300 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> Message-ID: rusi writes: >> I actually use rcs in Windows. Needs a little setup, but works great, >> from Emacs VC-mode too. > > Where do you get it? > [What google is showing seems to be about 10-15 years old] As far as I know, RCS hasn't been updated since 5.7 which is about 10 years old now. Linux distributions also package the same version. I use the stuff from rcs57pc1.zip, at ftp://ftp.cs.purdue.edu/pub/RCS/ The package includes also comparison tools cmp, diff, diff3, sdiff as win32 versions. I suppose one would need to recompile if 64-bit versions were needed. The setup I mentioned was just setting RCSINIT to -x,v although I don't remember now why I needed that. From invalid at invalid.invalid Wed May 4 14:07:59 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 18:07:59 +0000 (UTC) Subject: Basic interaction with another program References: Message-ID: On 2011-05-04, Ian Kelly wrote: > On Wed, May 4, 2011 at 10:52 AM, Grant Edwards wrote: >> On 2011-05-04, Matty Sarro wrote: >>> On Wed, May 4, 2011 at 12:34 PM, ETP wrote: >>>> I have a dos program (run in a window) that I would like to control >>>> with a script. >> >>> Look into the pexpect library, it'll make this easy as punch. >> >> I don't think pexpect is going to do the OP much good. Quoting from >> the web page: >> >> ?"Pexpect does not currently work on the standard Windows Python" > > The OP said he was running Linux. My bad. When I saw that he wanted to run a DOS program, I jumped to the conclusion he was running Windows and missed the part about puppy linux. > I gather the DOS program is being run in DOSBox or something similar. If it's running in a window as the OP claims, Pexpect still won't work since when DOSBox or DOSEmu runs in a window it isn't reading commands from a pty but rather from X11. If he can get the program to run on a pty (e.g. console or xterm or whatever) rather than in a window, then Pexpect should work. -- Grant Edwards grant.b.edwards Yow! Are we wet yet? at gmail.com From python at rcn.com Wed May 4 14:17:12 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 4 May 2011 11:17:12 -0700 (PDT) Subject: Today's fun and educational Python recipe Message-ID: Here's a 22-line beauty for a classic and amazing algorithm: http://bit.ly/bloom_filter The wiki article on the algorithm is brief and well-written: http://en.wikipedia.org/wiki/Bloom_filter It turns out that people in the 1970's were pretty smart :-) Raymond ------- follow my other python tips and recipes on twitter: @raymondh From robert.kern at gmail.com Wed May 4 14:30:36 2011 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 04 May 2011 13:30:36 -0500 Subject: Pickling extension types In-Reply-To: References: Message-ID: On 5/4/11 10:45 AM, Stefan Kuzminski wrote: > I got this to work by returning from reduce just the args that the __init__ of > the type being pickled requires ( rather than the 5 length tuple described in > the pickling docs ), I am not going to argue with it though.. Let's take a step back. The documentation says to return a tuple between 2 and 5 elements long. You can omit the optional ones or use Nones in their place. The original code you posted allocated a 5-tuple, but did not insert anything into positions 2, 3, or 4. This was an error. You should have returned a 2-tuple of the type object in the 0-index slot and the argument tuple in the 1-index slot. Are you saying that you just returned the argument tuple? I don't think that would work. -- 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 ethan at stoneleaf.us Wed May 4 14:36:51 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 May 2011 11:36:51 -0700 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <4DC19CC3.30802@stoneleaf.us> Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. Don't know if you are still looking for examples, but I recently came across a thread in Python-Dev which had an example using unittest: Ricardo Kirkner wrote [much snippage]: > I'll give you the example I came upon: > > I have a TestCase class, which inherits from both Django's TestCase > and from some custom TestCases that act as mixin classes. So I have > something like > > class MyTestCase(TestCase, Mixin1, Mixin2): > ... > > Since I explicitely base off 3 classes, I expected all 3 > classes to be initialized, and I expect the setUp method to be called > on all of them. As written this example failed because TestCase (from django) was based on unittest2.TestCase, which was not calling super. I understand, however, that if the mixins were listed before TestCase that it would work. Hope this helps. ~Ethan~ From tjreedy at udel.edu Wed May 4 14:37:14 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 14:37:14 -0400 Subject: [ann] pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: On 5/4/2011 10:06 AM, Luke Kenneth Casson Leighton wrote: > after a long delay the pyjamas project - http://pyjs.org - has begun the > 0.8 series of releases, beginning with alpha1: > > https://sourceforge.net/projects/pyjamas/files/pyjamas/0.8/ > > pyjamas is a suite of projects, including a python-to-javascript > compiler As you well know, there is no such thing as 'python' when it comes to compiling actual code. So please specify both in announcements here and on the project homepage http://sourceforge.net/projects/pyjamas/ which versions are supported. I do not really want to have to download and experiment to determine whether to bother downloading. If you do not yet support 3.x, I request and recommend that you do so, even if only on Windows with comtypes. Since comtypes uses ctypes, I presume it works fine with Python 3 (this is one major advantage of using ctypes.) Like it or not, Python 3 is the future of Python. It is the Python that many Python newcomers learn first, and perhaps ever will. Such students usually have no experience or loyalty to any other GUI package, and I am sure that many would love to be able to develop apps that they can run on their desktop, give to friends to run in a browser, and run on their phones. -- Terry Jan Reedy From tjreedy at udel.edu Wed May 4 14:58:23 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 14:58:23 -0400 Subject: Hooking into Python's memory management In-Reply-To: <4DC1841B.2030601@gmail.com> References: <4DC1841B.2030601@gmail.com> Message-ID: <4DC1A1CF.3070002@udel.edu> On 5/4/2011 12:51 PM, Daniel Neilson wrote: > > Hello, > I'm hoping that there will be someone here with sufficient expertise to > answer a question on Python 3 for me. > > I work in the Computer Science department at a large Canadian > University. We are currently doing a feasibility analysis for switching > to using Python in our first year major-stream courses. If you did, I believe you would be following in the footsteps of MIT. > Part of our first year curriculum requires that students be exposed to > explicit dynamic memory allocation in the form of C++'s new/delete, C's > malloc/free, etc. I realize that Python is garbage collected, and that > there is never a need to explicitly allocate & deallocate objects. > However, I am trying to determine whether or not it is possible to > simulate that behaviour within Python via a module for the purposes of > instruction. The Python ctypes module allows one to invoke compiled C (or C++, I presume) functions in shared libraries (.dll on Windows, .so on *Nix). > For these purposes, I would like to know whether it is possible within > Python 3 to write a Python-only module that, essentially, hooks into the > "constructor" and "destructor" of many of the Python built-in types Python is compiled as a small startup executable (<30 KB). The builtins are all in shared libraries that you can access with ctypes. The functions in those libraries are documented in the Python/C API manual. > (specifically list, dictionary, set, tuple, and string) so that the > module can: > 1) Maintain a list of object id()'s for objects that have been created. > Ideally, this list would also contain the file & line number where the > object was created. > 2) Provide a "deallocate" function that will remove a given object's > id() from the list from (1). > 3) Print out an error message if the python script terminates with a > non-empty list from (1). Preferably with a list of objects that are > still "allocated." I presume you can do all of this easily. For point 3, a script can register an 'atexit' function. As a sidenote, using ctypes 'allows' one to crash (segfault, bluescreen) a program just like when using C ;-). It thus voids the usual guarantee that one cannot do that. > Baring a Python-only module, would this behaviour be possible to add via > a C-language module? I do not think you will *need* to do this, though you might eventually decide to make a custom library with just the functions you want, with the names you want. > A module that hooked in to all memory allocation, and inspected the type > of the object being allocated to conditionally add the object's id() to > the list would also suffice. > > In either case, if such a module is possible, any pointers you could > provide regarding how to implement such a module would be appreciated. I hope the above helps. I think Python is a great learning language. -- Terry Jan Reedy From irmen at -NOSPAM-xs4all.nl Wed May 4 15:02:17 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Wed, 04 May 2011 21:02:17 +0200 Subject: Today's fun and educational Python recipe In-Reply-To: References: Message-ID: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> On 04-05-11 20:17, Raymond Hettinger wrote: > Here's a 22-line beauty for a classic and amazing algorithm: > http://bit.ly/bloom_filter > > The wiki article on the algorithm is brief and well-written: > http://en.wikipedia.org/wiki/Bloom_filter > > It turns out that people in the 1970's were pretty smart :-) > I think that often, the cleverness of people is inversely proportional to the amount of CPU power and RAM that they have in their computer. "Meh, what would I need such a thing for, I could just as well stick everything into a list" Thankfully there are also people for whom this doesn't count. (are they stuck in the '70s?) Also: wasn't there a talk on Pycon in which a bloom filter was mentioned? Irmen From python at rcn.com Wed May 4 15:13:15 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 4 May 2011 12:13:15 -0700 (PDT) Subject: Today's fun and educational Python recipe References: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> Message-ID: <00cf6d1f-518e-4638-abdf-9db2cad0735b@q12g2000prb.googlegroups.com> > > It turns out that people in the 1970's were pretty smart :-) > > I think that often, the cleverness of people is inversely proportional > to the amount of CPU power and RAM that they have in their computer. The Google guys have plenty of CPU power *and* plenty of cleverness :-) According to the wikipedia article, Google BigTable uses Bloom filters to reduce the disk lookups for non-existent rows or column. The Google Chrome web browser also uses Bloom filters to speed up its Safe Browsing service. > Also: wasn't there a talk on Pycon in which a bloom filter was mentioned? Yes! As a matter of fact there was: http://www.slideshare.net/c.titus.brown/pycon-2011-talk-ngram-assembly-with-bloom-filters Raymond ------- follow my other python tips and recipes on twitter: @raymondh From tjreedy at udel.edu Wed May 4 15:15:24 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 15:15:24 -0400 Subject: Basic interaction with another program In-Reply-To: References: Message-ID: On 5/4/2011 12:34 PM, ETP wrote: > I have a dos program (run in a window) that I would like to control > with a script. Look at the subprocess module. You may have to (and be able to) have it start up the window program with the dos program as an argument. It needs only text input. For example, I only need to > tell it: > > L > u > 100 > u > You should be able to send this through a pipe connected to the subprocess. -- Terry Jan Reedy From invalid at invalid.invalid Wed May 4 15:17:19 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 19:17:19 +0000 (UTC) Subject: Today's fun and educational Python recipe References: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> Message-ID: On 2011-05-04, Irmen de Jong wrote: > On 04-05-11 20:17, Raymond Hettinger wrote: >> Here's a 22-line beauty for a classic and amazing algorithm: >> http://bit.ly/bloom_filter >> >> The wiki article on the algorithm is brief and well-written: >> http://en.wikipedia.org/wiki/Bloom_filter >> >> It turns out that people in the 1970's were pretty smart :-) >> > > I think that often, the cleverness of people is inversely > proportional to the amount of CPU power and RAM that they have in > their computer. True. Unfortunately the difficulty in debugging and maintaining code is often directly proportional to the cleverness exhibited by the original programmer. -- Grant Edwards grant.b.edwards Yow! I'm also against at BODY-SURFING!! gmail.com From harrismh777 at charter.net Wed May 4 15:22:38 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 14:22:38 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <7q1898-f3l.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: <3Ihwp.18043$Ot6.11759@newsfe15.iad> Hans Georg Schaathun wrote: > It only works by assuming > knowledge of C, which is language which has proved unsuitable for > complex and abstract data modelling. That statement is untrue; evidenced by the very fact the CPython's complex and abstract data modeling has been very suitably handled by C. You cannot possibly mean what you have asserted... I realize there must be a contextual problem. I have been handling complex data abstractions with C for more than 20 years... its quite well suited to the task... although, I am able to do my research today faster and with less lines of code in CPython. That does not in any way impugn C..;. quite the contrary, given enough time, C is better suited for modeling on a von Neumann processor, period. Here is the thing that everyone forgets... all we have to work with is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). Assembler is still the best language on that processor. 'C' is still the best high-level language on that processor. CPython is implemented in C for a reason: gcc and the von Neumann processor make it a no-brainer. Its silly to claim that one high-level language or another is better suited to complex data abstraction... don't go there. > Digging down into C should be unnecessary to explain Python. huh? You have to be kidding. Why do you suppose we want it to be open-sourced? Use the force Luke, read the source. If you really want to know how Python is working you *must* dig down into the C code which implements it. The folks who document Python should be able to tell us enough to know how to use the language, but to really 'know' you need the implementation source. kind regards, m harris From no.email at nospam.invalid Wed May 4 15:27:48 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 04 May 2011 12:27:48 -0700 Subject: Today's fun and educational Python recipe References: Message-ID: <7xy62mxo3v.fsf@ruckus.brouhaha.com> Raymond Hettinger writes: > Here's a 22-line beauty for a classic and amazing algorithm: > http://bit.ly/bloom_filter The use of pickle to serialize the keys is a little bit suspicious if there might be a reason to dump the filter to disk and re-use it in another run of the program. Pickle representation might change between Python releases, for example. It's just supposed to stay interoperable between versions, not necessarily bitwise-identical. Otherwise it's quite nice. I'd suggest adding a .update() operation that adds keys from a user-supplied iterator. From harrismh777 at charter.net Wed May 4 15:33:34 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 14:33:34 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Hans Georg Schaathun wrote: > In C it is pass by value, as the pointer > is explicit and do whatever you want with the pointer value. You clearly are not a C programmer. Most of my C data abstractions use dual circular linked lists of pointers to structures of pointers. *All* of that is only ever passed (at least in my programming) as references. My code almost never passes data by value. We do not consider passing a pointer as *by value* because its an address; by definition, that is pass-by-reference. We are not passing the *value* of the data, we are passing the memory location (the reference) to the data. Pass by *value* on the other hand actually places the *value* of the data item on the call stack as a parameter. Much of this conversation has more to do with semantics. kind regards, m harris From irmen at -NOSPAM-xs4all.nl Wed May 4 15:35:11 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Wed, 04 May 2011 21:35:11 +0200 Subject: Today's fun and educational Python recipe In-Reply-To: <00cf6d1f-518e-4638-abdf-9db2cad0735b@q12g2000prb.googlegroups.com> References: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> <00cf6d1f-518e-4638-abdf-9db2cad0735b@q12g2000prb.googlegroups.com> Message-ID: <4dc1aa6f$0$41102$e4fe514c@news.xs4all.nl> On 04-05-11 21:13, Raymond Hettinger wrote: >>> It turns out that people in the 1970's were pretty smart :-) >> >> I think that often, the cleverness of people is inversely proportional >> to the amount of CPU power and RAM that they have in their computer. > > The Google guys have plenty of CPU power *and* plenty of > cleverness :-) Haha, true. We need to add a Googlyness factor in the equation. Or perhaps: think what they could achieve if they only had a few machines instead of thousands ;-) >> Also: wasn't there a talk on Pycon in which a bloom filter was mentioned? > > Yes! As a matter of fact there was: > http://www.slideshare.net/c.titus.brown/pycon-2011-talk-ngram-assembly-with-bloom-filters Thanks, that was the one. I didn't attend Pycon but I watched a truckload of talks on blip.tv and that one caught my attention because of its somewhat funny title 'handling ridiculous amounts of data with probabilistic data structures' I didn't understand all of it but the name Bloom Filter stuck, it seems. Adding it to my list of bookmarks of useful-stuff-I-intend-to-use-one-day-in-the-future... Irmen From tjreedy at udel.edu Wed May 4 15:42:33 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 15:42:33 -0400 Subject: Today's fun and educational Python recipe In-Reply-To: References: Message-ID: On 5/4/2011 2:17 PM, Raymond Hettinger wrote: > Here's a 22-line beauty for a classic and amazing algorithm: > http://bit.ly/bloom_filter > > The wiki article on the algorithm is brief and well-written: > http://en.wikipedia.org/wiki/Bloom_filter As I understand the article, the array of num_bits should have num_probes (more or less independent) bits set for each key. But as I understand the code for i in range(self.num_probes): h, array_index = divmod(h, num_words) h, bit_index = divmod(h, 32) yield array_index, 1 << bit_index the same bit is being set or tested num_probes times. The last three lines have no dependence on i that I can see, so they appear to do the same thing each time. This seems like a bug. The article says "For a good hash function with a wide output, there should be little if any correlation between different bit-fields of such a hash, so this type of hash can be used to generate multiple "different" hash functions by slicing its output into multiple bit fields. Alternatively, one can pass k different initial values (such as 0, 1, ..., k ? 1) to a hash function that takes an initial value; or add (or append) these values to the key." I do not see the code doing either of these. -- Terry Jan Reedy From benjamin.kaplan at case.edu Wed May 4 15:46:07 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 4 May 2011 15:46:07 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <3Ihwp.18043$Ot6.11759@newsfe15.iad> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: On Wed, May 4, 2011 at 3:22 PM, harrismh777 wrote: > Hans Georg Schaathun wrote: >> >> It only works by assuming >> knowledge of C, which is language which has proved unsuitable for >> complex and abstract data modelling. > > ? That statement is untrue; evidenced by the very fact the CPython's complex > and abstract data modeling has been very suitably handled by C. > ? You cannot possibly mean what you have asserted... I realize there must be > a contextual problem. ?I have been handling complex data abstractions with C > for more than 20 years... its quite well suited to the task... although, I > am able to do my research today faster and with less lines of code in > CPython. ?That does not in any way impugn C..;. quite the contrary, given > enough time, ?C is better suited for modeling on a von Neumann processor, > period. > > ? Here is the thing that everyone forgets... all we have to work with is a > von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). Assembler is > still the best language on that processor. ?'C' ?is still the best > high-level language on that processor. ?CPython is implemented in C for a > reason: ?gcc and the von Neumann processor make it a no-brainer. > CPython is implemented in C because that's the language chosen. Python is also implemented in Java, C#, Python, and several other languages. And it's not tied to the von Neumann architecture either. Only the current implementations of it are. > ? Its silly to claim that one high-level language or another is better > suited to complex data abstraction... don't go there. > > >> Digging down into C should be unnecessary to explain Python. > > > ? huh? ? You have to be kidding. Why do you suppose we want it to be > open-sourced? ? Use the force Luke, read the source. ? If you really want to > know how Python is working you *must* dig down into the C code which > implements it. ?The folks who document Python should be able to tell us > enough to know how to use the language, but to really 'know' you need the > implementation source. > Reading the CPython sources will show you how CPython works under the hood, but it has nothing to do with how Python works. There are lots of things that CPython does that "Python" does not. For instance, the GIL is not a part of Python. Reference counting is not a part of Python. Caching small integers and strings is not a part of Python. Why not read the Jython sources instead of the CPython? It's the same language, after all. From harrismh777 at charter.net Wed May 4 15:47:35 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 14:47:35 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Devin Jeanpierre wrote: >> "How was the date last night?" >> > "Oh, it was marvelous! He presented me with a single red stink-weed, and >> > then we went to a disgusting little restaurant. I had the swill." > Please don't argue with me in this manner. D'Aprano takes a little getting used to. He likes strawmen, red-hearings, and the venerable bogus analogy. Just read around them, he usually has some good points in there... kind regards, m harris From hg at schaathun.net Wed May 4 15:58:01 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 20:58:01 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <9nn898-dnl.ln1@svn.schaathun.net> On Wed, 04 May 2011 14:22:38 -0500, harrismh777 wrote: : That statement is untrue; evidenced by the very fact the CPython's : complex and abstract data modeling has been very suitably handled by C. That's an implementation. Not modelling. : You cannot possibly mean what you have asserted... I realize there : must be a contextual problem. I have been handling complex data : abstractions with C for more than 20 years... I did not say that it is impossible. On the other hand, you are clearly not talking about abstraction or modelling at all, but rather about computation or data processing. : its quite well suited to : the task... although, I am able to do my research today faster and with : less lines of code in CPython. That does not in any way impugn C..;. : quite the contrary, given enough time, C is better suited for modeling : on a von Neumann processor, period. What has that got to do with abstraction? : Here is the thing that everyone forgets... all we have to work with : is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). : Assembler is still the best language on that processor. 'C' is still : the best high-level language on that processor. CPython is implemented : in C for a reason: gcc and the von Neumann processor make it a no-brainer. Again, what has that got to do with abstraction? : Its silly to claim that one high-level language or another is better : suited to complex data abstraction... don't go there. : : > Digging down into C should be unnecessary to explain Python. : : huh? You have to be kidding. Why do you suppose we want it to be : open-sourced? Python is a /language/. The /implementation/ is may be open-source (and may or may not be written in C). : Use the force Luke, read the source. If you really : want to know how Python is working you *must* dig down into the C code : which implements it. Except that whatever you learn by doing so is only valid for that one interpreter. -- :-- Hans Georg From harrismh777 at charter.net Wed May 4 15:58:38 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 14:58:38 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: Benjamin Kaplan wrote: > CPython is implemented in C because that's the language chosen. Python > is also implemented in Java, C#, Python, and several other languages. True enough. If I used Jython, I would want to take a look at those sources... as well as the Java sources... which were wrtten in, um, C. > And it's not tied to the von Neumann architecture either. Only the > current implementations of it are. Oh, yes they are. That is the $10,000,000 dollar problem... how to extricate ourselves from the von Neumann processor. *Everthing* comes down to that... its hilarious to hear folks talk about lambda the ultimate (especially those guys on Lambda the Ultimate) when there is no such thing until such time as we have lambda the hardware architecture. As long as we are all constrained to funnel data through the von Neumann ALU, that really is *all* that matters. Another way of saying this is that no matter how sophisticated our high level coding gets, it all has to be translated somehow one way or another into von Neumann codes toggling 1's and 0's on and off in the registers of the von Neumann ALU. > Reading the CPython sources will show you how CPython works under the > hood, but it has nothing to do with how Python works. Not conceptually, but practically. For instance, for a C programmer to see that Python's object references are C void pointers, tells the newbie Python ( C programmer ) much about how Python considers variables... as references... to objects. > There are lots > of things that CPython does that "Python" does not. For instance, the > GIL is not a part of Python. Reference counting is not a part of > Python. Caching small integers and strings is not a part of Python. This is not something I was aware of... caching of small ints is unique to CPython implementation only ?? I guess I'll have to go read the "sources" of the other implementations to check that out... ;-) > Why not read the Jython sources instead of the CPython? It's the same > language, after all. Yep. Agreed. .... on both counts. From invalid at invalid.invalid Wed May 4 16:19:05 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 20:19:05 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On 2011-05-04, harrismh777 wrote: > Hans Georg Schaathun wrote: >> In C it is pass by value, as the pointer is explicit and do whatever >> you want with the pointer value. > > You clearly are not a C programmer. > > Most of my C data abstractions use dual circular linked lists of > pointers to structures of pointers. *All* of that is only ever passed > (at least in my programming) as references. My code almost never > passes data by value. > > We do not consider passing a pointer as *by value* because its an > address; by definition, that is pass-by-reference. No, it isn't. It's pass by value. The fact that you are passing a value that is a pointer to another value is not relevent. Pass by reference means that if I call foo(x) And foo looks like this: foo(param) param = 4 Then 'x' in the caller's namespace ends up set to 4. > We are not passing the *value* of the data, we are passing the memory > location (the reference) to the data. You're pass a value. That value is a pointer to some other value. > Pass by *value* on the other hand actually places the *value* of the > data item on the call stack as a parameter. C is pass by value. if I call foo(x) And this is foo: void foo (float param) { param = 1.23 } The value of x in the caller's namespace is not changed. If C used pass by reference, x would change. -- Grant Edwards grant.b.edwards Yow! SHHHH!! I hear SIX at TATTOOED TRUCK-DRIVERS gmail.com tossing ENGINE BLOCKS into empty OIL DRUMS ... From hg at schaathun.net Wed May 4 16:20:54 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 21:20:54 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <62p898-ipl.ln1@svn.schaathun.net> On Wed, 04 May 2011 14:33:34 -0500, harrismh777 wrote: : Hans Georg Schaathun wrote: : > In C it is pass by value, as the pointer : > is explicit and do whatever you want with the pointer value. : : You clearly are not a C programmer. I am not really a programmer period. I am many things and run into programming from many more angles than a typical programmer does. And as to C, I no longer use C when I can avoid it (which I can most but not all of the time). A few words are missing though. C is semantically pass by value. Always. But because you have pointers are data object, you can do whatever you want with them, and pass a pointer by value. Thus you can achieve the effect of transmission by reference or by name, if you want to. : Most of my C data abstractions use dual circular linked lists of : pointers to structures of pointers. *All* of that is only ever passed : (at least in my programming) as references. My code almost never passes : data by value. Not if you do not consider pointers as data, but C does, in the sense that pointers can be manipulated in the same ways as any other kind of data. : We do not consider passing a pointer as *by value* because its an : address; by definition, that is pass-by-reference. We are not passing : the *value* of the data, we are passing the memory location (the : reference) to the data. Pass by *value* on the other hand actually : places the *value* of the data item on the call stack as a parameter. That is a useful viewpoint, but it falls a bit short when you need to explain how to deal with pointers to pointers to pointers. Pointers in C are objects. But mind you, I was not the one to suggested to refer to this as pass by value. I was explaining why it makes more sense to do so for C but not for Python. You simply end up with different wordings if you try to explain how C works, and how to model data in C. We can both be right, you know; we are just addressing the issues at different levels of abstraction. : Much of this conversation has more to do with semantics. Of course. The concepts are used to explain the semantics of the languages. -- :-- Hans Georg From drsalists at gmail.com Wed May 4 16:24:10 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 4 May 2011 13:24:10 -0700 Subject: Basic interaction with another program In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 9:34 AM, ETP wrote: > I have a dos program (run in a window) that I would like to control > with a script. It needs only text input. > > It will then wait for a file to be created, rename the file, then > loop. Simple. > Or not. > I'd like to run this on Lucid Puppy Linux as it will be implemented on > a very old laptop, but can probably deal with windows if needed. > Easiest would probably be to do this on Windows - not because of any inherent value in Windows, but because Microsoft limited what you could do to protect their own interests. I believe I once encountered a DOS emulator that could give curses output for non-graphical (no CGA, Hercules, EGA, or VGA) applications. It was ages ago. It probably was on SCO Xenix. You could try one of these, and then talk to your program over a serial port: http://en.wikipedia.org/wiki/PC_Weasel_2000 ...but I wouldn't count on it working well on a laptop. You could possibly set up a DOS box somewhere, and access it over a network from your laptop - depending on how the DOS program is doing its I/O. If it's writing directly to video RAM, good luck (other than the PC Weasel option), but if it's disciplined enough to use DOS or the BIOS for I/O, it might work pretty well. Your best option, if legally and economically viable, would be to get the source code to your DOS app and port it (or have it ported) to Linux. Back in the DOS days, Some programs were surprisingly easily ported to *ix. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hg at schaathun.net Wed May 4 16:40:43 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 21:40:43 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: On Wed, 04 May 2011 14:58:38 -0500, harrismh777 wrote: : True enough. If I used Jython, I would want to take a look at those : sources... as well as the Java sources... which were wrtten in, um, C. And then, suddenly, you'll be developing code which fails on CPython instead of code which fails on Jython. Except that it will still fail on Jython too, unless you happen to have the right jvm. Marvelous. : Oh, yes they are. That is the $10,000,000 dollar problem... how to : extricate ourselves from the von Neumann processor. *Everthing* comes : down to that... its hilarious to hear folks talk about lambda the : ultimate (especially those guys on Lambda the Ultimate) when there is no : such thing until such time as we have lambda the hardware architecture. The problem with your approach is that software development does not scale. Assembly worked very well with a few 100 lines of codes half a century ago. C and friends were a great step forward and reduced the complexity to allow another magnitude of lines of codes. Then came further languages further removed from von Neumann, but close enough to human cognition to handle yet a magnitude or too. Of course you can still gain useful understanding by studying assembly or von Neumann, or the instruction set of the CPU you use. And in some projects it may be an optimal strategy. However, there are many skills necessary to make an efficient system and in many projects assembly and hardware skills are far down the list. Virtualisation is there to the cut costs of rethinking solutions for multiple architectures. If you need to understand the implementation to do your programming, you are in fact disregarding one of the most significant achievements deployed in computing the last two decades. : Not conceptually, but practically. For instance, for a C programmer : to see that Python's object references are C void pointers, tells the : newbie Python ( C programmer ) much about how Python considers : variables... as references... to objects. And of course, this is useful as /one/ way to consider python variables. As long as one is aware that this is just an example, one approach out of many, then it enhances understanding. If one blindly extrapolates from one implementation, it enhances misunderstanding. -- :-- Hans Georg From tacyt1007 at gmail.com Wed May 4 17:09:09 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Wed, 4 May 2011 23:09:09 +0200 Subject: Embedding Python's library as zip file Message-ID: Hello, I spent a lot of time googling for a solution of this problem, with no result. I have a C++ application, in which I would like to embed Python interpreter. I don't want to rely on an interpreter being installed on user machine, instead I would like to distribute all the necessary files with my app. As far as I understand, beside of my executable and Python.dll (I am using Python27), I need to provide two folders: - DLLs, - Lib If I place the Lib folder and the contents of the DLLs folder in a directory of my executable, then everything seems to work. However I would like to use a zipped Lib folder. Hence I made an archive (which contains contents of Lib folder) called Python27.zip. Unfortunately the app crashes during execution. I assume the reason might be lack of zlib.pyd. Is that assumption correct? If so, how to obtain it? If not, what am I doing wrong? Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From harrismh777 at charter.net Wed May 4 17:35:50 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 16:35:50 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Grant Edwards wrote: >> We do not consider passing a pointer as*by value* because its an >> > address; by definition, that is pass-by-reference. > No, it isn't. It's pass by value. The fact that you are passing a > value that is a pointer to another value is not relevent. > @ Edwards, &Schaathun You are most definitely mistaken. See: http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr233.htm I understand that semantically some people insist that when C receives parms as pointers that pass-by-reference is only being simulated. But that is the silliness of this argument... because down in the guts of the ALU we only have direct and indirect memory addressing. Period. You either pass a function the memory directly (value) or you pass the data indirectly (reference). Everything above that is high-level semantics. If I want to pass values to my C functions, I can. If I want to pass references to my C functions, I can. If I want to implement a C language that does not use pointers directly (hides them) I can implement pass by reference completely (on the surface). In fact, I can implement the C compiler so that pass by value is not allowed! [ it wouldn't look much like C, but its do-able ] Everyone forgets that their high-level language is not 'really' what's working... gcc does not produce machine code... it produces assembler instructions that are passed to a translator... you can interrupt the process and have it produce the assembly instructions so you can see them if you want to... the point being, after all is said and done, all you can do with today's von Neumann processors is pass data directly (value) or indirectly (reference). Everything else is semantics. From python at rcn.com Wed May 4 17:39:28 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 4 May 2011 14:39:28 -0700 (PDT) Subject: Today's fun and educational Python recipe References: Message-ID: On May 4, 12:42?pm, Terry Reedy wrote: > On 5/4/2011 2:17 PM, Raymond Hettinger wrote: > > > Here's a 22-line beauty for a classic and amazing algorithm: > >http://bit.ly/bloom_filter > > > The wiki article on the algorithm is brief and well-written: > >http://en.wikipedia.org/wiki/Bloom_filter > > As I understand the article, the array of num_bits should have > num_probes (more or less independent) bits set for each key. But as I > understand the code > > ? ? ? ? ?for i in range(self.num_probes): > ? ? ? ? ? ? ?h, array_index = divmod(h, num_words) > ? ? ? ? ? ? ?h, bit_index = divmod(h, 32) > ? ? ? ? ? ? ?yield array_index, 1 << bit_index > > the same bit is being set or tested num_probes times. The last three > lines have no dependence on i that I can see, so they appear to do the > same thing each time. This seems like a bug. The 512 bits in h are progressively eaten-up between iterations. So each pass yields a different (array index, bit_mask) pair. It's easy to use the interactive prompt to show that different probes are produced on each pass: >>> bf = BloomFilter(num_bits=1000, num_probes=8) >>> pprint(list(bf.get_probes('Alabama'))) [(19, 1073741824), (11, 64), (9, 134217728), (25, 1024), (24, 33554432), (6, 16), (7, 16777216), (22, 1048576)] The 512 bits are uncorrelated -- otherwise sha512 wouldn't be much of a cryptographic hash ;) The fifty state example in the recipe is a reasonable demonstration that the recipe works as advertised. It successfully finds all fifty states (the true positives) and it tries 100,000 negatives resulting in only a handful of false negatives. That should be somewhat convincing that it all works. Raymond ------- follow my other python tips and recipes on twitter: @raymondh From ben+python at benfinney.id.au Wed May 4 17:43:59 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 May 2011 07:43:59 +1000 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mxj2f8f4.fsf@benfinney.id.au> Steven D'Aprano writes: > Given the following statement of Python code: > > >>> x = "spam" > > what is the value of the variable x? Mu (?). ?x? is a name. Names are bound to values. Talk of ?variable? only confuses the issue because of the baggage carried with that term. Yes, the Python documentation disagrees with me. > (1) The string "spam". > I argue that any answer except for (1) is (almost always) counter- > productive: it adds more confusion than shedding light. I prefer to respond ?The name ?x? is bound to a string, "spam"?. (If I knew which version of Python we're using, I'd qualify the type as ?a text string? or ?a byte string?.) > It requires thinking at the wrong level, at the implementation level > instead of the level of Python code. If we define "value" to mean the > invisible, inaccessible reference, then that leaves no word to > describe was the string "spam" is. Fine, the value is the string. No problem there. But the data model of Python doesn't fit well with the ideas that the term ?variable? connotes for most programmers: a box, perhaps of a rigid shape (data type) or not, which is labelled ?x? and nothing else. For another variable to have an equal value, that value needs to be copied and put in a separate box; or perhaps some special reference to the original needs to be made and placed in a box. Saying ?variable? and ?has the value? just invites baggage needlessly, and creates many assumptions about Python's data model which has to be un-done, often after much false mental scaffolding has been built on them by the newbie and needs to be dismantled carefully. As we all know, Python doesn't work as the term ?variable? implies for many. Rather, ?x? isn't a container at all, but an identifier only. It's more like a paper tag which can be tied to objects; that brings a bunch of useful implications: * that the paper tag is tied to only one object * that a paper tag tied to no object is rather useless * that many paper tags can be tied to the same object * that the paper tag is only loosely associated with the object and can be removed and tied to a different object, without any change to the objects themselves * that the object doesn't necessarily have any tag at a given point in time * that the tag with its string is useful to find the object even without a name on the tag (the concept of other non-name bindings to objects, e.g. list items) All those implications of the ?paper tag? analogy are helpful in thinking about the Python data model. And those implications don't even have to be explicitly stated in order to help. So instead of inviting confusion with ?variable ?x? has the value "spam"? I prefer to say ?name ?x? is bound to the value "spam"?. > The intellectual contortions that some people will go through to > hammer the square peg of actual programming language behaviour into > the two round holes of "pass by value" and "pass by reference" never > cease to astonish me. I maintain that avoiding the use of the term ?variable?, and gently correcting those who use it in the context of Python (with humility in the face of the fact that the Python documentation liberally uses the term), can short-circuit a lot of that needless confusion. Python isn't pass by anything. Nothing gets copied, nothing gets passed; when a function is called with an object as a parameter, the object stays put, and simply gets a new temporary name bound to it for the function's use. Speaking of objects (or values) with names bound to them helps that explanation in a way that the traditional image of ?variables? does not. > > Whatever, a rose by any other name...) > > Do you really think that roses would be the symbol of romantic love if > they were called "disgusting stink-weeds of perversion and death"? Juliet's point stands, though: they would still smell as sweet, and the term you describe would be unlikely to catch on since it doesn't describe them well at all. -- \ ?I like to fill my bathtub up with water, then turn the shower | `\ on and pretend I'm in a submarine that's been hit.? ?Steven | _o__) Wright | Ben Finney From ben+python at benfinney.id.au Wed May 4 17:46:13 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 May 2011 07:46:13 +1000 Subject: Python Developers with 5 years of experience References: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> Message-ID: <87iptqf8be.fsf@benfinney.id.au> "Jerome jjcpl.rpo" writes: > One of our client in New Jersey is looking for Python Developers with > 5 years of experience. If you have any resumes please send it across. Please do not solicit for jobs here. Instead, the Python Job Board is intended for that purpose. -- \ ?The right to search for truth implies also a duty; one must | `\ not conceal any part of what one has recognized to be true.? | _o__) ?Albert Einstein | Ben Finney From harrismh777 at charter.net Wed May 4 17:49:25 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 16:49:25 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <9nn898-dnl.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <9nn898-dnl.ln1@svn.schaathun.net> Message-ID: Hans Georg Schaathun wrote: > That does not in any way impugn C..;. > : quite the contrary, given enough time, C is better suited for modeling > : on a von Neumann processor, period. > > What has that got to do with abstraction? Everything, really. Folks seem to think that because they are doing abstraction at a high-level (well, they never maybe programmed at a lower level) that abstraction somehow 'requires' a high level language. (not true) Back in the day, our abstractions were encapsulated not in source, but in psuedo-code, flow-charts, diagrams, and sometimes pretty pictures. It all ended up in assembly and machine code. Today, high-level languages like Python (and others) allow programmers to place some of their abstraction into their source code directly. This does not make the high-level language any more 'suited' to abstraction than any other lower-level language; because the abstraction is a mental process not a language feature. It all ends up in assembly and machine code. kind regards, m harris From nagle at animats.com Wed May 4 17:52:11 2011 From: nagle at animats.com (John Nagle) Date: Wed, 04 May 2011 14:52:11 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc1ca92$0$10552$742ec2ed@news.sonic.net> On 5/4/2011 3:51 AM, Steven D'Aprano wrote: > On Wed, 04 May 2011 02:56:28 -0700, Devin Jeanpierre wrote: > >> Python is pass-by-value in a >> meaningful sense, it's just that by saying that we say that the values >> being passed are references/pointers. This is maybe one level of >> abstraction below what's ideal, > > "Maybe"? > > Given the following statement of Python code: > >>>> x = "spam" > > what is the value of the variable x? Is it...? > > (1) The string "spam". > > (2) Some invisible, inaccessible, unknown data structure deep in the > implementation of the Python virtual machine, which the coder cannot > access in any way using pure Python code. > > (Possibly a pointer, but since it's an implementation detail, other > implementations may make different choices.) > > (3) Something else. > > > I argue that any answer except for (1) is (almost always) counter- > productive: it adds more confusion than shedding light. It requires > thinking at the wrong level, at the implementation level instead of the > level of Python code. If we define "value" to mean the invisible, > inaccessible reference, then that leaves no word to describe was the > string "spam" is. > > (I say "almost always" counter-productive because abstractions leak, and > sometimes you do need to think about implementation.) Yes. In Python, the main leak involves the "is" operator and the "id()" function. Consider: >>> x = "spam" >>> y = "spam" >>> x == y True >>> x is y True >>> z = x + 'a' >>> z = z[:4] >>> z 'spam' >>> x is z False >>> x == z True >>> id(x) 30980704 >>> id(y) 30980704 >>> id(z) 35681952 There, the abstraction has broken down. x, y, and z all reference the value "spam", but they reference two, not one or three, instances of it. Arguably, Python should not allow "is" or "id()" on immutable objects. The programmer shouldn't be able to tell when the system decides to optimize an immutable. "is" is more of a problem than "id()"; "id()" is an explicit peek into an implementation detail. The "is" operator is a normal part of the language, and can result in weird semantics. Consider >>> 1 is (1+1-1) True >>> 100000 is (100000+1-1) False That's a quirk of CPython's boxed number implementation. All integers are boxed, but there's a set of canned objects for small integers. CPython's range for this is -5 to +256, incidentally. That's visible through the "is" operator. Arguably, it should not be. John Nagle From python at rcn.com Wed May 4 17:53:35 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 4 May 2011 14:53:35 -0700 (PDT) Subject: Today's fun and educational Python recipe References: <7xy62mxo3v.fsf@ruckus.brouhaha.com> Message-ID: <555ea465-0faf-428b-bfe0-c51efbc2d07f@35g2000prp.googlegroups.com> On May 4, 12:27?pm, Paul Rubin wrote: > Raymond Hettinger writes: > > Here's a 22-line beauty for a classic and amazing algorithm: > >http://bit.ly/bloom_filter > > The use of pickle to serialize the keys is a little bit suspicious if > there might be a reason to dump the filter to disk and re-use it in > another run of the program. ?Pickle representation might change between > Python releases, for example. ?It's just supposed to stay interoperable > between versions, not necessarily bitwise-identical. > > Otherwise it's quite nice. ?I'd suggest adding a .update() operation > that adds keys from a user-supplied iterator. I chose pickle because it solved the problem of turning arbitrary objects into bytes which are needed as inputs to sha512. It seems that this particular choice of hash function is distracting some readers away from the interesting part of how a Bloom filter works. Since the choice of hash functions is completely arbitrary, I'm thinking of substituting something a little more basic. What do you think of this alternative as a way to make it clearer that each successive probe is uncorrelated, yet fully dependent on the key? def get_probes(self, key): hasher = Random(key).randrange num_words = len(self.arr) for _ in range(self.num_probes): array_index = hasher(num_words) bit_index = hasher(32) yield array_index, 1 << bit_index Raymond ------- follow my other python tips and recipes on twitter: @raymondh From invalid at invalid.invalid Wed May 4 17:57:29 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 21:57:29 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On 2011-05-04, harrismh777 wrote: > Grant Edwards wrote: >>> We do not consider passing a pointer as*by value* because its an >>> > address; by definition, that is pass-by-reference. >> No, it isn't. It's pass by value. The fact that you are passing a >> value that is a pointer to another value is not relevent. >> > > @ Edwards, &Schaathun > > You are most definitely mistaken. The "pass by value" and "pass by reference" parameter passing mechanisms are pretty well defined, and C uses "pass by value". > I understand that semantically some people insist that when C > receives parms as pointers that pass-by-reference is only being > simulated. And they are right. > If I want to pass values to my C functions, I can. If I want to pass > references to my C functions, I can. We're not talking about what _you_ do. We're talking about what the C _compiler_ does. The C compiler passes by value -- always. > If I want to implement a C language that does not use pointers directly > (hides them) I can implement pass by reference completely (on the > surface). That wouldn't be C. > In fact, I can implement the C compiler so that pass by value is not > allowed! [ it wouldn't look much like C, but its do-able ] If you don't pass by value, it's not a C compiler. > Everyone forgets that their high-level language is not 'really' > what's working... gcc does not produce machine code... it produces > assembler instructions that are passed to a translator... you can > interrupt the process and have it produce the assembly instructions > so you can see them if you want to... the point being, after all is > said and done, all you can do with today's von Neumann processors is > pass data directly (value) or indirectly (reference). I have no idea what your point is. At the machine level, there _is_ nothing but values. You can use a value as an integer, or as a pointer. It's still just a value. But we're talking about parameter passing mechanisms defined by high-level language specifications -- particularly C. -- Grant Edwards grant.b.edwards Yow! It was a JOKE!! at Get it?? I was receiving gmail.com messages from DAVID LETTERMAN!! ! From ian.g.kelly at gmail.com Wed May 4 18:01:39 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 May 2011 16:01:39 -0600 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak wrote: > Hello, > > I spent a lot of time googling for a solution of this problem, with no > result. > > I have a C++ application, in which I would like to embed Python interpreter. > I don't want to rely on an interpreter being installed on user machine, > instead I would like to distribute all the necessary files with my app. > > As far as I understand, beside of my executable and Python.dll (I am using > Python27), I need to provide two folders: > ?- DLLs, > ?- Lib > > If I place the Lib folder and the contents of the DLLs folder in a directory > of my executable, then everything seems to work. > However I would like to use a zipped Lib folder. Hence I made an archive > (which contains contents of Lib folder) called Python27.zip. Unfortunately > the app crashes during execution. > I assume the reason might be lack of zlib.pyd. Is that assumption correct? > If so, how to obtain it? If not, what am I doing wrong? I believe zlib.pyd is statically linked into python27.dll nowadays. Some things to check: Can you import from zip files when running the Python.exe interpreter? Is the zip file included in sys.path? You might need to add this yourself after callying Py_Initialize(). Is there a top-level directory in the zip file that may be throwing the importer off? Are you getting any sort of error message? From matthew.moorland at gmail.com Wed May 4 18:21:33 2011 From: matthew.moorland at gmail.com (ETP) Date: Wed, 4 May 2011 15:21:33 -0700 (PDT) Subject: Basic interaction with another program References: Message-ID: Thanks everyone. I actually ran the program in question using Wine compatibility layer and it seemed to work fine. Terry, that looks like it could be useful, too. I'll give it a shot and let you guys know how it works. From ian.g.kelly at gmail.com Wed May 4 18:22:42 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 May 2011 16:22:42 -0600 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On Wed, May 4, 2011 at 3:35 PM, harrismh777 wrote: > Grant Edwards wrote: >>> >>> We do not consider passing a pointer as*by value* ?because its an >>> > ?address; by definition, that is pass-by-reference. >> >> No, it isn't. ?It's pass by value. ?The fact that you are passing a >> value that is a pointer to another value is not relevent. >> > > @ Edwards, &Schaathun > > You are most definitely mistaken. ? See: > > http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr233.htm That source actually supports the claim that pass-by-pointer falls under pass-by-value. It reads, in part (emphasis added): > In C++, the reference parameters are initialized with the actual arguments when the function is called. In C, the pointer parameters > are initialized with pointer _values_ when the function is called. However, I hope we can all agree that pass-by-pointer shares certain features with both pass-by-value and pass-by-reference, and there are perfectly reasonable arguments for lumping it in either category, yes? From ben+python at benfinney.id.au Wed May 4 19:33:54 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 May 2011 09:33:54 +1000 Subject: Today's fun and educational Python recipe References: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> Message-ID: <87ei4ef3bx.fsf@benfinney.id.au> Grant Edwards writes: > On 2011-05-04, Irmen de Jong wrote: > > I think that often, the cleverness of people is inversely > > proportional to the amount of CPU power and RAM that they have in > > their computer. > > True. > > Unfortunately the difficulty in debugging and maintaining code is > often directly proportional to the cleverness exhibited by the > original programmer. +1 QOTW -- \ ?Without cultural sanction, most or all of our religious | `\ beliefs and rituals would fall into the domain of mental | _o__) disturbance.? ?John F. Schumaker | Ben Finney From prologic at shortcircuit.net.au Wed May 4 20:13:21 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 5 May 2011 10:13:21 +1000 Subject: [OT]: PiCloud - really cool! Message-ID: If anyone hasn't seen this yet, I encourage you to! (I stumbled upon it with some random thoughts and Gooogling) http://www.picloud.com/ Here's a quick test I wrote up that works locally using the simulator and live (I did run it live): #!/usr/bin/env python import cloud def fib(n): a, b, = 1, 1 while n > 1: a, b = b, a + b n -= 1 return b #cloud.start_simulator() jobs = cloud.map(fib, range(100)) print [cloud.result(job) for job in jobs] Enjoy! :) cheers James -- -- James Mills -- -- "Problems are solved by method" From debatem1 at gmail.com Wed May 4 20:19:38 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 4 May 2011 17:19:38 -0700 Subject: [OT]: PiCloud - really cool! In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 5:13 PM, James Mills wrote: > If anyone hasn't seen this yet, I encourage you to! > (I stumbled upon it with some random thoughts and Gooogling) > > http://www.picloud.com/ > > Here's a quick test I wrote up that works locally using the simulator > and live (I did run it live): > > #!/usr/bin/env python > > import cloud > > def fib(n): > ? ?a, b, = 1, 1 > ? ?while n > 1: > ? ? ? ?a, b = b, a + b > ? ? ? ?n -= 1 > ? ?return b > > #cloud.start_simulator() > > jobs = cloud.map(fib, range(100)) > > print [cloud.result(job) for job in jobs] > > Enjoy! :) I was the poster across from them at PyCon two years back. Pretty fun to play with, although last I checked it was hard to do true HPC on it. Geremy Condra From tjreedy at udel.edu Wed May 4 20:26:51 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 20:26:51 -0400 Subject: Today's fun and educational Python recipe In-Reply-To: References: Message-ID: On 5/4/2011 5:39 PM, Raymond Hettinger wrote: > The 512 bits in h are progressively eaten-up between iterations. So > each pass yields a different (array index, bit_mask) pair. Yeh, obvious now that I see it. > It's easy to use the interactive prompt to show that different probes > are produced on each pass: > >>>> bf = BloomFilter(num_bits=1000, num_probes=8) >>>> pprint(list(bf.get_probes('Alabama'))) > [(19, 1073741824), > (11, 64), > (9, 134217728), > (25, 1024), > (24, 33554432), > (6, 16), > (7, 16777216), > (22, 1048576)] Should have tried that. > The 512 bits are uncorrelated -- otherwise sha512 wouldn't be much of > a cryptographic hash ;) > The fifty state example in the recipe is a reasonable demonstration > that the recipe works as advertised. It successfully finds all fifty > states (the true positives) and it tries 100,000 negatives resulting > in only a handful of false negatives. I presume you mean 'false positives', as in the program comment and Wikipedia. The test would be more convincing to many with 100000 other geographic names (hard to come by, I know), or other english names or words or even with longer random strings that matched the lengths of the state names. But an average of 5/100000 false positives in 5 runs is good. -- Terry Jan Reedy From prologic at shortcircuit.net.au Wed May 4 20:29:20 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 5 May 2011 10:29:20 +1000 Subject: [OT]: PiCloud - really cool! In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 10:19 AM, geremy condra wrote: > I was the poster across from them at PyCon two years back. Pretty fun > to play with, although last I checked it was hard to do true HPC on > it. Why's that ? And what is true HPC (High Performance Computing) anyway ? I find the API provided to be quite simple robust and potentially very powerful - depending on your application. cheers James -- -- James Mills -- -- "Problems are solved by method" From debatem1 at gmail.com Wed May 4 20:45:21 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 4 May 2011 17:45:21 -0700 Subject: [OT]: PiCloud - really cool! In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 5:29 PM, James Mills wrote: > On Thu, May 5, 2011 at 10:19 AM, geremy condra wrote: >> I was the poster across from them at PyCon two years back. Pretty fun >> to play with, although last I checked it was hard to do true HPC on >> it. > > Why's that ? And what is true HPC (High Performance Computing) anyway ? > I find the API provided to be quite simple robust and potentially very > powerful - depending on your application. Last time I checked- and again, it's been a while- you were basically just able to run some (probably computationally bound) function on an EC2 instance that they managed for you without having any of the muss and fuss of doing it yourself. That's very cool, but there are problems where you really need more horsepower than a normal EC2 instance can provide, and if your application crosses that boundary after you've written it against PiCloud you're probably in the same hole you would have been without PiCloud. The other limitation is with problems that take a lot of input data, where it's more time intensive to ship the data across to EC2 than it is to just process it locally. Once more for effect: I haven't played with this in a while, the guys who built it seem pretty sharp, and it wouldn't surprise me at all to find out that they have ways of dealing with this better now. Geremy Condra From harrismh777 at charter.net Wed May 4 20:46:57 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 19:46:57 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc1ca92$0$10552$742ec2ed@news.sonic.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> Message-ID: <5smwp.309$BG2.230@newsfe08.iad> John Nagle wrote: > Arguably, Python should not allow "is" or "id()" on > immutable objects. The programmer shouldn't be able to tell when > the system decides to optimize an immutable. > > "is" is more of a problem than "id()"; "id()" is an explicit peek > into an implementation detail. Yes, yes, yes... and I'll go you one more... ... Python should optimize on *all* immutables when possible. For instance: a = (1,2,3) b = (1,2,3) a == b True a is b False To be consistent, in this case and others, a and b should reference the same immutable tuple. Or, as stated earlier, Python should not allow 'is' on immutable objects. kind regards, m harris From harrismh777 at charter.net Wed May 4 20:51:15 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 19:51:15 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <7wmwp.310$BG2.82@newsfe08.iad> Ian Kelly wrote: > However, I hope we can all agree that pass-by-pointer shares certain > features with both pass-by-value and pass-by-reference, and there are > perfectly reasonable arguments for lumping it in either category, yes? Yes. From harrismh777 at charter.net Wed May 4 21:11:02 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 20:11:02 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Grant Edwards wrote: > The "pass by value" and "pass by reference" parameter passing > mechanisms are pretty well defined, and C uses "pass by value". Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that helped define them.... The problem you're having here is that you're thinking of parameter passing 'mechanisms' and not focusing on the definition of the terms. A reference is a pointer (an address). A value is memory (not an address). These definitions go all the way back before the 8080, or the 6502, 8 bit processors. Pass by reference has 'always' meant pass by using a memory address (indirect addressing); a reference has always been a memory pointer. If I call a function in C, and pass-by-value, the data's 'value' is placed on the stack in a stack-frame, as a 'value' parm... its a copy of the actual data in memory. If I call a function in C, and pass-by-reference, the data's 'address' is placed on the stack in a stack-frame, as a 'reference' parm... no data is copied and the function must de-reference the pointer to get to the data.... this is by definition. There may be some language somewhere that does pass-by-reference which is not implemented under the hood as pointers, but I can't think of any... 'cause like I've been saying, way down under the hood, we only have direct and indirect memory addressing in today's processors. EOS. If you pass a parm, you can either pass a copy (value) or pass a reference to its location (not a copy, a reference). kind regards, m harris From python at rcn.com Wed May 4 21:15:05 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 4 May 2011 18:15:05 -0700 (PDT) Subject: Today's fun and educational Python recipe References: Message-ID: <1ba35556-6dd8-4ddb-a9ea-19d3ed3768bc@34g2000pru.googlegroups.com> On May 4, 5:26?pm, Terry Reedy wrote: > The test would be more convincing to many with 100000 other geographic > names (hard to come by, I know), or other english names or words or even > with longer random strings that matched the lengths of the state names. > But an average of 5/100000 false positives in 5 runs is good. I've just posted an update with a spell checker using a large dictionary. That should make it easy to validate against some real world text samples. Raymond From mhammond at skippinet.com.au Wed May 4 22:09:08 2011 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 05 May 2011 12:09:08 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4DC206C4.3070206@skippinet.com.au> On 5/05/2011 11:11 AM, harrismh777 wrote: >> The "pass by value" and "pass by reference" parameter passing >> mechanisms are pretty well defined, and C uses "pass by value". > > Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that helped define them.... Cool - please tell us more about your involvement in that. Obviously lots of people were in the industry then, but only a select few would be able to claim they helped define those terms. > There may be some language somewhere that does pass-by-reference which > is not implemented under the hood as pointers, but I can't think of > any... 'cause like I've been saying, way down under the hood, we only > have direct and indirect memory addressing in today's processors. EOS. What about Python, where passing an integer to a function passes a pointer to an int object, but that function is able to change the value of the variable locally without changing the passed object (indeed, it is impossible to change the passed integer)? So given the definitions above, Python uses a by-reference mechanism but (in some cases) has by-value semantics. While I understand exactly how things work (so don't need an explanation), the point is that for anything close to a high-level language, things aren't as black and white as they are for the low-level languages... Mark From rosuav at gmail.com Wed May 4 22:22:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 12:22:35 +1000 Subject: Today's fun and educational Python recipe In-Reply-To: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> References: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> Message-ID: On Thu, May 5, 2011 at 5:02 AM, Irmen de Jong wrote: > I think that often, the cleverness of people is inversely proportional to > the amount of CPU power and RAM that they have in their computer. As Mark Rosewater is fond of saying, restrictions breed creativity. Lack of computational resources is a major restriction (for an extreme example of RAM shortage, look at how much code you can fit into a boot sector without loading anything more from the disk). Take away all the restrictions, and people will tend to code sloppily. Chris Angelico From greg.ewing at canterbury.ac.nz Wed May 4 22:28:34 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 14:28:34 +1200 Subject: importing class objects from a pickled file In-Reply-To: References: Message-ID: <92egalFbk1U1@mid.individual.net> Catherine Moroney wrote: > I am having some problems reading the > object back out, as I get complaints about "unable to import module X". > > The only way I have found around it is to run the read-file code out of > the same directory that contains the X.py file > > Even when I put statements into the code such as "from Y.X import X" ... > the import statement works, but I am still unable to read the object Is the program that reads the pickle file the same one that was used to write it? If not, what might be happening is that the writing program has module X at the top level instead of inside package Y. Then it will get pickled simply under the name "X" instead of "Y.X", and the reading program will expect to find it at the top level as well. It's important that the reading and writing programs agree about the location of the pickled classes in the package namespace, unless you take steps to customise the pickling process. -- Greg From greg.ewing at canterbury.ac.nz Wed May 4 22:35:41 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 14:35:41 +1200 Subject: Fibonacci series recursion error In-Reply-To: References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92ego0Fe7vU1@mid.individual.net> Chris Angelico wrote: > There's definitely something attractive about that letter. Lots of > programming languages' names start with P. Including one I invented some years ago, that (in the spirit of C and its derivatives) was called simply "P". (I was playing around with Sun's NeWS window server, which was programmed in Postscript, and I got fed up with Forth-like syntax, so I wrote a translator that took an infix language and generated Postscript from it.) -- Greg From rosuav at gmail.com Wed May 4 22:43:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 12:43:04 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <87mxj2f8f4.fsf@benfinney.id.au> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> Message-ID: On Thu, May 5, 2011 at 7:43 AM, Ben Finney wrote: > * that the paper tag is tied to only one object > > * that a paper tag tied to no object is rather useless > > * that many paper tags can be tied to the same object I disagree minorly; a tag tied to no object is quite useful in some circumstances. You can ditch the concept by having a special object that's called "No Object" (Python does this, with None), or you can allow your tag to point nowhere (C does this, with null pointers). The difference is semantic; either way, your tag can point to any object or it can point nowhere. (Pike goes for a slightly different approach; any variable, regardless of its stated types, may legally hold the integer 0. It acts somewhat as a null pointer, but it isn't really.) Chris Angelico From greg.ewing at canterbury.ac.nz Wed May 4 23:16:45 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 15:16:45 +1200 Subject: Hooking into Python's memory management In-Reply-To: References: Message-ID: <92ej51Ft7kU1@mid.individual.net> Daniel Neilson wrote: > 1) Maintain a list of object id()'s for objects that have been created. > Ideally, this list would also contain the file & line number where the > object was created. > 2) Provide a "deallocate" function that will remove a given object's > id() from the list from (1). > 3) Print out an error message if the python script terminates with a > non-empty list from (1). Preferably with a list of objects that are > still "allocated." I don't think this will work out quite the way you seem to be imagining. Consider that Python creates a lot of objects behind the scenes without you doing anything specific to "allocate" them. Examples include the dicts holding module and class namespaces, all the strings representing names in loaded code, ints, floats and strings representing literals in the code, etc. If you automatically add any object of any of these types to the "allocated" list, these implicitly-created objects will all still be present in it when the program terminates, and the student will be told off for failing to deallocate them. An alternative might be to provide an allocate() function which the student is expected to use on any explicitly-created object. But there wouldn't be any way of enforcing this. Personally I think the whole idea is misguided, and it would be better to teach these concepts in the context of a language where they actually matter, which these days more or less means C. If teaching C in the first year in parallel with Python is considered too steep, then leave explicit memory management until later in the curriculum. (It's really a shame that Pascal is not taught any more. It provided a fairly clean environment for teaching about things like this, without getting so close to the machine that you get your nosed rubbed in segfaults.) -- Greg From timr at probo.com Wed May 4 23:23:36 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 04 May 2011 20:23:36 -0700 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: harrismh777 wrote: > >If I call a function in C, and pass-by-value, the data's 'value' is >placed on the stack in a stack-frame, as a 'value' parm... its a copy of >the actual data in memory. > >If I call a function in C, and pass-by-reference, the data's 'address' >is placed on the stack in a stack-frame, as a 'reference' parm... no >data is copied and the function must de-reference the pointer to get to >the data.... this is by definition. This is not correct. Consider an example. int BumpMe( int * a ) { return *a+3; } int Other() { int x = 9; return BumpMe( &x ); } That is not an instance of passing an "int" by reference. That is an instance of passing an "int *" by value. The fact that the parameter "a" in BumpMe happens to be an address is completely irrelevent to the definition of the parameter passing mechanism. C has pass-by-value, exclusively. End of story. >There may be some language somewhere that does pass-by-reference which >is not implemented under the hood as pointers, but I can't think of >any... Fortran had genuine pass-by-reference. In Fortran, you could write a program like this: SUBROUTINE CONFUSION(IVALUE) INTEGER IVALUE IVALUE = IVALUE + 1 END PROGRAM MAIN CONFUSION(4) END That program would actually modify the value of the constant 4. Such an abomination is simply not possible in C. Is that implemented under-the-hood with pointers/addresses? Of course it is. However, that does not change the parameter passing model as defined by the language specification. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From greg.ewing at canterbury.ac.nz Wed May 4 23:48:51 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 15:48:51 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92el16F9kaU1@mid.individual.net> Hans Georg Schaathun wrote: > Is transmission by name the same as call by object? No, it's not. With call-by-name, the caller passes a small function (known as a "thunk") that calculates the address of the parameter. Every time the callee needs to refer to the parameter, it evaluates this function. This allows some neat tricks, but it's massive overkill for most uses. In later languages, the functionality of call-by-name has been replaced by the ability to explicitly pass functions as parameters. > Anyway, I have never seen anyone counting more than > three ways of doing this ... There are other possibilities, such as value-result, where a local copy is made and its final value is copied back before returning. I think Fortran is defined in such a way that this is an acceptable way of implementing parameter passing. It's also the only way of getting anything akin to by-reference over an RPC connection. But for most situations, by-value and by-reference cover anything you might want to do. And if you have a dynamic data model like Python, you don't even need by-reference. -- Greg From harrismh777 at charter.net Thu May 5 00:01:13 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 23:01:13 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Mark Hammond wrote: > What about Python, where passing an integer to a function passes a > pointer to an int object, but that function is able to change the value > of the variable locally without changing the passed object (indeed, it > is impossible to change the passed integer)? > > So given the definitions above, Python uses a by-reference mechanism but > (in some cases) has by-value semantics. Yeah, Mark, the trouble is that the concepts (by-value, or by-reference) have morphed into a concept(s) that say something of what should or should not happen within scopes (or, in the case of Python, namespaces) and says something less about what 'reference' or 'value' mean as terms for data. So, again, its semantics... not black and white, as you say and some of both|and. If C were 'strictly' pass-by-value (that is what the K&R states, sec. 1.8, p27 2nd ed) and had no concept of indirect memory addressing (memory references is what we called them in the early days ca. 1970~) in the form of pointers, then all of this semantic discussion would be mute. But, 'C' does provide for pointers which are used by all 'C' programmers to firmly provide pass-by-reference in their coding (C++ also, by the way). My 'C' functions can most definitely modify the parms passed in from their calling functions by simply 'de-referencing' the parms. This is done all the time--- and a good thing too, since nobody would want to pass a list by value, or worse yet a linked list with a couple of thousand nodes, by value. So, I argue that its silly to say that because the parameter passing 'mechanism' of the 'C' language is pass-by-value (see K&R) that 'C' is a pass-by-value language, when clearly 'C' programmers use pass-by-reference routinely in their 'C' coding. This is quite different than some flavors of Fortran or Pascal where the called routines had access to the original vars--- which had more to do with scope than it did with parameter passing or indirection. In 'C' if I want to I can live with pass-by-value... or, I can live with pass-by-reference nicely... and its up to me... not language constraints. Again, it seems that some folks want to pigeon hole this concept into one or the other (and it clearly can be) but usually it is a combination of the two (both | and). kind regards, m harris From tooscattered at gmail.com Thu May 5 00:06:02 2011 From: tooscattered at gmail.com (scattered) Date: Wed, 4 May 2011 21:06:02 -0700 (PDT) Subject: Hooking into Python's memory management References: Message-ID: <015aefbf-8c86-48ee-aec9-8368b11cca0a@p13g2000yqh.googlegroups.com> On May 4, 12:51?pm, Daniel Neilson wrote: > Hello, > ? I'm hoping that there will be someone here with sufficient expertise > to answer a question on Python 3 for me. > > ? I work in the Computer Science department at a large Canadian > University. We are currently doing a feasibility analysis for switching > to using Python in our first year major-stream courses. > > ? Part of our first year curriculum requires that students be exposed to > explicit dynamic memory allocation in the form of C++'s new/delete, C's > malloc/free, etc. I realize that Python is garbage collected, and that > there is never a need to explicitly allocate & deallocate objects. > However, I am trying to determine whether or not it is possible to > simulate that behaviour within Python via a module for the purposes of > instruction. > > ? For these purposes, I would like to know whether it is possible within > Python 3 to write a Python-only module that, essentially, hooks into the > "constructor" and "destructor" of many of the Python built-in types > (specifically list, dictionary, set, tuple, and string) so that the > module can: > ? 1) Maintain a list of object id()'s for objects that have been > created. Ideally, this list would also contain the file & line number > where the object was created. > ? 2) Provide a "deallocate" function that will remove a given object's > id() from the list from (1). > ? 3) Print out an error message if the python script terminates with a > non-empty list from (1). Preferably with a list of objects that are > still "allocated." > > ? Baring a Python-only module, would this behaviour be possible to add > via a C-language module? > > ? A module that hooked in to all memory allocation, and inspected the > type of the object being allocated to conditionally add the object's > id() to the list would also suffice. > > ? In either case, if such a module is possible, any pointers you could > provide regarding how to implement such a module would be appreciated. > > Thank you for your time, > ? Daniel Maybe you can simulate a heap. Create a heap class where a heap-object maintains an internal list of fixed length (whose length is determined by a constructor)for its heap and a list of free blocks in this heap. It can have methods for allocating and deallocating objects in the heap. Perhaps some sort of dictionary with strings representing pointers as keys and indices of corresponding allocated blocks as values. Subscript-out of range errors in the internal heap would correspond to segmentation errors. The heap-class could catch this error and inform the student. It could also have methods which catch things like dangling pointers and memory leaks. Perhaps a method to display a schematic of the heap. Maybe something as simple as printing something like |||||____|||__|||______||||____________ where ||| represents used blocks and ____ represents free space. Displaying this could show the problem of heap-fragmentation. Once you get the interface down - assign some homework where the students need to implement a simple algorithm which requires dynamic memory alocation. The catch is that the students are forbidden from using things like Python lists directly in their code but instead have to get by with using a single instance of this heap object for their data storage needs. Make a bit of a game out of it. I obviously haven't worked out the details, but I suspect that this sort of thing is both easier and more pedagogically sound (since you can tailor the error messages) then what you were looking for. From nagle at animats.com Thu May 5 00:32:59 2011 From: nagle at animats.com (John Nagle) Date: Wed, 04 May 2011 21:32:59 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <5smwp.309$BG2.230@newsfe08.iad> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> Message-ID: <4dc22882$0$10557$742ec2ed@news.sonic.net> On 5/4/2011 5:46 PM, harrismh777 wrote: > John Nagle wrote: >> Arguably, Python should not allow "is" or "id()" on >> immutable objects. The programmer shouldn't be able to tell when >> the system decides to optimize an immutable. >> >> "is" is more of a problem than "id()"; "id()" is an explicit peek >> into an implementation detail. > > Yes, yes, yes... and I'll go you one more... > > ... Python should optimize on *all* immutables when possible. > > > For instance: > > a = (1,2,3) > b = (1,2,3) > > a == b True > > a is b False > > To be consistent, in this case and others, a and b should reference > the same immutable tuple. Actually, that's not necessarily an "optimization". The cost of looking up small tuples is probably higher than creating them. There's also a potential optimization of duplicating tuples in use by different threads, to reduce locking effort. (CPython's global lock is too dumb to exploit this, but there are other ways to do it.) > > > Or, as stated earlier, Python should not allow 'is' on immutable objects. A reasonable compromise would be that "is" is treated as "==" on immutable objects. John Nagle From harrismh777 at charter.net Thu May 5 00:55:39 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 23:55:39 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Tim Roberts wrote: > The fact that the parameter "a" > in BumpMe happens to be an address is completely irrelevent to the > definition of the parameter passing mechanism. > > C has pass-by-value, exclusively. End of story. Yeah, Tim, I know... but that's my entire point in a nut-shell... whether the language is pass-by-value or pass-by-reference has less to do with how it is 'defined' (its mechanism--- indirection and stack) and more to do with how it is routinely used with the standard features it provides--- in this case memory indirection--- as pointers. Something new here, just for fun... ... I ran my hello.c program through the gcc compiler and intercepted its assembly source output. Some folks on the list may not know that the gcc compiler used to generate CPython (at least on *nix systems) does not generate object or machine code directly, but generates an intermediate assembly source in AT&T syntax. The assembly code is interesting for the discussion, if you've never seen it. If you have, blow this off. Anyway, I built a small wrapper called 'say()' around the printf function, so that I could pass a string var to say(), and I then called it a couple of times in main(). The assembly source code is listed at the end of this post. The thing to notice here is two things: 1) assembly code is actually being used to generate the machine code, not 'C' (and this is true for Python as well, compiled from sources) In other words, Python interpreter does not do anything more (nor less) than what can be done with assembler (nor machine code for that matter). And, 2) The strings I am 'passing' to the say() function don't get 'passed' anywhere. (I know that most of you know this, bear with me) The strings are set in memory, and through memory indirection pointers (the parenthesis 'references') the string's memory addresses are placed on the stack. The called routine say() has full access to the original strings in memory (via their memory addresses) if necessary. The main point being that the say() function has a 'reference' to the original, and not a local copy of the 'value', and it can change it! The string's addresses are .LC0 and .LC1/ Here is the assembly of my hello.c saved as hello.s with: gcc -Wall -S -o hello.s hello.c .file "hello.c" .section .rodata .LC0: .string "\nhello, world!\n" .align 4 .LC1: .string "...and again I say, hello there, world!\n\n" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp andl $-16, %esp subl $32, %esp movl $0, 28(%esp) movl $.LC0, (%esp) call say movl $.LC1, (%esp) call say movl 28(%esp), %eax leave ret .size main, .-main .section .rodata .LC2: .string "%s" .text .globl say .type say, @function say: pushl %ebp movl %esp, %ebp subl $24, %esp movl $.LC2, %eax movl 8(%ebp), %edx movl %edx, 4(%esp) movl %eax, (%esp) call printf leave ret .size say, .-say .ident "GCC: (Ubuntu 4.4.1-4ubuntu9) 4.4.1" .section .note.GNU-stack,"", at progbits From hg at schaathun.net Thu May 5 00:58:51 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 5 May 2011 05:58:51 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <92el16F9kaU1@mid.individual.net> Message-ID: On Thu, 05 May 2011 15:48:51 +1200, Gregory Ewing wrote: : No, it's not. With call-by-name, the caller passes a : small function (known as a "thunk") that calculates the : address of the parameter. Every time the callee needs to : refer to the parameter, it evaluates this function. Well, call-by-name is not the same as transmission by name either. Transmission by name is what most posters here call call by reference, and transmission by reference is what this thread calls object sharing or call by object. No wonder I started off confused :-) It is better now. -- :-- Hans Georg From harrismh777 at charter.net Thu May 5 01:19:36 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 00:19:36 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Dennis Lee Bieber wrote: >> > We do not consider passing a pointer as*by value* because its an >> > address; by definition, that is pass-by-reference. We are not passing > To most of the world, pass-by-reference means the COMPILER, not the > PROGRAMMER is obtaining and passing the address, and the compiler also > always dereferences the passed "value"... The programmer has no control > over whether to operate on the address or the data referenced by the > address. Who is "most of the world" ? Please see: http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr233.htm From ddneilson at gmail.com Thu May 5 01:30:47 2011 From: ddneilson at gmail.com (Daniel Neilson) Date: Wed, 04 May 2011 23:30:47 -0600 Subject: Hooking into Python's memory management In-Reply-To: <4DC1841B.2030601@gmail.com> References: <4DC1841B.2030601@gmail.com> Message-ID: <4DC23607.1020407@gmail.com> Thanks for the feedback, everyone. I spent some time today playing around with the gc module, and came to the same conclusion that many of you have as well. for o in gc.get_objects(): print(o) was sufficient to convince me that I didn't want to go that route. Writing a simple memory pool/heap that students will have to use to allocate/deallocate objects of a particular type definitely seems the way to go. It will get the ideas across, and allow them to contrast the garbage collection and explicit memory management paradigms. -Daniel From no.email at nospam.invalid Thu May 5 01:50:37 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 04 May 2011 22:50:37 -0700 Subject: Python Developers with 5 years of experience References: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> <87iptqf8be.fsf@benfinney.id.au> Message-ID: <7x1v0dwv9u.fsf@ruckus.brouhaha.com> Ben Finney writes: > Please do not solicit for jobs here. Instead, the Python Job Board > is intended for that purpose. Wow, there's quite a lot of listings there. There had been only a few last time I looked. But, most of them seem to involve Django. From hg at schaathun.net Thu May 5 02:12:16 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 5 May 2011 07:12:16 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <9nn898-dnl.ln1@svn.schaathun.net> Message-ID: <0nr998-oen.ln1@svn.schaathun.net> On Wed, 04 May 2011 16:49:25 -0500, harrismh777 wrote: : Folks seem to think that because they are doing abstraction at a : high-level (well, they never maybe programmed at a lower level) that : abstraction somehow 'requires' a high level language. (not true) I never said 'requires', but when you do high-level modelling, low-level detail is a distraction. Using a low-level language for abstract modelling is therefore harder than it needs to be. : Today, high-level languages like Python (and others) allow programmers : to place some of their abstraction into their source code directly. This : does not make the high-level language any more 'suited' to abstraction : than any other lower-level language; because the abstraction is a mental : process not a language feature. It all ends up in assembly and machine : code. Indeed, except for the contradiction. The fact that you can put more of your abstraction into the source code means that it is better suited to abstraction. Mental processes depend on language; at least when you need to communicate the output. That language does not have to be computer readable (as is the case for your float charts etc). We may very well use a stack of languages and models at different levels of abstraction, but when you move down the stack you are moving away from abstraction and into implementation. C is very rarely suitable at the top of this stack. When I say that C is ill-suited for abstraction, I am not implying that it is ill-suited for implementing according to an abstract model. If you need human input in the lower layers of abstraction, C is a good choice. Using manual work to move down the layers of abstraction is possible, and given sufficient man-power should give the better result, but relying on human input when the work can be automated is ridiculously expensive. Now, python is only one level above C in abstraction, but that's a different matter. -- :-- Hans Georg From srikrishnamohan at gmail.com Thu May 5 02:18:57 2011 From: srikrishnamohan at gmail.com (km) Date: Thu, 5 May 2011 11:48:57 +0530 Subject: Python Developers with 5 years of experience In-Reply-To: <87iptqf8be.fsf@benfinney.id.au> References: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> <87iptqf8be.fsf@benfinney.id.au> Message-ID: probably it is good to post jobs in python-list itself rather than posting it on someother site. Many mailing lists do that. It gives a feel of what jobs we come across for the Python developers. KM On Thu, May 5, 2011 at 3:16 AM, Ben Finney wrote: > "Jerome jjcpl.rpo" writes: > > > One of our client in New Jersey is looking for Python Developers with > > 5 years of experience. If you have any resumes please send it across. > > Please do not solicit for jobs here. Instead, the Python Job Board > is intended for that > purpose. > > -- > \ ?The right to search for truth implies also a duty; one must | > `\ not conceal any part of what one has recognized to be true.? | > _o__) ?Albert Einstein | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hg at schaathun.net Thu May 5 02:34:09 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 5 May 2011 07:34:09 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <10t998-cgn.ln1@svn.schaathun.net> On Wed, 04 May 2011 20:11:02 -0500, harrismh777 wrote: : A reference is a pointer (an address). : : A value is memory (not an address). Sure, and pointers (from a hardware or C perspective) are memory, hence pointers are values. -- :-- Hans Georg From r.drew.davis at gmail.com Thu May 5 04:15:05 2011 From: r.drew.davis at gmail.com (Drew) Date: Thu, 5 May 2011 01:15:05 -0700 (PDT) Subject: python on iPad (PyPad) References: <4d9feaea$0$29996$c3e8da3$5496439d@news.astraweb.com> <57cb7f7c-922c-4913-8603-ccd138e0d3be@r6g2000vbz.googlegroups.com> Message-ID: On Apr 10, 1:48?am, Matt Schinckel wrote: > On Apr 9, 2:13?pm, Jon Dowdall wrote: > > > Hi All, > > > Sorry for the blatant advertising but hope some of you may be interested > > to know that I've created an iPad application containing the python > > interpreter and a simple execution environment. It's available in iTunes > > athttp://itunes.apple.com/us/app/pypad/id428928902?mt=8# > > > I wanted to have python available 'on the go' without carrying a laptop. > > The current implementation is based on my need to test simple python > > functions in an isolated environment. I hope to add more iOS specific > > capabilities if there is enough interest. > > > Enjoy... > > > Jon Dowdall > > I know this sound shallow, but you really need a nicer icon. > > Otherwise, I'm quite excited about this. It will certainly be better > than my current workflow of connecting via ssh to a server just to run > python code. > > Matt. There's a Pypad on SourceForge, but it is flagged as no longer under active development. Dead or just sleeping? Is this Pypad distinct from that old one on SourceForge? Or a revival? OpenSource? Drew From greg.ewing at canterbury.ac.nz Thu May 5 04:55:36 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 20:55:36 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <9fd898-0el.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> Message-ID: <92f70aF9pqU1@mid.individual.net> Hans Georg Schaathun wrote: > With the references being > purely abstract entities and not data objects, It's not clear to me that references are any more abstract than objects, or to put it another way, that objects are any less abstract than references. After all, in normal Python usage you never actually *see* an object -- at best you see some string of characters resulting from the str() or repr() of an object. The object is a mental construct we use to make sense of the behaviour we're seeing, as are references. If you were to look inside the interpreter closely enough to see the concrete representations of objects -- the bit patterns in memory making them up -- then you would also be able to see the bit patterns making up the references. -- Greg From greg.ewing at canterbury.ac.nz Thu May 5 05:08:11 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 21:08:11 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <3Ihwp.18043$Ot6.11759@newsfe15.iad> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <92f7nuFfhhU1@mid.individual.net> harrismh777 wrote: > 'C' is still the best high-level language on that processor. Some would argue that C is actually better than assembler these days, because modern architectures are so freaking complicated that it takes a computer to figure out the best instruction sequence. :-( -- Greg From rosuav at gmail.com Thu May 5 05:12:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 19:12:57 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <92f7nuFfhhU1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <92f7nuFfhhU1@mid.individual.net> Message-ID: On Thu, May 5, 2011 at 7:08 PM, Gregory Ewing wrote: > harrismh777 wrote: >> >> 'C' ?is still the best high-level language on that processor. > > Some would argue that C is actually better than assembler these > days, because modern architectures are so freaking complicated > that it takes a computer to figure out the best instruction > sequence. :-( I use C to hint to the compiler as to what I'd like it to write a program to do. It does all the writing, I just make some vague suggestions - which it's free to ignore if it chooses. GCC and me, we get along jess fine... ChrisA From greg.ewing at canterbury.ac.nz Thu May 5 05:31:52 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 21:31:52 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <92f94aFploU1@mid.individual.net> harrismh777 wrote: > That is the $10,000,000 dollar problem... how to > extricate ourselves from the von Neumann processor. *Everthing* comes > down to that... its hilarious to hear folks talk about lambda the > ultimate (especially those guys on Lambda the Ultimate) when there is no > such thing until such time as we have lambda the hardware architecture. I think there are fundamental problems that go beyond the issue of hardware design. It's easy to reason about a program that does things one step at a time, much harder when lots of things are happening at once. Whether you express the program using lambda calculus or a Turing machine doesn't change that fact. -- Greg From alexander at lyabah.com Thu May 5 05:43:28 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Thu, 5 May 2011 02:43:28 -0700 (PDT) Subject: Python competitions and learnings References: Message-ID: On May 1, 12:29?am, Terry Reedy wrote: > On 4/30/2011 3:22 PM, Alexander Lyabah wrote: > > > I spend a lot of time in writing a new service checkio.org > > > It's all about python, learn python, find the best solution in > > python. > > > And Im looking for feedback from peoples who best in python. Here I > > make some video tutorial about this servicehttp://checkio.blip.tv/ > > > What do you think about it? > > Pretty impressive. My main disappointment is that you are using 2.7 > instead of 3.2, as I feel that beginners should learn Py 3 now. Also, > that is what I routinely use ;-). > > In any case, the home page should say Python 2.7, not just Python, I had > to think to click Console Learn in order to find out what would be legal > when I tried out one of the tasks. > > You might consider offering 3.2 as an alternative. Solutions will be > similar, but details differ. For instance, I noticed that one solution > to 'string split' *depends* on the 2.x leaking of listcomp loop variables. > > > I'm also have a not a very good English, so I need help with it too, > > because some parts of checkio.org ?not in very well English > > Home page: "In the descriptions of this tasks there is always > information from manuals and tutorials," 'these tasks' > > "game.Choice a game " => "game. Choose a game " > "users. Choice a game" => again, 'Choose' > > "and fall into the top " I think you mean "and climb into the top " > > "programs on arena. " => "program in the arena. " > > "By the result of competition formed top of the game. " > This is unclear. perhaps "The best will be chosen by the result of the > competition." > > I see a mailto: link at the bottom of the page, so I will report > anything else I see later. > > -- > Terry Jan Reedy Terry, Hi, sent a mail to you, couple days ago. From alexander at lyabah.com From greg.ewing at canterbury.ac.nz Thu May 5 06:06:41 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 22:06:41 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc22882$0$10557$742ec2ed@news.sonic.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> Message-ID: <92fb5jFa2lU1@mid.individual.net> John Nagle wrote: > A reasonable compromise would be that "is" is treated as "==" on > immutable objects. That wouldn't work for tuples, which can contain references to other objects that are not immutable. -- Greg From greg.ewing at canterbury.ac.nz Thu May 5 06:19:18 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 22:19:18 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <92fbt9FfooU1@mid.individual.net> harrismh777 wrote: > 'C' does provide for pointers which are used by all 'C' > programmers to firmly provide pass-by-reference in their coding Yes, but when they do that, they're building an abstraction of their own on top of the facilities provided by the C language. C itself has no notion of pass-by-reference. If it did, the programmer would be able to use it directly instead of having to insert & and * operators himself. -- Greg From hg at schaathun.net Thu May 5 06:31:41 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 5 May 2011 11:31:41 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> Message-ID: On Thu, 05 May 2011 20:55:36 +1200, Gregory Ewing wrote: : It's not clear to me that references are any more abstract : than objects, or to put it another way, that objects are : any less abstract than references. : : After all, in normal Python usage you never actually : *see* an object Sure, but you can refer directly to objects, pass objects around, and refer to individual objects. This is abstract in the sense that it is far removed from the memory representation. However, the concept of a reference appears only when you explain how objects are handled (semantics). You cannot reference nor manipulate a reference in python, and that IMHO makes them more abstract. -- :-- Hans Georg From tacyt1007 at gmail.com Thu May 5 06:55:05 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Thu, 5 May 2011 12:55:05 +0200 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: Thanks for the reply! > Can you import from zip files when running the Python.exe interpreter? When I zip the folder "Lib" into Python27.zip and later rename it and try to run the python.exe, I receive an error: "Import error: no module named site" > Is the zip file included in sys.path? You might need to add this > yourself after callying Py_Initialize(). Before renaming the "Lib" folder, the path to the python27.zip exists in sys.path. > Is there a top-level directory in the zip file that may be throwing > the importer off? I am testing all the cases so this is not the issue. > Are you getting any sort of error message? When I run my app, it crashes while calling Py_Initialize(). The console closes suddenly. Is it necessary to create zip archive using zipfile.PyZipFile? regards 2011/5/5 Ian Kelly > > On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak wrote: > > Hello, > > > > I spent a lot of time googling for a solution of this problem, with no > > result. > > > > I have a C++ application, in which I would like to embed Python interpreter. > > I don't want to rely on an interpreter being installed on user machine, > > instead I would like to distribute all the necessary files with my app. > > > > As far as I understand, beside of my executable and Python.dll (I am using > > Python27), I need to provide two folders: > > ?- DLLs, > > ?- Lib > > > > If I place the Lib folder and the contents of the DLLs folder in a directory > > of my executable, then everything seems to work. > > However I would like to use a zipped Lib folder. Hence I made an archive > > (which contains contents of Lib folder) called Python27.zip. Unfortunately > > the app crashes during execution. > > I assume the reason might be lack of zlib.pyd. Is that assumption correct? > > If so, how to obtain it? If not, what am I doing wrong? > > I believe zlib.pyd is statically linked into python27.dll nowadays. > Some things to check: > > Can you import from zip files when running the Python.exe interpreter? > Is the zip file included in sys.path? ?You might need to add this > yourself after callying Py_Initialize(). > Is there a top-level directory in the zip file that may be throwing > the importer off? > Are you getting any sort of error message? > -- > http://mail.python.org/mailman/listinfo/python-list From mwilson at the-wire.com Thu May 5 07:44:12 2011 From: mwilson at the-wire.com (Mel) Date: Thu, 05 May 2011 07:44:12 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > On 5/4/2011 5:46 PM, harrismh777 wrote: >> Or, as stated earlier, Python should not allow 'is' on immutable objects. > > A reasonable compromise would be that "is" is treated as "==" on > immutable objects. I foresee trouble testing among float(5), int(5), Decimal(5) ... Mel. From rosuav at gmail.com Thu May 5 07:48:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 21:48:20 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> Message-ID: On Thu, May 5, 2011 at 9:44 PM, Mel wrote: > John Nagle wrote: >> On 5/4/2011 5:46 PM, harrismh777 wrote: >>> Or, as stated earlier, Python should not allow 'is' on immutable objects. >> >> ? ? A reasonable compromise would be that "is" is treated as "==" on >> immutable objects. > > I foresee trouble testing among float(5), int(5), Decimal(5) ... Define 'x is y' as 'type(x)==type(y) and isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then. Chris Angelico From mwilson at the-wire.com Thu May 5 08:09:21 2011 From: mwilson at the-wire.com (Mel) Date: Thu, 05 May 2011 08:09:21 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Tim Roberts wrote: > That is not an instance of passing an "int" by reference. That is an > instance of passing an "int *" by value. The fact that the parameter "a" > in BumpMe happens to be an address is completely irrelevent to the > definition of the parameter passing mechanism. > > C has pass-by-value, exclusively. End of story. Trouble with Turing-complete languages. If it can be done, you can convince a Turing-complete language to do it -- somehow. PL/I was the converse. All parameters were passed by reference, so with some_proc (rocks); the code in some_proc would be working with the address of rocks. If you wanted pass-by-value you wrote some_proc ((rocks)); whereupon the compiler would pass in by reference an unnamed temporary variable whose value was the expression `(rocks)`. I suspect the compiler I used avoided FORTRAN's troubles the same way. Your function could corrupt *a* 4, but it wouldn't corrupt the *only* 4. Mel. From steve+comp.lang.python at pearwood.info Thu May 5 08:14:23 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 12:14:23 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <4dc2949e$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 15:46:07 -0400, Benjamin Kaplan wrote: > On Wed, May 4, 2011 at 3:22 PM, harrismh777 > wrote: [...] >>> Digging down into C should be unnecessary to explain Python. >> >> >> ? huh? ? You have to be kidding. Why do you suppose we want it to be >> open-sourced? ? Use the force Luke, read the source. ? If you really >> want to know how Python is working you *must* dig down into the C code >> which implements it. ?The folks who document Python should be able to >> tell us enough to know how to use the language, but to really 'know' >> you need the implementation source. >> >> > Reading the CPython sources will show you how CPython works under the > hood, but it has nothing to do with how Python works. There are lots of > things that CPython does that "Python" does not. For instance, the GIL > is not a part of Python. Reference counting is not a part of Python. > Caching small integers and strings is not a part of Python. Why not read > the Jython sources instead of the CPython? It's the same language, after > all. More importantly, Python need not be implemented at all. If you're stuck on a desert island without electricity, you could simulate the effect of running any arbitrary Python code merely by understanding the semantics of high-level Python code, without caring the slightest about pointers at the C implementation level, or bit flipping at the hardware level, or von Neumann machines, or ref counting, or garbage collection, or any of a million other implementation details. All you need understand is the declared semantics of the language. Surely I can't be the only one who sometimes tries to work out a tricky bit of Python code by hand-simulating it on pencil and paper? -- Steven From rosuav at gmail.com Thu May 5 08:37:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 22:37:28 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2949e$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <4dc2949e$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 5, 2011 at 10:14 PM, Steven D'Aprano wrote: > More importantly, Python need not be implemented at all. If you're stuck > on a desert island without electricity, you could simulate the effect of > running any arbitrary Python code merely by understanding the semantics > of high-level Python code... http://xkcd.com/505/ Chris Angelico From steve+comp.lang.python at pearwood.info Thu May 5 08:49:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 12:49:33 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <4dc29cdd$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 14:22:38 -0500, harrismh777 wrote: > Here is the thing that everyone forgets... all we have to work with > is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). Actually, this is incorrect. Most processors these days are hybrids between that and either the Harvard or Modified Harvard architecture: http://en.wikipedia.org/wiki/Modified_Harvard_architecture http://en.wikipedia.org/wiki/Harvard_architecture http://en.wikipedia.org/wiki/Von_Neumann_architecture > Assembler is still the best language on that processor. Assembly is not "a" language, it is a generic term for dozens or hundreds of different languages. But in any case, it's not clear what you mean by "best language". > 'C' is still the best high-level language on that processor. C is better described as a high-level assembler, or a low-level language. It is too close to the hardware to describe it as high-level, it has no memory management, few data abstractions, and little protection. > Its silly to claim that one high-level language or another is better > suited to complex data abstraction... don't go there. Surely you can't possibly mean that? Surely you don't mean to tell us that the 1957 version of FORTRAN, or unstructured BASIC, or early COBOL, are just as well suited to data abstraction as (say) Haskell? Many implementations of unstructured BASIC didn't even have arrays, only character strings and integers. Or (one of my personal favourites), Apple's Hypertalk? *Everything* is a string in Hypertalk. I love Hypertalk, but good for data abstraction? Don't make me laugh. You should read Paul Graham on the Blub Paradox: http://www.paulgraham.com/avg.html -- Steven From asdrubal.ivan.suarez.rivera at gmail.com Thu May 5 09:11:48 2011 From: asdrubal.ivan.suarez.rivera at gmail.com (=?ISO-8859-1?Q?Asdr=FAbal_Iv=E1n_Su=E1rez_Rivera?=) Date: Thu, 5 May 2011 06:11:48 -0700 (PDT) Subject: : PiCloud - really cool! References: Message-ID: <57a80dce-9a05-4239-ba62-87ba4679aacb@x3g2000yqj.googlegroups.com> On May 4, 8:13?pm, James Mills wrote: > If anyone hasn't seen this yet, I encourage you to! > (I stumbled upon it with some random thoughts and Gooogling) > > http://www.picloud.com/ > > Here's a quick test I wrote up that works locally using the simulator > and live (I did run it live): > > #!/usr/bin/env python > > import cloud > > def fib(n): > ? ? a, b, = 1, 1 > ? ? while n > 1: > ? ? ? ? a, b = b, a + b > ? ? ? ? n -= 1 > ? ? return b > > #cloud.start_simulator() > > jobs = cloud.map(fib, range(100)) > > print [cloud.result(job) for job in jobs] > > Enjoy! :) > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" It looks interesting but unfortunately is not free software :( From neilc at norwich.edu Thu May 5 09:19:43 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 5 May 2011 13:19:43 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> Message-ID: <92fmffFucoU9@mid.individual.net> On 2011-05-04, John Nagle wrote: > That's a quirk of CPython's boxed number implementation. All > integers are boxed, but there's a set of canned objects for > small integers. CPython's range for this is -5 to +256, > incidentally. That's visible through the "is" operator. > Arguably, it should not be. But that's the sole purpose of the is operator. You either expose those details, or you don't have an is operator at all. -- Neil Cerutti From nicogrubert at yahoo.de Thu May 5 09:35:41 2011 From: nicogrubert at yahoo.de (Nico Grubert) Date: Thu, 05 May 2011 15:35:41 +0200 Subject: PIL: The _imaging C module is not installed Message-ID: <4DC2A7AD.5080606@yahoo.de> Hi there I am having trouble to install PIL 1.1.7 on CentOS. I read and followed the instructions from http://effbot.org/zone/pil-imaging-not-installed.htm However, I still get the "The _imaging C module is not installed" error if I run the selftest: $ python selftest.py *** The _imaging C module is not installed Here is what I have tested so far: 1.) $ python -v ... >>> import Image ... dlopen("/usr/local/lib/python2.4/site-packages/PIL/_imaging.so", 2); import _imaging # dynamically loaded from /usr/local/lib/python2.4/site-packages/PIL/_imaging.so ... 2.) $ python ... >>> import _imaging ...success imported! Any idea what might be wrong? Regards Nico From steve+comp.lang.python at pearwood.info Thu May 5 09:59:59 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 13:59:59 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> Message-ID: <4dc2ad5e$0$29991$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 May 2011 21:48:20 +1000, Chris Angelico wrote: > On Thu, May 5, 2011 at 9:44 PM, Mel wrote: >> John Nagle wrote: >>> On 5/4/2011 5:46 PM, harrismh777 wrote: >>>> Or, as stated earlier, Python should not allow 'is' on immutable >>>> objects. >>> >>> ? ? A reasonable compromise would be that "is" is treated as "==" on >>> immutable objects. >> >> I foresee trouble testing among float(5), int(5), Decimal(5) ... > > Define 'x is y' as 'type(x)==type(y) and > isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then. `is` is supposed to be a *fast* operator, not even slower than equality testing. -- Steven From steve+comp.lang.python at pearwood.info Thu May 5 10:10:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 14:10:27 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 20:11:02 -0500, harrismh777 wrote: > These definitions go all the way back before the 8080, or the 6502, 8 > bit processors. Pass by reference has 'always' meant pass by using a > memory address (indirect addressing); a reference has always been a > memory pointer. That's not a definition. That's an implementation. Some day, we'll be using quantum computers without memory addresses, or DNA computers, or some version of Babbage's Difference Engine (perhaps a trillion of them in the volume of a match-head, tiny nano computing devices... who knows?). Whatever it is, whether or not it has concepts of "memory address" or "memory pointer", it will still be possible to represent data indirectly via *some* mechanism. > If I call a function in C, and pass-by-value, the data's 'value' is > placed on the stack in a stack-frame, as a 'value' parm... its a copy > of the actual data in memory. Correct. > If I call a function in C, and pass-by-reference, the data's 'address' C doesn't do pass by reference. There is no way to declare a parameter to a function as a by-reference parameter. You can only simulate it by hand, by passing a pointer as data, pointing to what you *really* want as data, and dereferencing it yourself. But the pointer itself is passed by value: the address is copied onto the stack, just like any other piece of data would be. (The Python equivalent is to pass a list containing the object. If you want call-by-reference behaviour without the convenience of language support for it, you can have it.) Pascal, on the other hand, does do pass by reference. If you declare a "var" parameter, you then call the function with the variable you intend, and the compiler handles everything: function foo(x: int, var y: int): int; begin foo := x + y; y := 0; x := 0; end; a := 1; b := 2; c := foo(a, b); After calling foo, the variable a remains 1, but the variable b is now 0. The compiler is smart enough to figure out what to do behind the scenes to make it all work. We're not discussing what you, the coder, can do. Given any Turing- complete language, you can (with sufficient cleverness and hard-work) do anything any other Turing-complete language can do. We're discussing what the compiler does, and for C, that is purely call by value. Let me put it this way... old, unstructured BASIC has GOTOs and line numbers, correct? And Python doesn't, correct? But you could write a BASIC interpreter in Python, and call that interpreter from your Python code... therefore Python has line numbers and GOTOs, no? No. Of course not. We're discussing *language features*, and GOTO is not a language feature of Python. Neither is call by reference a language feature of C, or Python either for that matter, but it is a language feature of VB and Pascal. The only difference between the two scenarios is that writing a BASIC interpreter is a tad harder than dereferencing a pointer, but that's just a matter of degree, not of kind. -- Steven From alec.taylor6 at gmail.com Thu May 5 10:12:33 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 6 May 2011 00:12:33 +1000 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: ZIP is the wrong format. Use UPX with LZMA On Thu, May 5, 2011 at 8:55 PM, Wojtek Mamrak wrote: > Thanks for the reply! > >> Can you import from zip files when running the Python.exe interpreter? > When I zip the folder "Lib" into Python27.zip and later rename it and > try to run the python.exe, I receive an error: > "Import error: no module named site" > >> Is the zip file included in sys.path? ?You might need to add this >> yourself after callying Py_Initialize(). > Before renaming the "Lib" folder, the path to the python27.zip exists > in sys.path. > >> Is there a top-level directory in the zip file that may be throwing >> the importer off? > I am testing all the cases so this is not the issue. > >> Are you getting any sort of error message? > When I run my app, it crashes while calling Py_Initialize(). The > console closes suddenly. > > Is it necessary to create zip archive using zipfile.PyZipFile? > > regards > > > 2011/5/5 Ian Kelly >> >> On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak wrote: >> > Hello, >> > >> > I spent a lot of time googling for a solution of this problem, with no >> > result. >> > >> > I have a C++ application, in which I would like to embed Python interpreter. >> > I don't want to rely on an interpreter being installed on user machine, >> > instead I would like to distribute all the necessary files with my app. >> > >> > As far as I understand, beside of my executable and Python.dll (I am using >> > Python27), I need to provide two folders: >> > ?- DLLs, >> > ?- Lib >> > >> > If I place the Lib folder and the contents of the DLLs folder in a directory >> > of my executable, then everything seems to work. >> > However I would like to use a zipped Lib folder. Hence I made an archive >> > (which contains contents of Lib folder) called Python27.zip. Unfortunately >> > the app crashes during execution. >> > I assume the reason might be lack of zlib.pyd. Is that assumption correct? >> > If so, how to obtain it? If not, what am I doing wrong? >> >> I believe zlib.pyd is statically linked into python27.dll nowadays. >> Some things to check: >> >> Can you import from zip files when running the Python.exe interpreter? >> Is the zip file included in sys.path? ?You might need to add this >> yourself after callying Py_Initialize(). >> Is there a top-level directory in the zip file that may be throwing >> the importer off? >> Are you getting any sort of error message? >> -- >> http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list > From invalid at invalid.invalid Thu May 5 10:14:22 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:14:22 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On 2011-05-05, harrismh777 wrote: > Grant Edwards wrote: >> The "pass by value" and "pass by reference" parameter passing >> mechanisms are pretty well defined, and C uses "pass by value". > > Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that > helped define them.... I give up. You don't seem to understand the C language defintion or what is commonly meant by "pass by reference". -- Grant Edwards grant.b.edwards Yow! Inside, I'm already at SOBBING! gmail.com From invalid at invalid.invalid Thu May 5 10:17:15 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:17:15 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: On 2011-05-05, Gregory Ewing wrote: > harrismh777 wrote: >> 'C' does provide for pointers which are used by all 'C' >> programmers to firmly provide pass-by-reference in their coding > > Yes, but when they do that, they're building an abstraction > of their own on top of the facilities provided by the C > language. I've pointed that out to him. He's talking about what _he_ does in his program. We're talking about the C language definition and what the compiler does. > C itself has no notion of pass-by-reference. Exactly. C is pass by value. > If it did, the programmer would be able to use it directly > instead of having to insert & and * operators himself. That's what I was trying to say, but probably not as clearly. The "&" operatore returnas a _value_ that the OP passes _by_value_ to a function. That function then uses the "*" operator to use that value to access some data. -- Grant Edwards grant.b.edwards Yow! DIDI ... is that a at MARTIAN name, or, are we gmail.com in ISRAEL? From marduk at letterboxes.org Thu May 5 10:19:53 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 05 May 2011 10:19:53 -0400 Subject: PIL: The _imaging C module is not installed In-Reply-To: <4DC2A7AD.5080606@yahoo.de> References: <4DC2A7AD.5080606@yahoo.de> Message-ID: <1304605193.541346.2.camel@localhost.localdomain> On Thu, 2011-05-05 at 15:35 +0200, Nico Grubert wrote: > Hi there > > I am having trouble to install PIL 1.1.7 on CentOS. > > I read and followed the instructions from > http://effbot.org/zone/pil-imaging-not-installed.htm > > However, I still get the "The _imaging C module is not installed" error > if I run the selftest: > > $ python selftest.py > *** The _imaging C module is not installed > > > Here is what I have tested so far: > > 1.) > > $ python -v > ... > >>> import Image > ... > dlopen("/usr/local/lib/python2.4/site-packages/PIL/_imaging.so", 2); > import _imaging # dynamically loaded from > /usr/local/lib/python2.4/site-packages/PIL/_imaging.so > ... I had this problem earlier this week. Assuming that you pip-installed or similar. PIL will compile and install if you don't have some development libraries and then simply not work or not work up to full steam when used. To avoid this, you need to install the appropriate libraries, among which are: libjpeg-devel freetype-devel libpng-devel Probably others as well. HTH, -a From marduk at letterboxes.org Thu May 5 10:20:24 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 05 May 2011 10:20:24 -0400 Subject: PIL: The _imaging C module is not installed In-Reply-To: <4DC2A7AD.5080606@yahoo.de> References: <4DC2A7AD.5080606@yahoo.de> Message-ID: <1304605224.541346.3.camel@localhost.localdomain> Oh I forgot to say, after installing these libraries, you will need to re-compile (install) PIL. -a From invalid at invalid.invalid Thu May 5 10:21:31 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:21:31 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On 2011-05-05, harrismh777 wrote: > Tim Roberts wrote: >> The fact that the parameter "a" >> in BumpMe happens to be an address is completely irrelevent to the >> definition of the parameter passing mechanism. >> >> C has pass-by-value, exclusively. End of story. > > Yeah, Tim, I know... but that's my entire point in a nut-shell... > whether the language is pass-by-value or pass-by-reference has less to > do with how it is 'defined' (its mechanism--- indirection and stack) No, whether the _language_ is pass by value or pass-by-reference has _entirely_ to do with it's definition. > and more to do with how it is routinely used with the standard > features it provides--- in this case memory indirection--- as > pointers. Now you're talking about how you can implement higher level constructs using a language that doesn't directly implement such constructs. You might as well say that C is a linked-list language like Lisp since you can write a linked list implementation in C. If you said that you'd be just as wrong as saying that C uses call-by-reference. -- Grant Edwards grant.b.edwards Yow! I want another at RE-WRITE on my CEASAR gmail.com SALAD!! From gnarlodious at gmail.com Thu May 5 10:22:12 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Thu, 5 May 2011 07:22:12 -0700 (PDT) Subject: Need to solve the "Stateless HTTP" problem Message-ID: My scripting has grown to the point where the Apache server is a problem. My Python websites run and quit, which means I need to save data and recreate everything next page load. Bulky and slow. What is the simplest solution? I am running Py3 on OSX Server with Apache 2. Essentially I want certain objects to be a "constantly running process" that may timeout after some disuse. I suspect there are already systems for it. Please advise in simple terms, I am not a professional. -- Gnarlie From invalid at invalid.invalid Thu May 5 10:24:37 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:24:37 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <92el16F9kaU1@mid.individual.net> Message-ID: On 2011-05-05, Gregory Ewing wrote: > Hans Georg Schaathun wrote: >> Is transmission by name the same as call by object? > > No, it's not. With call-by-name, the caller passes a > small function (known as a "thunk") that calculates the > address of the parameter. Every time the callee needs to > refer to the parameter, it evaluates this function. > > This allows some neat tricks, but it's massive overkill for most > uses. It also is a very good source of surprising bugs. -- Grant Edwards grant.b.edwards Yow! I feel like I'm at in a Toilet Bowl with a gmail.com thumbtack in my forehead!! From invalid at invalid.invalid Thu May 5 10:25:58 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:25:58 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On 2011-05-05, harrismh777 wrote: > Dennis Lee Bieber wrote: >>> > We do not consider passing a pointer as*by value* because its an >>> > address; by definition, that is pass-by-reference. We are not passing >> To most of the world, pass-by-reference means the COMPILER, not the >> PROGRAMMER is obtaining and passing the address, and the compiler also >> always dereferences the passed "value"... The programmer has no control >> over whether to operate on the address or the data referenced by the >> address. > > Who is "most of the world" ? Pretty much everybody except you. Please see: > http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr233.htm Yea, I read that. It doesn't support your argument. It agrees with the rest of the world. -- Grant Edwards grant.b.edwards Yow! I need to discuss at BUY-BACK PROVISIONS gmail.com with at least six studio SLEAZEBALLS!! From invalid at invalid.invalid Thu May 5 10:30:08 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:30:08 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <92f7nuFfhhU1@mid.individual.net> Message-ID: On 2011-05-05, Gregory Ewing wrote: > harrismh777 wrote: >> 'C' is still the best high-level language on that processor. > > Some would argue that C is actually better than assembler these > days, because modern architectures are so freaking complicated > that it takes a computer to figure out the best instruction > sequence. :-( Been there, done that. Many years ago, it took me more than a week (and required the help of an ARM instruction set guru) to come up with an assembly language IP checksum routine for the ARM that out-performed the somewhat naive NetBSD "C" version. When we switched to the FreeBSD stack (and a newer compiler) a few years later, my assembly code got tossed out because was no longer any faster than the C version. -- Grant Edwards grant.b.edwards Yow! Half a mind is a at terrible thing to waste! gmail.com From roy at panix.com Thu May 5 10:31:33 2011 From: roy at panix.com (Roy Smith) Date: Thu, 05 May 2011 10:31:33 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: In article , Grant Edwards wrote: > That's what I was trying to say, but probably not as clearly. The "&" > operatore returnas a _value_ that the OP passes _by_value_ to a > function. That function then uses the "*" operator to use that value > to access some data. Then, of course, there's references in C++. I think it's fair to call the following "call by reference" in the sense we're talking about it here. void f(int& i) { i = 5; } int i = 42; f(i); Of course, C++ lets you go off the deep end with abominations like references to pointers. Come to think of it, C++ let's you go off the deep end in so many ways... From invalid at invalid.invalid Thu May 5 10:31:58 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:31:58 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <4dc29cdd$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-05, Steven D'Aprano wrote: > On Wed, 04 May 2011 14:22:38 -0500, harrismh777 wrote: > >> Here is the thing that everyone forgets... all we have to work with >> is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). > > Actually, this is incorrect. Most processors these days are hybrids > between that and either the Harvard or Modified Harvard architecture: > > http://en.wikipedia.org/wiki/Modified_Harvard_architecture > http://en.wikipedia.org/wiki/Harvard_architecture > http://en.wikipedia.org/wiki/Von_Neumann_architecture And a lot of the are still full-up Harvard architecture (e.g. the entire Atmel AVR family and Intel 8051 family for example). -- Grant Edwards grant.b.edwards Yow! When this load is at DONE I think I'll wash it gmail.com AGAIN ... From pruebauno at latinmail.com Thu May 5 10:33:31 2011 From: pruebauno at latinmail.com (nn) Date: Thu, 5 May 2011 07:33:31 -0700 (PDT) Subject: Today's fun and educational Python recipe References: Message-ID: On May 4, 2:17?pm, Raymond Hettinger wrote: > Here's a 22-line beauty for a classic and amazing algorithm:http://bit.ly/bloom_filter > > The wiki article on the algorithm is brief and well-written:http://en.wikipedia.org/wiki/Bloom_filter > > It turns out that people in the 1970's were pretty smart :-) > > Raymond > > ------- > follow my other python tips and recipes on twitter: ?@raymondh Very cool! Thanks. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Thu May 5 10:37:59 2011 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Thu, 5 May 2011 14:37:59 +0000 (UTC) Subject: Need to solve the "Stateless HTTP" problem References: Message-ID: Gnarlodious wrote: > My scripting has grown to the point where the Apache server is a > problem. My Python websites run and quit, which means I need to save > data and recreate everything next page load. Bulky and slow. What is > the simplest solution? Karrigell? -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From harrismh777 at charter.net Thu May 5 10:40:49 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 09:40:49 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc29cdd$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <4dc29cdd$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > You should read Paul Graham on the Blub Paradox: > > http://www.paulgraham.com/avg.html > > Excellent-! ... thanks, fun article. ... where is that lisp manual anyway? ... oh, yeah, emacs! :) From rosuav at gmail.com Thu May 5 10:47:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 May 2011 00:47:30 +1000 Subject: Need to solve the "Stateless HTTP" problem In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 12:22 AM, Gnarlodious wrote: > My scripting has grown to the point where the Apache server is a > problem. My Python websites run and quit, which means I need to save > data and recreate everything next page load. Bulky and slow. What is > the simplest solution? > > I am running Py3 on OSX Server with Apache 2. Essentially I want > certain objects to be a "constantly running process" that may timeout > after some disuse. I suspect there are already systems for it. Please > advise in simple terms, I am not a professional. Depending on how much of Apache's featureset you're using, it may be easiest to set it aside altogether and just run a Python HTTP server. Then you can maintain as much state as you like. But if you're currently hosting multiple sites and distinguishing between them using Host: headers (using NameVirtualHost), then you'd have to change them all, which probably wouldn't be worthwhile. Chris Angelico From roy at panix.com Thu May 5 10:49:35 2011 From: roy at panix.com (Roy Smith) Date: Thu, 05 May 2011 10:49:35 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <4dc29cdd$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4dc29cdd$0$29991$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > C is better described as a high-level assembler, or a low-level language. > It is too close to the hardware to describe it as high-level, it has no > memory management, few data abstractions, and little protection. +1 I (and most people who really know C and the specific hardware architecture they're working on) should be able to look at a C program and (modulo optimization) pretty much be able to write down the generated assembler by hand. In fact, I used to do exactly that. I was once working on M-6800 hardware (8/16-bit microprocessor). I used to write out procedures in C, then hand-compile it into assembler code (and leave the C code as a comment). I wasn't a true masochist, however. I did let an assembler convert it to hex for me before I keyed it in :-) On the other hand, trying to do that for something like C++ is damn near impossible. There's too much stuff that happens by magic. Creation (and destruction) of temporary objects. Exception handling. RTTI. Not to mention truly black magic like template expansion. From steve+comp.lang.python at pearwood.info Thu May 5 10:50:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 14:50:36 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <4dc2b93c$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 14:58:38 -0500, harrismh777 wrote: > Benjamin Kaplan wrote: >> CPython is implemented in C because that's the language chosen. Python >> is also implemented in Java, C#, Python, and several other languages. > > True enough. If I used Jython, I would want to take a look at those > sources... as well as the Java sources... which were wrtten in, um, C. No, Java sources are written in Java. That's why they're *Java* sources. Perhaps you mean that the Java compiler is written in C? Highly unlikely: Java compilers have been self-hosting for many years now. http://en.wikipedia.org/wiki/Self-hosting -- Steven From steve+comp.lang.python at pearwood.info Thu May 5 10:51:52 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 14:51:52 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4dc2b988$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 16:22:42 -0600, Ian Kelly wrote: > However, I hope we can all agree that pass-by-pointer shares certain > features with both pass-by-value and pass-by-reference, and there are > perfectly reasonable arguments for lumping it in either category, yes? *cries* Please don't invent another "pass by foo" term!!!! Seriously though, "pass by foo" refers to what the compiler or interpreter does when you, the coder, call a function with some variable, say, x: f(x) It is not referring to what you, the coder, does when you want to pass an indirect reference of some sort to a chunk of data to some function. In many languages, you would use a pointer, and write the function call something like this: f(^x) (using Pascal's up-arrow notation for "pointer to"). Such "pass by pointer" is a tactic used by the coder, as opposed to a language feature. I believe this distinction between what the compiler does, and what the coder does, is at the heart of much confusion. Pointers that are passed as arguments are themselves data, just as much as ints or floats, or (in languages that have first-class functions) functions. -- Steven From neilc at norwich.edu Thu May 5 11:10:43 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 5 May 2011 15:10:43 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: <92fsvjFkghU1@mid.individual.net> On 2011-05-05, Roy Smith wrote: > Of course, C++ lets you go off the deep end with abominations > like references to pointers. Come to think of it, C++ let's > you go off the deep end in so many ways... But you can do some really cool stuff in the deep end. -- Neil Cerutti From steve+comp.lang.python at pearwood.info Thu May 5 11:11:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 15:11:33 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 May 2011 14:14:22 +0000, Grant Edwards wrote: > On 2011-05-05, harrismh777 wrote: >> Grant Edwards wrote: >>> The "pass by value" and "pass by reference" parameter passing >>> mechanisms are pretty well defined, and C uses "pass by value". >> >> Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that >> helped define them.... > > I give up. You don't seem to understand the C language defintion or > what is commonly meant by "pass by reference". In fairness, he's not the only one. M Harris has twice now linked to an IBM site that describes pass-by-reference in C in terms of passing a pointer to the argument you want as the argument. Admittedly, doing so gives you almost the same behaviour, except that you have to dereference the pointers yourself. That's a pretty big difference though, and gets to the core of the argument: it's a bit like arguing that manual cars are fitted with exactly the same automatic transmission as auto cars, it's just that you have to engage the clutch and shift gears yourself. -- Steven From steve+comp.lang.python at pearwood.info Thu May 5 11:14:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 15:14:20 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: <4dc2becc$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 09:18:56 -0700, Devin Jeanpierre wrote: > On May 4, 9:44 am, Hans Georg Schaathun wrote: >> : The only twist is that you never get to dereference : >> pointers in Python, but you can in C. Not much of a twist if you ask : >> me, but then again, I've been thinking in thismodelfor years. Maybe : >> I'm brainwashed. :) >> >> You are. You explain Python in terms of C. That's useful when you >> talk to other speakers of C. >> >> If you want to explain the language to a broader audience, you should >> use terminology from the language's own level of abstraction. > > No, I explained Python in terms of pointers/reference. Python has no pointers or references unless you simulate them yourself using other data types. They exist as implementation details of the Python virtual machine, which is at least two levels below that of Python code. The first is the byte code which runs in the virtual machine; the second is the code in the VM. -- Steven From roy at panix.com Thu May 5 11:29:48 2011 From: roy at panix.com (Roy Smith) Date: Thu, 05 May 2011 11:29:48 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> <92fsvjFkghU1@mid.individual.net> Message-ID: In article <92fsvjFkghU1 at mid.individual.net>, Neil Cerutti wrote: > On 2011-05-05, Roy Smith wrote: > > Of course, C++ lets you go off the deep end with abominations > > like references to pointers. Come to think of it, C++ let's > > you go off the deep end in so many ways... > > But you can do some really cool stuff in the deep end. "Hey, let's override operator,() and have some fun" From mwilson at the-wire.com Thu May 5 11:30:27 2011 From: mwilson at the-wire.com (Mel) Date: Thu, 05 May 2011 11:30:27 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Some day, we'll be using quantum computers without memory addresses, [ ... ] it will still be possible to > represent data indirectly via *some* mechanism. :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the 'nonlocal' keyword! Mel. From ian.g.kelly at gmail.com Thu May 5 11:36:39 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 May 2011 09:36:39 -0600 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 4:55 AM, Wojtek Mamrak wrote: > Thanks for the reply! > >> Can you import from zip files when running the Python.exe interpreter? > When I zip the folder "Lib" into Python27.zip and later rename it and > try to run the python.exe, I receive an error: > "Import error: no module named site" That means it's not finding it. After startup, try adding the zip file to your sys.path and then do "import site" at the command line, and it should work. >> Are you getting any sort of error message? > When I run my app, it crashes while calling Py_Initialize(). The > console closes suddenly. Hm, that definitely seems odd. What if you put the zip file in your PYTHONPATH environment variable? > Is it necessary to create zip archive using zipfile.PyZipFile? It shouldn't be. It works for me (at least with Python.exe) creating the zip archive using 7-Zip. From nagle at animats.com Thu May 5 11:41:27 2011 From: nagle at animats.com (John Nagle) Date: Thu, 05 May 2011 08:41:27 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <92fb5jFa2lU1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> <92fb5jFa2lU1@mid.individual.net> Message-ID: <4dc2c52e$0$10567$742ec2ed@news.sonic.net> On 5/5/2011 3:06 AM, Gregory Ewing wrote: > John Nagle wrote: > >> A reasonable compromise would be that "is" is treated as "==" on >> immutable objects. > > That wouldn't work for tuples, which can contain references > to other objects that are not immutable. Such tuples are still identical, even if they contain identical references to immutable objects. John Nagle From steve+comp.lang.python at pearwood.info Thu May 5 11:42:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 15:42:58 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> Message-ID: <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> Given the following statement of Python code: >> >> >>> x = "spam" >> >> what is the value of the variable x? > > Mu (?). > > ?x? is a name. Names are bound to values. Talk of ?variable? only > confuses the issue because of the baggage carried with that term. Yes, good point. Consider me chastised, because I actually knew that. It's just that the term "variable" is so useful and so familiar that it's easy to use it even for languages that don't have variables in the C/ Pascal/Fortran/etc sense. > But the data model of Python doesn't fit well with the ideas that the > term ?variable? connotes for most programmers: a box, perhaps of a rigid > shape (data type) or not, which is labelled ?x? and nothing else. For > another variable to have an equal value, that value needs to be copied > and put in a separate box; or perhaps some special reference to the > original needs to be made and placed in a box. > > Saying ?variable? and ?has the value? just invites baggage needlessly, > and creates many assumptions about Python's data model which has to be > un-done, often after much false mental scaffolding has been built on > them by the newbie and needs to be dismantled carefully. I've quoted your two paragraphs because I think they're very important, not because I intend arguing. Possibly a first for me :) However.... > Python isn't pass by anything. Nothing gets copied, nothing gets passed; > when a function is called with an object as a parameter, the object > stays put, and simply gets a new temporary name bound to it for the > function's use. This, however, is incorrect. "Passing" in this sense refers to calling the function with an argument, hence "pass by..." and "call by..." are synonyms. The mechanics of how the compiler or interpreter makes arguments available to functions has real consequences at the language level: the calling strategy used by the compiler effects the language semantics. >> > Whatever, a rose by any other name...) >> >> Do you really think that roses would be the symbol of romantic love if >> they were called "disgusting stink-weeds of perversion and death"? > > Juliet's point stands, though: they would still smell as sweet, and the > term you describe would be unlikely to catch on since it doesn't > describe them well at all. Perhaps a counter-example is that of the tomato, which never took off as a food in Europe until people stopped calling them "love apples", and thinking that they were deadly poison. Or Chinese Gooseberries, better known by the name thought up by a marketing firm, "kiwi fruit". -- Steven From workitharder at gmail.com Thu May 5 11:51:10 2011 From: workitharder at gmail.com (buck) Date: Thu, 5 May 2011 08:51:10 -0700 (PDT) Subject: Development tools and practices for Pythonistas In-Reply-To: Message-ID: I use hg for even 50-line standalone python scripts. It's very well suited to these small environments, and scales up nicely. cd /my/working/dir hg init hg add myscript.py hg ci -m 'added myscript' It's that simple, and now hyou can go back if you make a terrible mistake, and you can post it to bitbucket and share with the world if you like, almost as easily. --Buck From workitharder at gmail.com Thu May 5 11:55:00 2011 From: workitharder at gmail.com (buck) Date: Thu, 5 May 2011 08:55:00 -0700 (PDT) Subject: [OT] From svn to something else? In-Reply-To: Message-ID: This is what made me choose Mercurial in my recent search. http://www.python.org/dev/peps/pep-0374/ There is a tremendous amount of detail there. In summary, hg and git are both very good, and essentially equal in features. The only salient difference is that hg is implemented in python, so they went with that. I did the same, and I'm quite happy. It's basically svn with the shiny new distributed features added. From workitharder at gmail.com Thu May 5 11:55:00 2011 From: workitharder at gmail.com (buck) Date: Thu, 5 May 2011 08:55:00 -0700 (PDT) Subject: [OT] From svn to something else? In-Reply-To: Message-ID: This is what made me choose Mercurial in my recent search. http://www.python.org/dev/peps/pep-0374/ There is a tremendous amount of detail there. In summary, hg and git are both very good, and essentially equal in features. The only salient difference is that hg is implemented in python, so they went with that. I did the same, and I'm quite happy. It's basically svn with the shiny new distributed features added. From harrismh777 at charter.net Thu May 5 11:56:11 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 10:56:11 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mel wrote: >> represent data indirectly via*some* mechanism. > :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the > 'nonlocal' keyword! I was thinking pass-by-osmosis.... :) From nagle at animats.com Thu May 5 11:58:33 2011 From: nagle at animats.com (John Nagle) Date: Thu, 05 May 2011 08:58:33 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2ad5e$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> <4dc2ad5e$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc2c92f$0$10586$742ec2ed@news.sonic.net> On 5/5/2011 6:59 AM, Steven D'Aprano wrote: > On Thu, 05 May 2011 21:48:20 +1000, Chris Angelico wrote: > >> On Thu, May 5, 2011 at 9:44 PM, Mel wrote: >>> John Nagle wrote: >>>> On 5/4/2011 5:46 PM, harrismh777 wrote: >>>>> Or, as stated earlier, Python should not allow 'is' on immutable >>>>> objects. >>>> >>>> A reasonable compromise would be that "is" is treated as "==" on >>>> immutable objects. >>> >>> I foresee trouble testing among float(5), int(5), Decimal(5) ... >> >> Define 'x is y' as 'type(x)==type(y) and >> isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then. That's close to the right answer. > > `is` is supposed to be a *fast* operator, not even slower than equality > testing. That's an implementation problem. Those are cheap tests at the machine code level. An efficient test looks like this: def istest(a, b) : if id(a) == id(b) : # the cheap address test return(True) if type(x) != type(y) : # cheap binary comparison return(False) if mutable(x) : # the interpreter knows this return(False) return(x == y) # equality test for mutables Probably about 12 machine instructions, and the full "==" test is only reached for cases in which "is" now produces wrong answers. It's encouraging that a Google code search finds no matches of if .* is \" or if .* is 1 in Python code. John Nagle From harrismh777 at charter.net Thu May 5 12:00:53 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 11:00:53 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > In fairness, he's not the only one. M Harris has twice now linked to an > IBM site that describes pass-by-reference in C in terms of passing a > pointer to the argument you want as the argument. Admittedly, doing so > gives you almost the same behaviour, except that you have to dereference > the pointers yourself. > > That's a pretty big difference though, and gets to the core of the > argument: it's a bit like arguing that manual cars are fitted with > exactly the same automatic transmission as auto cars, it's just that you > have to engage the clutch and shift gears yourself. ... and actually, if you feel it just right and you have just the right synchro-mesh setup, you can slide from 3rd into 4th without every touching the clutch peddle... and if that isn't automatic, I don't know what is.... man those were the days... now I just press a button that says, "Auto 4-wheel Lock", set the gps, and take a nap... :) From harrismh777 at charter.net Thu May 5 12:18:46 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 11:18:46 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Grant Edwards wrote: > I give up. You don't seem to understand the C language defintion or > what is commonly meant by "pass by reference". > ah, don't give up... here is a link that might help to clarify some of these semantics... me thinks: http://en.wikipedia.org/wiki/Pass_by_reference#Call_by_value kind regards, m harris From andreas.tawn at ubisoft.com Thu May 5 12:27:26 2011 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Thu, 5 May 2011 18:27:26 +0200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <654D9D97DA51AD479973BC2D5578603C0BEA7F4864@PDC-MAIL-CMS01.ubisoft.org> > Steven D'Aprano wrote: > > > Some day, we'll be using quantum computers without memory addresses, > [ ... > ] it will still be possible to > > represent data indirectly via *some* mechanism. > > :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the > 'nonlocal' keyword! > > Mel. > If True and False: waveFunction.collapse(cat) That's going to be fun ;o) Cheers, Drea From miki.tebeka at gmail.com Thu May 5 12:33:56 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 5 May 2011 09:33:56 -0700 (PDT) Subject: Need to solve the "Stateless HTTP" problem In-Reply-To: Message-ID: <1416652a-99ba-43c5-96f6-6f40b7442368@glegroupsg2000goo.googlegroups.com> > Essentially I want > certain objects to be a "constantly running process" that may timeout > after some disuse. memcached? From ian.g.kelly at gmail.com Thu May 5 12:44:39 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 May 2011 10:44:39 -0600 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2c52e$0$10567$742ec2ed@news.sonic.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> <92fb5jFa2lU1@mid.individual.net> <4dc2c52e$0$10567$742ec2ed@news.sonic.net> Message-ID: On Thu, May 5, 2011 at 9:41 AM, John Nagle wrote: > On 5/5/2011 3:06 AM, Gregory Ewing wrote: >> >> John Nagle wrote: >> >>> A reasonable compromise would be that "is" is treated as "==" on >>> immutable objects. >> >> That wouldn't work for tuples, which can contain references >> to other objects that are not immutable. > > ? ?Such tuples are still identical, even if they > contain identical references to immutable objects. >>> a = (1, 2, [3, 4, 5]) >>> b = (1, 2, [3, 4, 5]) >>> a == b True >>> a is b # Using the proposed definition True >>> a[0] is b[0] True >>> a[1] is b[1] True >>> a[2] is b[2] False >>> a[2].append(6) >>> a (1, 2, [3, 4, 5, 6]) >>> b (1, 2, [3, 4, 5]) >>> a == b False >>> a is b False Thus a and b cannot be used interchangeably even though "a is b" originally returned True. From invalid at invalid.invalid Thu May 5 12:48:58 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 16:48:58 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-05, Steven D'Aprano wrote: > On Thu, 05 May 2011 14:14:22 +0000, Grant Edwards wrote: > >> On 2011-05-05, harrismh777 wrote: >>> Grant Edwards wrote: >>>> The "pass by value" and "pass by reference" parameter passing >>>> mechanisms are pretty well defined, and C uses "pass by value". >>> >>> Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that >>> helped define them.... >> >> I give up. You don't seem to understand the C language defintion or >> what is commonly meant by "pass by reference". > > > In fairness, he's not the only one. M Harris has twice now linked to an > IBM site that describes pass-by-reference in C in terms of passing a > pointer to the argument you want as the argument. Admittedly, doing so > gives you almost the same behaviour, except that you have to dereference > the pointers yourself. > > That's a pretty big difference though, and gets to the core of the > argument: it's a bit like arguing that manual cars are fitted with > exactly the same automatic transmission as auto cars, it's just that > you have to engage the clutch and shift gears yourself. I like that analogy. "My car has an automatic transmission except you have to shift gears yourself with that lever and that it has a clutch operated by that pedal instead of a hydrostatic torque converter." -- Grant Edwards grant.b.edwards Yow! ... bleakness at ... desolation ... plastic gmail.com forks ... From invalid at invalid.invalid Thu May 5 12:52:52 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 16:52:52 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-05, harrismh777 wrote: > Steven D'Aprano wrote: >> In fairness, he's not the only one. M Harris has twice now linked to an >> IBM site that describes pass-by-reference in C in terms of passing a >> pointer to the argument you want as the argument. Admittedly, doing so >> gives you almost the same behaviour, except that you have to dereference >> the pointers yourself. >> >> That's a pretty big difference though, and gets to the core of the >> argument: it's a bit like arguing that manual cars are fitted with >> exactly the same automatic transmission as auto cars, it's just that you >> have to engage the clutch and shift gears yourself. > > > ... and actually, if you feel it just right and you have just the > right synchro-mesh setup, you can slide from 3rd into 4th without > every touching the clutch peddle... That's possible on pretty much any modern automotive or small-truck transmission, and it's not really that hard to do. I can go from 1st up to 5th and back down to 1st without touching the clutch. I don't as a habit do it, because it puts unnecessary wear on the syncros (and I've had cars with pretty weak syncros -- Alfa-Romeo Spyders were famous for the 2nd gear syncro wearing out). > and if that isn't automatic, I don't know what is.... No, that's _not_ automatic if you have to do it yourself. It's automatic when it happens without user-intervention. Now I think you're trolling... -- Grant Edwards grant.b.edwards Yow! I want to dress you at up as TALLULAH BANKHEAD and gmail.com cover you with VASELINE and WHEAT THINS ... From invalid at invalid.invalid Thu May 5 12:56:01 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 16:56:01 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: On 2011-05-05, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> That's what I was trying to say, but probably not as clearly. The "&" >> operatore returnas a _value_ that the OP passes _by_value_ to a >> function. That function then uses the "*" operator to use that value >> to access some data. > > Then, of course, there's references in C++. I think it's fair to call > the following "call by reference" in the sense we're talking about it > here. > > void f(int& i) { > i = 5; > } > int i = 42; > f(i); If after the call to f(i) the caller sees that i == 5, then that's call by reference. But, we were talking about C. > Of course, C++ lets you go off the deep end with abominations like > references to pointers. Come to think of it, C++ let's you go off > the deep end in so many ways... :) -- Grant Edwards grant.b.edwards Yow! Is this sexual at intercourse yet?? Is it, gmail.com huh, is it?? From invalid at invalid.invalid Thu May 5 12:57:34 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 16:57:34 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> <92fsvjFkghU1@mid.individual.net> Message-ID: On 2011-05-05, Neil Cerutti wrote: > On 2011-05-05, Roy Smith wrote: >> Of course, C++ lets you go off the deep end with abominations >> like references to pointers. Come to think of it, C++ let's >> you go off the deep end in so many ways... > > But you can do some really cool stuff in the deep end. Until you get pulled under and drowned by some flailing goof who oughtn't be there. -- Grant Edwards grant.b.edwards Yow! Zippy's brain cells at are straining to bridge gmail.com synapses ... From harrismh777 at charter.net Thu May 5 12:58:46 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 11:58:46 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: Grant Edwards wrote: > That's what I was trying to say, but probably not as clearly. The "&" > operatore returnas a_value_ that the OP passes_by_value_ to a > function. That function then uses the "*" operator to use that value > to access some data. I'm gonna try a D'Aprano-style bogus argument for a moment... ... saying that 'C' does not support pass-by-reference because you have to direct the compiler with the '&' and '*' characters is a little like saying that Python does not support decorations ! ... ... because you have to direct the interpreter with some @ bogus-decorator-syntax I want Python to support decorations automatically ! ;-) From harrismh777 at charter.net Thu May 5 13:03:27 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 12:03:27 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Grant Edwards wrote: > No, that's_not_ automatic if you have to do it yourself. It's > automatic when it happens without user-intervention. > > Now I think you're trolling... ... no, I was only kidding... :) From ian.g.kelly at gmail.com Thu May 5 13:07:42 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 May 2011 11:07:42 -0600 Subject: Need to solve the "Stateless HTTP" problem In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 8:22 AM, Gnarlodious wrote: > My scripting has grown to the point where the Apache server is a > problem. My Python websites run and quit, which means I need to save > data and recreate everything next page load. Bulky and slow. What is > the simplest solution? > > I am running Py3 on OSX Server with Apache 2. Essentially I want > certain objects to be a "constantly running process" that may timeout > after some disuse. I suspect there are already systems for it. Please > advise in simple terms, I am not a professional. It sounds to me like you're currently running your Python scripts as CGIs? You should look into running your scripts via mod_wsgi in daemon mode, which will do exactly what you are asking. See here: http://code.google.com/p/modwsgi/ From harrismh777 at charter.net Thu May 5 13:19:31 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 12:19:31 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Ethan Furman wrote: > PS > My thanks to those who kept explaining in various ways about the > difference between language supported features and programmer constructs > -- I hadn't realized before this thread that call-by-reference was not a > language feature of C, but rather a programmer-implemented feature using > the C operators. You are most welcome. :) From ethan at stoneleaf.us Thu May 5 13:28:08 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 05 May 2011 10:28:08 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4DC2DE28.9030501@stoneleaf.us> harrismh777 wrote: > Grant Edwards wrote: >> I give up. You don't seem to understand the C language defintion or >> what is commonly meant by "pass by reference". >> > > ah, don't give up... here is a link that might help to clarify some of > these semantics... me thinks: > > http://en.wikipedia.org/wiki/Pass_by_reference#Call_by_value Indeed it does (emphasis added): "In call-by-reference evaluation (also referred to as pass-by-reference), a function receives an *implicit* reference to a variable used as argument" In C the the reference is explicit, which the article states in the next paragraph: "Even among languages that don't exactly support call-by-reference, many, including C and ML, support explicit references (objects that refer to other objects), such as pointers" ~Ethan~ PS My thanks to those who kept explaining in various ways about the difference between language supported features and programmer constructs -- I hadn't realized before this thread that call-by-reference was not a language feature of C, but rather a programmer-implemented feature using the C operators. From neilc at norwich.edu Thu May 5 13:39:03 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 5 May 2011 17:39:03 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: <92g5lnFkolU1@mid.individual.net> On 2011-05-05, harrismh777 wrote: > ... saying that 'C' does not support pass-by-reference because > you have to direct the compiler with the '&' and '*' characters > is a little like saying that > > Python does not support decorations ! ... > > > ... because you have to direct the interpreter with some > > > @ bogus-decorator-syntax > > > I want Python to support decorations automatically ! You do have to declare decorators when defining them, but they are called automatically when you call the decorated function, with no special syntax required. C pointers don't automatically dereference themselves. -- Neil Cerutti From tjreedy at udel.edu Thu May 5 14:39:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 May 2011 14:39:28 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <92fmffFucoU9@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <92fmffFucoU9@mid.individual.net> Message-ID: On 5/5/2011 9:19 AM, Neil Cerutti wrote: > On 2011-05-04, John Nagle wrote: >> That's a quirk of CPython's boxed number implementation. All >> integers are boxed, but there's a set of canned objects for >> small integers. CPython's range for this is -5 to +256, >> incidentally. That's visible through the "is" operator. >> Arguably, it should not be. > > But that's the sole purpose of the is operator. You either expose > those details, or you don't have an is operator at all. Which is to say, the CPython testsuite has a CPython-specific implementation test that uses 'is' to test that implementation detail. -- Terry Jan Reedy From joaquin.barry at gmail.com Thu May 5 15:09:28 2011 From: joaquin.barry at gmail.com (Wok-Thee-Recruiter) Date: Thu, 5 May 2011 12:09:28 -0700 (PDT) Subject: Employment Opportunity in Chicago Message-ID: <73f67ec1-cac4-4bee-ad9f-958ac87e3cb7@s16g2000prf.googlegroups.com> Python Developer Looking for a candidate with hands on Python development experience to work for a fast growing company that provides in-flight broadband services. ? This person will be working on portal development and optimizing plane systems. ? Help integrate third party products such as video and other products pertaining to aviation. ? Candidate should have a minimum of 5-7 years of experience. ? Position reports directly into the CTO Requirements ? 5-7 years of full software development lifecycle experience ? 2-3 years of Python development ? 2-3 years of SQL experience ? MySQL ? Database configuration Send emails to jbarry at pt-corp.com or call Joaquin direct at 312-643-2010 From ian.g.kelly at gmail.com Thu May 5 15:13:11 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 May 2011 13:13:11 -0600 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: On Thu, May 5, 2011 at 10:58 AM, harrismh777 wrote: > Grant Edwards wrote: >> >> That's what I was trying to say, but probably not as clearly. ?The "&" >> operatore returnas a_value_ ?that the OP passes_by_value_ ?to a >> function. ?That function then uses the "*" operator to use that value >> to access some data. > > I'm gonna try a D'Aprano-style bogus argument for a moment... > > ... saying that 'C' does not support pass-by-reference because you have to > direct the compiler with the '&' and '*' characters is a little like saying > that > > ? ? Python does not support decorations ! ... > > > ... ?because you have to direct the interpreter with some > > > @ bogus-decorator-syntax > > > ? ? I want Python to support decorations automatically ! It seems to me that manually referencing and dereferencing in C is more akin to decorating functions like this: def foo(x): do_stuff() foo = decorate(foo) On the other hand, the @ syntax is analogous to declaring reference types in C++ (e.g. "int &" as opposed to "int *"). In both cases you have to tell the interpreter / compiler that you want to use the decoration / pass-by-reference feature, and the actual work is done for you automatically. From harrismh777 at charter.net Thu May 5 16:12:45 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 15:12:45 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: <2xDwp.49594$sS4.40218@newsfe11.iad> Ian Kelly wrote: > On the other hand, the @ syntax is analogous to declaring reference > types in C++ (e.g. "int&" as opposed to "int *"). In both cases you > have to tell the interpreter / compiler that you want to use the > decoration / pass-by-reference feature, and the actual work is done > for you automatically. [ @Ian, Neil ] :) ... uh, it was worth a shot... No, I see your point... with the slight small push-back that dereferencing a pointer with '*' can't really be called 'work' can it? ( I know, you'll say yes, because the 'compiler' didn't do it ! ) :)) From tacyt1007 at gmail.com Thu May 5 16:34:02 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Thu, 5 May 2011 22:34:02 +0200 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: > That means it's not finding it. After startup, try adding the zip > file to your sys.path and then do "import site" at the command line, > and it should work. Maybe I am missing the point, but I think I am not able to do this. When I remove the "Lib" folder and try to run Python.exe, the python console window closes rapidly, so that it is hard to read any message displayed in it and obvioulsy I can't run any python command. Could you clarify this please? > What if you put the zip file in your > PYTHONPATH environment variable? I don't have it defined. Maybe it is because I have 2 different Python interpreters installed. After adding the PYTHONPATH, the Python.exe seems to run normally. Unfortunately I am not able to import Image module (I am using it), which is installed in site-packages/PIL. This happens, because for some reason the site-packages directory is not present in sys.path. After reading the site module description I checked the sys.prefix and sys.exec_prefix, which are both empty, when the Lib folder is loaded from the zip archive. Thats why site-packages is not added to sys.path. Of course I can add site-packages directory to the sys.path by myself (yet I don't know why sys.prefix and sys.exec_prefix are empty), however how to deal with the PYTHONPATH, which is required to load site.py and hence has to be defined at the very beginning? thanks for your help 2011/5/5 Ian Kelly : > On Thu, May 5, 2011 at 4:55 AM, Wojtek Mamrak wrote: >> Thanks for the reply! >> >>> Can you import from zip files when running the Python.exe interpreter? >> When I zip the folder "Lib" into Python27.zip and later rename it and >> try to run the python.exe, I receive an error: >> "Import error: no module named site" > > That means it's not finding it. ?After startup, try adding the zip > file to your sys.path and then do "import site" at the command line, > and it should work. > >>> Are you getting any sort of error message? >> When I run my app, it crashes while calling Py_Initialize(). The >> console closes suddenly. > > Hm, that definitely seems odd. ?What if you put the zip file in your > PYTHONPATH environment variable? > >> Is it necessary to create zip archive using zipfile.PyZipFile? > > It shouldn't be. ?It works for me (at least with Python.exe) creating > the zip archive using 7-Zip. > From miki.tebeka at gmail.com Thu May 5 17:12:51 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 5 May 2011 14:12:51 -0700 (PDT) Subject: avro slow? Message-ID: <98cd6085-bb77-417b-80e4-68ca990001cf@glegroupsg2000goo.googlegroups.com> Greetings, I'm reading some data from avro file using the avro library. It takes about a minute to load 33K objects from the file. This seem very slow to me, specially with the Java version reading the same file in about 1sec. Here is the code, am I doing something wrong? import avro.datafile import avro.io from time import time def load(filename): fo = open(filename, "rb") reader = avro.datafile.DataFileReader(fo, avro.io.DatumReader()) for i, record in enumerate(reader): pass return i + 1 def main(argv=None): import sys from argparse import ArgumentParser argv = argv or sys.argv parser = ArgumentParser(description="Read avro file") start = time() num_records = load("events.avro") end = time() print("{0} records in {1} seconds".format(num_records, end - start)) if __name__ == "__main__": main() From pazurrobert at gmail.com Thu May 5 17:26:08 2011 From: pazurrobert at gmail.com (Robert Pazur) Date: Thu, 5 May 2011 23:26:08 +0200 Subject: access to some text string in PDFs Message-ID: Dear all, i would like to access some text and count the occurrence as follows > I got a lots of pdf with some scientific articles and i want to preview which words are usually related with for example "determinants" as an example in the article is a sentence > ....elevation is the most important determinant.... how can i acquire the "elevation" string? of course i dont know where the sententence in article is located or which particular word could there be any suggestions? Maybe its easy to solve, but its just one day since I subscribe to this forum (although i got some Python experience) so i really appreciate any help! Kind regards, Robert. ------------------------------------------------------- Robert Pazur -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu May 5 17:41:25 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 May 2011 15:41:25 -0600 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 2:34 PM, Wojtek Mamrak wrote: > Maybe I am missing the point, but I think I am not able to do this. > When I remove the "Lib" folder and try to run Python.exe, the python > console window closes rapidly, so that it is hard to read any message > displayed in it and obvioulsy I can't run any python command. Could > you clarify this please? Darn, it worked for me in Python 2.5: C:\Python25>python 'import site' failed; use -v for traceback Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append(r'C:\Python25\lib.zip') >>> import site Although I am also seeing the issue with sys.prefix not getting set and site-packages not getting added. But in Python 2.7 I just get: C:\Python27>python ImportError: No module named site C:\Python27> And in Python 3.2 it causes a full-on crash: C:\Python32>python Fatal Python error: Py_Initialize: unable to load the file system codec LookupError: no codec search functions registered: can't find encoding This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. >> What if you put the zip file in your >> PYTHONPATH environment variable? > > I don't have it defined. Maybe it is because I have 2 different Python > interpreters installed. > After adding the PYTHONPATH, the Python.exe seems to run normally. > Unfortunately I am not able to import Image module (I am using it), > which is installed in site-packages/PIL. > This happens, because for some reason the site-packages directory is > not present in sys.path. After reading the site module description I > checked the sys.prefix and sys.exec_prefix, which are both empty, when > the Lib folder is loaded from the zip archive. Thats why site-packages > is not added to sys.path. > Of course I can add site-packages directory to the sys.path by myself > (yet I don't know why sys.prefix and sys.exec_prefix are empty), > however how to deal with the PYTHONPATH, which is required to load > site.py and hence has to be defined at the very beginning? Are you calling Py_SetProgramName? That may help to set sys.prefix and sys.exec_prefix. However, looking at site.py, it appears that it's only looking for proper directories. I don't think it will be able to add a site-packages inside a zip archive at all; you will just have to add that yourself. From rosuav at gmail.com Thu May 5 17:56:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 May 2011 07:56:17 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <654D9D97DA51AD479973BC2D5578603C0BEA7F4864@PDC-MAIL-CMS01.ubisoft.org> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> <654D9D97DA51AD479973BC2D5578603C0BEA7F4864@PDC-MAIL-CMS01.ubisoft.org> Message-ID: On Fri, May 6, 2011 at 2:27 AM, Andreas Tawn wrote: > If True and False: > ? ?waveFunction.collapse(cat) > > > That's going to be fun ;o) If a process crashes and init isn't there to hear it, does it produce a core dump? Chris Angelico From rosuav at gmail.com Thu May 5 18:01:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 May 2011 08:01:27 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> <92fsvjFkghU1@mid.individual.net> Message-ID: On Fri, May 6, 2011 at 1:29 AM, Roy Smith wrote: > "Hey, let's override operator,() and have some fun" Destroying sanity, for fun and profit. Chris Angelico From clp2 at rebertia.com Thu May 5 18:29:09 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 May 2011 15:29:09 -0700 Subject: access to some text string in PDFs In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 2:26 PM, Robert Pazur wrote: > Dear all, > i would like to access some text and count the?occurrence?as follows > > I got a lots of pdf with some scientific articles and i want to preview > ?which words are usually related with for example "determinants" > as an example in the article is a sentence > ....elevation is the most > important determinant.... > how can i acquire the "elevation" string? > of course i dont know where the sententence in article is located or which > particular word could there be > any suggestions? Extract the text using PDFMiner[1], pyPdf[2], or PageCatcher[3]. Then use something similar to n-grams on the extracted text, filtering out those that don't contain "determinant(s)". Then just keep a word frequency table for the remaining n-grams. Not-quite-pseudo-code: from collections import defaultdict, deque N = 7 # length of n-grams to consider; tune as needed buf = deque(maxlen=N) targets = frozenset(("determinant", "determinants")) steps_until_gone = 0 word2freq = defaultdict(int) for word in words_from_pdf: if word in targets: steps_until_gone = N buf.append(word) if steps_until_gone: for related_word in buf: if related_word not in targets: word2freq[related_word] += 1 steps_until_gone -= 1 for count, word in sorted((v,k) for k,v in word2freq.iteritems()): print(word, ':', count) Making this more efficient and less naive is left as an exercise to the reader. There may very well already be something similar but more sophisticated in NLTK[4]; I've never used it, so I dunno. [1]: http://www.unixuser.org/~euske/python/pdfminer/index.html [2]: http://pybrary.net/pyPdf/ [3]: http://www.reportlab.com/software/#pagecatcher [4]: http://www.nltk.org/ Cheers, Chris -- http://rebertia.com From drsalists at gmail.com Thu May 5 18:36:52 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 5 May 2011 15:36:52 -0700 Subject: avro slow? In-Reply-To: <98cd6085-bb77-417b-80e4-68ca990001cf@glegroupsg2000goo.googlegroups.com> References: <98cd6085-bb77-417b-80e4-68ca990001cf@glegroupsg2000goo.googlegroups.com> Message-ID: On Thu, May 5, 2011 at 2:12 PM, Miki Tebeka wrote: > Greetings, > > I'm reading some data from avro file using the avro library. It takes about > a minute to load 33K objects from the file. This seem very slow to me, > specially with the Java version reading the same file in about 1sec. > You might want to try an apache mailing list, like at http://avro.apache.org/mailing_lists.html , as I suspect most Python people use Python's native pickle support instead. It looks like the Python version of Avro is doing single-byte-at-a-time I/O for some types, which is almost guaranteed to perform poorly. If you're decoding an 8 byte integer, its much faster to at least read 8 bytes and then chop that up, and better still is to read a buffer at a time and chop that up too. Even in C, the performance of byte-at-a-time I/O is not going to be stellar, especially if you use read() rather than fread(). A related note: Python is often more about programmer efficiency than machine efficiency. With cost per MIPS going down and the price of programmer time going up, it seems a good idea. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Thu May 5 19:18:03 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 06 May 2011 01:18:03 +0200 Subject: avro slow? In-Reply-To: References: <98cd6085-bb77-417b-80e4-68ca990001cf@glegroupsg2000goo.googlegroups.com> Message-ID: Dan Stromberg, 06.05.2011 00:36: > Python is often more about programmer efficiency than > machine efficiency. With cost per MIPS going down and the price of > programmer time going up, it seems a good idea. Especially when you also count the MIPS improvement during the time it takes to write the code. Stefan From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu May 5 19:45:09 2011 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Fri, 06 May 2011 01:45:09 +0200 Subject: PIL: The _imaging C module is not installed References: Message-ID: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> Hi! > you need to install the appropriate libraries, among which are: > libjpeg-devel > freetype-devel > libpng-devel OK, but where can I find it? I want use PIL with Python under Windows, and I can't compile C's sources. Should I replace PIL by ImageMagick? @-salutations -- Michel Claveau From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu May 5 19:48:33 2011 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Fri, 06 May 2011 01:48:33 +0200 Subject: PIL: The _imaging C module is not installed References: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> Message-ID: <4dc3375a$0$14665$ba4acef3@reader.news.orange.fr> Re! And why the problem no exist with PIL 1.1.6? (only 1.1.7) Is that the version 1.1.6 does not use these libraries? @+ -- Michel Claveau From rosuav at gmail.com Thu May 5 20:51:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 May 2011 10:51:33 +1000 Subject: Py_XDECREF/Py_DECREF evaluating its argument more than once Message-ID: Okay, this is mainly a tale of a stupid C++ programmer who forgot the rules of C... I simplified a whole lot of code recently, cut out some temporary variables, did some general tidying-up, and then found that my program was segfaulting occasionally. Sure that I hadn't made any substantive changes, I went tinkering, and pinned it down to this change: Old code: PyObject *v=PyRun_StringFlags(code,Py_file_input,py_globals,locals,0); if (v) Py_DECREF(v); New code: Py_XDECREF(PyRun_StringFlags(code,Py_file_input,py_globals,locals,0)); It's the same, right? Py_XDECREF is just Py_DECREF with a check against null? No and whoops. DEC and XDEC are both implemented as *macros* and they evaluate their arguments more than once. (I'm not entirely sure of the cause of the segfault, but I'm guessing that the two runs of the code produced different results, or something. Not significant.) Would it be possible at some point to have them implemented as inline functions instead? At the top of my code, I just forced it thus: #undef Py_XDECREF inline void Py_XDECREF(PyObject *ob) {if (ob) Py_DECREF(ob);} Failing that, a warning note on the docs would be nice, but I'm guessing that idiots like me wouldn't think to read it. (Or if "idiot" is too strong, try "guy who's been spoiled by C++'s luxury".) Fortunately for my career, solving this self-created problem didn't take long, and my boss didn't even know about it till I'd solved it. *whoops* Just figured it might be worth mentioning, in case someone else is tempted to take a shortcut! Chris Angelico From rosuav at gmail.com Thu May 5 20:59:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 May 2011 10:59:59 +1000 Subject: Py_XDECREF/Py_DECREF evaluating its argument more than once In-Reply-To: References: Message-ID: Clarification: This IS stated in the source - in object.h are the following sage words: --- *** WARNING*** The Py_DECREF macro must have a side-effect-free argument since it may evaluate its argument multiple times. (The alternative would be to mace it a proper function or assign it to a global temporary variable first, both of which are slower; and in a multi-threaded environment the global variable trick is not safe.) --- (I assume that should be "make" not "mace", unless the implication is that turning a macro into a function involves pounding it into submission...) Since inline functions are a part of C99 as well as C++, would it be possible to have configure.sh detect its availability and optionally use that instead of preprocessor macros, or would this run the risk of encouraging trickily unportable code? Chris Angelico From clp2 at rebertia.com Thu May 5 21:11:23 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 May 2011 18:11:23 -0700 Subject: Py_XDECREF/Py_DECREF evaluating its argument more than once In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 5:59 PM, Chris Angelico wrote: > Since inline functions are a part of C99 as well as C++, would it be > possible to have configure.sh detect its availability and optionally > use that instead of preprocessor macros, or would this run the risk of > encouraging trickily unportable code? PEP 7 explicitly says to use C89... Cheers, Chris From 1011_wxy at 163.com Thu May 5 21:37:38 2011 From: 1011_wxy at 163.com (1011_wxy) Date: Fri, 6 May 2011 09:37:38 +0800 Subject: BeautifulSoup import error Message-ID: <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com> Dear friends: I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 . Is there any differences between Python 3.2 and other version? This is my first time to use Python3.2 . And the error message will be as below. >>> from BeautifulSoup import BeautifulSoup Traceback (most recent call last): File "", line 1, in from BeautifulSoup import BeautifulSoup File "C:\Python32\BeautifulSoup.py", line 448 raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr) ^ SyntaxError: invalid syntax And the error place point to BeautifulSoup class NavigableString(unicode, PageElement): def __new__(cls, value): """Create a new NavigableString. When unpickling a NavigableString, this method is called with the string in DEFAULT_OUTPUT_ENCODING. That encoding needs to be passed in to the superclass's __new__ or the superclass won't know how to handle non-ASCII characters. """ if isinstance(value, unicode): return unicode.__new__(cls, value) return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING) def __getnewargs__(self): return (NavigableString.__str__(self),) def __getattr__(self, attr): """text.string gives you text. This is for backwards compatibility for Navigable*String, but for CData* it lets you get the string without the CData wrapper.""" if attr == 'string': return self else: raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr) def __unicode__(self): return str(self).decode(DEFAULT_OUTPUT_ENCODING) def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING): if encoding: return self.encode(encoding) else: return self Did I make any mistake? How can I do this correctly? 2011-05-06 Kerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Thu May 5 21:46:30 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 May 2011 11:46:30 +1000 Subject: BeautifulSoup import error In-Reply-To: <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com> References: <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com> Message-ID: On Fri, May 6, 2011 at 11:37 AM, 1011_wxy <1011_wxy at 163.com> wrote: > I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 . > Is there any differences between Python 3.2 and other version? This is my > first time to use Python3.2 . > And the error message will be as below. Judging from your tracebacks, it would appear that BeuituflSoup has not yet been ported to and/or fixed for Python 3 compatibility. Maybe there's a later version of BeauitifulSOup or a development version that does support Python 3? There are several Syntax differences between Python 2.x and Python 3.x - notably: except Exception, e: # Python 2.x except Exception as e: # Python 3.x I might suggest you take a look at using lxml instead which ships with the standard library. [ ... ] cheers James -- -- James Mills -- -- "Problems are solved by method" From marduk at letterboxes.org Thu May 5 21:52:13 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 05 May 2011 21:52:13 -0400 Subject: PIL: The _imaging C module is not installed In-Reply-To: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> References: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> Message-ID: <1304646734.3212.3.camel@localhost.localdomain> On Fri, 2011-05-06 at 01:45 +0200, Michel Claveau - MVP wrote: > Hi! > > > you need to install the appropriate libraries, among which are: > > libjpeg-devel > > freetype-devel > > libpng-devel > > OK, but where can I find it? I want use PIL with Python under Windows, > and I can't compile C's sources. > Should I replace PIL by ImageMagick? The OP was about CentOS. I have no idea about Windows. From 1011_wxy at 163.com Thu May 5 22:29:15 2011 From: 1011_wxy at 163.com (1011_wxy) Date: Fri, 6 May 2011 10:29:15 +0800 Subject: =?UTF-8?Q?=E5=9B=9E=E5=A4=8D:=20=20Re:=20BeautifulSoup=20import=20error?= Message-ID: <541cf585.23105.12fc3207ff9.Coremail.1011_wxy@163.com> Dear JM: Thank you very much. BeautifulSoup does not work well with Python3.2 . 2011-05-06 Kerry ???: James Mills ????: 2011-05-06 09:47 ? ?: Re: BeautifulSoup import error ???: python list On Fri, May 6, 2011 at 11:37 AM, 1011_wxy <1011_wxy at 163.com> wrote: > I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 . > Is there any differences between Python 3.2 and other version? This is my > first time to use Python3.2 . > And the error message will be as below. Judging from your tracebacks, it would appear that BeuituflSoup has not yet been ported to and/or fixed for Python 3 compatibility. Maybe there's a later version of BeauitifulSOup or a development version that does support Python 3? There are several Syntax differences between Python 2.x and Python 3.x - notably: except Exception, e: # Python 2.x except Exception as e: # Python 3.x I might suggest you take a look at using lxml instead which ships with the standard library. [ ... ] cheers James -- -- James Mills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From miki.tebeka at gmail.com Thu May 5 23:20:56 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 5 May 2011 20:20:56 -0700 (PDT) Subject: Embedding Python's library as zip file In-Reply-To: Message-ID: <4bccd7ab-4bff-4b7c-a289-5c25ff259257@glegroupsg2000goo.googlegroups.com> I used py2exe in the past for that, see http://www.py2exe.org/index.cgi/ShippingEmbedded From miki.tebeka at gmail.com Thu May 5 23:20:56 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 5 May 2011 20:20:56 -0700 (PDT) Subject: Embedding Python's library as zip file In-Reply-To: Message-ID: <4bccd7ab-4bff-4b7c-a289-5c25ff259257@glegroupsg2000goo.googlegroups.com> I used py2exe in the past for that, see http://www.py2exe.org/index.cgi/ShippingEmbedded From jussij at zeusedit.com Fri May 6 00:39:36 2011 From: jussij at zeusedit.com (JussiJ) Date: Thu, 5 May 2011 21:39:36 -0700 (PDT) Subject: Python IDE/text-editor References: Message-ID: On Apr 16, 1:20 pm, Alec Taylor wrote: > I'm looking for an IDE which offers syntax-highlighting, > code-completion, tabs, The Zeus editor does offers all these features: http://www.zeusedit.com/ Zeus is also scriptable and Zeus scripts can be written in Python. Zeus also does Python smart indenting and code folding. > an embedded interpreter and which is portable Zeus does not have an embedded Python interpreter, but by using something like tee.exe it should be possible to emulate this: http://www.zeusedit.com/zforum/viewtopic.php?t=3156 > (for running from USB on Windows). Zeus is a Windows editor but it is not a Protable application. NOTE: Zeus is shareware. Jussi Jumppanen Author: Zeus for Windows From eaglebalti at gmail.com Fri May 6 00:55:22 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Thu, 5 May 2011 21:55:22 -0700 (PDT) Subject: Hello Friends Message-ID: Do you need legal help.If so Please visit www.chicagopersonalinjurylawyerz.blogspot.com From stefan_ml at behnel.de Fri May 6 01:57:51 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 06 May 2011 07:57:51 +0200 Subject: =?UTF-8?B?5Zue5aSNOiAgUmU6IEJlYXV0aWZ1bFNvdXAgaW1wb3J0IGVycm8=?= =?UTF-8?B?cg==?= In-Reply-To: <541cf585.23105.12fc3207ff9.Coremail.1011_wxy@163.com> References: <541cf585.23105.12fc3207ff9.Coremail.1011_wxy@163.com> Message-ID: 1011_wxy, 06.05.2011 04:29: > ???: James Mills >> On Fri, May 6, 2011 at 11:37 AM, 1011_wxy wrote: >>> I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 . >>> Is there any differences between Python 3.2 and other version? This is my >>> first time to use Python3.2 . >>> And the error message will be as below. >> >> Judging from your tracebacks, it would appear >> that BeuituflSoup has not yet been ported to >> and/or fixed for Python 3 compatibility. > > BeautifulSoup does not work well with Python3.2 . You can try to convert it using 2to3, though. > I might suggest you take a look at using lxml instead ... which works with all Python versions from 2.3 through 3.2. > which ships with the standard library. No. While this has been suggested, it will not become part of the stdlib in the foreseeable future. It's readily available as a separate package on PyPI, though. Stefan From prologic at shortcircuit.net.au Fri May 6 02:11:49 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 May 2011 16:11:49 +1000 Subject: =?UTF-8?B?UmU6IOWbnuWkjTogUmU6IEJlYXV0aWZ1bFNvdXAgaW1wb3J0IGVycm9y?= In-Reply-To: References: <541cf585.23105.12fc3207ff9.Coremail.1011_wxy@163.com> Message-ID: On Fri, May 6, 2011 at 3:57 PM, Stefan Behnel wrote: > No. While this has been suggested, it will not become part of the stdlib in > the foreseeable future. It's readily available as a separate package on > PyPI, though. Opps I meant xml.etree :/ My bad! cheers James -- -- James Mills -- -- "Problems are solved by method" From jabba.laci at gmail.com Fri May 6 02:36:26 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 6 May 2011 02:36:26 -0400 Subject: checking if a list is empty Message-ID: Hi, If I want to check if a list is empty, which is the more pythonic way? li = [] (1) if len(li) == 0: ... or (2) if not li: ... Thanks, Laszlo From nicogrubert at yahoo.de Fri May 6 02:55:32 2011 From: nicogrubert at yahoo.de (Nico Grubert) Date: Fri, 06 May 2011 08:55:32 +0200 Subject: Python-list Digest, Vol 92, Issue 40 In-Reply-To: References: Message-ID: <4DC39B64.5000708@yahoo.de> > PIL will compile and install if you don't have some development > libraries and then simply not work or not work up to full steam when > used. > > To avoid this, you need to install the appropriate libraries, among > which are: > > libjpeg-devel > freetype-devel > libpng-devel Dear Albert Thank you for your reply. I did install all these libraries. Testing it with yum shows: $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version $ yum install libjpeg-devel Package libjpeg-devel-6b-37.x86_64 already installed and latest version Package libjpeg-devel-6b-37.i386 already installed and latest version $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version Re-Compiling PIL shows: $ python setup.py build_ext -i -------------------------------------------------------------------- *** TKINTER support not available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available -------------------------------------------------------------------- However, running the selftest still fails: $ python selftest.py *** The _imaging C module is not installed Regards Nico From clp2 at rebertia.com Fri May 6 03:08:24 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 00:08:24 -0700 Subject: checking if a list is empty In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 11:36 PM, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? Option (2), IMO. > li = [] > > (1) if len(li) == 0: > ... FYI, also equivalent: if not len(li): ... > or > (2) if not li: Cheers, Chris From jabba.laci at gmail.com Fri May 6 03:18:17 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 6 May 2011 03:18:17 -0400 Subject: string formatting Message-ID: Hi, Which is the preferred way of string formatting? (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky', 'blue') As I know (1) is old style. (2) and (3) are new but (3) is only supported from Python 2.7+. Which one should be used? Laszlo From steve+comp.lang.python at pearwood.info Fri May 6 04:46:04 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 May 2011 08:46:04 GMT Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> Message-ID: <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: > Jabba Laci a ?crit ce vendredi 6 mai 2011 09:18 dans > : > >> Hi, >> >> Which is the preferred way of string formatting? >> >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {}".format('sky', 'blue') >> >> As I know (1) is old style. (2) and (3) are new but (3) is only >> supported from Python 2.7+. >> >> Which one should be used? > > According to python's documentation, (3) and (2) are preferred and (1) > is deprecated. I think you are wrong, % formatting is not deprecated. Do you have a link showing otherwise? [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 warnings >>> warnings.simplefilter("always") >>> "%d" % 42 '42' I see no DeprecationWarning. -- Steven From clp2 at rebertia.com Fri May 6 05:23:19 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 02:23:19 -0700 Subject: string formatting In-Reply-To: <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 6, 2011 at 1:46 AM, Steven D'Aprano wrote: > On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: >> Jabba Laci a ?crit ce vendredi 6 mai 2011 09:18 dans >> : >>> Hi, >>> >>> Which is the preferred way of string formatting? >>> >>> (1) "the %s is %s" % ('sky', 'blue') >>> >>> (2) "the {0} is {1}".format('sky', 'blue') >>> >>> (3) "the {} is {}".format('sky', 'blue') >>> >>> As I know (1) is old style. (2) and (3) are new but (3) is only >>> supported from Python 2.7+. >>> >>> Which one should be used? >> >> According to python's documentation, (3) and (2) are preferred and (1) >> is deprecated. > > I think you are wrong, % formatting is not deprecated. Do you have a link > showing otherwise? I'm not them, but: "Note: The formatting operations described here [involving %] are obsolete and may go away in future versions of Python. Use the new String Formatting [i.e. format()] in new code." http://docs.python.org/dev/library/stdtypes.html#old-string-formatting-operations Technically, not formally deprecated, but such a characterization isn't too far off the mark either. Cheers, Chris -- http://rebertia.com From dmitrey15 at gmail.com Fri May 6 05:24:23 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 6 May 2011 02:24:23 -0700 (PDT) Subject: seems like a bug in isinstance() Message-ID: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> hi all, suppose I've created a class Point in file .../openopt/kernel/Point.py Consider the code in file .../somewhere/file1.py from openopt.kernel.Point import Point p = Point() now let's pass p into a func from .../openopt/kernel/file2.py and check from Point import Point isinstance(p, Point) So, it returns False! p is , while Point is I have Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) D. From tartley at tartley.com Fri May 6 05:51:09 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 6 May 2011 02:51:09 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: On Apr 26, 3:39?pm, snorble wrote: > I appreciate any advice or guidance anyone has to offer. The 'Python Project HOWTO' gives good advice in terms of setting up a new project, what files and directories to create, what to put in version control, etc: http://infinitemonkeycorps.net/docs/pph/ Also, where I work we have tried many IDEs, but happily and productively use GVim and very little else, so don't feel you *have* to use an IDE. Best regards, Jonathan Hartley From clp2 at rebertia.com Fri May 6 05:57:39 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 02:57:39 -0700 Subject: seems like a bug in isinstance() In-Reply-To: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> Message-ID: On Fri, May 6, 2011 at 2:24 AM, dmitrey wrote: > hi all, > > suppose I've created a class Point in file .../openopt/kernel/Point.py > > Consider the code in file .../somewhere/file1.py > from openopt.kernel.Point import Point > p = Point() > > now let's pass p into a func from .../openopt/kernel/file2.py and > check > from Point import Point > isinstance(p, Point) > > So, it returns False! > > p is , while Point is openopt.kernel.Point.Point at 0x2048e20> > > [Subject: seems like a bug in isinstance()] This is due to a peculiarity of how (C)Python's import machinery works; isinstance() is working just fine. (And if you ever think you've found a bug in Python's built-ins, odds are you haven't. Python has been around too long, someone ought to have encountered it earlier, statistically speaking.) Note how the class is referred to as both Point.Point and openopt.kernel.Point.Point. This is because you did `from Point import ...` in file2.py, whereas in file1.py you did `from openopt.kernel.Point import ...`. These 2 different ways of referring to the same module are sufficient to "trick"/"outsmart" (C)Python and cause it to import the same module twice as 2 separate instances (i.e. it gets re-executed). Why the import machinery isn't smarter in this situation, I don't recall. The output of this should be illuminating: print(Point, type(p), type(p) is Point, id(Point), id(type(p))) As this demonstrates, you're dealing with 2 separate definitions of the same Point class. Solution: Avoid the implicitly-relative `from Point import ...` style of import; always use the absolute `from openopt.kernel.Point import ...` style instead. Subsequent imports will thus reference the already-previously-imported instance of a module rather than importing a copy of it from scratch again. Cheers, Chris -- http://rebertia.com From mail at timgolden.me.uk Fri May 6 05:59:54 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 06 May 2011 10:59:54 +0100 Subject: Development tools and practices for Pythonistas In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <4DC3C69A.3010606@timgolden.me.uk> On 06/05/2011 10:51, Jonathan Hartley wrote: > On Apr 26, 3:39 pm, snorble wrote: >> I appreciate any advice or guidance anyone has to offer. > > The 'Python Project HOWTO' gives good advice in terms of setting up a > new project, what files and directories to create, what to put in > version control, etc: > > http://infinitemonkeycorps.net/docs/pph/ I'd forgotten about that. Great resource! Thanks for reminding me... TJG From tacyt1007 at gmail.com Fri May 6 06:10:33 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Fri, 6 May 2011 12:10:33 +0200 Subject: Embedding Python's library as zip file In-Reply-To: <4bccd7ab-4bff-4b7c-a289-5c25ff259257@glegroupsg2000goo.googlegroups.com> References: <4bccd7ab-4bff-4b7c-a289-5c25ff259257@glegroupsg2000goo.googlegroups.com> Message-ID: > Are you calling Py_SetProgramName? That may help to set sys.prefix > and sys.exec_prefix. However, looking at site.py, it appears that > it's only looking for proper directories. I don't think it will be > able to add a site-packages inside a zip archive at all; you will just > have to add that yourself. Yes, I have tried Py_SetProgramName, but I am even not sure what argument (name, path?) should be passed to it and how it will affect the application. Some good news. After simplifying my application I realized, that importing of modules from the zip archive works well, I only have to add site-packages to sys.path (it looks like "python27.zip/site-packages"). Unfortunately even though I can import Image package, something still causes applications' sudden death. I will try to figure out what is the reason of that. As I said, the only non-standard package I am using is PIL. From lists at cheimes.de Fri May 6 06:16:03 2011 From: lists at cheimes.de (Christian Heimes) Date: Fri, 06 May 2011 12:16:03 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: <4dc3375a$0$14665$ba4acef3@reader.news.orange.fr> References: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> <4dc3375a$0$14665$ba4acef3@reader.news.orange.fr> Message-ID: Am 06.05.2011 01:48, schrieb Michel Claveau - MVP: > Re! > > And why the problem no exist with PIL 1.1.6? (only 1.1.7) > Is that the version 1.1.6 does not use these libraries? PIL 1.1.6 also uses its internal C library to speed things up. For Windows you should use the precompiled packages. http://www.pythonware.com/products/pil/ offers X86 Windows binaries for 1.1.7. You might run into a problem with 1.1.7 Windows binaries. The freetype C library references a debug CRT that is not available on all machines. You can easily patch the _imagingft.pyd file with a hex editor. Christian From dmitrey15 at gmail.com Fri May 6 06:20:58 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 6 May 2011 03:20:58 -0700 (PDT) Subject: seems like a bug in isinstance() References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> Message-ID: <8a61409d-7b30-4644-96dd-9bc750906e31@cu4g2000vbb.googlegroups.com> On May 6, 12:57?pm, Chris Rebert wrote: > On Fri, May 6, 2011 at 2:24 AM, dmitrey wrote: > > hi all, > > > suppose I've created a class Point in file .../openopt/kernel/Point.py > > > Consider the code in file .../somewhere/file1.py > > from openopt.kernel.Point import Point > > p = Point() > > > now let's pass p into a func from .../openopt/kernel/file2.py and > > check > > from Point import Point > > isinstance(p, Point) > > > So, it returns False! > > > p is , while Point is > openopt.kernel.Point.Point at 0x2048e20> > > > [Subject: seems like a bug in isinstance()] > > This is due to a peculiarity of how (C)Python's import machinery > works; isinstance() is working just fine. > (And if you ever think you've found a bug in Python's built-ins, odds > are you haven't. Python has been around too long, someone ought to > have encountered it earlier, statistically speaking.) > > Note how the class is referred to as both Point.Point and > openopt.kernel.Point.Point. This is because you did `from Point import > ...` in file2.py, whereas in file1.py you did `from > openopt.kernel.Point import ...`. These 2 different ways of referring > to the same module are sufficient to "trick"/"outsmart" (C)Python and > cause it to import the same module twice as 2 separate instances (i.e. > it gets re-executed). Why the import machinery isn't smarter in this > situation, I don't recall. > > The output of this should be illuminating: > print(Point, type(p), type(p) is Point, id(Point), id(type(p))) > As this demonstrates, you're dealing with 2 separate definitions of > the same Point class. > > Solution: Avoid the implicitly-relative `from Point import ...` style > of import; always use the absolute `from openopt.kernel.Point import > ...` style instead. Subsequent imports will thus reference the > already-previously-imported instance of a module rather than importing > a copy of it from scratch again. > > Cheers, > Chris > --http://rebertia.com Thanks Cris, however, I had understood reason of the bug and mere informed Python developers of the bug to fix it. >>> print(Point, type(p), type(p) is Point, id(Point), id(type(p))) (, , False, 44211536, 8585344) The proposed solution of using `from openopt.kernel.Point import ... ' everywhere is already performed but is not nice for me. I have lots of places like that in my code; also, when I import something from openopt it performs recursive import of many files including that one where Point is defined, thus I have cycled imports (well, it somehow works, but is unstable and may lead to future bugs). Also, writing "from Point import Point" is much simpler than using each time the long string "from name1.name2.Point import Point". I think it's Python developers who have to fix the issue, not users. I have 5 years of intensive Python experience yet it took same time to me to locate the bug, because my algorithm got "False" from isinstance() and went absolutely different thread from "if isinstance(): ... else: ...". This bug could be encountered very seldom under rare circumstances and thus be quite difficult to be located, especially for Python newbies unawared of this one. Regards, D. From chardster at gmail.com Fri May 6 06:34:40 2011 From: chardster at gmail.com (Richard Thomas) Date: Fri, 6 May 2011 03:34:40 -0700 (PDT) Subject: checking if a list is empty References: Message-ID: <39d4afc7-633f-4a44-a2f7-d4e442fafb38@k25g2000yqf.googlegroups.com> On May 6, 7:36?am, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: > ... > > Thanks, > > Laszlo I prefer (1), it feels more explicit about what I'm testing. The fact that empty sequences evaluate as false feels like a bit of a quirk to me. Actually the fact that 0 evaluates as false feels like a bit of a quirk to me, I more of a "use booleans in boolean contexts" kind of programmer. From lutfioduncuoglu at gmail.com Fri May 6 06:47:12 2011 From: lutfioduncuoglu at gmail.com (Lutfi Oduncuoglu) Date: Fri, 6 May 2011 13:47:12 +0300 Subject: if statement multiple or Message-ID: Hi, I am trying to write a script and I realised that I need to use something like if ('a' or 'b' or 'c') not in line: print line But it does not work for. What may be the problem Thanks, Lutfi -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Fri May 6 07:00:24 2011 From: lists at cheimes.de (Christian Heimes) Date: Fri, 06 May 2011 13:00:24 +0200 Subject: if statement multiple or In-Reply-To: References: Message-ID: Am 06.05.2011 12:47, schrieb Lutfi Oduncuoglu: > Hi, > > I am trying to write a script and I realised that I need to use something > like > > if ('a' or 'b' or 'c') not in line: > print line > > But it does not work for. What may be the problem if any(s not in line for s in ('a', 'b', 'c')): # do something Christian From marduk at letterboxes.org Fri May 6 07:02:30 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 06 May 2011 07:02:30 -0400 Subject: if statement multiple or In-Reply-To: References: Message-ID: <1304679750.355863.0.camel@localhost.localdomain> On Fri, 2011-05-06 at 13:47 +0300, Lutfi Oduncuoglu wrote: > Hi, > > I am trying to write a script and I realised that I need to use > something like > > if ('a' or 'b' or 'c') not in line: > print line > The expression: ('a' or 'b' or 'c') evaluates to True True not in line Is probably not what you intended. From marduk at letterboxes.org Fri May 6 07:04:18 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 06 May 2011 07:04:18 -0400 Subject: if statement multiple or In-Reply-To: References: Message-ID: <1304679858.355863.1.camel@localhost.localdomain> Correction: ('a' or 'b' or 'c') evaluates to 'a' From clp2 at rebertia.com Fri May 6 07:08:33 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 04:08:33 -0700 Subject: if statement multiple or In-Reply-To: <1304679750.355863.0.camel@localhost.localdomain> References: <1304679750.355863.0.camel@localhost.localdomain> Message-ID: On Fri, May 6, 2011 at 4:02 AM, Albert Hopkins wrote: > On Fri, 2011-05-06 at 13:47 +0300, Lutfi Oduncuoglu wrote: >> Hi, >> >> I am trying to write a script and I realised that I need to use >> something like >> >> if ('a' or 'b' or 'c') ?not in line: >> ? ?print line >> > > The expression: > ? ?('a' or 'b' or 'c') > > evaluates to True Not quite: $ python Python 2.6.6 (r266:84292, Jan 12 2011, 13:35:00) >>> 'a' or 'b' or 'c' 'a' >>> Cheers, Chris From prologic at shortcircuit.net.au Fri May 6 07:34:27 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 May 2011 21:34:27 +1000 Subject: checking if a list is empty In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 4:36 PM, Jabba Laci wrote: > If I want to check if a list is empty, which is the more pythonic way? [...] > (2) if not li: This is fine. cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Fri May 6 07:36:22 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 May 2011 21:36:22 +1000 Subject: if statement multiple or In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 8:47 PM, Lutfi Oduncuoglu wrote: > I am trying to write a script and I realised that I need to use something > like > > if ('a' or 'b' or 'c')? not in line: > ?? print line > > But it does not work for. What may be the problem You will need to (naively) do this: if "a" not in line or "b" not in line or "c" not in line: print line cheers James -- -- James Mills -- -- "Problems are solved by method" From rustompmody at gmail.com Fri May 6 07:55:12 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 6 May 2011 04:55:12 -0700 (PDT) Subject: Python packaging (was Development tools and practices for Pythonistas) References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: On May 6, 2:59?pm, Tim Golden wrote: > On 06/05/2011 10:51, Jonathan Hartley wrote: > > > On Apr 26, 3:39 pm, snorble ?wrote: > >> I appreciate any advice or guidance anyone has to offer. > > > The 'Python Project HOWTO' gives good advice in terms of setting up a > > new project, what files and directories to create, what to put in > > version control, etc: > > >http://infinitemonkeycorps.net/docs/pph/ > > I'd forgotten about that. Great resource! Thanks for reminding me... > > TJG Thanks for that link. There is one question in this regard that is not covered: package-use Of course this http://infinitemonkeycorps.net/docs/pph/#id10 is there. But I am talking of setting up one's python environment. For example on a linux box how to best optimize using the native package manager (eg apt/rpm) along with packages from pypi. And when one needs to run with multiple pythons how to use virtualenv etc From tooscattered at gmail.com Fri May 6 08:09:49 2011 From: tooscattered at gmail.com (scattered) Date: Fri, 6 May 2011 05:09:49 -0700 (PDT) Subject: if statement multiple or References: Message-ID: <9e36f9bc-0009-4924-9b36-62438bd52399@k22g2000yqh.googlegroups.com> On May 6, 7:00?am, Christian Heimes wrote: > Am 06.05.2011 12:47, schrieb Lutfi Oduncuoglu: > > > Hi, > > > I am trying to write a script and I realised that I need to use something > > like > > > if ('a' or 'b' or 'c') ?not in line: > > ? ?print line > > > But it does not work for. What may be the problem > > if any(s not in line for s in ('a', 'b', 'c')): > ? ?# do something > > Christian sets could also work if set('abc') & set(line) == set(): print line From lists at cheimes.de Fri May 6 08:25:27 2011 From: lists at cheimes.de (Christian Heimes) Date: Fri, 06 May 2011 14:25:27 +0200 Subject: if statement multiple or In-Reply-To: <9e36f9bc-0009-4924-9b36-62438bd52399@k22g2000yqh.googlegroups.com> References: <9e36f9bc-0009-4924-9b36-62438bd52399@k22g2000yqh.googlegroups.com> Message-ID: Am 06.05.2011 14:09, schrieb scattered: > sets could also work > > if set('abc') & set(line) == set(): > print line Right! Sets work in this special case, because the OP just wants to search for a single char. It won't work for longer strings, though. Also I would write the test as: if set(line).isdisjoint("abc"): print line Christian From nirina.raseliarison at gmail.com Fri May 6 08:27:41 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Fri, 06 May 2011 15:27:41 +0300 Subject: BeautifulSoup import error In-Reply-To: <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com> References: <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com> Message-ID: [1011_wxy] > I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 the error i see is a SyntaxError. > Is there any differences between Python 3.2 and other version? yes. and there is a tool, 2to3, which converts Python 2.x scripts to work with 3.x. > And the error message will be as below. > > >>>> from BeautifulSoup import BeautifulSoup > Traceback (most recent call last): > File "", line 1, in > from BeautifulSoup import BeautifulSoup > File "C:\Python32\BeautifulSoup.py", line 448 > raise AttributeError, "'%s' object has no attribute '%s'" % > (self.__class__.__name__, attr) > ^ > SyntaxError: invalid syntax a quick fix here, change: raise AttributeError, "'%s' object has no attribute '%s'" %(self.__class__.__name__, attr) to: raise AttributeError("'%s' object has no attribute '%s'" %(self.__class__.__name__, attr)) enclose the string message with parentheses. at least, you will not get the SyntaxError. but a better solution is to use 2to3. i don't use BeautifulSoup, and i'm still stick with Python2.5.4 on windows, so can't help much. with Linux, it is just: 2to3 a_python_file_or_a_dir_package on windows, i don't know, maybe: import subprocess subprocess.Popen(('python.exe', 'Tools/Scripts/2to3.py', 'the_package')) -- nirinA From tacyt1007 at gmail.com Fri May 6 08:52:52 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Fri, 6 May 2011 14:52:52 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: References: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> <4dc3375a$0$14665$ba4acef3@reader.news.orange.fr> Message-ID: @Michel use PIL downloaded from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/ regards 2011/5/6 Christian Heimes : > Am 06.05.2011 01:48, schrieb Michel Claveau - MVP: >> Re! >> >> And why the problem no exist with PIL 1.1.6? ?(only 1.1.7) >> Is that the version 1.1.6 does not use these libraries? > > PIL 1.1.6 also uses its internal C library to speed things up. > > For Windows you should use the precompiled packages. > http://www.pythonware.com/products/pil/ offers X86 Windows binaries for > 1.1.7. You might run into a problem with 1.1.7 Windows binaries. The > freetype C library references a debug CRT that is not available on all > machines. You can easily patch the _imagingft.pyd file with a hex editor. > > Christian > > -- > http://mail.python.org/mailman/listinfo/python-list > From pruebauno at latinmail.com Fri May 6 09:06:46 2011 From: pruebauno at latinmail.com (nn) Date: Fri, 6 May 2011 06:06:46 -0700 (PDT) Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc3e52a$0$24510$426a74cc@news.free.fr> Message-ID: On May 6, 8:10?am, Web Dreamer wrote: > Chris Rebert a ?crit ce vendredi 6 mai 2011 11:23 dans > : > > > > > I'm not them, but: > > "Note: The formatting operations described here [involving %] are > > obsolete and may go away in future versions of Python. Use the new > > String Formatting [i.e. format()] in new code." > >http://docs.python.org/dev/library/stdtypes.html#old-string-formatting- > operations > > > Technically, not formally deprecated, but such a characterization > > isn't too far off the mark either. > > Thanks Chris for the link. > > Indeed, They mention: > > "The formatting operations described here are obsolete and may go away in > future versions of Python. Use the new String Formatting in new code." > > So the proper word is "obsolete" and in my mind I remembered "deprecated" > since they say it could be removed from future versions of python. > > So I should have said "obsolete". > > What I would like to know is the difference between "deprecated" and > "obsolete"... > > -- > Web Dreamer In this context I think obsolete means: Will be removed in some undetermined version in the future; 3 versions or more from now. There is also pending deprecation: Will be (usually) removed in the version after the next. And deprecated: Will be removed in the next version. From neilc at norwich.edu Fri May 6 09:10:27 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 6 May 2011 13:10:27 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> <92fsvjFkghU1@mid.individual.net> Message-ID: <92iaa2FdjoU4@mid.individual.net> On 2011-05-05, Chris Angelico wrote: > On Fri, May 6, 2011 at 1:29 AM, Roy Smith wrote: >> "Hey, let's override operator,() and have some fun" > > Destroying sanity, for fun and profit. I was thinking more along the lines of stuff like combining the envelope pattern (an interface class containing a pointer to an implementation) with template classes to create type-safe polymorphic types with specializable, decoupled implementations. A Python programmer just feels depressed that anyone could have a need for such innovations, though. ;) -- Neil Cerutti From pazurrobert at gmail.com Fri May 6 09:12:35 2011 From: pazurrobert at gmail.com (Robert Pazur) Date: Fri, 6 May 2011 15:12:35 +0200 Subject: access to some text string in PDFs In-Reply-To: References: Message-ID: Hi Chris, thanks for fast reply and all recommendations in helps me much! as you recommended me i used Pdfminer module to extract the text from pdf files and then with file.xreadlines() I allocated the lines where my keyword ("factors in this case") appears. Till now i extract just the lines but im wondering if its able to extract whole sentenses (only this) where my keawords ("factors in this case") are located. I used following script >> import os, subprocess path="C:\\PDF" # insert the path to the directory of interest here dirList=os.listdir(path) for fname in dirList: output =fname.rstrip(".pdf") + ".txt" subprocess.call(["C:\Python26\python.exe", "pdf2txt.py", "-o", output, fname]) print fname file = open(output) for line in file.xreadlines(): if "driving" in line: print(line) ------------------------------------------------------- Robert Pazur Mobile : +421 948 001 705 Skype : ruegdeg 2011/5/6 Chris Rebert > On Thu, May 5, 2011 at 2:26 PM, Robert Pazur > wrote: > > Dear all, > > i would like to access some text and count the occurrence as follows > > > I got a lots of pdf with some scientific articles and i want to preview > > which words are usually related with for example "determinants" > > as an example in the article is a sentence > ....elevation is the most > > important determinant.... > > how can i acquire the "elevation" string? > > of course i dont know where the sententence in article is located or > which > > particular word could there be > > any suggestions? > > Extract the text using PDFMiner[1], pyPdf[2], or PageCatcher[3]. Then > use something similar to n-grams on the extracted text, filtering out > those that don't contain "determinant(s)". Then just keep a word > frequency table for the remaining n-grams. > > Not-quite-pseudo-code: > from collections import defaultdict, deque > N = 7 # length of n-grams to consider; tune as needed > buf = deque(maxlen=N) > targets = frozenset(("determinant", "determinants")) > steps_until_gone = 0 > word2freq = defaultdict(int) > for word in words_from_pdf: > if word in targets: > steps_until_gone = N > buf.append(word) > if steps_until_gone: > for related_word in buf: > if related_word not in targets: > word2freq[related_word] += 1 > steps_until_gone -= 1 > for count, word in sorted((v,k) for k,v in word2freq.iteritems()): > print(word, ':', count) > > Making this more efficient and less naive is left as an exercise to the > reader. > There may very well already be something similar but more > sophisticated in NLTK[4]; I've never used it, so I dunno. > > [1]: http://www.unixuser.org/~euske/python/pdfminer/index.html > [2]: http://pybrary.net/pyPdf/ > [3]: http://www.reportlab.com/software/#pagecatcher > [4]: http://www.nltk.org/ > > Cheers, > Chris > -- > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tooscattered at gmail.com Fri May 6 09:17:26 2011 From: tooscattered at gmail.com (scattered) Date: Fri, 6 May 2011 06:17:26 -0700 (PDT) Subject: if statement multiple or References: <9e36f9bc-0009-4924-9b36-62438bd52399@k22g2000yqh.googlegroups.com> Message-ID: <67941d2c-ad97-4395-80b9-59e8c941df99@w21g2000yqm.googlegroups.com> On May 6, 8:25?am, Christian Heimes wrote: > Am 06.05.2011 14:09, schrieb scattered: > > > sets could also work > > > if set('abc') & set(line) == set(): > > ? ? ?print line > > Right! > Sets work in this special case, because the OP just wants to search for > a single char. It won't work for longer strings, though. > > Also I would write the test as: > > if set(line).isdisjoint("abc"): > ? ? print line > > Christian Thanks for the tip - I'm still learning Python and was unaware of the isdisjoint method. From tacyt1007 at gmail.com Fri May 6 09:23:48 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Fri, 6 May 2011 15:23:48 +0200 Subject: Embedding Python's library as zip file In-Reply-To: References: <4bccd7ab-4bff-4b7c-a289-5c25ff259257@glegroupsg2000goo.googlegroups.com> Message-ID: > I used py2exe in the past for that, see http://www.py2exe.org/index.cgi/ShippingEmbedded Thanks for the advice, py2exe seems to be a great tool. Unfortunately the application stops executing at the same place. It might be the case of PIL library, I found some entries about it on py2exe site. From mail at timgolden.me.uk Fri May 6 09:31:41 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 06 May 2011 14:31:41 +0100 Subject: if statement multiple or In-Reply-To: <67941d2c-ad97-4395-80b9-59e8c941df99@w21g2000yqm.googlegroups.com> References: <9e36f9bc-0009-4924-9b36-62438bd52399@k22g2000yqh.googlegroups.com> <67941d2c-ad97-4395-80b9-59e8c941df99@w21g2000yqm.googlegroups.com> Message-ID: <4DC3F83D.7040407@timgolden.me.uk> On 06/05/2011 14:17, scattered wrote: > On May 6, 8:25 am, Christian Heimes wrote: >> Am 06.05.2011 14:09, schrieb scattered: >> >>> sets could also work >> >>> if set('abc')& set(line) == set(): >>> print line >> >> Right! >> Sets work in this special case, because the OP just wants to search for >> a single char. It won't work for longer strings, though. >> >> Also I would write the test as: >> >> if set(line).isdisjoint("abc"): >> print line >> >> Christian > > Thanks for the tip - I'm still learning Python and was unaware of the > isdisjoint method. If it's any consolation, I've been using Python for 10 years and I was unaware of the isdisjoint method. :) TJG From nicogrubert at yahoo.de Fri May 6 09:56:32 2011 From: nicogrubert at yahoo.de (Nico Grubert) Date: Fri, 06 May 2011 15:56:32 +0200 Subject: PIL: The _imaging C module is not installed Message-ID: <4DC3FE10.2060001@yahoo.de> > PIL will compile and install if you don't have some development > libraries and then simply not work or not work up to full steam when > used. > > To avoid this, you need to install the appropriate libraries, among > which are: > > libjpeg-devel > freetype-devel > libpng-devel Dear Albert Thank you for your reply. I did install all these libraries. Testing it with yum shows: $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version $ yum install libjpeg-devel Package libjpeg-devel-6b-37.x86_64 already installed and latest version Package libjpeg-devel-6b-37.i386 already installed and latest version $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version Re-Compiling PIL shows: $ python setup.py build_ext -i -------------------------------------------------------------------- *** TKINTER support not available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available -------------------------------------------------------------------- However, running the selftest still fails: $ python selftest.py *** The _imaging C module is not installed Regards Nico From steve+comp.lang.python at pearwood.info Fri May 6 10:24:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 May 2011 14:24:56 GMT Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 02:23:19 -0700, Chris Rebert wrote: > On Fri, May 6, 2011 at 1:46 AM, Steven D'Aprano > wrote: >> On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: >>> Jabba Laci a ?crit ce vendredi 6 mai 2011 09:18 dans >>> : >>>> Hi, >>>> >>>> Which is the preferred way of string formatting? >>>> >>>> (1) "the %s is %s" % ('sky', 'blue') >>>> >>>> (2) "the {0} is {1}".format('sky', 'blue') >>>> >>>> (3) "the {} is {}".format('sky', 'blue') >>>> >>>> As I know (1) is old style. (2) and (3) are new but (3) is only >>>> supported from Python 2.7+. >>>> >>>> Which one should be used? >>> >>> According to python's documentation, (3) and (2) are preferred and (1) >>> is deprecated. >> >> I think you are wrong, % formatting is not deprecated. Do you have a >> link showing otherwise? > > I'm not them, but: > "Note: The formatting operations described here [involving %] are > obsolete and may go away in future versions of Python. Use the new > String Formatting [i.e. format()] in new code." > http://docs.python.org/dev/library/stdtypes.html#old-string-formatting- operations > > Technically, not formally deprecated, but such a characterization isn't > too far off the mark either. Not deprecated at all. In context, deprecation *is* a formal process. In any case, on occasions that the issue has been raised, there has been considerable community objection to removal of % formatting. Guido might want to remove it, but I wouldn't bet on it happening before Python 4000. It's perfectly safe to continue using % formatting, if you choose. -- Steven From za_yaniddd at abv.bg Fri May 6 10:29:55 2011 From: za_yaniddd at abv.bg (za_yaniddd at abv.bg) Date: Fri, 6 May 2011 07:29:55 -0700 (PDT) Subject: $$$ GET FREE 1000 DOLLARS $$$ Message-ID: $$$ GET FREE 1000 DOLLARS $$$ GET FREE $ 1000 for first poker deposit in BET 365 !!! GET FREE $ 200 for first sports deposit in BET365 !!! GET FREE $ 200 for first casino deposit in BET 365 !!! http://sportbet365casino.blogspot.com/ From steve+comp.lang.python at pearwood.info Fri May 6 10:33:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 May 2011 14:33:01 GMT Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc3e52a$0$24510$426a74cc@news.free.fr> Message-ID: <4dc4069d$0$29992$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 14:10:17 +0200, Web Dreamer wrote: > What I would like to know is the difference between "deprecated" and > "obsolete"... Writing x*x instead of x**2 is obsolete, but it will never go away. Writing apply(func, args) instead of func(*args) is deprecated. It has gone away. Obsolete is a value judgment you are welcome to ignore. Deprecation is a formal process that warns you that your code *will* break in the future. -- Steven From info at wingware.com Fri May 6 10:54:35 2011 From: info at wingware.com (Wingware) Date: Fri, 06 May 2011 10:54:35 -0400 Subject: Wing IDE 4.0.2 Released Message-ID: <4DC40BAB.2080206@wingware.com> Hi, Wingware has released version 4.0.2 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.2** * Added introduce variable refactoring operation * Support for using *.pi files to augment source analysis of *.py files * Support autocompletion for PySide Qt bindings * Recognize tags and attributes for HTML5 * Avoid problems with Ubuntu Unity * Fixed matplotlib support for GtkAgg backend and missing default backend * Syntax highlight comments in Django template files * Fixed syntax highlighting for Cython, VHDL, R, and several others * Fixed failure to replace all search matches near the end of a file * About 40 other bug fixes and minor improvements See the change log for details. **New Features in Version 4.0** Version 4.0 adds the following new major features: * Refactoring -- Rename/move, extract to function/method, and introduce variable * 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.2/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 alec.taylor6 at gmail.com Fri May 6 10:55:31 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 7 May 2011 00:55:31 +1000 Subject: Python IDE/text-editor In-Reply-To: References: Message-ID: No thanks, it's shareware, doesn't included embedded python interpreter out-of-the-box, and isn't portable. On Fri, May 6, 2011 at 2:39 PM, JussiJ wrote: > On Apr 16, 1:20 pm, Alec Taylor wrote: > >> I'm looking for an IDE which offers syntax-highlighting, >> code-completion, tabs, > > The Zeus editor does offers all these features: > > ? ?http://www.zeusedit.com/ > > Zeus is also scriptable and Zeus scripts can be written in Python. > > Zeus also does Python smart indenting and code folding. > >> an embedded interpreter and which is portable > > Zeus does not have an embedded Python interpreter, but by using > something like tee.exe it should be possible to emulate this: > > ? ?http://www.zeusedit.com/zforum/viewtopic.php?t=3156 > >> (for running from USB on Windows). > > Zeus is a Windows editor but it is not a Protable application. > > NOTE: Zeus is shareware. > > Jussi Jumppanen > Author: Zeus for Windows > -- > http://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Fri May 6 10:58:19 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 May 2011 15:58:19 +0100 Subject: string formatting In-Reply-To: References: Message-ID: <4DC40C8B.5090901@mrabarnett.plus.com> On 06/05/2011 08:18, Jabba Laci wrote: > Hi, > > Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old style. (2) and (3) are new but (3) is only > supported from Python 2.7+. > > Which one should be used? > I use Python 3, and I tend to use (3), unless I need to use the same value more than once. From awilliam at whitemice.org Fri May 6 11:06:13 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 06 May 2011 11:06:13 -0400 Subject: string formatting In-Reply-To: <4DC40C8B.5090901@mrabarnett.plus.com> References: <4DC40C8B.5090901@mrabarnett.plus.com> Message-ID: <1304694373.8740.13.camel@linux-yu4c.site> On Fri, 2011-05-06 at 15:58 +0100, MRAB wrote: > On 06/05/2011 08:18, Jabba Laci wrote: > > Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old style. (2) and (3) are new but (3) is only > > supported from Python 2.7+. > > Which one should be used? > I use Python 3, and I tend to use (3), unless I need to use the same > value more than once. I like: 'my name is {name}'.format(name='Adam') That makes things clearest, IMO. From python at mrabarnett.plus.com Fri May 6 11:29:01 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 May 2011 16:29:01 +0100 Subject: string formatting In-Reply-To: <1304694373.8740.13.camel@linux-yu4c.site> References: <4DC40C8B.5090901@mrabarnett.plus.com> <1304694373.8740.13.camel@linux-yu4c.site> Message-ID: <4DC413BD.7060701@mrabarnett.plus.com> On 06/05/2011 16:06, Adam Tauno Williams wrote: > On Fri, 2011-05-06 at 15:58 +0100, MRAB wrote: >> On 06/05/2011 08:18, Jabba Laci wrote: >>> Which is the preferred way of string formatting? >>> (1) "the %s is %s" % ('sky', 'blue') >>> (2) "the {0} is {1}".format('sky', 'blue') >>> (3) "the {} is {}".format('sky', 'blue') >>> As I know (1) is old style. (2) and (3) are new but (3) is only >>> supported from Python 2.7+. >>> Which one should be used? >> I use Python 3, and I tend to use (3), unless I need to use the same >> value more than once. > > I like: > > 'my name is {name}'.format(name='Adam') > > That makes things clearest, IMO. > I wouldn't do that for a short piece of text, but for a much longer piece of text with multiple values, it does make it a lot clearer. From gandalf at shopzeus.com Fri May 6 12:21:07 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 06 May 2011 18:21:07 +0200 Subject: dictionary size changed during iteration In-Reply-To: References: <4DAED72B.2030400@shopzeus.com> Message-ID: <4DC41FF3.3090601@shopzeus.com> >> ... > That works, but if d is large, it won't be very efficient because it has > to generate a large list. It is not large. But I'm using Python 2.6 , not Python 3. I did not get this error again in the last two days. I'll post a new reply if I encounter it again. (It happened just a few times out of many thousand program invocations) From steve+comp.lang.python at pearwood.info Fri May 6 12:59:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 May 2011 16:59:30 GMT Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 May 2011 10:33:31 -0700, Raymond Hettinger wrote: > I think it is time to give some visibility to some of the instructive > and very cool recipes in ActiveState's python cookbook. [...] > What are your favorites? I'm not sure if favourite is the right word, but I'm amazed by this one: McCarthy's "amb" (ambiguous) operator. http://code.activestate.com/recipes/577368 Here's how I might use it to solve the problem if making change. In Australian currency, I have 5, 10, 20, 50 cent and $1 and $2 coins. Ignoring the dollar coins, how can I make up change for any multiple of five cents up to a dollar? Suppose I have more 5 cent coins that I can deal with, and I want to make sure I hand out at least three of them. Here's how to make 45 cents worth of change: >>> amb = Amb() >>> a = amb(range(3, 21)) # number of 5 cent coins >>> b = amb(range(11)) # number of 10 cent coins >>> c = amb(range(6)) # number of 20 cent coins >>> d = amb(range(3)) # number of 50 cent coins >>> for _ in amb(lambda a,b,c,d: 5*a+10*b+20*c+50*d == 45): ... print a, b, c, d ... 3 1 1 0 3 3 0 0 5 0 1 0 5 2 0 0 7 1 0 0 9 0 0 0 Suppose I have some words, and want to put them together so that there are a certain number of vowels: >>> amb = Amb() >>> a = amb(['quick', 'slow', 'hungry', 'wise-old']) >>> b = amb(['fox', 'hare', 'turtle', 'kangaroo']) >>> c = amb(['lazy', 'stupid', 'sleepy', 'confused']) >>> d = amb(['dog', 'aardvark', 'sloth', 'wombat']) >>> >>> def test(a, b, c, d): ... s = "The %s brown %s jumped over the %s %s." % (a, b, c, d) ... num_vowels = sum(s.count(c) for c in 'aeiou') ... return num_vowels in (12, 18, 19) ... >>> for _ in amb(test): ... print a, b, c, d ... quick fox lazy sloth quick fox lazy dog quick kangaroo stupid aardvark [...more solutions cut for brevity] hungry kangaroo confused aardvark As written, amb is just a brute-force solver using more magic than is good for any code, but it's fun to play with. -- Steven From ian.g.kelly at gmail.com Fri May 6 13:27:18 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 11:27:18 -0600 Subject: seems like a bug in isinstance() In-Reply-To: <8a61409d-7b30-4644-96dd-9bc750906e31@cu4g2000vbb.googlegroups.com> References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> <8a61409d-7b30-4644-96dd-9bc750906e31@cu4g2000vbb.googlegroups.com> Message-ID: On Fri, May 6, 2011 at 4:20 AM, dmitrey wrote: > Thanks Cris, however, I had understood reason of the bug and mere > informed Python developers of the bug to fix it. No you haven't. Few if any Python developers make a habit of reading this newsgroup. To actually report the issue so that it might get fixed, you need to add it to the issue tracker at http://bugs.python.org Anyway, I played around with this a little and was unable to reproduce it, so I suspect the issue is actually a bit more complicated than what Chris is describing. From debatem1 at gmail.com Fri May 6 13:43:06 2011 From: debatem1 at gmail.com (geremy condra) Date: Fri, 6 May 2011 10:43:06 -0700 Subject: Coolest Python recipe of all time In-Reply-To: <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 6, 2011 at 9:59 AM, Steven D'Aprano wrote: > On Mon, 02 May 2011 10:33:31 -0700, Raymond Hettinger wrote: > >> I think it is time to give some visibility to some of the instructive >> and very cool recipes in ActiveState's python cookbook. > [...] >> What are your favorites? > > > I'm not sure if favourite is the right word, but I'm amazed by this one: > McCarthy's "amb" (ambiguous) operator. > > http://code.activestate.com/recipes/577368 > > Here's how I might use it to solve the problem if making change. In > Australian currency, I have 5, 10, 20, 50 cent and $1 and $2 coins. > Ignoring the dollar coins, how can I make up change for any multiple of > five cents up to a dollar? > > Suppose I have more 5 cent coins that I can deal with, and I want to make > sure I hand out at least three of them. Here's how to make 45 cents worth > of change: > >>>> amb = Amb() >>>> a = amb(range(3, 21)) ?# number of 5 cent coins >>>> b = amb(range(11)) ?# number of 10 cent coins >>>> c = amb(range(6)) ?# number of 20 cent coins >>>> d = amb(range(3)) ?# number of 50 cent coins >>>> for _ in amb(lambda a,b,c,d: 5*a+10*b+20*c+50*d == 45): > ... ? ? print a, b, c, d > ... > 3 1 1 0 > 3 3 0 0 > 5 0 1 0 > 5 2 0 0 > 7 1 0 0 > 9 0 0 0 > > > Suppose I have some words, and want to put them together so that there > are a certain number of vowels: > >>>> amb = Amb() >>>> a = amb(['quick', 'slow', 'hungry', 'wise-old']) >>>> b = amb(['fox', 'hare', 'turtle', 'kangaroo']) >>>> c = amb(['lazy', 'stupid', 'sleepy', 'confused']) >>>> d = amb(['dog', 'aardvark', 'sloth', 'wombat']) >>>> >>>> def test(a, b, c, d): > ... ? ? s = "The %s brown %s jumped over the %s %s." % (a, b, c, d) > ... ? ? num_vowels = sum(s.count(c) for c in 'aeiou') > ... ? ? return num_vowels in (12, 18, 19) > ... >>>> for _ in amb(test): > ... ? ? print a, b, c, d > ... > quick fox lazy sloth > quick fox lazy dog > quick kangaroo stupid aardvark > [...more solutions cut for brevity] > hungry kangaroo confused aardvark > > > > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. I use a similar technique *a lot* for various kinds of constraint solvers, but I have yet to come up with a really satisfying spelling for it. Have you looked at the way this is done in Sage? Geremy Condra From Dick.Bridges at wdc.com Fri May 6 13:43:08 2011 From: Dick.Bridges at wdc.com (Dick Bridges) Date: Fri, 6 May 2011 10:43:08 -0700 Subject: setuptools for 64-bit 2.7.1 on 64-bit Windows 7? Message-ID: Hi all, Can someone provide some search terms I can use to find guidelines for installing modules for my 'stock' 64-bit r 271:86832, Nov 27, 2010 [MSC v.1500 64 bit (AMD)] on Win32. Host is 64-bit Windows 7. My goal is to install suds. Period. That's all. So far I've spent the better part of two days trying to figure out how to make python setup.py install actually work. Current error involves "...no module named setuptools" and, of course all I can find is the 32-bit setuptools-0.6c11.win32-py2.7.exe which fails with "Python version 2.7 required, which was not found in the registry." There's nothing new here - all of this has appeared in various forums over the last few years - but none I have found contains an actual answer. Simple question: Is it true that no setuptools (or any other module installer) exists for 64-bit python 2.7.1? If there is an installer that works, what terms might I use to Google for information on how to acquire and install it? Regards, Dick Bridges (\(\ Western Digital ?". .. ( . .) The opinions and data in this missive are my own and do not necessarily | ? ? represent Western Digital positions, strategies, or opinions. ? ; c?".UJ" Glenda: http://glenda.cat-v.org/gallery/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen at -NOSPAM-xs4all.nl Fri May 6 13:47:58 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Fri, 06 May 2011 19:47:58 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: References: Message-ID: <4dc4344f$0$65870$e4fe514c@news.xs4all.nl> On 06-05-11 15:56, Nico Grubert wrote: > > However, running the selftest still fails: > $ python selftest.py > *** The _imaging C module is not installed > I had this happening to me as well someday. I recall that first installing it (python setup.py install), and then rerunning selftest, solved that error. Irmen From alister.ware at ntlworld.com Fri May 6 13:49:41 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Fri, 06 May 2011 17:49:41 GMT Subject: Hello Friends References: Message-ID: On Thu, 05 May 2011 21:55:22 -0700, Ashraf Ali wrote: > Do you need legal help.If so Please visit > www.chicagopersonalinjurylawyerz.blogspot.com sorry I would only use a reputable firm (spaming a news group makes you disreputable by default) -- My NOSE is NUMB! From nospam at torek.net Fri May 6 13:57:03 2011 From: nospam at torek.net (Chris Torek) Date: 6 May 2011 17:57:03 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <92fb5jFa2lU1@mid.individual.net> <4dc2c52e$0$10567$742ec2ed@news.sonic.net> Message-ID: >>> John Nagle wrote: >>>> A reasonable compromise would be that "is" is treated as "==" on >>>> immutable objects. (Note: I have no dog in this fight, I would be happy with a changed "is" or with the current one -- leaky abstractions are fine with me, provided I am told *when* they may -- or sometimes may not -- leak. :-) ) >> On 5/5/2011 3:06 AM, Gregory Ewing wrote: >>> That wouldn't work for tuples, which can contain references >>> to other objects that are not immutable. >On Thu, May 5, 2011 at 9:41 AM, John Nagle wrote: >> Such tuples are still identical, even if they >> contain identical references to immutable objects. In article Ian Kelly wrote: >>>> a = (1, 2, [3, 4, 5]) >>>> b = (1, 2, [3, 4, 5]) >>>> a == b >True >>>> a is b # Using the proposed definition >True I believe that John Nagle's proposal would make "a is b" false, because while a and b are both immutable, they contain *different* refernces to *mutable* objects (thus failing the "identical references to immutable objects" part of the claim). On the other hand, should one do: L = [3, 4, 5] a = (1, 2, L) b = (1, 2, L) then "a is b" should (I say) be True under the proposal -- even though they contain (identical) references to *mutable* objects. Loosely speaking, we would define the "is" relation as: (x is y) if and only if (id(x) == id(y) or (x is immutable and y is immutable and (for all components xi and yi of x, xi is yi))) In this case, even if the tuples "a" and "b" have different id()s, we would find that both have an immutable type, and both have components -- in this case, numbered, subscriptable tuple elements, but instances of immutable class types like decimal.Decimal would have dictionaries instead -- and thus we would recursively apply the modified "is" definition to each element. (For tuples, the "all components" implies that the lengths must be equal; for class instances, it implies that they need to have "is"-equal attributes, etc.) It's not entirely clear to me whether different immutable classes (i.e., different types) but with identical everything-else should compare equal under this modified "is". I.e., today: $ cp /usr/lib/python2.?/decimal.py /tmp/deccopy.py $ python ... >>> sys.path.append('/tmp') >>> import decimal >>> import deccopy >>> x = decimal.Decimal('1') >>> y = deccopy.Decimal('1') >>> print x, y 1 1 >>> x == y False and obviously "x is y" is currently False: >>> type(x) >>> type(y) However, even though the types differ, both x and y are immutable [%] and obviously (because I copied the code) they have all the same operations. Since they were both created with the same starting value, x and y will behave identically given identical treatment. As such, it might be reasonable to ask that "x is y" be True rather than False. [% This is not at all obvious -- I have written an immutable class, and it is pretty easy to accidentally mutate an instance inside the class implementation. There is nothing to prevent this in CPython, at least. If there were a minor bug in the decimal.Decimal code such that x.invoke_bug() modified x, then x would *not* be immutable, even though it is "intended to be". (As far as I know there are no such bugs in decimal.Decimal, it's just that I had them in my "Money" class.)] -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From nospam at torek.net Fri May 6 14:17:55 2011 From: nospam at torek.net (Chris Torek) Date: 6 May 2011 18:17:55 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article harrismh777 wrote: >There may be some language somewhere that does pass-by-reference which >is not implemented under the hood as pointers, but I can't think of >any... 'cause like I've been saying, way down under the hood, we only >have direct and indirect memory addressing in today's processors. EOS. There have been Fortran compilers that implemented modification of variables via "value-result" rather than "by-reference". This is perhaps best illustrated by some code fragments: SUBROUTINE FOO(X, Y) INTEGER X, Y ... X = 3 Y = 4 RETURN SUBROUTINE BAR(A) FOO(A, 0) RETURN might compile to the equivalent of the following C code: void foo(int *x0, int *y0) { int x = *x0, y = *y0; ... *x0 = x; *y0 = y; } void bar(int *a0) { int a = *a0; int temp = 0; foo(&a, &temp); *a0 = a; } In order to allow both by-reference and value-result, Fortran forbids the programmer to peek at the machinery. That is, the following complete program is invalid: SUBROUTINE PEEK(X) INTEGER X, GOTCHA COMMON /BLOCK/ GOTCHA PRINT *, 'INITIALLY GOTCHA = ', GOTCHA X = 4 PRINT *, 'AFTER X=4 GOTCHA = ', GOTCHA RETURN PROGRAM MAIN INTEGER GOTCHA COMMON /BLOCK/ GOTCHA GOTCHA = 3 PEEK(GOTCHA) PRINT *, 'FINALLY GOTCHA = ', GOTCHA STOP END (It has been so long since I used Fortran that the above may not be quite right in ways other than the one intended. Please forgive small errors. :-) ) The trick in "subroutine peek" is that it refers to both a "global variable" (in Fortran, simulated with a common block) and a "dummy variable" (as it is termed in Fortran) -- the parameter that aliases the global variable -- in such a way that we can see *when* the change happens. If "gotcha" starts out set to 3, remains 3 after assignment to x, and changes to 4 after peek() returns, then peek() effectively used value-result to change the parameter. If, on the other hand, "gotcha" became 4 immediately after the assignment to x, then peek() effectively used by-reference. The key take-away here is not so much the trick by which we "peeked inside" the implementation (although peeking *is* useful in solving the "murder mystery" we have after some program aborts with a core-dump or what-have-you), but rather the fact that the Fortran language proper forbids us from peeking at all. By forbidding it -- by making the program illegal -- the language provide implementors the freedom to use *either* by-reference or value-result. All valid Fortran programs behave identically under either kind of implementation. Like it or not, Python has similar "defined as undefined" grey areas: one is not promised, for instance, whether the "is" operator is always True for small integers that are equal (although it is in CPython), nor when __del__ is called (if ever), and so on. As with the Python-named-Monty, we have "rigidly defined areas of doubt and uncertainty". These exist for good reasons: to allow different implementations. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From ian.g.kelly at gmail.com Fri May 6 14:36:09 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 12:36:09 -0600 Subject: Coolest Python recipe of all time In-Reply-To: <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 6, 2011 at 10:59 AM, Steven D'Aprano wrote: > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. This isn't really amb; as you said it's just a brute-force solver with some weird syntax. The whole point of amb is to enable non-deterministic programming, such as this: def find_values(): a = amb(1, 3, 5) b = amb(2, 4, 8) if a + b <= 5: fail() if not is_prime(a * b + 1): fail() c = amb(a, b, None) if c is not None and c < 5: fail() return a, b, c The amb engine would conceptually execute this function for every possible combination of a, b, and c, pruning away the combinations that fail at some point, and arbitrarily returning one of the remaining combinations. So find_values() here might return (3, 4, None) after failing at one point or another on (1, 2); (1, 4); (1, 8); (3, 2); (3, 4, 3); and (3; 4; 4). Note in particular that the declaration of c is not easily expressible using the Python recipe. This is typically implemented using continuations, and I'm not sure whether a true amb could actually be achieved in Python without adding continuations or flow-control macros to the language. From john at castleamber.com Fri May 6 14:46:52 2011 From: john at castleamber.com (John Bokma) Date: Fri, 06 May 2011 13:46:52 -0500 Subject: Hello Friends References: Message-ID: <87k4e3hdk3.fsf@castleamber.com> Alister Ware writes: > On Thu, 05 May 2011 21:55:22 -0700, Ashraf Ali wrote: > >> Do you need legal help.If so Please visit >> > > sorry I would only use a reputable firm > (spaming a news group makes you disreputable by default) Does it make you disreputable? Since you just repeated the spamvertized URL... -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From nospam at torek.net Fri May 6 15:06:27 2011 From: nospam at torek.net (Chris Torek) Date: 6 May 2011 19:06:27 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article I wrote, in part: >Like it or not, Python has similar "defined as undefined" grey >areas: one is not promised, for instance, whether the "is" operator >is always True for small integers that are equal (although it is >in CPython), nor when __del__ is called (if ever), and so on. As >with the Python-named-Monty, we have "rigidly defined areas of >doubt and uncertainty". These exist for good reasons: to allow >different implementations. Oops, attribution error: this comes from Douglas Adams rather than Monty Python. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From harrismh777 at charter.net Fri May 6 15:22:25 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 06 May 2011 14:22:25 -0500 Subject: string formatting In-Reply-To: <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > It's perfectly safe to continue using % formatting, if you choose. > I would hope so, since its the way in most of the books, much of the doc and a majority of the code... I don't really like the old style, not because there is anything wrong with it, because its an obvious carry-over from the cryptic formatting style of 'C' printf(), and others. It seems to me that the purpose of formatting is to make output clear, and therefore the output formatting style itself should be clear and clean. On the other hand, among the three styles listed by the OP (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky', 'blue') ... they all *feel* good... I mean, they're all clear, clean, precise... On the other hand, while any 'C' programmer is able to see instantly that (1) is a some type of formatting construct, (2) & (3) are clear and obvious formatting constructs, even for newbies and esp. for non 'C' programmers. On the other hand, at this point, it seems that this is personal preference issue completely. So, if the book says you can do it, and there is no formal deprecation process in the works, feel free to express yourself with the style that best suits 'you'. On the other hand,..... :) kind regards, m harris From harrismh777 at charter.net Fri May 6 15:25:52 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 06 May 2011 14:25:52 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4XXwp.18782$Ot6.2313@newsfe15.iad> Chris Torek wrote: >> with the Python-named-Monty, we have "rigidly defined areas of >> >doubt and uncertainty". These exist for good reasons: to allow >> >different implementations. > Oops, attribution error: this comes from Douglas Adams rather > than Monty Python. Well, its certainly Monte-esq.... I like it, whoever said it. From tjreedy at udel.edu Fri May 6 15:31:57 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 May 2011 15:31:57 -0400 Subject: checking if a list is empty In-Reply-To: References: Message-ID: On 5/6/2011 7:34 AM, James Mills wrote: > On Fri, May 6, 2011 at 4:36 PM, Jabba Laci wrote: >> If I want to check if a list is empty, which is the more pythonic way? > > [...] > >> (2) if not li: > > This is fine. This is the intended way. Anything in addition is extra noise and wasted calculation. In other words, let Python do the boilerplate work for you. -- Terry Jan Reedy From ian.g.kelly at gmail.com Fri May 6 15:38:08 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 13:38:08 -0600 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 6, 2011 at 12:36 PM, Ian Kelly wrote: > This is typically implemented using continuations, and I'm not sure > whether a true amb could actually be achieved in Python without adding > continuations or flow-control macros to the language. I stand corrected. After poking around a bit more I found this recipe that is designed for unit-testing but implements amb beautifully. http://lackingrhoticity.blogspot.com/2009/08/how-to-do-model-checking-of-python-code.html My code from the previous post using this recipe: def find_values(chooser): def amb(*choices): return chooser.choose(choices) def require(x): if not x: amb() a = amb(1, 3, 5) b = amb(2, 4, 8) require(a + b > 5) require(is_prime(a * b + 1)) c = amb(a, b, None) require(c is None or c >= 5) return a, b, c check(find_values) The one downside is that the check function (again, designed for unit-testing) does not provide any way to retrieve the returned values, but that is easily solved by rewriting as a generator. Cheers, Ian From harrismh777 at charter.net Fri May 6 15:39:15 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 06 May 2011 14:39:15 -0500 Subject: string formatting In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: harrismh777 wrote: OP wrote: > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') On the other hand, consider this 3.x code snip: print("the %s is %d" % ('sky', 'blue')) That formatting will throw an exception, because the format construct is restricting the format entry to be a number, which 'blue' clearly isn't.... The following print() is better, because *any* time or *most* types can be substituted and the 'polymorphism' of Python kicks in allowing for that, as so: print("the {} is {}".format('sky', 3.4)) print("the {} is {}".format('sky', 'blue')) l=['cloudy', 'today'] print("the {} is {}".format('sky', l)) On the other hand,.... :) kind regards, m harris From dmitrey15 at gmail.com Fri May 6 15:40:13 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 6 May 2011 12:40:13 -0700 (PDT) Subject: Python 3 dict question Message-ID: hi all, suppose I have Python dict myDict and I know it's not empty. I have to get any (key, value) pair from the dict (no matter which one) and perform some operation. In Python 2 I used mere key, val = myDict.items()[0] but in Python 3 myDict.items() return iterator. Of course, I could use for key, val in myDict.items(): do_something break but maybe there is any better way? Thank you in advance, D. From harrismh777 at charter.net Fri May 6 15:49:24 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 06 May 2011 14:49:24 -0500 Subject: checking if a list is empty In-Reply-To: References: Message-ID: <9hYwp.5805$xo2.3333@newsfe07.iad> Terry Reedy wrote: >>> (2) if not li: >> >> This is fine. > > This is the intended way. Anything in addition is extra noise and wasted > calculation. In other words, let Python do the boilerplate work for you. I agree, but I don't like it. ... if not li says nothing about what li is supposed to 'be' and implies in any case that li does not exist, or worse is some kind of boolean. li is in fact an empty list [] and will identify as such, and of course (as a list object) has all of the attributes and methods of a list... Why not have a list method that makes this more explicit: if not li.emptylist() if not li.empty([]) there might be others... kind regards, m harris From clp2 at rebertia.com Fri May 6 15:51:27 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 12:51:27 -0700 Subject: Python 3 dict question In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 12:40 PM, dmitrey wrote: > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterator. > Of course, I could use > for key, val in myDict.items(): > ? do_something > ? break > but maybe there is any better way? key, val = next(myDict.items()) Cheers, Chris From neilc at norwich.edu Fri May 6 15:54:14 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 6 May 2011 19:54:14 GMT Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92j1v6FthtU1@mid.individual.net> On 2011-05-06, harrismh777 wrote: > Steven D'Aprano wrote: >> It's perfectly safe to continue using % formatting, if you >> choose. > > I would hope so, since its the way in most of the books, much > of the doc and a majority of the code... > > I don't really like the old style, not because there is > anything wrong with it, because its an obvious carry-over from > the cryptic formatting style of 'C' printf(), and others. It > seems to me that the purpose of formatting is to make output > clear, and therefore the output formatting style itself should > be clear and clean. C's printf is a venerable example of the power of notation. Notation kicks ass. Another that's well known are regular expressions. Python uses this powerful idea again in the struct module. Any other places? Functions and classes are a general purpose, though verbose, form of notation and can be used in place of mini languages when you don't want to bother, e.g., C++'s iostreams, and pyparsing's grammar declarations. Lisp declared that you could implement mini-languages in Lisp, rather than just parsing them. Python 3's format notation is an improvement for Python, since Python doesn't need the type information that's crucial for C and particularly scanf, an application of C's mini-language that Python doesn't need. Delimiting the escape sequences also makes it easier to read and parse complex formating declarations. For simple constructs there's not much difference between them, but if you switch to .format you'll probably reap some benefit. -- Neil Cerutti From ian.g.kelly at gmail.com Fri May 6 15:54:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 13:54:52 -0600 Subject: string formatting In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 6, 2011 at 1:39 PM, harrismh777 wrote: > harrismh777 wrote: ? ?OP wrote: > >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {}".format('sky', 'blue') > > ? On the other hand, consider this 3.x code snip: > > ? print("the %s is %d" % ('sky', 'blue')) > > > ? That formatting will throw an exception, because the format construct is > restricting the format entry to be a number, which 'blue' clearly isn't.... If you used %d, then that exception is presumably what you wanted. If not, then you should just do: print("the %s is %s" % ('sky', 'blue')) > ? The following print() is better, because *any* time or *most* types can be > substituted and the 'polymorphism' of Python kicks in allowing for that, as > so: '%s' has exactly the same degree of polymorphism as '{}', because both simply call str() on their argument. There are good reasons to use format instead of % if possible, but polymorphism isn't one of them. From dmitrey15 at gmail.com Fri May 6 15:57:11 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 6 May 2011 12:57:11 -0700 (PDT) Subject: Python 3 dict question References: Message-ID: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> On May 6, 10:51?pm, Chris Rebert wrote: > On Fri, May 6, 2011 at 12:40 PM, dmitrey wrote: > > hi all, > > suppose I have Python dict myDict and I know it's not empty. > > I have to get any (key, value) pair from the dict (no matter which > > one) and perform some operation. > > In Python 2 I used mere > > key, val = myDict.items()[0] > > but in Python 3 myDict.items() return iterator. > > Of course, I could use > > for key, val in myDict.items(): > > ? do_something > > ? break > > but maybe there is any better way? > > key, val = next(myDict.items()) > > Cheers, > Chris Unfortunately, it doesn't work, it turn out to be dict_items: >>> next({1:2}.items()) Traceback (most recent call last): File "", line 1, in TypeError: dict_items object is not an iterator >>> dir({1:2}.items()) ['__and__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__or__', '__rand__', '__reduce__', '__reduce_ex__', '__repr__', '__ror__', '__rsub__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__xor__', 'isdisjoint'] From python at rcn.com Fri May 6 15:58:56 2011 From: python at rcn.com (Raymond Hettinger) Date: Fri, 6 May 2011 12:58:56 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <31819e29-a02f-4721-bb75-5decbd0056ae@i39g2000prd.googlegroups.com> [Steven D'Aprano]: > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. With a small change in API, much of the magic isn't needed. from itertools import product def amb(func, *argument_ranges): for args in product(*argument_ranges): if func(*args): print(args) amb(lambda a,b,c,d: 5*a+10*b+20*c+50*d == 45, range(3, 21), # number of 5 cent coins range(11), # number of 10 cent coins range(6), # number of 20 cent coins range(3), # number of 50 cent coins ) def test(a, b, c, d): s = "The %s brown %s jumped over the %s %s." % (a, b, c, d) num_vowels = sum(s.count(c) for c in 'aeiou') return num_vowels in (12, 18, 19) amb(test, ['quick', 'slow', 'hungry', 'wise-old'], ['fox', 'hare', 'turtle', 'kangaroo'], ['lazy', 'stupid', 'sleepy', 'confused'], ['dog', 'aardvark', 'sloth', 'wombat'], ) amb(lambda x, y, z: x*x + y*y == z*z, range(1, 11), range(1, 11), range(1, 11), ) Raymond ------------ follow my recipes and tips on twitter: @raymondh From ericsnowcurrently at gmail.com Fri May 6 16:00:02 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 6 May 2011 14:00:02 -0600 Subject: checking if a list is empty In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 1:31 PM, Terry Reedy wrote: > On 5/6/2011 7:34 AM, James Mills wrote: > >> On Fri, May 6, 2011 at 4:36 PM, Jabba Laci wrote: >> >>> If I want to check if a list is empty, which is the more pythonic way? >>> >> >> [...] >> >> (2) if not li: >>> >> >> This is fine. >> > > This is the intended way. Anything in addition is extra noise and wasted > calculation. In other words, let Python do the boilerplate work for you. > > That works for lists, but for a class that implements a list-like interface, subclassing list or not, it will not always work the way you want. The language reference indicates that, for the implicit cast to a bool, __bool__ is checked on the object, then __len__, and then it defaults to True [1]. So the above only works the way you expect if __len__ is the normal length for a list and __bool__ is not defined. I ran into this once when I had a class that defined __len__ but wanted the object to cast to True no matter what. For my case I chose to redefine __bool__. So it seems like this boils down to what you want to know. Is the list empty (length 0) or is the boolean version false? Again, for lists these are the same. For list-like classes they are not necessarily the same. Incidently, you can also check "if li == []:". This will let the __eq__ operator jump in. -eric [1] http://docs.python.org/dev/py3k/reference/datamodel.html#object.__bool__ -- > Terry Jan Reedy > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri May 6 16:02:23 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 14:02:23 -0600 Subject: Python 3 dict question In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 1:51 PM, Chris Rebert wrote: > On Fri, May 6, 2011 at 12:40 PM, dmitrey wrote: >> hi all, >> suppose I have Python dict myDict and I know it's not empty. >> I have to get any (key, value) pair from the dict (no matter which >> one) and perform some operation. >> In Python 2 I used mere >> key, val = myDict.items()[0] >> but in Python 3 myDict.items() return iterator. >> Of course, I could use >> for key, val in myDict.items(): >> ? do_something >> ? break >> but maybe there is any better way? > > key, val = next(myDict.items()) Recognizing that if myDict is empty then this will raise StopIteration instead of KeyError. From awilliam at whitemice.org Fri May 6 16:05:09 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 06 May 2011 16:05:09 -0400 Subject: checking if a list is empty In-Reply-To: <9hYwp.5805$xo2.3333@newsfe07.iad> References: <9hYwp.5805$xo2.3333@newsfe07.iad> Message-ID: <1304712309.9905.10.camel@linux-yu4c.site> On Fri, 2011-05-06 at 14:49 -0500, harrismh777 wrote: > Terry Reedy wrote: > >>> (2) if not li: > >> This is fine. > > This is the intended way. Anything in addition is extra noise and wasted > > calculation. In other words, let Python do the boilerplate work for you. > I agree, but I don't like it. +1 This is the Python reality-distortion-field at work. Motto#1: Python is all about readability! Motto#2: Crytic code is awesome if it is Pythoncally cryptic! I'd never accept code like "if not x" as an empty test. > ... if not li says nothing about what li is supposed to 'be' and > implies in any case that li does not exist, or worse is some kind of > boolean. > li is in fact an empty list [] and will identify as such, and of > course (as a list object) has all of the attributes and methods of a list... > Why not have a list method that makes this more explicit: > if not li.emptylist() > if not li.empty([]) > there might be others... Good luck. Just code - # You can immediately tell what this is meant to do! if len(x) == 0: - and ignore the Pythonistas [they're nuts; that x.count() doesn't work is amazingly stupid]. From clp2 at rebertia.com Fri May 6 16:46:14 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 13:46:14 -0700 Subject: checking if a list is empty In-Reply-To: <1304712309.9905.10.camel@linux-yu4c.site> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <1304712309.9905.10.camel@linux-yu4c.site> Message-ID: On Fri, May 6, 2011 at 1:05 PM, Adam Tauno Williams wrote: > - and ignore the Pythonistas [they're nuts; ?that x.count() doesn't work > is amazingly stupid]. Eh? It works fine. [5, 2, 2, 1, 2].count(2) == 3. If you mean you want len(x) to be spelled x.count(), that's equally stupid; `count` would be a lousy name (people would confuse it with what the current .count() does). `length` or `size` would make much more sense. Cheers, Chris From rw at smsnet.pl Fri May 6 16:46:36 2011 From: rw at smsnet.pl (Rob Wolfe) Date: Fri, 06 May 2011 22:46:36 +0200 Subject: Python 3 dict question References: Message-ID: <87pqnvr1zn.fsf@smsnet.pl> dmitrey writes: > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterator. > Of course, I could use > for key, val in myDict.items(): > do_something > break > but maybe there is any better way? key, val = next(iter(myDict.items())) http://docs.python.org/py3k/library/stdtypes.html#dictionary-view-objects HTH, Rob From ian.g.kelly at gmail.com Fri May 6 16:48:45 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 14:48:45 -0600 Subject: Python 3 dict question In-Reply-To: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> Message-ID: On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: > Unfortunately, it doesn't work, it turn out to be dict_items: >>>> next({1:2}.items()) > Traceback (most recent call last): > ?File "", line 1, in > TypeError: dict_items object is not an iterator So call iter() on it first: next(iter(myDict.items())) From listas.programacao at gmail.com Fri May 6 16:49:47 2011 From: listas.programacao at gmail.com (Jayme Proni Filho) Date: Fri, 6 May 2011 17:49:47 -0300 Subject: How can I print one sqlite table with UTF-8 collumn Message-ID: I have one sqlite database called aripuanaonline.db. In this database I have one table with two collumns first with autoincrement not null and other with varchar(100) not null. I got this error: Traceback (most recent call last): File "C:\Documents and Settings\Marco\Desktop\aripuanaonline\aripuana.py", line 9, in rows = cursor.fetchall() sqlite3.OperationalError: Could not decode to UTF-8 column 'mensagem' with text 'Shampoo Pantene Restaura??o Profunda ? vista por R$4,99' How can I print my table? --------------------------------------------------------------------------------------- Jayme Proni Filho Skype: jaymeproni Twitter: @jaymeproni Phone: +55 - 17 - 3631 - 6576 Mobile: +55 - 17 - 9605 - 3560 e-Mail: jaymeproni at yahoo dot com dot br --------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri May 6 16:54:17 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 May 2011 16:54:17 -0400 Subject: string formatting In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/6/2011 3:22 PM, harrismh777 wrote: > I don't really like the old style, not because there is anything wrong > with it, There is in that it special cases tuples. For instance, a message function like def emsg(x): print("The following object caused a proplem: %s" % x) raises "TypeError: not all arguments converted during string formatting" if x is a tuple with other than 1 member and extracts x[0] if there is just one. Neither is the desired behavior. That has been a problem (and sometimes a debugging puzzle) in real code One has to remember to write something like def emsg(x): if isinstance(x,tuple): x = (x,) print(The following object caused a proplem: %s" % x) Guido sees that his original design is a bit of a bug trap, which is one reason he wanted to replace it. -- Terry Jan Reedy From nirina.raseliarison at gmail.com Fri May 6 17:18:59 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Fri, 06 May 2011 14:18:59 -0700 (PDT) Subject: Python 3 dict question References: Message-ID: <4dc465c3.454de50a.7493.7e68@mx.google.com> [dmitrey] > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterator. > Of course, I could use > for key, val in myDict.items(): > do_something > break > but maybe there is any better way? key, val = list(myDict.items())[0] -- nirinA From tooscattered at gmail.com Fri May 6 17:57:21 2011 From: tooscattered at gmail.com (scattered) Date: Fri, 6 May 2011 14:57:21 -0700 (PDT) Subject: checking if a list is empty References: Message-ID: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> On May 6, 2:36?am, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: > ... > > Thanks, > > Laszlo is there any problem with (3) if li == []: ? Seems to work when I test it and seems to clearly test what you are trying to test. The only problem might be if in some contexts == has the semantics of checking for object identity. From philip at semanchuk.com Fri May 6 18:21:09 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 6 May 2011 18:21:09 -0400 Subject: checking if a list is empty In-Reply-To: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> Message-ID: <8BD5792C-AFE3-4B86-82DB-B6C3F249FA5F@semanchuk.com> On May 6, 2011, at 5:57 PM, scattered wrote: > On May 6, 2:36 am, Jabba Laci wrote: >> Hi, >> >> If I want to check if a list is empty, which is the more pythonic way? >> >> li = [] >> >> (1) if len(li) == 0: >> ... >> or >> (2) if not li: >> ... >> >> Thanks, >> >> Laszlo > > is there any problem with > > (3) if li == []: > > ? What if it's not a list but a tuple or a numpy array? Often I just want to iterate through an element's items and I don't care if it's a list, set, etc. For instance, given this function definition -- def print_items(an_iterable): if not an_iterable: print "The iterable is empty" else: for item in an_iterable: print item I get the output I want with all of these calls: print_items( list() ) print_items( tuple() ) print_items( set() ) print_items( numpy.array([]) ) Given this slightly different definition, only the first call gives me the output I expect: def print_items(an_iterable): if an_iterable == []: print "The iterable is empty" else: for item in an_iterable: print item I find I use the the former style ("if not an_iterable") almost exclusively. bye Philip From drobinow at gmail.com Fri May 6 18:24:44 2011 From: drobinow at gmail.com (David Robinow) Date: Fri, 6 May 2011 18:24:44 -0400 Subject: setuptools for 64-bit 2.7.1 on 64-bit Windows 7? In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 1:43 PM, Dick Bridges wrote: > Simple question: Is it true that no setuptools (or any other module > installer) exists for 64-bit python 2.7.1? If there is an installer that > works, what terms might I use to Google for information on how to acquire > and install it? Doesn't the installer at http://www.lfd.uci.edu/~gohlke/pythonlibs/ work? From ethan at stoneleaf.us Fri May 6 18:49:40 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 06 May 2011 15:49:40 -0700 Subject: Dictionary Views -- good examples? [was Re: Python 3 dict question] In-Reply-To: References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> Message-ID: <4DC47B04.9070007@stoneleaf.us> Ian Kelly wrote: > On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: >> Unfortunately, it doesn't work, it turn out to be dict_items: >>>>> next({1:2}.items()) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: dict_items object is not an iterator > > So call iter() on it first: > > next(iter(myDict.items())) Which is becoming less elegant. Seems to me that View objects should be directly iterable, but then I don't really understand the motivation behind them or what greatness is facilitated by having them. Anybody care to chime in with their usage of this construct? ~Ethan~ From python at rcn.com Fri May 6 18:52:18 2011 From: python at rcn.com (Raymond Hettinger) Date: Fri, 6 May 2011 15:52:18 -0700 (PDT) Subject: checking if a list is empty References: Message-ID: On May 5, 11:36?pm, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: The Python core developers use the second form. See http://www.python.org/dev/peps/pep-0008/ for the official recommendation. Raymond From rosuav at gmail.com Fri May 6 19:43:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 May 2011 09:43:20 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <4XXwp.18782$Ot6.2313@newsfe15.iad> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <4XXwp.18782$Ot6.2313@newsfe15.iad> Message-ID: On Sat, May 7, 2011 at 5:25 AM, harrismh777 wrote: > Chris Torek wrote: >>> >>> with the Python-named-Monty, we have "rigidly defined areas of >>> >doubt and uncertainty". ?These exist for good reasons: to allow >>> >different implementations. >> >> Oops, attribution error: this comes from Douglas Adams rather >> than Monty Python. > > Well, its certainly Monte-esq.... I like it, whoever said it. Same style of humour, they both derived significantly from Spike Milligan and "The Goon Show". That particular quote relates to the famous computer that calculated the number 42, which - to drag this, kicking and screaming, back to some semblance of on-topicness - was clearly built with a view to conserving programmer time at the expense of execution time. I don't understand why they didn't just recode the heavy computation in C and cut it down to just a few thousand years... Chris Angelico From ian.g.kelly at gmail.com Fri May 6 19:51:44 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 17:51:44 -0600 Subject: checking if a list is empty In-Reply-To: <8BD5792C-AFE3-4B86-82DB-B6C3F249FA5F@semanchuk.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <8BD5792C-AFE3-4B86-82DB-B6C3F249FA5F@semanchuk.com> Message-ID: On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk wrote: > What if it's not a list but a tuple or a numpy array? Often I just want to iterate through an element's items and I don't care if it's a list, set, etc. For instance, given this function definition -- > > def print_items(an_iterable): > ? ?if not an_iterable: > ? ? ? ?print "The iterable is empty" > ? ?else: > ? ? ? ?for item in an_iterable: > ? ? ? ? ? ?print item > > I get the output I want with all of these calls: > print_items( list() ) > print_items( tuple() ) > print_items( set() ) > print_items( numpy.array([]) ) But sadly it fails on iterators: print_items(xrange(0)) print_items(-x for x in []) print_items({}.iteritems()) From rosuav at gmail.com Fri May 6 20:09:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 May 2011 10:09:49 +1000 Subject: string formatting In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 7, 2011 at 6:54 AM, Terry Reedy wrote: > def emsg(x): > ?if isinstance(x,tuple): > ? ?x = (x,) > ?print(The following object caused a proplem: %s" % x) > Couldn't you just do that unconditionally? print(The following object caused a proplem: %s" % (x,)) Chris Angelico From ian.g.kelly at gmail.com Fri May 6 20:23:22 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 18:23:22 -0600 Subject: Dictionary Views -- good examples? [was Re: Python 3 dict question] In-Reply-To: <4DC47B04.9070007@stoneleaf.us> References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> <4DC47B04.9070007@stoneleaf.us> Message-ID: On Fri, May 6, 2011 at 4:49 PM, Ethan Furman wrote: > Ian Kelly wrote: >> >> On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: >>> >>> Unfortunately, it doesn't work, it turn out to be dict_items: >>>>>> >>>>>> next({1:2}.items()) >>> >>> Traceback (most recent call last): >>> ?File "", line 1, in >>> TypeError: dict_items object is not an iterator >> >> So call iter() on it first: >> >> next(iter(myDict.items())) > > Which is becoming less elegant. That's not even the worst of it. If the dict is empty, then the code above will raise a StopIteration, which must be caught locally since if it propagates it could be swallowed by a generator. So a full recipe should really look more like this: try: first_item = next(iter(my_dict.items())) except StopIteration: raise ValueError("empty dict") >?Seems to me that View objects should be directly iterable They are. They're just not directly nextable because they're treated as dependent collections, not iterators. > but then I don't really understand the motivation behind them or what greatness is facilitated by having them. > > Anybody care to chime in with their usage of this construct? You should start with PEP 3106. The main idea is that dict.keys() and dict.items() can be treated as frozensets, while still being more lightweight than lists. That lets you do nifty things like "a.keys() == b.keys()" which, if a and b are Python 3 dicts, will tell you whether they contain the same keys. Whether anybody actually uses this, I have no idea. From joncle at googlemail.com Fri May 6 20:43:51 2011 From: joncle at googlemail.com (Jon Clements) Date: Fri, 6 May 2011 17:43:51 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <8BD5792C-AFE3-4B86-82DB-B6C3F249FA5F@semanchuk.com> Message-ID: <61e9b51a-492f-410d-8ebc-e516165795df@y12g2000yqh.googlegroups.com> On May 7, 12:51?am, Ian Kelly wrote: > On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk wrote: > > What if it's not a list but a tuple or a numpy array? Often I just want to iterate through an element's items and I don't care if it's a list, set, etc. For instance, given this function definition -- > > > def print_items(an_iterable): > > ? ?if not an_iterable: > > ? ? ? ?print "The iterable is empty" > > ? ?else: > > ? ? ? ?for item in an_iterable: > > ? ? ? ? ? ?print item > > > I get the output I want with all of these calls: > > print_items( list() ) > > print_items( tuple() ) > > print_items( set() ) > > print_items( numpy.array([]) ) > > But sadly it fails on iterators: > print_items(xrange(0)) > print_items(-x for x in []) > print_items({}.iteritems()) My stab: from itertools import chain def print_it(iterable): it = iter(iterable) try: head = next(it) except StopIteration: print 'Empty' return for el in chain( (head,), it ): print el Not sure if I'm truly happy with that though. Jon Jon. From rosuav at gmail.com Fri May 6 20:51:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 May 2011 10:51:43 +1000 Subject: checking if a list is empty In-Reply-To: <1304712309.9905.10.camel@linux-yu4c.site> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <1304712309.9905.10.camel@linux-yu4c.site> Message-ID: On Sat, May 7, 2011 at 6:05 AM, Adam Tauno Williams wrote: > On Fri, 2011-05-06 at 14:49 -0500, harrismh777 wrote: >> Terry Reedy wrote: >> >>> (2) if not li: >> >> This is fine. >> > This is the intended way. Anything in addition is extra noise and wasted >> > calculation. In other words, let Python do the boilerplate work for you. >> ? ? I agree, but I don't like it. > > +1 ?This is the Python reality-distortion-field at work. > > Motto#1: Python is all about readability! > Motto#2: Crytic code is awesome if it is Pythoncally cryptic! As a C and C++ programmer, I probably shouldn't offer an opinion, but it is quite normal in C++ to compare objects for truth/falseness - for instance, stream objects return false on error/eof, so you can efficiently code a loop with "while (infile) {...}". Not to mention that the nullness of a C string (a PSZ) is quite happily and safely tested by seeing if the pointer is true (non-null) or false (null). That said, though, readability is a relative thing. A construct is transparently obvious if it does something in the exact same way that it's always been done, no matter how obscure it was the first time. Why is it, for instance, that putting two short strokes perpendicular to one another indicates addition? Yet if you see the construct "x + y", you know exactly what it means - it's readable, it's not cryptic at all. People assume and expect that this compact syntax will be available, and object heavily to such notation as "add(x,y)" which says exactly what it does. if not li: is perfectly readable; you just need a comprehension of what truth means for a list. Chris Angelico From daniil.re at gmail.com Fri May 6 22:02:26 2011 From: daniil.re at gmail.com (=?UTF-8?B?0JTQsNC90LjQuNC7INCg0YvQttC60L7Qsg==?=) Date: Sat, 7 May 2011 13:02:26 +1100 Subject: PyGTK, Glade/libglade. What am I doing wrong? Message-ID: Sorry for my English (I could not find help in the Russian community) I'm trying to learn PyGTK and Glade. I made test window in Glade and saved it as "test.glade" (attached). Then I wrote script "test.py"(attached, http://pastebin.com/waKytam3). I tried to run it. While the script was executed, console did not show anything and window wasn't displayed. When I pressed CTRL+? console displayed trackback: --- CTraceback (most recent call last): File "test.py", line 32, in gtk.main() KeyboardInterrupt --- So what am I doing wrong? -- Best wishes, Daniil -------------- next part -------------- A non-text attachment was scrubbed... Name: test.py Type: text/x-python Size: 547 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test.glade Type: application/x-glade Size: 385 bytes Desc: not available URL: From steve+comp.lang.python at pearwood.info Fri May 6 22:30:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2011 02:30:53 GMT Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc4aedc$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 14:39:15 -0500, harrismh777 wrote: > On the other hand, consider this 3.x code snip: > > print("the %s is %d" % ('sky', 'blue')) > > > That formatting will throw an exception, because the format > construct is restricting the format entry to be a number, which 'blue' > clearly isn't.... Er, yes. That's clearly deliberate, because the target uses %d rather than %s. If the author wanted to accept anything, she would used %r or %s. You might as well argue that: print("the {} is {}".format('sky', int(x))) is wrong, because if you leave the int out, any object can be used. > The following print() is better, because *any* time or *most* types > can be substituted and the 'polymorphism' of Python kicks in allowing > for that, as so: > > print("the {} is {}".format('sky', 3.4)) This is not comparing apples with apples. The format equivalent is: print("the {} is {:d}".format('sky', 'blue')) which will also raise an exception, ValueError instead of TypeError. -- Steven From benjamin.kaplan at case.edu Fri May 6 22:48:40 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 6 May 2011 22:48:40 -0400 Subject: PyGTK, Glade/libglade. What am I doing wrong? In-Reply-To: References: Message-ID: On May 6, 2011 7:05 PM, "?????? ??????" wrote: > > Sorry for my English (I could not find help in the Russian community) > I'm trying to learn PyGTK and Glade. I made test window in Glade and > saved it as "test.glade" (attached). Then I wrote script > "test.py"(attached, http://pastebin.com/waKytam3). I tried to run it. > While the script was executed, console did not show anything and > window wasn't displayed. When I pressed CTRL+? console displayed > trackback: > --- > CTraceback (most recent call last): > File "test.py", line 32, in > gtk.main() > KeyboardInterrupt > --- > So what am I doing wrong? > I haven't used gtk before, but is there a show method or something similar you need, to actually make the window appear? The KeyboardInterrupt is normal. That's how control-c works. > -- > Best wishes, > Daniil > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri May 6 22:49:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2011 02:49:53 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> Message-ID: <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 16:05:09 -0400, Adam Tauno Williams wrote: > I'd never accept code like "if not x" as an empty test. So much the worse for you then. The point of the "if x" idiom is that it is a polymorphic test which is independent of the type. It works with any non-broken object[1], no matter what x is, since it allows x to decide for itself whether it is empty or not. Of course, you can write your own polymorphic test: try: flag = len(x) == 0 except TypeError: # This *should* succeed, for anything not broken. If not, we can't # recover, so just let the exception propagate. flag = bool(x) # Hilariously, bool(x) may also try len(x) == 0... oh well. if flag: ... Congratulations! You've now found a way to write "if x:" in five lines, 53 characters (plus whitespace and comments) and an extraneous variable polluting the namespace. If you're being paid per line of code, this is a good win. Of course, sometimes you don't want polymorphism (or at least, not too much polymorphism). Sometimes I'll write "if x == 0" or similar if I want to emphasize that x is a special case unrelated to the truth/falseness of x. But that's quite rare. Normally I trust x to decide for itself whether it is empty or not. [1] Arguably with the exception of iterables. But then the len(x) test doesn't work for them either. -- Steven From steve+comp.lang.python at pearwood.info Fri May 6 22:51:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2011 02:51:50 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> Message-ID: <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 14:57:21 -0700, scattered wrote: > is there any problem with > > (3) if li == []: > > ? > > Seems to work when I test it and seems to clearly test what you are > trying to test. The only problem might be if in some contexts == has the > semantics of checking for object identity. Yes, if li == [] works too. But how do you know li is a list and not some other sequence type? The advantage of the "if x" test is that it is independent of the type of x. -- Steven From daniil.re at gmail.com Fri May 6 23:46:06 2011 From: daniil.re at gmail.com (=?UTF-8?B?0JTQsNC90LjQuNC7INCg0YvQttC60L7Qsg==?=) Date: Sat, 7 May 2011 14:46:06 +1100 Subject: PyGTK, Glade/libglade. What am I doing wrong? In-Reply-To: References: Message-ID: > I haven't used gtk before, but is there a show method or something similar > you need, to actually make the window appear? I don't know. I think "self.wTree = gtk.glade.XML(self.gladefile)" should do this. For example, author of this tutorial (http://www.learningpython.com/2006/05/07/creating-a-gui-using-pygtk-and-glade/) wrote script similar to my. P.S. I have glade3 3.8.0, gtk 2.24.4, GNOME 2.32.1 and Python 2.7.1 -- Best wishes, Daniil From pyclutter at gmail.com Fri May 6 23:47:42 2011 From: pyclutter at gmail.com (craf) Date: Sat, 07 May 2011 00:47:42 -0300 Subject: PyGTK, Glade/libglade. What am I doing wrong? In-Reply-To: References: Message-ID: <1304740062.2510.2.camel@cristian-desktop> On May 6, 2011 7:05 PM, "?????? ??????" wrote: > > Sorry for my English (I could not find help in the Russian community) > I'm trying to learn PyGTK and Glade. I made test window in Glade and > saved it as "test.glade" (attached). Then I wrote script > "test.py"(attached, http://pastebin.com/waKytam3). I tried to run it. > While the script was executed, console did not show anything and > window wasn't displayed. When I pressed CTRL+? console displayed > trackback: > --- > CTraceback (most recent call last): > File "test.py", line 32, in > gtk.main() > KeyboardInterrupt > --- > So what am I doing wrong? > >I haven't used gtk before, but is there a show method or something >similar you need, to actually make the window appear? The >KeyboardInterrupt is normal. That's how control-c works. > -- > Best wishes, > Daniil > > -- > http://mail.python.org/mailman/listinfo/python-list > Hi. Try this: #!/usr/bin/env python import gtk.glade class TestPyGtk: """This is an Hello World GTK application""" def __init__(self): #Set the Glade file self.gladefile = "test.glade" self.glade = gtk.glade.XML(self.gladefile) self.MainWindow = self.glade.get_widget('MainWindow') self.MainWindow.show() self.MainWindow.connect('destroy', lambda e:gtk.main_quit()) TestPyGtk() gtk.main() Regards. Cristian. List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk From daniil.re at gmail.com Sat May 7 00:14:07 2011 From: daniil.re at gmail.com (=?UTF-8?B?0JTQsNC90LjQuNC7INCg0YvQttC60L7Qsg==?=) Date: Sat, 7 May 2011 15:14:07 +1100 Subject: PyGTK, Glade/libglade. What am I doing wrong? In-Reply-To: References: <1304740062.2510.2.camel@cristian-desktop> Message-ID: Thanks, Cristian! It works. > List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk Thanks again. Subscribed :) 2011/5/7 craf : > Hi. > > Try this: > > #!/usr/bin/env python > > import gtk.glade > > class TestPyGtk: > ? ?"""This is an Hello World GTK application""" > > ? ?def __init__(self): > > ? ? ? ?#Set the Glade file > ? ? ? ?self.gladefile = "test.glade" > ? ? ? ?self.glade = gtk.glade.XML(self.gladefile) > > ? ? ? ?self.MainWindow = self.glade.get_widget('MainWindow') > ? ? ? ?self.MainWindow.show() > ? ? ? ?self.MainWindow.connect('destroy', lambda e:gtk.main_quit()) > > > > TestPyGtk() > gtk.main() > > Regards. > > Cristian. > > List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk -- Best wishes, Daniil From rustompmody at gmail.com Sat May 7 01:21:02 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 6 May 2011 22:21:02 -0700 (PDT) Subject: Testing tools classification Message-ID: <0a6beebc-35b7-4f81-b64b-55c0dbed1bae@h12g2000pro.googlegroups.com> There is this nice page of testing tools taxonomy: http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy But it does not list staf: http://staf.sourceforge.net/index.php. From tjreedy at udel.edu Sat May 7 03:55:01 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 May 2011 03:55:01 -0400 Subject: string formatting In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/6/2011 8:09 PM, Chris Angelico wrote: > On Sat, May 7, 2011 at 6:54 AM, Terry Reedy wrote: >> def emsg(x): >> if isinstance(x,tuple): >> x = (x,) >> print(The following object caused a proplem: %s" % x) >> > > Couldn't you just do that unconditionally? > print(The following object caused a proplem: %s" % (x,)) I guess so, as long as one remembers the ','. That does not obviate the fact that % x is an attractive nuisance which works until it does not. -- Terry Jan Reedy From alister.ware at ntlworld.com Sat May 7 04:11:40 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Sat, 07 May 2011 08:11:40 GMT Subject: PyGTK, Glade/libglade. What am I doing wrong? References: <1304740062.2510.2.camel@cristian-desktop> Message-ID: <097xp.16$_T5.11@newsfe02.ams2> On Sat, 07 May 2011 15:14:07 +1100, ?????? ?????? wrote: > Thanks, Cristian! It works. >> List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk > Thanks again. Subscribed :) > 2011/5/7 craf : >> Hi. >> >> Try this: >> >> #!/usr/bin/env python >> >> import gtk.glade >> >> class TestPyGtk: >> ? ?"""This is an Hello World GTK application""" >> >> ? ?def __init__(self): >> >> ? ? ? ?#Set the Glade file >> ? ? ? ?self.gladefile = "test.glade" >> ? ? ? ?self.glade = gtk.glade.XML(self.gladefile) >> >> ? ? ? ?self.MainWindow = self.glade.get_widget('MainWindow') >> ? ? ? ?self.MainWindow.show() >> ? ? ? ?self.MainWindow.connect('destroy', lambda e:gtk.main_quit()) >> >> >> >> TestPyGtk() >> gtk.main() >> >> Regards. >> >> Cristian. >> >> List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk you may also want to look at using gtk.builder instread as it is now the prefered option. -- The human mind ordinarily operates at only ten percent of its capacity -- the rest is overhead for the operating system. From steve+comp.lang.python at pearwood.info Sat May 7 04:28:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2011 08:28:56 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> Message-ID: <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 14:49:24 -0500, harrismh777 wrote: > Terry Reedy wrote: >>>> (2) if not li: >>> >>> This is fine. >> >> This is the intended way. Anything in addition is extra noise and >> wasted calculation. In other words, let Python do the boilerplate work >> for you. > > I agree, but I don't like it. > > ... if not li says nothing about what li is supposed to 'be' Yes, and? Neither does: isempty(li) # li could be anything that polymorphic isempty can deal with li.isempty() # li could be anything with a "isempty" method len(li) == 0 # li could be anything with a length (list, dict, set, ...) That's duck-typing for you, and it is generally a strength rather than a weakness. For those times when it is a weakness, that's where we have naming conventions, type-testing, and (in some languages) static types. > and implies in any case that li does not exist It does nothing of the sort. If li doesn't exist, you get a NameError. > or worse is some kind of boolean. Only if you're still thinking in some language that isn't Python. Boolean tests in Python are polymorphic. bool() exists mainly to provide a canonical representation of true and false values, not because you are limited to using booleans in truth-testing. Far from it: it is often very useful to do something like this: settings = local_settings or global_settings or builtin_settings where the first non-empty *_settings wins. > li is in fact an empty list [] and will identify as such, and of > course (as a list object) has all of the attributes and methods of a > list... > > Why not have a list method that makes this more explicit: For the same reason that we don't have an int method that makes zero testing more explicit: n = 0 n.iszero() # returns True Because sometimes you can have too much explicitness. -- Steven From steve+comp.lang.python at pearwood.info Sat May 7 04:29:28 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2011 08:29:28 GMT Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc502e8$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 12:36:09 -0600, Ian Kelly wrote: > On Fri, May 6, 2011 at 10:59 AM, Steven D'Aprano > wrote: >> As written, amb is just a brute-force solver using more magic than is >> good for any code, but it's fun to play with. > > This isn't really amb; as you said it's just a brute-force solver with > some weird syntax. The whole point of amb is to enable > non-deterministic programming, such as this: [...] > The amb engine would conceptually execute this function for every > possible combination of a, b, and c, Which pretty much is the definition of "brute-force solver", no? -- Steven From greg.ewing at canterbury.ac.nz Sat May 7 04:53:40 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 20:53:40 +1200 Subject: seems like a bug in isinstance() In-Reply-To: References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> Message-ID: <92kfkmF4d5U1@mid.individual.net> Chris Rebert wrote: > This is because you did `from Point import > ...` in file2.py, whereas in file1.py you did `from > openopt.kernel.Point import ...`. These 2 different ways of referring > to the same module are sufficient to "trick"/"outsmart" (C)Python and > cause it to import the same module twice That can't be the whole story, because those two ways of referring to the module *should* have returned the same module object, even though one is absolute and the other relative. I suspect what's happened is that somehow sys.path contains both the directory containing .../openopt *and* the directory .../openopt/kernel, and the second import is picking up Point.py a second time as though it were a top-level module. This could have happened by starting an interactive session while cd'ed to .../openopt/kernel, or by launching a .py file from there as a main script. The solution is to make sure that sys.path only contains the top level directories of the package hierarchy, and doesn't also contain any of their subdirectories. Always using absolute imports may be a good idea stylistically, but in this case it will only mask the symptoms of whatever is really wrong, and further problems could result from the same cause. -- Greg From greg.ewing at canterbury.ac.nz Sat May 7 05:09:09 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 21:09:09 +1200 Subject: Dictionary Views -- good examples? [was Re: Python 3 dict question] In-Reply-To: References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> Message-ID: <92kghnFb37U1@mid.individual.net> Ethan Furman wrote: > Ian Kelly wrote: > >> next(iter(myDict.items())) > > Which is becoming less elegant. If you're doing this sort of thing a lot you can make a little helper function: def first(x): return next(iter(x)) then you get to say first(myDict.items()) -- Greg From greg.ewing at canterbury.ac.nz Sat May 7 05:21:45 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 21:21:45 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> Message-ID: <92kh9cFgdcU1@mid.individual.net> Hans Georg Schaathun wrote: > You cannot reference nor manipulate a > reference in python, and that IMHO makes them more abstract. You can manipulate them just fine by moving them from one place to another: a = b You can use them to get at stuff they refer to: a = b.c a[:] = b[:] You can compare them: if a is b: ... That's about all you can do with pointers in Pascal, and I've never heard anyone argue that Pascal pointers are any more or less abstract than any other piece of data in that language. As for "referencing" a reference, you can't really do that in Pascal either, at least not the way you can in C, because (plain) Pascal doesn't have an address-of operator. The only way to get a pointer to a pointer in Pascal is to heap-allocate a single pointer, which isn't normally a very useful thing to do. -- Greg From rosuav at gmail.com Sat May 7 05:28:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 May 2011 19:28:50 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <92kh9cFgdcU1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> Message-ID: On Sat, May 7, 2011 at 7:21 PM, Gregory Ewing wrote: > Hans Georg Schaathun wrote: > >> You cannot reference nor manipulate a reference in python, and that IMHO >> makes them more abstract. > > You can manipulate them just fine by moving them > from one place to another: I think "manipulate" here means things like pointer arithmetic, which are perfectly normal and common in C and assembly, but not in languages where they're references. Chris Angelico From greg.ewing at canterbury.ac.nz Sat May 7 05:39:47 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 21:39:47 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2c52e$0$10567$742ec2ed@news.sonic.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> <92fb5jFa2lU1@mid.individual.net> <4dc2c52e$0$10567$742ec2ed@news.sonic.net> Message-ID: <92kib3FgdcU2@mid.individual.net> John Nagle wrote: > Such tuples are still identical, even if they > contain identical references to immutable objects. The point is you'd have to do the comparison only one level deep, so it wouldn't be exactly the same as == on tuples. -- Greg From dmitrey15 at gmail.com Sat May 7 06:02:29 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Sat, 7 May 2011 03:02:29 -0700 (PDT) Subject: Python3: imports don't see files from same directory? Message-ID: hi all, I try to port my code to Python 3 and somehow files don't see files from same directory, so I have to add those directories explicitly, e.g. import sys sys.path += [...] Also, it leads to bugs like this one: http://groups.google.com/group/comp.lang.python/browse_thread/thread/961a90219a61e19d# any ideas what's the reason and how to fix it? I have tried to search google but got nothing yet. Thank you in advance, D. From greg.ewing at canterbury.ac.nz Sat May 7 06:04:06 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 22:04:06 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92kjooF31mU1@mid.individual.net> > On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote: > >>?x? is a name. Names are bound to values. Talk of ?variable? only >>confuses the issue because of the baggage carried with that term. But to use 'name' as a complete replacement for 'variable', you have to stretch it to include things like a[i], b.c, e.f(x).g[i:j].k, etc. which goes rather a long way beyond the everyday meaning of the word. In Python I use 'variable' to mean more or less 'something that can be assigned to', which accords with the way it's used in relation to many other languages, and doesn't suggest any restriction to things named by a single identifier. >>But the data model of Python doesn't fit well with the ideas that the >>term ?variable? connotes for most programmers: Seems to me that anyone taking that connotation from it has not yet been sufficiently educated about the Python data model itself. Part of explaining that data model consists of instilling the very idea that the things in Python that are analogous to variables in other languages only refer to data rather than containing the actual data. >>Saying ?variable? and ?has the value? But I don't say "has a value", I say "refers to". -- Greg From dmitrey15 at gmail.com Sat May 7 06:04:09 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Sat, 7 May 2011 03:04:09 -0700 (PDT) Subject: seems like a bug in isinstance() References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> <92kfkmF4d5U1@mid.individual.net> Message-ID: <619d1edd-4aeb-4c2d-a5c1-757f63e52bd5@d27g2000vbz.googlegroups.com> On May 7, 11:53?am, Gregory Ewing wrote: > Chris Rebert wrote: > > This is because you did `from Point import > > ...` in file2.py, whereas in file1.py you did `from > > openopt.kernel.Point import ...`. These 2 different ways of referring > > to the same module are sufficient to "trick"/"outsmart" (C)Python and > > cause it to import the same module twice > > That can't be the whole story, because those two ways of > referring to the module *should* have returned the same > module object, even though one is absolute and the other > relative. > > I suspect what's happened is that somehow sys.path contains > both the directory containing .../openopt *and* the directory > .../openopt/kernel, and the second import is picking up > Point.py a second time as though it were a top-level module. > > This could have happened by starting an interactive session > while cd'ed to .../openopt/kernel, or by launching a .py > file from there as a main script. > > The solution is to make sure that sys.path only contains the > top level directories of the package hierarchy, and doesn't > also contain any of their subdirectories. > > Always using absolute imports may be a good idea stylistically, > but in this case it will only mask the symptoms of whatever > is really wrong, and further problems could result from the > same cause. > > -- > Greg > I suspect what's happened is that somehow sys.path contains both the directory containing .../openopt *and* the directory .../openopt/kernel Yes, you are right. But I have to do it due to another issue I haven't solved yet: Python3 imports don't see files from same directory http://groups.google.com/group/comp.lang.python/browse_thread/thread/9470dbdacc138709# Regards, D. From greg.ewing at canterbury.ac.nz Sat May 7 06:09:42 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 22:09:42 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92kk36F31mU2@mid.individual.net> Andreas Tawn wrote: > If True and False: > waveFunction.collapse(cat) Call-by-entanglement would be interesting. Anything that the callee does to the parameter would affect the caller, but you would only be able to tell by examining a trace of the output afterwards. -- Greg From greg.ewing at canterbury.ac.nz Sat May 7 06:12:27 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 22:12:27 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92kk8bF31mU3@mid.individual.net> Grant Edwards wrote: > if you feel it just right and you have just the >>right synchro-mesh setup, you can slide from 3rd into 4th without >>every touching the clutch peddle... > >>and if that isn't automatic, I don't know what is.... > > No, that's _not_ automatic if you have to do it yourself. It's > automatic when it happens without user-intervention. Does it count if the transmission is activated by saying "Home, Jeeves"? -- Greg From nobody at nowhere.net.no Sat May 7 07:40:35 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 07 May 2011 19:40:35 +0800 Subject: A suggestion for an easy logger Message-ID: Hello, I've resumed my hold project and I like to convert it for py3k2. My knowledge has stagnated at version 2.4, then I found some improvements, but it will take me some time before I get used to. I was using this logger >> ========================================================================= class log: """ It outputs lists and strings on file or any possible device that allows write mode. Options are: output file writing mode and special end of line (EOL)""" def __init__(self, output= None, mode= 'w', lsp= EOL): """ Can instantiate even no output is given. Choose to build an open file object to append to, or new and give a different line separator""" self.lsp = lsp self.output= output self.mode= mode try: self.output= open(output, self.mode) except (IOError, TypeError): self.output = None def logger(self, strng, allowed=None): # without any output will simply send log to nowhere :-) if not allowed and not self.output: return # no allowed to write the output # keep silent even temporary skip writing # if allowed, it will go to stderr if isinstance(strng,list): a= EOL.join(strng)+ EOL strng = a strng= strng.replace(EOL,self.lsp) # when not allowed just return if allowed is None: return if strng == '?close?': try: # try to close the file self.output.close() return except IOError: return # silently ignore the failure if self.output and Exists(self.output): self.output.write(strng) else: sys.stderr.write(strng) sys.stderr.flush() return ========================================================================= It is somehow convulitive, isn't it? I do believe the builtin *print* would do more better than my logger. Basically I would like a class which shoudl do: 1) print to stdout either with or without carriage return 2) writing to a file 3) Skip some output Everything should do according to the caller. I didn't picked up the logging module, a way of confusion on my point of view. Some small example might easy my aberration :P -- goto /dev/null From invalid at invalid.invalid Sat May 7 08:03:47 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 7 May 2011 12:03:47 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kk8bF31mU3@mid.individual.net> Message-ID: On 2011-05-07, Gregory Ewing wrote: > Grant Edwards wrote: >> if you feel it just right and you have just the >>>right synchro-mesh setup, you can slide from 3rd into 4th without >>>every touching the clutch peddle... >> >>>and if that isn't automatic, I don't know what is.... >> >> No, that's _not_ automatic if you have to do it yourself. It's >> automatic when it happens without user-intervention. > > Does it count if the transmission is activated > by saying "Home, Jeeves"? Only if your name is Bertie Wooster. From nobody at nowhere.net.no Sat May 7 08:18:46 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 07 May 2011 20:18:46 +0800 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <92f7nuFfhhU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > because modern architectures are so freaking complicated > that it takes a computer to figure out the best instruction > sequence certainly is, I would not imagine one who writes on scraps of paper :D :D :D -- goto /dev/null From marian at sendung.de Sat May 7 08:24:33 2011 From: marian at sendung.de (Marian Steinbach) Date: Sat, 7 May 2011 14:24:33 +0200 Subject: Stuck with urllib.quote and Unicode/UTF-8 Message-ID: Hi! I am stuck with calling URLs with parameters containing non-ASCII characters. I'm creating a url like this. url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + urllib.quote(address) + '&sensor=false&language=DE' address can be a string like u"K?ln, Nordrhein-Westfalen". This results in http://maps.googleapis.com/maps/api/geocode/json?address=K%F6ln%2C%20Nordrhein-Westfalen&sensor=false&language=DE and this doesn't seem to meet Google's Encoding expectations. I get an "INVALID REQUEST" response. (The same things works if there are only ASCII characters in the address.) When I manually enter the "K?ln"... string in the Firefox address bar, Firefox makes the URL http://maps.googleapis.com/maps/api/geocode/xml?address=K%C3%B6ln,%20Nordrhein-Westfalen&sensor=false&language=DE out of this and it works fine. %C3%B6 seems to be the url-encoded representation of an UTF-8 representation of a "?" character. So the next thing I tried is to get address utf-8-encoded, like this: url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + urllib.quote(address.encode('utf-8')) + '&sensor=false&language=DE' This gives me an error like UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 1: ordinal not in range(128) Again, the input string for address is u"K?ln, Nordrhein-Westfalen". Can you see what I'm doing wrong or what I would have to to to get from u"?" to "%C3%B6"? Thanks! Marian From cpopa at bitdefender.com Sat May 7 08:31:33 2011 From: cpopa at bitdefender.com (Claudiu Popa) Date: Sat, 7 May 2011 15:31:33 +0300 Subject: Custom string joining Message-ID: <254518825.20110507153133@bitdefender.com> Hello Python-list, I have an object which defines some methods. I want to join a list or an iterable of those objects like this: new_string = "|".join(iterable_of_custom_objects) What is the __magic__ function that needs to be implemented for this case to work? I though that __str__ is sufficient but it doesn't seems to work. Thanks in advance. PC From marian at sendung.de Sat May 7 08:35:09 2011 From: marian at sendung.de (Marian Steinbach) Date: Sat, 7 May 2011 14:35:09 +0200 Subject: Stuck with urllib.quote and Unicode/UTF-8 In-Reply-To: References: Message-ID: An addition/correction: It seems as if my input variable address is not Unicode. This is what I get for print [address]: ['K\xf6ln, Nordrhein-Westfalen'] Isn't this utf-8 encoding? And I'm using Python 2.5.2. From clp2 at rebertia.com Sat May 7 10:14:55 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 7 May 2011 07:14:55 -0700 Subject: Stuck with urllib.quote and Unicode/UTF-8 In-Reply-To: References: Message-ID: On Sat, May 7, 2011 at 5:35 AM, Marian Steinbach wrote: > An addition/correction: > > It seems as if my input variable address is not Unicode. This is what > I get for print [address]: > > ['K\xf6ln, Nordrhein-Westfalen'] > > Isn't this utf-8 encoding? Nope, it's Latin-1 (or similar, e.g. Windows-1252): Python 2.7.1 (r271:86832, Dec 5 2010, 00:12:20) >>> x = u"K?ln" >>> x.encode('utf_8') 'K\xc3\xb6ln' >>> x.encode('latin_1') 'K\xf6ln' >>> Cheers, Chris -- http://rebertia.com From clp2 at rebertia.com Sat May 7 10:25:58 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 7 May 2011 07:25:58 -0700 Subject: Custom string joining In-Reply-To: <254518825.20110507153133@bitdefender.com> References: <254518825.20110507153133@bitdefender.com> Message-ID: On Sat, May 7, 2011 at 5:31 AM, Claudiu Popa wrote: > Hello Python-list, > > I ?have ?an object which defines some methods. I want to join a list or > an iterable of those objects like this: > > new_string = "|".join(iterable_of_custom_objects) > > What ? is ? the ? __magic__ ?function that needs to be implemented for > this case to work? ?I ?though ?that ?__str__ ?is sufficient but it doesn't seems to > work. Thanks in advance. You need to do the string conversion yourself; .join() doesn't do it for you, due to strong typing. It only accepts iterables of strings: new_string = "|".join(str(x) for x in iterable_of_custom_objects) Cheers, Chris -- http://rebertia.com From ian.g.kelly at gmail.com Sat May 7 10:54:23 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 7 May 2011 08:54:23 -0600 Subject: Coolest Python recipe of all time In-Reply-To: <4dc502e8$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc502e8$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 7, 2011 at 2:29 AM, Steven D'Aprano wrote: >> This isn't really amb; as you said it's just a brute-force solver with >> some weird syntax. ?The whole point of amb is to enable >> non-deterministic programming, such as this: > [...] >> The amb engine would conceptually execute this function for every >> possible combination of a, b, and c, > > Which pretty much is the definition of "brute-force solver", no? The "execute the function for every possible combination" part, yes. The "non-deterministic programming" part, no. From affdfsdfdsfsd at b.com Sat May 7 11:04:22 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 07 May 2011 15:04:22 GMT Subject: PyGTK notebook: get current page Message-ID: <4dc55f75$0$38638$4fafbaef@reader1.news.tin.it> Hi all! I've made a simple PyGTK program. It's a window with a notebook, the notebook have 2 pages When changing page, i'ld like to get the id of current page. I've coded it, but i can get only the previously open page, not the current one. This is not a big deal if i have only 2 pages, but it could be with 3 or more pages. Here's the code: #!/usr/bin/env python # -*- coding: utf-8 -*- # template di finestra in pyGTK import pygtk pygtk.require('2.0') import gtk class FinestraGTK: def pippo(self, widget, event, data=None): print "current page: " + str(self.nb.get_current_page() ) def delete_event(self, widget, event, data=None): print "delete event occurred" return False def destroy(self, widget, data=None): print "destroy signal occurred" gtk.main_quit() def __init__(self): self.w = gtk.Window(gtk.WINDOW_TOPLEVEL) self.w.connect("delete_event", self.delete_event) self.w.connect("destroy", self.destroy) self.w.set_border_width(10) self.w.set_default_size(455,460) # NOTEBOOK + LABELS self.nb = gtk.Notebook() self.nb_label1 = gtk.Label("page 0") self.nb_label2 = gtk.Label("page 1") # PAGE 1 self.b1 = gtk.Button("button tab 0") self.nb.insert_page(self.b1, self.nb_label1, 0) # PAGE 2 self.b2 = gtk.Button("button tab 1") self.nb.insert_page(self.b2, self.nb_label2, 1) self.w.add(self.nb) self.nb.connect("switch-page", self.pippo) self.b1.connect("clicked", self.pippo, "") self.b2.connect("clicked", self.pippo, "") self.w.show_all() def main(self): gtk.main() if __name__ == "__main__": hello = FinestraGTK() hello.main() any hint? i know it's all about correctly temporize signals, but i don't know how to accompliesh this many thanks regards sorry for my english Nico From ian.g.kelly at gmail.com Sat May 7 11:07:37 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 7 May 2011 09:07:37 -0600 Subject: Python3: imports don't see files from same directory? In-Reply-To: References: Message-ID: On Sat, May 7, 2011 at 4:02 AM, dmitrey wrote: > hi all, > I try to port my code to Python 3 and somehow files don't see files > from same directory, so I have to add those directories explicitly, > e.g. > import sys > sys.path += [...] > > Also, it leads to bugs like this one: > http://groups.google.com/group/comp.lang.python/browse_thread/thread/961a90219a61e19d# > > any ideas what's the reason and how to fix it? > I have tried to search google but got nothing yet. Implicit relative imports were removed in Python 3 to prevent ambiguity as the number of packages grows. See PEP 328. If you have two modules in the same package, pack1.mod1 and pack1.mod2, then in pack1.mod1 you can no longer just do "import mod2" or "from mod2 import foo". Either use an absolute import ("from pack1.mod2 import foo") or make the relative import explicit ("from .mod2 import foo" -- note the ".") If you're upgrading scripts from Python 2 to Python 3, you should really run them through the 2to3 tool. I believe this is one of the many things it will fix for you automatically. From jlsphar at gmail.com Sat May 7 11:20:32 2011 From: jlsphar at gmail.com (John) Date: Sat, 7 May 2011 08:20:32 -0700 (PDT) Subject: Django/AppEngine DevSoup Message-ID: Sooo I have a windows box... which I like to think is the reason I'm a django/appengine mess right now. There's eclipse, pydev, django non-rel, mediagenerator, etc.... Would it be stupid of me to just use the simple, clean notepad++ & django with aims to port into appengine after I finish in a week? I don't want to deal with all of the other stuff. Will this come back to haunt me in 7 days? Yours frazzled, John From emato at nothere.tampabay.com Sat May 7 14:29:41 2011 From: emato at nothere.tampabay.com (emato) Date: Sat, 7 May 2011 14:29:41 -0400 Subject: Python IDE/text-editor References: Message-ID: <4dc58fa3$0$8718$9a6e19ea@unlimited.newshosting.com> > On Apr 16, 1:20 pm, Alec Taylor wrote: > >> I'm looking for an IDE which offers syntax-highlighting, >> code-completion, tabs, gedit http://projects.gnome.org/gedit/index.html From andrew at acooke.org Sat May 7 15:03:28 2011 From: andrew at acooke.org (andrew cooke) Date: Sat, 7 May 2011 12:03:28 -0700 (PDT) Subject: ABC-registered Exceptions are not caught as subclasses Message-ID: <69a952d2-55c8-4328-85de-47f51ef53d32@glegroupsg2000goo.googlegroups.com> This isn't hugely surprising, but doesn't seem to be documented. Is it a bug, or worth raising as one, or have I misunderstood? Python 3.2 (r32:88445, Feb 27 2011, 13:00:05) [GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from abc import ABCMeta >>> class RootException(Exception,metaclass=ABCMeta): pass ... >>> class MyException(Exception): pass ... >>> RootException.register(MyException) >>> try: ... raise MyException ... except RootException: ... print('caught') ... Traceback (most recent call last): File "", line 2, in __main__.MyException If you assume that the ABC "register" class should work likeinheritance (as it does with issubclass and isinstance then you would, I think, have expected the exception above to have been caught. Andrew From ben+python at benfinney.id.au Sat May 7 16:09:19 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 May 2011 06:09:19 +1000 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> Message-ID: <87aaeymfww.fsf@benfinney.id.au> Gregory Ewing writes: > > On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote: > > > >>?x? is a name. Names are bound to values. Talk of ?variable? only > >>confuses the issue because of the baggage carried with that term. > > But to use 'name' as a complete replacement for 'variable', I don't propose doing that. > In Python I use 'variable' to mean more or less 'something that can be > assigned to', which accords with the way it's used in relation to many > other languages, and doesn't suggest any restriction to things named > by a single identifier. No, I think not. The term ?variable? usually comes with a strong expectation that every variable has exactly one name. Your more broad usage would need to be carefully explained to newbies anyway, so I don't see a good reason to use the term ?variable? for that either. > Seems to me that anyone taking that connotation from it has not yet > been sufficiently educated about the Python data model itself. Yes, of course. But why not meet such newcomers partway, by not confusing the issue with a term which needs such delicate treatment? > >>Saying ?variable? and ?has the value? > > But I don't say "has a value", I say "refers to". Good for you. Most don't. -- \ Q: ?I've heard that Linux causes cancer...? Torvalds: ?That's a | `\ filthy lie. Besides, it was only in rats and has not been | _o__) reproduced in humans.? ?Linus Torvalds | Ben Finney From roy at panix.com Sat May 7 16:24:26 2011 From: roy at panix.com (Roy Smith) Date: Sat, 07 May 2011 16:24:26 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> <87aaeymfww.fsf@benfinney.id.au> Message-ID: In article <87aaeymfww.fsf at benfinney.id.au>, Ben Finney wrote: > No, I think not. The term ???variable??? usually comes with a strong > expectation that every variable has exactly one name. Heh. You've never used common blocks in Fortran? Or, for that matter, references in C++? I would call either of those "two names for the same variable". From python at rcn.com Sat May 7 17:02:10 2011 From: python at rcn.com (Raymond Hettinger) Date: Sat, 7 May 2011 14:02:10 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc502e8$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 7, 1:29?am, Steven D'Aprano wrote: > On Fri, 06 May 2011 12:36:09 -0600, Ian Kelly wrote: > > The amb engine would conceptually execute this function for every > > possible combination of a, b, and c, > > Which pretty much is the definition of "brute-force solver", no? FWIW, here's one of my favorite brute-force solvers: http://code.activestate.com/recipes/576615-alphametics-solver/ Raymond ------- follow my recipes and tips on twitter: @raymondh From no.email at nospam.invalid Sat May 7 17:07:38 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 07 May 2011 14:07:38 -0700 Subject: dictionary size changed during iteration References: <4DAED72B.2030400@shopzeus.com> Message-ID: <7xd3jukyn9.fsf@ruckus.brouhaha.com> Roy Smith writes: > changes = [ ] > for key in d.iterkeys(): > if is_bad(key): > changes.append(key) changes = list(k for k in d if is_bad(k)) is a little bit more direct. From alex.kapps at web.de Sat May 7 18:05:16 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Sun, 08 May 2011 00:05:16 +0200 Subject: PyGTK notebook: get current page In-Reply-To: <4dc55f75$0$38638$4fafbaef@reader1.news.tin.it> References: <4dc55f75$0$38638$4fafbaef@reader1.news.tin.it> Message-ID: <4DC5C21C.6030107@web.de> On 07.05.2011 17:04, Tracubik wrote: > Hi all! > I've made a simple PyGTK program. > It's a window with a notebook, the notebook have 2 pages > When changing page, i'ld like to get the id of current page. > > I've coded it, but i can get only the previously open page, not the > current one. This is not a big deal if i have only 2 pages, but it could > be with 3 or more pages. > > Here's the code: > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > # template di finestra in pyGTK > > import pygtk > pygtk.require('2.0') > import gtk > > class FinestraGTK: > > def pippo(self, widget, event, data=None): > print "current page: " + str(self.nb.get_current_page() ) According to PyGTK docs, the event handler for the switch_page signal should look like this: def pippo(self, notebook, page, page_num, user_data=None): ... With this method you get the new page number in page_num (or in your original method with the misleadingly named "data" argument) HTH From roy at panix.com Sat May 7 18:12:21 2011 From: roy at panix.com (Roy Smith) Date: Sat, 07 May 2011 18:12:21 -0400 Subject: dictionary size changed during iteration References: <4DAED72B.2030400@shopzeus.com> <7xd3jukyn9.fsf@ruckus.brouhaha.com> Message-ID: In article <7xd3jukyn9.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Roy Smith writes: > > changes = [ ] > > for key in d.iterkeys(): > > if is_bad(key): > > changes.append(key) > > changes = list(k for k in d if is_bad(k)) > > is a little bit more direct. This is true. I still file list comprehensions under "new fangled toys". While I use them, and appreciate their value, I admit they're not always the first thing that comes to my mind. OBTW, > changes = [k for k in d if is_bad(k)] is even more direct :-) From greg.ewing at canterbury.ac.nz Sat May 7 18:39:39 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 08 May 2011 10:39:39 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> Message-ID: <92m01eFeilU1@mid.individual.net> Chris Angelico wrote: > I think "manipulate" here means things like pointer arithmetic, I don't believe that allowing arithmetic on pointers is a prerequisite to considering them first-class values. You can't do arithmetic on pointers in Pascal, for example, but nobody argues that Pascal pointers are not values. -- Greg From stef.mientki at gmail.com Sat May 7 18:40:20 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 08 May 2011 00:40:20 +0200 Subject: is there an autocompletion like Dasher ? Message-ID: <4DC5CA54.7010606@gmail.com> hello, I would like to have a autocompletion / help /snippet system like Dasher : http://www.inference.phy.cam.ac.uk/dasher/ anyone seen such a component ? thanks, Stef From greg.ewing at canterbury.ac.nz Sat May 7 18:54:57 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 08 May 2011 10:54:57 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <87aaeymfww.fsf@benfinney.id.au> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> <87aaeymfww.fsf@benfinney.id.au> Message-ID: <92m0u4Fkl5U1@mid.individual.net> Ben Finney wrote: > No, I think not. The term ?variable? usually comes with a strong > expectation that every variable has exactly one name. I would say that many variables don't have names *at all*, unless you consider an expression such as a[i] to be a "name". And if you *do* consider that to be a name, then clearly one variable can have a great many names. What would *you* call a[i]? -- Greg From greg.ewing at canterbury.ac.nz Sat May 7 18:58:39 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 08 May 2011 10:58:39 +1200 Subject: seems like a bug in isinstance() In-Reply-To: <619d1edd-4aeb-4c2d-a5c1-757f63e52bd5@d27g2000vbz.googlegroups.com> References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> <92kfkmF4d5U1@mid.individual.net> <619d1edd-4aeb-4c2d-a5c1-757f63e52bd5@d27g2000vbz.googlegroups.com> Message-ID: <92m151Fm76U1@mid.individual.net> dmitrey wrote: > Yes, you are right. But I have to do it due to another issue I haven't > solved yet: Python3 imports don't see files from same directory > http://groups.google.com/group/comp.lang.python/browse_thread/thread/9470dbdacc138709# That's because the syntax for relative imports has changed in Python 3. See the recent comment on your posting there for details. -- Greg From greg.ewing at canterbury.ac.nz Sat May 7 19:04:53 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 08 May 2011 11:04:53 +1200 Subject: Django/AppEngine DevSoup In-Reply-To: References: Message-ID: <92m1goFoinU1@mid.individual.net> John wrote: > There's eclipse, pydev, django non-rel, mediagenerator, etc.... > > Would it be stupid of me to just use the simple, clean notepad++ & > django with aims to port into appengine after I finish in a week? I > don't want to deal with all of the other stuff. Will this come back to > haunt me in 7 days? I'd say you definitely don't need Eclipse, and probably don't need the other stuff. I've being doing all my Python coding using relatively dumb text editors for many years, including maintaining a django-based site, and haven't suffered any hauntings so far. :-) -- Greg From drsalists at gmail.com Sat May 7 19:28:12 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 7 May 2011 16:28:12 -0700 Subject: is there an autocompletion like Dasher ? In-Reply-To: <4DC5CA54.7010606@gmail.com> References: <4DC5CA54.7010606@gmail.com> Message-ID: On Sat, May 7, 2011 at 3:40 PM, Stef Mientki wrote: > hello, > > I would like to have a autocompletion / help /snippet system like Dasher : > > http://www.inference.phy.cam.ac.uk/dasher/ > > anyone seen such a component ? > Ummm... For what OS and what hardware? Do you need something that was written in Python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat May 7 19:43:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 May 2011 09:43:28 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <92m0u4Fkl5U1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> <87aaeymfww.fsf@benfinney.id.au> <92m0u4Fkl5U1@mid.individual.net> Message-ID: On Sun, May 8, 2011 at 8:54 AM, Gregory Ewing wrote: > Ben Finney wrote: > >> No, I think not. The term ?variable? usually comes with a strong >> expectation that every variable has exactly one name. > > I would say that many variables don't have names *at all*, > unless you consider an expression such as a[i] to be > a "name". And if you *do* consider that to be a name, > then clearly one variable can have a great many names. > > What would *you* call a[i]? a is a variable; i is a variable; a[i] is an expression. It's not a single name, and if you had two variables i and j with the same value, nobody would disagree that a[i] and a[j] ought to be the same thing. That's the whole point of arrays/lists/etc/etc. But if you want to fry your noggin, wrap your head around REXX's compound variables: a=5 b=3 array.a.b="Hello" /* see, this is a two-dimensional array */ c=63/10 array.c="world!" /* see, we can have non-integers as array indices */ d=a+1 result = array.a.b", "array.d.b /* "Hello, world!" */ So what is a "name" in REXX? You have to evaluate the compound variable as a set of tokens, then evaluate the whole thing again, and is that the name? Because the resulting "name" might not be a valid identifier... Yep, it's good stuff. Chris Angelico From stef.mientki at gmail.com Sat May 7 19:56:52 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 08 May 2011 01:56:52 +0200 Subject: is there an autocompletion like Dasher ? In-Reply-To: References: <4DC5CA54.7010606@gmail.com> Message-ID: <4DC5DC44.3030208@gmail.com> On 08-05-2011 01:28, Dan Stromberg wrote: > > On Sat, May 7, 2011 at 3:40 PM, Stef Mientki > wrote: > > hello, > > I would like to have a autocompletion / help /snippet system like Dasher : > > http://www.inference.phy.cam.ac.uk/dasher/ > > anyone seen such a component ? > > > Ummm... For what OS and what hardware? Windows desktop (and webbrowser would be nice) > Do you need something that was written in Python? > > preferable thanks, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From noah.mcilraith at gmail.com Sat May 7 20:00:11 2011 From: noah.mcilraith at gmail.com (mcilrain) Date: Sat, 7 May 2011 17:00:11 -0700 (PDT) Subject: A suggestion for an easy logger In-Reply-To: Message-ID: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> Aside from the fact that it's very Javay, what's wrong with the logging module? From ben+python at benfinney.id.au Sat May 7 21:16:40 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 May 2011 11:16:40 +1000 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> <87aaeymfww.fsf@benfinney.id.au> <92m0u4Fkl5U1@mid.individual.net> Message-ID: <8762pmm1on.fsf@benfinney.id.au> Gregory Ewing writes: > Ben Finney wrote: > > > No, I think not. The term ?variable? usually comes with a strong > > expectation that every variable has exactly one name. > > I would say that many variables don't have names *at all*, unless you > consider an expression such as a[i] to be a "name". Again, our disagreement is not over the behaviour of Python, but over what an average newcomer to Python can be expected to understand by the term ?variable? from its usage elsewhere in programming. > What would *you* call a[i]? What *I* would call that isn't relevant to the point. I do think it's even more misleading to call that ?a variable?, though, since it's not what the Python docs call a variable and it's not what an average newcomer would call a variable. It's a reference. So is ?a?, so is ?i?; names are a special kind of reference. In Python, references are how we get at objects within our code, and names are one kind of reference. -- \ ?Not using Microsoft products is like being a non-smoker 40 or | `\ 50 years ago: You can choose not to smoke, yourself, but it's | _o__) hard to avoid second-hand smoke.? ?Michael Tiemann | Ben Finney From clp2 at rebertia.com Sat May 7 22:03:35 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 7 May 2011 19:03:35 -0700 Subject: ABC-registered Exceptions are not caught as subclasses In-Reply-To: <69a952d2-55c8-4328-85de-47f51ef53d32@glegroupsg2000goo.googlegroups.com> References: <69a952d2-55c8-4328-85de-47f51ef53d32@glegroupsg2000goo.googlegroups.com> Message-ID: On Sat, May 7, 2011 at 12:03 PM, andrew cooke wrote: > > This isn't hugely surprising, but doesn't seem to be documented. ?Is it a bug, or worth raising as one, or have I misunderstood? > > > Python 3.2 (r32:88445, Feb 27 2011, 13:00:05) > [GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from abc import ABCMeta >>>> class RootException(Exception,metaclass=ABCMeta): pass > ... >>>> class MyException(Exception): pass > ... >>>> RootException.register(MyException) >>>> try: > ... ? ? raise MyException > ... except RootException: > ... ? ? print('caught') > ... > Traceback (most recent call last): > ?File "", line 2, in > __main__.MyException > > If you assume that the ABC "register" class should work likeinheritance (as it does with issubclass and isinstance then you would, I think, have expected the exception above to have been caught. Seems worth filing a bug IMO; it probably deserves clarification in the docs if nothing else, though this behavior isn't inconsistent with them as they're currently written (due to the vagaries of natural language). Cheers, Chris From steve+comp.lang.python at pearwood.info Sat May 7 22:17:38 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2011 02:17:38 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> Message-ID: <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 May 2011 21:21:45 +1200, Gregory Ewing wrote: > Hans Georg Schaathun wrote: > >> You cannot reference nor manipulate a reference in python, and that >> IMHO makes them more abstract. > > You can manipulate them just fine by moving them from one place to > another: > > a = b I see no reference there, nor do I see any moving taking place. What I see is a name binding operation. What is happening is that the name "a" is being bound to the object "b" (or to be precise, to whatever object is currently bound to name "b"). Since you haven't explained what you think is happening, I can only guess. My guess is that you are thinking about some implementation of the Python VM which uses some sort of reference internally. Perhaps it's CPython, which uses pointers, or some C++ implementation which actually uses an indirect pointer-like data structure called "reference", or maybe even some old-time FORTRAN I implementation that simulates pointers with integer indexes into a fixed size array. It could be anything. But whatever you're thinking of, it's not the behaviour of *Python* code, it's behaviour of the Python virtual machine's implementation. It astonishes me how hard it is to distinguish between abstraction levels when discussing computer languages. We don't have this problem in other fields. Nobody talking about (say) Solitaire on a computer would say: "Blat the pixels in the rect A,B,C,D to the rect E,F,G,H. That will free up the Ace of Spades and allow you to memcopy the records in the far right column of the tableau into the foundation." but when it comes to high-level computer languages like Python, we do the equivalent *all the time*. (I include myself in this.) And people get into (often angry) arguments over definitions, when what they're really arguing about is what is happening at different abstraction levels. A simplified view: At the Python level: binding of objects to names. No data is copied except by use of a direct "copy" instruction, e.g. slicing. At the Python VM level: objects pushed and popped from a stack. At the VM implementation level: Name binding may be implemented by copying pointers, or some other reference, in some data structure representing name spaces. Or by any other mechanism you like, so long as the behaviour at the Python level is the same. At the assembly language level: memory is copied from one address to another. At the hardware level: we usually describe bit manipulation in terms of binary AND, XOR and OR, but even that may be an abstraction: it's possible that the only binary op physically used by the machine is NAND. -- Steven From vinay_sajip at yahoo.co.uk Sat May 7 22:27:17 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 7 May 2011 19:27:17 -0700 (PDT) Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> Message-ID: On May 8, 1:00?am, mcilrain wrote: > Aside from the fact that it's very Javay, what's wrong with theloggingmodule? It's not especially Java-like. Since you can log using just import logging logging.basicConfig(level=logging.DEBUG) logging.debug('This is %sic, not %s-like - that's FUD', 'Python', 'Java') it doesn't seem especially Java-like: no factories, Interfaces, builders, using plain functions etc. The second line is optional and needed only if you want to log DEBUG or INFO messages (as the default threshold is WARNING). Despite other logging libraries claiming to be more Pythonic, they have pretty much the same concepts as stdlib logging - because those concepts are tied to logging, not to Java. Call it correlation vs. causation, or convergent evolution, or what you will. Regards, Vinay Sajip From gnarlodious at gmail.com Sat May 7 22:55:21 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 7 May 2011 19:55:21 -0700 (PDT) Subject: Py 3.2: sqlite can't operate on a closed cursor Message-ID: <2ba90070-ee5e-4388-a713-c612a7419db0@s16g2000prf.googlegroups.com> I installed Python 3.2, suddenly getting an error on my sqlite pages (CGI): ProgrammingError: Cannot operate on a closed cursor Works normally in interactive mode. Seems to error when the sqlite statement is in a function. Are sqlite objects now required to be declared global? -- Gnarlie From gnarlodious at gmail.com Sat May 7 23:17:57 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 7 May 2011 20:17:57 -0700 (PDT) Subject: Py 3.2: sqlite can't operate on a closed cursor References: <2ba90070-ee5e-4388-a713-c612a7419db0@s16g2000prf.googlegroups.com> Message-ID: It turns out Python 3.2 now honors closing sqlite connections opened in another module. Previous versions allowed you to have identically named sqlite connections open in other modules. Python 3.2 apparently treats them all as the same connection. Hopefully some other victim will find this, because it wasn't written in the documentation http://docs.python.org/dev/whatsnew/3.2.html#sqlite3 -- Gnarlie From harrismh777 at charter.net Sat May 7 23:50:55 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 07 May 2011 22:50:55 -0500 Subject: checking if a list is empty In-Reply-To: <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> ... if not li says nothing about what li is supposed to 'be' > Yes, and? Neither does: > > isempty(li) # li could be anything that polymorphic isempty can deal with > li.isempty() # li could be anything with a "isempty" method > len(li) == 0 # li could be anything with a length (list, dict, set, ...) Sure. > That's duck-typing for you, and it is generally a strength rather than a > weakness. For those times when it is a weakness, that's where we have > naming conventions, type-testing, and (in some languages) static types. I can fix almost anything with duck-type... :) >> > and implies in any case that li does not exist > It does nothing of the sort. If li doesn't exist, you get a NameError. That was the point. 'not' implies something that is not logical; which is irony extreme since 'not' is typically considered a logical operator. What does it mean to say not ? Well, apparently it means the list is 'empty'... but why should it mean that? Why not have it mean the list has been reversed in place? Why not have it mean that the list isn't homogeneous? Why not have it mean that its not mutable? I could think of more... Why should 'not' mean 'empty'? >> > or worse is some kind of boolean. > Only if you're still thinking in some language that isn't Python. Which most of us are... hate to remind you... Python is the new kid on the block, and most of us are coming at this from multiple filters in comp sci experience. Its just the truth. >> > Why not have a list method that makes this more explicit: > For the same reason that we don't have an int method that makes zero > testing more explicit: > Because sometimes you can have too much explicitness. True. kind regards, m harris From harrismh777 at charter.net Sun May 8 00:10:54 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 07 May 2011 23:10:54 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Nobody talking about (say) Solitaire on a computer would say: > > "Blat the pixels in the rect A,B,C,D to the rect E,F,G,H. That will free > up the Ace of Spades and allow you to memcopy the records in the far > right column of the tableau into the foundation." > > but when it comes to high-level computer languages like Python, we do the > equivalent *all the time*. I find exception to that argument. That is an example of the bogus analogy fallacy. (I am offering this in friendship, actually). The two cases have nothing to do with one another, do not affect one another directly or indirectly, and are not helpful for comparison sake. Analogies are generally not helpful in discussion and ought to be avoided generally... except for entertainment sake... and frankly I have found many of your analogies most entertaining (and creative) ! Second point, we seldom do anything *all the time* / this is a fallacy that presupposes extreme references, as we think about the argument; extreme exageration is not helpful... may or may not be rightly extreme, and may or may not be relevant. What can be said (about the argument) is that we sometimes waste time arguing over abstraction layers with limited cross-dependent understanding. (I include myself in this.) (myself, as well) ... the humility is appreciated. > And people get > into (often angry) arguments over definitions, when what they're really > arguing about is what is happening at different abstraction levels. Sometimes. More often than not, folks are not really angry (I am seldom angry at my computer terminal... its one of the places where I relax, learn, communicate, and relate with other computer scientists who enjoy what they do because its enjoyable. I do agree with you that we all sometimes talk past each other because we're arguing from within a 'different' level of abstraction. kind regards, m harris From nobody at nowhere.net.no Sun May 8 00:49:21 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 08 May 2011 12:49:21 +0800 Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> Message-ID: Vinay Sajip wrote: WoW :O , the creator !! > import logging > > logging.basicConfig(level=logging.DEBUG) I'm getting there, but the result it's not what I would. As far as I got to know, it should take to write a configuration file, which I still not aware of. I'd like to just have the 4 conditions mentioned in the first post. Once I'll get into the dirt I'll try to bring up also the other features that logging module gives. -- goto /dev/null From ethan at stoneleaf.us Sun May 8 00:57:13 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 07 May 2011 21:57:13 -0700 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DC622A9.4010000@stoneleaf.us> harrismh777 wrote: > Steven D'Aprano wrote: >>> attribution lost wrote: >>> > and implies in any case that li does not exist >> It does nothing of the sort. If li doesn't exist, you get a NameError. > > That was the point. 'not' implies something that is not logical; > which is irony extreme since 'not' is typically considered a logical > operator. What does it mean to say not ? Well, apparently > it means the list is 'empty'... but why should it mean that? Why not > have it mean the list has been reversed in place? Why not have it mean > that the list isn't homogeneous? Why not have it mean that its not > mutable? I could think of more... Why should 'not' mean 'empty'? Because this is Python, and in Python that's what it means. > >>> > or worse is some kind of boolean. >> Only if you're still thinking in some language that isn't Python. > > Which most of us are... hate to remind you... Python is the new kid > on the block, and most of us are coming at this from multiple filters in > comp sci experience. Its just the truth. And your point would be? If you're going to use a language, and use it well, you have to learn how that language works. ~Ethan~ From robert.brown at gmail.com Sun May 8 01:44:13 2011 From: robert.brown at gmail.com (Robert Brown) Date: Sun, 08 May 2011 01:44:13 -0400 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87hb9521ci.fsf@ugg.bibliotech.com> Steven D'Aprano writes: > If you value runtime efficiency over development time, sure. There are > plenty of languages which have made that decision: Pascal, C, Java, > Lisp, Forth, and many more. I don't understand why you place Lisp and Forth in the same category as Pascal, C, and Java. Lisp and Forth generally have highly interactive development environments, while the other languages generally require an edit, compile, run it again debugging cycle. Lisp in particular does a better job than Python in optimizing developer time. I can change class definitions interactively without restarting my program. I can add type declarations to a single function and recompile it without restarting my program. Python requires me to rewrite the slow bits of my program in C to get good performance. Why is that an efficient use of developer time? bob From rustompmody at gmail.com Sun May 8 01:48:20 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 7 May 2011 22:48:20 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1cf03d24-5e64-4770-a03b-b82978b35a6b@y27g2000prb.googlegroups.com> On May 8, 7:17?am, Steven D'Aprano wrote: > On Sat, 07 May 2011 21:21:45 +1200, Gregory Ewing wrote: > > Hans Georg Schaathun wrote: > > >> You cannot reference nor manipulate a reference in python, and that > >> IMHO makes them more abstract. > > > You can manipulate them just fine by moving them from one place to > > another: > > > ? ? a = b > > I see no reference there, nor do I see any moving taking place. What I > see is a name binding operation. What is happening is that the name "a" > is being bound to the object "b" (or to be precise, to whatever object is > currently bound to name "b"). > > Since you haven't explained what you think is happening, I can only > guess. My guess is that you are thinking about some implementation of the > Python VM which uses some sort of reference internally. Perhaps it's > CPython, which uses pointers, or some C++ implementation which actually > uses an indirect pointer-like data structure called "reference", or maybe > even some old-time FORTRAN I implementation that simulates pointers with > integer indexes into a fixed size array. It could be anything. > > But whatever you're thinking of, it's not the behaviour of *Python* code, > it's behaviour of the Python virtual machine's implementation. > > It astonishes me how hard it is to distinguish between abstraction levels > when discussing computer languages. We don't have this problem in other > fields. Nobody talking about (say) Solitaire on a computer would say: > > "Blat the pixels in the rect A,B,C,D to the rect E,F,G,H. That will free > up the Ace of Spades and allow you to memcopy the records in the far > right column of the tableau into the foundation." > > but when it comes to high-level computer languages like Python, we do the > equivalent *all the time*. It has to be so -- because the Turing machine like the modern computer is an unbelievable abstraction squasher. Yes unbelievable in the sense that people simply cant come to terms with this. [Witness your "It astonishes me..." Harris: "I take exception.." etc] The modern computer (von Neumann) <- self-modifying code <- Data=Code <- Undecidability (Halting problem) <- Consistency XOR Completeness (Godels theorem(s)) <- Leaky Abstractions as inevitable If anyone thinks Godels theorems are easy trivial, he probably does not know what he is talking about, Yet we think that computers are easy to understand? [Ive personally witnessed PhDs in computer science not appreciate compilers' inability to do certain things, and yet they could go and take a bunch of lectures on the halting problem. What they understand is anybody's guess :-) ] Coming back to topic: The argument (about bindings, variables etc) arises because python (like lisp) is an imperative language masquerading as a functional one. Such arguments dont arise in Haskell or in assembly language. They arise and are tolerable in C. They are terrible in C++ because all the abstractions are built to leak. Where python sits in this (circular) spectrum is an interesting question (and I watch the arguments with much interest) From research at johnohagan.com Sun May 8 02:04:30 2011 From: research at johnohagan.com (John O'Hagan) Date: Sun, 8 May 2011 06:04:30 +0000 Subject: Python3: imports don't see files from same directory? In-Reply-To: References: Message-ID: <201105080604.31146.research@johnohagan.com> On Sat, 7 May 2011, Ian Kelly wrote: [...] > > Implicit relative imports were removed in Python 3 to prevent > ambiguity as the number of packages grows. See PEP 328. > > If you have two modules in the same package, pack1.mod1 and > pack1.mod2, then in pack1.mod1 you can no longer just do "import mod2" > or "from mod2 import foo". Either use an absolute import ("from > pack1.mod2 import foo") or make the relative import explicit ("from > .mod2 import foo" -- note the ".") > > If you're upgrading scripts from Python 2 to Python 3, you should > really run them through the 2to3 tool. I believe this is one of the > many things it will fix for you automatically. For some reason I haven't fathomed yet, I've found that while 2to3 does change the import syntax to the dot form as you say, this results in "ValueError: Attempted relative import in non-package", and I have to change it back to the old way, which works fine although the docs say it shouldn't. This is python 3.2 on Debian testing. For example, if I have a directory containing an __init__.py file, and two modules, one of which is called mod1 and contains #!/usr/bin/python3 a=1 in the other module I can have import mod1 or from mod1 import a but not from .mod1 import a or import .mod1 What gives? From nobody at nowhere.net.no Sun May 8 02:15:57 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 08 May 2011 14:15:57 +0800 Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> Message-ID: TheSaint wrote: > I'd like to just have the 4 conditions mentioned in the first post. > OK, my analysis led me to the print() function, which would suffice for initial my purposes. Meanwhile I reading the tutorials, but I couldn't get how to make a formatter to suppress or keep the LF(CR) at the end of the statement. -- goto /dev/null From benjamin.kaplan at case.edu Sun May 8 02:24:03 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 7 May 2011 23:24:03 -0700 Subject: Python3: imports don't see files from same directory? In-Reply-To: <201105080604.31146.research@johnohagan.com> References: <201105080604.31146.research@johnohagan.com> Message-ID: On Sat, May 7, 2011 at 11:04 PM, John O'Hagan wrote: > On Sat, 7 May 2011, Ian Kelly wrote: > [...] >> >> Implicit relative imports were removed in Python 3 to prevent >> ambiguity as the number of packages grows. ?See PEP 328. >> >> If you have two modules in the same package, pack1.mod1 and >> pack1.mod2, then in pack1.mod1 you can no longer just do "import > mod2" >> or "from mod2 import foo". ?Either use an absolute import ("from >> pack1.mod2 import foo") or make the relative import explicit ("from >> .mod2 import foo" -- note the ".") >> >> If you're upgrading scripts from Python 2 to Python 3, you should >> really run them through the 2to3 tool. ?I believe this is one of the >> many things it will fix for you automatically. > > For some reason I haven't fathomed yet, I've found that while 2to3 > does change the import syntax to the dot form as you say, this results > in "ValueError: Attempted relative import in non-package", and I have > to change it back to the old way, which works fine although the docs > say it shouldn't. This is python 3.2 on Debian testing. > > For example, if I have a directory containing an __init__.py file, and two > modules, one of which is called mod1 and contains > > #!/usr/bin/python3 > a=1 > > in the other module I can have > > import mod1 > > or > > from ?mod1 import a > > but not > > from .mod1 import a > > or > > import .mod1 > > > What gives? * Absolute imports are given as modules coming straight from something on sys.path. If you actually check sys.path, you'll probably notice that '' is on there, which in this case refers to the current directory. * In order to do relative imports, you need to be in a package. Having an __init__.py somewhere does not automatically make it a package. To be a package, it has to be in one of the folders on sys.path. Since python doesn't have a name for that folder that __init__.py is in, it's not actually a part of a package. From rosuav at gmail.com Sun May 8 02:32:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 May 2011 16:32:04 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> <87aaeymfww.fsf@benfinney.id.au> <92m0u4Fkl5U1@mid.individual.net> Message-ID: On Sun, May 8, 2011 at 4:16 PM, Dennis Lee Bieber wrote: > On Sun, 08 May 2011 10:54:57 +1200, Gregory Ewing > declaimed the following in > gmane.comp.python.general: > >> >> What would *you* call a[i]? >> > ? ? ? ?Depending upon the nature of the beast, I'd be tempted to call it a > "fully qualified name" or a "partially qualified name" > > ? ? ? ?a = [1, 2, 4, ("c", "d", "e")] Why is an integer more or less important than a tuple? a[3] is no less qualified than a[2]; each of them points to an object. One of those objects happens to contain other objects. What if you had: stdio = [stdin, stdout, stderr] They might be 'file' objects, or they might be integers (unlikely in Python), or they could be pipes or other file-like objects, or they might be some kind of special tee object that contains two file objects. Let's say your standard I/O uses the notation stdout.write('message') and that you have a subclass of tuple that will apply the . operator to all its members (is that possible in Python? If not, pretend it is). You could then execute stdio[1]=(stdout,teeobject) to easily copy your screen output to another file. At this point, you can actually pretend that stdio[0] and stdio[1] are identical objects, but you can use stdio[1][1] and you can't use stdio[0][1] - which means that, per your definition, one of them is only partially qualified. As Inigo Montoya said, there is too much - let me sum up. Lists/tuples and integers are equally objects, so whether or not you have a 'name' is not affected by what type of object it points to. Chris Angelico From rustompmody at gmail.com Sun May 8 03:43:37 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 8 May 2011 00:43:37 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <7ab08d8c-3af0-4292-8f6b-68b912762474@d19g2000prh.googlegroups.com> On Apr 26, 7:39?pm, snorble wrote: > I'm not a Pythonista, but I aspire to be. > > My current tools: > > Python, gvim, OS file system > > My current practices: > > When I write a Python app, I have several unorganized scripts in a > directory (usually with several named test1.py, test2.py, etc., from > random ideas I have tested), and maybe a todo.txt file. Then I hack > away, adding features in a semi-random order. Then I get busy with > other things. Maybe one week I spend 20 hours on development. The next > week, no time on development. A few weeks later when I have some time, > I'm excited to get back to making progress, only to find that I have > to spend 30-60 minutes figuring out where I left off. The code is > usually out of sync with todo.txt. I see people who release new > versions and bug fixes, so I sometimes will create a new directory and > continue working from that copy, because it seems like the thing to > do. But if I ever made something worth releasing, and got a request > like, "I have problems with the 2.0 version. Can you send me the old > 1.1 version?" I'd be like, "uhhh... let me hunt through my files by > hand and get back to you in a month". I'm thinking I can do a lot > better than this. > > I am aware of tools like version control systems, bug trackers, and > things like these, but I'm not really sure if I need them, or how to > use them properly. I think having some organization to all of this > would help me to make more consistent progress, and spend less time > bringing myself up to speed after some time off. > > I really like the idea of having a list of features, and tackling > those features one at a time. I read about people who do this, and > each new features gets a new minor version number. It sounds very > organized and clean. But I'm not really sure of the best way to > achieve this. Mainly I think I just need some recommendations to help > create a good mental map of what needs to happen, and mapping jargon > to concepts. Like, "each feature gets its own directory". Or with a > version control tool, I don't know if a feature maps to a branch, or a > commit? > > I appreciate any advice or guidance anyone has to offer. Recently saw this: [Disclaimer: Not tried] http://labs.creativecommons.org/2010/11/10/bridging-public-bugtrackers-and-local-tasklists/ From andrew at acooke.org Sun May 8 04:55:08 2011 From: andrew at acooke.org (andrew cooke) Date: Sun, 8 May 2011 01:55:08 -0700 (PDT) Subject: ABC-registered Exceptions are not caught as subclasses In-Reply-To: Message-ID: <3638ce9d-a1c0-4f3f-9a76-84103244a6e5@glegroupsg2000goo.googlegroups.com> http://bugs.python.org/issue12029 From andrew at acooke.org Sun May 8 04:55:08 2011 From: andrew at acooke.org (andrew cooke) Date: Sun, 8 May 2011 01:55:08 -0700 (PDT) Subject: ABC-registered Exceptions are not caught as subclasses In-Reply-To: Message-ID: <3638ce9d-a1c0-4f3f-9a76-84103244a6e5@glegroupsg2000goo.googlegroups.com> http://bugs.python.org/issue12029 From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sun May 8 05:23:48 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sun, 08 May 2011 11:23:48 +0200 Subject: Dictionary Views -- good examples? [was Re: Python 3 dict question] In-Reply-To: <92kghnFb37U1@mid.individual.net> References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> <92kghnFb37U1@mid.individual.net> Message-ID: Am 07.05.2011 11:09, schrieb Gregory Ewing: > Ethan Furman wrote: >> Ian Kelly wrote: >> >>> next(iter(myDict.items())) >> >> Which is becoming less elegant. > > If you're doing this sort of thing a lot you can make > a little helper function: > > def first(x): > return next(iter(x)) > > then you get to say > > first(myDict.items()) ... and get a StopIteration if the dict is empty. If you do def first(x, default=None): for i in x: return i return default you might have an alternative approach to do so. Thomas From vinay_sajip at yahoo.co.uk Sun May 8 06:26:18 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 8 May 2011 03:26:18 -0700 (PDT) Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> Message-ID: <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> On May 8, 7:15?am, TheSaint wrote: > OK, my analysis led me to the print() function, which would suffice for > initial my purposes. The logging HOWTO tells you when to use logging, warnings and print(): http://docs.python.org/howto/logging.html > Meanwhile I reading the tutorials, but I couldn't get how to make a > formatter to suppress or keep the LF(CR) at the end of the statement. For Python 3.2 and later, it's the terminator attribute of the StreamHandler. See: http://plumberjack.blogspot.com/2010/10/streamhandlers-newline-terminator-now.html Unfortunately, for earlier Python versions, you'd need to subclass and override StreamHandler.emit() to get equivalent functionality :-( Regards, Vinay Sajip From peterthebag at yahoo.com Sun May 8 06:44:06 2011 From: peterthebag at yahoo.com (pb) Date: Sun, 8 May 2011 03:44:06 -0700 (PDT) Subject: scipy Message-ID: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> Hi, I', having trouble with scipy. I have followed the instructions at scipy website and have installed the following on my mac osx 10.6.6 NumPy version 1.5.1 NumPy is installed in /Library/Frameworks/Python.framework/Versions/ 2.6/lib/python2.6/site-packages/numpy SciPy version 0.8.0 SciPy is installed in /Library/Frameworks/Python.framework/Versions/ 2.6/lib/python2.6/site-packages/scipy Python version 2.6.6 (r266:84374, Aug 31 2010, 11:00:51) [GCC 4.0.1 (Apple Inc. build 5493)] nose version 1.0.0 When I run the test scipy.test('1','10') some items seem to pass: test_streams.test_make_stream(True,) ... ok Some tests seem to be skipped: nose.selector: INFO: /Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/scipy/io/matlab/mio5_utils.so is executable; skipped some seem to fail: /Users/user/.python26_compiled/m7/module_multi_function.cpp:13:19: error: complex: No such file or directory and ====================================================================== ERROR: test_string_and_int (test_ext_tools.TestExtModule) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/scipy/weave/tests/test_ext_tools.py", line 72, in test_string_and_int mod.compile(location = build_dir) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/scipy/weave/ext_tools.py", line 367, in compile verbose = verbose, **kw) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/scipy/weave/build_tools.py", line 273, in build_extension setup(name = module_name, ext_modules = [ext],verbose=verb) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/numpy/distutils/core.py", line 186, in setup return old_setup(**new_attr) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/distutils/core.py", line 169, in setup raise SystemExit, "error: " + str(msg) CompileError: error: Command "c++ -fno-strict-aliasing -fno-common - dynamic -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/ 2.6/lib/python2.6/site-packages/scipy/weave -I/Library/Frameworks/ Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/weave/ scxx -I/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/core/include -I/Library/Frameworks/ Python.framework/Versions/2.6/include/python2.6 -c /Library/Frameworks/ Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/weave/ scxx/weave_imp.cpp -o /var/folders/4b/4bhByeH9HSuDIezfnSZ6G++++TI/- Tmp-/user/python26_intermediate/ compiler_7ca1591dfd3261e140e707030a00840e/Library/Frameworks/ Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/weave/ scxx/weave_imp.o" failed with exit status 1 with the final result being: FAILED (KNOWNFAIL=15, SKIP=40, errors=242, failures=2) I'm assuming I have the wrong version of something, would that be right? Does anyone know how I can fix this? thanks, Peter From nobody at nowhere.net.no Sun May 8 07:21:18 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 08 May 2011 19:21:18 +0800 Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> Message-ID: Vinay Sajip wrote: 8< > For Python 3.2 and later, it's the terminator attribute of the > StreamHandler. See: 8< > Unfortunately, for earlier Python versions, you'd need to subclass and > override StreamHandler.emit() to get equivalent functionality :-( > I'm with 3.2 and willing to stay :) I was trying ==================================code================================== >>>logging.basicConfig(format='%(message)s',terminator='',level=logging.DEBUG) >>> logging.debug('here we are') DEBUG:root:here we are >>> ==================================code================================== First I didn't espect to see much more than my message. I agree that I'm very new to the module Second the will terminator appear only to real stdout, or am I doing something incorrect? Note: some word wrapping doesn't show the python shell correctly. -- goto /dev/null From msarro at gmail.com Sun May 8 07:52:55 2011 From: msarro at gmail.com (Matty Sarro) Date: Sun, 8 May 2011 07:52:55 -0400 Subject: Python IDE/text-editor In-Reply-To: <4dc58fa3$0$8718$9a6e19ea@unlimited.newshosting.com> References: <4dc58fa3$0$8718$9a6e19ea@unlimited.newshosting.com> Message-ID: Pydev for eclipse/aptana On Saturday, May 7, 2011, emato wrote: > >> On Apr 16, 1:20 pm, Alec Taylor wrote: >> >>> I'm looking for an IDE which offers syntax-highlighting, >>> code-completion, tabs, > > gedit > > http://projects.gnome.org/gedit/index.html > > > -- > http://mail.python.org/mailman/listinfo/python-list > From vinay_sajip at yahoo.co.uk Sun May 8 08:31:15 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 8 May 2011 05:31:15 -0700 (PDT) Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> Message-ID: On May 8, 12:21?pm, TheSaint wrote: > First I didn't espect to see much more than my message. I agree that I'm > very new to the module You could do logging.basicConfig(level=logging.DEBUG, format='%(message)s') to get just the message. > Second the will terminator appear only to real stdout, or am I doing > something incorrect? The terminator is an attribute on the StreamHandler instance, so works with whatever stream the handler is using. You can't use basicConfig() directly, if you want to configure the terminator - instead, use something like sh = logging.StreamHandler(sys.stdout) sh.terminator = '' logging.getLogger().addHandler(sh) but be sure to execute this code one time only, or you will get multiple identical messages for a single logging call. Regards, Vinay Sajip From steve+comp.lang.python at pearwood.info Sun May 8 08:59:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2011 12:59:02 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> <87hb9521ci.fsf@ugg.bibliotech.com> Message-ID: <4dc69395$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 08 May 2011 01:44:13 -0400, Robert Brown wrote: > Steven D'Aprano writes: >> If you value runtime efficiency over development time, sure. There are >> plenty of languages which have made that decision: Pascal, C, Java, >> Lisp, Forth, and many more. > > I don't understand why you place Lisp and Forth in the same category as > Pascal, C, and Java. Lisp and Forth generally have highly interactive > development environments, while the other languages generally require an > edit, compile, run it again debugging cycle. Good point. Perhaps I need to rethink where Lisp and Forth sit in the development vs runtime trade-off continuum. > Python requires me to rewrite the slow bits of my program in C > to get good performance. Python doesn't require you to re-write anything in C. If you want to make a different trade-off (faster runtime, slower development time) then you use a language that has made the appropriate trade-off. This applies whether you are talking about the entire program, or just one subroutine. > Why is that an efficient use of developer time? Because for any non-trivial program, it is faster and more developer friendly to just write one or three performance-critical routines in C, and the rest in Python, than it is to write everything in C. -- Steven From rdsteph at mac.com Sun May 8 09:28:26 2011 From: rdsteph at mac.com (rdsteph at mac.com) Date: Sun, 8 May 2011 06:28:26 -0700 (PDT) Subject: Pushing for Pythoncard 1.0 References: <6d896b66-3933-4743-8eb5-b9754f1ec14f@t19g2000prd.googlegroups.com> <5348cf4b-ffd2-41f0-a7a5-afedc00ed703@b35g2000yqn.googlegroups.com> Message-ID: <8a52d854-a029-4a5a-a6ba-7a060444a026@22g2000prx.googlegroups.com> On May 3, 12:15?pm, rnd wrote: > On May 2, 10:48?pm, John Henry wrote: > > > Attempt to push Pythoncard to a 1.0 status is now underway. ?A > > temporary website has been created at: > > >http://code.google.com/p/pythoncard-1-0/ > > > The official website continues to behttp://pythoncard.sourceforge.net/ > > > Pythoncard is such a wonderful package that it would be a shame to > > allow development for the package to go stagnant. ? The Python > > community deserves to continue enjoying the simplicity of Pythoncard > > for creating a GUI Python application. > > I was very positively surprised to hear someone talking about > PythonCard these days. > Even though I've not needed to develop GUI apps for years, I believe > its still great idea > to revive PythonCard even though everybody is busy developing for > "iThings" right now. > > Regards, > Roman Suzi I love and use PythonCard! From roy at panix.com Sun May 8 09:31:10 2011 From: roy at panix.com (Roy Smith) Date: Sun, 08 May 2011 09:31:10 -0400 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: In article <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21 at r35g2000prj.googlegroups.com>, snorble wrote: > [standard tale of chaotic software development elided] > > I am aware of tools like version control systems, bug trackers, and > things like these, but I'm not really sure if I need them, or how to > use them properly. None of this has anything to do with python. It's all standard software engineering stuff that's the same with any language or technology. Bug trackers are essential for large projects. For a one-man project, it's probably more effort than it's worth. For the project I'm on now (4 developers co-located with the customer), we're using a shared google docs spreadsheet for bug tracking. It's free, low-overhead, and works well enough. For a single person, even that may be more than you need. On the other hand version control is essential from day zero, even on a one-man project. There's plenty of perfectly good, free, systems out there. The obvious choices are hg, git, and bzr. Pick one and use it. The nice thing about them all is there's no lock-in. If you decide you don't like the one you're using, you can easily convert your entire code repository to any of the others without losing anything. > I really like the idea of having a list of features, and tackling > those features one at a time. Yup, that's the core concept of all the agile development processes that are all the rage these days. Sometimes called "release early and often". > I read about people who do this, and > each new features gets a new minor version number. For the project I'm on, we don't even bother with version numbers. We have a main branch which we (try to) keep stable and shippable at all times, and push that to production whenever we've completed a feature (or bug fix) that the customer needs. I see we're currently running: 9be3fc6a0e01cf128f63d1af2b19c180fb4eaacb (tip) Version numbers make more sense with a traditional ("waterfall") type process, where you design a bunch of stuff, write the code, go through a testing and bug-fixing cycle, and the finally push it out the door. > I think I just need some recommendations to help > create a good mental map of what needs to happen, and mapping jargon > to concepts. Like, "each feature gets its own directory". Or with a > version control tool, I don't know if a feature maps to a branch, or a > commit? Well, start from the premise that you have a main branch which is always shippable. That means the code runs and passes all the tests after every single commit to that branch. Now, when you need to make a change (add a feature or fix a bug), ask yourself if the change is small enough that you can do all the work required in one day. If so, then doing it in a single commit on your main branch may make sense. If not, then spin up a development branch, do the work there, and when you're satisfied it's shippable, merge it onto your main branch. From steve+comp.lang.python at pearwood.info Sun May 8 10:07:23 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2011 14:07:23 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 May 2011 22:50:55 -0500, harrismh777 wrote: > Steven D'Aprano wrote: >>> > and implies in any case that li does not exist >> It does nothing of the sort. If li doesn't exist, you get a NameError. > > That was the point. 'not' implies something that is not logical; I'm afraid that makes no sense to me. How does "does not exist" imply something not logical? In what way is "this is not my house" implying something not logical? > which is irony extreme since 'not' is typically considered a logical > operator. Because "not" is typically used as a logical operator. In English, it negates a word or statement: "the cat is not on the mat" --> "the cat is on the mat" is false. As an operator, "not" negates a true value to a false value. In mathematical Boolean algebra, there only is one true value and one false value, conventionally called True/False or 1/0. In non-Boolean algebras, you can define other values. In three-value logic, the negation of True/ False/Maybe is usually False/True/Maybe. In fuzzy logic, the logic values are the uncountable infinity (that's a technical term, not hyperbole) of real numbers between 0 and 1. Python uses a boolean algebra where there are many ways of spelling the true and false values. The "not" operator returns the canonical bool values: not returns False not returns True Take note of the distinction between lower-case true/false, which are adjectives, and True/False, which are objects of class bool. This is not unique to Python. I understand the practice of allowing any value to be used in boolean expressions comes from Lisp in 1958, which makes it practically antediluvian. Lisp uses the empty list and the special atom NIL as false values, any other s-expression is true. Scheme is different: it defines a special false atom, and empty lists are considered true. In Ruby, only the false object and the null object are considered false. In Forth, any non-zero word is true. In Javascript, the empty string, null, undefined, NaN, +0, -0, and false are all considered false. > What does it mean to say not ? Well, apparently > it means the list is 'empty'... but why should it mean that? Because that is the definition chosen by the language designers. It is based on the fact that distinguishing between "something" and "nothing" is useful, common, fundamental, and applies to nearly all data types. > Why not > have it mean the list has been reversed in place? Why not have it mean > that the list isn't homogeneous? Why not have it mean that its not > mutable? I could think of more... Because those tests are not fundamental tests that deserve to be elevated to a language design feature, any more than we need a built-in function to add 27 and three quarters to the argument. > Why should 'not' mean 'empty'? Because the test of "is this nothing, or something?" is a common, useful test: 0 (nothing) vs 1, 2, 3, ... (something) empty list versus non-empty list empty dict versus non-empty dict empty set versus non-empty set empty string versus non-empty string no search results returned versus some search results returned no network connection available versus some network connection available no food in the cupboard versus food in the cupboard This is a fundamental distinction which is very useful in practice. >>> > or worse is some kind of boolean. >> Only if you're still thinking in some language that isn't Python. > > Which most of us are... hate to remind you... Time to stop then. This is Python, not whatever language you're thinking in. Don't force language A into the conceptual pigeonholes of language B. To be effective in a programming language, you need to understand how that language works, and not see everything filtered through the conceptual framework of another language. Bringing the viewpoints of other languages is a good thing. Python borrows concepts from many languages (sometimes what it borrows is the idea of "that's not how to do it"). And many idioms do cross language boundaries. But in general, it pays to think, and code, in the appropriate style for whatever language you are writing in. And certainly, you should not argue that a language feature is invalid or wrong merely because that's not how another language does it. Or, to put it another way: http://dirtsimple.org/2004/12/python-is-not-java.html http://dirtsimple.org/2004/12/java-is-not-python-either.html > Python is the new kid on the block, Nonsense. Python is 20 years old (1991), which makes it older than: Java, PHP, Ruby (1995) Javascript (1996) C# (2000) Visual Basic .Net (2001) to say nothing of dozens of other languages. > and most of us are coming at this from multiple > filters in comp sci experience. Its just the truth. There's nothing wrong with having experience in many languages. That's a good thing. -- Steven From gslindstrom at gmail.com Sun May 8 11:20:44 2011 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Sun, 8 May 2011 10:20:44 -0500 Subject: Dictionary from String? Message-ID: Is it possible to create a dictionary from a string value? Something along these lines (but that works): >>> mystring = "{'name':'greg','hatsize':'7 5/8'}" >>> mystring "{'name':'greg','hatsize':'7 5/8'}" >>> dict(mystring) Traceback (most recent call last): File "", line 1, in ValueError: dictionary update sequence element #0 has length 1; 2 is required >>> I would like to return an undetermined (at call time) number of fields from a postgres database (only 1 record) for a given request. My thought is that I could build a dictionary in the form of a string, return the string and then convert the string value to a dictionary. I can do that now, but I have to parse the string and then build the dictionary. Any thoughts or help you could provide would be appreciated. --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Sun May 8 11:59:44 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 08 May 2011 18:59:44 +0300 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > Lisp uses the empty list and the special atom NIL as false values, > any other s-expression is true. Scheme is different: it defines a > special false atom, and empty lists are considered true. In Ruby, I'll inject a pedantic note: there is only one false value in both Lisp (which now is mostly Common Lisp) and Scheme. The empty list () and the symbol NIL in Lisp are one value, not two values. The first Google hit (for me, just now) explains it the way I understand it: . (Common Lisp The Language, 2nd edition. Odd place to find that book. It predates the formal standard, but then I think this particular feature of the language is, indeed, as old as you say, and unlikely to have changed.) Scheme was the same. Then for a time it was not specified whether the empty list was distinct from the false value or the symbol nil - people disagreed and implementations were allowed to differ - until the three were definitely separated. From rosuav at gmail.com Sun May 8 12:16:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 May 2011 02:16:50 +1000 Subject: Dictionary from String? In-Reply-To: References: Message-ID: On Mon, May 9, 2011 at 1:20 AM, Greg Lindstrom wrote: > Is it possible to create a dictionary from a string value?? Something along > these lines (but that works): > >>>> mystring = "{'name':'greg','hatsize':'7 5/8'}" >>>> mystring > "{'name':'greg','hatsize':'7 5/8'}" >>>> dict(mystring) > Traceback (most recent call last): > ? File "", line 1, in > ValueError: dictionary update sequence element #0 has length 1; 2 is > required >>>> > > I would like to return an undetermined (at call time) number of fields from > a postgres database (only 1 record) for a given request.? My thought is that > I could build a dictionary in the form of a string, return the string and > then convert the string value to a dictionary.? I can do that now, but I > have to parse the string and then build the dictionary.? Any thoughts or > help you could provide would be appreciated. The first one can be done with the eval() function, but you want to be REALLY sure that the string is safe. But if you're building the dictionary from a database, it would be far more efficient to build it directly in Python and return it; I'm assuming that you're currently building the string outside of Python, but the easiest solution (in my opinion, based solely on the information given and potentially hopelessly useless to your actual situation) would be to simply return multiple values from postgres and have Python do the parsing and building. Alternatively, if there is a character that you can guarantee does not exist in the content, you could do something like this: mystring = "name=greg#hatsize=7 5/8" dict((field.split('=',1) for field in mystring.split('#'))) I used the hash character as a separator here, but you could just as easily use a non-printing character like \n if you can be sure it never appears in any string value. (It's okay for an equals sign, as long as it's not in the field name.) Hope that's of value! Chris Angelico From tlikonen at iki.fi Sun May 8 12:34:13 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Sun, 08 May 2011 19:34:13 +0300 Subject: Development time vs. runtime performance (was: Fibonacci series recursion error) References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> <87hb9521ci.fsf@ugg.bibliotech.com> <4dc69395$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87fwoprw1m.fsf@mithlond.arda> * 2011-05-08T12:59:02Z * Steven D'Aprano wrote: > On Sun, 08 May 2011 01:44:13 -0400, Robert Brown wrote: >> I don't understand why you place Lisp and Forth in the same category >> as Pascal, C, and Java. Lisp and Forth generally have highly >> interactive development environments, while the other languages >> generally require an edit, compile, run it again debugging cycle. > > Good point. Perhaps I need to rethink where Lisp and Forth sit in the > development vs runtime trade-off continuum. > >> Python requires me to rewrite the slow bits of my program in C to get >> good performance. > > Python doesn't require you to re-write anything in C. If you want to > make a different trade-off (faster runtime, slower development time) > then you use a language that has made the appropriate trade-off. I believe that Robert Brown wanted to imply that Common Lisp is quite optimal on both sides. It supports dynamic interactive development and yet it has implementations with very efficient compilers. The trade-off is not necessarily between the two. But of course "development time" is a nicely vague concept. Depending on the argument it can include just the features of language and implementation. Other times it could include all the available resources such as documentation, library archives and community mailing lists. All these can reduce development time. From benjamin.kaplan at case.edu Sun May 8 12:43:59 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 May 2011 09:43:59 -0700 Subject: Dictionary from String? In-Reply-To: References: Message-ID: On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom wrote: > Is it possible to create a dictionary from a string value?? Something along > these lines (but that works): > >>>> mystring = "{'name':'greg','hatsize':'7 5/8'}" >>>> mystring > "{'name':'greg','hatsize':'7 5/8'}" >>>> dict(mystring) > Traceback (most recent call last): > ? File "", line 1, in > ValueError: dictionary update sequence element #0 has length 1; 2 is > required >>>> > > I would like to return an undetermined (at call time) number of fields from > a postgres database (only 1 record) for a given request.? My thought is that > I could build a dictionary in the form of a string, return the string and > then convert the string value to a dictionary.? I can do that now, but I > have to parse the string and then build the dictionary.? Any thoughts or > help you could provide would be appreciated. > > --greg building the dictionary as a string seems like a hacky thing to do and you might want to reevaluate your methods. But if everything in the dict is a literal, you can do ast.literal_eval. > > -- > http://mail.python.org/mailman/listinfo/python-list > > From drsalists at gmail.com Sun May 8 15:00:22 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 8 May 2011 12:00:22 -0700 Subject: Dictionary from String? In-Reply-To: References: Message-ID: On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom wrote: > Is it possible to create a dictionary from a string value? Something along > these lines (but that works): > > >>> mystring = "{'name':'greg','hatsize':'7 5/8'}" > >>> mystring > "{'name':'greg','hatsize':'7 5/8'}" > >>> dict(mystring) > Traceback (most recent call last): > File "", line 1, in > ValueError: dictionary update sequence element #0 has length 1; 2 is > required > >>> > > I would like to return an undetermined (at call time) number of fields from > a postgres database (only 1 record) for a given request. My thought is that > I could build a dictionary in the form of a string, return the string and > then convert the string value to a dictionary. I can do that now, but I > have to parse the string and then build the dictionary. Any thoughts or > help you could provide would be appreciated. > Does this help any? $ /usr/local/cpython-3.2/bin/python Python 3.2 (r32:88445, Mar 4 2011, 22:43:54) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> my_dict = {'name':'greg','hatsize':'7 5/8'} >>> import json >>> my_string = json.dumps(my_dict) >>> my_string '{"hatsize": "7 5/8", "name": "greg"}' >>> my_dict2 = json.loads(my_string) >>> my_dict2 {'hatsize': '7 5/8', 'name': 'greg'} >>> my_dict == my_dict2 True >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From hansmu at xs4all.nl Sun May 8 15:32:06 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 08 May 2011 21:32:06 +0200 Subject: dictionary size changed during iteration In-Reply-To: References: <4DAED72B.2030400@shopzeus.com> <7xd3jukyn9.fsf@ruckus.brouhaha.com> Message-ID: <4dc6f077$0$41117$e4fe514c@news.xs4all.nl> On 08/05/2011 00:12, Roy Smith wrote: > In article<7xd3jukyn9.fsf at ruckus.brouhaha.com>, > Paul Rubin wrote: > >> Roy Smith writes: >>> changes = [ ] >>> for key in d.iterkeys(): >>> if is_bad(key): >>> changes.append(key) >> >> changes = list(k for k in d if is_bad(k)) >> >> is a little bit more direct. > > This is true. I still file list comprehensions under "new fangled > toys". While I use them, and appreciate their value, I admit they're > not always the first thing that comes to my mind. > > OBTW, > >> changes = [k for k in d if is_bad(k)] > > is even more direct :-) How about: changes = filter(is_bad, d) Or would that be too compact? -- HansM From gslindstrom at gmail.com Sun May 8 15:39:53 2011 From: gslindstrom at gmail.com (gslindstrom at gmail.com) Date: Sun, 08 May 2011 19:39:53 +0000 Subject: Dictionary from String? In-Reply-To: Message-ID: <0016363b796e0a697004a2c8e313@google.com> On May 8, 2011 2:00pm, Dan Stromberg wrote: > On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom gslindstrom at gmail.com> > wrote: > Is it possible to create a dictionary from a string value? Something > along these lines (but that works): > >>> mystring = "{'name':'greg','hatsize':'7 5/8'}" > >>> mystring > "{'name':'greg','hatsize':'7 5/8'}" > >>> dict(mystring) > Traceback (most recent call last): > File "", line 1, in > ValueError: dictionary update sequence element #0 has length 1; 2 is > required Yes. It works like a champ. Thanks! --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Sun May 8 15:42:23 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 08 May 2011 12:42:23 -0700 Subject: dictionary size changed during iteration References: <4DAED72B.2030400@shopzeus.com> <7xd3jukyn9.fsf@ruckus.brouhaha.com> <4dc6f077$0$41117$e4fe514c@news.xs4all.nl> Message-ID: <7xhb952d40.fsf@ruckus.brouhaha.com> Hans Mulder writes: > How about: > changes = filter(is_bad, d) > Or would that be too compact? I thought of writing something like that but filter in python 3 creates an iterator that would have the same issue of walking the dictionary while the dictionary is mutating. changes = list(filter(is_bad, d)) should work. From tjreedy at udel.edu Sun May 8 18:41:20 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 08 May 2011 18:41:20 -0400 Subject: checking if a list is empty In-Reply-To: <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/8/2011 10:07 AM, Steven D'Aprano wrote: > Because the test of "is this nothing, or something?" is a common, useful > test: Because inductive algorithms commonly branch on 'input is something' (not done, change args toward 'nothing'and recurse or iterate) versus 'input is nothing (done, return base expression). > 0 (nothing) vs 1, 2, 3, ... (something) > empty list versus non-empty list > empty dict versus non-empty dict > empty set versus non-empty set > empty string versus non-empty string and non-inductive algorithms also branch on the same question. > no search results returned versus some search results returned > no network connection available versus some network connection available > no food in the cupboard versus food in the cupboard > > This is a fundamental distinction which is very useful in practice. Definitely. Python commonly hides the distinction inside of iterators called by for statememts, but StopIteration is understood as 'collection is empty'. An I suspect something vs. nothing is also the most common overt condition in if and while statements. -- Terry Jan Reedy From tjreedy at udel.edu Sun May 8 19:29:50 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 08 May 2011 19:29:50 -0400 Subject: scipy In-Reply-To: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> Message-ID: On 5/8/2011 6:44 AM, pb wrote: > Hi, > I', having trouble with scipy. If you do not get an answer here, try the scipy list where scipy experts hang out. You might also try searching the archives of that list or the scipy bug tracker. -- Terry Jan Reedy From drsalists at gmail.com Sun May 8 19:36:11 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 8 May 2011 16:36:11 -0700 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 8, 2011 at 3:41 PM, Terry Reedy wrote: > On 5/8/2011 10:07 AM, Steven D'Aprano wrote: > > Because the test of "is this nothing, or something?" is a common, useful >> test: >> > > Because inductive algorithms commonly branch on 'input is something' (not > done, change args toward 'nothing'and recurse or iterate) versus 'input is > nothing (done, return base expression). > Just what is an inductive algorithm? I'm familiar with inductive reasoning and inductive proofs, but there doesn't seem to be much on the 'net defining inductive algorithms. There are some papers that reference the topic, but few seem to spend much time on defining it. They seem to have to do with A.I. knowledge acquisition - perhaps it's an algorithm that reasons from a bunch of factlets to create a general rule? -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sun May 8 20:52:27 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 09 May 2011 12:52:27 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92os6dF5jbU1@mid.individual.net> Steven D'Aprano wrote: > Since you haven't explained what you think is happening, I can only > guess. Let me save you from guessing. I'm thinking of a piece of paper with a little box on it and the name 'a' written beside it. There is an arrow from that box to a bigger box. +-------------+ +---+ | | a | --+---------------->| | +---+ | | +-------------+ There is another little box labelled 'b'. After executing 'a = b', both little boxes have arrows pointing to the same big box. +-------------+ +---+ | | a | --+---------------->| | +---+ | | +-------------+ ^ +---+ | b | --+-----------------------| +---+ In this model, a "reference" is an arrow. Manipulating references consists of rubbing out the arrows and redrawing them differently. Also in this model, a "variable" is a little box. It's *not* the same thing as a name; a name is a label for a variable, not the variable itself. It seems that you would prefer to eliminate the little boxes and arrows and write the names directly beside the objects: +-------------+ a | | | | b | | +-------------+ +-------------+ c | | | | | | +-------------+ But what would you do about lists? With little boxes and arrows, you can draw a diagram like this: +---+ +---+ a | --+----->| | +-------------+ +---+ +---+ | | | --+----->| | +---+ | | | | +-------------+ +---+ (Here, the list is represented as a collection of variables. That's why variables and names are not the same thing -- the elements of the list don't have textual names.) But without any little boxes or arrows, you can't represent the list itself as a coherent object. You would have to go around and label various objects with 'a[0]', 'a[1]', etc. +-------------+ a[0] | | | | | | +-------------+ +-------------+ a[1] | | | | | | +-------------+ This is not very satisfactory. If the binding of 'a' changes, you have to hunt for all your a[i] labels, rub them out and rewrite them next to different objects. It's hardly conducive to imparting a clear understanding of what is going on, whereas the boxes-and-arrows model makes it instantly obvious. There is a half-way position, where we use boxes to represent list items, but for bare names we just draw the arrow coming directly out of the name: +---+ a --------->| | +-------------+ +---+ | | | --+----->| | +---+ | | | | +-------------+ +---+ But this is really just a minor variation. It can be a useful shorthand, but it has the drawback of making it seem as though the binding of a bare name is somehow different from the binding of a list element, when it isn't really. Finally, there's another benefit of considering a reference to be a distinct entity in the data model. If you think of the little boxes as being of a fixed size, just big enough to hold a reference, then it's obvious that you can only bind it to *one* object at a time. Otherwise it might appear that you could draw more than one arrow coming out of a name, or write the same name next to more than one object. It seems to me that the boxes-and-arrows model, or something isomorphic to it, is the most abstract model you can make of Python that captures everything necessary to reason about it both easily and correctly. -- Greg From qwsxza147 at 163.com Sun May 8 21:04:38 2011 From: qwsxza147 at 163.com (qw) Date: Sun, 8 May 2011 18:04:38 -0700 (PDT) Subject: payment wholesale SHOES(UGG BOOTS, Timberland boots ,Munich www dot 51-wholesale dot com Message-ID: <2e156db0-4306-4302-9f35-bf75f9860976@q12g2000prb.googlegroups.com> payment wholesale SHOES(UGG BOOTS, Timberland boots ,Munich shoes,NIKE,ADIDAS,LV,GUCCI,CHANEL,PRADA,POLO,D&G,DIOR AND SO ON) www dot 51-wholesale dot com From rosuav at gmail.com Sun May 8 22:49:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 May 2011 12:49:01 +1000 Subject: Development time vs. runtime performance (was: Fibonacci series recursion error) In-Reply-To: <87fwoprw1m.fsf@mithlond.arda> References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> <87hb9521ci.fsf@ugg.bibliotech.com> <4dc69395$0$29991$c3e8da3$5496439d@news.astraweb.com> <87fwoprw1m.fsf@mithlond.arda> Message-ID: On Mon, May 9, 2011 at 2:34 AM, Teemu Likonen wrote: > But of course "development time" is a nicely vague concept. Depending on > the argument it can include just the features of language and > implementation. Other times it could include all the available resources > such as documentation, library archives and community mailing lists. All > these can reduce development time. > And it also includes a developer's personal experience level. A good programmer will have a mental "algorithmic library" if you like; effectively, it's a gigantic hash table of "if I need to do this, I can do it this way". A mediocre programmer will both take longer and produce less efficient code than an awesome programmer. This is primarily not a language feature, but a language that usually has one obvious way to do things will likely be easier to grok than a language that has myriad "gotchas" to work around. Chris Angelico From robert.brown at gmail.com Sun May 8 23:01:18 2011 From: robert.brown at gmail.com (Robert Brown) Date: Sun, 08 May 2011 23:01:18 -0400 Subject: Development time vs. runtime performance (was: Fibonacci series recursion error) References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> <87hb9521ci.fsf@ugg.bibliotech.com> <4dc69395$0$29991$c3e8da3$5496439d@news.astraweb.com> <87fwoprw1m.fsf@mithlond.arda> Message-ID: <8739ko7f29.fsf@ugg.bibliotech.com> Teemu Likonen writes: > * 2011-05-08T12:59:02Z * Steven D'Aprano wrote: > >> On Sun, 08 May 2011 01:44:13 -0400, Robert Brown wrote: >>> Python requires me to rewrite the slow bits of my program in C to get >>> good performance. >> >> Python doesn't require you to re-write anything in C. If you want to >> make a different trade-off (faster runtime, slower development time) >> then you use a language that has made the appropriate trade-off. > > I believe that Robert Brown wanted to imply that Common Lisp is quite > optimal on both sides. It supports dynamic interactive development and > yet it has implementations with very efficient compilers. The trade-off > is not necessarily between the two. Yes, exactly. Sometimes I don't know in advance which parts of my Python program will run too slowly or take too much memory. I only find out after the code is written, when it fails to run fast enough or doesn't fit in my computer's 32-bit address space. Then the slow parts get recoded in C. Common Lisp supports a larger performance range. A developer can write slow code quickly or faster code by giving the compiler more information, which requires more developer time. > But of course "development time" is a nicely vague concept. Depending on > the argument it can include just the features of language and > implementation. Other times it could include all the available resources > such as documentation, library archives and community mailing lists. All > these can reduce development time. This is definitely true. The total time to complete any task always depends on tons of factors outside of the programming language. The ecosystem is important ... How much code can I avoid writing myself? bob From chris_roysmith.nothere at internode.on.net Sun May 8 23:15:51 2011 From: chris_roysmith.nothere at internode.on.net (Chris Roy-Smith) Date: 09 May 2011 03:15:51 GMT Subject: How to access elemenst in a list of lists? Message-ID: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Just learning python. I can see that I can address an individual element of a list of lists by doing something like: row = list[5] element = row[3] But is there a way to directly address an entry in a single statement? Thanks for any help. Regards Chris Roy-Smith From rosuav at gmail.com Sun May 8 23:23:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 May 2011 13:23:38 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 9, 2011 at 1:15 PM, Chris Roy-Smith wrote: > Just learning python. > I can see that I can address an individual element of a list of lists by > doing something like: > row = list[5] > element = row[3] > > But is there a way to directly address an entry in a single statement? Yep! element = list[5][3] Everything's an expression, there's nothing special about something that's stored in a variable. You can even use square brackets after a function call that returns a list (which is very useful at times). Chris Angelico From prologic at shortcircuit.net.au Sun May 8 23:31:30 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 9 May 2011 13:31:30 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 9, 2011 at 1:23 PM, Chris Angelico wrote: >> Just learning python. >> I can see that I can address an individual element of a list of lists by >> doing something like: >> row = list[5] >> element = row[3] This is the correct approach. Here's an interactive example (tested): $ python Python 2.7.1 (r271:86832, Feb 8 2011, 10:07:16) [GCC 4.5.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> grid = [[" " for x in range(5)] for y in range(5)] >>> from pprint import pprint >>> pprint(grid) [[' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ']] >>> grid[2][2] = "X" >>> pprint(grid) [[' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', 'X', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ']] >>> cheers James -- -- James Mills -- -- "Problems are solved by method" From torriem at gmail.com Sun May 8 23:31:35 2011 From: torriem at gmail.com (Michael Torrie) Date: Sun, 08 May 2011 21:31:35 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DC76017.7010705@gmail.com> On 05/08/2011 05:36 PM, Dan Stromberg wrote: > Just what is an inductive algorithm? >From what I can remember, it's just an implementation of a proof essentially. Any algorithm that can be inductively proven can be implemented with recursion and specific base cases. In other words you program just like you'd do the proof. First you deal with the base cases and then you can call yourself for F(n) and F(n-1). The inductive proof provides the pattern for the code. From harrismh777 at charter.net Sun May 8 23:33:11 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 08 May 2011 22:33:11 -0500 Subject: checking if a list is empty In-Reply-To: <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> which is irony extreme since 'not' is typically considered a logical >> > operator. > Because "not" is typically used as a logical operator. > > In English, it negates a word or statement: > > "the cat is not on the mat" --> "the cat is on the mat" is false. Your pedantic bogus cat analogy talks past my point entirely, as well as making you look silly... if you would stop being pedantic long enough to think about what I'm saying you might come to some understanding... ... yes, 'not' is a logical negation. Why would you waste time with a pedantic explanation of 'not' ? Wait--- its a rhetorical question... Why should the negation of a list imply that the list empty? ... nor any other abstract condition which is not well suited to 'not' ? (forget python for a moment... then move on to my argument...) What made the python development team (or individual) decide that the logical construct 'not list' would return True if the list is empty? To say that "This is the way we do it in Python because Python does it this way"--- goes beyond pedantic becoming circular and redundant. On the other hand, if you were to tell me *why* you think that the logical construct 'not list' should be logically True when the list is empty--- when clearly negating a list would not necessarily mean to make the list empty (including destroying it)... then you might be seeing my point. Here's the bottom line you missed... ... although syntactically correct, the following test is not a logical construct that makes sense (except for the syntactically initiated): if not list <===== this makes no logical sense... ... to test for an empty list . . . ... although, it is legal syntax. :-} I know that is the way Python does it... I've been coding it that way for a long time... but that doesn't answer my concern.... To say this another way, IMHO, if not list ... should return True only if 'list' is bound to NULL, or if the name 'list' would throw a name exception... ... and, Python should have an explicit way of testing for an empty list that is clear, concise, and easy to understand even for the relatively new Python programmer. This is not intended to generate counter argument, its just my feedback on a language construct that I find to be inconsistent logically. ... Please, no pedantic discourse explaining why I'm wrong... just put in into a PEP and move on. :) kind regards, m harris From harrismh777 at charter.net Sun May 8 23:56:02 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 08 May 2011 22:56:02 -0500 Subject: checking if a list is empty In-Reply-To: <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> Python is the new kid on the block, > Nonsense. Python is 20 years old (1991), which makes it older than: > > Java, PHP, Ruby (1995) > Javascript (1996) > C# (2000) > Visual Basic .Net (2001) Python is the new kid on the block. ... not chronologically perhaps, but measured in terms of acceptance and widespread use it is only really now coming into its own. It usually takes an advance in technology about 20 - 25 years to catch on... and Python has finally arrived IMHO. As an example of this... in many default setups in linux distros today Python is now the default 'Programming' environment. This was not true in 1991, nor was it true in 2001... in fact, this has not been true until the past couple of years. Python is catching on in the community at large... not just specialized development shops. As I've given my opinion before on this list, Python is finally becoming the New BASIC for 'people'. Python is also the new kid on the block in educational settings. Haskell and Erlang have dominated for some time now (in fact, many colleges and universities have focused beginning classes on pure functional programming)... and before that Pascal and Lisp... and in limited ways C or C++ ./ Python is moving into that arena lately. For me personally, the environment provided by TCL/Tk was the way for many years... TCL was the glue, Tk was the graphics, and 'C' was the engine (it all works together seamlessly with great performance and minimal lines of coding). Python takes it up a notch; big time. Because, as you've pointed out, less has to be written in 'C'. Almost all of the app can be written in Python, with only one (or three) mods written in 'C'... frankly, for most scripting, the whole thing can be written in Python. But *this* is a relatively *new* discovery for much of the community at large. (I'm not talking here about Google, nor YouTube). Linux is in this same boat... Linux is twenty years old; however, Linux has not enjoyed wide-spread use on the Desktop (until this year, and part of last) and has only enjoyed wide-spread use on servers over the past ten years. Linux is now coming into its own, and when everything is said and done and all the dust settles history is going to find Windows as a minor footnote in personal computing (I'm talking 100 years from now). Linux is the new kid on the block, twenty years old and kicking it... Python is the new kid on the block... twenty years old and kicking it.... many of us are catching up with the new trend; however, we will be evaluating the new trends through historic filters. This cannot be avoided--- for linux, nor for python. kind regards, m harris From i.m.laurent at gmail.com Mon May 9 00:31:44 2011 From: i.m.laurent at gmail.com (Mali Laurent) Date: Sun, 8 May 2011 21:31:44 -0700 (PDT) Subject: Python IDE/text-editor References: Message-ID: <0818ae3c-b55a-4a06-9472-0e5530c8654f@p6g2000vbn.googlegroups.com> On Apr 16, 5:20?am, Alec Taylor wrote: > Good Afternoon, > > I'm looking for an IDE which offers syntax-highlighting, > code-completion, tabs, an embedded interpreter and which is portable > (for running from USB on Windows). > > Here's a mockup of the app I'm looking for:http://i52.tinypic.com/2uojswz.png > > Which would you recommend? > > Thanks in advance for any suggestions, What about geany? I mostly use that. And sometimes eclipse with python support. From ian.g.kelly at gmail.com Mon May 9 00:34:04 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 8 May 2011 22:34:04 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 8, 2011 at 9:33 PM, harrismh777 wrote: > ? Why should the negation of a list imply that the list empty? ?... nor any > other abstract condition which is not well suited to 'not' ? (forget python > for a moment... then move on to my argument...) > > ? What made the python development team (or individual) decide that the > logical construct ? 'not list' ? would return True if the list is empty? > To say that "This is the way we do it in Python because Python does it this > way"--- ?goes beyond pedantic becoming circular and redundant. > > ? On the other hand, if you were to tell me *why* you think that the logical > construct 'not list' should be logically True when the list is empty--- when > clearly negating a list would not necessarily mean to make the list empty > (including destroying it)... then you might be seeing my point. "bool(list)" describes whether the list contains something. "Not" being a logical operator, it stands to reason that "not list" should mean the same thing as "not bool(list)". Anything else would be surprising and pointlessly convoluted. If "not list" bothers you, then I would suggest that your problem is actually with "bool(list)". > ? ? ? ?... ?should return True only if 'list' is bound to NULL, or if the > name 'list' would throw a name exception... Why? Should "not False" return True only if "False" is bound to NULL (whatever you mean by that), or if the name "False" would throw a name exception? > ? ? ? ?... ?and, Python should have an explicit way of testing for an empty > list that is clear, concise, and easy to understand even for the relatively > new Python programmer. ?This is not intended to generate counter argument, > its just my feedback on a language construct that I find to be inconsistent > logically. ... Please, no pedantic discourse explaining why I'm wrong... > just put in into a PEP and move on. ?:) It does. "if len(list) == 0" From chris_roysmith at internode.on.net Mon May 9 00:40:55 2011 From: chris_roysmith at internode.on.net (Chris Roy-Smith) Date: Mon, 09 May 2011 14:40:55 +1000 Subject: How to access elements in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc77057$0$29999$c3e8da3$5496439d@news.astraweb.com> On 09/05/11 13:31, James Mills wrote: > On Mon, May 9, 2011 at 1:23 PM, Chris Angelico wrote: >>> Just learning python. >>> I can see that I can address an individual element of a list of lists by >>> doing something like: >>> row = list[5] >>> element = row[3] > > This is the correct approach. > > Here's an interactive example (tested): > > $ python > Python 2.7.1 (r271:86832, Feb 8 2011, 10:07:16) > [GCC 4.5.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> grid = [[" " for x in range(5)] for y in range(5)] >>>> from pprint import pprint >>>> pprint(grid) > [[' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' ']] >>>> grid[2][2] = "X" >>>> pprint(grid) > [[' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' '], > [' ', ' ', 'X', ' ', ' '], > [' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' ']] >>>> > > cheers > James > Thanks, that has my understanding problem fixed! And answers what would probably be my next question. Regards Chris Roy-Smith From prologic at shortcircuit.net.au Mon May 9 00:46:45 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 9 May 2011 14:46:45 +1000 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 9, 2011 at 2:34 PM, Ian Kelly wrote: > "bool(list)" describes whether the list contains something. ?"Not" > being a logical operator, it stands to reason that "not list" should > mean the same thing as "not bool(list)". ?Anything else would be > surprising and pointlessly convoluted. ?If "not list" bothers you, > then I would suggest that your problem is actually with "bool(list)". I concur! +1 >> ? ? ? ?... ?should return True only if 'list' is bound to NULL, or if the >> name 'list' would throw a name exception... [...] >> ? ? ? ?... ?and, Python should have an explicit way of testing for an empty >> list that is clear, concise, and easy to understand even for the relatively >> new Python programmer. ?This is not intended to generate counter argument, >> its just my feedback on a language construct that I find to be inconsistent >> logically. ... Please, no pedantic discourse explaining why I'm wrong... >> just put in into a PEP and move on. ?:) > > It does. ?"if len(list) == 0" Again +1 on the if len(list) == 0: Now... One thing that really concerns me about the Python community as a whole is the no. of varying opinions of "correct" ways of doing things and the distaste for a lot of things (which in Python are just obvious). If you are an opinionated individuals and disagree with the suggestion (even if it is "right"), perhaps keep that to yourself. if not my_list: is a perfectly valid and fine idiom to use in Python. If you prefer some other way, that's fine. Quite frankly I'm sick of seeing posts that argue for the sake of arguing. cheers James -- -- James Mills -- -- "Problems are solved by method" From wuwei23 at gmail.com Mon May 9 01:47:04 2011 From: wuwei23 at gmail.com (alex23) Date: Sun, 8 May 2011 22:47:04 -0700 (PDT) Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9ea3dc0e-06ba-4391-8e6a-1fdc3072ee10@35g2000prp.googlegroups.com> harrismh777 wrote: > [...] because *any* time or *most* types > can be substituted and the 'polymorphism' of Python kicks in allowing > for that [...] The same benefit one might get from using the idiomatic 'if not list:'? ;) From nicogrubert at yahoo.de Mon May 9 02:22:29 2011 From: nicogrubert at yahoo.de (Nico Grubert) Date: Mon, 09 May 2011 08:22:29 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: References: Message-ID: <4DC78825.4030905@yahoo.de> > I had this happening to me as well someday. > I recall that first installing it (python setup.py install), and then > rerunning selftest, solved that error. I tried that as well. Here is the summary of the install process: build/temp.linux-x86_64-2.4/libImaging/ZipEncode.o -L/usr/local/lib -L/usr/lib -ljpeg -lz -o build/lib.linux-x86_64-2.4/_imaging.so /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc building '_imagingft' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/freetype2 -IlibImaging -I/usr/local/include -I/usr/include -I/usr/local/include/python2.4 -c _imagingft.c -o build/temp.linux-x86_64-2.4/_imagingft.o gcc -pthread -shared build/temp.linux-x86_64-2.4/_imagingft.o -L/usr/local/lib -L/usr/lib -lfreetype -o build/lib.linux-x86_64-2.4/_imagingft.so /usr/bin/ld: skipping incompatible /usr/lib/libfreetype.so when searching for -lfreetype /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc building '_imagingmath' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/freetype2 -IlibImaging -I/usr/local/include -I/usr/include -I/usr/local/include/python2.4 -c _imagingmath.c -o build/temp.linux-x86_64-2.4/_imagingmath.o gcc -pthread -shared build/temp.linux-x86_64-2.4/_imagingmath.o -L/usr/local/lib -L/usr/lib -o build/lib.linux-x86_64-2.4/_imagingmath.so /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc -------------------------------------------------------------------- PIL 1.1.7 SETUP SUMMARY -------------------------------------------------------------------- version 1.1.7 platform linux2 2.4.6 (#1, Mar 16 2011, 11:33:33) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] -------------------------------------------------------------------- *** TKINTER support not available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available -------------------------------------------------------------------- To add a missing option, make sure you have the required library, and set the corresponding ROOT variable in the setup.py script. To check the build, run the selftest.py script. running build_scripts creating build/scripts-2.4 copying Scripts/pilfont.py -> build/scripts-2.4 copying and adjusting Scripts/pilconvert.py -> build/scripts-2.4 copying and adjusting Scripts/pilfile.py -> build/scripts-2.4 copying and adjusting Scripts/pilprint.py -> build/scripts-2.4 copying and adjusting Scripts/pildriver.py -> build/scripts-2.4 changing mode of build/scripts-2.4/pilfont.py from 644 to 755 changing mode of build/scripts-2.4/pilconvert.py from 644 to 755 changing mode of build/scripts-2.4/pilfile.py from 644 to 755 changing mode of build/scripts-2.4/pilprint.py from 644 to 755 changing mode of build/scripts-2.4/pildriver.py from 644 to 755 running install_lib copying build/lib.linux-x86_64-2.4/_imagingft.so -> /usr/local/lib/python2.4/site-packages/PIL copying build/lib.linux-x86_64-2.4/_imagingmath.so -> /usr/local/lib/python2.4/site-packages/PIL copying build/lib.linux-x86_64-2.4/_imaging.so -> /usr/local/lib/python2.4/site-packages/PIL running install_scripts copying build/scripts-2.4/pilconvert.py -> /usr/local/bin copying build/scripts-2.4/pilfile.py -> /usr/local/bin copying build/scripts-2.4/pilprint.py -> /usr/local/bin copying build/scripts-2.4/pildriver.py -> /usr/local/bin changing mode of /usr/local/bin/pilfont.py to 755 changing mode of /usr/local/bin/pilconvert.py to 755 changing mode of /usr/local/bin/pilfile.py to 755 changing mode of /usr/local/bin/pilprint.py to 755 changing mode of /usr/local/bin/pildriver.py to 755 creating /usr/local/lib/python2.4/site-packages/PIL.pth $ python selftest.py *** The _imaging C module is not installed Regards Nico From hg at schaathun.net Mon May 9 02:23:40 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 9 May 2011 07:23:40 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> Message-ID: On Sat, 07 May 2011 21:21:45 +1200, Gregory Ewing wrote: : You can manipulate them just fine by moving them : from one place to another: : : a = b : : You can use them to get at stuff they refer to: : : a = b.c : a[:] = b[:] Surely you can refer to the objects, but you cannot refer to the reference. : You can compare them: : : if a is b: : ... This could be implemented as pointer comparison, but it is not defined as such and there is no requirement that it be. : That's about all you can do with pointers in Pascal, : and I've never heard anyone argue that Pascal pointers : are any more or less abstract than any other piece of : data in that language. In Pascal a pointer is a distinct data type, and you can have variables of a given type or of type pointer to that given type. That makes the pointer a concrete concept defined by the languagedefined by the language. -- :-- Hans Georg From 4aedc00f81024 at poster.grepler.com Mon May 9 04:25:11 2011 From: 4aedc00f81024 at poster.grepler.com (Antonio CHESSA) Date: 09 May 2011 08:25:11 GMT Subject: How to access elemenst in a list of lists? In-Reply-To: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: >Just learning python. >I can see that I can address an individual element of a list of lists >by >doing something like: >row = list[5] >element = row[3] > >But is there a way to directly address an entry in a single statement? >Thanks for any help. >Regards >Chris Roy-Smith suppose you have a list like this: apple = [["a","b","c"],[1,2,3,4,5,6],["antony","max","sandra","sebastian"]] apple[0] = ["a","b","c"] apple[1] = [1,2,3,4,5,6] apple[2] = ["antony","max","sandra","sebastian"] apple[0][1] = "b" apple[2][3] = "sebastian" to view all videos in a loop so you can set: for i in range(len(apple)): print apple[i] for j in range (len(apple[i])): print apple[i][j] in your monitor when you do run this little program, you will see: ["a","b","c"] a b c [1,2,3,4,5,6] 1 2 3 4 5 6 ["antony","max","sandra","sebastian"] antony max sandra sebastian Bay vonkes ---------------------------- http://grepler.com groups From peterthebag at yahoo.com Mon May 9 04:35:11 2011 From: peterthebag at yahoo.com (pb) Date: Mon, 9 May 2011 01:35:11 -0700 (PDT) Subject: scipy References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> Message-ID: <7bee87fe-f157-4001-8901-e67586a999ba@q20g2000vbx.googlegroups.com> On May 9, 12:29?am, Terry Reedy wrote: > On 5/8/2011 6:44 AM, pb wrote: > > > Hi, > > I', having trouble with scipy. > > If you do not get an answer here, try the scipy list where scipy experts > hang out. You might also try searching the archives of that list or the > scipy bug tracker. > > -- > Terry Jan Reedy Hi, the scipy mailing list? Thanks, Peter From jean_paez at hotmail.es Mon May 9 04:56:40 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?RW55R21BIE3hcyBQcm8=?=) Date: Mon, 9 May 2011 03:56:40 -0500 Subject: HELP ME, PLEASE. SCRIP EXPORT TO .TM Message-ID: Good morning Python community, I need help to develop or create a script to export to. tmb but blender, there is to import. tmb in blender (look here: http://www.mediafire.com/?2g20yymmxam) this and I have, but need one to export in a blender. tmb. Windows platform (XP, Windows 7 and Windows Server). Thank you for your attention and your prompt response. Sincerely, Jean Carlos Paez R. I am of Colombia. ____________________________________ Versi?n espa?ol: Buenos d?as comunidad Python, necesito ayuda para desarrollar o crear un script para exportar a .tmb pero en blender, existe el de importar a .tmb en blender (miren aqu?: http://www.mediafire.com/?2g20yymmxam) este ya lo tengo, pero necesito uno que exporte en blender a .tmb. Plataforma windows (xp, windows 7 y windows server). Gracias por su atenci?n prestada y su pronta respuesta. Atentamente, Jean carlos P?ez R. Yo soy de Colombia. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jean_paez at hotmail.es Mon May 9 05:05:06 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?RW55R21BIE3hcyBQcm8=?=) Date: Mon, 9 May 2011 04:05:06 -0500 Subject: FW: AYUDA PORFAVOR. HELP ME, PLEASE. SCRIP EXPORT TO .TM In-Reply-To: References: Message-ID: aYudenme porfavor. Gracias. From: jean_paez at hotmail.es To: python-list at python.org; help at python.org; pycolombia at listas.el-directorio.org Subject: HELP ME, PLEASE. SCRIP EXPORT TO .TM Date: Mon, 9 May 2011 03:56:40 -0500 Good morning Python community, I need help to develop or create a script to export to. tmb but blender, there is to import. tmb in blender (look here: http://www.mediafire.com/?2g20yymmxam) this and I have, but need one to export in a blender. tmb. Windows platform (XP, Windows 7 and Windows Server). Thank you for your attention and your prompt response. Sincerely, Jean Carlos Paez R. I am of Colombia. ____________________________________ Versi?n espa?ol: Buenos d?as comunidad Python, necesito ayuda para desarrollar o crear un script para exportar a .tmb pero en blender, existe el de importar a .tmb en blender (miren aqu?: http://www.mediafire.com/?2g20yymmxam) este ya lo tengo, pero necesito uno que exporte en blender a .tmb. Plataforma windows (xp, windows 7 y windows server). Gracias por su atenci?n prestada y su pronta respuesta. Atentamente, Jean carlos P?ez R. Yo soy de Colombia. -------------- next part -------------- An HTML attachment was scrubbed... URL: From trent at snakebite.org Mon May 9 05:31:07 2011 From: trent at snakebite.org (Trent Nelson) Date: Mon, 9 May 2011 02:31:07 -0700 Subject: Coolest Python recipe of all time In-Reply-To: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: <5E3A89398864414E8EE2CB192E0C965C0A956F2746@EXMBX10.exchhosting.com> > What are your favorites? I think I've posted this before, but I love my 3-lines-if-you-ignore-the-scaffolding language translator. Not because it's clever code -- quite the opposite, the code is dead simple -- but because it encompasses one of the things I love about Python the most: it gets shit done. In [1]: from translate import * In [2]: translate('French', 'The quick brown fox jumped over the lazy dog.') Le renard brun rapide a saut? par-dessus le chien paresseux. In [3]: translate('German', 'The quick brown fox jumped over the lazy dog.') Der schnelle braune Fuchs sprang ?ber den faulen Hund. In [4]: translate('Spanish', 'The quick brown fox jumped over the lazy dog.') El zorro marr?n r?pido salt? sobre el perro perezoso. translate.py: import sys from urllib import urlopen, urlencode from BeautifulSoup import BeautifulSoup url = 'http://babelfish.altavista.com/tr' languages = { 'French' : 'en_fr', 'German' : 'en_de', 'Italian' : 'en_it', 'Spanish' : 'en_es', 'Russian' : 'en_ru', 'Portuguese': 'en_pt', 'Dutch' : 'en_nl', 'Japanese' : 'en_ja', } def translate(lang, text): kwds = { 'trtext' : text, 'lp' : languages[lang]} soup = BeautifulSoup(urlopen(url, urlencode(kwds))) print soup.find('div', style='padding:10px;').string if __name__ == '__main__': translate(sys.argv[1], sys.argv[2]) From lists at cheimes.de Mon May 9 06:28:06 2011 From: lists at cheimes.de (Christian Heimes) Date: Mon, 09 May 2011 12:28:06 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: <4DC78825.4030905@yahoo.de> References: <4DC78825.4030905@yahoo.de> Message-ID: Am 09.05.2011 08:22, schrieb Nico Grubert: > $ python selftest.py > *** The _imaging C module is not installed It works for me after an inplace installation of the C extensions with "python setup.py build_ext -i". With build_ext -i the C extension is installed inside the source tree so selftest can find it. Christian From hg at schaathun.net Mon May 9 06:38:30 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 9 May 2011 11:38:30 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> Message-ID: <6qsk98-em1.ln1@svn.schaathun.net> On Mon, 09 May 2011 12:52:27 +1200, Gregory Ewing wrote: : Let me save you from guessing. I'm thinking of a piece of paper with : a little box on it and the name 'a' written beside it. There is an : arrow from that box to a bigger box. : : +-------------+ : +---+ | | : a | --+---------------->| | : +---+ | | : +-------------+ The flaw of this model, and I am not discounting its merits, just pointing out that it isn't perfect, is that it creates the illusion that references are boxes (objects) just like data objects, leading the reader to think that we could have a reference to a reference. If they are all boxes, by can't we make reference thereto? -- :-- Hans Georg From felipe.vinturini at gmail.com Mon May 9 07:07:14 2011 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Mon, 9 May 2011 08:07:14 -0300 Subject: FW: AYUDA PORFAVOR. HELP ME, PLEASE. SCRIP EXPORT TO .TM In-Reply-To: References: Message-ID: On Mon, May 9, 2011 at 6:05 AM, EnyGmA M?s Pro wrote: > aYudenme porfavor. Gracias. > > ------------------------------ > From: jean_paez at hotmail.es > To: python-list at python.org; help at python.org; > pycolombia at listas.el-directorio.org > Subject: HELP ME, PLEASE. SCRIP EXPORT TO .TM > Date: Mon, 9 May 2011 03:56:40 -0500 > > Good morning Python community, I need help to develop or create a script > to export to. tmb but blender, there is to import. tmb in blender (look > here: http://www.mediafire.com/?2g20yymmxam) this and I have, but need one > to export in a blender. tmb. Windows platform (XP, Windows 7 and Windows > Server). > > Thank you for your attention and your prompt response. > > Sincerely, > > Jean Carlos Paez R. > > I am of Colombia. > > ____________________________________ > > Versi?n espa?ol: > > Buenos d?as comunidad Python, necesito ayuda para desarrollar o crear un > script para exportar a .tmb pero en blender, existe el de importar a .tmb en > blender (miren aqu?: http://www.mediafire.com/?2g20yymmxam) este ya lo > tengo, pero necesito uno que exporte en blender a .tmb. Plataforma windows > (xp, windows 7 y windows server). > > Gracias por su atenci?n prestada y su pronta respuesta. > > Atentamente, > > Jean carlos P?ez R. > > > Yo soy de Colombia. > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, What have you done so far? Please, post your code and traceback. It will be easier to help you... Regards, Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon May 9 07:18:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 May 2011 21:18:29 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <6qsk98-em1.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <6qsk98-em1.ln1@svn.schaathun.net> Message-ID: On Mon, May 9, 2011 at 8:38 PM, Hans Georg Schaathun wrote: > The flaw of this model, and I am not discounting its merits, just > pointing out that it isn't perfect, is that it creates the illusion > that references are boxes (objects) just like data objects, leading > the reader to think that we could have a reference to a reference. > If they are all boxes, by can't we make reference thereto? http://www.xkcd.com/895/ Analogies are like diagrams. Not all of them are perfect or useful. The boxes are different sizes. If you really want them to look different, do one as squares and one as circles, but don't try that in plain text. Chris Angelico From ander2_1434 at hotmail.com Mon May 9 08:13:00 2011 From: ander2_1434 at hotmail.com (ander2_1434 at hotmail.com) Date: Mon, 9 May 2011 05:13:00 -0700 (PDT) Subject: input() or raw_input() in Console module. Message-ID: I'm using Console module (doc: http://effbot.org/zone/console-handbook.htm, like nCurses) on Windows, but I don't know how to call a keyboard input like input() or raw_input(). What to do? From steve+comp.lang.python at pearwood.info Mon May 9 10:29:04 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 May 2011 14:29:04 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> Message-ID: <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 May 2011 12:52:27 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> Since you haven't explained what you think is happening, I can only >> guess. > > Let me save you from guessing. I'm thinking of a piece of paper with a > little box on it and the name 'a' written beside it. There is an arrow > from that box to a bigger box. > > +-------------+ > +---+ | | > a | --+---------------->| | > +---+ | | > +-------------+ > > There is another little box labelled 'b'. After executing 'a = b', both > little boxes have arrows pointing to the same big box. [...] > In this model, a "reference" is an arrow. Manipulating references > consists of rubbing out the arrows and redrawing them differently. All very good, but that's not what takes place at the level of Python code. It's all implementation. I think Hans Georg Schaathun made a good objection to the idea that "Python has references": In Pascal a pointer is a distinct data type, and you can have variables of a given type or of type pointer to that given type. That makes the pointer a concrete concept defined by the language. The same can't be said of "references" in Python. It's not part of Python the language, although it might be part of Python's implementation. > Also > in this model, a "variable" is a little box. It's *not* the same thing > as a name; a name is a label for a variable, not the variable itself. That's essentially the same model used when dealing with pointers. I've used it myself, programming in Pascal. The "little box" named a or b is the pointer variable, and the "big box" is the data that the pointer points to. It's not an awful model for Python: a name binding a = obj is equivalent to sticking a reference (a pointer?) in box a that points to obj. Certainly there are advantages to it. But one problem is, the model is ambiguous with b = a. You've drawn little boxes a and b both pointing to the big box (which I deleted for brevity). But surely, if a = 1234 creates a reference from a to the big box 1234, then b = a should create a reference from b to the box a? +-------------+ +---+ | | a | --+---------------->| | +---+ | | ^ +-------------+ | +-|-+ b | | | +---+ which is the reference (pointer) model as most people would recognise it. That's how it works in C and Pascal (well, at least with the appropriate type declarations). To get b pointing to the big box, you would need an explicit dereference: "b = whatever a points to" rather than "b = a". Of course, both of these concepts are models, which is another word for "lies" *wink*. Your model is closer to what the CPython implementation actually does, using actual C pointers, except of course you do need to dereference the pointers appropriately. One of my objections to it is not that it is wrong (all models are wrong) but that it will mislead some people to reason incorrectly about Python's behaviour, e.g. that b now points to the little box a, and therefore if you change what a points to, b will follow along. The whole "call by reference" thing. I suppose you might argue that you're not responsible for the misunderstandings of blinkered C coders *wink*, and there's something to that. But there's another objection... take, say, the line of Python code: n = len('hello world') I can identify the little box "n", which ends up pointing to the big box holding int 11; another little box "len", which points to a big box holding a function; and a third big box holding the string 'hello world'. But where is its little box? If len were written in pure Python, then *inside* len's namespace there would be a local little box for the argument. I expect that there is an analogous local little box for built-in functions too. But I don't care what happens inside len. What about outside len? Where's the little box pointing to 'hello world'? So it seems your model fails to deal with sufficiently anonymous objects. I say "sufficiently", because of course your model deals fine with objects without names inside, say, lists: the little box there is the list slot rather than a named entry in a namespace. It's not just literals that your model fails to deal with, it's any expression that isn't bound to a little box: n = len('hello world') + func(y) func(y) produces a new object, a big box. Where is the little box pointing to it? If we drop down an abstraction layer, we can see where objects live: >>> code = compile("n = len('hello world') + func(y)", '', 'single') >>> import dis >>> dis.dis(code) 1 0 LOAD_NAME 0 (len) 3 LOAD_CONST 0 ('hello world') 6 CALL_FUNCTION 1 9 LOAD_NAME 1 (func) 12 LOAD_NAME 2 (y) 15 CALL_FUNCTION 1 18 BINARY_ADD 19 STORE_NAME 3 (n) 22 LOAD_CONST 1 (None) 25 RETURN_VALUE Both the call to len and the call to func push their results onto the stack. There's no little box pointing to the result. There's no little box pointing to len, or y, or any of the others: there are just names and abstract operations LOAD_NAME and friends. Again, this is just an abstraction layer. Python objects can be huge, potentially hundreds of megabytes or gigabytes. No way are they being pushed and popped onto a stack, even if the virtual machine gives the illusion that they are. For practical reasons, there must be some sort of indirection. But that's implementation and not the VM's model. > It seems that you would prefer to eliminate the little boxes and arrows > and write the names directly beside the objects: > > +-------------+ > a | | > | | > b | | > +-------------+ > > +-------------+ > c | | > | | > | | > +-------------+ That's not a bad model. But again, it's incomplete, because it would suggest that the big box should be able to read its own name tags, which of course is impossible in Python. But I suppose one might say, if the tag is on the outside of the object, the object can't use introspection to see it, can it? But note that this is really your model in disguise: if you imagine the name tags are stuck on with a little piece of blutack, and you carefully pull on the name and stretch it away, you get a name sitting over here with a tiny thread of blutack attaching it to the big box over there, just like in your model. I actually prefer to keep the nature of the mapping between name and object abstract: names map to objects. Objects float around in space, wherever the interpreter happens to put them, and you can optionally give them names. Objects are dumb and don't know their own name, but the Python interpreter knows the names. Names are not the only way to ask the interpreter for an object: e.g. you can put them in a list, and ask for them by position. If people then ask, how does the interpreter know the names?, I can add more detail: names are actually strings in a namespace, which is usually nothing more than a dict. Oh, and inside functions, it's a bit more complicated still. And so on. There is a problem with my model of free-floating objects in space: it relies on objects being able to be in two places at once, even *inside* themselves (you can append a list to itself). If you hate that concept, you'll hate my model. But if you're a science fiction fan from way back, then you won't have any problem with the idea that objects can be inside themselves: http://www.youtube.com/watch?v=51JtuEa_OPc Remember: it's just a model, and all models are lies. Abstractions all leak. You can only chose where and how badly they break down. Now, that's a good challenge for your model. Little boxes only point to big boxes. So how do you model cycles, including lists that contain themselves? > But what would you do about lists? With little boxes and arrows, you can > draw a diagram like this: > > +---+ +---+ > a | --+----->| | +-------------+ > +---+ +---+ | | > | --+----->| | > +---+ | | > | | +-------------+ > +---+ > > (Here, the list is represented as a collection of variables. That's why > variables and names are not the same thing -- the elements of the list > don't have textual names.) But that's wrong! Names (little boxes) can't point to *slots in a list*, any more than they can point to other names! This doesn't work: >>> L = [None, 42, None] >>> a = L[0] >>> L[0] = 23 >>> print(a) # This doesn't work! 23 It's a pity that Python doesn't actually have references. Imagine how much time we'd save: all the unproductive time we spend arguing about whether Python has references, we could be fixing bugs caused by the use of references instead... > But without any little boxes or arrows, you can't represent the list > itself as a coherent object. You would have to go around and label > various objects with 'a[0]', 'a[1]', etc. > > +-------------+ > a[0] | | > | | > | | > +-------------+ > > +-------------+ > a[1] | | > | | > | | > +-------------+ > > This is not very satisfactory. If the binding of 'a' changes, you have > to hunt for all your a[i] labels, rub them out and rewrite them next to > different objects. It's hardly conducive to imparting a clear > understanding of what is going on, whereas the boxes-and-arrows model > makes it instantly obvious. But I wouldn't do it like that. I'd do it like this: 0 1 2 3 4 +--------+--------+--------+--------+--------+ a | | | | | | | | | | | | | | | | | | +--------+--------+--------+--------+--------+ which conveniently happens to be the way Python lists actually are set up. More or less. [...] > Finally, there's another benefit of considering a reference to be a > distinct entity in the data model. If you think of the little boxes as > being of a fixed size, just big enough to hold a reference, then it's > obvious that you can only bind it to *one* object at a time. Otherwise > it might appear that you could draw more than one arrow coming out of a > name, or write the same name next to more than one object. But that's pretty much an arbitrary restriction. Why are the boxes so small? Just because. Why can't you carefully tease the thread of blutack apart, into a bifurcated Y shaped thread? Just because. If objects can be in two places at once, why can't names? Just because. (Actually, because Guido decrees it so. Also because it would be kinda crazy to do otherwise. I can't think of any language that has a many:many mapping between names and values.) -- Steven From robert.kern at gmail.com Mon May 9 10:34:12 2011 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 09 May 2011 09:34:12 -0500 Subject: scipy In-Reply-To: <7bee87fe-f157-4001-8901-e67586a999ba@q20g2000vbx.googlegroups.com> References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> <7bee87fe-f157-4001-8901-e67586a999ba@q20g2000vbx.googlegroups.com> Message-ID: On 5/9/11 3:35 AM, pb wrote: > On May 9, 12:29 am, Terry Reedy wrote: >> On 5/8/2011 6:44 AM, pb wrote: >> >>> Hi, >>> I', having trouble with scipy. >> >> If you do not get an answer here, try the scipy list where scipy experts >> hang out. You might also try searching the archives of that list or the >> scipy bug tracker. >> >> -- >> Terry Jan Reedy > > Hi, > the scipy mailing list? http://www.scipy.org/Mailing_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 mail at timgolden.me.uk Mon May 9 10:41:11 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 09 May 2011 15:41:11 +0100 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DC7FD07.6060402@timgolden.me.uk> On 09/05/2011 15:29, Steven D'Aprano wrote: [... snippage galore ...] Slightly abstract comment: while I don't usually get much enjoyment out of the regular "Python is call-by-value; no it isn't; yes it is" debates, I always enjoy reading Steven D'Aprano's responses. Thanks, Mr D'A. :) TJG From nobody at nowhere.net.no Mon May 9 10:53:44 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 09 May 2011 22:53:44 +0800 Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> Message-ID: Vinay Sajip wrote: > logging.basicConfig(level=logging.DEBUG, format='%(message)s') logging.basicConfig(format='%(message)s', level=logging.DEBUG) I formulated in the reverse order of arguments, may that cause an unpredicted result? The other points became clearer.. Once again Thank You -- goto /dev/null From Dick.Bridges at wdc.com Mon May 9 11:22:42 2011 From: Dick.Bridges at wdc.com (Dick Bridges) Date: Mon, 9 May 2011 08:22:42 -0700 Subject: setuptools for 64-bit 2.7.1 on 64-bit Windows 7? In-Reply-To: References: Message-ID: David, Thanks for the link. I'd scanned but skipped it because it was "third-party". This time I started following some of the links and finally found the link for distutils: http://pypi.python.org/pypi/distribute#installation-instructions. Works like a charm. Thanks for pointing me back to that link - I was clearly too hasty dismissing it during my so-called "due diligence". 8-P Dick Bridges (\(\ Western Digital ?". .. ( . .) The opinions and data in this missive are my own and do not necessarily | ? ? represent Western Digital positions, strategies, or opinions. ? ; c?".UJ" Glenda: http://glenda.cat-v.org/gallery/ > -----Original Message----- > From: David Robinow [mailto:drobinow at gmail.com] > Sent: Friday, May 06, 2011 3:25 PM > To: Dick Bridges > Cc: python-list at python.org > Subject: Re: setuptools for 64-bit 2.7.1 on 64-bit Windows 7? > > On Fri, May 6, 2011 at 1:43 PM, Dick Bridges > wrote: > > Simple question: Is it true that no setuptools (or any other module > > installer) exists for 64-bit python 2.7.1? If there is an installer > that > > works, what terms might I use to Google for information on how to > acquire > > and install it? > Doesn't the installer at > http://www.lfd.uci.edu/~gohlke/pythonlibs/ > work? From chris at simplistix.co.uk Mon May 9 12:22:33 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 09 May 2011 17:22:33 +0100 Subject: Zope with mySQL In-Reply-To: <31499628.post@talk.nabble.com> References: <31499628.post@talk.nabble.com> Message-ID: <4DC814C9.5040301@simplistix.co.uk> Hi Harry, You'd be better off asking this on the zope at zope.org mailing list... cheers, Chris On 28/04/2011 20:19, harryjatt wrote: > > Hi, i am doing web development with Zope. My connected database is mySQL. I > am new to this combination.I have to upload the files to mySQL with > programming in zope and then downloading them via zope.Can you help me in > this regard? I will be very thankfull to you. > Regards, Harry -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From vinay_sajip at yahoo.co.uk Mon May 9 12:34:54 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 9 May 2011 09:34:54 -0700 (PDT) Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> Message-ID: <7508a36a-5d27-49a7-8572-c9bba3d2c61e@h12g2000pro.googlegroups.com> On May 9, 3:53?pm, TheSaint wrote: > Vinay Sajip wrote: > >logging.basicConfig(level=logging.DEBUG, format='%(message)s') > > logging.basicConfig(format='%(message)s', level=logging.DEBUG) > > I formulated in the reverse order of arguments, may that cause an > unpredicted result? No, you can pass keyword arguments in any order - that's what makes them keyword, as opposed to positional, arguments. Regards, Vinay Sajip From ethan at stoneleaf.us Mon May 9 13:15:05 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 09 May 2011 10:15:05 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DC82119.2020601@stoneleaf.us> Steven D'Aprano wrote: > But that's wrong! Names (little boxes) can't point to *slots in a list*, > any more than they can point to other names! This doesn't work: > > > --> L = [None, 42, None] > --> a = L[0] > --> L[0] = 23 > --> print(a) # This doesn't work! > 23 Minor nitpick -- having a comment saying "this doesn't work" then having output showing that it does is confusing. I had to load up the interpretor to make sure I was confused! ;) ~Ethan~ From mwilson at the-wire.com Mon May 9 13:38:44 2011 From: mwilson at the-wire.com (Mel) Date: Mon, 09 May 2011 13:38:44 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > It's not an awful model for Python: a name binding a = obj is equivalent > to sticking a reference (a pointer?) in box a that points to obj. > Certainly there are advantages to it. > > But one problem is, the model is ambiguous with b = a. You've drawn > little boxes a and b both pointing to the big box (which I deleted for > brevity). But surely, if a = 1234 creates a reference from a to the big > box 1234, then b = a should create a reference from b to the box a? :) There's a way around that too. Describe literals as "magic names" or "Platonic names" that are bound to objects in ideal space. I actually considered that for a while as a way of explaining to newbs why the characters in a string literal could be different from the characters in the string value. This would probably have troubles of its own; I never took it through the knock-down drag-out disarticulation that would show what the problems were. Mel. From jamfwright at gmail.com Mon May 9 14:10:21 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 14:10:21 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? Message-ID: Hello, I have been using a script on several boxes that have been around for a while, and everything works just fine. I am finding though, that on some new OS installs the script fails with: Traceback (most recent call last): File "render4.py", line 114, in create_report_index(each_item) File "render4.py", line 25, in create_report_index [clean_name, _] = each_value.split('_', 1) ValueError: need more than 1 value to unpack The OS's are various OpenSuse installs from 10.3 to 11.4. It works on all the existing ones, which leads me to believe that I have a package or configuration inconsistency. It should be noted though that I am quite new to python programming and very well could have coded in a non-portable manner and was just lucky to get it working in the first place :) Here is the code snippet that generates the failure ( when you look at this remember that I am a novice :-) ): for each_item in D4: #D4 is a dictionary create_report_index(each_item) def create_report_index(report): #Here we are creating a simple index.html file from data in a text file newfile = open(report + '.html', 'w') #Create the index file using report name for each_value in D4[report]: [clean_name, _] = each_value.split('_', 1) newfile.write('' + clean_name + '
\n') I've tried to match packages from a known working install and even compiled a newer python (one known to work, version 3.1.3 in this particular case). The only discernible difference is that the new OS installs are VM's hosted on VMWare ESX. Using the same ISO I can spin up a VirtualBox VM and the script works just fine. I've tried this with OpenSuse 11.3 and 11.4, once again, using the exact same ISO's to install. Do I have a Python, OS, or package issue? Many thanks, James From peterthebag at yahoo.com Mon May 9 14:13:55 2011 From: peterthebag at yahoo.com (pb) Date: Mon, 9 May 2011 11:13:55 -0700 (PDT) Subject: scipy References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> <7bee87fe-f157-4001-8901-e67586a999ba@q20g2000vbx.googlegroups.com> Message-ID: <6bfdb99c-c8db-4c5c-af2b-35ff88bd94d8@32g2000vbe.googlegroups.com> On May 9, 3:34?pm, Robert Kern wrote: > On 5/9/11 3:35 AM, pb wrote: > > > On May 9, 12:29 am, Terry Reedy ?wrote: > >> On 5/8/2011 6:44 AM, pb wrote: > > >>> Hi, > >>> I', having trouble with scipy. > > >> If you do not get an answer here, try the scipy list where scipy experts > >> hang out. You might also try searching the archives of that list or the > >> scipy bug tracker. > > >> -- > >> Terry Jan Reedy > > > Hi, > > the scipy mailing list? > > http://www.scipy.org/Mailing_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 Thanks, I have tried to register for the mailing lists there, but cannot loggin and have received no "registration comfirmation email" from them. I'd email the list maintainer/admin, but cannot find an email address for them. Peter From irmen.NOSPAM at xs4all.nl Mon May 9 14:16:42 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 09 May 2011 20:16:42 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: References: Message-ID: <4dc82f8b$0$32470$e4fe514c@news.xs4all.nl> On 9-5-2011 8:22, Nico Grubert wrote: >> I had this happening to me as well someday. >> I recall that first installing it (python setup.py install), and then >> rerunning selftest, solved that error. > > I tried that as well. > Here is the summary of the install process: > > build/temp.linux-x86_64-2.4/libImaging/ZipEncode.o -L/usr/local/lib -L/usr/lib -ljpeg > -lz -o build/lib.linux-x86_64-2.4/_imaging.so [...] > > $ python selftest.py > *** The _imaging C module is not installed > Don't know why the build seems to fail. PIL installs and works fine on all computers I've installed it on recently... What happens when you just forget about selftest and run python and type import Image? Doesn't the package manager on CentOS offer a python-imaging, python-pil or whatever precompiled and configured package? If not (why not!?) try pip install PIL. Irmen From bob at example.com Mon May 9 14:20:01 2011 From: bob at example.com (Bob Fnord) Date: Mon, 09 May 2011 20:20:01 +0200 Subject: can't get urllib2 or httplib to work with tor & privoxy Message-ID: Here's my python code: import httplib, urllib2 proxy_handler = {'http' : 'localhost:8118', 'https' : 'localhost:8118'} def connect_u2(url = 'http://ipid.shat.net/iponly/'):, proxied = urllib2.ProxyHandler(proxy_handler) opnr = urllib2.build_opener(proxied) opnr.addheaders = [('User-agent', agent)] rsp = opnr.open(url) page = rsp.read() return page def connect_h(url = 'http://ipid.shat.net/iponly/'): cnn = httplib.HTTPConnection('127.0.0.1', 8118) cnn.connect() cnn.request('GET', url) rsp = cnn.getresponse() stderr.write('%u %s\n' % (rsp.status, rsp.reason)) page = rsp.read(500) cnn.close() return page Both methods give me a 503 error, even though this export http_proxy='http://localhost:8118/' lynx -dump 'http://ipid.shat.net/iponly/' works in bash and prints out the IP of a tor exit. What am I doing wrong in python? (I tried both 'localhost:8118' and 'http://localhost:8118/' in the proxy_handler dict.) From ian.g.kelly at gmail.com Mon May 9 14:41:58 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 May 2011 12:41:58 -0600 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: Message-ID: On Mon, May 9, 2011 at 12:10 PM, James Wright wrote: > Hello, > > I have been using a script on several boxes that have been around for > a while, and everything works just fine. ?I am finding though, that on > some new OS installs the script fails with: > > Traceback (most recent call last): > ?File "render4.py", line 114, in > ? ?create_report_index(each_item) > ?File "render4.py", line 25, in create_report_index > ? ?[clean_name, _] = each_value.split('_', 1) > ValueError: need more than 1 value to unpack You should check the value of each_value at the point when the script fails. It sounds like split() is getting passed a string that doesn't contain any '_' characters at all, resulting in a sequence with only one value. Passing 1 as the second argument ensures that there will be at most 1 split, but there may still be fewer. Cheers, Ian From steve+comp.lang.python at pearwood.info Mon May 9 14:43:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 May 2011 18:43:09 GMT Subject: Inconsistency with split() - Script, OS, or Package Problem? References: Message-ID: <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 May 2011 14:10:21 -0400, James Wright wrote: > Hello, > > I have been using a script on several boxes that have been around for a > while, and everything works just fine. I am finding though, that on > some new OS installs the script fails with: > > Traceback (most recent call last): > File "render4.py", line 114, in > create_report_index(each_item) > File "render4.py", line 25, in create_report_index > [clean_name, _] = each_value.split('_', 1) > ValueError: need more than 1 value to unpack It's a data issue, not an OS or package problem. Firstly, you don't have to wrap the left hand side in brackets, this works fine: >>> each_value = "aaa_bbb_ccc" >>> clean_name, _ = each_value.split('_', 1) >>> clean_name 'aaa' However, if your data has no underscore at all: >>> each_value = "aaa*bbb*ccc" >>> clean_name, _ = each_value.split('_', 1) Traceback (most recent call last): File "", line 1, in ValueError: need more than 1 value to unpack So you need to allow for the possibility that there is no underscore. -- Steven From ethan at stoneleaf.us Mon May 9 14:56:13 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 09 May 2011 11:56:13 -0700 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: Message-ID: <4DC838CD.7030404@stoneleaf.us> James Wright wrote: > Hello, Howdy! > def create_report_index(report): #Here we are creating a simple > index.html file from data in a text file > newfile = open(report + '.html', 'w') #Create the index file using > report name > for each_value in D4[report]: > [clean_name, _] = each_value.split('_', 1) > newfile.write('' + clean_name + '
\n') Add the line print("current each_value is: %s" % each_value) just before the line [clean_name, _] = each_value.split('_', 1) I'm guessing you'll see a value with no '_' in it -- at that point you can track down why. ~Ethan~ From jamfwright at gmail.com Mon May 9 15:02:17 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 15:02:17 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: <4DC838CD.7030404@stoneleaf.us> References: <4DC838CD.7030404@stoneleaf.us> Message-ID: Thank you Ethan, This is what I see now: # python render4.py current each_value is: vsr Traceback (most recent call last): File "render4.py", line 115, in create_report_index(each_item) File "render4.py", line 26, in create_report_index [clean_name, _] = each_value.split('_', 1) ValueError: need more than 1 value to unpack # grep -i vsr * # Using the informational line you suggested I see that 'vsr' showing as the current each_value. The string 'vsr' does not exist in my data though. Where could this be coming from? Thanks, James On Mon, May 9, 2011 at 2:56 PM, Ethan Furman wrote: > James Wright wrote: >> >> Hello, > > Howdy! > >> def create_report_index(report): ?#Here we are creating a simple >> index.html file from data in a text file >> ? ?newfile = open(report + '.html', 'w') #Create the index file using >> report name >> ? ?for each_value in D4[report]: >> ? ? ? ?[clean_name, _] = each_value.split('_', 1) >> ? ? ? ?newfile.write('' + clean_name + '
\n') > > Add the line > > ? ?print("current each_value is: %s" % each_value) > > just before the line > > ? ?[clean_name, _] = each_value.split('_', 1) > > > I'm guessing you'll see a value with no '_' in it -- at that point you can > track down why. > > ~Ethan~ > From jamfwright at gmail.com Mon May 9 15:09:32 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 15:09:32 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thank you Steven, I will take your advice :) In this particular case though, I do not think a lack of underscore is the issue, at least as far as I can understand the issue. Please see my reply to Ethan. Thanks, James On Mon, May 9, 2011 at 2:43 PM, Steven D'Aprano wrote: > On Mon, 09 May 2011 14:10:21 -0400, James Wright wrote: > >> Hello, >> >> I have been using a script on several boxes that have been around for a >> while, and everything works just fine. ?I am finding though, that on >> some new OS installs the script fails with: >> >> Traceback (most recent call last): >> ? File "render4.py", line 114, in >> ? ? create_report_index(each_item) >> ? File "render4.py", line 25, in create_report_index >> ? ? [clean_name, _] = each_value.split('_', 1) >> ValueError: need more than 1 value to unpack > > It's a data issue, not an OS or package problem. > > Firstly, you don't have to wrap the left hand side in brackets, this > works fine: > >>>> each_value = "aaa_bbb_ccc" >>>> clean_name, _ = each_value.split('_', 1) >>>> clean_name > 'aaa' > > > However, if your data has no underscore at all: > >>>> each_value = "aaa*bbb*ccc" >>>> clean_name, _ = each_value.split('_', 1) > Traceback (most recent call last): > ?File "", line 1, in > ValueError: need more than 1 value to unpack > > > > So you need to allow for the possibility that there is no underscore. > > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From jamfwright at gmail.com Mon May 9 15:10:39 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 15:10:39 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: Message-ID: Hello Ian, It does indeed to seem that way. However the script works just fine on other machines, with the same input file. Thanks, James On Mon, May 9, 2011 at 2:41 PM, Ian Kelly wrote: > On Mon, May 9, 2011 at 12:10 PM, James Wright wrote: >> Hello, >> >> I have been using a script on several boxes that have been around for >> a while, and everything works just fine. ?I am finding though, that on >> some new OS installs the script fails with: >> >> Traceback (most recent call last): >> ?File "render4.py", line 114, in >> ? ?create_report_index(each_item) >> ?File "render4.py", line 25, in create_report_index >> ? ?[clean_name, _] = each_value.split('_', 1) >> ValueError: need more than 1 value to unpack > > You should check the value of each_value at the point when the script > fails. ?It sounds like split() is getting passed a string that doesn't > contain any '_' characters at all, resulting in a sequence with only > one value. ?Passing 1 as the second argument ensures that there will > be at most 1 split, but there may still be fewer. > > Cheers, > Ian > From csamaras72 at gmail.com Mon May 9 15:13:31 2011 From: csamaras72 at gmail.com (CTS) Date: Mon, 9 May 2011 12:13:31 -0700 (PDT) Subject: Missing 'line' event when writing to frame.f_lineno in trace function Message-ID: <4a0fce60-2ecd-47fd-822d-9a9b90210b3d@17g2000prr.googlegroups.com> Hello all, I've been playing with sys.settrace() in an attempt to better understand how trace functions (and debugging) work. I'm running Python3.2 on Windows, which I installed by running the installer package (i.e. I did not compile from source code). Here's my code, some of which I borrowed from Pdb/Bdb. The trace function basically prints out the event type, the filename, and the line number, and asks the user what to do next. If "jump " is entered, is written to frame.f_lineno before moving on. Otherwise, we just move on to the next trace event. # ---------- BEGIN tracing code ------------------- import sys import __main__ import re class Tracer: def __init__( self, filename ): __main__.__dict__.clear() __main__.__dict__.update( { "__name__": "__main__", "__file__": filename, "__builtins__": __builtins__, } ) with open( filename, "rb" ) as file: code = compile( file.read(), filename, 'exec') sys.settrace( self.trace ) exec( code, __main__.__dict__ ) def trace( self, frame, event, arg ): filename = frame.f_code.co_filename line = frame.f_lineno prompt = event + " -> " + filename + "(" + str( line ) + "):" action = input( prompt ) tokens = re.split( " +", action ) if tokens[ 0 ] == "jump": frame.f_lineno = int( tokens[ 1 ] ) return self.trace def run( filename ): Tracer( filename ) # ---------- END end tracing code ------------- I start tracing a script's execution by typing the following at the interactive prompt: >>> import tracer >>> tracer.run( "insert file name here" ) Given the following code, # ----- BEGIN traced script ------ print( "Line 1" ) print( "Line 2" ) print( "Line 3" ) print( "Line 4" ) # ----- END traced script------- ... I get the following output if I just step though from beginning to end: # BEGIN output (no writes to frame.f_lineno) C:\python_tests>python Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1 32 Type "help", "copyright", "credits" or "license" for m >>> import tracer >>> tracer.run('just_prints.py') call -> just_prints.py(1): line -> just_prints.py(1): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 1call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(2): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 2call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(3): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 3call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(4): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 4call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): return -> just_prints.py(6): >>> # END output (no writes to frame.f_lineno) So, as expected, I get "line" events for each of my script's lines, and it appears that the print() built-in calls some helper functions in lib\encodings\cp437.py, which is fine and explainable. Now, if I try to jump to any line during the trace (in the following output, after I'm done with line 3, I try to jump back to line 1 by writing "1" to frame.f_lineno), I don't get the "line" event; instead I go directly to the first "call" event of file cp437.py: # BEGIN output (with a write to frame.f_lineno) C:\python_tests>python Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit ( 32 Type "help", "copyright", "credits" or "license" for more informat >>> import tracer >>> tracer.run( 'just_prints.py') call -> just_prints.py(1): line -> just_prints.py(1): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 1call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(2): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 2call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(3): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 3call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(4):jump 1 <======= write to frame.f_lineno call -> c:\python32\lib\encodings\cp437.py(18): <======= No "line" event !!!! line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 1call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(2): # # END output (with a write to frame.f_lineno) The above behavior occurs both when I jump back, as well as forward in a script. My questions to the group: 1) I was expecting a "line" event for line 1 of my traced script right after I wrote "1" to frame.f_lineno, shouldn't that event have been passed to my trace function? 2) Is there a way to get the missing "line" event by any means other than by writing to frame.f_lineno? My apologies for the lengthy message. Thanks in advance for your insights, -CTS From tjreedy at udel.edu Mon May 9 15:24:16 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 15:24:16 -0400 Subject: How to access elemenst in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/9/2011 4:25 AM, Antonio CHESSA wrote: > apple = [["a","b","c"],[1,2,3,4,5,6],["antony","max","sandra","sebastian"]] > > apple[0] = ["a","b","c"] > apple[1] = [1,2,3,4,5,6] > apple[2] = ["antony","max","sandra","sebastian"] > > apple[0][1] = "b" > apple[2][3] = "sebastian" > > to view all videos in a loop so you can set: > > for i in range(len(apple)): > print apple[i] > for j in range (len(apple[i])): > print apple[i][j] While this illustrate double indexing, it can be simplified to for top in apple: print(top) for inner in top: print(inner) and give the same output. Indexing is only needed for random access and for changing a list in place. -- Terry Jan Reedy From python at mrabarnett.plus.com Mon May 9 15:25:40 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 09 May 2011 20:25:40 +0100 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: Message-ID: <4DC83FB4.4050503@mrabarnett.plus.com> On 09/05/2011 20:10, James Wright wrote: > On Mon, May 9, 2011 at 2:41 PM, Ian Kelly wrote: >> On Mon, May 9, 2011 at 12:10 PM, James Wright wrote: >>> Hello, >>> >>> I have been using a script on several boxes that have been around for >>> a while, and everything works just fine. I am finding though, that on >>> some new OS installs the script fails with: >>> >>> Traceback (most recent call last): >>> File "render4.py", line 114, in >>> create_report_index(each_item) >>> File "render4.py", line 25, in create_report_index >>> [clean_name, _] = each_value.split('_', 1) >>> ValueError: need more than 1 value to unpack >> >> You should check the value of each_value at the point when the script >> fails. It sounds like split() is getting passed a string that doesn't >> contain any '_' characters at all, resulting in a sequence with only >> one value. Passing 1 as the second argument ensures that there will >> be at most 1 split, but there may still be fewer. >> > It does indeed to seem that way. However the script works just fine > on other machines, with the same input file. > 'each_value' gets its value from D4[report], so check which value of 'report' that is, and look at where 'D4' is filled. From ggrp2.20.martineau at dfgh.net Mon May 9 15:26:28 2011 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Mon, 9 May 2011 12:26:28 -0700 (PDT) Subject: Custom string joining References: Message-ID: On May 7, 5:31?am, Claudiu Popa wrote: > Hello Python-list, > > I ?have ?an object which defines some methods. I want to join a list or > an iterable of those objects like this: > > new_string = "|".join(iterable_of_custom_objects) > > What ? is ? the ? __magic__ ?function that needs to be implemented for > this case to work? ?I ?though ?that ?__str__ ?is sufficient but it doesn't seems to > work. Thanks in advance. > > PC Instead of join() here's a function that does something similar to what the string join() method does. The first argument can be a list of any type of objects and the second separator argument can likewise be any type. The result is list of the various objects. (The example usage just uses a list of string objects and separator to illustrate what it does.) def tween(seq, sep): return reduce(lambda r,v: r+[sep,v], seq[1:], seq[:1]) lst = ['a','b','c','d','e'] print tween(lst, '|') print ''.join(tween(lst, '|')) Output: ['a', '|', 'b', '|', 'c', '|', 'd', '|', 'e'] a|b|c|d|e It could be made a little more memory efficient by applying the itertools module's islice() generator to the first 'seq' argument passed to reduce(): def tween(seq, sep): return reduce(lambda r,v: r+[sep,v], itertools.islice(seq,1,None), seq[:1]) -- Martin From jamfwright at gmail.com Mon May 9 15:29:34 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 15:29:34 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: <4DC84223.3000502@stoneleaf.us> References: <4DC838CD.7030404@stoneleaf.us> <4DC84223.3000502@stoneleaf.us> Message-ID: On Mon, May 9, 2011 at 3:36 PM, Ethan Furman wrote: > James Wright wrote: >> >> Thank you Ethan, >> >> This is what I see now: >> >> # python render4.py >> current each_value is: vsr >> Traceback (most recent call last): >> ?File "render4.py", line 115, in >> ? ?create_report_index(each_item) >> ?File "render4.py", line 26, in create_report_index >> ? ?[clean_name, _] = each_value.split('_', 1) >> ValueError: need more than 1 value to unpack >> >> # grep -i vsr * >> # >> >> Using the informational line you suggested I see that 'vsr' showing as >> the current each_value. ?The string 'vsr' does not exist in my data >> though. ?Where could this be coming from? > > So 'vsr' in the value -- what is the key? ?(Sorry, should have had you print > that at the same time...) > > Change your print line to: > > ? ?print("D4[%s] = %s" % (report, each_value)) > > After that, you'll have to track down how D4 is being created to see where > 'vsr' is coming from. > > ~Ethan~ > Hi Ethan, It does not appear to show a key: D4[] = vsr Traceback (most recent call last): File "render4.py", line 115, in create_report_index(each_item) File "render4.py", line 26, in create_report_index [clean_name, _] = each_value.split('_', 1) ValueError: need more than 1 value to unpack Thanks, James From ethan at stoneleaf.us Mon May 9 15:36:03 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 09 May 2011 12:36:03 -0700 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: <4DC838CD.7030404@stoneleaf.us> Message-ID: <4DC84223.3000502@stoneleaf.us> James Wright wrote: > Thank you Ethan, > > This is what I see now: > > # python render4.py > current each_value is: vsr > Traceback (most recent call last): > File "render4.py", line 115, in > create_report_index(each_item) > File "render4.py", line 26, in create_report_index > [clean_name, _] = each_value.split('_', 1) > ValueError: need more than 1 value to unpack > > # grep -i vsr * > # > > Using the informational line you suggested I see that 'vsr' showing as > the current each_value. The string 'vsr' does not exist in my data > though. Where could this be coming from? So 'vsr' in the value -- what is the key? (Sorry, should have had you print that at the same time...) Change your print line to: print("D4[%s] = %s" % (report, each_value)) After that, you'll have to track down how D4 is being created to see where 'vsr' is coming from. ~Ethan~ From ian.g.kelly at gmail.com Mon May 9 15:51:01 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 May 2011 13:51:01 -0600 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: <4DC838CD.7030404@stoneleaf.us> <4DC84223.3000502@stoneleaf.us> Message-ID: On Mon, May 9, 2011 at 1:29 PM, James Wright wrote: > It does not appear to show a key: > > D4[] = vsr > Traceback (most recent call last): > ?File "render4.py", line 115, in > ? ?create_report_index(each_item) > ?File "render4.py", line 26, in create_report_index > ? ?[clean_name, _] = each_value.split('_', 1) > ValueError: need more than 1 value to unpack The key appears to be the empty string. You can confirm that by changing the %s to %r in Ethan's diagnostic. That will print out the repr() of the value, which should make it more clear what the value actually is. From alex at moreati.org.uk Mon May 9 16:02:04 2011 From: alex at moreati.org.uk (Alex Willmer) Date: Mon, 9 May 2011 13:02:04 -0700 (PDT) Subject: Inconsistency with split() - Script, OS, or Package Problem? References: Message-ID: <3722b403-ac45-4360-a13b-4814f14de389@gu8g2000vbb.googlegroups.com> (Direct reply to me, reposted on Jame's behalf) Hi Alex, On Mon, May 9, 2011 at 3:21 PM, Alex Willmer wrote: > On May 9, 8:10 pm, James Wright wrote: >> Hello Ian, >> >> It does indeed to seem that way. However the script works just fine >> on other machines, with the same input file. > > How sure of that are you? Post md5sums of the script and the input > file on a working machine and a non-working (4 md5sums total). > > Does the script use an non-stdlib modules? Check the md5sum of those > too. > > Are the platforms/python versions the same? Post the uname and python - > v from each. > > Can you post the script and the file online for us? Do so. > > Regards, Alex > The md5sums match (great idea by the way, I hadn't thought of that). What do you mean by using a non-stdlib module? I am not using any import statements, if that is what you are referring to. As for kernel and Python versions, I have updated both in case this was a bug - they no longer match across the machines I am testing on. The script consistently works with the machines that it always has been working with. The script continues to not work on the new VMWare installs (but does in new VirtualBox installs - odd). I can post the script (attached), but am not so certain that is at fault - given that the script is running on other hosts just fine. Please read the script with a grain of salt, this is my first run at this, and I am well aware that I am not yet following the conventions of Python. I have much to learn. Thanks, James From ethan at stoneleaf.us Mon May 9 16:04:07 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 09 May 2011 13:04:07 -0700 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: <4DC838CD.7030404@stoneleaf.us> <4DC84223.3000502@stoneleaf.us> Message-ID: <4DC848B7.6010804@stoneleaf.us> James Wright wrote: > On Mon, May 9, 2011 at 3:36 PM, Ethan Furman wrote: >> Change your print line to: >> >> print("D4[%s] = %s" % (report, each_value)) >> >> After that, you'll have to track down how D4 is being created to see where >> 'vsr' is coming from. > > It does not appear to show a key: > > D4[] = vsr Huh -- probably the empty string ('') -- to verify that (and know for sure -- always good when debugging! ;) change the both %s to %r and run again; then you'll have to track down where D4 is being created to see why it's getting that weird key. ~Ethan~ From ian.g.kelly at gmail.com Mon May 9 16:07:40 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 May 2011 14:07:40 -0600 Subject: Custom string joining In-Reply-To: References: Message-ID: On Mon, May 9, 2011 at 1:26 PM, Martineau wrote: > Instead of join() here's a function that does something similar to > what the string join() method does. The first argument can be a list > of any type of objects and the second separator argument can likewise > be any type. The result is list of the various objects. (The example > usage just uses a list of string objects ?and separator to illustrate > what it does.) > > def tween(seq, sep): > ? ?return reduce(lambda r,v: r+[sep,v], seq[1:], seq[:1]) > > lst = ['a','b','c','d','e'] > > print tween(lst, '|') > print ''.join(tween(lst, '|')) > > Output: > > ['a', '|', 'b', '|', 'c', '|', 'd', '|', 'e'] > a|b|c|d|e > > > It could be made a little more memory efficient by applying the > itertools module's islice() generator to the first 'seq' argument > passed to reduce(): > > def tween(seq, sep): > ? ?return reduce(lambda r,v: r+[sep,v], itertools.islice(seq,1,None), > seq[:1]) This version accepts any iterable, not just a list: def tween(seq, sep): it = iter(seq) try: first = it.next() except StopIteration: return [] return reduce(lambda r, v: r + [sep, v], it, [first]) A further efficiency improvement would be to do the list concatenation in place to avoid generating O(n) intermediate copies: def tween(seq, sep): it = iter(seq) try: first = it.next() except StopIteration: return [] def add_sep(r, v): r += [sep, v] return r return reduce(add_sep, it, [first]) From jamfwright at gmail.com Mon May 9 16:08:20 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 16:08:20 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: <4DC848B7.6010804@stoneleaf.us> References: <4DC838CD.7030404@stoneleaf.us> <4DC84223.3000502@stoneleaf.us> <4DC848B7.6010804@stoneleaf.us> Message-ID: Hello Ethan, On Mon, May 9, 2011 at 4:04 PM, Ethan Furman wrote: > James Wright wrote: >> >> On Mon, May 9, 2011 at 3:36 PM, Ethan Furman wrote: >>> >>> Change your print line to: >>> >>> ? print("D4[%s] = %s" % (report, each_value)) >>> >>> After that, you'll have to track down how D4 is being created to see >>> where >>> 'vsr' is coming from. >> >> It does not appear to show a key: >> >> D4[] = vsr > > Huh -- probably the empty string ('') -- to verify that (and know for sure > -- always good when debugging! ;) ?change the both %s to %r and run again; > ?then you'll have to track down where D4 is being created to see why it's > getting that weird key. > > ~Ethan~ > A quick note: Renaming the file allowed it to run successfully one time. Then it failed per usual. Renaming it again did not help, so that is not a repeatable test. Changing %s to %r: D4[''] = vsr Traceback (most recent call last): File "render5.py", line 115, in create_report_index(each_item) File "render5.py", line 26, in create_report_index [clean_name, _] = each_value.split('_', 1) ValueError: need more than 1 value to unpack Thanks, James From jamfwright at gmail.com Mon May 9 16:08:45 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 16:08:45 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: <3722b403-ac45-4360-a13b-4814f14de389@gu8g2000vbb.googlegroups.com> References: <3722b403-ac45-4360-a13b-4814f14de389@gu8g2000vbb.googlegroups.com> Message-ID: Sorry Alex, and thank you. On Mon, May 9, 2011 at 4:02 PM, Alex Willmer wrote: > (Direct reply to me, reposted on Jame's behalf) > > > > Hi Alex, > > On Mon, May 9, 2011 at 3:21 PM, Alex Willmer > wrote: >> On May 9, 8:10 pm, James Wright wrote: >>> Hello Ian, >>> >>> It does indeed to seem that way. ?However the script works just fine >>> on other machines, with the same input file. >> >> How sure of that are you? Post md5sums of the script and the input >> file on a working machine and a non-working (4 md5sums total). >> >> Does the script use an non-stdlib modules? Check the md5sum of those >> too. >> >> Are the platforms/python versions the same? Post the uname and python - >> v from each. >> >> Can you post the script and the file online for us? Do so. >> >> Regards, Alex >> > > The md5sums match (great idea by the way, I hadn't thought of that). > > What do you mean by using a non-stdlib module? ?I am not using any > import statements, if that is what you are referring to. > > As for kernel and Python versions, I have updated both in case this > was a bug - they no longer match across the machines I am testing on. > The script consistently works with the machines that it always has > been working with. ?The script continues to not work on the new VMWare > installs (but does in new VirtualBox installs - odd). > > I can post the script (attached), but am not so certain that is at > fault - given that the script is running on other hosts just fine. > > Please read the script with a grain of salt, this is my first run at > this, and I am well aware that I am not yet following the conventions > of Python. ?I have much to learn. > > > > Thanks, > James > -- > http://mail.python.org/mailman/listinfo/python-list > From karim.liateni at free.fr Mon May 9 16:14:38 2011 From: karim.liateni at free.fr (Karim) Date: Mon, 09 May 2011 22:14:38 +0200 Subject: Custom string joining In-Reply-To: References: <254518825.20110507153133@bitdefender.com> Message-ID: <4DC84B2E.9090209@free.fr> On 05/07/11 16:25, Chris Rebert wrote: > On Sat, May 7, 2011 at 5:31 AM, Claudiu Popa wrote: >> Hello Python-list, >> >> I have an object which defines some methods. I want to join a list or >> an iterable of those objects like this: >> >> new_string = "|".join(iterable_of_custom_objects) >> >> What is the __magic__ function that needs to be implemented for >> this case to work? I though that __str__ is sufficient but it doesn't seems to >> work. Thanks in advance. > You need to do the string conversion yourself; .join() doesn't do it > for you, due to strong typing. It only accepts iterables of strings: > new_string = "|".join(str(x) for x in iterable_of_custom_objects) You just have to implement __str__() python special method for your "custom_objects". Regards Karim > Cheers, > Chris > -- > http://rebertia.com From tjreedy at udel.edu Mon May 9 16:23:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 16:23:21 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/9/2011 10:29 AM, Steven D'Aprano wrote: > > If people then ask, how does the interpreter know the names?, I can add > more detail: names are actually strings in a namespace, which is usually > nothing more than a dict. Oh, and inside functions, it's a bit more > complicated still. And so on. Which is why I think it best to stick with 'A namespace is a many-to-one mapping (in other words, a function) of names to objects'. Any programmer should understand the abstractions 'mapping' and 'function'. Asking how the interpreter finds the object associated with a name amounts to asking how to do tabular lookup. Well, we basically know, though the details depends on the implementation of the table (mapping). An interpreter can *implement* namespaces various ways. One is to objectify names and namespaces as strings and dicts. If the set of names in a namespace is fixed, another way is to objectify names and namespaces as ints and arrays. Python prohibits 'from x import *' within functions precisely to keep the set of local namespace names fixed. Therefore, CPython can and does always use C ints and array for function local namespaces. -- Terry Jan Reedy From cpopa at bitdefender.com Mon May 9 16:25:27 2011 From: cpopa at bitdefender.com (Claudiu Popa) Date: Mon, 9 May 2011 23:25:27 +0300 Subject: Custom string joining In-Reply-To: <4DC84B2E.9090209@free.fr> References: <254518825.20110507153133@bitdefender.com> <4DC84B2E.9090209@free.fr> Message-ID: <354289288.20110509232527@bitdefender.com> Hello Karim, > You just have to implement __str__() python special method for your > "custom_objects". > Regards > Karim >> Cheers, >> Chris >> -- >> http://rebertia.com I already told in the first post that I've implemented __str__ function, but it doesn't seems to be automatically called. For instance, the following example won't work: >>> class a: def __init__(self, i): self.i = i def __str__(self): return "magic_function_{}".format(self.i) >>> t = a(0) >>> str(t) 'magic_function_0' >>> "".join([t]) Traceback (most recent call last): File "", line 1, in "".join([t]) TypeError: sequence item 0: expected str instance, a found -- Best regards, Claudiu From ethan at stoneleaf.us Mon May 9 16:44:43 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 09 May 2011 13:44:43 -0700 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: <4DC838CD.7030404@stoneleaf.us> <4DC84223.3000502@stoneleaf.us> <4DC848B7.6010804@stoneleaf.us> Message-ID: <4DC8523B.7010705@stoneleaf.us> James Wright wrote: > On Mon, May 9, 2011 at 4:04 PM, Ethan Furman wrote: >> James Wright wrote: >>> On Mon, May 9, 2011 at 3:36 PM, Ethan Furman wrote: >>>> >>>> Change your print line to: >>>> >>>> print("D4[%s] = %s" % (report, each_value)) >>>> >>>> After that, you'll have to track down how D4 is being created to see >>>> where 'vsr' is coming from. >>> >>> It does not appear to show a key: >>> >>> D4[] = vsr >> >> Huh -- probably the empty string ('') -- to verify that (and know for sure >> -- always good when debugging! ;) change the both %s to %r and run again; >> then you'll have to track down where D4 is being created to see why it's >> getting that weird key. > > A quick note: Renaming the file allowed it to run successfully one > time. Then it failed per usual. Renaming it again did not help, so > that is not a repeatable test. > > Changing %s to %r: > > D4[''] = vsr When you find the problem let us know -- might save somebody else some grief. :) ~Ethan~ From tjreedy at udel.edu Mon May 9 16:46:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 16:46:02 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: Message-ID: On 5/9/2011 2:10 PM, James Wright wrote: > Hello, > > I have been using a script on several boxes that have been around for > a while, and everything works just fine. I am finding though, that on > some new OS installs the script fails with: > > Traceback (most recent call last): > File "render4.py", line 114, in > create_report_index(each_item) > File "render4.py", line 25, in create_report_index > [clean_name, _] = each_value.split('_', 1) > ValueError: need more than 1 value to unpack What this means is that at some point you tried to split a string that does not have an underscore to print on. >>> [s,_] = 'no underscore'.split('_',1) Traceback (most recent call last): File "", line 1, in [s,_] = 'no underscore'.split('_',1) ValueError: need more than 1 value to unpack > The OS's are various OpenSuse installs from 10.3 to 11.4. It works on > all the existing ones, which leads me to believe that I have a package > or configuration inconsistency. It should be noted though that I am > quite new to python programming and very well could have coded in a > non-portable manner and was just lucky to get it working in the first > place :) Your code is fine. The question is,"How could, or why, would new installs result in invalid inputs?" > Here is the code snippet that generates the failure ( when you look > at this remember that I am a novice :-) ): > > for each_item in D4: #D4 is a dictionary > create_report_index(each_item) I might write 'for key in D4:' which makes it obvious that D4 is a dict and that you are iterating through its keys. Or 'for report_name...' > def create_report_index(report): #Here we are creating a simple > index.html file from data in a text file > newfile = open(report + '.html', 'w') #Create the index file using > report name > for each_value in D4[report]: For debugging, add if '_' not in each_value: print(report, D4[report], each_value > [clean_name, _] = each_value.split('_', 1) > newfile.write('' + clean_name +'
\n') Once you find the offending input, then investigate its source in the code that creates D4. Your other questions are premature. If a no_underscore each_value is wrong, fix the source. If you decide that such are actually ok, then fix the code above: if '_' in each_value: clean_name = each_value.split('_', 1) else: clean_name = each_value -- Terry Jan Reedy From bahamutzero8825 at gmail.com Mon May 9 16:52:52 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 09 May 2011 15:52:52 -0500 Subject: Finding the bitness of an arbitrary executable with Python Message-ID: <4DC85424.2020609@gmail.com> I need to find whether a given file is 32-bit or 64-bit (and raise an exception if the file doesn't exist or isn't an executable file). I thought platform.architecture() would do this, but it returns ('64bit', '') no matter what value I assign to the executable parameter (looks like it uses the given executable to find info on the underlying system rather than info on the specific file, reverting to sys.executable if there are any errors). A quick look on Google doesn't give me anything useful. Something cross-platform would be nice, but it really only needs to work on Windows (on win32 binaries). From hg at schaathun.net Mon May 9 16:53:33 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 9 May 2011 21:53:33 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <6qsk98-em1.ln1@svn.schaathun.net> Message-ID: On Mon, 9 May 2011 21:18:29 +1000, Chris Angelico wrote: : Analogies are like diagrams. Not all of them are perfect or useful. : : The boxes are different sizes. If you really want them to look : different, do one as squares and one as circles, but don't try that in : plain text. Analogies, even imperfect ones, are good when we are clear about the fact that they are analogies. Using C pointers to illustrate how to use bound names in python may be useful, but only if we are clear about the fact that it is an analogy and do not pretend that it explains it in full. -- :-- Hans Georg From chardster at gmail.com Mon May 9 17:02:17 2011 From: chardster at gmail.com (Richard Thomas) Date: Mon, 9 May 2011 14:02:17 -0700 (PDT) Subject: Finding the bitness of an arbitrary executable with Python References: Message-ID: On May 9, 9:52?pm, Andrew Berg wrote: > I need to find whether a given file is 32-bit or 64-bit (and raise an > exception if the file doesn't exist or isn't an executable file). I > thought platform.architecture() would do this, but it returns ('64bit', > '') no matter what value I assign to the executable parameter (looks > like it uses the given executable to find info on the underlying system > rather than info on the specific file, reverting to sys.executable if > there are any errors). A quick look on Google doesn't give me anything > useful. Something cross-platform would be nice, but it really only needs > to work on Windows (on win32 binaries). I don't know of anything that does that. If you wanted to do it yourself the correct place to start is by reading up on the Protable Executable Format: http://en.wikipedia.org/wiki/PE_format. That page has references to the MSDN article which is probably most useful. Other platforms have other executable formats of course but there's no reason it couldn't exist... From irmen.NOSPAM at xs4all.nl Mon May 9 17:10:25 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 09 May 2011 23:10:25 +0200 Subject: Finding the bitness of an arbitrary executable with Python In-Reply-To: References: Message-ID: <4dc85842$0$81484$e4fe514c@news.xs4all.nl> On 9-5-2011 22:52, Andrew Berg wrote: > I need to find whether a given file is 32-bit or 64-bit (and raise an > exception if the file doesn't exist or isn't an executable file). I > thought platform.architecture() would do this, but it returns ('64bit', > '') no matter what value I assign to the executable parameter (looks > like it uses the given executable to find info on the underlying system > rather than info on the specific file, reverting to sys.executable if > there are any errors). A quick look on Google doesn't give me anything > useful. Something cross-platform would be nice, but it really only needs > to work on Windows (on win32 binaries). A few options are mentioned here: http://stackoverflow.com/questions/1345632/determine-if-an-executable-or-library-is-32-or-64-bits-on-windows -irmen From python at rcn.com Mon May 9 17:10:54 2011 From: python at rcn.com (Raymond Hettinger) Date: Mon, 9 May 2011 14:10:54 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: <55c0b493-7d4e-42c2-a411-537c68a058b3@b7g2000prg.googlegroups.com> On May 9, 2:31?am, Trent Nelson wrote: > > What are your favorites? > > I think I've posted this before, but I love my 3-lines-if-you-ignore-the-scaffolding language translator. ?Not because it's clever code -- quite the opposite, the code is dead simple -- but because it encompasses one of the things I love about Python the most: it gets shit done. > > ? ? In [1]: from translate import * > > ? ? In [2]: translate('French', 'The quick brown fox jumped over the lazy dog.') > ? ? Le renard brun rapide a saut? par-dessus le chien paresseux. > > ? ? In [3]: translate('German', 'The quick brown fox jumped over the lazy dog.') > ? ? Der schnelle braune Fuchs sprang ?ber den faulen Hund. > > ? ? In [4]: translate('Spanish', 'The quick brown fox jumped over the lazy dog.') > ? ? El zorro marr?n r?pido salt? sobre el perro perezoso. > > translate.py: > > ? ? import sys > ? ? from urllib import urlopen, urlencode > ? ? from BeautifulSoup import BeautifulSoup > > ? ? url = 'http://babelfish.altavista.com/tr' > ? ? languages = { > ? ? ? ? 'French' ? ?: 'en_fr', > ? ? ? ? 'German' ? ?: 'en_de', > ? ? ? ? 'Italian' ? : 'en_it', > ? ? ? ? 'Spanish' ? : 'en_es', > ? ? ? ? 'Russian' ? : 'en_ru', > ? ? ? ? 'Portuguese': 'en_pt', > ? ? ? ? 'Dutch' ? ? : 'en_nl', > ? ? ? ? 'Japanese' ?: 'en_ja', > ? ? } > > ? ? def translate(lang, text): > ? ? ? ? kwds = { 'trtext' : text, 'lp' : languages[lang]} > ? ? ? ? soup = BeautifulSoup(urlopen(url, urlencode(kwds))) > ? ? ? ? print soup.find('div', style='padding:10px;').string > > ? ? if __name__ == '__main__': > ? ? ? ? translate(sys.argv[1], sys.argv[2]) That completely rocks! Thanks for the recipe. Raymond ---------- follow my recipes and tips on twitter: @raymondh From robert.kern at gmail.com Mon May 9 17:22:47 2011 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 09 May 2011 16:22:47 -0500 Subject: Finding the bitness of an arbitrary executable with Python In-Reply-To: <4DC85424.2020609@gmail.com> References: <4DC85424.2020609@gmail.com> Message-ID: On 5/9/11 3:52 PM, Andrew Berg wrote: > I need to find whether a given file is 32-bit or 64-bit (and raise an > exception if the file doesn't exist or isn't an executable file). I > thought platform.architecture() would do this, but it returns ('64bit', > '') no matter what value I assign to the executable parameter (looks > like it uses the given executable to find info on the underlying system > rather than info on the specific file, reverting to sys.executable if > there are any errors). Actually, that information is built into the Python interpreter when it gets built. It is not actually examining the file referenced by sys.executable. -- 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 harrismh777 at charter.net Mon May 9 17:28:43 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 09 May 2011 16:28:43 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <92os6dF5jbU1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > > +-------------+ > +---+ | | > a | --+---------------->| | > +---+ | | > +-------------+ > ^ > +---+ | > b | --+-----------------------| > +---+ > > In this model, a "reference" is an arrow. Manipulating references > consists of rubbing out the arrows and redrawing them differently. Greg, this is an excellent model, thank you for taking the time to put it together for the list... very helpful. Both Summerfield and Lutz use the same model (and almost the identical graphic symbolism) to explain dynamic typing in Python. Summerfield's Programming in Python 3 2nd ed. has a good explanation similar, see pages 17 and 32 (there are others). Lutz has an entire chapter devoted to the topic in Learning Python 4th ed., see chapter six. He calls it the Dynamic Typing Interlude. The model is in-the-field and very workable; and yet, it does have limitations, as most models do. For visual thinkers this model probably comes closest to being most helpful, esp in the beginning. kind regards, m harris From tjreedy at udel.edu Mon May 9 17:30:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 17:30:22 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/8/2011 7:36 PM, Dan Stromberg wrote: > > On Sun, May 8, 2011 at 3:41 PM, Terry Reedy > wrote: > Because inductive algorithms commonly branch on 'input is something' > (not done, change args toward 'nothing'and recurse or iterate) > versus 'input is nothing (done, return base expression). > > > Just what is an inductive algorithm? The parenthesized comments were meant to define common patterns such as: def f(x): if x: return g(f(reduce_arg(x)) else: return base(x) def f(x) ret = start(x) while x: ret = reduce_arg(x) return x More generally, an inductive algorithm computes by looping (with recursion or iteration). That is my definition. That includes most of the 'interesting' algorithms. You might ask, what is not an inductive algorithm? One that does no looping and just returns non-recursive expressions, perhaps in multiple branches. The functions in the expression are taken as primitives and their internal use of induction is ignored. Of course, a computer is nothing but an induction machine: while not halted: get next instruction get args compute result Michal Torrie's response is right. Inductive algorithms follow the pattern of inductive proofs. -- Terry Jan Reedy From ggrp2.20.martineau at dfgh.net Mon May 9 17:38:24 2011 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Mon, 9 May 2011 14:38:24 -0700 (PDT) Subject: Custom string joining References: <254518825.20110507153133@bitdefender.com> <4DC84B2E.9090209@free.fr> Message-ID: On May 9, 1:25?pm, Claudiu Popa wrote: > Hello Karim, > > > You just have to implement __str__() python special method for your > > "custom_objects". > > Regards > > Karim > >> Cheers, > >> Chris > >> -- > >>http://rebertia.com > > I ?already told in the first post that I've implemented __str__ function, but it doesn't > seems to be automatically called. > For instance, the following example won't work: > > >>> class a: > > ? ? ? ? def __init__(self, i): > ? ? ? ? ? ? ? ? self.i = i > ? ? ? ? def __str__(self): > ? ? ? ? ? ? ? ? return "magic_function_{}".format(self.i)>>> t = a(0) > >>> str(t) > 'magic_function_0' > >>> "".join([t]) > > Traceback (most recent call last): > ? File "", line 1, in > ? ? "".join([t]) > TypeError: sequence item 0: expected str instance, a found > > -- > Best regards, > ?Claudiu The built-in str join() method just doesn't do the conversion to string automatically -- instead it assume it has been given a sequence of string. You can achieve the effect you want by modifying the optimized version of my earlier post that @Ian Kelly submitted. def join(seq, sep): it = iter(seq) sep = str(sep) try: first = it.next() except StopIteration: return [] def add_sep(r, v): r += [sep, str(v)] return r return ''.join(reduce(add_sep, it, [str(first)])) class A: def __init__(self, i): self.i = i def __str__(self): return "magic_function_{}".format(self.i) lst = [A(0),A(1),A('b'),A(3)] print repr( join(lst, '|') ) Output: 'magic_function_0|magic_function_1|magic_function_b|magic_function_3' From bahamutzero8825 at gmail.com Mon May 9 17:44:41 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 09 May 2011 16:44:41 -0500 Subject: Finding the bitness of an arbitrary executable with Python In-Reply-To: <4dc85842$0$81484$e4fe514c@news.xs4all.nl> References: <4dc85842$0$81484$e4fe514c@news.xs4all.nl> Message-ID: <4DC86049.3070509@gmail.com> On 2011.05.09 04:10 PM, Irmen de Jong wrote: > http://stackoverflow.com/questions/1345632/determine-if-an-executable-or-library-is-32-or-64-bits-on-windows The code using struct doesn't look terribly complicated, so that could work. I might need to inspect other executable types, but I don't see it being any time soon. Thank you. From harrismh777 at charter.net Mon May 9 17:58:14 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 09 May 2011 16:58:14 -0500 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian Kelly wrote: > "bool(list)" describes whether the list contains something. "Not" > being a logical operator, it stands to reason that "not list" should > mean the same thing as "not bool(list)". Ian, James, Agreed, and thank you. This *is* the explanation I was trying to prompt D'Aprano for, rather than getting his 'not cat' analogy. James, the argument is not for argument sake. The argument is to better facilitate understanding for others who are also trying to make sense of new ideas, some of whom are lurking. :) This argument actually goes back to a previous discussion D'Aprano and I (and others) were having pertaining to whether software is mathematics. It is easy to see how that negating a binary value ( on or off ) works with 'not'... because there are only two possible states. not on, means off.... not off, means on. Same with '1' and '0' where we have only two states, or True and False where we have only two states... &etc. But when we have a list, what two states are we really discussing? Aren't we really talking about set theory? A list is an ordered collection of 'stuff' comprising a set. Negating the set 'not set' is saying 'not bool(set)' / The two states are either 1) the elements of the set, or 2) not the elements of the set--- the empty set, or that 'stuff' outside the set. The answer to the 'not list' question has to do with the conceived semantics of Python ordered collections, which are based more in mathematics proper (set theory) than in logic--- the 'not' operator. It is better to explain to students where the syntax is based (as Ian did) than to state uniformly, "This is just the way Python does it!". As a side point, the answer, "This is the way Python does it!"... would be o.k. if-and-only-if Python were a standardized language, which it isn't. Python's greatest strength is also its greatest weakness... that it is constantly evolving through the PEP process. James, one of the reasons we argue about language features is for that very purpose invited by PEP (and other feedback mechanisms, including this list). The community decides over time how Python does things (along with the final stamp, I suppose, of Guido the BDFL). So, we must needs be arguing, but its not for pedantic squabbling sake.... :-) kind regards, m harris From tjreedy at udel.edu Mon May 9 19:16:24 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 19:16:24 -0400 Subject: Custom string joining In-Reply-To: <354289288.20110509232527@bitdefender.com> References: <254518825.20110507153133@bitdefender.com> <4DC84B2E.9090209@free.fr> <354289288.20110509232527@bitdefender.com> Message-ID: On 5/9/2011 4:25 PM, Claudiu Popa wrote: > I already told in the first post that I've implemented __str__ function, > but it doesn't seems to be automatically called. No, Python does not auto-coerce to strings (only between numbers). You have to be explicit by calling str. Karim's statement "You just have to implement __str__() python special method for your "custom_objects". " means that str will then work. > For instance, the following example won't work: > >>>> class a: > def __init__(self, i): > self.i = i > def __str__(self): > return "magic_function_{}".format(self.i) >>>> t = a(0) >>>> str(t) > 'magic_function_0' >>>> "".join([t]) print('\n'.join(str(ob) for ob in [a(0), a(1), a(None)])) magic_function_0 magic_function_1 magic_function_None -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Mon May 9 19:34:59 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 May 2011 23:34:59 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 May 2011 16:58:14 -0500, harrismh777 wrote: > Ian Kelly wrote: >> "bool(list)" describes whether the list contains something. "Not" >> being a logical operator, it stands to reason that "not list" should >> mean the same thing as "not bool(list)". > > Ian, James, > > Agreed, and thank you. This *is* the explanation I was trying to > prompt D'Aprano for, rather than getting his 'not cat' analogy. Your dislike of analogies is leading you to see them where they aren't. The "cat on the mat" sentence I gave is a concrete example of the use of negation in English, not an analogy. It is virtually the opposite of an analogy. In that same post that annoyed you with the cat on the mat example, I wrote: Python uses a boolean algebra where there are many ways of spelling the true and false values. The "not" operator returns the canonical bool values: not returns False not returns True Take note of the distinction between lower-case true/false, which are adjectives, and True/False, which are objects of class bool. and later on, I contrasted: empty list versus non-empty list Ergo, "not (empty list)" returns True, and "not (non-empty list)" returns False, because the empty list is considered false and any non-empty list is considered true. I'm sorry that I failed to make that more explicit. If I were talking to a programming n00b, I would have been more careful, but you've made numerous references to your long, long programming experience and I thought you would be able to draw the obvious connection without me insulting you by stating the obvious. -- Steven From ben+python at benfinney.id.au Mon May 9 19:54:48 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 10 May 2011 09:54:48 +1000 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r587l99z.fsf@benfinney.id.au> Steven D'Aprano writes: > I'm sorry that I failed to make that more explicit. If I were talking > to a programming n00b, I would have been more careful, but you've made > numerous references to your long, long programming experience and I > thought you would be able to draw the obvious connection without me > insulting you by stating the obvious. +1 QOTW -- \ ?Never use a long word when there's a commensurate diminutive | `\ available.? ?Stan Kelly-Bootle | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Mon May 9 20:00:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2011 00:00:34 GMT Subject: Inconsistency with split() - Script, OS, or Package Problem? References: <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc88022$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 May 2011 15:09:32 -0400, James Wright wrote: > Thank you Steven, > > I will take your advice :) In this particular case though, I do not > think a lack of underscore is the issue, at least as far as I can > understand the issue. Please see my reply to Ethan. In your reply to Ethan, you inserted a print statement in the code and got this output: # python render4.py current each_value is: vsr Traceback (most recent call last): File "render4.py", line 115, in create_report_index(each_item) File "render4.py", line 26, in create_report_index [clean_name, _] = each_value.split('_', 1) ValueError: need more than 1 value to unpack The current value of each_value is the three letter string "vsr". There are no underscores in "vsr". Clearly the lack of underscore is the issue. Now that this has been solved, it has revealed a deeper problem, namely, how you get an empty key and "vsr" into your data on some machines but not others. If your script is behaving differently on different machines with the same data, it is *far* more likely that there is something non- deterministic in your code than that it is a bug in either the OS, Python, or the virtualization environment. Without seeing either your code or data, it is impossible to know what. No offense, but are you sure it's not a PEBCAK error? Are you absolutely sure you're running the same script the same way from the same data on each virtual machine? The fact that your script works correctly *once* when you rename it doesn't strike me with confidence. Renaming the script shouldn't change its behaviour. I suppose it is just barely plausible that one of the VMs is reading its data from faulty sectors on a disk, and hence gets inconsistent results, but that is stretching the bounds of possibility almost to breaking. You posted the data and script to Alex off list. Perhaps you could post it again on-list? As they say, many eyes make bugs shallow. -- Steven From harrismh777 at charter.net Mon May 9 20:10:18 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 09 May 2011 19:10:18 -0500 Subject: checking if a list is empty In-Reply-To: <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Python uses a boolean algebra where there are many ways of > spelling the true and false values. The "not" operator returns > the canonical bool values: > Take note of the distinction between lower-case true/false, > which are adjectives, and True/False, which are objects of > class bool. Yes, yes... to your previous comments, and to move the discussion forward a bit... ... the interesting thing about this part of the discussion is the class bool... because it looks like 'list' is being 'promoted' to type class bool in the following: if not list: <=== this is not logical on the surface... ... if the equivalent is: if not bool(list): <=== this is more explicit, and more readable although it still doesn't tell a casual reader how the bool(list) evaluates... is it empty? is it name exception? other? I'm just saying; no need to respond... just that its easier to understand the syntax of 'not list' in the knowledge that what is happening under the hood is that the 'not' operator does require a bool() and that list is being evaluated bool(list) as one of two logical states. Having played around a little bit with this today I am again impressed that bool() can take *any* object as a parm and derive the correct binary state, whatever that happens to be: bool({}) False bool([]) False bool(0) False bool('') False bool(()) False Therefore, if not str tests for the empty string... if not dict tests for the empty dictionary... &etc. ... is at least consistent ... kind regards, m harris From harrismh777 at charter.net Mon May 9 20:19:55 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 09 May 2011 19:19:55 -0500 Subject: checking if a list is empty In-Reply-To: <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > If I were talking to a programming n00b, I would have been more careful, > but you've made numerous references to your long, long programming > experience and I thought you would be able to draw the obvious connection > without me insulting you by stating the obvious. Pedantics is always potentially insulting, which was your intent, me thinks. Whether I choose to be insulted is my own prerogative, and I choose to 'not' be insulted. I would only suggest an argumentation style that is clear, 'not' pedantic, and 'not' potentially insulting when possible. (not necessarily for my sake) uh, not bool(insulting) kind regards, m harris From akabaila at pcug.org.au Mon May 9 20:31:15 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 10 May 2011 10:31:15 +1000 Subject: scipy In-Reply-To: <6bfdb99c-c8db-4c5c-af2b-35ff88bd94d8@32g2000vbe.googlegroups.com> References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> <6bfdb99c-c8db-4c5c-af2b-35ff88bd94d8@32g2000vbe.googlegroups.com> Message-ID: <201105101031.15778.akabaila@pcug.org.au> On Tuesday 10 May 2011 04:13:55 pb wrote: > On May 9, 3:34 pm, Robert Kern wrote: > > On 5/9/11 3:35 AM, pb wrote: > > > On May 9, 12:29 am, Terry Reedy wrote: > > >> On 5/8/2011 6:44 AM, pb wrote: > > >>> Hi, > > >>> I', having trouble with scipy. > > >> > > >> If you do not get an answer here, try the scipy list > > >> where scipy experts hang out. You might also try > > >> searching the archives of that list or the scipy bug > > >> tracker. > > >> > > >> -- > > >> Terry Jan Reedy > > > > > > Hi, > > > the scipy mailing list? > > > > http://www.scipy.org/Mailing_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 > > Thanks, > I have tried to register for the mailing lists there, but > cannot loggin and have received no "registration > comfirmation email" from them. I'd email the list > maintainer/admin, but cannot find an email address for them. > Peter Some lists require a "real email address", I think it is because it is so easy to create web mail addresses that it makes it too easy for the spammers to flood a mailing list with spam. Just a thought - I do not know what scipy list requirements are. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From onexpadREMOVE at EVOMERyahoodotyouknow.com Mon May 9 20:40:02 2011 From: onexpadREMOVE at EVOMERyahoodotyouknow.com (Kyle T. Jones) Date: Mon, 09 May 2011 19:40:02 -0500 Subject: Overuse of try/except/else? Message-ID: It has been hard for me to determine what would constitute overuse. Cheers. From akabaila at pcug.org.au Mon May 9 20:44:28 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 10 May 2011 10:44:28 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201105101044.28593.akabaila@pcug.org.au> On Tuesday 10 May 2011 05:24:16 Terry Reedy wrote: > On 5/9/2011 4:25 AM, Antonio CHESSA wrote: > > apple = > > [["a","b","c"],[1,2,3,4,5,6],["antony","max","sandra","seb > > astian"]] > > for j in range (len(apple[i])): > > print apple[i][j] > > While this illustrate double indexing, it can be simplified > to > > for top in apple: > print(top) > for inner in top: > print(inner) > > and give the same output. Indexing is only needed for random > access and for changing a list in place. The method of double indexing in the manner apple[i][j] or a[i][j] for the (i, j) -th element of multi-dimensional array is well known and widely used. But how to enable the "standard" matrix notation a[i, j] in Python 3.2 in the manner of numpy (and other matrix packages)? Is it subclassing of "special methods" __getitem__() and/or __setitem__() and if so how? OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Mon May 9 21:09:01 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 10 May 2011 11:09:01 +1000 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: On Tue, May 10, 2011 at 10:40 AM, Kyle T. Jones wrote: > It has been hard for me to determine what would constitute overuse. A rule of thumb I always follow and practice is: "Let the error lie where it occurred." or "Don't hide errors.". It's good practice to follow IHMO as it makes it easier to find the source of defects in your function(s). If you constantly do things like try/except/log then it makes finding the source harder and may make it harder to identify what caused it. I favor Test Driven Development (TDD) over Contracts in Python (as Python is a dynamic programming language) but errors should be handled and caught by the caller - not the callee. My 2c, others may have other points of view... cheers James -- -- James Mills -- -- "Problems are solved by method" From tjreedy at udel.edu Mon May 9 21:25:59 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 21:25:59 -0400 Subject: How to access elemenst in a list of lists? In-Reply-To: <201105101044.28593.akabaila@pcug.org.au> References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> <201105101044.28593.akabaila@pcug.org.au> Message-ID: On 5/9/2011 8:44 PM, Algis Kabaila wrote: > The method of double indexing in the manner > a[i][j] > for the (i, j) -th element of multi-dimensional array is well known and > widely used. But how to enable the "standard" matrix notation > a[i, j] > in Python 3.2 in the manner of numpy (and other matrix packages)? Is it > subclassing of "special methods" > > __getitem__() # to get > __setitem__() # to set Yes. class listwrap: def __init__(self, lis): self._list = lis def __getitem__(self, dex): i,j = dex return self._list[i][j] # __setitem__: exercise for reader l = listwrap([[1,2,3],['a','b','c']]) print(l[0,2],l[1,0]) # 3 a IMO, Hardly worth it for two dimensions. -- Terry Jan Reedy From w.g.sneddon at gmail.com Mon May 9 21:33:31 2011 From: w.g.sneddon at gmail.com (python) Date: Mon, 9 May 2011 18:33:31 -0700 (PDT) Subject: Dictionary from String? References: Message-ID: <75c131bb-ac5f-4292-9ae2-b0e3e631cc2e@cu4g2000vbb.googlegroups.com> On May 8, 12:43?pm, Benjamin Kaplan wrote: > On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom wrote: > > Is it possible to create a dictionary from a string value?? Something along > > these lines (but that works): > > >>>> mystring = "{'name':'greg','hatsize':'7 5/8'}" > >>>> mystring > > "{'name':'greg','hatsize':'7 5/8'}" > >>>> dict(mystring) > > Traceback (most recent call last): > > ? File "", line 1, in > > ValueError: dictionary update sequence element #0 has length 1; 2 is > > required > > > I would like to return an undetermined (at call time) number of fields from > > a postgres database (only 1 record) for a given request.? My thought is that > > I could build a dictionary in the form of a string, return the string and > > then convert the string value to a dictionary.? I can do that now, but I > > have to parse the string and then build the dictionary.? Any thoughts or > > help you could provide would be appreciated. > > > --greg > > building the dictionary as a string seems like a hacky thing to do and > you might want to reevaluate your methods. But if everything in the > dict is a literal, you can do ast.literal_eval. > > > > > > > > > > > -- > >http://mail.python.org/mailman/listinfo/python-list There are lots of possibilites and the "best" solution will very based on your strings' structure. List of tuples convert to dict nicely for example. So if your string can be parse to a list of tuples. a = [ (chr(num),num) for num in range(48,58)] [('0', 48), ('1', 49), ('2', 50), ('3', 51), ('4', 52), ('5', 53), ('6', 54), ('7', 55), ('8', 56)] dict(a) {'1': 49, '0': 48, '3': 51, '2': 50, '5': 53, '4': 52, '7': 55, '6': 54, '9': 57, '8': 56} if your string looks something like your example above. The shlex module might be helpful. From w.g.sneddon at gmail.com Mon May 9 21:41:47 2011 From: w.g.sneddon at gmail.com (python) Date: Mon, 9 May 2011 18:41:47 -0700 (PDT) Subject: Dictionary from String? References: <75c131bb-ac5f-4292-9ae2-b0e3e631cc2e@cu4g2000vbb.googlegroups.com> Message-ID: <916ad167-2559-443f-9527-92f827c4603e@m10g2000yqd.googlegroups.com> On May 9, 9:33?pm, python wrote: > On May 8, 12:43?pm, Benjamin Kaplan wrote: > > > > > > > > > > > On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom wrote: > > > Is it possible to create a dictionary from a string value?? Something along > > > these lines (but that works): > > > >>>> mystring = "{'name':'greg','hatsize':'7 5/8'}" > > >>>> mystring > > > "{'name':'greg','hatsize':'7 5/8'}" > > >>>> dict(mystring) > > > Traceback (most recent call last): > > > ? File "", line 1, in > > > ValueError: dictionary update sequence element #0 has length 1; 2 is > > > required > > > > I would like to return an undetermined (at call time) number of fields from > > > a postgres database (only 1 record) for a given request.? My thought is that > > > I could build a dictionary in the form of a string, return the string and > > > then convert the string value to a dictionary.? I can do that now, but I > > > have to parse the string and then build the dictionary.? Any thoughts or > > > help you could provide would be appreciated. > > > > --greg > > > building the dictionary as a string seems like a hacky thing to do and > > you might want to reevaluate your methods. But if everything in the > > dict is a literal, you can do ast.literal_eval. > > > > -- > > >http://mail.python.org/mailman/listinfo/python-list > > There are lots of possibilites and the "best" solution will very based > on your strings' structure. ?List of tuples convert to dict nicely for > example. ?So if your string can be parse to a list of tuples. > > a = [ (chr(num),num) for num in range(48,58)] > [('0', 48), ('1', 49), ('2', 50), ('3', 51), ('4', 52), ('5', 53), > ('6', 54), ('7', 55), ('8', 56)] > dict(a) > {'1': 49, '0': 48, '3': 51, '2': 50, '5': 53, '4': 52, '7': 55, '6': > 54, '9': 57, '8': 56} > if your string looks something like your example above. The shlex > module might be helpful. After re-reading your post saw you were reading from a database. Have you looked at SQLAlchemy? It might have the functionality you are trying to create. From greg.ewing at canterbury.ac.nz Mon May 9 21:49:04 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 10 May 2011 13:49:04 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92rjsiFfsoU1@mid.individual.net> Steven D'Aprano wrote: > It's just that the term "variable" is so useful and so familiar that it's > easy to use it even for languages that don't have variables in the C/ > Pascal/Fortran/etc sense. Who says it has to have the Pascal/Fortran/etc sense? Why should static languages have a monopoly on the use of the term? That seems like a rather languagist attitude! And BTW, applying it to Python is not inconsistent with its usage in Pascal. In the technical vocabulary of Pascal, a "variable" is anything that can appear on the left hand side of an assignment. The analogous term in C is "lvalue". -- Greg From greg.ewing at canterbury.ac.nz Mon May 9 21:51:46 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 10 May 2011 13:51:46 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92rk1jFfsoU2@mid.individual.net> Steven D'Aprano wrote: > Or Chinese Gooseberries, better known by the name thought up by a > marketing firm, "kiwi fruit". And I'm told that there is a language (one of the Nordic ones, IIRC) where "kiwi" means "stone". So in that country they wonder why they should be getting so excited about something called a "stonefruit". :-) -- Greg From sjmachin at lexicon.net Mon May 9 22:27:26 2011 From: sjmachin at lexicon.net (John Machin) Date: Tue, 10 May 2011 12:27:26 +1000 Subject: codecs.open() doesn't handle platform-specific line terminator Message-ID: <3f197ae5a0fbd1da75e8088aa5ba2f52.squirrel@webmail.lexicon.net> According to the 3.2 docs (http://docs.python.org/py3k/library/codecs.html#codecs.open), """Files are always opened in binary mode, even if no binary mode was specified. This is done to avoid data loss due to encodings using 8-bit values. This means that no automatic conversion of b'\n' is done on reading and writing.""" The first point is that one would NOT expect "conversion of b'\n'" anyway. One expects '\n' -> os.sep.encode(the_encoding) on writing and vice versa on reading. The second point is that there is no such restriction with the built-in open(), which appears to work as expected, doing (e.g. Windows, UTF-16LE) '\n' -> b'\r\x00\n\x00' when writing and vice versa on reading, and not striking out when thrown curve balls like '\u0a0a'. Why is codecs.open() different? What does "encodings using 8-bit values" mean? What data loss? From python at mrabarnett.plus.com Mon May 9 22:47:40 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 May 2011 03:47:40 +0100 Subject: What other languages use the same data model as Python? In-Reply-To: <92rk1jFfsoU2@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rk1jFfsoU2@mid.individual.net> Message-ID: <4DC8A74C.7000705@mrabarnett.plus.com> On 10/05/2011 02:51, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> Or Chinese Gooseberries, better known by the name thought up by a >> marketing firm, "kiwi fruit". > > And I'm told that there is a language (one of the > Nordic ones, IIRC) where "kiwi" means "stone". So in > that country they wonder why they should be getting so > excited about something called a "stonefruit". :-) > I had heard something about the meaning of the word "gift", so I checked in Google Translate. For Swedish "gift" it says: noun 1. POISON 2. VENOM 3. TOXIN 4. VIRUS adjective 1. MARRIED 2. WEDDED From steve+comp.lang.python at pearwood.info Mon May 9 23:13:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2011 03:13:12 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: <4dc8ad47$0$29979$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 May 2011 13:49:04 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> It's just that the term "variable" is so useful and so familiar that >> it's easy to use it even for languages that don't have variables in the >> C/ Pascal/Fortran/etc sense. > > Who says it has to have the Pascal/Fortran/etc sense? Why should static > languages have a monopoly on the use of the term? That seems like a > rather languagist attitude! Established usage. They came first, and outnumber us :/ But I wouldn't quite say they have a monopoly of the term. Where there is no risk of misunderstanding, it's fine to use the term. Mathematicians' "variable" is different still, but there's very little risk of misunderstanding. I'm far less cautious about using "variable" when I'm talking to you, because I know you won't be confused, than I would be when talking to a newbie, who may be. When two people use the same words, but their understanding of them are slightly different, it's often easier to change the terminology than it is to break people's preconceptions and connotations. > And BTW, applying it to Python is not inconsistent with its usage in > Pascal. In the technical vocabulary of Pascal, a "variable" is anything > that can appear on the left hand side of an assignment. The analogous > term in C is "lvalue". Sure, but if you think Python "variables" behave like Pascal "variables", you'll may be surprised by Python and wonder why integer arguments are call by value and list arguments are call by reference... -- Steven From wuwei23 at gmail.com Mon May 9 23:30:53 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 9 May 2011 20:30:53 -0700 (PDT) Subject: input() or raw_input() in Console module. References: Message-ID: On May 9, 10:13?pm, ander2_1... at hotmail.com wrote: > I'm using Console module (doc:http://effbot.org/zone/console-handbook.htm, > like nCurses) on Windows, but I don't know how to call a keyboard > input like input() or raw_input(). > What to do? Maybe read the docs, specifically the section titled "Input": get() => event Get the first event from the input queue. The return value is an instance of the Event class. If the input queue is empty, this method blocks. getchar() => event Get the first character event from the input queue, ignoring any other kind of event. The return value is an instance of the KeyPress class. If the input queue is empty, this method blocks. If you've tried playing with these without success, at least post code showing what you've tried, it makes it easier in providing a suitable response. From gagsl-py2 at yahoo.com.ar Mon May 9 23:55:51 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 May 2011 00:55:51 -0300 Subject: Testing tools classification References: <0a6beebc-35b7-4f81-b64b-55c0dbed1bae@h12g2000pro.googlegroups.com> Message-ID: En Sat, 07 May 2011 02:21:02 -0300, rusi escribi?: > There is this nice page of testing tools taxonomy: > http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy > > But it does not list staf: http://staf.sourceforge.net/index.php. The good thing about wikis is, you can add it yourself. -- Gabriel Genellina From cpopa at bitdefender.com Tue May 10 01:51:55 2011 From: cpopa at bitdefender.com (Claudiu Popa) Date: Tue, 10 May 2011 08:51:55 +0300 Subject: Custom string joining In-Reply-To: References: <254518825.20110507153133@bitdefender.com> <4DC84B2E.9090209@free.fr> <354289288.20110509232527@bitdefender.com> Message-ID: <931720564.20110510085155@bitdefender.com> Hello Terry, Thanks, I understand now. Tuesday, May 10, 2011, 2:16:24 AM, you wrote: > On 5/9/2011 4:25 PM, Claudiu Popa wrote: >> I already told in the first post that I've implemented __str__ function, >> but it doesn't seems to be automatically called. > No, Python does not auto-coerce to strings (only between numbers). > You have to be explicit by calling str. Karim's statement "You just have > to implement __str__() python special method for your "custom_objects". > " means that str will then work. >> For instance, the following example won't work: >> >>>>> class a: >> def __init__(self, i): >> self.i = i >> def __str__(self): >> return "magic_function_{}".format(self.i) >>>>> t = a(0) >>>>> str(t) >> 'magic_function_0' >>>>> "".join([t]) > print('\n'.join(str(ob) for ob in [a(0), a(1), a(None)])) > magic_function_0 > magic_function_1 > magic_function_None -- Best regards, Claudiu From akabaila at pcug.org.au Tue May 10 03:22:42 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 10 May 2011 17:22:42 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> <201105101044.28593.akabaila@pcug.org.au> Message-ID: <201105101722.42524.akabaila@pcug.org.au> On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote: > On 5/9/2011 8:44 PM, Algis Kabaila wrote: > > The method of double indexing in the manner > > a[i][j] > > for the (i, j) -th element of multi-dimensional array is > > well known and widely used. But how to enable the > > "standard" matrix notation a[i, j] > > in Python 3.2 in the manner of numpy (and other matrix > > packages)? Is it subclassing of "special methods" > > > > __getitem__() # to get > > > > __setitem__() # to set > > Yes. > > class listwrap: > def __init__(self, lis): > self._list = lis > def __getitem__(self, dex): > i,j = dex > return self._list[i][j] > # __setitem__: exercise for reader > > l = listwrap([[1,2,3],['a','b','c']]) > print(l[0,2],l[1,0]) > # 3 a > > IMO, Hardly worth it for two dimensions. Terry, Thank you for your response. I have to confess that I do have the cludge of an answer to my own quesion, but it is a cludge; Your method looks much better, though I don't think it is complete - this subclassing of __getitem__ appears to stop simple list access, i.e. if li = [1, 2 ,3], it seems to me that print(li[2]) would raise an exception, no? However, the method that you have indicated is a neat way to solve the problem -- thank you for it! OldAl PS: just to confirm your method and the limitation of it "as is": It is NOT a criticism, just a mere observation, Good method, nice examle, great contribution! >>> 3 a Showing limitation of "as is" in this great method for access of list of lists Traceback (most recent call last): File "/dat/work/linalg/dim2.py", line 15, in print(ll[1]) File "/dat/work/linalg/dim2.py", line 6, in __getitem__ i,j = dex TypeError: 'int' object is not iterable >>> -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From akabaila at pcug.org.au Tue May 10 03:32:38 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 10 May 2011 17:32:38 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: <201105101722.42524.akabaila@pcug.org.au> References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> <201105101722.42524.akabaila@pcug.org.au> Message-ID: <201105101732.38838.akabaila@pcug.org.au> On Tuesday 10 May 2011 17:22:42 Algis Kabaila wrote: > On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote: > > On 5/9/2011 8:44 PM, Algis Kabaila wrote: > > > The method of double indexing in the manner > > > a[i][j] > > > for the (i, j) -th element of multi-dimensional array is > > > well known and widely used. But how to enable the > > > "standard" matrix notation a[i, j] > > > in Python 3.2 in the manner of numpy (and other matrix > > > packages)? Is it subclassing of "special methods" > > > > > > __getitem__() # to get > > > > > > __setitem__() # to set > > > > Yes. > > > > class listwrap: > > def __init__(self, lis): > > self._list = lis > > > > def __getitem__(self, dex): > > i,j = dex > > return self._list[i][j] > > > > # __setitem__: exercise for reader > > > > l = listwrap([[1,2,3],['a','b','c']]) > > print(l[0,2],l[1,0]) > > # 3 a > > > > IMO, Hardly worth it for two dimensions. > > Terry, > > Thank you for your response. I have to confess that I do > have the cludge of an answer to my own question, but it is a > cludge; Your method looks much better, though I don't think > it is complete - this subclassing of __getitem__ appears to > stop simple list access, i.e. if li = [1, 2 ,3], it seems to > me that print(li[2]) > would raise an exception, no? > However, the method that you have indicated is a neat way to > solve the problem -- thank you for it! > > OldAl > > PS: just to confirm your method and the limitation of it "as > is": It is NOT a criticism, just a mere observation, Good > method, nice example, great contribution! > > > 3 a > Showing limitation of "as is" in this > great method for access of list of lists > Traceback (most recent call last): > File "/dat/work/linalg/dim2.py", line 15, in > print(ll[1]) > File "/dat/work/linalg/dim2.py", line 6, in __getitem__ > i,j = dex > TypeError: 'int' object is not iterable Apologies for accidental mail sending before it was completed: The original code and additional data is as follows l = listwrap([[1,2,3],['a','b','c']]) print(l[0,2],l[1,0]) print('''Showing limitation of "as is" in this great method for access of list of lists''') ll = listwrap([1,2,3]) print(ll[1]) Above is the output. Thank you again, Al. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Tue May 10 03:41:38 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 10 May 2011 19:41:38 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92s8hlFqn5U1@mid.individual.net> Steven D'Aprano wrote: > All very good, but that's not what takes place at the level of Python > code. It's all implementation. Actually, you're right. What I've presented is a paper-and-pencil implementation of the Python data model. Together with a set of rules for manipulating the diagram under the direction of Python code, you have a complete implementation of Python that you can execute in your head. And you NEED such an implementation in order to reason correctly about Python programs under all circumstances. I find it very difficult to imagine *any* implementation of Python, computer-based or otherwise, that doesn't have something equivalent to references. Whether you call them that, or pointers, or arrows, or object bindings, or something else, the concept needs to be there in some form. > But surely, if a = 1234 creates a reference from a to the big > box 1234, then b = a should create a reference from b to the box a? > > +-------------+ > +---+ | | > a | --+---------------->| | > +---+ | | > ^ +-------------+ > | > +-|-+ > b | | | > +---+ You can't expect anyone to draw correct conclusions from the diagram alone; you also need to explain the rules for manipulating the diagram under control of Python code. Here, the explanation goes something like this: 1. The right hand side of an assignment denotes a big box. The literal 1234 in a program denotes a big box containing the integer value 1234. 2. The left hand side of an assignment denotes a little box. The effect of an assignment is to make the arrow from the left hand side's little box point to the big box denoted by the right hand side. So the assignment a = 1234 results in +-------------+ +---+ | | a | --+---------------->| 1234 | +---+ | | +-------------+ 3. When a name is used on the right hand side, it denotes whichever big box is pointed to by the arrow from its little box. So given the above diagram, the assignment b = a results in +-------------+ +---+ | | a | --+---------------->| 1234 | +---+ | | +-------------+ ^ +---+ | b | --+--------------------- +---+ Furthermore, from rule 2 alone it's evident that no assignment can ever make an arrow lead from one little box to another little box. Arrows can only lead from a little box to a big box. > That's how it works in C and Pascal (well, at least with the appropriate > type declarations). Um, no, it doesn't, really. There's no way 'b = a' can give you that in C; you would have to write 'b = &a'. And you couldn't do it at all in standard Pascal, because there is no equivalent to the & operator there. > Your model is closer to what the CPython implementation > actually does, I think it's close -- actually, I would say isomorphic -- to what *any conceivable* Python implementation would do in some form. > n = len('hello world') > > What about outside len? Where's the little box > pointing to 'hello world'? > So it seems your model fails to deal with sufficiently anonymous objects. Anonymous objects are fine. You just draw a little box and don't write any label beside it. Or you don't bother drawing a little box at all and just draw a big box until such time as some little box that you care about needs to point to it. If that's a problem, then you have the same problem talking about names bound to objects. An anonymous object obviously doesn't have any name bound to it. So you have to admit that objects can exist, at least temporarily, without being bound to anything, or bound to some anonymous thing. > Both the call to len and the call to func push their results onto the > stack. There's no little box pointing to the result. If you want to model things at that level of detail, then the stack itself is an array of little boxes inside a frame object. And the frame object is pointed to by a little box in its calling frame object, etc. until you get to some global little box, that doesn't have a name in Python, but exists somewhere and keeps the chain of active stack frames alive. But you don't have to draw any of that if you don't want to. > For practical reasons, there must be some sort of > indirection. But that's implementation and not the VM's model. No, it's not just implementation. Indirection is needed for *correct semantics*, not just practicality. > There is a problem with my model of free-floating objects in space: it > relies on objects being able to be in two places at once, Yes, that's the point I'm trying to make. While it might be possible to make such a model work, it would require bizarre contortions that actually obscure what is going on instead of clarifying it. Trying to teach someone about Python using a model like that would be actively harmful, and probably vilolate several human rights conventions. > But if you're a science fiction fan from way back, > then you won't have any problem with the idea that objects can be inside > themselves: > > http://www.youtube.com/watch?v=51JtuEa_OPc Yeah, it's fun to play around with ideas like that precisely because they twist our brains into knots. But it's not a good way to explain Python semantics clearly! > Now, that's a good challenge for your model. Little boxes only point to > big boxes. So how do you model cycles, including lists that contain > themselves? I'll answer your next question first, and come back to that. >> +---+ +---+ >> a | --+----->| | +-------------+ >> +---+ +---+ | | >> | --+----->| | >> +---+ | | >> | | +-------------+ >> +---+ > > But that's wrong! Names (little boxes) can't point to *slots in a list*, The arrow from a is to be understood as pointing to the whole list, not any particular little box within the list. If you want to clarify that, you can embellish the big boxes with some kind of header area and point to that instead. +---+ a | --+----->/---\ +---+ +---+ | | +---+ | --+----->/-------------\ +---+ +-------------+ | | | | +---+ | | | | +-------------+ Now, a list that "contains" itself: -------- | | +---+ V | a | --+----->/---\ | +---+ +---+ | | | | +---+ | | --+----- +---+ | | +---+ > But I wouldn't do it like that. I'd do it like this: > > 0 1 2 3 4 > +--------+--------+--------+--------+--------+ > a | | | | | | > | | | | | | > | | | | | | > +--------+--------+--------+--------+--------+ But then you can't model two list items bound to the same object, unless you invoke the two-places-at-once idea. Even then, you would have trouble unambiguously indicating that boxes draw in two places are mean to actually represent the *same* object as against two different objects with equal values. > Why are the boxes so > small? Just because. Why can't you carefully tease the thread of blutack > apart, into a bifurcated Y shaped thread? Just because. Yes, it's probably just as good to leave it as an arbitrary rule that a little box can only point to one big box at a time. -- Greg From tjreedy at udel.edu Tue May 10 03:44:44 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 May 2011 03:44:44 -0400 Subject: How to access elemenst in a list of lists? In-Reply-To: <201105101722.42524.akabaila@pcug.org.au> References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> <201105101044.28593.akabaila@pcug.org.au> <201105101722.42524.akabaila@pcug.org.au> Message-ID: On 5/10/2011 3:22 AM, Algis Kabaila wrote: > On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote: > > class listwrap: > > def __init__(self, lis): > > self._list = lis > > def __getitem__(self, dex): > > i,j = dex > > return self._list[i][j] > > > # __setitem__: exercise for reader > > l = listwrap([[1,2,3],['a','b','c']]) > > print(l[0,2],l[1,0]) > > # 3 a > Thank you for your response. I have to confess that I do have the cludge > of an answer to my own quesion, but it is a cludge; Your method looks > much better, though I don't think it is complete - this subclassing of > __getitem__ appears to stop simple list access, i.e. if li = [1, 2 ,3], > it seems to me that print(li[2]) would raise an exception, no? Yes, there really should be a guard condition: if isinstance(x tuple) or try: len(x) == 2. A __getattr__ method could be added to forwar other list methods to the wrapped list. One could try subclassing instead of wrapping, but some special methods have a fast path access for builtins that bypasses subclass methods. I think __getitem__ may be one such. Wrapping is safe in that respect. -- Terry Jan Reedy From jeanmichel at sequans.com Tue May 10 05:34:10 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 10 May 2011 11:34:10 +0200 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: <4DC90692.50903@sequans.com> James Mills wrote: > On Tue, May 10, 2011 at 10:40 AM, Kyle T. Jones > wrote: > >> It has been hard for me to determine what would constitute overuse. >> > > A rule of thumb I always follow and practice is: > > "Let the error lie where it occurred." > > or > > "Don't hide errors.". > > It's good practice to follow IHMO as it makes it easier to find > the source of defects in your function(s). If you constantly > do things like try/except/log then it makes finding the source > harder and may make it harder to identify what caused it. > You can reraise the exception without loosing the stack trace. try: ... except SomeException, exc: log(exc) print 'Hello world' raise # "raise exc" would loose the original stack trace JM PS : "code that crashes could use improvement, but incorrect code that doesn?t crash is a horrible nightmare." (I don't know the author) From rosuav at gmail.com Tue May 10 05:35:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 May 2011 19:35:22 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <92s8hlFqn5U1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> <92s8hlFqn5U1@mid.individual.net> Message-ID: On Tue, May 10, 2011 at 12:29 AM, Steven D'Aprano wrote: > If objects can be in two places at once, why can't names? Just because. Because then you'd need some way to identify which object you wanted to refer to - something like name[0] and name[1]. A tuple is one effective way to do this (sort of - actually, the name points at the tuple and the tuple points at each of the objects). On Tue, May 10, 2011 at 12:47 PM, MRAB wrote: > I had heard something about the meaning of the word "gift", so I > checked in Google Translate. For Swedish "gift" it says: > > noun > 1. POISON > 2. VENOM > 3. TOXIN > 4. VIRUS Beware of Swedes bearing gifts! On Tue, May 10, 2011 at 5:41 PM, Gregory Ewing wrote: > Anonymous objects are fine. You just draw a little box and > don't write any label beside it. Or you don't bother drawing > a little box at all and just draw a big box until such time > as some little box that you care about needs to point to it. > > If that's a problem, then you have the same problem talking > about names bound to objects. An anonymous object obviously > doesn't have any name bound to it. So you have to admit that > objects can exist, at least temporarily, without being bound > to anything, or bound to some anonymous thing. There has to be a way to get from some mythical "home" location (which we know in Python as locals()+globals()+current expression - the "current namespace") to your object. That might involve several names, or none at all, but if there's no such path, the object is unreferenced and must be disposed of. IIRC that's not just an implementation detail (the garbage collector), but a language guarantee (that the __del__ method will be called). Names are immaterial to that. Chris Angelico From nobody at nowhere.net.no Tue May 10 06:06:02 2011 From: nobody at nowhere.net.no (TheSaint) Date: Tue, 10 May 2011 18:06:02 +0800 Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> <7508a36a-5d27-49a7-8572-c9bba3d2c61e@h12g2000pro.googlegroups.com> Message-ID: Vinay Sajip wrote: > No, you can pass keyword arguments in any order - that's what makes > them keyword, as opposed to positional, arguments. I getting puzzled :) ==================================code================================== myself at laptop-~> python Python 3.2 (r32:88445, Apr 15 2011, 11:09:05) [GCC 4.5.2 20110127 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import logging, sys >>> logging.basicConfig(level=logging.DEBUG, format='%(message)s') >>> sh = logging.StreamHandler(sys.stdout) >>> sh.terminator = '' >>> logging.getLogger().addHandler(sh) >>> logging.debug('here we are') here we are here we are>>> print(logging.__version__) 0.5.1.2 ==================================code================================== Terminator is removed, but as you stated it's doing double print-out One more point is, if you'd have the time to look back to one of the first posts, that the leading *"DEBUG:root:"* doesn't show :-/ It's reported herein the version of Python and logging module's version. For my thinking I'd go to look into the code and docs as well, to understand what I should do to have my 4 way of logging. I repeat, I'm very new on using logging module, but I should go in that way, it isn't necessary to re-invent the wheel :). Also I'd like to say that's only for my own learning, which I do as hobby. -- goto /dev/null From rosuav at gmail.com Tue May 10 06:33:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 May 2011 20:33:12 +1000 Subject: can't get urllib2 or httplib to work with tor & privoxy In-Reply-To: References: Message-ID: On Tue, May 10, 2011 at 4:20 AM, Bob Fnord wrote: > Both methods give me a 503 error... As a networking geek, my first thought would be to fire up a tiny little "snoop server" and see what, exactly, the two methods are doing. (Ignore the HTTPS options as they're more complicated to snoop on; you're almost certainly going to see exactly the same on the HTTP.) A snoop server is simply an HTTP server that dumps its requests to stdout or a file, utterly raw. You can write one in Python fairly easily, or use another program; if I'm working on Windows, I'll generally use my own RosMud MUD client, but you'll be able to whip up a cross-platform one in half a page of code in any decent high level language. I recommend you work at the sockets level, rather than using an HTTP library, unless you have one that can emit the entire request, exactly as it came from the client. Once you've found the difference(s) between Lynx and your script, you can see what's causing the 503 (Service Unavailable) error; it may be that you need to authenticate with the proxy. Chris Angelico From akabaila at pcug.org.au Tue May 10 07:11:09 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 10 May 2011 21:11:09 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> <201105101722.42524.akabaila@pcug.org.au> Message-ID: <201105102111.09577.akabaila@pcug.org.au> On Tuesday 10 May 2011 17:44:44 Terry Reedy wrote: > On 5/10/2011 3:22 AM, Algis Kabaila wrote: > > On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote: > > > class listwrap: > > > def __init__(self, lis): > > > self._list = lis > > > > > > def __getitem__(self, dex): > > > i,j = dex > > > return self._list[i][j] > > > > > > # __setitem__: exercise for reader > > > > > > l = listwrap([[1,2,3],['a','b','c']]) > > > print(l[0,2],l[1,0]) > > > # 3 a > > > > Thank you for your response. I have to confess that I do > > have the cludge of an answer to my own quesion, but it is > > a cludge; Your method looks much better, though I don't > > think it is complete - this subclassing of __getitem__ > > appears to stop simple list access, i.e. if li = [1, 2 > > ,3], it seems to me that print(li[2]) would raise an > > exception, no? > > Yes, there really should be a guard condition: if > isinstance(x tuple) or try: len(x) == 2. A __getattr__ > method could be added to forwar other list methods to the > wrapped list. One could try subclassing instead of wrapping, > but some special methods have a fast path access for > builtins that bypasses subclass methods. I think __getitem__ > may be one such. Wrapping is safe in that respect. Actually, I am working on an array class that subclasses list. My interest is to have a module that deals with matrices with pure Python 3.2 or higher. The class would need to deal with many different arrays and matrix operations between them. In since Array subclasses list, any modifications of __getitem__ ir __setitem__ would naturally be in the array class and would in fact subclass the list special methods if implemented in the Array class. And, to my chagrin, I do manage to mess it up... Thanks for your bright suggestion, OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Tue May 10 07:36:42 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 10 May 2011 07:36:42 -0400 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: <1305027402.3751.11.camel@linux-yu4c.site> On Mon, 2011-05-09 at 19:40 -0500, Kyle T. Jones wrote: > It has been hard for me to determine what would constitute overuse. The chronic problem is under use; so I wouldn't worry much about it. try/except should occur as often as is required for the application to either deal gracefully with the condition or report *meaningful* error messages to the user/administrator. From hg at schaathun.net Tue May 10 08:10:11 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 10 May 2011 13:10:11 +0100 Subject: Overuse of try/except/else? References: Message-ID: <3imn98-6r3.ln1@svn.schaathun.net> On Tue, 10 May 2011 07:36:42 -0400, Adam Tauno Williams wrote: : On Mon, 2011-05-09 at 19:40 -0500, Kyle T. Jones wrote: : > It has been hard for me to determine what would constitute overuse. : : The chronic problem is under use; so I wouldn't worry much about it. : : try/except should occur as often as is required for the application to : either deal gracefully with the condition or report *meaningful* error : messages to the user/administrator. So overuse is really when you cannot do anything meaningful about the exception. The two interesting questions are really 1. where and when to catch a given exception 2. at what stage of the development cycle catching a particular (class of) exception should become a priority There is a potential overuse of exceptions, where they are used for quite ordinary and frequent (i.e. not exceptional) conditions, and the information could be passed through the return value instead. Exceptions is a very flexible, but also rather expensive means of communications. You can, actually, write any program using raise instead of return. That would be overuse. -- :-- Hans Georg From rustompmody at gmail.com Tue May 10 08:32:31 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 10 May 2011 05:32:31 -0700 (PDT) Subject: Testing tools classification References: <0a6beebc-35b7-4f81-b64b-55c0dbed1bae@h12g2000pro.googlegroups.com> Message-ID: <8073828a-e871-4b06-b4f2-0abf247c5e34@q12g2000prb.googlegroups.com> On May 10, 8:55?am, "Gabriel Genellina" wrote: > En Sat, 07 May 2011 02:21:02 -0300, rusi escribi?: > > > There is this nice page of testing tools taxonomy: > >http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy > > > But it does not list staf:http://staf.sourceforge.net/index.php. > > The good thing about wikis is, you can add it yourself. > > -- > Gabriel Genellina Could not figure out how to get edit rights. [Which is all for the good considering what a testing-ignoramus I am :-) ] From invalid at invalid.invalid Tue May 10 10:05:34 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 May 2011 14:05:34 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On 2011-05-10, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> It's just that the term "variable" is so useful and so familiar that it's >> easy to use it even for languages that don't have variables in the C/ >> Pascal/Fortran/etc sense. > > Who says it has to have the Pascal/Fortran/etc sense? Because it's easier to communicate if everybody agrees on what a word means. -- Grant Edwards grant.b.edwards Yow! The SAME WAVE keeps at coming in and COLLAPSING gmail.com like a rayon MUU-MUU ... From rosuav at gmail.com Tue May 10 10:43:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 00:43:33 +1000 Subject: string formatting In-Reply-To: <4dc94897$0$18589$426a74cc@news.free.fr> References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc3e52a$0$24510$426a74cc@news.free.fr> <4dc94897$0$18589$426a74cc@news.free.fr> Message-ID: On Wed, May 11, 2011 at 12:15 AM, Web Dreamer wrote: > I was unsure of the difference between deprecated and obsolete. > > So now, if I understand well, obsolete comes before deprecated, such that if > a feature is obsolete it will be deprecated in an unknown future, after > which it will be removed once it has been deprecated (a certain time after > it was rendered obsolete)? > (might need an aspirin to read that one :-) ) > > So If I'm right, old string formatting "could" one day be deprecated but it > is not yet? I wouldn't say that obsolete features "will be" deprecated. That expression makes little sense (I know, for I have seen it in eBay's API documentation, and it did not fill me with joy). Deprecation is (usually) a formal procedure that clearly states that a feature should not be used. It may be accompanied by a strict cutoff ("will be removed in version X"), or just left vague, but linting tools can identify all use of deprecated features. Obsolete, however, is simply a description. Sopwith Camels were obsolete in the second world war, and VHS has been obsoleted by optical disc media. However, if you wish to fly a Camel or play a VHS, nothing's stopping you. The sky will still accept your Camel, and your VHS player will still talk to your television. (The analogy breaks down a bit in that your obsolete VHS player may be using a deprecated cabling style, but it's coax that's deprecated, not VHS.) There's no "projected end date" for them. Generally, a feature is obsolete before it's deprecated, but technically that's not a requirement, and API designers can sometimes be quite arbitrary. On the other hand, obsolescence is quite informal, and people can disagree about whether or not something is. (Hi Ken, your continued use of inches is noted. Thank you.) Chris Angelico From hg at schaathun.net Tue May 10 11:09:14 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 10 May 2011 16:09:14 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On Tue, 10 May 2011 14:05:34 +0000 (UTC), Grant Edwards wrote: : Because it's easier to communicate if everybody agrees on what a word : means. Why should we agree on that particular word? Are there any other words we agree about? Other key words, such as class, object, or function don't have universal meanings. :-) -- :-- Hans Georg From invalid at invalid.invalid Tue May 10 11:16:10 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 May 2011 15:16:10 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On 2011-05-10, Hans Georg Schaathun wrote: > On Tue, 10 May 2011 14:05:34 +0000 (UTC), Grant Edwards > wrote: >: Because it's easier to communicate if everybody agrees on what a word >: means. > > Why should we agree on that particular word? Are there any other words > we agree about? Other key words, such as class, object, or function don't > have universal meanings. And what do we mean by "agree"? What do we mean by "mean"? It's turtles all they down... -- Grant Edwards grant.b.edwards Yow! at gmail.com From rosuav at gmail.com Tue May 10 11:27:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 01:27:36 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On Wed, May 11, 2011 at 1:16 AM, Grant Edwards wrote: > And what do we mean by "agree"? > > What do we mean by "mean"? > > It's turtles all they down... When I use a word, it means just what I choose it to mean - neither more nor less. -- Humpty Dumpty. Language is for communication. If we're not using the same meanings for words, we will have problems. Chris Angelico PS. By "mean", I mean average. Except when I mean mean. But now I'm just being mean. From hg at schaathun.net Tue May 10 11:40:05 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 10 May 2011 16:40:05 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On Wed, 11 May 2011 01:27:36 +1000, Chris Angelico wrote: : Language is for communication. If we're not using the same meanings : for words, we will have problems. So if you adopt the word class to mean a type (or composite type), as in python, what word would you use for a class of types (as in haskell or ada)? I think there are too many meanings and too few words ... That's why some languages support overloading. I am afraid we just need to cope with it, overloading I mean. -- :-- Hans Georg From rosuav at gmail.com Tue May 10 11:44:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 01:44:03 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On Wed, May 11, 2011 at 1:40 AM, Hans Georg Schaathun wrote: > On Wed, 11 May 2011 01:27:36 +1000, Chris Angelico > ? wrote: > : ?Language is for communication. If we're not using the same meanings > : ?for words, we will have problems. > > So if you adopt the word class to mean a type (or composite type), > as in python, what word would you use for a class of types (as in > haskell or ada)? > > I think there are too many meanings and too few words ... > > That's why some languages support overloading. Of course. Nobody ever said that one name had to point to one value... oh wait. Yes, Virginia, there is overloading. Chris Angelico From hg at schaathun.net Tue May 10 11:49:52 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 10 May 2011 16:49:52 +0100 Subject: scipy References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> Message-ID: <0e3o98-t84.ln1@svn.schaathun.net> On Sun, 8 May 2011 03:44:06 -0700 (PDT), pb wrote: : I', having trouble with scipy. I have followed the instructions at : scipy website and have installed the following on my mac osx 10.6.6 : (...) : I'm assuming I have the wrong version of something, would that be : right? : Does anyone know how I can fix this? I had the same problem, but assumed that it was more likely to be a bug in the unit tests than a bug anywhere else. But then I mainly use linux boxen to run the stuff, so a bug on the mac installation does not bother me much. Installing software on a mac is just painful. -- :-- Hans Georg From rustompmody at gmail.com Tue May 10 12:41:19 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 10 May 2011 09:41:19 -0700 (PDT) Subject: Non Programming in python References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: Sorry for a silly subject change: A better one will be welcome -- cant think of a name myself. There is this whole area of python that may be called the non- programming side of programming: Is there some central site where all such is put up? What if any should such a bundle of things be called? ------------------------------------------------- | Area | Tool(s) | |------------------+------------------------| | packaging | distutils, setuptools, | | | distutils2, distribute | | | Native tools (eg apt) | | versioning | hg, git, bzr | | multiple pythons | virtualenv | | ?? | tox | | testing | unittest, nose, pytest | | build | scons, make... | | deployment | fabric | ------------------------------ * Primary Development tools/aids 1. Help 2. Completion ('intellisense') 3. Tags (Jumping) 4. Refactoring 5. Integration with 'non-programming' above (eg VCSes, packagers etc) * Other Development Tools - Debugger - Profiler - Heap Profiler - Coverage From claird271 at gmail.com Tue May 10 12:45:43 2011 From: claird271 at gmail.com (Cameron Laird) Date: Tue, 10 May 2011 09:45:43 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (May 10) Message-ID: [This content provided by Gabriel Genellina, despite what the "From:" line says.] QOTW: "Often, the cleverness of people is inversely proportional to the amount of CPU power and RAM that they have in their computer. Unfortunately, the difficulty in debugging and maintaining code is often directly proportional to the cleverness exhibited by the original programmer." - Irmen de Jong and Grant Edwards http://groups.google.com/group/comp.lang.python/t/58559ead6dc82448 Looking for "The Coolest Python Recipe of All Times": http://groups.google.com/group/comp.lang.python/t/141fdde77caab932 A nice and clever probabilistic data structure: http://groups.google.com/group/comp.lang.python/t/58559ead6dc82448 Development tools and best practices (continued from previous week): http://groups.google.com/group/comp.lang.python/t/836537e6c25cf027 Things to be aware of when using dictionary views: http://groups.google.com/group/comp.lang.python/t/b9c6ded7522e7425 Python3 and absolute/relative imports: http://groups.google.com/group/comp.lang.python/t/9470dbdacc138709 Another gotcha when using import with packages: http://groups.google.com/group/comp.lang.python/t/961a90219a61e19d Fibonacci, recursion, and the 'P' conspiracy theory: http://groups.google.com/group/comp.lang.python/t/b713b14e3e0d9872 The preferred way for string formatting: http://groups.google.com/group/comp.lang.python/t/f0cd2717ffe13560 Checking if a list is empty - and how to think "the Python way": http://groups.google.com/group/comp.lang.python/t/d36dcd2e2e175d1e Classics never die: What other languages use the same data model as Python? http://groups.google.com/group/comp.lang.python/t/4b8b0e06a2d5cfcc ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- From ethan at stoneleaf.us Tue May 10 13:18:53 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 10 May 2011 10:18:53 -0700 Subject: Dictionary Views -- good examples? [was Re: Python 3 dict question] In-Reply-To: References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> <4DC47B04.9070007@stoneleaf.us> Message-ID: <4DC9737D.1040608@stoneleaf.us> Ian Kelly wrote: > On Fri, May 6, 2011 at 4:49 PM, Ethan Furman wrote: >> Anybody care to chime in with their usage of this construct? > > You should start with PEP 3106. The main idea is that dict.keys() and > dict.items() can be treated as frozensets, while still being more > lightweight than lists. That lets you do nifty things like "a.keys() > == b.keys()" which, if a and b are Python 3 dicts, will tell you > whether they contain the same keys. Cool, thanks. ~Ethan~ From python at rcn.com Tue May 10 13:20:27 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 10 May 2011 10:20:27 -0700 (PDT) Subject: string formatting References: Message-ID: > Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old style. (2) and (3) are new but (3) is only > supported from Python 2.7+. > > Which one should be used? Sometimes, I use both ;-) That can save you from ugly escapes such as %%s or {{0}}. Here's an example from the standard library: http://hg.python.org/cpython/file/7254c03b7180/Lib/collections.py#l235 Note the template has both {typename} formatting for the first pass and %r style formatting in the generated code. Raymond ------------ follow my tips and recipes on twitter: @raymondh From python at rcn.com Tue May 10 13:25:54 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 10 May 2011 10:25:54 -0700 (PDT) Subject: Python 3 dict question References: Message-ID: <36fba210-18e8-4e9f-8de3-7386ecaf6a21@s16g2000prf.googlegroups.com> On May 6, 12:40?pm, dmitrey wrote: > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterator. > Of course, I could use > for key, val in myDict.items(): > ? ?do_something > ? ?break > but maybe there is any better way? If your use case allows the item to be removed, then use: key, val = myDict.popitem() Otherwise, use: key, val = next(iter(MyDict.items())) The latter is nice because next() allows you to supply a default argument in case the dictionary is emtpy: key, val = next(iter(MyDict.items()), (None, None)) Raymond --------- follow my tips and recipes on twitter: @raymondh From hg at schaathun.net Tue May 10 14:31:54 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 10 May 2011 19:31:54 +0100 Subject: vertical ordering of functions References: Message-ID: On Tue, 3 May 2011 18:08:27 -0400, Jabba Laci wrote: : I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. : 5 he says that a function that is called should be below a function : that does the calling. This creates a nice flow down from top to : bottom. My advice would be to order it in the same way as you would if you were presenting the algorithm in a paper. >From such a viewpoint, it depends on whether you consider the called names to be terms which need definitions, or operations with an intutive purpose, merely requiring an explanation (implentation) of how it is done. In a paper that means that definitions must come before the theorems and lemmata very often between the theorem and its proof. If you don't write papers, that may not be particularly useful :-) In programming, it means that names which have self-explanatory name may very well be called first and defined later. The caller will give a high-level view of what is going on. The callees are building blocks whose purpose can be understood immediately, and whose inner workings can be sought further down the file. Fundamental definitions which may be as easy to implement as explain may often come first. The question here, is didactics and not programming per se. A simple rule does not make complex code significantly easier to read, but a thought structure of the code (with comments and choice of names) over-all does. And let's not forget that calls may be circular or otherwise convolved in a way that does not allow consistent sorting of caller before/after callee. -- :-- Hans Georg From jean_paez at hotmail.es Tue May 10 14:51:03 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?SmVhbiBDYXJsb3MgUOFleiBSYW3tcmV6?=) Date: Tue, 10 May 2011 13:51:03 -0500 Subject: This it is the code of tmb_import.py (to matter of .tmb to blender) I need tmb_exporter.py (to export of blender to .tmb) Thanks. In-Reply-To: References: , , Message-ID: I need help. Hello. The attached file is script of blender fact in python that .tmb serves to concern archives (secondly attached file), unloadings to blender and uses script and concerns the second file that you shipment you see so that it. Everything can be published and, but it is not possible to be exported again to .tmb To unload in this Link: http://www.blender.org/ script: http://www.mediafire.com/?clmdgkymsfooddd secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 PD: I need script to export in extension .tmb Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue May 10 15:18:52 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 May 2011 15:18:52 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <92s8hlFqn5U1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> <92s8hlFqn5U1@mid.individual.net> Message-ID: On 5/10/2011 3:41 AM, Gregory Ewing wrote: > Actually, you're right. What I've presented is a paper-and-pencil > implementation of the Python data model. Together with a set of > rules for manipulating the diagram under the direction of Python > code, you have a complete implementation of Python that you can > execute in your head. I think that it would be both fun and useful to have an animated graphical tutorial that used and box and arrow model. Names should be in ovals (instead of the little boxes used here due to text limitations) to differentiate them from objects. Immutable objects could have solid boundaries and mutables a broken line boundary. Collection objects would have dotted lines to separate slots. Ovals could also use different lines for builtins, globals, and locals. > And you NEED such an implementation in order to reason correctly > about Python programs under all circumstances. > > I find it very difficult to imagine *any* implementation of > Python, computer-based or otherwise, that doesn't have something > equivalent to references. Whether you call them that, or pointers, > or arrows, or object bindings, or something else, the concept > needs to be there in some form. Since namespaces link names in a namespace with objects not in the namespace, any practical implementation needs a third entity to link or associated each name with an object. This is pretty much needed to explain multiple links without objects being in multiple locations. It is also needed to explain how an object can link to itself. -- Terry Jan Reedy From tjreedy at udel.edu Tue May 10 15:28:27 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 May 2011 15:28:27 -0400 Subject: Non Programming in python In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: On 5/10/2011 12:41 PM, rusi wrote: > Sorry for a silly subject change: A better one will be welcome -- cant > think of a name myself. Associated tools. I might separate them into development tools (up to the production of python.exe) and usage tools (everything thereafter). On Windows, this is a pretty clean separation. On Linux, less so since users sometimes build their own binaries and therefore use some of the development tools. Assuming that there is not one already, this could be the beginning of a useful overview wiki page with links to existing pages on the specific topics ('areas') listed below. > There is this whole area of python that may be called the non- > programming side of programming: > > Is there some central site where all such is put up? > What if any should such a bundle of things be called? > > ------------------------------------------------- > > | Area | Tool(s) | > |------------------+------------------------| > | packaging | distutils, setuptools, | > | | distutils2, distribute | > | | Native tools (eg apt) | > | versioning | hg, git, bzr | > | multiple pythons | virtualenv | > | ?? | tox | > | testing | unittest, nose, pytest | > | build | scons, make... | > | deployment | fabric | > > ------------------------------ I would reorder this list in the typical order used, starting with editors. > * Primary Development tools/aids > > 1. Help > 2. Completion ('intellisense') > 3. Tags (Jumping) > 4. Refactoring > 5. Integration with 'non-programming' above (eg VCSes, packagers > etc) > > * Other Development Tools > - Debugger > - Profiler > - Heap Profiler > - Coverage -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Tue May 10 18:47:46 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 11 May 2011 10:47:46 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> <92s8hlFqn5U1@mid.individual.net> Message-ID: <92ttklFqs3U1@mid.individual.net> Chris Angelico wrote: > There has to be a way to get from some mythical "home" location (which > we know in Python as locals()+globals()+current expression - the > "current namespace") to your object. That might involve several names, > or none at all, but if there's no such path, the object is > unreferenced and must be disposed of. Yes, that's what I mean by "bound to some anonymous thing". Somewhere in the implementation there must be one or more "root" references, but they don't necessarily have any names that you can refer to from Python. When I say "not bound to any name", I just mean that it's okay to leave some bindings out of your diagram if they're not pertinent to what you're trying to illustrate. For example, you can draw a box representing a string object and trust that something will keep it alive long enough for you to draw an arrow to it from the name you're assigning it to. -- Greg From steve+comp.lang.python at pearwood.info Tue May 10 18:53:54 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2011 22:53:54 GMT Subject: Non Programming in python References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <4dc9c202$0$29991$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 May 2011 09:41:19 -0700, rusi wrote: > Sorry for a silly subject change: A better one will be welcome -- cant > think of a name myself. > > There is this whole area of python that may be called the non- > programming side of programming: > > Is there some central site where all such is put up? What if any should > such a bundle of things be called? Documentation. Check the Python wiki. -- Steven From drsalists at gmail.com Tue May 10 19:00:40 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 10 May 2011 16:00:40 -0700 Subject: Python backup programs? Message-ID: What are your favorite backup programs written, in whole or in part, in Python? What do you like about them? Dislike about them? Are there any features you wish your backup program had, whether in Python or not? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Tue May 10 19:57:48 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 11 May 2011 09:57:48 +1000 Subject: Python backup programs? In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 9:00 AM, Dan Stromberg wrote: > > What are your favorite backup programs written, in whole or in part, in > Python? > > What do you like about them?? Dislike about them? > > Are there any features you wish your backup program had, whether in Python > or not? Recently I wrote a simple backup system for a client using a mixture of Python and Bash using rsync, ssh and pptp. (Not packaged well enough to show source though) It works very well and does the job. cheers James -- -- James Mills -- -- "Problems are solved by method" From gagsl-py2 at yahoo.com.ar Tue May 10 21:30:03 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 May 2011 22:30:03 -0300 Subject: This it is the code of tmb_import.py (to matter of .tmb to blender) I need tmb_exporter.py (to export of blender to .tmb) Thanks. References: Message-ID: En Tue, 10 May 2011 15:51:03 -0300, Jean Carlos P?ez Ram?rez escribi?: > The attached file is script of blender fact in python that .tmb serves to > concern archives (secondly attached file), unloadings to blender and uses Por lo que pude entender, tu problema es bastante espec?fico de Blender, as? que tal vez te convenga preguntar en un foro como: http://www.g-blender.org/ (espec?ficamente dedicado a Blender 3D en espa?ol) Tambi?n est? la comunidad de Python Argentina: http://python.org.ar/pyar/ (busca la lista de correo) Suerte! -- Gabriel Genellina From paulprobert at sbcglobal.net Tue May 10 23:26:18 2011 From: paulprobert at sbcglobal.net (Paul Probert) Date: Tue, 10 May 2011 22:26:18 -0500 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: On 05/09/2011 07:40 PM, Kyle T. Jones wrote: > > It has been hard for me to determine what would constitute overuse. > > Cheers. Well, for me the power of exceptions is that it lets me write much more concise code. For example, suppose I call a routine I wrote over and over, and I have to check for errors on each call. Then you have a long block of code like: if err == 0: x1,err=somefunction(1) if err == o: x2,err=somefunction(2) ... ... but if somefunction just raises an exception on error, then you do try: x1=somefunction(1) x2=somefunction(2) ... ... except: blah blah So for my uses, its handy to let things raise exceptions willy nilly in the lower level functions, and do the catching in the higher level function. Paul Probert From rustompmody at gmail.com Tue May 10 23:36:43 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 10 May 2011 20:36:43 -0700 (PDT) Subject: Non Programming in python References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <56535cf9-1b78-4150-9013-24c891753bc8@h12g2000pro.googlegroups.com> On May 11, 12:28?am, Terry Reedy wrote: > On 5/10/2011 12:41 PM, rusi wrote: > > > Sorry for a silly subject change: A better one will be welcome -- cant > > think of a name myself. > > Associated tools. I might separate them into development tools (up to > the production of python.exe) and usage tools (everything thereafter). > On Windows, this is a pretty clean separation. On Linux, less so since > users sometimes build their own binaries and therefore use some of the > development tools. Can you elaborate? I dont understand > > Assuming that there is not one already, this could be the beginning of a > useful overview wiki page with links to existing pages on the specific > topics ('areas') listed below. > > > > > There is this whole area of python that may be called the non- > > programming side of programming: > > > Is there some central site where all such is put up? > > What if any should such a bundle of things be called? > > > ------------------------------------------------- > > > ? ?| Area ? ? ? ? ? ? | Tool(s) ? ? ? ? ? ? ? ?| > > ? ?|------------------+------------------------| > > ? ?| packaging ? ? ? ?| distutils, setuptools, | > > ? ?| ? ? ? ? ? ? ? ? ?| distutils2, distribute | > > ? ?| ? ? ? ? ? ? ? ? ?| Native tools (eg apt) ?| > > ? ?| versioning ? ? ? | hg, git, bzr ? ? ? ? ? | > > ? ?| multiple pythons | virtualenv ? ? ? ? ? ? | > > ? ?| ?? ? ? ? ? ? ? ? | tox ? ? ? ? ? ? ? ? ? ?| > > ? ?| testing ? ? ? ? ?| unittest, nose, pytest | > > ? ?| build ? ? ? ? ? ?| scons, make... ? ? ? ? | > > ? ?| deployment ? ? ? | fabric ? ? ? ? ? ? ? ? | > > > ------------------------------ > > I would reorder this list in the typical order used, starting with editors. > > > * Primary Development tools/aids > > > ? ?1. Help > > ? ?2. Completion ('intellisense') > > ? ?3. Tags (Jumping) > > ? ?4. Refactoring > > ? ?5. Integration with 'non-programming' above (eg VCSes, packagers > > etc) > > > * Other Development Tools > > ? ?- Debugger > > ? ?- Profiler > > ? ?- Heap Profiler > > ? ?- Coverage Some more 'areas': 1. Which python 'form' does one use? At the least python vs pythonw on windows. But more generally scripting vs REPL. In REPL python vs ipython Note 1. I am often unnerved by how even experienced python programmers think that the only way to 'do' python is like C -- write a main, not appreciating the luxury of an unstructured, exploratory mode that an REPL makes possible. Note 2. ruby makes this distinction more obvious by distinguishing the scripting engine -- ruby -- form the interactive interpreter (REPL) -- irb. 2. Literate Programming: When the primary purpose of the program is not the program but (some form of) discussion around it 3. Program namespace lookup and structuring: sys.path is the interior program view but there is also the 'exterior' view -- PYTHONPATH, .pth files etc. Finally some thoughts on how to name this list of areas: a. Software Engineering? : Inasmuch as real program development is programming + 'something-else' and SE is that 'something else' b. Python Development Environment? Similar to above [Cannot say I like these names too much but at least its more specific than Steven's vanilla 'documentation' :-) ] From prologic at shortcircuit.net.au Tue May 10 23:37:57 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 11 May 2011 13:37:57 +1000 Subject: Overuse of try/except/else? In-Reply-To: <4DC90692.50903@sequans.com> References: <4DC90692.50903@sequans.com> Message-ID: On Tue, May 10, 2011 at 7:34 PM, Jean-Michel Pichavant wrote: > You can reraise the exception without loosing the stack trace. > > try: > ... > except SomeException, exc: > log(exc) > print 'Hello world' > raise # "raise exc" would loose the original stack trace Valid point :) However I was referring to real experience where I've seen code that "catches all any any exception" and simply logs it. cheers James -- -- James Mills -- -- "Problems are solved by method" From greg.ewing at canterbury.ac.nz Wed May 11 01:35:08 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 11 May 2011 17:35:08 +1200 Subject: Merge multiple source directories into one package with distutils? Message-ID: <92ulgfFmukU1@mid.individual.net> Is there a straightforward way to tell distutils to merge .py files from more than one source directory into a single package when installing? PyGUI consists of some generic modules and some platform specific ones, that conceptually all live at the same level within a single package. In the source, there is a subdirectory for each platform containing the platform-dependent files. When run from the source, __path__ manipulation is done to make the appropriate platform subdirectory appear to be part of the main package. However, when installing, I would like to just copy the generic files plus the relevant platform ones directly into the destination package directory, so that __path__ fiddling is not needed. This is so that bundling tools such as py2app and py2exe can find all the relevant modules without requiring any hacking. But distutils doesn't appear to support this. Unless I'm missing something, you only get to specify one source directory for each package. Anyone have any ideas for getting around this? -- Greg From moky.math at gmail.com Wed May 11 02:45:51 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Wed, 11 May 2011 08:45:51 +0200 Subject: Python backup programs? In-Reply-To: References: Message-ID: Le 11/05/2011 01:57, James Mills a ?crit : > On Wed, May 11, 2011 at 9:00 AM, Dan Stromberg wrote: >> >> What are your favorite backup programs written, in whole or in part, in >> Python? My favorite one is the one I wrote myself for myself ;) The point I like : 1. the backup is a simple copy. I can retrieve it without any specific programs. 2. if a file changed, before to be copied, the backup file is moved to a specific repertory whose name is the date and hour. So if I destroy a file and backup the destroyed one, the old non-destroyed one is still available. 3. Since the program is anyway performing a long os.walk operation, in the same time, it performs `git commit` in the directories that need it. 4. My program is command-line only. Works fine in tty Points that are of no importance (very personal and adapted to my specific case !) : 1. time. One backup takes between 10 minutes and one hour. I don't really care. 2. space. Since my backup is a copy (and copy of copies), my backup directory takes ~150Go while my home is about 25 Go. Hope it answer your question. Have a nice day Laurent From swavijay at gmail.com Wed May 11 02:57:13 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Wed, 11 May 2011 12:27:13 +0530 Subject: NewBie Doubt in Python Thread Programming Message-ID: Hi All, I'm new bie to thread programming and I need some assistance in understanding few concepts ... I have a very simple program which runs a thread and prints a string. import threading class MyThread(threading.Thread): def __init__(self, parent = None): threading.Thread.__init__(self) def run(self): print 'Hello World' def main(): for i in range(10): MyThread_Object = MyThread() print 'Object id is : ' , id(MyThread_Object) print 'Staring thread ----------> ' , MyThread_Object.getName() MyThread_Object.start() count = threading.activeCount() print 'The active thread count is: ' , count if __name__ == '__main__': main() When I run this, I could see 10 thread being called. But when I print the active thread count it is only 2. Need some understanding on the following. 1. How the total active thread is 2? 2. how do I stop a thread? does it get automatically stopped after execution ? 3. Am I totally wrong in understanding the concepts. 4. what is the difference between active_count() and activeCount() since both seem to give the same result. 5. is there a way to find out if the thread is still active or dead? Please help me in understanding .. -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed May 11 03:15:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 17:15:25 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 4:57 PM, vijay swaminathan wrote: > ??? for i in range(10): > ??????? MyThread_Object.start() > ??? count = threading.activeCount() > > When I run this, I could see 10 thread being called. But when I print the > active thread count it is only 2. > > Need some understanding on the following. > > 1. How the total active thread is 2? My guess is that all (or all but one) of the threads have finished already by the time you check activeCount. If you add a call to time.sleep(1) in the run() method, you'll see 11 or 12 threads (your main threads and 10 others). If you print out threading.activeCount() at the top of the program, you'll see that it starts at 2 in IDLE, or 1 in stand-alone Python. > 2. how do I stop a thread? does it get automatically stopped after execution Once the run() method returns, the thread is terminated. You shouldn't normally need to stop a thread from another thread. > 3. Am I totally wrong in understanding the concepts. > 4. what is the difference between active_count() and activeCount() since > both seem to give the same result. The camelCase function names were inspired by Java's API, the ones with underscores are more Python's style. They are absolutely the same though. See the notes at the top of http://docs.python.org/library/threading.html for that and other information. > 5. is there a way to find out if the thread is still active or dead? Yep! Call is_alive() on your thread object. It'll return True if it's still going. Again, the docs for the threading module (http://docs.python.org/library/threading.html) have all that sort of thing. Threading is a bit of a tricky concept, and takes some getting used to. There are many places where threads are awesome, and many where they're pretty useless. The place I most often use threads is in socket programming; when I run a server, I usually spin off a thread to handle each incoming socket, as it's the easiest way to handle sequential actions (especially if the socket protocol is command-response, like a MUD or a mail server). Once you get your head around the threading module, you'll find the multiprocessing module very similar. For Python, the difference is sometimes quite important, so it's as well to understand both. Hope that helps! Chris Angelico From gagsl-py2 at yahoo.com.ar Wed May 11 03:31:50 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 11 May 2011 04:31:50 -0300 Subject: NewBie Doubt in Python Thread Programming References: Message-ID: En Wed, 11 May 2011 03:57:13 -0300, vijay swaminathan escribi?: > Hi All, > > I'm new bie to thread programming and I need some assistance in > understanding few concepts ... > > I have a very simple program which runs a thread and prints a string. > > import threading > > class MyThread(threading.Thread): > def __init__(self, parent = None): > threading.Thread.__init__(self) > > def run(self): > print 'Hello World' > > def main(): > for i in range(10): > MyThread_Object = MyThread() > print 'Object id is : ' , id(MyThread_Object) > print 'Staring thread ----------> ' , MyThread_Object.getName() > MyThread_Object.start() > count = threading.activeCount() > print 'The active thread count is: ' , count > > if __name__ == '__main__': > main() > > When I run this, I could see 10 thread being called. But when I print the > active thread count it is only 2. > > Need some understanding on the following. > > 1. How the total active thread is 2? Because most of them have already finished by then. Your run() method executes quite fast. Make it take more time (maybe by adding time.sleep(1)) and you'll see 10 active threads. > 2. how do I stop a thread? does it get automatically stopped after > execution > ? You don't; a trhread runs until the run() method exits. After that, the OS thread finishes. The Python object (a threading.Thread instance) is still alive (until the last reference to it disappears, as any other object). > 3. Am I totally wrong in understanding the concepts. I don't know... > 4. what is the difference between active_count() and activeCount() since > both seem to give the same result. Nothing. active_count is the preferred Python spelling per PEP8; activeCount is the original Java spelling. > 5. is there a way to find out if the thread is still active or dead? Yes, use is_alive() -- Gabriel Genellina From prologic at shortcircuit.net.au Wed May 11 03:34:10 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 11 May 2011 17:34:10 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 4:57 PM, vijay swaminathan wrote: [...] > 1. How the total active thread is 2? Your threads are terminating as normal. Without some kind of loop in your run() method they will execute the instructions and terminate. > 2. how do I stop a thread? does it get automatically stopped after execution Usually by a flag or condition that terminates your run() function/method. > 3. Am I totally wrong in understanding the concepts. > 4. what is the difference between active_count() and activeCount() since > both seem to give the same result. They are synonyms. > 5. is there a way to find out if the thread is still active or dead? See: pydoc threading.Thread or help(threading.Thread) cheers James -- -- James Mills -- -- "Problems are solved by method" From nobody at nowhere.net.no Wed May 11 04:04:13 2011 From: nobody at nowhere.net.no (TheSaint) Date: Wed, 11 May 2011 16:04:13 +0800 Subject: Py3k,email header handling Message-ID: Hello, some time ago, I wrote a program to eliminate undesided emails from the server(s) and leave those which comply to certain filter criteria. I started it when I got to know whit Python 2.3. Now a days I'd like to spend some time to improve it, just for my interest, however it didn't gather anybody's interest before. Now python 3.2 (and some version before) started to use byte, rather than text strings, almost for all data handling in compliance to unicode. My problem arise that my program handle text strings, so I'd like to rewrite the code My program reads from IMAP4 or POP3 server, I'd prefer that a function/class will return either a list or a dictionary which contains the following fields: 'from', 'to', 'cc', 'bcc', 'date', 'subject', 'reply-to', 'message-id' The list may be organized as tuple (from, its_content,), etc,etc for each field, but I think dictionary would be more efficient to use. 1) is there a way to call the IMAPlib or POPlib and pass the data directly to email.parser.HeaderParser to achieve my intention? 2) If the above will do, do re.compile compile unicode results? I guess yes. 3) any related documentation... -- goto /dev/null From rosuav at gmail.com Wed May 11 04:46:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 18:46:36 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: I'm responding to this on-list on the assumption that this wasn't meant to be private; apologies if you didn't intend for this to be the case! On Wed, May 11, 2011 at 6:38 PM, vijay swaminathan wrote: > so If i understand correctly, once the run method of the thread is executed, > the thread is no more alive. Once run() finishes executing, the thread dies. > Actually, I'm trying to invoke a command prompt to run some script and as > long as the script runs on the command prompt, I would like to have the > thread alive. But according to your statement, the thread would die off > after invoking the command prompt. is there a way to keep the thread active > till I manually close the command prompt? That depends on how the "invoke command prompt" function works. > A snippet of the code written is: > # Thread definition > class RunMonitor(QThread): > ??? def __init__(self, parent=None): > ??????? QThread.__init__(self) > ??? def run(self): > ??????? print 'Invoking Command Prompt..........' > ??????? subprocess.call(["start", "/DC:\\Scripts", > "scripts_to_execute.bat"], shell=True) > > ?def sendData(self): > > ??????? if self.run_timer: > ??????????? run_monitor_object = RunMonitor() > ??????????? print 'Starting the thread...........' > ??????????? run_monitor_object.start() > ??????????? self.run_timer = False > > ??????? if run_monitor_object.isAlive(): > ??????????? print 'Thread Alive...' > ??????? else: > ??????????? print 'Thread is Dead....' > subprocess.call() will return immediately, so this won't work. But if you use os.system() instead, then it should do as you intend. > to check the status of the thread repeatedly I have the QTimer which would > call the self.sendData() for every minute. > > ??????? self.timer = QTimer() > ??????? self.timer.connect(self.timer, SIGNAL("timeout()"),self.sendData) > ??????? self.timer.start(1000) I'm not really sure what your overall goal is. Can you explain more of your high-level intentions for this program? There may be a much easier way to accomplish it. Chris Angelico From hg at schaathun.net Wed May 11 05:02:42 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 10:02:42 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07 May 2011 02:51:50 GMT, Steven D'Aprano wrote: : On Fri, 06 May 2011 14:57:21 -0700, scattered wrote: : : > is there any problem with : > : > (3) if li == []: : > : > ? : > : > Seems to work when I test it and seems to clearly test what you are : > trying to test. The only problem might be if in some contexts == has the : > semantics of checking for object identity. : : Yes, if li == [] works too. But how do you know li is a list and not some : other sequence type? It says so in the Subject header :-) : The advantage of the "if x" test is that it is independent of the type of : x. Sure, but the question wasn't ... The problem with 'if x' is that it requires a much more detailed understanding of python. li == [] is as explicit as it gets, and leaves no room for doubt. len(li) == 0 is almost as explicit and much more flexible. Just x is as generic as it gets, but depends on python's convolved rules for duck processing and if you aim at legibility it is better avoided. -- :-- Hans Georg From swavijay at gmail.com Wed May 11 05:08:55 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Wed, 11 May 2011 14:38:55 +0530 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: Sorry. My intention was not to send out a private message. when I chose reply to all, I was confused if this would start as a new thread. so just did a reply.. coming back, I have developed a GUI based on pyQT4 which has a run button. when I click on run, it invokes a command prompt and runs a .bat file. Till the execution of .bat file is over, I want the run button on the GUI to be disabled. so i thought of invoking the command prompt and running the .bat file on a thread so that I could monitor the status of the thread (assuming that the thread would be active till command prompt is active - correct me if I'm wrong). for this, the code that I had written is; # to invoke a command prompt and execute the .bat file. class RunMonitor(threading.Thread): def __init__(self, parent=None): threading.Thread.__init__(self) def run(self): print 'Invoking Command Prompt..........' subprocess.call(["start", "/DC:\\Script", "scripts_to_execute.bat"], shell=True) A timer function to call this thread and monitor this thread.. def runscript(self): self.timer = QTimer() self.timer.connect(self.timer, SIGNAL("timeout()"),self.sendData) self.timer.start(1000) def sendData(self): if self.run_timer: run_monitor_object = RunMonitor() print 'Starting the thread...........' run_monitor_object.start() self.run_timer = False if run_monitor_object.isAlive(): print 'Thread Alive...' else: print 'Thread is Dead....' Any flaw in the logic? any other better ways of achieving this? On Wed, May 11, 2011 at 2:16 PM, Chris Angelico wrote: > I'm responding to this on-list on the assumption that this wasn't > meant to be private; apologies if you didn't intend for this to be the > case! > > On Wed, May 11, 2011 at 6:38 PM, vijay swaminathan > wrote: > > so If i understand correctly, once the run method of the thread is > executed, > > the thread is no more alive. > > Once run() finishes executing, the thread dies. > > > Actually, I'm trying to invoke a command prompt to run some script and as > > long as the script runs on the command prompt, I would like to have the > > thread alive. But according to your statement, the thread would die off > > after invoking the command prompt. is there a way to keep the thread > active > > till I manually close the command prompt? > > That depends on how the "invoke command prompt" function works. > > > A snippet of the code written is: > > # Thread definition > > class RunMonitor(QThread): > > def __init__(self, parent=None): > > QThread.__init__(self) > > def run(self): > > print 'Invoking Command Prompt..........' > > subprocess.call(["start", "/DC:\\Scripts", > > "scripts_to_execute.bat"], shell=True) > > > > def sendData(self): > > > > if self.run_timer: > > run_monitor_object = RunMonitor() > > print 'Starting the thread...........' > > run_monitor_object.start() > > self.run_timer = False > > > > if run_monitor_object.isAlive(): > > print 'Thread Alive...' > > else: > > print 'Thread is Dead....' > > > > subprocess.call() will return immediately, so this won't work. But if > you use os.system() instead, then it should do as you intend. > > > to check the status of the thread repeatedly I have the QTimer which > would > > call the self.sendData() for every minute. > > > > self.timer = QTimer() > > self.timer.connect(self.timer, SIGNAL("timeout()"),self.sendData) > > self.timer.start(1000) > > I'm not really sure what your overall goal is. Can you explain more of > your high-level intentions for this program? There may be a much > easier way to accomplish it. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From hg at schaathun.net Wed May 11 05:14:38 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 10:14:38 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07 May 2011 02:49:53 GMT, Steven D'Aprano wrote: : On Fri, 06 May 2011 16:05:09 -0400, Adam Tauno Williams wrote: : : > I'd never accept code like "if not x" as an empty test. : : So much the worse for you then. : : The point of the "if x" idiom is that it is a polymorphic test which is : independent of the type. Normally, polymorphisms implies multiple forms only, where the different forms has some form of common interpretation. That's what makes polymorphism useful and helpful, increasing legibility. In this case, the interpretation of an arbitrary object as a boolean is peculiar for python. An empty list is a real, existing object, and the supposition that [] be false is counter-intuitive. It can be learnt, and the shorthand may be powerful when it is, but it will confuse many readers. -- :-- Hans Georg From moky.math at gmail.com Wed May 11 05:48:16 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Wed, 11 May 2011 11:48:16 +0200 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: > In this case, the interpretation of an arbitrary object as a boolean > is peculiar for python. An empty list is a real, existing object, and > the supposition that [] be false is counter-intuitive. It can be > learnt, and the shorthand may be powerful when it is, but it will > confuse many readers. Once I wrote something like: def f(x=None): if x: print x else: print "I have no value" The caller of that function was something like f(cos(2*theta)) where theta come from some computations. Well. When it turned out that theta was equal to pi/4, I got "I have no value". I spent a while to figure out the problem :) Conclusion: the boolean value of an object is to be used with care in order to tests if an optional parameter is given or not (when default value is None). Have a good noon Laurent From hg at schaathun.net Wed May 11 06:47:42 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 11:47:42 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 07 May 2011 21:57:13 -0700, Ethan Furman wrote: : If you're going to use a language, and use it well, you have to learn : how that language works. And if the world evolves around the compiler and you, that advice suffices. However, programming is often as much about developing ideas in a large and complex community, where perfect universal mastery of one language is not an option, because half the community do not normally use that language or aren't really programmers at all. The less you assume about the skill of the reader, the better it is. -- :-- Hans Georg From rosuav at gmail.com Wed May 11 07:13:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 21:13:33 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 7:08 PM, vijay swaminathan wrote: > Sorry. My intention was not to send out a private message. when I chose > reply to all, I was confused if this would start as a new thread. so just > did a reply.. No probs. If you just send your response to the list python-list at python.org. it'll get to everyone. > I have developed a GUI based on pyQT4 which has a run button. when I click > on run, it invokes a command prompt and runs a .bat file. > > Till the execution of .bat file is over, I want the run button on the GUI to > be disabled. so i thought of invoking the command prompt and running the > .bat file on a thread so that I could monitor the status of the thread > (assuming that the thread would be active till command prompt is active - > correct me if I'm wrong). Yes, but only if you use os.system(). > Any flaw? in the logic? any other better ways of achieving this? > You'll find it easier to get an event at the end of it; simply have another line of code after the os.system() which will reenable the button. Chris Angelico From steve+comp.lang.python at pearwood.info Wed May 11 07:14:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 11:14:25 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dca6f91$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 11:48:16 +0200, Laurent Claessens wrote: > Once I wrote something like: > > def f(x=None): > if x: > print x > else: > print "I have no value" > > > The caller of that function was something like f(cos(2*theta)) where > theta come from some computations. > > Well. When it turned out that theta was equal to pi/4, I got "I have no > value". I spent a while to figure out the problem :) I believe you are grossly oversimplifying whatever code you had. Using the definition of f from above: >>> theta = math.pi/4 >>> f(math.cos(2*theta)) 6.12303176911e-17 But even if you rounded the result of cos(2*theta) to zero, you will get the same result regardless of whether you test for "if x" or "if x != 0". > Conclusion: the boolean value of an object is to be used with care in > order to tests if an optional parameter is given or not (when default > value is None). Or, to put it another way: if you want to test for an object being None, test for the object being None. -- Steven From jean_paez at hotmail.es Wed May 11 07:30:04 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?SmVhbiBDYXJsb3MgUOFleiBSYW3tcmV6?=) Date: Wed, 11 May 2011 06:30:04 -0500 Subject: HELP. This it is the code of tmb_import.py (to matter of .tmb to blender) I need tmb_exporter.py (to export of blender to .tmb) Thanks. In-Reply-To: References: , , , , , Message-ID: Buen d?a comunidad Hola. El archivo adjunto es un script de blender hecho en python que sirve para importar archivos .tmb (http://www.mediafire.com/?clmdgkymsfooddd), descargas blender y usa el script e importa el segundo archivo que te envio para que lo veas (http://www.mediafire.com/?lbmj594ru6r4b67). El se puede editar y todo, pero no se puede exportar de nuevo a .tmb link del script: http://www.mediafire.com/?clmdgkymsfooddd Segundo archivo adjunto: http://www.mediafire.com/?lbmj594ru6r4b67 PD: Necesito el script para exportar en extension .tmb En si necesito ayuda en ese dise?o de un script que exporte de .blend a .tmb Gracias. _________________________________________ Hello. The attached file is script of blender fact in python that .tmb serves to concern archives (secondly attached file), unloadings to blender and uses script and concerns the second file that you shipment you see so that it. Everything can be published and, but it is not possible to be exported again to .tmb To unload in this Link: http://www.blender.org/ script: http://www.mediafire.com/?clmdgkymsfooddd secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 PD: I need script to export in extension .tmb Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jean_paez at hotmail.es Wed May 11 07:31:27 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?SmVhbiBDYXJsb3MgUOFleiBSYW3tcmV6?=) Date: Wed, 11 May 2011 06:31:27 -0500 Subject: HELP. This it is the code of tmb_import.py (to matter of .tmb to blender) I need tmb_exporter.py (to export of blender to .tmb) Thanks. In-Reply-To: References: , , , , , Message-ID: Buen d?a comunidad Hola. El archivo adjunto es un script de blender hecho en python que sirve para importar archivos .tmb (http://www.mediafire.com/?clmdgkymsfooddd), descargas blender y usa el script e importa el segundo archivo que te envio para que lo veas (http://www.mediafire.com/?lbmj594ru6r4b67). El se puede editar y todo, pero no se puede exportar de nuevo a .tmb link del script: http://www.mediafire.com/?clmdgkymsfooddd Segundo archivo adjunto: http://www.mediafire.com/?lbmj594ru6r4b67 PD: Necesito el script para exportar en extension .tmb En si necesito ayuda en ese dise?o de un script que exporte de .blend a .tmb Gracias. _________________________________________ Hello. The attached file is script of blender fact in python that .tmb serves to concern archives (secondly attached file), unloadings to blender and uses script and concerns the second file that you shipment you see so that it. Everything can be published and, but it is not possible to be exported again to .tmb To unload in this Link: http://www.blender.org/ script: http://www.mediafire.com/?clmdgkymsfooddd secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 PD: I need script to export in extension .tmb Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From moky.math at gmail.com Wed May 11 07:45:05 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Wed, 11 May 2011 13:45:05 +0200 Subject: checking if a list is empty In-Reply-To: <4dca6f91$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca6f91$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCA76C1.4040205@gmail.com> > I believe you are grossly oversimplifying whatever code you had. Using > the definition of f from above: > >>>> theta = math.pi/4 >>>> f(math.cos(2*theta)) > 6.12303176911e-17 Yes: its oversimplifued. The angle come from a normal vector of a curve and so on.... In particular, I was using Sage; the computations are exact: pi is pi and cos(pi) is zero. >> Conclusion: the boolean value of an object is to be used with care in >> order to tests if an optional parameter is given or not (when default >> value is None). > > Or, to put it another way: if you want to test for an object being None, > test for the object being None. It was my conclusion too ;) Laurent From moky.math at gmail.com Wed May 11 07:45:23 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Wed, 11 May 2011 13:45:23 +0200 Subject: checking if a list is empty In-Reply-To: <4dca6f91$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca6f91$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: > I believe you are grossly oversimplifying whatever code you had. Using > the definition of f from above: > >>>> theta = math.pi/4 >>>> f(math.cos(2*theta)) > 6.12303176911e-17 Yes: its oversimplifued. The angle come from a normal vector of a curve and so on.... In particular, I was using Sage; the computations are exact: pi is pi and cos(pi) is zero. >> Conclusion: the boolean value of an object is to be used with care in >> order to tests if an optional parameter is given or not (when default >> value is None). > > Or, to put it another way: if you want to test for an object being None, > test for the object being None. It was my conclusion too ;) Laurent From steve+comp.lang.python at pearwood.info Wed May 11 08:14:46 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 12:14:46 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 10:02:42 +0100, Hans Georg Schaathun wrote: > The problem with 'if x' is that it requires a much more detailed > understanding of python. "Much" more detailed? Hardly. Understanding that Python accepts any and all objects in truth-testing concepts, and the rules thereof, is Python 101 territory. It's beginner- level knowledge. It is far less advanced than the knowledge that ** is used for exponentiation. After all, many programmers have never needed to raise a number to a power, and might not learn about it for years, but every programmer writes if or while statements at some point. Not knowing that you can write "if x" instead of "if x == []" is like not knowing that you can write elif condition instead of else: if condition If somebody were to argue that it is "better to write else if explicitly, instead of the confusing elif", we'd all laugh at them. Every time the question of conditional testing comes up here, it never ceases to astonish me how many developers argue against learning the idioms of the language, and prefer to re-use the idioms of other languages in Python. Python is an object-oriented language where objects get to decide for themselves whether they should be treated as true or false. Writing: if x == []: instead of if x: merely[1] because you worry that it isn't explicit enough, or could confuse other developers, or out of some nagging concern that maybe Python will do the wrong thing[2] unless you hold its hand through the process, is as silly as writing this: count = 0 for item in x: count += 1 instead of: count = len(x) (As silly, but not as verbose.) I don't mean to insult anyone, but I've heard and read all the arguments against Python's truth-testing, and they don't impress me in the slightest. Most of them strike me as silly. The only argument that carries any weight to me is one which I haven't seen anyone raise: "if x:" turns something which arguably could have been a mistake ("oops, I forgot to write the condition!") into valid code. [1] It may be that there are good, solid reasons for writing explicit len(x)==0 tests, although I'm hard-pressed to think of any. The closest I come to is when you wish to emphasize "equal to some number that just happens to be zero" rather than "it's a false/empty value". If so, you get a free pass to write the test the long way. E.g. you might write "x % 2 == 1" rather than just "x % 2" because you want to highlight that the remainder equals one, rather than the remainder merely being a true value. [2] Of course, a custom object x might misbehave when you test it for truth value. That would be a bug, just like it would be a bug if it misbehaved when you call len(x) == 0. If you can't trust "if x" to work, what makes you think you can trust "len(x) == 0" either? -- Steven From roy at panix.com Wed May 11 08:26:53 2011 From: roy at panix.com (Roy Smith) Date: Wed, 11 May 2011 08:26:53 -0400 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hans Georg Schaathun wrote: > li == [] is as explicit as it gets, and > leaves no room for doubt. I was about to write, "this fails if li is an instance of a subclass of list", but then I tried it. I was astounded to discover that: class MyList(list): "I'm a subclass" li = MyList() print li == [] print [] == li prints True, twice! I expected them both to be false. In fact, the docs (http://tinyurl.com/3qga3lb) explicitly say: > If both are numbers, they are converted to a common type. Otherwise, > objects of different types always compare unequal Since these are different types, i.e. print type(li) print type([]) print type(li) == type([]) prints False I conclude that li == [] should have returned False. Either I'm not understanding things correctly, or this is a bug. From ironfroggy at gmail.com Wed May 11 08:27:13 2011 From: ironfroggy at gmail.com (Calvin Spealman) Date: Wed, 11 May 2011 08:27:13 -0400 Subject: Non Programming in python In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: If this is the "non-programming side of python" then maybe some of us have a lacking definition of what "programming" is. My mechanic stilll has to check the tire pressure and I need to update the version number in PyPI. On May 10, 2011 12:46 PM, "rusi" wrote: Sorry for a silly subject change: A better one will be welcome -- cant think of a name myself. There is this whole area of python that may be called the non- programming side of programming: Is there some central site where all such is put up? What if any should such a bundle of things be called? ------------------------------------------------- | Area | Tool(s) | |------------------+------------------------| | packaging | distutils, setuptools, | | | distutils2, distribute | | | Native tools (eg apt) | | versioning | hg, git, bzr | | multiple pythons | virtualenv | | ?? | tox | | testing | unittest, nose, pytest | | build | scons, make... | | deployment | fabric | ------------------------------ * Primary Development tools/aids 1. Help 2. Completion ('intellisense') 3. Tags (Jumping) 4. Refactoring 5. Integration with 'non-programming' above (eg VCSes, packagers etc) * Other Development Tools - Debugger - Profiler - Heap Profiler - Coverage -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From vithyamaha6 at gmail.com Wed May 11 08:28:59 2011 From: vithyamaha6 at gmail.com (maha) Date: Wed, 11 May 2011 05:28:59 -0700 (PDT) Subject: EARN 1000 DOLLARS PER DAY - FOREX TRADING CLICK HERE Message-ID: <77cbe98f-e740-4fb5-895b-27b04913af54@z7g2000prh.googlegroups.com> http://earnforexnow.blogspot.com/ http://earnforexnow.blogspot.com/ http://earnforexnow.blogspot.com/ http://earnforexnow.blogspot.com/ http://earnforexnow.blogspot.com/ From miki.tebeka at gmail.com Wed May 11 09:15:34 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 11 May 2011 06:15:34 -0700 (PDT) Subject: Merge multiple source directories into one package with distutils? In-Reply-To: <92ulgfFmukU1@mid.individual.net> Message-ID: <4228410e-4631-47be-936c-041122f27ffb@glegroupsg2000goo.googlegroups.com> Greg, > Is there a straightforward way to tell distutils to merge .py files from more than one source directory into a single package when installing? The Selenium Python bindings does something like that, have a look at http://selenium.googlecode.com/svn/trunk/setup.py The other option is to write some code in setup.py before calling "setup" to do the merge. HTH -- Miki Tebeka http://pythonwise.blogspot.com From steve+comp.lang.python at pearwood.info Wed May 11 09:29:38 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 13:29:38 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dca8f41$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 08:26:53 -0400, Roy Smith wrote: > Hans Georg Schaathun wrote: > >> li == [] is as explicit as it gets, and leaves no room for doubt. > > I was about to write, "this fails if li is an instance of a subclass of > list", but then I tried it. I was astounded to discover that: > > class MyList(list): > "I'm a subclass" > > li = MyList() > print li == [] > print [] == li > > prints True, twice! I expected them both to be false. In fact, the > docs (http://tinyurl.com/3qga3lb) explicitly say: > >> If both are numbers, they are converted to a common type. Otherwise, >> objects of different types always compare unequal That should be understood as only applying for built-in types, not arbitrary types. For arbitrary types, you can decide what counts as equal by writing an __eq__ method, and you can do *anything*: def __eq__(self, other): if today() == "Tuesday": return True else: ... To understand the behaviour you are seeing, it helps to understand that while li is a MyList, it is also a list: >>> isinstance(li, list) True It therefore inherits the same behaviour as list, unless you override or overload it. Since you did neither, MyLists work just like lists, right down to their __eq__ method. It is normally considered The Right Thing To Do for subclasses to be usable anywhere where a superclass was. That is, subclasses like MyList should only *add* behaviour, never *subtract* it. Since: >>> li = list() >>> li == [] True applies, you should be able to replace list() with any subclass of list and it should still work. (This is known as the Liskov Substitution Principle, if you wish to google on it.) This being Python, it's more of a guideline than a law, and you can violate it if you choose, but you probably shouldn't unless you have good reason. But if you want, just add a method: def __eq__(self, other): # untested if type(self) is not type(other): return False return super(self, MyList).__eq__(other) to get the behaviour you are after. So, not a bug, but a subtle point that isn't explained terribly well in the docs. -- Steven From emile at fenx.com Wed May 11 09:34:28 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 11 May 2011 06:34:28 -0700 Subject: Python backup programs? In-Reply-To: References: Message-ID: On 5/10/2011 4:00 PM Dan Stromberg said... > What are your favorite backup programs written, in whole or in part, in > Python? bup > What do you like about them? resilient and written in python > Dislike about them? lack of a user accessible front-end to monitor and restore > Are there any features you wish your backup program had, whether in > Python or not? I like backuppc because of it's front-end. Emile From steve+comp.lang.python at pearwood.info Wed May 11 09:36:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 13:36:02 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 10:14:38 +0100, Hans Georg Schaathun wrote: > In this case, the interpretation of an arbitrary object as a boolean is > peculiar for python. Incorrect. It is widespread among many languages. Programmers have been writing conditional tests using arbitrary values since 1958 when Lisp introduced the concept. C, Forth and Visual Basic treat any non-zero number as true, and zero as false; that's not quite arbitrary objects, but it's arbitrary integer values. Similarly, Objective C has two different boolean types, "BOOL" which is a C char where 0 is false and everything else is true, and "bool" which is more like the Java boolean type. Perl treats the empty string, "0", 0 and undefined variables as false, and everything else as true. Ruby treats null and false as false, and everything else as true. JavaScript treats "", null, undefined, NaN, 0 and false as false values, and everything else as true. PHP treats FALSE, 0, "", "0", empty arrays, objects with no member variables, NULL, unset variables, and SimpleXML objects created from empty tags as false, everything else as true. Clojure treats nil and false as false, everything else as true. SQL's boolean type has three or four values: true, false, null and unknown, where implementations are free to treat null and unknown as either the same or different values. (So a 3 or 4 value logic, not actually Boolean at all.) So Python is hardly unique, nor is this some new-fangled innovation. > An empty list is a real, existing object, and the > supposition that [] be false is counter-intuitive. Not to me, nor to anyone who has an intuition about "something" versus "nothing". I believe this distinction is fundamental to the universe, and that nearly every person understands this intuitively. The distinction between something and nothing is so strong that it took centuries of argument for the finest minds in Europe[1] to finally decide that, yes, zero is a number -- and they only did it because the Arabs and Indians had proven how useful it was, and Roman numerals really do suck for doing calculations. > It can be learnt, > and the shorthand may be powerful when it is, but it will confuse many > readers. In my experience, it does not confuse newbies or beginners. The only people it confuses are those who are over-educated into thinking that the One Correct Way of doing truth testing is with a dedicated boolean type, and anything else is heresy. [1] At least is you asked them. -- Steven From steve+comp.lang.python at pearwood.info Wed May 11 09:44:17 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 13:44:17 GMT Subject: Py3k,email header handling References: Message-ID: <4dca92b1$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 16:04:13 +0800, TheSaint wrote: > Now python 3.2 (and some version before) started to use byte, rather > than text strings, almost for all data handling in compliance to > unicode. My problem arise that my program handle text strings, so I'd > like to rewrite the code Before you re-write it, you should run 2to3 over it and see how much it can do automatically: http://docs.python.org/library/2to3.html > My program reads from IMAP4 or POP3 server, I'd prefer that a > function/class will return either a list or a dictionary which contains > the following fields: > > 'from', 'to', 'cc', 'bcc', 'date', 'subject', 'reply-to', 'message-id' > > The list may be organized as tuple (from, its_content,), etc,etc for > each field, but I think dictionary would be more efficient to use. > > 1) is there a way to call the IMAPlib or POPlib and pass the data > directly to email.parser.HeaderParser to achieve my intention? I'm afraid I don't understand the question. > 2) If the above will do, do re.compile compile unicode results? I guess > yes. Yes. In Python 3, re.compile("some string") is automatically unicode, because "some string" is unicode. > 3) any related documentation... http://docs.python.org/py3k/library/email.html http://docs.python.org/py3k/library/re.html http://docs.python.org/py3k/library/imaplib.html http://docs.python.org/py3k/library/poplib.html If you have any more concrete questions, please ask. -- Steven From steve+comp.lang.python at pearwood.info Wed May 11 09:45:52 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 13:45:52 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 11:47:42 +0100, Hans Georg Schaathun wrote: > On Sat, 07 May 2011 21:57:13 -0700, Ethan Furman > wrote: > : If you're going to use a language, and use it well, you have to learn > : how that language works. > > And if the world evolves around the compiler and you, that advice > suffices. > > However, programming is often as much about developing ideas in a large > and complex community, where perfect universal mastery of one language > is not an option, because half the community do not normally use that > language or aren't really programmers at all. The less you assume about > the skill of the reader, the better it is. Do you think that we should avoid chained comparisons, class methods, closures, co-routines, decorators, default values to functions, delegation, doc tests, exceptions, factory functions, generator expressions, inheritance, iterators, list comprehensions, operator overloading, properties, regular expressions, tuple unpacking, or unit tests, to say nothing of *advanced* techniques like descriptors or metaclasses, just in case the person reading your code is a clueless n00b? We routinely and uncontroversially use all of these techniques (well, sometimes metaclasses get a few raised eyebrows). Truth testing is MUCH simpler than any of those. It is extremely patronizing to say that we should avoid truth-testing arbitrary objects because it is too complicated for other people. It's not hard, and they can learn. -- Steven From hg at schaathun.net Wed May 11 10:00:17 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 15:00:17 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 13:36:02 GMT, Steven D'Aprano wrote: : > In this case, the interpretation of an arbitrary object as a boolean is : > peculiar for python. : : Incorrect. It is widespread among many languages. Programmers have been : writing conditional tests using arbitrary values since 1958 when Lisp : introduced the concept. The fact that you need to list language by language which objects evaluate as false or equivalent to false illustrates that this has to be learnt language by language. Allowing arbitrary objects is one thing, the particular interpretation is peculiar. The fact that if and while accepts any object for the condition may be chapter 1 stuff, but the memorisation of exactly how the interpretation does not come early (unless you learn it by rote of course). : C, Forth and Visual Basic treat any non-zero number as true, and zero as : false; that's not quite arbitrary objects, but it's arbitrary integer : values. Similarly, Objective C has two different boolean types, "BOOL" : which is a C char where 0 is false and everything else is true, and : "bool" which is more like the Java boolean type. Mentioning C, with no Boolean type at all, in this context is a bit absurd. Understanding boolean evaluation in C is very little help when you want to understand it in python. : > An empty list is a real, existing object, and the : > supposition that [] be false is counter-intuitive. : : Not to me, nor to anyone who has an intuition about "something" versus : "nothing". I believe this distinction is fundamental to the universe, and : that nearly every person understands this intuitively. The distinction : between something and nothing is so strong that it took centuries of : argument for the finest minds in Europe[1] to finally decide that, yes, : zero is a number -- and they only did it because the Arabs and Indians : had proven how useful it was, and Roman numerals really do suck for doing : calculations. Exactly. By now we have gotten past that old-fashioned idea that 0 is not a number. Computer scientists even tend to count 0 as a natural number. When 0 is a number as real and existent as any other, one would think that the empty list is also as real and existent as any other list. : In my experience, it does not confuse newbies or beginners. The only : people it confuses are those who are over-educated into thinking that the : One Correct Way of doing truth testing is with a dedicated boolean type, : and anything else is heresy. What kind of beginners are you talking about? Beginners to python or beginners to programming. The audience I am concerned about is the ones who are over-educated into using and having used a score of different meanings of the same symbols. They will be used to their intuition being wrong when they move into a new context. Being explicit will help them. -- :-- Hans Georg From hg at schaathun.net Wed May 11 10:05:45 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 15:05:45 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 12:14:46 GMT, Steven D'Aprano wrote: : Not knowing that you can write "if x" instead of "if x == []" is like not : knowing that you can write : : elif condition : : instead of : : else: : if condition My concern was with the reader and not the writer. What could elif mean other than else: if? if x could, for instance, mean "if x is defined". -- :-- Hans Georg From darcy at druid.net Wed May 11 10:27:49 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 11 May 2011 10:27:49 -0400 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110511102749.5ff8ef57.darcy@druid.net> On Wed, 11 May 2011 15:05:45 +0100 Hans Georg Schaathun wrote: > What could elif mean other than else: if? If run by an elf? Who knows. You do, of course, if you have learned the basics of the language you are using. > if x could, for instance, mean "if x is defined". It could also mean "if x was created on a Tuesday." A short introduction to the language explains what it actually means. When did we come to the idea that people should be able to program in a language without actually learning it? The fact that Python comes so close to that possibility is nothing short of revolutionary. I suppose one day a reasoning android will be able to sit down at the terminal of a star ship computer and ask simple questions while making random hand movements across a screen but for now I am afraid that programmers still have to learn programming. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Wed May 11 10:33:51 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 11 May 2011 10:33:51 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110511103351.2dd25113.darcy@druid.net> On Wed, 11 May 2011 11:47:42 +0100 Hans Georg Schaathun wrote: > However, programming is often as much about developing ideas in a large > and complex community, where perfect universal mastery of one language > is not an option, because half the community do not normally use that > language or aren't really programmers at all. The less you assume about > the skill of the reader, the better it is. Non-programmers should be able to program? Should non-doctors be able to doctor? Should cars be built so that anyone can intuitively fix them without a mechanic? Should trucks be built so that drivers don't have to learn how to split shift? Why is programming so different that we can't expect people to actually learn their discipline? This discussion is giving me some insight into some of the crap programming I see these days. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From hg at schaathun.net Wed May 11 10:34:28 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 15:34:28 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 13:45:52 GMT, Steven D'Aprano wrote: : Do you think that we should avoid chained comparisons, class methods, : closures, co-routines, decorators, default values to functions, : delegation, doc tests, exceptions, factory functions, generator : expressions, inheritance, iterators, list comprehensions, operator : overloading, properties, regular expressions, tuple unpacking, or unit : tests, to say nothing of *advanced* techniques like descriptors or : metaclasses, just in case the person reading your code is a clueless n00b? Not at all. On both accounts. 1. My concern was not about clueless newbies. They need to learn. My concern is about experienced scientists and engineers who are simply new to python. They will be dealing with a dozen different languages (programming and otherwise), with a need to read more languages than they can possibly learn to master. 2. You should avoid constructs which can /reasonably/ be avoided to /increase/ legibility. Writing if x for if len(x) > 0 when you know that x is of some sort of collection type with len defined does nothing to help legibility. Many of the socalled advanced constructs you mention are used to increase legibility one way or another. Others will simply allow functionality which would otherwise be impossible. I don't object to using if x in a case where x may or may not have len() defined. : We routinely and uncontroversially use all of these techniques (well, : sometimes metaclasses get a few raised eyebrows). Truth testing is MUCH : simpler than any of those. Simpler, yes, but it surely depends on more detailed knowledge. One has to remember how the boolean conversion works, for each possible data type. This requires looking up the rules for each data type. E.g. Anyone who has used list/set comprehension in Z, haskell, set theory, or whereever will understand python list comprehension immediately. : It is extremely patronizing to say that we should avoid truth-testing : arbitrary objects because it is too complicated for other people. It's : not hard, and they can learn. Again you miss the point. It is not /too/ complicated. It is /unnecessarily/ complicated. You don't noticeably gain anything by using if x instead of if len(x) > 0, if you know that the latter is defined. If everyone who ever needs to see your program is a python programmer, then your approach works as well as mine. -- :-- Hans Georg From rosuav at gmail.com Wed May 11 10:46:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 00:46:47 +1000 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 at 12:00 AM, Hans Georg Schaathun wrote: > The fact that you need to list language by language which objects > evaluate as false or equivalent to false illustrates that this has > to be learnt language by language. Allowing arbitrary objects is > one thing, the particular interpretation is peculiar. Languages have to be learned language by language. Yes, you want to be similar to others if you can (and in 'most every language where it's legal syntax, "1+2" will mean "3"), but whenever I'm working in a language with which I'm not _really_ fluent, I like to keep an operator table handy (precedence, plus oddments like what the exponentiation operator is, or whether & is bitwise or boolean). They do differ, and if I'm writing in PHP or Python or Pike or C++ or Java or whatever else it be, I have to use the operators the way the interpreter/compiler will understand them, not in some other way that I "deem better". > Mentioning C, with no Boolean type at all, in this context is a bit > absurd. Understanding boolean evaluation in C is very little help > when you want to understand it in python. Actually, it's not. # Python code: if x: statements /* C code: */ if (x) { statements; } What's the difference? Both of them let you test the truth of some arbitrary object or expression, and neither of those statements implies a Boolean type. In C++, this is exploited extensively with, for instance, the stream I/O objects evaluating as false when in an error or EOF state: while (infile) infile >> *ptr++; // Compact and convenient way to read into an array Actually that one can be combined down even further, but for clarity I leave it like that. Chris Angelico From tacyt1007 at gmail.com Wed May 11 11:16:28 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Wed, 11 May 2011 17:16:28 +0200 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: Is there any special reason you don't want to use QThread? http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details regards 2011/5/11 Chris Angelico : > On Wed, May 11, 2011 at 7:08 PM, vijay swaminathan wrote: >> Sorry. My intention was not to send out a private message. when I chose >> reply to all, I was confused if this would start as a new thread. so just >> did a reply.. > > No probs. If you just send your response to the list > python-list at python.org. it'll get to everyone. > >> I have developed a GUI based on pyQT4 which has a run button. when I click >> on run, it invokes a command prompt and runs a .bat file. >> >> Till the execution of .bat file is over, I want the run button on the GUI to >> be disabled. so i thought of invoking the command prompt and running the >> .bat file on a thread so that I could monitor the status of the thread >> (assuming that the thread would be active till command prompt is active - >> correct me if I'm wrong). > > Yes, but only if you use os.system(). > >> Any flaw? in the logic? any other better ways of achieving this? >> > > You'll find it easier to get an event at the end of it; simply have > another line of code after the os.system() which will reenable the > button. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Wed May 11 11:22:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 01:22:03 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 1:16 AM, Wojtek Mamrak wrote: > Is there any special reason you don't want to use QThread? > http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details Other than that QThread is part of QT and threading isn't, what are the advantages of QThread? Is it possible (safe) to manipulate QT objects - in this case, the button - from a thread other than the one that created them? (If not, that would be a good reason for using QThread, which will fire an event upon termination.) Chris Angelico From redcat at catfolks.net Wed May 11 11:31:01 2011 From: redcat at catfolks.net (Redcat) Date: 11 May 2011 15:31:01 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92vodkFrniU3@mid.individual.net> On Wed, 11 May 2011 10:33:51 -0400, D'Arcy J.M. Cain wrote: > Non-programmers should be able to program? Wasn't that sort of the premise behind Visual Basic? I don't know if that was the intention, but it sure was the result in a lot of cases. From steve+comp.lang.python at pearwood.info Wed May 11 11:50:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 15:50:45 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dcab055$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 15:05:45 +0100, Hans Georg Schaathun wrote: > My concern was with the reader and not the writer. > > What could elif mean other than else: if? It could mean "Oh, the author has made a stupid typo, I better fix it." It could mean "What does the elif command do?" The first time I read Python code, I had literally no idea what to make of elif. It seemed so obvious to me that any language would let you write "else if ..." (on a single line) that I just assumed that elif must be some other construct, and I had no idea what it was. It never even crossed my mind that it could be "else if" rammed together into one word. I soon learned better though. Once you start dumbing down your code for readers who don't know your language, it's a race to the bottom. There's very little you can write that *somebody* won't misunderstand. > if x could, for instance, mean "if x is defined". Yes it could, if you're programming in Perl. But we're not. When I write a sentence in English, and I use the word "gift" to mean a thing which is given, I don't worry that German or Swedish readers will think I'm talking about poison. If I use "preservative", I mean something which preserves, and if Italian and Spanish readers mistake it for a condom, that's their problem, not mine. Writing code is no different. When I'm coding in Python, I use Python rules and meanings, not some other language. Why should I code according to what some hypothetical Python dummy *might* think the code will do, instead of what the code *actually* does? -- Steven From ethan at stoneleaf.us Wed May 11 11:53:24 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 May 2011 08:53:24 -0700 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCAB0F4.7040106@stoneleaf.us> Hans Georg Schaathun wrote: > On 11 May 2011 13:36:02 GMT, Steven D'Aprano > wrote: > : > In this case, the interpretation of an arbitrary object as a boolean is > : > peculiar for python. > : > : Incorrect. It is widespread among many languages. Programmers have been > : writing conditional tests using arbitrary values since 1958 when Lisp > : introduced the concept. > > The fact that you need to list language by language which objects > evaluate as false or equivalent to false illustrates that this has > to be learnt language by language. Allowing arbitrary objects is > one thing, the particular interpretation is peculiar. Like so many other things Python got right, I think it got this right as well. "something" vs "nothing" is simple, useful, and easy to remember. > By now we have gotten past that old-fashioned idea that 0 > is not a number. Computer scientists even tend to count 0 as a > natural number. When 0 is a number as real and existent as any other, > one would think that the empty list is also as real and existent as > any other list. Python is not concerned with whether it exists -- that's a name binding; Python is concerned with whether anything is there. 0 apples is nothing and a an empty list is nothing as well. ~Ethan~ From tacyt1007 at gmail.com Wed May 11 11:55:19 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Wed, 11 May 2011 17:55:19 +0200 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: 2011/5/11 Chris Angelico : > On Thu, May 12, 2011 at 1:16 AM, Wojtek Mamrak wrote: >> Is there any special reason you don't want to use QThread? >> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details > > Other than that QThread is part of QT and threading isn't, what are > the advantages of QThread? Is it possible (safe) to manipulate QT > objects - in this case, the button - from a thread other than the one > that created them? (If not, that would be a good reason for using > QThread, which will fire an event upon termination.) > QThread provides mechanism of signals and slots ("from" and "to" the thread), which are used across all pyQt. Unfortunately it is not possible to use any widget classes in the thread (direct quote from the docs). On the other hand signals can fire methods from the main thread (running the app'a main loop), so this is not a big deal. The signals are: - finished - started - terminated It is possible to block the thread, make it sleep, check whether the thread is running, and few others. From rosuav at gmail.com Wed May 11 12:05:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 02:05:21 +1000 Subject: checking if a list is empty In-Reply-To: <4dcab055$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab055$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 at 1:50 AM, Steven D'Aprano wrote: > On Wed, 11 May 2011 15:05:45 +0100, Hans Georg Schaathun wrote: > >> My concern was with the reader and not the writer. >> >> What could elif mean other than else: if? > > The first time I read Python code, I had literally no idea what to make > of elif. It seemed so obvious to me that any language would let you write > "else if ..." (on a single line) that I just assumed that elif must be > some other construct, and I had no idea what it was. It never even > crossed my mind that it could be "else if" rammed together into one word. In a Bourne shell script, if ends with fi... case ends with esac... so file would end with... hmm. Yeah, I think it's best to know the language you're trying to comprehend, and/or actually look at context instead of shoving a piece of code under someone's nose and saying "I bet you can't figure out what THIS does!". Chris Angelico From steve+comp.lang.python at pearwood.info Wed May 11 12:26:40 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 16:26:40 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 15:34:28 +0100, Hans Georg Schaathun wrote: > On 11 May 2011 13:45:52 GMT, Steven D'Aprano > wrote: > : Do you think that we should avoid chained comparisons, class methods, > : closures, co-routines, decorators, default values to functions, : > delegation, doc tests, exceptions, factory functions, generator : > expressions, inheritance, iterators, list comprehensions, operator : > overloading, properties, regular expressions, tuple unpacking, or unit : > tests, to say nothing of *advanced* techniques like descriptors or : > metaclasses, just in case the person reading your code is a clueless > n00b? > > Not at all. On both accounts. > 1. My concern was not about clueless newbies. They need to > learn. My concern is about experienced scientists and engineers who > are simply new to python. Which makes them clueless newbies *about Python*. I don't care how experienced they are in astrophysics or biology or calculating the average airspeed of an unladen swallow. > They will be dealing with a dozen different > languages (programming and otherwise), with a need to read more > languages than they can possibly learn to master. Yeah, life is hard and then you die, and scientists don't even get paid that much. So what? Do physicists write their scientific papers about string theory with the thought "What if some Python programmer who knows nothing about string theory is reading this? I better dumb it down." Of course not. A ridiculous idea. They use their tools the way they are designed to be used, and outsiders have to learn the language and the jargon to make sense of it. This is not a problem that needs solving. It's one thing to simplify code that you are explicitly using as a teaching aid. That's a good thing, I approve of that. But it's a completely different thing to dumb down production code because you think some non-programmer might have to read it. > 2. You should avoid constructs which can /reasonably/ be avoided to > /increase/ legibility. Writing if x for if len(x) > 0 when you know > that x is of some sort of collection type with len defined does > nothing to help legibility. Of course it does. It means you don't have to care about implementation details of what emptiness means for a list. It means you don't force the reader to read, parse and understand three extraneous terms. It means you don't force the reader to wonder why you bothered to use a long-winded test when a short test would do, or be concerned that maybe > 0 is a typo and you actually meant > 10. [...] > Simpler, yes, but it surely depends on more detailed knowledge. One has > to remember how the boolean conversion works, for each possible data > type. This requires looking up the rules for each data type. No. You have that exactly backwards. The point of "if x" is that you DON'T have to care about how the boolean conversion works, because the object itself encapsulates that behaviour. This is basic object-oriented principles. When you call len(x) you don't care about the details of how to calculate the length of x. The object itself knows so that you don't have to. The same applies to truth testing. I have a data type that is an array of lists. When you call "if len(x) > 0" on it, it will blow up in your face, because len(x) returns a list of lengths like [12, 0, 2, 5]. But if you say "if x", it will do the right thing. You don't need to care how to truth-test my data type, because it does it for you. By ignoring my type's interface, and insisting on doing the truth-test by hand, you shoot yourself in the foot. > E.g. Anyone who has used list/set comprehension in Z, haskell, set > theory, or whereever will understand python list comprehension > immediately. Yes. And anyone who hasn't, probably won't. But they will learn. -- Steven From nobody at nowhere.net.no Wed May 11 12:27:22 2011 From: nobody at nowhere.net.no (TheSaint) Date: Thu, 12 May 2011 00:27:22 +0800 Subject: Py3k,email header handling References: <4dca92b1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Before you re-write it, you should run 2to3 over it and see how much it > can do automatically: Widely done, only the results from some query has radically changed on favour of unicode. Errors raising about results which are not strings anymore. > I'm afraid I don't understand the question. Making an example : from poplib import POP3 as pop3 pop3.user('userid') pop3.pass_('password') numMsg, total = pop3.stat() for cnt in numMsgs: header = pop3.top(cnt) # here I'd like to pass the header to some function that will return # a dictionary filling # from', 'to', 'cc', 'bcc', 'date', 'subject', 'reply-to', 'message-id' # keys, if nothing the leave empty string or None dict = email.header,decode_header(header) # but might not my result # Should I subclass this? The same would be from the IMAP4 message parsing. Some different process would take, would it ? > If you have any more concrete questions, please ask. If these aren't concrete questions, forgive me, I perhaps got into wrong news group. In the other and I hugely apreciated your clues. I'll see the docs some more long to achieve a clear learning. -- goto /dev/null From genstein at invalid.invalid Wed May 11 12:27:32 2011 From: genstein at invalid.invalid (Genstein) Date: Wed, 11 May 2011 17:27:32 +0100 Subject: py3k buffered IO - flush() required between read/write? Message-ID: Hey all, Apologies if this is a dumb question (self = Python noob), but under py3k is it necessary to flush() a file between read/write calls in order to see consistent results? I ask because I have a case under Python 3.2 (r32:88445) where it does appear to be, on both Gentoo Linux and Windows Vista. I've naturally read http://docs.python.org/py3k/library/io.html and http://docs.python.org/py3k/tutorial/inputoutput.html#reading-and-writing-files but could find no reference to such a requirement. PEP 3116 suggested this might not be required in py3k and the implementation notes in bufferedio.c state "BufferedReader, BufferedWriter and BufferedRandom...share a single buffer...this enables interleaved reads and writes without flushing." Which seemed conclusive but I'm seeing otherwise. I have a test case, which is sadly rather long: http://pastebin.com/xqrzKr5D It's lengthy because it's autogenerated from some rather more complex code I'm working on, in order to reproduce the issue in isolation. Any advice and/or flames appreciated. All the best, -eg. From ian.g.kelly at gmail.com Wed May 11 12:31:59 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 11 May 2011 10:31:59 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 11, 2011 at 8:34 AM, Hans Georg Schaathun wrote: > E.g. Anyone who has used list/set comprehension in Z, haskell, set theory, > or whereever will understand python list comprehension immediately. They would understand the underlying concept. But would somebody who is not a Python programmer intuitively understand the difference between this: [x + 3 for x in xs if x % 2 == 1] and this: {x + 3 for x in xs if x % 2 == 1} and this: (x + 3 for x in xs if x % 2 == 1) Somebody with rudimentary Python knowledge might even reason that since the first two create a list and a set respectively, the third must therefore create a tuple, which is wrong. None of this should be taken as an argument against using generator expressions. From ericsnowcurrently at gmail.com Wed May 11 13:22:06 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 11 May 2011 11:22:06 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: All of this just boils down to Python providing an implicit bool cast in syntactic situations that expect conditional expressions, including if [1]. So "if x:" is equivalent to "if bool(x)". Perhaps that is the part that is not immediately obvious, being implicit to Python conditional syntax. Python also provides a mechanism for customization of a wide variety of behavior that is not obvious without reading the [excellent] documentation [2]. So the following three forms will implicitly call the special method names: if x: => if bool(x): => if x.__bool__(): [3] if x == []: => if x.__eq__([]): if len(x) == 0: => if x.__len__() == 0: Other than the implicit cast to bool for conditional syntax and the implicit calls to special method names as appropriate I am not clear that there is any remaining mystery for this question. And the language reference makes all of the above very clear, so I highly recommend it. The only caveat is that builtin types don't always act the same way as user defined types (classes). Not sure if the few differences are well documented, but to be honest that hasn't bit me hard enough that I needed to look it up. I do know that the builtin list has a __eq__ method and a __len__ method, but not a __bool__ method (which it doesn't need [3]). -eric [1] http://docs.python.org/dev/py3k/reference/compound_stmts.html#the-if-statement [2] http://docs.python.org/dev/py3k/reference/datamodel.html#special-method-names [3] http://docs.python.org/dev/py3k/reference/datamodel.html#object.__bool__ so if __bool__ doesn't exist it tries __len__ and so forth. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Wed May 11 13:29:50 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 11 May 2011 12:29:50 -0500 Subject: Proper way to handle errors in a module Message-ID: <4DCAC78E.1000901@gmail.com> I'm a bit new to programming outside of shell scripts (and I'm no expert there), so I was wondering what is considered the best way to handle errors when writing a module. Do I just let exceptions go and raise custom exceptions for errors that don't trigger a standard one? Have the function/method return nothing or a default value and show an error message? I'm sure there's not a clear-cut answer, but I was just wondering what most developers would expect a module to do in certain situations. From ramit.prasad at jpmchase.com Wed May 11 13:39:44 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Wed, 11 May 2011 13:39:44 -0400 Subject: checking if a list is empty In-Reply-To: <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA3B33534@EMARC112VS01.exchad.jpmchase.net> > I don't mean to insult anyone, but I've heard and read all the arguments against Python's truth-testing, and they >don't impress me in the slightest. Most of them strike me as silly. The only argument that carries any weight to me is >one which I haven't seen anyone raise: >"if x:" turns something which arguably could have been a mistake ("oops, I forgot to write the condition!") into valid >code. The only problem I have had with the "if x:" notation is when I have values that might be empty lists, empty strings, None, or a boolean value being returned from the same source. But this is probably an instance when a good programmer would explicitly check the type instead of the naive "if x:" notation. On the other hand, as a fairly n00b Python (and n00b Perl) developer, I find the notation "if not x:" to be far more English readable than "if x==None or len(x)== 0 or x==0 or bool(x):" (or some derivative/combination of those). Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From hg at schaathun.net Wed May 11 13:44:34 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 18:44:34 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2huq98-2v6.ln1@svn.schaathun.net> On Wed, 11 May 2011 10:33:51 -0400, D'Arcy J.M. Cain wrote: : Non-programmers should be able to program? That was not really what I suggested; I was primarily talking about reading programs and commenting on formul? and algorithms. : Should non-doctors be able to doctor? If I were God, I might consider simplifying the anatomy to allow that, yes. : Should cars be built so that : anyone can intuitively fix them without a mechanic? Should trucks be : built so that drivers don't have to learn how to split shift? That's out of my area so I don't know. However, contrary to software, I have never seen any use of rebuilding the car to do something other than transport ... And, besides, as mechanics do not design cars or even engines, they are not analogous to programmers, but rather to computer technicians (maintenance, deployment, installation, etc). : Why is : programming so different that we can't expect people to actually learn : their discipline? It is not different from other engineering disciplines, where you would have to interact with experts from other disciplines, and understand and comment on their designs. That's the way to build a /system/. Say, you want to create the software to make weather forcasts. At the end of the day, that's programming, but no way that's going to be a task for programmers alone. You need mathematicians, algorithm theorists, physicists, programmers, and multiple specialisations within each discipline. If you can make your programs clear enough to be used as a language of communications, you will simplify the development, and allow the code to be validated by those who knows how the computation has to be done without specialising in talking to the computer. : This discussion is giving me some insight into some of the crap : programming I see these days. I wonder if you would do a better job at programming the software to crack equations from quantum physics than the physicist :-) -- :-- Hans Georg From hg at schaathun.net Wed May 11 13:46:01 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 18:46:01 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 May 2011 10:31:59 -0600, Ian Kelly wrote: : (x + 3 for x in xs if x % 2 == 1) Interesting. Thanks. That might come in handy some time. -- :-- Hans Georg From ramit.prasad at jpmchase.com Wed May 11 13:50:54 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Wed, 11 May 2011 13:50:54 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA3B33589@EMARC112VS01.exchad.jpmchase.net> >The audience I am concerned about is the ones who are over-educated >into using and having used a score of different meanings of the same >symbols. They will be used to their intuition being wrong when they >move into a new context. Being explicit will help them. I find this argument to be flawed. Should I stop using built-in generators instead of range/xrange for looping through lists? Certainly for loops with loop counting are understood more widely than generators. Should I stop using any advanced feature Python because it is difficult to understand without knowing Python? I do not code for absolute beginner in Python to read my code. That way lies madness! I code with the assumption that someone with intermediate knowledge can read my code (unless I am forced into optimizing and then I rely on comments to explain). Actually, that is how I attempt to code in any language. I may not have made the point well, but I cannot see any advantage for trying to program for the lowest common denominator. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From hg at schaathun.net Wed May 11 13:56:00 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 18:56:00 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab055$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 12 May 2011 02:05:21 +1000, Chris Angelico wrote: : In a Bourne shell script, if ends with fi... case ends with esac... so : file would end with... hmm. Yeah, I think it's best to know the : language you're trying to comprehend, and/or actually look at context : instead of shoving a piece of code under someone's nose and saying "I : bet you can't figure out what THIS does!". Code is quite often published to document algorithms, methods and formul? for the purpose of scientific research. Since there is no universal language which suits everything and everyone, this is exactly what happens. One has to have the rudimentary knowledge to read half a dozen different languages to be able to read the code and extract the algorithms. If one tried to maintain the necessary programming skills to exploit all of those languages to their full potential, one would simply not be able to keep up with the application discipline. If all you do is to write software for computer illiterate users, YMWV. -- :-- Hans Georg From tjreedy at udel.edu Wed May 11 13:56:16 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 May 2011 13:56:16 -0400 Subject: Py3k,email header handling In-Reply-To: References: <4dca92b1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/11/2011 12:27 PM, TheSaint wrote: > Steven D'Aprano wrote: > >> Before you re-write it, you should run 2to3 over it and see how much it >> can do automatically: > > Widely done, only the results from some query has radically changed on > favour of unicode. Errors raising about results which are not strings > anymore. Make sure you use 3.2 and not 3.1 (or 3.0) as there were improvements to the email module. -- Terry Jan Reedy From patty at cruzio.com Wed May 11 13:57:49 2011 From: patty at cruzio.com (Patty) Date: Wed, 11 May 2011 10:57:49 -0700 Subject: Proper way to handle errors in a module References: <4DCAC78E.1000901@gmail.com> Message-ID: <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> ----- Original Message ----- From: "Andrew Berg" To: Sent: Wednesday, May 11, 2011 10:29 AM Subject: Proper way to handle errors in a module > I'm a bit new to programming outside of shell scripts (and I'm no expert > there), so I was wondering what is considered the best way to handle > errors when writing a module. Do I just let exceptions go and raise > custom exceptions for errors that don't trigger a standard one? Have the > function/method return nothing or a default value and show an error > message? I'm sure there's not a clear-cut answer, but I was just > wondering what most developers would expect a module to do in certain > situations. > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi Andrew - Sometimes you want an exception come up and then use that information to take your program in some direction. For example, you might want your program to 'see' the exception that comes up when you go one beyond the end of an array. This means that something you wanted to happen within the array you set up finished successfully (the program just reached one beyond it and you didn't get an error!). The enduser doesn't need to see this displayed on the screen or in a window, you can just use an exception as-is to your advantage within the program. Regards, Patty From hg at schaathun.net Wed May 11 13:59:58 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 18:59:58 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 May 2011 10:27:49 -0400, D'Arcy J.M. Cain wrote: : When did we come to the idea that people should be able to program in a : language without actually learning it? The fact that Python comes so : close to that possibility is nothing short of revolutionary. Revolutionary indeed, so why don't we exploit the revolution and write the programs to be as accessible as possible? (Although, python is not the most revolutionary in this respect.) -- :-- Hans Georg From roy at panix.com Wed May 11 14:05:09 2011 From: roy at panix.com (Roy Smith) Date: Wed, 11 May 2011 14:05:09 -0400 Subject: Proper way to handle errors in a module References: Message-ID: In article , Andrew Berg wrote: > I'm a bit new to programming outside of shell scripts (and I'm no expert > there), so I was wondering what is considered the best way to handle > errors when writing a module. Do I just let exceptions go and raise > custom exceptions for errors that don't trigger a standard one? Have the > function/method return nothing or a default value and show an error > message? I'm sure there's not a clear-cut answer, but I was just > wondering what most developers would expect a module to do in certain > situations. In general, raise an exception when there is no valid value that can be returned from a function. Sometimes it makes more sense to return 0, None, an empty list, etc. So: count_vowels("banana") ==> 3 count_vowels("xyzzy") ==> 0 # counting "y" as not a vowel count_vowels("") ==> 0 count_vowels(None) ==> raises TypeError You want to raise specific errors. Let's say you've got a function like this: def airspeed(swallow): speeds = {"european": 42, "african", 196} return speeds[swallow] If somebody passes an invalid string, it will raise KeyError as written. Better to do something like: def airspeed(swallow): speeds = {"european": 42, "african", 196} try: return speeds[swallow] except KeyError: raise UnknownBirdError(swallow) This lets somebody catch UnknownBirdError at some higher level and do something useful. If you let KeyError escape, that's a lot harder to deal with because it could come from almost anywhere. From hg at schaathun.net Wed May 11 14:05:31 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 19:05:31 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 16:26:40 GMT, Steven D'Aprano wrote: : > 1. My concern was not about clueless newbies. They need to : > learn. My concern is about experienced scientists and engineers who : > are simply new to python. : : Which makes them clueless newbies *about Python*. I don't care how : experienced they are in astrophysics or biology or calculating the : average airspeed of an unladen swallow. Someone who knows how to program is never clueless starting a new language. Newbie, may be, but he knows most of the constructions and semantic principles to look for; most of it is learning the syntax. : Yeah, life is hard and then you die, and scientists don't even get paid : that much. So what? Do physicists write their scientific papers about : string theory with the thought "What if some Python programmer who knows : nothing about string theory is reading this? I better dumb it down." That depends on the purpose of that particular paper, but the real question is, who writes the software to test that string theory empirically? Please tell. -- :-- Hans Georg From python at mrabarnett.plus.com Wed May 11 14:08:57 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 11 May 2011 19:08:57 +0100 Subject: Proper way to handle errors in a module In-Reply-To: <4DCAC78E.1000901@gmail.com> References: <4DCAC78E.1000901@gmail.com> Message-ID: <4DCAD0B9.7030406@mrabarnett.plus.com> On 11/05/2011 18:29, Andrew Berg wrote: > I'm a bit new to programming outside of shell scripts (and I'm no expert > there), so I was wondering what is considered the best way to handle > errors when writing a module. Do I just let exceptions go and raise > custom exceptions for errors that don't trigger a standard one? Have the > function/method return nothing or a default value and show an error > message? I'm sure there's not a clear-cut answer, but I was just > wondering what most developers would expect a module to do in certain > situations. Generally speaking, a function or method should either do what it's expected to do, returning the expected result, or raise an exception if it can't. Also, it's often clearer to distinguish between a function, which returns a result, and a procedure, which doesn't (in Python it would return None). For example, if you have a list, the functional form is: sorted(my_list) which returns a new sorted list, and the procedural form is: my_list.sort() which sorts in-place (modifying the list) and returns None. From bahamutzero8825 at gmail.com Wed May 11 14:14:39 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 11 May 2011 13:14:39 -0500 Subject: Proper way to handle errors in a module In-Reply-To: <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> References: <4DCAC78E.1000901@gmail.com> <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> Message-ID: <4DCAD20F.4010206@gmail.com> On 2011.05.11 12:57 PM, Patty wrote: > Hi Andrew - > > Sometimes you want an exception come up and then use that information to > take your > program in some direction. Right, but I'm wondering how I should handle errors in a module, where different people will want their programs to do different things when an error occurs in a function or method from my module (which is not necessarily because of a bug in my module - the calling script could send a bad parameter or some system configuration could prevent the function from doing something). On one hand, I could let almost all exceptions go unhandled and have the calling script handle them. This would force the developer of the calling script to learn all the exceptions that my module could raise (which could be really annoying if I have custom exceptions for problems that don't otherwise raise an exception). OTOH, I could handle all the exceptions and return None or some default value, but that would make it harder for the developer to make the script react appropriately. From hg at schaathun.net Wed May 11 14:15:59 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 19:15:59 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 May 2011 13:50:54 -0400, Prasad, Ramit wrote: : I find this argument to be flawed. Should I stop using built-in : generators instead of range/xrange for looping through lists? : Certainly for loops with loop counting are understood more widely : than generators. Should I stop using any advanced feature Python : because it is difficult to understand without knowing Python? No; I'd suggest the most legible and intuitive construct that /does/ the job. Never something which requires one extra (illegible) page to do the job, or something which does not do the job at all. : I may not have made the point well, but I cannot see any advantage : for trying to program for the lowest common denominator. Common to what? I'd try the lowest common denominator of legibility and effictiveness. It is just KISS. -- :-- Hans Georg From tjreedy at udel.edu Wed May 11 14:24:57 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 May 2011 14:24:57 -0400 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 5/11/2011 12:27 PM, Genstein wrote: > In py3k is it necessary to flush() a file between read/write calls in order > to see consistent results? > > I ask because I have a case under Python 3.2 (r32:88445) where it does > appear to be, on both Gentoo Linux and Windows Vista. > > I've naturally read http://docs.python.org/py3k/library/io.html and > http://docs.python.org/py3k/tutorial/inputoutput.html#reading-and-writing-files > but could find no reference to such a requirement. > > PEP 3116 suggested this might not be required in py3k and the > implementation notes in bufferedio.c state "BufferedReader, > BufferedWriter and BufferedRandom...share a single buffer...this enables > interleaved reads and writes without flushing." Which seemed conclusive > but I'm seeing otherwise. > > I have a test case, which is sadly rather long: > http://pastebin.com/xqrzKr5D It's lengthy because it's autogenerated > from some rather more complex code I'm working on, in order to reproduce > the issue in isolation. I notice that you have required seek calls when switching between writing and reading. If you want others to look at this more, you should 1) produce a minimal* example that demonstrates the questionable behavior, and 2) show the comparative outputs that raise your question. The code is way too long to cut and paste into an editor and see what is does on my windows machine. *minimal = local minimum rather than global minimum. That means that removal or condensation of a line or lines removes the problem. In this case, remove extra seeks, unless doing so removes behavior discrepancy. Condense 1 byte writes to multibyte writes, unless ... . Are repeated interleavings required or is write, seek, read, seek, write enough? -- Terry Jan Reedy From tartley at tartley.com Wed May 11 14:34:32 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 11 May 2011 19:34:32 +0100 Subject: lightweight way to create new projects from templates Message-ID: <4DCAD6B8.3070003@tartley.com> Hi. I'm looking for a quick way to create new Python projects from a template. I understand that 'Paste' (http://pythonpaste.org/) is one way to do this, but I find Paste very intimidating because of all the functionality it includes. I'm not even sure whether 'creating new projects from templates' is the central goal of Paste, or just an incidental benefit that it provides while performing some other task. As a lightweight alternative, I'm creating a project called 'Genesis'. Functionally, it will be little more than a 'cp -r' followed by a few search and replace operations. I realise this idea is modest, but I think it could be helpful for: a) people who are just getting started with Python, and want to see how best to structure their projects, and b) people who are already up-to-speed, and who want to create their own templates and spawn projects from them with a minimum of effort. c) for the community, to exemplify and publicise best practices for new projects. My goals include: * Create a new project using the default template: $ genesis myproj * or using a particular project template: $ genesis --template=mytemplate myproj * Allow people to create their own templates, simply stored as directories under '~/.genesis' * Files in a template contain 'tags' of the form 'G{author}'. When a new project is created, these tags are replaced. For example, G{author} will be replaced with the value for 'author' supplied either on the command-line: $ genesis myproj author=Jonathan Or in your ~/.genesis/config file (a python file read using 'exec'): author = 'Jonathan' * The default template should embody good practices like those demonstrated in the Python Project howto: http://infinitemonkeycorps.net/docs/pph/ * The default template should include a setup.py, supporting sdist, register and upload commands. * I'd also like the default template to include things like creating Windows binaries, so that it is easier for projects to include this out of the box. It would be nice to extend this to binaries for other platforms too. * The default template for command-line applications should include an acceptance test, which invokes the script in a new process and makes assertions about stdout, stderr and exit value. * One of my inspirations is to create a good template for events like pyweek, where many people set out to write opengl or pyglet applications from scratch, and yet every time, many entrants fail to properly create binaries, etc. Genesis is only partially written, so is not yet on PyPI, but is on bitbucket: https://bitbucket.org/tartley/genesis/overview If you have any feedback, it would be very welcome. In particular: What do you think about the approach in general? What do you think about the contents of my default template: https://bitbucket.org/tartley/genesis/src/tip/genesis/config/default/ Do you think a single default template containing all the above ideas is viable? Or is it likely to be so idiosyncratic that I might be better shipping with several built-in templates, including a 'minimal' one? Do I need different templates for applications than for libraries? For console apps vs GUI apps? What do you think of my choice of 'G{name}' for replaceable tags in the template? I wanted something that would not be valid Python, and would be unlikely to occur naturally in a project. Best regards, Jonathan -- Jonathan Hartley tartley at tartley.com http://tartley.com Made of meat. +44 7737 062 225 twitter/skype: tartley From ramit.prasad at jpmchase.com Wed May 11 14:44:37 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Wed, 11 May 2011 14:44:37 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA3B33714@EMARC112VS01.exchad.jpmchase.net> > Someone who knows how to program is never clueless starting a new >language. Newbie, may be, but he knows most of the constructions >and semantic principles to look for; most of it is learning the syntax. I claim to be able to program (Java/Python), but would be absolutely lost programming in Lisp. It is more than just "learning the syntax", it includes a thought paradigm as well. Just like I claim to be able to do math, but severely suck at RPN math. (Okay, that analogy is bad but it is all I can come up with at the moment.) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -----Original Message----- From: python-list-bounces+ramit.prasad=jpmchase.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com at python.org] On Behalf Of Hans Georg Schaathun Sent: Wednesday, May 11, 2011 1:06 PM To: python-list at python.org Subject: Re: checking if a list is empty On 11 May 2011 16:26:40 GMT, Steven D'Aprano wrote: : > 1. My concern was not about clueless newbies. They need to : > learn. My concern is about experienced scientists and engineers who : > are simply new to python. : : Which makes them clueless newbies *about Python*. I don't care how : experienced they are in astrophysics or biology or calculating the : average airspeed of an unladen swallow. : Yeah, life is hard and then you die, and scientists don't even get paid : that much. So what? Do physicists write their scientific papers about : string theory with the thought "What if some Python programmer who knows : nothing about string theory is reading this? I better dumb it down." That depends on the purpose of that particular paper, but the real question is, who writes the software to test that string theory empirically? Please tell. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From ramit.prasad at jpmchase.com Wed May 11 14:50:00 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Wed, 11 May 2011 14:50:00 -0400 Subject: Proper way to handle errors in a module In-Reply-To: <4DCAD20F.4010206@gmail.com> References: <4DCAC78E.1000901@gmail.com> <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> <4DCAD20F.4010206@gmail.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA3B3373E@EMARC112VS01.exchad.jpmchase.net> The simple but code heavy system is to create two functions. One that raises an error and one that returns None or something that is mutually agreed to be invalid. You can even get away with one of them doing the actual work and the other one just as a wrapper. I feel too lazy to fix the mistakes below, but you get the idea. Def a(): Blahblah Raise SomeError Def b(): Try: A() Except SomeError: Return blah Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -----Original Message----- From: python-list-bounces+ramit.prasad=jpmchase.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com at python.org] On Behalf Of Andrew Berg Sent: Wednesday, May 11, 2011 1:15 PM To: python-list at python.org Subject: Re: Proper way to handle errors in a module On 2011.05.11 12:57 PM, Patty wrote: > Hi Andrew - > > Sometimes you want an exception come up and then use that information to > take your > program in some direction. Right, but I'm wondering how I should handle errors in a module, where different people will want their programs to do different things when an error occurs in a function or method from my module (which is not necessarily because of a bug in my module - the calling script could send a bad parameter or some system configuration could prevent the function from doing something). On one hand, I could let almost all exceptions go unhandled and have the calling script handle them. This would force the developer of the calling script to learn all the exceptions that my module could raise (which could be really annoying if I have custom exceptions for problems that don't otherwise raise an exception). OTOH, I could handle all the exceptions and return None or some default value, but that would make it harder for the developer to make the script react appropriately. -- http://mail.python.org/mailman/listinfo/python-list This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From ramit.prasad at jpmchase.com Wed May 11 14:59:34 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Wed, 11 May 2011 14:59:34 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA3B33787@EMARC112VS01.exchad.jpmchase.net> >Common to what? I'd try the lowest common denominator of >legibility and effictiveness. >It is just KISS. Fair enough. I am a sheep, so I do what other (more knowledgeable) people do. It is a fair assumption (for my specific code writing environments) that everyone who is going to read my code understands "if x:" notation or is expected to learn enough Python to understand it. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -----Original Message----- From: python-list-bounces+ramit.prasad=jpmchase.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com at python.org] On Behalf Of Hans Georg Schaathun Sent: Wednesday, May 11, 2011 1:16 PM To: python-list at python.org Subject: Re: checking if a list is empty On Wed, 11 May 2011 13:50:54 -0400, Prasad, Ramit wrote: : I find this argument to be flawed. Should I stop using built-in : generators instead of range/xrange for looping through lists? : Certainly for loops with loop counting are understood more widely : than generators. Should I stop using any advanced feature Python : because it is difficult to understand without knowing Python? No; I'd suggest the most legible and intuitive construct that /does/ the job. Never something which requires one extra (illegible) page to do the job, or something which does not do the job at all. : I may not have made the point well, but I cannot see any advantage : for trying to program for the lowest common denominator. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From nospam at torek.net Wed May 11 15:05:03 2011 From: nospam at torek.net (Chris Torek) Date: 11 May 2011 19:05:03 GMT Subject: checking if a list is empty References: <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4dcab8bf$0$29980$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: >When you call len(x) you don't care about the details of how to calculate >the length of x. The object itself knows so that you don't have to. The >same applies to truth testing. > >I have a data type that is an array of lists. When you call "if len(x) > >0" on it, it will blow up in your face, because len(x) returns a list of >lengths like [12, 0, 2, 5]. But if you say "if x", it will do the right >thing. You don't need to care how to truth-test my data type, because it >does it for you. By ignoring my type's interface, and insisting on doing >the truth-test by hand, you shoot yourself in the foot. What this really points out is that "if x" and "if len(x) > 0" are *different tests*. Consider xml.etree.ElementTree "Element" objects. The documentation says, in part: In ElementTree 1.2 and earlier, the sequence behavior means that an element without any subelements tests as false (since it's an empty sequence), even if it contains text and attributions. ... Note: This behavior is likely to change somewhat in ElementTree 1.3. To write code that is compatible in both directions, use ... "len(element)" to test for non-empty elements. In this case, when x is an Element, the result of bool(x) *could* mean just "x has sub-elements", but it could also/instead mean "x has sub-elements, text, or attributions". The issue raised at the beginning of this thread was: which test is "better" when x is a list, the test that invokes bool(x), or the test that invokes len(x)? There is no answer to that, any more than there is to which ice cream flavor is "best". [%] A more interesting question to ask, in any given bit of code, is whether bool(x) or len(x) is more appropriate for *all* the types x might take at that point, rather than whether one or the other is better for lists, where the result is defined as equivalent. (The biggest problem with answering that tends to be deciding what types x might take.) [% Chocolate with raspberry, or mint, or similar.] -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From genstein at invalid.invalid Wed May 11 15:08:08 2011 From: genstein at invalid.invalid (Genstein) Date: Wed, 11 May 2011 20:08:08 +0100 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 11/05/2011 19:24, Terry Reedy wrote: > writing and reading. If you want others to look at this more, you should > 1) produce a minimal* example that demonstrates the questionable > behavior, and 2) show the comparative outputs that raise your question. Thanks for a quick response. Perhaps I was being unclear - in py3k, given the following code and assuming no errors arise: > f = open("foo", "w+b") > f.write(b'test') > f.seek(0) > print(f.read(4)) What is the printed result supposed to be? i) b'test' ii) never b'test' iii) platform dependent/undefined/other All the best, -eg. From hg at schaathun.net Wed May 11 15:08:19 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 20:08:19 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3e3r98-k67.ln1@svn.schaathun.net> On Wed, 11 May 2011 14:59:34 -0400, Prasad, Ramit wrote: : Fair enough. I am a sheep, so I do what other (more knowledgeable) : people do. It is a fair assumption (for my specific code writing : environments) that everyone who is going to read my code understands : "if x:" notation or is expected to learn enough Python to understand it. That's fair enough. You know your code, so it is probably true. It would not be true for the code I am writing. -- :-- Hans Georg From hg at schaathun.net Wed May 11 15:13:35 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 20:13:35 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 May 2011 12:17:33 -0700, Ethan Furman wrote: : 'if li' *is* KISS. It /might/ be in some contexts, but a priori it is not, as it superimposes a truth value on a data type which is otherwise a pretty accurate model of real objects (outside python). One principle of object oriented programming is to bestow the objects with properties reflecting known properties from the domain being modelled. Lists do not have truth values in the application domain, and therefore truth values in the implementation domain is complicated. -- :-- Hans Georg From ethan at stoneleaf.us Wed May 11 15:17:33 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 May 2011 12:17:33 -0700 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCAE0CD.1040406@stoneleaf.us> Hans Georg Schaathun wrote: > On Wed, 11 May 2011 13:50:54 -0400, Prasad, Ramit > wrote: > : I find this argument to be flawed. Should I stop using built-in > : generators instead of range/xrange for looping through lists? > : Certainly for loops with loop counting are understood more widely > : than generators. Should I stop using any advanced feature Python > : because it is difficult to understand without knowing Python? > > No; I'd suggest the most legible and intuitive construct that /does/ the > job. Never something which requires one extra (illegible) page to do > the job, or something which does not do the job at all. > > : I may not have made the point well, but I cannot see any advantage > : for trying to program for the lowest common denominator. > > Common to what? I'd try the lowest common denominator of > legibility and effictiveness. > > It is just KISS. 'if li' *is* KISS. ~Ethan~ From hg at schaathun.net Wed May 11 15:26:48 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 20:26:48 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 May 2011 14:44:37 -0400, Prasad, Ramit wrote: : > Someone who knows how to program is never clueless starting a new : >language. Newbie, may be, but he knows most of the constructions : >and semantic principles to look for; most of it is learning the syntax. : : I claim to be able to program (Java/Python), but would be absolutely : lost programming in Lisp. It is more than just "learning the syntax", : it includes a thought paradigm as well. OK. I should written 'how to program imperatively' ... 'new imperative language'. Or substitute functional/logical/whatever for imperative. You would not be completely clueless moving to ada/fortran/C/pascal/simula. There may be new concepts, and some concepts which must be adapted to another level of abstraction, but you do have a clue about the core concepts. -- :-- Hans Georg From rodrick.brown at gmail.com Wed May 11 16:54:16 2011 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 11 May 2011 16:54:16 -0400 Subject: How to deal with optional argument evaluation Message-ID: I'm having a hard time dealing with the following scenario My class takes a hash like the following: rdargs = {'env:'prod','feed':'opra','hostname':'host13dkp1','process':'delta','side':'a','zone','ny'} All the keys in this hash can be optional. I'm having a hard time dealing with all 36 possible combinations and I dont want to use a monstorous if not and else or etc... to evaluate all possible combinations before I call my search routine. How do others deal with situations like this? And have it look readable? if someone supplies just a host and side my search can return 400 responses, if they supply all 6 elements it can return just 1-5 matches. class RD(object): def __init__(self,**kwargs): self.value = 0 #for field in ('env', 'side', 'zone', 'feed', 'hostname', 'process', 'status'): #val = kwargs[field] if kwargs.has_key(field) else False #setattr(self, field, val) self.env = kwargs.get('env',False) self.side = kwargs.get('side',False) self.zone = kwargs.get('zone',False) self.feed = kwargs.get('feed',False) self.hostname = kwargs.get('hostname',False) self.process = kwargs.get('process',False) self.status = kwargs.get('status',False) -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown -------------- next part -------------- An HTML attachment was scrubbed... URL: From hobson42 at gmail.com Wed May 11 17:02:19 2011 From: hobson42 at gmail.com (Ian) Date: Wed, 11 May 2011 22:02:19 +0100 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCAF95B.60307@gmail.com> On 11/05/2011 20:13, Hans Georg Schaathun wrote: > On Wed, 11 May 2011 12:17:33 -0700, Ethan Furman > wrote: > : 'if li' *is* KISS. > > It /might/ be in some contexts, but a priori it is not, as it > superimposes a truth value on a data type which is otherwise > a pretty accurate model of real objects (outside python). > > One principle of object oriented programming is to bestow the > objects with properties reflecting known properties from the > domain being modelled. Lists do not have truth values in the > application domain, and therefore truth values in the > implementation domain is complicated. > Exactly. Its just a convention. If it exists, its true, if if doesn't its false. In the "real world" lists of zero items do not exist. You don't go shopping with a shopping list of zero items. You don't take a journey going nowhere. You wouldn't have a party and invite nobody. What kind of building is one with zero floors? Would you have an Aircraft Carrier with no aircraft? Oh Wait - the UK has one of those coming into service soon. Regards Ian From harrismh777 at charter.net Wed May 11 17:13:03 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 16:13:03 -0500 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab055$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hans Georg Schaathun wrote: > Code is quite often published to document algorithms, methods and > formul? for the purpose of scientific research. Since there is no > universal language which suits everything and everyone, this > is exactly what happens. One has to have the rudimentary knowledge > to read half a dozen different languages to be able to read the > code and extract the algorithms. +1 QOTW From harrismh777 at charter.net Wed May 11 17:24:47 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 16:24:47 -0500 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: D'Arcy J.M. Cain wrote: > Non-programmers should be able to program? > > Should non-doctors be able to doctor? Should cars be built so that > anyone can intuitively fix them without a mechanic? Non-programmers should not be expected to program in 'C' nor in lisp... ... but non-programmers were able to program in BASIC jes fine... I contend that non-programmers are able to learn rudimentary python and work with it to solve real problems 'without' formal training in 'programming'. Python is the New BASIC for 'people'. At least, it has the potential to be that... people should be able to talk to their computers (whatever we mean by that) and have the computer respond with real-world solutions. We need to move away from 'canned apps' to a new day where the masses can sit down to their computer and solve new problems with it through intuitive language skills. Why not? From ethan at stoneleaf.us Wed May 11 17:26:02 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 May 2011 14:26:02 -0700 Subject: How to deal with optional argument evaluation In-Reply-To: References: Message-ID: <4DCAFEEA.8040102@stoneleaf.us> Rodrick Brown wrote: > I'm having a hard time dealing with the following scenario > > My class takes a hash like the following: > rdargs = > {'env:'prod','feed':'opra','hostname':'host13dkp1','process':'delta','side':'a','zone','ny'} > > All the keys in this hash can be optional. > > I'm having a hard time dealing with all 36 possible combinations and I > dont want to use a monstorous if not and else or etc... to evaluate all > possible combinations before I call my search routine. > > How do others deal with situations like this? And have it look readable? > > if someone supplies just a host and side my search can return 400 > responses, if they supply all 6 elements it can return just 1-5 matches. > > class RD(object): > def __init__(self,**kwargs): > self.value = 0 > #for field in ('env', 'side', 'zone', 'feed', 'hostname', > 'process', 'status'): > #val = kwargs[field] if kwargs.has_key(field) else False > #setattr(self, field, val) > self.env = kwargs.get('env',False) > self.side = kwargs.get('side',False) > self.zone = kwargs.get('zone',False) > self.feed = kwargs.get('feed',False) > self.hostname = kwargs.get('hostname',False) > self.process = kwargs.get('process',False) > self.status = kwargs.get('status',False) class RD(object): def __init__( self, env=False, side=False, zone=False, feed=False, hostname=False, process=False, status=False ): self.env = env self.side = side self.zone = zone self.feed = feed self.hostname = hostname self.process = process self.status = status What does the code look like that actually uses this information? ~Ethan~ From harrismh777 at charter.net Wed May 11 17:37:49 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 16:37:49 -0500 Subject: unicode by default Message-ID: hi folks, I am puzzled by unicode generally, and within the context of python specifically. For one thing, what do we mean that unicode is used in python 3.x by default. (I know what default means, I mean, what changed?) I think part of my problem is that I'm spoiled (American, ascii heritage) and have been either stuck in ascii knowingly, or UTF-8 without knowing (just because the code points lined up). I am confused by the implications for using 3.x, because I am reading that there are significant things to be aware of... what? On my installation 2.6 sys.maxunicode comes up with 1114111, and my 2.7 and 3.2 installs come up with 65535 each. So, I am assuming that 2.6 was compiled with UCS-4 (UTF-32) option for 4 byte unicode(?) and that the default compile option for 2.7 & 3.2 (I didn't change anything) is set for UCS-2 (UTF-16) or 2 byte unicode(?). Do I understand this much correctly? The books say that the .py sources are UTF-8 by default... and that 3.x is either UCS-2 or UCS-4. If I use the file handling capabilities of Python in 3.x (by default) what encoding will be used, and how will that affect the output? If I do not specify any code points above ascii 0xFF does any of this matter anyway? Thanks. kind regards, m harris From tjreedy at udel.edu Wed May 11 17:38:26 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 May 2011 17:38:26 -0400 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 5/11/2011 3:08 PM, Genstein wrote: > On 11/05/2011 19:24, Terry Reedy wrote: >> writing and reading. If you want others to look at this more, you should >> 1) produce a minimal* example that demonstrates the questionable >> behavior, and 2) show the comparative outputs that raise your question. > > Thanks for a quick response. Perhaps I was being unclear - in py3k, > given the following code and assuming no errors arise: > > > f = open("foo", "w+b") > > f.write(b'test') > > f.seek(0) > > print(f.read(4)) > > What is the printed result supposed to be? > > i) b'test' > ii) never b'test' > iii) platform dependent/undefined/other Good clear question. I expect i). With 3.2 on winxp, that is what I get with StringIO, text file, and bytes file (the first two with b's removed). I would expect the same on any system. If you get anything different, I would consider it a bug -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed May 11 17:42:10 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 21:42:10 GMT Subject: checking if a list is empty References: <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dcb02b1$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 19:05:03 +0000, Chris Torek wrote: > In article <4dcab8bf$0$29980$c3e8da3$5496439d at news.astraweb.com> Steven > D'Aprano wrote: >>When you call len(x) you don't care about the details of how to >>calculate the length of x. The object itself knows so that you don't >>have to. The same applies to truth testing. >> >>I have a data type that is an array of lists. When you call "if len(x) > >>0" on it, it will blow up in your face, because len(x) returns a list of >>lengths like [12, 0, 2, 5]. But if you say "if x", it will do the right >>thing. You don't need to care how to truth-test my data type, because it >>does it for you. By ignoring my type's interface, and insisting on doing >>the truth-test by hand, you shoot yourself in the foot. > > What this really points out is that "if x" and "if len(x) > 0" are > *different tests*. *Potentially* different tests. Which is exactly the point. Given an arbitrary object, the developer doesn't know what test is appropriate. Should I write len(x) == 0 or list(x) == [] or x.next is None or something else? How can I tell which is appropriate without knowing everything about the internals of every object I ever see? But if x is a non-broken object, then you don't have to. Just test on x itself, because it knows what to do to be considered a truth value. Of course there may be objects where this doesn't work. There are no guarantees in Python. You can't even guarantee that printing an object won't blow up: >>> class Broken: ... def __str__(self): ... return "... %s ..." % 1/2 ... __repr__ = __str__ ... >>> b = Broken() >>> b Traceback (most recent call last): File "", line 1, in File "", line 3, in __str__ TypeError: unsupported operand type(s) for /: 'str' and 'int' > Consider xml.etree.ElementTree "Element" objects. > The documentation says, in part: > > In ElementTree 1.2 and earlier, the sequence behavior means that an > element without any subelements tests as false (since it's an empty > sequence), even if it contains text and attributions. ... > > Note: This behavior is likely to change somewhat in ElementTree 1.3. > To write code that is compatible in both directions, use ... > "len(element)" to test for non-empty elements. > > In this case, when x is an Element, the result of bool(x) *could* mean > just "x has sub-elements", but it could also/instead mean "x has > sub-elements, text, or attributions". Either behaviour is correct, but a semantic change to the class means that you have to do more work if you care about supporting both versions in the same code base. That is a neat example of where you might choose *not* to let an object decide for itself whether it is true or false, but instead impose your own definition on it. -- Steven From steve+comp.lang.python at pearwood.info Wed May 11 17:47:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 21:47:27 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: > One principle of object oriented programming is to bestow the objects > with properties reflecting known properties from the domain being > modelled. Lists do not have truth values in the application domain Yes they do. Empty lists are nothing, ergo false, and non-empty lists are something, ergo true. -- Steven From hansmu at xs4all.nl Wed May 11 18:06:57 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 12 May 2011 00:06:57 +0200 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> Message-ID: <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> On 03/05/2011 09:52, rusi wrote: > [If you believe it is, then try writing a log(n) fib iteratively :D ] It took me a while, but this one seems to work: from collections import namedtuple Triple = namedtuple('Triple', 'hi mid lo') Triple.__mul__ = lambda self, other: Triple( self.hi * other.hi + self.mid * other.mid, self.hi * other.mid + self.mid * other.lo, self.mid * other.mid + self.lo * other.lo, ) def fib(n): f = Triple(1, 1, 0) a = Triple(1, 0, 1) while n: if n & 1: a *= f f *= f n >>= 1 return a.mid -- HansM From ian.g.kelly at gmail.com Wed May 11 18:09:29 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 11 May 2011 16:09:29 -0600 Subject: unicode by default In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 3:37 PM, harrismh777 wrote: > hi folks, > ? I am puzzled by unicode generally, and within the context of python > specifically. For one thing, what do we mean that unicode is used in python > 3.x by default. (I know what default means, I mean, what changed?) The `unicode' class was renamed to `str', and a stripped-down version of the 2.X `str' class was renamed to `bytes'. > ? I think part of my problem is that I'm spoiled (American, ascii heritage) > and have been either stuck in ascii knowingly, or UTF-8 without knowing > (just because the code points lined up). I am confused by the implications > for using 3.x, because I am reading that there are significant things to be > aware of... what? Mainly Python 3 no longer does explicit conversion between bytes and unicode, requiring the programmer to be explicit about such conversions. If you have Python 2 code that is sloppy about this, you may get some Unicode encode/decode errors when trying to run the same code in Python 3. The 2to3 tool can help somewhat with this, but it can't prevent all problems. > ? On my installation 2.6 ?sys.maxunicode comes up with 1114111, and my 2.7 > and 3.2 installs come up with 65535 each. So, I am assuming that 2.6 was > compiled with UCS-4 (UTF-32) option for 4 byte unicode(?) and that the > default compile option for 2.7 & 3.2 (I didn't change anything) is set for > UCS-2 (UTF-16) or 2 byte unicode(?). ? Do I understand this much correctly? I think that UCS-2 has always been the default unicode width for CPython, although the exact representation used internally is an implementation detail. > ? The books say that the .py sources are UTF-8 by default... and that 3.x is > either UCS-2 or UCS-4. ?If I use the file handling capabilities of Python in > 3.x (by default) what encoding will be used, and how will that affect the > output? If you open a file in binary mode, the result is a non-decoded byte stream. If you open a file in text mode and do not specify an encoding, then the result of locale.getpreferredencoding() is used for decoding, and the result is a unicode stream. > ? If I do not specify any code points above ascii 0xFF does any of this > matter anyway? You mean 0x7F, and probably, due to the need to explicitly encode and decode. From howe.steven at gmail.com Wed May 11 18:09:51 2011 From: howe.steven at gmail.com (Steven Howe) Date: Wed, 11 May 2011 15:09:51 -0700 Subject: checking if a list is empty In-Reply-To: <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCB092F.5020202@gmail.com> On 05/11/2011 02:47 PM, Steven D'Aprano wrote: > On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: > >> One principle of object oriented programming is to bestow the objects >> with properties reflecting known properties from the domain being >> modelled. Lists do not have truth values in the application domain > Yes they do. Empty lists are nothing, ergo false, and non-empty lists are > something, ergo true. > > > >>> a=[] > >>> if a: > ... print 'Yes' > ... > >>> a=[1] > >>> if a: > ... print 'Yes' > ... > Yes Cool; I'd never of thought to try that method to determine if a list was empty. I usually test it's length. This looks faster. From benjamin.kaplan at case.edu Wed May 11 18:34:02 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 May 2011 15:34:02 -0700 Subject: unicode by default In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 2:37 PM, harrismh777 wrote: > hi folks, > ? I am puzzled by unicode generally, and within the context of python > specifically. For one thing, what do we mean that unicode is used in python > 3.x by default. (I know what default means, I mean, what changed?) > > ? I think part of my problem is that I'm spoiled (American, ascii heritage) > and have been either stuck in ascii knowingly, or UTF-8 without knowing > (just because the code points lined up). I am confused by the implications > for using 3.x, because I am reading that there are significant things to be > aware of... what? > > ? On my installation 2.6 ?sys.maxunicode comes up with 1114111, and my 2.7 > and 3.2 installs come up with 65535 each. So, I am assuming that 2.6 was > compiled with UCS-4 (UTF-32) option for 4 byte unicode(?) and that the > default compile option for 2.7 & 3.2 (I didn't change anything) is set for > UCS-2 (UTF-16) or 2 byte unicode(?). ? Do I understand this much correctly? > Not really sure about that, but it doesn't matter anyway. Because even though internally the string is stored as either a UCS-2 or a UCS-4 string, you never see that. You just see this string as a sequence of characters. If you want to turn it into a sequence of bytes, you have to use an encoding. > ? The books say that the .py sources are UTF-8 by default... and that 3.x is > either UCS-2 or UCS-4. ?If I use the file handling capabilities of Python in > 3.x (by default) what encoding will be used, and how will that affect the > output? > > ? If I do not specify any code points above ascii 0xFF does any of this > matter anyway? ASCII only goes up to 0x7F. If you were using UTF-8 bytestrings, then there is a difference for anything over that range. A byte string is a sequence of bytes. A unicode string is a sequence of these mythical abstractions called characters. So a unicode string u'\u00a0' will have a length of 1. Encode that to UTF-8 and you'll find it has a length of 2 (because UTF-8 uses 2 bytes to encode everything over 128- the top bit is used to signal that you need the next byte for this character) If you want the history behind the whole encoding mess, Joel Spolsky wrote a rather amusing article explaining how this all came about: http://www.joelonsoftware.com/articles/Unicode.html And the biggest reason to use Unicode is so that you don't have to worry about your program messing up because someone hands you input in a different encoding than you used. From harrismh777 at charter.net Wed May 11 18:38:58 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 17:38:58 -0500 Subject: checking if a list is empty In-Reply-To: <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6eEyp.199$BS4.197@newsfe01.iad> Steven D'Aprano wrote: >> modelled. Lists do not have truth values in the application domain > Yes they do. Empty lists are nothing, ergo false, and non-empty lists are > something, ergo true. > No they don't. Empty lists are empty lists... which just happen to become False when type cast bool(list[])--> False. lists cannot have a truth... binary False or True... however, when cast with bool(list) they can be used in a test (even with 'not') to make some decision. Lists by themselves, empty or not, cannot have a 'truth' in an of themselves. kind regards, m harris From greg.ewing at canterbury.ac.nz Wed May 11 18:50:23 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 12 May 2011 10:50:23 +1200 Subject: Merge multiple source directories into one package with distutils? In-Reply-To: <4228410e-4631-47be-936c-041122f27ffb@glegroupsg2000goo.googlegroups.com> References: <4228410e-4631-47be-936c-041122f27ffb@glegroupsg2000goo.googlegroups.com> Message-ID: <930i5iFas9U1@mid.individual.net> Miki Tebeka wrote: > .py files from more than one source directory into a single > package when installing? > The Selenium Python bindings does something like that, have a look at http://selenium.googlecode.com/svn/trunk/setup.py Unless I'm missing something, nothing out of the ordinary is happening there. Each destination directory is getting .py files from just one source directory. I'm not talking about a package with multiple submodules, I know how to do that. I'm talking about putting .py files from more than one source directory into the same intallation directory. E.g. Source: stuff/__init__.py stuff/dir1/foo.py stuff/dir2/blarg.py Installation: stuff/__init__.py stuff/foo.py stuff/blarg.py -- Greg From harrismh777 at charter.net Wed May 11 18:51:07 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 17:51:07 -0500 Subject: unicode by default In-Reply-To: References: Message-ID: Ian Kelly wrote: Ian, Benjamin, thanks much. > The `unicode' class was renamed to `str', and a stripped-down version > of the 2.X `str' class was renamed to `bytes'. ... thank you, this is very helpful. >> > If I do not specify any code points above ascii 0xFF does any of this >> > matter anyway? > You mean 0x7F, and probably, due to the need to explicitly encode and decode. Yes, actually, I did... and from Benjamin's reply it seems that this matters only if I am working with bytes. Is it true that if I am working without using bytes sequences that I will not need to care about the encoding anyway, unless of course I need to specify a unicode code point? Thanks again. kind regards, m harris From greg.ewing at canterbury.ac.nz Wed May 11 19:08:04 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 12 May 2011 11:08:04 +1200 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <930j6nFi2lU1@mid.individual.net> Hans Georg Schaathun wrote: > 0 is a number as real and existent as any other, > one would think that the empty list is also as real and existent as > any other list. 0 does have some special properties, though, such as being the additive identity and not having a multiplicative inverse. Adding falseness as another special property isn't too much of a stretch and turns out to be useful. Likewise, it's useful to treat empty containers as having a similar special property, since they're often a base or terminating case in algorithms. It's especially useful in a dynamic language where any additional operations such as finding the length or comparing with zero has a run-time cost. Yes, you have to learn it, but it's a small thing to learn with a considerable payoff. -- Greg From harrismh777 at charter.net Wed May 11 19:12:13 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 18:12:13 -0500 Subject: checking if a list is empty In-Reply-To: <6eEyp.199$BS4.197@newsfe01.iad> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> <6eEyp.199$BS4.197@newsfe01.iad> Message-ID: harrismh777 wrote: > Lists by themselves, empty or not, cannot have a 'truth' in an of > themselves. ... forgot., Based on Ian's comment a couple of days ago... if alist: ... is actually : if bool(alist): I think this is more than just semantics or silly argumentation. Its important to understand where the boolean truth is coming from... my understanding 'now' is that the list[] has no such boolean attribute, but is cast for the 'if' construct.... so... if alist: is --> if bool(alist): and... if not alist: is also --> if not bool(alist): The 'alist[]' has no boolean attribute, right?? kind regards, m harris From martin.hellwig at gmail.com Wed May 11 19:24:46 2011 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Wed, 11 May 2011 23:24:46 +0000 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 11/05/2011 19:08, Genstein wrote: > On 11/05/2011 19:24, Terry Reedy wrote: >> writing and reading. If you want others to look at this more, you should >> 1) produce a minimal* example that demonstrates the questionable >> behavior, and 2) show the comparative outputs that raise your question. > > Thanks for a quick response. Perhaps I was being unclear - in py3k, > given the following code and assuming no errors arise: > > > f = open("foo", "w+b") > > f.write(b'test') > > f.seek(0) > > print(f.read(4)) > > What is the printed result supposed to be? > > i) b'test' > ii) never b'test' > iii) platform dependent/undefined/other > > All the best, > > -eg. from: http://docs.python.org/py3k/library/functions.html#open """ open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True)? buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows: * Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device?s ?block size? and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long. * ?Interactive? text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files. """ So given that explanation, and assuming I understand it, I go for option 'iii'. -- mph From sjmachin at lexicon.net Wed May 11 19:32:06 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 09:32:06 +1000 Subject: unicode by default In-Reply-To: References: Message-ID: On Thu, May 12, 2011 8:51 am, harrismh777 wrote: > Is it true that if I am > working without using bytes sequences that I will not need to care about > the encoding anyway, unless of course I need to specify a unicode code > point? Quite the contrary. (1) You cannot work without using bytes sequences. Files are byte sequences. Web communication is in bytes. You need to (know / assume / be able to extract / guess) the input encoding. You need to encode your output using an encoding that is expected by the consumer (or use an output method that will do it for you). (2) You don't need to use bytes to specify a Unicode code point. Just use an escape sequence e.g. "\u0404" is a Cyrillic character. From michiel at thingmajig.org Wed May 11 20:20:13 2011 From: michiel at thingmajig.org (Michiel Sikma) Date: Thu, 12 May 2011 02:20:13 +0200 Subject: urllib2 request with binary file as payload Message-ID: Hi there, I made a small script implementing a part of Youtube's API that allows you to upload videos. It's pretty straightforward and uses urllib2. The script was written for Python 2.6, but the server I'm going to use it on only has 2.5 (and I can't update it right now, unfortunately). It seems that one vital thing doesn't work in 2.5's urllib2: -- data = open(video['filename'], 'rb') opener = urllib2.build_opener(urllib2.HTTPHandler) req = urllib2.Request(settings['upload_location'], data, { 'Host': 'uploads.gdata.youtube.com', 'Content-Type': video['type'], 'Content-Length': '%d' % os.path.getsize(video['filename']) }) req.get_method = lambda: 'PUT' url = opener.open(req) -- This works just fine on 2.6: send: sendIng a read()able However, on 2.5 it refuses: Traceback (most recent call last): File "./pyup", line 119, in main() File "./pyup", line 116, in main url = opener.open(req) File "/usr/lib/python2.5/urllib2.py", line 381, in open response = self._open(req, data) File "/usr/lib/python2.5/urllib2.py", line 399, in _open '_open', req) File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 1107, in http_open return self.do_open(httplib.HTTPConnection, req) File "/usr/lib/python2.5/urllib2.py", line 1079, in do_open h.request(req.get_method(), req.get_selector(), req.data, headers) File "/usr/lib/python2.5/httplib.py", line 866, in request self._send_request(method, url, body, headers) File "/usr/lib/python2.5/httplib.py", line 892, in _send_request self.send(body) File "/usr/lib/python2.5/httplib.py", line 711, in send self.sock.sendall(str) File "", line 1, in sendall TypeError: sendall() argument 1 must be string or read-only buffer, not file Is there any other way I can do this? I'm pretty new to Python so I'm not sure how to proceed at this point. Thanks! Michiel Sikma We Demand HTML http://wedemandhtml.com/ michiel at wedemandhtml.com From jpiee at aim.com Wed May 11 20:52:26 2011 From: jpiee at aim.com (jpiee at aim.com) Date: Wed, 11 May 2011 20:52:26 -0400 (EDT) Subject: pymultimouse access violation error Message-ID: <8CDDE55FF32795F-A04-FD35@angweb-usd005.sysops.aol.com> A couple of years back Oscar Lindberg wrote a program called pymultimouse, which has a homepage at http://code.google.com/p/pymultimouse/. I've been using the file rawinputreader.py, which is avaliable in the zipped folder in the downloads section of the above link. I'm trying to get raw mouse input in a program I'm working on, and I've been trying to use pymultimouse . I'm trying to run the code he's got, but it uses ctypes, and when I try to run I'm getting this error: Traceback (most recent call last): File "C:\Users\jmite\rawinputreader.py", line 324, in pprint.pprint(rir.pollEvents()) File "C:\Users\jmite\rawinputreader.py", line 210, in pollEvents windll.user32.DispatchMessageA(pMsg) WindowsError: exception: access violation writing 0x00000001 Does anybody have ideas as to how the code could be patched to possibly fix this? There's only been one release of it, and other people seem to be able to run it just fine, so is it possibly something machine specific? I'm new to python, let alone ctypes and win32 modules, so any help would be tremendously wonderful at this point. Thanks! Jmite -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Wed May 11 20:57:31 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 10:57:31 +1000 Subject: urllib2 request with binary file as payload In-Reply-To: References: Message-ID: <2fa89ca32d0796866e0fe4121371b882.squirrel@webmail.lexicon.net> On Thu, May 12, 2011 10:20 am, Michiel Sikma wrote: > Hi there, > I made a small script implementing a part of Youtube's API that allows > you to upload videos. It's pretty straightforward and uses urllib2. > The script was written for Python 2.6, but the server I'm going to use > it on only has 2.5 (and I can't update it right now, unfortunately). > It seems that one vital thing doesn't work in 2.5's urllib2: > > -- > > data = open(video['filename'], 'rb') > > opener = urllib2.build_opener(urllib2.HTTPHandler) > req = urllib2.Request(settings['upload_location'], data, { > 'Host': 'uploads.gdata.youtube.com', > 'Content-Type': video['type'], > 'Content-Length': '%d' % os.path.getsize(video['filename']) > }) > req.get_method = lambda: 'PUT' > url = opener.open(req) > > -- > > This works just fine on 2.6: > send: > sendIng a read()able > > However, on 2.5 it refuses: > Traceback (most recent call last): [snip] > TypeError: sendall() argument 1 must be string or read-only buffer, not > file I don't use this stuff, just curious. But I can read docs. Quoting from the 2.6.6 docs: """ class urllib2.Request(url[, data][, headers][, origin_req_host][, unverifiable]) This class is an abstraction of a URL request. url should be a string containing a valid URL. data may be a string specifying additional data to send to the server, or None if no such data is needed. Currently HTTP requests are the only ones that use data; the HTTP request will be a POST instead of a GET when the data parameter is provided. data should be a buffer in the standard application/x-www-form-urlencoded format. The urllib.urlencode() function takes a mapping or sequence of 2-tuples and returns a string in this format. """ 2.6 is expecting a string, according to the above. No mention of file. Moreover it expects the data to be urlencoded. 2.7.1 docs say the same thing. Are you sure you have shown the code that worked with 2.6? From steve+comp.lang.python at pearwood.info Wed May 11 21:07:05 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 May 2011 01:07:05 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> <6eEyp.199$BS4.197@newsfe01.iad> Message-ID: <4dcb32b9$0$29973$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 17:38:58 -0500, harrismh777 wrote: > Steven D'Aprano wrote: >>> modelled. Lists do not have truth values in the application domain >> Yes they do. Empty lists are nothing, ergo false, and non-empty lists >> are something, ergo true. >> >> > No they don't. Empty lists are empty lists... which just happen to > become False when type cast bool(list[])--> False. > > lists cannot have a truth... binary False or True... however, when cast > with bool(list) they can be used in a test (even with 'not') to make > some decision. Have you been not paying any attention at all? >>> alist = [] >>> if alist: pass ... else: print "alist is a false value" ... alist is a false value >>> >>> if type(alist) is bool: pass ... else: print "but not a bool" ... but not a bool > Lists by themselves, empty or not, cannot have a 'truth' in an of > themselves. Despite your confident tone, they really do. Just like EVERY OTHER OBJECT IN PYTHON. And Perl, and Ruby, and Javascript, and PHP, and many other languages. You might not like that fact, but it is a fact. -- Steven From harrismh777 at charter.net Wed May 11 21:22:50 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 20:22:50 -0500 Subject: unicode by default In-Reply-To: References: Message-ID: John Machin wrote: > (1) You cannot work without using bytes sequences. Files are byte > sequences. Web communication is in bytes. You need to (know / assume / be > able to extract / guess) the input encoding. You need to encode your > output using an encoding that is expected by the consumer (or use an > output method that will do it for you). > > (2) You don't need to use bytes to specify a Unicode code point. Just use > an escape sequence e.g. "\u0404" is a Cyrillic character. > Thanks John. In reverse order, I understand point (2). I'm less clear on point (1). If I generate a string of characters that I presume to be ascii/utf-8 (no \u0404 type characters) and write them to a file (stdout) how does default encoding affect that file.by default..? I'm not seeing that there is anything unusual going on... If I open the file with vi? If I open the file with gedit? emacs? .... Another question... in mail I'm receiving many small blocks that look like sprites with four small hex codes, scattered about the mail... mostly punctuation, maybe? ... guessing, are these unicode code points, and if so what is the best way to 'guess' the encoding? ... is it coded in the stream somewhere...protocol? thanks From python at mrabarnett.plus.com Wed May 11 22:31:18 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 May 2011 03:31:18 +0100 Subject: unicode by default In-Reply-To: References: Message-ID: <4DCB4676.9070904@mrabarnett.plus.com> On 12/05/2011 02:22, harrismh777 wrote: > John Machin wrote: >> (1) You cannot work without using bytes sequences. Files are byte >> sequences. Web communication is in bytes. You need to (know / assume / be >> able to extract / guess) the input encoding. You need to encode your >> output using an encoding that is expected by the consumer (or use an >> output method that will do it for you). >> >> (2) You don't need to use bytes to specify a Unicode code point. Just use >> an escape sequence e.g. "\u0404" is a Cyrillic character. >> > > Thanks John. In reverse order, I understand point (2). I'm less clear on > point (1). > > If I generate a string of characters that I presume to be ascii/utf-8 > (no \u0404 type characters) and write them to a file (stdout) how does > default encoding affect that file.by default..? I'm not seeing that > there is anything unusual going on... If I open the file with vi? If I > open the file with gedit? emacs? > > .... > > Another question... in mail I'm receiving many small blocks that look > like sprites with four small hex codes, scattered about the mail... > mostly punctuation, maybe? ... guessing, are these unicode code points, > and if so what is the best way to 'guess' the encoding? ... is it coded > in the stream somewhere...protocol? > You need to understand the difference between characters and bytes. A string contains characters, a file contains bytes. The encoding specifies how a character is represented as bytes. For example: In the Latin-1 encoding, the character "?" is represented by the byte 0xA3. In the UTF-8 encoding, the character "?" is represented by the byte sequence 0xC2 0xA3. In the ASCII encoding, the character "?" can't be represented at all. The advantage of UTF-8 is that it can represent _all_ Unicode characters (codepoints, actually) as byte sequences, and all those in the ASCII range are represented by the same single bytes which the original ASCII system used. Use the UTF-8 encoding unless you have to use a different one. A file contains only bytes, a socket handles only bytes. Which encoding you should use for characters is down to protocol. A system such as email, which can handle different encodings, should have a way of specifying the encoding, and perhaps also a default encoding. From wuwei23 at gmail.com Wed May 11 23:16:01 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 11 May 2011 20:16:01 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hans Georg Schaathun wrote: > Revolutionary indeed, so why don't we exploit the revolution > and write the programs to be as accessible as possible? Where do you draw the line, though? No decorators, as they're not intuitively obvious? No custom descriptors, as that requires a deeper knowledge of Python internals that utter ignorance allows? Both of those aspects alone seem far more complex and advanced than treating empty collections as False. From steve+comp.lang.python at pearwood.info Wed May 11 23:16:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 May 2011 03:16:09 GMT Subject: unicode by default References: Message-ID: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 May 2011 03:31:18 +0100, MRAB wrote: >> Another question... in mail I'm receiving many small blocks that look >> like sprites with four small hex codes, scattered about the mail... >> mostly punctuation, maybe? ... guessing, are these unicode code points, >> and if so what is the best way to 'guess' the encoding? ... is it coded >> in the stream somewhere...protocol? >> > You need to understand the difference between characters and bytes. http://www.joelonsoftware.com/articles/Unicode.html is also a good resource. -- Steven From wuwei23 at gmail.com Wed May 11 23:31:45 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 11 May 2011 20:31:45 -0700 (PDT) Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> On May 12, 7:24?am, harrismh777 wrote: >?We need to move away from 'canned apps' to a new day where > the masses can sit down to their computer and solve new problems with it > through intuitive language skills. ?Why not? Because the vast majority of them don't seem to want to be bothered? From tlikonen at iki.fi Wed May 11 23:37:50 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Thu, 12 May 2011 06:37:50 +0300 Subject: Learning new languages (was: checking if a list is empty) References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vcxgoagh.fsf_-_@mithlond.arda> * 2011-05-11T20:26:48+01:00 * Hans Georg Schaathun wrote: > On Wed, 11 May 2011 14:44:37 -0400, Prasad, Ramit > wrote: >> I claim to be able to program (Java/Python), but would be absolutely >> lost programming in Lisp. It is more than just "learning the syntax", >> it includes a thought paradigm as well. > > OK. I should written 'how to program imperatively' ... 'new imperative > language'. Or substitute functional/logical/whatever for imperative. Common Lisp is an imperative language. It is also functional and object-oriented language. It does not force any paradigm but supports many. Thus, it is called a multi-paradigm language. I understand that Lisp can be scary, though. Lisp code looks weird and it seems that the myth that it's a functional language can't be busted. Anyway, I agree with this: * 2011-05-11T19:05:31+01:00 * Hans Georg Schaathun wrote: > Someone who knows how to program is never clueless starting a new > language. Newbie, may be, but he knows most of the constructions > and semantic principles to look for; most of it is learning the > syntax. From harrismh777 at charter.net Wed May 11 23:44:23 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 22:44:23 -0500 Subject: unicode by default In-Reply-To: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> You need to understand the difference between characters and bytes. > > http://www.joelonsoftware.com/articles/Unicode.html > > is also a good resource. Thanks for being patient guys, here's what I've done: >>>> astr="pound sign" >>>> asym=" \u00A3" >>>> afile=open("myfile", mode='w') >>>> afile.write(astr + asym) > 12 >>>> afile.close() When I edit "myfile" with vi I see the 'characters' : pound sign ? ... same with emacs, same with gedit ... When I hexdump myfile I see this: 0000000 6f70 6375 2064 6973 6e67 c220 00a3 This is *not* what I expected... well it is (little-endian) right up to the 'c2' and that is what is confusing me.... I did not open the file with an encoding of UTF-8... so I'm assuming UTF-16 by default (python3) so I was expecting a '00A3' little-endian as 'A300' but what I got instead was UTF-8 little-endian 'c2a3' .... See my problem?... when I open the file with emacs I see the character pound sign... same with gedit... they're all using UTF-8 by default. By default it looks like Python3 is writing output with UTF-8 as default... and I thought that by default Python3 was using either UTF-16 or UTF-32. So, I'm confused here... also, I used the character sequence \u00A3 which I thought was UTF-16... but Python3 changed my intent to 'c2a3' which is the normal UTF-8... Thanks again for your patience... I really do hate to be dense about this... but this is another area where I'm just beginning to dabble and I'd like to know soon what I'm doing... Thanks for the link Steve... I'm headed there now... kind regards, m harris From nospam at torek.net Wed May 11 23:49:05 2011 From: nospam at torek.net (Chris Torek) Date: 12 May 2011 03:49:05 GMT Subject: checking if a list is empty References: <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4dc6a39a$0$29991$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: >In English, [the word "not"] negates a word or statement: > >"the cat is not on the mat" --> "the cat is on the mat" is false. As a mostly off topic aside, English is considerably more complicated than that. There are people who use the word "not" as a purely boolean operator (a la computer languages), so that "the cat is not not on the mat" means "the cat IS on the mat", but others use double negation as a form of intensifier, so that the phrase with multiple "not"s is simply a more emphatic claim: the cat is really, truly, *definitely*, not on that particular mat. :-) In various other "natural languages" -- i.e., languages meant for human-to-human communications, rather than for computers -- multiple negatives are more often (or always?) intensifiers. Some languages have the idea of "negative matching" in much the same sense that English has number [%] matching: "the cat is on the mat" and "the cats are on the mat" are OK because the noun and verb numbers match, but neither "the cats is on the mat" nor "the cat are on the mat" are correct. [% "Number" here is really 1 vs not-1: no cats, one cat, two cats.] Of course, there are descriptivists and prescriptivists, and many of the latter claim that using multi-valued boolean logic in English is "nonstandard" or "invalid". Many of those in turn will tell you that "ain't good English" ain't good English. Still, one should be aware of these forms and their uses, in much the same way as one should be able to boldly split infinitives. :-) Moving back towards on-topic-ness: >As an operator, "not" negates a true value to a false value. In >mathematical Boolean algebra, there only is one true value and one false >value, conventionally called True/False or 1/0. In non-Boolean algebras, >you can define other values. In three-value logic, the negation of True/ >False/Maybe is usually False/True/Maybe. In fuzzy logic, the logic values >are the uncountable infinity (that's a technical term, not hyperbole) of >real numbers between 0 and 1. Or, to put it another way, before we can communicate clearly, we have to pick out a set of rules. Most computer languages do this pretty well, and Python does a good (and reasonably conventional) job: >Python uses a boolean algebra where there are many ways of spelling the >true and false values. The "not" operator returns the canonical bool >values: > >not returns False >not returns True > >Take note of the distinction between lower-case true/false, which are >adjectives, and True/False, which are objects of class bool. (At least as of current versions of Python -- in much older versions there was no real distinction between booleans and type "int", presumably a a holdover from C.) [remainder snipped as I have nothing else to add] -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From rosuav at gmail.com Wed May 11 23:51:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 13:51:12 +1000 Subject: checking if a list is empty In-Reply-To: <4DCAF95B.60307@gmail.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4DCAF95B.60307@gmail.com> Message-ID: On Thu, May 12, 2011 at 7:02 AM, Ian wrote: > In the "real world" ?lists of zero items do not exist. > You don't go shopping with a shopping list of zero items. Actually, yes you do. You maintain your shopping list between trips; whenever you need something, you put it on the list immediately. Then when you go shopping, you just take the list with you (if you're lucky, you don't need to move or copy it at all, you just get another reference to it). Once you're done, you empty the list - you now have a shopping list with zero items (until you get home and realize you forgot something). Chris Angelico From harrismh777 at charter.net Wed May 11 23:53:45 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 22:53:45 -0500 Subject: checking if a list is empty In-Reply-To: <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> Message-ID: alex23 wrote: >> through intuitive language skills. Why not? > Because the vast majority of them don't seem to want to be bothered? > That could very well be... but I have a hope for them. I honestly think its not because they don't want to be bothered, rather they just think its too far past them... and not do-able. This is where I think it would be helpful at the undergraduate level to insist that *all* students learn some programming (and yes, using Python). Actually, I am thinking that it would be great to begin this in grade school. But then, I'm also one of those Americans who believe that every student should learn at least (1) non-English language beginning in 1st grade--- mandatory. (of course others are just hoping they learn English...) kind regards, m harris From sjmachin at lexicon.net Wed May 11 23:54:20 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 13:54:20 +1000 Subject: unicode by default In-Reply-To: References: Message-ID: On Thu, May 12, 2011 11:22 am, harrismh777 wrote: > John Machin wrote: >> (1) You cannot work without using bytes sequences. Files are byte >> sequences. Web communication is in bytes. You need to (know / assume / >> be >> able to extract / guess) the input encoding. You need to encode your >> output using an encoding that is expected by the consumer (or use an >> output method that will do it for you). >> >> (2) You don't need to use bytes to specify a Unicode code point. Just >> use >> an escape sequence e.g. "\u0404" is a Cyrillic character. >> > > Thanks John. In reverse order, I understand point (2). I'm less clear > on point (1). > > If I generate a string of characters that I presume to be ascii/utf-8 > (no \u0404 type characters) > and write them to a file (stdout) how does > default encoding affect that file.by default..? I'm not seeing that > there is anything unusual going on... About """characters that I presume to be ascii/utf-8 (no \u0404 type characters)""": All Unicode characters (including U+0404) are encodable in bytes using UTF-8. The result of sys.stdout.write(unicode_characters) to a TERMINAL depends mostly on sys.stdout.encoding. This is likely to be UTF-8 on a linux/OSX/platform. On a typical American / Western European /[former] colonies Windows box, this is likely to be cp850 on a Command Prompt window, and cp1252 in IDLE. UTF-8: All Unicode characters are encodable in UTF-8. Only problem arises if the terminal can't render the character -- you'll get spaces or blobs or boxes with hex digits in them or nothing. Windows (Command Prompt window): only a small subset of characters can be encoded in e.g. cp850; anything else causes an exception. Windows (IDLE): ignores sys.stdout.encoding and renders the characters itself. Same outcome as *x/UTF-8 above. If you write directly (or sys.stdout is redirected) to a FILE, the default encoding is obtained by sys.getdefaultencoding() and is AFAIK ascii unless the machine's site.py has been fiddled with to make it UTF-8 or something else. > If I open the file with vi? If > I open the file with gedit? emacs? Any editor will have a default encoding; if that doesn't match the file encoding, you have a (hopefully obvious) problem if the editor doesn't detect the mismatch. Consult your editor's docs or HTFF1K. > Another question... in mail I'm receiving many small blocks that look > like sprites with four small hex codes, scattered about the mail... > mostly punctuation, maybe? ... guessing, are these unicode code > points, yes > and if so what is the best way to 'guess' the encoding? google("chardet") or rummage through the mail headers (but 4 hex digits in a box are a symptom of inability to render, not necessarily caused by an incorrect decoding) ... is > it coded in the stream somewhere...protocol? Should be. From rosuav at gmail.com Thu May 12 00:00:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 14:00:08 +1000 Subject: lightweight way to create new projects from templates In-Reply-To: <4DCAD6B8.3070003@tartley.com> References: <4DCAD6B8.3070003@tartley.com> Message-ID: On Thu, May 12, 2011 at 4:34 AM, Jonathan Hartley wrote: > Hi. > > I'm looking for a quick way to create new Python projects from a template. > > I understand that 'Paste' (http://pythonpaste.org/) is one way to do this, > but I find Paste very intimidating because of all the functionality it > includes. I'm not even sure whether 'creating new projects from templates' > is the central goal of Paste, or just an incidental benefit that it provides > while performing some other task. > > As a lightweight alternative, I'm creating a project called 'Genesis'. > Functionally, it will be little more than a 'cp -r' followed by a few search > and replace operations. Depending on how simple your goals are, it might be possible to do it with a simple shell or Python script that creates multiple files and/or directories. That way, your template is all contained in a single file, which is convenient for distribution and such; and the scripting facilities can handle the search and replace operations. Chris Angelico From ben+python at benfinney.id.au Thu May 12 00:07:08 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 May 2011 14:07:08 +1000 Subject: unicode by default References: Message-ID: <874o50k1eb.fsf@benfinney.id.au> MRAB writes: > You need to understand the difference between characters and bytes. Yep. Those who don't need to join us in the third millennium, and the resources pointed out in this thread are good to help that. > A string contains characters, a file contains bytes. That's not true for Python 2. I'd phrase that as: * Text is a sequence of characters. Most inputs to the program, including files, sockets, etc., contain a sequence of bytes. * Always know whether you're dealing with text or with bytes. No object can be both. * In Python 2, ?str? is the type for a sequence of bytes. ?unicode? is the type for text. * In Python 3, ?str? is the type for text. ?bytes? is the type for a sequence of bytes. -- \ ?I went to a garage sale. ?How much for the garage?? ?It's not | `\ for sale.?? ?Steven Wright | _o__) | Ben Finney From tjreedy at udel.edu Thu May 12 00:12:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 00:12:02 -0400 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/11/2011 11:44 PM, harrismh777 wrote: > Steven D'Aprano wrote: >>> You need to understand the difference between characters and bytes. >> >> http://www.joelonsoftware.com/articles/Unicode.html >> >> is also a good resource. > > Thanks for being patient guys, here's what I've done: > >>>>> astr="pound sign" >>>>> asym=" \u00A3" >>>>> afile=open("myfile", mode='w') >>>>> afile.write(astr + asym) >> 12 >>>>> afile.close() > > > When I edit "myfile" with vi I see the 'characters' : > > pound sign ? > > ... same with emacs, same with gedit ... > > > When I hexdump myfile I see this: > > 0000000 6f70 6375 2064 6973 6e67 c220 00a3 > This is *not* what I expected... well it is (little-endian) right up to > the 'c2' and that is what is confusing me.... > I did not open the file with an encoding of UTF-8... so I'm assuming > UTF-16 by default (python3) so I was expecting a '00A3' little-endian as > 'A300' but what I got instead was UTF-8 little-endian 'c2a3' .... > > See my problem?... when I open the file with emacs I see the character > pound sign... same with gedit... they're all using UTF-8 by default. By > default it looks like Python3 is writing output with UTF-8 as default... > and I thought that by default Python3 was using either UTF-16 or UTF-32. > So, I'm confused here... also, I used the character sequence \u00A3 > which I thought was UTF-16... but Python3 changed my intent to 'c2a3' > which is the normal UTF-8... If you open a file as binary (bytes), you must write bytes, and they are stored without transformation. If you open in text mode, you must write text (string as unicode in 3.2) and Python will encode to bytes using either some default or the encoding you specified in the open statement. It does not matter how Python stored the unicode internally. Does this help? Your intent is signalled by how you open the file. -- Terry Jan Reedy From sjmachin at lexicon.net Thu May 12 00:14:35 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 14:14:35 +1000 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 1:44 pm, harrismh777 wrote: > By > default it looks like Python3 is writing output with UTF-8 as default... > and I thought that by default Python3 was using either UTF-16 or UTF-32. > So, I'm confused here... also, I used the character sequence \u00A3 > which I thought was UTF-16... but Python3 changed my intent to 'c2a3' > which is the normal UTF-8... Python uses either a 16-bit or a 32-bit INTERNAL representation of Unicode code points. Those NN bits have nothing to do with the UTF-NN encodings, which can be used to encode the codepoints as byte sequences for EXTERNAL purposes. In your case, UTF-8 has been used as it is the default encoding on your platform. From benjamin.kaplan at case.edu Thu May 12 00:14:49 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 May 2011 21:14:49 -0700 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 11, 2011 at 8:44 PM, harrismh777 wrote: > Steven D'Aprano wrote: >>> >>> You need to understand the difference between characters and bytes. >> >> http://www.joelonsoftware.com/articles/Unicode.html >> >> is also a good resource. > > Thanks for being patient guys, here's what I've done: > >>>>> astr="pound sign" >>>>> asym=" \u00A3" >>>>> afile=open("myfile", mode='w') >>>>> afile.write(astr + asym) >> >> 12 >>>>> >>>>> afile.close() > > > When I edit "myfile" with vi I see the 'characters' : > > pound sign ? > > ? ... same with emacs, same with gedit ?... > > > When I hexdump myfile I see this: > > 0000000 6f70 6375 2064 6973 6e67 c220 00a3 > > > This is *not* what I expected... well it is (little-endian) right up to the > 'c2' and that is what is confusing me.... > > I did not open the file with an encoding of UTF-8... so I'm assuming UTF-16 > by default (python3) so I was expecting a '00A3' little-endian as 'A300' but > what I got instead was UTF-8 little-endian ?'c2a3' .... > quick note here: UTF-8 doesn't have an endian-ness. It's always read from left to right, with the high bit telling you whether you need to continue or not. So it's always "little endian". > See my problem?... when I open the file with emacs I see the character pound > sign... same with gedit... they're all using UTF-8 by default. By default it > looks like Python3 is writing output with UTF-8 as default... and I thought > that by default Python3 was using either UTF-16 or UTF-32. So, I'm confused > here... ?also, I used the character sequence \u00A3 which I thought was > UTF-16... but Python3 changed my intent to ?'c2a3' which is the normal > UTF-8... > The fact that CPython uses UCS-2 or UCS-4 internally is an implementation detail and isn't actually part of the Python specification. As far as a Python program is concerned, a Unicode string is a list of character objects, not bytes. Much like any other object, a unicode character needs to be serialized before it can be written to a file. An encoding is a serialization function for characters. If the file you're writing to doesn't specify an encoding, Python will default to locale.getdefaultencoding(), which tries to get your system's preferred encoding from environment variables (in other words, the same source that emacs and gedit will use to get the default encoding). From sjmachin at lexicon.net Thu May 12 00:41:47 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 14:41:47 +1000 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 2:14 pm, Benjamin Kaplan wrote: > > If the file you're writing to doesn't specify an encoding, Python will > default to locale.getdefaultencoding(), No such attribute. Perhaps you mean locale.getpreferredencoding() From hg at schaathun.net Thu May 12 01:20:37 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 06:20:37 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5a7s98-m68.ln1@svn.schaathun.net> On Wed, 11 May 2011 20:16:01 -0700 (PDT), alex23 wrote: : Hans Georg Schaathun wrote: : > Revolutionary indeed, so why don't we exploit the revolution : > and write the programs to be as accessible as possible? : : Where do you draw the line, though? I said that, "as possible". You draw it at the limit of possibility. : No decorators, as they're not intuitively obvious? No custom : descriptors, as that requires a deeper knowledge of Python internals : that utter ignorance allows? When they help clarify or simplify the code, they are good. When they do nothing of the sort, they aren't. : Both of those aspects alone seem far more complex and advanced than : treating empty collections as False. Probably, but they also seem far more useful. -- :-- Hans Georg From hg at schaathun.net Thu May 12 01:21:28 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 06:21:28 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 21:47:27 GMT, Steven D'Aprano wrote: : On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: : > One principle of object oriented programming is to bestow the objects : > with properties reflecting known properties from the domain being : > modelled. Lists do not have truth values in the application domain : : Yes they do. Empty lists are nothing, ergo false, and non-empty lists are : something, ergo true. What application domain has established that terminology? -- :-- Hans Georg From swavijay at gmail.com Thu May 12 01:35:14 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Thu, 12 May 2011 11:05:14 +0530 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: I tried using QThread as well.. But the problem is, on the run method when i invoke the command prompt, it sends out the finished signal... I want it to send out the finished signal only on closing the command prompt that is invoked earlier in my process. guess some logic to be implement inside run() which monitors the command prompt / reports the status once the command prompt is closed. I tried running loop inside the run() to keep the thread active but no help.. class RunMonitor(QThread): def __init__(self, parent = None): QThread.__init__(self) def run(self): print 'Invoking command prompt...............' subprocess.call(["start", "/DC:\\PerfLocal_PAL", "scripts_to_execute.bat"], shell=True) while True: pass def runscript(self): print 'Complete_file_Path inside Run script is : ' , self.complete_file_path file_operation.Generate_Bat_File(self.complete_file_path) self.run_monitor_object = RunMonitor() self.run_monitor_object.start() self.connect(self.run_monitor_object, SIGNAL("finished()"),self.threadstatus) On Wed, May 11, 2011 at 9:25 PM, Wojtek Mamrak wrote: > 2011/5/11 Chris Angelico : > > On Thu, May 12, 2011 at 1:16 AM, Wojtek Mamrak > wrote: > >> Is there any special reason you don't want to use QThread? > >> > http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details > > > > Other than that QThread is part of QT and threading isn't, what are > > the advantages of QThread? Is it possible (safe) to manipulate QT > > objects - in this case, the button - from a thread other than the one > > that created them? (If not, that would be a good reason for using > > QThread, which will fire an event upon termination.) > > > > > QThread provides mechanism of signals and slots ("from" and "to" the > thread), which are used across all pyQt. Unfortunately it is not > possible to use any widget classes in the thread (direct quote from > the docs). On the other hand signals can fire methods from the main > thread (running the app'a main loop), so this is not a big deal. > The signals are: > - finished > - started > - terminated > It is possible to block the thread, make it sleep, check whether the > thread is running, and few others. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Thu May 12 01:44:07 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 12 May 2011 17:44:07 +1200 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <931adaF9g1U1@mid.individual.net> Roy Smith wrote: > Hans Georg Schaathun wrote: >>If both are numbers, they are converted to a common type. Otherwise, >>objects of different types always compare unequal That's just the default treatment for unrelated types that don't know anything about each other. I would guess that the list's == method is asking "Is the other object a list?", and since a subclass of list is also a list, it's happy and goes on to compare the elements. -- Greg From darcy at druid.net Thu May 12 01:49:05 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 12 May 2011 01:49:05 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110512014905.96c592f6.darcy@druid.net> On Wed, 11 May 2011 16:24:47 -0500 harrismh777 wrote: > D'Arcy J.M. Cain wrote: > Non-programmers should not be expected to program in 'C' nor in lisp... > > ... but non-programmers were able to program in BASIC jes fine... They still had to learn the language. > I contend that non-programmers are able to learn rudimentary python and > work with it to solve real problems 'without' formal training in > 'programming'. When did the discussion shift from "learn the language" to "formal training?" How you learn the language is totally irrelevant. > Python is the New BASIC for 'people'. At least, it has the potential to > be that... people should be able to talk to their computers (whatever > we mean by that) and have the computer respond with real-world > solutions. We need to move away from 'canned apps' to a new day where > the masses can sit down to their computer and solve new problems with it > through intuitive language skills. Why not? That's not programming. That's using a canned app that a programmer wrote that takes your unstructured input and does something useful with it. Spreadsheets are a primitive example of that. Google is a more advanced example. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From hg at schaathun.net Thu May 12 02:06:42 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 07:06:42 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> Message-ID: On Thu, 12 May 2011 17:44:07 +1200, Gregory Ewing wrote: : Roy Smith wrote: : > Hans Georg Schaathun wrote: : >>If both are numbers, they are converted to a common type. Otherwise, : >>objects of different types always compare unequal Actually, I did not. :-- hg From hg at schaathun.net Thu May 12 02:13:28 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 07:13:28 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> Message-ID: <8das98-nd8.ln1@svn.schaathun.net> On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 wrote: : On May 12, 7:24?am, harrismh777 wrote: : >?We need to move away from 'canned apps' to a new day where : > the masses can sit down to their computer and solve new problems with it : > through intuitive language skills. ?Why not? : : Because the vast majority of them don't seem to want to be bothered? Why does that matter? There is a sizeable group who need computers for purposes not (sufficiently) supported by the `canned apps'. The fact that they are outnumbered by users who really only need typewriters and entertainment theatres does in no way reduce the need of those who actually need /computers/. -- :-- Hans Georg From steve+comp.lang.python at pearwood.info Thu May 12 02:13:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 May 2011 06:13:34 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> Message-ID: <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 22:53:45 -0500, harrismh777 wrote: > alex23 wrote: >>> through intuitive language skills. Why not? >> Because the vast majority of them don't seem to want to be bothered? >> >> > That could very well be... but I have a hope for them. I honestly think > its not because they don't want to be bothered, rather they just think > its too far past them... and not do-able. An admirable hope, but there is a significant amount of research into teaching computer programming that suggests that learning to program is simply beyond a large portion of the population, no matter what you do or what language you teach. Some 30-60% of people barely get past "Hello World". (That's not to imply that they're dumb, just that whatever mental skills are needed for programming is beyond them, just as whatever mental skills are needed for writing poetry are beyond me.) http://www.codinghorror.com/blog/2006/07/separating-programming-sheep-from-non-programming-goats.html Shorter version: it seems that programming aptitude is a bimodal distribution, with very little migration from the "can't program" hump into the "can program" hump. There does seem to be a simple predictor for which hump you fall into: those who intuitively develop a consistent model of assignment (right or wrong, it doesn't matter, so long as it is consistent) can learn to program. Those who don't, can't. -- Steven From harrismh777 at charter.net Thu May 12 02:14:37 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 12 May 2011 01:14:37 -0500 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: John Machin wrote: > On Thu, May 12, 2011 2:14 pm, Benjamin Kaplan wrote: >> >> If the file you're writing to doesn't specify an encoding, Python will >> default to locale.getdefaultencoding(), > > No such attribute. Perhaps you mean locale.getpreferredencoding() >>> import locale >>> locale.getpreferredencoding() 'UTF-8' >>> Yessssssss! :) From hg at schaathun.net Thu May 12 02:21:09 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 07:21:09 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 12 May 2011 01:49:05 -0400, D'Arcy J.M. Cain wrote: : That's not programming. That's using a canned app that a programmer : wrote that takes your unstructured input and does something useful with : it. Spreadsheets are a primitive example of that. Google is a more : advanced example. You are really trying to defend the programmers' status as a modern day priesthood, mastering a mystic art completely inaccessible to those not initiated. For ages, the literate elite deliberately made the language cryptic to protect their art and their status. Some programmers seem to do the same. The fact is that it is not black and white. There are programmers with domain expertise, programmers without domain expertise, domain experts with decent programming skills, domain experts with rudimentary programming skills, monolingual programmers, domain experts without programming skills, polyglot programmers etc. Only very narrow-purpose applications can be created by one of these groups on their own, and to collaborate their abilities must be overlapping. -- :-- Hans Georg From hg at schaathun.net Thu May 12 02:23:20 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 07:23:20 +0100 Subject: checking if a list is empty References: <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb02b1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 21:42:10 GMT, Steven D'Aprano wrote: : *Potentially* different tests. Which is exactly the point. Given an : arbitrary object, the developer doesn't know what test is appropriate. : Should I write len(x) == 0 or list(x) == [] or x.next is None or : something else? How can I tell which is appropriate without knowing : everything about the internals of every object I ever see? Sure, but the question asked was how to check if a /list/ is empty. You defend your answer assuming a different question. You could at least have the decency to change the subject header when you go down that route. -- :-- Hans Georg From harrismh777 at charter.net Thu May 12 02:31:16 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 12 May 2011 01:31:16 -0500 Subject: unicode by default In-Reply-To: <874o50k1eb.fsf@benfinney.id.au> References: <874o50k1eb.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > I'd phrase that as: > * Text is a sequence of characters. Most inputs to the program, > including files, sockets, etc., contain a sequence of bytes. > * Always know whether you're dealing with text or with bytes. No object > can be both. > * In Python 2, ?str? is the type for a sequence of bytes. ?unicode? is > the type for text. > * In Python 3, ?str? is the type for text. ?bytes? is the type for a > sequence of bytes. That is very helpful... thanks MRAB, Steve, John, Terry, Ben F, Ben K, Ian... ...thank you guys so much, I think I've got a better picture now of what is going on... this is also one place where I don't think the books are as clear as they need to be at least for me...(Lutz, Summerfield). So, the UTF-16 UTF-32 is INTERNAL only, for Python... and text in/out is based on locale... in my case UTF-8 ...that is enormously helpful for me... understanding locale on this system is as mystifying as unicode is in the first place. Well, after reading about unicode tonight (about four hours) I realize that its not really that hard... there's just a lot of details that have to come together. Straightening out that whole tower-of-babel thing is sure a pain in the butt. I also was not aware that UTF-8 chars could be up to six(6) byes long from left to right. I see now that the little-endianness I was ascribing to python is just a function of hexdump... and I was a little disappointed to find that hexdump does not support UTF-8, just ascii...doh. Anyway, thanks again... I've got enough now to play around a bit... PS thanks Steve for that link, informative and entertaining too... Joe says, "If you are a programmer . . . and you don't know the basics of characters, character sets, encodings, and Unicode, and I catch you, I'm going to punish you by making you peel onions for 6 months in a submarine. I swear I will". :) kind regards, m harris From swavijay at gmail.com Thu May 12 02:31:30 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Thu, 12 May 2011 12:01:30 +0530 Subject: Need Assistance on this program. Message-ID: Hi All, I'm new bie to python thread programming and would like to assistance on the attached code. In this, I'm calling a thread to invoke a command prompt and would like to print the "Thread as alive" as long as the command prompt is opened and would like to print "Thread is Dead" only when the command prompt is closed by the user. based on my understand I have written this peace of code which does not seem to work. There is some flaw in the logic which I could not understand since I'm not that familiar with the thread concepts. Can somebody help me in getting this piece of code working. Also can somebody point me to a good tutorial on understanding python thread programming since I want to get my understanding on the concept of thread better. I googled a few but quite confusing. -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Thread_Example1.py Type: application/octet-stream Size: 830 bytes Desc: not available URL: From harrismh777 at charter.net Thu May 12 02:43:23 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 12 May 2011 01:43:23 -0500 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Terry Reedy wrote: > It does not matter how Python stored the unicode internally. Does this > help? Your intent is signalled by how you open the file. Very much, actually, thanks. I was missing the 'internal' piece, and did not realize that if I didn't specify the encoding on the open that python would pull the default encoding from locale... kind regards, m harris From ben+python at benfinney.id.au Thu May 12 02:46:38 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 May 2011 16:46:38 +1000 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <8das98-nd8.ln1@svn.schaathun.net> Message-ID: <87zkmsifg1.fsf@benfinney.id.au> Hans Georg Schaathun writes: > On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 > wrote: > : On May 12, 7:24?am, harrismh777 wrote: > : >?We need to move away from 'canned apps' to a new day where > : > the masses can sit down to their computer and solve new problems with it > : > through intuitive language skills. ?Why not? > : > : Because the vast majority of them don't seem to want to be bothered? > > Why does that matter? There is a sizeable group who need computers > for purposes not (sufficiently) supported by the `canned apps'. Those people, outnumbered by the masses as you say, are thereby not themselves ?the masses?. -- \ ?Hey Homer! You're late for English!? ?Pff! English, who needs | `\ that? I'm never going to England!? ?Barney & Homer, _The | _o__) Simpsons_ | Ben Finney From hg at schaathun.net Thu May 12 03:28:03 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 08:28:03 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <8das98-nd8.ln1@svn.schaathun.net> <87zkmsifg1.fsf@benfinney.id.au> Message-ID: <3pes98-eh8.ln1@svn.schaathun.net> On Thu, 12 May 2011 16:46:38 +1000, Ben Finney wrote: : Hans Georg Schaathun writes: : : > On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 : > wrote: : > : On May 12, 7:24?am, harrismh777 wrote: : > : >?We need to move away from 'canned apps' to a new day where : > : > the masses can sit down to their computer and solve new problems with it : > : > through intuitive language skills. ?Why not? : > : : > : Because the vast majority of them don't seem to want to be bothered? : > : > Why does that matter? There is a sizeable group who need computers : > for purposes not (sufficiently) supported by the `canned apps'. : : Those people, outnumbered by the masses as you say, are thereby not : themselves ?the masses?. So what? Do we only need solutions and systems for the masses? What about systems for those who develop systems for the masses? Or the theory necessary to develop the systems to develop more advanced systems for the masses in the future? Get real, software development and programming is more than just overpriced web systems that just almost manage to replicate the functionality of IBM page based terminals and mainframes of 1973, just slower and with more eye candy. -- :-- Hans Georg From ben+python at benfinney.id.au Thu May 12 03:37:58 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 May 2011 17:37:58 +1000 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <8das98-nd8.ln1@svn.schaathun.net> <87zkmsifg1.fsf@benfinney.id.au> <3pes98-eh8.ln1@svn.schaathun.net> Message-ID: <87vcxgid2h.fsf@benfinney.id.au> Hans Georg Schaathun writes: > On Thu, 12 May 2011 16:46:38 +1000, Ben Finney > wrote: > : Hans Georg Schaathun writes: > : > : > On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 > : > wrote: > : > : On May 12, 7:24?am, harrismh777 wrote: > : > : >?We need to move away from 'canned apps' to a new day where > : > : > the masses can sit down to their computer and solve new problems with it > : > : > through intuitive language skills. ?Why not? > : > : > : > : Because the vast majority of them don't seem to want to be bothered? > : > > : > Why does that matter? There is a sizeable group who need computers > : > for purposes not (sufficiently) supported by the `canned apps'. > : > : Those people, outnumbered by the masses as you say, are thereby not > : themselves ?the masses?. > > So what? Do we only need solutions and systems for the masses? Your ?why does that matter?? was addressed to an answer specifically in the context of ?a new day where the masses can sit down to their computer and ??. The question is asked and answered. If you want to raise a *new* topic ? that of the non-masses who have different needs ? it's best not to start with ?Why does that matter?? but to lay out your separate case. -- \ ?Visitors are expected to complain at the office between the | `\ hours of 9 and 11 a.m. daily.? ?hotel, Athens | _o__) | Ben Finney From nagle at animats.com Thu May 12 03:40:08 2011 From: nagle at animats.com (John Nagle) Date: Thu, 12 May 2011 00:40:08 -0700 Subject: Python Developers with 5 years of experience In-Reply-To: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> References: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> Message-ID: <4dcb8ef9$0$60254$742ec2ed@news.sonic.net> On 5/4/2011 10:32 AM, Jerome jjcpl.rpo wrote: > send resumes to jerome at jjcpl.net > > > One of our client in New Jersey is looking for Python Developers with > 5 years of experience. If you have any resumes please send it > across. Very strange recruiting organization. Strong Christian religious orientation, but run from India. "He who trusts in the LORD will be prospered ! Proverb 28:25" "JEHOVAH JIREH COMMUNICATIONS is promoted by a group of professionals with extensive IT experience, especially in the Staffing Industry, across the globe." Headoffice Plot No 158, CGE Colony First Street Tuticorin - 628003 Tamilnadu Phone no: 91 461 4005333 / 3290473 Fax No: 91 461 4001473 Email : contact at jjcpl.net John Nagle From sjmachin at lexicon.net Thu May 12 03:58:24 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 17:58:24 +1000 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> Message-ID: <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> On Thu, May 12, 2011 4:31 pm, harrismh777 wrote: > > So, the UTF-16 UTF-32 is INTERNAL only, for Python NO. See one of my previous messages. UTF-16 and UTF-32, like UTF-8 are encodings for the EXTERNAL representation of Unicode characters in byte streams. > I also was not aware that UTF-8 chars could be up to six(6) byes long > from left to right. It could be, once upon a time in ISO faerieland, when it was thought that Unicode could grow to 2**32 codepoints. However ISO and the Unicode consortium have agreed that 17 planes is the utter max, and accordingly a valid UTF-8 byte sequence can be no longer than 4 bytes ... see below >>> chr(17 * 65536) Traceback (most recent call last): File "", line 1, in ValueError: chr() arg not in range(0x110000) >>> chr(17 * 65536 - 1) '\U0010ffff' >>> _.encode('utf8') b'\xf4\x8f\xbf\xbf' >>> b'\xf5\x8f\xbf\xbf'.decode('utf8') Traceback (most recent call last): File "", line 1, in File "C:\python32\lib\encodings\utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xf5 in position 0: invalid start byte From tartley at tartley.com Thu May 12 04:04:58 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 12 May 2011 01:04:58 -0700 (PDT) Subject: lightweight way to create new projects from templates In-Reply-To: Message-ID: <8c898c2b-d858-41f0-950f-14570c0931c9@glegroupsg2000goo.googlegroups.com> Hey Chris, Thanks for the thoughts. I must confess I had already given up on a 'single file' approach, because I want to make it easy for people to create their own templates, so I have to handle copying a template defined by creating a new directory full of diles. If I'm already handling this case, I thought, I might as well bundle the built-in default templates as a bunch of files. I'd hope to provide platform binaries to make download and install easy for end-users, regardless of what Python version they already have installed. Which reminds me, I should make sure the default template works on Python2.x as well as 3.x. Thanks! From tartley at tartley.com Thu May 12 04:04:58 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 12 May 2011 01:04:58 -0700 (PDT) Subject: lightweight way to create new projects from templates In-Reply-To: Message-ID: <8c898c2b-d858-41f0-950f-14570c0931c9@glegroupsg2000goo.googlegroups.com> Hey Chris, Thanks for the thoughts. I must confess I had already given up on a 'single file' approach, because I want to make it easy for people to create their own templates, so I have to handle copying a template defined by creating a new directory full of diles. If I'm already handling this case, I thought, I might as well bundle the built-in default templates as a bunch of files. I'd hope to provide platform binaries to make download and install easy for end-users, regardless of what Python version they already have installed. Which reminds me, I should make sure the default template works on Python2.x as well as 3.x. Thanks! From michiel at wedemandhtml.com Thu May 12 04:05:52 2011 From: michiel at wedemandhtml.com (Michiel Sikma) Date: Thu, 12 May 2011 10:05:52 +0200 Subject: urllib2 request with binary file as payload In-Reply-To: <2fa89ca32d0796866e0fe4121371b882.squirrel@webmail.lexicon.net> References: <2fa89ca32d0796866e0fe4121371b882.squirrel@webmail.lexicon.net> Message-ID: > > 2.6 is expecting a string, according to the above. No mention of file. > Moreover it expects the data to be urlencoded. 2.7.1 docs say the same > thing. Are you sure you have shown the code that worked with 2.6? > > > -- > http://mail.python.org/mailman/listinfo/python-list > Yes, in fact I simply tried passing the file to the Request class without having checked the docs to see if I could even do that, but it worked. I also send an unencoded XML string a little bit earlier on. Maybe it no longer needs to be a urlencoded string as soon as you add a Content-Type header. Here's what happens when I put the HTTPHandler in debug mode and pass a file in 2.6: send: 'PUT /resumable/feeds/api/users/default/uploads?upload_id=[id]HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 898801\r\nHost: uploads.gdata.youtube.com\r\nContent-Type: application/octet-stream\r\nConnection: close\r\nUser-Agent: Python-urllib/2.6\r\n\r\n' send: sendIng a read()able A little while later: reply: 'HTTP/1.1 201 Created\r\n' [...etc] So it seems to work just fine, but 2.5 does indeed complain about this being an incorrect use of Request. Moreover, though I can't upgrade my Python from 2.5 I was able to compile another alongside it (latest stable 2.7) and use that with my code, and it worked just fine. Uploaded a 6GB file to Youtube this way. :) Michiel Sikma We Demand HTML http://wedemandhtml.com/ michiel at wedemandhtml.com From rosuav at gmail.com Thu May 12 04:08:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 18:08:05 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 3:35 PM, vijay swaminathan wrote: > I tried using QThread as well.. But the problem is, on the run method when i > invoke the command prompt, it sends out the finished signal...? I want it to > send out the finished signal only on closing the command prompt that is > invoked earlier in my process. > ??????? subprocess.call(["start", "/DC:\\PerfLocal_PAL", > "scripts_to_execute.bat"], shell=True) This is your problem, still. You need to change to a call that waits. In my testing on Windows (Python 2.6.5), this can be done with os.system() quite happily. Change that, and it should all work. Chris Angelico From andrea.crotti.0 at gmail.com Thu May 12 05:16:36 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 12 May 2011 11:16:36 +0200 Subject: Need Assistance on this program. In-Reply-To: References: Message-ID: vijay swaminathan writes: > Hi All, > > I'm new bie to python thread programming and would like to assistance > on the attached code. > > In this, I'm calling a thread to invoke a command prompt and would > like to print the "Thread as alive" as long as the command prompt is > opened and would like to print "Thread is Dead" only when the command > prompt is closed by the user. > > based on my understand I have written this peace of code which does > not seem to work. There is some flaw in the logic which I could not > understand since I'm not that familiar with the thread concepts. > > Can somebody help me in getting this piece of code working. > > Also can somebody point me to a good tutorial on understanding python > thread programming since I want to get my understanding on the concept > of thread better. I googled a few but quite confusing. > > -- > Vijay Swaminathan Easy mistake, this: if mythread_object.is_alive: is wrong, since is_alive is a method, not a bool so it should be is_alive(). Pay attention to these things, and actually something called "is_adjective" is almost never a variable. From swavijay at gmail.com Thu May 12 05:42:39 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Thu, 12 May 2011 15:12:39 +0530 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: Hi Chris, I tried using os.system as well but it did not even open up the command prompt. Can you please share the code that worked for you.. just wondering if I'm missing something very basic. Regards, -Vijay Swaminathan., On Thu, May 12, 2011 at 1:38 PM, Chris Angelico wrote: > On Thu, May 12, 2011 at 3:35 PM, vijay swaminathan > wrote: > > I tried using QThread as well.. But the problem is, on the run method > when i > > invoke the command prompt, it sends out the finished signal... I want it > to > > send out the finished signal only on closing the command prompt that is > > invoked earlier in my process. > > > subprocess.call(["start", "/DC:\\PerfLocal_PAL", > > "scripts_to_execute.bat"], shell=True) > > This is your problem, still. You need to change to a call that waits. > In my testing on Windows (Python 2.6.5), this can be done with > os.system() quite happily. Change that, and it should all work. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From swavijay at gmail.com Thu May 12 05:45:07 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Thu, 12 May 2011 15:15:07 +0530 Subject: Need Assistance on this program. In-Reply-To: References: Message-ID: I tried using that as well. The problem is, the thread becomes dead as soon as it executes the invocation of command prompt. I want the thread to be alive till I go and manually close the command prompt. -Vijay Swaminathan. On Thu, May 12, 2011 at 2:46 PM, Andrea Crotti wrote: > vijay swaminathan writes: > > > Hi All, > > > > I'm new bie to python thread programming and would like to assistance > > on the attached code. > > > > In this, I'm calling a thread to invoke a command prompt and would > > like to print the "Thread as alive" as long as the command prompt is > > opened and would like to print "Thread is Dead" only when the command > > prompt is closed by the user. > > > > based on my understand I have written this peace of code which does > > not seem to work. There is some flaw in the logic which I could not > > understand since I'm not that familiar with the thread concepts. > > > > Can somebody help me in getting this piece of code working. > > > > Also can somebody point me to a good tutorial on understanding python > > thread programming since I want to get my understanding on the concept > > of thread better. I googled a few but quite confusing. > > > > -- > > Vijay Swaminathan > > Easy mistake, this: > if mythread_object.is_alive: > > is wrong, since is_alive is a method, not a bool so it should be > is_alive(). > > Pay attention to these things, and actually something called > "is_adjective" is almost never a variable. > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Thu May 12 06:08:11 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 12 May 2011 11:08:11 +0100 Subject: Need Assistance on this program. In-Reply-To: References: Message-ID: <4DCBB18B.5050309@timgolden.me.uk> On 12/05/2011 10:45, vijay swaminathan wrote: > > I tried using that as well. > The problem is, the thread becomes dead as soon as it executes the > invocation of command prompt. Can you post the code you're using, please? This should be simple so maybe you've misunderstood something in the threading / subprocess mix. TJG From swavijay at gmail.com Thu May 12 06:29:51 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Thu, 12 May 2011 15:59:51 +0530 Subject: Need Assistance on this program. In-Reply-To: <4DCBB18B.5050309@timgolden.me.uk> References: <4DCBB18B.5050309@timgolden.me.uk> Message-ID: Hi Tim, I have already done that. But for some reason my response went as a new thread. Attaching the code again. On Thu, May 12, 2011 at 3:38 PM, Tim Golden wrote: > On 12/05/2011 10:45, vijay swaminathan wrote: > >> >> I tried using that as well. >> The problem is, the thread becomes dead as soon as it executes the >> invocation of command prompt. >> > > Can you post the code you're using, please? > > This should be simple so maybe you've misunderstood > something in the threading / subprocess mix. > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Thread_Example1.py Type: application/octet-stream Size: 814 bytes Desc: not available URL: From mail at timgolden.me.uk Thu May 12 06:38:02 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 12 May 2011 11:38:02 +0100 Subject: Need Assistance on this program. In-Reply-To: References: <4DCBB18B.5050309@timgolden.me.uk> Message-ID: <4DCBB88A.8020702@timgolden.me.uk> On 12/05/2011 11:29, vijay swaminathan wrote: <... snippet from code ...> print 'Invoking Command Promptt..............' #subprocess.call(["start", "/DC:\\PerfLocal_PAL", "scripts_to_execute.bat"], shell=True) subprocess.call(["start", "C:\\windows\\system32\\cmd.exe"], shell = True) self.status() If you want to use start, use start /wait. But you don't have to: import threading import time import subprocess def run_command (command): # # .call is shorthand for: start process and wait # CREATE_NEW_CONSOLE prevents it from getting messed # up with the Python console # subprocess.call ( [command], creationflags=subprocess.CREATE_NEW_CONSOLE ) t = threading.Thread (target=run_command, args=("cmd.exe",)) t.start () while t.is_alive (): print "alive" time.sleep (0.5) print "Thread is dead" TJG From rosuav at gmail.com Thu May 12 06:46:15 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 20:46:15 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 7:42 PM, vijay swaminathan wrote: > Hi Chris, > > I tried using os.system as well but it did not even open up the command > prompt. > > Can you please share the code that worked for you.. just wondering if I'm > missing something very basic. Caveat: I'm not using Qt, I just tried this in IDLE (which is graphical). C:\>copy con test.bat echo Hello, world! pause ^Z 1 file(s) copied. IDLE 2.6.5 >>> import os >>> os.system("c:\\test.bat") 0 The 0 and subsequent prompt don't appear until the batch file finishes. Meanwhile, the batch file is executing in a separate window. When you try it inside Qt, do you get a background window that needs to be brought to the front? Does execution pause while the batch file runs? Chris Angelico From qtvali at gmail.com Thu May 12 07:06:52 2011 From: qtvali at gmail.com (Tambet) Date: Thu, 12 May 2011 14:06:52 +0300 Subject: Slice implementation bug Message-ID: Hello! Let's say slice is multidimensional now - how to interpret it? I excpect these to work: - m[0, 3] - get one element from matrix - m[0:2, 0:2] - get four elements from matrix, iterate over them (I have actually an rtree if it doesn't make sense to you) But it won't, because if m[0, 3] returns something, then m[0:2, 0:2] cannot yield anymore. Ofcourse I could return an iterator, but this would not be so simple. So, maybe we need these: - __isslice__(key) - return true, false - __getitem__(key) - return a value - __getslice__(key) - yield a lots of values So that if isslice returns true, getslice will be called. Would be much more beauty! Right now it's ugly. I love Python, but I also love n-dimensional spaces and those are ugly in Python - last time I did Matrix multiplication I could not implement m[0, 3] (stupid errors), could not m[0j + 3], could not use tuple. Now I was happy that it's implemented and just ran into another problem that I have to choose, if getter returns one or many :) Ofcourse I could return list or other iterable, but I want to be able to do it with three-liner, because the rest of my code mostly consists of those. Except the few masterfunctions, which do some complex manipulations with data. I also need to implement things like that, which also return true for __isslice__: m[Circle(0, 0, 10)] - for RTree, any shape object implementing getExtent and doesOverlap can be used as slice index. Because I do complex map transformations and all this trivial stuff must be *hidden*! Tambet -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Thu May 12 07:36:27 2011 From: roy at panix.com (Roy Smith) Date: Thu, 12 May 2011 07:36:27 -0400 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> Message-ID: In article <931adaF9g1U1 at mid.individual.net>, Gregory Ewing wrote: > Roy Smith wrote: > >>If both are numbers, they are converted to a common type. Otherwise, > >>objects of different types always compare unequal > > That's just the default treatment for unrelated types that don't > know anything about each other. > > I would guess that the list's == method is asking "Is the > other object a list?", and since a subclass of list is also > a list, it's happy and goes on to compare the elements. Well, that explains what's happening, but the behavior still doesn't match the docs. Is this a bug or are the docs wrong? From andrea.crotti.0 at gmail.com Thu May 12 08:12:37 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 12 May 2011 14:12:37 +0200 Subject: Slice implementation bug In-Reply-To: References: Message-ID: Tambet writes: > Hello! > > Let's say slice is multidimensional now - how to interpret it? > But who said that slice is multidimensional in the first place? Since python is not matlab I don't think it will ever be done, so what's the purpose of talking about a bug in something that doesn't exist? PS. probably in numpy you can find what you look for From rosuav at gmail.com Thu May 12 08:16:10 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 22:16:10 +1000 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 at 4:21 PM, Hans Georg Schaathun wrote: > On Thu, 12 May 2011 01:49:05 -0400, D'Arcy J.M. Cain > ? wrote: > : ?That's not programming. ?That's using a canned app that a programmer > : ?wrote that takes your unstructured input and does something useful with > : ?it. ?Spreadsheets are a primitive example of that. ?Google is a more > : ?advanced example. > > You are really trying to defend the programmers' status as a modern > day priesthood, mastering a mystic art completely inaccessible to > those not initiated. Anyone can join. Not everyone wants to join. Me, I'm happy here as a priest of the software industry, and I have no desire to become a priest of, say, automotive engineering or concrete pouring. Would an expert concreter be expected to explain to me exactly how to make different sorts of concrete, or would he be expected simply to fulfill his contract and provide me with my structure? Chris Angelico From roy at panix.com Thu May 12 08:23:04 2011 From: roy at panix.com (Roy Smith) Date: Thu, 12 May 2011 08:23:04 -0400 Subject: list equal to subclass of list? Message-ID: I have a vague feeling this may have been discussed a long time ago, but I can't find the thread, so I'll bring it up again. I recently observed in the "checking if a list is empty" thread that a list and a subclass of list can compare equal: ---------------------------- class MyList(list): "I'm a subclass" l1 = [] l2 = MyList() print type(l1), type(l2) print type(l1) == type(l2) print l1 == l2 ---------------------------- when run, prints: False True The docs say: [http://docs.python.org/library/stdtypes.html] Objects of different types, except different numeric types and different string types, never compare equal [http://docs.python.org/release/2.7/reference/expressions.html#notin] objects of different types (emphasis)always compare unequal In the test code above, l1 an l2 are different types, at least in the sense that type() returns something different for each of them. What's the intended behavior here? Either the code is wrong or the docs are wrong. From nobody at nowhere.net.no Thu May 12 08:40:08 2011 From: nobody at nowhere.net.no (TheSaint) Date: Thu, 12 May 2011 20:40:08 +0800 Subject: unicode by default References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: John Machin wrote: > On Thu, May 12, 2011 2:14 pm, Benjamin Kaplan wrote: >> >> If the file you're writing to doesn't specify an encoding, Python will >> default to locale.getdefaultencoding(), > > No such attribute. Perhaps you mean locale.getpreferredencoding() what about sys.getfilesystemencoding() In the event to distribuite a program how to guess which encoding will the user has? -- goto /dev/null From hg at schaathun.net Thu May 12 08:43:51 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 13:43:51 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <791t98-659.ln1@svn.schaathun.net> On Thu, 12 May 2011 22:16:10 +1000, Chris Angelico wrote: : Anyone can join. Not everyone wants to join. Me, I'm happy here as a : priest of the software industry, and I have no desire to become a : priest of, say, automotive engineering or concrete pouring. Would an : expert concreter be expected to explain to me exactly how to make : different sorts of concrete, or would he be expected simply to fulfill : his contract and provide me with my structure? Of course he would. When a piece of software to calculate the properties or recipes for different kinds of concrete is needed. -- :-- Hans Georg From james.housden at deutsche-boerse.com Thu May 12 09:11:42 2011 From: james.housden at deutsche-boerse.com (JamesEM) Date: Thu, 12 May 2011 06:11:42 -0700 (PDT) Subject: generate properties code in class dynamically Message-ID: Hello, I have a python class that contains a dictionary. I would like to use python properties to access the elements of the dictionary. This could be achieved as follows: class MyClass(object): def __init__(self): self.d = {} d['field1'] = 1.0 d['field2'] = 'A' d['field3'] = [10.0,20.0,30.0] @property def field1(self): return self.d['field1'] @field1.setter def field1(self, value): self.d['field1'] = value @field1.deleter def field1(self): del self.d['field1'] @property def field2(self): return self.d['field2'] @field1.setter def field2(self, value): self.d['field2'] = value @field1.deleter def field2(self): del self.d['field2'] @property def field3(self): return self.d['field3'] @field3.setter def field3(self, value): self.d['field3'] = value @field3.deleter def field3(self): del self.d['field3'] However, I am effectively writing the same properties code three times. I would prefer to generate the properties code dynamically from the keys of the dictionaries. What I am looking for is something like: class MyClass(object): def __init__(self): self.d = {} d['field1'] = 1.0 d['field2'] = 'A' d['field3'] = [10.0,20.0,30.0] for f in d: create_property(f) where create_property(f) dynamically creates the property code for field f in MyClass. Is this possible? If so, how could I do it? Thanks, James From rosuav at gmail.com Thu May 12 09:20:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 23:20:20 +1000 Subject: checking if a list is empty In-Reply-To: <791t98-659.ln1@svn.schaathun.net> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <791t98-659.ln1@svn.schaathun.net> Message-ID: On Thu, May 12, 2011 at 10:43 PM, Hans Georg Schaathun wrote: > On Thu, 12 May 2011 22:16:10 +1000, Chris Angelico > ? wrote: > : ?Anyone can join. Not everyone wants to join. Me, I'm happy here as a > : ?priest of the software industry, and I have no desire to become a > : ?priest of, say, automotive engineering or concrete pouring. Would an > : ?expert concreter be expected to explain to me exactly how to make > : ?different sorts of concrete, or would he be expected simply to fulfill > : ?his contract and provide me with my structure? > > Of course he would. ?When a piece of software to calculate the > properties or recipes for different kinds of concrete is needed. Writing a program requires expertise both in programming and in the purpose for which it's being written. Ultimately, a programmer is a translator; without proper comprehension of the material he's translating, he can't make a clear translation. But that's completely different from hiring someone to do a job, and then looking at the job afterwards; if I order a concreting job, I'll look at whether it's properly suited to the task, but I won't expect an explanation of exactly what went into it, and I do not expect to understand the exact chemistry of it. Only another expert in concrete would truly comprehend it all. Chris Angelico From genstein at invalid.invalid Thu May 12 09:30:18 2011 From: genstein at invalid.invalid (Genstein) Date: Thu, 12 May 2011 14:30:18 +0100 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: > With 3.2 on winxp, that is what I get with StringIO, text file, and > bytes file (the first two with b's removed). I would expect the same on > any system. If you get anything different, I would consider it a bug Thanks Terry, you're entirely right there; I trimmed down my test case, asked for confirmation and have reported it as http://bugs.python.org/issue12062. Noted here in case anyone else trips over it. From thorsten at thorstenkampe.de Thu May 12 09:38:31 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 12 May 2011 15:38:31 +0200 Subject: Customize help output from optparse (or argparse) Message-ID: Hi, I'm using optparse for a little Python script. 1. The output from "--help" is: """ Usage: script.py script.py does something Options: -h, --help show this help message and exit """ I would prefer to have the description before the usage, like... """ script.py does something Usage: script.py Options: -h, --help show this help message and exit """ 2. The output from "--doesnotexit" is: """ Usage: script.py script.py: error: no such option: --doesnotexist """ I would prefer to have the error first, then the usage and additionally the options, like... """ script.py: error: no such option: --doesnotexist Usage: script.py Options: -h, --help show this help message and exit """ Is that possible with either optparse or the "new kid on the block" argparse. If so how? Thorsten From akabaila at pcug.org.au Thu May 12 09:41:54 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Thu, 12 May 2011 23:41:54 +1000 Subject: list equal to subclass of list? In-Reply-To: References: Message-ID: <201105122341.54998.akabaila@pcug.org.au> On Thursday 12 May 2011 22:23:04 Roy Smith wrote: > I have a vague feeling this may have been discussed a long > time ago, but I can't find the thread, so I'll bring it up > again. > > I recently observed in the "checking if a list is empty" > thread that a list and a subclass of list can compare equal: > > ---------------------------- > class MyList(list): > "I'm a subclass" > > l1 = [] > l2 = MyList() > > print type(l1), type(l2) > print type(l1) == type(l2) > print l1 == l2 > ---------------------------- > > when run, prints: > > > False > True > > The docs say: > > [http://docs.python.org/library/stdtypes.html] > Objects of different types, except different numeric types > and different string types, never compare equal > > [http://docs.python.org/release/2.7/reference/expressions.htm > l#notin] objects of different types (emphasis)always compare > unequal > > In the test code above, l1 an l2 are different types, at > least in the sense that type() returns something different > for each of them. What's the intended behavior here? > Either the code is wrong or the docs are wrong. Subclassing of lists can be tricky, as you have indicated. Here is another simple example: Using Python 3.2, >>> class Array(list): def __init__(self): print(type(self)) temp = [[0,0], [0,0]] print('temp =', temp) self = temp[:] print(type(self), type(temp)) print('self =', self) >>> a = Array() temp = [[0, 0], [0, 0]] self = [[0, 0], [0, 0]] So copying *values* of a list to a subclass of list ( tem[:]) makes converts the subclass back to its parent... The equality of list is rather an ambiguous concept. For instance, a euclidian vector is usually represented by a list of 3 vector components. So if two vectors are of equal length and point in opposite directions, are they equal to each other? The answer is clearly no. The other difficulty is that a list is creted by [], viz. lst = []. So an array has to use the square brackets with great care not to be converted back to a list. Thanks for your nice example and pointers to docs. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Thu May 12 10:02:37 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 07:02:37 -0700 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4DCAF95B.60307@gmail.com> Message-ID: <4DCBE87D.6000300@stoneleaf.us> Chris Angelico wrote: > On Thu, May 12, 2011 at 7:02 AM, Ian wrote: >> In the "real world" lists of zero items do not exist. >> You don't go shopping with a shopping list of zero items. > > Actually, yes you do. You maintain your shopping list between trips; > whenever you need something, you put it on the list immediately. Then > when you go shopping, you just take the list with you (if you're > lucky, you don't need to move or copy it at all, you just get another > reference to it). Once you're done, you empty the list - you now have > a shopping list with zero items (until you get home and realize you > forgot something). Um -- you contradicted Ian, then contradicted yourself -- according to your scenario your shopping list is *not* empty when you go to the store (otherwise known as "going shopping" ;). ~Ethan~ From ayaskanta.swain at altair.com Thu May 12 10:11:00 2011 From: ayaskanta.swain at altair.com (Ayaskanta Swain) Date: Thu, 12 May 2011 19:41:00 +0530 Subject: os.popen command working differently on Windows Message-ID: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> Hi All, Please help me in solving the following issue I am facing while executing my python script. Basically I am executing the OS specific move command to move a file/dir from one location to another. I am executing the 'mv' command on linux & the 'move' DOS command on windows machine from my python script. Everything works fine on linux & windows , but the script fails to detect a particular error situation on Windows, which is very important for my application. Normally the move operation fails if we try to move a directory to a location where the same directory already exists. That means overwriting of directories is not allowed by the OS for move operation. For example on Windows command prompt - "move /Y C:\temp\my_dir C:\stage\profiles\" will fail with Access is Denied message if C:\stage\profiles\ already contains my_dir inside it. It is an expected OS behavior. But the problem is that, this error message is not thrown if the command is executed from a python script. --- filemove.py script has the following code - .................................................. import os src = sys.argv[1] dst = sys.argv[2] # Using the DOS command 'move'. Adding quotes("") to avoid issues with spaces in the path. command = 'move' + ' ' + '/Y' + ' ' + '"' + src + '"' + ' ' + '"' + dst + '"' try: os.popen(command) except IOError: print 'fatal: failed to execute move command' except OSError, err: print >> sys.stderr, "System Error while making a copy from " + src + " to " + dst ........................................................................ .................... The script executes without giving any error msg and returns 0 exit code, but in the back ground the directory is not moved to the destination. I am providing the source & destination values as command line arguments to the script. On Linux this type of use case gives me the OS error message "cannot overwrite directory" which makes it easy for me to catch the error message & return it the end user. But I wonder why is this not the case on Windows. Any help to solve this will be great. Thanks Ayaskant- -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 12 10:13:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 May 2011 00:13:06 +1000 Subject: checking if a list is empty In-Reply-To: <4DCBE87D.6000300@stoneleaf.us> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4DCAF95B.60307@gmail.com> <4DCBE87D.6000300@stoneleaf.us> Message-ID: On Fri, May 13, 2011 at 12:02 AM, Ethan Furman wrote: > Chris Angelico wrote: >> >> On Thu, May 12, 2011 at 7:02 AM, Ian wrote: >>> >>> In the "real world" ?lists of zero items do not exist. >>> You don't go shopping with a shopping list of zero items. >> >> Actually, yes you do. You maintain your shopping list between trips; >> whenever you need something, you put it on the list immediately. Then >> when you go shopping, you just take the list with you (if you're >> lucky, you don't need to move or copy it at all, you just get another >> reference to it). Once you're done, you empty the list - you now have >> a shopping list with zero items (until you get home and realize you >> forgot something). > > Um -- you contradicted Ian, then contradicted yourself -- according to your > scenario your shopping list is *not* empty when you go to the store > (otherwise known as "going shopping" ;). Ehh, mea culpa (I shouldn't post in haste). Replace "Actually, yes you do" with "Actually, yes they do". Indeed you do not *go shopping* with a list of zero items; but a shopping list with no items on it DOES exist (when you come back). def do_shopping(): if shopping_list: goto shop; # Muahahahahaha. for item in shopping_list: inventory.append(item) return; # Muahahahaha again! Chris Angelico From pruebauno at latinmail.com Thu May 12 10:14:36 2011 From: pruebauno at latinmail.com (nn) Date: Thu, 12 May 2011 07:14:36 -0700 (PDT) Subject: generate properties code in class dynamically References: Message-ID: <922112f8-956f-49da-9a95-fd2eccd4911f@l30g2000vbn.googlegroups.com> On May 12, 9:11?am, JamesEM wrote: > Hello, > I have a python class that contains a dictionary. > I would like to use python properties to access the elements of the > dictionary. > This could be achieved as follows: > > class MyClass(object): > > ? ? def __init__(self): > ? ? ? ? self.d = {} > ? ? ? ? d['field1'] = 1.0 > ? ? ? ? d['field2'] = 'A' > ? ? ? ? d['field3'] = [10.0,20.0,30.0] > > ? ? @property > ? ? def field1(self): > ? ? ? ? return self.d['field1'] > > ? ? @field1.setter > ? ? def field1(self, value): > ? ? ? ? self.d['field1'] = value > > ? ? @field1.deleter > ? ? def field1(self): > ? ? ? ? del self.d['field1'] > > ? ? @property > ? ? def field2(self): > ? ? ? ? return self.d['field2'] > > ? ? @field1.setter > ? ? def field2(self, value): > ? ? ? ? self.d['field2'] = value > > ? ? @field1.deleter > ? ? def field2(self): > ? ? ? ? del self.d['field2'] > > ? ? @property > ? ? def field3(self): > ? ? ? ? return self.d['field3'] > > ? ? @field3.setter > ? ? def field3(self, value): > ? ? ? ? self.d['field3'] = value > > ? ? @field3.deleter > ? ? def field3(self): > ? ? ? ? del self.d['field3'] > > However, I am effectively writing the same properties code three > times. > I would prefer to generate the properties code dynamically from the > keys of the dictionaries. > What I am looking for is something like: > > class MyClass(object): > > ? ? def __init__(self): > ? ? ? ? self.d = {} > ? ? ? ? d['field1'] = 1.0 > ? ? ? ? d['field2'] = 'A' > ? ? ? ? d['field3'] = [10.0,20.0,30.0] > ? ? ? ? for f in d: > ? ? ? ? ? ?create_property(f) > > where create_property(f) dynamically creates the property code for > field f in MyClass. > > Is this possible? > If so, how could I do it? > > Thanks, > James Some searching in the cookbook should help. I found this: http://code.activestate.com/recipes/577590-dictionary-whos-keys-act-like-attributes-as-well/ From mail at timgolden.me.uk Thu May 12 10:21:41 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 12 May 2011 15:21:41 +0100 Subject: os.popen command working differently on Windows In-Reply-To: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> References: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> Message-ID: <4DCBECF5.2050908@timgolden.me.uk> On 12/05/2011 15:11, Ayaskanta Swain wrote: > Please help me in solving the following issue I am facing while > executing my python script. Basically I am executing the OS specific > move command to move a file/dir from one location to another. Why? Why not use os.rename or shutil.move which already do whatever is needed under the covers for different Operating Systems? os.popen returns a file-like object from which you can read any error messages generated. You're not doing that, and os.popen won't raise an error itself unless you, say, pass it a number rather than a string. import os output = os.popen ("dir") print output.read () # # But note: # os.popen ("Nonsen*se") # raises no exception TJG From python at mrabarnett.plus.com Thu May 12 10:45:51 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 May 2011 15:45:51 +0100 Subject: os.popen command working differently on Windows In-Reply-To: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> References: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> Message-ID: <4DCBF29F.20801@mrabarnett.plus.com> On 12/05/2011 15:11, Ayaskanta Swain wrote: > Hi All, > > Please help me in solving the following issue I am facing while > executing my python script. Basically I am executing the OS specific > move command to move a file/dir from one location to another. I am > executing the ?mv? command on linux & the ?move? DOS command on windows > machine from my python script. Everything works fine on linux & windows > , but the script fails to detect a particular error situation on > Windows, which is very important for my application. > > Normally the move operation fails if we try to move a directory to a > location where the same directory already exists. That means overwriting > of directories is not allowed by the OS for move operation. > > For example on Windows command prompt ? *?move /Y C:\temp\my_dir > C:\stage\profiles\?* will fail with *Access is Denied* message if > C:\stage\profiles\ already contains my_dir inside it. It is an expected > OS behavior. But the problem is that, this error message is not thrown > if the command is executed from a python script. > > --- > > filemove.py script has the following code ? > > ????????????????.. > > import os > > src = sys.argv[1] > dst = sys.argv[2] > > # Using the DOS command 'move'. Adding quotes("") to avoid issues with spaces in the path. > > command = 'move' + ' ' + '/Y' + ' ' + '"' + src + '"' + ' ' + '"' + dst + '"' > > try: > os.popen(command) > except IOError: > print 'fatal: failed to execute move command' > except OSError, err: > print >> sys.stderr, "System Error while making a copy from " + src + " to " + dst > > ??????????????????????????????.. > > The script executes without giving any error msg and returns 0 exit > code, but in the back ground the directory is not moved to the > destination. I am providing the source & destination values as command > line arguments to the script. > > On Linux this type of use case gives me the OS error message ?cannot > overwrite directory? which makes it easy for me to catch the error > message & return it the end user. But I wonder why is this not the case > on Windows. Any help to solve this will be great. > os.popen(command) will just call the command. If the command fails, its exit code will be non-zero, but that won't make Python raise an exception. os.popen(...) will return an object and you can get the exit code of the command on closing it: p = os.popen(command) exit_code = p.close() On my PC (Windows XP) I get None (not 0) if the command succeeded and 1 if it failed. From up2date.cyborg at gmail.com Thu May 12 11:06:05 2011 From: up2date.cyborg at gmail.com (up2date.cyborg) Date: Thu, 12 May 2011 17:06:05 +0200 Subject: urllib2.urlopen+BadStatusLine+https Message-ID: <4DCBF75D.4020603@gmail.com> Hi, I am new to this list, I don't really know if I should post here my request. Anyway. The following code is raising httplib.BadStatusLine on urllib2.urlopen(url) url = 'https://stat.netaffiliation.com/requete.php?login=xxx&mdp=yyy&debut=2011-05-01&fin=2011-05-12' response = urllib2.urlopen(url) content = response.read() response.close() if the url is http, it doesn't fail, if it's https://www.gmail.com, it doesn't fail neither! someone could help me to make it work. When going to the url using a browser, there is no error. The only thing is that the certificate is signed for another domain. of course, on my real test I replace xxx and yyy, but anyway the error is the same with or without the parameters, even https://stat.netaffiliation.com raises the exception... Thanks! From jorgeromero178 at gmail.com Thu May 12 11:27:46 2011 From: jorgeromero178 at gmail.com (Jorge Romero) Date: Thu, 12 May 2011 11:27:46 -0400 Subject: Python 2.7 Debian 6.0. Squeeze Message-ID: Hi all, My machine is running Debian Squeeze so my default Python runtime is 2.6.6. According to Python docs *optparse* library is deprecated and the development will be moved to *argparse*, which is new in Python 2.7.1. So now that I'm about to write a script that parse command line arguments thought would be a good idea to do the transition right now, besides the good comments about this version. I tried Googling about Python 2.7 on Debian Squeeze, but did not find anything but discussions -.-. Anyone out there that can point me some helpful material or anyone who had luck running 2.7 on Debian? Thanks in advanced. -- Jorge Romero -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericsnowcurrently at gmail.com Thu May 12 11:30:19 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Thu, 12 May 2011 09:30:19 -0600 Subject: list equal to subclass of list? In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 6:23 AM, Roy Smith wrote: > I have a vague feeling this may have been discussed a long time ago, but > I can't find the thread, so I'll bring it up again. > > I recently observed in the "checking if a list is empty" thread that a > list and a subclass of list can compare equal: > > ---------------------------- > class MyList(list): > "I'm a subclass" > > l1 = [] > l2 = MyList() > > print type(l1), type(l2) > print type(l1) == type(l2) > print l1 == l2 > ---------------------------- > > when run, prints: > > > False > True > > The docs say: > > [http://docs.python.org/library/stdtypes.html] > Objects of different types, except different numeric types and different > string types, never compare equal > > [http://docs.python.org/release/2.7/reference/expressions.html#notin] > objects of different types (emphasis)always compare unequal > > That definitely makes it unclear. A little further down it says that you can customize comparison with the __cmp__ special method. You can also override implement other specific comparison special methods, like __eq__ in your classes. So I can definitely see what you mean. In the case of list, a list object has a __eq__ method that it uses for determining equality, rather than using the __eq__ method of the base object type (which behaves as described in your citation). Many of the builtin types have custom special methods for a variety of operators, including comparison. Looking over the documentation, it seems like it could be touched up to alleviate any confusion. Perhaps rewording to make it clear that the described behavior is the default for objects, rather than always the case. -eric > In the test code above, l1 an l2 are different types, at least in the > sense that type() returns something different for each of them. What's > the intended behavior here? Either the code is wrong or the docs are > wrong. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at example.com Thu May 12 11:51:09 2011 From: bob at example.com (Bob Fnord) Date: Thu, 12 May 2011 17:51:09 +0200 Subject: can't get urllib2 or httplib to work with tor & privoxy References: Message-ID: <44ec92ef1af181bd3839228f88c1b78d@msgid.frell.theremailer.net> Chris Angelico wrote: > On Tue, May 10, 2011 at 4:20 AM, Bob Fnord wrote: > > Both methods give me a 503 error... > > As a networking geek, my first thought would be to fire up a tiny > little "snoop server" and see what, exactly, the two methods are > doing. (Ignore the HTTPS options as they're more complicated to snoop > on; you're almost certainly going to see exactly the same on the > HTTP.) > > A snoop server is simply an HTTP server that dumps its requests to > stdout or a file, utterly raw. You can write one in Python fairly > easily, or use another program; if I'm working on Windows, I'll > generally use my own RosMud MUD client, but you'll be able to whip up > a cross-platform one in half a page of code in any decent high level > language. I recommend you work at the sockets level, rather than using > an HTTP library, unless you have one that can emit the entire request, > exactly as it came from the client. > > Once you've found the difference(s) between Lynx and your script, you > can see what's causing the 503 (Service Unavailable) error; it may be > that you need to authenticate with the proxy. Duh, I was doing something else stupid. Thanks but never mind! From roy at panix.com Thu May 12 12:02:09 2011 From: roy at panix.com (Roy Smith) Date: Thu, 12 May 2011 12:02:09 -0400 Subject: list equal to subclass of list? In-Reply-To: References: Message-ID: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> On May 12, 2011, at 11:30 AM, Eric Snow wrote: > On Thu, May 12, 2011 at 6:23 AM, Roy Smith wrote: > The docs say: > > [http://docs.python.org/library/stdtypes.html] > Objects of different types, except different numeric types and different > string types, never compare equal > > [http://docs.python.org/release/2.7/reference/expressions.html#notin] > objects of different types (emphasis)always compare unequal > > > That definitely makes it unclear. I don't think it's unclear at all. It's very clear. Clearly wrong :-) > A little further down it says that you can customize comparison with the __cmp__ special method. Yes, and that says: The operators <, >, ==, >=, <=, and != compare the values of two objects. The objects need not have the same type. If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal, and are ordered consistently but arbitrarily. You can control comparison behavior of objects of non-built-in types by defining a __cmp__ method or rich comparison methods like __gt__, described in section Special method names. I read that as saying that if you implement __eq__(), you must make sure that it returns False if self and other have different types (and likewise, __ne__() should return True for that case). The same way that it says that obj1.__lt__(obj2) must return a consistent result for all types of obj1 and obj2. > Looking over the documentation, it seems like it could be touched up to alleviate any confusion. Perhaps rewording to make it clear that the described behavior is the default for objects, rather than always the case. That would be a start, but doesn't address this specific problem. If the docs are changed to say that "type(obj1) != type(obj2) implies obj1 != obj2" in only the default, people will assume that list follows this default rule since it's a built-in type. Built-in types which don't follow the default rule need to have their behavior documented. --- Roy Smith roy at panix.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jorgeromero178 at gmail.com Thu May 12 12:03:26 2011 From: jorgeromero178 at gmail.com (Jorge Romero) Date: Thu, 12 May 2011 12:03:26 -0400 Subject: Python 2.7 Debian 6.0. Squeeze In-Reply-To: References: Message-ID: Actually came back with some feedback to my own question. The following repositories do the job: # /etc/apt/sources.list deb http://ftp.uk.debian.org/debian/ unstable main contrib non-free deb http://ftp.uk.debian.org/debian/ experimental main contrib non-free deb http://security.debian.org/ testing/updates main contrib $ apt-get update $ apt-get install python2.7 $ python --version Python 2.6.6 $ python2.7 --version Python 2.7.1+ If you need 2.7 as default runtime: $ update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10 This is the first time I need two Python instances, so might helpful for someone in the same position. Any further help feel free to reply. Cheers. On Thu, May 12, 2011 at 11:27 AM, Jorge Romero wrote: > Hi all, > > My machine is running Debian Squeeze so my default Python runtime is 2.6.6. > > According to Python docs *optparse* library is deprecated and the > development will be moved to *argparse*, which is new in Python 2.7.1. So > now that I'm about to write a script that parse command line arguments > thought would be a good idea to do the transition right now, besides the > good comments about this version. > > I tried Googling about Python 2.7 on Debian Squeeze, but did not find > anything but discussions -.-. Anyone out there that can point me some > helpful material or anyone who had luck running 2.7 on Debian? > > Thanks in advanced. > > -- > Jorge Romero > > -- Jorge Romero -------------- next part -------------- An HTML attachment was scrubbed... URL: From vanboxem.ruben at gmail.com Thu May 12 12:14:18 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Thu, 12 May 2011 18:14:18 +0200 Subject: Python enabled gdb on Windows and relocation Message-ID: Hi, I am currently trying to integrate Python support into my toolchain build (including GDB of course). It is a sysrooted binutils+GCC+GDB+mingw-w64 toolchain. I currently have the basic setup working: I can link gdb with my manually generated import lib to the python dll from the official Windows install. If there is anything I am missing or a very easy solution to the problems decsribed below, please just say so. I am only suggesting what I would like to happen. Now on to the problems I'd like to discuss: 1. gdb.exe won't start without me having set PYTHONPATH manually. I understand the need for this, but as gdb requires Python 2, and users of my toolchain may have installed Python 3 or a 32-bit version python they want to use from the same environment (without changing their own PYTHONPATH), there is no way to run python-enabled gdb. What I suggest is perhaps a Windows only change: a kind of "sysroot"ed gdb+python, so that the python used by gdb is truly built in. I cannot require everyone using my toolchain to install the correct python version for obvious reasons (Windows != Linux in this regard). However way this is tackled, the gdb I want should look relative to it's current (relocatable) directory for Python modules/*;py files in a well-defined directory at build time. That would allow me to distribute gdb in a very clear way: /bin /bin/python27.dll /bin/gdb.exe /lib /lib/python27 /lib/python27/ Currently, this scheme only works if I manually set the PYTHONPATH environment variable to /lib/python27. This global environment variable could conflict with existing Python installations, that may have another bitness (I have 64- and 32-bit toolchains). I think you can see there are problems enough with the current set up. I also read this old discussion: http://comments.gmane.org/gmane.comp.gdb.patches/62811 that might imply that the PYTHONPATH check is something built-in to the python dll. Can anyone shed some light on this? 2. With PYTHONPATH set as a temporary workaround, gdb starts, but spits out a traceback: Traceback (most recent call last): File "", line 35, in File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line 18, in gdb.command.pretty_printers.register_pretty_printer_commands() File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", line 368, in register_pretty_printer_commands InfoPrettyPrinter() File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", line 100, in __init__ gdb.COMMAND_DATA) RuntimeError: Could not find command prefix info. This is a minor problem I think, as "python import time" "python print time.clock()" works as expected. What is wrong? Thanks very much! Ruben PS: I've sent this to both the gdb and python mailing lists, as these issues have a large overlap to both projects. PS2: Please reply-to-all as I do not want daily mails from both mailing lists on every issue brought up there. My apologies. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu May 12 12:17:33 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 12 May 2011 10:17:33 -0600 Subject: unicode by default In-Reply-To: <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> Message-ID: On Thu, May 12, 2011 at 1:58 AM, John Machin wrote: > On Thu, May 12, 2011 4:31 pm, harrismh777 wrote: > >> >> So, the UTF-16 UTF-32 is INTERNAL only, for Python > > NO. See one of my previous messages. UTF-16 and UTF-32, like UTF-8 are > encodings for the EXTERNAL representation of Unicode characters in byte > streams. Right. *Under the hood* Python uses UCS-2 (which is not exactly the same thing as UTF-16, by the way) to represent Unicode strings. However, this is entirely transparent. To the Python programmer, a unicode string is just an abstraction of a sequence of code-points. You don't need to think about UCS-2 at all. The only times you need to worry about encodings are when you're encoding unicode characters to byte strings, or decoding bytes to unicode characters, or opening a stream in text mode; and in those cases the only encoding that matters is the external one. From vanboxem.ruben at gmail.com Thu May 12 12:19:55 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Thu, 12 May 2011 18:19:55 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: (now in plain-text as required by gdb mailing list) Hi, I am currently trying to integrate Python support into my toolchain build (including GDB of course). It is a sysrooted binutils+GCC+GDB+mingw-w64 toolchain. I currently have the basic setup working: I can link gdb with my manually generated import lib to the python dll from the official Windows install. If there is anything I am missing or a very easy solution to the problems decsribed below, please just say so. I am only suggesting what I would like to happen. Now on to the problems I'd like to discuss: 1. gdb.exe won't start without me having set PYTHONPATH manually. I understand the need for this, but as gdb requires Python 2, and users of my toolchain may have installed Python 3 or a 32-bit version python they want to use from the same environment (without changing their own PYTHONPATH), there is no way to run python-enabled gdb. What I suggest is perhaps a Windows only change: a kind of "sysroot"ed gdb+python, so that the python used by gdb is truly built in. I cannot require everyone using my toolchain to install the correct python version for obvious reasons (Windows != Linux in this regard). However way this is tackled, the gdb I want should look relative to it's current (relocatable) directory for Python modules/*;py files in a well-defined directory at build time. That would allow me to distribute gdb in a very clear way: /bin /bin/python27.dll /bin/gdb.exe /lib /lib/python27 /lib/python27/ Currently, this scheme only works if I manually set the PYTHONPATH environment variable to /lib/python27. This global environment variable could conflict with existing Python installations, that may have another bitness (I have 64- and 32-bit toolchains). I think you can see there are problems enough with the current set up. I also read this old discussion: http://comments.gmane.org/gmane.comp.gdb.patches/62811 that might imply that the PYTHONPATH check is something built-in to the python dll. Can anyone shed some light on this? 2. With PYTHONPATH set as a temporary workaround, gdb starts, but spits out a traceback: Traceback (most recent call last): ? File "", line 35, in ? File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line 18, in ??? gdb.command.pretty_printers.register_pretty_printer_commands() ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", line 368, in register_pretty_printer_commands ??? InfoPrettyPrinter() ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", line 100, in __init__ ??? gdb.COMMAND_DATA) RuntimeError: Could not find command prefix info. This is a minor problem I think, as "python import time" "python print time.clock()" works as expected. What is wrong? Thanks very much! Ruben PS: I've sent this to both the gdb and python mailing lists, as these issues have a large overlap to both projects. PS2: Please reply-to-all as I do not want daily mails from both mailing lists on every issue brought up there. My apologies. From ethan at stoneleaf.us Thu May 12 12:43:23 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 09:43:23 -0700 Subject: list equal to subclass of list? In-Reply-To: References: Message-ID: <4DCC0E2B.4010803@stoneleaf.us> Roy Smith wrote: > I recently observed in the "checking if a list is empty" thread that a > list and a subclass of list can compare equal: > > ---------------------------- > class MyList(list): > "I'm a subclass" > > l1 = [] > l2 = MyList() > > print type(l1), type(l2) > print type(l1) == type(l2) > print l1 == l2 > ---------------------------- > > when run, prints: > > > False > True > > The docs say: > > [http://docs.python.org/library/stdtypes.html] > Objects of different types, except different numeric types and different > string types, never compare equal This part of the documentation is talking about built-in types, which your MyList is not. > [http://docs.python.org/release/2.7/reference/expressions.html#notin] > objects of different types *always* compare unequal Should probably have the word 'built-in' precede 'types' here, since constructed objects can do whatever they have been told to do. > In the test code above, l1 an l2 are different types, at least in the > sense that type() returns something different for each of them. --> MyList.__mro__ (, , ) MyList is a list -- just a more specific kind of list -- as can be seen from its mro; this is analogous to a square (2 sets of parallel lines joined at 90 degree angles, both sets being the same length) also being a rectangle (2 sets of parallel lines joined at 90 degree angles). > What's the intended behavior here? Either the code is wrong or the docs > are wrong. The code is correct. ~Ethan~ PS Yes, I know my square/rectangle definitions are incomplete, thanks. ;) From robert.kern at gmail.com Thu May 12 13:24:11 2011 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 12 May 2011 12:24:11 -0500 Subject: Slice implementation bug In-Reply-To: References: Message-ID: On 5/12/11 6:06 AM, Tambet wrote: > Hello! > > Let's say slice is multidimensional now - how to interpret it? > > I excpect these to work: > > * m[0, 3] - get one element from matrix > * m[0:2, 0:2] - get four elements from matrix, iterate over them (I have > actually an rtree if it doesn't make sense to you) > > But it won't, because if m[0, 3] returns something, then m[0:2, 0:2] cannot > yield anymore. Let me try to rephrase, since you seem to be leaving out a lot of assumptions. You are trying to say that you want m[0:2,0:2] to return an iterator and that if you define __getitem__() such that m[0,3] returns a value, then you cannot implement __getitem__() to be a generator using a yield statement. Okay. Fine. But there is no reason that __getitem__() needs to be a generator function for you to return an iterator. You can simply return another generator. For example: def __getitem__(self, key): if isinstance(key, tuple): if any(isinstance(x, slice) for x in key): return self._generate_from_slice(key) # The default, boring case. return self._get_value(key) def _generate_from_slice(self, key): yield foo yield bar yield etc > Ofcourse I could return an iterator, but this would not be so simple. Really, it is. -- 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 rurpy at yahoo.com Thu May 12 13:42:44 2011 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 12 May 2011 10:42:44 -0700 (PDT) Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> On 05/12/2011 12:13 AM, Steven D'Aprano wrote: >[snip] > http://www.codinghorror.com/blog/2006/07/separating-programming-sheep-from-non-programming-goats.html > > Shorter version: it seems that programming aptitude is a bimodal > distribution, with very little migration from the "can't program" hump > into the "can program" hump. There does seem to be a simple predictor for > which hump you fall into: those who intuitively develop a consistent > model of assignment (right or wrong, it doesn't matter, so long as it is > consistent) can learn to program. Those who don't, can't. A later paper by the same authors... (http://www.eis.mdx.ac.uk/research/PhDArea/saeed/paper3.pdf) Abstract: [...] Despite a great deal of research into teaching methods and student responses, there have been to date no strong predictors of success in learning to program. Two years ago we appeared to have discovered an exciting and enigmatic new predictor of success in a first programming course. We now report that after six experiments, involving more than 500 students at six institutions in three countries, the predictive effect of our test has failed to live up to that early promise. We discuss the strength of the effects that have been observed and the reasons for some apparent failures of prediction. From ethan at stoneleaf.us Thu May 12 14:29:54 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 11:29:54 -0700 Subject: list equal to subclass of list? In-Reply-To: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> References: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> Message-ID: <4DCC2722.9090003@stoneleaf.us> Roy Smith wrote: > On May 12, 2011, at 11:30 AM, Eric Snow wrote: >> >> That definitely makes it unclear. > > I don't think it's unclear at all. It's very clear. Clearly wrong :-) While it is wrong (it should have 'built-in' precede the word 'types'), it is not wrong in the way you think -- a subclass *is* a type of its superclass. >> A little further down it says that you can customize comparison with >> the __cmp__ special method. > > I read that as saying that if you implement __eq__(), you must make sure > that it returns False if self and other have different types (and > likewise, __ne__() should return True for that case). Your understanding is flawed. If your object does not know how to compare itself to some other object, it should return NotImplemented -- at that point Python will follow the rules outlined in the docs. By returning NotImplemented you are allowing the other object a chance to perform the comparison -- after all, it might know how! :) If the other object also returns NotImplemented then (drum-roll please) they won't compare equal. > The same way that it says that obj1.__lt__(obj2) must return a consistent > result for all types of obj1 and obj2. Where do you see that? I couldn't find it. The point of being able to write your own rich comparison methods is so you can control what happens -- there is no "must" about it. This is Python -- do what you want! :) ~Ethan~ PS I have a broken sense of humor -- sometimes it works, sometimes it doesn't. My apologies in advance if my attempt at humor was not funny. From jean_paez at hotmail.es Thu May 12 15:13:28 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?SmVhbiBDYXJsb3MgUOFleiBSYW3tcmV6?=) Date: Thu, 12 May 2011 14:13:28 -0500 Subject: Hi all. I need aid in creating script to blender. In-Reply-To: References: , , , , Message-ID: Hello. The attached file is script of blender fact in python that .tmb serves to concern archives (secondly attached file), unloadings to blender and uses script and concerns the second file that you shipment you see so that it. Everything can be published and, but it is not possible to be exported again to .tmb To unload in this Link: http://www.blender.org/ script: http://www.mediafire.com/?clmdgkymsfooddd secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 PD: I need script to export in extension .tmb Thanks. Buen d?a comunidad Hola. El archivo adjunto es un script de blender hecho en python que sirve para importar archivos .tmb (http://www.mediafire.com/?clmdgkymsfooddd), descargas blender y usa el script e importa el segundo archivo que te envio para que lo veas (http://www.mediafire.com/?lbmj594ru6r4b67). El se puede editar y todo, pero no se puede exportar de nuevo a .tmb link del script: http://www.mediafire.com/?clmdgkymsfooddd Segundo archivo adjunto: http://www.mediafire.com/?lbmj594ru6r4b67 PD: Necesito el script para exportar en extension .tmb En si necesito ayuda en ese dise?o de un script que exporte de .blend a .tmb Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Thu May 12 15:14:22 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 12 May 2011 14:14:22 -0500 Subject: Proper way to handle errors in a module In-Reply-To: References: Message-ID: <4DCC318E.7020809@gmail.com> On 2011.05.11 01:05 PM, Roy Smith wrote: > You want to raise specific errors. Let's say you've got a function like > this: > > def airspeed(swallow): > speeds = {"european": 42, > "african", 196} > return speeds[swallow] > > If somebody passes an invalid string, it will raise KeyError as written. > Better to do something like: > > def airspeed(swallow): > speeds = {"european": 42, > "african", 196} > try: > return speeds[swallow] > except KeyError: > raise UnknownBirdError(swallow) Is there any way to do this without purposely setting up the code to trigger an arbitrary exception if the function can't do its job? That is, can I raise an UnknownBirdError outside of an except clause, and if so, how? I can't find much help for doing this in Python 3, even in the official docs. From felipe.vinturini at gmail.com Thu May 12 15:23:12 2011 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Thu, 12 May 2011 16:23:12 -0300 Subject: Me ayudas? Hi . I need aid in creating script to blender. In-Reply-To: References: Message-ID: 2011/5/12 Jean Carlos P?ez Ram?rez > Hello. > > The attached file is script of blender fact in python that .tmb serves to > concern archives (secondly attached file), unloadings to blender and uses > script and concerns the second file that you shipment you see so that it. > Everything can be published and, but it is not possible to be exported again > to .tmb > > To unload in this Link: http://www.blender.org/ > script: http://www.mediafire.com/?clmdgkymsfooddd > secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 > > PD: I need script to export in extension .tmb in BLENDER. > > Thanks. > > ------------------------------ > Buen d?a comunidad > > Hola. > > El archivo adjunto es un script de blender hecho en python que sirve para > importar archivos .tmb (http://www.mediafire.com/?clmdgkymsfooddd), > descargas blender y usa el script e importa el segundo archivo que te envio > para que lo veas (http://www.mediafire.com/?lbmj594ru6r4b67). El se puede > editar y todo, pero no se puede exportar de nuevo a .tmb > > > link del script: http://www.mediafire.com/?clmdgkymsfooddd > Segundo archivo adjunto: http://www.mediafire.com/?lbmj594ru6r4b67 > > PD: Necesito el script para exportar en extension .tmb En si necesito ayuda > en ese dise?o de un script que exporte de .blend a .tmb > > > > Gracias. > Hei! If you don't try to do anything, nobody will help you... That's why you didn't have any answer for all your posts! I think you got the point... Sorry. Regads, Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu May 12 15:25:21 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 May 2011 20:25:21 +0100 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC318E.7020809@gmail.com> References: <4DCC318E.7020809@gmail.com> Message-ID: <4DCC3421.9070007@mrabarnett.plus.com> On 12/05/2011 20:14, Andrew Berg wrote: > On 2011.05.11 01:05 PM, Roy Smith wrote: >> You want to raise specific errors. Let's say you've got a function like >> this: >> >> def airspeed(swallow): >> speeds = {"european": 42, >> "african", 196} >> return speeds[swallow] >> >> If somebody passes an invalid string, it will raise KeyError as written. >> Better to do something like: >> >> def airspeed(swallow): >> speeds = {"european": 42, >> "african", 196} >> try: >> return speeds[swallow] >> except KeyError: >> raise UnknownBirdError(swallow) > Is there any way to do this without purposely setting up the code to > trigger an arbitrary exception if the function can't do its job? That > is, can I raise an UnknownBirdError outside of an except clause, and if > so, how? I can't find much help for doing this in Python 3, even in the > official docs. > You can raise an exception wherever you like! :-) From felipe.vinturini at gmail.com Thu May 12 15:34:25 2011 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Thu, 12 May 2011 16:34:25 -0300 Subject: Me ayudas? Hi . I need aid in creating script to blender. In-Reply-To: References: Message-ID: 2011/5/12 Jean Carlos P?ez Ram?rez > To ok there is no problem friend, of all ways thanks, I will see that I > can do, nor in the pages Web of blender they answer to me. > > Thanks friend. > > Regads, > > Jean P. > > ------------------------------ > From: felipe.vinturini at gmail.com > Date: Thu, 12 May 2011 16:23:12 -0300 > Subject: Re: Me ayudas? Hi . I need aid in creating script to blender. > To: jean_paez at hotmail.es > CC: python-list at python.org > > > > 2011/5/12 Jean Carlos P?ez Ram?rez > > Hello. > > The attached file is script of blender fact in python that .tmb serves to > concern archives (secondly attached file), unloadings to blender and uses > script and concerns the second file that you shipment you see so that it. > Everything can be published and, but it is not possible to be exported again > to .tmb > > To unload in this Link: http://www.blender.org/ > script: http://www.mediafire.com/?clmdgkymsfooddd > secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 > > PD: I need script to export in extension .tmb in BLENDER. > > Thanks. > > ------------------------------ > Buen d?a comunidad > > Hola. > > El archivo adjunto es un script de blender hecho en python que sirve para > importar archivos .tmb (http://www.mediafire.com/?clmdgkymsfooddd), > descargas blender y usa el script e importa el segundo archivo que te envio > para que lo veas (http://www.mediafire.com/?lbmj594ru6r4b67). El se puede > editar y todo, pero no se puede exportar de nuevo a .tmb > > > link del script: http://www.mediafire.com/?clmdgkymsfooddd > Segundo archivo adjunto: http://www.mediafire.com/?lbmj594ru6r4b67 > > PD: Necesito el script para exportar en extension .tmb En si necesito ayuda > en ese dise?o de un script que exporte de .blend a .tmb > > > Gracias. > > > Hei! > > If you don't try to do anything, nobody will help you... > > That's why you didn't have any answer for all your posts! > > I think you got the point... > > Sorry. > > Regads, > Felipe. > Ok, no problem! When you have something come back... Also, don't forget to always copy the list on your posts and try no to top post... Regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu May 12 15:37:48 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 15:37:48 -0400 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/11/2011 8:26 AM, Roy Smith wrote: > I conclude that li == [] should have returned False. Either I'm not > understanding things correctly, or this is a bug. The doc is wrong (and not only on this). I am working on a report with suggested fixes. Will post number when finish. -- Terry Jan Reedy From tjreedy at udel.edu Thu May 12 15:44:31 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 15:44:31 -0400 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 5/12/2011 9:30 AM, Genstein wrote: >> With 3.2 on winxp, that is what I get with StringIO, text file, and >> bytes file (the first two with b's removed). I would expect the same on >> any system. If you get anything different, I would consider it a bug > > Thanks Terry, you're entirely right there; I trimmed down my test case, > asked for confirmation and have reported it as > http://bugs.python.org/issue12062. Noted here in case anyone else trips > over it. I want people to know that with a simple, minimal, easy to run and reproduce and think about test case posted, more info, more test cases, and probable fixes were posted within an hour. (Fixes are not always that quick, but stripping away irrelevancies really helps speed the process.) -- Terry Jan Reedy From tjreedy at udel.edu Thu May 12 16:04:07 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 16:04:07 -0400 Subject: generate properties code in class dynamically In-Reply-To: References: Message-ID: On 5/12/2011 9:11 AM, JamesEM wrote: > I would prefer to generate the properties code dynamically from the > keys of the dictionaries. > What I am looking for is something like: > > class MyClass(object): > > def __init__(self): > self.d = {} > d['field1'] = 1.0 > d['field2'] = 'A' > d['field3'] = [10.0,20.0,30.0] > for f in d: > create_property(f) > > where create_property(f) dynamically creates the property code for > field f in MyClass. > > Is this possible? Without actually trying, I am not sure, but I believe maybe (possibly version dependent). The init method is the wrong place. Create the properties exactly once, just after the class is created. It is possible to add functions to classes as attributes (instance methods) after they are created. The property decorators *might* require that they be invoked with the class body, I do not know. I would first try with property(). Assuming dict name 'd' is fixed: def gsd(key): def get(self): return self.d[key] def set(self, value): self.d[key] = value def del(self): del self.d[key] return get,set,del for key in fieldnames: setattr(MyClass, key, property(*gsd(key))) For recent versions, this could be done within a class decorator, but that is only convenient syntactic sugar. -- Terry Jan Reedy From bahamutzero8825 at gmail.com Thu May 12 16:12:39 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 12 May 2011 15:12:39 -0500 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC3421.9070007@mrabarnett.plus.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> Message-ID: <4DCC3F37.3010904@gmail.com> On 2011.05.12 02:25 PM, MRAB wrote: > You can raise an exception wherever you like! :-) If I raise an exception that isn't a built-in exception, I get something like "NameError: name 'HelloError' is not defined". I don't know how to define the exception. From kb1pkl at aim.com Thu May 12 16:20:13 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Thu, 12 May 2011 16:20:13 -0400 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC3F37.3010904@gmail.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> Message-ID: <4DCC40FD.2030907@aim.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/12/2011 04:12 PM, Andrew Berg wrote: > On 2011.05.12 02:25 PM, MRAB wrote: >> You can raise an exception wherever you like! :-) > If I raise an exception that isn't a built-in exception, I get something > like "NameError: name 'HelloError' is not defined". I don't know how to > define the exception. class HelloError(Exception): pass Of course, there are all sorts of other things you could do with your exception. http://docs.python.org/tutorial/errors.html#user-defined-exceptions - -- Corey Richardson -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJNzED9AAoJEAFAbo/KNFvp1uQIAKFaKyD1Q3RL7LGFSmnyRFTK 9XWRH3CSM9mOALccfQ8bUkrquol1fAqhrm4jyOW0scWmsJpRlcb6Rj4HtrmMQOuG DpsUzEZCTnT9Xk80OeTFbpWWBIVBkxdhCxCl75XAP22o5EjhHpgLyqoqMD+81BKH 5/JWAGRJx/9E4BvNWsxIUhb1jlz+XT4H1XykTE1UUOP0uZneWRJMs7P12WNiL2Ii HT0hEUhQc1eP1fJ5BqPB/6/B9q/KxTbN55hCq1VwwfRhgbaM4kR7Bekri7QUHGAK 1MKxRa1v+Co59y+ywAIH92L3wky3xNyFrUlFzK4AwYOnwRkVvUWw7vPG1iShE+k= =2+y6 -----END PGP SIGNATURE----- From PointedEars at web.de Thu May 12 16:22:20 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 12 May 2011 22:22:20 +0200 Subject: Customize help output from optparse (or argparse) References: Message-ID: <2635961.LZWGnKmheA@PointedEars.de> Thorsten Kampe wrote: > I'm using optparse for a little Python script. > > 1. The output from "--help" is: > """ > Usage: script.py > > script.py does something > > Options: > -h, --help show this help message and exit > """ > > I would prefer to have the description before the usage, like... > """ > script.py does something > > Usage: script.py > > Options: > -h, --help show this help message and exit > """ > > 2. The output from "--doesnotexit" is: > """ > Usage: script.py > > script.py: error: no such option: --doesnotexist > """ > > I would prefer to have the error first, then the usage and additionally > the options, like... > """ > script.py: error: no such option: --doesnotexist > > Usage: script.py > > Options: > -h, --help show this help message and exit > """ > > Is that possible with either optparse or the "new kid on the block" > argparse. If so how? You can easily have #1 with optparse.OptionParser(usage="?")?, but optparse is deprecated in favor of argparse.ArgumentParser. I do not think you can have #2 with either optparse or argparse: OptionParser() would print the error message last, and ArgumentParser() would not print the description on error. Subclassing ArgumentParser might be feasible, though. ______ ? -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From tycho at tycho.ws Thu May 12 16:26:27 2011 From: tycho at tycho.ws (Tycho Andersen) Date: Thu, 12 May 2011 15:26:27 -0500 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC3F37.3010904@gmail.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> Message-ID: <20110512202627.GW18269@point.cs.wisc.edu> On Thu, May 12, 2011 at 03:12:39PM -0500, Andrew Berg wrote: > On 2011.05.12 02:25 PM, MRAB wrote: > > You can raise an exception wherever you like! :-) > If I raise an exception that isn't a built-in exception, I get something > like "NameError: name 'HelloError' is not defined". I don't know how to > define the exception. You'll have to define it, as you would anything else (exceptions are just regular "things"; in fact you can raise anything that's a class or instance). I typically don't put a whole lot in my exception classes, though. point:~/working$ python Python 2.6.2 (r262:71600, Jun 8 2009, 11:11:42) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class HelloError(Exception): pass ... >>> raise HelloError("hello!") Traceback (most recent call last): File "", line 1, in __main__.HelloError: hello! \t From python at mrabarnett.plus.com Thu May 12 16:26:55 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 May 2011 21:26:55 +0100 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC3F37.3010904@gmail.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> Message-ID: <4DCC428F.6070002@mrabarnett.plus.com> On 12/05/2011 21:12, Andrew Berg wrote: > On 2011.05.12 02:25 PM, MRAB wrote: >> You can raise an exception wherever you like! :-) > If I raise an exception that isn't a built-in exception, I get something > like "NameError: name 'HelloError' is not defined". I don't know how to > define the exception. Define it as a subclass of Exception: class UnknownBirdError(Exception): pass From bahamutzero8825 at gmail.com Thu May 12 16:35:16 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 12 May 2011 15:35:16 -0500 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC40FD.2030907@aim.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> <4DCC40FD.2030907@aim.com> Message-ID: <4DCC4484.7050509@gmail.com> On 2011.05.12 03:20 PM, Corey Richardson wrote: > class HelloError(Exception): > pass > > Of course, there are all sorts of other things you could do with your > exception. > > http://docs.python.org/tutorial/errors.html#user-defined-exceptions So that's where that info is. I wasn't looking in the tutorial section. Thanks! From PointedEars at web.de Thu May 12 16:36:23 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 12 May 2011 22:36:23 +0200 Subject: Need Assistance on this program. References: <4DCBB18B.5050309@timgolden.me.uk> Message-ID: <5331926.9J7NaK4W3v@PointedEars.de> vijay swaminathan wrote: > I have already done that. But for some reason my response went > as a new thread. Attaching the code again. JFYI: Please DO NOT post attachments in a non-binary newsgroup or to a mailing list (are there binary ones at all?) again. TIA. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From genstein at invalid.invalid Thu May 12 16:38:53 2011 From: genstein at invalid.invalid (Genstein) Date: Thu, 12 May 2011 21:38:53 +0100 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 12/05/2011 20:44, Terry Reedy wrote: > I want people to know that with a simple, minimal, easy to run and > reproduce and think about test case posted, more info, more test cases, > and probable fixes were posted within an hour. (Fixes are not always > that quick, but stripping away irrelevancies really helps speed the > process.) A very good point. I'm extremely impressed with the speed and deftness which the bug was handled once raised. Hats off to the people involved. I should have posted a short test case initially, but I knew it would take some time for me to produce and didn't want to go that far if it was clear to everyone but me that flushes were required by design :) Thanks again, -eg. From karim.liateni at free.fr Thu May 12 16:40:01 2011 From: karim.liateni at free.fr (Karim) Date: Thu, 12 May 2011 22:40:01 +0200 Subject: Customize help output from optparse (or argparse) In-Reply-To: <2635961.LZWGnKmheA@PointedEars.de> References: <2635961.LZWGnKmheA@PointedEars.de> Message-ID: <4DCC45A1.4020305@free.fr> On 05/12/2011 10:22 PM, Thomas 'PointedEars' Lahn wrote: > Thorsten Kampe wrote: > >> I'm using optparse for a little Python script. >> >> 1. The output from "--help" is: >> """ >> Usage: script.py >> >> script.py does something >> >> Options: >> -h, --help show this help message and exit >> """ >> >> I would prefer to have the description before the usage, like... >> """ >> script.py does something >> >> Usage: script.py >> >> Options: >> -h, --help show this help message and exit >> """ >> >> 2. The output from "--doesnotexit" is: >> """ >> Usage: script.py >> >> script.py: error: no such option: --doesnotexist >> """ >> >> I would prefer to have the error first, then the usage and additionally >> the options, like... >> """ >> script.py: error: no such option: --doesnotexist >> >> Usage: script.py >> >> Options: >> -h, --help show this help message and exit >> """ >> >> Is that possible with either optparse or the "new kid on the block" >> argparse. If so how? > You can easily have #1 with optparse.OptionParser(usage="?")?, but optparse > is deprecated in favor of argparse.ArgumentParser. I do not think you can > have #2 with either optparse or argparse: OptionParser() would print the > error message last, and ArgumentParser() would not print the description > on error. Subclassing ArgumentParser might be feasible, though. > > ______ > ? Please find documentation to configure help in ArgumentParser BUT for argparse module: - HelpFormatter, RawDescriptionHelpFormatter, RawTextHelpFormatter, 50 ArgumentDefaultsHelpFormatter -- Formatter classes which 51 may be passed as the formatter_class= argument to the 52 ArgumentParser constructor. HelpFormatter is the default, 53 RawDescriptionHelpFormatter and RawTextHelpFormatter tell the parser 54 not to change the formatting for help text, and 55 ArgumentDefaultsHelpFormatter adds information about argument defaults 56 to the help. So It seems easy to a different pass formatter_class to ArgumentParser. You can inherite from HelpFormater class but you have to know the implementation details: File is located at /lib/python2.7/argparse.py Cheers Karim From ethan at stoneleaf.us Thu May 12 16:40:44 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 13:40:44 -0700 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC3F37.3010904@gmail.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> Message-ID: <4DCC45CC.8040808@stoneleaf.us> Andrew Berg wrote: > On 2011.05.12 02:25 PM, MRAB wrote: >> You can raise an exception wherever you like! :-) > If I raise an exception that isn't a built-in exception, I get something > like "NameError: name 'HelloError' is not defined". I don't know how to > define the exception. class HelloError(Exception): "custom exception" and that's all you need. You can override __init__ to add your own attributes, etc, if you need to. ~Ethan~ From PointedEars at web.de Thu May 12 16:40:55 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 12 May 2011 22:40:55 +0200 Subject: list equal to subclass of list? References: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> Message-ID: <7378643.eNJFYEL58v@PointedEars.de> Ethan Furman wrote: > PS > I have a broken sense of humor -- sometimes it works, sometimes it > doesn't. My apologies in advance if my attempt at humor was not funny. Now that was very unpythonic. Know where your roots are! :) -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From tjreedy at udel.edu Thu May 12 16:42:45 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 16:42:45 -0400 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> Message-ID: On 5/12/2011 12:17 PM, Ian Kelly wrote: > On Thu, May 12, 2011 at 1:58 AM, John Machin wrote: >> On Thu, May 12, 2011 4:31 pm, harrismh777 wrote: >> >>> >>> So, the UTF-16 UTF-32 is INTERNAL only, for Python >> >> NO. See one of my previous messages. UTF-16 and UTF-32, like UTF-8 are >> encodings for the EXTERNAL representation of Unicode characters in byte >> streams. > > Right. *Under the hood* Python uses UCS-2 (which is not exactly the > same thing as UTF-16, by the way) to represent Unicode strings. I know some people say that, but according to the definitions of the unicode consortium, that is wrong! The earlier UCS-2 *cannot* represent chars in the Supplementary Planes. The later (1996) UTF-16, which Python uses, can. The standard considers 'UCS-2' obsolete long ago. See https://secure.wikimedia.org/wikipedia/en/wiki/UTF-16/UCS-2 or http://www.unicode.org/faq/basic_q.html#14 The latter says: "Q: What is the difference between UCS-2 and UTF-16? A: UCS-2 is obsolete terminology which refers to a Unicode implementation up to Unicode 1.1, before surrogate code points and UTF-16 were added to Version 2.0 of the standard. This term should now be avoided." It goes on: "Sometimes in the past an implementation has been labeled "UCS-2" to indicate that it does not support supplementary characters and doesn't interpret pairs of surrogate code points as characters. Such an implementation would not handle processing of character properties, code point boundaries, collation, etc. for supplementary characters." I know that 16-bit Python *does* use surrogate pairs for supplementary chars and at least some properties work for them. I am not sure exactly what the rest means. > However, this is entirely transparent. To the Python programmer, a > unicode string is just an abstraction of a sequence of code-points. > You don't need to think about UCS-2 at all. The only times you need > to worry about encodings are when you're encoding unicode characters > to byte strings, or decoding bytes to unicode characters, or opening a > stream in text mode; and in those cases the only encoding that matters > is the external one. If one uses unicode chars in the Supplementary Planes above the BMP (the first 2**16), which require surrogate pairs for 16 bit unicode (UTF-16), then the abstraction leaks. -- Terry Jan Reedy From roy at panix.com Thu May 12 16:49:00 2011 From: roy at panix.com (Roy Smith) Date: Thu, 12 May 2011 13:49:00 -0700 (PDT) Subject: list equal to subclass of list? References: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> Message-ID: <925edfdd-51c7-400b-af2b-4171779779c8@r35g2000prj.googlegroups.com> On May 12, 2:29?pm, Ethan Furman wrote: > While it is wrong (it should have 'built-in' precede the word 'types'), > it is not wrong in the way you think -- a subclass *is* a type of its > superclass. Well, consider this: class List_A(list): "A list subclass" class List_B(list): "Another list subclass" a = List_A() b = List_B() print a == b It prints "True". Neither a nor b are a type of the other: print isinstance(List_A, List_B) print isinstance(List_B, List_A) False False From ethan at stoneleaf.us Thu May 12 17:48:20 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 14:48:20 -0700 Subject: list equal to subclass of list? In-Reply-To: <925edfdd-51c7-400b-af2b-4171779779c8@r35g2000prj.googlegroups.com> References: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> <925edfdd-51c7-400b-af2b-4171779779c8@r35g2000prj.googlegroups.com> Message-ID: <4DCC55A4.1020303@stoneleaf.us> Roy Smith wrote: > On May 12, 2:29 pm, Ethan Furman wrote: > >> While it is wrong (it should have 'built-in' precede the word 'types'), >> it is not wrong in the way you think -- a subclass *is* a type of its >> superclass. > > Well, consider this: > > class List_A(list): > "A list subclass" > > class List_B(list): > "Another list subclass" > > a = List_A() > b = List_B() > print a == b > > It prints "True". Neither a nor b are a type of the other: > > print isinstance(List_A, List_B) > print isinstance(List_B, List_A) > > False > False Okay, considering: List_A is a user-defined type. List_B is a user-defined type. Both are sub-classes of list. Corrected documentation (which says 'built-in types' etc, etc) says nothing about user-defined types not being able to be equal to each other neither List_A nor List_B have overridden the __eq__ method, so list.__eq__ will be used... conclusion: if they have equal elements in the same order, they will compare equal since they are, in fact, list's Do you not get the same conclusion? ~Ethan~ From tjreedy at udel.edu Thu May 12 18:00:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 18:00:11 -0400 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/12/2011 3:37 PM, Terry Reedy wrote: > On 5/11/2011 8:26 AM, Roy Smith wrote: > >> I conclude that li == [] should have returned False. Either I'm not >> understanding things correctly, or this is a bug. > > The doc is wrong (and not only on this). I am working on a report with > suggested fixes. Will post number when finish. > http://bugs.python.org/issue12067 -- Terry Jan Reedy From ian.g.kelly at gmail.com Thu May 12 18:25:24 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 12 May 2011 16:25:24 -0600 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> Message-ID: On Thu, May 12, 2011 at 2:42 PM, Terry Reedy wrote: > On 5/12/2011 12:17 PM, Ian Kelly wrote: >> Right. ?*Under the hood* Python uses UCS-2 (which is not exactly the >> same thing as UTF-16, by the way) to represent Unicode strings. > > I know some people say that, but according to the definitions of the unicode > consortium, that is wrong! The earlier UCS-2 *cannot* represent chars in the > Supplementary Planes. The later (1996) UTF-16, which Python uses, can. The > standard considers 'UCS-2' obsolete long ago. See > > https://secure.wikimedia.org/wikipedia/en/wiki/UTF-16/UCS-2 > or http://www.unicode.org/faq/basic_q.html#14 At the first link, in the section _Use in major operating systems and environments_ it states, "The Python language environment officially only uses UCS-2 internally since version 2.1, but the UTF-8 decoder to "Unicode" produces correct UTF-16. Python can be compiled to use UCS-4 (UTF-32) but this is commonly only done on Unix systems." PEP 100 says: The internal format for Unicode objects should use a Python specific fixed format implemented as 'unsigned short' (or another unsigned numeric type having 16 bits). Byte order is platform dependent. This format will hold UTF-16 encodings of the corresponding Unicode ordinals. The Python Unicode implementation will address these values as if they were UCS-2 values. UCS-2 and UTF-16 are the same for all currently defined Unicode character points. UTF-16 without surrogates provides access to about 64k characters and covers all characters in the Basic Multilingual Plane (BMP) of Unicode. It is the Codec's responsibility to ensure that the data they pass to the Unicode object constructor respects this assumption. The constructor does not check the data for Unicode compliance or use of surrogates. I'm getting out of my depth here, but that implies to me that while Python stores UTF-16 and can correctly encode/decode it to UTF-8, other codecs might only work correctly with UCS-2, and the unicode class itself ignores surrogate pairs. Although I'm not sure how much this might have changed since the original implementation, especially for Python 3. From weichen302 at aol.com Thu May 12 19:18:23 2011 From: weichen302 at aol.com (Chen Wei) Date: Fri, 13 May 2011 07:18:23 +0800 Subject: Python 2.7 Debian 6.0. Squeeze In-Reply-To: References: Message-ID: <20110512231823.GA6528@Tungsten.DarkStar> On Thu, May 12, 2011 at 12:03:26PM -0400, Jorge Romero wrote: > Actually came back with some feedback to my own question. > > The following repositories do the job: > # /etc/apt/sources.list > deb http://ftp.uk.debian.org/debian/ unstable main contrib non-free > deb http://ftp.uk.debian.org/debian/ experimental main contrib non-free > deb http://security.debian.org/ testing/updates main contrib python2.7 is included in debian testing, so point the sources.list to testing instead of unstable or experimental should also works. deb http://ftp.uk.debian.org/debian/ testing main contrib non-free > $ apt-get update > $ apt-get install python2.7 > $ python --version > Python 2.6.6 > $ python2.7 --version > Python 2.7.1+ > -- Chen Wei From amannijhawan at gmail.com Thu May 12 19:29:57 2011 From: amannijhawan at gmail.com (Aman Nijhawan) Date: Thu, 12 May 2011 16:29:57 -0700 Subject: Peculiar Behaviour of __builtins__ Message-ID: I was trying to call the builtin function min by using getattr(__builtins__,'min') This works at the interpretter prompt However when I called it inside a module that was imported by another module it fails and gives an attribute error print getattr(__builtins__,'min')(range(20)) AttributeError: 'dict' object has no attribute 'min' Also in the interpreter >>>type(__builtins__) but in my module print type(__builtins__) Can anyone help me understand whats going on here? Thanks -- Aman Nijhawan -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu May 12 20:16:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2011 00:16:30 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> Message-ID: <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 May 2011 07:36:27 -0400, Roy Smith wrote: > In article <931adaF9g1U1 at mid.individual.net>, > Gregory Ewing wrote: > >> Roy Smith wrote: >> >>If both are numbers, they are converted to a common type. Otherwise, >> >>objects of different types always compare unequal >> >> That's just the default treatment for unrelated types that don't know >> anything about each other. >> >> I would guess that the list's == method is asking "Is the other object >> a list?", and since a subclass of list is also a list, it's happy and >> goes on to compare the elements. > > Well, that explains what's happening, but the behavior still doesn't > match the docs. Is this a bug or are the docs wrong? The docs are incomplete. You are missing two facts: * The docs you are quoting refer only to built-in types. That it doesn't make so clear is a documentation bug. * Talking about "different" and "same" types is ambiguous. It depends on how you compare types: type(a) is type(b) isinstance(a, type(b)) You are reading the docs as if the first comparison is the way to do it, but the second is usually preferred. Any time you read something about "the same type", you should mentally add "(or an instance of a sub-class)" to it, unless explicitly told different. Whether it is better to add that parenthetical comment every time it is needed, or to assume that the read knows enough about object- oriented programming to assume it, is an open question. Me personally, I think it's part of the mental landscape that can be assumed, like C docs might state "dereference the pointer" without adding "(unless it is a nul pointer)" *every single time*. -- Steven From steve+comp.lang.python at pearwood.info Thu May 12 20:18:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2011 00:18:01 GMT Subject: list equal to subclass of list? References: Message-ID: <4dcc78b8$0$29980$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 May 2011 09:43:23 -0700, Ethan Furman wrote: > MyList is a list -- just a more specific kind of list -- as can be seen > from its mro; this is analogous to a square (2 sets of parallel lines > joined at 90 degree angles, both sets being the same length) also being > a rectangle (2 sets of parallel lines joined at 90 degree angles). Possibly the worst analogy ever! *wink* http://en.wikipedia.org/wiki/Circle-ellipse_problem Also known as the square-rectangle problem. A better analogy might be, Lassie is a dog, and Flipper is a dolphin, so they are different types of animal. But both dogs and dolphins are mammals, so in that sense, Lassie and Flipper are both mammals and therefore the same type of animal. It depends on what you mean by "type". -- Steven From steve+comp.lang.python at pearwood.info Thu May 12 20:43:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2011 00:43:06 GMT Subject: Proper way to handle errors in a module References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> Message-ID: <4dcc7e9a$0$29980$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 May 2011 15:26:27 -0500, Tycho Andersen wrote: > On Thu, May 12, 2011 at 03:12:39PM -0500, Andrew Berg wrote: >> On 2011.05.12 02:25 PM, MRAB wrote: >> > You can raise an exception wherever you like! :-) >> If I raise an exception that isn't a built-in exception, I get >> something like "NameError: name 'HelloError' is not defined". I don't >> know how to define the exception. > > You'll have to define it, as you would anything else (exceptions are > just regular "things"; in fact you can raise anything that's a class or > instance). Not quite. >>> raise 42 Traceback (most recent call last): File "", line 1, in TypeError: exceptions must be classes or instances, not int Not a very good error message, because 42 is an instance! >>> isinstance(42, int) True In Python 3, you get a better error message, and further restrictions on what you can raise: >>> raise 42 Traceback (most recent call last): File "", line 1, in TypeError: exceptions must derive from BaseException In general, you should always subclass Exception rather than BaseException. There are, er, exceptions, but for error-handling you normally should inherit from Exception directly, or some sub-class like ValueError, KeyError, etc. -- Steven From ben+python at benfinney.id.au Thu May 12 20:56:14 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 13 May 2011 10:56:14 +1000 Subject: Proper way to handle errors in a module References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> <4DCC40FD.2030907@aim.com> Message-ID: <87r583ifkh.fsf@benfinney.id.au> Andrew Berg writes: > So that's where that info is. I wasn't looking in the tutorial > section. Does this mean you haven't worked through the tutorial? Time to remedy that. -- \ ?You are welcome to visit the cemetery where famous Russian and | `\ Soviet composers, artists, and writers are buried daily except | _o__) Thursday.? ?Russian orthodox monastery, Moscow | Ben Finney From ethan at stoneleaf.us Thu May 12 21:04:20 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 18:04:20 -0700 Subject: list equal to subclass of list? In-Reply-To: <4dcc78b8$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4dcc78b8$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCC8394.60307@stoneleaf.us> Steven D'Aprano wrote: > On Thu, 12 May 2011 09:43:23 -0700, Ethan Furman wrote: > >> MyList is a list -- just a more specific kind of list -- as can be seen >> from its mro; this is analogous to a square (2 sets of parallel lines >> joined at 90 degree angles, both sets being the same length) also being >> a rectangle (2 sets of parallel lines joined at 90 degree angles). > > Possibly the worst analogy ever! *wink* > > http://en.wikipedia.org/wiki/Circle-ellipse_problem > > Also known as the square-rectangle problem. > > A better analogy might be, Lassie is a dog, and Flipper is a dolphin, so > they are different types of animal. But both dogs and dolphins are > mammals, so in that sense, Lassie and Flipper are both mammals and > therefore the same type of animal. It depends on what you mean by "type". I thought about using the mammal analogy instead, but geometry seemed simpler. *sigh* Oh, well, can't win 'em all! ~Ethan~ From roy at panix.com Thu May 12 21:53:05 2011 From: roy at panix.com (Roy Smith) Date: Thu, 12 May 2011 21:53:05 -0400 Subject: list equal to subclass of list? References: Message-ID: In article , Ethan Furman wrote: > > [http://docs.python.org/library/stdtypes.html] > > Objects of different types, except different numeric types and different > > string types, never compare equal > > This part of the documentation is talking about built-in types, which > your MyList is not. > > > > [http://docs.python.org/release/2.7/reference/expressions.html#notin] > > objects of different types *always* compare unequal > > Should probably have the word 'built-in' precede 'types' here, since > constructed objects can do whatever they have been told to do. Changing the docs (in numerous places) to make it clear that this is only true of built-in types would indeed resolve the problem. As it reads now, it's a general statement about ALL types, built-in or user-defined. From gagsl-py2 at yahoo.com.ar Thu May 12 21:59:24 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 12 May 2011 22:59:24 -0300 Subject: Peculiar Behaviour of __builtins__ References: Message-ID: En Thu, 12 May 2011 20:29:57 -0300, Aman Nijhawan escribi?: > I was trying to call the builtin function min by using > getattr(__builtins__,'min') > > This works at the interpretter prompt > > However when I called it inside a module that was imported by another > module > it fails and gives an attribute error __builtins__ (note the final 's') is an implementation detail. You want the __builtin__ (no 's') module, renamed 'builtin' in Python 3.x py> import __builtin__ py> builtin_min = __builtin__.min py> builtin_min([8,2,5]) 2 See http://docs.python.org/library/__builtin__.html Note: using getattr with a literal name is not so useful. Better to use dot notation. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu May 12 22:02:02 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 12 May 2011 23:02:02 -0300 Subject: Peculiar Behaviour of __builtins__ References: Message-ID: En Thu, 12 May 2011 22:59:24 -0300, Gabriel Genellina escribi?: > En Thu, 12 May 2011 20:29:57 -0300, Aman Nijhawan > escribi?: > >> I was trying to call the builtin function min by using >> getattr(__builtins__,'min') >> >> This works at the interpretter prompt >> >> However when I called it inside a module that was imported by another >> module >> it fails and gives an attribute error > > __builtins__ (note the final 's') is an implementation detail. You want > the __builtin__ (no 's') module, renamed 'builtin' in Python 3.x Should read "...renamed 'builtins' in Python 3.x, just to add to the confusion." :) -- Gabriel Genellina From rustompmody at gmail.com Thu May 12 23:53:19 2011 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 13 May 2011 09:23:19 +0530 Subject: Non Programming in python In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: On Wed, May 11, 2011 at 5:57 PM, Calvin Spealman wrote: > If this is the "non-programming side of python" then maybe some of us have > a lacking definition of what "programming" is. My mechanic stilll has to > check the tire pressure and I need to update the version number in PyPI. > O well you dont like the term 'non-programming'? As I said neither do I... On May 10, 2011 12:46 PM, "rusi" wrote: > > Sorry for a silly subject change: A better one will be welcome -- cant > think of a name myself. > > Maybe another way of describing this list may be 1. Programming from 'inside' or 'under' python and 2. The rest of it which is outside/surrounding the python interpreter Because 1 is mostly called 'programming' and 2 has no name, 2 gets neglected more than it should. Or take any python book and browse the contents. What will you find? Python data structures, Python control structures, OOP in python, advanced function topics, scopes, modules, exceptions etc -- almost all the 'inside' stuff well organized, with the outside stuff strewn around in hard-to-find corners of the index (if at all). Does that reflect the reality of python's actual learning curve? -------------- next part -------------- An HTML attachment was scrubbed... URL: From swavijay at gmail.com Fri May 13 01:22:54 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Fri, 13 May 2011 10:52:54 +0530 Subject: Need Assistance on this program. In-Reply-To: <4DCBB88A.8020702@timgolden.me.uk> References: <4DCBB18B.5050309@timgolden.me.uk> <4DCBB88A.8020702@timgolden.me.uk> Message-ID: Hi Tim., Thanks.. This works as I had expected. are there any documentation for the subprocess.call method? I tried going through the python doc but could not narrow down. I just wanted to know how do I pass an arguement after invoking the command prompt? Any thoughts on this pls? On Thu, May 12, 2011 at 4:08 PM, Tim Golden wrote: > On 12/05/2011 11:29, vijay swaminathan wrote: > > <... snippet from code ...> > print 'Invoking Command Promptt..............' > #subprocess.call(["start", "/DC:\\PerfLocal_PAL", > "scripts_to_execute.bat"], shell=True) > subprocess.call(["start", "C:\\windows\\system32\\cmd.exe"], shell = > True) > self.status() > > > If you want to use start, use start /wait. > > But you don't have to: > > > import threading > import time > import subprocess > > def run_command (command): > # > # .call is shorthand for: start process and wait > # CREATE_NEW_CONSOLE prevents it from getting messed > # up with the Python console > # > subprocess.call ( > [command], > creationflags=subprocess.CREATE_NEW_CONSOLE > ) > > t = threading.Thread (target=run_command, args=("cmd.exe",)) > t.start () > > while t.is_alive (): > print "alive" > time.sleep (0.5) > > print "Thread is dead" > > > > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From james.housden at deutsche-boerse.com Fri May 13 01:45:10 2011 From: james.housden at deutsche-boerse.com (JamesEM) Date: Thu, 12 May 2011 22:45:10 -0700 (PDT) Subject: generate properties code in class dynamically References: Message-ID: <9d949617-f4f0-4421-8de7-f283861995ac@t19g2000yql.googlegroups.com> On May 12, 10:04?pm, Terry Reedy wrote: > On 5/12/2011 9:11 AM, JamesEM wrote: > > > > > I would prefer to generate the properties code dynamically from the > > keys of the dictionaries. > > What I am looking for is something like: > > > class MyClass(object): > > > ? ? ?def __init__(self): > > ? ? ? ? ?self.d = {} > > ? ? ? ? ?d['field1'] = 1.0 > > ? ? ? ? ?d['field2'] = 'A' > > ? ? ? ? ?d['field3'] = [10.0,20.0,30.0] > > ? ? ? ? ?for f in d: > > ? ? ? ? ? ? create_property(f) > > > where create_property(f) dynamically creates the property code for > > field f in MyClass. > > > Is this possible? > > Without actually trying, I am not sure, but I believe maybe (possibly > version dependent). The init method is the wrong place. Create the > properties exactly once, just after the class is created. It is possible > to add functions to classes as attributes (instance methods) after they > are created. The property decorators *might* require that they be > invoked with the class body, I do not know. I would first try with > property(). > > Assuming dict name 'd' is fixed: > > def gsd(key): > ? ?def get(self): > ? ? ?return self.d[key] > ? ?def set(self, value): > ? ? ?self.d[key] = value > ? ?def del(self): > ? ? ?del self.d[key] > ? ?return get,set,del > > for key in fieldnames: > ? ?setattr(MyClass, key, property(*gsd(key))) > > For recent versions, this could be done within a class decorator, but > that is only convenient syntactic sugar. > > -- > Terry Jan Reedy Thanks for your help. I tried the above for get and set which worked as desired. However, the del did not seem to work for me (using python 2.6.5). I hope I did not mistype anything, but it objects to def del with a syntax error. I guess because del is a reserved word. James From wxjmfauth at gmail.com Fri May 13 02:28:09 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 12 May 2011 23:28:09 -0700 (PDT) Subject: unicode by default References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> Message-ID: <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> On 12 mai, 18:17, Ian Kelly wrote: > ... > to worry about encodings are when you're encoding unicode characters > to byte strings, or decoding bytes to unicode characters A small but important correction/clarification: In Unicode, "unicode" does not encode a *character*. It encodes a *code point*, a number, the integer associated to the character. jmf From rustompmody at gmail.com Fri May 13 02:46:12 2011 From: rustompmody at gmail.com (rusi) Date: Thu, 12 May 2011 23:46:12 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mathematics has existed for millenia. Hindu-arabic numerals (base-10 numbers) have been known for about one millennium The boolean domain is only a 100 years old. Unsurprisingly it is not quite 'first-class' yet: See http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html [Lifted from http://c2.com/cgi/wiki?EqualVsTrueFalse ] ---------------------------- "In retrospect, one might be tempted to regard the introduction of something as simple as the boolean domain as a minor invention, but I think that that would be a grave mistake: it is a great invention because, being so simple, it is such a powerful simplifier. It is of the same level as the introduction of natural numbers, which enabled us to add 3 to 5, regardless of whether we are adding apples or pears." "George Boole made a radical invention, so radical, in fact, that now, more than a century later, the scientific community has not absorbed it yet. (To stay with the metaphor: officially, boolean expressions may have reached the status of first-class citizens, in practice ? because old habits and prejudices die hard? they are still the victims of discrimination.) Let me give you a few examples." "In the programming language FORTRAN, as conceived a century after Boole published his invention, boolean expressions are allowed, but there are no boolean variables! Their introduction into programming had to wait until the design of ALGOL 60." ------------------------ So, M Harris problem is that python could almost be a language for the 'masses' (whatever that might mean) were it not for warts like "l not is empty" is shorten-able to just "l" Dijkstra's problem (paraphrased) is that python, by choosing the FORTRAN alternative of having a non-first-class boolean type, hinders scientific/mathematical thinking/progress. I tend to agree with Dijkstra's view that the boolean type should be given more respect except for the small fact that the computer's ALU is based on the logic-arithmetic pun: half-adder = xor (half)-carry = and From mail at timgolden.me.uk Fri May 13 03:40:10 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 May 2011 08:40:10 +0100 Subject: Need Assistance on this program. In-Reply-To: References: <4DCBB18B.5050309@timgolden.me.uk> <4DCBB88A.8020702@timgolden.me.uk> Message-ID: <4DCCE05A.2070600@timgolden.me.uk> On 13/05/2011 06:22, vijay swaminathan wrote: > Hi Tim., > > Thanks.. This works as I had expected. > > are there any documentation for the subprocess.call method? I tried > going through the python doc but could not narrow down. http://docs.python.org/library/subprocess.html?highlight=subprocess%20call#subprocess.call > I just wanted to > know how do I pass an arguement after invoking the command prompt? Well, now, that's a whole 'nother can of worms :) The more so since you're relying on a command prompt. Can I suggest you read around the Popen.communicate method: http://docs.python.org/library/subprocess.html?highlight=subprocess%20call#subprocess.Popen.communicate and some of the examples below and try something out for yourself. It can be a little bit fiddly, but you'll do better if you get something up-and-running (or up-and-failing) and then ask for advice on where you're going wrong. TJG From clp2 at rebertia.com Fri May 13 04:02:07 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 13 May 2011 01:02:07 -0700 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 at 11:46 PM, rusi wrote: > The boolean domain is only a 100 years old. > Unsurprisingly it is not quite 'first-class' yet: See It is nowadays. Every halfway-mainstream language I can think of has an explicit boolean datatype. Heck, as of C99, even C has one now. I conjecture the only languages still lacking one are exotic niche/fringe languages. I would be interested to see a counterexample. > http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > [Lifted from http://c2.com/cgi/wiki?EqualVsTrueFalse ] > > ---------------------------- > "In retrospect, one might be tempted to regard the introduction of > something as simple as the boolean domain as a minor invention, but I > think that that would be a grave mistake: it is a great invention > because, being so simple, it is such a powerful simplifier. It is of > the same level as the introduction of natural numbers, which enabled > us to add 3 to 5, regardless of whether we are adding apples or > pears." > > "George Boole made a radical invention, so radical, in fact, that now, > more than a century later, the scientific community has not absorbed > it yet. (To stay with the metaphor: officially, boolean expressions > may have reached the status of first-class citizens, in practice ? > because old habits and prejudices die hard? they are still the victims > of discrimination.) Let me give you a few examples." > > "In the programming language FORTRAN, as conceived a century after > Boole published his invention, boolean expressions are allowed, but > there are no boolean variables! Their introduction into programming > had to wait until the design of ALGOL 60." > > ------------------------ > So, M Harris problem is that python could almost be a language for the > 'masses' (whatever that might mean) were it not for warts like "l not > is empty" is shorten-able to just "l" One language's wart is another language's idiom. And I think the irrational hate towards syntactically-significant indentation is by far a much larger barrier to "mass" adoption of Python; C++ has some features that are at least (if not more) subtle/unobvious than Python's __bool__(), yet it still enjoys "mass" use. > Dijkstra's problem (paraphrased) is that python, by choosing the > FORTRAN alternative of having a non-first-class boolean type, hinders > scientific/mathematical thinking/progress. Python has *not* chosen the Fortran alternative; *it has a first-class Boolean type*, namely bool. This line of argument thus fails. The fact that other types are implicitly coercible to bools doesn't make `bool` itself any less first-class. It is also ironic that one of the projects that exploits Python's flexible typing regarding normally-Boolean operators is a scientific one (NumPy). Cheers, Chris -- http://rebertia.com From hg at schaathun.net Fri May 13 04:47:50 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Fri, 13 May 2011 09:47:50 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <791t98-659.ln1@svn.schaathun.net> Message-ID: On Thu, 12 May 2011 23:20:20 +1000, Chris Angelico wrote: : Writing a program requires expertise both in programming and in the : purpose for which it's being written. Ultimately, a programmer is a : translator; without proper comprehension of the material he's : translating, he can't make a clear translation. But that's completely : different from hiring someone to do a job, and then looking at the job : afterwards; True. When you are able completely to specify the job and commission it, then it is possible to isolate the disciplines, and reduce the programmer to translator. The challenge is that that very often is not the case. The double challenge in computing is that software its development is still not as well understood as hardware or construction. We still do not have sufficient tools, experience and frameworks to project and precisely plan a software development projects. They go over time, over budget, and under specifications far more often and more seriously than projects in other disciplines. Civil and electronic engineers spend much of their time learning to project and cost solutions. Computer engineers very rarely do; they just hack it. In other trades, there tend to be clear role divisions with different roles and specialisations, complementing eachothers. We have not yet quite managed to work out what a programmer, architect, designer, engineer, et cetera are in software. We have the idea that we need them, but we have not formalised them to the point where we know what to expect from each role, and we struggle communicating between them. Therefore, a programmer is not just a translator. The language to specify precisely what is required is not good enough, and therefor the programmer also needs to be a system designer, to some extent. What extent depends much on the situation. >From my point of view, it is just harder to instruct a programmer to write a code than it is to instruct a python interpreter. : if I order a concreting job, I'll look at whether it's : properly suited to the task, but I won't expect an explanation of : exactly what went into it, and I do not expect to understand the exact : chemistry of it. Only another expert in concrete would truly : comprehend it all. Now you are thinking black and white, while reality is a gray blur. You may not care about your concrete, but someone commissioning concrete to build a skyscraper would surely want to check the spec's to quite some level of detail. The construction engineers will surely need to know a lot more about the exact composition and science behind the recipe than the manager renting the top floor, and still much less than the concrete engineer. And the main difference here, is that the civil engineers have a much better language to share information. The best programmers have is the programmming language, and we ought to make that as good as possible. -- :-- Hans Georg From nobody at nowhere.com Fri May 13 04:48:52 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 13 May 2011 09:48:52 +0100 Subject: os.popen command working differently on Windows References: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> Message-ID: On Thu, 12 May 2011 15:21:41 +0100, Tim Golden wrote: > os.popen returns a file-like object from which you can read any error > messages generated. The documentation doesn't say, but if it's anything like the Unix popen() function, with mode='r' the returned file-like object will correspond to the child's stdout, but error messages will normally be written to stderr. In any case, os.popen() and similar are deprecated in favour of subprocess.Popen(). From saeedullah at gmail.com Fri May 13 05:33:29 2011 From: saeedullah at gmail.com (saeed) Date: Fri, 13 May 2011 02:33:29 -0700 (PDT) Subject: Call for Papers (CFP) Message-ID: <3afe5ec5-5ff9-436f-92c4-70ce85daff31@r27g2000prr.googlegroups.com> ========================================================= Journal of Emerging Trends in Computing and Information Sciences Call for Research Papers (Vol. 2 No. 6) June 2011 http://cisjournal.org/ ========================================================= Dear Sir/ Madam, Journal of Emerging Trends in Computing and Information Sciences (E- ISSN 2218-6301/ ISSN 2079-8407) is an international refereed research publishing journal, focused on promoting and publishing original high quality research work in both theoretical and scientific aspects of all disciplines of Computing and Information Sciences. The objectives of the journal are to promote and publish original high quality research and to provide a forum to the researchers and industry practitioners for exchanging ideas, knowledge, and experience. We welcome original research and industry experience papers. Contributions should be written for one of the following categories: Original research Literature Review / Systematic Literature Review Short Articles on ongoing research Preliminary Findings Technical Reports / Notes Results previously published in conferences and/or journals may be submitted as extended versions. For more information about Journal and Publication Charges, please visit http://www.cisjournal.org/. You are requested to circulate this message among your colleagues and college/university fellows. Sincerely Yours, Editor Journal of Emerging Trends in Computing and Information Sciences URL: http://www.cisjournal.org E-mail:editor at cisjournal.org From balle at chaostal.de Fri May 13 06:19:01 2011 From: balle at chaostal.de (Bastian Ballmann) Date: Fri, 13 May 2011 12:19:01 +0200 Subject: Parsing a graph image Message-ID: <20110513121901.7ff67dd1@chaostal.de> Hi python lovers out there, I am searching for a library to parse data from a graph in an image file something like http://pytseries.sourceforge.net/_images/yahoo.png Any suggestions, hints, links? TIA && have a nice day! :) Basti -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From rustompmody at gmail.com Fri May 13 06:58:44 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 13 May 2011 03:58:44 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ebe45e2-9f6c-4f2c-b641-647490a75888@y27g2000prb.googlegroups.com> On May 13, 1:02?pm, Chris Rebert wrote: > On Thu, May 12, 2011 at 11:46 PM, rusi wrote: > > > The boolean domain is only a 100 years old. > > Unsurprisingly it is not quite 'first-class' yet: See > > It is nowadays. Every halfway-mainstream language I can think of has > an explicit boolean datatype. I guess you did not quite see my 'quite' -- which itself is a summarization of Dijkstra's "officially" vs "in practice" ? [Heres the quote] > >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > > [Lifted fromhttp://c2.com/cgi/wiki?EqualVsTrueFalse] > > > ---------------------------- > > "In retrospect, one might be tempted to regard the introduction of > > something as simple as the boolean domain as a minor invention, but I > > think that that would be a grave mistake: it is a great invention > > because, being so simple, it is such a powerful simplifier. It is of > > the same level as the introduction of natural numbers, which enabled > > us to add 3 to 5, regardless of whether we are adding apples or > > pears." > > > "George Boole made a radical invention, so radical, in fact, that now, > > more than a century later, the scientific community has not absorbed > > it yet. (To stay with the metaphor: officially, boolean expressions > > may have reached the status of first-class citizens, in practice ? > > because old habits and prejudices die hard? they are still the victims > > of discrimination.) Let me give you a few examples." > > > "In the programming language FORTRAN, as conceived a century after > > Boole published his invention, boolean expressions are allowed, but > > there are no boolean variables! Their introduction into programming > > had to wait until the design of ALGOL 60." As an analogy, in Perl, a list can get coerced to its length "... when in scalar context.." or something like that. Most programmers from the static-typechecked-languages camp would balk at that laissez faire attitude. Likewise Harris is pointing out that noob python programmers may feel a bit unnerved by non-boolean types unexpectedly showing 'boolean-ness.' Maybe we are just more in noob category and we've not got the zen of python?? Dunno... From swavijay at gmail.com Fri May 13 07:03:07 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Fri, 13 May 2011 16:33:07 +0530 Subject: Assistance in understanding the sub-Process module Message-ID: Hi Gurus, I'm new to Python programming and in the process of learning the sub process module. I went through the python documentation http://docs.python.org/library/subprocess.html and I have the following queries 1. The class definition as per the documentation is: *class *subprocess.Popen(*args*, *bufsize=0*, *executable=None*, *stdin=None *, *stdout=None*, *stderr=None*, *preexec_fn=None*, *close_fds=False*, * shell=False*, *cwd=None*, *env=None*, *universal_newlines=False*, * startupinfo=None*, *creationflags=0*) *args* should be a string, or a sequence of program arguments. so I assume that args can be a string or a list with first item of the list being the program to execute. so on the python IDLE, I executed this command, >>> subprocess.Popen('cmd.exe') which opened up a command prompt. when I give this as a list, as below it throwed this error. >>> subprocess.Popen(['cmd.exe', 'dir']) Traceback (most recent call last): File "", line 1, in subprocess.Popen(['cmd.exe' 'dir']) File "C:\Python26\lib\subprocess.py", line 623, in __init__ errread, errwrite) File "C:\Python26\lib\subprocess.py", line 833, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified >>> I would assume that a list is accepted as part of the args and first being the program (cmd.exe) and the rest being the arguments... please correct me If i misunderstood. Thanks, -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri May 13 07:11:33 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 13 May 2011 04:11:33 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> Message-ID: On May 12, 3:06?am, Hans Mulder wrote: > On 03/05/2011 09:52, rusi wrote: > > > [If you believe it is, then try writing a log(n) fib iteratively :D ] > > It took me a while, but this one seems to work: > > from collections import namedtuple > > Triple = namedtuple('Triple', 'hi mid lo') > Triple.__mul__ = lambda self, other: Triple( > ? ? ?self.hi * other.hi + self.mid * other.mid, > ? ? ?self.hi * other.mid + self.mid * other.lo, > ? ? ?self.mid * other.mid + self.lo * other.lo, > ) > > def fib(n): > ? ? ?f = Triple(1, 1, 0) > ? ? ?a = Triple(1, 0, 1) > ? ? ?while n: > ? ? ? ? ?if n & 1: > ? ? ? ? ? ? ?a *= f > ? ? ? ? ?f *= f > ? ? ? ? ?n >>= 1 > ? ? ?return a.mid > > -- HansM Bravo! Can you explain this? The tightest way I knew so far was this: The 2x2 matrix 0 1 1 1 raised to the nth power gives the nth fibonacci number. [And then use a logarithmic matrix mult] Your version is probably tighter than this. Yet one could argue that this is 'cheating' because you (and I) are still solving the power problem. What I had in mind was to use fib results like: f_(2n) = f_n^2 + f_(n+1)^2 and use these in the same way (from first principles) like we use the equation x^2n = (x*x)^n to arrive at a logarithmic power algo. From ulrich.eckhardt at dominolaser.com Fri May 13 08:01:48 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 13 May 2011 14:01:48 +0200 Subject: Parsing a graph image References: Message-ID: <90jv98-322.ln1@satorlaser.homedns.org> Bastian Ballmann wrote: > I am searching for a library to parse data from a graph in an image file > something like http://pytseries.sourceforge.net/_images/yahoo.png > Any suggestions, hints, links? I'm not sure I understand 100% what you want. If you want to extract ("parse") the data that is contained in an image file, I have no clue how to do that. However, if you want to create such images and you already have the data, that should be as easy as picking the right library for that. I did a short search of Packages available for Debian and it gave me these: python-magics++ - python support for Magics++ python-matplotlib - Python based plotting system in a style similar to Matlab python-mpmath - library for arbitrary-precision floating-point arithmetic python-plplot - Python support for PLplot, a plotting library python-qwt3d-qt3 - Python bindings of the QwtPlot3D library python-qwt3d-qt4 - Python bindings of the QwtPlot3D library python-qwt5-qt3 - Python version of the Qwt5 technical widget library python-qwt5-qt4 - Python version of the Qwt5 technical widget library python-pybiggles - Scientific plotting package for Python python-chaco - interactive plotting application toolkit python-gnuplot - A Python interface to the gnuplot plotting program python-pychart - Python library for creating high quality charts python-simpy - python-based simulation package python-scitools - Python library for scientific computing python-sympy - Computer Algebra System (CAS) in Python python-viper - minimalistic scientific plotter and run-time visualization module Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From balle at chaostal.de Fri May 13 08:24:45 2011 From: balle at chaostal.de (Bastian Ballmann) Date: Fri, 13 May 2011 14:24:45 +0200 Subject: Parsing a graph image In-Reply-To: <90jv98-322.ln1@satorlaser.homedns.org> References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <20110513142445.0792eb4e@chaostal.de> Hi, Am Fri, 13 May 2011 14:01:48 +0200 schrieb Ulrich Eckhardt : > I'm not sure I understand 100% what you want. If you want to extract > ("parse") the data that is contained in an image file, I have no clue > how to do that. Yes, I want to extract the data that is contained in an image file. Greets Basti -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From moky.math at gmail.com Fri May 13 08:30:01 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:30:01 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <4DCD2449.8010203@gmail.com> > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent From moky.math at gmail.com Fri May 13 08:30:12 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:30:12 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <4DCD2454.3080208@gmail.com> > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent From moky.math at gmail.com Fri May 13 08:30:19 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:30:19 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <4DCD245B.4000301@gmail.com> > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent From moky.math at gmail.com Fri May 13 08:30:37 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:30:37 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <4DCD246D.9030001@gmail.com> > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent From moky.math at gmail.com Fri May 13 08:30:56 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:30:56 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <4DCD2480.9030009@gmail.com> > Yes, I want to extract the data that is contained in an image file. > Greets > > Basti > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent From nitw.saurabh at gmail.com Fri May 13 08:42:40 2011 From: nitw.saurabh at gmail.com (saurabh verma) Date: Fri, 13 May 2011 18:12:40 +0530 Subject: Parsing a graph image In-Reply-To: <20110513142445.0792eb4e@chaostal.de> References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> Message-ID: On 13-May-2011, at 5:54 PM, Bastian Ballmann wrote: > Hi, > > Am Fri, 13 May 2011 14:01:48 +0200 > schrieb Ulrich Eckhardt : > >> I'm not sure I understand 100% what you want. If you want to extract >> ("parse") the data that is contained in an image file, I have no clue >> how to do that. > > Yes, I want to extract the data that is contained in an image file. > Greets > I guess it requires some kind of image processing , where you can move around image pixel by pixel and somehow figure out what color is present in that pixel . If there isn?t much noise in the image you should sharp contrast and would be able to differentiate between two colors ? if yes ( I don?t know matlab might provide some tools .. just guessing ) then its easy i think to pick (X,Y) as time and value ? ~saurabh verma From moky.math at gmail.com Fri May 13 08:43:46 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:43:46 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> Message-ID: <4DCD2782.2010803@gmail.com> > I guess it requires some kind of image processing , where you can move around image pixel >by pixel and somehow figure out what color is present in that pixel . > If there isn?t much noise in the image you should sharp contrast and would >be able to differentiate between two colors ? if yes ( I don?t know matlab >might provide some tools .. just guessing ) then its easy i think to pick (X,Y) as time and value ? You made me think that in addition to ask to imagemagick's and matplotlib, one can also as to Sage[1] In order of pythonicity : - matplotlib - sage - imagemagick's Laurent [1] www.sagemath.org PS : Sorry for having send my previous answer 5 times. I don't understand :( From mail at timgolden.me.uk Fri May 13 08:44:03 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 May 2011 13:44:03 +0100 Subject: Assistance in understanding the sub-Process module In-Reply-To: References: Message-ID: <4DCD2793.5060806@timgolden.me.uk> On 13/05/2011 12:03, vijay swaminathan wrote: > 1. The class definition as per the documentation is: > /class /subprocess.Popen(/args/, /bufsize=0/, /executable=None/, > /stdin=None/, /stdout=None/, /stderr=None/, /preexec_fn=None/, > /close_fds=False/, /shell=False/, /cwd=None/, /env=None/, > /universal_newlines=False/, /startupinfo=None/, /creationflags=0/) > /args/ should be a string, or a sequence of program arguments. > so I assume that args can be a string or a list with first item of the > list being the program to execute. That's more or less correct. A list is usually preferable as it leaves the heavy-lifting of getting the quotes right to the underlying library. > so on the python IDLE, I executed this command, > >>> subprocess.Popen('cmd.exe') > which opened up a command prompt. > when I give this as a list, as below it throwed this error. > >>> subprocess.Popen(['cmd.exe', 'dir']) > Traceback (most recent call last): > File "", line 1, in > subprocess.Popen(['cmd.exe' 'dir']) > File "C:\Python26\lib\subprocess.py", line 623, in __init__ > errread, errwrite) > File "C:\Python26\lib\subprocess.py", line 833, in _execute_child > startupinfo) > WindowsError: [Error 2] The system cannot find the file specified Well I would actually have expected it to open a command prompt and do nothing else. If you do this in a (Windows) command prompt: cmd /? you can see that the way to run a command from with a command shell is to use: cmd /c (or /k which leaves the console running afterwards). Note that you only even need to launch cmd for internal commands which aren't executables in their own right. ie you don't need to do cmd /c notepad since notepad can run on its own. So doing cmd will just run cmd and, I think, ignore the rest of the line. You actually want: import subprocess subprocess.Popen (["cmd", "/c", "dir"]) However, that is exactly what passing shell=True to Popen does for you so... import subprocess subprocess.Popen ("dir", shell=True) # or subprocess.Popen (["dir"], shell=True) TJG From alister.ware at ntlworld.com Fri May 13 09:13:00 2011 From: alister.ware at ntlworld.com (alister ware) Date: Fri, 13 May 2011 13:13:00 GMT Subject: problem with GKT module? Message-ID: I am using gtk.builder with a glade generated GUI I have a simple call back defined for a radio button widget when I use widget.name in linux I get a value of None, windows returns the widget name as I would expect. is this a bug? if not how should i find the name of the widget that has triggered a call back? (I would like all my radio buttons to go to the same callback routine if possible to make code maintenance easier) -- 101-ism: The tendency to pick apart, often in minute detail, all aspects of life using half-understood pop psychology as a tool. -- Douglas Coupland, "Generation X: Tales for an Accelerated Culture" -- You may my glories and my state dispose, But not my griefs; still am I king of those. -- William Shakespeare, "Richard II" From neilc at norwich.edu Fri May 13 09:31:25 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 13 May 2011 13:31:25 GMT Subject: Parsing a graph image References: Message-ID: <934q5dFrhdU6@mid.individual.net> On 2011-05-13, Bastian Ballmann wrote: > Hi python lovers out there, > > I am searching for a library to parse data from a graph in an > image file something like > http://pytseries.sourceforge.net/_images/yahoo.png Any > suggestions, hints, links? You can do this with PIL . The technique is necessary in The Python Challenge, for example. -- Neil Cerutti From ian.g.kelly at gmail.com Fri May 13 09:55:51 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 May 2011 07:55:51 -0600 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> Message-ID: On Fri, May 13, 2011 at 5:11 AM, rusi wrote: > The tightest way I knew so far was this: > The 2x2 matrix > 0 1 > 1 1 > raised to the nth power gives the nth fibonacci number. [And then use > a logarithmic matrix mult] > Your version is probably tighter than this. Oh, nice! I did it this way once: V = [0 1] M = [0 1] [1 1] fib(n) = (V * M ** n)[0] Since I viewed M as operating on V, it never occurred to me that multiplying by V is actually unnecessary, but it is obvious in retrospect. I think it's just a fortuitous coincidence that it works, since V sets up the base case and M describes the recursive case. For a FIbonacci sequence starting with any other pair of numbers, V would change, but M would not, and so V would no longer happen to be identical to the top row of M. Ian From yagnesh.cyberthink at gmail.com Fri May 13 11:21:18 2011 From: yagnesh.cyberthink at gmail.com (Yagnesh from CyberThink) Date: Fri, 13 May 2011 08:21:18 -0700 (PDT) Subject: My direct client Hiring and interviewing going on Live today. Message-ID: <63b52b88-b7ce-42b1-a971-df9b628e8655@h36g2000pro.googlegroups.com> Hi, My direct client Hiring and interviewing going on Live today. I am having some very good direct client openings currently. I can get the consultant interviewed within 24 business hours. Please drop me an email to get all my direct client openings. I will reply to only those emails which are delivered to yagnesh at cyberthink.com. Thanks and Regards, Yagnesh From yagnesh.cyberthink at gmail.com Fri May 13 11:22:24 2011 From: yagnesh.cyberthink at gmail.com (Yagnesh from CyberThink) Date: Fri, 13 May 2011 08:22:24 -0700 (PDT) Subject: My direct client Hiring and interviewing going on Live today. Message-ID: Hi, My direct client Hiring and interviewing going on Live today. I am having some very good direct client openings currently. I can get the consultant interviewed within 24 business hours. Please drop me an email to get all my direct client openings. I will reply to only those emails which are delivered to yagnesh at cyberthink.com. Thanks and Regards, Yagnesh From lechten at helios.uni-muenster.de Fri May 13 12:01:30 2011 From: lechten at helios.uni-muenster.de (Jens Lechtenboerger) Date: Fri, 13 May 2011 18:01:30 +0200 Subject: Regular Expression for words (with umlauts, without numbers) Message-ID: <878vua4mjp.fsf@pcwi7557.uni-muenster.de> Dear experts, I'm looking for a regular expression to recognize natural language words with umlauts but without numbers. While \w with re.U does recognize words with umlauts, it also matches numbers, which I do not want. Is there a better way than an exhaustive enumeration such as [-a-z???????...]? I guess there should be a better way as \w appears to know about alphabetical characters... Thanks in advance Jens From devchon at gmail.com Fri May 13 12:14:47 2011 From: devchon at gmail.com (Tim Chon) Date: Fri, 13 May 2011 09:14:47 -0700 Subject: Regular Expression for words (with umlauts, without numbers) In-Reply-To: <878vua4mjp.fsf@pcwi7557.uni-muenster.de> References: <878vua4mjp.fsf@pcwi7557.uni-muenster.de> Message-ID: Hallo Jens, In current python re module, you have to do something like: ((?!\d|_\w)+ which uses the negative look ahead to grab all words except integers and underscore. Of course, if you turn on the unicode flag re.U or use it inline like, (?u) then this will grab your desired umlauts. I'd actually recommend, however, that if you have an extra 20 minutes, to use Regexp 2.7: http://bugs.python.org/issue2636 Its a much needed improvement over F.Lundh's re implementation (from 1999!) and its 40% faster. Moreover, you can do exactly what you are requesting like so, (?u)[[:alpha:]]+ cheers, --tim On Fri, May 13, 2011 at 9:01 AM, Jens Lechtenboerger < lechten at helios.uni-muenster.de> wrote: > Dear experts, > > I'm looking for a regular expression to recognize natural language > words with umlauts but without numbers. While \w with re.U does > recognize words with umlauts, it also matches numbers, which I do > not want. > > Is there a better way than an exhaustive enumeration such as > [-a-z???????...]? > > I guess there should be a better way as \w appears to know about > alphabetical characters... > > Thanks in advance > Jens > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri May 13 12:18:43 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 May 2011 18:18:43 +0200 Subject: Regular Expression for words (with umlauts, without numbers) References: Message-ID: Jens Lechtenboerger wrote: > I'm looking for a regular expression to recognize natural language > words with umlauts but without numbers. While \w with re.U does > recognize words with umlauts, it also matches numbers, which I do > not want. > > Is there a better way than an exhaustive enumeration such as > [-a-z???????...]? > > I guess there should be a better way as \w appears to know about > alphabetical characters... How about [^\W\d] ? From lechten at helios.uni-muenster.de Fri May 13 12:49:21 2011 From: lechten at helios.uni-muenster.de (Jens Lechtenboerger) Date: Fri, 13 May 2011 18:49:21 +0200 Subject: Regular Expression for words (with umlauts, without numbers) In-Reply-To: (Peter Otten's message of "Fri, 13 May 2011 18:18:43 +0200") References: Message-ID: <87tycy35ri.fsf@pcwi7557.uni-muenster.de> On 2011-05-13, Peter Otten wrote: > Jens Lechtenboerger wrote: > >> I'm looking for a regular expression to recognize natural language >> words with umlauts but without numbers. While \w with re.U does >> recognize words with umlauts, it also matches numbers, which I do >> not want. >> >> Is there a better way than an exhaustive enumeration such as >> [-a-z???????...]? >> >> I guess there should be a better way as \w appears to know about >> alphabetical characters... > > How about [^\W\d] ? Brilliant. Thanks Jens From hansmu at xs4all.nl Fri May 13 13:10:44 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 13 May 2011 19:10:44 +0200 Subject: os.popen command working differently on Windows In-Reply-To: References: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> Message-ID: <4dcd66d6$0$81483$e4fe514c@news.xs4all.nl> On 12/05/2011 16:21, Tim Golden wrote: > On 12/05/2011 15:11, Ayaskanta Swain wrote: >> Please help me in solving the following issue I am facing while >> executing my python script. Basically I am executing the OS specific >> move command to move a file/dir from one location to another. > > Why? Why not use os.rename or shutil.move which already do > whatever is needed under the covers for different Operating Systems? > > os.popen returns a file-like object from which you can read any > error messages generated. You're not doing that, and os.popen > won't raise an error itself unless you, say, pass it a number > rather than a string. > > > import os > > output = os.popen ("dir") > print output.read () > > # > # But note: > # > os.popen ("Nonsen*se") > > # raises no exception > > If you want exceptions, try the subprocess module: >>> import subprocess >>> subprocess.Popen("Nonsen*se") Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__ errread, errwrite) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1201, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory >>> In fact, os.popen is deprecated in favour of subprocess.Popen(). HTH, -- HansM From jenn.duerr at gmail.com Fri May 13 13:15:29 2011 From: jenn.duerr at gmail.com (noydb) Date: Fri, 13 May 2011 10:15:29 -0700 (PDT) Subject: How best to convert a string "list" to a python list Message-ID: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> I want some code to take the items in a semi-colon-delimted string "list" and places each in a python list. I came up with below. In the name of learning how to do things properly, do you experts have a better way of doing it? Thanks for any inputs! *** x = "red;blue;green;yellow" ## string of semi-colon delimited colors color_list = [] ## sc = semi-colon while x.find(";") <> -1: sc_pos = x.find(";") current_color = x[0:sc_pos] ## color w/o sc current_color_sc = x[0:sc_pos+1] ## color with sc color_list.append(current_color) ## append color to list x = x.replace(current_color_sc, "") ## remove color and sc from string print current_color print color_list print x + "\n" color_list.append(x) # append last color left in x (no sc at end of string) print color_list print "done" From prahamark at gmail.com Fri May 13 13:25:54 2011 From: prahamark at gmail.com (Mark Niemczyk) Date: Fri, 13 May 2011 10:25:54 -0700 (PDT) Subject: How best to convert a string "list" to a python list In-Reply-To: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: There are a series of built-in methods for string objects; including the split method which will accomplish exactly the result you are looking for. >>> x = "red;blue;green;yellow" >>> color_list = x.split(';') >>> color_list ['red', 'blue', 'green', 'yellow'] >>> Here is the link to a discussion of the build-in str methods (3.2), but this documentation exists for prior versions of Python as well. http://docs.python.org/py3k/library/stdtypes.html#str.split Good luck, Mark Niemczyk From malaclypse2 at gmail.com Fri May 13 13:30:39 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 13 May 2011 13:30:39 -0400 Subject: How best to convert a string "list" to a python list In-Reply-To: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 1:15 PM, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. ?I came up with below. ?In > the name of learning how to do things properly, do you experts have a > better way of doing it? Strings have a split method, which splits the string into a list based on a delimiter, like this: >>> x = "red;blue;green;yellow" >>> color_list = x.split(";") >>> print color_list ['red', 'blue', 'green', 'yellow'] That's how I'd do it. -- Jerry From jenn.duerr at gmail.com Fri May 13 13:31:26 2011 From: jenn.duerr at gmail.com (noydb) Date: Fri, 13 May 2011 10:31:26 -0700 (PDT) Subject: How best to convert a string "list" to a python list References: Message-ID: On May 13, 1:25?pm, Mark Niemczyk wrote: > There are a series of built-in methods for string objects; including the split method which will accomplish exactly the result you are looking for. > > >>> x = "red;blue;green;yellow" > >>> color_list = x.split(';') > >>> color_list > > ['red', 'blue', 'green', 'yellow'] > > > > Here is the link to a discussion of the build-in str methods (3.2), but this documentation exists for prior versions of Python as well. > > ? ? ?http://docs.python.org/py3k/library/stdtypes.html#str.split > > Good luck, > > Mark Niemczyk Haha! This is why I ask, because my code is pretty laughable and elementary! I'm learning... Thanks Mark! From python at mrabarnett.plus.com Fri May 13 13:34:55 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 May 2011 18:34:55 +0100 Subject: Regular Expression for words (with umlauts, without numbers) In-Reply-To: References: <878vua4mjp.fsf@pcwi7557.uni-muenster.de> Message-ID: <4DCD6BBF.70308@mrabarnett.plus.com> On 13/05/2011 17:14, Tim Chon wrote: > Hallo Jens, > > In current python re module, you have to do something like: > > ((?!\d|_\w)+ which uses the negative look ahead to grab all words except > integers and underscore. Of course, if you turn on the unicode flag re.U > or use it inline like, (?u) then this will grab your desired umlauts. > > I'd actually recommend, however, that if you have an extra 20 minutes, > to use Regexp 2.7: > http://bugs.python.org/issue2636 > > Its a much needed improvement over F.Lundh's re implementation (from > 1999!) and its 40% faster. Moreover, you can do exactly what you are > requesting like so, > > (?u)[[:alpha:]]+ > The latest release is here: http://pypi.python.org/pypi/regex From python at mrabarnett.plus.com Fri May 13 13:36:53 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 May 2011 18:36:53 +0100 Subject: How best to convert a string "list" to a python list In-Reply-To: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: <4DCD6C35.9060607@mrabarnett.plus.com> On 13/05/2011 18:15, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In > the name of learning how to do things properly, do you experts have a > better way of doing it? > > Thanks for any inputs! > > *** > x = "red;blue;green;yellow" ## string of semi-colon delimited colors > > color_list = [] > ## sc = semi-colon > > while x.find(";")<> -1: > sc_pos = x.find(";") > current_color = x[0:sc_pos] ## color w/o sc > current_color_sc = x[0:sc_pos+1] ## color with sc > color_list.append(current_color) ## append color to list > x = x.replace(current_color_sc, "") ## remove color and sc from > string > print current_color > print color_list > print x + "\n" > > color_list.append(x) # append last color left in x (no sc at end of > string) > print color_list > > print "done" >>> x = "red;blue;green;yellow" >>> x.split(";") ['red', 'blue', 'green', 'yellow'] From ericsnowcurrently at gmail.com Fri May 13 13:37:55 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 13 May 2011 11:37:55 -0600 Subject: How best to convert a string "list" to a python list In-Reply-To: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 11:15 AM, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In > the name of learning how to do things properly, do you experts have a > better way of doing it? > > Thanks for any inputs! > > *** > x = "red;blue;green;yellow" ## string of semi-colon delimited colors > > color_list = [] > ## sc = semi-colon > > while x.find(";") <> -1: > sc_pos = x.find(";") > current_color = x[0:sc_pos] ## color w/o sc > current_color_sc = x[0:sc_pos+1] ## color with sc > color_list.append(current_color) ## append color to list > x = x.replace(current_color_sc, "") ## remove color and sc from > string > print current_color > print color_list > print x + "\n" > > color_list.append(x) # append last color left in x (no sc at end of > string) > print color_list > > print "done" > -- > http://mail.python.org/mailman/listinfo/python-list > Try the following: color_list = x.split(";") Python string objects have a variety of helpful methods. Take a look at http://docs.python.org/library/stdtypes.html#string-methods. Hope that helps. -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri May 13 13:40:44 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 13 May 2011 10:40:44 -0700 (PDT) Subject: how to install easy_install Message-ID: <9f994806-bb7e-4219-9d64-eb50890b4b68@18g2000prd.googlegroups.com> I tried to install easy_install (This is on windows) I downloaded the executable and ran it. It claimed to have done its job. But now when I type easy_install at a cmd prompt I get easy_install is not a command... [I guess I am a perennial noob to windows, never being able to comprehend the PATH lookup logic (or lack of it)] Another related question: I gather that easy_install is being superseded by pypi or some such but I cant find the link... From ian.g.kelly at gmail.com Fri May 13 14:29:17 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 May 2011 12:29:17 -0600 Subject: how to install easy_install In-Reply-To: <9f994806-bb7e-4219-9d64-eb50890b4b68@18g2000prd.googlegroups.com> References: <9f994806-bb7e-4219-9d64-eb50890b4b68@18g2000prd.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 11:40 AM, rusi wrote: > I tried to install easy_install (This is on windows) > I downloaded the executable and ran it. It claimed to have done its > job. > > But now when I type easy_install at a cmd prompt I get > easy_install is not a command... > > [I guess I am a perennial noob to windows, never being able to > comprehend the PATH lookup logic (or lack of it)] > > Another related question: I gather that easy_install is being > superseded by pypi or some such but I cant find the link... easy_install is part of the setuptools or distribute package. I assume that one of these is what you installed. On Windows, the easy_install command is installed into your Python Scripts directory, which should be something like "C:\Python27\Tools\Scripts" or "C:\Python25\Scripts" depending on your Python version. You just need to find that directory and add it to your PATH. PyPI is the Python package index. It's a website at http://pypi.python.org/ -- not a replacement for setuptools or easy_install, which uses it to look up package metadata. Setuptools is supposed to be superseded by distribute, which may be what you heard. HTH, Ian From mitchell.hashimoto at gmail.com Fri May 13 14:43:23 2011 From: mitchell.hashimoto at gmail.com (Mitchell Hashimoto) Date: Fri, 13 May 2011 11:43:23 -0700 Subject: Import on case insensitive filesystem Message-ID: Hello, I'm developing an app which runs Python on a filesystem which is not case sensitive (Mac OS X), but is mounted as an NFS drive on a remote machine. This causes errors because of the import being case sensitive but accessing an FS which is case insensitive. Short of copying the entire directory tree over to another filesystem, is there anything I can do to flag Python to act as though it were on a case sensitive FS? The exact issue I'm seeing is this file, named crypto.py, and relying on pycrypto: from Crypto.Cipher import AES print("Made it!") That attempts to import the same file (itself) instead of finding the Crypto module since the filesystem casing is incorrect. Any tips would be greatly appreciated. Best, Mitchell -------------- next part -------------- An HTML attachment was scrubbed... URL: From redcat at catfolks.net Fri May 13 15:26:40 2011 From: redcat at catfolks.net (Redcat) Date: 13 May 2011 19:26:40 GMT Subject: How best to convert a string "list" to a python list References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: <935evgF8cmU1@mid.individual.net> On Fri, 13 May 2011 10:15:29 -0700, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In the > name of learning how to do things properly, do you experts have a better > way of doing it? How about the below? dan at dan:~/development$ python Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = "cyan;magenta;yellow;black" >>> xList = x.split(';') >>> xList ['cyan', 'magenta', 'yellow', 'black'] >>> From robert.kern at gmail.com Fri May 13 15:38:45 2011 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 13 May 2011 14:38:45 -0500 Subject: Parsing a graph image In-Reply-To: <20110513142445.0792eb4e@chaostal.de> References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> Message-ID: On 5/13/11 7:24 AM, Bastian Ballmann wrote: > Hi, > > Am Fri, 13 May 2011 14:01:48 +0200 > schrieb Ulrich Eckhardt: > >> I'm not sure I understand 100% what you want. If you want to extract >> ("parse") the data that is contained in an image file, I have no clue >> how to do that. > > Yes, I want to extract the data that is contained in an image file. There is nothing in Python that solves this problem, per se, but there are free and open source tools for this out there. E.g. http://digitizer.sourceforge.net/ -- 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 harrismh777 at charter.net Fri May 13 15:41:02 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 13 May 2011 14:41:02 -0500 Subject: checking if a list is empty In-Reply-To: <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: >> http://www.codinghorror.com/blog/2006/07/separating-programming-sheep-from-non-programming-goats.html > A later paper by the same authors... > (http://www.eis.mdx.ac.uk/research/PhDArea/saeed/paper3.pdf) > These papers are fascinating reading, not only for philosophy sake in a great study in epistemology, but for a good clean study in good science and an appropriate measure of the scientific method in an interesting case study that 'failed'. In that regard it was a huge success! The authors recognize (in paper [2]) that while their findings disproved their hypothesis the advances they made through good science have left the door open for further study. This is good news for the field of philosophy generally, and for epistemology in particular. ------- I too have noticed the general 'case' put forward in paper(1): namely, some people just don't seem to get it on the surface, and we can't figure out why. On the other hand, I have 'always' been able to teach computer science (programming in particular) to 'anyone' given enough time, attention, creativity, and caring. In fact, when I find someone who is exhibiting low aptitude potential (let's say zero '0') then I must allow even more time, more attention, much more creativity, and a lot more caring. I remember a line from "Mr. Holland's Opus," (a great movie, by the way) where Mr Holland is explaining to the coach why a certain young man has not any musical acumen --- and the coach says, "..you telling me you can't teach a willing kid to beat a drum...?... then you're a lousy teacher!" Holland ended up teaching us all a lot more than how to beat a drum, before the end of the movie.... The point here is that aptitude says what a person has been conditioned for at this 'point in time' to be able to do... but says nothing about what re-conditioning might do for a transformed life! If I can't teach a kid how to program a computer, I'm a lousy teacher! ------- I grew up with computers. But kids today have 'magical' thinking about these machines, because they didn't grow up with them. If you started out (like I did) on the Altair 8800, or the Wang 700, programming in machine code, it became very clear rapidly why a high level language of some type might be beneficial ( and you could relate how the language constructs made the translation to machine code possible ). It was easier for me to learn programming, because I evolved with it. On the other hand, kids today are dumped into a first comp sci course in programming and plopped in-front of a Hugs interactive shell and then are expected to learn programming and be successful by trying to grasp pure functional programming in Haskell(!) in a ten to 12 week term and we wonder why so many students are failing their 'first' programming class!! Give me a break. No, give them a break. Guido van Rossum has said in one of his interviews (can't remember now which one) that BASIC is a terrible first computer language... and I agree... but, it was a lot better than Hugs! But that's not my point, my point is that Python is better still. Why? Because Python can be taught at a *very* rudimentary level ( input, control, arithmetic, logic and output ) in almost a BASIC or REXX procedural style -- top down -- so that students 'get it'. Then, in subsequent classes down the road (much later) Python can grow and expand with the student's re-conditioning for more in-depth expansion of concepts and knowledge. At the graduate level Python will still be there... challenging students to extend and expand in ways that were not even possible to discuss in the first introductory course. It seems to me that if the goal of comp sci courses at universities and colleges is 'education' that comp sci professors and instructors would get a handle on this. If you can't teach a willing kid to write a functioning computer program then you're a lousy teacher. kind regards, m harris From hansmu at xs4all.nl Fri May 13 15:46:04 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 13 May 2011 21:46:04 +0200 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> Message-ID: <4dcd8b47$0$81473$e4fe514c@news.xs4all.nl> On 13/05/2011 13:11, rusi wrote: > On May 12, 3:06 am, Hans Mulder wrote: >> On 03/05/2011 09:52, rusi wrote: >> >>> [If you believe it is, then try writing a log(n) fib iteratively :D ] >> >> It took me a while, but this one seems to work: >> >> from collections import namedtuple >> >> Triple = namedtuple('Triple', 'hi mid lo') >> Triple.__mul__ = lambda self, other: Triple( >> self.hi * other.hi + self.mid * other.mid, >> self.hi * other.mid + self.mid * other.lo, >> self.mid * other.mid + self.lo * other.lo, >> ) >> >> def fib(n): >> f = Triple(1, 1, 0) >> a = Triple(1, 0, 1) >> while n: >> if n& 1: >> a *= f >> f *= f >> n>>= 1 >> return a.mid >> >> -- HansM > > Bravo! Can you explain this? > > The tightest way I knew so far was this: > The 2x2 matrix > 0 1 > 1 1 > raised to the nth power gives the nth fibonacci number. [And then use > a logarithmic matrix mult] > Your version is probably tighter than this. My method is just a thinly disguised version of your method: your 2x2 matrices are symmetrical, i.e. the number in the upper right is equal to the number in the lower left. So I can save some memory and some CPU time by working with only three numbers. > Yet one could argue that this is 'cheating' because you (and I) are > still solving the power problem. That's true. > What I had in mind was to use fib results like: > f_(2n) = f_n^2 + f_(n+1)^2 > and use these in the same way (from first principles) like we use the > equation > x^2n = (x*x)^n > to arrive at a logarithmic power algo. To compute f(4n) this way, you need to compute both f(2n) and f(2n+1) first, and to compute those, you need f(n) and f(n+1) and f(n+2).... I think I can construct an O(log(n)**2) algorithm this way. And it would still be 'cheating', because we'd still use some special property of the Fibonacci sequence to reduce our problem to the power problem. I think this sort of cheating can't be avoided: there is no general method to compute recurrent sequences faster than O(n); Fibonacci is just a special case. -- HansM From harrismh777 at charter.net Fri May 13 15:53:50 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 13 May 2011 14:53:50 -0500 Subject: unicode by default In-Reply-To: <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: jmfauth wrote: >> to worry about encodings are when you're encoding unicode characters >> > to byte strings, or decoding bytes to unicode characters > > A small but important correction/clarification: > > In Unicode, "unicode" does not encode a*character*. It > encodes a*code point*, a number, the integer associated > to the character. > That is a huge code-point... pun intended. ... and there is another point that I continue to be somewhat puzzled about, and that is the issue of fonts. On of my hobbies at the moment is ancient Greek (biblical studies, Septuaginta LXX, and Greek New Testament). I have these texts on my computer in a folder in several formats... pdf, unicode 'plaintext', osis.xml, and XML. These texts may be found at http://sblgnt.com I am interested for the moment only in the 'plaintext' stream, because it is unicode. ( first, in unicode, according to all the doc there is no such thing as 'plaintext,' so keep that in mind). When I open the text stream in one of my unicode editors I can see 'most' of the characters in a rudimentary Greek font with accents; however, I also see many tiny square blocks indicating (I think) that the code points do *not* have a corresponding character in my unicode font for that Greek symbol (whatever it is supposed to be). The point, or question is, how does one go about making sure that there is a corresponding font glyph to match a specific unicode code point for display in a particular terminal (editor, browser, whatever) ? The unicode consortium is very careful to make sure that thousands of symbols have a unique code point (that's great !) but how do these thousands of symbols actually get displayed if there is no font consortium? Are there collections of 'standard' fonts for unicode that I am not aware? Is there a unix linux package that can be installed that drops at least 'one' default standard font that will be able to render all or 'most' (whatever I mean by that) code points in unicode? Is this a Python issue at all? kind regards, m harris From robert.kern at gmail.com Fri May 13 16:18:33 2011 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 13 May 2011 15:18:33 -0500 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: On 5/13/11 2:53 PM, harrismh777 wrote: > The unicode consortium is very careful to make sure that thousands of symbols > have a unique code point (that's great !) but how do these thousands of symbols > actually get displayed if there is no font consortium? Are there collections of > 'standard' fonts for unicode that I am not aware? There are some well-known fonts that try to cover a large section of the Unicode standard. http://en.wikipedia.org/wiki/Unicode_typeface > Is there a unix linux package > that can be installed that drops at least 'one' default standard font that will > be able to render all or 'most' (whatever I mean by that) code points in > unicode? Is this a Python issue at all? Not really. -- 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 Fri May 13 16:21:49 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 May 2011 14:21:49 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 1:41 PM, harrismh777 wrote: > On the other hand, kids today are dumped into a first comp sci course in > programming and plopped in-front of a Hugs interactive shell and then are > expected to learn programming and be successful by trying to grasp pure > functional programming in Haskell(!) in a ten to 12 week term and we wonder > why so many students are failing their 'first' programming class!! ?Give me > a break. ?No, give them a break. Well, at least Haskell is probably better as an introductory language than Lisp or Scheme. But what schools actually do this? My perception is that the vast majority of schools use C++ or C# or Java, typically relegating functional programming to a single second- or third-year course. Of course it's well known that MIT used to use Scheme, but they switched to Python a couple years ago. > Guido van Rossum has said in one of his interviews (can't remember now which > one) that BASIC is a terrible first computer language... and I agree... but, > it was a lot better than Hugs! ?But that's not my point, my point is that > Python is better still. ?Why? ?Because Python can be taught at a *very* > rudimentary level ( input, control, arithmetic, logic and output ) in almost > a BASIC or REXX procedural style -- top down -- so that students 'get it'. > Then, in subsequent classes down the road (much later) Python can grow and > expand with the student's re-conditioning for more in-depth expansion of > concepts and knowledge. I don't think a single language is necessarily going to be best for all students. If a math major comes to you wanting to learn some programming for theorem-proving, bearing in mind that they probably aren't interested in learning more than a single language, would you try to start them out with Python, or would you just give them the functional language that they're ultimately going to want? From dickinsm at gmail.com Fri May 13 17:48:32 2011 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 13 May 2011 14:48:32 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> Message-ID: On May 11, 11:06?pm, Hans Mulder wrote: > On 03/05/2011 09:52, rusi wrote: > > > [If you believe it is, then try writing a log(n) fib iteratively :D ] > > It took me a while, but this one seems to work: > > from collections import namedtuple > > Triple = namedtuple('Triple', 'hi mid lo') > Triple.__mul__ = lambda self, other: Triple( > ? ? ?self.hi * other.hi + self.mid * other.mid, > ? ? ?self.hi * other.mid + self.mid * other.lo, > ? ? ?self.mid * other.mid + self.lo * other.lo, > ) > [...] You can even get away with pairs rather than triples: ---- from collections import namedtuple Pair = namedtuple('Pair', 'z o') Pair.__mul__ = lambda self, other: Pair( self.z * other.z + self.o * other.o, self.z * other.o + self.o * other.z + self.o * other.o, ) def fib(n): f = Pair(0, 1) a = Pair(1, 0) while n: if n & 1: a *= f f *= f n >>= 1 return a.o ---- I don't see this (or Hans' version) as cheating at all. This really *is* the power algorithm, just in a different number system from the usual one. For those with a bit of abstract algebra, the above algorithm is just computing x^n in the ring Z[x] / (x^2 - x - 1). A pair 'Pair(a, b)' represents the element 'a + bx' (more precisely, the image of 'a + bx' under the natural quotient map Z[x] -> Z[x] / (x^2 - x - 1)) of that ring. And this *can* be generalised to other sequences given by a linear recurrence. Mark From drsalists at gmail.com Fri May 13 19:23:08 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 13 May 2011 16:23:08 -0700 Subject: Parsing a graph image In-Reply-To: <20110513121901.7ff67dd1@chaostal.de> References: <20110513121901.7ff67dd1@chaostal.de> Message-ID: You could convert the image to a netpbm format, like ppm, pgm or pbm. If the image has few colors, that should be quite viable. Each of these formats are easy to work with in Python. ppm is for color, pgm is for grayscale, pbm is for strictly black and white, pnm pertains to any of the 3. There are all sorts of filters for converting between these formats and many others in netpbm, and image processing. You might be able to use pnmcut (to select just the part of the image you need - I'm guessing your math will be simpler if you crop off the axes and everything outside them), ppmdist (to convert color (with a low number of colors) to grayscale) or ppmtopgm (for high color images), and pgmedge (for edge detection), etc. Then you might pnmnoraw to get an ASCII pbm instead of a binary one - ASCII netpbm files are even simpler than binary onesto work with. Here's an example of generating a ppm file in Python 2. It looks like this after conversion to png format: http://stromberg.dnsalias.org/~dstromberg/software/circle.png If you set a bunch of them next to each other (say, by tiling it as a wallpaper), it gives a slightly eerie 3D effect. It's an application of the inverse square law. I know, it's kind of the opposite of what you need, but it may still illustrate the approach: #!/usr/bin/python # writes a ppm file for a sort of sphere on stdout. import math import sys def pad(n): s = str(n) while len(s) < 4: s = s + ' ' return s size=200 colors=256 print 'P3' print size,size print colors-1 half=float(size/2) sqrt2 = math.sqrt(2) for i in range(0,size): for j in range(0,size): x = float(i - half) / half y = float(j - half) / half z = math.sqrt(x*x + y*y)/sqrt2 col = int(z * (colors-1)) #sys.stderr.write(str(x)+' '+str(y)+' '+str(col)+'\n') ch = chr(col) sys.stdout.write(pad(col)+pad(col)+pad(col)+' ') print BTW, I don't do string concatenation this much anymore, and xrange is good in 2.x. :) On Fri, May 13, 2011 at 3:19 AM, Bastian Ballmann wrote: > Hi python lovers out there, > > I am searching for a library to parse data from a graph in an image file > something like http://pytseries.sourceforge.net/_images/yahoo.png > Any suggestions, hints, links? > > TIA && have a nice day! :) > > Basti > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Fri May 13 19:30:03 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 14 May 2011 01:30:03 +0200 Subject: Regular Expression for words (with umlauts, without numbers) In-Reply-To: <4DCD6BBF.70308@mrabarnett.plus.com> References: <878vua4mjp.fsf@pcwi7557.uni-muenster.de> <4DCD6BBF.70308@mrabarnett.plus.com> Message-ID: 2011/5/13 MRAB : > The latest release is here: > > ? ?http://pypi.python.org/pypi/regex > -- Wow, set operators were added recently ... https://code.google.com/p/mrab-regex-hg/wiki/GeneralDetails ok, it might be not necassary to sove this exact problem with respect to the solutions already mentioned, but I quite like this extra possibilities, anyway, the double negation [^\W] is not needed here: (?u)[\w--\d] Thank you very much for this excellent library! vbr From harrismh777 at charter.net Fri May 13 20:48:15 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 13 May 2011 19:48:15 -0500 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: Ian Kelly wrote: > Well, at least Haskell is probably better as an introductory language > than Lisp or Scheme. But what schools actually do this? http://www.cs.kent.ac.uk/teaching/resources/haskell/HugsResources.html http://research.cs.queensu.ca/home/cisc260/2010w/haskell.html These are just two schools that teach functional programming early on using Haskell... but there are many. (google around) caveat: thingks are changing all the time, for instance I notice that Margaret Lamb at Queen's University in Ontario hasn't updated her page in about a year... so things may be different there for her classes than when we were first corresponding... ... and I'm also lumping two other languages into this 'category'... namely, Scheme, and Erlang. > perception is that the vast majority of schools use C++ or C# or Java, ... that may be the trend now... > typically relegating functional programming to a single second- or > third-year course. Of course it's well known that MIT used to use > Scheme, but they switched to Python a couple years ago. Scheme seems to be very popular in education, based on the discussions, as a functional language; but, alas, I've not seen it nor played with it ( so can't comment too much, yet ). I'm glad to hear that MIT is using Python now..! > I don't think a single language is necessarily going to be best for > all students. no doubt... I can dream can't I ? > If a math major comes to you wanting to learn some > programming for theorem-proving, bearing in mind that they probably > aren't interested in learning more than a single language, would you > try to start them out with Python, or would you just give them the > functional language that they're ultimately going to want? Well, that's just it... learning how to program is essential for all disciplines IMHO and learning just one language is not an option. Everyone needs a GPL and that's going to be Python... me hopes. And then some majors are going to require special purpose languages that meet certain requirements... and functional languages (haskell, erlang, scheme) are going to suit that need very well) by the by, don't get me wrong... I think Haskell is elegant, one of the best... but, not for students with no programming background, nor for those who just don't seem to be getting it on the first pass. kind regards, m harris From tjreedy at udel.edu Fri May 13 21:41:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 May 2011 21:41:30 -0400 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: On 5/13/2011 3:53 PM, harrismh777 wrote: > The unicode consortium is very careful to make sure that thousands of > symbols have a unique code point (that's great !) but how do these > thousands of symbols actually get displayed if there is no font > consortium? Are there collections of 'standard' fonts for unicode that I > am not aware? Is there a unix linux package that can be installed that > drops at least 'one' default standard font that will be able to render > all or 'most' (whatever I mean by that) code points in unicode? Is this > a Python issue at all? Easy, practical use of unicode is still a work in progress. -- Terry Jan Reedy From ian.g.kelly at gmail.com Fri May 13 21:52:39 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 May 2011 19:52:39 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 6:48 PM, harrismh777 wrote: > Ian Kelly wrote: >> >> Well, at least Haskell is probably better as an introductory language >> than Lisp or Scheme. ?But what schools actually do this? > > http://www.cs.kent.ac.uk/teaching/resources/haskell/HugsResources.html > http://research.cs.queensu.ca/home/cisc260/2010w/haskell.html > > ? These are just two schools that teach functional programming early on > using Haskell... but there are many. ?(google around) The first link is just a collection of Haskell resources, which indicates that they use it, but not when. They also have a collection of Java resources on the department website. Perusing the handbook, I see the following modules: CO320 Introduction to Object-Oriented Programming This appears to be their introductory module. It doesn't say what language they use, but since they have Java resources on the website that's what I'm going to guess. CO530 Functional Programming This is listed as an intermediate-level course and is in the 2nd/3rd year handbook. The synopsis includes: "Introduction to a Haskell system (sessions and scripts)." So no, Kent does not appear to be teaching Haskell as an introductory course, or even in the first year. The Queen's course also appears to be a 2nd year class, based on the number. Its description includes this: "You will learn two new languages: Haskell and Prolog. These languages are a bit different from languages such as *Python* and *Java* that you have learned so far in Queen's courses" (emphasis added). Notably, this class isn't even focused on functional programming; it's an introduction to programming paradigms other than the imperative one. So far, neither of these universities support your claim that "kids today are dumped into a first comp sci course in programming and plopped in-front of a Hugs interactive shell and then are expected to learn programming and be successful by trying to grasp pure functional programming in Haskell(!) in a ten to 12 week term". From greg.ewing at canterbury.ac.nz Fri May 13 22:26:08 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 14 May 2011 14:26:08 +1200 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: <9367i3Fnq3U1@mid.individual.net> Ian Kelly wrote: > If a math major comes to you wanting to learn some > programming for theorem-proving, bearing in mind that they probably > aren't interested in learning more than a single language, I would question whether theorem-proving is the *only* thing they will ever want to do with a programming language. If they really only want to learn one language, it would be better to learn the one with the widest field of applicability. I'd hazard to guess that writing a theorem prover in Python would be a more practical proposition than writing a script to automate processing his LaTeX papers in Haskell. -- Greg From greg.ewing at canterbury.ac.nz Fri May 13 22:32:06 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 14 May 2011 14:32:06 +1200 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: <9367t9Fq0fU1@mid.individual.net> harrismh777 wrote: > ... and I'm also lumping two other languages into this 'category'... > namely, Scheme, and Erlang. Scheme isn't really a functional language, though. You can use a subset of it in a functional way, but it doesn't have the sort of built-in support for pattern matching and case analysis that true functional languages tend to have. As families of languages go, Scheme has more in common with Python than Haskell. -- Greg From greg.ewing at canterbury.ac.nz Fri May 13 22:34:51 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 14 May 2011 14:34:51 +1200 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <93682bFq0fU2@mid.individual.net> rusi wrote: > Dijkstra's problem (paraphrased) is that python, by choosing the > FORTRAN alternative of having a non-first-class boolean type, hinders > scientific/mathematical thinking/progress. Python doesn't have the flaw that Dijkstra was talking about. Fortran's flaw wasn't so much the lack of a boolean type, but that you couldn't assign the result of a logical expression to a variable. Python has always been able to do that, even before it had a distinct boolean type. -- Greg From jjposner at optimum.net Fri May 13 23:47:49 2011 From: jjposner at optimum.net (John Posner) Date: Fri, 13 May 2011 23:47:49 -0400 Subject: How best to convert a string "list" to a python list In-Reply-To: References: Message-ID: <4DCDFB65.5000603@optimum.net> On 5/13/2011 3:38 PM, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In > the name of learning how to do things properly, No big deal that you weren't aware of the split() method for strings. Since you asked for pointers, here are some notes on your code -- which is just fine, overall! > x = "red;blue;green;yellow" ## string of semi-colon delimited colors > > color_list = [] > ## sc = semi-colon > > while x.find(";") <> -1: > sc_pos = x.find(";") > current_color = x[0:sc_pos] ## color w/o sc > current_color_sc = x[0:sc_pos+1] ## color with sc You don't really need the variable "current_color_sc", since you use it only once. For example, your invocation of replace() could look like this: x = x.replace(current_color + ";", "") But if you really want the extra variable, the following definition is clearer (and also avoids a slice operation): current_color_sc = current_color + ";" > color_list.append(current_color) ## append color to list > x = x.replace(current_color_sc, "") ## remove color and sc from string Here's another reason why you don't need the variable "current_color_sc": instead of using replace(), why not just chop off the first N characters of the string: x = x[len(current_color)+1:] (The "+1" takes care of the semicolon.) > print current_color > print color_list > print x + "\n" > > color_list.append(x) # append last color left in x (no sc at end of > string) Does that last append(), outside the loop, offend you? You can get rid of it by modifying the original string: x = "red;blue;green;yellow" x += ";" Now, the final component of the string is no longer a special case, but is terminated by ";" -- just like all the other components. HTH, John From far.runner at gmail.com Sat May 14 00:46:12 2011 From: far.runner at gmail.com (Far.Runner) Date: Fri, 13 May 2011 21:46:12 -0700 Subject: Get IP address of WIFI interface Message-ID: Hi Python Experts: There are two network interfaces on my laptop, one is 100M Ethernet interface, the other is wifi interface, both are connected and has an IP address. then the question is: how to get the ip address of the wifi interface in a python script? OS: Windows or Linux -------------- next part -------------- An HTML attachment was scrubbed... URL: From harrismh777 at charter.net Sat May 14 00:47:06 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 13 May 2011 23:47:06 -0500 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: Ian Kelly wrote: >> >> Well, at least Haskell is probably better as an introductory language >> >> than Lisp or Scheme. But what schools actually do this? >> http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/ http://www.cs.ou.edu/~rlpage/fpclassSpring97/ There are lots of these... the two above afaik are still doing this at the entry level... ... supposedly, these kids are 'mostly' successful and exit interviews are great... but that doesn't fit with the observed idea that students are not doing well in comp sci classes generally... but, read below... this at the entry level?? ====== block quote ========= The first 10 to 11 weeks of the course use Haskell. Students are required to write nine programs in Haskell, three of which are team projects that combine software developed in individual projects. Different members of a team are assigned different individual projects, and the team efforts combine their solutions into a working piece of software. In the early part of the course, students use operators like map, foldr, zip, and iterate to express computations. Explicit recursion is introduced after some experience with these common patterns of computation. Examples and problems address non-numeric applications, for the most part. Both interactive and file I/O are covered, but general purpose monads are not. The last 5 to 6 weeks of the course use C, and most of the projects in that part of the course duplicate the function of earlier pieces of software that the students have written in Haskell. ====== /block quote ========= From far.runner at gmail.com Sat May 14 01:09:24 2011 From: far.runner at gmail.com (Far.Runner) Date: Fri, 13 May 2011 22:09:24 -0700 Subject: Get the IP address of WIFI interface Message-ID: Hi python experts: There are two network interfaces on my laptop: one is 100M Ethernet interface, the other is wifi interface, both are connected and has an ip address. The question is: How to get the ip address of the wifi interface in a python script without parsing the output of a shell command like "ipconfig" or "ifconfig"? OS: Windows or Linux F.R -------------- next part -------------- An HTML attachment was scrubbed... URL: From hujun.work at gmail.com Sat May 14 01:40:01 2011 From: hujun.work at gmail.com (Jun Hu) Date: Fri, 13 May 2011 22:40:01 -0700 Subject: How to get the IP address of the wifi interface? Message-ID: Hi python experts: There are two network interfaces on my laptop, one is 100M Ethernet, the other is wifi, both are connected and have IP addresses. The question is: how to get the ip address of WIFI interface without parsing the output of a shell command like "ipconfig" or "ifconfig"? OS: Windows or Linux H.J -------------- next part -------------- An HTML attachment was scrubbed... URL: From ishwor.gurung at gmail.com Sat May 14 01:41:05 2011 From: ishwor.gurung at gmail.com (Ishwor Gurung) Date: Sat, 14 May 2011 15:41:05 +1000 Subject: Get IP address of WIFI interface In-Reply-To: References: Message-ID: Hi. On 14 May 2011 14:46, Far.Runner wrote: > Hi Python Experts: > There are two network interfaces on my laptop, one is > 100M?Ethernet?interface, the other is wifi interface, both are connected and > has an IP address. then the question is: how to get the ip address of the > wifi interface in a python script? > OS: Windows or Linux Detect the OS with os.name and branch out to specific use case. The specific functionality can be implemented 2 ways: 1/ Regular expression pattern match 2/ Substring match and splits The subprocess module will then let you run those commands. 1/ posix - (Linux in your case) will use ifconfig 2/ nt - (windows in your ase) will use ipconfig. HTH. -- Regards Ishwor Gurung Key id:0xa98db35e Key fingerprint:FBEF 0D69 6DE1 C72B A5A8? 35FE 5A9B F3BB 4E5E 17B5 From astan.chee at gmail.com Sat May 14 02:08:44 2011 From: astan.chee at gmail.com (Astan Chee) Date: Sat, 14 May 2011 16:08:44 +1000 Subject: turn monitor off and on Message-ID: Hi, I'm trying to turn off my monitor, pause and then turn it on again. I'm doing this in python 2.6 and windows xp. Here is my script so far (that doesn't work): import time import win32gui import win32con import win32api def turnOffMonitor(): SC_MONITORPOWER = 0xF170 win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) def turnOnMonitor(): SC_MONITORPOWER = 0xF170 win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) if __name__ == "__main__": turnOffMonitor() time.sleep(5) turnOnMonitor() For some reason, the script doesn't turn the monitor back on. What am I doing wrong here or are there any other alternative? From ian.g.kelly at gmail.com Sat May 14 02:14:59 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 May 2011 00:14:59 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 10:47 PM, harrismh777 wrote: > http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/ > > http://www.cs.ou.edu/~rlpage/fpclassSpring97/ > > > There are lots of these... ? the two above afaik are still doing this at the > entry level... ? ?... supposedly, these kids are 'mostly' successful and > exit interviews are great... ?but that doesn't fit with the observed idea > that students are not doing well in comp sci classes generally... but, read > below... ?this at the entry level?? I'll grant you Edinburgh. That Oklahoma syllabus is from 1997. The 2010 syllabus for the entry-level course indicates that it is taught in Java. From dje at google.com Sat May 14 02:38:59 2011 From: dje at google.com (Doug Evans) Date: Fri, 13 May 2011 23:38:59 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem wrote: > (now in plain-text as required by gdb mailing list) > > Hi, > > I am currently trying to integrate Python support into my toolchain > build (including GDB of course). It is a sysrooted > binutils+GCC+GDB+mingw-w64 toolchain. > > I currently have the basic setup working: I can link gdb with my > manually generated import lib to the python dll from the official > Windows install. If there is anything I am missing or a very easy > solution to the problems decsribed below, please just say so. I am > only suggesting what I would like to happen. > > Now on to the problems I'd like to discuss: > > 1. gdb.exe won't start without me having set PYTHONPATH manually. In a properly configured/built gdb on linux this isn't necessary, even if python is installed in some random place. I'm not sure about windows though. Did you specify --with-python when you configured gdb, and if so did you specify a value? e.g., --with-python=SOME_VALUE > I understand the need for this, but as gdb requires Python 2, and users > of my toolchain may have installed Python 3 or a 32-bit version python > they want to use from the same environment (without changing their own > PYTHONPATH), there is no way to run python-enabled gdb. > [...] Yeah. There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have gdb use that instead of PYTHONPATH if it exists, but there's been resistance to it. I think(!) what would happen is that gdb would set $PYTHONPATH to the value of $GDB_PYTHONPATH. [Inferiors started by gdb should still get the original value of PYTHONPATH though.] > 2. With PYTHONPATH set as a temporary workaround, gdb starts, but > spits out a traceback: > Traceback (most recent call last): > ? File "", line 35, in > ? File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line > 18, in > ??? gdb.command.pretty_printers.register_pretty_printer_commands() > ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", > line 368, in register_pretty_printer_commands > ??? InfoPrettyPrinter() > ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", > line 100, in __init__ > ??? gdb.COMMAND_DATA) > RuntimeError: Could not find command prefix info. > > This is a minor problem I think, as "python import time" "python print > time.clock()" works as expected. What is wrong? I'm not sure. The error message is complaining that the "info" command prefix doesn't exist. I don't see how that can happen as python is initialized long after the info command is created. From harrismh777 at charter.net Sat May 14 03:13:57 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 02:13:57 -0500 Subject: turn monitor off and on In-Reply-To: References: Message-ID: Astan Chee wrote: > import time > import win32gui > import win32con > import win32api > > def turnOffMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) > > def turnOnMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > if __name__ == "__main__": > turnOffMonitor() > time.sleep(5) > turnOnMonitor() What we need here is a matching script that turns off WinXP and leaves it off too... ... ouch, :) lol m harris From harrismh777 at charter.net Sat May 14 03:20:55 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 02:20:55 -0500 Subject: turn monitor off and on In-Reply-To: References: Message-ID: harrismh777 wrote: > > def turnOnMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) I've never tried turning my monitor on/off without using my finger... gonna have to play with this... wouldn't that be a great script kiddie tool... just turn off all the windows monitors around the world... no problem(s) after that... ... what happens if you try to turn it back on with your finger... ? ... I have another idea... while its off, try pushing the alt key on your keyboard... or moving your mouse... (come back on ? ) kind regards, m harris From rustompmody at gmail.com Sat May 14 03:23:51 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 00:23:51 -0700 (PDT) Subject: how to install easy_install References: mailman.1522.1305311391.9059.python-list@python.org Message-ID: On May 13, 11:29?pm, Ian Kelly wrote: > On Fri, May 13, 2011 at 11:40 AM, rusi wrote: > > I tried to install easy_install (This is on windows) > > I downloaded the executable and ran it. It claimed to have done its > > job. > > > But now when I type easy_install at a cmd prompt I get > > easy_install is not a command... > > > [I guess I am a perennial noob to windows, never being able to > > comprehend the PATH lookup logic (or lack of it)] > > > Another related question: I gather that easy_install is being > > superseded by pypi or some such but I cant find the link... > > easy_install is part of the setuptools or distribute package. ?I > assume that one of these is what you installed. > > On Windows, the easy_install command is installed into your Python > Scripts directory, which should be something like > "C:\Python27\Tools\Scripts" or "C:\Python25\Scripts" depending on your > Python version. ?You just need to find that directory and add it to > your PATH. > > PyPI is the Python package index. ?It's a website athttp://pypi.python.org/-- not a replacement for setuptools or > easy_install, which uses it to look up package metadata. ?Setuptools > is supposed to be superseded by distribute, which may be what you > heard. It seems to be something called pip -- Easy_install and plain setup.py install cant uninstall whereas pip can. But to install pip you have to do easy_install pip. O well :-) From harrismh777 at charter.net Sat May 14 03:29:02 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 02:29:02 -0500 Subject: turn monitor off and on In-Reply-To: References: Message-ID: <2bqzp.1932$7N5.281@newsfe04.iad> harrismh777 wrote: >> >> def turnOnMonitor(): >> SC_MONITORPOWER = 0xF170 >> win32gui.SendMessage(win32con.HWND_BROADCAST, >> win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) Wonder what the equivalent of this is in Linux... ? From steve+comp.lang.python at pearwood.info Sat May 14 03:39:31 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 May 2011 07:39:31 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 May 2011 23:46:12 -0700, rusi wrote: > Mathematics has existed for millenia. Hindu-arabic numerals (base-10 > numbers) have been known for about one millennium > The boolean domain is only a 100 years old. Unsurprisingly it is not > quite 'first-class' yet: See > http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > [Lifted from http://c2.com/cgi/wiki?EqualVsTrueFalse ] Th money-quote as regards using arbitrary objects in truth tests: [quote] All this changed with the introduction of the two-element boolean domain {true, false} which provides the vocabulary needed to assign values to boolean expressions: 3<4 is a way for writing true, 3>4 is a way for writing false, whereas the value of x>0 depends on the value of x ... [end quote] In Python, [1, 2, 3] is another way of writing true, and [] is another way of writing false. Similarly with any other arbitrary objects. The only things that bools True and False are good for are: * giving functions a canonical way of spelling true/false when they want to emit a Boolean value; * giving documentation writers a canonical way of spelling true/false when they want to discuss passing a Boolean value. Other than those conveniences, there's nothing you can do with True and False in Python that you can't do with any other set of objects. -- Steven From harrismh777 at charter.net Sat May 14 03:41:10 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 02:41:10 -0500 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: Terry Reedy wrote: >> Is there a unix linux package that can be installed that >> drops at least 'one' default standard font that will be able to render >> all or 'most' (whatever I mean by that) code points in unicode? Is this >> a Python issue at all? > > Easy, practical use of unicode is still a work in progress. Apparently... the good news for me is that SBL provides their unicode font here: http://www.sbl-site.org/educational/biblicalfonts.aspx I'm getting much closer here, but now the problem is typing. The pain with unicode fonts is that the glyph is tied to the code point for the represented character, and not tied to any code point that matches any keyboard scan code for typing. :-} So, I can now see the ancient text with accents and aparatus in all of my editors, but I still cannot type any ancient Greek with my keyboard... because I have to make up a keymap first. I don't find that SBL (nor Logos Software) has provided keymaps as yet... rats. I can read the test with Python though... yessss. m harris From steve+comp.lang.python at pearwood.info Sat May 14 03:43:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 May 2011 07:43:12 GMT Subject: turn monitor off and on References: Message-ID: <4dce3290$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 May 2011 02:20:55 -0500, harrismh777 wrote: > harrismh777 wrote: >> >> def turnOnMonitor(): >> SC_MONITORPOWER = 0xF170 >> win32gui.SendMessage(win32con.HWND_BROADCAST, >> win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > > I've never tried turning my monitor on/off without using my finger... You've never had your PC turn your monitor off after X minutes of inactivity? > gonna have to play with this... wouldn't that be a great script kiddie > tool... just turn off all the windows monitors around the world... no > problem(s) after that... > > ... what happens if you try to turn it back on with your finger... ? Then you actually turn it off, at the power switch, instead of merely off in software. > ... I have another idea... while its off, try pushing the alt key on > your keyboard... or moving your mouse... (come back on ? ) Presumably you would need to program something to watch for activity and turn it back on. It would be somewhat embarrassing if you neglected to so this... -- Steven From rustompmody at gmail.com Sat May 14 03:45:29 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 00:45:29 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 14, 12:39?pm, Steven D'Aprano wrote: > On Thu, 12 May 2011 23:46:12 -0700, rusi wrote: > > Mathematics has existed for millenia. Hindu-arabic numerals (base-10 > > numbers) have been known for about one millennium > > The boolean domain is only a 100 years old. Unsurprisingly it is not > > quite 'first-class' yet: See > >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > > [Lifted fromhttp://c2.com/cgi/wiki?EqualVsTrueFalse] > > Th money-quote as regards using arbitrary objects in truth tests: > > ? ? [quote] > ? ? All this changed with the introduction of the two-element > ? ? boolean domain {true, false} which provides the vocabulary > ? ? needed to assign values to boolean expressions: 3<4 is a > ? ? way for writing true, 3>4 is a way for writing false, > ? ? whereas the value of x>0 depends on the value of x ... > ? ? [end quote] > > In Python, [1, 2, 3] is another way of writing true, and [] is another > way of writing false. Similarly with any other arbitrary objects. Well so is [1,2] another way of writing True And then we get the interesting result that (True = True) is False From alex.kapps at web.de Sat May 14 03:59:07 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 14 May 2011 09:59:07 +0200 Subject: turn monitor off and on In-Reply-To: <2bqzp.1932$7N5.281@newsfe04.iad> References: <2bqzp.1932$7N5.281@newsfe04.iad> Message-ID: <4DCE364B.3090603@web.de> On 14.05.2011 09:29, harrismh777 wrote: > harrismh777 wrote: >>> >>> def turnOnMonitor(): >>> SC_MONITORPOWER = 0xF170 >>> win32gui.SendMessage(win32con.HWND_BROADCAST, >>> win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > > Wonder what the equivalent of this is in Linux... ? Probably xset dpms force {on,off,...} From harrismh777 at charter.net Sat May 14 04:05:11 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 03:05:11 -0500 Subject: turn monitor off and on In-Reply-To: <4dce3290$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4dce3290$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> I've never tried turning my monitor on/off without using my finger... > You've never had your PC turn your monitor off after X minutes of > inactivity? I know you're being funny, but actually, no-- I don't. That's a back-in-the-day thing... all of my monitors (and I only have a couple now because I use VNC to get to the rest of my machines) are flat panel LED, very low power, cool, and virtually indestructible. I just leave them on... with beautiful screen savers running... which aren't screen savers these days either... because nothing really burns... more like perpetual light-candy eye-pleasers... Sure, back in the day I configured my system to shutoff the CRT... but honestly, I haven't had a CRT for almost a decade... you can still shutdown the flat panel several different ways on the linux platform based on timing if you want to... in BIOS, in the OS, in gnome, using the xscreensaver, etc... but, no, I have never written a code routine to shutoff the monitor (my finger always worked just fine). :) I wrote a code routine one time just to open the drive bay door, timer(), and then close the door... from across the network... until my wife got wise to it, I would open her drive bay door over the network... it was fun for a while, even after she got wise to it... ... till the morning I tried it and she had a cup of cocoa sitting on the desk in front of the drive bay... ... there have been better days in my house. :) From nobody at nowhere.com Sat May 14 04:34:54 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 14 May 2011 09:34:54 +0100 Subject: unicode by default References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: On Fri, 13 May 2011 14:53:50 -0500, harrismh777 wrote: > The unicode consortium is very careful to make sure that thousands > of symbols have a unique code point (that's great !) but how do these > thousands of symbols actually get displayed if there is no font > consortium? Are there collections of 'standard' fonts for unicode that I > am not aware? Is there a unix linux package that can be installed that > drops at least 'one' default standard font that will be able to render all > or 'most' (whatever I mean by that) code points in unicode? Using the original meaning of "font" (US) or "fount" (commonwealth), you can't have a single font cover the whole of Unicode. A font isn't a random set of glyphs, but a set of glyphs in a common style, which can only practically be achieved for a specific alphabet. You can bundle multiple fonts covering multiple repertoires into a single TTF (etc) file, but there's not much point. In software, the term "font" is commonly used to refer to some ad-hoc mapping between codepoints and glyphs. This typically works by either associating each specific font with a specific repertoire (set of codepoints), or by simply trying each font in order until one is found with the correct glyph. This is a sufficiently common problem that the FontConfig library exists to simplify a large part of it. > Is this a Python issue at all? No. From nobody at nowhere.com Sat May 14 04:41:20 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 14 May 2011 09:41:20 +0100 Subject: How best to convert a string "list" to a python list References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: On Fri, 13 May 2011 10:15:29 -0700, noydb wrote: > I want some code to take the items in a semi-colon-delimted string "list" > and places each in a python list. I came up with below. In the name of > learning how to do things properly, do you experts have a better way of > doing it? > x = "red;blue;green;yellow" ## string of semi-colon delimited colors Provided that a semicolon is *always* a delimiter, just use the .split() method: color_list = x.split(";") For more complex formats, where there are quote and/or escape characters which allow the delimiter to occur as part of an item, you typically need to use a regular expression to match everything up to the next delimiter, and do this in a loop to extract the individual items. From pmartinsen at gmail.com Sat May 14 04:44:39 2011 From: pmartinsen at gmail.com (Paul) Date: Sat, 14 May 2011 01:44:39 -0700 (PDT) Subject: Parsing a graph image References: mailman.1510.1305281943.9059.python-list@python.org Message-ID: <759e1b75-cbf7-4caf-9658-9fbef3731dc2@34g2000pru.googlegroups.com> On May 13, 11:19?pm, Bastian Ballmann wrote: > Hi python lovers out there, > > I am searching for a library to parse data from a graph in an image file > something likehttp://pytseries.sourceforge.net/_images/yahoo.png > Any suggestions, hints, links? > > TIA && have a nice day! :) > > Basti > > ?signature.asc > < 1KViewDownload Hi, If you are trying to digitize data from the graph, you could try Dagra: http://www.BlueLeafSoftware.com/Products/Dagra/ There is a Python library for reading the files it produces. hth paul From hansmu at xs4all.nl Sat May 14 04:52:50 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 14 May 2011 10:52:50 +0200 Subject: checking if a list is empty In-Reply-To: <61e9b51a-492f-410d-8ebc-e516165795df@y12g2000yqh.googlegroups.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <8BD5792C-AFE3-4B86-82DB-B6C3F249FA5F@semanchuk.com> <61e9b51a-492f-410d-8ebc-e516165795df@y12g2000yqh.googlegroups.com> Message-ID: <4dce43a7$0$81476$e4fe514c@news.xs4all.nl> On 07/05/2011 02:43, Jon Clements wrote: > On May 7, 12:51 am, Ian Kelly wrote: >> On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk wrote: >>> What if it's not a list but a tuple or a numpy array? Often I just want to iterate through an element's items and I don't care if it's a list, set, etc. For instance, given this function definition -- >> >>> def print_items(an_iterable): >>> if not an_iterable: >>> print "The iterable is empty" >>> else: >>> for item in an_iterable: >>> print item >> >>> I get the output I want with all of these calls: >>> print_items( list() ) >>> print_items( tuple() ) >>> print_items( set() ) >>> print_items( numpy.array([]) ) >> >> But sadly it fails on iterators: >> print_items(xrange(0)) >> print_items(-x for x in []) >> print_items({}.iteritems()) > > My stab: > > from itertools import chain > > def print_it(iterable): > it = iter(iterable) > try: > head = next(it) > except StopIteration: > print 'Empty' > return > for el in chain( (head,), it ): > print el > > Not sure if I'm truly happy with that though. How about: def print_items(an_iterable): found_item = False for item in an_iterable: print item found_item = True if not found_item: print "The iterable was empty" -- HansM From nobody at nowhere.net.no Sat May 14 04:52:54 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 14 May 2011 16:52:54 +0800 Subject: how to install easy_install References: <9f994806-bb7e-4219-9d64-eb50890b4b68@18g2000prd.googlegroups.com> Message-ID: rusi wrote: > tried to install easy_install (This is on windows) > I downloaded the executable and ran it. It claimed to have done its > job. Perhaps, the abit to just click is disordering some easy steps like copy the script files into the normal place. Only when there's a particular copy then it's the time to pay attention, like some executable and/or framework. In the README.txt should mention these few easy steps -- goto /dev/null From nobody at nowhere.net.no Sat May 14 05:02:48 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 14 May 2011 17:02:48 +0800 Subject: Converting a set into list Message-ID: Hello I've stumble to find a solution to get a list from a set >>> aa= ['a','b','c','f'] >>> aa ['a', 'b', 'c', 'f'] >>> set(aa) {'a', 'c', 'b', 'f'} >>> [k for k in aa] ['a', 'b', 'c', 'f'] I repute the comprehension list too expensive, is there another method? -- goto /dev/null From vanboxem.ruben at gmail.com Sat May 14 05:09:13 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Sat, 14 May 2011 11:09:13 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: 2011/5/14 Doug Evans : > On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem > wrote: >> (now in plain-text as required by gdb mailing list) >> >> Hi, >> >> I am currently trying to integrate Python support into my toolchain >> build (including GDB of course). It is a sysrooted >> binutils+GCC+GDB+mingw-w64 toolchain. >> >> I currently have the basic setup working: I can link gdb with my >> manually generated import lib to the python dll from the official >> Windows install. If there is anything I am missing or a very easy >> solution to the problems decsribed below, please just say so. I am >> only suggesting what I would like to happen. >> >> Now on to the problems I'd like to discuss: >> >> 1. gdb.exe won't start without me having set PYTHONPATH manually. > > In a properly configured/built gdb on linux this isn't necessary, even > if python is installed in some random place. > I'm not sure about windows though. > Did you specify --with-python when you configured gdb, and if so did > you specify a value? > e.g., --with-python=SOME_VALUE I was cross-compiling a mingw toolchain+gdb from Linux, so I used --with-python without a value (because gdb configure tries to find the Python executabe), and I added -I"/path/to/python/includes" to CFLAGS and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it should. This is hacky though, and gdb configure should provide --with-python-libs and --with-python-include to make it more streamlined with any other build prerequisite (like gmp/mpfr/mpc/cloog/ppl in GCC for example). > >> I understand the need for this, but as gdb requires Python 2, and users >> of my toolchain may have installed Python 3 or a 32-bit version python >> they want to use from the same environment (without changing their own >> PYTHONPATH), there is no way to run python-enabled gdb. >> [...] > > Yeah. > There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have > gdb use that instead of PYTHONPATH if it exists, but there's been > resistance to it. > I think(!) what would happen is that gdb would set $PYTHONPATH to the > value of $GDB_PYTHONPATH. > [Inferiors started by gdb should still get the original value of > PYTHONPATH though.] That way would be almost ideal, but a hardcoded *relative* path to the python scripts (that is standardized within gdb) wouldn't hurt. An extra environment variable would require a lot of explaining for Windows, and is not "plug-and-play", like the rest of a sysrooted toolchain is supposed to be like. I think this should work on all setups: 1. Check hardcoded path; my suggestion would be "/../lib/python27" 2. If this fails to find the necessary files/scripts, find it like you described above in Linux, without PYTHONPATH set. 3. Check PYTHONPATH. I would think only number one would change, and perhaps be only enabled with a special configure option. Nothing else would have to change, and Windows users would rejoice :) Again, this is only my suggestion, if there are problems with it in way I haven't thought of, please say so, and we can come up with another solution. > >> 2. With PYTHONPATH set as a temporary workaround, gdb starts, but >> spits out a traceback: >> Traceback (most recent call last): >> ? File "", line 35, in >> ? File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line >> 18, in >> ??? gdb.command.pretty_printers.register_pretty_printer_commands() >> ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", >> line 368, in register_pretty_printer_commands >> ??? InfoPrettyPrinter() >> ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", >> line 100, in __init__ >> ??? gdb.COMMAND_DATA) >> RuntimeError: Could not find command prefix info. >> >> This is a minor problem I think, as "python import time" "python print >> time.clock()" works as expected. What is wrong? > > I'm not sure. > The error message is complaining that the "info" command prefix doesn't exist. > I don't see how that can happen as python is initialized long after > the info command is created. > Thanks for the prompt response. From eliz at gnu.org Sat May 14 05:29:57 2011 From: eliz at gnu.org (Eli Zaretskii) Date: Sat, 14 May 2011 12:29:57 +0300 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: <83ei41fx4a.fsf@gnu.org> > Date: Sat, 14 May 2011 11:09:13 +0200 > From: Ruben Van Boxem > Cc: gdb at sourceware.org, python-list at python.org > > 1. Check hardcoded path; my suggestion would be "/../lib/python27" > 2. If this fails to find the necessary files/scripts, find it like you > described above in Linux, without PYTHONPATH set. > 3. Check PYTHONPATH. > > I would think only number one would change, and perhaps be only > enabled with a special configure option. Nothing else would have to > change, and Windows users would rejoice :) The problem, I think, is that it's not so easy on Unix to get the place where the GDB executable leaves. There isn't a system call to do that (similar to what Windows gives you). So I think on Posix platforms, number 2 would be used most of the time. From __peter__ at web.de Sat May 14 05:33:15 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 14 May 2011 11:33:15 +0200 Subject: Converting a set into list References: Message-ID: TheSaint wrote: > I've stumble to find a solution to get a list from a set > > > >>>> aa= ['a','b','c','f'] >>>> aa > ['a', 'b', 'c', 'f'] >>>> set(aa) To clarify: this creates a new object, so aa is still a list. > {'a', 'c', 'b', 'f'} >>>> [k for k in aa] > ['a', 'b', 'c', 'f'] So you are actually converting a list to a (new) list here. Of course it would have worked with a set or an arbitrary iterable, too. > > I repute the comprehension list too expensive, is there another method? mylist = list(myset) Do you notice the similarity to converting a list to a set? From vanboxem.ruben at gmail.com Sat May 14 06:10:03 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Sat, 14 May 2011 12:10:03 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: <83ei41fx4a.fsf@gnu.org> References: <83ei41fx4a.fsf@gnu.org> Message-ID: 2011/5/14 Eli Zaretskii : >> Date: Sat, 14 May 2011 11:09:13 +0200 >> From: Ruben Van Boxem >> Cc: gdb at sourceware.org, python-list at python.org >> >> 1. Check hardcoded path; my suggestion would be "/../lib/python27" >> 2. If this fails to find the necessary files/scripts, find it like you >> described above in Linux, without PYTHONPATH set. >> 3. Check PYTHONPATH. >> >> I would think only number one would change, and perhaps be only >> enabled with a special configure option. Nothing else would have to >> change, and Windows users would rejoice :) > > The problem, I think, is that it's not so easy on Unix to get the > place where the GDB executable leaves. ?There isn't a system call to > do that (similar to what Windows gives you). > > So I think on Posix platforms, number 2 would be used most of the > time. > I understand. So better/feasible would be: Windows: Check /../lib/python27 or any configure-time specified relative path to gdb executable? If that fails, revert to current behavoir. POSIX (so pretty much everythin else): Keep current behavior. Which would come down to a configure option+ a small block of #if _WIN32 code in the Python part of the code. Thanks, Ruben From dan.kluev at gmail.com Sat May 14 06:16:02 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sat, 14 May 2011 21:16:02 +1100 Subject: How best to convert a string "list" to a python list In-Reply-To: References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: On Sat, May 14, 2011 at 7:41 PM, Nobody wrote: > to use a regular expression to match everything up to the next delimiter, > and do this in a loop to extract the individual items. re.findall() should let you match all items at once, without loop. -- With best regards, Daniel Kluev From wxjmfauth at gmail.com Sat May 14 06:26:26 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Sat, 14 May 2011 03:26:26 -0700 (PDT) Subject: unicode by default References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: On 14 mai, 09:41, harrismh777 wrote: > ... > I'm getting much closer here, > ... You should really understand, that Unicode is a domain per se. It is independent from any os's, programming languages or applications. It is up to these tools to be "unicode" compliant. Working in a full unicode mode (at least for texts) is today practically a solved problem. But you have to ensure the whole toolchain is unicode compliant (editors, fonts (OpenType technology), rendering devices, ...). Tip. This list is certainly not the best place to grab informations. I suggest you start by getting informations about XeTeX. XeTeX is the "new" TeX engine working only in a unicode mode. From this starting point, you will fall on plenty web sites speaking about the "unicode world", tools, fonts, ... A variant is to visit sites speaking about *typography*. jmf From chrispaton2005 at gmail.com Sat May 14 07:48:31 2011 From: chrispaton2005 at gmail.com (Chris Paton) Date: Sat, 14 May 2011 12:48:31 +0100 Subject: Having a problem getting python working... Message-ID: <6E09A0F4-B9A6-4C9F-874B-CB6E21EF7A45@gmail.com> Hey all, Not sure if this is the right place to put this (forgive me for my ignorance, I'm looking everywhere!). I'm having a problem getting IDLE working. I'm working off Mac OSX 10.6.7 with Python 3.2 installed and I installed Activetcl 8.5.9 as recommended. IDLE is still crashing at random moments - loading, saving, typing, compiling... I tried to do a simple 'hello world' but it kept crashing. There's no official report; I just get the spinning beach ball then have to force quit. I'm quite new to all of this so any help would be extremely appreciated. Need to get into this ASAP as I need to do some stuff for my thesis project! Thanks! Chris From highfellow at gmail.com Sat May 14 09:12:44 2011 From: highfellow at gmail.com (Andy Baxter) Date: Sat, 14 May 2011 14:12:44 +0100 Subject: threads with gtk gui problem Message-ID: <4DCE7FCC.8020907@gmail.com> Hi, I'm working on adding a Gtk GUI to a python program. Its main function is to read raw data from an arduino board over USB, and convert it to MIDI note/controller events to be sent to another program. I've had it working fine with just a command line interface, but when I replaced the command line with a Gtk interface, I started having problems getting the thread that reads the USB port to run. I'm not sure what the custom is on this list for pasting code - It's a long program so I don't want to paste the whole thing. The sequence of events I've coded is: - the program starts. - the port reader thread (which is a threading.Thread subclass) is initialised. - the object which controls the interface is initialised (i.e. the glade file is loaded.) - the port reader is started (i.e. the 'start' method is called, which calls the 'run' method in a thread). - then the gtk main loop is run. The behaviour I'm getting is that the port reader either fails to start, or stops running at the point where it tries to initialise the serial port. It then does nothing until I close the main window, at which point it starts running again. The port reader's run method begins like this: # the method called by the thread superclass to run the main loop of the thread. def run(self): # main loop of thread. print "Starting port reader." fhan=serial.Serial(port=keeper.config['usbPort'], baudrate=keeper.config['usbBaud'], timeout=0.1) print "1" fhan.open() print "2" seq=PySeq() # the sequencer library object port=seq.createOutPort(keeper.config['midiPortName']) # make a midi out port. midich=keeper.config['midich'] print "3" while True: inbuf=[] print ".", char=fhan.read(1) if self.quit: fhan.close() return if len(char)==0: continue ... (code to process the character read in) ('keeper' is a global object which stores the config data and references to a few key objects). When you start the program, the thread stops either before the first print statement, or on the line which initialises the serial port ( fhan=serial.Serial(...) ). '1', '2', and '3' only get printed /after/ you close the gtk main window. Can anyone help with this? cheers, andy baxter -- http://highfellow.org From rosuav at gmail.com Sat May 14 09:42:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 May 2011 23:42:45 +1000 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 14, 2011 at 5:45 PM, rusi wrote: > And then we get the interesting result that > (True = True) is False How does this work? In Python, the = sign is illegal there, and if you mean True == True, then it's True (obviously), which is not False. Chris Angelico From ben+python at benfinney.id.au Sat May 14 10:12:31 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 May 2011 00:12:31 +1000 Subject: Converting a set into list References: Message-ID: <87iptdid68.fsf@benfinney.id.au> TheSaint writes: > Hello > > I've stumble to find a solution to get a list from a set > > > > >>> aa= ['a','b','c','f'] Creates a new list object. Binds the name ?aa? to that object. > >>> aa > ['a', 'b', 'c', 'f'] Evaluates the object referenced by the name ?aa?. > >>> set(aa) > {'a', 'c', 'b', 'f'} Creates a new set object, populating it with the contents from the list object referenced by ?aa?. Doesn't do anything with the new set object, which will soon be garbage-collected. > >>> [k for k in aa] > ['a', 'b', 'c', 'f'] Creates a new list object by iterating each of the items from the list referenced by ?aa?. Does nothing with the new list object, which will soon be garbage-collected. > > I repute the comprehension list too expensive, is there another method? Another method to do what? If you want to bind ?aa? to a new object, do so with an assignment statement. (Your example has exactly one assignment statement; all the other statements create objects which are never bound to anything.) But what is it you actually want to do? -- \ ?The fact that I have no remedy for all the sorrows of the | `\ world is no reason for my accepting yours. It simply supports | _o__) the strong probability that yours is a fake.? ?Henry L. Mencken | Ben Finney From nobody at nowhere.net.no Sat May 14 10:14:40 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 14 May 2011 22:14:40 +0800 Subject: Converting a set into list References: Message-ID: Peter Otten wrote: > mylist = list(myset) > Do you notice the similarity to converting a list to a set? > There was something confusing me yesterday in doing that, but (for me strangely) I got cleared out. The point was that after a result from: newset= set(myset1) & set(myset2) list= [newset] << [{'bla', 'alb', 'lab'}] Probably list(set) is not like [set]. -- goto /dev/null From drobinow at gmail.com Sat May 14 10:28:07 2011 From: drobinow at gmail.com (David Robinow) Date: Sat, 14 May 2011 10:28:07 -0400 Subject: checking if a list is empty In-Reply-To: <93682bFq0fU2@mid.individual.net> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <93682bFq0fU2@mid.individual.net> Message-ID: On Fri, May 13, 2011 at 10:34 PM, Gregory Ewing wrote: > rusi wrote: > >> Dijkstra's problem (paraphrased) is that python, by choosing the >> FORTRAN alternative of having a non-first-class boolean type, hinders >> scientific/mathematical thinking/progress. > > Python doesn't have the flaw that Dijkstra was talking about. > Fortran's flaw wasn't so much the lack of a boolean type, but > that you couldn't assign the result of a logical expression to > a variable. Python has always been able to do that, even before > it had a distinct boolean type. And Fortran could do it at least 25 years before Python was invented. From nobody at nowhere.net.no Sat May 14 10:51:30 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 14 May 2011 22:51:30 +0800 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Another method to do what? > Sorry, some time we expect to have said it as we thought it. The example was to show that after having made a set set(aa) the need to get that set converted into a list. My knowledge drove me to use a comprehension list as a converter. In another post I got to know the simplest way to state list(aa) Where aa is a set. -- goto /dev/null From roy at panix.com Sat May 14 11:04:15 2011 From: roy at panix.com (Roy Smith) Date: Sat, 14 May 2011 11:04:15 -0400 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <93682bFq0fU2@mid.individual.net> Message-ID: In article , David Robinow wrote: > On Fri, May 13, 2011 at 10:34 PM, Gregory Ewing > wrote: > > rusi wrote: > > > >> Dijkstra's problem (paraphrased) is that python, by choosing the > >> FORTRAN alternative of having a non-first-class boolean type, hinders > >> scientific/mathematical thinking/progress. > > > > Python doesn't have the flaw that Dijkstra was talking about. > > Fortran's flaw wasn't so much the lack of a boolean type, but > > that you couldn't assign the result of a logical expression to > > a variable. Python has always been able to do that, even before > > it had a distinct boolean type. > And Fortran could do it at least 25 years before Python was invented. I vaguely remember that Fortran called the data type LOGICAL, but yes, it was exactly what most modern languages call a bool or boolean. And the operators were spelled .NOT., .AND., .OR., etc but that's because Fortran was designed for punch cards, which didn't have much in the way of special characters. From cesium5500 at yahoo.ca Sat May 14 11:11:36 2011 From: cesium5500 at yahoo.ca (cesium5500 at yahoo.ca) Date: Sat, 14 May 2011 11:11:36 -0400 Subject: Question about available python lib for a task Message-ID: <4DCE9BA8.6030509@yahoo.ca> Hello, I would like to build a database of all the MS-Excel file on a LAN. I would like to get the files metadata : filename, summary, location, size, etc. Is there a dedicated python lib for the task? Is pywin32 one of the possible lib available? I would prefer to not building everything from scratch testing, etc. ETL software could also is a solution maybe... Thanks From rustompmody at gmail.com Sat May 14 11:47:41 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 08:47:41 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 14, 6:42?pm, Chris Angelico wrote: > On Sat, May 14, 2011 at 5:45 PM, rusi wrote: > > And then we get the interesting result that > > (True = True) is False > > How does this work? In Python, the = sign is illegal there, and if you > mean True == True, then it's True (obviously), which is not False. > > Chris Angelico 1. = vs == Ok to be true to python syntax I should have said (True == True) is False. But then the question arises, is the is a python is or an English is? If its python then that's fine but its just bland code with no discussion about it. To say something about it (in English) one would have to say (True == True) is False is True (where the first is is a python is and the second an English one). 2. True == True is (obviously) True Here is the quote (with internal quote from Dijkstra) from Steven that I was answering: ------------------------------ [Dijkstra quote] All this changed with the introduction of the two-element boolean domain {true, false} which provides the vocabulary needed to assign values to boolean expressions: 3<4 is a way for writing true, 3>4 is a way for writing false, whereas the value of x>0 depends on the value of x ... [end quote] [Steven quote] In Python, [1, 2, 3] is another way of writing true, and [] is another way of writing false. Similarly with any other arbitrary objects. The only things that bools True and False are good for are: [end Steven quote] ------------------------ So since [1,2,3] is one way of writing True (lets call it True3) and [1,2] is another (call it True2) then we have True3 == True2 is False But since according to Steven (according to Python?) True3 *is the same* as True2 we get False = [1,2,3] == [1,2] = True3 == True2 = True == True = True From rosuav at gmail.com Sat May 14 11:55:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 May 2011 01:55:34 +1000 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 15, 2011 at 1:47 AM, rusi wrote: > So since > [1,2,3] is one way of writing True (lets call it True3) > and [1,2] is another (call it True2) > then we have True3 == True2 is False > > But since according to Steven (according to Python?) True3 *is the > same* as True2 > we get > ?False > = [1,2,3] == [1,2] > = True3 ?== True2 > = True == True > = True Okay, I see what you're doing here. http://www.rinkworks.com/ithink/search.cgi?words=compress When you condense a whole lot of information down to just two states, True and False, *obviously* there'll be a huge amount that fits into one or the other without being identical. It's not an argument for whether [1,2,3] ought to be True or ought to be False. You could make the exact same argument if they evaluated to False. You have proven nothing and just wasted your time proving it. Chris Angelico From nobody at nowhere.net.no Sat May 14 11:55:45 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 14 May 2011 23:55:45 +0800 Subject: Trace in a class Message-ID: Hello, first of all, I'm a dummy in programming. My methods are just do-it-and-try- it. For more convinience I commonly using and go with step-into and breakpoints. Lately I was setting a class, but it's incomplete and just calling it at the pdb prompt line I can't use breakpoints or stop it to check what values are coming into the play. BTW, would it be much difference to use the class functions outside the class. I mean I don't declare the class statement just leave funtions alone in the module. -- goto /dev/null From hujun.work at gmail.com Sat May 14 12:02:59 2011 From: hujun.work at gmail.com (Jun Hu) Date: Sat, 14 May 2011 09:02:59 -0700 Subject: Get IP address of WIFI interface In-Reply-To: References: Message-ID: Thanks, is there any other way without using external command? On Fri, May 13, 2011 at 10:41 PM, Ishwor Gurung wrote: > Hi. > > On 14 May 2011 14:46, Far.Runner wrote: > > Hi Python Experts: > > There are two network interfaces on my laptop, one is > > 100M Ethernet interface, the other is wifi interface, both are connected > and > > has an IP address. then the question is: how to get the ip address of the > > wifi interface in a python script? > > OS: Windows or Linux > > Detect the OS with os.name and branch out to specific use case. > > The specific functionality can be implemented 2 ways: > 1/ Regular expression pattern match > 2/ Substring match and splits > > The subprocess module will then let you run those commands. > 1/ posix - (Linux in your case) will use ifconfig > 2/ nt - (windows in your ase) will use ipconfig. > > HTH. > > > > -- > > Regards > Ishwor Gurung > Key id:0xa98db35e > Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Sat May 14 13:24:13 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 10:24:13 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> Message-ID: <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> On May 14, 2:48?am, Mark Dickinson wrote: > I don't see this (or Hans' version) as cheating at all. Yeah sure -- cheating is a strong word :-) > This really *is* the power algorithm, just in a different number system from the > usual one. Yes that was my point. If we take the standard logarithmic power algo as trivial (in the sense that it is well known) then all these solutions do heavy-lifting to transform fib to power and then use the 'trivial' algo. A more direct approach would be to use the identities: f_2n = f_n ^ 2 + 2*f_n * f_(n-1) f_(2n-1) = f_n ^ 2 + f_(n-1) ^ 2 The naive python implementation of which is: def even(n): return n % 2 == 0 def sq(x): return x * x def fib(n): if n==1 or n==2: return 1 elif even(n): return sq(fib (n//2)) + 2 * fib(n//2) * fib(n//2 - 1) else: return sq(fib (n//2 + 1)) + sq(fib(n // 2)) This is a strange algo -- logarithmic because it halves the n, exponential because of the double (triple) calls. [I cannot say I know how to work out its exact complexity but I would guess its about linear] -------------- BTW How do I parse "the ring Z[x] / (x^2 - x - 1)"? Is this a division ring? From rustompmody at gmail.com Sat May 14 13:43:31 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 10:43:31 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <311327ac-2593-44d7-b19d-32533af87d4b@x38g2000pri.googlegroups.com> On May 14, 8:55?pm, Chris Angelico wrote: > On Sun, May 15, 2011 at 1:47 AM, rusi wrote: > > So since > > [1,2,3] is one way of writing True (lets call it True3) > > and [1,2] is another (call it True2) > > then we have True3 == True2 is False > > > But since according to Steven (according to Python?) True3 *is the > > same* as True2 > > we get > > ?False > > = [1,2,3] == [1,2] > > = True3 ?== True2 > > = True == True > > = True > > Okay, I see what you're doing here. > > http://www.rinkworks.com/ithink/search.cgi?words=compress LOL -- Thanks for that. But it seems you did not get the moral? Spelt out: "Beware of lossy compression!" [Which is also the moral of my 'proof'] > > When you condense a whole lot of information down to just two states, > True and False, *obviously* there'll be a huge amount that fits into > one or the other without being identical. It's not an argument for > whether [1,2,3] ought to be True or ought to be False. You could make > the exact same argument if they evaluated to False. You have proven > nothing and just wasted your time proving it. > > Chris Angelico From rosuav at gmail.com Sat May 14 14:22:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 May 2011 04:22:33 +1000 Subject: Converting a set into list In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 12:14 AM, TheSaint wrote: > newset= set(myset1) & set(myset2) > list= [newset] > > << [{'bla', 'alb', 'lab'}] > > Probably list(set) is not like [set]. list(set) creates a list out of the set. [set] creates a list with one element, the set itself. It's not a copy of the set, it's another reference to the same set; change one and you'll see the change in the other. Chris Angelico From dje at google.com Sat May 14 14:30:55 2011 From: dje at google.com (Doug Evans) Date: Sat, 14 May 2011 11:30:55 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem wrote: > 2011/5/14 Doug Evans : >> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem >> wrote: >>> (now in plain-text as required by gdb mailing list) >>> >>> Hi, >>> >>> I am currently trying to integrate Python support into my toolchain >>> build (including GDB of course). It is a sysrooted >>> binutils+GCC+GDB+mingw-w64 toolchain. >>> >>> I currently have the basic setup working: I can link gdb with my >>> manually generated import lib to the python dll from the official >>> Windows install. If there is anything I am missing or a very easy >>> solution to the problems decsribed below, please just say so. I am >>> only suggesting what I would like to happen. >>> >>> Now on to the problems I'd like to discuss: >>> >>> 1. gdb.exe won't start without me having set PYTHONPATH manually. >> >> In a properly configured/built gdb on linux this isn't necessary, even >> if python is installed in some random place. >> I'm not sure about windows though. >> Did you specify --with-python when you configured gdb, and if so did >> you specify a value? >> e.g., --with-python=SOME_VALUE > > I was cross-compiling a mingw toolchain+gdb from Linux, so I used > --with-python without a value (because gdb configure tries to find the > Python executabe), and I added -I"/path/to/python/includes" to CFLAGS > and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it > should. This is hacky though, and gdb configure should provide > --with-python-libs and --with-python-include to make it more > streamlined with any other build prerequisite (like > gmp/mpfr/mpc/cloog/ppl in GCC for example). Ah. Cross-compiling gdb with python is in need of improvement. Alas python hasn't been designed with cross-compilation in mind (e.g. build on linux, run on windows). AIUI, the way to get the parameters required for compiling with libpython is to get them from python's "distutils": kinda hard to do in a cross-compile. Done correctly there's no need to run python. I haven't done anything more to support python in gdb's configure.ac because it's not clear to me what the right thing to do is: distutils provides more than just --libs and --includes (btw, we don't use --libs though, we use --ldflags which includes all of: the directory in which to find libpython, the -l for libpython, and the -l's for all the other libraries python needs). [Which isn't to say that someone else isn't free to tackle this.] In the meantime, what I've been doing is a hack: write a script that responds to: --includes --ldflags --exec-prefix and pass that as --with-python. E.g. bash$ cat $HOME/my-python-for-config #! /bin/sh if [ $# -ne 2 ] then echo "Bad # args. Blech!" >&2 exit 1 fi # The first argument is the path to python-config.py, ignore it. case "$2" in --includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;; --ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm -lpython2.6" ;; --exec-prefix) echo "/usr" ;; *) echo "Bad arg $2. Blech!" >&2 ; exit 1 ;; esac exit 0 bash$ ./configure --with-python=$HOME/my-python-for-config [...] [...] Note that --exec-prefix is the runtime location of python. GCC uses this to tell libpython where to find its support files. [grep for Py_SetProgramName in gdb/python/python.c] >>> I understand the need for this, but as gdb requires Python 2, and users >>> of my toolchain may have installed Python 3 or a 32-bit version python >>> they want to use from the same environment (without changing their own >>> PYTHONPATH), there is no way to run python-enabled gdb. >>> [...] >> >> Yeah. >> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have >> gdb use that instead of PYTHONPATH if it exists, but there's been >> resistance to it. >> I think(!) what would happen is that gdb would set $PYTHONPATH to the >> value of $GDB_PYTHONPATH. >> [Inferiors started by gdb should still get the original value of >> PYTHONPATH though.] > > That way would be almost ideal, but a hardcoded *relative* path to the > python scripts (that is standardized within gdb) wouldn't hurt. See above re: --exec-prefix. > An > extra environment variable would require a lot of explaining for > Windows, and is not "plug-and-play", like the rest of a sysrooted > toolchain is supposed to be like. I think this should work on all > setups: > > 1. Check hardcoded path; my suggestion would be " executable>/../lib/python27" > 2. If this fails to find the necessary files/scripts, find it like you > described above in Linux, without PYTHONPATH set. > 3. Check PYTHONPATH. The problem being solved by the proposed GDB_PYTHONPATH is "What if the user has PYTHONPATH set and it points to an incompatible version of python?". Leaving such a value for PYTHONPATH set while gdb's python is running feels wrong (and IIRC has caused some problems). The problem of telling python where to find itself is already solved (or at least is intended to be solved) with gdb's calling Py_SetProgramName with a value derived from the python-provided --exec-prefix. > I would think only number one would change, and perhaps be only > enabled with a special configure option. Nothing else would have to > change, and Windows users would rejoice :) > Again, this is only my suggestion, if there are problems with it in > way I haven't thought of, please say so, and we can come up with > another solution. From dje at google.com Sat May 14 14:38:16 2011 From: dje at google.com (Doug Evans) Date: Sat, 14 May 2011 11:38:16 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: <83ei41fx4a.fsf@gnu.org> References: <83ei41fx4a.fsf@gnu.org> Message-ID: On Sat, May 14, 2011 at 2:29 AM, Eli Zaretskii wrote: >> Date: Sat, 14 May 2011 11:09:13 +0200 >> From: Ruben Van Boxem >> Cc: gdb at sourceware.org, python-list at python.org >> >> 1. Check hardcoded path; my suggestion would be "/../lib/python27" >> 2. If this fails to find the necessary files/scripts, find it like you >> described above in Linux, without PYTHONPATH set. >> 3. Check PYTHONPATH. >> >> I would think only number one would change, and perhaps be only >> enabled with a special configure option. Nothing else would have to >> change, and Windows users would rejoice :) > > The problem, I think, is that it's not so easy on Unix to get the > place where the GDB executable leaves. ?There isn't a system call to > do that (similar to what Windows gives you). > > So I think on Posix platforms, number 2 would be used most of the > time. For reference sake, gdb is "relocatable". [meaning, if you take a gdb installation and move it, it should continue to work fine] And if gdb's python lives inside the gdb tree, that too should continue to work fine if moved with gdb (the value to pass to Py_SetProgramName is appropriately (re-)computed when gdb is run). [For completeness sake, IIRC the calculation of a path being "relocatable" isn't bulletproof, but it works in practice.] It's not impossible for gdb to find where it lives, but you're right it can be moderately difficult (basically, if argv[0] isn't an absolute path then scan $PATH for it). From andy at earthsong.free-online.co.uk Sat May 14 14:39:44 2011 From: andy at earthsong.free-online.co.uk (andy baxter) Date: Sat, 14 May 2011 19:39:44 +0100 Subject: threads with gtk gui problem In-Reply-To: <4DCE7FCC.8020907@gmail.com> References: <4DCE7FCC.8020907@gmail.com> Message-ID: <4DCECC70.5020703@earthsong.free-online.co.uk> On 14/05/11 14:12, Andy Baxter wrote: > Hi, > > I'm working on adding a Gtk GUI to a python program. Its main function > is to read raw data from an arduino board over USB, and convert it to > MIDI note/controller events to be sent to another program. I've had it > working fine with just a command line interface, but when I replaced > the command line with a Gtk interface, I started having problems > getting the thread that reads the USB port to run. > > I'm not sure what the custom is on this list for pasting code - It's a > long program so I don't want to paste the whole thing. > > The sequence of events I've coded is: > > - the program starts. > - the port reader thread (which is a threading.Thread subclass) is > initialised. > - the object which controls the interface is initialised (i.e. the > glade file is loaded.) > - the port reader is started (i.e. the 'start' method is called, which > calls the 'run' method in a thread). > - then the gtk main loop is run. > > The behaviour I'm getting is that the port reader either fails to > start, or stops running at the point where it tries to initialise the > serial port. It then does nothing until I close the main window, at > which point it starts running again. > > The port reader's run method begins like this: > > # the method called by the thread superclass to run the main loop > of the thread. > def run(self): > # main loop of thread. > print "Starting port reader." > fhan=serial.Serial(port=keeper.config['usbPort'], > baudrate=keeper.config['usbBaud'], timeout=0.1) > print "1" > fhan.open() > print "2" > seq=PySeq() # the sequencer library object > port=seq.createOutPort(keeper.config['midiPortName']) # make a > midi out port. > midich=keeper.config['midich'] > print "3" > while True: > inbuf=[] > print ".", > char=fhan.read(1) > if self.quit: > fhan.close() > return > if len(char)==0: continue > ... (code to process the character read in) > > ('keeper' is a global object which stores the config data and > references to a few key objects). > > When you start the program, the thread stops either before the first > print statement, or on the line which initialises the serial port ( > fhan=serial.Serial(...) ). '1', '2', and '3' only get printed /after/ > you close the gtk main window. > I've verified that the problem is due to the gtk main loop interfering with the thread I've started. If I use this code: if __name__ == "__main__": print "Starting mapper" keeper=Keeper() # initialise the keeper. (A global object which holds references to key objects) keeper.start() # tell the keeper to start the port reader. for n in xrange(10): # wait for 10 seconds. time.sleep(1) print "x" #gtk.main() # start the gtk main loop. keeper.stop() # tell the keeper to shut things down. the program runs correctly. I.e. values are read from the usb port when they come in. if I use this code: if __name__ == "__main__": print "Starting mapper" keeper=Keeper() # initialise the keeper. (A global object which holds references to key objects) keeper.start() # tell the keeper to start the port reader. #for n in xrange(10): # time.sleep(1) # print "x" gtk.main() # start the gtk main loop. keeper.stop() # tell the keeper to shut things down. The port reader thread blocks at the point it tries to open the serial port. I.e. 'Starting port reader' is printed straight away, but '1', '2', and '3' are only printed after you close the gtk main window. From dje at google.com Sat May 14 14:40:15 2011 From: dje at google.com (Doug Evans) Date: Sat, 14 May 2011 11:40:15 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: On Sat, May 14, 2011 at 11:30 AM, Doug Evans wrote: > Note that --exec-prefix is the runtime location of python. > GCC uses this to tell libpython where to find its support files. > [grep for Py_SetProgramName in gdb/python/python.c] Oops. s/GCC/GDB/ From andy at earthsong.free-online.co.uk Sat May 14 14:51:37 2011 From: andy at earthsong.free-online.co.uk (andy baxter) Date: Sat, 14 May 2011 19:51:37 +0100 Subject: threads with gtk gui problem In-Reply-To: <4DCE7FCC.8020907@gmail.com> References: <4DCE7FCC.8020907@gmail.com> Message-ID: <4DCECF39.5020701@earthsong.free-online.co.uk> On 14/05/11 14:12, Andy Baxter wrote: > Hi, > > I'm working on adding a Gtk GUI to a python program. Its main function > is to read raw data from an arduino board over USB, and convert it to > MIDI note/controller events to be sent to another program. I've had it > working fine with just a command line interface, but when I replaced > the command line with a Gtk interface, I started having problems > getting the thread that reads the USB port to run. I've solved this by adding 'import gobject' and 'gobject.threads_init()' to the start of the program. Looks like if you don't do this then the gtk main loop never releases the python threading lock to other threads. andy From tjreedy at udel.edu Sat May 14 15:58:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 15:58:28 -0400 Subject: turn monitor off and on In-Reply-To: References: Message-ID: On 5/14/2011 3:20 AM, harrismh777 wrote: > harrismh777 wrote: >> >> def turnOnMonitor(): >> SC_MONITORPOWER = 0xF170 >> win32gui.SendMessage(win32con.HWND_BROADCAST, >> win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > > I've never tried turning my monitor on/off without using my finger... The computer cannot turn off the monitor. It can only tell the graphics card to turnoff the signal to the monitor. My monitor then displays 'No signal detected' in a box and puts itself into a low-power state awaiting a signal. Even if the monitor does not do that, a black screen should use less power. Why the turnon does not work, if indeed it does not (and the monitor is not failing to respond to its resumption) is not a Python question. 2 and -1 as off and on parameters is a bit strange. The OP might try a different api reference source or ask on a windows innards list. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 14 15:59:33 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 15:59:33 -0400 Subject: How best to convert a string "list" to a python list In-Reply-To: References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: On 5/14/2011 4:41 AM, Nobody wrote: > On Fri, 13 May 2011 10:15:29 -0700, noydb wrote: > >> I want some code to take the items in a semi-colon-delimted string "list" >> and places each in a python list. I came up with below. In the name of >> learning how to do things properly, do you experts have a better way of >> doing it? > >> x = "red;blue;green;yellow" ## string of semi-colon delimited colors > > Provided that a semicolon is *always* a delimiter, just use the .split() > method: > > color_list = x.split(";") > > For more complex formats, where there are quote and/or escape characters > which allow the delimiter to occur as part of an item, you typically need > to use a regular expression to match everything up to the next delimiter, > and do this in a loop to extract the individual items. Or, for some formats, use the cvs module. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 14 16:26:53 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 16:26:53 -0400 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: On 5/14/2011 3:41 AM, harrismh777 wrote: > Terry Reedy wrote: >> Easy, practical use of unicode is still a work in progress. > > Apparently... the good news for me is that SBL provides their unicode > font here: > > http://www.sbl-site.org/educational/biblicalfonts.aspx > > I'm getting much closer here, but now the problem is typing. The pain > with unicode fonts is that the glyph is tied to the code point for the > represented character, and not tied to any code point that matches any > keyboard scan code for typing. :-} > > So, I can now see the ancient text with accents and aparatus in all of > my editors, but I still cannot type any ancient Greek with my > keyboard... because I have to make up a keymap first. > > I don't find that SBL (nor Logos Software) has provided keymaps as > yet... rats. You need what is called, at least with Windows, an IME -- Input Method Editor. These are part of (or associated with) the OS, so they can be used with *any* application that will accept unicode chars (in whatever encoding) rather than just ascii chars. Windows has about a hundred or so, including Greek. I do not know if that includes classical Greek with the extra marks. > I can read the test with Python though... yessss. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 14 16:31:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 16:31:30 -0400 Subject: Question about available python lib for a task In-Reply-To: <4DCE9BA8.6030509@yahoo.ca> References: <4DCE9BA8.6030509@yahoo.ca> Message-ID: On 5/14/2011 11:11 AM, cesium5500 at yahoo.ca wrote: > I would like to build a database of all the MS-Excel file on a LAN. I > would like to get the files metadata : filename, summary, location, > size, etc. You subject line is about a non-specific as can be, which means that the person who can answer would not know and would likely skip over it. Something like "Wanted: a module to catalog Excel files on a LAN" would grab attention better. > Is there a dedicated python lib for the task? Is pywin32 one of the > possible lib available? Sorry, I have no idea. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 14 16:53:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 16:53:39 -0400 Subject: checking if a list is empty In-Reply-To: <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/14/2011 3:39 AM, Steven D'Aprano wrote: > Th money-quote as regards using arbitrary objects in truth tests: > > [quote] > All this changed with the introduction of the two-element > boolean domain {true, false} which provides the vocabulary > needed to assign values to boolean expressions: 3<4 is a > way for writing true, 3>4 is a way for writing false, > whereas the value of x>0 depends on the value of x ... > [end quote] > > > In Python, [1, 2, 3] is another way of writing true, and [] is another > way of writing false. Similarly with any other arbitrary objects. Another way to look at it is that Python automatically calls bool() on every expression in its two boolean or conditional contexts: 'if e:' and 'while e'. This is a boilerplate-removing, labor-saving convenience. Python has many such conveniences. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 14 16:59:40 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 16:59:40 -0400 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/14/2011 3:45 AM, rusi wrote: > (True = True) is False is a syntax error ;-) and 'True = True' is a (useless) statement, and statements do not have boolean values, and 'True == True' *is* True, which is to say, ((True == True) is False) is False. -- Terry Jan Reedy From ian.g.kelly at gmail.com Sat May 14 17:19:55 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 May 2011 15:19:55 -0600 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> Message-ID: On Sat, May 14, 2011 at 11:24 AM, rusi wrote: > def fib(n): > ? ?if n==1 or n==2: > ? ? ? ?return 1 > ? ?elif even(n): > ? ? ? ?return sq(fib (n//2)) + 2 * fib(n//2) * fib(n//2 - 1) > ? ?else: > ? ? ? ?return sq(fib (n//2 + 1)) + sq(fib(n // 2)) > > This is a strange algo ?-- logarithmic because it halves the n, > exponential because of the double (triple) calls. ?[I cannot say I > know how to work out its exact complexity but I would guess its about > linear] Yup, linear. Assuming you optimize the even case so that it doesn't actually call fib(n//2) twice, the call tree can be approximated as a balanced binary tree with height log(n). The total number of nodes in the tree is thus O(2 ** log(n)) = O(n). From tjreedy at udel.edu Sat May 14 17:29:53 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 17:29:53 -0400 Subject: checking if a list is empty In-Reply-To: <311327ac-2593-44d7-b19d-32533af87d4b@x38g2000pri.googlegroups.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <311327ac-2593-44d7-b19d-32533af87d4b@x38g2000pri.googlegroups.com> Message-ID: On 5/14/2011 1:43 PM, rusi wrote: > But it seems you did not get the moral? Spelt out: "Beware of lossy > compression!" > [Which is also the moral of my 'proof'] I get it now. As I suggested in response to Stephen, [] and [1] spell False and True only in boolean contexts (if/while headers) where they are implicitly wrapped with a bool() call, which is to say, where their boolean value is extracted from them. As you point out, there is information loss as all other context-irrelevant details are ignored. -- Terry Jan Reedy From brenNOSPAMbarn at NObrenSPAMbarn.net Sat May 14 19:01:15 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 14 May 2011 23:01:15 +0000 (UTC) Subject: Python drawing library? Message-ID: Is there any Python library for interactive drawing? I've done some googling but most searches for "drawing" lead me to libraries for programmatic creation of shapes on some GUI canvas. I'm looking for GUI widgets that allow the user to draw with the mouse, like a paint program, and let me get info about the drawing as its made (get color at mouse location, etc.). I'd prefer a wxPython solution, although any Python solution would be better than none. Thanks, -- --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 ben+python at benfinney.id.au Sat May 14 19:21:38 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 May 2011 09:21:38 +1000 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> Message-ID: <871v00j2bh.fsf@benfinney.id.au> TheSaint writes: > The example was to show that after having made a set > > set(aa) > > the need to get that set converted into a list. As pointed out: you already know how to create a set from an object; creating a list from an object is very similar: list(set(aa)) But why are you doing that? What are you trying to achieve? -- \ ?We are all agreed that your theory is crazy. The question that | `\ divides us is whether it is crazy enough to have a chance of | _o__) being correct.? ?Niels Bohr (to Wolfgang Pauli), 1958 | Ben Finney From ben+python at benfinney.id.au Sat May 14 19:26:59 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 May 2011 09:26:59 +1000 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wrhshni4.fsf@benfinney.id.au> rusi writes: > [Steven quote] > In Python, [1, 2, 3] is another way of writing true, and [] is another > way of writing false. Similarly with any other arbitrary objects. The > only things that bools True and False are good for are: > > [end Steven quote] > ------------------------ > > So since > [1,2,3] is one way of writing True (lets call it True3) No. Steven knew exactly why he was using ?true? versus ?True?. He's explained why elsewhere in this thread. The former does not refer to the Python boolean singleton, the latter does. The only object that is True is the True singleton. But there are many objects that are true. -- \ ?I got up the other day, and everything in my apartment has | `\ been stolen and replaced with an exact replica.? ?Steven Wright | _o__) | Ben Finney From ben+python at benfinney.id.au Sat May 14 19:47:05 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 May 2011 09:47:05 +1000 Subject: unicode by default References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: <87r580hmkm.fsf@benfinney.id.au> Terry Reedy writes: > You need what is called, at least with Windows, an IME -- Input Method > Editor. For a GNOME or KDE environment you want an input method framework; I recommend IBus which comes with the major GNU+Linux operating systems . Then you have a wide range of input methods available. Many of them are specific to local writing systems. For writing special characters in English text, I use either ?rfc1345? or ?latex? within IBus. That allows special characters to be typed into any program which communicates with the desktop environment's input routines. Yay, unified input of special characters! Except Emacs :-( which fortunately has ?ibus-el? available to work with IBus :-). -- \ ??????????| `\ (What is undesirable to you, do not do to others.) | _o__) ???? Confucius, 551 BCE ? 479 BCE | Ben Finney From see at sig.for.address Sat May 14 20:08:24 2011 From: see at sig.for.address (Victor Eijkhout) Date: Sat, 14 May 2011 19:08:24 -0500 Subject: I don't understand generator.send() Message-ID: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> #! /usr/bin/env python def ints(): i=0 while True: yield i i += 1 gen = ints() while True: i = gen.next() print i if i==5: r = gen.send(2) print "return:",r if i>10: break I thought the send call would push the value "2" at the front of the queue. Instead it coughs up the 2, which seems senseless to me. 1/ How should I view the send call? I'm reading the manual and dont' get it 2/ Is there a way to push something in the generator object? So that it becomes the next yield expression? In my code I was hoping to get 0,1,2,3,4,5,2,6,7 as yield expressions. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From harrismh777 at charter.net Sat May 14 20:25:39 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 19:25:39 -0500 Subject: turn monitor off and on In-Reply-To: References: Message-ID: <74Fzp.572$ar1.165@newsfe08.iad> Terry Reedy wrote: > The computer cannot turn off the monitor. ... this was my point ;-) From brenNOSPAMbarn at NObrenSPAMbarn.net Sat May 14 20:38:47 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sun, 15 May 2011 00:38:47 +0000 (UTC) Subject: I don't understand generator.send() References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: Victor Eijkhout wrote: > #! /usr/bin/env python > > def ints(): > i=0 > while True: > yield i > i += 1 > > gen = ints() > while True: > i = gen.next() > print i > if i==5: > r = gen.send(2) > print "return:",r > if i>10: > break > > I thought the send call would push the value "2" at the front of > the queue. Instead it coughs up the 2, which seems senseless to me. > > 1/ How should I view the send call? I'm reading the manual and > dont' get it > 2/ Is there a way to push something in the generator object? So > that it becomes the next yield expression? In my code I was hoping > to get 0,1,2,3,4,5,2,6,7 as yield expressions. You can't usefully use send() unless the generator is set up to make use of the sent values. You can't just push values into any old generator. For it to do anything, you need to use assign the result of the yield to something within your generator and make use of it. See http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features for an example. -- --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 crebert at ucsd.edu Sat May 14 20:47:00 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Sat, 14 May 2011 17:47:00 -0700 Subject: I don't understand generator.send() In-Reply-To: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sat, May 14, 2011 at 5:08 PM, Victor Eijkhout wrote: > #! /usr/bin/env python > > def ints(): > ? ?i=0 > ? ?while True: > ? ? ? ?yield i > ? ? ? ?i += 1 > > gen = ints() > while True: > ? ?i = gen.next() > ? ?print i > ? ?if i==5: > ? ? ? ?r = gen.send(2) > ? ? ? ?print "return:",r > ? ?if i>10: > ? ? ? ?break > > I thought the send call would push the value "2" at the front of the > queue. Instead it coughs up the 2, which seems senseless to me. > > 1/ How should I view the send call? I'm reading the manual and dont' get > it `yield` is an expression. Within the generator, the result of that expression is [, ignoring the complications of .throw() etc.,] the argument to .send(). You're currently using `yield` only as a statement, so it's no wonder you're not quite understanding .send(). I think this example should clarify things somewhat: >>> def example(start): ... i = ord(start) ... while True: ... sent = (yield chr(i)) # Note use of yield as expression ... print('was sent', sent) ... i += 1 ... >>> g = example('a') >>> g.send(3) Traceback (most recent call last): File "", line 1, in TypeError: can't send non-None value to a just-started generator >>> # Ok, so we can't send something back to `yield` >>> # until we hit the first `yield`. >>> g.send(None) # Follow the error message's advice 'a' >>> g.send(3) # Let's try again now. was sent 3 'b' >>> g.send(5) was sent 5 'c' >>> g.send(9) was sent 9 'd' >>> Cheers, Chris -- http://rebertia.com From rosuav at gmail.com Sat May 14 20:47:09 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 May 2011 10:47:09 +1000 Subject: I don't understand generator.send() In-Reply-To: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sun, May 15, 2011 at 10:08 AM, Victor Eijkhout wrote: > ? ? ? ?yield i > ? ? ? ?r = gen.send(2) When you send() something to a generator, it becomes the return value of the yield expression. See the example here: http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features For what you're doing, there's a little complexity. If I understand, you want send() to be like an ungetc call... you could do that like this: def ints(): i=0 while True: sent=(yield i) if sent is not None: yield None # This becomes the return value from gen.send() yield sent # This is the next value yielded i += 1 This lets you insert at most one value per iteration. Supporting more than one insertion is more complicated, but changing the loop structure entirely may help: def ints(): i=0 queue=[] while True: if queue: # see other thread, this IS legal and pythonic and quite sensible sent=(yield queue.pop(0)) else: sent=(yield i) i+=1 if sent is not None: yield None # This is the return value from gen.send() queue.append(sent) With this generator, you maintain a queue of sent values (if you want it to be a LIFO stack rather than a FIFO queue, just change the pop(0) to just pop()), and if the queue's empty, it produces sequential integers. (Incidentally, the sent values don't have to be integers. I leave it to you to decide whether that's any use or not.) Hope that helps! Chris Angelico From ian.g.kelly at gmail.com Sat May 14 20:57:56 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 May 2011 18:57:56 -0600 Subject: I don't understand generator.send() In-Reply-To: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sat, May 14, 2011 at 6:08 PM, Victor Eijkhout wrote: > I thought the send call would push the value "2" at the front of the > queue. Instead it coughs up the 2, which seems senseless to me. > > 1/ How should I view the send call? I'm reading the manual and dont' get > it There is no queue unless you create one inside the generator. The generator by itself behaves more like a coroutine. > 2/ Is there a way to push something in the generator object? So that it > becomes the next yield expression? In my code I was hoping to get > 0,1,2,3,4,5,2,6,7 as yield expressions. This will do what you're asking for: def ints(): i=0 while True: next_yield = (yield i) while next_yield is not None: next_yield = (yield next_yield) i += 1 However, I don't think this is what you want. The send call returns a yield expression, which will then be the value that you just passed in, which seems a bit silly. Probably you want something more like this: def ints(): i=0 while True: next_yield = (yield i) while next_yield is not None: yield None next_yield = (yield next_yield) i += 1 Then the send() call will return None, and the next next() call will return the value you passed in. Note though that this is too simple to work correctly if you call send() more than once before calling next() again. In general, I think it is a bad idea to mix calling next() and send() on the same generator. It makes the generator logic too complicated, and I think it's better just to create a stateful iterator class instead, where send() and next() are two entirely separate methods. Cheers, Ian From ian.g.kelly at gmail.com Sat May 14 21:05:27 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 May 2011 19:05:27 -0600 Subject: I don't understand generator.send() In-Reply-To: References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sat, May 14, 2011 at 6:47 PM, Chris Angelico wrote: > def ints(): > ? ?i=0 > ? ?queue=[] > ? ?while True: > ? ? ? ?if queue: ?# see other thread, this IS legal and pythonic and > quite sensible > ? ? ? ? ? ?sent=(yield queue.pop(0)) > ? ? ? ?else: > ? ? ? ? ? ?sent=(yield i) > ? ? ? ? ? ?i+=1 > ? ? ? ?if sent is not None: > ? ? ? ? ? ?yield None ?# This is the return value from gen.send() > ? ? ? ? ? ?queue.append(sent) > > With this generator, you maintain a queue of sent values (if you want > it to be a LIFO stack rather than a FIFO queue, just change the pop(0) > to just pop()), and if the queue's empty, it produces sequential > integers. (Incidentally, the sent values don't have to be integers. I > leave it to you to decide whether that's any use or not.) Actually, this won't work, because the value of the "yield None" gets ignored. Thus if you try to call send() twice in a row, the generator the treats second send() as if it were a next(), and it is not possible to have more than one item in the queue. From rosuav at gmail.com Sat May 14 21:17:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 May 2011 11:17:31 +1000 Subject: I don't understand generator.send() In-Reply-To: References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sun, May 15, 2011 at 11:05 AM, Ian Kelly wrote: > Actually, this won't work, because the value of the "yield None" gets > ignored. ?Thus if you try to call send() twice in a row, the generator > the treats second send() as if it were a next(), and it is not > possible to have more than one item in the queue. You're right. It needs a while loop instead of the if (and some slight reordering): def ints(): i=0 queue=[] while True: if queue: # see other thread, this IS legal and pythonic and quite sensible sent=(yield queue.pop(0)) else: sent=(yield i) i+=1 while sent is not None: queue.append(sent) sent=(yield None) # This is the return value from gen.send() That should work. Chris Angelico From see at sig.for.address Sat May 14 21:40:22 2011 From: see at sig.for.address (Victor Eijkhout) Date: Sat, 14 May 2011 20:40:22 -0500 Subject: I don't understand generator.send() References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: <1k19yop.1np9xao1gbclj4N%see@sig.for.address> Chris Angelico wrote: > For what you're doing, there's a little complexity. If I understand, > you want send() to be like an ungetc call... you could do that like > this: > > > def ints(): > i=0 > while True: > sent=(yield i) > if sent is not None: > yield None # This becomes the return value from gen.send() > yield sent # This is the next value yielded > i += 1 I think this will serve my purposes. Thanks everyone for broadening my understanding of generators. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From nospam at torek.net Sat May 14 22:11:11 2011 From: nospam at torek.net (Chris Torek) Date: 15 May 2011 02:11:11 GMT Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Message-ID: In article <871v00j2bh.fsf at benfinney.id.au> Ben Finney wrote: >As pointed out: you already know how to create a set from an object; >creating a list from an object is very similar: > > list(set(aa)) > >But why are you doing that? What are you trying to achieve? I have no idea why someone *else* is doing that, but I have used this very expression to unique-ize a list: >>> x = [3, 1, 4, 1, 5, 9, 2, 6] >>> x [3, 1, 4, 1, 5, 9, 2, 6] >>> list(set(x)) [1, 2, 3, 4, 5, 6, 9] >>> Of course, this trick only works if all the list elements are hashable. This might not be the best example since the result is sorted "by accident", while other list(set(...)) results are not. Add sorted() or .sort() if needed: >>> x = ['three', 'one', 'four', 'one', 'five'] >>> x ['three', 'one', 'four', 'one', 'five'] >>> list(set(x)) ['four', 'five', 'three', 'one'] >>> sorted(list(set(x))) ['five', 'four', 'one', 'three'] >>> -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From rustompmody at gmail.com Sat May 14 22:41:32 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 19:41:32 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> Message-ID: <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> On May 15, 4:26?am, Ben Finney wrote: > rusi writes: > > [Steven quote] > > In Python, [1, 2, 3] is another way of writing true, and [] is another > > way of writing false. Similarly with any other arbitrary objects. The > > only things that bools True and False are good for are: > > > > [end Steven quote] > > ------------------------ > > > So since > > [1,2,3] is one way of writing True (lets call it True3) > > No. Steven knew exactly why he was using ?true? versus ?True?. He's > explained why elsewhere in this thread. The former does not refer to the > Python boolean singleton, the latter does. > > The only object that is True is the True singleton. But there are many > objects that are true. Yes. The python entities: {True, False} are not an exact (isomorphic) model for the semantic boolean domain {true, false} (which is needed for example to explicate the semantics of if while etc) Which is to say the boolean type in python is not first class. From wallenpb at gmail.com Sat May 14 22:45:31 2011 From: wallenpb at gmail.com (Bill Allen) Date: Sat, 14 May 2011 21:45:31 -0500 Subject: PyPad 2.7.1 (Update 2) In-Reply-To: <950dfcf2-0ebf-4d7a-ab57-c862f2fedfd8@y27g2000prb.googlegroups.com> References: <950dfcf2-0ebf-4d7a-ab57-c862f2fedfd8@y27g2000prb.googlegroups.com> Message-ID: Jon, Looks very promising. Seems to be an issue with interactive mode. The following code behaves as thus: testvar=raw_input("enter value: ") print testvar When run, the prompt from raw_input does print to the output screen as: enter value: But when you tap in the lower window to enter the value for the input, the app closes unexpected. When I reopen it, what I was working on is still present. However, if I tap into the lower window and do this one line at a time from the interactive prompt >>>, the above code works ok. A problem? Or am I missing something? Anyway, I love this little Python app. Been wanting something like this for a long time. I installed this on my iPhone running iOS 4.3.3 (8J2). Congrats on a great app! Bill Allen On Thu, May 12, 2011 at 02:06, Jon D wrote: > Hi All, > > PyPad 2.7.1 Update 2 is now available on the AppStore. This is mainly > a bug fix release addressing a number of issues with the interactive > mode, but does also add some colour highlighting of output. > > PyPad is a port of the standard python code base to the iPad. It > includes most of the standard python modules and can be used for > testing small scripts or interactively for simple computation. > > Regards, > > Jon > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sat May 14 23:03:41 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 May 2011 21:03:41 -0600 Subject: I don't understand generator.send() In-Reply-To: References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sat, May 14, 2011 at 7:17 PM, Chris Angelico wrote: > You're right. It needs a while loop instead of the if (and some slight > reordering): > > def ints(): > ? i=0 > ? queue=[] > ? while True: > ? ? ? if queue: ?# see other thread, this IS legal and pythonic and > quite sensible > ? ? ? ? ? sent=(yield queue.pop(0)) > ? ? ? else: > ? ? ? ? ? sent=(yield i) > ? ? ? ? ? i+=1 > ? ? ? while sent is not None: > ? ? ? ? ? queue.append(sent) > ? ? ? ? ? sent=(yield None) ?# This is the return value from gen.send() > > That should work. Yeah, that should do it. But this is so much easier to get right and to understand: import itertools class Ints(object): def __init__(self): self.ints = itertools.count() self.queue = [] def __iter__(self): return self def next(self): if self.queue: return self.queue.pop(0) else: return self.ints.next() def insert(self, x): self.queue.append(x) From rustompmody at gmail.com Sat May 14 23:32:47 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 20:32:47 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> Message-ID: On May 15, 2:19?am, Ian Kelly wrote: > On Sat, May 14, 2011 at 11:24 AM, rusi wrote: > > def fib(n): > > ? ?if n==1 or n==2: > > ? ? ? ?return 1 > > ? ?elif even(n): > > ? ? ? ?return sq(fib (n//2)) + 2 * fib(n//2) * fib(n//2 - 1) > > ? ?else: > > ? ? ? ?return sq(fib (n//2 + 1)) + sq(fib(n // 2)) > > > This is a strange algo ?-- logarithmic because it halves the n, > > exponential because of the double (triple) calls. ?[I cannot say I > > know how to work out its exact complexity but I would guess its about > > linear] > > Yup, linear. ?Assuming you optimize the even case so that it doesn't > actually call fib(n//2) twice, the call tree can be approximated as a > balanced binary tree with height log(n). ?The total number of nodes in > the tree is thus O(2 ** log(n)) = O(n). It would be linear if the base of the log were 2. I am not sure it is. You see the naive fib has a complexity which is fib itself. [Earlier discussion with Steven] fib is exponential but with radix < 2 [phi = (1 + sqrt(5))/2 ] This would suggest that this algo is slightly better than linear. But I have no idea of the exact complexity. From steve+comp.lang.python at pearwood.info Sun May 15 01:00:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2011 05:00:36 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dcf5df4$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 May 2011 00:45:29 -0700, rusi wrote: > On May 14, 12:39?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Thu, 12 May 2011 23:46:12 -0700, rusi wrote: >> > Mathematics has existed for millenia. Hindu-arabic numerals (base-10 >> > numbers) have been known for about one millennium The boolean domain >> > is only a 100 years old. Unsurprisingly it is not quite 'first-class' >> > yet: See >> >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html >> > [Lifted fromhttp://c2.com/cgi/wiki?EqualVsTrueFalse] >> >> Th money-quote as regards using arbitrary objects in truth tests: >> >> ? ? [quote] >> ? ? All this changed with the introduction of the two-element boolean >> ? ? domain {true, false} which provides the vocabulary needed to >> ? ? assign values to boolean expressions: 3<4 is a way for writing >> ? ? true, 3>4 is a way for writing false, whereas the value of x>0 >> ? ? depends on the value of x ... [end quote] >> >> In Python, [1, 2, 3] is another way of writing true, and [] is another >> way of writing false. Similarly with any other arbitrary objects. > > Well so is [1,2] another way of writing True > > And then we get the interesting result that (True = True) is False I presume you mean to say: ([1, 2] == True) is False that is, that one true value is not equal to another true value. That is correct. However, Python's == operator is not a Boolean Algebra operator. If it were, it would probably be called "material biconditional", or XNOR, and written ? or <-> and would be smart enough to recognise that both [1, 2] and True are true. Or possibly dumb enough... the difficulty is that the equality operator knows more about the objects than just their truth value. And furthermore: ([1, 2] and True) == (True and [1, 2]) is also False, again because == is too smart to recognise that the left hand side (True) and the right hand side ([1, 2]) are both true values. It's not that Python bools aren't first class objects, but that Python doesn't have a full set of all 16 possible boolean algebra operators. -- Steven From steve+comp.lang.python at pearwood.info Sun May 15 01:07:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2011 05:07:37 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> Message-ID: <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 May 2011 19:41:32 -0700, rusi wrote: > The python entities: {True, False} are not an exact (isomorphic) model > for the semantic boolean domain {true, false} (which is needed for > example to explicate the semantics of if while etc) Which is to say the > boolean type in python is not first class. I'm afraid I don't understand what you mean. Can you explain please, what properties of "first class booleans" do you think are missing from Python? -- Steven From cwg at falma.de Sun May 15 04:28:53 2011 From: cwg at falma.de (Christoph Groth) Date: Sun, 15 May 2011 10:28:53 +0200 Subject: dict: retrieve the original key by key Message-ID: <874o4wwenu.fsf@falma.de> Dear python experts, I use a huge python dictionary where the values are lists of that dictionary's keys (yes, a graph). Each key is thus referenced several times. As the keys are rather large objects, I would like to save memory by re-using key objects wherever possible, instead of having several equal objects in memory. There does not seem to be a way to retrieve the original key from a python dictionary. Is there a technical reason for this? (Other than that such functionality was not considered to be useful enough.) What I will probably do now is store (key, real_value) as values in my dictionary. Is there a better solution? thanks, Christoph From rafadurancastaneda at gmail.com Sun May 15 04:37:46 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sun, 15 May 2011 10:37:46 +0200 Subject: Python drawing library? In-Reply-To: References: Message-ID: <4DCF90DA.6090609@gmail.com> On 15/05/11 01:01, OKB (not okblacke) wrote: > Is there any Python library for interactive drawing? I've done > some googling but most searches for "drawing" lead me to libraries for > programmatic creation of shapes on some GUI canvas. I'm looking for GUI > widgets that allow the user to draw with the mouse, like a paint > program, and let me get info about the drawing as its made (get color at > mouse location, etc.). I'd prefer a wxPython solution, although any > Python solution would be better than none. > > Thanks, I'm not suere, but I think you should be able to do that using PyQt QPaintDevice. From clp2 at rebertia.com Sun May 15 04:44:19 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 May 2011 01:44:19 -0700 Subject: dict: retrieve the original key by key In-Reply-To: <874o4wwenu.fsf@falma.de> References: <874o4wwenu.fsf@falma.de> Message-ID: On Sun, May 15, 2011 at 1:28 AM, Christoph Groth wrote: > Dear python experts, > > I use a huge python dictionary where the values are lists of that > dictionary's keys (yes, a graph). ?Each key is thus referenced several > times. > > As the keys are rather large objects, I would like to save memory by > re-using key objects wherever possible, instead of having several equal > objects in memory. > > There does not seem to be a way to retrieve the original key from a > python dictionary. ?Is there a technical reason for this? ?(Other than > that such functionality was not considered to be useful enough.) Define "original key". Cheers, Chris From tacyt1007 at gmail.com Sun May 15 04:47:14 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Sun, 15 May 2011 10:47:14 +0200 Subject: Python drawing library? In-Reply-To: <4DCF90DA.6090609@gmail.com> References: <4DCF90DA.6090609@gmail.com> Message-ID: Yes, it is possible with use of PyQt. 2011/5/15 Rafael Dur?n Casta?eda : > On 15/05/11 01:01, OKB (not okblacke) wrote: >> >> ? ? ? ?Is there any Python library for interactive drawing? ?I've done >> some googling but most searches for "drawing" lead me to libraries for >> programmatic creation of shapes on some GUI canvas. ?I'm looking for GUI >> widgets that allow the user to draw with the mouse, like a paint >> program, and let me get info about the drawing as its made (get color at >> mouse location, etc.). ?I'd prefer a wxPython solution, although any >> Python solution would be better than none. >> >> Thanks, > > I'm not suere, but I think you should be able to do that using PyQt > QPaintDevice. > -- > http://mail.python.org/mailman/listinfo/python-list > From n4vpython at gmail.com Sun May 15 05:00:14 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Sun, 15 May 2011 14:30:14 +0530 Subject: recvall() Message-ID: Hi All, I am trying to program an HTTP webserver, I am a little confused about the best way to program a recvall function. There are a couple of ways to do this? But performance wise which one is better? a) recvall using a timeout? b) recvall using a condition that nothing was received? c) recvall using a condition for it to wait for a CRLF or a timeout whichever occurs first? Any help would be appreciated. Regards, Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From cwg at falma.de Sun May 15 05:11:41 2011 From: cwg at falma.de (Christoph Groth) Date: Sun, 15 May 2011 11:11:41 +0200 Subject: dict: retrieve the original key by key References: <874o4wwenu.fsf@falma.de> Message-ID: <87wrhsuy42.fsf@falma.de> Chris Rebert writes: > On Sun, May 15, 2011 at 1:28 AM, Christoph Groth wrote: >> I use a huge python dictionary where the values are lists of that >> dictionary's keys (yes, a graph). ?Each key is thus referenced >> several times. >> >> As the keys are rather large objects, I would like to save memory by >> re-using key objects wherever possible, instead of having several >> equal objects in memory. >> >> There does not seem to be a way to retrieve the original key from a >> python dictionary. ?Is there a technical reason for this? ?(Other >> than that such functionality was not considered to be useful enough.) > > Define "original key". def original_key(dictionary, key): for k in dictionary: if k == key: return k raise KeyError(key) But this is not efficient. I would like to avoid having _multiple_ objects which are equal (a == b) but not the same (a is not b). This would save a lot of memory. From akabaila at pcug.org.au Sun May 15 05:15:48 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Sun, 15 May 2011 19:15:48 +1000 Subject: Python 3.2 Vectors.py module Message-ID: <201105151915.48203.akabaila@pcug.org.au> Hi All, I would really appreciate any comments and suggestions for the Vectors.py module, which can be downloaded from http://akabaila.pcug.org.au/linalg/vectors.tar.gz The tar ball is only about 4 KiB, but I gather that this mailing list does not tolerate attachments. The module is designed with PYTHON 3.2 and it is required for some structural analysis programs to port them to Python 3.x world. A quick start introduction to the module follows ********************************* #!/usr/bin/env python3.2 ''' quickVector.py - quick introduction to Vectors module. More information in "the manual". The quick introduction starts right here! With Vectors.py in the current directory, fire up the Python 3.2 Idle and try Vector algebra in the Python Shell. (Alternatively, just fire up Python 3.2 and try the commands from the terminal - CLI. >>> from Vectors import Vector >>> v1 = Vector(3, 4) >>> print('v1 = ', v1) v1 = Vector(3.0, 4.0, 0.0) >>> print('v1.size =', v1.size) v1.size = 5.0 >>> v2 = Vector(0, -5) >>> print('v2 =', v2) v2 = Vector(0.0, -5.0, 0.0) >>> print('scalar product =', v1 * v2) scalar product = -20.0 >>> print('vector product =', v1 ** v2) vector product = Vector(0.0, 0.0, -15.0) >>> v3 = v1 + v2 >>> print('v1 + v2 =', v3) v1 + v2 = Vector(3.0, -1.0, 0.0) >>> print('v3 - v1 verify = v2 =', v3 -v1) v3 - v1 verify = v2 = Vector(0.0, -5.0, 0.0) >>> # All vectors are three dimensional. But >>> # by specifying z = 0 we had vectors in (x y) >>> # plane. However, when we form a vector product >>> # (aka cross product), the resulting vector has >>> # to be at right angles to the (x y) plane, so >>> # we return to the 3 Dimensional media... >>> # Vector (cross) product is signalled by ** >>> w1 = v1 ** v2 >>> print('w1 = v1 ** v2 =', w1) w1 = v1 ** v2 = Vector(0.0, 0.0, -15.0) >>> w2 = w1 + v1 >>> print('w2 a vector in 3 dim. =', w2) w2 a vector in 3 dim. = Vector(3.0, 4.0, -15.0) >>> # Time to look at the "user manual" and other examples. >>> # Temp. home: http://akabaila/pcug.org.au/linalg/vectors.py ''' import doctest doctest.testmod() ********************************* Thank you in anticipation for suggestions and comments. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From gruszczy at gmail.com Sun May 15 05:33:40 2011 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Sun, 15 May 2011 11:33:40 +0200 Subject: ANN: Fathom 0.3.0 Message-ID: Hi, I have released version 0.2.0 of fathom, python3 package for database inspection. Fathom supports retrieving database schema from Sqlite3, PostgreSQL, MySQL and Oracle. This is still very early version and I am experimenting with different approaches. As always I would be very thankful for any input and suggestions about what would be useful in the library or tools. Here you can download the package: http://code.google.com/p/fathom/downloads/list **Changes in 0.3.0:** -> Oracle support :-) -> Triggers provide information about event upon which they are fired -> utility function for finding procedures that access a table -> fathom2graphviz draws lines between columns for foreign key -> fathom2graphviz and fathom2django can now print output to a file, rather than to std -- Filip Gruszczy?ski From chris at spam.org Sun May 15 05:44:04 2011 From: chris at spam.org (Christoph Scheingraber) Date: Sun, 15 May 2011 09:44:04 +0000 (UTC) Subject: connect SIGINT to custom interrupt handler Message-ID: Hi, I am trying to connect SIGINT (^c) to a custom interrupt handler like this (no threading, just straightforward): if __name__ == "__main__": quit = False def interrupt_handler(signal, frame): global quit if not quit: print "blabla, i'll finish my task and quit kind of message" print "Press ^C again to interrupt immediately." else: sys.exit(2) quit = True signal.signal(signal.SIGINT, interrupt_handler) # main will use the quit flag to determine if it should quit before next # task status = main() This worked fine in some rare lucky cases, but most of the times, the module I am using (my university's seismology project) catches the SIGINT and quits: select.error: (4, 'Interrupted system call') How can I prevent the imported module's function from catching the interrupt signal? Thanks to anyone that takes the time to help me... Chris -- Chris Scheingraber - www.scheingraber.net From dan.kluev at gmail.com Sun May 15 05:44:29 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 15 May 2011 20:44:29 +1100 Subject: Python 3.2 Vectors.py module In-Reply-To: <201105151915.48203.akabaila@pcug.org.au> References: <201105151915.48203.akabaila@pcug.org.au> Message-ID: On Sun, May 15, 2011 at 8:15 PM, Algis Kabaila wrote: > Hi All, > > I would really appreciate any comments and suggestions for the Vectors.py > module, which can be downloaded from - If you intend to provide it as general-purpose vector module for other people to use, it would be better if you pack it in separate package and upload to PyPI. You can find good tutorial on packaging here: http://diveintopython3.org/packaging.html - NumPy/SciPy has pretty fair support for vectors. Would be good if you pointed out the differences to begin with. -- With best regards, Daniel Kluev From dan.kluev at gmail.com Sun May 15 05:49:46 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 15 May 2011 20:49:46 +1100 Subject: threads with gtk gui problem In-Reply-To: <4DCECC70.5020703@earthsong.free-online.co.uk> References: <4DCE7FCC.8020907@gmail.com> <4DCECC70.5020703@earthsong.free-online.co.uk> Message-ID: You can also use multiprocessing module instead of threads. Use pipe and gobject.idle_add(somefunc) to process data from other thread. -- With best regards, Daniel Kluev From steve+comp.lang.python at pearwood.info Sun May 15 06:18:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2011 10:18:45 GMT Subject: dict: retrieve the original key by key References: <874o4wwenu.fsf@falma.de> Message-ID: <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: > I would like to avoid having _multiple_ objects which are equal (a == b) > but not the same (a is not b). This would save a lot of memory. Based on the idea of interning, which is used for Python strings: cache = {} def my_intern(obj): return cache.setdefault(obj, obj) x = make_some_object() x = my_intern(x) This ensures that equal objects in the graph are not just equal, but the same cached object. -- Steven From cwg at falma.de Sun May 15 06:46:15 2011 From: cwg at falma.de (Christoph Groth) Date: Sun, 15 May 2011 12:46:15 +0200 Subject: dict: retrieve the original key by key References: <874o4wwenu.fsf@falma.de> <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjsgutqg.fsf@falma.de> Steven D'Aprano writes: > On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: > >> I would like to avoid having _multiple_ objects which are equal (a == >> b) but not the same (a is not b). This would save a lot of memory. > > Based on the idea of interning, which is used for Python strings: > > cache = {} def my_intern(obj): > return cache.setdefault(obj, obj) > > > x = make_some_object() x = my_intern(x) > > This ensures that equal objects in the graph are not just equal, but > the same cached object. This requires another dictionary, though. But hey, they keys of my dictionary are actually strings, so I can use the built-in intern. Somehow, I have never stumbled accross this built-in function so far. Thanks a lot for the hint! Christoph From akabaila at pcug.org.au Sun May 15 06:55:32 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Sun, 15 May 2011 20:55:32 +1000 Subject: Python 3.2 Vectors.py module In-Reply-To: References: <201105151915.48203.akabaila@pcug.org.au> Message-ID: <201105152055.32225.akabaila@pcug.org.au> On Sunday 15 May 2011 19:44:29 Daniel Kluev wrote: > On Sun, May 15, 2011 at 8:15 PM, Algis Kabaila wrote: > > Hi All, > > > > I would really appreciate any comments and suggestions for > > the Vectors.py module, which can be downloaded from > > - If you intend to provide it as general-purpose vector > module for other people to use, it would be better if you > pack it in separate package and upload to PyPI. > You can find good tutorial on packaging here: > http://diveintopython3.org/packaging.html > > - NumPy/SciPy has pretty fair support for vectors. Would be > good if you pointed out the differences to begin with. Daniel, Thank you for the packaging suggestion. I had a glance at Chapter 16 of Dive into Python, do the packaging for my own use and only then will go to PyPi. Pointing out the differences is a tall order, but I do understand its importance. Actually, airing early the development in a mailing list may be a good way to get some suggestions as to where similarities may be. For one, "euclid " was an inspiration. I started by trying to update it for Python 3.x and that lead to developing an alternative package. The size of it (in terms of code lines) is differs by a factor of 10, partly because the Vectors.py does not deal with matrices as for my interests I would need a much wider reaching package. My moves are slow for a variety of reasons, but ignoring advice is not one of the reasons. Your suggestions are greatly appreciated. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Sun May 15 07:04:27 2011 From: ndbecker2 at gmail.com (Neal Becker) Date: Sun, 15 May 2011 07:04:27 -0400 Subject: Get the IP address of WIFI interface References: Message-ID: Far.Runner wrote: > Hi python experts: > There are two network interfaces on my laptop: one is 100M Ethernet > interface, the other is wifi interface, both are connected and has an ip > address. > The question is: How to get the ip address of the wifi interface in a python > script without parsing the output of a shell command like "ipconfig" or > "ifconfig"? > > OS: Windows or Linux > > F.R Here's some useful snippits for linux: def get_default_if(): f = open('/proc/net/route') for i in csv.DictReader(f, delimiter="\t"): if long(i['Destination'], 16) == 0: return i['Iface'] return None def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) From mail at timgolden.me.uk Sun May 15 07:12:07 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 15 May 2011 12:12:07 +0100 Subject: Get the IP address of WIFI interface In-Reply-To: References: Message-ID: <4DCFB507.2040007@timgolden.me.uk> On 15/05/2011 12:04 PM, Neal Becker wrote: > Far.Runner wrote: > >> Hi python experts: >> There are two network interfaces on my laptop: one is 100M Ethernet >> interface, the other is wifi interface, both are connected and has an ip >> address. >> The question is: How to get the ip address of the wifi interface in a python >> script without parsing the output of a shell command like "ipconfig" or >> "ifconfig"? >> >> OS: Windows or Linux >> >> F.R > > Here's some useful snippits for linux: ... and for Windows: import wmi for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): print nic.Caption, nic.IPAddress TJG From alister.ware at ntlworld.com Sun May 15 07:13:17 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Sun, 15 May 2011 11:13:17 GMT Subject: problem with GKT module? References: Message-ID: On Fri, 13 May 2011 13:13:00 +0000, alister ware wrote: > I am using gtk.builder with a glade generated GUI > > I have a simple call back defined for a radio button widget when I use > widget.name in linux I get a value of None, windows returns the widget > name as I would expect. > > is this a bug? > if not how should i find the name of the widget that has triggered a > call back? > > (I would like all my radio buttons to go to the same callback routine if > possible to make code maintenance easier) > So nobody has any Ideas on this at all? -- I never failed to convince an audience that the best thing they could do was to go away. From sigmundv at gmail.com Sun May 15 07:18:46 2011 From: sigmundv at gmail.com (SigmundV) Date: Sun, 15 May 2011 04:18:46 -0700 (PDT) Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Message-ID: <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> I think the OP wants to find the intersection of two lists. list(set(list1) & set(list2)) is indeed one way to achieve this. [i for i in list1 if i in list2] is another one. Sigmund On May 15, 4:11?am, Chris Torek wrote: > In article <871v00j2bh.... at benfinney.id.au> > Ben Finney ? wrote: > > >As pointed out: you already know how to create a set from an object; > >creating a list from an object is very similar: > > > ? ?list(set(aa)) > > >But why are you doing that? What are you trying to achieve? > > I have no idea why someone *else* is doing that, but I have used > this very expression to unique-ize a list: > > ? ? >>> x = [3, 1, 4, 1, 5, 9, 2, 6] > ? ? >>> x > ? ? [3, 1, 4, 1, 5, 9, 2, 6] > ? ? >>> list(set(x)) > ? ? [1, 2, 3, 4, 5, 6, 9] > ? ? >>> > > Of course, this trick only works if all the list elements are > hashable. > > This might not be the best example since the result is sorted > "by accident", while other list(set(...)) results are not. ?Add > sorted() or .sort() if needed: > > ? ? >>> x = ['three', 'one', 'four', 'one', 'five'] > ? ? >>> x > ? ? ['three', 'one', 'four', 'one', 'five'] > ? ? >>> list(set(x)) > ? ? ['four', 'five', 'three', 'one'] > ? ? >>> sorted(list(set(x))) > ? ? ['five', 'four', 'one', 'three'] > ? ? >>> > -- > In-Real-Life: Chris Torek, Wind River Systems > Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) ?+1 801 277 2603 > email: gmail (figure it out) ? ? ?http://web.torek.net/torek/index.html From sigmundv at gmail.com Sun May 15 07:23:40 2011 From: sigmundv at gmail.com (SigmundV) Date: Sun, 15 May 2011 04:23:40 -0700 (PDT) Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: <7b1ee48b-cd41-4baa-bfa2-473e7d898150@gu8g2000vbb.googlegroups.com> I'm sorry I top posted. I'll remember not to top post next time. Sigmund From vanboxem.ruben at gmail.com Sun May 15 08:29:57 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Sun, 15 May 2011 14:29:57 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: 2011/5/14 Doug Evans : > On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem > wrote: >> 2011/5/14 Doug Evans : >>> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem >>> wrote: >>>> (now in plain-text as required by gdb mailing list) >>>> >>>> Hi, >>>> >>>> I am currently trying to integrate Python support into my toolchain >>>> build (including GDB of course). It is a sysrooted >>>> binutils+GCC+GDB+mingw-w64 toolchain. >>>> >>>> I currently have the basic setup working: I can link gdb with my >>>> manually generated import lib to the python dll from the official >>>> Windows install. If there is anything I am missing or a very easy >>>> solution to the problems decsribed below, please just say so. I am >>>> only suggesting what I would like to happen. >>>> >>>> Now on to the problems I'd like to discuss: >>>> >>>> 1. gdb.exe won't start without me having set PYTHONPATH manually. >>> >>> In a properly configured/built gdb on linux this isn't necessary, even >>> if python is installed in some random place. >>> I'm not sure about windows though. >>> Did you specify --with-python when you configured gdb, and if so did >>> you specify a value? >>> e.g., --with-python=SOME_VALUE >> >> I was cross-compiling a mingw toolchain+gdb from Linux, so I used >> --with-python without a value (because gdb configure tries to find the >> Python executabe), and I added -I"/path/to/python/includes" to CFLAGS >> and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it >> should. This is hacky though, and gdb configure should provide >> --with-python-libs and --with-python-include to make it more >> streamlined with any other build prerequisite (like >> gmp/mpfr/mpc/cloog/ppl in GCC for example). > > Ah. > Cross-compiling gdb with python is in need of improvement. > Alas python hasn't been designed with cross-compilation in mind (e.g. > build on linux, run on windows). > AIUI, the way to get the parameters required for compiling with > libpython is to get them from python's "distutils": kinda hard to do > in a cross-compile. ?Done correctly there's no need to run python. > > I haven't done anything more to support python in gdb's configure.ac > because it's not clear to me what the right thing to do is: distutils > provides more than just --libs and --includes (btw, we don't use > --libs though, we use --ldflags which includes all of: the directory > in which to find libpython, the -l for libpython, and the -l's for all > the other libraries python needs). [Which isn't to say that someone > else isn't free to tackle this.] > > In the meantime, what I've been doing is a hack: write a script that > responds to: > --includes > --ldflags > --exec-prefix > and pass that as --with-python. > > E.g. > bash$ cat $HOME/my-python-for-config > #! /bin/sh > > if [ $# -ne 2 ] > then > ? ? ? ?echo "Bad # args. ?Blech!" >&2 > ? ? ? ?exit 1 > fi > > # The first argument is the path to python-config.py, ignore it. > > case "$2" in > --includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;; > --ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm > -lpython2.6" ;; > --exec-prefix) echo "/usr" ;; > *) echo "Bad arg $2. ?Blech!" >&2 ; exit 1 ;; > esac > > exit 0 > bash$ ./configure --with-python=$HOME/my-python-for-config [...] > [...] > > > Note that --exec-prefix is the runtime location of python. > GCC uses this to tell libpython where to find its support files. > [grep for Py_SetProgramName in gdb/python/python.c] OK, I tried your script in a couple of variations. It gets rid of the traceback I had before, but still doesn't help the PYTHONPATH problem. My directory structure is as follows (this is not in root, "/" is just my main build directory, there are several levels below it): /gdb <-- gdb build dir /gdb/gdb <-- where the python configuration is done /python <-- temporary install dir for python files for build, extracted from the official Windows installer, also location of libpython2.7.a import library /python/include/python27 <-- python headers, found by gdb in both cases /mingw64 <-- toolchain sysroot prefix /mingw64/bin <-- install location of gdb and python27.dll /mingw64/lib/python27 <-- install location of all python scripts First variant: --includes) echo "-I../../python/include" ;; --ldflags) echo "-L../../python -lpython2.7" ;; --exec-prefix) echo "../../mingw64/lib/python27" ;; Here exec-prefix would be the relative path from where "configure" does its magic to the final location of the scripts on the build system. Second variant: --includes) echo "-I../../python/include" ;; --ldflags) echo "-L../../python -lpython2.7" ;; --exec-prefix) echo "../lib/python27" ;; I thought the second points gdb to the installed location of the python scripts, but it still needed PYTHONPATH for that. I used relative paths in an attempt to "do the right thing", hackwise... Remember that the whole "/mingw64" directory gets zipped and moved, then it gets extracted to a random location in the Windows filesystem. Thanks for the help so far, I think we might just get this worked out together. Ruben > >>>> I understand the need for this, but as gdb requires Python 2, and users >>>> of my toolchain may have installed Python 3 or a 32-bit version python >>>> they want to use from the same environment (without changing their own >>>> PYTHONPATH), there is no way to run python-enabled gdb. >>>> [...] >>> >>> Yeah. >>> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have >>> gdb use that instead of PYTHONPATH if it exists, but there's been >>> resistance to it. >>> I think(!) what would happen is that gdb would set $PYTHONPATH to the >>> value of $GDB_PYTHONPATH. >>> [Inferiors started by gdb should still get the original value of >>> PYTHONPATH though.] >> >> That way would be almost ideal, but a hardcoded *relative* path to the >> python scripts (that is standardized within gdb) wouldn't hurt. > > See above re: --exec-prefix. > >> An >> extra environment variable would require a lot of explaining for >> Windows, and is not "plug-and-play", like the rest of a sysrooted >> toolchain is supposed to be like. I think this should work on all >> setups: >> >> 1. Check hardcoded path; my suggestion would be "> executable>/../lib/python27" >> 2. If this fails to find the necessary files/scripts, find it like you >> described above in Linux, without PYTHONPATH set. >> 3. Check PYTHONPATH. > > The problem being solved by the proposed GDB_PYTHONPATH is "What if > the user has PYTHONPATH set and it points to an incompatible version > of python?". > Leaving such a value for PYTHONPATH set while gdb's python is running > feels wrong (and IIRC has caused some problems). > > The problem of telling python where to find itself is already solved > (or at least is intended to be solved) with gdb's calling > Py_SetProgramName with a value derived from the python-provided > --exec-prefix. > >> I would think only number one would change, and perhaps be only >> enabled with a special configure option. Nothing else would have to >> change, and Windows users would rejoice :) >> Again, this is only my suggestion, if there are problems with it in >> way I haven't thought of, please say so, and we can come up with >> another solution. > From devivithyamaha at gmail.com Sun May 15 09:08:55 2011 From: devivithyamaha at gmail.com (devi vithya) Date: Sun, 15 May 2011 06:08:55 -0700 (PDT) Subject: DATING FOR BEAUTY GIRLS - DATING TIPS FOR GUYS - DATING ROMANCE - CLICK HERE Message-ID: http://dating4maha.blogspot.com/ http://dating4maha.blogspot.com/ http://dating4maha.blogspot.com/ http://dating4maha.blogspot.com/ http://dating4maha.blogspot.com/ From nobody at nowhere.com Sun May 15 09:08:59 2011 From: nobody at nowhere.com (Nobody) Date: Sun, 15 May 2011 14:08:59 +0100 Subject: connect SIGINT to custom interrupt handler References: Message-ID: On Sun, 15 May 2011 09:44:04 +0000, Christoph Scheingraber wrote: > signal.signal(signal.SIGINT, interrupt_handler) > This worked fine in some rare lucky cases, but most of the times, the > module I am using (my university's seismology project) catches the SIGINT > and quits: > > select.error: (4, 'Interrupted system call') After installing the signal handler, call: signal.siginterrupt(signal.SIGINT, False) This will cause (most) interrupted system calls to be restarted after the signal has been handled. > How can I prevent the imported module's function from catching the > interrupt signal? It isn't catching the signal. Unless you enable restarting of system calls, an interrupted system call will typically fail with EINTR. Python typically reports failures via exceptions; failures due to EINTR aren't handled differently. From vanboxem.ruben at gmail.com Sun May 15 09:26:45 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Sun, 15 May 2011 15:26:45 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: 2011/5/15 Ruben Van Boxem : > 2011/5/14 Doug Evans : >> On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem >> wrote: >>> 2011/5/14 Doug Evans : >>>> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem >>>> wrote: >>>>> (now in plain-text as required by gdb mailing list) >>>>> >>>>> Hi, >>>>> >>>>> I am currently trying to integrate Python support into my toolchain >>>>> build (including GDB of course). It is a sysrooted >>>>> binutils+GCC+GDB+mingw-w64 toolchain. >>>>> >>>>> I currently have the basic setup working: I can link gdb with my >>>>> manually generated import lib to the python dll from the official >>>>> Windows install. If there is anything I am missing or a very easy >>>>> solution to the problems decsribed below, please just say so. I am >>>>> only suggesting what I would like to happen. >>>>> >>>>> Now on to the problems I'd like to discuss: >>>>> >>>>> 1. gdb.exe won't start without me having set PYTHONPATH manually. >>>> >>>> In a properly configured/built gdb on linux this isn't necessary, even >>>> if python is installed in some random place. >>>> I'm not sure about windows though. >>>> Did you specify --with-python when you configured gdb, and if so did >>>> you specify a value? >>>> e.g., --with-python=SOME_VALUE >>> >>> I was cross-compiling a mingw toolchain+gdb from Linux, so I used >>> --with-python without a value (because gdb configure tries to find the >>> Python executabe), and I added -I"/path/to/python/includes" to CFLAGS >>> and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it >>> should. This is hacky though, and gdb configure should provide >>> --with-python-libs and --with-python-include to make it more >>> streamlined with any other build prerequisite (like >>> gmp/mpfr/mpc/cloog/ppl in GCC for example). >> >> Ah. >> Cross-compiling gdb with python is in need of improvement. >> Alas python hasn't been designed with cross-compilation in mind (e.g. >> build on linux, run on windows). >> AIUI, the way to get the parameters required for compiling with >> libpython is to get them from python's "distutils": kinda hard to do >> in a cross-compile. ?Done correctly there's no need to run python. >> >> I haven't done anything more to support python in gdb's configure.ac >> because it's not clear to me what the right thing to do is: distutils >> provides more than just --libs and --includes (btw, we don't use >> --libs though, we use --ldflags which includes all of: the directory >> in which to find libpython, the -l for libpython, and the -l's for all >> the other libraries python needs). [Which isn't to say that someone >> else isn't free to tackle this.] >> >> In the meantime, what I've been doing is a hack: write a script that >> responds to: >> --includes >> --ldflags >> --exec-prefix >> and pass that as --with-python. >> >> E.g. >> bash$ cat $HOME/my-python-for-config >> #! /bin/sh >> >> if [ $# -ne 2 ] >> then >> ? ? ? ?echo "Bad # args. ?Blech!" >&2 >> ? ? ? ?exit 1 >> fi >> >> # The first argument is the path to python-config.py, ignore it. >> >> case "$2" in >> --includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;; >> --ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm >> -lpython2.6" ;; >> --exec-prefix) echo "/usr" ;; >> *) echo "Bad arg $2. ?Blech!" >&2 ; exit 1 ;; >> esac >> >> exit 0 >> bash$ ./configure --with-python=$HOME/my-python-for-config [...] >> [...] >> >> >> Note that --exec-prefix is the runtime location of python. >> GCC uses this to tell libpython where to find its support files. >> [grep for Py_SetProgramName in gdb/python/python.c] > > OK, I tried your script in a couple of variations. It gets rid of the > traceback I had before, but still doesn't help the PYTHONPATH problem. > My directory structure is as follows (this is not in root, "/" is just > my main build directory, there are several levels below it): > > /gdb <-- gdb build dir > /gdb/gdb <-- where the python configuration is done > /python <-- temporary install dir for python files for build, > extracted from the official Windows installer, also location of > libpython2.7.a import library > /python/include/python27 <-- python headers, found by gdb in both cases > /mingw64 <-- toolchain sysroot prefix > /mingw64/bin <-- install location of gdb and python27.dll > /mingw64/lib/python27 <-- install location of all python scripts > > First variant: > --includes) echo "-I../../python/include" ;; > --ldflags) echo "-L../../python -lpython2.7" ;; > --exec-prefix) echo "../../mingw64/lib/python27" ;; > > Here exec-prefix would be the relative path from where "configure" > does its magic to the final location of the scripts on the build > system. > > Second variant: > --includes) echo "-I../../python/include" ;; > --ldflags) echo "-L../../python -lpython2.7" ;; > --exec-prefix) echo "../lib/python27" ;; > > I thought the second points gdb to the installed location of the > python scripts, but it still needed PYTHONPATH for that. I used > relative paths in an attempt to "do the right thing", hackwise... > Remember that the whole "/mingw64" directory gets zipped and moved, > then it gets extracted to a random location in the Windows filesystem. > > Thanks for the help so far, I think we might just get this worked out together. > > Ruben Wow, I think I have a partial solution. Delving into the Python docs, for example here: http://docs.python.org/using/windows.html#finding-modules, you can see that PYTHONPATH is used first, then the Windows registry, then PYTHONHOME, then some default relative paths. I placed the python scripts all in the directory structure like so: /bin/gdb /bin/Lib/ /bin/python27.dll This works, even without any manual PYTHONPATH intervention. Problem is though, that as soon as someone has a PYTHONPATH environment variable from a (incompatible) Python installation (think different bitness or version 3.x instead of 2.7.1), I cannot predict what will go wrong. This problem originates in Python's way of filling in the search path (sys.path). A true solution in the GDB case to prevent this collision of an incompatible PYTHONPATH would be that GDB sets an internal PYTHONPATH as directed by configure, uses that to load its Python internals, and allows the GDB child processes (apps being debugged) to use the environment PYTHONPATH. For now, I have a functional installation, but it will break as soon as someone installs Python on their system. The part your script plays in this (if I haven't misunderstood the intention/effects of the "--exec-prefix" part) is allowing a uniform way of directing the configure script to the right directories for includes/libs. Ruben > >> >>>>> I understand the need for this, but as gdb requires Python 2, and users >>>>> of my toolchain may have installed Python 3 or a 32-bit version python >>>>> they want to use from the same environment (without changing their own >>>>> PYTHONPATH), there is no way to run python-enabled gdb. >>>>> [...] >>>> >>>> Yeah. >>>> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have >>>> gdb use that instead of PYTHONPATH if it exists, but there's been >>>> resistance to it. >>>> I think(!) what would happen is that gdb would set $PYTHONPATH to the >>>> value of $GDB_PYTHONPATH. >>>> [Inferiors started by gdb should still get the original value of >>>> PYTHONPATH though.] >>> >>> That way would be almost ideal, but a hardcoded *relative* path to the >>> python scripts (that is standardized within gdb) wouldn't hurt. >> >> See above re: --exec-prefix. >> >>> An >>> extra environment variable would require a lot of explaining for >>> Windows, and is not "plug-and-play", like the rest of a sysrooted >>> toolchain is supposed to be like. I think this should work on all >>> setups: >>> >>> 1. Check hardcoded path; my suggestion would be ">> executable>/../lib/python27" >>> 2. If this fails to find the necessary files/scripts, find it like you >>> described above in Linux, without PYTHONPATH set. >>> 3. Check PYTHONPATH. >> >> The problem being solved by the proposed GDB_PYTHONPATH is "What if >> the user has PYTHONPATH set and it points to an incompatible version >> of python?". >> Leaving such a value for PYTHONPATH set while gdb's python is running >> feels wrong (and IIRC has caused some problems). >> >> The problem of telling python where to find itself is already solved >> (or at least is intended to be solved) with gdb's calling >> Py_SetProgramName with a value derived from the python-provided >> --exec-prefix. >> >>> I would think only number one would change, and perhaps be only >>> enabled with a special configure option. Nothing else would have to >>> change, and Windows users would rejoice :) >>> Again, this is only my suggestion, if there are problems with it in >>> way I haven't thought of, please say so, and we can come up with >>> another solution. >> > From usgallery01 at gmail.com Sun May 15 10:21:48 2011 From: usgallery01 at gmail.com (charmi s) Date: Sun, 15 May 2011 07:21:48 -0700 (PDT) Subject: SEE KAREENA KAPOOR BOLLYWOOD HOT ACTRESS BOOBS PRESSED IN SHOPPING MALL Message-ID: SEE KAREENA KAPOOR BOLLYWOOD HOT ACTRESS BOOBS PRESSED IN SHOPPING MALL At http://hollypops.Co.CC Due to GOOGLE security risks, i have hidden the videos in an image. in that website on Right side below search box click on image and watch videos in all angles. From chris at spam.org Sun May 15 10:32:13 2011 From: chris at spam.org (Christoph Scheingraber) Date: Sun, 15 May 2011 14:32:13 +0000 (UTC) Subject: connect SIGINT to custom interrupt handler References: Message-ID: I now have signal.siginterrupt(signal.SIGINT, False) in the line below signal.signal(signal.SIGINT, interrupt_handler) Unfortunately, pressing ^c still results in the same interrupt error. I also tried putting signal.siginterrupt into the interrupt_handler function, which gave an interesting result: File "/usr/local/bin/obspysod", line 586, in interrupt_handler signal.siginterrupt(signal.SIGINT, False) AttributeError: 'int' object has no attribute 'siginterrupt' Could there be a namespace problem? On 2011-05-15, Nobody wrote: > On Sun, 15 May 2011 09:44:04 +0000, Christoph Scheingraber wrote: > >> signal.signal(signal.SIGINT, interrupt_handler) > >> This worked fine in some rare lucky cases, but most of the times, the >> module I am using (my university's seismology project) catches the SIGINT >> and quits: >> >> select.error: (4, 'Interrupted system call') > > After installing the signal handler, call: > > signal.siginterrupt(signal.SIGINT, False) > > This will cause (most) interrupted system calls to be restarted after the > signal has been handled. > >> How can I prevent the imported module's function from catching the >> interrupt signal? > > It isn't catching the signal. Unless you enable restarting of system > calls, an interrupted system call will typically fail with EINTR. Python > typically reports failures via exceptions; failures due to EINTR aren't > handled differently. > -- Chris Scheingraber - www.scheingraber.net From miki.tebeka at gmail.com Sun May 15 11:25:42 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 15 May 2011 08:25:42 -0700 (PDT) Subject: connect SIGINT to custom interrupt handler In-Reply-To: Message-ID: <04cee22d-fc07-4c54-b91b-3f9e4730f095@glegroupsg2000goo.googlegroups.com> Greetings, > I am trying to connect SIGINT (^c) to a custom interrupt handler like > this (no threading, just straightforward): Why not just catch KeyboardInterrupt? All the best, -- Miki From rosuav at gmail.com Sun May 15 11:30:10 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 01:30:10 +1000 Subject: connect SIGINT to custom interrupt handler In-Reply-To: References: Message-ID: On Mon, May 16, 2011 at 12:32 AM, Christoph Scheingraber wrote: > I now have signal.siginterrupt(signal.SIGINT, False) in the line > below signal.signal(signal.SIGINT, interrupt_handler) > > Unfortunately, pressing ^c still results in the same interrupt error. I > also tried putting signal.siginterrupt into the interrupt_handler > function, which gave an interesting result: > ? ?File "/usr/local/bin/obspysod", line 586, in interrupt_handler > ? ?signal.siginterrupt(signal.SIGINT, False) > ? ?AttributeError: 'int' object has no attribute 'siginterrupt' > > Could there be a namespace problem? def interrupt_handler(signal, frame): You're using 'signal' as a parameter here. The local int is masking the global module. Chris Angelico From PointedEars at web.de Sun May 15 11:43:40 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 15 May 2011 17:43:40 +0200 Subject: connect SIGINT to custom interrupt handler References: Message-ID: <1691845.hkbZ0PkbqX@PointedEars.de> Christoph Scheingraber wrote: > I now have signal.siginterrupt(signal.SIGINT, False) in the line > below signal.signal(signal.SIGINT, interrupt_handler) > > Unfortunately, pressing ^c still results in the same interrupt error. I > also tried putting signal.siginterrupt into the interrupt_handler > function, which gave an interesting result: > File "/usr/local/bin/obspysod", line 586, in interrupt_handler > signal.siginterrupt(signal.SIGINT, False) > AttributeError: 'int' object has no attribute 'siginterrupt' > > Could there be a namespace problem? Obviously. `signal' refers to an `int' object, probably by something like signal = 42 before. E.g. `print' or a debugger will tell you, as you have not showed the relevant parts of the code. Please trim your quotes to the relevant minimum; DO NOT top-post. Also, it is not acceptable behavior to use domain namespaces without authorization (chris at spam.org is not a mailbox, yet spam.org is registered to someone else). -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From nobody at nowhere.net.no Sun May 15 11:56:58 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 15 May 2011 23:56:58 +0800 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: SigmundV wrote: > I think the OP wants to find the intersection of two lists. > list(set(list1) & set(list2)) is indeed one way to achieve this. [i > for i in list1 if i in list2] is another one Exactly. I was confused on that I wasn't able to have a list in return. The set intersection is the smartest result better than a "for" loop or a comprehension list. Infact the operatin loops are compiled into python, therfore they are the fastest. -- goto /dev/null From nobody at nowhere.net.no Sun May 15 12:05:44 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 16 May 2011 00:05:44 +0800 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Message-ID: Chris Torek wrote: > >>> x = ['three', 'one', 'four', 'one', 'five'] > >>> x > ['three', 'one', 'four', 'one', 'five'] > >>> list(set(x)) > ['four', 'five', 'three', 'one'] Why one *"one"* has purged out? Removing double occurences in a list? -- goto /dev/null From vanboxem.ruben at gmail.com Sun May 15 12:11:43 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Sun, 15 May 2011 18:11:43 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: 2011/5/15 Ruben Van Boxem : > 2011/5/15 Ruben Van Boxem : >> 2011/5/14 Doug Evans : >>> On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem >>> wrote: >>>> 2011/5/14 Doug Evans : >>>>> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem >>>>> wrote: >>>>>> (now in plain-text as required by gdb mailing list) >>>>>> >>>>>> Hi, >>>>>> >>>>>> I am currently trying to integrate Python support into my toolchain >>>>>> build (including GDB of course). It is a sysrooted >>>>>> binutils+GCC+GDB+mingw-w64 toolchain. >>>>>> >>>>>> I currently have the basic setup working: I can link gdb with my >>>>>> manually generated import lib to the python dll from the official >>>>>> Windows install. If there is anything I am missing or a very easy >>>>>> solution to the problems decsribed below, please just say so. I am >>>>>> only suggesting what I would like to happen. >>>>>> >>>>>> Now on to the problems I'd like to discuss: >>>>>> >>>>>> 1. gdb.exe won't start without me having set PYTHONPATH manually. >>>>> >>>>> In a properly configured/built gdb on linux this isn't necessary, even >>>>> if python is installed in some random place. >>>>> I'm not sure about windows though. >>>>> Did you specify --with-python when you configured gdb, and if so did >>>>> you specify a value? >>>>> e.g., --with-python=SOME_VALUE >>>> >>>> I was cross-compiling a mingw toolchain+gdb from Linux, so I used >>>> --with-python without a value (because gdb configure tries to find the >>>> Python executabe), and I added -I"/path/to/python/includes" to CFLAGS >>>> and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it >>>> should. This is hacky though, and gdb configure should provide >>>> --with-python-libs and --with-python-include to make it more >>>> streamlined with any other build prerequisite (like >>>> gmp/mpfr/mpc/cloog/ppl in GCC for example). >>> >>> Ah. >>> Cross-compiling gdb with python is in need of improvement. >>> Alas python hasn't been designed with cross-compilation in mind (e.g. >>> build on linux, run on windows). >>> AIUI, the way to get the parameters required for compiling with >>> libpython is to get them from python's "distutils": kinda hard to do >>> in a cross-compile. ?Done correctly there's no need to run python. >>> >>> I haven't done anything more to support python in gdb's configure.ac >>> because it's not clear to me what the right thing to do is: distutils >>> provides more than just --libs and --includes (btw, we don't use >>> --libs though, we use --ldflags which includes all of: the directory >>> in which to find libpython, the -l for libpython, and the -l's for all >>> the other libraries python needs). [Which isn't to say that someone >>> else isn't free to tackle this.] >>> >>> In the meantime, what I've been doing is a hack: write a script that >>> responds to: >>> --includes >>> --ldflags >>> --exec-prefix >>> and pass that as --with-python. >>> >>> E.g. >>> bash$ cat $HOME/my-python-for-config >>> #! /bin/sh >>> >>> if [ $# -ne 2 ] >>> then >>> ? ? ? ?echo "Bad # args. ?Blech!" >&2 >>> ? ? ? ?exit 1 >>> fi >>> >>> # The first argument is the path to python-config.py, ignore it. >>> >>> case "$2" in >>> --includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;; >>> --ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm >>> -lpython2.6" ;; >>> --exec-prefix) echo "/usr" ;; >>> *) echo "Bad arg $2. ?Blech!" >&2 ; exit 1 ;; >>> esac >>> >>> exit 0 >>> bash$ ./configure --with-python=$HOME/my-python-for-config [...] >>> [...] >>> >>> >>> Note that --exec-prefix is the runtime location of python. >>> GCC uses this to tell libpython where to find its support files. >>> [grep for Py_SetProgramName in gdb/python/python.c] >> >> OK, I tried your script in a couple of variations. It gets rid of the >> traceback I had before, but still doesn't help the PYTHONPATH problem. >> My directory structure is as follows (this is not in root, "/" is just >> my main build directory, there are several levels below it): >> >> /gdb <-- gdb build dir >> /gdb/gdb <-- where the python configuration is done >> /python <-- temporary install dir for python files for build, >> extracted from the official Windows installer, also location of >> libpython2.7.a import library >> /python/include/python27 <-- python headers, found by gdb in both cases >> /mingw64 <-- toolchain sysroot prefix >> /mingw64/bin <-- install location of gdb and python27.dll >> /mingw64/lib/python27 <-- install location of all python scripts >> >> First variant: >> --includes) echo "-I../../python/include" ;; >> --ldflags) echo "-L../../python -lpython2.7" ;; >> --exec-prefix) echo "../../mingw64/lib/python27" ;; >> >> Here exec-prefix would be the relative path from where "configure" >> does its magic to the final location of the scripts on the build >> system. >> >> Second variant: >> --includes) echo "-I../../python/include" ;; >> --ldflags) echo "-L../../python -lpython2.7" ;; >> --exec-prefix) echo "../lib/python27" ;; >> >> I thought the second points gdb to the installed location of the >> python scripts, but it still needed PYTHONPATH for that. I used >> relative paths in an attempt to "do the right thing", hackwise... >> Remember that the whole "/mingw64" directory gets zipped and moved, >> then it gets extracted to a random location in the Windows filesystem. >> >> Thanks for the help so far, I think we might just get this worked out together. >> >> Ruben > > Wow, I think I have a partial solution. Delving into the Python docs, > for example here: > http://docs.python.org/using/windows.html#finding-modules, you can see > that PYTHONPATH is used first, then the Windows registry, then > PYTHONHOME, then some default relative paths. I placed the python > scripts all in the directory structure like so: > > /bin/gdb > /bin/Lib/ > /bin/python27.dll > > This works, even without any manual PYTHONPATH intervention. Problem > is though, that as soon as someone has a PYTHONPATH environment > variable from a (incompatible) Python installation (think different > bitness or version 3.x instead of 2.7.1), I cannot predict what will > go wrong. This problem originates in Python's way of filling in the > search path (sys.path). A true solution in the GDB case to prevent > this collision of an incompatible PYTHONPATH would be that GDB sets an > internal PYTHONPATH as directed by configure, uses that to load its > Python internals, and allows the GDB child processes (apps being > debugged) to use the environment PYTHONPATH. For now, I have a > functional installation, but it will break as soon as someone installs > Python on their system. > > The part your script plays in this (if I haven't misunderstood the > intention/effects of the "--exec-prefix" part) is allowing a uniform > way of directing the configure script to the right directories for > includes/libs. > > Ruben I am sorry for the repeated messages that no one cares about, but I may have discovered GDB in its current form already allows what I want: I tried to figure out what exact paths the snake in gdb was using to search for its modules, and came up with this: (gdb) python import sys (gdb) python print sys.path ['m:\\development\\mingw64\\share\\gdb/python', 'M:\\Development\\mingw64\\bin\\python27.zip', 'M:\\Development\\mingw64\\bin\\DLLs', 'M:\\Development\\mingw64\\bin\\lib', 'M:\\Development\\mingw64\\bin\\lib\\plat-win', 'M:\\Development\\mingw64\\bin\\lib\\lib-tk', 'M:\\Development\\mingw64\\bin', 'M:\\Development\\mingw64\\bin\\lib\\site-packages'] This means that every python command within gdb searches /share/gdb/python FIRST (even before an environment's PYTHONPATH), alleviating any concerns or problems I or anyone would have with another python installation, as this apparently built-in path comes up first. All I, or anyone interested in doing this kind of thing, have to do is copy all the python scripts from the Windows installation's Lib directory to the /share/gdb/python directory. I don't know where this path comes from, but it is quite handy, and makes this whole discussion moot for Python people. Only "issue" that I'll have to work around is the --with-python-includes and --with-python-libs that are missing, using either manual CFLAGS/LDFLAGS or a variant of your script. Thanks for all the help and motivation to keep trying :) Ruben > >> >>> >>>>>> I understand the need for this, but as gdb requires Python 2, and users >>>>>> of my toolchain may have installed Python 3 or a 32-bit version python >>>>>> they want to use from the same environment (without changing their own >>>>>> PYTHONPATH), there is no way to run python-enabled gdb. >>>>>> [...] >>>>> >>>>> Yeah. >>>>> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have >>>>> gdb use that instead of PYTHONPATH if it exists, but there's been >>>>> resistance to it. >>>>> I think(!) what would happen is that gdb would set $PYTHONPATH to the >>>>> value of $GDB_PYTHONPATH. >>>>> [Inferiors started by gdb should still get the original value of >>>>> PYTHONPATH though.] >>>> >>>> That way would be almost ideal, but a hardcoded *relative* path to the >>>> python scripts (that is standardized within gdb) wouldn't hurt. >>> >>> See above re: --exec-prefix. >>> >>>> An >>>> extra environment variable would require a lot of explaining for >>>> Windows, and is not "plug-and-play", like the rest of a sysrooted >>>> toolchain is supposed to be like. I think this should work on all >>>> setups: >>>> >>>> 1. Check hardcoded path; my suggestion would be ">>> executable>/../lib/python27" >>>> 2. If this fails to find the necessary files/scripts, find it like you >>>> described above in Linux, without PYTHONPATH set. >>>> 3. Check PYTHONPATH. >>> >>> The problem being solved by the proposed GDB_PYTHONPATH is "What if >>> the user has PYTHONPATH set and it points to an incompatible version >>> of python?". >>> Leaving such a value for PYTHONPATH set while gdb's python is running >>> feels wrong (and IIRC has caused some problems). >>> >>> The problem of telling python where to find itself is already solved >>> (or at least is intended to be solved) with gdb's calling >>> Py_SetProgramName with a value derived from the python-provided >>> --exec-prefix. >>> >>>> I would think only number one would change, and perhaps be only >>>> enabled with a special configure option. Nothing else would have to >>>> change, and Windows users would rejoice :) >>>> Again, this is only my suggestion, if there are problems with it in >>>> way I haven't thought of, please say so, and we can come up with >>>> another solution. >>> >> > From steve+comp.lang.python at pearwood.info Sun May 15 12:28:05 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2011 16:28:05 GMT Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Message-ID: <4dcfff15$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 May 2011 00:05:44 +0800, TheSaint wrote: > Chris Torek wrote: > >> >>> x = ['three', 'one', 'four', 'one', 'five'] x >> ['three', 'one', 'four', 'one', 'five'] >> >>> list(set(x)) >> ['four', 'five', 'three', 'one'] > > Why one *"one"* has purged out? > Removing double occurences in a list? Break the operation up into two steps instead of one: >>> x = ['three', 'one', 'four', 'one', 'five'] >>> s = set(x) >>> print s set(['four', 'five', 'three', 'one']) >>> list(s) ['four', 'five', 'three', 'one'] Once an element is already in a set, adding it again is a null-op: >>> s = set() >>> s.add(42) >>> s.add(42) >>> s.add(42) >>> print s set([42]) -- Steven From nobody at nowhere.net.no Sun May 15 12:35:55 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 16 May 2011 00:35:55 +0800 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <4dcfff15$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >>>> s = set() >>>> s.add(42) >>>> s.add(42) >>>> s.add(42) >>>> print s > set([42]) Good to know. I'll remember it -- goto /dev/null From spam at scheingraber.net Sun May 15 13:05:57 2011 From: spam at scheingraber.net (Christoph Scheingraber) Date: Sun, 15 May 2011 17:05:57 +0000 (UTC) Subject: connect SIGINT to custom interrupt handler References: <1691845.hkbZ0PkbqX@PointedEars.de> Message-ID: On 2011-05-15, Thomas 'PointedEars' Lahn wrote: > > Obviously. `signal' refers to an `int' object, probably by something like > > signal = 42 > > before. E.g. `print' or a debugger will tell you, as you have not showed > the relevant parts of the code. The problem is that I am running someone else's module which seems to use signal, I guess that means I have to create a child method? Is it correct anyway to have signal.siginterrupt(signal.SIGINT, False) in my custom interrupt_handler function or should it be outside but after signal.signal(signal.SIGINT, interrupt_handler)? > > Please trim your quotes to the relevant minimum; DO NOT top-post. > Also, it is not acceptable behavior to use domain namespaces without > authorization (chris at spam.org is not a mailbox, yet spam.org is > registered to someone else). > I am sorry, I changed it to my own domain. -- Chris Scheingraber - www.scheingraber.net From roy at panix.com Sun May 15 13:07:25 2011 From: roy at panix.com (Roy Smith) Date: Sun, 15 May 2011 13:07:25 -0400 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: In article <34fc571c-f382-405d-94b1-0a673da5f46b at t16g2000vbi.googlegroups.com>, SigmundV wrote: > I think the OP wants to find the intersection of two lists. > list(set(list1) & set(list2)) is indeed one way to achieve this. [i > for i in list1 if i in list2] is another one. Both ways work, but the first is O(n) and the second is O(n^2). import time n = 10000 list1 = range(n) list2 = range(n) t0 = time.time() list(set(list1) & set(list2)) t1 = time.time() print "list(set) method took %f seconds" % (t1 - t0) t0 = time.time() [i for i in list1 if i in list2] t1 = time.time() print "loop method took %f seconds" % (t1 - t0) ./intersect.py 100000 list(set) method took 0.004791 seconds loop method took 1.437322 seconds From rustompmody at gmail.com Sun May 15 13:33:38 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 15 May 2011 10:33:38 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> On May 15, 10:07?am, Steven D'Aprano wrote: > > I'm afraid I don't understand what you mean. Can you explain please, what > properties of "first class booleans" do you think are missing from Python? Dijkstra's writings I alluded to, take a logic/math line to this. Let me try to rephrase Dijkstra (who is now sadly not able to defend our (mis)understandings of his writings) in a more linguistic way: In English when we say something like "x is y" the y (predicate) can be an adjective phrase -- the apple is red -- or a noun phrase -- the apple is a fruit. They seem similar; they are very different -- you agree?? >From times immemorial 'true' and 'false' have been used in the adjective sense: eg Such-and-such statement is true. Boole's contribution -- actually Dijkstra's recognition of Boole's contribution -- is that dignifying {true, false} from adjectives to nouns -- the boolean domain -- fundamentally alter and improve the rules and possibilities for our thinking. [See his puzzles in the same paper: http://www.google.com/url?sa=D&q=http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html As an analogy for this consider arithmetic. Even primitive people can count: My 3 children, my 5 sheep. They do this with the ordinals -- first child, second child, third child... But arithmetic cannot really take off until we allow these numbers (ordinals) to be dignified into entities in their own right -- cardinals. ie the mathematician needs to believe in the existence of the numbers 1,2 etc for him to do his job well. [As an aside I may mention that philosophers of mathematicians will call this platonism: "In which heaven do these numbers exist?" And platonism is mysticism. And mysticism is bullshit. But the vast majority of practicing mathematicians refuse to be dislodged from their 'platonic heaven.' For them mathematics can only be done if it is done in 'discovery' mode and not in 'invention' mode.] And so just as good math happens by believing that the numbers exist and discovering their properties, good logic happens when we believe that {True, False} exist (in some platonic heaven). Which is to say they should be nouns in our language. Well that in summary is the Boole's ideology (Dijkstra's evangelism) understood linguistically and independent of python/programming. Reapplied back to the math/programming field, we find that if a value- domain (data-type) has to be first-class, it at the least has to be a denotable entity in the language which should be conformable with its abstract/expected properties. For example if my language seems to have entities like '2' '3' '+' but 2+3 does not work out equal to 5 we would (I hope!) not say the language has first-class numbers. But in order for any of this discussion to be possible, equality should be well-defined. Which means that in addition to being an equivalence relation it must have substitutivity http://en.wikipedia.org/wiki/Equality_%28mathematics%29#Some_basic_logical_properties_of_equality which is another form of a very fundamental principle attributed to Leibniz, the principle of identity of indiscernibles: http://en.wikipedia.org/wiki/Leibniz%27s_law Seemingly you and Dijkstra are saying something similar when you say [1,2,3] is a way of writing true and he says 2<3 is a way of writing true. But on further examination (with Leibniz law above) Dijkstra's 2<3 = True will work consistently in all contexts but [1,2,3] = True will work sometimes and fail sometimes. In mathSpeak we say, the definition of bool is not well defined In CSSpeak we say the definition is not first class. In the language of algebraic specifications, the slogan is "No confusion, No junk" eg http://www.informatik.uni-bremen.de/agbkb/lehre/ws06-07/casl/slides/Datatypes-II.pdf This is usually applied to specific models in a given language But it could as well be applied to the models that a language supplies by default. And when we apply it to python's bool as a model of the abstract/math concept bool it has confusion and junk. From dickinsm at gmail.com Sun May 15 15:20:03 2011 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 15 May 2011 12:20:03 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> Message-ID: On May 15, 4:32?am, rusi wrote: > On May 15, 2:19?am, Ian Kelly wrote: > > Yup, linear. ?Assuming you optimize the even case so that it doesn't > > actually call fib(n//2) twice, the call tree can be approximated as a > > balanced binary tree with height log(n). ?The total number of nodes in > > the tree is thus O(2 ** log(n)) = O(n). > > It would be linear if the base of the log were 2. > I am not sure it is. > You see the naive fib has a complexity which is fib itself. [Earlier > discussion with Steven] > fib is exponential but with radix < 2 [phi = (1 + sqrt(5))/2 ] > This would suggest that this algo is slightly better than linear. Nope. It's linear, just as Ian Kelly said. If g(n) is the total number of fib calls made for fib(n), then it's easy to show (e.g., by induction) that: (a) g(n) is an increasing function of n, and (b) g(2^k) = 2^k - 1 for all k >= 1. Hence g(n) is O(n). Mark From hujun.work at gmail.com Sun May 15 15:23:14 2011 From: hujun.work at gmail.com (Jun Hu) Date: Sun, 15 May 2011 12:23:14 -0700 Subject: Get the IP address of WIFI interface In-Reply-To: <4DCFB507.2040007@timgolden.me.uk> References: <4DCFB507.2040007@timgolden.me.uk> Message-ID: Thanks for the tip, it is really helpful! however the class of Win32_NetworkAdapterConfiguration doesn't include the interface type (you can NOT tell if it is a wifi interface), so I change the code a bit like following: import wmi wlan_int_id=None for nic in wmi.WMI().Win32_NetworkAdapter(): if nic.NetConnectionID == "Wireless Network Connection": wlan_int_id=nic.Index break if wlan_int_id<>None: for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): if nic.Index==wlan_int_id: print nic.IPAddress[0] else: print "WLAN interface NOT Found" On Sun, May 15, 2011 at 4:12 AM, Tim Golden wrote: > On 15/05/2011 12:04 PM, Neal Becker wrote: > >> Far.Runner wrote: >> >> Hi python experts: >>> There are two network interfaces on my laptop: one is 100M Ethernet >>> interface, the other is wifi interface, both are connected and has an ip >>> address. >>> The question is: How to get the ip address of the wifi interface in a >>> python >>> script without parsing the output of a shell command like "ipconfig" or >>> "ifconfig"? >>> >>> OS: Windows or Linux >>> >>> F.R >>> >> >> Here's some useful snippits for linux: >> > > ... and for Windows: > > > import wmi > > for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): > print nic.Caption, nic.IPAddress > > > > TJG > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Sun May 15 15:29:38 2011 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 15 May 2011 12:29:38 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> Message-ID: On May 15, 8:20?pm, Mark Dickinson wrote: > On May 15, 4:32?am, rusi wrote: > > > On May 15, 2:19?am, Ian Kelly wrote: > > > Yup, linear. ?Assuming you optimize the even case so that it doesn't > > > actually call fib(n//2) twice, the call tree can be approximated as a > > > balanced binary tree with height log(n). ?The total number of nodes in > > > the tree is thus O(2 ** log(n)) = O(n). > > > It would be linear if the base of the log were 2. > > I am not sure it is. > > You see the naive fib has a complexity which is fib itself. [Earlier > > discussion with Steven] > > fib is exponential but with radix < 2 [phi = (1 + sqrt(5))/2 ] > > This would suggest that this algo is slightly better than linear. > > Nope. ?It's linear, just as Ian Kelly said. ?If g(n) is the total > number of fib calls made for fib(n), then it's easy to show (e.g., by > induction) that: > > (a) g(n) is an increasing function of n, and > (b) g(2^k) = 2^k - 1 for all k >= 1. > > Hence g(n) is O(n). Hmm. It's even easier: g(n) is: * 1 if n == 1 * n if n > 1, n odd * n-1 if n > 1, n even So definitely linear. :-) -- Mark From mail at timgolden.me.uk Sun May 15 15:38:40 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 15 May 2011 20:38:40 +0100 Subject: Get the IP address of WIFI interface In-Reply-To: References: <4DCFB507.2040007@timgolden.me.uk> Message-ID: <4DD02BC0.60005@timgolden.me.uk> On 15/05/2011 20:23, Jun Hu wrote: > Thanks for the tip, it is really helpful! > however the class of Win32_NetworkAdapterConfiguration doesn't include > the interface type (you can NOT tell if it is a wifi interface), so I > change the code a bit like following: > > import wmi > > wlan_int_id=None > for nic in wmi.WMI().Win32_NetworkAdapter(): > if nic.NetConnectionID == "Wireless Network Connection": > wlan_int_id=nic.Index > break > > if wlan_int_id<>None: > for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): > if nic.Index==wlan_int_id: > print nic.IPAddress[0] > else: > print "WLAN interface NOT Found" Glad it was useful; you can get a little bit prettier: import wmi c = wmi.WMI () for nic in c.Win32_NetworkAdapter ( NetConnectionID="Wireless Network Connection" ): for config in nic.associators ( wmi_result_class="Win32_NetworkAdapterConfiguration" ): print config.Caption, "=>", " / ".join (config.IPAddress) break else: print "No Wireless NIC found" TJG From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sun May 15 16:27:34 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sun, 15 May 2011 22:27:34 +0200 Subject: Converting a set into list In-Reply-To: References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: Am 15.05.2011 17:56 schrieb TheSaint: > SigmundV wrote: > >> I think the OP wants to find the intersection of two lists. >> list(set(list1)& set(list2)) is indeed one way to achieve this. [i >> for i in list1 if i in list2] is another one > > Exactly. I was confused on that I wasn't able to have a list in return. > The set intersection is the smartest result better than a "for" loop or a > comprehension list. I'm not sure about if it is really the smartest way. s=set(list2); [i for i in list1 if i in s] is in the same order of magnitude as the set operation. Both solutions seem to be equivalent in that concerns the number of needed loop runs, but this two-step operation might require one less loop over list1. The set&set solution, in contrary, might require one loop while transforming to a set and another one for the & operation. > Infact the operatin loops are compiled into python, therfore they are the > fastest. Which loops do you mean here? Thomas From bahamutzero8825 at gmail.com Sun May 15 16:45:29 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 15 May 2011 15:45:29 -0500 Subject: Trying to understand html.parser.HTMLParser Message-ID: <4DD03B69.6050301@gmail.com> I'm trying to understand why HMTLParser.feed() isn't returning the whole page. My test script is this: import urllib.request import html.parser class MyHTMLParser(html.parser.HTMLParser): def handle_starttag(self, tag, attrs): if tag == 'a' and attrs: print(tag,'-',attrs) url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth' page = urllib.request.urlopen(url).read() parser = MyHTMLParser() parser.feed(str(page)) I can do print(page) and get the entire HTML source, but parser.feed(str(page)) only spits out the information for the top links and none of the "revisionxxxx" links. Ultimately, I just want to find the name of the first "revisionxxxx" link (right now it's "revision1995", when a new build is uploaded it will be "revision2000" or whatever). I figure this is a relatively simple page; once I understand all of this, I can move on to more complicated pages. I've searched Google, but everything I find is either outdated, a recommendation for some external module (I don't need to do anything too fancy and most modules don't completely support Python 3 anyway) or is just a code snippet with no real explanation. I had a book that explained this, but I had to return it to the library (and I'll have to get back in line to check it out again). From tjreedy at udel.edu Sun May 15 16:53:07 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 May 2011 16:53:07 -0400 Subject: dict: retrieve the original key by key In-Reply-To: <87sjsgutqg.fsf@falma.de> References: <874o4wwenu.fsf@falma.de> <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> <87sjsgutqg.fsf@falma.de> Message-ID: On 5/15/2011 6:46 AM, Christoph Groth wrote: > Steven D'Aprano writes: > >> On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: >> >>> I would like to avoid having _multiple_ objects which are equal (a == >>> b) but not the same (a is not b). This would save a lot of memory. Python hashed collections have methods used to test if the collection has an item/key that is equal to some object. They do not currently have a method to return the equal item/key already there. This has been proposed and, I believe, rejected due to lack of sufficient presented use cases or because, conceptually, one wants to map key values to an object with the key value and Stephen's identity dict does precisely that. In any case, if you put an object into a collection and you want to use the object for other purposes without accessing the collection, you must keep a reference to it outside of the collection. >> Based on the idea of interning, which is used for Python strings: >> >> cache = {} def my_intern(obj): >> return cache.setdefault(obj, obj) >> >> >> x = make_some_object() x = my_intern(x) >> >> This ensures that equal objects in the graph are not just equal, but >> the same cached object. > > This requires another dictionary, though. It does, however, twice reuse the key already in your graph dict, so each entry is minimal extra memory. It is typical in graph algorithms to have both a graph map (nodes to set of nodes) and a properties map (nodes to property structure). Some properties are fixed, others are changed during particular algoritms. It is also typical to use counts as node identifiers, so that both maps are implemented as sequences, but string indentifiers and dict for maps work too. > But hey, they keys of my dictionary are actually strings, so I can use > the built-in intern. Somehow, I have never stumbled accross this > built-in function so far. It was, however, removed in 3.x as a seldom-externally-used internal implementation detail. -- Terry Jan Reedy From bahamutzero8825 at gmail.com Sun May 15 17:14:18 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 15 May 2011 16:14:18 -0500 Subject: Get the IP address of WIFI interface In-Reply-To: <4DCFB507.2040007@timgolden.me.uk> References: <4DCFB507.2040007@timgolden.me.uk> Message-ID: <4DD0422A.8030008@gmail.com> On 2011.05.15 06:12 AM, Tim Golden wrote: > ... and for Windows: > > > import wmi > > for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): > print nic.Caption, nic.IPAddress > > One thing I found out about Win32_NetworkAdapterConfiguration is that it only contains /current/ information and not the stored info that it uses when making an initial connection (you can see and edit this info in the Network and Sharing Center applet). The difference is that if you're offline, that WMI object will have no useful info at all. You can find the info in the registry if you know what the UUID (or whatever it is) of (or assigned to) the interface (it's in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces). The OP said the card would be connected, so it might not be an issue, but I think it's important to know that. Wouldn't want you to suddenly get blank strings or exceptions and not know why. ;-) From clp2 at rebertia.com Sun May 15 17:19:42 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 May 2011 14:19:42 -0700 Subject: dict: retrieve the original key by key In-Reply-To: References: <874o4wwenu.fsf@falma.de> <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> <87sjsgutqg.fsf@falma.de> Message-ID: On Sun, May 15, 2011 at 1:53 PM, Terry Reedy wrote: > On 5/15/2011 6:46 AM, Christoph Groth wrote: >> But hey, they keys of my dictionary are actually strings, so I can use >> the built-in intern. ?Somehow, I have never stumbled accross this >> built-in function so far. > > It was, however, removed in 3.x as a seldom-externally-used internal > implementation detail. Still exists in sys module though: http://docs.python.org/dev/library/sys.html#sys.intern Cheers, Chris From tjreedy at udel.edu Sun May 15 17:36:01 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 May 2011 17:36:01 -0400 Subject: checking if a list is empty In-Reply-To: <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> Message-ID: On 5/15/2011 1:33 PM, rusi wrote: > On May 15, 10:07 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> >> I'm afraid I don't understand what you mean. Can you explain please, what >> properties of "first class booleans" do you think are missing from Python? Given the usual CS definition of 'first class object', all Python objects are first class. But that does not preclude other definitions. > Dijkstra's writings I alluded to, take a logic/math line to this. Let > me try to rephrase Dijkstra (who is now sadly not able to defend our > (mis)understandings of his writings) in a more linguistic way: > > In English when we say something like "x is y" the y (predicate) can > be an adjective phrase -- the apple is red -- or a noun phrase -- the > apple is a fruit. > > They seem similar; they are very different -- you agree?? Sometimes. Sometimes it could mean 'the apple is fruity' or 'the apple has the characters that define the wider grouping of fruits'. "John is brilliant", "John is a brilliant man", and "John is a genius" (there is no 'a brilliant') pretty much have the same effective meaning. But I get the point about reification. >> From times immemorial 'true' and 'false' have been used in the > adjective sense: eg Such-and-such statement is true. > Boole's contribution -- actually Dijkstra's recognition of Boole's > contribution -- is that dignifying {true, false} from adjectives to > nouns -- the boolean domain -- fundamentally alter and improve the > rules and possibilities for our thinking. [See his puzzles in the same > paper: > http://www.google.com/url?sa=D&q=http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > > As an analogy for this consider arithmetic. > > Even primitive people can count: My 3 children, my 5 sheep. They do > this with the ordinals -- first child, second child, third child... > But arithmetic cannot really take off until we allow these numbers > (ordinals) to be dignified into entities in their own right -- > cardinals. > ie the mathematician needs to believe in the existence of the numbers > 1,2 etc for him to do his job well. > > [As an aside I may mention that philosophers of mathematicians will > call this platonism: "In which heaven do these numbers exist?" > And platonism is mysticism. And mysticism is bullshit. But the vast > majority of practicing mathematicians refuse to be dislodged from > their 'platonic heaven.' For them mathematics can only be done if it > is done in 'discovery' mode and not in 'invention' mode.] > > And so just as good math happens by believing that the numbers exist > and discovering their properties, good logic happens when we believe > that {True, False} exist (in some platonic heaven). Which is to say > they should be nouns in our language. > > Well that in summary is the Boole's ideology (Dijkstra's evangelism) > understood linguistically and independent of python/programming. > > Reapplied back to the math/programming field, we find that if a value- > domain (data-type) has to be first-class, it at the least has to be a > denotable entity in the language which should be conformable with its > abstract/expected properties. > For example if my language seems to have entities like '2' '3' '+' but > 2+3 does not work out equal to 5 we would (I hope!) not say the > language has first-class numbers. You seem to equate 'number' with 'natural number' in the classical sense. If '2' and '3' are residue classes (remainers) mod 5, then 2 + 3 is 0. Even kids understand clock arithmetics. Of course, the 24 hour (0 to 23 hourse) is saner than the older 1-12,am/pm system, but kids even manage with that. > But in order for any of this discussion to be possible, equality > should be well-defined. > Which means that in addition to being an equivalence relation it must > have substitutivity > http://en.wikipedia.org/wiki/Equality_%28mathematics%29#Some_basic_logical_properties_of_equality > which is another form of a very fundamental principle attributed to > Leibniz, the principle of identity of indiscernibles: > http://en.wikipedia.org/wiki/Leibniz%27s_law > > Seemingly you and Dijkstra are saying something similar when you say > [1,2,3] is a way of writing true > and he says 2<3 is a way of writing true. > But on further examination (with Leibniz law above) Dijkstra's 2<3 = > True will work consistently in all contexts In general, a < b will work consistently as generally expected of total orders if, but only if, a and b are members of a totally ordered set and < indicates that total order. If '<' represents a partial order, 'a but [1,2,3] = True will work sometimes and fail sometimes. 'Bool() is a much a spelling of true or false as 'a < b'. It works just as consistently in all contexts. *nornal expression: evaluates to an object with a well-defined boolean value, which is to say, causes bool() to return True or False. > In mathSpeak we say, the definition of bool is not well defined The math definition of bool or the Python definition? And what definition of 'well-defined'? On builtins, bool(ob) always returns the same value. And the values are pretty consistent. > In CSSpeak we say the definition is not first class. What CS definition? -- Terry Jan Reedy From hujun.work at gmail.com Sun May 15 19:07:20 2011 From: hujun.work at gmail.com (Jun Hu) Date: Sun, 15 May 2011 16:07:20 -0700 Subject: Get the IP address of WIFI interface In-Reply-To: <4DD0422A.8030008@gmail.com> References: <4DCFB507.2040007@timgolden.me.uk> <4DD0422A.8030008@gmail.com> Message-ID: On Sun, May 15, 2011 at 2:14 PM, Andrew Berg wrote: > > One thing I found out about Win32_NetworkAdapterConfiguration is that it > only contains /current/ information and not the stored info that it uses > when making an initial connection (you can see and edit this info in the > Network and Sharing Center applet). The difference is that if you're > offline, that WMI object will have no useful info at all. You can find > the info in the registry if you know what the UUID (or whatever it is) > of (or assigned to) the interface (it's in > > HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces). > The OP said the card would be connected, so it might not be an issue, > but I think it's important to know that. Wouldn't want you to suddenly > get blank strings or exceptions and not know why. ;-) > > Thanks for the reminder, however, it seems the IPAddress of Win32_NetworkAdapterConfiguration will be 0.0.0.0 if the interface is NOT connected (at least that is the result on my winxp), so I think we are safe here. ^_^ -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sun May 15 20:00:01 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 16 May 2011 12:00:01 +1200 Subject: turn monitor off and on In-Reply-To: References: Message-ID: <93b7o1Fb92U1@mid.individual.net> Terry Reedy wrote: > My monitor then displays 'No > signal detected' in a box and puts itself into a low-power state > awaiting a signal. Even if the monitor does not do that, a black screen > should use less power. I'm not so sure about that. If the monitor is an LCD and isn't doing anything to reduce its own power usage, then the backlight is still running and using just as much power, whether the screen is black or not. -- Greg From steve+comp.lang.python at pearwood.info Sun May 15 20:36:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2011 00:36:19 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> Message-ID: <4dd07182$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 May 2011 10:33:38 -0700, rusi wrote: > On May 15, 10:07?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> >> I'm afraid I don't understand what you mean. Can you explain please, >> what properties of "first class booleans" do you think are missing from >> Python? [snip] I'm afraid I didn't find your discussion about reification, Platonism and linguistics very helpful. Some of it I disagree with, some I agree with, but in neither case do I see any relevance to the question of whether bools are first class objects in Python, and if not, why not. > Reapplied back to the math/programming field, we find that if a value- > domain (data-type) has to be first-class, it at the least has to be a > denotable entity in the language which should be conformable with its > abstract/expected properties. Now you're getting somewhere! > For example if my language seems to have entities like '2' '3' '+' but > 2+3 does not work out equal to 5 we would (I hope!) not say the language > has first-class numbers. Well, that's a problem. By that definition, floats are not first class numbers. While 2+3 does work out to be equal to 5, other standard properties of the real number system do not apply: >>> 0.3 + 0.4 - 0.3 == 0.4 False Similarly, in many languages (including older versions of Python), neither are integers: >>> 2147483647 + 1 Traceback (innermost last): File "", line 1, in ? OverflowError: integer addition Other languages may wrap around, giving -1 or -2147483648. So it seems that either we're forced to accept that neither floats nor integers are "first class", or instead back-track and ask: "Hang on, who decides what the expected properties are?" > But in order for any of this discussion to be possible, equality should > be well-defined. > Which means that in addition to being an equivalence relation it must > have substitutivity Can you show us a problem that is hard to solve in Python because ([1,2] and True) evaluates as True, but ([1,2] == True) evaluates as False? > http://en.wikipedia.org/wiki/Equality_%28mathematics% 29#Some_basic_logical_properties_of_equality > which is another form of a very fundamental principle attributed to > Leibniz, the principle of identity of indiscernibles: > http://en.wikipedia.org/wiki/Leibniz%27s_law But Python truth values are not indiscernible. Do you think they must be? If they are indiscernible, there can only be two unique values (possibly spelled "Veritas" and "Falsus" to avoid confusion with Python's True and False). But why must they be indiscernible? > Seemingly you and Dijkstra are saying something similar when you say > [1,2,3] is a way of writing true > and he says 2<3 is a way of writing true. But on further examination > (with Leibniz law above) Dijkstra's 2<3 = True will work consistently in > all contexts but [1,2,3] = True will work sometimes and fail sometimes. Please do not arbitrarily mix Python and mathematics syntax. What you have stated gives a SyntaxError. [1,2,3] == True will work always, or you have a very buggy version of Python. It will always return False, as expected. I suspect that in a boolean context, the operator you want is material biconditional, or XNOR, also known as "p if and only if q". Python does not have this as a built-in, but it's easy enough to write it: def xnor(p, q): if p: return q else: return p if q else True (I have deliberately written it to return one of the two arguments when possible. If you don't care for this behaviour, the else clause is even simpler: return not q) If you don't like the name XNOR, rename it "equals" and be done. Nobody says that equality *must* be spelled with = or == as an infix operator. That would be a foolish insistence. Another way would be to compare the canonical truth values for equality: bool(p) == bool(q) but of course there's nothing special about the canonical truth values except ease of use. One could choose any other values: def canonical(flag): if flag: return "Nobody expects the Spanish Inquisition!!!" else: return None canonical(p) == canonical(q) The important thing is that Python's sense of equality doesn't just apply in the boolean domain, it applies to the broader any-arbitrary-Python- object domain. Python's equals is too powerful to be limited to Python's truth values: it needs to distinguish between 42 and 23, while in the boolean domain one need not. Consequently, if you want equality in the boolean domain, you need to use something other than the built-in == operator. Python doesn't allow you to override == for built-in objects, so the simplest, most straight- forward way is with a function. Using such a function: >>> equals = xnor >>> equals( equals([1, 2], 42), equals("spam", 23) ) 23 which is, naturally, just another way of spelling True. > In mathSpeak we say, the definition of bool is not well defined In > CSSpeak we say the definition is not first class. That is not the normal definition of "first class" in computer science. The normal definition relates to whether a data type can be assigned to variables, passed to functions, and otherwise treated like ints or floats or other "first class" types. That certainly applies to truth values in Python, and bools. > In the language of algebraic specifications, the slogan is "No > confusion, No junk" > eg > http://www.informatik.uni-bremen.de/agbkb/lehre/ws06-07/casl/slides/ Datatypes-II.pdf > > This is usually applied to specific models in a given language > > But it could as well be applied to the models that a language supplies > by default. > And when we apply it to python's bool as a model of the abstract/math > concept bool it has confusion and junk. Well there is certainly confusion, but it's not in Python's model. The confusion seems to entirely rest in your mistake in thinking that the only valid way to do an equality test is with the built-in == syntax. -- Steven From jorgeromero178 at gmail.com Sun May 15 20:42:07 2011 From: jorgeromero178 at gmail.com (Jorge Romero) Date: Sun, 15 May 2011 20:42:07 -0400 Subject: MySQLdb SEC_TO_TIME function returns datetime.timedelta class Message-ID: Hi Pythonists, I'm retrieving some time data from a MySQL database using Python's MySQLdb library. Here's the situation, I got a time field on MySQL given in seconds, I need it on HH:MM:SS format, so I'm SELECTING that field with SEC_TO_TIME function, something like this: query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table" fetched = cursor.execute(query) return fetched[0] The result of the query is given to me as *datetime.timedelta *type, which has an undesired print behavior for my purposes: >>> query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table" >>> fetched = cursor.execute(query) >>> print fetched[0] 3 days, 7:30:09 >>> print type(fetched[0]) Instead of *datetime.timedelta *I need *datetime.time *type. Does anybody knows how to change this behavior or is it something I must deal with my code? Thanks in advanced. -- Jorge Romero -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sun May 15 20:47:45 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 15 May 2011 18:47:45 -0600 Subject: dict: retrieve the original key by key In-Reply-To: <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <874o4wwenu.fsf@falma.de> <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 15, 2011 at 4:18 AM, Steven D'Aprano wrote: > On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: > >> I would like to avoid having _multiple_ objects which are equal (a == b) >> but not the same (a is not b). ?This would save a lot of memory. > > Based on the idea of interning, which is used for Python strings: > > cache = {} > def my_intern(obj): > ? ?return cache.setdefault(obj, obj) And if the idea of a dictionary with identical keys and values offends, you can also use a set: cache = set() def my_intern(obj): cache.add(obj) return cache.intersection([obj]).pop() Cheers, Ian From timr at probo.com Sun May 15 20:50:59 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 15 May 2011 17:50:59 -0700 Subject: Question about available python lib for a task References: Message-ID: <9os0t6pa69gl9e1uhvts087s8d2re4jr4v@4ax.com> cesium5500 at yahoo.ca wrote: > >I would like to build a database of all the MS-Excel file on a LAN. I >would like to get the files metadata : filename, summary, location, >size, etc. > >Is there a dedicated python lib for the task? No. The file name, location, and size are all completely generic. You can do that with standard Python and the os.walk command. The document properties (like the summary) can be accessed in a couple of ways. You can do it in Excel by opening the application, opening the document, and using the BuiltinDocumentProperties collection. Or, you can do it without Excel, using the COM interfaces for "structured storage", like IPropertySetStorage and IPropertyStorage. >Is pywin32 one of the possible lib available? You will need PyWin32 in order to use COM to launch Excel, or use the structured storage interfaces. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From drobinow at gmail.com Sun May 15 21:06:49 2011 From: drobinow at gmail.com (David Robinow) Date: Sun, 15 May 2011 21:06:49 -0400 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD03B69.6050301@gmail.com> References: <4DD03B69.6050301@gmail.com> Message-ID: On Sun, May 15, 2011 at 4:45 PM, Andrew Berg wrote: > I'm trying to understand why HMTLParser.feed() isn't returning the whole > page. My test script is this: > > import urllib.request > import html.parser > class MyHTMLParser(html.parser.HTMLParser): > ? ?def handle_starttag(self, tag, attrs): > ? ? ? ?if tag == 'a' and attrs: > ? ? ? ? ? ?print(tag,'-',attrs) > > url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth' > page = urllib.request.urlopen(url).read() > parser = MyHTMLParser() > parser.feed(str(page)) > > I can do print(page) and get the entire HTML source, but > parser.feed(str(page)) only spits out the information for the top links > and none of the "revisionxxxx" links. Ultimately, I just want to find > the name of the first "revisionxxxx" link (right now it's > "revision1995", when a new build is uploaded it will be "revision2000" > or whatever). I figure this is a relatively simple page; once I > understand all of this, I can move on to more complicated pages. You've got bad HTML. Look closely and you'll see the there's no space between the "revisionxxxx" strings and the style tag following. The parser doesn't like this. I don't know a solution other than fixing the html. (I created a local copy, edited it and it worked.) From harrismh777 at charter.net Sun May 15 21:25:44 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 20:25:44 -0500 Subject: checking if a list is empty In-Reply-To: <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> Message-ID: rusi wrote: > But on further examination (with Leibniz law above) Dijkstra's 2<3 = > True will work consistently in all contexts but [1,2,3] = True will > work sometimes and fail sometimes. It would have to be written 2<3 == True; [1,2,3] == True; otherwise, ... +1 QOTW From mrjean1 at gmail.com Sun May 15 21:42:32 2011 From: mrjean1 at gmail.com (MrJean1) Date: Sun, 15 May 2011 18:42:32 -0700 (PDT) Subject: Get the IP address of WIFI interface References: <4DCFB507.2040007@timgolden.me.uk> Message-ID: <537d5138-2dc1-422a-8ebc-24a76270f2ce@k27g2000pri.googlegroups.com> Perhaps, this recipe works for your case: It does parse ifconfig and ipconfig, if found. /Jean On May 15, 2:14?pm, Andrew Berg wrote: > On 2011.05.15 06:12 AM, Tim Golden wrote:> ... and for Windows: > > > > > import wmi > > > for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): > > ? ?print nic.Caption, nic.IPAddress > > > > > One thing I found out about Win32_NetworkAdapterConfiguration is that it > only contains /current/ information and not the stored info that it uses > when making an initial connection (you can see and edit this info in the > Network and Sharing Center applet). The difference is that if you're > offline, that WMI object will have no useful info at all. You can find > the info in the registry if you know what the UUID (or whatever it is) > of (or assigned to) the interface (it's in > HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Inter faces). > The OP said the card would be connected, so it might not be an issue, > but I think it's important to know that. Wouldn't want you to suddenly > get blank strings or exceptions and not know why. ;-) From harrismh777 at charter.net Sun May 15 21:42:46 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 20:42:46 -0500 Subject: problem with GKT module? In-Reply-To: References: Message-ID: Alister Ware wrote: > I have a simple call back defined for a radio button widget when I use >> widget.name in linux I get a value of None, windows returns the widget >> name as I would expect. >> First, not familiar with your issue... ... but might be able to help you think through it... I am assuming that you are building a Python script using a glade interface that provides the widgets drag-an-drop style and then allowing you to take the default code, add to it, or otherwise modify it. I am also assuming that the /call back/ is returning a Python None, on the linux platform... otherwise you're getting the widget name from the same script on the windows platform?? right? It might be helpful to examine both scripts to see where (if any) they differ. More likely than not, this little snag is a difference in the way that the windows version of gtk+ libraries are working, than the original ones on the linux platform. On the other hand, the Python wrappers for the gtk+ library on the linux platform may be hiding the return values. Python functions return 'None' if the 'return' is not explicitly coded. The gtk+ libraries may be returning a value but the 'builder' is not generating the right Python wrapper. I'm making this up, but you get the idea, and you can probably check from here. On the other hand, folks here can enter into a discussion with you regarding the generated Python code (output from the builder) if you provide relevant code snippets. Kind regards, m harris From harrismh777 at charter.net Sun May 15 21:48:37 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 20:48:37 -0500 Subject: turn monitor off and on In-Reply-To: <93b7o1Fb92U1@mid.individual.net> References: <93b7o1Fb92U1@mid.individual.net> Message-ID: Gregory Ewing wrote: > I'm not so sure about that. If the monitor is an LCD and isn't > doing anything to reduce its own power usage, then the backlight > is still running and using just as much power, whether the screen > is black or not. Depends on dpmi. Some monitors turn off the backlight, and some don't. My monitor(s) that are LCD turn off the backlight... and the downside of that (very annoying) is that they have to 'warm up' again... making them dim for the first few seconds of use... An LED flat panel is a completely different animal, because there is no backlight (no ccfl). They monitors don't use much power in the first place, but they use less when they're blank, obviously, not producing light. kind regards, m harris From tjreedy at udel.edu Sun May 15 21:57:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 May 2011 21:57:39 -0400 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroup s.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> Message-ID: On 5/15/2011 5:36 PM, Terry Reedy wrote: > On 5/15/2011 1:33 PM, rusi wrote: >> Dijkstra's writings I alluded to, at http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html "Acquiring that familiarity requires what in these financial times is known as "intellectual investment"; you can take my word for it that this investment quickly pays off." I recommend understanding the following as three more "intellectual investments": We create a Boolean domain by drawing a distinction in some domain and treating everything on each side of the distinction as equal in some value. A Boolean value or variable represents such a dichotomy, a choice between two all-inclusive but mutually exclusive possibilities. Boole derived his domain from truth/falsity of propositions. But that is an interpretation of his abstract model and only one of endless possibilities. This realization that switching networks are another interpretation is the basis of digital computation. Boolean algebra theorems are theorems about switching networks and can be used to design such networks. Such networks can be used to do boolean arithmetic. The trick is to coerce physical components into one of two states. Part of the trick is to not look when they are transiting between them. For its built-in information objects, Python choose 'representation of something' versus 'representation of nothing' as the dichotomy. It matches 'something' to True and 'nothing' to False as this is generally more useful than the opposite matching. In boolean contexts, it automatically fetches the boolean value of an object. -- Terry Jan Reedy From harrismh777 at charter.net Sun May 15 21:59:28 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 20:59:28 -0500 Subject: checking if a list is empty In-Reply-To: <4dd07182$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> <4dd07182$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4y%zp.4255$iv4.1254@newsfe09.iad> Steven D'Aprano wrote: > I'm afraid I don't understand what you mean. Can you explain please, >>> http://www.informatik.uni-bremen.de/agbkb/lehre/ws06-07/casl/slides/Datatypes-II.pdf Geeze, I wonder if software is mathematics.... kind regards, m harris From tyler at tysdomain.com Sun May 15 22:04:16 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 15 May 2011 20:04:16 -0600 Subject: obviscating python code for distribution Message-ID: <4DD08620.4030507@tysdomain.com> Hello all: I have been considering writing a couple of programs in Python, but I don't want to distribute the code along with them. So I'm curious of a couple things. First, does there exist a cross-platform library for playing audio files, whose license I would not be violating if I do this? Second, would I be violating the twisted, wxpython licenses by doing this? Finally, is there a good way to accomplish this? I know that I can make .pyc files, but those can be disassembled very very easily with the disassembler and shipping these still means that the person needs the modules that are used. Is there another way to go about this? -- Take care, Ty my website: http://tds-solutions.net my blog: http://tds-solutions.net/blog skype: st8amnd127 ?Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.? ?If Java had true garbage collection, most programs would delete themselves upon execution.? From akabaila at pcug.org.au Sun May 15 22:17:00 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Mon, 16 May 2011 12:17:00 +1000 Subject: checking if a list is empty In-Reply-To: References: Message-ID: <201105161217.00473.akabaila@pcug.org.au> On Friday 13 May 2011 18:47:50 Hans Georg Schaathun wrote: > On Thu, 12 May 2011 23:20:20 +1000, Chris Angelico > > wrote: > : Writing a program requires expertise both in programming snip... > > And the main difference here, is that the civil engineers > have a much better language to share information. The best > programmers have is the programming language, and we ought > to make that as good as possible. As an old Civil Engineer and a retired educator of Civil and Aeronautical Engineers, I want to get at the end of the long thread. Early in the thread I (wrongly) thought that the discussion just did not make sense. Much as has been said, makes a good sense, though some of it is hardly relevant. So what is the purpose of this discussion - is it to proffer advice to the "Benevolent Dictator for life" and to his cohort or is it to better understand the programming language Python? In relation to the first part of the question is that the aim is far too ambitious - the success of Python language is enough to suggest that Guido and his team do not need advice and they will ask for it if they really do want to hear the opinions about it. The job they have done in developing the language is admirable and the users better concentrate on trying to understand it better. The second part of the (rhetorical) question is that the answer depends what the designers of Python have chosen as criterion for "True" or "False". In my little effort to present Vector algebra in an easy to use manner (refer to thread of yesterday: "Python 3.2 Vectors.py module") it was necessary to answer the question of what could and what should be used to determine what the instruction '==' or '>=' should mean and what should be used for comparison. The only one that I could find useful was the equality - two vectors are equal if and only if all three of their components are equal. As the components (for purposes of engineering analysis) are real numbers, even the postulation of (v1.x == v2.x) is problematic, as has been pointed out in the thread (as the "floats" are subject to unavoidable round off errors). So the answers are not necessarily unique and one must consider what the program is supposed to achieve. BTW, the "Vector" class inherits from the list, which avoids "reinventing the wheel". The other operators are assigned specific purposes, viz. v1 * v2 is a scalar product of two vectors (the result is a scalar, float), while v1 * r (where v1 is a vector and r is a float) is scaling the size of vector by factor r, (the result is a vector) i.e. each component of v1 is multiplied by r. Vector product (cross product) is shown as v1 ** v2 (the result is a vector). The purpose of choosing this scheme is neither linguistic, nor philosophical - it is practical, just as the vector algebra is practical. It helps to visualise solutions of physical problems (or, if you prefer, engineering problems). OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan.kluev at gmail.com Sun May 15 22:21:00 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 16 May 2011 13:21:00 +1100 Subject: obviscating python code for distribution In-Reply-To: <4DD08620.4030507@tysdomain.com> References: <4DD08620.4030507@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 1:04 PM, Littlefield, Tyler wrote: > Hello all: > Finally, is there a good way to accomplish this? I know that I can make .pyc > files, but those can be disassembled very very easily with the disassembler > and shipping these still means that the person needs the modules that are > used. Is there another way to go about this? No, there is no way to prevent users from getting access to raw python sources. By its nature and design, python is not meant to be used this way, and even obfuscation would not harm readability much. However, you can write all parts you want to hide in C/C++/Cython and distribute them as .so/.dll -- With best regards, Daniel Kluev From nobody at nowhere.com Sun May 15 22:28:31 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 16 May 2011 03:28:31 +0100 Subject: connect SIGINT to custom interrupt handler References: <1691845.hkbZ0PkbqX@PointedEars.de> Message-ID: On Sun, 15 May 2011 17:05:57 +0000, Christoph Scheingraber wrote: > Is it correct anyway to have > > signal.siginterrupt(signal.SIGINT, False) > > in my custom interrupt_handler function No. > or should it be outside but after > signal.signal(signal.SIGINT, interrupt_handler)? Yes. From prologic at shortcircuit.net.au Sun May 15 22:36:56 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 16 May 2011 12:36:56 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 12:21 PM, Daniel Kluev wrote: > No, there is no way to prevent users from getting access to raw python > sources. By its nature and design, python is not meant to be used this > way, and even obfuscation would not harm readability much. > However, you can write all parts you want to hide in C/C++/Cython and > distribute them as .so/.dll Or you could do what everyone else is doing and provide your "application" as a service in some manner. cheers James -- -- James Mills -- -- "Problems are solved by method" From dan.kluev at gmail.com Sun May 15 22:37:17 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 16 May 2011 13:37:17 +1100 Subject: Converting a set into list In-Reply-To: References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: > Both solutions seem to be equivalent in that concerns the number of needed loop runs, but this two-step operation might require one less loop over list1. > The set&set solution, in contrary, might require one loop while transforming to a set and another one for the & operation. python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" "l3 = list(set(l1) & set(l2))" 100 loops, best of 3: 2.19 msec per loop python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" "s=set(l2); l3 = [i for i in l1 if i in s]" 100 loops, best of 3: 2.45 msec per loop python -m timeit -s "l1 = range(1, 100000); l2 = range(50000, 150000)" "l3 = list(set(l1) & set(l2))" 10 loops, best of 3: 28 msec per loop python -m timeit -s "l1 = range(1, 100000); l2 = range(50000, 150000)" "s=set(l2); l3 = [i for i in l1 if i in s]" 10 loops, best of 3: 28.1 msec per loop So even with conversion back into list set&set is still marginally faster. -- With best regards, Daniel Kluev From nobody at nowhere.com Sun May 15 22:53:22 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 16 May 2011 03:53:22 +0100 Subject: connect SIGINT to custom interrupt handler References: Message-ID: On Sun, 15 May 2011 14:32:13 +0000, Christoph Scheingraber wrote: > I now have signal.siginterrupt(signal.SIGINT, False) in the line > below signal.signal(signal.SIGINT, interrupt_handler) > > Unfortunately, pressing ^c still results in the same interrupt error. Sorry; I wasn't paying sufficient attention to the details: >>> select.error: (4, 'Interrupted system call') According to Linux' signal(7) manpage, select() is never restarted, regardless of the siginterrupt() setting. In general, wait-for-something functions aren't restarted; the caller is expected to check that the waited-for condition actually happened, so returning prematurely isn't considered problematic. EINTR is one of those "special" errors (like EAGAIN) which don't actually indicate an error. In the context of select(), a return value of -1 with errno set to EINTR should normally be handled in the same way as a return value of zero, i.e. "nothing has happened yet, try again". While the EINTR case isn't identical to the zero-return case, it's much closer to it than it is to a genuine error. If it's being treated like genuine errors (i.e. raising an exception), that's a defect in the Python bindings. In which case, I'd suggest catching the exception and checking the error code, e.g.: def myselect(rlist, wlist, xlist, timeout = None): try: return select.select(rlist, wlist, xlist, timeout) except select.error, e: if e[0] == errno.EINTR: return 0 raise From ben+python at benfinney.id.au Sun May 15 23:29:49 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 16 May 2011 13:29:49 +1000 Subject: obviscating python code for distribution References: Message-ID: <87boz3gw5u.fsf@benfinney.id.au> "Littlefield, Tyler" writes: > I have been considering writing a couple of programs in Python, but I > don't want to distribute the code along with them. This topic has been raised many times before, and there is a response which is now common but may sound harsh: What is it you think you would gain by obfuscating the code, and why is that worthwhile? What evidence do you have that code obfuscation would achieve that? > Finally, is there a good way to accomplish this? I know that I can > make .pyc files, but those can be disassembled very very easily with > the disassembler and shipping these still means that the person needs > the modules that are used. Is there another way to go about this? Not really, no. You would be best served by critically examining the requirement to obfuscate the code at all. -- \ ?Leave nothing to chance. Overlook nothing. Combine | `\ contradictory observations. Allow yourself enough time.? | _o__) ?Hippocrates | Ben Finney From tyler at tysdomain.com Sun May 15 23:36:53 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 15 May 2011 21:36:53 -0600 Subject: obviscating python code for distribution In-Reply-To: <87boz3gw5u.fsf@benfinney.id.au> References: <87boz3gw5u.fsf@benfinney.id.au> Message-ID: <4DD09BD5.9070405@tysdomain.com> I'm putting lots of work into this. I would rather not have some script kiddy dig through it, yank out chunks and do whatever he wants. I just want to distribute the program as-is, not distribute it and leave it open to being hacked. On 5/15/2011 9:29 PM, Ben Finney wrote: > "Littlefield, Tyler" writes: > >> I have been considering writing a couple of programs in Python, but I >> don't want to distribute the code along with them. > This topic has been raised many times before, and there is a response > which is now common but may sound harsh: > > What is it you think you would gain by obfuscating the code, and why is > that worthwhile? What evidence do you have that code obfuscation would > achieve that? > >> Finally, is there a good way to accomplish this? I know that I can >> make .pyc files, but those can be disassembled very very easily with >> the disassembler and shipping these still means that the person needs >> the modules that are used. Is there another way to go about this? > Not really, no. You would be best served by critically examining the > requirement to obfuscate the code at all. > -- Take care, Ty my website: http://tds-solutions.net my blog: http://tds-solutions.net/blog skype: st8amnd127 ?Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.? ?If Java had true garbage collection, most programs would delete themselves upon execution.? From harrismh777 at charter.net Sun May 15 23:48:03 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 22:48:03 -0500 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> Message-ID: Littlefield, Tyler wrote: > I'm putting lots of work into this. I would rather not have some script > kiddy dig through it, yank out chunks and do whatever he wants. I just > want to distribute the program as-is, not distribute it and leave it > open to being hacked. Protection via obfuscation is invalid practically as well as philosophically. Those of us who work in the free software movement (or the open software movement too) specifically believe that obfuscation is an incorrect approach. Obfuscation is the paramount Microsoft strategy for protection and for security. It doesn't work. In fact, making the code open permits what many of us who consider open source to be 'good science' more secure by allowing peer review and community improvement. Some of us believe that code is not useful unless its open. If I can't see what you're doing, comment on it, improve it if I like, and share it with others I don't need it (its really that simple). Nobody can make this decision for you, of course, but please consider making your coding free software (GPL license), or at least open and GPL compatible licensed. kind regards, m harris From rosuav at gmail.com Sun May 15 23:50:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 13:50:05 +1000 Subject: MySQLdb SEC_TO_TIME function returns datetime.timedelta class In-Reply-To: References: Message-ID: On Mon, May 16, 2011 at 10:42 AM, Jorge Romero wrote: > Hi Pythonists, > I'm retrieving some time data from a MySQL database using Python's MySQLdb > library. Here's the situation, I got a time field on MySQL given in seconds, > I need it on HH:MM:SS format, so I'm SELECTING that field with SEC_TO_TIME > function, something like this: > query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table" You're summing a column, so presumably the values are actually deltas (it doesn't make sense, for instance, to add Tues March 16th to Sat Nov 2nd). The result exceeds a day; in what format do you actually want it? For maximum flexibility, you could ditch the SEC_TO_TIME call and simply work with the integer seconds in Python. You can then format that into HHHHH:MM:SS or whatever suits you. Chris Angelico From gnarlodious at gmail.com Sun May 15 23:53:31 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 15 May 2011 20:53:31 -0700 (PDT) Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) Message-ID: Can someone please explain what I am doing wrong? Calling script: from Gnomon import GnomonBase Gnomon=GnomonBase(3) Called script: class GnomonBase(object): def __init__(self, bench): # do stuff But all I get is: TypeError: __init__() takes exactly 1 positional argument (2 given) I don't understand, I am only sending one variable. What does it think I am sending two? This is Python 3.1.3. -- Gnarlie From harrismh777 at charter.net Sun May 15 23:59:57 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 22:59:57 -0500 Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) In-Reply-To: References: Message-ID: <1j1Ap.30146$Vp.4643@newsfe14.iad> Gnarlodious wrote: > class GnomonBase(object): > def __init__(self, bench): <======= (1) (2) > # do stuff This only answers the surface question.... I have not taken any time to see or understand what (if anything) you are doing which might make any sense... only that the message is complaining about giving __init__() two parms, because you gave it two parms.... ... I know you're joking, but I don't know why...? kind regards, m harris From steve+comp.lang.python at pearwood.info Mon May 16 00:03:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2011 04:03:09 GMT Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> Message-ID: <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 May 2011 21:36:53 -0600, Littlefield, Tyler wrote: > I'm putting lots of work into this. I would rather not have some script > kiddy dig through it, yank out chunks and do whatever he wants. The best way to do that is to labour in obscurity, where nobody either knows or cares about your application. There are hundreds of thousands, possibly millions, of such applications, with a user base of one: the creator. One other alternative is to ask yourself, what's the marginal value of yanking out chunks from my code? What harm does it do me if Joe Haxor spends hours pulling out one subroutine, or a dozen, from my app, and using them in his app? Why should I care? It never ceases to amaze me how often people write some trivial application, like a thousand others, or even some trivial function or class, and then treat it like the copyright to Mickey Mouse. I don't know what your application is, or how it works. It's conceivable that it's the next Microsoft Office. But my advice to you is to take a pragmatic, realistic view of the cost of copyright infringement. If it's going to cost you $1000 in extra effort to prevent $100 of harm, it's simply not worth it. > I just > want to distribute the program as-is, not distribute it and leave it > open to being hacked. Right... because of course we all know how Windows being distributed without source code makes it soooooo secure. You are conflating two different issues: * Can people "steal" or copy my ideas and code? * Can people hack my code (in the bad sense)? I hope this does not offend, because I mean it in the nicest possible way, but if you think that not distributing source code will prevent your code from being broken, then you are delusional. Look at Facebook and its periodic security holes and accounts being hacked. Not only don't Facebook distribute source code, but they don't distribute *anything* -- their application is on their servers, behind a firewall. Does it stop hackers? Not a chance. -- Steven From jorgeromero178 at gmail.com Mon May 16 00:06:21 2011 From: jorgeromero178 at gmail.com (Jorge Romero) Date: Mon, 16 May 2011 00:06:21 -0400 Subject: MySQLdb SEC_TO_TIME function returns datetime.timedelta class In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 11:50 PM, Chris Angelico wrote: > On Mon, May 16, 2011 at 10:42 AM, Jorge Romero > wrote: > > Hi Pythonists, > > I'm retrieving some time data from a MySQL database using Python's > MySQLdb > > library. Here's the situation, I got a time field on MySQL given in > seconds, > > I need it on HH:MM:SS format, so I'm SELECTING that field with > SEC_TO_TIME > > function, something like this: > > query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table" > > You're summing a column, so presumably the values are actually deltas > (it doesn't make sense, for instance, to add Tues March 16th to Sat > Nov 2nd). The result exceeds a day; in what format do you actually > want it? > > For maximum flexibility, you could ditch the SEC_TO_TIME call and > simply work with the integer seconds in Python. You can then format > that into HHHHH:MM:SS or whatever suits you. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > Yeah, I believe that's the way to go, retrieve seconds and deal with them with Python, for flexibility as you pointed. I need the seconds to become HH:MM:SS format. What seems weird to me is why MySQLdb treats the result of the query as deltas. Here's what I get if a query directly the database, output from PHP MyAdmin: SEC_TO_TIME(SUM(billsec)) *79:30:09* * * *This value suits better the datetime.time type, instead of datetime.deltatime. * Thanks Chris for your feedback. -- Jorge Romero -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon May 16 00:10:06 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 May 2011 21:10:06 -0700 Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 8:53 PM, Gnarlodious wrote: > Can someone please explain what I am doing wrong? > > Calling script: > > from Gnomon import GnomonBase > Gnomon=GnomonBase(3) > > > Called script: > > class GnomonBase(object): > ? ?def __init__(self, bench): > ? ? ? ?# do stuff > > But all I get is: > TypeError: __init__() takes exactly 1 positional argument (2 given) > > I don't understand, I am only sending one variable. What does it think > I am sending two? Please post the *full* exception Traceback. Cheers, Chris From ben+python at benfinney.id.au Mon May 16 00:10:11 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 16 May 2011 14:10:11 +1000 Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> Message-ID: <877h9rguak.fsf@benfinney.id.au> "Littlefield, Tyler" writes: > I'm putting lots of work into this. I would rather not have some > script kiddy dig through it, yank out chunks and do whatever he wants. > I just want to distribute the program as-is, not distribute it and > leave it open to being hacked. How do these arguments apply to your code base when they don't apply to, say, LibreOffice or Linux or Python or Apache or Firefox? How is your code base going to be harmed by having the source code available to recipients, when that demonstrably doesn't harm countless other code bases out there? -- \ ?Let others praise ancient times; I am glad I was born in | `\ these.? ?Ovid (43 BCE?18 CE) | _o__) | Ben Finney From ian.g.kelly at gmail.com Mon May 16 00:12:47 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 15 May 2011 22:12:47 -0600 Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 9:53 PM, Gnarlodious wrote: > class GnomonBase(object): > ? ?def __init__(self, bench): > ? ? ? ?# do stuff > > But all I get is: > TypeError: __init__() takes exactly 1 positional argument (2 given) > > I don't understand, I am only sending one variable. What does it think > I am sending two? Usually this error means that you forgot to include "self" in the method signature. As a result it receives two arguments (self and bench) but only has one defined (bench). The snippet you posted looks correct, though. It might be easier to help if you posted the actual code. Also the full stack trace might be helpful. From gnarlodious at gmail.com Mon May 16 00:30:06 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 15 May 2011 21:30:06 -0700 (PDT) Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) References: Message-ID: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> I don't have a trace because I am using mod_wsgi under Apache. Maybe there is a way to debug using mod_wsgi but I haven't been able to figure out how. My problem is that in order to run mod_wsgi I had to downgrade to Python 3.1.3 which may be causing the problem. This website was running fine in Py3.2. I did find an explanation that sounds like this is an intentional deprecation in Python: It looks like we are now expected to initialize instance variables with a setter statement? -- Gnarlie From steve+comp.lang.python at pearwood.info Mon May 16 00:31:00 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2011 04:31:00 GMT Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) References: Message-ID: <4dd0a883$0$29983$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 May 2011 20:53:31 -0700, Gnarlodious wrote: > Can someone please explain what I am doing wrong? > > Calling script: > > from Gnomon import GnomonBase > Gnomon=GnomonBase(3) > > > Called script: > > class GnomonBase(object): > def __init__(self, bench): > # do stuff > > But all I get is: > TypeError: __init__() takes exactly 1 positional argument (2 given) > > I don't understand, I am only sending one variable. What does it think I > am sending two? Whenever you call a method, the instance is automatically provided by Python as an argument (conventionally called "self") to the function. So, for any arbitrary method, the call: instance.method(arg) is converted to: type(instance).method(instance, arg) hence two arguments. My guess is that your GnomonBase __init__ method is *not* what you show above, but (probablY) one of the following: def __init__(bench): # oops, forgot self # do stuff def __init__(selfbench): # oops, forgot the comma # do stuff -- Steven From rosuav at gmail.com Mon May 16 00:40:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 14:40:17 +1000 Subject: obviscating python code for distribution In-Reply-To: <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 16, 2011 at 2:03 PM, Steven D'Aprano wrote: > The best way to do that is to labour in obscurity, where nobody either > knows or cares about your application. There are hundreds of thousands, > possibly millions, of such applications, with a user base of one: the > creator. And I'm sure Steven will agree with me that this is not in any way a bad thing. I've written hundreds of such programs myself (possibly thousands), and they have all served their purposes. On a slightly larger scale, there are even more programs that have never left the walls of my house, having been written for my own family - not because I'm afraid someone else will steal them, but because they simply are of no value to anyone else. But hey, if anyone wants a copy of my code that's basically glue between [obscure application #1] and [obscure application #2] that does [obscure translation] as well to save a human from having to do it afterwards, sure! You're welcome to it! :) However, I do not GPL my code; I prefer some of the other licenses (such as CC-BY-SA), unless I'm working on a huge project that's not meant to have separate authors. For something that by and large is one person's work, I think it's appropriate to give attribution. But discussion of exactly _which_ open source license to use is a can of worms that's unlikely to be worth opening at this stage. Chris Angelico From clp2 at rebertia.com Mon May 16 00:44:23 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 May 2011 21:44:23 -0700 Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) In-Reply-To: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> References: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> Message-ID: On Sun, May 15, 2011 at 9:30 PM, Gnarlodious wrote: > I don't have a trace because I am using mod_wsgi under Apache. Maybe > there is a way to debug using mod_wsgi but I haven't been able to > figure out how. > > My problem is that in order to run mod_wsgi I had to downgrade to > Python 3.1.3 which may be causing the problem. This website was > running fine in Py3.2. > > I did find an explanation that sounds like this is an intentional > deprecation in Python: > do-they-do> > > > It looks like we are now expected to initialize instance variables > with a setter statement? Er, what are you talking about? That's always been the case; it's nothing new at all. Perhaps your "# do stuff" from earlier isn't doing the right stuff? Posting the actual code would help. Cheers, Chris -- http://rebertia.com From n4vpython at gmail.com Mon May 16 00:52:24 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Mon, 16 May 2011 10:22:24 +0530 Subject: Memcached in python 3 Message-ID: Hi Guys, How can I used memcached with python 3? Are there any other good alternatives to memcached? What about python dictionary manager, would it compare to memcached if I were to use it for storing in-memory information? Any light on this matter will be appreciated. Regards, Navkirat -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnarlodious at gmail.com Mon May 16 00:53:45 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 15 May 2011 21:53:45 -0700 (PDT) Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) References: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> Message-ID: <09233fe8-b1ef-4c1c-a7f6-9aa65de48368@z7g2000prh.googlegroups.com> Well, I have a whole lot of scripts where I could say something like this: def __init__(self, var1, var2, var3...): Now suddenly I have to change them all to run in Python 3.1.3? This is apparently not a bug. And I rebooted still getting the same behavior. Can someone explain it? -- Gnarlie From ian.g.kelly at gmail.com Mon May 16 00:54:03 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 15 May 2011 22:54:03 -0600 Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) In-Reply-To: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> References: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> Message-ID: On Sun, May 15, 2011 at 10:30 PM, Gnarlodious wrote: > I don't have a trace because I am using mod_wsgi under Apache. Maybe > there is a way to debug using mod_wsgi but I haven't been able to > figure out how. http://code.google.com/p/modwsgi/wiki/DebuggingTechniques > My problem is that in order to run mod_wsgi I had to downgrade to > Python 3.1.3 which may be causing the problem. This website was > running fine in Py3.2. > > I did find an explanation that sounds like this is an intentional > deprecation in Python: > do-they-do> > I don't think those are related. If it were an intentional change in Python from 2007, then you would be seeing the error in both versions. I don't see how the stackoverflow link has any bearing on the error at all. > It looks like we are now expected to initialize instance variables > with a setter statement? You mean like this? x = Foo() x.y = z No, there is no such expectation. From gnarlodious at gmail.com Mon May 16 01:08:10 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 15 May 2011 22:08:10 -0700 (PDT) Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) References: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> Message-ID: <42766145-b076-40c1-bc2b-b85c9c2e1edc@35g2000prp.googlegroups.com> Thanks for all the help, this looks like a bug in mod_wsgi. I tried it interactively under Py3.1.3 and it behaves normally. I'll take this over to the mod_wsgi group. -- Gnarlie http://Gnarlodious.com From rustompmody at gmail.com Mon May 16 01:40:37 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 15 May 2011 22:40:37 -0700 (PDT) Subject: checking if a list is empty References: <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> <4dd07182$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0266541d-3039-42ef-a979-23722b78f9cd@f15g2000pro.googlegroups.com> I have been scolded off-list for pursuing a discussion that has nothing to do with python. So I continue a bit gingerly :-) and will stop when others feel this is useless/irrelevant/whatever. Steven wrote: > I'm afraid I didn't find your discussion about reification, Platonism and > linguistics very helpful. Some of it I disagree with, some I agree with, > but in neither case do I see any relevance to the question of whether > bools are first class objects in Python, and if not, why not. Thank you (Steven and Terry) for using the word 'reification'. I used the more common 'firstclass' because I assumed that will be more generally known. I however prefer reification since one can discuss (more cooly :-) ) what and how much one should reify; the word reification has less of a strong value judgment in philosophy than firstclass has in computer science. The lead-writeup on reification http://en.wikipedia.org/wiki/Reification_%28computer_science%29 has the following line: > Informally, reification is often referred to as "making something a first-class citizen" within the scope of a particular system. So from the CS side reification == movement-towards-firstclassness >From the philosophical side we could try to define platonism (non- mystically) as "The strong reification of abstract concepts" So much for my defense of bringing in platonism into the discussion. Steven wrote: > > > Seemingly you and Dijkstra are saying something similar when you say > > [1,2,3] is a way of writing true > > and he says 2<3 is a way of writing true. But on further examination > > (with Leibniz law above) Dijkstra's 2<3 = True will work consistently in > > all contexts but [1,2,3] = True will work sometimes and fail sometimes. > Please do not arbitrarily mix Python and mathematics syntax. What you have stated gives a SyntaxError. Is this non-mixing-up possible? Like 'reification,' I do not know if using the funny brackets of denotational semantics would be intelligible on this list ( and I dont know how to write them in ASCII) but using |[ ]| as an approximation, I would have to say something like: Dijkstra's |[ 2<3 ]| = True will work consistently... Python's | [ [1,2,3] ]| = |[True ]| will be be true in boolean contexts and not elsewhere. Note that the first |[]| is for the object language called mathematics and the other two for the object language called python. And the = is in a pidgin English-math meta language that is need to discuss these object languages. I am not clear that this form of discourse actually enhances clarity, however it does bring up the point that this discussion is as much about object/meta-language distinctions and confusions as it is about reification. You see when Terry talks of boolean algebra for switching networks, he is referring to logic as an object language. But when we use logic to discuss and understand (and argue :-) ) we are using it in the meta-language. Dijkstra's signal contribution -- which he attributes to Boole, Leibniz and Recorde (for the = sign) -- lies in this: >From the time of Aristotle, all usage of logic in the meta-language (logic as the substrate for arguments rather than logic as a model for things like switching networks) has been a string of assertions linked up with 'implies' 'therefore' 'follows from' etc. All these when modelled (in a suitable object logic) would traditionally look like => (implies) or at best <= (follows from) It is possible to do all this -- traditional logic -- using = (aka iff, <=>, etc) The benefit is that logic becomes much more like traditional algebra: Proofs become of the form: desideradum = : : = true The cost is that bool has to be properly reified. Steven wrote: > Rusi wrote: > > For example if my language seems to have entities like '2' '3' '+' but > > 2+3 does not work out equal to 5 we would (I hope!) not say the language > > has first-class numbers. > Well, that's a problem. By that definition, floats are not first class > numbers. While 2+3 does work out to be equal to 5, other standard > properties of the real number system do not apply: > >>> 0.3 + 0.4 - 0.3 == 0.4 >From C onwards (and in Fortran), its been called float, not real. Note that C like python uses a math-suggesting name int for integers but a hardware implementation name for float. This suggests that (aside from overflow) int in C corresponds to the math Z whereas float does not quite correspond to real. [The whole field of numerical analysis comes about because of this non-correspondence] In the language Pascal, what we call float today was called real and this would be an argument. But in this context I dont get the argument... From tyler at tysdomain.com Mon May 16 01:41:23 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 15 May 2011 23:41:23 -0600 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DD0B903.4090109@tysdomain.com> Hello: Thanks all for your information and ideas. I like the idea of open source; I have a fairly large (or large, by my standards anyway) project that I am working on that is open source. Here's kind of what I want to prevent. I want to write a multi-player online game; everyone will essentually end up connecting to my server to play the game. I don't really like the idea of security through obscurity, but I wanted to prevent a couple of problems. 1) First I want to prevent people from hacking at the code, then using my server as a test for their new setups. I do not want someone to gain some extra advantage just by editing the code. Is there some other solution to this, short of closed-source? Thanks, From rustompmody at gmail.com Mon May 16 01:56:03 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 15 May 2011 22:56:03 -0700 (PDT) Subject: checking if a list is empty References: <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> Message-ID: <56619d3d-f1e4-4f45-9dc6-88ff4668f40f@18g2000prd.googlegroups.com> On May 16, 2:36?am, Terry Reedy wrote: > On 5/15/2011 1:33 PM, rusi wrote: > > > On May 15, 10:07 am, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> ?wrote: > > >> I'm afraid I don't understand what you mean. Can you explain please, what > >> properties of "first class booleans" do you think are missing from Python? > > Given the usual CS definition of 'first class object', all Python > objects are first class. But that does not preclude other definitions. > > > > What CS definition? Perhaps your definition matches the wikipedia article: http://en.wikipedia.org/wiki/First-class_object And I am using the extended definition on the talk page: http://en.wikipedia.org/wiki/Talk:First-class_object#Is_it_is.2C_or_is_it_aint.3F [Evidently the arguments of this thread are repeatedly played out elsewhere :-; ] From prologic at shortcircuit.net.au Mon May 16 02:00:12 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 16 May 2011 16:00:12 +1000 Subject: obviscating python code for distribution In-Reply-To: <4DD0B903.4090109@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 3:41 PM, Littlefield, Tyler wrote: > Here's kind of what I want to prevent. I want to write a multi-player online > game; everyone will essentually end up connecting to my server to play the > game. I don't really like the idea of security through obscurity, but I > wanted to prevent a couple of problems. > 1) First I want to prevent people from hacking at the code, then using my > server as a test for their new setups. I do not want someone to gain some > extra advantage just by editing the code. > Is there some other solution to this, short of closed-source? As I mentioned before (which I don't think you quite got)... Write your "game" for the "web". Write is as a SaaS (Software as a Service) - even if it's free and open source. cheers James -- -- James Mills -- -- "Problems are solved by method" From rosuav at gmail.com Mon May 16 02:12:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 16:12:36 +1000 Subject: obviscating python code for distribution In-Reply-To: <4DD0B903.4090109@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 3:41 PM, Littlefield, Tyler wrote: > Here's kind of what I want to prevent. I want to write a multi-player online > game; everyone will essentually end up connecting to my server to play the > game. I don't really like the idea of security through obscurity, but I > wanted to prevent a couple of problems. > 1) First I want to prevent people from hacking at the code, then using my > server as a test for their new setups. I do not want someone to gain some > extra advantage just by editing the code. > Is there some other solution to this, short of closed-source? 1) If you're worried about people getting hold of the code that's running on your server, that's a server security issue and not a Python obscurity issue (if they get the code, they can run it no matter how obscured it is). 2) Was there a problem 2? :) As James Mills said, just leave it on the server and then you don't have to give out the source (and by "don't have to", I mean ethically, legally, and technically). You may want to give some thought to scaleability of your code; Google told their staff to avoid Python for things that are going to get hammered a lot (although it's possible that Google's idea of "a lot" is five orders of magnitude more than you'll ever get!!). But if your game world puts a hard limit on its own load (eg if players are on a 50x50 board and you know you can handle 2500 simultaneous players), you won't have a problem. Also, Python doesn't really cater to servers that want to have their code updated on the fly; I'm sure you could work something out using a dictionary of function objects, but otherwise you're stuck with bringing the server down to do updates. That's considered normal in today's world, but I really don't know why... downtime is SO last century! Chris Angelico happily running servers on fully open source stacks From tyler at tysdomain.com Mon May 16 02:17:15 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 16 May 2011 00:17:15 -0600 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: <4DD0C16B.4010500@tysdomain.com> >Write your "game" for the "web". >Write is as a SaaS (Software as a Service) - even if it's free and open source. I understood you loud and clear. And that makes a lot of assumptions on my game and the design. I don't really care to host this over the web. I want a centralized server that would perform the logic, where I can offload the playing of sounds (through a soundpack that's already installed) to the client-side. Not only that, but a lot of web technologies that would be used for this wouldn't really work, as I am doing this for the blind; Flash as well as a lot of the popular setups are not very accessible. From tyler at tysdomain.com Mon May 16 02:20:07 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 16 May 2011 00:20:07 -0600 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: <4DD0C217.9050304@tysdomain.com> Hello: I wanted to make the client in python, and the server possibly, though I'm not really sure on that. I was not worried about the code for the server being stolen, as much as I was worried about people tinkering with the client code for added advantages. Most of the logic can be handled by the server to prevent a lot of this, but there are still ways people could give themselves advantages by altering the client. From prologic at shortcircuit.net.au Mon May 16 02:24:12 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 16 May 2011 16:24:12 +1000 Subject: obviscating python code for distribution In-Reply-To: <4DD0C127.80300@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> <4DD0C127.80300@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 4:16 PM, Littlefield, Tyler wrote: > I understood you loud and clear. And that makes a lot of assumptions on my > game and the design. I don't really care to host this over the web. I want a > centralized server that would perform the logic, where I can offload the > playing of sounds (through a soundpack that's already installed) to the > client-side. Not only that, but a lot of web technologies that would be used > for this wouldn't really work, as I am doing this for the blind; Flash as > well as a lot of the popular setups are not very accessible. Funny you should mention this "now" :) I happen to be blind myself. Yes I agree Flash is not very accessible (never has been). Web Standards web apps and such however are quite accessible! cheers James -- -- James Mills -- -- "Problems are solved by method" From __peter__ at web.de Mon May 16 02:34:44 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 May 2011 08:34:44 +0200 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: Daniel Kluev wrote: >> Both solutions seem to be equivalent in that concerns the number of >> needed loop runs, but this two-step operation might require one less loop >> over list1. The set&set solution, in contrary, might require one loop >> while transforming to a set and another one for the & operation. > > python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" > "l3 = list(set(l1) & set(l2))" > 100 loops, best of 3: 2.19 msec per loop > > python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" > "s=set(l2); l3 = [i for i in l1 if i in s]" > 100 loops, best of 3: 2.45 msec per loop > > python -m timeit -s "l1 = range(1, 100000); l2 = range(50000, 150000)" > "l3 = list(set(l1) & set(l2))" > 10 loops, best of 3: 28 msec per loop > > python -m timeit -s "l1 = range(1, 100000); l2 = range(50000, 150000)" > "s=set(l2); l3 = [i for i in l1 if i in s]" > 10 loops, best of 3: 28.1 msec per loop > > So even with conversion back into list set&set is still marginally faster. If you are looking for speed, consider s = set(l1) s.intersection_update(l2) l3 = list(s) $ python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" "list(set(l1) & set(l2))" 100 loops, best of 3: 4 msec per loop $ python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" "s = set(l1); s.intersection_update(l2); list(s)" 100 loops, best of 3: 1.99 msec per loop From karim.liateni at free.fr Mon May 16 03:26:26 2011 From: karim.liateni at free.fr (Karim) Date: Mon, 16 May 2011 09:26:26 +0200 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: References: <4DD03B69.6050301@gmail.com> Message-ID: <4DD0D1A2.6060109@free.fr> On 05/16/2011 03:06 AM, David Robinow wrote: > On Sun, May 15, 2011 at 4:45 PM, Andrew Berg wrote: >> I'm trying to understand why HMTLParser.feed() isn't returning the whole >> page. My test script is this: >> >> import urllib.request >> import html.parser >> class MyHTMLParser(html.parser.HTMLParser): >> def handle_starttag(self, tag, attrs): >> if tag == 'a' and attrs: >> print(tag,'-',attrs) >> >> url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth' >> page = urllib.request.urlopen(url).read() >> parser = MyHTMLParser() >> parser.feed(str(page)) >> >> I can do print(page) and get the entire HTML source, but >> parser.feed(str(page)) only spits out the information for the top links >> and none of the "revisionxxxx" links. Ultimately, I just want to find >> the name of the first "revisionxxxx" link (right now it's >> "revision1995", when a new build is uploaded it will be "revision2000" >> or whatever). I figure this is a relatively simple page; once I >> understand all of this, I can move on to more complicated pages. > You've got bad HTML. Look closely and you'll see the there's no space > between the "revisionxxxx" strings and the style tag following. > The parser doesn't like this. I don't know a solution other than > fixing the html. > (I created a local copy, edited it and it worked.) Hello, Use regular expression for bad HTLM or beautifulSoup (google it), below a exemple to extract all html links: linksList = re.findall('.*?',htmlSource) for link in linksList: print link Cheers Karim From debatem1 at gmail.com Mon May 16 03:27:44 2011 From: debatem1 at gmail.com (geremy condra) Date: Mon, 16 May 2011 00:27:44 -0700 Subject: obviscating python code for distribution In-Reply-To: <4DD0B903.4090109@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: On Sun, May 15, 2011 at 10:41 PM, Littlefield, Tyler wrote: > Hello: > Thanks all for your information and ideas. I like the idea of open source; I > have a fairly large (or large, by my standards anyway) project that I am > working on that is open source. > > Here's kind of what I want to prevent. I want to write a multi-player online > game; everyone will essentually end up connecting to my server to play the > game. I don't really like the idea of security through obscurity, but I > wanted to prevent a couple of problems. > 1) First I want to prevent people from hacking at the code, then using my > server as a test for their new setups. I do not want someone to gain some > extra advantage just by editing the code. > Is there some other solution to this, short of closed-source? > Thanks, I don't know that closing the source does you much more good than obfuscating it. The obvious attack surface here is pretty much totally exposed via network traffic, which any legitimate client can gain access to. A better approach would be to simply write more secure code in the first place. Geremy Condra From gagsl-py2 at yahoo.com.ar Mon May 16 03:50:11 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 May 2011 04:50:11 -0300 Subject: Import on case insensitive filesystem References: Message-ID: En Fri, 13 May 2011 15:43:23 -0300, Mitchell Hashimoto escribi?: > I'm developing an app which runs Python on a filesystem which is not case > sensitive (Mac OS X), but is mounted as an NFS drive on a remote machine. > This causes errors because of the import being case sensitive but > accessing > an FS which is case insensitive. Short of copying the entire directory > tree > over to another filesystem, is there anything I can do to flag Python to > act > as though it were on a case sensitive FS? Try creating an environment variable PYTHONCASEOK with any value. See http://www.python.org/dev/peps/pep-0235/ for details. -- Gabriel Genellina From jnr.gonzalez at googlemail.com Mon May 16 04:19:31 2011 From: jnr.gonzalez at googlemail.com (J) Date: Mon, 16 May 2011 01:19:31 -0700 (PDT) Subject: Convert AWK regex to Python Message-ID: Good morning all, Wondering if you could please help me with the following query:- I have just started learning Python last weekend after a colleague of mine showed me how to dramatically cut the time a Bash script takes to execute by re-writing it in Python. I was amazed at how fast it ran. I would now like to do the same thing with another script I have. This other script reads a log file and using AWK it filters certain fields from the log and writes them to a new file. See below the regex the script is executing. I would like to re-write this regex in Python as my script is currently taking about 1 hour to execute on a log file with about 100,000 lines. I would like to cut this time down as much as possible. cat logs/pdu_log_fe.log | awk -F\- '{print $1,$NF}' | awk -F\. '{print $1,$NF}' | awk '{print $1,$4,$5}' | sort | uniq | while read service command status; do echo "Service: $service, Command: $command, Status: $status, Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | grep $status | wc -l | awk '{ print $1 }'`" >> logs/pdu_log_fe_clean.log; done This AWK command gets lines which look like this:- 2011-05-16 09:46:22,361 [Thread-4847133] PDU D And outputs lines like this:- CC_SMS_SERVICE_51408 submit_resp: 0 I have tried writing the Python script myself but I am getting stuck writing the regex. So far I have the following:- #!/usr/bin/python # Import RegEx module import re as regex # Log file to work on filetoread = open('/tmp/ pdu_log.log', "r") # File to write output to filetowrite = file('/tmp/ pdu_log_clean.log', "w") # Perform filtering in the log file linetoread = filetoread.readlines() for line in linetoread: filter0 = regex.sub(r" References: Message-ID: On Mon, May 16, 2011 at 6:19 PM, J wrote: > cat logs/pdu_log_fe.log | awk -F\- '{print $1,$NF}' | awk -F\. '{print $1,$NF}' | awk '{print $1,$4,$5}' | sort | uniq | while read service command status; do echo "Service: $service, Command: $command, Status: $status, Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | grep $status | wc -l | awk '{ print $1 }'`" >> logs/pdu_log_fe_clean.log; done Small side point: Instead of "| sort | uniq |", you could use a Python dictionary. That'll likely speed things up somewhat! Chris Angelico From jnr.gonzalez at googlemail.com Mon May 16 04:43:20 2011 From: jnr.gonzalez at googlemail.com (J) Date: Mon, 16 May 2011 01:43:20 -0700 (PDT) Subject: Convert AWK regex to Python In-Reply-To: Message-ID: <0426dbb3-178c-42ac-aebc-29603b3b3bce@glegroupsg2000goo.googlegroups.com> Good morning Angelico, Do I understand correctly? Do you mean incorporating a Python dict inside the AWK command? How can I do this? From jnr.gonzalez at googlemail.com Mon May 16 04:43:20 2011 From: jnr.gonzalez at googlemail.com (J) Date: Mon, 16 May 2011 01:43:20 -0700 (PDT) Subject: Convert AWK regex to Python In-Reply-To: Message-ID: <0426dbb3-178c-42ac-aebc-29603b3b3bce@glegroupsg2000goo.googlegroups.com> Good morning Angelico, Do I understand correctly? Do you mean incorporating a Python dict inside the AWK command? How can I do this? From rosuav at gmail.com Mon May 16 04:46:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 18:46:51 +1000 Subject: Convert AWK regex to Python In-Reply-To: <0426dbb3-178c-42ac-aebc-29603b3b3bce@glegroupsg2000goo.googlegroups.com> References: <0426dbb3-178c-42ac-aebc-29603b3b3bce@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 16, 2011 at 6:43 PM, J wrote: > Good morning Angelico, > Do I understand correctly? Do you mean incorporating a Python dict inside the AWK command? How can I do this? No, inside Python. What I mean is that you can achieve the same uniqueness requirement by simply storing the intermediate data in a dictionary and then retrieving it at the end. Chris Angelico From steve+comp.lang.python at pearwood.info Mon May 16 04:49:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2011 08:49:12 GMT Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dd0e507$0$29983$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 May 2011 23:41:23 -0600, Littlefield, Tyler wrote: > Here's kind of what I want to prevent. I want to write a multi-player > online game; everyone will essentually end up connecting to my server to > play the game. I don't really like the idea of security through > obscurity, but I wanted to prevent a couple of problems. 1) First I want > to prevent people from hacking at the code, then using my server as a > test for their new setups. I do not want someone to gain some extra > advantage just by editing the code. Is there some other solution to > this, short of closed-source? Thanks, Closed source is not a solution. Please wipe that out of your mind. People successfully hack closed source applications. The lack of source is hardly a barrier at all: it's like painting over the door to your house in camouflage colours so from a distance people won't see it. To a guy with a network sniffer and debugger, the lack of source is no barrier at all. You're trying to solve a hard problem, and by hard, I mean "impossible". It simply isn't possible to trust software on a machine you don't control, and pretty damn hard on a machine you do control. To put it in a nutshell, you can't trust *anything*. See the classic paper by Ken Thompson, "Reflections on Trusting Trust": http://cm.bell-labs.com/who/ken/trust.html Now, in a more practical sense, you might not fear that the operating system will turn on you, or the Python compiler. Some threats you don't care about. The threat model you do care about is a much more straight- forward one: how to trust the desktop client of your game? Alas, the answer is, you can't. You can't trust anything that comes from the client until you've verified it is unmodified, and you can't verify it is unmodified until you can trust the information it sends you. A vicious circle. You're fighting physics here. Don't think that obscuring the source code will help. On-line game servers are engaged in a never-ending arms race against "punks" who hack the clients. The servers find a way to detect one hack and block it, and the punks find another hack that goes unnoticed for a while. It's like anti-virus and virus, or immune systems and germs. The question you should be asking is not "how do I make this secure against cheats?", but "how much cheating can I afford to ignore?". If your answer is "No cheating is acceptable", then you have to do all the computation on the server, nothing on the client, and to hell with performance. All your client does is the user interface part. If the answer is, "Its a MUD, who's going to cheat???" then you don't have to do anything. Trust your users. If the benefit from "cheating" is small enough, and the number of cheaters low, who cares? You're not running an on-line casino for real money. See also here: http://web.archiveorange.com/archive/v/bqumydkHsi2ytdsX7ewa Another approach might be to use psychology on your users. Run one server for vanilla clients to connect to, and another server where anything goes. Let the punks get it out of their system by competing with other punks. Run competitions to see who can beat the most souped up, dirty, cheating turbo-powered clients, for honour and glory. Name and shame the punks who cheat on the vanilla server, praise the best cheaters on the anything-goes machine, and you'll (hopefully!) find that the level of cheating on the vanilla server is quite low. Who wants to be the low-life loser who wins by cheating when you can challenge your hacker peers instead? (Note: I don't know if this approach ever works, but I know it does *not* work when real money or glory is involved. Not even close.) If Blizzard can't stop private servers, rogue clients and hacked accounts, what makes you think you can? -- Steven From rosuav at gmail.com Mon May 16 05:10:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 19:10:20 +1000 Subject: obviscating python code for distribution In-Reply-To: <4dd0e507$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4dd0e507$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 16, 2011 at 6:49 PM, Steven D'Aprano wrote: > If your answer is "No cheating is acceptable", then you have to do all > the computation on the server, nothing on the client, and to hell with > performance. All your client does is the user interface part. > > If the answer is, "Its a MUD, who's going to cheat???" then you don't > have to do anything. Trust your users. If the benefit from "cheating" is > small enough, and the number of cheaters low, who cares? You're not > running an on-line casino for real money. The nearest I've seen to the latter is Dungeons and Dragons. People can cheat in a variety of ways, but since they're not playing *against* each other, cheating is rare. As to the former, though... the amount of computation that you can reliably offload to even a trusted client is low, so you don't lose much by doing it all on the server. The most computationally-intensive client-side work would be display graphics and such, and that's offloadable if and ONLY if there's no game-sensitive information hidden behind things. Otherwise someone could snoop the traffic-stream and find out what's behind that big nasty obstacle, or turn the obstacle transparent, or whatever... not safe. There's an old OS/2 game called Stellar Frontier that moves sprites around on the screen using clientside code, but if there's a bit of lag talking to the server, you see a ship suddenly yoinked to its new position when the client gets the latest location data. That's a fair compromise, I think; the client predicts where the ship "ought to be", and the server corrects it when it can. Chris Angelico From gagsl-py2 at yahoo.com.ar Mon May 16 05:29:00 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 May 2011 06:29:00 -0300 Subject: turn monitor off and on References: Message-ID: En Sat, 14 May 2011 03:08:44 -0300, Astan Chee escribi?: > I'm trying to turn off my monitor, pause and then turn it on again. > I'm doing this in python 2.6 and windows xp. Here is my script so far > (that doesn't work): > > def turnOnMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > For some reason, the script doesn't turn the monitor back on. What am > I doing wrong here or are there any other alternative? Your script worked fine for me, 2.6 and XP also. Perhaps your monitor device driver is buggy or does not implement the required functionality. Mine is from Philips. -- Gabriel Genellina From jeanmichel at sequans.com Mon May 16 05:36:02 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 16 May 2011 11:36:02 +0200 Subject: obviscating python code for distribution In-Reply-To: <4DD0B903.4090109@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: <4DD0F002.10005@sequans.com> Littlefield, Tyler wrote: > Hello: > Thanks all for your information and ideas. I like the idea of open > source; I have a fairly large (or large, by my standards anyway) > project that I am working on that is open source. > > Here's kind of what I want to prevent. I want to write a multi-player > online game; everyone will essentually end up connecting to my server > to play the game. I don't really like the idea of security through > obscurity, but I wanted to prevent a couple of problems. > 1) First I want to prevent people from hacking at the code, then using > my server as a test for their new setups. I do not want someone to > gain some extra advantage just by editing the code. > Is there some other solution to this, short of closed-source? > Thanks, > If your App meet some success, you'll need some help. You'll be able to get some only if the community grows and has access to your code. If you want to battle versus hackers, you have already lost (if your app hos no success, there will be no hacker anyway :o) ) Otherwise I guess that most online games execute all decisions and state machine transitions at server side, which is the only code you can trust. The client only forwards user inputs to the server, and display the resulting effect . JM From __peter__ at web.de Mon May 16 06:07:27 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 May 2011 12:07:27 +0200 Subject: Convert AWK regex to Python References: Message-ID: J wrote: > Good morning all, > Wondering if you could please help me with the following query:- > I have just started learning Python last weekend after a colleague of mine > showed me how to dramatically cut the time a Bash script takes to execute > by re-writing it in Python. I was amazed at how fast it ran. I would now > like to do the same thing with another script I have. > > This other script reads a log file and using AWK it filters certain fields > from the log and writes them to a new file. See below the regex the > script is executing. I would like to re-write this regex in Python as my > script is currently taking about 1 hour to execute on a log file with > about 100,000 lines. I would like to cut this time down as much as > possible. > > cat logs/pdu_log_fe.log | awk -F\- '{print $1,$NF}' | awk -F\. '{print > $1,$NF}' | awk '{print $1,$4,$5}' | sort | uniq | while read service > command status; do echo "Service: $service, Command: $command, Status: > $status, Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | > grep $status | wc -l | awk '{ print $1 }'`" >> logs/pdu_log_fe_clean.log; > done > > This AWK command gets lines which look like this:- > > 2011-05-16 09:46:22,361 [Thread-4847133] PDU D > CC_SMS_SERVICE_51408_656-ServerThread- VASPSessionThread-7ee35fb0-7e87-11e0-a2da-00238bce423b-TRX > - 2011-05-16 09:46:22 - OUT - (submit_resp: (pdu: L: 53 ID: 80000004 > Status: 0 SN: 25866) 98053090-7f90-11e0-a2da-00238bce423b (opt: ) ) > > > And outputs lines like this:- > > CC_SMS_SERVICE_51408 submit_resp: 0 > > I have tried writing the Python script myself but I am getting stuck > writing the regex. So far I have the following:- For the moment forget about the implementation. The first thing you should do is to describe the problem as clearly as possible, in plain English. From duncan.booth at invalid.invalid Mon May 16 06:24:28 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 16 May 2011 10:24:28 GMT Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Message-ID: Chris Torek wrote: > >>> x = [3, 1, 4, 1, 5, 9, 2, 6] > >>> x > [3, 1, 4, 1, 5, 9, 2, 6] > >>> list(set(x)) > [1, 2, 3, 4, 5, 6, 9] > >>> > > Of course, this trick only works if all the list elements are > hashable. > > This might not be the best example since the result is sorted > "by accident", while other list(set(...)) results are not. A minor change to your example makes it out of order even for integers: >>> x = [7, 8, 9, 1, 4, 1] >>> list(set(x)) [8, 9, 1, 4, 7] or for that mattter: >>> list(set([3, 32, 4, 32, 5, 9, 2, 6])) [32, 2, 3, 4, 5, 6, 9] -- Duncan Booth http://kupuguy.blogspot.com From jnr.gonzalez at googlemail.com Mon May 16 06:57:49 2011 From: jnr.gonzalez at googlemail.com (J) Date: Mon, 16 May 2011 03:57:49 -0700 (PDT) Subject: Convert AWK regex to Python In-Reply-To: Message-ID: Hello Peter, Angelico, Ok lets see, My aim is to filter out several fields from a log file and write them to a new log file. The current log file, as I mentioned previously, has thousands of lines like this:- 2011-05-16 09:46:22,361 [Thread-4847133] PDU D All the lines in the log file are similar and they all have the same length (same amount of fields). Most of the fields are separated by spaces except for couple of them which I am processing with AWK (removing " Message-ID: Hello Peter, Angelico, Ok lets see, My aim is to filter out several fields from a log file and write them to a new log file. The current log file, as I mentioned previously, has thousands of lines like this:- 2011-05-16 09:46:22,361 [Thread-4847133] PDU D All the lines in the log file are similar and they all have the same length (same amount of fields). Most of the fields are separated by spaces except for couple of them which I am processing with AWK (removing " Message-ID: <4dd10a8a$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 May 2011 03:57:49 -0700, J wrote: > Most of the fields are separated by > spaces except for couple of them which I am processing with AWK > (removing " to do is evaluate each line in the log file and break them down into > fields which I can call individually and write them to a new log file > (for example selecting only fields 1, 2 and 3). fields = line.split(' ') output.write(fields[1] + ' ') output.write(fields[2] + ' ') output.write(fields[3] + '\n') -- Steven From __peter__ at web.de Mon May 16 07:36:01 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 May 2011 13:36:01 +0200 Subject: Convert AWK regex to Python References: Message-ID: J wrote: > Hello Peter, Angelico, > > Ok lets see, My aim is to filter out several fields from a log file and > write them to a new log file. The current log file, as I mentioned > previously, has thousands of lines like this:- 2011-05-16 09:46:22,361 > [Thread-4847133] PDU D CC_SMS_SERVICE_51408_656-ServerThread- VASPSessionThread-7ee35fb0-7e87-11e0-a2da-00238bce423b-TRX > - 2011-05-16 09:46:22 - OUT - (submit_resp: (pdu: L: 53 ID: 80000004 > Status: 0 SN: 25866) 98053090-7f90-11e0-a2da-00238bce423b (opt: ) ) > > > All the lines in the log file are similar and they all have the same > length (same amount of fields). Most of the fields are separated by > spaces except for couple of them which I am processing with AWK (removing > " evaluate each line in the log file and break them down into fields which I > can call individually and write them to a new log file (for example > selecting only fields 1, 2 and 3). > > I hope this is clearer now Not much :( It doesn't really matter whether there are 100, 1000, or a million lines in the file; the important information is the structure of the file. You may be able to get away with a quick and dirty script consisting of just a few regular expressions, e. g. import re filename = ... def get_service(line): return re.compile(r"[(](\w+)").search(line).group(1) def get_command(line): return re.compile(r" <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 15 May 2011 23:41:23 -0600, Littlefield, Tyler wrote: > Here's kind of what I want to prevent. I want to write a multi-player > online game; everyone will essentually end up connecting to my server to > play the game. I don't really like the idea of security through > obscurity, but I wanted to prevent a couple of problems. > 1) First I want to prevent people from hacking at the code, then using > my server as a test for their new setups. I do not want someone to gain > some extra advantage just by editing the code. > Is there some other solution to this, short of closed-source? Closed source will not help in the slightest. What will help is to remember the fundamental rule of client-server security: Don't Trust The Client. If you don't remember this rule, you have no security whatsoever, whether the source is open or closed. Obfuscating the source won't prevent someone from running it under a modified Python interpreter, or running an unmodified Python interpreter under a debugger, or with modified DLLs (or even device drivers). To give just one example, Blizzard has a whole team of people working on anti-cheating measures, most of which involve installing various pieces of privacy-invading, security-endangering malware on their customers' systems. And it still doesn't work. From alister.ware at ntlworld.com Mon May 16 08:29:43 2011 From: alister.ware at ntlworld.com (alister ware) Date: Mon, 16 May 2011 12:29:43 GMT Subject: problem with GKT module? References: Message-ID: On Sun, 15 May 2011 20:42:46 -0500, harrismh777 wrote: > Alister Ware wrote: >> I have a simple call back defined for a radio button widget when I use >>> widget.name in linux I get a value of None, windows returns the >>> widget name as I would expect. >>> >>> > First, not familiar with your issue... > > ... but might be able to help you think through it... > > I am assuming that you are building a Python script using a glade > interface that provides the widgets drag-an-drop style and then allowing > you to take the default code, add to it, or otherwise modify it. > > I am also assuming that the /call back/ is returning a Python None, on > the linux platform... otherwise you're getting the widget name from the > same script on the windows platform?? right? > > It might be helpful to examine both scripts to see where (if any) they > differ. More likely than not, this little snag is a difference in the > way that the windows version of gtk+ libraries are working, than the > original ones on the linux platform. > > On the other hand, the Python wrappers for the gtk+ library on the linux > platform may be hiding the return values. Python functions return 'None' > if the 'return' is not explicitly coded. The gtk+ libraries may be > returning a value but the 'builder' is not generating the right Python > wrapper. I'm making this up, but you get the idea, and you can probably > check from here. > > On the other hand, folks here can enter into a discussion with you > regarding the generated Python code (output from the builder) if you > provide relevant code snippets. > > > Kind regards, > m harris glade generates an xml file that is processed by the python script it is the same ml file & the same python script running on both platforms the basic structure of my call back for testing is:- import gtk class GUI: def __init__(self): builder=gtk.Builder() builder.add_from_file('glade.test') # xml file from glade builder.get_object('window1').show() builder.connect_signals(self) def callback(self,widget,data=None): print widget #gives reference to radio button ok print widget.name #widget name on windoze, None on linux def main (self): gtk.main() def main(): gui=GUI() gui.main() if __name__ =='__main__':main() I can provide more detailed sample code if required (including the xml from glade) -- Has everyone noticed that all the letters of the word "database" are typed with the left hand? Now the layout of the QWERTYUIOP typewriter keyboard was designed, among other things, to facilitate the even use of both hands. It follows, therefore, that writing about databases is not only unnatural, but a lot harder than it appears. From balle at chaostal.de Mon May 16 09:38:54 2011 From: balle at chaostal.de (Bastian Ballmann) Date: Mon, 16 May 2011 15:38:54 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> Message-ID: <20110516153854.28b7fe4f@chaostal.de> Hi, the project sounds like the exact tool that i need but regarding the user manual one has to mark the points on the graph manually. Therefore it's more work to get the data out than doing it without a tool. Or may I miss something here? Greets Basti Am Fri, 13 May 2011 14:38:45 -0500 schrieb Robert Kern : > On 5/13/11 7:24 AM, Bastian Ballmann wrote: > > Hi, > > > > Am Fri, 13 May 2011 14:01:48 +0200 > > schrieb Ulrich Eckhardt: > > > >> I'm not sure I understand 100% what you want. If you want to > >> extract ("parse") the data that is contained in an image file, I > >> have no clue how to do that. > > > > Yes, I want to extract the data that is contained in an image file. > > There is nothing in Python that solves this problem, per se, but > there are free and open source tools for this out there. E.g. > > http://digitizer.sourceforge.net/ > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From invalid at invalid.invalid Mon May 16 09:52:46 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 16 May 2011 13:52:46 +0000 (UTC) Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <877h9rguak.fsf@benfinney.id.au> Message-ID: On 2011-05-16, Ben Finney wrote: > "Littlefield, Tyler" writes: > >> I'm putting lots of work into this. I would rather not have some >> script kiddy dig through it, yank out chunks and do whatever he wants. >> I just want to distribute the program as-is, not distribute it and >> leave it open to being hacked. > > How do these arguments apply to your code base when they don't apply to, > say, LibreOffice or Linux or Python or Apache or Firefox? One obvious way that those arguments don't apply is that the OP didn't put lots of work into LibreOffice, Linux, Python, Apache or Firefox and therefore doesn't have any right to control their distribution. > How is your code base going to be harmed by having the source code > available to recipients, when that demonstrably doesn't harm > countless other code bases out there? The owner of something is free to determine how it is distributed -- he doesn't have any obligation to prove to you that some particular method of distribution is harmful to him or anybody else. -- Grant Edwards grant.b.edwards Yow! at BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI- gmail.com From jnr.gonzalez at googlemail.com Mon May 16 10:01:22 2011 From: jnr.gonzalez at googlemail.com (J) Date: Mon, 16 May 2011 07:01:22 -0700 (PDT) Subject: Convert AWK regex to Python References: Message-ID: Thanks for the sugestions Peter, I will give them a try Peter Otten wrote: > J wrote: > > > Hello Peter, Angelico, > > > > Ok lets see, My aim is to filter out several fields from a log file and > > write them to a new log file. The current log file, as I mentioned > > previously, has thousands of lines like this:- 2011-05-16 09:46:22,361 > > [Thread-4847133] PDU D > CC_SMS_SERVICE_51408_656-ServerThread- > VASPSessionThread-7ee35fb0-7e87-11e0-a2da-00238bce423b-TRX > > - 2011-05-16 09:46:22 - OUT - (submit_resp: (pdu: L: 53 ID: 80000004 > > Status: 0 SN: 25866) 98053090-7f90-11e0-a2da-00238bce423b (opt: ) ) > > > > > All the lines in the log file are similar and they all have the same > > length (same amount of fields). Most of the fields are separated by > > spaces except for couple of them which I am processing with AWK (removing > > " > evaluate each line in the log file and break them down into fields which I > > can call individually and write them to a new log file (for example > > selecting only fields 1, 2 and 3). > > > > I hope this is clearer now > > Not much :( > > It doesn't really matter whether there are 100, 1000, or a million lines in > the file; the important information is the structure of the file. You may be > able to get away with a quick and dirty script consisting of just a few > regular expressions, e. g. > > import re > > filename = ... > > def get_service(line): > return re.compile(r"[(](\w+)").search(line).group(1) > > def get_command(line): > return re.compile(r" > def get_status(line): > return re.compile(r"Status:\s+(\d+)").search(line).group(1) > > with open(filename) as infile: > for line in infile: > print get_service(line), get_command(line), get_status(line) > > but there is no guarantee that there isn't data in your file that breaks the > implied assumptions. Also, from the shell hackery it looks like your > ultimate goal seems to be a kind of frequency table which could be built > along these lines: > > freq = {} > with open(filename) as infile: > for line in infile: > service = get_service(line) > command = get_command(line) > status = get_status(line) > key = command, service, status > freq[key] = freq.get(key, 0) + 1 > > for key, occurences in sorted(freq.iteritems()): > print "Service: {}, Command: {}, Status: {}, Occurences: {}".format(*key > + (occurences,)) From giacomo.boffi at polimi.it Mon May 16 10:19:49 2011 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Mon, 16 May 2011 16:19:49 +0200 Subject: Convert AWK regex to Python References: Message-ID: <86iptabud6.fsf@aiuole.stru.polimi.it> J writes: > cat logs/pdu_log_fe.log | awk -F\- '{print $1,$NF}' | awk -F\. '{print $1,$NF}' | awk '{print $1,$4,$5}' | sort | uniq | while read service command status; do echo "Service: $service, Command: $command, Status: $status, Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | grep $status | wc -l | awk '{ print $1 }'`" >> logs/pdu_log_fe_clean.log; done > > This AWK command gets lines which look like this:- > > 2011-05-16 09:46:22,361 [Thread-4847133] PDU D > > And outputs lines like this:- > > CC_SMS_SERVICE_51408 submit_resp: 0 > i see some discrepancies in the description of your problem 1. if i echo a properly quoted line "like this" above in the pipeline formed by the first three awk commands i get $ echo $likethis | awk -F\- '{print $1,$NF}' \ | awk -F\. '{print$1,$NF}' \ | awk '{print $1,$4,$5}' 2011 ) ) $ not a triple 'service command status' 2. with regard to the final product, you script outputs lines like in echo "Service: $service, [...]" and you say that it produces lines like CC_SMS_SERVICE_51408 submit_resp: WHATEVER, the abnormous run time is due to the fact that for every output line you rescan again and again the whole log file IF i had understood what you want, imho you should run your data through sort and uniq -c $ awk -F\- '{print $1,$NF}' < $file \ | awk -F\. '{print$1,$NF}' \ | awk '{print $1,$4,$5}' | sort | uniq -c | format_program uniq -c drops repeated lines from a sorted input AND prepends to each line the count of equal lines in the original stream hth g From nobody at nowhere.net.no Mon May 16 10:23:07 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 16 May 2011 22:23:07 +0800 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: Thomas Rachel wrote: > Which loops do you mean here? list(set) has been proved to largely win against list = [] for item in set: list.append(item) or [list.append(item) for item in set] -- goto /dev/null From tyler at tysdomain.com Mon May 16 10:44:33 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 16 May 2011 08:44:33 -0600 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> <4DD0C127.80300@tysdomain.com> Message-ID: <4DD13851.7040406@tysdomain.com> >Funny you should mention this "now" I don't go around parading the info, until I have to. >Yes I agree Flash is not very accessible (never has been). >Web Standards web apps and such however are quite >accessible! If I was making a browser-based game, yes. As I'm not though... Anyway, thanks to everyone else who answered this thread. I've not done much like this besides muds, and all the logic is on the server there, I think I will build the client in python, open source it for people to fix/add to if they want and make sure to keep the server as secure as it can be. From python.list at tim.thechases.com Mon May 16 10:54:21 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 May 2011 09:54:21 -0500 Subject: obviscating python code for distribution In-Reply-To: <87boz3gw5u.fsf@benfinney.id.au> References: <87boz3gw5u.fsf@benfinney.id.au> Message-ID: <4DD13A9D.1080906@tim.thechases.com> On 05/15/2011 10:29 PM, Ben Finney wrote: > What is it you think you would gain by obfuscating the code, > and why is that worthwhile? What evidence do you have that > code obfuscation would achieve that? Based on past experience at several employers', the preeminent reason for obfuscating is to make it hard for people to see the absolutely atrocious coding that takes place behind closed doors. Having seen behind the curtain, every time I hear the buzzword(s) "enterprise software", I now equate that with "shovelware pushed out the door driven by a marketing agenda rather than customer needs; held together by baling wire and string; lacking test-suites, UI testing, or attention to failure conditions; random hit-or-miss deployment processes; usually a lack of decent revision control; etc". -tkc From matthewberends at gmail.com Mon May 16 11:02:42 2011 From: matthewberends at gmail.com (Matt Berends) Date: Mon, 16 May 2011 08:02:42 -0700 (PDT) Subject: Convert AWK regex to Python References: <86iptabud6.fsf@aiuole.stru.polimi.it> Message-ID: <69be0110-1992-46b2-bafb-ec3204663bbc@x10g2000yqj.googlegroups.com> This doesn't directly bear upon the posted example, but I found the following tutorial extremely helpful for learning how to parse log files with idiomatic python. Maybe you'll might find it useful, too. http://www.dabeaz.com/generators/ http://www.dabeaz.com/generators/Generators.pdf From ian.g.kelly at gmail.com Mon May 16 11:37:44 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 16 May 2011 09:37:44 -0600 Subject: obviscating python code for distribution In-Reply-To: <4DD0C16B.4010500@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> <4DD0C16B.4010500@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 12:17 AM, Littlefield, Tyler wrote: >>Write your "game" for the "web". >>Write is as a SaaS (Software as a Service) - even if it's free and open >> source. > I understood you loud and clear. And that makes a lot of assumptions on my > game and the design. I don't really care to host this over the web. I want a > centralized server that would perform the logic, where I can offload the > playing of sounds (through a soundpack that's already installed) to the > client-side. > Not only that, but a lot of web technologies that would be used for this > wouldn't really work, as I am doing this for the blind; Flash as well as a > lot > of the popular setups are not very accessible. Probably the best thing you can do is just to treat your client as untrusted. That means: 1) Avoid sending it any data that you would not want the user to have. If they want it, they'll find a way to get it. 2) Don't rely on the client to restrict the user. If they're not supposed to be able to send a command 10 times a second, that should be enforced by the server. If the client has no useful data beyond what is normally presented to the user, and if every input that the server will accept can be done with the vanilla client, then there is no way to cheat, and the only reason remaining to hack up the client that could be detrimental to gameplay is for botting. For that, I'm afraid you'll just have to employ detection algorithms and enforce a strict no-botting policy. Cheers, Ian From trisha4u4u at gmail.com Mon May 16 11:41:01 2011 From: trisha4u4u at gmail.com (Elisha trisha4uuu.blogspot.com) Date: Mon, 16 May 2011 08:41:01 -0700 (PDT) Subject: KAJAL old pictures Message-ID: <93150c74-69bf-4836-b659-10c256145487@x38g2000pri.googlegroups.com> she is good and most poplar actress she is looking very cute and milky white and big eyes and good looking she always smiley face she act wit top and young hero's Ramcharan teja, JR.Ntr, Ram,Prabas,Kalyanram,Allu Arjun, and also top tamil hero's her more pictures wallpapers photos for you watch and enjoy http://trisha4uuu.blogspot.com/2011/05/kajal-hot-old-wallpapers.html From robert.kern at gmail.com Mon May 16 11:44:57 2011 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 16 May 2011 10:44:57 -0500 Subject: Parsing a graph image In-Reply-To: <20110516153854.28b7fe4f@chaostal.de> References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> <20110516153854.28b7fe4f@chaostal.de> Message-ID: On 5/16/11 8:38 AM, Bastian Ballmann wrote: > Hi, > > the project sounds like the exact tool that i need but regarding the > user manual one has to mark the points on the graph manually. Therefore > it's more work to get the data out than doing it without a tool. Or may > I miss something here? You are probably looking at the tutorials for manually digitizing graphs. Check out this one: http://digitizer.sourceforge.net/usermanual/tutorautolinegraph.html -- 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 affdfsdfdsfsd at b.com Mon May 16 12:25:00 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 16 May 2011 16:25:00 GMT Subject: regular expression i'm going crazy Message-ID: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> pls help me fixing this: import re s = "linka la baba" re_s = re.compile(r'(link|l)a' , re.IGNORECASE) print re_s.findall(s) output: ['link', 'l'] why? i want my re_s to find linka and la, he just find link and l and forget about the ending a. can anyone help me? trying the regular expression in redemo.py (program provided with python to explore the use of regular expression) i get what i want, so i guess re_s is ok, but it still fail... why? help! Nico From python at mrabarnett.plus.com Mon May 16 12:39:11 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 May 2011 17:39:11 +0100 Subject: Convert AWK regex to Python In-Reply-To: References: Message-ID: <4DD1532F.1090204@mrabarnett.plus.com> On 16/05/2011 09:19, J wrote: [snip] > #!/usr/bin/python > > # Import RegEx module > import re as regex > # Log file to work on > filetoread = open('/tmp/ pdu_log.log', "r") > # File to write output to > filetowrite = file('/tmp/ pdu_log_clean.log', "w") > # Perform filtering in the log file > linetoread = filetoread.readlines() > for line in linetoread: > filter0 = regex.sub(r" filter1 = regex.sub(r"\."," ",filter0) > # Write new log file > filetowrite.write(filter1) > filetowrite.close() > # Read new log and get required fields from it > filtered_log = open('/tmp/ pdu_log_clean.log', "r") > filtered_line = filtered_log.readlines() > for line in filtered_line: > token = line.split(" ") > print token[0], token[1], token[5], token[13], token[20] > print "Done" > [snip] If you don't need the power of regex, it's faster to use string methods: filter0 = line.replace(" References: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> Message-ID: On 5/16/11 11:25 AM, Tracubik wrote: > pls help me fixing this: > > import re > s = "linka la baba" > re_s = re.compile(r'(link|l)a' , re.IGNORECASE) > > print re_s.findall(s) > > output: > ['link', 'l'] > > why? > i want my re_s to find linka and la, he just find link and l and forget > about the ending a. > > can anyone help me? trying the regular expression in redemo.py (program > provided with python to explore the use of regular expression) i get what > i want, so i guess re_s is ok, but it still fail... > why? The parentheses () create a capturing group, which specifies that the contents of the group should be extracted. See the "(...)" entry here: http://docs.python.org/library/re#regular-expression-syntax You can use the non-capturing version of parentheses if you want to just isolate the | from affecting the rest of the regex: """ (?:...) A non-capturing version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern. """ [~] |1> import re [~] |2> s = "linka la baba" [~] |3> re_s = re.compile(r'(?:link|l)a' , re.IGNORECASE) [~] |4> print re_s.findall(s) ['linka', 'la'] -- 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 alex.kapps at web.de Mon May 16 13:01:35 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Mon, 16 May 2011 19:01:35 +0200 Subject: regular expression i'm going crazy In-Reply-To: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> References: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> Message-ID: <4DD1586F.4070308@web.de> On 16.05.2011 18:25, Tracubik wrote: > pls help me fixing this: > > import re > s = "linka la baba" > re_s = re.compile(r'(link|l)a' , re.IGNORECASE) > > print re_s.findall(s) > > output: > ['link', 'l'] > > why? As the docs say: "If one or more groups are present in the pattern, return a list of groups;" http://docs.python.org/library/re.html?highlight=findall#re.findall > i want my re_s to find linka and la, he just find link and l and forget > about the ending a. Try with non-grouping parentheses: re_s = re.compile(r'(?:link|l)a' , re.IGNORECASE) From andy at earthsong.free-online.co.uk Mon May 16 13:11:01 2011 From: andy at earthsong.free-online.co.uk (andy baxter) Date: Mon, 16 May 2011 18:11:01 +0100 Subject: regular expression i'm going crazy In-Reply-To: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> References: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> Message-ID: <4DD15AA5.3090509@earthsong.free-online.co.uk> On 16/05/11 17:25, Tracubik wrote: > pls help me fixing this: > > import re > s = "linka la baba" > re_s = re.compile(r'(link|l)a' , re.IGNORECASE) > > print re_s.findall(s) > > output: > ['link', 'l'] > > why? > i want my re_s to find linka and la, he just find link and l and forget > about the ending a. The round brackets define a 'capturing group'. I.e. when you do findall it returns those elements in the string that match what's inside the brackets. If you want to get linka and la, you need something like this: >>> re_s = re.compile(r'((link|l)a)' , re.IGNORECASE) >>> print re_s.findall(s) [('linka', 'link'), ('la', 'l')] Then just look at the first element in each of the tuples in the array (which matches the outside set of brackets). see: http://www.regular-expressions.info/python.html From goldtech at worldpost.com Mon May 16 13:11:43 2011 From: goldtech at worldpost.com (goldtech) Date: Mon, 16 May 2011 10:11:43 -0700 (PDT) Subject: Image processing to auto adjust colors in python ? Message-ID: <4bb21cd6-6ece-4341-8231-18818e942ab3@y19g2000yqk.googlegroups.com> Hi, I'm processing thumbnails with python but one thing I need to do is to auto-adjust an image for the "best" colors. I am using ffmpeg to get thumbs three seconds into a video, sometimes the image is too dark. Normally I'd go into something like the windows program Irfan View and do "Auto Adjust Colors", but I need a comand-line solution to processes hundreds of images in a loop. I'm using Ubuntu and Python. Is there an image precessing package i could use to do this? thanks, Lee G. From nobody at nowhere.com Mon May 16 14:02:08 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 16 May 2011 19:02:08 +0100 Subject: Image processing to auto adjust colors in python ? References: <4bb21cd6-6ece-4341-8231-18818e942ab3@y19g2000yqk.googlegroups.com> Message-ID: On Mon, 16 May 2011 10:11:43 -0700, goldtech wrote: > I'm processing thumbnails with python but one thing I need to do is to > auto-adjust an image for the "best" colors. I am using ffmpeg to get > thumbs three seconds into a video, sometimes the image is too dark. > Normally I'd go into something like the windows program Irfan View and > do "Auto Adjust Colors", but I need a comand-line solution to > processes hundreds of images in a loop. I'm using Ubuntu and Python. > Is there an image precessing package i could use to do this? PIL (Python Imaging Library) is the most widely-used general-purpose image library. For more advanced tasks, the usual solution is to use PIL to load/save images and do the processing with NumPy/SciPy (array-processing library). But you might want to check whether either ImageMagick (e.g. "convert -equalize ...") or NetPBM (e.g. pnmhisteq) do what you want. If they do, it will probably be the simplest solution. From saeedullah at gmail.com Mon May 16 14:59:44 2011 From: saeedullah at gmail.com (saeed) Date: Mon, 16 May 2011 11:59:44 -0700 (PDT) Subject: Call for Papers (CFP) Message-ID: ========================================================= Journal of Emerging Trends in Computing and Information Sciences Call for Research Papers (Vol. 2 No. 6) June 2011 http://cisjournal.org/ ========================================================= Dear Sir/ Madam, Journal of Emerging Trends in Computing and Information Sciences (E- ISSN 2218-6301/ ISSN 2079-8407) is an international refereed research publishing journal, focused on promoting and publishing original high quality research work in both theoretical and scientific aspects of all disciplines of Computing and Information Sciences. The objectives of the journal are to promote and publish original high quality research and to provide a forum to the researchers and industry practitioners for exchanging ideas, knowledge, and experience. We welcome original research and industry experience papers. Contributions should be written for one of the following categories: Original research Literature Review / Systematic Literature Review Short Articles on ongoing research Preliminary Findings Technical Reports / Notes Results previously published in conferences and/or journals may be submitted as extended versions. For more information about Journal and Publication Charges, please visit http://www.cisjournal.org/. You are requested to circulate this message among your colleagues and college/university fellows. Sincerely Yours, Editor Journal of Emerging Trends in Computing and Information Sciences URL: http://www.cisjournal.org E-mail:editor at cisjournal.org From harrismh777 at charter.net Mon May 16 15:40:39 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 16 May 2011 14:40:39 -0500 Subject: obviscating python code for distribution In-Reply-To: <4dd0e507$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4dd0e507$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > To put it in a > nutshell, you can't trust*anything*. See the classic paper by Ken > Thompson, "Reflections on Trusting Trust": > This is true, but there's another way to put it pro-active--- ... expect the client to be untrustworthy. In other words, write the server code with a protocol that 'expects' the client to be hacked. Yes, it takes three times the code and at least five times the work, but its worth it. What do you do with syn floods? What do you do with attempted overruns? What if someone builds a client emulator, just to hammer your protocol and slow the server down, just for fun...? You must build your server side 'assuming' that *all* of these things are going to happen (and more), and then be able to handle them when they do. That is what makes server-side coding so difficult. In other words, you build the server in such a way that you can confidently hand Mr junior cracker your client source code and be confident that your gaming server is going to be a.o.k. Many, many, coders don't want to go to all this trouble (and don't)... mainly because they're just glad if they can get simple sockets to work. So, they don't handle attempted overruns, or syn flood open attempts, or other. One thing to remember (think about this) is whether your server/client is in a push or pull mode. *Never* allow the client to be in control (pushing) while your server is passively (pulling). The server must control everything so that the untrusted client will be *controlled* regardless of client side hacks. I realize that this probably means redesign of your server. Do it. Happy gaming! m harris From harrismh777 at charter.net Mon May 16 15:56:38 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 16 May 2011 14:56:38 -0500 Subject: problem with GKT module? In-Reply-To: References: Message-ID: alister ware wrote: > def callback(self,widget,data=None): > print widget #gives reference to radio button ok > print widget.name #widget name on windoze, None on linux Well, you're obviously using Python 2.x ... ... have you tried this in Python 3.x ? Neither here nor there... you need to know who/what is generating 'widget'. Is widget buried in gtk where you can't see how it works, or is widget a Python class (or wrapper) where you can see what its doing? The fact that widget.name returns None on the linux platform tells me that widget is a Python class (or wrapper) ... so you probably have a widget.py file somewhere... or some other module that widget is a class definition in... who knows... (at this point). It seems to me that the 'builder' is behaving differently on the two platforms (rather than Python is behaving differently on the two platforms). What happens if you change the data=None pair? What happens if you omit data=None pair? Do you see this difference with *all* widgets, or just radio buttons? kind regards, m harris From as at sci.fi Mon May 16 15:57:29 2011 From: as at sci.fi (Anssi Saari) Date: Mon, 16 May 2011 22:57:29 +0300 Subject: Get the IP address of WIFI interface References: Message-ID: Neal Becker writes: > Here's some useful snippits for linux: > > def get_default_if(): > f = open('/proc/net/route') > for i in csv.DictReader(f, delimiter="\t"): > if long(i['Destination'], 16) == 0: > return i['Iface'] > return None > > def get_ip_address(ifname): > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > return socket.inet_ntoa(fcntl.ioctl( > s.fileno(), > 0x8915, # SIOCGIFADDR > struct.pack('256s', ifname[:15]) > )[20:24]) One possible solution in Linux is asking NetworkManager, if it's in use. It knows which interfaces are active and what kind they are (LAN, WLAN, WWAN etc.) NetworkManager communicates via dbus and even includes python example scripts. So here's my scriptlet based on NetworkManager example nm-state.py. This one prints out all active devices and their type and IP address. Easily modified to print only WLAN types. import dbus, socket, struct bus = dbus.SystemBus() proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager") manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager") # Get device-specific state devices = manager.GetDevices() for d in devices: dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d) prop_iface = dbus.Interface(dev_proxy, "org.freedesktop.DBus.Properties") # Get the device's current state and interface name state = prop_iface.Get("org.freedesktop.NetworkManager.Device", "State") name = prop_iface.Get("org.freedesktop.NetworkManager.Device", "Interface") ifa = "org.freedesktop.NetworkManager.Device" type = prop_iface.Get(ifa, "DeviceType") addr = prop_iface.Get(ifa, "Ip4Address") # and print them out if state == 8: # activated addr_dotted = socket.inet_ntoa(struct.pack(' Message-ID: Alister Ware writes: > On Fri, 13 May 2011 13:13:00 +0000, alister ware wrote: > >> I am using gtk.builder with a glade generated GUI >> >> I have a simple call back defined for a radio button widget when I use >> widget.name in linux I get a value of None, windows returns the widget >> name as I would expect. >> >> is this a bug? >> if not how should i find the name of the widget that has triggered a >> call back? >> >> (I would like all my radio buttons to go to the same callback routine if >> possible to make code maintenance easier) >> > So nobody has any Ideas on this at all? You may want to post runnable code demonstrating your problem. From garyr at fidalgo.net Mon May 16 17:23:33 2011 From: garyr at fidalgo.net (garyr) Date: Mon, 16 May 2011 14:23:33 -0700 Subject: Deleting a file? Message-ID: A file can be deleted by opening it with mode os.O_TEMPORARY and then closing it. How can a file be moved to the Recycle Bin, a la Windows? From drsalists at gmail.com Mon May 16 18:37:20 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 16 May 2011 15:37:20 -0700 Subject: Memcached in python 3 In-Reply-To: References: Message-ID: Do you need something shared across multiple hosts? Across multiple CPU's of the same host? Or single process? By "Python Dictionary Manager", do you mean the manager stuff in the multiprocessing module? On Sun, May 15, 2011 at 9:52 PM, Navkirat Singh wrote: > Hi Guys, > > How can I used memcached with python 3? Are there any other good > alternatives to memcached? What about python dictionary manager, would it > compare to memcached if I were to use it for storing in-memory information? > > Any light on this matter will be appreciated. > > Regards, > Navkirat > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Mon May 16 18:42:40 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 16 May 2011 23:42:40 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> Message-ID: On Mon, 16 May 2011 03:21:00 +0100, Daniel Kluev wrote: > On Mon, May 16, 2011 at 1:04 PM, Littlefield, Tyler > wrote: >> Hello all: >> Finally, is there a good way to accomplish this? I know that I can make >> .pyc >> files, but those can be disassembled very very easily with the >> disassembler >> and shipping these still means that the person needs the modules that >> are >> used. Is there another way to go about this? > > No, there is no way to prevent users from getting access to raw python > sources. By its nature and design, python is not meant to be used this > way, and even obfuscation would not harm readability much. > However, you can write all parts you want to hide in C/C++/Cython and > distribute them as .so/.dll ...which is, of course, not exactly secure either. A sufficiently determined hacker won't have much trouble disassembling a shared library even if you do strip out all the debug information. By chance I'm having to do something closely related to this at work just at the moment; it's hard, but far from impossible. -- Rhodri James *-* Wildebeest Herder to the Masses From luke.leighton at gmail.com Mon May 16 19:32:12 2011 From: luke.leighton at gmail.com (Luke Kenneth Casson Leighton) Date: Tue, 17 May 2011 00:32:12 +0100 Subject: pythonwebkit-gtk, pythonwebkit-dfb Message-ID: in preparation for a 0.8 release of pyjamas, a bit of work has been done on pythonwebkit (http://www.gnu.org/software/pythonwebkit) that makes it easier to compile and install. pythonwebkit provides full and complete (see caveats below!) bindings to web browser functionality... in python. what you would normally expect to be able to do in javascript "in-browser", you can do EXACTLY the same thing, in a "declarative" programming style, in python: import gtk import pywebkitgtk url = "http://www.gnu.org/software/pythonwebkit" wv = pywebkitgtk.WebView(1024,768, url=url) def _doc_loaded(*args): doc = wv.GetDomDocument() txt = doc.createTextNode("hello") doc.body.appendChild(txt) wv.SetDocumentLoadedCallback(_doc_loaded) gtk.main() yes, that's really python, doing a createTextNode and an appendChild, *not* javascript. not interpreted javascript, not interpreted python, *real* python, byte-coded and everything. throw in some AJAX, some browser event callbacks (onclick etc.) and some web browser timer callbacks and it all starts to get a bit weird, as two or maybe three disparate programming worlds that should never really have been brought together suddenly.. um... well, are brought together. the bit that's easier about installing pythonwebkit is that it is no longer necessary to download and patch up the http://code.google.com/p/pywebkitgtk project in order to use pythonwebkit. you can simply do "./autogen.sh" followed by the usual "make" and "make install". a new and absolute minimalist python module is created and installed which will get you a blank window - just like if you were firing up a python-GTK application or a python-QT4 application. anyway - just a bit of an informal not-really-announcement because, well, it's a side-dependency to the pyjamas project, even if it is a whopping 20mb one. those caveats btw are that a) you can't set CSS properties as if they were python object properties: you have to use the method "setProperty", duh, and b) there are *no* 2D or 3D SVG Canvas objects or functions available, yet, because it would take a good full-time 7 to 10 days to smack the codegenerator into shape and i'm waiting for someone to step forward and fund that work. am still servicing ?20,000 in debt and still have to find a way to pay back a complete stranger who incredibly kindly paid ?4,000 in owed rent so that we did not end up with a County Court Judgement against us. myself, my partner and our 25 month old daughter still got evicted, but that's another story. against this kind of background, perhaps i might be forgiven for not doing "freebie" free software development, i trust. l. From hujun.work at gmail.com Mon May 16 19:44:27 2011 From: hujun.work at gmail.com (Jun Hu) Date: Mon, 16 May 2011 16:44:27 -0700 Subject: Get the IP address of WIFI interface In-Reply-To: References: Message-ID: Thanks, this code works perfectly in ubuntu 10.04. one question though, is dbus usually implemented in other distribution of linux? On Mon, May 16, 2011 at 12:57 PM, Anssi Saari wrote: > Neal Becker writes: > > One possible solution in Linux is asking NetworkManager, if it's in > use. It knows which interfaces are active and what kind they are (LAN, > WLAN, WWAN etc.) NetworkManager communicates via dbus and even > includes python example scripts. So here's my scriptlet based on > NetworkManager example nm-state.py. This one prints out all active > devices and their type and IP address. Easily modified to print only > WLAN types. > > import dbus, socket, struct > > bus = dbus.SystemBus() > > proxy = bus.get_object("org.freedesktop.NetworkManager", > "/org/freedesktop/NetworkManager") > manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager") > > # Get device-specific state > devices = manager.GetDevices() > for d in devices: > dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d) > prop_iface = dbus.Interface(dev_proxy, > "org.freedesktop.DBus.Properties") > > # Get the device's current state and interface name > state = prop_iface.Get("org.freedesktop.NetworkManager.Device", "State") > name = prop_iface.Get("org.freedesktop.NetworkManager.Device", > "Interface") > ifa = "org.freedesktop.NetworkManager.Device" > type = prop_iface.Get(ifa, "DeviceType") > addr = prop_iface.Get(ifa, "Ip4Address") > > # and print them out > if state == 8: # activated > addr_dotted = socket.inet_ntoa(struct.pack(' > s = "Device %s is activated and has type %s and address %s" > print s % (name, type, addr_dotted) > else: > print "Device %s is not activated" % name > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon May 16 20:22:48 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 10:22:48 +1000 Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: <8739kegopz.fsf@benfinney.id.au> "Littlefield, Tyler" writes: > I wanted to make the client in python, and the server possibly, though > I'm not really sure on that. I was not worried about the code for the > server being stolen, as much as I was worried about people tinkering > with the client code for added advantages. Thank you for making your constraints explicit; that's more than most people do when asked. As Steven said, you're trying to solve a problem which is very difficult, and obfuscating the code won't be of much help. If people have the program running on their own computers, they can hack it. You can't stop that, so you have to consider other ways of making it ineffective. -- \ ?The fact that a believer is happier than a skeptic is no more | `\ to the point than the fact that a drunken man is happier than a | _o__) sober one.? ?George Bernard Shaw | Ben Finney From ben+python at benfinney.id.au Mon May 16 20:27:48 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 10:27:48 +1000 Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <877h9rguak.fsf@benfinney.id.au> Message-ID: <87y626f9x7.fsf@benfinney.id.au> Grant Edwards writes: > On 2011-05-16, Ben Finney wrote: > > "Littlefield, Tyler" writes: > > > >> I'm putting lots of work into this. I would rather not have some > >> script kiddy dig through it, yank out chunks and do whatever he > >> wants. I just want to distribute the program as-is, not distribute > >> it and leave it open to being hacked. > > > > How do these arguments apply to your code base when they don't apply > > to, say, LibreOffice or Linux or Python or Apache or Firefox? > > One obvious way that those arguments don't apply is that the OP didn't > put lots of work into LibreOffice, Linux, Python, Apache or Firefox Yet the copyright holders *did* put lots of effort into those works respectively. So the arguments would apply equally well; which is to say, they don't. > > How is your code base going to be harmed by having the source code > > available to recipients, when that demonstrably doesn't harm > > countless other code bases out there? > > The owner of something is free to determine how it is distributed -- > he doesn't have any obligation to prove to you that some particular > method of distribution is harmful to him or anybody else. Note that I didn't say anything about obligation or harm to persons. I asked only about the code base and the distribution thereof. In the meantime, Tyler has come back to us with arguments that *do* differentiate between the above cases and his own. So thanks, Tyler, for answering the questions. -- \ ?Of course, everybody says they're for peace. Hitler was for | `\ peace. Everybody is for peace. The question is: what kind of | _o__) peace?? ?Noam Chomsky, 1984-05-14 | Ben Finney From ben+python at benfinney.id.au Mon May 16 20:30:22 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 10:30:22 +1000 Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> <4DD0C127.80300@tysdomain.com> Message-ID: <87r57yf9sx.fsf@benfinney.id.au> "Littlefield, Tyler" writes: > Anyway, thanks to everyone else who answered this thread. I've not > done much like this besides muds, and all the logic is on the server > there, I think I will build the client in python, open source it for > people to fix/add to if they want and make sure to keep the server as > secure as it can be. Sounds like a good approach to me that doesn't treat users as necessarily hostile. I wish you good fortune in building a strong community around the game so that it can defend itself from cheaters, and a free-software client will IMO promote exactly that. -- \ ?I do not believe in immortality of the individual, and I | `\ consider ethics to be an exclusively human concern with no | _o__) superhuman authority behind it.? ?Albert Einstein, letter, 1953 | Ben Finney From ben+python at benfinney.id.au Mon May 16 20:33:16 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 10:33:16 +1000 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: <87mximf9o3.fsf@benfinney.id.au> TheSaint writes: > Thomas Rachel wrote: > > > Which loops do you mean here? > > list(set) has been proved to largely win against > list = [] > for item in set: > list.append(item) > or [list.append(item) for item in set] Remember that the criterion of speed is a matter of the implementation, and what's fast on one won't necessarily be fast on others. Which implementations did you try? Where I do agree is that ?list(foo)? wins over the other examples you show on the important criteria of concision and readability. -- \ ?A thing moderately good is not so good as it ought to be. | `\ Moderation in temper is always a virtue; but moderation in | _o__) principle is always a vice.? ?Thomas Paine | Ben Finney From bahamutzero8825 at gmail.com Mon May 16 21:05:25 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 16 May 2011 20:05:25 -0500 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD0D1A2.6060109@free.fr> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> Message-ID: <4DD1C9D5.4070206@gmail.com> On 2011.05.16 02:26 AM, Karim wrote: > Use regular expression for bad HTLM or beautifulSoup (google it), below > a exemple to extract all html links: > > linksList = re.findall('.*?',htmlSource) > for link in linksList: > print link I was afraid I might have to use regexes (mostly because I could never understand them). Even the BeautifulSoup website itself admits it's awful with Python 3 - only the admittedly broken 3.1.0 will work with Python 3 at all. ElementTree doesn't seem to have been updated in a long time, so I'll assume it won't work with Python 3. lxml looks promising, but it doesn't say anywhere whether it'll work on Python 3 or not, which is puzzling since the latest release was only a couple months ago. Actually, if I'm going to use regex, I might as well try to implement Versions* in Python. Thanks for the answers! *http://en.totalcmd.pl/download/wfx/net/Versions (original, made for Total Commander) and https://addons.mozilla.org/en-US/firefox/addon/versions-wfx_versions/ (clone implemented as a Firefox add-on; it's so wonderful, I even wrote the docs for it!) From nospam at torek.net Mon May 16 21:07:41 2011 From: nospam at torek.net (Chris Torek) Date: 17 May 2011 01:07:41 GMT Subject: Converting a set into list References: <871v00j2bh.fsf@benfinney.id.au> Message-ID: >Chris Torek wrote: >> >>> x = [3, 1, 4, 1, 5, 9, 2, 6] >> >>> list(set(x)) >> This might not be the best example since the result is sorted >> "by accident", while other list(set(...)) results are not. In article , Duncan Booth wrote: >A minor change to your example makes it out of order even for integers: > >>>> x = [7, 8, 9, 1, 4, 1] >>>> list(set(x)) >[8, 9, 1, 4, 7] > >or for that mattter: > >>>> list(set([3, 32, 4, 32, 5, 9, 2, 6])) >[32, 2, 3, 4, 5, 6, 9] Yes, but then it is no longer "as easy as pi". :-) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From ben+python at benfinney.id.au Mon May 16 21:39:37 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 11:39:37 +1000 Subject: Deleting a file? References: Message-ID: <878vu6f6li.fsf@benfinney.id.au> "garyr" writes: > A file can be deleted by opening it with mode os.O_TEMPORARY and then > closing it. Much simpler: ?os.remove(path)?. > How can a file be moved to the Recycle Bin, a la Windows? That's not deleting it (as you probably know), so you might better change the subject field for the thread. -- \ ?Unix is an operating system, OS/2 is half an operating system, | `\ Windows is a shell, and DOS is a boot partition virus.? ?Peter | _o__) H. Coffin | Ben Finney From malaclypse2 at gmail.com Mon May 16 23:06:44 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 16 May 2011 23:06:44 -0400 Subject: Deleting a file? In-Reply-To: References: Message-ID: On Mon, May 16, 2011 at 5:23 PM, garyr wrote: > A file can be deleted by opening it with mode os.O_TEMPORARY and then > closing it. How can a file be moved to the Recycle Bin, a la Windows? I see a send2trash module (http://hg.hardcoded.net/send2trash and http://www.hardcoded.net/articles/send-files-to-trash-on-all-platforms.htm) The source code looks pretty straightforward, but I don't think there's anything in the standard library that does that. -- Jerry From wuwei23 at gmail.com Mon May 16 23:45:55 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 16 May 2011 20:45:55 -0700 (PDT) Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> <4DD0C127.80300@tysdomain.com> Message-ID: <15eb7b39-fea0-4f9c-8673-2b13c17705c5@34g2000pru.googlegroups.com> "Littlefield, Tyler" wrote: > Anyway, thanks to everyone else who answered this thread. I've not done > much like this besides muds, and all the logic is on the server there, I > think I will build the client in python, open source it for people to > fix/add to if they want and make sure to keep the server as secure as it > can be. The browser-based game Lacuna Expanse actually open sources the Perl client for their game, it might be a good place for ideas on how to approach this: https://github.com/plainblack/Lacuna-Web-Client The MMO EVE uses Stackless Python for both the client & server. Here's a slightly older doc detailing their architecture: http://www.slideshare.net/Arbow/stackless-python-in-eve Hope this helps. From n4vpython at gmail.com Tue May 17 00:36:34 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Tue, 17 May 2011 10:06:34 +0530 Subject: Memcached in python 3 In-Reply-To: References: Message-ID: On Tue, May 17, 2011 at 4:07 AM, Dan Stromberg wrote: > > Do you need something shared across multiple hosts? Across multiple CPU's > of the same host? Or single process? > > By "Python Dictionary Manager", do you mean the manager stuff in the > multiprocessing module? > > On Sun, May 15, 2011 at 9:52 PM, Navkirat Singh wrote: > >> Hi Guys, >> >> How can I used memcached with python 3? Are there any other good >> alternatives to memcached? What about python dictionary manager, would it >> compare to memcached if I were to use it for storing in-memory information? >> >> Any light on this matter will be appreciated. >> >> Regards, >> Navkirat >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > Hi, I need something that can be scalable. Something that if needed, can scale to multiple hosts. Yes, I mean the manager stuff in the multiprocessing module. Regards, Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From n4vpython at gmail.com Tue May 17 00:48:52 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Tue, 17 May 2011 10:18:52 +0530 Subject: Python 3 vs Python 2.7 dilemma Message-ID: Hi Guys, I have been trying to fight this issue for sometime now. I know that a large part of the python 3rd party software base has not been ported to python 3 yet. I am trying to build a web-based enterprise solution for my client. Most of reputed frameworks like Django and Turbo gears are yet in the 2.x stage. I know that these frameworks are extremely good. But I wanted to build my base with python 3 as that is what is going to prevail in the future. I have built my own little architecture using python3. Here is what I have accomplished till now: a) A multiprocessing webserver built directly using low level sockets for maximum control, conforming to RFC 2616 (not completely right now). b) A HTTP message parser for parsing HTTP/1.1 requests and generating response messages c) A session control base using python multiprocessing dictionary manager d) A partially build MVC model, without a templating engine at the moment. I am planning to put Jinja 3 there. I have spent months of free time doing this. I have learnt a lot, but well I am not sure if the path I am on is the right one. My question to everyone is whether I should go ahead with this approach, or should I just use 2.x technology? I am not sure if I will be able to port all the code to python3 later. I will really appreciate any input. Thanks and regards, Navkirat -------------- next part -------------- An HTML attachment was scrubbed... URL: From highfellow at gmail.com Tue May 17 01:13:21 2011 From: highfellow at gmail.com (Andy Baxter) Date: Tue, 17 May 2011 06:13:21 +0100 Subject: indirect assignment question Message-ID: <4DD203F1.1000202@gmail.com> Hi, I have some lines of code which currently look like this: self.window = self.wTree.get_widget("mainWindow") self.outputToggleMenu = self.wTree.get_widget("menuitem_output_on") self.outputToggleButton = self.wTree.get_widget("button_toggle_output") self.logView = self.wTree.get_widget("textview_log") self.logScrollWindow = self.wTree.get_widget("scrolledwindow_log") and I would like (for tidiness / compactness's sake) to replace them with something like this: widgetDic = { "mainWindow": self.window, "menuitem_output_on": self.outputToggleMenu, "button_toggle_output": self.outputToggleButton, "textview_log": self.logView, "scrolledwindow_log": self.logScrollWindow } for key in widgetDic: ... set the variable in dic[key] to point to self.wTree.get_widget(key) somehow what I need is some kind of indirect assignment where I can assign to a variable whose name is referenced in a dictionary value. Is there a way of doing this in python? thanks, andy baxter -- http://highfellow.org From clp2 at rebertia.com Tue May 17 01:24:34 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 May 2011 22:24:34 -0700 Subject: indirect assignment question In-Reply-To: <4DD203F1.1000202@gmail.com> References: <4DD203F1.1000202@gmail.com> Message-ID: On Mon, May 16, 2011 at 10:13 PM, Andy Baxter wrote: > Hi, > > I have some lines of code which currently look like this: > > ? ? ?self.window = self.wTree.get_widget("mainWindow") > ? ? ?self.outputToggleMenu = self.wTree.get_widget("menuitem_output_on") > ? ? ?self.outputToggleButton = self.wTree.get_widget("button_toggle_output") > ? ? ?self.logView = self.wTree.get_widget("textview_log") > ? ? ?self.logScrollWindow = self.wTree.get_widget("scrolledwindow_log") > > and I would like (for tidiness / compactness's sake) to replace them with > something like this: > ? ? ? ?widgetDic = { > ? ? ? ? ? "mainWindow": self.window, > ? ? ? ? ? "menuitem_output_on": self.outputToggleMenu, > ? ? ? ? ? "button_toggle_output": self.outputToggleButton, > ? ? ? ? ? "textview_log": self.logView, > ? ? ? ? ? "scrolledwindow_log": self.logScrollWindow > ? ? ? ?} > ? ? ? ?for key in widgetDic: > ? ? ? ? ? ... set the variable in dic[key] to point to > self.wTree.get_widget(key) somehow > > what I need is some kind of indirect assignment where I can assign to a > variable whose name is referenced in a dictionary value. > > Is there a way of doing this in python? You can achieve almost the same level of brevity, with less use of magic, by simply using a local variable to refer to self.wTree.get_widget: w = self.wTree.get_widget # or choose some other similarly short variable name self.window = w("mainWindow") self.outputToggleMenu = w("menuitem_output_on") self.outputToggleButton = w("button_toggle_output") self.logView = w("textview_log") self.logScrollWindow = w("scrolledwindow_log") Python functions/methods are first-class; exploit this feature! Cheers, Chris -- http://rebertia.com From ben+python at benfinney.id.au Tue May 17 02:01:25 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 16:01:25 +1000 Subject: indirect assignment question References: Message-ID: <87y625euh6.fsf@benfinney.id.au> Andy Baxter writes: > with something like this: > widgetDic = { > "mainWindow": self.window, > "menuitem_output_on": self.outputToggleMenu, > "button_toggle_output": self.outputToggleButton, > "textview_log": self.logView, > "scrolledwindow_log": self.logScrollWindow > } > for key in widgetDic: > ... set the variable in dic[key] to point to > self.wTree.get_widget(key) somehow > > what I need is some kind of indirect assignment where I can assign to > a variable whose name is referenced in a dictionary value. for (name, value) in widgetDic.iteritems(): setattr(self, name, value) -- \ ?The double standard that exempts religious activities from | `\ almost all standards of accountability should be dismantled | _o__) once and for all.? ?Daniel Dennett, 2010-01-12 | Ben Finney From dotancohen at gmail.com Tue May 17 02:16:35 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 17 May 2011 09:16:35 +0300 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 16, 2011 at 07:40, Chris Angelico wrote: > And I'm sure Steven will agree with me that this is not in any way a > bad thing. I've written hundreds of such programs myself (possibly > thousands), and they have all served their purposes. On a slightly > larger scale, there are even more programs that have never left the > walls of my house, having been written for my own family - not because > I'm afraid someone else will steal them, but because they simply are > of no value to anyone else. But hey, if anyone wants a copy of my code > that's basically glue between [obscure application #1] and [obscure > application #2] that does [obscure translation] as well to save a > human from having to do it afterwards, sure! You're welcome to it! :) > > However, I do not GPL my code; I prefer some of the other licenses > (such as CC-BY-SA), unless I'm working on a huge project that's not > meant to have separate authors. For something that by and large is one > person's work, I think it's appropriate to give attribution. But > discussion of exactly _which_ open source license to use is a can of > worms that's unlikely to be worth opening at this stage. > Actually, Chris, those applications are probably no less valuable to be open source than Linux or Firefox. The reason is that when one goes to learn a new language it is valuable to look at existing real world code. However, the code available online generally falls into one of two categories: 1) Simple sample code, which demonstrates a principle or technique 2) Full-blown FOSS application with hundreds of source files and a build It sounds to me like your home-brew code might be one of the missing links between the two. It won't be so tiny as to be trivial, but it won't be so huge as to be beyond the grasp of novices. I for one would love to look over such code. I'll learn something, without a doubt. Maybe someone might even spot a bug or make a suggestion to improve it. And almost invariably, any problem that I've ever had someone has had first. So while you might have been one of the first have a need to interface FooWidget with PlasmoidBar, someone after you will in fact need just the code to do that. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From rosuav at gmail.com Tue May 17 02:39:48 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 May 2011 16:39:48 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 17, 2011 at 4:16 PM, Dotan Cohen wrote: > Actually, Chris, those applications are probably no less valuable to > be open source than Linux or Firefox. The reason is that when one goes > to learn a new language it is valuable to look at existing real world > code. However, the code available online generally falls into one of > two categories: > 1) Simple sample code, which demonstrates a principle or technique > 2) Full-blown FOSS application with hundreds of source files and a build > > It sounds to me like your home-brew code might be one of the missing > links between the two. It won't be so tiny as to be trivial, but it > won't be so huge as to be beyond the grasp of novices. You have a point there. Although I can't guarantee that all my code is particularly *good*, certainly not what I'd want to hold up for a novice to learn from - partly because it dates back anywhere up to two decades, and partly because quite a few of the things I was working with are completely undocumented! But if you have Pastel Accounting Version 5, running in a Windows 3.1 virtual session, and you want to export some of its data to a DB2 database, I can help you quite a bit. Assuming you have an OS/2 system to run it on, of course. (You see what I mean about obscure?) I should probably dust off some of the slightly-more-useful pieces and put them up on either The Esstu Pack (my old web site) or rosuav.com (my new web site, doesn't have any better name than that), but that kinda requires time, a resource that I don't have an awful lot of. I'm sure there'll be a few oddments in there where at least one half of the glue is more useful. Back then, though, I didn't know Python, nor Pike, nor any of quite a few other awesome languages, but REXX and C++ are at least available open source. Chris Angelico From rustompmody at gmail.com Tue May 17 03:00:39 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 17 May 2011 00:00:39 -0700 (PDT) Subject: ipython prompt does not appear in windows Message-ID: If I use ipython under emacs on linux it works (at least basic REPL) ie I can type an expression and I get a result followed by a prompt On windows ipython works at the shell. Plain python works in emacs as well. But inside emacs I dont see a prompt in ipython although I see it in python. I have to type an expression and then the prompt appears. Any clues? From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue May 17 03:15:57 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 17 May 2011 09:15:57 +0200 Subject: indirect assignment question In-Reply-To: References: Message-ID: Am 17.05.2011 07:13 schrieb Andy Baxter: > self.window = self.wTree.get_widget("mainWindow") > self.outputToggleMenu = self.wTree.get_widget("menuitem_output_on") > self.outputToggleButton = self.wTree.get_widget("button_toggle_output") > self.logView = self.wTree.get_widget("textview_log") > self.logScrollWindow = self.wTree.get_widget("scrolledwindow_log") > > and I would like (for tidiness / compactness's sake) to replace them > with something like this: > widgetDic = { > "mainWindow": self.window, > "menuitem_output_on": self.outputToggleMenu, > "button_toggle_output": self.outputToggleButton, > "textview_log": self.logView, > "scrolledwindow_log": self.logScrollWindow > } > for key in widgetDic: > ... set the variable in dic[key] to point to self.wTree.get_widget(key) > somehow assignmap = ( ('mainWindow', 'window'), ('menuitem_output_on', 'outputToggleMenu'), ('button_toggle_output', 'outputToggleButton'), ('textview_log', 'logView'), ('scrolledwindow_log', 'logScrollWindow'), ) for name, selfname in assignmap: val = widgetDic[name] = self.wTree.get_widget(name) setattr(self, selfname, val) HTH, Thomas From akabaila at pcug.org.au Tue May 17 03:44:22 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 17 May 2011 17:44:22 +1000 Subject: Deleting a file? In-Reply-To: References: Message-ID: <201105171744.22500.akabaila@pcug.org.au> On Tuesday 17 May 2011 07:23:33 garyr wrote: > A file can be deleted by opening it with mode os.O_TEMPORARY > and then closing it. How can a file be moved to the Recycle > Bin, a la Windows? Just highlight it, pess the "Del" key and select "move to Trash". (With minor variation between different desktops, viz. KDE, gnome etc. If you ask a genuine answer, the above are genuine answers. HTH, OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From vgnulinux at gmail.com Tue May 17 03:50:07 2011 From: vgnulinux at gmail.com (VGNU Linux) Date: Tue, 17 May 2011 13:20:07 +0530 Subject: How to select Python web frameworks and which one is the best framework ? Message-ID: Hi all, I am confused on which web framework to select for developing a small data driven web application. Application will have features generally found in now-a-days web application like security, database connectivity, authentication etc. I found few web frameworks over the net like django, zope 2/3, pylons, turbogears, web2py, grok etc. etc. I just want to know that how developers/managers/organizations select a framework which best suits their needs ? what are the parameters for selection ? also which is the best and widely used web framework for python ? I apologize if this is a repeated question. Regards, VGNU -------------- next part -------------- An HTML attachment was scrubbed... URL: From hamed3099 at hotmail.com Tue May 17 05:43:51 2011 From: hamed3099 at hotmail.com (hamed azarkeshb) Date: Tue, 17 May 2011 14:13:51 +0430 Subject: FW: help please In-Reply-To: References: Message-ID: From: hamed3099 at hotmail.com To: webmaster at python.org Subject: help please Date: Tue, 17 May 2011 13:20:22 +0430 hi dearinwant to useautomation with catiaby python,but i dont know,how do we can creat catsafearrayvariant in python?please help me.i need urhelp by one example.thank u forany thing -------------- next part -------------- An HTML attachment was scrubbed... URL: From jnr.gonzalez at googlemail.com Tue May 17 06:07:34 2011 From: jnr.gonzalez at googlemail.com (J) Date: Tue, 17 May 2011 03:07:34 -0700 (PDT) Subject: Convert AWK regex to Python In-Reply-To: Message-ID: Hello, I have managed to get my script finished in the end by taking bits from everyone who answered. Thank you so much. the finished query string looks like this (still not the best but it gets the job done. Once I learn to code more with Python I will probably go back to it and re-write it):- # Log file to work on filetoread = open("/tmp/pdu.log", "r") # Perform filtering in the log file text = filetoread.read() text = text.replace(" Message-ID: Hello, I have managed to get my script finished in the end by taking bits from everyone who answered. Thank you so much. the finished query string looks like this (still not the best but it gets the job done. Once I learn to code more with Python I will probably go back to it and re-write it):- # Log file to work on filetoread = open("/tmp/pdu.log", "r") # Perform filtering in the log file text = filetoread.read() text = text.replace(" Hi list I'm using datetime.timedelta and i have a problem delta = 1 day, 2:30:00 hours = delta.days * 8 how to add 8 + 2:30:00 Regards Tsolmon. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Tue May 17 07:41:41 2011 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 17 May 2011 07:41:41 -0400 Subject: cPickle -> invalid signature Message-ID: What does it mean when cPickle.load says: RuntimeError: invalid signature Is binary format not portable? From gagsl-py2 at yahoo.com.ar Tue May 17 07:44:48 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 08:44:48 -0300 Subject: Datetime.timedelta References: Message-ID: En Tue, 17 May 2011 07:44:08 -0300, Tsolmon Narantsogt escribi?: > I'm using datetime.timedelta and i have a problem > > delta = 1 day, 2:30:00 > hours = delta.days * 8 > > how to add 8 + 2:30:00 Just operate with it as it were a number. The timedelta class implements all "sane" mathematical operations. py> from datetime import * py> def timedelta_from_dhms(days=0, hours=0, mins=0, secs=0): ... return timedelta(days, hours*3600 + mins*60 + secs) ... py> delta = timedelta_from_dhms(1, 2, 30) py> delta datetime.timedelta(1, 9000) py> hours = delta.days * 8 py> delta + hours Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'datetime.timedelta' and 'int' py> hours = timedelta_from_dhms(0, delta.days * 8) py> hours datetime.timedelta(0, 28800) py> delta + hours datetime.timedelta(1, 37800) py> def dhms_from_timedelta(td): ... return td.days, td.seconds // 3600, (td.seconds % 3600) // 60, td.seconds % 60 ... py> dhms_from_timedelta(delta + hours) (1, 10, 30, 0) -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue May 17 08:17:10 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 09:17:10 -0300 Subject: FW: help please References: Message-ID: En Tue, 17 May 2011 06:43:51 -0300, hamed azarkeshb escribi?: > hi dearinwant to useautomation with catiaby python,but i dont know,how > do we can creat catsafearrayvariant in python?please help me.i need > urhelp by one example.thank u forany thing There are two sides when you want to use automation with Python: * learn how to do automation by itself, how COM works, how to invoke a COM server from Python. This is mostly application-independent. A good resource is "Python Programming in Win32" book by Mark Hammond. Chapter 5 "Introduction to COM" is exactly what you need, and is available for preview in Google Books: http://books.google.com.ar/books?id=fzUCGtyg0MMC&lpg=PA65&pg=PA65#v=onepage&f=false * learn how to use the actual objects exposed by the desired application. Usually, documentation is available for VBA or other languages, but can be easily translated into Python terms. So I'd say you first read the book, then search the documentation about CATSafeArrayVariant and see how to create it, and then translate that into Python. Feel free to post any problem you encounter, a better place would be the python-win32 list: http://mail.python.org/mailman/listinfo/python-win32 Good luck! -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue May 17 08:29:01 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 09:29:01 -0300 Subject: cPickle -> invalid signature References: Message-ID: En Tue, 17 May 2011 08:41:41 -0300, Neal Becker escribi?: > What does it mean when cPickle.load says: > RuntimeError: invalid signature > > Is binary format not portable? Are you sure that's the actual error message? I cannot find such message anywhere in the sources. The pickle format is quite portable, even cross-version. As a generic answer, make sure you open the file in binary mode, both when writing and reading. -- Gabriel Genellina From chaoyuejoy at gmail.com Tue May 17 08:53:20 2011 From: chaoyuejoy at gmail.com (Yue Chao) Date: Tue, 17 May 2011 14:53:20 +0200 Subject: where to find shared python script? Message-ID: Dear all, I am new to python and thank you for your help! the first question is, is there any resource online where we can find shared python script (like reading a csv file for ready plot making, I know to use csv module while I find it's not good enough) . The second one is, is there a search function in the our mailing list archive http://mail.python.org/pipermail/python-list/. ? Best, Chao -- *********************************************************************************** Chao YUE Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL) UMR 1572 CEA-CNRS-UVSQ Batiment 712 - Pe 119 91191 GIF Sur YVETTE Cedex Tel: (33) 01 69 08 77 30 Portable Phone (Mobil phone) : (33) 07 60 54 23 71 ************************************************************************************ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue May 17 09:10:07 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 17 May 2011 14:10:07 +0100 Subject: where to find shared python script? In-Reply-To: References: Message-ID: <4DD273AF.7090000@timgolden.me.uk> On 17/05/2011 13:53, Yue Chao wrote: > I am new to python and thank you for your help! > the first question is, is there any resource online where we can find > shared python script (like reading a csv file for ready plot making, I > know to use csv module while I find it's not good enough) . I don't know if that specific example is there, but the ActiveState Python Cookbook is usually a good resource: http://code.activestate.com/recipes/langs/python/ > The second one is, is there a search function in the our mailing list > archive http://mail.python.org/pipermail/python-list/. ? http://www.google.com/search?q=site%3Amail.python.org+csv%20module&safe=active There's also the corresponding Google Group: http://groups.google.com/group/comp.lang.python/topics?lnk and MarkMail: http://python.markmail.org/ and GMane: http://news.gmane.org/gmane.comp.python.general and quite a few others which republish the list as Web pages TJG From matt.j.warren at gmail.com Tue May 17 09:33:25 2011 From: matt.j.warren at gmail.com (AlienBaby) Date: Tue, 17 May 2011 06:33:25 -0700 (PDT) Subject: Convert AWK regex to Python References: Message-ID: <12e7b8b8-20ac-40b1-bb66-3a9e22172b3f@d28g2000yqf.googlegroups.com> On May 17, 11:07?am, J wrote: > Hello, > > I have managed to get my script finished in the end by taking bits from everyone who answered. ?Thank you so much. ?the finished query string looks like this (still not the best but it gets the job done. ?Once I learn to code more with Python I will probably go back to it and re-write it):- > > # Log file to work on > filetoread = open("/tmp/pdu.log", "r") > # Perform filtering in the log file > text = filetoread.read() > text = text.replace(" text = text.replace(".", " ") > text = text.replace(r"(", " ") > filetoread.close() > # File to write output to > filetowrite = file("/tmp/pdu_filtered.log", "w") > # Write new log file > filetowrite.write(text) > filetowrite.close() > # Read new log and get required fields from it > filtered_log = ?open("/tmp/pdu_filtered.log", "r") > filtered_line = filtered_log.readlines() > for line in filtered_line: > ? ? ? ? field = line.split(" ") > ? ? ? ? field5 = field[5].rsplit("_", 1) > ? ? ? ? print field5[0], field[14], field[22] > print "Done" You can also process the lines and write them out to the new logfile as you read them in first time around, rather than: read them in, process them, write them out, read them in, process them, write them out; log_file=open("old_log_file","r") output_file=open("new_log_file","w") for line in log_file: line=line.replace(" References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110517093623.c420c9b3.darcy@druid.net> On Tue, 17 May 2011 16:39:48 +1000 Chris Angelico wrote: > You have a point there. Although I can't guarantee that all my code is > particularly *good*, certainly not what I'd want to hold up for a > novice to learn from - partly because it dates back anywhere up to two > decades, and partly because quite a few of the things I was working > with are completely undocumented! Sounds like a perfect reason to open source it. If what you say is true it could benefit you more than others, at least at the beginning. Remember, open source is a two way street. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From harrismh777 at charter.net Tue May 17 09:58:03 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 17 May 2011 08:58:03 -0500 Subject: Convert AWK regex to Python In-Reply-To: References: Message-ID: J wrote: > Hello, Hello, J, This is totally off-topic, but I was wondering why you are posting with double messages (triple) all over the place? Your reply-to is set to comp.lang.python at googlegroups.com, and you cc to python-list at python.org... and you're stuff is showing up in newsgroup comp.lang.python... ... did you know that all you need to do is use the newsgroup (use a client like sea monkey, or other... ) and your posts will show up in googlegroups, and will also be archived forever.... authomatically? Your messages are duplicating which is not only annoying on the surface, but also breaks the threads apart in a news client. What should appear (and does in googlegroups) as a single thread appears as many threads in the mail client; partly because of the RE: in the subject, and partly because of the reduplication. Just a heads up.... kind regards, m harris From jorgeromero178 at gmail.com Tue May 17 10:10:30 2011 From: jorgeromero178 at gmail.com (Jorge Romero) Date: Tue, 17 May 2011 10:10:30 -0400 Subject: Python 3 vs Python 2.7 dilemma In-Reply-To: References: Message-ID: I would recommend you going on the Python 2.x path. Python 2.x is far from being deprecated. According to Wesley Chun (active member of Python community and author of Core Python Programming) on a Google I/O talk, everybody will be using Python 3 by 2018, so there's still plenty of time. Besides, you can start with Python 2.7, which still is 2.x but introduces 3.x features, and in some benchmarks seems to be more efficient than latest 3.x. 3.x is said to be backwards incompatible, but that incompatibility is not something that would bring you a limitation on porting your code later. So, for the sake of web frameworks and runtime infrastructures, I'd stick to 2.x. This is my IMHO, I'm sure you can get a more accurate answer from someone in this list more experienced in the matter ;) Have a good one. On Tue, May 17, 2011 at 12:48 AM, Navkirat Singh wrote: > Hi Guys, > > I have been trying to fight this issue for sometime now. I know that a > large part of the python 3rd party software base has not been ported to > python 3 yet. I am trying to build a web-based enterprise solution for my > client. Most of reputed frameworks like Django and Turbo gears are yet in > the 2.x stage. I know that these frameworks are extremely good. But I wanted > to build my base with python 3 as that is what is going to prevail in the > future. > > I have built my own little architecture using python3. Here is what I have > accomplished till now: > > a) A multiprocessing webserver built directly using low level sockets for > maximum control, conforming to RFC 2616 (not completely right now). > b) A HTTP message parser for parsing HTTP/1.1 requests and generating > response messages > c) A session control base using python multiprocessing dictionary manager > d) A partially build MVC model, without a templating engine at the moment. > I am planning to put Jinja 3 there. > > I have spent months of free time doing this. I have learnt a lot, but well > I am not sure if the path I am on is the right one. > > My question to everyone is whether I should go ahead with this approach, or > should I just use 2.x technology? I am not sure if I will be able to port > all the code to python3 later. > > I will really appreciate any input. > > Thanks and regards, > Navkirat > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Jorge Romero -------------- next part -------------- An HTML attachment was scrubbed... URL: From mosmann at expires-31-05-2011.news-group.org Tue May 17 10:40:54 2011 From: mosmann at expires-31-05-2011.news-group.org (Andreas Mosmann) Date: Tue, 17 May 2011 16:40:54 +0200 Subject: Newbie: Python 3.2, search for module dBase + Excel Message-ID: <1305643254.64@user.newsoffice.de> Hi, I am new to python and so I decided to use python 3.2 But, if I found out correctly, the are no working modules concerning Excel and dBase for this python version. Did I only misunderstand anything or is this right? I tried to download and use pydbf and pyexcelerator but both gave me an syntax error inside the modules and I somewhere read, that both modules only exist for version 2.X Is there a way for me to use them anyway or do I have to change to any 2.X- Version? If last, which should I install? Thanks in advance Andreas remark: My task is to compare 2 directories incl. subdirs containing dBase- Files and find out differencers in FileNames and FileStructures. Up t now I devided it into 3 lists: OnlyInDir1, OnlyInDir2 and InBothDirs. Next step is to put it into an Excel- File with 3 worksheets. If this would be impossible, so I could save this in any other way. But I really need a module that handles dBase- files to compare Structures of files with equal names. My Code up to now is something like import os dirV1 = "C:\Path1" dirV2 = "C:\Path2" anzL1=0 listV1 = [] for root, dirs, files in os.walk(dirV1): for file in files: myFile=os.path.join(root[len(dirV1):], file) listV1.append(myFile) anzL1=anzL1+1 print(anzL1) anzL2=0 anzLG=0 listV2 = [] listGem = [] for root, dirs, files in os.walk(dirV2): for file in files: myFile=os.path.join(root[len(dirV2):], file) try: listV1.index(myFile) listV1.remove(myFile) listGem.append(myFile) anzL1=anzL1-1 anzLG=anzLG+1 except ValueError: listV2.append(myFile) anzL2=anzL2+1 print(anzL1) print(anzLG) print(anzL2) -- wenn email, dann AndreasMosmann web de From garyr at fidalgo.net Tue May 17 10:43:41 2011 From: garyr at fidalgo.net (garyr) Date: Tue, 17 May 2011 07:43:41 -0700 Subject: Deleting a file? References: Message-ID: Jerry, There was an error during the install but only required a minor change to an __init__.py file to correct. Works great. Just what I was looking for. Many thanks! Gary "Jerry Hill" wrote in message news:mailman.1654.1305601607.9059.python-list at python.org... > On Mon, May 16, 2011 at 5:23 PM, garyr wrote: >> A file can be deleted by opening it with mode os.O_TEMPORARY and then >> closing it. How can a file be moved to the Recycle Bin, a la Windows? > > I see a send2trash module (http://hg.hardcoded.net/send2trash and > http://www.hardcoded.net/articles/send-files-to-trash-on-all-platforms.htm) > > The source code looks pretty straightforward, but I don't think > there's anything in the standard library that does that. > > -- > Jerry From eric.frederich at gmail.com Tue May 17 11:14:21 2011 From: eric.frederich at gmail.com (Eric Frederich) Date: Tue, 17 May 2011 11:14:21 -0400 Subject: portable multiprocessing code Message-ID: I have written some code using Python 2.7 but I'd like these scripts to be able to run on Red Hat 5's 2.4.3 version of Python which doesn't have multiprocessing. I can try to import multiprocessing and set a flag as to whether it is available. Then I can create a Queue.Queue instead of a multiprocessing.Queue for the arg_queue and result_queue. Without actually trying this yet it seems like things would work okay except for the Worker class. It seems I can conditionally replace multiprocessing.Queue with Queue.Queue, but is there anything to replace multiprocessing.Process with? Are there any best practices for doing something like this? Below is a dumb example that just counts lines in files. What would be the best way to make this runnable in older (2.4.3) versions of Python? #!/usr/bin/env python import sys import os import multiprocessing import Queue fnames = sys.argv[1:] def SimpleWorker(func): class SimpleWorker_wrapped(multiprocessing.Process): def __init__(self, arg_queue, result_queue): super(SimpleWorker_wrapped, self).__init__() self.arg_queue = arg_queue self.result_queue = result_queue def run(self): while True: try: args = self.arg_queue.get_nowait() except Queue.Empty: break self.result_queue.put(func(*args)) return SimpleWorker_wrapped @SimpleWorker def line_counter(fname): lc = len(open(fname).read().splitlines()) return fname, lc arg_queue = multiprocessing.Queue() result_queue = multiprocessing.Queue() for fname in fnames: arg_queue.put((fname,)) for i in range(multiprocessing.cpu_count()): w = line_counter(arg_queue, result_queue) w.start() results = {} for fname in sorted(fnames): while fname not in results: n, i = result_queue.get() results[n] = i print "%-40s %d" % (fname, results[fname]) From benjamin.kaplan at case.edu Tue May 17 11:49:02 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 17 May 2011 08:49:02 -0700 Subject: portable multiprocessing code In-Reply-To: References: Message-ID: On Tue, May 17, 2011 at 8:14 AM, Eric Frederich wrote: > I have written some code using Python 2.7 but I'd like these scripts > to be able to run on Red Hat 5's 2.4.3 version of Python which doesn't > have multiprocessing. > I can try to import multiprocessing and set a flag as to whether it is > available. ?Then I can create a Queue.Queue instead of a > multiprocessing.Queue for the arg_queue and result_queue. > Without actually trying this yet it seems like things would work okay > except for the Worker class. ?It seems I can conditionally replace > multiprocessing.Queue with Queue.Queue, but is there anything to > replace multiprocessing.Process with? > > Are there any best practices for doing something like this? > Below is a dumb example that just counts lines in files. > What would be the best way to make this runnable in older (2.4.3) > versions of Python? > http://pypi.python.org/pypi/multiprocessing Also, you may be able to find the processing package (what multiprocessing was called back when it was 3rd party) in your package manager. From rbotting at csusb.edu Tue May 17 11:50:59 2011 From: rbotting at csusb.edu (RJB) Date: Tue, 17 May 2011 08:50:59 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers Message-ID: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> I noticed some discussion of recursion..... the trick is to find a formula where the arguments are divided, not decremented. I've had a "divide-and-conquer" recursion for the Fibonacci numbers for a couple of years in C++ but just for fun rewrote it in Python. It was easy. Enjoy. And tell me how I can improve it! def fibo(n): """A Faster recursive Fibonaci function Use a formula from Knuth Vol 1 page 80, section 1.2.8: If F[n] is the n'th Fibonaci number then F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. First set m = n+1 F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. Then put m = n in Knuth's formula, F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], and replace F[n+1] by F[n]+F[n-1], F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). """ if n<=0: return 0 elif n<=2: return 1 elif n%2==0: half=n//2 f1=fibo(half) f2=fibo(half-1) return f1*(f1+2*f2) else: nearhalf=(n-1)//2 f1=fibo(nearhalf+1) f2=fibo(nearhalf) return f1*f1 + f2*f2 RJB the Lurker http://www.csci.csusb.edu/dick/cs320/lab/10.html From luke.leighton at gmail.com Tue May 17 12:07:14 2011 From: luke.leighton at gmail.com (lkcl) Date: Tue, 17 May 2011 09:07:14 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: Message-ID: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> On May 4, 7:37?pm, Terry Reedy wrote: > On 5/4/2011 10:06 AM, Luke Kenneth Casson Leighton wrote: > > > after a long delay thepyjamasproject -http://pyjs.org- has begun the > > 0.8 series of releases, beginning with alpha1: > > >https://sourceforge.net/projects/pyjamas/files/pyjamas/0.8/ > > >pyjamasis a suite of projects, including a python-to-javascript > > compiler > > As you well know, there is no such thing as 'python' when it comes to > compiling actual code. So please specify both in announcements here and > on the project homepagehttp://sourceforge.net/projects/pyjamas/ > which versions are supported. I do not really want to have to download > and experiment to determine whether to bother downloading. > > If you do not yet support 3.x, I request and recommend that you do so, with the situation as it is, there is not a snowball in hell's chance that's going to happen. allow me to explain. the python translator in pyjamas is heavily dependent on the "compiler" module (which is written in c) and is in turn, as you are no doubt aware, specifically dependent on the grammar file. the python translator for pyjamas 0.3 was 1,200 lines of code. thanks to some brilliant and dedicated work by kees bos, over something like a 6 month virtually full-time period, it's now somewhere around 5,000 lines of heavily-dense code in which very specific javascript optimisations have been encoded. then, on top of that, it is necessary to implement the data types that are supported in python 3.x, along with several built-ins (exceptions etc.). the basic implementation - pyjslib.py - is 6,700 lines of python code with in-built hand-optimised javascript, and it would be necessary to reimplement / re-work... and then support... that reimplementation. then, on top of that, there are a number of python-based reimplementations of various python modules, such as md5.py, re.py, string.py and so on, each of which would have to be double-checked for compatibility with their python 3.x counterparts. do they exist, have they been rewritten, modified etc.` then, on top of that, it is necessary to run the pyjamas UI code, which is some 15,000 lines of code, along with the other libraries such as GChart, through lib2to3, and then to double-check them. then, on top of that, it is necessary to run the examples - of which there are 70 - again through lib2to3. i've just done a "wc" on the examples source code: it comes to a whopping total of 60,000 lines of code. so you have to do all this work, and really it's impossible to begin realistically checking that it works until you get to the LibTest example (which is the main test suite, comprising some 3,000 or so regression tests), and once you've done all that work you now need a userbase and also some maintainers. and, when it comes to doing a release, you need to test all 70 examples in a matrix of 14 browsers plus 4 desktop runtime engines, and the browsers you need to recompile three times - with -O (optimised), --strict (python-compliant) and there's one more, i forget its name, it's designed to minimise the amount of javascript generated. to support 3.x therefore requires a complete and utter rewrite, and then a hell of a lot of work on top of that. it's basically supporting a totally separate language, and so is basically a completely new project. i know you mean well, but... you've drastically underestimated quite how much effort has gone into the pyjamas project - just look at the ohloh statistics for goodness sake! it's listed as having had 31 man-years gone into it! http://www.ohloh.net/p/pyjamas so if you can find the money to get people paid to create a python 3.x to javascript compiler, which will require approximately twelve to fifteen man-months of full-time dedicated programming effort, please do speak up! otherwise please - really: just saying "give me support for python 3.x or else" is ... honestly - it's a free software project, _not_ a paid-up corporate google/nokia/ibm/redhat/etc. funded project: you know the score, and you know the drill. now. leaving _that_ aside, there happens to be absolutely no really good compelling reason to support python 3.x in the first place. "python 3 is the future of python" gimme a break!! [so why is archlinux the only linux distribution that's converted over to run everything off of python 3.x?] the thing is: there aren't really any major dependencies to "get in the way" in pyjs. as in: it's entirely self-sufficient [it has to be]. even the installation has its own sandbox system. the only dependency *is* python 2.N, and when daniel kluev completes his GSoC2011 project, that'll be a "bootstrap" into javascript, including the translator itself being compiled into javascript, and then not even python 2.N will be a dependency! the bottom line is this: somewhere in the next 8 to 10 years, python 2.N will be deprecated in all but the most die-hard places. at *that* time, it will have been worthwhile to convert pyjamas over to python 3.N - and probably not even then would it be strictly necessary. the only really compelling reason would be if it became difficult for the pyjamas-desktop engines to be compiled for python 2. that's MSHTML (python-comtypes for python 2 disappearing or being hard to get) - i'm the maintainer of the pyjd/mshtml.py engine so that'll be around for a long time; pythonwebkit (again, i'm the maintainer, so that'll be around for a long time) and xulrunner / python-xpcom and python-hulahop (python-xpcom is maintained by activestate.com). so - if it becomes "difficult" to get hold of all the pyjd engines, *then* and *only* then does it make sense to look at converting to python 3. i seriously, seriously doubt that pythonwebkit, python- comtypes or python-xpcom for python 2 are going to disappear within the next 5 years, don't you? l. p.s. if you _really_ want to use python 3 with pyjs, then run the pyjs translator code through lib2to3, and then make damn sure that you use the "--internal-ast" option when compiling [this is what is recommended for people who use python 2.4, or 2.7 and above. one minor change and we might even be able to support python 2.3 or below]. you will then use the (duh) internal AST code in pyjs, and will *still* need to write pyjamas applications that are in python 2.N syntax, because that's what the pyjs translator supports. but you will at least not require an http://python.org version 2.N interpreter. p.p.s for anyone who might be interested, the --internal-ast code sort- of came from the lib2to3 project, and was used to create a module which is entirely compatible with the standard http://python.org version 2.0 "compile" module and the ast module. except that it supports the features of lib2to3 which include line and character numbers. From ericsnowcurrently at gmail.com Tue May 17 12:07:20 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 17 May 2011 10:07:20 -0600 Subject: Python 3 vs Python 2.7 dilemma In-Reply-To: References: Message-ID: On Mon, May 16, 2011 at 10:48 PM, Navkirat Singh wrote: > Hi Guys, > > I have been trying to fight this issue for sometime now. I know that a > large part of the python 3rd party software base has not been ported to > python 3 yet. I am trying to build a web-based enterprise solution for my > client. Most of reputed frameworks like Django and Turbo gears are yet in > the 2.x stage. I know that these frameworks are extremely good. But I wanted > to build my base with python 3 as that is what is going to prevail in the > future. > > I have built my own little architecture using python3. Here is what I have > accomplished till now: > > a) A multiprocessing webserver built directly using low level sockets for > maximum control, conforming to RFC 2616 (not completely right now). > b) A HTTP message parser for parsing HTTP/1.1 requests and generating > response messages > c) A session control base using python multiprocessing dictionary manager > d) A partially build MVC model, without a templating engine at the moment. > I am planning to put Jinja 3 there. > > I have spent months of free time doing this. I have learnt a lot, but well > I am not sure if the path I am on is the right one. > > My question to everyone is whether I should go ahead with this approach, or > should I just use 2.x technology? I am not sure if I will be able to port > all the code to python3 later. > > I will really appreciate any input. > > Thanks and regards, > Navkirat > > -- > http://mail.python.org/mailman/listinfo/python-list > > I would say go Python 3, unless you have a dependency that prevents it. There was a lot of talk at pycon this year about how the rate of Python 3 transition is drastically increasing. Many of the large projects (as well as pypy, ironpython, and jython) talked about their transition plans for Python 3 in the next year or two. The expectation is that this year will see a switch across many projects. It is a snowball effect, as more dependencies transition the remaining ones have less reason to stay on Python 2. The anticipation was to see everyone on Python 3 by 5 years after its release. It was released just over 2.5 years ago. Here are some references that you might find helpful: http://wiki.python.org/moin/Python2orPython3 http://py3ksupport.appspot.com/ http://dev.pocoo.org/~gbrandl/py3pkgs.png Cheers, -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyler at tysdomain.com Tue May 17 12:18:57 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Tue, 17 May 2011 10:18:57 -0600 Subject: FW: help please In-Reply-To: References: Message-ID: <4DD29FF1.9090506@tysdomain.com> Not to be pedantic or anything, and I may not be able to help regardless, but it looks like your space key is fixed, and I don't really care to pick through and try to play hangman with your message. On 5/17/2011 3:43 AM, hamed azarkeshb wrote: > > > From: hamed3099 at hotmail.com > To: webmaster at python.org > Subject: help please > Date: Tue, 17 May 2011 13:20:22 +0430 > > hi dear > inwant to useautomation with catiaby python,but i dont know,h*ow do we > can creat catsafearrayvariant in python?* > please help me.i need urhelp by one example. > thank u forany thing -- Take care, Ty my website: http://tds-solutions.net my blog: http://tds-solutions.net/blog skype: st8amnd127 ?Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.? ?If Java had true garbage collection, most programs would delete themselves upon execution.? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 17 12:23:48 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 10:23:48 -0600 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> Message-ID: On Tue, May 17, 2011 at 9:50 AM, RJB wrote: > I noticed some discussion of recursion..... the trick is to find a > formula where the arguments are divided, not decremented. > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > for a couple of years in C++ but just for fun rewrote it > in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! > > def fibo(n): > ? ? ? ?"""A Faster recursive Fibonaci function > Use a formula from Knuth Vol 1 page 80, section 1.2.8: > ? ? ? ? ? If F[n] is the n'th Fibonaci number then > ? ? ? ? ? ? ? ? ? F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. > ?First set m = n+1 > ? F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. > > ?Then put m = n in Knuth's formula, > ? ? ? ? ? F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], > ? and replace F[n+1] by F[n]+F[n-1], > ? ? ? ? ? F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). > """ > ? ? ? ?if n<=0: > ? ? ? ? ? ? ? ?return 0 > ? ? ? ?elif n<=2: > ? ? ? ? ? ? ? ?return 1 > ? ? ? ?elif n%2==0: > ? ? ? ? ? ? ? ?half=n//2 > ? ? ? ? ? ? ? ?f1=fibo(half) > ? ? ? ? ? ? ? ?f2=fibo(half-1) > ? ? ? ? ? ? ? ?return f1*(f1+2*f2) > ? ? ? ?else: > ? ? ? ? ? ? ? ?nearhalf=(n-1)//2 > ? ? ? ? ? ? ? ?f1=fibo(nearhalf+1) > ? ? ? ? ? ? ? ?f2=fibo(nearhalf) > ? ? ? ? ? ? ? ?return f1*f1 + f2*f2 Thanks for posting! Actually, it looks like this is the same O(n) algorithm that rusi posted. There was also a O(log n) algorithm discussed that is based on vector math. You might want to take a look. Cheers, Ian From rustompmody at gmail.com Tue May 17 12:25:40 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 17 May 2011 09:25:40 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> Message-ID: On May 17, 8:50?pm, RJB wrote: > I noticed some discussion of recursion..... the trick is to find a > formula where the arguments are divided, not decremented. > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > for a couple of years in C++ but just for fun rewrote it > in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! > > def fibo(n): > ? ? ? ? """A Faster recursive Fibonaci function > Use a formula from Knuth Vol 1 page 80, section 1.2.8: > ? ? ? ? ? ?If F[n] is the n'th Fibonaci number then > ? ? ? ? ? ? ? ? ? ?F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. > ? First set m = n+1 > ? ?F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. > > ? Then put m = n in Knuth's formula, > ? ? ? ? ? ?F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], > ? ?and replace F[n+1] by F[n]+F[n-1], > ? ? ? ? ? ?F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). > """ > ? ? ? ? if n<=0: > ? ? ? ? ? ? ? ? return 0 > ? ? ? ? elif n<=2: > ? ? ? ? ? ? ? ? return 1 > ? ? ? ? elif n%2==0: > ? ? ? ? ? ? ? ? half=n//2 > ? ? ? ? ? ? ? ? f1=fibo(half) > ? ? ? ? ? ? ? ? f2=fibo(half-1) > ? ? ? ? ? ? ? ? return f1*(f1+2*f2) > ? ? ? ? else: > ? ? ? ? ? ? ? ? nearhalf=(n-1)//2 > ? ? ? ? ? ? ? ? f1=fibo(nearhalf+1) > ? ? ? ? ? ? ? ? f2=fibo(nearhalf) > ? ? ? ? ? ? ? ? return f1*f1 + f2*f2 > > RJB the Lurkerhttp://www.csci.csusb.edu/dick/cs320/lab/10.html From vanboxem.ruben at gmail.com Tue May 17 12:32:37 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Tue, 17 May 2011 18:32:37 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: 2011/5/15 Ruben Van Boxem : > 2011/5/15 Ruben Van Boxem : >> 2011/5/15 Ruben Van Boxem : >>> 2011/5/14 Doug Evans : >>>> On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem >>>> wrote: >>>>> 2011/5/14 Doug Evans : >>>>>> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem >>>>>> wrote: >>>>>>> (now in plain-text as required by gdb mailing list) >>>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> I am currently trying to integrate Python support into my toolchain >>>>>>> build (including GDB of course). It is a sysrooted >>>>>>> binutils+GCC+GDB+mingw-w64 toolchain. >>>>>>> >>>>>>> I currently have the basic setup working: I can link gdb with my >>>>>>> manually generated import lib to the python dll from the official >>>>>>> Windows install. If there is anything I am missing or a very easy >>>>>>> solution to the problems decsribed below, please just say so. I am >>>>>>> only suggesting what I would like to happen. >>>>>>> >>>>>>> Now on to the problems I'd like to discuss: >>>>>>> >>>>>>> 1. gdb.exe won't start without me having set PYTHONPATH manually. >>>>>> >>>>>> In a properly configured/built gdb on linux this isn't necessary, even >>>>>> if python is installed in some random place. >>>>>> I'm not sure about windows though. >>>>>> Did you specify --with-python when you configured gdb, and if so did >>>>>> you specify a value? >>>>>> e.g., --with-python=SOME_VALUE >>>>> >>>>> I was cross-compiling a mingw toolchain+gdb from Linux, so I used >>>>> --with-python without a value (because gdb configure tries to find the >>>>> Python executabe), and I added -I"/path/to/python/includes" to CFLAGS >>>>> and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it >>>>> should. This is hacky though, and gdb configure should provide >>>>> --with-python-libs and --with-python-include to make it more >>>>> streamlined with any other build prerequisite (like >>>>> gmp/mpfr/mpc/cloog/ppl in GCC for example). >>>> >>>> Ah. >>>> Cross-compiling gdb with python is in need of improvement. >>>> Alas python hasn't been designed with cross-compilation in mind (e.g. >>>> build on linux, run on windows). >>>> AIUI, the way to get the parameters required for compiling with >>>> libpython is to get them from python's "distutils": kinda hard to do >>>> in a cross-compile. ?Done correctly there's no need to run python. >>>> >>>> I haven't done anything more to support python in gdb's configure.ac >>>> because it's not clear to me what the right thing to do is: distutils >>>> provides more than just --libs and --includes (btw, we don't use >>>> --libs though, we use --ldflags which includes all of: the directory >>>> in which to find libpython, the -l for libpython, and the -l's for all >>>> the other libraries python needs). [Which isn't to say that someone >>>> else isn't free to tackle this.] >>>> >>>> In the meantime, what I've been doing is a hack: write a script that >>>> responds to: >>>> --includes >>>> --ldflags >>>> --exec-prefix >>>> and pass that as --with-python. >>>> >>>> E.g. >>>> bash$ cat $HOME/my-python-for-config >>>> #! /bin/sh >>>> >>>> if [ $# -ne 2 ] >>>> then >>>> ? ? ? ?echo "Bad # args. ?Blech!" >&2 >>>> ? ? ? ?exit 1 >>>> fi >>>> >>>> # The first argument is the path to python-config.py, ignore it. >>>> >>>> case "$2" in >>>> --includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;; >>>> --ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm >>>> -lpython2.6" ;; >>>> --exec-prefix) echo "/usr" ;; >>>> *) echo "Bad arg $2. ?Blech!" >&2 ; exit 1 ;; >>>> esac >>>> >>>> exit 0 >>>> bash$ ./configure --with-python=$HOME/my-python-for-config [...] >>>> [...] >>>> >>>> >>>> Note that --exec-prefix is the runtime location of python. >>>> GCC uses this to tell libpython where to find its support files. >>>> [grep for Py_SetProgramName in gdb/python/python.c] >>> >>> OK, I tried your script in a couple of variations. It gets rid of the >>> traceback I had before, but still doesn't help the PYTHONPATH problem. >>> My directory structure is as follows (this is not in root, "/" is just >>> my main build directory, there are several levels below it): >>> >>> /gdb <-- gdb build dir >>> /gdb/gdb <-- where the python configuration is done >>> /python <-- temporary install dir for python files for build, >>> extracted from the official Windows installer, also location of >>> libpython2.7.a import library >>> /python/include/python27 <-- python headers, found by gdb in both cases >>> /mingw64 <-- toolchain sysroot prefix >>> /mingw64/bin <-- install location of gdb and python27.dll >>> /mingw64/lib/python27 <-- install location of all python scripts >>> >>> First variant: >>> --includes) echo "-I../../python/include" ;; >>> --ldflags) echo "-L../../python -lpython2.7" ;; >>> --exec-prefix) echo "../../mingw64/lib/python27" ;; >>> >>> Here exec-prefix would be the relative path from where "configure" >>> does its magic to the final location of the scripts on the build >>> system. >>> >>> Second variant: >>> --includes) echo "-I../../python/include" ;; >>> --ldflags) echo "-L../../python -lpython2.7" ;; >>> --exec-prefix) echo "../lib/python27" ;; >>> >>> I thought the second points gdb to the installed location of the >>> python scripts, but it still needed PYTHONPATH for that. I used >>> relative paths in an attempt to "do the right thing", hackwise... >>> Remember that the whole "/mingw64" directory gets zipped and moved, >>> then it gets extracted to a random location in the Windows filesystem. >>> >>> Thanks for the help so far, I think we might just get this worked out together. >>> >>> Ruben >> >> Wow, I think I have a partial solution. Delving into the Python docs, >> for example here: >> http://docs.python.org/using/windows.html#finding-modules, you can see >> that PYTHONPATH is used first, then the Windows registry, then >> PYTHONHOME, then some default relative paths. I placed the python >> scripts all in the directory structure like so: >> >> /bin/gdb >> /bin/Lib/ >> /bin/python27.dll >> >> This works, even without any manual PYTHONPATH intervention. Problem >> is though, that as soon as someone has a PYTHONPATH environment >> variable from a (incompatible) Python installation (think different >> bitness or version 3.x instead of 2.7.1), I cannot predict what will >> go wrong. This problem originates in Python's way of filling in the >> search path (sys.path). A true solution in the GDB case to prevent >> this collision of an incompatible PYTHONPATH would be that GDB sets an >> internal PYTHONPATH as directed by configure, uses that to load its >> Python internals, and allows the GDB child processes (apps being >> debugged) to use the environment PYTHONPATH. For now, I have a >> functional installation, but it will break as soon as someone installs >> Python on their system. >> >> The part your script plays in this (if I haven't misunderstood the >> intention/effects of the "--exec-prefix" part) is allowing a uniform >> way of directing the configure script to the right directories for >> includes/libs. >> >> Ruben > > I am sorry for the repeated messages that no one cares about, but I > may have discovered GDB in its current form already allows what I > want: I tried to figure out what exact paths the snake in gdb was > using to search for its modules, and came up with this: > (gdb) python import sys > (gdb) python print sys.path > ['m:\\development\\mingw64\\share\\gdb/python', > 'M:\\Development\\mingw64\\bin\\python27.zip', > 'M:\\Development\\mingw64\\bin\\DLLs', > 'M:\\Development\\mingw64\\bin\\lib', > 'M:\\Development\\mingw64\\bin\\lib\\plat-win', > 'M:\\Development\\mingw64\\bin\\lib\\lib-tk', > 'M:\\Development\\mingw64\\bin', > 'M:\\Development\\mingw64\\bin\\lib\\site-packages'] > > This means that every python command within gdb searches > /share/gdb/python FIRST (even before an environment's > PYTHONPATH), alleviating any concerns or problems I or anyone would > have with another python installation, as this apparently built-in > path comes up first. All I, or anyone interested in doing this kind of > thing, have to do is copy all the python scripts from the Windows > installation's Lib directory to the /share/gdb/python > directory. > > I don't know where this path comes from, but it is quite handy, and > makes this whole discussion ?moot for Python people. Only "issue" that > I'll have to work around is the --with-python-includes and > --with-python-libs that are missing, using either manual > CFLAGS/LDFLAGS or a variant of your script. > > Thanks for all the help and motivation to keep trying :) > > Ruben Scratch that, I had lingering install of Python laying around. Without PYTHONPATH, no gdb (module site not found). Why not make gdb search the ../share/gdb/python path first, and then complain? Ruben > >> >>> >>>> >>>>>>> I understand the need for this, but as gdb requires Python 2, and users >>>>>>> of my toolchain may have installed Python 3 or a 32-bit version python >>>>>>> they want to use from the same environment (without changing their own >>>>>>> PYTHONPATH), there is no way to run python-enabled gdb. >>>>>>> [...] >>>>>> >>>>>> Yeah. >>>>>> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have >>>>>> gdb use that instead of PYTHONPATH if it exists, but there's been >>>>>> resistance to it. >>>>>> I think(!) what would happen is that gdb would set $PYTHONPATH to the >>>>>> value of $GDB_PYTHONPATH. >>>>>> [Inferiors started by gdb should still get the original value of >>>>>> PYTHONPATH though.] >>>>> >>>>> That way would be almost ideal, but a hardcoded *relative* path to the >>>>> python scripts (that is standardized within gdb) wouldn't hurt. >>>> >>>> See above re: --exec-prefix. >>>> >>>>> An >>>>> extra environment variable would require a lot of explaining for >>>>> Windows, and is not "plug-and-play", like the rest of a sysrooted >>>>> toolchain is supposed to be like. I think this should work on all >>>>> setups: >>>>> >>>>> 1. Check hardcoded path; my suggestion would be ">>>> executable>/../lib/python27" >>>>> 2. If this fails to find the necessary files/scripts, find it like you >>>>> described above in Linux, without PYTHONPATH set. >>>>> 3. Check PYTHONPATH. >>>> >>>> The problem being solved by the proposed GDB_PYTHONPATH is "What if >>>> the user has PYTHONPATH set and it points to an incompatible version >>>> of python?". >>>> Leaving such a value for PYTHONPATH set while gdb's python is running >>>> feels wrong (and IIRC has caused some problems). >>>> >>>> The problem of telling python where to find itself is already solved >>>> (or at least is intended to be solved) with gdb's calling >>>> Py_SetProgramName with a value derived from the python-provided >>>> --exec-prefix. >>>> >>>>> I would think only number one would change, and perhaps be only >>>>> enabled with a special configure option. Nothing else would have to >>>>> change, and Windows users would rejoice :) >>>>> Again, this is only my suggestion, if there are problems with it in >>>>> way I haven't thought of, please say so, and we can come up with >>>>> another solution. >>>> >>> >> > From rustompmody at gmail.com Tue May 17 12:36:49 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 17 May 2011 09:36:49 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> Message-ID: <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> On May 17, 8:50?pm, RJB wrote: > I noticed some discussion of recursion..... the trick is to find a > formula where the arguments are divided, not decremented. > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > for a couple of years in C++ but just for fun rewrote it > in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! > > def fibo(n): > ? ? ? ? """A Faster recursive Fibonaci function > Use a formula from Knuth Vol 1 page 80, section 1.2.8: > ? ? ? ? ? ?If F[n] is the n'th Fibonaci number then > ? ? ? ? ? ? ? ? ? ?F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. > ? First set m = n+1 > ? ?F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. > > ? Then put m = n in Knuth's formula, > ? ? ? ? ? ?F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], > ? ?and replace F[n+1] by F[n]+F[n-1], > ? ? ? ? ? ?F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). > """ > ? ? ? ? if n<=0: > ? ? ? ? ? ? ? ? return 0 > ? ? ? ? elif n<=2: > ? ? ? ? ? ? ? ? return 1 > ? ? ? ? elif n%2==0: > ? ? ? ? ? ? ? ? half=n//2 > ? ? ? ? ? ? ? ? f1=fibo(half) > ? ? ? ? ? ? ? ? f2=fibo(half-1) > ? ? ? ? ? ? ? ? return f1*(f1+2*f2) > ? ? ? ? else: > ? ? ? ? ? ? ? ? nearhalf=(n-1)//2 > ? ? ? ? ? ? ? ? f1=fibo(nearhalf+1) > ? ? ? ? ? ? ? ? f2=fibo(nearhalf) > ? ? ? ? ? ? ? ? return f1*f1 + f2*f2 > > RJB the Lurkerhttp://www.csci.csusb.edu/dick/cs320/lab/10.html ------------------------------------------------------------- Its an interesting problem and you are 75% there. You see the halving gives you logarithmic behavior and the double calls give exponential behavior. So how to get rid of double calls? Its quite simple: Just define your function in terms of return pairs of adjacent pairs ie (fib(n), fib(n +1)) for some n rather then a single number fib(n) Here's a straightforward linear function: def fp(n): #fibpair if n==1: return (1,1) else: a,b = fp(n-1) return (b, a+b) def fib(n): a,b = fp(n) return a --------------- Now use this (pairing) idea with your (halving) identities and you should get a logarithmic algo. [If you cant do it ask again but yes its fun to work out so do try :-) ] From harrismh777 at charter.net Tue May 17 12:38:36 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 17 May 2011 11:38:36 -0500 Subject: [ann] pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: Terry Reedy wrote: > Like it or not, Python 3 is the future of Python. It is the Python that > many Python newcomers learn first, and perhaps ever will. Yes, no doubt, and I'm genuine about that... ... but there is something else to consider, as I'm sure you are aware. At some point Python is going to have to standardize in order to survive. And by survive I'm not talking about the Python 'community,' as much as I'm talking about the acceptance and wide-spread use of Python by people who just want to get work done and solve problems. If there is another major jump like 2.x --> 3.x in the future, Python will die. I hope you guys are aware of this. The user base might accept this thing once, but they're not going do it again... Like it or not, Python 2.x has millions of lines of code running out there, and they're not going to get morphed into 3.x coding. So, 2x is going to be around for many years to come. On the other hand, I'm teaching 3x, coding 3x, and porting to 3x... and also encouraging others to do the same... but there is a limit to that also. My system has 2.4, 2.5, 2.6, 2.7 and 3.2... and that's the trouble with an interpreter. Different versions of the source code (.py files) require a matching 'interpreter,' where-as in other languages a new compiler version does not require recompiling source, but if source is recompiled everything still works... not so in Python. The fact that Python is free to morph gleely from PEP to PEP without responsibility or accountability with the user base is what may kill Python, unless the Python community gets a grip on this concept. kind regards, m harris From jackcwoodhead at googlemail.com Tue May 17 13:01:23 2011 From: jackcwoodhead at googlemail.com (Jackson) Date: Tue, 17 May 2011 10:01:23 -0700 (PDT) Subject: groupby - summing multiple columns in a list of lists Message-ID: <2f60e6c7-1ce2-4094-a777-e544293e8843@hg8g2000vbb.googlegroups.com> I'm currently using a function pasted in below. This allows me to sum a column (index) in a list of lists. So if mylist = [[1, 2, 3], [1, 3, 4], [2, 3, 4], [2, 4, 5]] group_results(mylist,[0],1) Returns: [(1, 5), (2, 7)] What I would like to do is allow a tuple/list of index values, rather than a single index value to be summed up, so you could say group_results(mylist,[0],[1,2]) would return [(1, 5,7), (2, 7,9)] but I'm struggling to do so, any thoughts? Cheers from itertools import groupby as gb from operator import itemgetter as ig def group_results(table,keys,value): res = [] nkey = ig(*keys) value = ig(value) for k, group in gb(sorted(table,key=ig(*keys)),nkey): res.append((k,sum(value(row) for row in group))) return res From debatem1 at gmail.com Tue May 17 13:02:21 2011 From: debatem1 at gmail.com (geremy condra) Date: Tue, 17 May 2011 10:02:21 -0700 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> Message-ID: On Tue, May 17, 2011 at 9:36 AM, rusi wrote: > On May 17, 8:50?pm, RJB wrote: >> I noticed some discussion of recursion..... the trick is to find a >> formula where the arguments are divided, not decremented. >> I've had a "divide-and-conquer" recursion for the Fibonacci numbers >> for a couple of years in C++ but just for fun rewrote it >> in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! >> >> def fibo(n): >> ? ? ? ? """A Faster recursive Fibonaci function >> Use a formula from Knuth Vol 1 page 80, section 1.2.8: >> ? ? ? ? ? ?If F[n] is the n'th Fibonaci number then >> ? ? ? ? ? ? ? ? ? ?F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. >> ? First set m = n+1 >> ? ?F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. >> >> ? Then put m = n in Knuth's formula, >> ? ? ? ? ? ?F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], >> ? ?and replace F[n+1] by F[n]+F[n-1], >> ? ? ? ? ? ?F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). >> """ >> ? ? ? ? if n<=0: >> ? ? ? ? ? ? ? ? return 0 >> ? ? ? ? elif n<=2: >> ? ? ? ? ? ? ? ? return 1 >> ? ? ? ? elif n%2==0: >> ? ? ? ? ? ? ? ? half=n//2 >> ? ? ? ? ? ? ? ? f1=fibo(half) >> ? ? ? ? ? ? ? ? f2=fibo(half-1) >> ? ? ? ? ? ? ? ? return f1*(f1+2*f2) >> ? ? ? ? else: >> ? ? ? ? ? ? ? ? nearhalf=(n-1)//2 >> ? ? ? ? ? ? ? ? f1=fibo(nearhalf+1) >> ? ? ? ? ? ? ? ? f2=fibo(nearhalf) >> ? ? ? ? ? ? ? ? return f1*f1 + f2*f2 >> >> RJB the Lurkerhttp://www.csci.csusb.edu/dick/cs320/lab/10.html > > ------------------------------------------------------------- > Its an interesting problem and you are 75% there. > You see the halving gives you logarithmic behavior and the double > calls give exponential behavior. > > So how to get rid of double calls? ?Its quite simple: Just define your > function in terms of return pairs of adjacent pairs ie (fib(n), fib(n > +1)) for some n rather then a single number fib(n) > > Here's a straightforward linear function: > > def fp(n): ?#fibpair > ? ?if n==1: > ? ? ? ?return (1,1) > ? ?else: > ? ? ? ?a,b = fp(n-1) > ? ? ? ?return (b, a+b) > > def fib(n): > ? ?a,b = fp(n) > ? ?return a > > --------------- > Now use this (pairing) idea with your (halving) identities and you > should get a logarithmic algo. > > [If you cant do it ask again but yes its fun to work out so do > try :-) ] > -- > http://mail.python.org/mailman/listinfo/python-list > or O(1): ? = (1 + sqrt(5)) / 2 def fib(n): numerator = (?**n) - (1 - ?)**n denominator = sqrt(5) return round(numerator/denominator) Testing indicates that it's faster somewhere around 7 or so. Geremy Condra From chris at simplistix.co.uk Tue May 17 13:04:25 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 17 May 2011 18:04:25 +0100 Subject: in search of graceful co-routines Message-ID: <4DD2AA99.3010508@simplistix.co.uk> Hi All, I'm looking for a graceful pattern for the situation where I have a provider of a sequence, the consumer of a sequence and code to moderate the two, and where I'd like to consumer to be able to signal to the provider that it hasn't succeeded in processing one element in the queue. So, I'd want the controlling code to look a lot like: for item in provider: try: consumer.handleItem(self) except: provider.failed(item) Now, since the sequence is long, and comes from a file, I wanted the provider to be an iterator, so it occurred to me I could try and use the new 2-way generator communication to solve the "communicate back with the provider", with something like: for item in provider: try: consumer.handleItem(self) except: provider.send('fail') else: provider.send('succeed') ..but of course, this won't work, as 'send' causes the provider iteration to continue and then returns a value itself. That feels weird and wrong to me, but I guess my use case might not be what was intended for the send method. Anyway, I wonder how other people would write this? (I'm particularly interested in a sane way to use the two way communication that PEP 342 introduced) cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From jpiitula at ling.helsinki.fi Tue May 17 13:19:05 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 17 May 2011 20:19:05 +0300 Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> Message-ID: geremy condra writes: > or O(1): > > ? = (1 + sqrt(5)) / 2 > def fib(n): > numerator = (?**n) - (1 - ?)**n > denominator = sqrt(5) > return round(numerator/denominator) > > Testing indicates that it's faster somewhere around 7 or so. And increasingly inaccurate from 71 on. From ian.g.kelly at gmail.com Tue May 17 13:26:54 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 11:26:54 -0600 Subject: in search of graceful co-routines In-Reply-To: <4DD2AA99.3010508@simplistix.co.uk> References: <4DD2AA99.3010508@simplistix.co.uk> Message-ID: On Tue, May 17, 2011 at 11:04 AM, Chris Withers wrote: > Now, since the sequence is long, and comes from a file, I wanted the > provider to be an iterator, so it occurred to me I could try and use the new > 2-way generator communication to solve the "communicate back with the > provider", with something like: > > for item in provider: > ?try: > ? ?consumer.handleItem(self) > ?except: > ? ? provider.send('fail') > ?else: > ? ? provider.send('succeed') > > ..but of course, this won't work, as 'send' causes the provider iteration to > continue and then returns a value itself. That feels weird and wrong to me, > but I guess my use case might not be what was intended for the send method. > > Anyway, I wonder how other people would write this? > (I'm particularly interested in a sane way to use the two way communication > that PEP 342 introduced) You can use send the way you're wanting to. It will look something like this: def provider(): result = None while True: if result is None: if has_more_items(): next_item = get_next_item() else: break elif result == 'fail': process_fail() next_item = None elif result == 'succeed': process_succeed() next_item = None else: raise ValueError('unknown result %s' % result) result = (yield next_item) Whenever you call provider().next() or provider().send(None), you simply get the next item. If you call provider().send('succeed') or provider().send('fail'), then the corresponding code is run and the yielded value is None, without consuming anything from the sequence. Cheers, Ian From pavlovevidence at gmail.com Tue May 17 13:30:25 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 17 May 2011 10:30:25 -0700 (PDT) Subject: in search of graceful co-routines In-Reply-To: Message-ID: On Tuesday, May 17, 2011 10:04:25 AM UTC-7, Chris Withers wrote: > Now, since the sequence is long, and comes from a file, I wanted the > provider to be an iterator, so it occurred to me I could try and use the > new 2-way generator communication to solve the "communicate back with > the provider", with something like: > > for item in provider: > try: > consumer.handleItem(self) > except: > provider.send('fail') > else: > provider.send('succeed') > > ..but of course, this won't work, as 'send' causes the provider > iteration to continue and then returns a value itself. That feels weird > and wrong to me, but I guess my use case might not be what was intended > for the send method. You just have to call send() in a loop yourself. Note that you should usually catch StopIteration whenever calling send() or next() by hand. Untested: result = None while True: try: item = provider.send(result) except StopIteration: break try: consumer.handleItem(item) except: result = 'failure' else: result = 'success' Carl Banks From pavlovevidence at gmail.com Tue May 17 13:30:25 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 17 May 2011 10:30:25 -0700 (PDT) Subject: in search of graceful co-routines In-Reply-To: Message-ID: On Tuesday, May 17, 2011 10:04:25 AM UTC-7, Chris Withers wrote: > Now, since the sequence is long, and comes from a file, I wanted the > provider to be an iterator, so it occurred to me I could try and use the > new 2-way generator communication to solve the "communicate back with > the provider", with something like: > > for item in provider: > try: > consumer.handleItem(self) > except: > provider.send('fail') > else: > provider.send('succeed') > > ..but of course, this won't work, as 'send' causes the provider > iteration to continue and then returns a value itself. That feels weird > and wrong to me, but I guess my use case might not be what was intended > for the send method. You just have to call send() in a loop yourself. Note that you should usually catch StopIteration whenever calling send() or next() by hand. Untested: result = None while True: try: item = provider.send(result) except StopIteration: break try: consumer.handleItem(item) except: result = 'failure' else: result = 'success' Carl Banks From joe.leonardo at datalogix.com Tue May 17 14:02:03 2011 From: joe.leonardo at datalogix.com (Joe Leonardo) Date: Tue, 17 May 2011 11:02:03 -0700 Subject: if statement on lenght of a list Message-ID: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Hey all, Totally baffled by this...maybe I need a nap. Writing a small function to reject input that is not a list of 19 fields. def breakLine(value): if value.__class__() != [] and value.__len__() != 19: print 'You must pass a list that contains 19 fields.' else: print 'YAY!' If I pass: breakLine([]) I get: YAY! I expect: You must pass a list that contains 19 fields. If I print len(value) I get: 0 What is going on here? Thanks! [cid:image001.png at 01CC148A.3C0C1950] Joe Leonardo | Business Intelligence Analyst | DataLogix 303.327.1730 d | 415.812.5244 c | joe.leonardo at datalogix.com Better Marketing through Data(tm) -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.png Type: image/png Size: 3465 bytes Desc: image001.png URL: From pazurrobert at gmail.com Tue May 17 14:22:33 2011 From: pazurrobert at gmail.com (Robert Pazur) Date: Tue, 17 May 2011 20:22:33 +0200 Subject: best way to extract sentence from txt file In-Reply-To: References: Message-ID: Hi all, my question is maybe quite simple: What is the best (and shortest) way to extract sentence from .txt file? Thanks in advance, Robert Pazur -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue May 17 14:24:14 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 May 2011 20:24:14 +0200 Subject: groupby - summing multiple columns in a list of lists References: <2f60e6c7-1ce2-4094-a777-e544293e8843@hg8g2000vbb.googlegroups.com> Message-ID: Jackson wrote: > I'm currently using a function pasted in below. This allows me to sum > a column (index) in a list of lists. > > So if mylist = [[1, 2, 3], [1, 3, 4], [2, 3, 4], [2, 4, 5]] > group_results(mylist,[0],1) > > Returns: > [(1, 5), (2, 7)] > > What I would like to do is allow a tuple/list of index values, rather > than a single index value to be summed up, so you could say > group_results(mylist,[0],[1,2]) would return [(1, 5,7), (2, 7,9)] but > I'm struggling to do so, any thoughts? Cheers > > from itertools import groupby as gb > from operator import itemgetter as ig > > def group_results(table,keys,value): > res = [] > nkey = ig(*keys) > value = ig(value) > for k, group in gb(sorted(table,key=ig(*keys)),nkey): > res.append((k,sum(value(row) for row in group))) > return res You could write a version of sum() that can cope with tuples: from itertools import groupby, imap def itemgetter(keys, rowtype=tuple): def getitem(value): return rowtype(value[key] for key in keys) return getitem def sum_all(rows): rows = iter(rows) sigma = next(rows) rowtype = type(sigma) sigma = list(sigma) for row in rows: for i, x in enumerate(row): sigma[i] += x return rowtype(sigma) def group_results(table, key, value): get_key = itemgetter(key) get_value = itemgetter(value) table = sorted(table, key=get_key) for keyvalue, group in groupby(table, get_key): yield keyvalue + sum_all(imap(get_value, group)) but I'd probably use a dict-based approach: def group_results(table, key, value): get_key = itemgetter(key) get_value = itemgetter(value) grouped = {} for row in table: key = get_key(row) value = get_value(row) if key in grouped: grouped[key] = tuple(a + b for a, b in zip(grouped[key], value)) else: grouped[key] = value return [k + v for k, v in sorted(grouped.iteritems())] if __name__ == "__main__": items = [(1, 2, 3), (1, 3, 4), (2, 3, 4), (2, 4, 5)] print list(group_results(items, [0], [1, 2])) Note that the function built with my version of itemgetter() will always return a tuple. From ndbecker2 at gmail.com Tue May 17 14:26:53 2011 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 17 May 2011 14:26:53 -0400 Subject: cPickle -> invalid signature References: Message-ID: Gabriel Genellina wrote: > En Tue, 17 May 2011 08:41:41 -0300, Neal Becker > escribi?: > >> What does it mean when cPickle.load says: >> RuntimeError: invalid signature >> >> Is binary format not portable? > > Are you sure that's the actual error message? > I cannot find such message anywhere in the sources. > The pickle format is quite portable, even cross-version. As a generic > answer, make sure you open the file in binary mode, both when writing and > reading. > Yes, that's the message. Part of what is pickled is a numpy array. I am writing on a 32-bit linux system and reading on a 64-bit system. Reading on the 64-bit system is no problem. Maybe the message comes from numpy's unpickling? From malaclypse2 at gmail.com Tue May 17 14:28:02 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 17 May 2011 14:28:02 -0400 Subject: if statement on lenght of a list In-Reply-To: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> References: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Message-ID: On Tue, May 17, 2011 at 2:02 PM, Joe Leonardo wrote: > Hey all, > > > > Totally baffled by this?maybe I need a nap. Writing a small function to > reject input that is not a list of 19 fields. > > > > def breakLine(value): > > if value.__class__() != [] and value.__len__() != 19: > > This should use an "or" test, not "and". And is probably better written as: if not isinstance(value, list) or len(value) != 19: That would allow for subclasses of list, assuming that would be okay. -- Jerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue May 17 14:31:19 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 May 2011 11:31:19 -0700 Subject: if statement on lenght of a list In-Reply-To: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> References: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Message-ID: On Tue, May 17, 2011 at 11:02 AM, Joe Leonardo wrote: > > Hey all, > > Totally baffled by this?maybe I need a nap. Writing a small function to reject input that is not a list of 19 fields. > > def breakLine(value): > ??? if value.__class__() != [] and value.__len__() != 19: > ??????? print 'You must pass a list that contains 19 fields.' > ??? else: > ??????? print 'YAY!' > > If I pass: > breakLine([]) > > I get: > YAY! > > I expect: > You must pass a list that contains 19 fields. Your test should use `or` as opposed to `and`. Since you're indeed passing in a list, the first part of your condition is False; since you used `and`, this makes the entire condition False. Therefore, the else clause ("YAY!") gets executed. Also, your test is written quite strangely. One would more normally and straightforwardly write it as: if not isinstance(value, list) or len(value) != 19: Cheers, Chris -- http://rebertia.com From python at mrabarnett.plus.com Tue May 17 14:32:14 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 May 2011 19:32:14 +0100 Subject: if statement on lenght of a list In-Reply-To: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> References: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Message-ID: <4DD2BF2E.4050001@mrabarnett.plus.com> On 17/05/2011 19:02, Joe Leonardo wrote: > Hey all, > > Totally baffled by this?maybe I need a nap. Writing a small function to > reject input that is not a list of 19 fields. > > def breakLine(value): > if value.__class__() != [] and value.__len__() != 19: > print 'You must pass a list that contains 19 fields.' > else: > print 'YAY!' > > If I pass: > > breakLine([]) > > I get: > > YAY! > > I expect: > > You must pass a list that contains 19 fields. > > If I print len(value) I get: 0 > > What is going on here? > If value is [], then value.__class__() is [], so value.__class__() != [] is False. What you meant was: if value.__class__() != [] or value.__len__() != 19: print 'You must pass a list that contains 19 fields.' else: print 'YAY!' although the Pythonic way to write it would be: if not isinstance(value, list) or len(value) != 19: print 'You must pass a list that contains 19 fields.' else: print 'YAY!' or, even better: if isinstance(value, list) and len(value) == 19: print 'YAY!' else: print 'You must pass a list that contains 19 fields.' From ian.g.kelly at gmail.com Tue May 17 14:33:51 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 12:33:51 -0600 Subject: if statement on lenght of a list In-Reply-To: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> References: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Message-ID: On Tue, May 17, 2011 at 12:02 PM, Joe Leonardo wrote: > Hey all, > > > > Totally baffled by this?maybe I need a nap. Writing a small function to > reject input that is not a list of 19 fields. > > > > def breakLine(value): > > if value.__class__() != [] and value.__len__() != 19: > > print 'You must pass a list that contains 19 fields.' > > else: > > print 'YAY!' > > > > If I pass: > > breakLine([]) > > > > I get: > > YAY! > > > > I expect: > > You must pass a list that contains 19 fields. > > > > If I print len(value) I get: 0 > > > > What is going on here? > > Evaluating the conditions, the first line reduces to "if False and True" which further reduces to "if False". You probably meant to write "or" instead of "and". A few other comments: "value.__len__()" is better written as "len(value)". "value.__class__() != []" would be better written as "type(value) is list". Better yet would be to not worry so much about the particular type of sequence passed in by the caller. To allow any sequence you could just do this: def break_line(value): if len(value) != 19: raise ValueError('value must contain 19 items') If value is not a sequence, then it will just raise a TypeError, which is typically what you would want in that situation anyway. Or if value absolutely must be a list due to the way your function works, you can do this: def break_line(value): value = list(value) if len(value) != 19: raise ValueError('value must contain 19 items') Again that will just raise a TypeError if the value can't be converted to a list. One of the niceties about this version is that value can be any iterable, not just a sequence. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From motoom at xs4all.nl Tue May 17 14:40:40 2011 From: motoom at xs4all.nl (Michiel Overtoom) Date: Tue, 17 May 2011 20:40:40 +0200 Subject: best way to extract sentence from txt file In-Reply-To: References: Message-ID: On May 17, 2011, at 20:22, Robert Pazur wrote: > my question is maybe quite simple: > What is the best (and shortest) way to extract sentence from .txt file? Well, open("filename.txt").readlines() gives you a list of all the lines in a txt file, which might not be sentences, depending on the text file is structured. If you really want to interpret the text file as a collection of sentences, some parsing might be involved. What is a sentence? A sequence of words ending with a dot? With a question mark? How do quotes play a role in this? Did you have a specific sentence (or line) in thought? The first line? The last line? A random line somewhere in between? Until then we have to guess, and my E.S.P. is notoriously bad. Greetings, -- "Learn to value yourself, which means: fight for your happiness." - Ayn Rand From ethan at stoneleaf.us Tue May 17 14:47:01 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 May 2011 11:47:01 -0700 Subject: Python 3.x and bytes Message-ID: <4DD2C2A5.3080403@stoneleaf.us> In Python 3 one can say --> huh = bytes(5) Since the bytes type is actually a list of integers, I would have expected this to have huh being a bytestring with one element -- the integer 5. Actually, what you get is: --> huh b'\x00\x00\x00\x00\x00' or five null bytes. Note that this is an immutable type, so you cannot go in later and say --> huh[3] = 9 Traceback (most recent call last): File "", line 1, in TypeError: 'bytes' object does not support item assignment So, out of curiosity, does anyone actually use this, um, feature? ~Ethan~ From georg at python.org Tue May 17 14:50:37 2011 From: georg at python.org (Georg Brandl) Date: Tue, 17 May 2011 20:50:37 +0200 Subject: [RELEASED] Python 3.2.1 rc 1 Message-ID: <4DD2C37D.7000008@python.org> On behalf of the Python development team, I am pleased to announce the first release candidate of Python 3.2.1. Python 3.2.1 will the first bugfix release for Python 3.2, fixing over 120 bugs and regressions in Python 3.2. For an extensive list of changes and features in the 3.2 line, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2.1 visit: http://www.python.org/download/releases/3.2.1/ This is a testing release: Please consider trying Python 3.2.1 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 debatem1 at gmail.com Tue May 17 14:56:33 2011 From: debatem1 at gmail.com (geremy condra) Date: Tue, 17 May 2011 11:56:33 -0700 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> Message-ID: On Tue, May 17, 2011 at 10:19 AM, Jussi Piitulainen wrote: > geremy condra writes: > >> or O(1): >> >> ? = (1 + sqrt(5)) / 2 >> def fib(n): >> ? ? numerator = (?**n) - (1 - ?)**n >> ? ? denominator = sqrt(5) >> ? ? return round(numerator/denominator) >> >> Testing indicates that it's faster somewhere around 7 or so. > > And increasingly inaccurate from 71 on. Yup. That's floating point for you. For larger values you could just add a linear search at the bottom using the 5f**2 +/- 4 rule, which would still be quite fast out to about 10 times that. The decimal module gets you a tiny bit further, and after that it's time to just use Dijkstra's, like rusi suggested. In any event, I still think this formulation is the most fun ;). Geremy Condra From ethan at stoneleaf.us Tue May 17 15:07:44 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 May 2011 12:07:44 -0700 Subject: if statement on lenght of a list In-Reply-To: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> References: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Message-ID: <4DD2C780.9010909@stoneleaf.us> Joe Leonardo wrote: > > Totally baffled by this?maybe I need a nap. Writing a small function to > reject input that is not a list of 19 fields. > > def breakLine(value): > if value.__class__() != [] and value.__len__() != 19: > print 'You must pass a list that contains 19 fields.' > else: > print 'YAY!' > > If I pass: > > breakLine([]) > > I get: > > YAY! Change your 'and' to an 'or'. Also, change your 'value.__len__()' to 'len(value)'. Finally, if you absolutely don't want any iterable that might work (such as a tuple), change 'value.__class__() != []' to either 'type(value) != list' or, if subclasses are okay (and they probably should be) 'not isinstance(value, list)'. Incorporating these suggestions looks like this: def breakLine(value): if not isinstance(value, list) or len(value) != 19: print 'You must pass a list that contains 19 fields.' else: print 'YAY!' From miki.tebeka at gmail.com Tue May 17 15:15:30 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 17 May 2011 12:15:30 -0700 (PDT) Subject: best way to extract sentence from txt file In-Reply-To: Message-ID: http://nltk.googlecode.com/svn/trunk/doc/api/nltk.tokenize-module.html ? From miki.tebeka at gmail.com Tue May 17 15:15:30 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 17 May 2011 12:15:30 -0700 (PDT) Subject: best way to extract sentence from txt file In-Reply-To: Message-ID: http://nltk.googlecode.com/svn/trunk/doc/api/nltk.tokenize-module.html ? From ian.g.kelly at gmail.com Tue May 17 15:20:32 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 13:20:32 -0600 Subject: Python 3.x and bytes In-Reply-To: <4DD2C2A5.3080403@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: On Tue, May 17, 2011 at 12:47 PM, Ethan Furman wrote: > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have expected > this to have huh being a bytestring with one element -- the integer 5. > ?Actually, what you get is: > > --> huh > b'\x00\x00\x00\x00\x00' > > or five null bytes. ?Note that this is an immutable type, so you cannot go > in later and say > > --> huh[3] = 9 > Traceback (most recent call last): > ?File "", line 1, in > TypeError: 'bytes' object does not support item assignment > > > So, out of curiosity, does anyone actually use this, um, feature? I suppose it's for interoperability with the mutable bytearray type, which takes the same parameters in the constructor. From felipe.bastosn at gmail.com Tue May 17 15:22:30 2011 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Tue, 17 May 2011 16:22:30 -0300 Subject: Python 3.x and bytes In-Reply-To: <4DD2C2A5.3080403@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: They accept .replace(b"00", b"12") for example. Documentation about it. 2011/5/17 Ethan Furman > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have expected > this to have huh being a bytestring with one element -- the integer 5. > Actually, what you get is: > > --> huh > b'\x00\x00\x00\x00\x00' > > or five null bytes. Note that this is an immutable type, so you cannot go > in later and say > > --> huh[3] = 9 > Traceback (most recent call last): > File "", line 1, in > TypeError: 'bytes' object does not support item assignment > > > So, out of curiosity, does anyone actually use this, um, feature? > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 17 15:25:35 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 13:25:35 -0600 Subject: Python 3.x and bytes In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: On Tue, May 17, 2011 at 1:20 PM, Ian Kelly wrote: > I suppose it's for interoperability with the mutable bytearray type, > which takes the same parameters in the constructor. http://www.python.org/dev/peps/pep-3137/#constructors From topher.bartos at gmail.com Tue May 17 15:26:52 2011 From: topher.bartos at gmail.com (Chris M. Bartos) Date: Tue, 17 May 2011 15:26:52 -0400 Subject: Cartoonify Myself Message-ID: <4DD2CBFC.4070109@gmail.com> Hi, Is there a Python module that can "cartoonify" a picture of myself? There's got to be an algorithm out there somewhere, right? If there is a way to cartoon a single picture, could you cartoonify a video, too? Thanks for your help. Chris -- Christopher M. Bartos bartos.25 at osu.edu 330-324-0018 From alister.ware at ntlworld.com Tue May 17 15:26:58 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Tue, 17 May 2011 19:26:58 GMT Subject: problem with GKT module? References: Message-ID: <6_zAp.5859$6K4.49@newsfe14.ams2> On Mon, 16 May 2011 14:56:38 -0500, harrismh777 wrote: > alister ware wrote: >> def callback(self,widget,data=None): >> print widget #gives reference to radio button ok print >> widget.name #widget name on windoze, None on linux > > Well, you're obviously using Python 2.x ... > > ... have you tried this in Python 3.x ? > > > Neither here nor there... you need to know who/what is generating > 'widget'. Is widget buried in gtk where you can't see how it works, or > is widget a Python class (or wrapper) where you can see what its doing? > > The fact that widget.name returns None on the linux platform tells me > that widget is a Python class (or wrapper) ... so you probably have a > widget.py file somewhere... or some other module that widget is a class > definition in... who knows... (at this point). > > It seems to me that the 'builder' is behaving differently on the two > platforms (rather than Python is behaving differently on the two > platforms). > > What happens if you change the data=None pair? > > What happens if you omit data=None pair? > > Do you see this difference with *all* widgets, or just radio buttons? > > > > kind regards, > m harris It seems it was introduced in pygtk 2.1.7 as a side effect of correcting something to do with widget id's and the fact that widget names do not have to be unique (although glade insists that they are). looks like i have to modify my code & use gtk.buildable.get_name(widget) instead, not really a big change but may break someone else's code -- If you're not careful, you're going to catch something. From python at mrabarnett.plus.com Tue May 17 15:39:12 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 May 2011 20:39:12 +0100 Subject: Python 3.x and bytes In-Reply-To: <4DD2C2A5.3080403@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: <4DD2CEE0.4080403@mrabarnett.plus.com> On 17/05/2011 19:47, Ethan Furman wrote: > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have > expected this to have huh being a bytestring with one element -- the > integer 5. Actually, what you get is: > > --> huh > b'\x00\x00\x00\x00\x00' > > or five null bytes. Note that this is an immutable type, so you cannot > go in later and say > > --> huh[3] = 9 > Traceback (most recent call last): > File "", line 1, in > TypeError: 'bytes' object does not support item assignment > > > So, out of curiosity, does anyone actually use this, um, feature? > I suppose it follows the example of 'list' and 'tuple' in accepting an iterable. Producing a bytestring of zero bytes might have its uses, but because Python lets me do coding at a high level (lists, dicts, etc), I've never used that feature. BTW, help(bytes) doesn't seem to mention it! From marduk at letterboxes.org Tue May 17 15:48:29 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 17 May 2011 15:48:29 -0400 Subject: FW: help please In-Reply-To: <4DD29FF1.9090506@tysdomain.com> References: <4DD29FF1.9090506@tysdomain.com> Message-ID: <1305661713.3831.1.camel@localhost.localdomain> On Tue, 2011-05-17 at 10:18 -0600, Littlefield, Tyler wrote: > Not to be pedantic or anything, and I may not be able to help > regardless, but it looks like your space key is fixed, and I don't > really care to pick through and try to play hangman with your message. I actually, at first glance, thought it was spam, ignored it, and was wondering why people were replying to it :| -a From kb1pkl at aim.com Tue May 17 15:50:13 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Tue, 17 May 2011 15:50:13 -0400 Subject: Python 3.x and bytes In-Reply-To: <4DD2C2A5.3080403@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: <4DD2D175.30506@aim.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/17/2011 02:47 PM, Ethan Furman wrote: > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have > expected this to have huh being a bytestring with one element -- the > integer 5. Actually, what you get is: > > --> huh > b'\x00\x00\x00\x00\x00' > > or five null bytes. Note that this is an immutable type, so you cannot > go in later and say For the bytes to actually be a 'list of integers', you need to pass it an iterable, ex: >>> bytes([5, 6, 1, 3]) b'\x05\x06\x01\x03' - From help(bytes): | bytes(iterable_of_ints) -> bytes | bytes(string, encoding[, errors]) -> bytes | bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer | bytes(memory_view) -> bytes Looks like you're using the fourth when you want the first, possibly? - -- Corey Richardson -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJN0tF1AAoJEAFAbo/KNFvp41AH/1l2zR6XVOJ0xM7s2P+PDYZX OAhmi19hFEP0zQoWiW3TiMEVPlaqgtipPCp1t+jTeNNN3F+H4NG2DHJJZ3dPDr2J CpABQKyS4MJQTUxhCIlXqAaA2I1pejzAv6fwsF66/zPFmyaTAJLDP+3WMQvCUUoZ 5A3qHgHNp6vBHXd13RNdQStLeprfQptA+z6XdiJPos348ecRj/u9id7v28dwxxsm d9WA6oYwJ+Y/NcG2OP0Flyp3Zc3hymVsv5vhmhG2+EiIrxMn95k8ImsKLEhvUW3a 72CxlE6EaOMD4MuWyeGMS33c0vHwtAvEIE7M56R2FAl8EsUFwP2swaij0tEiemg= =8MRV -----END PGP SIGNATURE----- From drsalists at gmail.com Tue May 17 15:53:11 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 17 May 2011 12:53:11 -0700 Subject: ipython prompt does not appear in windows In-Reply-To: References: Message-ID: Try running ipython in a cmd.exe. If that works, it almost certainly means that the I/O is going directly to video RAM instead of through a disciplined API. On Tue, May 17, 2011 at 12:00 AM, rusi wrote: > If I use ipython under emacs on linux it works (at least basic REPL) > ie I can type an expression and I get a result followed by a prompt > > On windows ipython works at the shell. > Plain python works in emacs as well. > > But inside emacs I dont see a prompt in ipython although I see it in > python. > I have to type an expression and then the prompt appears. > > Any clues? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrmakent at gmail.com Tue May 17 16:10:11 2011 From: mrmakent at gmail.com (Michael Kent) Date: Tue, 17 May 2011 13:10:11 -0700 (PDT) Subject: portable multiprocessing code In-Reply-To: Message-ID: <216bc8df-560c-4417-935f-5421c2a495fe@glegroupsg2000goo.googlegroups.com> You could also install Python 2.7 on that RedHat machine. It can be done without interfering with the 2.5 that RedHat depends on. From mrmakent at gmail.com Tue May 17 16:10:11 2011 From: mrmakent at gmail.com (Michael Kent) Date: Tue, 17 May 2011 13:10:11 -0700 (PDT) Subject: portable multiprocessing code In-Reply-To: Message-ID: <216bc8df-560c-4417-935f-5421c2a495fe@glegroupsg2000goo.googlegroups.com> You could also install Python 2.7 on that RedHat machine. It can be done without interfering with the 2.5 that RedHat depends on. From felipe.bastosn at gmail.com Tue May 17 16:19:10 2011 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Tue, 17 May 2011 17:19:10 -0300 Subject: Python 3.x and bytes In-Reply-To: <4DD2D89D.4000303@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> Message-ID: This piece of code works fine for me: > >>> somevar = bytes() > >>> somevar > '' > >>> somevar.replace(b'', b'10') > '10' > >>> somevar > '' > >>> somevar = somevar.replace(b'', b'10') > >>> somevar > '10' > >>> somevar2 = bytes(b'10'*2) > >>> somevar2 > '1010' > >>> somevar2 = somevar2.replace(b'01', b'57'*3) > >>> somevar2 > '15757570' > > They're unmutable, but replace deals with it. 2011/5/17 Ethan Furman > Felipe Bastos Nunes wrote: > > 2011/5/17 Ethan Furman wrote: >> >>> >>> In Python 3 one can say >>> >>> --> huh = bytes(5) >>> >>> Since the bytes type is actually a list of integers, I would have >>> expected this to have huh being a bytestring with one element -- the >>> integer 5. Actually, what you get is: >>> >>> --> huh >>> b'\x00\x00\x00\x00\x00' >>> >>> or five null bytes. Note that this is an immutable type, so you >>> cannot go in later and say >>> >>> --> huh[3] = 9 >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: 'bytes' object does not support item assignment >>> >>> >>> So, out of curiosity, does anyone actually use this, um, feature? >>> >> > > >> They accept .replace(b"00", b"12") for example. >> > > So they do. Although that particular example doesn't work since b'0' is > the integer 48... > > --> huh.replace(b'00',b'12') > > b'\x00\x00\x00\x00\x00' > > > The big question, though, is would you do it this way: > > some_var = bytes(23).replace(b'\x00', b'a') > > or this way? > > some_var = bytes(b'a' * 23) > > ~Ethan~ > -- Felipe Bastos Nunes -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue May 17 16:20:45 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 May 2011 13:20:45 -0700 Subject: Python 3.x and bytes In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: <4DD2D89D.4000303@stoneleaf.us> Felipe Bastos Nunes wrote: > 2011/5/17 Ethan Furman wrote: >> >> In Python 3 one can say >> >> --> huh = bytes(5) >> >> Since the bytes type is actually a list of integers, I would have >> expected this to have huh being a bytestring with one element -- the >> integer 5. Actually, what you get is: >> >> --> huh >> b'\x00\x00\x00\x00\x00' >> >> or five null bytes. Note that this is an immutable type, so you >> cannot go in later and say >> >> --> huh[3] = 9 >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: 'bytes' object does not support item assignment >> >> >> So, out of curiosity, does anyone actually use this, um, feature? > > They accept .replace(b"00", b"12") for example. So they do. Although that particular example doesn't work since b'0' is the integer 48... --> huh.replace(b'00',b'12') b'\x00\x00\x00\x00\x00' The big question, though, is would you do it this way: some_var = bytes(23).replace(b'\x00', b'a') or this way? some_var = bytes(b'a' * 23) ~Ethan~ From andy at earthsong.free-online.co.uk Tue May 17 16:25:31 2011 From: andy at earthsong.free-online.co.uk (andy baxter) Date: Tue, 17 May 2011 21:25:31 +0100 Subject: Cartoonify Myself In-Reply-To: <4DD2CBFC.4070109@gmail.com> References: <4DD2CBFC.4070109@gmail.com> Message-ID: <4DD2D9BB.5080405@earthsong.free-online.co.uk> On 17/05/11 20:26, Chris M. Bartos wrote: > Hi, > > Is there a Python module that can "cartoonify" a picture of myself? > There's got to be an algorithm out there somewhere, right? If there is > a way to cartoon a single picture, could you cartoonify a video, too? > > Thanks for your help. > > > Chris > You could have a look at the python automation module for the gimp (a free software image editor). See e.g.: http://starryalley.homelinux.net/blog/index.php?/archives/1248-Star-Trail-Automation-script-using-python-gimp.html From karim.liateni at free.fr Tue May 17 16:26:13 2011 From: karim.liateni at free.fr (Karim) Date: Tue, 17 May 2011 22:26:13 +0200 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD1C9D5.4070206@gmail.com> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD1C9D5.4070206@gmail.com> Message-ID: <4DD2D9E5.1040308@free.fr> On 05/17/2011 03:05 AM, Andrew Berg wrote: > On 2011.05.16 02:26 AM, Karim wrote: >> Use regular expression for bad HTLM or beautifulSoup (google it), below >> a exemple to extract all html links: >> >> linksList = re.findall('.*?',htmlSource) >> for link in linksList: >> print link > I was afraid I might have to use regexes (mostly because I could never > understand them). > Even the BeautifulSoup website itself admits it's awful with Python 3 - > only the admittedly broken 3.1.0 will work with Python 3 at all. > ElementTree doesn't seem to have been updated in a long time, so I'll > assume it won't work with Python 3. > lxml looks promising, but it doesn't say anywhere whether it'll work on > Python 3 or not, which is puzzling since the latest release was only a > couple months ago. > > Actually, if I'm going to use regex, I might as well try to implement > Versions* in Python. > > Thanks for the answers! > > *http://en.totalcmd.pl/download/wfx/net/Versions (original, made for > Total Commander) and > https://addons.mozilla.org/en-US/firefox/addon/versions-wfx_versions/ > (clone implemented as a Firefox add-on; it's so wonderful, I even wrote > the docs for it!) Andrew, I wrote a class with HMLTParser to get only one link for a given project, cf below: 73 class ResultsLinkParser(HTMLParser.HTMLParser): 74 """Class ResultsLinkParser inherits form HTMLParser to extract 75 the original 'Submission date' of the a bug. 76 This customized parser will deals with the 'View Defect' HTML 77 page from Clear DDTS. 78 """ 79 def __init__(self): 80 HTMLParser.HTMLParser.__init__(self) 81 self._link = None 82 83 def handle_starttag(self, tag, attrs): 84 """Implement standard class HTMLParser customizing method.""" 85 if tag == 'frame': 86 try: 87 attributes = dict(attrs) 88 if attributes['name'] == 'indexframe': 89 self._link = attributes['src'] 90 except KeyError, e: 91 print("""WARNING: Attribute '{keyname}' from frame tag 92 in QueryResult page does not exist!""".format(keyname=e)) 93 94 def link(self): 95 """Return the html link of the query results page.""" 96 return self._link You can use it and just modified it to get the latest just add some code (and change the tag 'name' of my example) to compare revision number with max and keep the max to compare it to the next value. I let you add this little code just create self._revision = None in the __init__(self) which hold the current max revision. After parser.feed() you can get the value by parser._revision or a public parser.revision() method to get the value. Cheers Karim From dje at google.com Tue May 17 16:35:27 2011 From: dje at google.com (Doug Evans) Date: Tue, 17 May 2011 13:35:27 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 6:26 AM, Ruben Van Boxem wrote: > Wow, I think I have a partial solution. Delving into the Python docs, > for example here: > http://docs.python.org/using/windows.html#finding-modules, you can see > that PYTHONPATH is used first, then the Windows registry, then > PYTHONHOME, then some default relative paths. I placed the python > scripts all in the directory structure like so: > > /bin/gdb > /bin/Lib/ > /bin/python27.dll > > This works, even without any manual PYTHONPATH intervention. Problem > is though, that as soon as someone has a PYTHONPATH environment > variable from a (incompatible) Python installation (think different > bitness or version 3.x instead of 2.7.1), I cannot predict what will > go wrong. This problem originates in Python's way of filling in the > search path (sys.path). A true solution in the GDB case to prevent > this collision of an incompatible PYTHONPATH would be that GDB sets an > internal PYTHONPATH as directed by configure, uses that to load its > Python internals, and allows the GDB child processes (apps being > debugged) to use the environment PYTHONPATH. For now, I have a > functional installation, but it will break as soon as someone installs > Python on their system. What if the user *wants* gdb's python to use $PYTHONPATH from his/her environment? To handle *this* case, *and* the case of an incompatible python installation using $PYTHONPATH, there is the $GDB_PYTHONPATH proposal (see earlier email for details). It feels problematic to decide at configure time whether there will or will not be an incompatible python at runtime. [I realize you have subsequent messages. Just replying in sequence.] From felipe.bastosn at gmail.com Tue May 17 16:50:00 2011 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Tue, 17 May 2011 17:50:00 -0300 Subject: Python 3.x and bytes In-Reply-To: <4DD2D175.30506@aim.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com> Message-ID: Mine bytes constructor when useing Corey's advice give's me a string instead of a b''... 2011/5/17 Corey Richardson > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 05/17/2011 02:47 PM, Ethan Furman wrote: > > In Python 3 one can say > > > > --> huh = bytes(5) > > > > Since the bytes type is actually a list of integers, I would have > > expected this to have huh being a bytestring with one element -- the > > integer 5. Actually, what you get is: > > > > --> huh > > b'\x00\x00\x00\x00\x00' > > > > or five null bytes. Note that this is an immutable type, so you cannot > > go in later and say > > For the bytes to actually be a 'list of integers', you need to pass it > an iterable, ex: > >>> bytes([5, 6, 1, 3]) > b'\x05\x06\x01\x03' > > - From help(bytes): > | bytes(iterable_of_ints) -> bytes > | bytes(string, encoding[, errors]) -> bytes > | bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer > | bytes(memory_view) -> bytes > > Looks like you're using the fourth when you want the first, possibly? > > - -- > Corey Richardson > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.17 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iQEcBAEBAgAGBQJN0tF1AAoJEAFAbo/KNFvp41AH/1l2zR6XVOJ0xM7s2P+PDYZX > OAhmi19hFEP0zQoWiW3TiMEVPlaqgtipPCp1t+jTeNNN3F+H4NG2DHJJZ3dPDr2J > CpABQKyS4MJQTUxhCIlXqAaA2I1pejzAv6fwsF66/zPFmyaTAJLDP+3WMQvCUUoZ > 5A3qHgHNp6vBHXd13RNdQStLeprfQptA+z6XdiJPos348ecRj/u9id7v28dwxxsm > d9WA6oYwJ+Y/NcG2OP0Flyp3Zc3hymVsv5vhmhG2+EiIrxMn95k8ImsKLEhvUW3a > 72CxlE6EaOMD4MuWyeGMS33c0vHwtAvEIE7M56R2FAl8EsUFwP2swaij0tEiemg= > =8MRV > -----END PGP SIGNATURE----- > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 17 16:51:31 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 14:51:31 -0600 Subject: Python 3.x and bytes In-Reply-To: <4DD2D175.30506@aim.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com> Message-ID: On Tue, May 17, 2011 at 1:50 PM, Corey Richardson wrote: > - From help(bytes): > ?| ?bytes(iterable_of_ints) -> bytes > ?| ?bytes(string, encoding[, errors]) -> bytes > ?| ?bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer > ?| ?bytes(memory_view) -> bytes > > Looks like you're using the fourth when you want the first, possibly? Nope, he's using the fifth form, bytes(int), which is listed in the PEP but not in the help. From dje at google.com Tue May 17 16:52:13 2011 From: dje at google.com (Doug Evans) Date: Tue, 17 May 2011 13:52:13 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 9:11 AM, Ruben Van Boxem wrote: > I am sorry for the repeated messages that no one cares about, but I > may have discovered GDB in its current form already allows what I > want: I tried to figure out what exact paths the snake in gdb was > using to search for its modules, and came up with this: > (gdb) python import sys > (gdb) python print sys.path > ['m:\\development\\mingw64\\share\\gdb/python', > 'M:\\Development\\mingw64\\bin\\python27.zip', > 'M:\\Development\\mingw64\\bin\\DLLs', > 'M:\\Development\\mingw64\\bin\\lib', > 'M:\\Development\\mingw64\\bin\\lib\\plat-win', > 'M:\\Development\\mingw64\\bin\\lib\\lib-tk', > 'M:\\Development\\mingw64\\bin', > 'M:\\Development\\mingw64\\bin\\lib\\site-packages'] > > This means that every python command within gdb searches > /share/gdb/python FIRST (even before an environment's > PYTHONPATH), alleviating any concerns or problems I or anyone would > have with another python installation, as this apparently built-in > path comes up first. All I, or anyone interested in doing this kind of > thing, have to do is copy all the python scripts from the Windows > installation's Lib directory to the /share/gdb/python > directory. > > I don't know where this path comes from, but it is quite handy, and > makes this whole discussion ?moot for Python people. Only "issue" that > I'll have to work around is the --with-python-includes and > --with-python-libs that are missing, using either manual > CFLAGS/LDFLAGS or a variant of your script. IMO *if* gdb wanted to support people adding files to *its* /share/gdb directory, more thought is needed - e.g. maybe document a "site" directory for such files. Dunno. IMO we certainly don't want to formally allow folks to willy-nilly put anything there - no guarantees a future release might add something that collides with something the user put there. If and until then, you're probably pretty safe if you put everything in a subdirectory with a unique enough name, if you really wanted to go this route. Btw, there is the system.gdbinit file which sites *are* free to customize. E.g., configure --with-system-gdbinit=/share/gdb/system.gdbinit. You can put whatever you want in that file. E.g., you could add a directory to python's sys.path. [Technically speaking, the path /share/gdb/system.gdbinit goes against what I just said, but IMO this name is safe.] From ian.g.kelly at gmail.com Tue May 17 16:52:43 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 14:52:43 -0600 Subject: Python 3.x and bytes In-Reply-To: <4DD2D89D.4000303@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> Message-ID: On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: > The big question, though, is would you do it this way: > > some_var = bytes(23).replace(b'\x00', b'a') > > or this way? > > some_var = bytes(b'a' * 23) Actually, I would just do it this way: some_var = b'a' * 23 That's already a bytes object. Passing it into the constructor is redundant. From mail2fei at gmail.com Tue May 17 16:55:34 2011 From: mail2fei at gmail.com (Fei) Date: Tue, 17 May 2011 13:55:34 -0700 (PDT) Subject: python logging Message-ID: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> where is default logging file on Mac? I saw lots of app just import logging, and begins to logging.info(...) etc. I'm not sure where to look at the logging configuration to figure out the log location. I just get in touch of python about 1month ago, and I appreciate your help. From ethan at stoneleaf.us Tue May 17 16:55:36 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 May 2011 13:55:36 -0700 Subject: Python 3.x and bytes In-Reply-To: <4DD2D175.30506@aim.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com> Message-ID: <4DD2E0C8.2090101@stoneleaf.us> Corey Richardson wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 05/17/2011 02:47 PM, Ethan Furman wrote: >> In Python 3 one can say >> >> --> huh = bytes(5) >> >> Since the bytes type is actually a list of integers, I would have >> expected this to have huh being a bytestring with one element -- the >> integer 5. Actually, what you get is: >> >> --> huh >> b'\x00\x00\x00\x00\x00' >> >> or five null bytes. Note that this is an immutable type, so you cannot >> go in later and say > > For the bytes to actually be a 'list of integers', you need to pass it > an iterable, ex: >>>> bytes([5, 6, 1, 3]) > b'\x05\x06\x01\x03' Not so. --> huh = b'abcedfg' --> huh[3] 101 It's a list of int's. > - From help(bytes): > | bytes(iterable_of_ints) -> bytes > | bytes(string, encoding[, errors]) -> bytes > | bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer > | bytes(memory_view) -> bytes > > Looks like you're using the fourth when you want the first, possibly? Nope. Apparently, it's not well documented. If you check PEP 358 you'll find it. ~Ethan~ From wolfram.hinderer at googlemail.com Tue May 17 17:04:50 2011 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Tue, 17 May 2011 14:04:50 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> Message-ID: <80ba3b5e-34c1-420a-aade-9c1996d0239e@u26g2000vby.googlegroups.com> On 17 Mai, 20:56, geremy condra wrote: > On Tue, May 17, 2011 at 10:19 AM, Jussi Piitulainen > > wrote: > > geremy condra writes: > > >> or O(1): > > >> ? = (1 + sqrt(5)) / 2 > >> def fib(n): > >> ? ? numerator = (?**n) - (1 - ?)**n > >> ? ? denominator = sqrt(5) > >> ? ? return round(numerator/denominator) > > >> Testing indicates that it's faster somewhere around 7 or so. > > > And increasingly inaccurate from 71 on. > > Yup. That's floating point for you. For larger values you could just > add a linear search at the bottom using the 5f**2 +/- 4 rule, which > would still be quite fast out to about 10 times that. The decimal > module gets you a tiny bit further, and after that it's time to just > use Dijkstra's, like rusi suggested. In any event, I still think this > formulation is the most fun ;). I think you can write it even more funny def fib(n): return round(((.5 + .5 * 5 ** .5) ** n - (.5 - .5 * 5 ** .5) ** n) * 5 ** -.5) ;-) From ian.g.kelly at gmail.com Tue May 17 17:18:14 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 15:18:14 -0600 Subject: portable multiprocessing code In-Reply-To: References: Message-ID: On Tue, May 17, 2011 at 9:14 AM, Eric Frederich wrote: > I have written some code using Python 2.7 but I'd like these scripts > to be able to run on Red Hat 5's 2.4.3 version of Python which doesn't > have multiprocessing. > I can try to import multiprocessing and set a flag as to whether it is > available. ?Then I can create a Queue.Queue instead of a > multiprocessing.Queue for the arg_queue and result_queue. > Without actually trying this yet it seems like things would work okay > except for the Worker class. ?It seems I can conditionally replace > multiprocessing.Queue with Queue.Queue, but is there anything to > replace multiprocessing.Process with? Yes, threading.Thread. Pro: Since the multiprocessing module is designed to be a drop-in replacement for the threading module, it should also be pretty straight-forward to go in the reverse direction. Con: You won't have true concurrency because of the GIL. Cheers, Ian From kb1pkl at aim.com Tue May 17 17:27:04 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Tue, 17 May 2011 17:27:04 -0400 Subject: Python 3.x and bytes In-Reply-To: <4DD2E0C8.2090101@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com> <4DD2E0C8.2090101@stoneleaf.us> Message-ID: <4DD2E828.9000502@aim.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/17/2011 04:55 PM, Ethan Furman wrote: > Apparently, it's not well documented. If you check PEP 358 > you'll find it. > > ~Ethan~ Agreed, it looks like it should be mentioned in bytes.__doc__ about the single-integer argument. - -- Corey Richardson -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJN0ugoAAoJEAFAbo/KNFvphIsH/3LOzN8+D98D0+nm6m8sfCUC f+KfgTLITAmecYOuOBym1snl6qj2JnZkGYRW6M2O5NV8arNJ1dHty3dPbwMeKdfH 67m2a0UgHcwqv5M5VGNQQYTQ03Mzqy+A84MMvBKWUQ0nxZRCkPMtdxm2T4/UEVLx uelDPOdOWB1PDmc3sNUDPovXeOFlTKmcQ5yfolyrdLFU/KmbamgRSltpBFEbyInO 4KI3hoGka4PVaaBLf9QPjFC6tBu4QdQ4UTnWD3sy78LA3KPsa5MEpXFXctwJkJ+O q2Y7SWOPJDz19V+MT87Aeu69YpzxWwkp4fBflNxYaQUoJqNlzIfRkavUzZ0zfMQ= =E2qm -----END PGP SIGNATURE----- From nirina.raseliarison at gmail.com Tue May 17 17:31:52 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Wed, 18 May 2011 00:31:52 +0300 Subject: test_argparse.py FAILED (failures=6) Message-ID: ====================================================================== FAIL: test_failures_many_groups_listargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ====================================================================== FAIL: test_failures_many_groups_sysargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ====================================================================== FAIL: test_failures_no_groups_listargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ====================================================================== FAIL: test_failures_no_groups_sysargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ====================================================================== FAIL: test_failures_one_group_listargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ====================================================================== FAIL: test_failures_one_group_sysargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ---------------------------------------------------------------------- Ran 1599 tests in 6.298s FAILED (failures=6) Traceback (most recent call last): File "Lib/test/test_argparse.py", line 4681, in test_main() File "Lib/test/test_argparse.py", line 4673, in test_main support.run_unittest(__name__) File "/mnt/sda14/pack_build/Python-3.2.1rc1/Lib/test/support.py", line 1184, in run_unittest _run_suite(suite) File "/mnt/sda14/pack_build/Python-3.2.1rc1/Lib/test/support.py", line 1167, in _run_suite raise TestFailed(err) test.support.TestFailed: multiple errors occurred -- nirinA From nirina.raseliarison at gmail.com Tue May 17 17:32:16 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Wed, 18 May 2011 00:32:16 +0300 Subject: test_ftplib.py failed with segmentation fault,gcc4.6.0,glibc-2.13 Message-ID: hi all, i can't get connected to bugs.python.org so here my make test results. make test aborted when running test_ftplib. and running # ./python Lib/test/test_ftplib.py Segmentation fault with this kernel message: [ 2166.927138] python[12142]: segfault at 1d81 ip 00007f7e733a09c2 sp 00007f7e701038a0 error 4 in libc-2.13.so[7f7e73328000+19b000] however, i just tested using ftplib without tls and it worked fine. below the error log == CPython 3.2.1rc1 (default, May 17 2011, 22:01:34) [GCC 4.6.0] == Linux-2.6.38.wmodem-x86_64-Intel-R-_Pentium-R-_Dual__CPU__E2180__ at _2.00GHz-with-slackware-12.2.0 little-endian == /mnt/sda14/pack_build/Python-3.2.1rc1/build/test_python_12247 Testing with flags: sys.flags(debug=0, division_warning=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0) test_abort (__main__.TestFTPClass) ... ok test_acct (__main__.TestFTPClass) ... ok test_all_errors (__main__.TestFTPClass) ... ok test_delete (__main__.TestFTPClass) ... ok test_dir (__main__.TestFTPClass) ... ok test_exceptions (__main__.TestFTPClass) ... ok test_getwelcome (__main__.TestFTPClass) ... ok test_login (__main__.TestFTPClass) ... ok test_makepasv (__main__.TestFTPClass) ... ok test_makeport (__main__.TestFTPClass) ... ok test_mkd (__main__.TestFTPClass) ... ok test_nlst (__main__.TestFTPClass) ... ok test_parse257 (__main__.TestFTPClass) ... ok test_pwd (__main__.TestFTPClass) ... ok test_quit (__main__.TestFTPClass) ... ok test_rename (__main__.TestFTPClass) ... ok test_retrbinary (__main__.TestFTPClass) ... ok test_retrbinary_rest (__main__.TestFTPClass) ... ok test_retrlines (__main__.TestFTPClass) ... ok test_rmd (__main__.TestFTPClass) ... ok test_sanitize (__main__.TestFTPClass) ... ok test_set_pasv (__main__.TestFTPClass) ... ok test_size (__main__.TestFTPClass) ... ok test_storbinary (__main__.TestFTPClass) ... ok test_storbinary_rest (__main__.TestFTPClass) ... ok test_storlines (__main__.TestFTPClass) ... ok test_voidcmd (__main__.TestFTPClass) ... ok test_with_statement (__main__.TestFTPClass) ... ok testTimeoutConnect (__main__.TestTimeouts) ... ok testTimeoutDefault (__main__.TestTimeouts) ... ok testTimeoutDifferentOrder (__main__.TestTimeouts) ... ok testTimeoutDirectAccess (__main__.TestTimeouts) ... ok testTimeoutNone (__main__.TestTimeouts) ... ok testTimeoutValue (__main__.TestTimeouts) ... ok test_abort (__main__.TestTLS_FTPClassMixin) ... *** glibc detected *** ./python: free(): invalid next size (normal): 0x00007f38f0018cf0 *** ======= Backtrace: ========= /lib64/libc.so.6(+0x78f85)[0x7f38fa1e7f85] /lib64/libc.so.6(cfree+0x73)[0x7f38fa1ebd93] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(CRYPTO_free+0x3d)[0x7f38f940b3aa] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(+0x12f407)[0x7f38f9492407] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(RSA_private_decrypt+0x45)[0x7f38f9429979] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(ssl3_get_client_key_exchange+0x2a4)[0x7f38f93e7060] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(ssl3_accept+0xa0b)[0x7f38f93e40d2] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(SSL_do_handshake+0x98)[0x7f38f9400021] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(+0x77f69)[0x7f38f93daf69] ./python(PyEval_EvalFrameEx+0x709c)[0x45d4ec] ./python(PyEval_EvalCodeEx+0x696)[0x456186] ./python(PyEval_EvalFrameEx+0x6d83)[0x45d1d3] ./python(PyEval_EvalFrameEx+0x6e9e)[0x45d2ee] ./python(PyEval_EvalCodeEx+0x696)[0x456186] ./python(PyEval_EvalFrameEx+0x6d83)[0x45d1d3] ./python(PyEval_EvalFrameEx+0x6e9e)[0x45d2ee] ./python(PyEval_EvalCodeEx+0x696)[0x456186] ./python(PyEval_EvalFrameEx+0x6d83)[0x45d1d3] ./python(PyEval_EvalCodeEx+0x696)[0x456186] ./python(PyEval_EvalFrameEx+0x6d83)[0x45d1d3] ./python(PyEval_EvalFrameEx+0x6e9e)[0x45d2ee] ======= Memory map: ======== 00400000-00586000 r-xp 00000000 08:0e 54225 /mnt/sda14/pack_build/Python-3.2.1rc1/python 00786000-007cf000 rw-p 00186000 08:0e 54225 /mnt/sda14/pack_build/Python-3.2.1rc1/python 007cf000-007ed000 rw-p 00000000 00:00 0 00b9c000-0111a000 rw-p 00000000 00:00 0 [heap] 7f38f0000000-7f38f0022000 rw-p 00000000 00:00 0 7f38f0022000-7f38f4000000 ---p 00000000 00:00 0 7f38f6537000-7f38f654c000 r-xp 00000000 08:0b 224 /usr/lib64/libgcc_s.so.1 7f38f654c000-7f38f674b000 ---p 00015000 08:0b 224 /usr/lib64/libgcc_s.so.1 7f38f674b000-7f38f674c000 rw-p 00014000 08:0b 224 /usr/lib64/libgcc_s.so.1 7f38f674c000-7f38f674d000 ---p 00000000 00:00 0 7f38f674d000-7f38f6f4d000 rw-p 00000000 00:00 0 7f38f6f4d000-7f38f6f64000 r-xp 00000000 08:0b 117661 /lib64/libresolv-2.13.so 7f38f6f64000-7f38f7164000 ---p 00017000 08:0b 117661 /lib64/libresolv-2.13.so 7f38f7164000-7f38f7165000 r--p 00017000 08:0b 117661 /lib64/libresolv-2.13.so 7f38f7165000-7f38f7166000 rw-p 00018000 08:0b 117661 /lib64/libresolv-2.13.so 7f38f7166000-7f38f7168000 rw-p 00000000 00:00 0 7f38f7168000-7f38f716f000 r-xp 00000000 08:0b 117654 /lib64/libnss_dns-2.13.so 7f38f716f000-7f38f736e000 ---p 00007000 08:0b 117654 /lib64/libnss_dns-2.13.so 7f38f736e000-7f38f736f000 r--p 00006000 08:0b 117654 /lib64/libnss_dns-2.13.so 7f38f736f000-7f38f7370000 rw-p 00007000 08:0b 117654 /lib64/libnss_dns-2.13.so 7f38f7370000-7f38f737c000 r-xp 00000000 08:0b 117655 /lib64/libnss_files-2.13.so 7f38f737c000-7f38f757b000 ---p 0000c000 08:0b 117655 /lib64/libnss_files-2.13.so 7f38f757b000-7f38f757c000 r--p 0000b000 08:0b 117655 /lib64/libnss_files-2.13.so 7f38f757c000-7f38f757d000 rw-p 0000c000 08:0b 117655 /lib64/libnss_files-2.13.so 7f38f757d000-7f38f7587000 r-xp 00000000 08:0e 54307 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/array.cpython-32m.so 7f38f7587000-7f38f7786000 ---p 0000a000 08:0e 54307 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/array.cpython-32m.so 7f38f7786000-7f38f7789000 rw-p 00009000 08:0e 54307 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/array.cpython-32m.so 7f38f7789000-7f38f7826000 r-xp 00000000 08:0e 54337 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/unicodedata.cpython-32m.so 7f38f7826000-7f38f7a26000 ---p 0009d000 08:0e 54337 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/unicodedata.cpython-32m.so 7f38f7a26000-7f38f7a3b000 rw-p 0009d000 08:0e 54337 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/unicodedata.cpython-32m.so 7f38f7a3b000-7f38f7a3d000 r-xp 00000000 08:0e 54328 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/atexit.cpython-32m.so 7f38f7a3d000-7f38f7c3c000 ---p 00002000 08:0e 54328 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/atexit.cpython-32m.so 7f38f7c3c000-7f38f7c3d000 rw-p 00001000 08:0e 54328 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/atexit.cpython-32m.so 7f38f7c3d000-7f38f7c40000 r-xp 00000000 08:0e 54361 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_posixsubprocess.cpython-32m.so 7f38f7c40000-7f38f7e3f000 ---p 00003000 08:0e 54361 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_posixsubprocess.cpython-32m.so 7f38f7e3f000-7f38f7e40000 rw-p 00002000 08:0e 54361 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_posixsubprocess.cpython-32m.so 7f38f7e40000-7f38f7e51000 r-xp 00000000 08:0e 54325 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_pickle.cpython-32m.so 7f38f7e51000-7f38f8050000 ---p 00011000 08:0e 54325 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_pickle.cpython-32m.so 7f38f8050000-7f38f8054000 rw-p 00010000 08:0e 54325 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_pickle.cpython-32m.so 7f38f8054000-7f38f8063000 r-xp 00000000 08:0b 256 /lib64/libbz2.so.1.0.4 7f38f8063000-7f38f8262000 ---p 0000f000 08:0b 256 /lib64/libbz2.so.1.0.4 7f38f8262000-7f38f8264000 rw-p 0000e000 08:0b 256 /lib64/libbz2.so.1.0.4 7f38f8264000-7f38f826a000 r-xp 00000000 08:0e 54397 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/bz2.cpython-32m.so 7f38f826a000-7f38f846a000 ---p 00006000 08:0e 54397 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/bz2.cpython-32m.so 7f38f846a000-7f38f846c000 rw-p 00006000 08:0e 54397 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/bz2.cpython-32m.so 7f38f846c000-7f38f846e000 r-xp 00000000 08:0e 54341 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/grp.cpython-32m.so 7f38f846e000-7f38f866e000 ---p 00002000 08:0e 54341 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/grp.cpython-32m.so 7f38f866e000-7f38f866f000 rw-p 00002000 08:0e 54341 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/grp.cpython-32m.so 7f38f866f000-7f38f8730000 rw-p 00000000 00:00 0 7f38f8730000-7f38f8733000 r-xp 00000000 08:0e 54339 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/fcntl.cpython-32m.so 7f38f8733000-7f38f8933000 ---p 00003000 08:0e 54339 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/fcntl.cpython-32m.so 7f38f8933000-7f38f8935000 rw-p 00003000 08:0e 54339 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/fcntl.cpython-32m.so 7f38f8935000-7f38f8939000 r-xp 00000000 08:0e 54315 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/time.cpython-32m.so 7f38f8939000-7f38f8b39000 ---p 00004000 08:0e 54315 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/time.cpython-32m.so 7f38f8b39000-7f38f8b3b000 rw-p 00004000 08:0e 54315 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/time.cpython-32m.so 7f38f8b3b000-7f38f8b3f000 r-xp 00000000 08:0e 54345 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/select.cpython-32m.so 7f38f8b3f000-7f38f8d3f000 ---p 00004000 08:0e 54345 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/select.cpython-32m.so 7f38f8d3f000-7f38f8d41000 rw-p 00004000 08:0e 54345 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/select.cpython-32m.so 7f38f8d41000-7f38f8d55000 r-xp 00000000 08:0b 219 /usr/lib64/libz.so.1.2.3 7f38f8d55000-7f38f8f54000 ---p 00014000 08:0b 219 /usr/lib64/libz.so.1.2.3Aborted -- nirinA From nirina.raseliarison at gmail.com Tue May 17 17:32:19 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Wed, 18 May 2011 00:32:19 +0300 Subject: smtplib is broken when using TLS Message-ID: i think this has the same origin as the ftplib test failure. Python 3.2.1rc1 (default, May 17 2011, 22:01:34) [GCC 4.6.0] on linux2 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART >>> ================================ >>> send: 'ehlo [127.0.0.1]\r\n' reply: b'250-mx.google.com at your service, [41.188.13.184]\r\n' reply: b'250-SIZE 35882577\r\n' reply: b'250-8BITMIME\r\n' reply: b'250-STARTTLS\r\n' reply: b'250 ENHANCEDSTATUSCODES\r\n' reply: retcode (250); Msg: b'mx.google.com at your service, [41.188.13.184]\nSIZE 35882577\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES' send: 'STARTTLS\r\n' reply: b'220 2.0.0 Ready to start TLS\r\n' reply: retcode (220); Msg: b'2.0.0 Ready to start TLS' Traceback (most recent call last): File "/root/template_mail_text.py", line 49, in server.starttls() File "/usr/local/lib/python3.2/smtplib.py", line 649, in starttls self.sock = ssl.wrap_socket(self.sock, keyfile, certfile) File "/usr/local/lib/python3.2/ssl.py", line 509, in wrap_socket ciphers=ciphers) File "/usr/local/lib/python3.2/ssl.py", line 266, in __init__ raise x File "/usr/local/lib/python3.2/ssl.py", line 262, in __init__ self.do_handshake() File "/usr/local/lib/python3.2/ssl.py", line 441, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [Errno 1] _ssl.c:392: error:140943FC:SSL routines:SSL3_READ_BYTES:sslv3 alert bad record mac -- nirinA From nad at acm.org Tue May 17 17:46:32 2011 From: nad at acm.org (Ned Deily) Date: Tue, 17 May 2011 14:46:32 -0700 Subject: Having a problem getting python working... References: <6E09A0F4-B9A6-4C9F-874B-CB6E21EF7A45@gmail.com> Message-ID: In article <6E09A0F4-B9A6-4C9F-874B-CB6E21EF7A45 at gmail.com>, Chris Paton wrote: > Not sure if this is the right place to put this (forgive me for my ignorance, > I'm looking everywhere!). I'm having a problem getting IDLE working. I'm > working off Mac OSX 10.6.7 with Python 3.2 installed and I installed > Activetcl 8.5.9 as recommended. IDLE is still crashing at random moments - > loading, saving, typing, compiling... I tried to do a simple 'hello world' > but it kept crashing. There's no official report; I just get the spinning > beach ball then have to force quit. I'm quite new to all of this so any help > would be extremely appreciated. Need to get into this ASAP as I need to do > some stuff for my thesis project! Sorry for the late response but if you can document how to reproduce the crashes or have a crash report that would be great. But, first, are you sure you were using IDLE 3.2 and not the Apple-supplied IDLE 2.6 in OS X 10.6? The latter will definitely exhibit that behavior. If you are installed Python 3.2 from one of the python.org installers, IDLE 3.2 will be available in /Applications/Python 3.2/ or as /usr/local/bin/idle3.2. -- Ned Deily, nad at acm.org From debatem1 at gmail.com Tue May 17 17:59:06 2011 From: debatem1 at gmail.com (geremy condra) Date: Tue, 17 May 2011 14:59:06 -0700 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <80ba3b5e-34c1-420a-aade-9c1996d0239e@u26g2000vby.googlegroups.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <80ba3b5e-34c1-420a-aade-9c1996d0239e@u26g2000vby.googlegroups.com> Message-ID: On Tue, May 17, 2011 at 2:04 PM, Wolfram Hinderer wrote: > On 17 Mai, 20:56, geremy condra wrote: >> On Tue, May 17, 2011 at 10:19 AM, Jussi Piitulainen >> >> wrote: >> > geremy condra writes: >> >> >> or O(1): >> >> >> ? = (1 + sqrt(5)) / 2 >> >> def fib(n): >> >> ? ? numerator = (?**n) - (1 - ?)**n >> >> ? ? denominator = sqrt(5) >> >> ? ? return round(numerator/denominator) >> >> >> Testing indicates that it's faster somewhere around 7 or so. >> >> > And increasingly inaccurate from 71 on. >> >> Yup. That's floating point for you. For larger values you could just >> add a linear search at the bottom using the 5f**2 +/- 4 rule, which >> would still be quite fast out to about 10 times that. The decimal >> module gets you a tiny bit further, and after that it's time to just >> use Dijkstra's, like rusi suggested. In any event, I still think this >> formulation is the most fun ;). > > I think you can write it even more funny > > def fib(n): > ? ?return round(((.5 + .5 * 5 ** .5) ** n - ?(.5 - .5 * 5 ** .5) ** > n) * 5 ** -.5) > > ;-) Ok, that's amusing. It does hide the interaction with the golden ratio though, which is what I find so fascinating about the earlier one. Geremy Condra From rafadurancastaneda at gmail.com Tue May 17 18:00:58 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Wed, 18 May 2011 00:00:58 +0200 Subject: python logging In-Reply-To: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> Message-ID: <4DD2F01A.1000704@gmail.com> On 17/05/11 22:55, Fei wrote: > where is default logging file on Mac? I saw lots of app just import > logging, and begins to logging.info(...) etc. I'm not sure where to > look at the logging configuration to figure out the log location. > > I just get in touch of python about 1month ago, and I appreciate your > help. Looking at python docs you will find: http://docs.python.org/howto/logging.html#logging-basic-tutorial First example explains what you are asking. P.S.: Next time you may try to look for the info you need before asking From xahlee at gmail.com Tue May 17 18:26:42 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 17 May 2011 15:26:42 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively Message-ID: might be of interest. ?English Idiom in Unix: Directory Recursively? http://xahlee.org/comp/idiom_directory_recursively.html ------------------------------------------ English Idiom in Unix: Directory Recursively Xah Lee, 2011-05-17 Today, let's discuss something in the category of lingustics. You know how in unix tools, when you want to delete the whole directory and all sub-directories and files in it, it's referred as ?recursive?? For example, when you want to delete the whole dir in emacs, it prompts this message: ?Recursive delete of xx? (y or n) ?. (Note: to be able to delete whole dir in emacs in dired, you'll first need to turn it on. See: emacs dired tutorial.) Here's another example. A quote from ?rsync? man page: ? This would recursively transfer all files from the directory ? -r, --recursive recurse into directories This tells rsync to copy directories recursively. See also -- dirs (-d). ? Here's a quote from ?cp?'s man page: -R, -r, --recursive copy directories recursively and lots of other tools has a ?-r? option, and they all refer to it as ?recursive?. Though, if you think about it, it's not exactly a correct description. ?Recursive?, or ?recursion?, refers to a particular type of algorithm, or a implementation using that algorithm. Obviously, to process all directory's content does not necessarily mean it must be done by a recursive algorithm. A iteration can do it as well and it's easy to have the full behavior and properties in the result as a recursive approach, such as specifying depth order, level to dive into, etc. (because, dir is a tree, and recursive algorithm is useful for walking the tree data structure but is not necessary, because a tree can be laid out flat. Any path order taken by a recursive approach can be done by just enumerating the nodes in sequence. In fact, iteration approach can be faster and simpler in many aspects. (i wrote a article about this some 10 years ago, see: Trees and Indexes.) Note: this thought about tree and its nodes as a set of node addresses can be applied to any tree data structure, such as lisp's nested syntax, XML. See: Programing Language: Fundamental Problems of Lisp.) If you look at Windows or Mac OS X world, i don't think they ever refer to dealing with whole dir as ?recursive? in user interface. For example, in Windows Vista, while changing properties of a folder, it has this message: Apply changes to this folder only. Apply changes to this folder, subfolders and files. Note the second choice. In unix, it would say ?Apply changes to this folder recursively.? So, the word ?recursive? used in unixes may be technically incorrect, but more so, it's just not the right phrase. Because, we want to communicate whether the whole content of a directory are processed, not about certain algorithm or how it is implemented. A simple ?all the dir's branches/contents? or similar would be more apt. Recently i was chatting in Second Life with someone (Sleeves). She's typing, while i'm on voice. In part of our conversation, i said ?you sounded fine?. Note that it's technically incorrect, because she's typing, not on voice. So she didn't actually make any ?sound?. But to say ?you typed fine?, or ?you chatted fine?, won't get the message across. That's idiom. When you interpret a idiom logically, it doesn't make much sense, but people understand the particular phrase better anyway. I suspect the ?directory recursively? is also a idiom. It seems so natural and really gets the point across, without any ill effects. Even if the implementation actually used a iteration, it doesn't seems to matter. So the interesting question is, why this idiom works? Or, how it developed? I think, among programers (which all unix users are in the 1970s), every one knows the concept of recursion, and many unix tools on dir probably are implemented with a recursive algorithm. When you say ?? recursively?, the point gets across, because we all understand it, even when we are not actually talking about implementation. The phrase ?? directory recursively? is short and memorable, while ?? directory and all its contents? or ?? directory and all its branches? or ?? directory and all its sub-directories and files? are wordy and unwieldy. ? Idiocy Of Unix Copy Command Emacs Lisp Suggestion: Function to Copy/Delete a Directory Recursively How to rsync, unison, wget, curl Hunspell Tutorial Mac OS X Resource Fork and Command Line Tips ImageMagick Tutorial Making System Calls in Perl and Python Unix And Literary Correlation The Unix Pestilence To An Or Not To An On ?I? versus ?i? (capitalization of first person pronoun) On the Postposition of Conjunction in Penultimate Position of a Sequence What's Passive Voice? What's Aggressive Voice? Why You Should Avoid The Jargon ?Tail Recursion? Why You should Not Use The Jargon Lisp1 and Lisp2 Jargons of Info Tech Industry Xah From ethan at stoneleaf.us Tue May 17 18:28:23 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 May 2011 15:28:23 -0700 Subject: Python 3.x and bytes In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> Message-ID: <4DD2F687.9050809@stoneleaf.us> Ian Kelly wrote: > On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: >> The big question, though, is would you do it this way: >> >> some_var = bytes(23).replace(b'\x00', b'a') >> >> or this way? >> >> some_var = bytes(b'a' * 23) > > Actually, I would just do it this way: > > some_var = b'a' * 23 > > That's already a bytes object. Passing it into the constructor is redundant. Heh, good point. ~Ethan~ From ori.livneh at gmail.com Tue May 17 18:31:21 2011 From: ori.livneh at gmail.com (Ori L.) Date: Tue, 17 May 2011 15:31:21 -0700 (PDT) Subject: ipython prompt does not appear in windows References: Message-ID: See here for a workaround: https://bugs.launchpad.net/ipython/+bug/290228 First result on Google for the query "ipython emacs windows", BTW. On May 17, 3:00?am, rusi wrote: > If I use ipython under emacs on linux it works (at least basic REPL) > ie I can type an expression and I get a result followed by a prompt > > On windows ipython works at the shell. > Plain python works in emacs as well. > > But inside emacs I dont see a prompt in ipython although I see it in > python. > I have to type an expression and then the prompt appears. > > Any clues? From ian.g.kelly at gmail.com Tue May 17 18:55:55 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 16:55:55 -0600 Subject: python logging In-Reply-To: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> Message-ID: On Tue, May 17, 2011 at 2:55 PM, Fei wrote: > where is default logging file on Mac? I saw lots of app just import > logging, and begins to logging.info(...) etc. ?I'm not sure where to > look at the logging configuration to figure out the log location. There is no default log file. You're seeing that because logging only needs to be configured by the program once, not on a per-module basis. Thus most modules will just do import logging on the assumption that the configuration has already been performed somewhere else. If no logging configuration is done at all, then the logging statements will have no effect. From ian.g.kelly at gmail.com Tue May 17 19:20:12 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 17:20:12 -0600 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: On Tue, May 17, 2011 at 4:26 PM, Xah Lee wrote: > Though, if you think about it, it's not exactly a correct description. > ?Recursive?, or ?recursion?, refers to a particular type of algorithm, > or a implementation using that algorithm. Only when used as programming jargon. In mathematics, "recursive function" does *not* mean "a function implemented using a recursive algorithm". It's just a formal definition of a specific class of mathematical functions. As it turns out, "recursive" also has a non-technical definition, which again has nothing to do with algorithms except in the broadest sense: recursive adj. 1. pertaining to or using a rule or procedure that can be applied repeatedly (from dictionary.com) This definition fits the Unix usage perfectly. From rosuav at gmail.com Tue May 17 19:23:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 May 2011 09:23:40 +1000 Subject: best way to extract sentence from txt file In-Reply-To: References: Message-ID: On Wed, May 18, 2011 at 4:40 AM, Michiel Overtoom wrote: > Until then we have to guess, and my E.S.P. is notoriously bad. Roll d20 and add your ESP skill and your Wisdom modifier. The DC for this test is 20 if you're familiar with D&D, or 25 if you are not. Chris Angelico Dungeon Master From rosuav at gmail.com Tue May 17 19:42:54 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 May 2011 09:42:54 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: On Wed, May 18, 2011 at 8:26 AM, Xah Lee wrote: > ? ? ?Apply changes to this folder only. > ? ? ? ?Apply changes to this folder, subfolders and files. > > Note the second choice. In unix, it would say ?Apply changes to this > folder recursively.? I think this is more about the Windows and Mac philosophy to dumb things down at the expense of verbosity, than about Unix jargon. Archiving and compressing files using Phil Katz's PKZip utility uses the -r option to include all subdirectories; it's documented as "recurse subudirectories", which makes plenty of sense. (There's an equivalent utility from Info-ZIP in a lot of Linux distros, and it has the same option, listed as "recurse into directories".) Can you think of any other single word that clearly describes the action of tracing into all subdirectories? Even if it's not algorithmically accurate, it carries the meaning. The "mind-space" requirement is quite compact; you can ignore the "into subdirectories" part and just think "-r means recurse", whereas the alternative is "-r means files in this directory and all its subdirectories". Chris Angelico From gagsl-py2 at yahoo.com.ar Tue May 17 20:46:45 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 21:46:45 -0300 Subject: FW: help please References: <4DD29FF1.9090506@tysdomain.com> <1305661713.3831.1.camel@localhost.localdomain> Message-ID: En Tue, 17 May 2011 16:48:29 -0300, Albert Hopkins escribi?: > On Tue, 2011-05-17 at 10:18 -0600, Littlefield, Tyler wrote: >> Not to be pedantic or anything, and I may not be able to help >> regardless, but it looks like your space key is fixed, and I don't >> really care to pick through and try to play hangman with your message. > > I actually, at first glance, thought it was spam, ignored it, and was > wondering why people were replying to it :| I can't remember exactly in which release 'perfect English skills' were added to Python runtime requirements, could you please refresh my memory? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue May 17 20:47:06 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 21:47:06 -0300 Subject: cPickle -> invalid signature References: Message-ID: En Tue, 17 May 2011 15:26:53 -0300, Neal Becker escribi?: > Gabriel Genellina wrote: > >> En Tue, 17 May 2011 08:41:41 -0300, Neal Becker >> escribi?: >> >>> What does it mean when cPickle.load says: >>> RuntimeError: invalid signature >>> >>> Is binary format not portable? >> >> Are you sure that's the actual error message? >> I cannot find such message anywhere in the sources. >> The pickle format is quite portable, even cross-version. As a generic >> answer, make sure you open the file in binary mode, both when writing >> and >> reading. >> > > Yes, that's the message. > > Part of what is pickled is a numpy array. I am writing on a 32-bit > linux system > and reading on a 64-bit system. Reading on the 64-bit system is no > problem. > > Maybe the message comes from numpy's unpickling? Maybe, at least 'invalid signature' makes sense in Numpy. In that case, a better place to ask would be a numpy specific list, see http://www.scipy.org/Mailing_Lists -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue May 17 20:47:06 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 21:47:06 -0300 Subject: cPickle -> invalid signature References: Message-ID: En Tue, 17 May 2011 15:26:53 -0300, Neal Becker escribi?: > Gabriel Genellina wrote: > >> En Tue, 17 May 2011 08:41:41 -0300, Neal Becker >> escribi?: >> >>> What does it mean when cPickle.load says: >>> RuntimeError: invalid signature >>> >>> Is binary format not portable? >> >> Are you sure that's the actual error message? >> I cannot find such message anywhere in the sources. >> The pickle format is quite portable, even cross-version. As a generic >> answer, make sure you open the file in binary mode, both when writing >> and >> reading. >> > > Yes, that's the message. > > Part of what is pickled is a numpy array. I am writing on a 32-bit > linux system > and reading on a 64-bit system. Reading on the 64-bit system is no > problem. > > Maybe the message comes from numpy's unpickling? Maybe, at least 'invalid signature' makes sense in Numpy. In that case, a better place to ask would be a numpy specific list, see http://www.scipy.org/Mailing_Lists -- Gabriel Genellina From dmuchap001 at gmail.com Tue May 17 20:50:30 2011 From: dmuchap001 at gmail.com (john kode) Date: Tue, 17 May 2011 17:50:30 -0700 (PDT) Subject: Ed hardy, (tshirt$13, swim strunk$25, jean$30, handbag$34, cap$13, sunglass$12, shoes$25), Nike shoes:$32, Handbag:$35, NFL:$20, jean:$30, air force one shoes, lv, gucci, D&G, bbc, coachUGG boot:$50 Message-ID: Get Nike Shoes at Super Cheap Prices Discount Ed hardy tshirt (www.dmuch.com) Discount Ed hardy swimming suit (www.dmuch.com) Discount Ed hardy jean (www.dmuch.com) Discount Ed hardy shoes (www.dmuch.com) Discount Ed hardy handbag (www.dmuch.com) Discount Ed hardy other porduct (www.dmuch.com) Discount Nike air jordans (www.dmuch.com) Discount Nike Air Max 90 Sneakers (www.dmuch.com) Discount Nike Air Max 91 Supplier (www.dmuch.com) Discount Nike Air Max 95 Shoes Supplier (www.dmuch.com) Discount Nike Air Max 97 Trainers (www.dmuch.com) Discount Nike Air Max 2003 Wholesale (www.dmuch.com) Discount Nike Air Max 2004 Shoes Wholesale (www.dmuch.com) Discount Nike Air Max 2005 Shop (www.dmuch.com) Discount Nike Air Max 2006 Shoes Shop (www.dmuch.com) Discount Nike Air Max 360 Catalogs (www.dmuch.com) Discount Nike Air Max Ltd Shoes Catalogs (www.dmuch.com) Discount Nike Air Max Tn Men's Shoes (www.dmuch.com) Discount Nike Air Max Tn 2 Women's Shoes (www.dmuch.com) Discount Nike Air Max Tn 3 Customize (www.dmuch.com) Discount Nike Air Max Tn 4 Shoes Customize ( www.dmuch.com) Discount Nike Air Max Tn 6 Supply (www.dmuch.com) Discount Nike Shox NZ Shoes Supply (www.dmuch.com) Discount Nike Shox OZ Sale (www.dmuch.com) Discount Nike Shox TL Store (www.dmuch.com) Discount Nike Shox TL 2 Shoes Store (www.dmuch.com) Discount Nike Shox TL 3 Distributor (www.dmuch.com) Discount Nike Shox Bmw Shoes Distributor (www.dmuch.com) Discount Nike Shox Elite Shoes Manufacturer (www.dmuch.com) Discount Nike Shox Monster Manufacturer (www.dmuch.com) Discount Nike Shox R4 Running Shoes (www.dmuch.com) Discount Nike Shox R5 Mens Shoes (www.dmuch.com) Discount Nike Shox Ride Womens Shoes (www.dmuch.com) Discount Nike Shox Rival Shoes Wholesaler (www.dmuch.com) Discount Nike Shox Energia Wholesaler (www.dmuch.com) Discount Nike Shox LV Sneaker (www.dmuch.com) Discount Nike Shox Turbo Suppliers (www.dmuch.com) Discount Nike Shox Classic Shoes Suppliers (www.dmuch.com) Discount Nike Shox Dendara Trainer (www.dmuch.com) Discount Nike Air Jordan 1 Seller (www.dmuch.com) Discount Nike Air Jordan 2 Shoes Seller (www.dmuch.com) Discount Nike Air Jordan 3 Collection (www.dmuch.com) Discount Nike Air Jordan 4 Shoes Collection (www.dmuch.com) Discount Nike Air Jordan 5 Chaussure Shoes (www.dmuch.com) Discount Nike Air Jordan 6 Catalog (www.dmuch.com) Discount Nike Air Jordan 7 Shoes Catalog (www.dmuch.com) Discount Nike Air Jordan 8 Customized (www.dmuch.com) Discount Nike Air Jordan 9 Shoes Customized From tyler at tysdomain.com Tue May 17 20:50:53 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Tue, 17 May 2011 18:50:53 -0600 Subject: FW: help please In-Reply-To: References: <4DD29FF1.9090506@tysdomain.com> <1305661713.3831.1.camel@localhost.localdomain> Message-ID: <4DD317ED.1060906@tysdomain.com> >I can't remember exactly in which release 'perfect English skills' were >added to Python runtime requirements, could you please refresh my memory? the one that requires people use the space key and check over their messages before they hit the enter key. Not so bad a request, I don't think. I am using a screen reader--it takes the text and puts it in speech. It uses the space as it's separation between words, as we all do, so wheniseetextlikethis it just jumbles it altogether. The point was to request that the OP try to formulate a good request, or get the space key fixed, both of which would've helped. From rouslank at msn.com Tue May 17 21:03:50 2011 From: rouslank at msn.com (Rouslan Korneychuk) Date: Tue, 17 May 2011 21:03:50 -0400 Subject: basic bytecode to machine code compiler (part 2) Message-ID: I mentioned before that I had a proof of concept to convert Python bytecode to native machine code. It's available at https://github.com/Rouslan/nativecompile Now that I have a substantial number of the bytecode instructions implemented, I thought I would share some benchmark results. The first test performs a quicksort on a list of 100 numbers, 5000 times. The second calculates all the prime numbers up to 10000000. Each test is run three times in a row, first with the interpreter, then with the compiled code. #### SCRIPT ONE #### import time import random import nativecompile bcode = compile(''' def quicksort(array): if len(array) <= 1: return array pindex = len(array)//2 pivot = array[pindex] less = [] greater = [] for i,x in enumerate(array): if i != pindex: (less if x <= pivot else greater).append(x) return quicksort(less) + [pivot] + quicksort(greater) in_ = list(range(100)) random.seed(346097) random.shuffle(in_) t = time.clock() for x in range(5000): out = quicksort(in_) t = time.clock()-t assert out == sorted(in_) print('execution time: {}'.format(round(t,10))) ''','','exec') mcode = nativecompile.compile(bcode) print('byte code') for x in range(3): eval(bcode) print() print('machine code') for x in range(3): mcode() print() #### OUTPUT #### byte code execution time: 1.77 execution time: 1.76 execution time: 1.77 machine code execution time: 1.42 execution time: 1.42 execution time: 1.42 #### SCRIPT TWO #### import time import math import nativecompile bcode = compile(''' def primes_list(upto): nums = [True] * (upto//2-1) for i in range(3,math.floor(math.sqrt(upto))+1,2): if nums[i//2-1]: for j in range(i*3,upto,i*2): nums[j//2-1] = False primes = [] for i,n in enumerate(nums): if n: primes.append((i+1)*2+1) return primes t = time.clock() primes = primes_list(10000000) t = time.clock()-t print(primes[-1]) print('execution time: {}'.format(round(t,10))) ''','','exec') mcode = nativecompile.compile(bcode) print('byte code') for x in range(3): eval(bcode) print() print('machine code') for x in range(3): mcode() print() #### OUTPUT #### byte code 9999991 execution time: 3.47 9999991 execution time: 3.38 9999991 execution time: 3.36 machine code 9999991 execution time: 2.95 9999991 execution time: 2.96 9999991 execution time: 2.95 The results are not terribly impressive, but it's something. Also, although I wasn't intending on doing anything more complicated than getting rid of the interpreter loop, I'm starting to notice little ways the code can be optimized without needing run-time analysis. The most obvious is looping over a range object. I could do away with the iterator and just use a native integer (and have the program fall back to the iterator interface if 'range' didn't refer to the built-in range object after all). From mail2fei at gmail.com Tue May 17 21:09:28 2011 From: mail2fei at gmail.com (Fei) Date: Tue, 17 May 2011 18:09:28 -0700 (PDT) Subject: python logging References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> Message-ID: <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> On May 17, 6:55?pm, Ian Kelly wrote: > On Tue, May 17, 2011 at 2:55 PM, Fei wrote: > > where is default logging file on Mac? I saw lots of app just import > > logging, and begins to logging.info(...) etc. ?I'm not sure where to > > look at the logging configuration to figure out the log location. > > There is no default log file. ?You're seeing that because logging only > needs to be configured by the program once, not on a per-module basis. > ?Thus most modules will just do import logging on the assumption that > the configuration has already been performed somewhere else. > > If no logging configuration is done at all, then the logging > statements will have no effect. Thanks Ian. From steveo at syslang.net Tue May 17 21:16:46 2011 From: steveo at syslang.net (Steven W. Orr) Date: Tue, 17 May 2011 21:16:46 -0400 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: <4DD31DFE.9030707@syslang.net> On 5/17/2011 6:26 PM, Xah Lee wrote: > might be of interest. > > ?English Idiom in Unix: Directory Recursively? > http://xahlee.org/comp/idiom_directory_recursively.html The answer is from compute science 101. From any standard data structures course, you learn the algorithm for how to walk a tree. To make it simple, the example is to use a binary tree which means that any non-leaf node of a tree may only have two child nodes, which are designated as Left and Right. There are only three things that are possible: Visit, Go Left, or Go Right. This means that a tree traversal program can only be written three ways: A PreOrder Traversal will Visit, Go Left, Go Right. An InOrder Traversal will Go Left, Visit, Go Right. A PostOrder Traversal will Go Left, Go Right, Visit. So, the Visit function is the function that does whatever you want to have happen at that node. Selection of whether you want to do things like copy, print or delete are designated by what kind of traversal you perform. And, since the Traversal function calls itself, it is, by definition, recursive. QED. -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From tjreedy at udel.edu Tue May 17 21:33:55 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 May 2011 21:33:55 -0400 Subject: pyjamas 0.8alpha1 release In-Reply-To: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> References: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> Message-ID: On 5/17/2011 12:07 PM, lkcl wrote: > On May 4, 7:37 pm, Terry Reedy wrote: >> On 5/4/2011 10:06 AM, Luke Kenneth Casson Leighton wrote: >>> pyjamasis a suite of projects, including a python-to-javascript >>> compiler >> As you well know, there is no such thing as 'python' when it comes to >> compiling actual code. So please specify both in announcements here and >> on the project homepagehttp://sourceforge.net/projects/pyjamas/ >> which versions are supported. > [no response] I would still like to know. Do you fully support 2.7? It has many of the same changes that are in 3.1 and even 3.2 so I can imagine it would be difficult. >> If you do not yet support 3.x, I request and recommend that you do so, > > with the situation as it is, there is not a snowball in hell's chance > that's going to happen. allow me to explain. Thank you for the explanation. You are right that I probably underestimated the work, though you have or will do some of what is needed to fully support 2.7. ... > otherwise please - really: just saying "give me support for python > 3.x or else" is ... And I did not say that. I first learned Python with 1.3 and could again write 2.x code if motivated. ... > leaving _that_ aside, there happens to be absolutely no really good > compelling reason to support python 3.x in the first place. Depend on who *you* want to target as users. *Your* choice, of course. > "python 3 is the future of python" gimme a break!! Let's discuss that in a couple of years. > [so why is archlinux the only linux distribution that's converted > over to run everything off of python 3.x?] Because being first is their thing. -- Terry Jan Reedy From are.dogue at gmail.com Tue May 17 21:44:41 2011 From: are.dogue at gmail.com (are Dogue) Date: Tue, 17 May 2011 18:44:41 -0700 (PDT) Subject: Finding the local directory of a file in the python path Message-ID: <208b4720-ee3d-4dd1-b4cd-c455af2cde9a@p13g2000yqh.googlegroups.com> Hi there, I have a problem that I can't seem to solve after quite a bit of searching, probably because I can't find the right terms to search for. Basically, here's the situation. Let's say I have a file at ~/foo/bin/ foo.py that imports a script that at ~/bar/bin/bar.py. The imported file needs to load something from '~/bar/bin/data/', but I cannot hard code the full path. Instead, what I need is to have something in bar.py like dir = .... # Not sure what this line should be datadir = dir + '/data/' If I use sys.path[0] or os.getcwd(), then when I import the file from ~/foo/bin/, I get that dir is '~/foo/bin' rather than '~/bar/bin' I hope this explanation makes sense. If you have any insights, I would be most appreciative. Thanks Are From tjreedy at udel.edu Tue May 17 21:52:44 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 May 2011 21:52:44 -0400 Subject: [ann] pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: On 5/17/2011 12:38 PM, harrismh777 wrote: > Terry Reedy wrote: >> Like it or not, Python 3 is the future of Python. It is the Python that >> many Python newcomers learn first, and perhaps ever will. > > Yes, no doubt, and I'm genuine about that... > > ... but there is something else to consider, as I'm sure you are aware. > At some point Python is going to have to standardize in order to > survive. And by survive I'm not talking about the Python 'community,' as > much as I'm talking about the acceptance and wide-spread use of Python > by people who just want to get work done and solve problems. > > If there is another major jump like 2.x --> 3.x in the future, There can't be, in that the essence of the jump was elimination of original flaws in 1.0 or 1.1 by elimination of old ways in favor of new ways that are already present in 2.7 or before. > Python will die. I hope you guys are aware of this. No, because I think you are exaggerating. That said, I think core Python is pretty close to 'complete' and I would not mind further syntax freezes like the one for 3.2. > Like it or not, Python 2.x has millions of lines of code running out > there, and they're not going to get morphed into 3.x coding. Except for public libraries, I do not think it should be. > So, 2x is going to be around for many years to come. For as long the existing binaries can run or a long as the code can be compiled. > with an interpreter. Different versions of the source code (.py files) > require a matching 'interpreter,' Most 2.x code is forward compatible with newer 2.x versions. > where-as in other languages a new > compiler version does not require recompiling source, but if source is > recompiled everything still works... Unless the new compiler is for a newer version of the language. I believe C89 compilers had problems with some K&R + extensions C. I do not know if C89 code is completely C99 compatible. I know the reverse is not true, CPython is still C89 code since that apparently still makes it available on more machines. -- Terry Jan Reedy From are.dogue at gmail.com Tue May 17 21:53:11 2011 From: are.dogue at gmail.com (are Dogue) Date: Tue, 17 May 2011 18:53:11 -0700 (PDT) Subject: Finding the local directory of a file in the python path References: <208b4720-ee3d-4dd1-b4cd-c455af2cde9a@p13g2000yqh.googlegroups.com> Message-ID: Nevermind... os.path.dirname (__file__) On May 17, 9:44?pm, are Dogue wrote: > Hi there, > > I have a problem that I can't seem to solve after quite a bit of > searching, probably because I can't find the right terms to search > for. > > Basically, here's the situation. Let's say I have a file at ~/foo/bin/ > foo.py that imports a script that at ~/bar/bin/bar.py. The imported > file needs to load something from '~/bar/bin/data/', but I cannot hard > code the full path. Instead, what I need is to have something in > bar.py like > > dir = .... # Not sure what this line should be > datadir = dir + '/data/' > > If I use sys.path[0] or os.getcwd(), then when I import the file from > ~/foo/bin/, I get that dir is '~/foo/bin' rather than '~/bar/bin' > > I hope this explanation makes sense. If you have any insights, I would > be most appreciative. > > Thanks > Are From tjreedy at udel.edu Tue May 17 22:10:08 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 May 2011 22:10:08 -0400 Subject: in search of graceful co-routines In-Reply-To: <4DD2AA99.3010508@simplistix.co.uk> References: <4DD2AA99.3010508@simplistix.co.uk> Message-ID: On 5/17/2011 1:04 PM, Chris Withers wrote: > Hi All, > > I'm looking for a graceful pattern for the situation where I have a > provider of a sequence, the consumer of a sequence and code to moderate > the two, and where I'd like to consumer to be able to signal to the > provider that it hasn't succeeded in processing one element in the queue. > > So, I'd want the controlling code to look a lot like: > > for item in provider: > try: > consumer.handleItem(self) > except: > provider.failed(item) > > Now, since the sequence is long, and comes from a file, I wanted the > provider to be an iterator, so it occurred to me I could try and use the > new 2-way generator communication to solve the "communicate back with > the provider", with something like: > > for item in provider: > try: > consumer.handleItem(self) > except: > provider.send('fail') > else: > provider.send('succeed') > > ..but of course, this won't work, as 'send' causes the provider > iteration to continue and then returns a value itself. That feels weird > and wrong to me, but I guess my use case might not be what was intended > for the send method. > > Anyway, I wonder how other people would write this? > (I'm particularly interested in a sane way to use the two way > communication that PEP 342 introduced) By default, Python iterators operate in pull mode -- consumers request a new item when they want one. I believe .send was mostly intended to reverse that, to operate in push mode where producers .send() a item to a consumer when they are ready to. That is certainly true of examples I have seen. Using .send for feedback to a provider is trickier, as the two other posts have shown. Another option is to write an iterator class instead of generator function. You can then give the provider a message receive method (.send or whatever) that is decoupled from the send-next method. Your example above then *would* work, as 'send' would not cause anything in the provider except what you want it to cause. Standard generator functions abbreviate standard iterator classes. When one moves beyond standard iterator behavior, the equivalence tends to break down. -- Terry Jan Reedy From tjreedy at udel.edu Tue May 17 22:28:08 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 May 2011 22:28:08 -0400 Subject: Python 3.x and bytes In-Reply-To: <4DD2CEE0.4080403@mrabarnett.plus.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2CEE0.4080403@mrabarnett.plus.com> Message-ID: On 5/17/2011 3:39 PM, MRAB wrote: > On 17/05/2011 19:47, Ethan Furman wrote: >> In Python 3 one can say >> >> --> huh = bytes(5) > BTW, help(bytes) doesn't seem to mention it! I believe I mentioned that on some tracker issue. -- Terry Jan Reedy From tjreedy at udel.edu Tue May 17 22:30:45 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 May 2011 22:30:45 -0400 Subject: Python 3.x and bytes In-Reply-To: <4DD2E828.9000502@aim.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com> <4DD2E0C8.2090101@stoneleaf.us> <4DD2E828.9000502@aim.com> Message-ID: On 5/17/2011 5:27 PM, Corey Richardson wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 05/17/2011 04:55 PM, Ethan Furman wrote: >> Apparently, it's not well documented. If you check PEP 358 >> you'll find it. >> >> ~Ethan~ > > Agreed, it looks like it should be mentioned in bytes.__doc__ about the > single-integer argument. It will be when some volunteer writes a patch. http://bugs.python.org/issue11231 -- Terry Jan Reedy From rosuav at gmail.com Tue May 17 22:50:09 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 May 2011 12:50:09 +1000 Subject: in search of graceful co-routines In-Reply-To: <4DD2AA99.3010508@simplistix.co.uk> References: <4DD2AA99.3010508@simplistix.co.uk> Message-ID: On Wed, May 18, 2011 at 3:04 AM, Chris Withers wrote: > Hi All, > > I'm looking for a graceful pattern for the situation where I have a provider > of a sequence, the consumer of a sequence and code to moderate the two, and > where I'd like to consumer to be able to signal to the provider that it > hasn't succeeded in processing one element in the queue. I wonder would this work nicely if concepted as a couple of threads with a Queue between them? Whether or not you actually use threads per se, or if you just have two separate processing loops and message passing between them, it might be easier to code that way than as generators. Chris Angelico From gwrkarthik at gmail.com Wed May 18 00:22:56 2011 From: gwrkarthik at gmail.com (gowri karthik) Date: Tue, 17 May 2011 21:22:56 -0700 (PDT) Subject: EARN EASY PPC FORM FILLING JOB Message-ID: <1b015bb0-764d-4007-a85b-058822d18d4d@d26g2000prn.googlegroups.com> http://internetjob4u.yolasite.com From rustompmody at gmail.com Wed May 18 00:43:07 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 17 May 2011 21:43:07 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <80ba3b5e-34c1-420a-aade-9c1996d0239e@u26g2000vby.googlegroups.com> Message-ID: <444f4191-b530-4049-b041-09a8ec1a796e@s16g2000prf.googlegroups.com> On May 18, 2:04?am, Wolfram Hinderer wrote: > On 17 Mai, 20:56, geremy condra wrote: > > > > > On Tue, May 17, 2011 at 10:19 AM, Jussi Piitulainen > > > wrote: > > > geremy condra writes: > > > >> or O(1): > > > >> ? = (1 + sqrt(5)) / 2 > > >> def fib(n): > > >> ? ? numerator = (?**n) - (1 - ?)**n > > >> ? ? denominator = sqrt(5) > > >> ? ? return round(numerator/denominator) > > > >> Testing indicates that it's faster somewhere around 7 or so. > > > > And increasingly inaccurate from 71 on. > > > Yup. That's floating point for you. For larger values you could just > > add a linear search at the bottom using the 5f**2 +/- 4 rule, which > > would still be quite fast out to about 10 times that. The decimal > > module gets you a tiny bit further, and after that it's time to just > > use Dijkstra's, like rusi suggested. In any event, I still think this > > formulation is the most fun ;). > > I think you can write it even more funny > > def fib(n): > ? ? return round(((.5 + .5 * 5 ** .5) ** n - ?(.5 - .5 * 5 ** .5) ** > n) * 5 ** -.5) > > ;-) VOW! Tour de Force - Thanks [I am going to trouble some class of students with that :-) ] From my.spamtrap at verizon.net Wed May 18 00:51:59 2011 From: my.spamtrap at verizon.net (Roland Hutchinson) Date: Wed, 18 May 2011 04:51:59 +0000 (UTC) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On Tue, 17 May 2011 15:26:42 -0700, Xah Lee wrote: > might be of interest. > > ?English Idiom in Unix: Directory Recursively? > http://xahlee.org/comp/idiom_directory_recursively.html > > ------------------------------------------ English Idiom in Unix: > Directory Recursively > > Xah Lee, 2011-05-17 > > Today, let's discuss something in the category of lingustics. > > You know how in unix tools, when you want to delete the whole directory > and all sub-directories and files in it, it's referred as ?recursive?? > > For example, when you want to delete the whole dir in emacs, it prompts > this message: ?Recursive delete of xx? (y or n) ?. (Note: to be able to > delete whole dir in emacs in dired, you'll first need to turn it on. > See: emacs dired tutorial.) > > Here's another example. A quote from ?rsync? man page: > > ? > This would recursively transfer all files from the directory ? -r, > --recursive recurse into directories This tells rsync > to copy directories recursively. See also -- > dirs (-d). > ? > > Here's a quote from ?cp?'s man page: > > -R, -r, --recursive > copy directories recursively > > and lots of other tools has a ?-r? option, and they all refer to it as > ?recursive?. > > Though, if you think about it, it's not exactly a correct description. > ?Recursive?, or ?recursion?, refers to a particular type of algorithm, > or a implementation using that algorithm. Obviously, to process all > directory's content does not necessarily mean it must be done by a > recursive algorithm. A iteration can do it as well and it's easy to have > the full behavior and properties in the result as a recursive approach, > such as specifying depth order, level to dive into, etc. (because, dir > is a tree, and recursive algorithm is useful for walking the tree data > structure but is not necessary, because a tree can be laid out flat. Any > path order taken by a recursive approach can be done by just enumerating > the nodes in sequence. In fact, iteration approach can be faster and > simpler in many aspects. (i wrote a article about this some 10 years > ago, see: Trees and Indexes.) Note: this thought about tree and its > nodes as a set of node addresses can be applied to any tree data > structure, such as lisp's nested syntax, XML. See: Programing Language: > Fundamental Problems of Lisp.) > > If you look at Windows or Mac OS X world, i don't think they ever refer > to dealing with whole dir as ?recursive? in user interface. For example, > in Windows Vista, while changing properties of a folder, it has this > message: > > Apply changes to this folder only. > Apply changes to this folder, subfolders and files. > > Note the second choice. In unix, it would say ?Apply changes to this > folder recursively.? > > So, the word ?recursive? used in unixes may be technically incorrect, > but more so, it's just not the right phrase. Because, we want to > communicate whether the whole content of a directory are processed, not > about certain algorithm or how it is implemented. A simple ?all the > dir's branches/contents? or similar would be more apt. > Sorry to have to contradict you, but it really is a textbook example of recursion. Try this psuedo-code on for size: FUNCTION DIR-DELETE (directory) FOR EACH entry IN directory IF entry IS-A-DIRECTORY THEN DIR-DELETE (entry). Well, now that's not just recursion; it's tail recursion. Tail recursion can always be turned into an iteration when it is executed. Reasonably designed compilers are required to do so, in fact--have been for decades now. That doesn't mean that recursion isn't the best way of describing the algorithm. > Recently i was chatting in Second Life with someone (Sleeves). She's > typing, while i'm on voice. In part of our conversation, i said ?you > sounded fine?. Note that it's technically incorrect, because she's > typing, not on voice. So she didn't actually make any ?sound?. But to > say ?you typed fine?, or ?you chatted fine?, won't get the message > across. > > That's idiom. When you interpret a idiom logically, it doesn't make much > sense, but people understand the particular phrase better anyway. I > suspect the ?directory recursively? is also a idiom. The collocation in question is not "directory recursively"; it's "delete ... recursively". Or "Change ... recursively" (etc). Does that help? > It seems so natural > and really gets the point across, without any ill effects. Even if the > implementation actually used a iteration, it doesn't seems to matter. > > So the interesting question is, why this idiom works? Or, how it > developed? It's also not an idiom. It's meaning is completely determined by the meaning of "delete" and the meaning of "recurse", as in "recurse down a tree structure"--which is precisely what the various *nix commands do when their recursive option is invoked. "Recurse _down_ a tree" is an interesting phrase, though, as it implies that, in computing, trees are thought of as growing with their root topmost and their branches underneath -- i.e., upside-down! > I think, among programers (which all unix users are in the 1970s), every > one knows the concept of recursion, and many unix tools on dir probably > are implemented with a recursive algorithm. When you say ?? > recursively?, the point gets across, because we all understand it, even > when we are not actually talking about implementation. The phrase ?? > directory recursively? is short and memorable, while ?? directory and > all its contents? or ?? directory and all its branches? or ?? directory > and all its sub-directories and files? are wordy and unwieldy. > ? > > Idiocy Of Unix Copy Command > Emacs Lisp Suggestion: Function to Copy/Delete a Directory > Recursively > How to rsync, unison, wget, curl > Hunspell Tutorial > Mac OS X Resource Fork and Command Line Tips ImageMagick Tutorial > Making System Calls in Perl and Python Unix And Literary Correlation > The Unix Pestilence > To An Or Not To An > On ?I? versus ?i? (capitalization of first person pronoun) On the > Postposition of Conjunction in Penultimate Position of a > Sequence > What's Passive Voice? What's Aggressive Voice? Why You Should Avoid > The Jargon ?Tail Recursion? Why You should Not Use The Jargon Lisp1 > and Lisp2 Jargons of Info Tech Industry > > Xah I'm writing from alt.usage.english. The non-natural language mavens may have more to add. -- Roland Hutchinson He calls himself "the Garden State's leading violist da gamba," ... comparable to being ruler of an exceptionally small duchy. --Newark (NJ) Star Ledger ( http://tinyurl.com/RolandIsNJ ) From pjb at informatimago.com Wed May 18 01:19:08 2011 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Wed, 18 May 2011 07:19:08 +0200 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Roland Hutchinson writes: > Sorry to have to contradict you, Don't be sorry. > but it really is a textbook example of > recursion. Try this psuedo-code on for size: > > FUNCTION DIR-DELETE (directory) > FOR EACH entry IN directory > IF entry IS-A-DIRECTORY THEN DIR-DELETE (entry). > > Well, now that's not just recursion; it's tail recursion. It's not tail recursion. If you had indented your code properly, you'd see why it's not: (defun dir-delete (directory) (loop for entry in directory do (if (is-a-directory entry) (dir-delete entry)))) (I put parentheses, so my editor knows what I mean and can do the indentation for me). That's why walking a directory is done with a recursive procedure, instead of an iterative one: it's much simplier. To implement an iterative procedure, you would have to manage a stack yourself, instead of using the implicit stack of the recursive procedure. > Tail recursion can always be turned into an iteration when it is > executed. All recursions can be turned into iterations, before execution. > Reasonably designed compilers are required to do so, in fact--have > been for decades now. That doesn't mean that recursion isn't the > best way of describing the algorithm. -- p__Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From chris at simplistix.co.uk Wed May 18 01:27:15 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 18 May 2011 06:27:15 +0100 Subject: in search of graceful co-routines In-Reply-To: References: <4DD2AA99.3010508@simplistix.co.uk> Message-ID: <4DD358B3.2060308@simplistix.co.uk> On 17/05/2011 18:26, Ian Kelly wrote: > You can use send the way you're wanting to. It will look something like this: > > def provider(): > result = None > while True: > if result is None: > if has_more_items(): > next_item = get_next_item() > else: > break > elif result == 'fail': > process_fail() > next_item = None > elif result == 'succeed': > process_succeed() > next_item = None > else: > raise ValueError('unknown result %s' % result) > result = (yield next_item) Yes, but it's this kind of birds nest I'm trying to avoid... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From harrismh777 at charter.net Wed May 18 01:29:04 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 18 May 2011 00:29:04 -0500 Subject: [ann] pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: Terry Reedy wrote: > > No, because I think you are exaggerating. That said, I think core > Python is pretty close to 'complete' and I would not mind further syntax > freezes like the one for 3.2. I am exaggerating only to the extent that someone can imagine folks becoming just annoyed with PEP progress to drop the whole thing... I am exaggerating only to the extent that we define 'it' as language death... if the user base narrows, python's future is held tentative... on the other hand, if the user base grows and campers are happy, then python's future is more stable... I don't think this is an exaggeration... That said, I am encouraged to here your other words, including a favored tendency towards syntax freeze... thanks... kind regards, m harris From ian.g.kelly at gmail.com Wed May 18 01:46:27 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 23:46:27 -0600 Subject: in search of graceful co-routines In-Reply-To: <4DD358B3.2060308@simplistix.co.uk> References: <4DD2AA99.3010508@simplistix.co.uk> <4DD358B3.2060308@simplistix.co.uk> Message-ID: On Tue, May 17, 2011 at 11:27 PM, Chris Withers wrote: > Yes, but it's this kind of birds nest I'm trying to avoid... I was actually kind of hoping you might see it that way. That's about as simple as you're going to get using a generator for this, though. I'll second Terry's suggestion on this: forget using a generator for the provider, and instead create an iterator class with regular methods to decouple the push logic from the pull logic. I think you'll be glad that you did. Cheers, Ian From wuwei23 at gmail.com Wed May 18 01:54:43 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 May 2011 22:54:43 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: Message-ID: harrismh777 wrote: > If there is another major jump like ?2.x --> 3.x ?in the future, Python > will die. I hope you guys are aware of this. The user base might accept > this thing once, but they're not going do it again... The differences between major version releases of Python are far, far less than those of PHP's _minor_ releases. Hasn't seemed to have harmed its uptake at all. From chris at simplistix.co.uk Wed May 18 02:00:20 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 18 May 2011 07:00:20 +0100 Subject: in search of graceful co-routines In-Reply-To: References: <4DD2AA99.3010508@simplistix.co.uk> Message-ID: <4DD36074.3000505@simplistix.co.uk> On 18/05/2011 03:10, Terry Reedy wrote: > By default, Python iterators operate in pull mode -- consumers request a > new item when they want one. I believe .send was mostly intended to > reverse that, to operate in push mode where producers .send() a item to > a consumer when they are ready to. That is certainly true of examples I > have seen. My first exposure was with the @inlineCallbacks decorator in twisted, which does use it both ways... > Using .send for feedback to a provider is trickier, as the two other > posts have shown. The closest I've found to something graceful is: def mygenerator(*args): for arg in args: print "yielding:",arg result = yield arg print "returned:",result if result is not None: yield None provider = mygenerator(1,2,3) for arg in provider: print "got:",arg if arg%2: provider.send('hello') However, if you do g.send(None), you still get a result back, which feels a bit weird... It's pretty disappointing that neither the send nor throw methods added as part of PEP342 were provided with a parameter or variant that did "send an item but don't advance the generator". > Another option is to write an iterator class instead > of generator function. You can then give the provider a message receive > method (.send or whatever) that is decoupled from the send-next method. Yes, that's an option I'd considered, however, with a provider class as follows: class Provider: def __init__(self,*args): self.args = args self.current = 0 def next(self): try: val = self.args[self.current] except: raise StopIteration() self.current += 1 print "yielding:",val return val def send(self,value): print "returned:",value def __iter__(self): return self provider = Provider(1,2,3) for arg in provider: print "got:",arg if arg%2: provider.send('hello') ...but that's a lot more code, and allows one of my anti-use cases to happen: provider = Provider(1,2,3) provider.send("don't want this to be possible") The generator implementation deals with the above specific case: File "test.py", line 12, in provider.send('hello') TypeError: can't send non-None value to a just-started generator ...which is, in itself, a little weird, given that it doesn't protect against: provider = Provider(1,2,3) val = provider.next() provider.send("don't want this to be possible") provider.send("don't want this to be possible") cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rustompmody at gmail.com Wed May 18 02:06:44 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 17 May 2011 23:06:44 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> On May 18, 9:51?am, Roland Hutchinson wrote: > Sorry to have to contradict you, but it really is a textbook example of > recursion. ?Try this psuedo-code on for size: ? Well and so far this thread is a textbook example of myths and misconceptions regarding recursion :D 1. 'Recursive' is a meaningful adjective for algorithms only and not data structures 2. Recursion is inefficient which is a corollary to 3. Recursion is different from (more general, less efficient) iteration 4. Recursion in 'recursion theory' aka 'computability theory' is somehow different from recursion in programming. Let me start with 1. The Haskell (pseudocode) defn for lists is: data List(t) = [] | (:) t List(t) In words, a list over type t is either empty or is made byt taking a (smaller) list and consing (:) and element onto it It is only given this defn that al the list functions which are (in the sense that most programmers understand) recursive. For example: len [] = 0 len (x:xs) = 1 + len xs Note that the definition of List is primary and the recursive functions on this definition are secondary to this definition. What happens in languages more and more far from the 'functional purity' of Haskell? Much the same except that implementation details muddy the waters. eg in C the defn for list (of an elsewhere specified type t) runs thus struct node { t elem; struct node *next; } To make the recursion more explicit, introduce the typedef: typedef struct node *nodeptr; struct node { t elem; nodeptr next; }; And we see clearly a mutual recursion in this data type: node contains nodeptr nodeptr points to node So one could say that the C defn is more recursive than the Haskell one in the sense that double recursion is 'more recursion' than single. I could continue down 2,3,4 but really it may be worthwhile if the arguers first read the wikipedia disambiguation pages on recursion... From techtonik at gmail.com Wed May 18 02:07:19 2011 From: techtonik at gmail.com (anatoly techtonik) Date: Wed, 18 May 2011 09:07:19 +0300 Subject: [Python-Dev] [RELEASED] Python 3.2.1 rc 1 In-Reply-To: <4DD2C37D.7000008@python.org> References: <4DD2C37D.7000008@python.org> Message-ID: That's great, but where is the list if changes? -- anatoly t. On Tue, May 17, 2011 at 9:50 PM, Georg Brandl wrote: > On behalf of the Python development team, I am pleased to announce the > first release candidate of Python 3.2.1. > > Python 3.2.1 will the first bugfix release for Python 3.2, fixing over 120 > bugs and regressions in Python 3.2. > > For an extensive list of changes and features in the 3.2 line, see > > ? ?http://docs.python.org/3.2/whatsnew/3.2.html > > To download Python 3.2.1 visit: > > ? ?http://www.python.org/download/releases/3.2.1/ > > This is a testing release: Please consider trying Python 3.2.1 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) > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: http://mail.python.org/mailman/options/python-dev/techtonik%40gmail.com > From tyler at tysdomain.com Wed May 18 02:19:33 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Wed, 18 May 2011 00:19:33 -0600 Subject: [Python-Dev] [RELEASED] Python 3.2.1 rc 1 In-Reply-To: References: <4DD2C37D.7000008@python.org> Message-ID: <4DD364F5.4020708@tysdomain.com> >For an extensive list of changes and features in the 3.2 line, see >http://docs.python.org/3.2/whatsnew/3.2.html Might I presume that clicking the link would show the required changes? From tar at sevak.isi.edu Wed May 18 02:42:20 2011 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 17 May 2011 23:42:20 -0700 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: "Pascal J. Bourguignon" writes: > Roland Hutchinson writes: > > Tail recursion can always be turned into an iteration when it is > > executed. > > All recursions can be turned into iterations, before execution. True, but only by simulating the call stack in the iterative code. To my mind that isn't really an iterative algorithm anymore if it ends up simulating the call stack. Tree walks are the canonical example of what can't be done in an iterative fashion without the addition of an explicitly managed stack -- Thomas A. Russ, USC/Information Sciences Institute From harrishill at gmx.com Wed May 18 02:50:09 2011 From: harrishill at gmx.com (Harrison Hill) Date: Tue, 17 May 2011 23:50:09 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> Message-ID: <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> On May 18, 7:06?am, rusi wrote: > On May 18, 9:51?am, Roland Hutchinson wrote: > > > Sorry to have to contradict you, but it really is a textbook example of > > recursion. ?Try this psuedo-code on for size: ? > > Well and so far this thread is a textbook example of myths and > misconceptions regarding recursion :D > > 1. 'Recursive' is a meaningful adjective for algorithms only and not > data structures > > 2. Recursion is inefficient > > which is a corollary to > > 3. Recursion is different from (more general, less efficient) > iteration > > 4. Recursion in 'recursion theory' aka 'computability theory' is > somehow different from recursion in programming. > > Let me start with 1. > > The Haskell (pseudocode) defn for lists is: > ? ?data List(t) = [] ? ?| ? ?(:) t List(t) > > In words, a list over type t is either empty or is made byt taking a > (smaller) list and consing (:) and element onto it > > It is only given this defn that al the list functions which are (in > the sense that > most programmers understand) recursive. For example: > > len [] = 0 > len (x:xs) = 1 + len xs > > Note that the definition of List is primary and the recursive > functions on this definition are secondary to this definition. > > What happens in languages more and more far from the 'functional > purity' of Haskell? > Much the same except that implementation details muddy the waters. > > eg in C the defn for list (of an elsewhere specified type t) runs thus > > struct node { > ? t elem; > ? struct node *next; > > } > > To make the recursion more explicit, introduce the typedef: > > typedef struct node *nodeptr; > > struct node { > ? t elem; > ? nodeptr next; > > }; > > And we see clearly a mutual recursion in this data type: > node contains nodeptr > nodeptr points to node > > So one could say that the C defn is more recursive than the Haskell > one in the sense that double recursion is 'more recursion' than > single. > > I could continue down 2,3,4 but really it may be worthwhile if the > arguers first read the wikipedia disambiguation pages on recursion... No need - I have the Dictionary definition of recursion here: Recursion: (N). See recursion. From trisha4u4u at gmail.com Wed May 18 02:52:34 2011 From: trisha4u4u at gmail.com (Elisha trisha4uuu.blogspot.com) Date: Tue, 17 May 2011 23:52:34 -0700 (PDT) Subject: Actresses mumaith khan old movies updated wallpapers Message-ID: <62a94dbe-8c73-4b03-9b14-926fac913160@x38g2000pri.googlegroups.com> http://trisha4uuu.blogspot.com/2011/01/mumaith-khan-wall-papers.html mumaith khan wallpapers and photos and pictures watch and enjoy Mumaith Khan Includes mumaith khan photos, mumaith khan gossip, mumaith khan biography, mumaith khan wallpapers, mumaith khan filmography, mumaith khan videos, mumaith khan pictures. Mumaith khan facebook mumaith khan - telugupedia collaboratively authored wiki about telugu, telugu people, ugadi telugu greetings 2011, telugu films news, telugu newspapers, eenaud newspaper. Mumaith khan mumait khan hot sexy actress profile biography mumaith khan - description: mumaith khan is an indian film actress known for her item numbers she has acted in movies in hindi, telugu, tamil and kannada languages. Mumaith khan facebook mumaith khan is on facebook join facebook to connect with mumaith khan and others you may know facebook gives people the power to share and makes the world more open. Mumaith khan - telugupedia download telugu calendar 2011, ugadi hot and news mumaith khan mumaith khan wallpapers mumaith khan pictures mumaith khan photos mumaith khan hot pics.Mumaith khan mumaith khan wallpapers mumaith khan pictures mumaith khan mumait khan hot sexy actress profile biography movies psyphil celebrity. Mumaith khan mumaith khan an indian film actress who is very popular by her glamour songs she has acted in nearly 15 movies in hindi, telugu, tamil and kannada languages. Mumaith khan - ask jeeves encyclopedia why mumaith khan should be called as cameo girl as she has done almost all her movies for just item dances her dance in pokkiri got attention and no longer far she grew. Mumaith khan sexy photo tamil actress photos tamil movies mumaith khan is an indian film actress known for her item numbers she has acted in movies in hindi, telugu, tamil and kannada languages mumaith khan is 39 years old. http://trisha4uuu.blogspot.com/2011/01/mumaith-khan-wall-papers.html From ian.g.kelly at gmail.com Wed May 18 02:58:00 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 00:58:00 -0600 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> Message-ID: On Wed, May 18, 2011 at 12:06 AM, rusi wrote: > 4. Recursion in 'recursion theory' aka 'computability theory' is > somehow different from recursion in programming. Um, it is. Consider the simple function (lambda x, y: x + y). Mathematically, this function is recursive. Algorithmically, it is not. Do you disagree? From sdouche at gmail.com Wed May 18 03:05:25 2011 From: sdouche at gmail.com (Sebastien Douche) Date: Wed, 18 May 2011 09:05:25 +0200 Subject: Python 2.7 Debian 6.0. Squeeze In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 17:27, Jorge Romero wrote: > I tried Googling about Python 2.7 on Debian Squeeze, but did not find > anything but discussions -.-. Anyone out there that can point me some > helpful material or anyone who had luck running 2.7 on Debian? I use pythonbrew : http://pypi.python.org/pypi/pythonbrew -- Sebastien Douche Twitter: @sdouche (agile, lean, python, git, open source) From rustompmody at gmail.com Wed May 18 03:10:51 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 00:10:51 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> Message-ID: <436ff55b-f61d-46a8-b5ea-f29d73190aba@s41g2000prb.googlegroups.com> On May 18, 11:58?am, Ian Kelly wrote: > On Wed, May 18, 2011 at 12:06 AM, rusi wrote: > > 4. Recursion in 'recursion theory' aka 'computability theory' is > > somehow different from recursion in programming. > > Um, it is. ?Consider the simple function (lambda x, y: x + y). > Mathematically, this function is recursive. ?Algorithmically, it is > not. ?Do you disagree? See the definition of primitive recursion eg. http://en.wikipedia.org/wiki/Primitive_recursive_function#Definition (2 of the second set of "more complex" definitions) from where the name 'primitive recursion' is presumably derived) And for the more general (wider) class of 'recursive' functions (in the math sense aka computable functions) see a little below: http://en.wikipedia.org/wiki/Primitive_recursive_function#Relationship_to_recursive_functions Of course I grant that the adjective 'recursive' is used differently in computability and in programming but the roots are not all that different. If I remember right (I may be misremembering) Hofstader, referring to the invention of 'recursive function' by Godel, says something to the effect that Godel was inventing lisp 30 years before lisp... From rustompmody at gmail.com Wed May 18 03:16:06 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 00:16:06 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: <814f4883-ae12-4444-bb32-e239d3837585@35g2000prp.googlegroups.com> On May 18, 11:50?am, Harrison Hill wrote: > Rusi wrote > > I could continue down 2,3,4 but really it may be worthwhile if the > > arguers first read the wikipedia disambiguation pages on recursion... > > No need - I have the Dictionary definition of recursion here: > > Recursion: (N). See recursion. Ha! Ha! Worth also looking at the talk page of the recursive disambiguation page: http://en.wikipedia.org/wiki/Talk:Recursive From hg at schaathun.net Wed May 18 03:36:37 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 08:36:37 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> Message-ID: <5h9ca8-ekq.ln1@svn.schaathun.net> On Mon, 16 May 2011 23:42:40 +0100, Rhodri James wrote: : ...which is, of course, not exactly secure either. A sufficiently : determined hacker won't have much trouble disassembling a shared library : even if you do strip out all the debug information. By chance I'm having : to do something closely related to this at work just at the moment; it's : hard, but far from impossible. But then, nothing is secure in any absolute sense. The best you can do with all your security efforts is to manage risk. Since obfuscation increases the cost of mounting an attack, it also reduces risk, and thereby provides some level of security. Obviously, if your threat sources are dedicated hackers or maybe MI5, there is no point bothering with obfuscation, but if your threat source is script kiddies, then it might be quite effective. -- :-- Hans Georg From rustompmody at gmail.com Wed May 18 03:41:12 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 00:41:12 -0700 (PDT) Subject: Multiple python environments (was Python 2.7 Debian 6.0. Squeeze) References: Message-ID: On May 18, 12:05?pm, Sebastien Douche wrote: > On Thu, May 12, 2011 at 17:27, Jorge Romero wrote: > > I tried Googling about Python 2.7 on Debian Squeeze, but did not find > > anything but discussions -.-. Anyone out there that can point me some > > helpful material or anyone who had luck running 2.7 on Debian? > > I use pythonbrew :http://pypi.python.org/pypi/pythonbrew Interesting. Is this an alternative to virtualenv? My overall impression of this area is that there are a zillion alternatives (Well ok exaggeration -- more alternatives than needed) And all of them fail on some essential aspects. Yesterday I was trying to setup python on a client site and easy_install kept giving errors. Not easy_install printing errors but python printing backtraces. After repeatedly trying it a few times the errors disappeared. God alone knows... (or maybe Heisenberg...) From rustompmody at gmail.com Wed May 18 04:00:26 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 01:00:26 -0700 (PDT) Subject: ipython prompt does not appear in windows References: Message-ID: On May 18, 3:31?am, "Ori L." wrote: > See here for a workaround:https://bugs.launchpad.net/ipython/+bug/290228 > > First result on Google for the query "ipython emacs windows", BTW. Thanks -- I did find that before asking. That link starts by recommending a small change (add -i flag) to ipython.bat I only find an ipython.exe (in C:\Python27|Scripts ) From hg at schaathun.net Wed May 18 04:12:05 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 09:12:05 +0100 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On Tue, 17 May 2011 15:26:42 -0700 (PDT), Xah Lee wrote: : If you look at Windows or Mac OS X world, i don't think they ever : refer to dealing with whole dir as ?recursive? in user interface. That's purely due to a difference in the level of abstraction. Mac OS introduced its own vocabulary, of folders, where Unix and DOS talked about directories. A folder is a visual element on the screen; exactly modelling a paper folder. It goes without saying that if you bin a folder, the contents goes with it. Anything else would break the model and abstraction. On Unix, the directory is just a file, listing other files by name and disk location. Then it is perfectly natural (although very rarely smart) to delete a directory without any concequences to the contents. The data structure is clearly recursive; a file is either an ordinary file or a directory, and a directory is a list of files. An operation traversing the recursive data structure is recursive regardless of how the algorithm is specified or implemented. A large, although diminishing, fraction of Unix (excluding Mac OS) users are likely to be familiar with the recursive structure of the file system. Now Mac OS X has maintained the folder concept of older mac generations, and Windows has cloned it. They do not want the user to understand recursive data structures, and therefore, naturally, avoid the word. -- :-- Hans Georg From espen at vestre.net Wed May 18 04:20:15 2011 From: espen at vestre.net (Espen Vestre) Date: Wed, 18 May 2011 10:20:15 +0200 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: Hans Georg Schaathun writes: > On Unix, the directory is just a file, listing other files by name > and disk location. Then it is perfectly natural (although very > rarely smart) to delete a directory without any concequences to the > contents. Ironically, the only unix I know of where this makes a lot of sense is Mac OS X (where multiple hard links to a single directory is utilised by TimeMachine to minimise the size of incremental backup trees) :-) -- (espen) From hg at schaathun.net Wed May 18 04:26:27 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 09:26:27 +0100 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: ["Followup-To:" header set to comp.lang.python.] On 17 May 2011 23:42:20 -0700, Thomas A. Russ wrote: : Tree walks are the canonical example of what can't be done in an : iterative fashion without the addition of an explicitly managed stack Of course you can do it. It isn't nice, but it is possible. I assume that you refer to depth first walks, as breadth first is more easily described by iteration on a queue in the first place. Depth first can be achieved by looping over the nodes, with a state keeping references to the current and the previous node considered. By comparing the previous node (pointer or ID) to the current node's parent and children one will know wherefrom the current node was entered, and can choose the next child in the list as the next node, or the parent if all children have been visited. A visit action may be added in any or all times the node is visited. This node requires no stack. The only state space is constant, regardless of the size of the tree, requiring just the two pointers to previous and current. -- :-- Hans Georg From stefan_ml at behnel.de Wed May 18 04:30:26 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 18 May 2011 10:30:26 +0200 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD1C9D5.4070206@gmail.com> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD1C9D5.4070206@gmail.com> Message-ID: Andrew Berg, 17.05.2011 03:05: > lxml looks promising, but it doesn't say anywhere whether it'll work on > Python 3 or not Well, it pretty clearly states that on the PyPI page, but I also added it to the project home page now. lxml 2.3 works with any CPython version from 2.3 to 3.2. Stefan From luke.leighton at gmail.com Wed May 18 05:24:45 2011 From: luke.leighton at gmail.com (lkcl) Date: Wed, 18 May 2011 02:24:45 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> Message-ID: On May 18, 2:33?am, Terry Reedy wrote: > On 5/17/2011 12:07 PM, lkcl wrote: > > > On May 4, 7:37 pm, Terry Reedy ?wrote: > >> On 5/4/2011 10:06 AM, Luke Kenneth Casson Leighton wrote: > >>> pyjamasis a suite of projects, including a python-to-javascript > >>> compiler > >> As you well know, there is no such thing as 'python' when it comes to > >> compiling actual code. So please specify both in announcements here and > >> on the project homepagehttp://sourceforge.net/projects/pyjamas/ > >> which versions are supported. > > ?> [no response] > > I would still like to know. Do you fully support 2.7? It has many of the > same changes that are in 3.1 and even 3.2 so I can imagine it would be > difficult. sorry, terry, missed this out. there are two answers: a) at the moment a http://python.org 2.N interpreter is required to actually run the translator. if you use http://python.org 2.5 or 2.6 you do not need to use the "--internal-ast" option. if you use 2.4, 2.7 or above, you will need to use --internal-ast because we're heavily reliant on the internal c-based "compile" module [without the --internal-ast option enabled]. b) the actual pyjs interpreter grammar (AST) was 2.5 but has mostly been updated to 2.6. actual python syntax / features are therefore mostly 2.5, with someone having pointed out that "slice" has different return results it's hard to say exactly which is best to be picked, 2.5 or 2.6. nobody's needed slice until recently, so it's not an issue that's ever come up before. the thing is - it's worth reiterating: you just... really don't need as much python interoperability for user-interfaces when they're split along MVC lines. bear in mind that it's necessary to do that split: it's web browser technology, you can't *actually* execute things like psycopg or mysql in a web browser as javascript! so once you've divided that application into "python that runs the actual user interface" and "python on the other side of the AJAX barrier e.g. a django app" you're left with a far smaller task for the pyjs interpreter to have to tackle. this is why it's been so unnecessary to keep absolutely up-to-date with the full python development that's been going on, yet we still have people developing 10,000+ LOC 2 man-year pyjamas projects. that having been said, there _is_ the requirement to be "python strict" as well as "fast" - mutually exclusive of course. and there is someone working on getting the pyjs compiler and supporting libraries into shape in order to run the entire http://python.org regression test suite. there really are quite a lot of little sub- projects within the pyjamas project. > >> If you do not yet support 3.x, I request and recommend that you do so, > > > with the situation as it is, there is not a snowball in hell's chance > > that's going to happen. allow me to explain. > > Thank you for the explanation. not a problem. > You are right that I probably underestimated the work, yeah... i apologise for the somewhat-evident flabbergasted tone that may have been apparent in what could otherwise be considered to be a project outline / roadmap :) > though you have or will do some of what is > needed to fully support 2.7. weell... see above: it's kiinda unnecessary - it just depends on people's needs. if there are intelligent and willing people (like kees) who just come along and go "yep, that's nice, but it's not good enough for me: i'm going to make it so" then it'll happen. everyone else _not_ willing to put in the effort to make pyjs do what they want will just have to put up with the foibles. so if someone wants to do it, hell i'm not going to stand in the way - anyone who asks i give them commit rights, point them at the DEVELOPER.RULES and let them get on with it. > ... > > > ? otherwise please - really: just saying "give me support for python > > 3.x or else" is ... > > And I did not say that. yeah i know - i'm sorry: it just, with a little bit of "twisting", could be construed as implying that. > > "python 3 is the future of python" gimme a break!! > > Let's discuss that in a couple of years. :) i think... people forget that there are now two mutually- exclusively-incompatible programming languages out there, where the first six letters of the name of the programming language happen to be the same... l. From mikebarnes at bluebottle.com Wed May 18 05:25:38 2011 From: mikebarnes at bluebottle.com (Mike Barnes) Date: Wed, 18 May 2011 10:25:38 +0100 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: Xah Lee : >For example, when you want to delete the whole dir in emacs, it >prompts this message: ?Recursive delete of xx? (y or n) ?. AFAICS what emacs calls "recursive delete" is what the ordinary person would simply call "delete". Presumably the non-recursive delete is called simply "delete" but is actually something more complicated than delete, and you're supposed to know what that is. Also (I'm speculating) a recursive delete means carrying out the (ordinary, non-recursive) delete process on sub-directories, recursively. The result of which is, put simply, to delete the directory. I find all this somewhat arcane. Questioning the precise suitability of the word "recursive" seems like a quibble. -- Mike Barnes Cheshire, England From luke.leighton at gmail.com Wed May 18 05:39:24 2011 From: luke.leighton at gmail.com (lkcl) Date: Wed, 18 May 2011 02:39:24 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: Message-ID: On May 18, 6:29?am, harrismh777 wrote: > Terry Reedy wrote: > > > No, because I think you are exaggerating. ?That said, I think core > > Python is pretty close to 'complete' and I would not mind further syntax > > freezes like the one for 3.2. > > I am exaggerating only to the extent that someone can imagine folks > becoming just annoyed with PEP progress to drop the whole thing... I am > exaggerating only to the extent that we define 'it' as language death... > if the user base narrows, python's future is held tentative... on the > other hand, if the user base grows and campers are happy, then python's > future is more stable... I don't think this is an exaggeration... one thing that people are not aware of - because it normally simply does not make its way out into the public world: you're forgetting those people who "just use" python. they don't get onto public mailing lists, they don't develop free software projects. i've mentioned this story before, but it's worth repeating in this context. i worked in a military environment (NC3A) back in 2006-2007. the version of python that they were using was http://python two... point... ONE. six years after its release. why??? well, it went something like this. someone got the idea that doing a portal would be good. so they looked around, and found Zope. so, they evaluated the latest version somewhere around ooo april to june of 2001. ok they _started_ evaluating it. so, some four months later, after doing some coding examples, we're now up to august 2001, a decision has to be made by the internal client. they say "yep, go for it", but that took another four months (dec 2002). now we do 18 months of software development (july 2003) to produce a base package. now the code now has to be handed over to a team who perform security evaluations. this has to be paid for. another six months go by, and the security accreditation is received (dec 2004). but this was just for the "base" code: now we have deployment and actual product / portal development, and a maintenance cycle of 2 years (2006). now i'm called in to help with that maintenance and development cycle (2007). and throughout this time there is *no way* that they can upgrade from python 2.1, because it would cost another $EUR 10,000 to get the accreditation certificate. it's now 2011. for all i know, some TEN YEARS after python 2.1 was released, they're still using it. you ... _just_ don't normally hear about these kinds of deployments of free software, but it illustrates that a particular version can hang around for a hell of a long time. l. From rustompmody at gmail.com Wed May 18 05:42:42 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 02:42:42 -0700 (PDT) Subject: Multiple python environments (was Python 2.7 Debian 6.0. Squeeze) References: Message-ID: On May 18, 12:41?pm, rusi wrote: > On May 18, 12:05?pm, Sebastien Douche wrote: > > > On Thu, May 12, 2011 at 17:27, Jorge Romero wrote: > > > I tried Googling about Python 2.7 on Debian Squeeze, but did not find > > > anything but discussions -.-. Anyone out there that can point me some > > > helpful material or anyone who had luck running 2.7 on Debian? > > > I use pythonbrew :http://pypi.python.org/pypi/pythonbrew > > Interesting. Is this an alternative to virtualenv? > > My overall impression of this area is that there are a zillion > alternatives > (Well ok exaggeration -- more alternatives than needed) > And all of them fail on some essential aspects. > > Yesterday I was trying to setup python on a client site and > easy_install kept giving errors. Not easy_install printing errors but > python printing backtraces. > > After repeatedly trying it a few times the errors disappeared. > > God alone knows... (or maybe Heisenberg...) pythonbrew does not run on windows [Just recording it here to save others time if/when they reach here] From marduk at letterboxes.org Wed May 18 07:47:28 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 18 May 2011 07:47:28 -0400 Subject: FW: help please In-Reply-To: References: <4DD29FF1.9090506@tysdomain.com> <1305661713.3831.1.camel@localhost.localdomain> Message-ID: <1305719249.29114.6.camel@localhost.localdomain> On Tue, 2011-05-17 at 21:46 -0300, Gabriel Genellina wrote: > En Tue, 17 May 2011 16:48:29 -0300, Albert Hopkins > escribi?: > > On Tue, 2011-05-17 at 10:18 -0600, Littlefield, Tyler wrote: > > >> Not to be pedantic or anything, and I may not be able to help > >> regardless, but it looks like your space key is fixed, and I don't > >> really care to pick through and try to play hangman with your message. > > > > I actually, at first glance, thought it was spam, ignored it, and was > > wondering why people were replying to it :| > > I can't remember exactly in which release 'perfect English skills' were > added to Python runtime requirements, could you please refresh my memory? I can't speak for Tyler (I assume your message was meant for him) but as for myself: I saw a glob of practically unreadable text and simply passed it off as spam, concluding that any well-intentioned, moderately intelligent human being wouldn't have intentionally posted such a monstrosity and actually expected an intelligent response. I'm guessing Tyler's message was to help you so that your messages don't continue to be ignored by people who may otherwise be of assistance. From invalid at peter.pmoylan.org.invalid Wed May 18 08:09:46 2011 From: invalid at peter.pmoylan.org.invalid (Peter Moylan) Date: Wed, 18 May 2011 22:09:46 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: Thomas A. Russ wrote: > "Pascal J. Bourguignon" writes: > >> Roland Hutchinson writes: > >>> Tail recursion can always be turned into an iteration when it is >>> executed. >> All recursions can be turned into iterations, before execution. > > True, but only by simulating the call stack in the iterative code. To > my mind that isn't really an iterative algorithm anymore if it ends up > simulating the call stack. When does a data structure stop being a simulation of a stack? I've often had to turn recursive algorithms into iterative ones, where the solution turned out to be "simulating the call stack" only in a very broad sense; a big stretch of the imagination is needed to see the equivalent of push or pop operations. > Tree walks are the canonical example of what can't be done in an > iterative fashion without the addition of an explicitly managed stack Let me throw in an example where the desired tree walk is neither depth-first or breadth-first. It's to do with the way I display my family tree on my web site; an example may be found at http://www.pmoylan.org/cgi-bin/wft.cmd?D=moylan;P=I004 Most people familiar with algorithm design will, I believe, end up deciding that the appropriate data structure in this case is a queue rather than a stack. ObAUE: In common parlance, the English word "recursion" means pretty much the same as what computing people call "iteration". This might be the first time I have ever found a point of agreement with Xah Lee. -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. From invalid at peter.pmoylan.org.invalid Wed May 18 08:19:16 2011 From: invalid at peter.pmoylan.org.invalid (Peter Moylan) Date: Wed, 18 May 2011 22:19:16 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: Harrison Hill wrote: > On May 18, 7:06 am, rusi wrote: >> I could continue down 2,3,4 but really it may be worthwhile if the >> arguers first read the wikipedia disambiguation pages on recursion... > > No need - I have the Dictionary definition of recursion here: > > Recursion: (N). See recursion. It's interesting to note that the definitions of 'recursive' to be found in Wikipedia and Wiktionary have very little in common with the definitions to be found in the dictionaries covered by Onelook. No wonder experts in different areas have trouble communicating with one another. -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. From smackay at flagstonesoftware.com Wed May 18 08:39:31 2011 From: smackay at flagstonesoftware.com (Stuart MacKay) Date: Wed, 18 May 2011 13:39:31 +0100 Subject: FW: help please In-Reply-To: <1305719249.29114.6.camel@localhost.localdomain> References: <4DD29FF1.9090506@tysdomain.com> <1305661713.3831.1.camel@localhost.localdomain> <1305719249.29114.6.camel@localhost.localdomain> Message-ID: <4DD3BE03.9060204@flagstonesoftware.com> On 18/05/2011 12:47, Albert Hopkins wrote: > On Tue, 2011-05-17 at 21:46 -0300, Gabriel Genellina wrote: >> En Tue, 17 May 2011 16:48:29 -0300, Albert Hopkins >> escribi?: >>> On Tue, 2011-05-17 at 10:18 -0600, Littlefield, Tyler wrote >>>> Not to be pedantic or anything, and I may not be able to help >>>> regardless, but it looks like your space key is fixed, and I don't >>>> really care to pick through and try to play hangman with your message. >>> I actually, at first glance, thought it was spam, ignored it, and was >>> wondering why people were replying to it :| >> I can't remember exactly in which release 'perfect English skills' were >> added to Python runtime requirements, could you please refresh my memory? > I can't speak for Tyler (I assume your message was meant for him) but as > for myself: I saw a glob of practically unreadable text and simply > passed it off as spam, concluding that any well-intentioned, moderately > intelligent human being wouldn't have intentionally posted such a > monstrosity and actually expected an intelligent response. > > I'm guessing Tyler's message was to help you so that your messages don't > continue to be ignored by people who may otherwise be of assistance. > Sure the English wasn't the best but there was enough information in the post to identify the likely source of the problem - with a little help from my favourite search engine - and give the guy/gal some ideas of where to look for a solution. If you were required to answer the question then asking the poster to phrase it better is going to help solve the issue faster but for a mailing list like this simply ignore it. Stuart From rustompmody at gmail.com Wed May 18 09:14:16 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 06:14:16 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> On May 18, 5:09?pm, Peter Moylan wrote: > > ObAUE: In common parlance, the English word "recursion" means pretty > much the same as what computing people call "iteration". ?This might be > the first time I have ever found a point of agreement with Xah Lee. Maybe the common usage mirrors the facts better than the lore that half-baked programmers remain devoted to. Consider first implementations: The implementation of recursion by a typical language (eg gcc for C) maximizes generality at the cost of efficiency The implementation of a very special case -- tail recursion -- in some special languages (most notably scheme) is required to be competitive with the iterative solution. [If I remember right in Chez scheme tail recursion was more efficient than a do (iteration) because a do typically needed assignment and assignment was more expensive than parameter passing] But there is a wide spectrum of cases between the most general case of recursion and tail recursion. Some examples 1 A non-tail recursive function, with a single recursive call, when implemented naively would push the return address. This is unnecessary as only a flag needs to be pushed -- return to internal call point or return to external call point. This itself can be efficiently simulated by storing the recursion depth -- zero => jump out; > 0 => jump to internal call 2. A single function with double recursion -- quicksort is the classic -- can be implemented without recursion or stack. It just needs a set of pending begin-end pairs yet to be sorted. This may look like the stack in another guise but unlike the stack it does not need to store any function call return paraphernalia. 3. Tree recursion (though not the case of the OP) can be solved non- recursively with threading http://en.wikipedia.org/wiki/Threaded_binary_tree and Schorr Waite Deutsch http://www.cs.cornell.edu/courses/cs312/2007fa/lectures/lec21-schorr-waite.pdf In fact the only example I can think of where the full blown generality of recursion cannot be tightened is perhaps recursive descent parsing. So much for implementations. Semantically the while loop while B: statement is equivalent to the recursion: def stateiter(): if B: statement stateiter() From spam at scheingraber.net Wed May 18 09:28:41 2011 From: spam at scheingraber.net (Christoph Scheingraber) Date: Wed, 18 May 2011 13:28:41 +0000 (UTC) Subject: connect SIGINT to custom interrupt handler References: <04cee22d-fc07-4c54-b91b-3f9e4730f095@glegroupsg2000goo.googlegroups.com> Message-ID: On 2011-05-15, Miki Tebeka wrote: > Why not just catch KeyboardInterrupt? Would it be possible to continue my program as nothing had happened in that case (like I did before, setting a flag to tell main() to finish the running data download and quit instead of starting the next data download {it's a for-loop})? I have tried it, but after catching the KeyboardInterrupt I could only continue to the next iteration. From luke.leighton at gmail.com Wed May 18 09:35:14 2011 From: luke.leighton at gmail.com (lkcl) Date: Wed, 18 May 2011 06:35:14 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> Message-ID: On May 18, 10:24?am, lkcl wrote: > > > ? otherwise please - really: just saying "give me support for python > > > 3.x or else" is ... > > > And I did not say that. > > ?yeah i know - i'm sorry: it just, with a little bit of "twisting", > could be construed as implying that. in case it wasn't clear, i apologise for doing that :) From luke.leighton at gmail.com Wed May 18 09:42:24 2011 From: luke.leighton at gmail.com (lkcl) Date: Wed, 18 May 2011 06:42:24 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: Message-ID: On May 17, 5:38?pm, harrismh777 wrote: > is recompiled everything still works... not so in Python. The fact that > Python is free to morph gleely from PEP to PEP without responsibility or > accountability with the user base is what may kill Python, unless the > Python community gets a grip on this concept. he's got a good point, terry. breaking backwards-compatibility was a completely mad and incomprehensible decision. i don't believe version N of python is going to "die" due to changes - the sheer inertia of hundreds of millions of lines of code and hundreds of thousands of projects will make sure that's not going to happen, but it doesn't help. it doesn't matter what the leading-edge developers behind python _want_ to happen: it took 10+ years for python 1 and 2 to gain traction, and i believe that's the sort of order of magnitude lag-time to expect people world-wide to make decisions [to replace code]. you only have to look at how long it's taking IE6 to die.... :) l. From marduk at letterboxes.org Wed May 18 09:48:13 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 18 May 2011 09:48:13 -0400 Subject: FW: help please In-Reply-To: <4DD3BE03.9060204@flagstonesoftware.com> References: <4DD29FF1.9090506@tysdomain.com> <1305661713.3831.1.camel@localhost.localdomain> <1305719249.29114.6.camel@localhost.localdomain> <4DD3BE03.9060204@flagstonesoftware.com> Message-ID: <1305726494.3259.0.camel@localhost.localdomain> On Wed, 2011-05-18 at 13:39 +0100, Stuart MacKay wrote: > If you were required to answer the question then asking the poster to > phrase it better is going to help solve the issue faster but for a > mailing list like this simply ignore it. Which is what I've done. From calderone.jeanpaul at gmail.com Wed May 18 10:16:40 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Wed, 18 May 2011 07:16:40 -0700 (PDT) Subject: connect SIGINT to custom interrupt handler References: <04cee22d-fc07-4c54-b91b-3f9e4730f095@glegroupsg2000goo.googlegroups.com> Message-ID: <18857efb-05be-42f0-8c62-40be5ec9dd26@gu8g2000vbb.googlegroups.com> On May 18, 9:28?am, Christoph Scheingraber wrote: > On 2011-05-15, Miki Tebeka wrote: > > > Why not just catch KeyboardInterrupt? > > Would it be possible to continue my program as nothing had happened in > that case (like I did before, setting a flag to tell main() to finish the > running data download and quit instead of starting the next data download > {it's a for-loop})? > > I have tried it, but after catching the KeyboardInterrupt I could only > continue to the next iteration. No, since the exception being raised represents a different flow of control through the program, one that is mutually exclusive with the flow of control which would be involved with continuing the processing in the "current" iteration of your loop. Setting SA_RESTART on SIGINT is probably the right thing to do. It's not totally clear to me from the messages in this thread if you managed to get that approach working. The most commonly encountered problem with this approach is that it means that any blocking (eg I/O) operation in progress won't be interrupted and you'll have to wait for it to complete normally. In this case, it sounds like this is the behavior you actually want, though. Jean-Paul From rbotting at csusb.edu Wed May 18 10:27:30 2011 From: rbotting at csusb.edu (RJB) Date: Wed, 18 May 2011 07:27:30 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: 9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com Message-ID: On May 17, 9:36?am, rusi wrote: > On May 17, 8:50?pm, RJB wrote: > > > > > > > I noticed some discussion of recursion..... the trick is to find a > > formula where the arguments are divided, not decremented. > > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > > for a couple of years in C++ but just for fun rewrote it > > in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! > > > def fibo(n): > > ? ? ? ? """A Faster recursive Fibonaci function > > Use a formula from Knuth Vol 1 page 80, section 1.2.8: > > ? ? ? ? ? ?If F[n] is the n'th Fibonaci number then > > ? ? ? ? ? ? ? ? ? ?F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. > > ? First set m = n+1 > > ? ?F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. > > > ? Then put m = n in Knuth's formula, > > ? ? ? ? ? ?F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], > > ? ?and replace F[n+1] by F[n]+F[n-1], > > ? ? ? ? ? ?F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). > > """ > > ? ? ? ? if n<=0: > > ? ? ? ? ? ? ? ? return 0 > > ? ? ? ? elif n<=2: > > ? ? ? ? ? ? ? ? return 1 > > ? ? ? ? elif n%2==0: > > ? ? ? ? ? ? ? ? half=n//2 > > ? ? ? ? ? ? ? ? f1=fibo(half) > > ? ? ? ? ? ? ? ? f2=fibo(half-1) > > ? ? ? ? ? ? ? ? return f1*(f1+2*f2) > > ? ? ? ? else: > > ? ? ? ? ? ? ? ? nearhalf=(n-1)//2 > > ? ? ? ? ? ? ? ? f1=fibo(nearhalf+1) > > ? ? ? ? ? ? ? ? f2=fibo(nearhalf) > > ? ? ? ? ? ? ? ? return f1*f1 + f2*f2 > > > RJB the Lurkerhttp://www.csci.csusb.edu/dick/cs320/lab/10.html > > ------------------------------------------------------------- > Its an interesting problem and you are 75% there. > You see the halving gives you logarithmic behavior and the double > calls give exponential behavior. > > So how to get rid of double calls? ?Its quite simple: Just define your > function in terms of return pairs of adjacent pairs ie (fib(n), fib(n > +1)) for some n rather then a single number fib(n) > > Here's a straightforward linear function: > > def fp(n): ?#fibpair > ? ? if n==1: > ? ? ? ? return (1,1) > ? ? else: > ? ? ? ? a,b = fp(n-1) > ? ? ? ? return (b, a+b) > > def fib(n): > ? ? a,b = fp(n) > ? ? return a > > --------------- > Now use this (pairing) idea with your (halving) identities and you > should get a logarithmic algo. > > [If you cant do it ask again but yes its fun to work out so do > try :-) ] Thank you! Very cool and clear. I hoped that there was something that Python made natural I couldn't see after 50 years in other languages. I'd like to work on combining both approaches. It may take a while... From ian.g.kelly at gmail.com Wed May 18 10:32:29 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 08:32:29 -0600 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <436ff55b-f61d-46a8-b5ea-f29d73190aba@s41g2000prb.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <436ff55b-f61d-46a8-b5ea-f29d73190aba@s41g2000prb.googlegroups.com> Message-ID: On Wed, May 18, 2011 at 1:10 AM, rusi wrote: >> Um, it is. ?Consider the simple function (lambda x, y: x + y). >> Mathematically, this function is recursive. ?Algorithmically, it is >> not. ?Do you disagree? > > See the definition of primitive recursion eg. > > http://en.wikipedia.org/wiki/Primitive_recursive_function#Definition > > (2 of the second set of "more complex" definitions) from where the > name 'primitive recursion' is presumably derived) > > And for the more general (wider) class of 'recursive' functions (in > the math sense aka computable functions) see a little below: > > http://en.wikipedia.org/wiki/Primitive_recursive_function#Relationship_to_recursive_functions I know what primitive recursive and computable functions are, thanks. What you're failing to explain is why you would consider that function to be recursive from a programming standpoint. In programming, when we say a function is recursive, we mean that it is implemented using the technique of recursion, not that it is computable. Since we're throwing around Wikipedia links, see the definition in the first sentence at: http://en.wikipedia.org/wiki/Recursion_%28computer_science%29 In fact, the mathematical definition would not be useful for programming since to us a function is an implementation of an algorithm (I expect Lispers may quibble over this, but it is true even there). Thus, in programming, all functions are computable. > Of course I grant that the adjective 'recursive' is used differently > in computability and in programming but the roots are not all that > different. Not just the adjective 'recursive', but also the noun 'function'. I'm not sure of the exact etymology of 'recursive', although I would bet that the mathematical usage came first and the programming usage is a derivative of it. From dotancohen at gmail.com Wed May 18 10:42:36 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 May 2011 17:42:36 +0300 Subject: obviscating python code for distribution In-Reply-To: <5h9ca8-ekq.ln1@svn.schaathun.net> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 10:36, Hans Georg Schaathun wrote: > But then, nothing is secure in any absolute sense. ?The best you can > do with all your security efforts is to manage risk. ?Since obfuscation > increases the cost of mounting an attack, it also reduces risk, > and thereby provides some level of security. > > Obviously, if your threat sources are dedicated hackers or maybe MI5, > there is no point bothering with obfuscation, but if your threat source > is script kiddies, then it might be quite effective. > The flip side is that the developer will not know about weaknesses until much later in the development, when making changes to the underlying code organization may be difficult or impossible. In this early phase of development, he should actually encourage the script kiddies to "report the bugs". -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From rustompmody at gmail.com Wed May 18 11:15:08 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 08:15:08 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <436ff55b-f61d-46a8-b5ea-f29d73190aba@s41g2000prb.googlegroups.com> Message-ID: <488559dd-b1a4-4b81-8d53-40f0af9773c0@d26g2000prn.googlegroups.com> On May 18, 7:32?pm, Ian Kelly wrote: > On Wed, May 18, 2011 at 1:10 AM, rusi wrote: > >> Um, it is. ?Consider the simple function (lambda x, y: x + y). > >> Mathematically, this function is recursive. ?Algorithmically, it is > >> not. ?Do you disagree? > > > See the definition of primitive recursion eg. > > >http://en.wikipedia.org/wiki/Primitive_recursive_function#Definition > > > (2 of the second set of "more complex" definitions) from where the > > name 'primitive recursion' is presumably derived) > > > And for the more general (wider) class of 'recursive' functions (in > > the math sense aka computable functions) see a little below: > > >http://en.wikipedia.org/wiki/Primitive_recursive_function#Relationshi... > > I know what primitive recursive and computable functions are, thanks. Myself, my memory of things studied badly decades ago may be fuzzy :D ) Anyhow taking those links to be authoritative, what I am saying is: Coming from the computability side, there are 3 related but distinct definitions of recursive: 1. Anything computable is recursive -- general recursive or partial recursive (evidently there is some dispute re these definitions http://mathworld.wolfram.com/RecursiveFunction.html 2. Primitive recursive -- ie any function that is defined using - constant - successor - projection - composition - primitive recursion [This definition is recursive in a bad sense but let that be... The first use of the term is for the set of functions such that... The second is for a specific operation. Comes to the third use: 3. The *operation* of primitive recursion is exactly what programmers call recursion. In other words one specific and characteristic operation is used to give the name to the set being defined. > What you're failing to explain is why you would consider that function > to be recursive from a programming standpoint. ? As for putting + under the format of primitive recursion, it would go something like this (I guess) Matching up that definition Put h is what is being defined ie + (or plus) k = 1 f = id g(y, ic, x) = S(ic) #ignore y and x, ic is internal (recursive) call Gives plus(0, x) = x plus((S y), x) = S(plus(y, x)) From rustompmody at gmail.com Wed May 18 11:23:17 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 08:23:17 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: 9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com Message-ID: <3ea62d61-cc9f-46ff-84a1-5c2cdfb1af13@18g2000prd.googlegroups.com> On May 18, 7:27?pm, RJB wrote: > Thank you! ?Very cool and clear. ?I > hoped that there was something that Python made natural I couldn't see > after 50 years in other languages. > > I'd like to work on combining both approaches. ?It may take a while... >From the Knuth identity F[n+m] = .. you pulled out two special cases F[2n+1] = .. and F[2n] = .. If you get one more: F[2n -1] = .. you are done From ian.g.kelly at gmail.com Wed May 18 11:43:24 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 09:43:24 -0600 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <488559dd-b1a4-4b81-8d53-40f0af9773c0@d26g2000prn.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <436ff55b-f61d-46a8-b5ea-f29d73190aba@s41g2000prb.googlegroups.com> <488559dd-b1a4-4b81-8d53-40f0af9773c0@d26g2000prn.googlegroups.com> Message-ID: On Wed, May 18, 2011 at 9:15 AM, rusi wrote: >> What you're failing to explain is why you would consider that function >> to be recursive from a programming standpoint. > > As for putting + under the format of primitive recursion, it would go > something like this (I guess) > > Matching up that definition > Put > h is what is being defined ie + (or plus) > k = 1 > f = id > g(y, ic, x) = S(ic) #ignore y and x, ic is internal (recursive) call > > Gives > > plus(0, x) = x > plus((S y), x) = S(plus(y, x)) You're still arguing mathematics. I am not disputing that the addition function is primitive recursive (in fact, I asserted that in my original reply). What I am saying is that this *implementation* of the addition function: def add(x, y): return y if x == 0 else add(x-1, y) + 1 is recursive in the programming sense (i.e. it uses the programming technique of recursion), while this implementation is not: def add(x, y): return x + y From claird271 at gmail.com Wed May 18 11:55:37 2011 From: claird271 at gmail.com (Cameron Laird) Date: Wed, 18 May 2011 08:55:37 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (May 18) Message-ID: QOTW: "When did we come to the idea that people should be able to program in a language without actually learning it? The fact that Python comes so close to that possibility is nothing short of revolutionary. I suppose one day a reasoning android will be able to sit down at the terminal of a star ship computer and ask simple questions while making random hand movements across a screen, but for now I am afraid that programmers still have to learn programming." - D'Arcy J.M. Cain - 2011-05-11 http://permalink.gmane.org/gmane.comp.python.general/690140 Fast way to convert a set into a list: http://groups.google.com/group/comp.lang.python/t/a3c72619c1e867e3/ 'Still time to submit a proposal to PyCon India 2011: http://pycon.blogspot.com/2011/05/pycon-india-2011-call-for-proposals.html How to make sure equal objects are unique: http://groups.google.com/group/comp.lang.python/t/a8889b7a327756dd/ generator.send() explained: http://groups.google.com/group/comp.lang.python/t/953c8f1f8a5f73ed/ "object of different types never compare equal", a documentation bug: http://groups.google.com/group/comp.lang.python/t/6ceb3a40dc263f25/ Ofuscating code: not a good idea http://groups.google.com/group/comp.lang.python/t/f887168ca476618f/ Summer pyGames Registration opens: http://pyfound.blogspot.com/2011/05/summer-pygames-registration-open.html The proper way to handle errors: http://groups.google.com/group/comp.lang.python/t/9c6a47de6bf8b352/ http://groups.google.com/group/comp.lang.python/t/79c38e653587d4a/ A long thread, now discussing an O(log n) algorithm for computing the Fibonacci sequence: http://groups.google.com/group/comp.lang.python/t/b713b14e3e0d9872/e9e64fa9a0348ad8?lnk=gst#e9e64fa9a0348ad8 Implementing a multi-dimensional array: a short but insightful response from Robert Kern: http://groups.google.com/group/comp.lang.python/t/f20a6522369d2bbe/ SciPy 2011, Austin, Texas, 11-16 July 2011: http://conference.scipy.org/scipy2011/index.php Unicode for dummies :-) : http://groups.google.com/group/comp.lang.python/t/23d8592a9170e26e/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From tar at sevak.isi.edu Wed May 18 12:16:26 2011 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 18 May 2011 09:16:26 -0700 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On 17 May 2011 23:42:20 -0700, Thomas A. Russ > wrote: > : Tree walks are the canonical example of what can't be done in an > : iterative fashion without the addition of an explicitly managed stack > > Of course you can do it. It isn't nice, but it is possible. > I assume that you refer to depth first walks, as breadth first > is more easily described by iteration on a queue in the first place. > > Depth first can be achieved by looping over the nodes, with a > state keeping references to the current and the previous node > considered. Well, unless you have a tree with backpointers, you have to keep the entire parent chain of nodes visited. Otherwise, you won't be able to find the parent node when you need to backtrack. A standard tree representation has only directional links. Consider: A--+---B----+---D | | | +---E | | | +---F | +---C If all you keep is the current and previous node, then the only thing you have reference do when doing the depth-first traverse is: 1. Current = A, Previous = null 2. Current = B. Previous = A 3. Current = D Previous = B 4. Current = E Previous = D 5. now what? You can't get from E or D back to B. > By comparing the previous node (pointer or ID) to the > current node's parent and children one will know wherefrom the > current node was entered, and can choose the next child in the > list as the next node, or the parent if all children have been > visited. A visit action may be added in any or all times the > node is visited. > > This node requires no stack. The only state space is constant, > regardless of the size of the tree, requiring just the two pointers > to previous and current. This will only work if there is a backpointer to the parent. So you have to add one extra pointer for each node back to its parent. This extra pointer will be the size of the graph, rather than (on average) log of the size of the graph stack frames. -- Thomas A. Russ, USC/Information Sciences Institute From ethan at stoneleaf.us Wed May 18 12:40:40 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 18 May 2011 09:40:40 -0700 Subject: Python 3.x and bytes In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> Message-ID: <4DD3F688.6030605@stoneleaf.us> Ian Kelly wrote: > On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: >> The big question, though, is would you do it this way: >> >> some_var = bytes(23).replace(b'\x00', b'a') >> >> or this way? >> >> some_var = bytes(b'a' * 23) > > Actually, I would just do it this way: > > some_var = b'a' * 23 > > That's already a bytes object. Passing it into the constructor is redundant. However, as I just discovered, it works well when dealing with a bytearray object: some_var = bytearray(b' ' * size) # want space initialized, not null ~Ethan~ From debatem1 at gmail.com Wed May 18 12:54:30 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 18 May 2011 09:54:30 -0700 Subject: obviscating python code for distribution In-Reply-To: <5h9ca8-ekq.ln1@svn.schaathun.net> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: > On Mon, 16 May 2011 23:42:40 +0100, Rhodri James > ? wrote: > : ?...which is, of course, not exactly secure either. ?A sufficiently > : ?determined hacker won't have much trouble disassembling a shared library > : ?even if you do strip out all the debug information. ?By chance I'm having > : ?to do something closely related to this at work just at the moment; it's > : ?hard, but far from impossible. > > But then, nothing is secure in any absolute sense. If you're talking security and not philosophy, there is such a thing as a secure system. As a developer you should aim for it. > The best you can > do with all your security efforts is to manage risk. ?Since obfuscation > increases the cost of mounting an attack, it also reduces risk, > and thereby provides some level of security. The on-the-ground reality is that it doesn't. Lack of access to the source code has not kept windows or adobe acrobat or flash player secure, and they have large full-time security teams, and as you might imagine from the amount of malware floating around targeting those systems there are a lot of people who have these skills in spades. > Obviously, if your threat sources are dedicated hackers or maybe MI5, > there is no point bothering with obfuscation, but if your threat source > is script kiddies, then it might be quite effective. On the theory that any attack model without an adversary is automatically secure? Geremy Condra From rosuav at gmail.com Wed May 18 13:24:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 03:24:12 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Thu, May 19, 2011 at 2:54 AM, geremy condra wrote: > On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: >> But then, nothing is secure in any absolute sense. > > If you're talking security and not philosophy, there is such a thing > as a secure system. As a developer you should aim for it. Agreed. Things can be secure if you accept caveats. A good server might be secure as long as attackers cannot, say: * Get physical access to the server, remove the hard disk, and tamper with it * Hold a gun to the developer and say "Log me in as root or you die" * Trigger a burst of cosmic rays that toggle some bits in memory If someone can do that, there's really not much you can do to stop them. But you CAN make a system 100% secure against network-based attacks. Denial of service attacks are the hardest to truly defend against, and if your level of business is low enough, you can probably ignore them in your code, and deal with them by human ("Hmm, we seem to be getting ridiculous amounts of traffic from XX.YY.ZZ.*, I think I'll put a temporary ban on that /24"). Although some really nasty DOSes can be blocked fairly easily, so it's worth thinking about them. But mainly: Don't panic about the really really obscure attack possibilities, the ones that would only happen if someone with a lot of resources is trying to bring you down. Just deal with the obvious stuff - make sure your server cannot be compromised via a standard network connection. Test your server by connecting with a basic TELNET client (or a hacked-up client, if it uses a binary protocol). Test your client by connecting it to a hacked-up server. Make sure you can't muck up either of them. Assume that any attacker will know every detail about your comms protocol, because chances are he will know most of it. Chris Angelico From john at castleamber.com Wed May 18 13:31:58 2011 From: john at castleamber.com (John Bokma) Date: Wed, 18 May 2011 12:31:58 -0500 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: <87mxijzzht.fsf@castleamber.com> Chris Angelico writes: > On Thu, May 19, 2011 at 2:54 AM, geremy condra wrote: >> On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: >>> But then, nothing is secure in any absolute sense. >> >> If you're talking security and not philosophy, there is such a thing >> as a secure system. As a developer you should aim for it. > > Agreed. Things can be secure if you accept caveats. A good server > might be secure as long as attackers cannot, say: > * Get physical access to the server, remove the hard disk, and tamper with it > * Hold a gun to the developer and say "Log me in as root or you die" > * Trigger a burst of cosmic rays that toggle some bits in memory You forgot the most important one: * if none of the software running on it has exploitable issues Personally, I think it's best to understand that no server is ever secure and hence one must always be prepared that a breach can happen. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From hg at schaathun.net Wed May 18 13:33:47 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 18:33:47 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, 18 May 2011 09:54:30 -0700, geremy condra wrote: : On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: : > But then, nothing is secure in any absolute sense. : : If you're talking security and not philosophy, there is such a thing : as a secure system. As a developer you should aim for it. You think so? Please name one, and let us know how you know that it is secure. : > and thereby provides some level of security. : : The on-the-ground reality is that it doesn't. Lack of access to the : source code has not kept windows or adobe acrobat or flash player : secure, and they have large full-time security teams, and as you might : imagine from the amount of malware floating around targeting those : systems there are a lot of people who have these skills in spades. You are just demonstrating that it does not provide complete security, something which I never argued against. : > Obviously, if your threat sources are dedicated hackers or maybe MI5, : > there is no point bothering with obfuscation, but if your threat source : > is script kiddies, then it might be quite effective. : : On the theory that any attack model without an adversary is : automatically secure? No, on the assumption that we were discussing real systems, real threats, and practical solutions, rather than models and theory. There will always be adversaries, but they have limited means, and limited interest in your system. And the limits vary. Any marginal control will stave off a few potential attackers who just could not be bothered. In theory, you can of course talk about absolute security. For instance, one can design something like AES?, which is secure in a very limited, theoretical model. However, to be of any practical use, AES must be built into a system, interacting with other systems, and the theory and skills to prove that such a system be secure simply has not been developed. Why do you think Common Criteria have not yet specified frameworks for the top levels of assurance? ? Advanced Encryption Standard -- :-- Hans Georg From debatem1 at gmail.com Wed May 18 13:40:51 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 18 May 2011 10:40:51 -0700 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 10:24 AM, Chris Angelico wrote: > On Thu, May 19, 2011 at 2:54 AM, geremy condra wrote: >> On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: >>> But then, nothing is secure in any absolute sense. >> >> If you're talking security and not philosophy, there is such a thing >> as a secure system. As a developer you should aim for it. > > Agreed. Things can be secure if you accept caveats. A good server > might be secure as long as attackers cannot, say: > * Get physical access to the server, remove the hard disk, and tamper with it > * Hold a gun to the developer and say "Log me in as root or you die" > * Trigger a burst of cosmic rays that toggle some bits in memory Just a note: you can do many cool things to prevent the last from working, assuming you're talking about RSA fault injection attacks. > If someone can do that, there's really not much you can do to stop > them. But you CAN make a system 100% secure against network-based > attacks. > > Denial of service attacks are the hardest to truly defend against, and > if your level of business is low enough, you can probably ignore them > in your code, and deal with them by human ("Hmm, we seem to be getting > ridiculous amounts of traffic from XX.YY.ZZ.*, I think I'll put a > temporary ban on that /24"). Although some really nasty DOSes can be > blocked fairly easily, so it's worth thinking about them. > > But mainly: Don't panic about the really really obscure attack > possibilities, the ones that would only happen if someone with a lot > of resources is trying to bring you down. Just deal with the obvious > stuff - make sure your server cannot be compromised via a standard > network connection. Just one caveat I would add to this: make sure you're drawing this line at the correct place. If your attack model is wrong things have a tendency to drop from 'impossible' to 'laughably easy' in a hurry. > Test your server by connecting with a basic TELNET client (or a > hacked-up client, if it uses a binary protocol). Test your client by > connecting it to a hacked-up server. Make sure you can't muck up > either of them. Assume that any attacker will know every detail about > your comms protocol, because chances are he will know most of it. I actually like to use scapy a lot. It's a little slow, but you can really get down deep and still feel sort of sane afterwards, and it makes it easier on you if you don't need to go all the way to the metal. Geremy Condra From rosuav at gmail.com Wed May 18 13:52:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 03:52:16 +1000 Subject: obviscating python code for distribution In-Reply-To: <87mxijzzht.fsf@castleamber.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <87mxijzzht.fsf@castleamber.com> Message-ID: On Thu, May 19, 2011 at 3:31 AM, John Bokma wrote: >> Agreed. Things can be secure if you accept caveats. A good server >> might be secure as long as attackers cannot, say: >> * Get physical access to the server, remove the hard disk, and tamper with it >> * Hold a gun to the developer and say "Log me in as root or you die" >> * Trigger a burst of cosmic rays that toggle some bits in memory > > You forgot the most important one: > > * if none of the software running on it has exploitable issues That's not a caveat. That's a purposeful and deliberate goal. And far from impossible. > Personally, I think it's best to understand that no server is ever > secure and hence one must always be prepared that a breach can happen. You need to balance the risk of a breach against the effort it'd take to prevent. See my comments re DOS attacks; it's not generally worth being preemptive with those, unless you're at a way higher transaction level than this discussion is about (for those who came in late, it's a basic network game, and not Google Docs or the DNS root servers or something). If it's going to impose 500ms latency on all packets just to prevent the one chance in 1E50 that you get some particular attack, then it's really not worthwhile. However, it IS possible to ensure that the server doesn't, for instance, trust the client; those extremely basic protections are well worth the effort (even if it seems like a lot of effort). Chris Angelico From see at sig.for.address Wed May 18 13:59:45 2011 From: see at sig.for.address (Victor Eijkhout) Date: Wed, 18 May 2011 12:59:45 -0500 Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> Harrison Hill wrote: > No need - I have the Dictionary definition of recursion here: > > Recursion: (N). See recursion. If you tell a joke, you have to tell it right. Recursion: (N). See recursion. See also tail recursion. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From rosuav at gmail.com Wed May 18 14:07:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 04:07:25 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Thu, May 19, 2011 at 3:40 AM, geremy condra wrote: > Just a note: you can do many cool things to prevent the last from > working, assuming you're talking about RSA fault injection attacks. Sure. Each of those caveats can be modified in various ways; keeping checksums of everything in memory, encrypting stored data with something that isn't stored on that computer, etc, etc, etc. But in terms of effort for gain, it's not usually worth it. However, it is a good idea to be aware of your caveats; for instance, are you aware that most Linux systems will allow a root login from another file system (eg a live-boot CD) to access the hard drive read-write, regardless of file ownership and passwords? (My boss wasn't, and was rather surprised at how easily it could be done.) >> But mainly: Don't panic about the really really obscure attack >> possibilities... > > Just one caveat I would add to this: make sure you're drawing this > line at the correct place. If your attack model is wrong things have a > tendency to drop from 'impossible' to 'laughably easy' in a hurry. Absolutely. Sometimes it's worth scribbling comments in your code like: /* TODO: If someone tries X, it might cause Y. Could rate-limit here if that's an issue. */ Then, you keep an administrative eye on the production code. If you start having problems, you can deal with them fast, rather than having the ridiculous situation of security issues lingering for months or years before finally getting a band-aid solution. >> Test your server by connecting with a basic TELNET client... > > I actually like to use scapy a lot. It's a little slow, but you can > really get down deep and still feel sort of sane afterwards, and it > makes it easier on you if you don't need to go all the way to the > metal. Sort of sane? I lost that feeling years ago. :) When I'm working on Windows, I'll sometimes use SMSniff for packet sniffing, but generally, I just stick with high level socket services and depend on the underlying libraries to deal with malformed packets and such. On Linux, I generally whip up a quick script to do whatever job on the spot (Python and Pike are both extremely well suited to this), but on Windows, I use my MUD client, RosMud, which has a "passive mode" option for playing the part of the server. Chris Angelico From hg at schaathun.net Wed May 18 14:11:29 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 19:11:29 +0100 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: ["Followup-To:" header set to comp.lang.python.] On 18 May 2011 09:16:26 -0700, Thomas A. Russ wrote: : Well, unless you have a tree with backpointers, you have to keep the : entire parent chain of nodes visited. Otherwise, you won't be able to : find the parent node when you need to backtrack. A standard tree : representation has only directional links. The array representation of a binary tree is standard, and the ?back? (parent) pointers are mathematically given. /Some/ standard tree representation do not have parent pointers. You are right that I assumed parent pointers of some description; but it does demonstrate that tree walks can be done iteratively, without keeping a stack of any sort. -- :-- Hans Georg From rosuav at gmail.com Wed May 18 14:12:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 04:12:49 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: On Thu, May 19, 2011 at 2:16 AM, Thomas A. Russ wrote: > Well, unless you have a tree with backpointers, you have to keep the > entire parent chain of nodes visited. ?Otherwise, you won't be able to > find the parent node when you need to backtrack. ?A standard tree > representation has only directional links. Sure, but there are plenty of trees that do have parent pointers. Widgets on every system I've tinkered with always have, and in a directory structure that doesn't allow files to be in multiple places, it's not hard (look at the . and .. entries in a directory). Of course, file systems are not idealized tree structures, so things will be a bit more complicated. ChrisA From raw at RAWMBP-2.local Wed May 18 14:20:01 2011 From: raw at RAWMBP-2.local (Raymond Wiker) Date: Wed, 18 May 2011 20:20:01 +0200 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On 18 May 2011 09:16:26 -0700, Thomas A. Russ > wrote: > : Well, unless you have a tree with backpointers, you have to keep the > : entire parent chain of nodes visited. Otherwise, you won't be able to > : find the parent node when you need to backtrack. A standard tree > : representation has only directional links. > > The array representation of a binary tree is standard, and the > ?back? (parent) pointers are mathematically given. /Some/ > standard tree representation do not have parent pointers. I don't think anybody mentioned *binary* trees. The context was directory traversal, in which case you would have nodes with an arbitrary (almost) number of children. > You are right that I assumed parent pointers of some description; > but it does demonstrate that tree walks can be done iteratively, > without keeping a stack of any sort. Except that the chain of parent pointers *would* constitue a stack. From tyler at tysdomain.com Wed May 18 14:26:45 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Wed, 18 May 2011 12:26:45 -0600 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: <4DD40F65.7090807@tysdomain.com> >might be secure as long as attackers cannot, say: You forgot UFOs. Anyway, again, thanks to everyone for the advice, this is good reading. Incidentally, I don't know to much about security. I know about rate limiting and dos attacks, as well as some others, but I think there's a lot more that I don't know--can someone kind of aim me in the right direction for some of this? I want to be able to take techniques, break my server and then fix it so that can't be done before I head to public with this. From dotancohen at gmail.com Wed May 18 14:30:00 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 May 2011 21:30:00 +0300 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 20:24, Chris Angelico wrote: > But you CAN make a system 100% secure against network-based > attacks. > Only by unplugging the network cable. This is called an air gap, and is common in military installations. Anything with a cable plugged in is hackable. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From dotancohen at gmail.com Wed May 18 14:31:48 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 May 2011 21:31:48 +0300 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 20:24, Chris Angelico wrote: > Denial of service attacks are the hardest to truly defend against, and > if your level of business is low enough, you can probably ignore them > in your code, and deal with them by human ("Hmm, we seem to be getting > ridiculous amounts of traffic from XX.YY.ZZ.*, I think I'll put a > temporary ban on that /24"). Although some really nasty DOSes can be > blocked fairly easily, so it's worth thinking about them. > The python code should not be concerned with DDoS, that is what iptables is for. Remember, never do in code what Linux will do for you. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From rosuav at gmail.com Wed May 18 14:37:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 04:37:30 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Thu, May 19, 2011 at 4:31 AM, Dotan Cohen wrote: > The python code should not be concerned with DDoS, that is what > iptables is for. Remember, never do in code what Linux will do for > you. In general, yes. Denial of service is a fairly broad term, though, and if there's a computationally-expensive request that a client can send, then it may be worth rate-limiting it. Or if there's a request that causes your server to send out inordinate amounts of data, and you're running it on a typical home internet connection, then that's a DOS vector too. So it's not only an iptables issue. But yes. The "system" is the entire system, not just the Python code you're writing. ChrisA From hg at schaathun.net Wed May 18 14:39:53 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 19:39:53 +0100 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: ["Followup-To:" header set to comp.lang.python.] On Wed, 18 May 2011 20:20:01 +0200, Raymond Wiker wrote: : I don't think anybody mentioned *binary* trees. The context was : directory traversal, in which case you would have nodes with an : arbitrary (almost) number of children. If we are being specific, then directory trees do have parent pointers. My point was really that ?standard tree representations? is not a well-defined concept, and having parent pointers is as standard as not having them. : Except that the chain of parent pointers *would* constitue a : stack. In the sense that the tree itself is a stack, yes. But if we consider the tree (or one of its branches) to be a stack, then the original claim becomes a tautology. But you do have a point. Keeping a stack of nodes on the path back to root is a great deal simpler and cheaper than a call stack, and not really a significant expense in context. -- :-- Hans Georg From rosuav at gmail.com Wed May 18 14:41:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 04:41:21 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: On Thu, May 19, 2011 at 4:20 AM, Raymond Wiker wrote: >> You are right that I assumed parent pointers of some description; >> but it does demonstrate that tree walks can be done iteratively, >> without keeping a stack of any sort. > > ? ? ? ?Except that the chain of parent pointers *would* constitue a > stack. Howso? It's part of your data structure, not part of your algorithm; and it's not something that grows and shrinks as you traverse. These considerations may be crucial if, for instance, you want to walk your tree in a signal handler, and you don't know how much memory is available to you... Chris Angelico From rosuav at gmail.com Wed May 18 14:49:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 04:49:30 +1000 Subject: obviscating python code for distribution In-Reply-To: <4DD40F65.7090807@tysdomain.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <4DD40F65.7090807@tysdomain.com> Message-ID: On Thu, May 19, 2011 at 4:26 AM, Littlefield, Tyler wrote: >>might be secure as long as attackers cannot, say: > You forgot UFOs. > Anyway, again, thanks to everyone for the advice, this is good reading. > Incidentally, I don't know to much about security. I know about rate > limiting and dos attacks, as well as some others, but I think there's a lot > more that I don't know--can someone kind of aim me in the right direction > for some of this? I want to be able to take techniques, break my server and > then fix it so that can't be done before I head to public with this. Your last sentence IS the right direction. The two easiest ways to find out if your system is secure are (1) try to break it, and (2) pore over the code and see what can be broken. When you start testing things, try doing things in the wrong order. Your server should either cope with it fine, or throw back an error to that client, but should never allow any action that that client hasn't already proven he's allowed to do. There's plenty of people here who know what they're talking about when it comes to security (just skim over this thread for a few good names!), so if you have specific questions regarding your Python code, do ask. Alternatively, if it's not particularly Python-related, I would be happy for you to email me privately; I'm a gamer, and run an online game, so I'd be quite willing to have a bit of a poke at your code. Chris Angelico From pjb at informatimago.com Wed May 18 14:57:25 2011 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Wed, 18 May 2011 20:57:25 +0200 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: <8762p7omzu.fsf@kuiper.lan.informatimago.com> tar at sevak.isi.edu (Thomas A. Russ) writes: > Well, unless you have a tree with backpointers, you have to keep the > entire parent chain of nodes visited. Otherwise, you won't be able to > find the parent node when you need to backtrack. A standard tree > representation has only directional links. > > Consider: > > A--+---B----+---D > | | > | +---E > | | > | +---F > | > +---C > > If all you keep is the current and previous node, then the only thing > you have reference do when doing the depth-first traverse is: > 1. Current = A, Previous = null > 2. Current = B. Previous = A > 3. Current = D Previous = B > 4. Current = E Previous = D > 5. now what? You can't get from E or D back to B. > >> By comparing the previous node (pointer or ID) to the >> current node's parent and children one will know wherefrom the >> current node was entered, and can choose the next child in the >> list as the next node, or the parent if all children have been >> visited. A visit action may be added in any or all times the >> node is visited. >> >> This node requires no stack. The only state space is constant, >> regardless of the size of the tree, requiring just the two pointers >> to previous and current. > > This will only work if there is a backpointer to the parent. No, you don't need backpointers; some cases have been mentionned in the other answer, but in general: (defun parent (tree node) (if (member node (children tree)) tree (some (lambda (child) (parent child node)) (children tree)))) Yes, the question wasn't about time complexity. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From tmac641382 at yahoo.com Wed May 18 15:06:07 2011 From: tmac641382 at yahoo.com (tmac641382 at yahoo.com) Date: Wed, 18 May 2011 12:06:07 -0700 (PDT) Subject: How To Make Fast Money Legally Message-ID: <99c99019-754c-4b43-8a84-22ab7f2fc498@bl1g2000vbb.googlegroups.com> HOW TO MAKE EASY MONEY FAST AND LEGALLY!!!!!!!! This seems to really have potential. This is the way the original post appeared when I first found it. Read it all then decide for yourself. It works for me! I found this on a bulletin board and decided to try it. A little while back, I was browsing through newsgroups, just like you are now, and came across an article similar to this that said you could make thousands of dollars within weeks with only an initial investment of $6.00! So I thought, "Yeah right, this must be a scam", but like most of us, I was curious, so I kept reading. Even though the investment was a measly $6, I had three questions that needed to be answered before I could get involved in this sort of thing. IS THIS REALLY LEGAL? I called a lawyer first. The lawyer was a little skeptical that I would actually make any CASH but he said it WAS LEGAL if I wanted to try it. I told him it sounded a lot like a chain letter but the details of the system (SEE BELOW) actually made it a legitimate legal business. 2. IS OK WITH THE POST OFFICE OR IS IT MAIL FRAUD? I called them: 1-800-725-2161 and they confirmed THIS IS ABSOLUTELY LEGAL! (See 18, h sections1302 NS 1341 of Postal Lottery Laws). This clarifies the program of collecting names and addresses for a mailing list. 3. IS IT RIGHT? Well, everyone who sends me a buck has a good chance of getting A LOT of CASH ... a much better chance than buying a lottery ticket!!! 4. WHAT IS THE BUSINESS? You are in the business of collecting mailing lists and recruiting new list developers. These questions answered, I decided to proceed. The instructions said that you have to send $1.00 to each of the 6 names and address stated in the article. You then place your own name and address in the bottom of the list at #6, and post the article in at least 300 newsgroups. (There are thousands) No catch, that was it. So, I invested the measly $6.00. Well GUESS WHAT!! Within 7 days, I started getting money in the mail! I was shocked! I figured it would end soon, but the money just kept coming in. In my first week, I made about $25.00. By the end of the second week I had made a total of over $1,000! In the third week I had over $10,000.00 and it's still growing. This is now my fourth week and I have made a total of just over $42,000.00 and it's still coming in rapidly. It's certainly worth $6.00, and 6 stamps, I have spent more than that on the lottery!! Let me tell you how this works and most importantly, why it works. Also, make sure you print a copy of this article NOW, so you can get the information off of it as you need it. I seems likely to me that if you follow the directions exactly, that you will start making more money than you thought possible by doing something so easy! Suggestion: Read this entire message carefully! (print it out or download it.) Follow the simple directions and watch the money come in! It's easy. It's legal. And, your investment is only $6.00 (Plus postage) IMPORTANT: This is not a rip-off; it is not indecent; it is not illegal; and it is virtually no risk - it really works!!!! If all of the following instructions are adhered to, you will receive extraordinary dividends. PLEASE NOTE: Please follow these directions EXACTLY, and $50,000 or more can be yours in 20 to 60 days. This program remains successful because of the honesty and integrity of the participants. Please continue its success by carefully adhering to the instructions. You will now become part of the Mail Order business. In this business your product is not solid and tangible, it's a service. You are in the business of developing Mailing Lists. Many large corporations are happy to pay big bucks for quality lists. However, the money made from the mailing lists is secondary to the income which is made from people like you and me asking to be included in that list. Here are the 4 easy steps to success: STEP 1: Get 6 separate pieces of paper and write the following on each piece of paper "PLEASE PUT ME ON YOUR MAILING LIST include your mailing address, the date and your signature." Now get 6 US $1.00 bills and place ONE inside EACH of the 6 pieces of paper so the bill will not be seen through the envelope (to prevent thievery). Next, place one paper in each of the 6 envelopes and seal them. You should now have 6 sealed envelopes, each with a piece of paper stating the above phrase, your name and address, and a $1.00 bill. What you are doing is creating a service. THIS IS ABSOLUTELY LEGAL! You are requesting a legitimate service and you are paying for it! Like most of us I was a little skeptical and a little worried about the legal aspects of it all. So I checked it out with the U.S. Post Office (1-800-725-2161) and they confirmed that it is indeed legal! Mail the 6 envelopes to the following addresses: 1.)T. Dunn 722 Hopital Rd. Dawson Springs, Ky 42408,USA 2.) K. Carpenter P.O. Box 5174 Rantoul Illinois 61866-5174 3) D. Stephens P.O. Box 512 Staunton, MI 24321 4) J. Zuk 13709 Flank March Ln Spotsylvania, VA 22553 5.) Cornelius Stewart 2821 Avenue b Fort Pierce, Fl 34947 6) M. Wright Jr 9930 Richmond Kansas City MO 64134 STEP 2: Now take the #1 name off the list that you see above, move the other names up (6 becomes 5, 5 becomes 4, etc...) and add YOUR Name as number 6 on the list. STEP 3: Change anything you need to, but try to keep this article as close to original as possible. Now, post your amended article to at least 300 newsgroups. (I think there are close to 32,000 groups) All you need is 300, but remember, the more you post, the more money you make! This is perfectly legal! If you have any doubts, refer to Title 18 Sec. 1302 & 1341 of the Postal lottery laws. PLEASE REMEMBER that this program remains successful because of the honesty and integrity of the participants and by their carefully adhering to the directions. Look at it this way. If you are of integrity, the program will continue and the money that so many others have received will come your way. NOTE: You want to retain every name and address sent to you, either on a computer or hard copy and keep the notes people send you. This VERIFIES that you are truly providing a service. (Also, it might be a good idea to wrap the $1 bill in dark paper to reduce the risk of mail theft.) So, as each post is downloaded and the directions carefully followed, six members will be reimbursed for their participation as a List Developer with one dollar each. Your name will move up the list geometrically so that when your name reaches the #1 position you will be receiving thousands of dollars in CASH!!! What an opportunity for only $6.00 ($1.00 for each of the first six people listed above) Send it now, add your own name to the list and you're in business! DIRECTIONS FOR HOW TO POST TO NEWSGROUPS STEP 1) You do not need to re-type this entire letter to do your own posting. Simply put your cursor at the beginning of this letter and drag your cursor to the bottom of this document, and select 'copy' from the edit menu. This will copy the entire letter into the computer's memory STEP 2) Open a blank 'notepad' file and place your cursor at the top of the blank page. From the 'edit' menu select 'paste'. This will paste a copy of the letter into notepad so that you can add your name to the list STEP 3) Save your new notepad file as a text file. If you want to do your postings in different settings, you'll always have this file to go back to. STEP 4) Use Netscape or Internet explorer and try searching for various newsgroups (on-line forums, message boards, chat sites, discussions.) STEP 5) Visit these message boards and post this article as a new message by highlighting the text of this letter and selecting paste from the edit menu. Fill in the Subject, this will be the header that everyone sees as they scroll through the list of postings in a particular group, click the post message button. You're done with your first one! Congratulations...THAT'S IT! All you have to do is jump to different newsgroups and post away, after you get the hang of it, it will take about 30 seconds for each newsgroup! REMEMBER, THE MORE NEWSGROUPS YOU POST IN, THE MORE MONEY YOU WILL MAKE!! BUT YOU HAVE TO POST A MINIMUM OF 300 That's it! You will begin receiving money from around the world within days! You may eventually want to rent a P.O. Box due to the large amount From debatem1 at gmail.com Wed May 18 15:07:49 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 18 May 2011 12:07:49 -0700 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 10:33 AM, Hans Georg Schaathun wrote: > On Wed, 18 May 2011 09:54:30 -0700, geremy condra > ? wrote: > : ?On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: > : > But then, nothing is secure in any absolute sense. > : > : ?If you're talking security and not philosophy, there is such a thing > : ?as a secure system. As a developer you should aim for it. > > You think so? ?Please name one, and let us know how you know that it > is secure. I was playing around with an HSM the other day that had originally targeted FIPS 140-3 level 5, complete with formal verification models and active side-channel countermeasures. I'm quite confident that it was secure in nearly any practical sense. > : > and thereby provides some level of security. > : > : ?The on-the-ground reality is that it doesn't. Lack of access to the > : ?source code has not kept windows or adobe acrobat or flash player > : ?secure, and they have large full-time security teams, and as you might > : ?imagine from the amount of malware floating around targeting those > : ?systems there are a lot of people who have these skills in spades. > > You are just demonstrating that it does not provide complete security, > something which I never argued against. Ah, my mistake- when you said 'some level of security' I read that as 'some meaningful level of security'. If you were arguing that it provided roughly as much protection to your code as the curtain of air surrounding you does to your body, then yes- you're correct. > : > Obviously, if your threat sources are dedicated hackers or maybe MI5, > : > there is no point bothering with obfuscation, but if your threat source > : > is script kiddies, then it might be quite effective. > : > : ?On the theory that any attack model without an adversary is > : ?automatically secure? > > No, on the assumption that we were discussing real systems, real > threats, and practical solutions, rather than models and theory. > There will always be adversaries, but they have limited means, and > limited interest in your system. ?And the limits vary. ?Any marginal > control will stave off a few potential attackers who just could not > be bothered. Empirically this doesn't appear to be a successful gambit, and from an attacker's point of view it's pretty easy to see why. When a system I'm trying to break turns out to have done something stupid like this, it really just ticks me off, and I know a lot of actual attackers who think the same way. > In theory, you can of course talk about absolute security. ?For > instance, one can design something like AES?, which is secure in > a very limited, theoretical model. ?However, to be of any practical > use, AES must be built into a system, interacting with other systems, > and the theory and skills to prove that such a system be secure simply > has not been developed. This is flatly incorrect. > Why do you think Common Criteria have not yet specified frameworks > for the top levels of assurance? Perhaps because the lower levels of 'assurance' don't seem to provide very much. Geremy Condra From raw at RAWMBP-2.local Wed May 18 15:09:15 2011 From: raw at RAWMBP-2.local (Raymond Wiker) Date: Wed, 18 May 2011 21:09:15 +0200 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On Wed, 18 May 2011 20:20:01 +0200, Raymond Wiker > wrote: > : I don't think anybody mentioned *binary* trees. The context was > : directory traversal, in which case you would have nodes with an > : arbitrary (almost) number of children. > > If we are being specific, then directory trees do have parent pointers. > My point was really that ?standard tree representations? is not a > well-defined concept, and having parent pointers is as standard as > not having them. I cannot see that going back to the original case (directory traversal) is any more specific than talking about a completely unrelated case (binary trees). Further, even though most(?) hierarchical file systems have parent pointers, this is not necessary. > : Except that the chain of parent pointers *would* constitue a > : stack. > > In the sense that the tree itself is a stack, yes. But if we > consider the tree (or one of its branches) to be a stack, then > the original claim becomes a tautology. No, the tree is not a stack, but the chain of parent pointers from a particular node may be considered as a stack that records the path taken to reach the current node. > But you do have a point. Keeping a stack of nodes on the path > back to root is a great deal simpler and cheaper than a call > stack, and not really a significant expense in context. For this particular operation, possibly. For other tree operations, a single parent pointer may not be sufficient. From rafadurancastaneda at gmail.com Wed May 18 15:42:33 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Wed, 18 May 2011 21:42:33 +0200 Subject: python logging In-Reply-To: <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> Message-ID: <4DD42129.7030705@gmail.com> On 18/05/11 03:09, Fei wrote: > On May 17, 6:55 pm, Ian Kelly wrote: >> On Tue, May 17, 2011 at 2:55 PM, Fei wrote: >>> where is default logging file on Mac? I saw lots of app just import >>> logging, and begins to logging.info(...) etc. I'm not sure where to >>> look at the logging configuration to figure out the log location. >> There is no default log file. You're seeing that because logging only >> needs to be configured by the program once, not on a per-module basis. >> Thus most modules will just do import logging on the assumption that >> the configuration has already been performed somewhere else. >> >> If no logging configuration is done at all, then the logging >> statements will have no effect. > Thanks Ian. That's not exactly how it works. You can use logging without any configuration and the default output will be console. In addition default logging level is warning, so: logging.info("Some text") won't show anything and logging.warning("Other text") will show: WARNING:root:Other text Please check the link I gave before. Bye From darcy at druid.net Wed May 18 15:48:13 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 18 May 2011 15:48:13 -0400 Subject: How To Make Fast Money Legally In-Reply-To: <99c99019-754c-4b43-8a84-22ab7f2fc498@bl1g2000vbb.googlegroups.com> References: <99c99019-754c-4b43-8a84-22ab7f2fc498@bl1g2000vbb.googlegroups.com> Message-ID: <20110518154813.7a06436f.darcy@druid.net> On Wed, 18 May 2011 12:06:07 -0700 (PDT) "tmac641382 at yahoo.com" wrote: > HOW TO MAKE EASY MONEY FAST AND LEGALLY!!!!!!!! Wow! Was this stuck in someone's mail queue since 1992? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From hg at schaathun.net Wed May 18 15:56:17 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 20:56:17 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: <1skda8-3as.ln1@svn.schaathun.net> On Wed, 18 May 2011 12:07:49 -0700, geremy condra wrote: : I was playing around with an HSM the other day that had originally : targeted FIPS 140-3 level 5, complete with formal verification models : and active side-channel countermeasures. I'm quite confident that it : was secure in nearly any practical sense. And you ostensibly use the word /nearly/ rather than ?absolutely?. It seems that we agree. BTW, according to the sources I can find quickly, FIPS 140-3 targets /modules/ and not systems. : Ah, my mistake- when you said 'some level of security' I read that as : 'some meaningful level of security'. If you were arguing that it : provided roughly as much protection to your code as the curtain of air : surrounding you does to your body, then yes- you're correct. Well, I didn't. Whether it is meaningful is relative and dependent on the context, but it sure isn't meaningful if any values at stake are. : Empirically this doesn't appear to be a successful gambit, and from an : attacker's point of view it's pretty easy to see why. When a system : I'm trying to break turns out to have done something stupid like this, : it really just ticks me off, and I know a lot of actual attackers who : think the same way. That is very true. It is a very crude measure with a marginal effect on risk. Going out of one's way to try to obfuscate the code as machine code, as was the starting point of the discussion, is surely not a good strategy, as one is then spending significant time to achieve a rather insignificant. My main concern is that the use of absolutes, ?you need this?, and ?that is silly?, is drawing attention from the main point. Rather, get to know your risks and focus on the greater ones. Consider possible controls, and choose cheap and effective ones. Even a marginally effective control may be worth-while if the cost is even less. We all seem to agree on the main point; many have argued the same way. As an aside, OTOH, don't you think MAYFARE would have been broken earlier if the source code were open? It was around for ages before it was. : > In theory, you can of course talk about absolute security. ?For : > instance, one can design something like AES?, which is secure in : > a very limited, theoretical model. ?However, to be of any practical : > use, AES must be built into a system, interacting with other systems, : > and the theory and skills to prove that such a system be secure simply : > has not been developed. : : This is flatly incorrect. Which part of it? If you claim that the theory and skills to prove it exist, could you give a reference please? Of course, if you are only thinking of ?nearly any practical sense? again, then we agree and always did. : > Why do you think Common Criteria have not yet specified frameworks : > for the top levels of assurance? : : Perhaps because the lower levels of 'assurance' don't seem to provide very much. If the lower levels do not, would that not be an argument to implement more levels? Too many governments have put too much resources into this to just throw it away if the methodology to achieve higher assurance could be codified. Or maybe it is right to say that the theory and skills do exist, but the money to gather it all in one project to demonstrate the security of a single system does not :-) -- :-- Hans Georg From xahlee at gmail.com Wed May 18 16:00:01 2011 From: xahlee at gmail.com (Xah Lee) Date: Wed, 18 May 2011 13:00:01 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: Xah wrote: ?English Idiom in Unix: Directory Recursively? http://xahlee.org/comp/idiom_directory_recursively.html Mike Barnes wrote: > Xah Lee : > > >For example, when you want to delete the whole dir in emacs, it > >prompts this message: ?Recursive delete of xx? (y or n) ?. > > AFAICS what emacs calls "recursive delete" is what the ordinary person > would simply call "delete". Presumably the non-recursive delete is > called simply "delete" but is actually something more complicated than > delete, and you're supposed to know what that is. > > Also (I'm speculating) a recursive delete means carrying out the > (ordinary, non-recursive) delete process on sub-directories, > recursively. The result of which is, put simply, to delete the > directory. > > I find all this somewhat arcane. Questioning the precise suitability of > the word "recursive" seems like a quibble. that's good point. I think what happens is that the ?recursive? has become a idiom associated with directory to such a degree that the unix people don't know what the fuck they are talking about. They just simply use the word to go with directory whever they mean the whole directory. In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it possibly mean by the word ?recursive? there? Like, it might delete the directory but not delete all files in it? also, in the rsync case: ?This would recursively transfer all files from the directory ? ?, what does the word ?recursively? mean there? Xah From hg at schaathun.net Wed May 18 16:02:43 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 21:02:43 +0100 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: <38lda8-8as.ln1@svn.schaathun.net> ["Followup-To:" header set to comp.lang.python.] On Wed, 18 May 2011 21:09:15 +0200, Raymond Wiker wrote: : > In the sense that the tree itself is a stack, yes. But if we : > consider the tree (or one of its branches) to be a stack, then : > the original claim becomes a tautology. : : No, the tree is not a stack, but the chain of parent pointers : from a particular node may be considered as a stack that records the : path taken to reach the current node. That is one of its branches, yes, path from root towards leaf. It is part of the data structure, and you don't travers a data structure without using the datastructure. : > But you do have a point. Keeping a stack of nodes on the path : > back to root is a great deal simpler and cheaper than a call : > stack, and not really a significant expense in context. : : For this particular operation, possibly. For other tree : operations, a single parent pointer may not be sufficient. Que? What tree operations do you have in mind? We have covered all the standard textbook tree walks by now. -- :-- Hans Georg From nagle at animats.com Wed May 18 16:07:59 2011 From: nagle at animats.com (John Nagle) Date: Wed, 18 May 2011 13:07:59 -0700 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: <4dd4274a$0$1843$742ec2ed@news.sonic.net> On 5/17/2011 3:26 PM, Xah Lee wrote: > might be of interest. > > ?English Idiom in Unix: Directory Recursively? > http://xahlee.org/comp/idiom_directory_recursively.html > > ------------------------------------------ > English Idiom in Unix: Directory Recursively > > Xah Lee, 2011-05-17 > > Today, let's discuss something in the category of lingustics. > > You know how in unix tools, when you want to delete the whole > directory and all sub-directories and files in it, it's referred as > ?recursive?? The proper terminology is "subtree", "subfolder", or "subdirectory". John Nagle From hg at schaathun.net Wed May 18 16:19:22 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 21:19:22 +0100 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: ["Followup-To:" header set to comp.lang.python.] On Wed, 18 May 2011 13:00:01 -0700 (PDT), Xah Lee wrote: : Mike Barnes wrote: : > I find all this somewhat arcane. Questioning the precise suitability of : > the word "recursive" seems like a quibble. : : that's good point. I think what happens is that the ?recursive? has : become a idiom associated with directory to such a degree that the : unix people don't know what the fuck they are talking about. They just : simply use the word to go with directory whever they mean the whole : directory. I totally agree that the motivation for the use of the word is arcane. We are many who understand and /need/ to understand arcane aspects of the system. However, the word ?recursive? is not automatically associated with discussion of directories. Listing a directory, and listing a directory recursively, are two different operations. Both are useful and important, and the distinction is necessary. : In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it : possibly mean by the word ?recursive? there? Like, it might delete the : directory but not delete all files in it? Yes you /might/ do exactly that. You just probably don't want to. I agree that the question could be rephrased in a more userfriendly manner, but OTOH, if you find the usage arcane, you probably don't have any benefit from using emacs over less arcane editors either. : also, in the rsync case: ?This would recursively transfer all files : from the directory ? ?, what does the word ?recursively? mean there? Exactly the same as it does in ?listing the directory recursively? or ?deleting the directory recursively?. Again the distinction could be useful. A non-recursive ?rsync dir1 dir2? probably isn't useful, but ?rsync * dir2? might be. -- :-- Hans Georg From lanarcam1 at yahoo.fr Wed May 18 16:33:00 2011 From: lanarcam1 at yahoo.fr (Lanarcam) Date: Wed, 18 May 2011 22:33:00 +0200 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: <4dd42cf8$0$26337$426a74cc@news.free.fr> Hans Georg Schaathun ?crivit: > > : also, in the rsync case: ?This would recursively transfer all files > : from the directory ? ?, what does the word ?recursively? mean there? > > Exactly the same as it does in ?listing the directory recursively? > or ?deleting the directory recursively?. Traversing recursively a directory is more readily understandable when there are sub-directories, the operation involves going down those sub-directories and applying the same function ad infinitum. Excuse my Latin. > Again the distinction could be useful. A non-recursive ?rsync dir1 > dir2? probably isn't useful, but ?rsync * dir2? might be. > From raw at RAWMBP-2.local Wed May 18 16:40:28 2011 From: raw at RAWMBP-2.local (Raymond Wiker) Date: Wed, 18 May 2011 22:40:28 +0200 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <38lda8-8as.ln1@svn.schaathun.net> Message-ID: Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On Wed, 18 May 2011 21:09:15 +0200, Raymond Wiker > wrote: > : > In the sense that the tree itself is a stack, yes. But if we > : > consider the tree (or one of its branches) to be a stack, then > : > the original claim becomes a tautology. > : > : No, the tree is not a stack, but the chain of parent pointers > : from a particular node may be considered as a stack that records the > : path taken to reach the current node. > > That is one of its branches, yes, path from root towards leaf. > It is part of the data structure, and you don't travers a data > structure without using the datastructure. > > : > But you do have a point. Keeping a stack of nodes on the path > : > back to root is a great deal simpler and cheaper than a call > : > stack, and not really a significant expense in context. > : > : For this particular operation, possibly. For other tree > : operations, a single parent pointer may not be sufficient. > > Que? What tree operations do you have in mind? We have covered > all the standard textbook tree walks by now. I said tree operations, not tree walks. A tree operation might involve several tree walks. Further, there has been an implicit assumption (I think) in this discussion that the order of children is given, or does not matter - if this is not the case, then you also need to maintain a stack of data structures representing lists (or sets) of children. From NotR at bestweb.net Wed May 18 16:54:49 2011 From: NotR at bestweb.net (Glenn Knickerbocker) Date: Wed, 18 May 2011 16:54:49 -0400 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: On 05/18/2011 02:50 AM, Harrison Hill wrote: > Recursion: (N). See recursion. The index of IBM's Document Composition Facility SCRIPT/VS Text Programmer's Guide, Release 3.0 (form SH35-0069-2), put it thus: > Circular definition > See definition, circular > definition > circular 211 > See also circular definition Sadly, only the Release 4 manuals are available online anymore. ?R From mikebarnes at bluebottle.com Wed May 18 17:00:22 2011 From: mikebarnes at bluebottle.com (Mike Barnes) Date: Wed, 18 May 2011 22:00:22 +0100 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: Xah Lee : >In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it >possibly mean by the word ?recursive? there? Like, it might delete the >directory but not delete all files in it? My understanding is that non-recursive means, I think there are no (non- empty?) subdirectories, or I haven't given the matter any thought, so if there are any such subdirectories, tell me and don't do anything. Recursive means I want everything deleted regardless. BICBW. -- Mike Barnes Cheshire, England From ian.g.kelly at gmail.com Wed May 18 17:29:47 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 15:29:47 -0600 Subject: python logging In-Reply-To: <4DD42129.7030705@gmail.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> Message-ID: 2011/5/18 Rafael Dur?n Casta?eda : > That's not exactly how it works. You can use logging without any > configuration and the default output will be console. In addition default > logging level is warning, so: > > logging.info("Some text") > > won't ?show anything and > > logging.warning("Other text") > > will show: > > WARNING:root:Other text > > Please check the link I gave before. > > Bye Odd. That seems to work, but it contradicts the documentation at: http://docs.python.org/howto/logging.html#what-happens-if-no-configuration-is-provided From debatem1 at gmail.com Wed May 18 17:34:46 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 18 May 2011 14:34:46 -0700 Subject: obviscating python code for distribution In-Reply-To: <1skda8-3as.ln1@svn.schaathun.net> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 12:56 PM, Hans Georg Schaathun wrote: > On Wed, 18 May 2011 12:07:49 -0700, geremy condra > ? wrote: > : ?I was playing around with an HSM the other day that had originally > : ?targeted FIPS 140-3 level 5, complete with formal verification models > : ?and active side-channel countermeasures. I'm quite confident that it > : ?was secure in nearly any practical sense. > > And you ostensibly use the word /nearly/ rather than ?absolutely?. > It seems that we agree. Systems can be designed that are absolutely secure under reasonable assumptions. The fact that it has assumptions does not make your statement true. > BTW, according to the sources I can find quickly, FIPS 140-3 > targets /modules/ and not systems. I can't tell if you're trying to play word games with the distinction between "system" and "module" or if you're just saying that you aren't sure what FIPS actually certifies. Could you please clarify? > : ?Ah, my mistake- when you said 'some level of security' I read that as > : ?'some meaningful level of security'. If you were arguing that it > : ?provided roughly as much protection to your code as the curtain of air > : ?surrounding you does to your body, then yes- you're correct. > > Well, I didn't. ?Whether it is meaningful is relative and dependent > on the context, but it sure isn't meaningful if any values at stake are. Again, I'm unsure what you're going for here. It sounds like you're saying that obfuscation doesn't provide meaningful security, which is my point. > : ?Empirically this doesn't appear to be a successful gambit, and from an > : ?attacker's point of view it's pretty easy to see why. When a system > : ?I'm trying to break turns out to have done something stupid like this, > : ?it really just ticks me off, and I know a lot of actual attackers who > : ?think the same way. > > That is very true. ?It is a very crude measure with a marginal > effect on risk. ?Going out of one's way to try to obfuscate the > code as machine code, as was the starting point of the discussion, > is surely not a good strategy, as one is then spending significant > time to achieve a rather insignificant. > > My main concern is that the use of absolutes, ?you need this?, and > ?that is silly?, is drawing attention from the main point. ?Rather, > get to know your risks and focus on the greater ones. ?Consider > possible controls, and choose cheap and effective ones. ?Even a > marginally effective control may be worth-while if the cost is even > less. ?We all seem to agree on the main point; many have argued the > same way. > > As an aside, OTOH, don't you think MAYFARE would have been broken > earlier if the source code were open? ?It was around for ages before > it was. Are you talking about the Mayfair classical cipher here? > : > In theory, you can of course talk about absolute security. ?For > : > instance, one can design something like AES?, which is secure in > : > a very limited, theoretical model. ?However, to be of any practical > : > use, AES must be built into a system, interacting with other systems, > : > and the theory and skills to prove that such a system be secure simply > : > has not been developed. > : > : ?This is flatly incorrect. > > Which part of it? ?If you claim that the theory and skills to prove it > exist, could you give a reference please? The entire field of formal modeling and verification has grown around solving this problem. My new favorite in the field is "formal models and techniques for analyzing security protocols", but there are other works discussing OS kernel verification (which has gotten a lot of attention lately) and tons of academic literature. Google (scholar) is the place to go. > Of course, if you are only thinking of ?nearly any practical sense? > again, then we agree and always did. Nope, talking about formal methods. > : > Why do you think Common Criteria have not yet specified frameworks > : > for the top levels of assurance? > : > : ?Perhaps because the lower levels of 'assurance' don't seem to provide very much. > > If the lower levels do not, would that not be an argument to implement > more levels? ?Too many governments have put too much resources into > this to just throw it away if the methodology to achieve higher assurance > could be codified. If you can't say with confidence that something meets minimum security standards, the answer is not to try to say it meets high security standards. > Or maybe it is right to say that the theory and skills do exist, but the > money to gather it all in one project to demonstrate the security of > a single system does not :-) Sorry, but again this is not correct. Geremy Condra From debatem1 at gmail.com Wed May 18 17:47:52 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 18 May 2011 14:47:52 -0700 Subject: obviscating python code for distribution In-Reply-To: <4DD40F65.7090807@tysdomain.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <4DD40F65.7090807@tysdomain.com> Message-ID: On Wed, May 18, 2011 at 11:26 AM, Littlefield, Tyler wrote: >>might be secure as long as attackers cannot, say: > You forgot UFOs. > Anyway, again, thanks to everyone for the advice, this is good reading. > Incidentally, I don't know to much about security. I know about rate > limiting and dos attacks, as well as some others, but I think there's a lot > more that I don't know--can someone kind of aim me in the right direction > for some of this? I want to be able to take techniques, break my server and > then fix it so that can't be done before I head to public with this. One good thing to do is to just read some of the black hat papers. They're pretty accessible and even if you don't know everything they're saying you should be able to get a general feel for things that way. You might also try working through things like Damn Vulnerable Web App, if you have the time. Geremy Condra From rafadurancastaneda at gmail.com Wed May 18 18:01:03 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Thu, 19 May 2011 00:01:03 +0200 Subject: python logging In-Reply-To: References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> Message-ID: <4DD4419F.5080400@gmail.com> On 18/05/11 23:29, Ian Kelly wrote: > 2011/5/18 Rafael Dur?n Casta?eda: >> That's not exactly how it works. You can use logging without any >> configuration and the default output will be console. In addition default >> logging level is warning, so: >> >> logging.info("Some text") >> >> won't show anything and >> >> logging.warning("Other text") >> >> will show: >> >> WARNING:root:Other text >> >> Please check the link I gave before. >> >> Bye > Odd. That seems to work, but it contradicts the documentation at: > > http://docs.python.org/howto/logging.html#what-happens-if-no-configuration-is-provided I think you are confuse because of you are looking at advanced logging, where getLogger is being used. Simple logging works without any configuration, getLogger doesn't. From tjreedy at udel.edu Wed May 18 18:02:53 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 May 2011 18:02:53 -0400 Subject: pyjamas 0.8alpha1 release In-Reply-To: References: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> Message-ID: On 5/18/2011 5:24 AM, lkcl wrote: There seem to be two somewhat separate requirement issues: the interpreter binary and the language version. > a) at the moment a http://python.org 2.N interpreter is required to > actually run the translator. if you use http://python.org 2.5 or 2.6 > you do not need to use the "--internal-ast" option. if you use 2.4, > 2.7 or above, you will need to use --internal-ast because we're > heavily reliant on the internal c-based "compile" module [without the > --internal-ast option enabled]. I presume '--internal-ast' is a 'compile the interpreter' option. Since I have never compilied Python (or anything else for perhaps 15 years), I do not understand completely. Am I correct to guess that the PSF Windows binaries for 2.7 were not compiled with the flag, and will not work? If so, Windows users should, I would think, use the latest 2.6.6 binaries. > b) the actual pyjs interpreter grammar (AST) was 2.5 but has mostly > been updated to 2.6. actual python syntax / features are therefore > mostly 2.5, with someone having pointed out that "slice" has different > return results it's hard to say exactly which is best to be picked, > 2.5 or 2.6. nobody's needed slice until recently, so it's not an > issue that's ever come up before. If I understand this, the safe thing to do is to stick with 2.5 syntax and omit exotic 3.x features put into 2.6 for eventual porting to 3.x. > the thing is - it's worth reiterating: you just... really don't need > as much python interoperability for user-interfaces when they're split > along MVC lines. bear in mind that it's necessary to do that split: > it's web browser technology, you can't *actually* execute things like > psycopg or mysql in a web browser as javascript! so once you've > divided that application into "python that runs the actual user > interface" and "python on the other side of the AJAX barrier e.g. a > django app" you're left with a far smaller task for the pyjs > interpreter to have to tackle. I do not get all this but it seems to say that I do not really need all the features of the later Pythons to write user-interface code. But I am not sure how this applies to business code behind the front end. Of course, it might work to run the UI in a separate process if on the same machine. >>> otherwise please - really: just saying "give me support for python >>> 3.x or else" is ... >> >> And I did not say that. > > yeah i know - i'm sorry: it just, with a little bit of "twisting", > could be construed as implying that. Let me be clear: some people think that free (as in beer) software developers have some sort of one-sided responsibility or obligation to users who pay nothing. I don't. If I say "Give me a Python 3 version of pyjamas or I will not use it", I consider you free to respond "Fine, don't use it." End of story until I compromise or contribute. I feel free to say the same to anyone who says "Stop developing new versions of Python or I will quit using the current version". > :) i think... people forget that there are now two mutually- > exclusively-incompatible programming languages out there, where the > first six letters of the name of the programming language happen to be > the same... Something of an exaggeration. It might well be possible to use a 3to2 frontend and run a mildly restricted subset of 3.x. -- Terry Jan Reedy From ian.g.kelly at gmail.com Wed May 18 18:10:20 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 16:10:20 -0600 Subject: python logging In-Reply-To: <4DD4419F.5080400@gmail.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> Message-ID: 2011/5/18 Rafael Dur?n Casta?eda : > I think you are confuse because of you are looking at advanced logging, > where getLogger is being used. Simple logging works without any > configuration, getLogger doesn't. It seems to work without any configuration just as well as the root logger: >>> import logging >>> logging.getLogger('foo').warning('test') WARNING:foo:test Or am I misunderstanding you? From rafadurancastaneda at gmail.com Wed May 18 18:21:56 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Thu, 19 May 2011 00:21:56 +0200 Subject: python logging In-Reply-To: References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> Message-ID: <4DD44684.1080504@gmail.com> On 19/05/11 00:10, Ian Kelly wrote: > 2011/5/18 Rafael Dur?n Casta?eda: >> I think you are confuse because of you are looking at advanced logging, >> where getLogger is being used. Simple logging works without any >> configuration, getLogger doesn't. > It seems to work without any configuration just as well as the root logger: > >>>> import logging >>>> logging.getLogger('foo').warning('test') > WARNING:foo:test > > Or am I misunderstanding you? Are you using python 2.x or 3.x? At python 2.7 using: import logging logging.getLogger('log').warning('test') I got: No handlers could be found for logger "log" From martin.hellwig at gmail.com Wed May 18 18:22:05 2011 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Wed, 18 May 2011 22:22:05 +0000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: On 17/05/2011 23:20, Ian Kelly wrote: > On Tue, May 17, 2011 at 4:26 PM, Xah Lee wrote: >> Though, if you think about it, it's not exactly a correct description. >> ?Recursive?, or ?recursion?, refers to a particular type of algorithm, >> or a implementation using that algorithm. > > Only when used as programming jargon. In mathematics, "recursive > function" does *not* mean "a function implemented using a recursive > algorithm". It's just a formal definition of a specific class of > mathematical functions. > > As it turns out, "recursive" also has a non-technical definition, > which again has nothing to do with algorithms except in the broadest > sense: > > recursive adj. > 1. pertaining to or using a rule or procedure that can be applied repeatedly > (from dictionary.com) > > This definition fits the Unix usage perfectly. I concur, although my dictionary defines the base of the word: "to happen many times or to happen again" http://dictionary.cambridge.org/dictionary/british/recur#recur__3 Perhaps the gp of the post might profit from a more holistic approach when adopting an opinion or at least consult a dictionary before going into a rant. -- mph From vinay_sajip at yahoo.co.uk Wed May 18 18:27:30 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 18 May 2011 15:27:30 -0700 (PDT) Subject: python logging References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> Message-ID: On May 18, 11:10?pm, Ian Kelly wrote: > It seems to work without any configuration just as well as the root logger: > > >>> importlogging > >>>logging.getLogger('foo').warning('test') > > WARNING:foo:test > > Or am I misunderstanding you? In general for Python 2.x, the code import logging logging.getLogger('foo').warning('test') will produce No handlers could be found for logger "foo" unless loggers have been configured, e.g. by calling logging.warning() - that call implicitly adds a console handler to the root logger, if no other handlers have been configured for the root logger. In Python 3.2 and later, if no handlers have been configured, messages at level WARNING and greater will be printed to sys.stderr using a "handler of last resort" - see http://docs.python.org/py3k/howto/logging.html#what-happens-if-no-configuration-is-provided Regards, Vinay Sajip From ian.g.kelly at gmail.com Wed May 18 18:30:18 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 16:30:18 -0600 Subject: Indexable properties recipe Message-ID: http://code.activestate.com/recipes/577703-item-properties/ From ian.g.kelly at gmail.com Wed May 18 18:37:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 16:37:52 -0600 Subject: python logging In-Reply-To: <4DD44684.1080504@gmail.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> <4DD44684.1080504@gmail.com> Message-ID: 2011/5/18 Rafael Dur?n Casta?eda : > Are you using python 2.x or 3.x? At python 2.7 using: > > import logging > logging.getLogger('log').warning('test') > > I got: > > No handlers could be found for logger "log" Ah, that's it. I was using Python 2.5. Using 2.7 I get the same result that you do. Still, it's a surprising change that doesn't seem to be documented as such. I'm not sure whether it's a regression or an intentional change. From ian.g.kelly at gmail.com Wed May 18 18:42:07 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 16:42:07 -0600 Subject: python logging In-Reply-To: References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> <4DD44684.1080504@gmail.com> Message-ID: 2011/5/18 Ian Kelly : > Ah, that's it. ?I was using Python 2.5. ?Using 2.7 I get the same > result that you do. > > Still, it's a surprising change that doesn't seem to be documented as > such. ?I'm not sure whether it's a regression or an intentional > change. I was wrong, it's more complicated than that. Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import logging >>> logging.getLogger('log').warning('test') No handlers could be found for logger "log" >>> logging.warning('test') WARNING:root:test >>> logging.getLogger('log').warning('test') WARNING:log:test Apparently, getLogger() is unconfigured by default, but if you just use the root logger once, then they magically get configured. From marduk at letterboxes.org Wed May 18 19:29:30 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 18 May 2011 19:29:30 -0400 Subject: How To Make Fast Money Legally In-Reply-To: <20110518154813.7a06436f.darcy@druid.net> References: <99c99019-754c-4b43-8a84-22ab7f2fc498@bl1g2000vbb.googlegroups.com> <20110518154813.7a06436f.darcy@druid.net> Message-ID: <1305761371.3259.3.camel@localhost.localdomain> On Wed, 2011-05-18 at 15:48 -0400, D'Arcy J.M. Cain wrote: > On Wed, 18 May 2011 12:06:07 -0700 (PDT) > "tmac641382 at yahoo.com" wrote: > > HOW TO MAKE EASY MONEY FAST AND LEGALLY!!!!!!!! > > Wow! Was this stuck in someone's mail queue since 1992? Me too! From bahamutzero8825 at gmail.com Wed May 18 20:39:42 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 18 May 2011 19:39:42 -0500 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD1C9D5.4070206@gmail.com> Message-ID: <4DD466CE.7050104@gmail.com> On 2011.05.18 03:30 AM, Stefan Behnel wrote: > Well, it pretty clearly states that on the PyPI page, but I also added it > to the project home page now. lxml 2.3 works with any CPython version from > 2.3 to 3.2. Thank you. I never would've looked at PyPI for info on a project that has its own site. I'll take a look at it. From invalid at peter.pmoylan.org.invalid Wed May 18 21:06:06 2011 From: invalid at peter.pmoylan.org.invalid (Peter Moylan) Date: Thu, 19 May 2011 11:06:06 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> Message-ID: rusi wrote: > On May 18, 5:09 pm, Peter Moylan > wrote: >> ObAUE: In common parlance, the English word "recursion" means pretty >> much the same as what computing people call "iteration". This might be >> the first time I have ever found a point of agreement with Xah Lee. > > Maybe the common usage mirrors the facts better than the lore that > half-baked programmers remain devoted to. Consider first > implementations: > > The implementation of recursion by a typical language (eg gcc for C) > maximizes generality at the cost of efficiency > > The implementation of a very special case -- tail recursion -- in some > special languages (most notably scheme) is required to be competitive > with the iterative solution. > > [If I remember right in Chez scheme tail recursion was more efficient > than a do (iteration) because a do typically needed assignment and > assignment was more expensive than parameter passing] I believe the word "legend", or something equivalent, was used elsewhere in this thread in this connection. The supposed inefficiency of recursive implementations is based largely on the properties of hardware that is now obsolete. With modern processors there's no great efficiency hit. In some of the smaller microcontrollers, it's true, you do have to worry about stack overflow; but the ARM processors, for example, provide plenty of stack space. In the microcontroller world, the big performance hits come from the fact that the only available compilers are for C and sometimes C++. (And nobody uses assembly language except for the very little jobs.) The nature of the C language prevents compilers from doing optimisations that are standard in compilers for high-level languages. Most C compilers will, for example, always pass parameters on the stack, despite the generous supply of registers available in newer hardware. -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. From tjreedy at udel.edu Wed May 18 21:13:51 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 May 2011 21:13:51 -0400 Subject: pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: On 5/18/2011 9:42 AM, lkcl wrote: > he's got a good point, terry. breaking backwards-compatibility was a > completely mad and incomprehensible decision. I see that I should take everything you (or Harris) say with a big grain of salt;-). You just gave me a lecture about the impossibility of doing everything one might like with limited all or mostly volunteer resources. So surely you can comprehend that the same applies to CPython also. Given that Python 1.0/1 had some design defects that became evident with experience and simply lacked some things thought of later, I can think of several options: 1. Never fix them. 2. Add fixes, but keep the old stuff. If the old and new ways are somewhat compatible, keep both available at the same time*. If they conflict, keep old as default and make new available on demand (future import)#. This was 2.x strategy. 2A. Make new ways default and have past imports. 3. Gradually delete old. This was and is policy mostly for library. 4. Delete lots of old ways all at once. This was 3.x. What would you have had us do instead? * Example: old and new style classes. Problems: the differences are hard to learn and hard to remember; they are sometimes irrelevant, but sometimes not; if you import and instantiate a class, you may not know which you have. # Example: int division. Problems: having the deprecated meaning be default is a damn nuisance; learning it is a stupid burden; if you see 'a/b' in a snippet extracted from a file, you do not know what it means. 2.7 is really the end of the road for strategy 2. Keeping obsolete features around is a learning burden for most newbies and a maintenance burden for developers. -- Terry Jan Reedy From harrismh777 at charter.net Wed May 18 22:54:48 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 18 May 2011 21:54:48 -0500 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: Littlefield, Tyler wrote: > I know about rate limiting and dos attacks, as well as some others, but > I think there's a lot more that I don't know--can someone kind of aim me > in the right direction for some of this? I want to be able to take > techniques, break my server and then fix it so that can't be done before > I head to public with this. Black-hat and gray-hat papers are some of the best resources; and entertaining ta-boot... Four resources that you will what to look into, in no particular order: Erickson, Jon, "Hacking: The Art of Exploitation," 2nd ed, San Francisco: No Starch Press, 2008. Anonymous, "Maximum Linux Security: A Hacker's Guide to Protecting Your Linux Server and Workstation," Indianapolis: Sams Publishing, 2000. (check for other editions) (this volume is a good read, even for other platforms, but is geared specifically to Linux) Graves, Kimberly, "CEH Certified Ethical Hacker: Study Guide," Indianapolis: Wiley Publishing, 2010. Seitz, Justin, "Gray Hat Python: Python Programming for Hackers and Reverse Engineers," San Francisco: No Starch Press, 2009. The best way to protect your system is first to be able to understand how someone else will attempt to compromise it. I personally am an *ethical* hacker; by definition, I exploit possibilities, for problem solving, and I cause *NO* harm. Having said that, I have studied *all* of the techniques employed in the field for causing harm; why? Because that is the *only* way to know how to defend against them. Its like missile anti missile... virus anti virus, and the like. Because *all* of software is mathematical by nature it is not possible to lock software with software... this is partially the decidability problem at work. But mostly its a matter of their skills getting better... yours better be better yet, and when they get even better than you--- well you better be ready to improve ... and on and on it goes... But, first you need to understand what you're up against. There is absolutely *no* way to prevent reverse engineering. Its all just code, and that code can be unraveled with the right math and enough time. (time and talent is all it takes; that and the will to be tenacious and uncompromising. If someone wants your system badly enough, they will own it... its just a matter of time... so be ready for it... like the Bible says, "If the master of the house knew what hour the thief would break in and steal, he would have kept better watch on his house!" kind regards, m harris From vgnulinux at gmail.com Wed May 18 23:53:06 2011 From: vgnulinux at gmail.com (VGNU Linux) Date: Thu, 19 May 2011 09:23:06 +0530 Subject: How to select Python web frameworks and which one is the best framework ? In-Reply-To: References: Message-ID: On Tue, May 17, 2011 at 1:20 PM, VGNU Linux wrote: > Hi all, > > I am confused on which web framework to select for developing a small data > driven web application. Application will have features generally found in > now-a-days web application like security, database connectivity, > authentication etc. I found few web frameworks over the net like django, > zope 2/3, pylons, turbogears, web2py, grok etc. etc. > I just want to know that how developers/managers/organizations select a > framework which best suits their needs ? what are the parameters for > selection ? > also which is the best and widely used web framework for python ? > > I apologize if this is a repeated question. > > Regards, > VGNU > Please guys help as I am novice to web development. Regards, VGNU -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Thu May 19 00:24:12 2011 From: nagle at animats.com (John Nagle) Date: Wed, 18 May 2011 21:24:12 -0700 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <4dd49b97$0$1909$742ec2ed@news.sonic.net> On 5/4/2011 11:36 AM, Ethan Furman wrote: > Raymond Hettinger wrote: >> I'm writing-up more guidance on how to use super() and would like to >> point at some real-world Python examples of cooperative multiple >> inheritance. Multiple inheritance in Python is so badly designed that it probably should not be used in production code. Generalizing multiple inheritance from a tree to a directed acyclic graph is usually a mistake. John Nagle From hg at schaathun.net Thu May 19 00:56:19 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 19 May 2011 05:56:19 +0100 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <38lda8-8as.ln1@svn.schaathun.net> Message-ID: ["Followup-To:" header set to comp.lang.python.] On Wed, 18 May 2011 22:40:28 +0200, Raymond Wiker wrote: : I said tree operations, not tree walks. A tree operation might : involve several tree walks. OK. The original claim under dispute regarded tree walks. : Further, there has been an implicit : assumption (I think) in this discussion that the order of children is : given, or does not matter - if this is not the case, then you also need : to maintain a stack of data structures representing lists (or sets) of : children. It assumes that there is some canonical ordering on the children. If the tree nodes store their children as sets, where the implementation does not guarantee that they can be retrieved in the same order every time, then it breaks. However, that would be an unusual implementation. The tree has to store the children for each node, one way or another. The only thing I am assuming is that the children can be inspected in the same order every time the node is visited. -- :-- Hans Georg From hg at schaathun.net Thu May 19 01:21:08 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 19 May 2011 06:21:08 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> Message-ID: <4vlea8-55t.ln1@svn.schaathun.net> On Wed, 18 May 2011 14:34:46 -0700, geremy condra wrote: : Systems can be designed that are absolutely secure under reasonable : assumptions. The fact that it has assumptions does not make your : statement true. : (...) : I can't tell if you're trying to play word games with the distinction : between "system" and "module" or if you're just saying that you aren't : sure what FIPS actually certifies. Could you please clarify? The distinction between system and module is rather significant. If you only consider modules, you have bounded your problem and drastically limited the complexity. : Again, I'm unsure what you're going for here. It sounds like you're : saying that obfuscation doesn't provide meaningful security, which is : my point. Meaningful is a relative term, and it is hard to rule out the possibility that meaning can be found in some case. Overall, we agree though. : Are you talking about the Mayfair classical cipher here? I am talking about the system used in public transport cards like Oyster and Octopus. I am not sure how classical it is, or whether mayfair/mayfare referred to the system or just a cipher. Any way, it was broken, and it took years. : The entire field of formal modeling and verification has grown around : solving this problem. My new favorite in the field is "formal models : and techniques for analyzing security protocols", but there are other : works discussing OS kernel verification (which has gotten a lot of : attention lately) and tons of academic literature. Google (scholar) is : the place to go. Sure, but now you are considering modules, rather than systems again. It is when these reliable components are put together to form systems that people fail (empirically). : If you can't say with confidence that something meets minimum security : standards, the answer is not to try to say it meets high security : standards. So what? The levels of assurance have nothing to do with standards. The levels of assurance refer to the /confidence/ you can have that the standards are met. : > Or maybe it is right to say that the theory and skills do exist, but the : > money to gather it all in one project to demonstrate the security of : > a single system does not :-) : : Sorry, but again this is not correct. You keep saying that, but whenever you try to back the claim, you keep referring to limited components and not systems at all. -- :-- Hans Georg From stefan_ml at behnel.de Thu May 19 02:18:23 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 19 May 2011 08:18:23 +0200 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD466CE.7050104@gmail.com> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD1C9D5.4070206@gmail.com> <4DD466CE.7050104@gmail.com> Message-ID: Andrew Berg, 19.05.2011 02:39: > On 2011.05.18 03:30 AM, Stefan Behnel wrote: >> Well, it pretty clearly states that on the PyPI page, but I also added it >> to the project home page now. lxml 2.3 works with any CPython version from >> 2.3 to 3.2. > Thank you. I never would've looked at PyPI for info on a project that > has its own site. You should, especially for standardised information like this. Stefan From rafadurancastaneda at gmail.com Thu May 19 03:18:11 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Thu, 19 May 2011 09:18:11 +0200 Subject: python logging In-Reply-To: References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> <4DD44684.1080504@gmail.com> Message-ID: You are right that behavior isn't documented and might be a bug. You could report it. Bye El 19 de mayo de 2011 00:42, Ian Kelly escribi?: > 2011/5/18 Ian Kelly : > > Ah, that's it. I was using Python 2.5. Using 2.7 I get the same > > result that you do. > > > > Still, it's a surprising change that doesn't seem to be documented as > > such. I'm not sure whether it's a regression or an intentional > > change. > > I was wrong, it's more complicated than that. > > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import logging > >>> logging.getLogger('log').warning('test') > No handlers could be found for logger "log" > >>> logging.warning('test') > WARNING:root:test > >>> logging.getLogger('log').warning('test') > WARNING:log:test > > Apparently, getLogger() is unconfigured by default, but if you just > use the root logger once, then they magically get configured. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kushal.kumaran+python at gmail.com Thu May 19 03:51:00 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 19 May 2011 13:21:00 +0530 Subject: How to select Python web frameworks and which one is the best framework ? In-Reply-To: References: Message-ID: On Thu, May 19, 2011 at 9:23 AM, VGNU Linux wrote: > > > On Tue, May 17, 2011 at 1:20 PM, VGNU Linux wrote: >> >> Hi all, >> I am confused on which web framework to select for developing a small data >> driven web application. Application will have features generally found in >> now-a-days web application like security, database connectivity, >> authentication etc. I found few web frameworks over the net like django, >> zope 2/3, pylons, turbogears, web2py, grok etc. etc. >> I just want to know that how developers/managers/organizations select a >> framework which best suits their needs ? what are the parameters for >> selection ? >> also which is the best and widely used web framework for python ? >> I?apologize if this is a repeated question. > > Please guys help as I am novice to web development. Search the list archives. This topic has been discussed many many times. -- regards, kushal From steve+comp.lang.python at pearwood.info Thu May 19 04:47:28 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 May 2011 08:47:28 GMT Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> Message-ID: <4dd4d920$0$29968$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 May 2011 06:21:08 +0100, Hans Georg Schaathun wrote: > : Are you talking about the Mayfair classical cipher here? > > I am talking about the system used in public transport cards like Oyster > and Octopus. I am not sure how classical it is, or whether > mayfair/mayfare referred to the system or just a cipher. I think Geremy is talking about the Playfair cipher: http://en.wikipedia.org/wiki/Playfair_cipher > Any way, it was broken, and it took years. You don't know that. All you know is that it took years for people to realise that it had been broken, when a security researcher publicly announced the MIFARE cipher had been broken. If criminals had broken the cipher, they would have had no incentive to publicize the fact, and the companies running Oyster and similar ticketing schemes would have no incentive to admit they were broken. Far from it: all the incentives are against disclosure. So it's possible that Oyster cards have been counterfeited for years without anyone but the counterfitters, and possibly the Oyster card people themselves, knowing. The real barrier to cracking Oyster cards is not that the source code is unavailable, but that the intersection of the set of those who know how to break encryption, and the set of those who want to break Oyster cards, is relatively small. I don't know how long it took to break the encryption, but I'd guess that it was probably a few days of effort by somebody skilled in the art. http://www.usenix.org/events/sec08/tech/full_papers/nohl/nohl_html/index.html -- Steven From slafs.e at gmail.com Thu May 19 05:12:45 2011 From: slafs.e at gmail.com (Slafs) Date: Thu, 19 May 2011 02:12:45 -0700 (PDT) Subject: pypi mirror Message-ID: <09b8851c-00ec-49ae-af85-93e55df91375@s9g2000yqm.googlegroups.com> Hi there. I would like to make a "local" mirror of some packages that are on pypi. What options do You recommend ? I am leaning towards z3c.pypimirror because it was kind of first on my google search results. Regards S?awek From hg at schaathun.net Thu May 19 05:16:54 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 19 May 2011 10:16:54 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <4dd4d920$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6p3fa8-bnt.ln1@svn.schaathun.net> On 19 May 2011 08:47:28 GMT, Steven D'Aprano wrote: : The real barrier to cracking Oyster cards is not that the source code is : unavailable, but that the intersection of the set of those who know how : to break encryption, and the set of those who want to break Oyster cards, : is relatively small. I don't know how long it took to break the encryption, : but I'd guess that it was probably a few days of effort by somebody : skilled in the art. : : http://www.usenix.org/events/sec08/tech/full_papers/nohl/nohl_html/index.html In that paper, more than one art seem to have been applied. An open design would have eliminated the need for image analysis and reduced the requirement on hardware/electronics skills. Hence, the obfuscation has made that intersection you talk about smaller, and increased the cost of mounting the attack. As the system was broken anyway, it is hardly a victory for obfuscation, but that's beside the point. The work of that paper is almost certainly more than just ?a few days of effort?. There are simply to many technical issues to tackle, and they must be tackled one by one. The cost of mounting the attack is to figure out what it takes to do it, before spend the resources barking up the wrong tree. For each successful attack, there probably is a number of failed ones. Thanks for the reference. BTW. That's not the only attack on MIFARE. I cannot remember the details of the other. -- :-- Hans Georg From vinay_sajip at yahoo.co.uk Thu May 19 05:27:52 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 19 May 2011 02:27:52 -0700 (PDT) Subject: python logging References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> <4DD44684.1080504@gmail.com> Message-ID: <073b63fa-51bc-4c21-bdb2-676adc405093@r20g2000yqd.googlegroups.com> On May 18, 11:42?pm, Ian Kelly wrote: > I was wrong, it's more complicated than that. > > >>>logging.getLogger('log').warning('test') > > No handlers could be found for logger "log">>>logging.warning('test') > WARNING:root:test > >>>logging.getLogger('log').warning('test') > > WARNING:log:test > > Apparently, getLogger() is unconfigured by default, but if you just > use the root logger once, then they magically get configured. The difference is that you called the module-level convenience function - logging.warning('test') The module-level convenience functions call basicConfig(), which configures a console handler on the root logger if no handlers are present there. This is documented at http://docs.python.org/library/logging.html#logging.log (see para starting "PLEASE NOTE:") and http://docs.python.org/howto/logging.html#advanced-logging-tutorial (search for "If you call the functions") This is not a behaviour change - it's been like this since logging appeared in Python, see http://hg.python.org/cpython/annotate/f72b1f8684a2/Lib/logging/__init__.py#l1145 Regards, Vinay Sajip From g.rodola at gmail.com Thu May 19 05:28:48 2011 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 19 May 2011 11:28:48 +0200 Subject: smtplib is broken when using TLS In-Reply-To: References: Message-ID: Please file a ticket on: http://bugs.python.org/ Regards, --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ 2011/5/17 nirinA raseliarison : > i think this has the same origin as the ftplib test failure. > > Python 3.2.1rc1 (default, May 17 2011, 22:01:34) > [GCC 4.6.0] on linux2 > Type "copyright", "credits" or "license()" for more information. >>>> >>>> ================================ RESTART >>>> ================================ >>>> > > send: 'ehlo [127.0.0.1]\r\n' > reply: b'250-mx.google.com at your service, [41.188.13.184]\r\n' > reply: b'250-SIZE 35882577\r\n' > reply: b'250-8BITMIME\r\n' > reply: b'250-STARTTLS\r\n' > reply: b'250 ENHANCEDSTATUSCODES\r\n' > reply: retcode (250); Msg: b'mx.google.com at your service, > [41.188.13.184]\nSIZE 35882577\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES' > send: 'STARTTLS\r\n' > reply: b'220 2.0.0 Ready to start TLS\r\n' > reply: retcode (220); Msg: b'2.0.0 Ready to start TLS' > Traceback (most recent call last): > ? ?File "/root/template_mail_text.py", line 49, in > ? ? ?server.starttls() > ? ?File "/usr/local/lib/python3.2/smtplib.py", line 649, in starttls > ? ? ?self.sock = ssl.wrap_socket(self.sock, keyfile, certfile) > ? ?File "/usr/local/lib/python3.2/ssl.py", line 509, in wrap_socket > ? ? ?ciphers=ciphers) > ? ?File "/usr/local/lib/python3.2/ssl.py", line 266, in __init__ > ? ? ?raise x > ? ?File "/usr/local/lib/python3.2/ssl.py", line 262, in __init__ > ? ? ?self.do_handshake() > ? ?File "/usr/local/lib/python3.2/ssl.py", line 441, in do_handshake > ? ? ?self._sslobj.do_handshake() > ssl.SSLError: [Errno 1] _ssl.c:392: error:140943FC:SSL > routines:SSL3_READ_BYTES:sslv3 alert bad record mac > > > -- > nirinA > -- > http://mail.python.org/mailman/listinfo/python-list > From g.rodola at gmail.com Thu May 19 05:30:18 2011 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 19 May 2011 11:30:18 +0200 Subject: test_argparse.py FAILED (failures=6) In-Reply-To: References: Message-ID: There's no point in posting this here. Use the bug tracker: http://bugs.python.org/ --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ 2011/5/17 nirinA raseliarison : > > ====================================================================== > FAIL: test_failures_many_groups_listargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ====================================================================== > FAIL: test_failures_many_groups_sysargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ====================================================================== > FAIL: test_failures_no_groups_listargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ====================================================================== > FAIL: test_failures_no_groups_sysargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ====================================================================== > FAIL: test_failures_one_group_listargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ====================================================================== > FAIL: test_failures_one_group_sysargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ---------------------------------------------------------------------- > Ran 1599 tests in 6.298s > > FAILED (failures=6) > > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 4681, in > ? ?test_main() > ?File "Lib/test/test_argparse.py", line 4673, in test_main > ? ?support.run_unittest(__name__) > ?File "/mnt/sda14/pack_build/Python-3.2.1rc1/Lib/test/support.py", line > 1184, in run_unittest > ? ?_run_suite(suite) > ?File "/mnt/sda14/pack_build/Python-3.2.1rc1/Lib/test/support.py", line > 1167, in _run_suite > ? ?raise TestFailed(err) > test.support.TestFailed: multiple errors occurred > > > -- > nirinA > -- > http://mail.python.org/mailman/listinfo/python-list > From nobody at nowhere.com Thu May 19 06:34:28 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 19 May 2011 11:34:28 +0100 Subject: connect SIGINT to custom interrupt handler References: <04cee22d-fc07-4c54-b91b-3f9e4730f095@glegroupsg2000goo.googlegroups.com> <18857efb-05be-42f0-8c62-40be5ec9dd26@gu8g2000vbb.googlegroups.com> Message-ID: On Wed, 18 May 2011 07:16:40 -0700, Jean-Paul Calderone wrote: > Setting SA_RESTART on SIGINT is probably the right thing to do. It's not > totally clear to me from the messages in this thread if you managed to get > that approach working. He didn't; select() isn't SA_RESTART-able. Unfortunately, the author of select.select() decided to treat EINTR as an error. It isn't; it's a "third way", neither success nor failure, similar to EAGAIN. Normally, you would treat EINTR from select() in the same way as a timeout. While it's possible to work around this, the interface encourages getting it wrong. From mail at agcasey.com Thu May 19 07:29:21 2011 From: mail at agcasey.com (Adrian Casey) Date: Thu, 19 May 2011 20:59:21 +0930 Subject: pexpect: TIMEOUT no longer clears child.before Message-ID: The behaviour of pexpect has changed between version 2.1 and 2.3. In version 2.1, the following code would result in child.before being cleared -: >>>child.expect(pexpect.TIMEOUT,1) In version 2.3, this is no longer the case. No matter how many times the above code is run, child.before continues to hold the output from previous commands. It is important to be able to clear the contents of child.before between each command. What is the correct way to do this in version 2.3? Adrian. From oisin.mulvihill at gmail.com Thu May 19 07:49:28 2011 From: oisin.mulvihill at gmail.com (Oisin Mulvihill) Date: Thu, 19 May 2011 12:49:28 +0100 Subject: pypi mirror In-Reply-To: <09b8851c-00ec-49ae-af85-93e55df91375@s9g2000yqm.googlegroups.com> References: <09b8851c-00ec-49ae-af85-93e55df91375@s9g2000yqm.googlegroups.com> Message-ID: Hi S?awek, You could also do a local or private egg repository. I documented how I did this for my internal projects here: http://www.sourceweaver.com/posts/private-python-egg-repository I hadn't come across z3c.pymirror before. All the best, Oisin On 19 May 2011 10:12, Slafs wrote: > Hi there. > > I would like to make a "local" mirror of some packages that are on > pypi. What options do You recommend ? > > I am leaning towards z3c.pypimirror because it was kind of first on my > google search results. > > Regards > > S?awek > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From luke.leighton at gmail.com Thu May 19 08:42:29 2011 From: luke.leighton at gmail.com (lkcl) Date: Thu, 19 May 2011 05:42:29 -0700 (PDT) Subject: python2+3 References: Message-ID: <42394efe-439f-4431-9b87-b70547f58c80@k17g2000vbn.googlegroups.com> [changing subject, seems a good idea...] On May 19, 2:13?am, Terry Reedy wrote: > On 5/18/2011 9:42 AM, lkcl wrote: > > > ? he's got a good point, terry. ?breaking backwards-compatibility was a > > completely mad and incomprehensible decision. > > I see that I should take everything you (or Harris) say with a big grain > of salt;-). *lol* - i realise it's a hell of a lot of work to get a python interpreter to support two different grammars and syntaxes: you can appreciate that i'm in a better position than most to understand that [i've also done a port of python to gnu-win32 so am familiar with the codebase] now that the code for both has been written, tested and proven, the task of adding one t't'othr is a leetle less of a challenging task. there is one teeny tiny annoying challenge: namespace clashes in c, of functions and data structures between the two codebases. however, this isn't as bad as it first seems. it's only the "public" face (Python.h) which has to remain the same, and that can be taken care of by having data structures that are identical internally and externally (macros to the rescue) where the internal name is Python2_xxxx and the external name Python_xxx. where it becomes less of a maintenance burden is when you say "ok, that's it: definitely end-of-the-road for all 2.N development, period". has anyone considered the idea of literally creating a Python2/ subdirectory in the python3 codebase, literally just dropping the entire python2.N code directly into it, renaming all functions and data structures, adding a "--2-compatible" switch to the python3 argc/ v and seeing what happens? no interoperability, no maintenance, no "compatibility" - just "support for python 2 directly in the python3 binary". l. From feeley at iro.umontreal.ca Thu May 19 08:54:13 2011 From: feeley at iro.umontreal.ca (Marc Feeley) Date: Thu, 19 May 2011 05:54:13 -0700 (PDT) Subject: Gambit REPL app for iPhone/iPod touch/iPad Message-ID: A version of the Gambit Scheme system for iPhone/iPod touch/iPad is now available on the Apple App Store: http://itunes.apple.com/us/app/gambit-repl/id434534076?mt=8&ls=1 "Gambit REPL" is a complete version of Gambit (http:// dynamo.iro.umontreal.ca/~gambit) including the interpreter, debugger and built-in library (but not the compiler). The standard REPL is provided and also a script editor. Scripts can be saved, attached to function keys, and the "main" function of the application can be redefined to customize the application to your needs. Applications can be debugged remotely by telneting to the device from a desktop machine. The application is sold for $0.99 as a demonstration that you can distribute on the App Store paid applications written in Scheme and containing an interpreter, something that wasn't clear with previous versions of the App Store developer agreement. A version of Gambit REPL for Android is not planned (by me). The Gambit Scheme system compiles fine on Android (for example see https://github.com/seoushi/gambit-android-example), but the user interface layer would have to be changed and tested, and I don't own an Android device. If someone wants to try porting Gambit REPL to Android let me know and I can help. The sources of Gambit REPL for iOS are in the examples/iOS subdirectory of the Gambit source distribution. Marc From Pietro.Abate at pps.jussieu.fr Thu May 19 09:10:57 2011 From: Pietro.Abate at pps.jussieu.fr (Pietro Abate) Date: Thu, 19 May 2011 15:10:57 +0200 Subject: Problem with multiprocessing Message-ID: <20110519131057.GA9082@pps.jussieu.fr> Hi all, I'm a bit struggling to understand a KeyError raised by the multiprocessing library. My idea is pretty simple. I want to create a server that will spawn a number of workers that will share the same socket and handle requests independently. The goal is to build a 3-tier structure where all requests are handled via an http server and then dispatched to nodes sitting in a cluster and from nodes to workers via the multiprocessing managers... There is one public server, one node per machine and x number of workers on each machine depending on the number of cores... I know I can use a more sophisticated library, but for such a simple task (I'm just prototyping here) I would just use the multiprocessing library... Is this possible or I should explore directly other solutions ? I feel I'm very close to have something working here ... The problem with the code below is that if I run the server as `python server.py 1` , that is, using only one process, it works as expected. However if I spawn two processes (`python server.py 2`) listening for connections, I get a nasty error : $python client.py ping Traceback (most recent call last): File "client.py", line 24, in sys.exit(main(sys.argv)) File "client.py", line 21, in main print m.solver(args[1])._getvalue() File "/usr/lib/python2.6/multiprocessing/managers.py", line 637, in temp authkey=self._authkey, exposed=exp File "/usr/lib/python2.6/multiprocessing/managers.py", line 894, in AutoProxy incref=incref) File "/usr/lib/python2.6/multiprocessing/managers.py", line 700, in __init__ self._incref() File "/usr/lib/python2.6/multiprocessing/managers.py", line 750, in _incref dispatch(conn, None, 'incref', (self._id,)) File "/usr/lib/python2.6/multiprocessing/managers.py", line 79, in dispatch raise convert_to_error(kind, result) multiprocessing.managers.RemoteError: --------------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.6/multiprocessing/managers.py", line 181, in handle_request result = func(c, *args, **kwds) File "/usr/lib/python2.6/multiprocessing/managers.py", line 402, in incref self.id_to_refcount[ident] += 1 KeyError: '7fb51084c518' --------------------------------------------------------------------------- My understanding is that all processes share the same socket (from the Manager). When a client wants to connect, a new connection is created and server independently by that process. If you look at the server trace (using logging), it actually receives the connection, handles it, but fails to communicate back to the client. Can anybody shed some light for me and maybe propose a solution ? thanks pietro ---------------------------------------- Server : import sys from multiprocessing.managers import BaseManager, BaseProxy, Process def baz(aa) : l = [] for i in range(3) : l.append(aa) return l class SolverManager(BaseManager): pass class MyProxy(BaseProxy): pass manager = SolverManager(address=('127.0.0.1', 50000), authkey='mpm') manager.register('solver', callable=baz, proxytype=MyProxy) def serve_forever(server): try : server.serve_forever() except KeyboardInterrupt: pass def runpool(n): server = manager.get_server() workers = [] for i in range(int(n)): Process(target=serve_forever, args=(server,)).start() if __name__ == '__main__': runpool(sys.argv[1]) Client : import sys from multiprocessing.managers import BaseManager, BaseProxy import multiprocessing, logging class SolverManager(BaseManager): pass class MyProxy(BaseProxy): pass def main(args) : SolverManager.register('solver') m = SolverManager(address=('127.0.0.1', 50000), authkey='mpm') m.connect() print m.solver(args[1])._getvalue() if __name__ == '__main__': sys.exit(main(sys.argv)) also tried on stack overflow and the python list, but I didn't manage to come up with a working solution yet... -- ---- http://en.wikipedia.org/wiki/Posting_style From luke.leighton at gmail.com Thu May 19 09:17:58 2011 From: luke.leighton at gmail.com (lkcl) Date: Thu, 19 May 2011 06:17:58 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> Message-ID: On May 18, 11:02?pm, Terry Reedy wrote: > On 5/18/2011 5:24 AM, lkcl wrote: > > There seem to be two somewhat separate requirement issues: the > interpreter binary and the language version. yes. [with the startling possibility of compiling the entire pyjs compiler into javascript and executing under e.g. spidermonkey's /usr/ bin/js turning that into just the one requirement - but that's another story] > > ? a) at the moment ahttp://python.org2.N interpreter is required to > > actually run the translator. ?if you usehttp://python.org2.5 or 2.6 > > you do not need to use the "--internal-ast" option. ?if you use 2.4, > > 2.7 or above, you will need to use --internal-ast because we're > > heavily reliant on the internal c-based "compile" module [without the > > --internal-ast option enabled]. > > I presume '--internal-ast' is a 'compile the interpreter' option. mmm... sort of. what it does is, in translator.py (the pyjs python- to-javascript compiler) is this: if options.internal_ast: import pyjamas.pgen.compile as compile # python version of compile module else: import compile # standard python compile module that "internal" compile module contains a complete independent grammar.txt file, and is basically lib2to3 re-ported *back* to being interoperable with, and a complete replacement for, the standard python "compile" module. including the ast module. we haven't *quite* got round to doing a "compile the interpreter" yet - it's half way there. the work that daniel kluev is doing, for his gsoc2011 project, will be a complete "compile the interpreter". by the time he's done, we'll even have "eval()" and "exec()" builtins... inside a web browser. > Since > I have never compilied Python (or anything else for perhaps 15 years), I > do not understand completely. Am I correct to guess that the PSF Windows > binaries for 2.7 were not compiled with the flag, and will not work? If > so, Windows users should, I would think, use the latest 2.6.6 binaries. ahh... i'm reading this as "requiring http://python.org c code to be compiled with different compilation flags". this isn't anything to do with compiling c-code: "pyjs the translator" is and always will be a pure vanilla python application, requiring absolutely no modifications to the python interpreter whatsoever. the --internal-ast option is an option which is passed to the pyjs application (which is a pure and vanilla python application). here's an example, shows the inter-relationships: /usr/bin/python pyjsbuild.py --internal-ast Hello.py python.exe pyjsbuild.py --internal-ast Hello.py * /usr/bin/python or python.exe - python2.N. * pyjsbuild.py - the pyjs python-to-javascript translator * --internal-ast - an option to pyjsbuild to tell it to use a version of compiler.ast which is written in pure python [and supports the 2.6 grammar] * Hello.py - the pyjamas application, written in python, being translated to javascript, for execution in a web browser. > > ? b) the actual pyjs interpreter grammar (AST) was 2.5 but has mostly > > been updated to 2.6. ?actual python syntax / features are therefore > > mostly 2.5, with someone having pointed out that "slice" has different > > return results it's hard to say exactly which is best to be picked, > > 2.5 or 2.6. ?nobody's needed slice until recently, so it's not an > > issue that's ever come up before. > > If I understand this, the safe thing to do is to stick with 2.5 syntax > and omit exotic 3.x features put into 2.6 for eventual porting to 3.x. yes. that would be the easiest path. however, we have a teeny problem: pyjamas desktop (pyjd). that's where you get to *really* execute the python code, exactly the same code that you munged through the pyjs compiler. in the pyjd case, what is going on is that it is *python* that has access to the features of the web browser engine (DOM functions, HTML5 etc.) and that is... ho hum, each engine is itself a massive project, and has to be a python c module (except for the MSHTML engine, which is COM). so for pyjd, we *have* to support whatever the latest easiest python 2.N is. that in turn dictates that we have to keep up-to-date with the python 2.N syntax/grammar, and, consequently, it dictates logically that the pyjs compiler, which *must* be interoperable with pyjd, must also support the latest python 2.N syntax/grammar. bummer, huh? :) fortunately, nobody on the pyjamas mailing list has really noticed that there _are_ any differences (!) between 2.5, 6 and 7 - except for daniel kluev, the gsoc2011 student, who is using pyjs with python-pyv8 to actually create a version of a python interpreter... by translating everything to javascript! the reason why they haven't really noticed is because the use-case for pyjamas UI code is much much smaller (due to web browsers being a restricted execution environment - see ongoing discussion below). > > ? the thing is - it's worth reiterating: you just... really don't need > > as much python interoperability for user-interfaces when they're split > > along MVC lines. ?bear in mind that it's necessary to do that split: > > it's web browser technology, you can't *actually* execute things like > > psycopg or mysql in a web browser as javascript! ?so once you've > > divided that application into "python that runs the actual user > > interface" and "python on the other side of the AJAX barrier e.g. a > > django app" you're left with a far smaller task for the pyjs > > interpreter to have to tackle. > > I do not get all this but it seems to say that I do not really need all > the features of the later Pythons to write user-interface code. by a roundabout route... yes. it's due to web browsers being a massively restricted environment. > But I am > not sure how this applies to business code behind the front end. Of > course, it might work to run the UI in a separate process if on the same > machine. ok, that's basically what happens: it's not like there is any choice in the matter. the python UI code has been translated to javascript: it's now an AJAX application, not a python application. the UI code therefore runs in that browser's "separate process". it's a highly restricted execution environment that's very very well-defined, and you cannot, *cannot* in any way go outside of the boundaries, as defined by W3C (sort-of). the only access to the outside world is either AJAX, HTML5 Sockets (if supported), or for the user to agree to the installation of a plugin (such as silverlight, java, adobe flash, or god forbid the xulrunner / firefox "language=python" extension which was sponsored by the mozilla foundation back in 2000 - it quite literally embeds the entire libpython library into a firefox plugin!) so, you REALLY have to subdivide the application, just as you have to subdivide *any* AJAX application, into "front-end", "back-end". at the front-end, you can do anything... as long as it's restricted javascript; at the back-end (server-side) you can do ANYTHING. django, whatever - even php or .net if you're feeling sick... this does take quite a long time to sink in :) even i had difficulty appreciating that yes, you can write UI web applications *in python*, but nooo, you can't *actually* execute that python code in the web browser, and consequently nooo, you cannot have "standard" python modules in the web browser. it's kinda like pypy - you can have anything you like, as long as it's in pure python [so it can be translated to javascript]. l. From drsalists at gmail.com Thu May 19 11:05:10 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 19 May 2011 08:05:10 -0700 Subject: Problem with multiprocessing In-Reply-To: <20110519131057.GA9082@pps.jussieu.fr> References: <20110519131057.GA9082@pps.jussieu.fr> Message-ID: Share as little as possible between your various processes - shared, mutable state is a parallelism tragedy. If you can avoid sharing an entire dictionary, do so. It'd probably be better to dedicate one process to updating your dictionary, and then using a multiprocessing.Queue to pass delta records from your workers to your dictionary management process. Also, I'm inclined to doubt it's going to work well to have multiple processes doing I/O on the same socket - you'd probably best have a process that does all the I/O on the socket, and then, again, have one or more multprocessing.Queue's that pass I/O results/requests around. On Thu, May 19, 2011 at 6:10 AM, Pietro Abate wrote: > Hi all, > > I'm a bit struggling to understand a KeyError raised by the multiprocessing > library. > > My idea is pretty simple. I want to create a server that will spawn a > number of > workers that will share the same socket and handle requests independently. > The > goal is to build a 3-tier structure where all requests are handled via an > http > server and then dispatched to nodes sitting in a cluster and from nodes to > workers via the multiprocessing managers... > > There is one public server, one node per machine and x number of workers on > each machine depending on the number of cores... I know I can use a more > sophisticated library, but for such a simple task (I'm just prototyping > here) I > would just use the multiprocessing library... Is this possible or I should > explore directly other solutions ? I feel I'm very close to have something > working here ... > > The problem with the code below is that if I run the server as > `python server.py 1` , that is, using only one process, it works as > expected. > > However if I spawn two processes (`python server.py 2`) listening for > connections, I get a nasty error : > > $python client.py ping > Traceback (most recent call last): > File "client.py", line 24, in > sys.exit(main(sys.argv)) > File "client.py", line 21, in main > print m.solver(args[1])._getvalue() > File "/usr/lib/python2.6/multiprocessing/managers.py", line 637, in > temp > authkey=self._authkey, exposed=exp > File "/usr/lib/python2.6/multiprocessing/managers.py", line 894, in > AutoProxy > incref=incref) > File "/usr/lib/python2.6/multiprocessing/managers.py", line 700, in > __init__ > self._incref() > File "/usr/lib/python2.6/multiprocessing/managers.py", line 750, in > _incref > dispatch(conn, None, 'incref', (self._id,)) > File "/usr/lib/python2.6/multiprocessing/managers.py", line 79, in > dispatch > raise convert_to_error(kind, result) > multiprocessing.managers.RemoteError: > > --------------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python2.6/multiprocessing/managers.py", line 181, in > handle_request > result = func(c, *args, **kwds) > File "/usr/lib/python2.6/multiprocessing/managers.py", line 402, in > incref > self.id_to_refcount[ident] += 1 > KeyError: '7fb51084c518' > > --------------------------------------------------------------------------- > > My understanding is that all processes share the same socket (from the > Manager). When a client wants to connect, a new connection is created and > server independently by that process. If you look at the server trace > (using > logging), it actually receives the connection, handles it, but fails to > communicate back to the client. > > Can anybody shed some light for me and maybe propose a solution ? > > thanks > pietro > > ---------------------------------------- > > Server : > > import sys > from multiprocessing.managers import BaseManager, BaseProxy, Process > > def baz(aa) : > l = [] > for i in range(3) : > l.append(aa) > return l > > class SolverManager(BaseManager): pass > > class MyProxy(BaseProxy): pass > > manager = SolverManager(address=('127.0.0.1', 50000), authkey='mpm') > manager.register('solver', callable=baz, proxytype=MyProxy) > > def serve_forever(server): > try : > server.serve_forever() > except KeyboardInterrupt: > pass > > def runpool(n): > server = manager.get_server() > workers = [] > > for i in range(int(n)): > Process(target=serve_forever, args=(server,)).start() > > if __name__ == '__main__': > runpool(sys.argv[1]) > > > Client : > > import sys > from multiprocessing.managers import BaseManager, BaseProxy > > import multiprocessing, logging > > class SolverManager(BaseManager): pass > > class MyProxy(BaseProxy): pass > > def main(args) : > SolverManager.register('solver') > m = SolverManager(address=('127.0.0.1', 50000), authkey='mpm') > m.connect() > > print m.solver(args[1])._getvalue() > > if __name__ == '__main__': > sys.exit(main(sys.argv)) > > > also tried on stack overflow and the python list, but I didn't manage to > come up > with a working solution yet... > > -- > ---- > http://en.wikipedia.org/wiki/Posting_style > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.net.no Thu May 19 12:02:08 2011 From: nobody at nowhere.net.no (TheSaint) Date: Fri, 20 May 2011 00:02:08 +0800 Subject: how to get PID from subprocess library Message-ID: hello, I'm using to launch a program by subprocess.getstatusoutput. I'd like to know whether I can get the program ID, in order to avoid another launch. For clarity sake, I'm calling aria2 (the download manager for linux) and I wouldn't like to call one more instance of it. So what will I use to find the PID of the launched program? -- goto /dev/null From miki.tebeka at gmail.com Thu May 19 12:05:38 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 19 May 2011 09:05:38 -0700 (PDT) Subject: how to get PID from subprocess library In-Reply-To: Message-ID: The best module for doing such things is subprocess. And the Popen object has a pid attribute (http://docs.python.org/library/subprocess.html#subprocess.Popen.pid) From debatem1 at gmail.com Thu May 19 13:23:47 2011 From: debatem1 at gmail.com (geremy condra) Date: Thu, 19 May 2011 10:23:47 -0700 Subject: obviscating python code for distribution In-Reply-To: <4vlea8-55t.ln1@svn.schaathun.net> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 10:21 PM, Hans Georg Schaathun wrote: > On Wed, 18 May 2011 14:34:46 -0700, geremy condra > ? wrote: > : ?Systems can be designed that are absolutely secure under reasonable > : ?assumptions. The fact that it has assumptions does not make your > : ?statement true. > : (...) > : ?I can't tell if you're trying to play word games with the distinction > : ?between "system" and "module" or if you're just saying that you aren't > : ?sure what FIPS actually certifies. Could you please clarify? > > The distinction between system and module is rather significant. > If you only consider modules, you have bounded your problem and > drastically limited the complexity. Ah, the 'word games' option. I'm not going to spend a lot of time arguing this one: HSMs are clearly the domain of systems research, are referred to in both technical and nontechnical documents as 'keystone systems', and the FIPS standard under which they are certified specifically calls them systems more times than I care to count. They are, to the people who make and use them, systems, and your attempt at redefinition won't change that. > : ?Are you talking about the Mayfair classical cipher here? > > I am talking about the system used in public transport cards like > Oyster and Octopus. ?I am not sure how classical it is, or whether > mayfair/mayfare referred to the system or just a cipher. ?Any way, > it was broken, and it took years. Ah, MIFARE. That's a different story, and no, I don't believe they would have been broken sooner if the specs were released. The importance (and difficulty) of securing devices like smartcards wasn't really recognized until much later, and certainly people with a foot in both worlds were very rare for a long time. Also remember that DES (with its 56-bit keys) was recertified just a few months before MIFARE (with its 48-bit keys) was first released- it was a different world. > : ?The entire field of formal modeling and verification has grown around > : ?solving this problem. My new favorite in the field is "formal models > : ?and techniques for analyzing security protocols", but there are other > : ?works discussing OS kernel verification (which has gotten a lot of > : ?attention lately) and tons of academic literature. Google (scholar) is > : ?the place to go. > > Sure, but now you are considering modules, rather than systems again. > It is when these reliable components are put together to form systems > that people fail (empirically). Let me get this straight: your argument is that operating *systems* aren't systems? > : ?If you can't say with confidence that something meets minimum security > : ?standards, the answer is not to try to say it meets high security > : ?standards. > > So what? ?The levels of assurance have nothing to do with standards. > The levels of assurance refer to the /confidence/ you can have that > the standards are met. The increasing levels of assurance don't just signify that you've checked for problems- it certifies that you don't have them, at least insofar as that level of testing is able to find. Insisting that this doesn't, or shouldn't, translate into tighter security doesn't make much sense. Geremy Condra From debatem1 at gmail.com Thu May 19 13:50:55 2011 From: debatem1 at gmail.com (geremy condra) Date: Thu, 19 May 2011 10:50:55 -0700 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 7:54 PM, harrismh777 wrote: > Littlefield, Tyler wrote: > Four resources that you will what to look into, in no particular order: > > Erickson, Jon, "Hacking: The Art of Exploitation," 2nd ed, > ? ? ? ?San Francisco: No Starch Press, 2008. This would be a very good choice. It's a bit light on details, but makes up for it by being exceptionally well-written and very accessible. > Anonymous, "Maximum Linux Security: A Hacker's Guide to Protecting > ? ? ? ?Your Linux Server and Workstation," Indianapolis: > ? ? ? ?Sams Publishing, 2000. > > ? ? ? ?(check for other editions) > ? ? ? ?(this volume is a good read, even for other platforms, > ? ? ? ? ? ? ? ?but is geared specifically to Linux) This is a good volume, but very dated. I'd probably pass on it. > Graves, Kimberly, "CEH Certified Ethical Hacker: Study Guide," > ? ? ? ?Indianapolis: Wiley Publishing, 2010. Briefly glancing over the TOC, this actually looks surprisingly good. CEH itself is a joke among black hats, but if this gets down to the nitty-gritty of actually performing the attacks it covers it sounds like a buy. > Seitz, Justin, "Gray Hat Python: Python Programming for Hackers > ? ? ? ?and Reverse Engineers," San Francisco: No Starch Press, 2009. I'd skip this one, as it isn't really focused on what you want. The web application hacker's handbook is probably more along the lines of what you need, if you're going for a book. There's also an older volume called 'counter hack' that gives a good overview of some of the ways that attacks proceed. Another recommend I'm surprised hasn't popped up already: 'security power tools' is a good way to get your foot in the door. It has a practical, no-nonsense approach and is split into self-contained chapters so you don't waste too much of your time on tools that aren't relevant to you. Geremy Condra From myeates at jpl.nasa.gov Thu May 19 14:03:34 2011 From: myeates at jpl.nasa.gov (Mathew) Date: Thu, 19 May 2011 11:03:34 -0700 Subject: Windows Registry Keys Message-ID: Hi I have installed a new version of Python27 in a new directory. I want to get this info into the registry so, when I install Numpy, it will use my new Python TIA -Mathew From hg at schaathun.net Thu May 19 14:23:28 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 19 May 2011 19:23:28 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> Message-ID: <0q3ga8-s2v.ln1@svn.schaathun.net> On Thu, 19 May 2011 10:23:47 -0700, geremy condra wrote: : Let me get this straight: your argument is that operating *systems* : aren't systems? You referred to the kernel and not the system. The complexities of the two are hardly comparable. There probably are different uses of system; in computer security literature? it often refers, not only to a product (hardware/software) an actual installation and configuration of that product in a specific context. /I/ did not redefine it. Speaking of reasonable assumptions, one necessary assumption which is particularly dodgy is that whoever deploys and configures it understands all the assumptions and do not break them through ignorance. Is your concern with security purely from a developer's viewpoint, so that you don't have to worry about the context in which it will be deployed? : > So what? ?The levels of assurance have nothing to do with standards. : > The levels of assurance refer to the /confidence/ you can have that : > the standards are met. : : The increasing levels of assurance don't just signify that you've : checked for problems- it certifies that you don't have them, at least : insofar as that level of testing is able to find. Insisting that this : doesn't, or shouldn't, translate into tighter security doesn't make : much sense. Tighter sure, but the security requirements and the requirement on testing and/or validation are orthogonal scales. The higher levels of assurance are based on formal methods while the lower ones are based primarily on testing. I read your initial comment to imply that if you cannot get satisfactory assurance using the lower levels, you won't get any at the higher levels. That does not make any sense. Obviously, if you were implying that no system passes the lower levels, then of course they won't pass the higher levels, but then, if that's the case, we would all know that we cannot even design /seemingly/ secure systems. And nobody has suggested that so far. ? e.g. Dieter Gollmann for just one ref off the top of my head. -- :-- Hans Georg From ayaskanta.swain at altair.com Thu May 19 15:37:22 2011 From: ayaskanta.swain at altair.com (Ayaskanta Swain) Date: Fri, 20 May 2011 01:07:22 +0530 Subject: os.access giving incorrect results on Windows Message-ID: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> Hi All, Please help me in solving this issue. I want to check the write permissions on a directory on windows from my python script. I tried to use os.access(dirpath, os.W_OK) to check whether the user has write access or not, but it gives me incorrect result. It always gives me False even if the user has write permission. Interestingly this function works just fine on Linux platforms. There is another way to check the write permissions by creating a temporary file inside the directory & then removing it. Catch the exception if create file is not allowed to decide the iswritable value. But this is changing the last modification time (timestamp) of the directory which is a critical issue for our application. Please suggest a solution. Thanks Ayaskant- -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Thu May 19 15:43:55 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 19 May 2011 20:43:55 +0100 Subject: os.access giving incorrect results on Windows In-Reply-To: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> Message-ID: <4DD572FB.2010809@timgolden.me.uk> On 19/05/2011 20:37, Ayaskanta Swain wrote: > Please help me in solving this issue. I want to check the write > permissions on a directory on windows from my python script. > > I tried to use *os.access(dirpath, os.W_OK)*to check whether the user > has write access or not, but it gives me incorrect result. It always > gives me False even if the user has write permission. Interestingly this > function works just fine on Linux platforms. This is basically issue2528 [1]. The problem is that, although Windows (and Python) expose a version of os.access to match the Posix function, the meaning is so far removed on Windows as to be useless. Really what you need to do is use the AccessCheck API, which is a little bit tortuous, but is intended for this purpose. You can look at the code in my patch for that issue to get an idea of how to do it. Does that help? TJG [1] http://bugs.python.org/issue2528 From bahamutzero8825 at gmail.com Thu May 19 15:56:17 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 19 May 2011 14:56:17 -0500 Subject: os.access giving incorrect results on Windows In-Reply-To: <4DD572FB.2010809@timgolden.me.uk> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> <4DD572FB.2010809@timgolden.me.uk> Message-ID: <4DD575E1.9060801@gmail.com> On 2011.05.19 02:43 PM, Tim Golden wrote: > This is basically issue2528 [1]. > The problem is that, although Windows (and Python) > expose a version of os.access to match the Posix function, > the meaning is so far removed on Windows as to be useless. Does this affect just os.W_OK and directories or all of os.access()? In any case, this information should really be reflected in the docs. From efotinis at yahoo.com Thu May 19 16:05:18 2011 From: efotinis at yahoo.com (Elias Fotinis) Date: Thu, 19 May 2011 23:05:18 +0300 Subject: Windows Registry Keys References: Message-ID: On Thu, 19 May 2011 21:03:34 +0300, Mathew wrote: > I have installed a new version of Python27 in a new directory. I want to get > this info into the registry so, when I install Numpy, it will use my new > Python If I understand correctly (you have multiple Python 2.7 installations and what to make this new one the current), you should change this key: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath (ignore "Wow6432Node" if you are not on 64-bit Windows) That'd would probably be enough for the Numpy installer. I assume you are aware about the changes that may be required to the PATH and file associations. From mail at timgolden.me.uk Thu May 19 16:08:15 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 19 May 2011 21:08:15 +0100 Subject: os.access giving incorrect results on Windows In-Reply-To: <4DD575E1.9060801@gmail.com> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> <4DD572FB.2010809@timgolden.me.uk> <4DD575E1.9060801@gmail.com> Message-ID: <4DD578AF.3000001@timgolden.me.uk> On 19/05/2011 20:56, Andrew Berg wrote: > On 2011.05.19 02:43 PM, Tim Golden wrote: >> This is basically issue2528 [1]. >> The problem is that, although Windows (and Python) >> expose a version of os.access to match the Posix function, >> the meaning is so far removed on Windows as to be useless. > Does this affect just os.W_OK and directories or all of os.access()? > > In any case, this information should really be reflected in the docs. The current code is very naive: * A R_OK check always succeeds if the file's attributes can be read at all * A W_OK check fails if the file has its DOS read-only attribute set * A W_OK check always succeeds for a directory (because read-only means something else for directories). Would you care to propose some wording for the docs? I'm quite happy to commit if we can come to an agreement. TJG From weidezhang2007 at gmail.com Thu May 19 16:18:20 2011 From: weidezhang2007 at gmail.com (Walter Chang) Date: Thu, 19 May 2011 13:18:20 -0700 (PDT) Subject: application level monitoring for python Message-ID: <7281a33b-a32c-4eba-8646-82d9cef459b1@m10g2000yqd.googlegroups.com> Hi is there any open source library for python that can allow application level monitoring ? For example,application can send per request level/ aggregated monitoring events and some remote server dump it and show in the monitoring graph in real time ? What's best way of doing that ? From bahamutzero8825 at gmail.com Thu May 19 16:40:26 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 19 May 2011 15:40:26 -0500 Subject: os.access giving incorrect results on Windows In-Reply-To: <4DD578AF.3000001@timgolden.me.uk> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> <4DD572FB.2010809@timgolden.me.uk> <4DD575E1.9060801@gmail.com> <4DD578AF.3000001@timgolden.me.uk> Message-ID: <4DD5803A.4080208@gmail.com> On 2011.05.19 03:08 PM, Tim Golden wrote: > * A R_OK check always succeeds if the file's attributes can be read > at all So is this the same as F_OK then, or does it return false if the user isn't allowed to read permissions? > * A W_OK check fails if the file has its DOS read-only attribute set DOS attribute? > * A W_OK check always succeeds for a directory (because read-only means > something else for directories). > > Would you care to propose some wording for the docs? I'm quite happy > to commit if we can come to an agreement. I'm a beginner when it comes to Python, but I could give it a shot. A big red warning box explaining how the code under Windows doesn't use ACLs under the os.access() entry (above the notes) seems appropriate. A warning box under os.W_OK saying something like "Under Windows, access() will always indicate that a directory is writable." would also fit. You know more about this than I do. I'm running Windows 7 right now and I have a Python 3.2 interpreter window open if you want me to test/confirm something. :-) From skunkworks at rikishi42.net Thu May 19 17:21:30 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Thu, 19 May 2011 23:21:30 +0200 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On 2011-05-18, Hans Georg Schaathun wrote: > Now Mac OS X has maintained the folder concept of older mac generations, > and Windows has cloned it. They do not want the user to understand > recursive data structures, and therefore, naturally, avoid the word. You imply they want to keep their users ignorant of these structures, as if to keep something valuable from them. Wouldn't it be more honest, more to the point and much simpler to state they don't NEED the user to understand recursive - or indeed any other - data structures? And that the user doesn't NEED to understand or know about them, just to use them? After all they are users. They use their system for fun, learning or work. Even a very competent or advanced use of a tool (computer, car, mobile phone, fridge, TV, radio, toilet) in no way implies an understanding of it's inner workings. Nor the need, nor the desire. PS: Isn't this thread much ado about nothing? :-) It starts with the misconception (or should I say confusion?) between performing a recursive job and using a recursive tool to do it. And then it blazes off in these huge discusions about semantics to define a definition of an abstraction of a alleady theoretical problem. Glorious, just frelling glorious. :-) We have an expression for that. But I'll avoid using it, since it has the word 'masturbation' in it... And PPS: the P(P)S's don't specifically refer to your posting. -- When in doubt, use brute force. -- Ken Thompson From bahamutzero8825 at gmail.com Thu May 19 17:35:09 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 19 May 2011 16:35:09 -0500 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD0D1A2.6060109@free.fr> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> Message-ID: <4DD58D0D.4050508@gmail.com> On 2011.05.16 02:26 AM, Karim wrote: > Use regular expression for bad HTLM or beautifulSoup (google it), below > a exemple to extract all html links: Actually, using regex wasn't so bad: > import re > import urllib.request > > url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth' > page = str(urllib.request.urlopen(url).read(), encoding='utf-8') # > urlopen() returns a bytes object, need to get a normal string > rev_re = re.compile('revision[0-9][0-9][0-9][0-9]') > num_re = re.compile('[0-9][0-9][0-9][0-9]') > rev = rev_re.findall(str(page))[0] # only need the first item since > the first listing is the latest revision > num = num_re.findall(rev)[0] # findall() always returns a list > print(num) prints out the revision number - 1995. 'revision1995' might be useful, so I saved that to rev. This actually works pretty well for consistently formatted lists. I suppose I went about this the wrong way - I thought I needed to parse the HTML to get the links and do simple regexes on those, but I can just do simple regexes on the entire HTML document. From karim.liateni at free.fr Thu May 19 17:52:20 2011 From: karim.liateni at free.fr (Karim) Date: Thu, 19 May 2011 23:52:20 +0200 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD58D0D.4050508@gmail.com> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD58D0D.4050508@gmail.com> Message-ID: <4DD59114.1080405@free.fr> On 05/19/2011 11:35 PM, Andrew Berg wrote: > On 2011.05.16 02:26 AM, Karim wrote: >> Use regular expression for bad HTLM or beautifulSoup (google it), below >> a exemple to extract all html links: > Actually, using regex wasn't so bad: >> import re >> import urllib.request >> >> url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth' >> page = str(urllib.request.urlopen(url).read(), encoding='utf-8') # >> urlopen() returns a bytes object, need to get a normal string >> rev_re = re.compile('revision[0-9][0-9][0-9][0-9]') >> num_re = re.compile('[0-9][0-9][0-9][0-9]') >> rev = rev_re.findall(str(page))[0] # only need the first item since >> the first listing is the latest revision >> num = num_re.findall(rev)[0] # findall() always returns a list >> print(num) > prints out the revision number - 1995. 'revision1995' might be useful, > so I saved that to rev. > > This actually works pretty well for consistently formatted lists. I > suppose I went about this the wrong way - I thought I needed to parse > the HTML to get the links and do simple regexes on those, but I can just > do simple regexes on the entire HTML document. Great for you! Use what works well and easy to code, always the simpler is the better. For complicate search link to avoid using too complex and bugs prone regex you can derived the code I gave on HTMLParser with max comparison. Anyway you get the choice which is cool, not be stuck on only one solution. Cheers Karim From ethan at stoneleaf.us Thu May 19 18:18:22 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 19 May 2011 15:18:22 -0700 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD1C9D5.4070206@gmail.com> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD1C9D5.4070206@gmail.com> Message-ID: <4DD5972E.1080205@stoneleaf.us> Andrew Berg wrote: > ElementTree doesn't seem to have been updated in a long time, so I'll > assume it won't work with Python 3. I don't know how to use it, but you'll find ElementTree as xml.etree in Python 3. ~Ethan~ From steve+comp.lang.python at pearwood.info Thu May 19 18:40:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 May 2011 22:40:16 GMT Subject: python2+3 References: <42394efe-439f-4431-9b87-b70547f58c80@k17g2000vbn.googlegroups.com> Message-ID: <4dd59c50$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 May 2011 05:42:29 -0700, lkcl wrote: > has anyone considered the idea of literally creating a Python2/ > subdirectory in the python3 codebase, literally just dropping the entire > python2.N code directly into it, renaming all functions and data > structures, adding a "--2-compatible" switch to the python3 argc/ v and > seeing what happens? > > no interoperability, no maintenance, no "compatibility" - just > "support for python 2 directly in the python3 binary". No maintenance? The code won't maintain itself, people using it won't stop reporting bugs. Are you suggesting that the CPython developers should just grit their teeth and refuse to maintain or support code that is part of the official release? Who is your suggested user-base? Those who want support for 2.7 to continue won't be happy with an unmaintained, unsupported compatibility layer. Those who are happy to keep on using obsolete software won't need this compatibility layer, they can just keep using the Python 2.7 they already have. Or 2.5, or 1.5 if they prefer. (I have 1.5 on my machine, installed from source, and it works perfectly well.) And what of the others? Jython, IronPython, PyPy, Stackless ... once they make the move to Python 3 compatibility, are they expected to implement this compatibility layer as well? I dare say that once the original developers stop supporting Python 2.7 in three or seven(?) years, there will be a good niche for some commercial distribution like ActiveState to continue support. Or one of the many critics who insist that Python 3 is a mistake can put their money where their mouth is and continue support themselves. After all, Python is open source. Somebody (you?) could even fork the code base and implement your suggested compatibility layer, or backport Python 3 features, be really daring and create a 2/3 hybrid. -- Steven From steve+comp.lang.python at pearwood.info Thu May 19 18:47:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 May 2011 22:47:58 GMT Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> Message-ID: <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> On Tue, 17 May 2011 10:02:21 -0700, geremy condra wrote: > or O(1): > > ? = (1 + sqrt(5)) / 2 > def fib(n): > numerator = (?**n) - (1 - ?)**n > denominator = sqrt(5) > return round(numerator/denominator) I'd just like to point out that, strictly speaking, it's only O(1) if you assume that exponentiation is O(1). Computer scientists often like to make this simplifying assumption, and it might even be true for floats, but for long ints and any numeric data types with unlimited precision, it won't be. -- Steven From tar at sevak.isi.edu Thu May 19 19:14:14 2011 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 19 May 2011 16:14:14 -0700 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] Ignored, since I don't follow that group. > On Wed, 18 May 2011 20:20:01 +0200, Raymond Wiker > wrote: > : I don't think anybody mentioned *binary* trees. The context was > : directory traversal, in which case you would have nodes with an > : arbitrary (almost) number of children. > > If we are being specific, then directory trees do have parent pointers. > My point was really that ?standard tree representations? is not a > well-defined concept, and having parent pointers is as standard as > not having them. I suppose that I just assumed the standard mathematical definition of a tree as a directed, acyclic graph. It seems that in the context of computability that one would tend toward using the mathematical definitions. Certainly in a complex graph with labeled links or trees with backpointers, you would have an alternate data structure that you could follow. So, to be more precise, then: For directed, acyclic graphs without backpointers, you cannot write an iterative tree walker without simulating a stack. The larger point is that there are algorithms that are inherently recursive and for which there is no natural iterative algorithm. -- Thomas A. Russ, USC/Information Sciences Institute From tar at sevak.isi.edu Thu May 19 19:17:53 2011 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 19 May 2011 16:17:53 -0700 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <8762p7omzu.fsf@kuiper.lan.informatimago.com> Message-ID: "Pascal J. Bourguignon" writes: > tar at sevak.isi.edu (Thomas A. Russ) writes: > > > > This will only work if there is a backpointer to the parent. > > No, you don't need backpointers; some cases have been mentionned in the > other answer, but in general: > > (defun parent (tree node) > (if (member node (children tree)) > tree > (some (lambda (child) (parent child node)) (children tree)))) > > Yes, the question wasn't about time complexity. :-p Um, this is a recursive function. Inside PARENT, there is another call to PARENT. -- Thomas A. Russ, USC/Information Sciences Institute From rosuav at gmail.com Thu May 19 19:37:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 09:37:59 +1000 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 8:47 AM, Steven D'Aprano wrote: > On Tue, 17 May 2011 10:02:21 -0700, geremy condra wrote: > >> or O(1): >> >> ? = (1 + sqrt(5)) / 2 >> ? ? numerator = (?**n) - (1 - ?)**n > > I'd just like to point out that, strictly speaking, it's only O(1) if you > assume that exponentiation is O(1). Computer scientists often like to > make this simplifying assumption, and it might even be true for floats, > but for long ints and any numeric data types with unlimited precision, it > won't be. > Python doesn't have arbitrary precision non-integers, does it? So this is going to be done with floats. Chris Angelico From debatem1 at gmail.com Thu May 19 20:03:45 2011 From: debatem1 at gmail.com (geremy condra) Date: Thu, 19 May 2011 17:03:45 -0700 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 19, 2011 at 3:47 PM, Steven D'Aprano wrote: > On Tue, 17 May 2011 10:02:21 -0700, geremy condra wrote: > >> or O(1): >> >> ? = (1 + sqrt(5)) / 2 >> def fib(n): >> ? ? numerator = (?**n) - (1 - ?)**n >> ? ? denominator = sqrt(5) >> ? ? return round(numerator/denominator) > > I'd just like to point out that, strictly speaking, it's only O(1) if you > assume that exponentiation is O(1). Computer scientists often like to > make this simplifying assumption, and it might even be true for floats, > but for long ints and any numeric data types with unlimited precision, it > won't be. Great point, and something I should have paid attention to. Thanks. Geremy Condra From pjb at informatimago.com Thu May 19 20:38:39 2011 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 20 May 2011 02:38:39 +0200 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <8762p7omzu.fsf@kuiper.lan.informatimago.com> Message-ID: <87pqnemcj4.fsf@kuiper.lan.informatimago.com> tar at sevak.isi.edu (Thomas A. Russ) writes: > "Pascal J. Bourguignon" writes: > >> tar at sevak.isi.edu (Thomas A. Russ) writes: >> > >> > This will only work if there is a backpointer to the parent. >> >> No, you don't need backpointers; some cases have been mentionned in the >> other answer, but in general: >> >> (defun parent (tree node) >> (if (member node (children tree)) >> tree >> (some (lambda (child) (parent child node)) (children tree)))) >> >> Yes, the question wasn't about time complexity. > > :-p > > Um, this is a recursive function. Inside PARENT, there is another call > to PARENT. Feel free to derecursive it. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From debatem1 at gmail.com Thu May 19 20:56:12 2011 From: debatem1 at gmail.com (geremy condra) Date: Thu, 19 May 2011 17:56:12 -0700 Subject: obviscating python code for distribution In-Reply-To: <0q3ga8-s2v.ln1@svn.schaathun.net> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: On Thu, May 19, 2011 at 11:23 AM, Hans Georg Schaathun wrote: > On Thu, 19 May 2011 10:23:47 -0700, geremy condra > ? wrote: > : ?Let me get this straight: your argument is that operating *systems* > : ?aren't systems? > > You referred to the kernel and not the system. ?The complexities of > the two are hardly comparable. I don't know about that. Among the many verified microkernels, at least two projects have formally verified both their kernel and their toolchain, and one of them claims they've verified everything in their TCB and are headed towards verified POSIX compliance in 2012. That would seem to be a fairly large system (and definitely a complete OS) to me. Another (seL4) says they've formally verified security of a complete system that includes a userspace and the ability to run other OSes in fully isolated containers, which also seems to be quite complete. Finally, there's one from Microsoft research that claims similar properties but which apparently isn't interested in compatibility, which I'm not sure how to interpret in terms of usefulness and size. In any event, higher level systems- like electronic voting mechanisms and automotive sensor networks- have also been verified, which seems to run counter to your original point. Also, not sure if it's open to the general public but if you're interested in this kind of thing and live near seattle, I think there's actually going to be a talk on verifying a POSIX userspace implementation here tomorrow. TL;DR version: large systems have indeed been verified for their security properties. > There probably are different uses of system; in computer security > literature? it often refers, not only to a product (hardware/software) > an actual installation and configuration of that product in a specific > context. ?/I/ did not redefine it. You chose a word with a many meanings, used it to make a very broad statement which is only a little bit true, and then pretended that you had the One True Definition in your pocket. I don't think that's legitimate, but whatever; let's just say that we meant different things by the word and drop it. > Speaking of reasonable assumptions, one necessary assumption which is > particularly dodgy is that whoever deploys and configures it > understands all the assumptions and do not break them through ignorance. Yup. Nothing is safe from idiots. > Is your concern with security purely from a developer's viewpoint, > so that you don't have to worry about the context in which it will > be deployed? My viewpoint is that of an attacker, since that's more or less my job. > I read your initial comment to imply that if you cannot get satisfactory > assurance using the lower levels, you won't get any at the higher > levels. ?That does not make any sense. Well, this is kind of like my point. My point was that you really don't get anything at the lower levels, and that they should fix that (which is far more useful to a normal consumer) rather than trying to talk about formal verification and similar tools, which are only going to be used on a tiny fraction of products. Geremy Condra From rosuav at gmail.com Thu May 19 21:33:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 11:33:25 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: On Fri, May 20, 2011 at 10:56 AM, geremy condra wrote: >> Speaking of reasonable assumptions, one necessary assumption which is >> particularly dodgy is that whoever deploys and configures it >> understands all the assumptions and do not break them through ignorance. > > Yup. Nothing is safe from idiots. > Which means that the assumption really is that you are evaluating a system, not a bald piece of code. I don't consider that an assumption. When you're writing code that you will yourself deploy, you take full responsibility; when you let other people deploy it, they have to take ultimate responsibility (although they will legitimately expect you to provide an install script and/or instructions). There are idiots in this world. Have you met them? Met them? I listen to you every week! -- The Goon Show, and so absolutely true Chris Angelico From n4vpython at gmail.com Thu May 19 22:13:51 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Fri, 20 May 2011 07:43:51 +0530 Subject: Inheriting Object Message-ID: Hi Guys, I have been wondering for a while now as to why some classes inherit Object? And what does it really do for the class? Can anyone shed some light on this? Regards, Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Thu May 19 22:30:52 2011 From: debatem1 at gmail.com (geremy condra) Date: Thu, 19 May 2011 19:30:52 -0700 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: On Thu, May 19, 2011 at 6:33 PM, Chris Angelico wrote: > On Fri, May 20, 2011 at 10:56 AM, geremy condra wrote: >>> Speaking of reasonable assumptions, one necessary assumption which is >>> particularly dodgy is that whoever deploys and configures it >>> understands all the assumptions and do not break them through ignorance. >> >> Yup. Nothing is safe from idiots. I actually think I need to take this statement back. The more I think about it, the less convinced I am that it's correct- I can at least conceive of violable systems which cannot be misconfigured. So, sorry about that. > Which means that the assumption really is that you are evaluating a > system, not a bald piece of code. I don't consider that an assumption. > When you're writing code that you will yourself deploy, you take full > responsibility; when you let other people deploy it, they have to take > ultimate responsibility (although they will legitimately expect you to > provide an install script and/or instructions). Sure, although I would personally still call it an assumption. Geremy Condra From rosuav at gmail.com Thu May 19 22:35:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 12:35:17 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: On Fri, May 20, 2011 at 12:30 PM, geremy condra wrote: >> On Fri, May 20, 2011 at 10:56 AM, geremy condra wrote: >>> Yup. Nothing is safe from idiots. > > I actually think I need to take this statement back. The more I think > about it, the less convinced I am that it's correct- I can at least > conceive of violable systems which cannot be misconfigured. So, sorry > about that. If it is, then you're not deploying it, you're just pushing buttons and acting like a user. I still stand by the view that the one with the root password is the one responsible for the computer's security; and if you have the root filesystem password, there's no way that something can be made unmisconfigurable. (You CAN, however, make something that's out-of-the-box secure, so someone just does a 'sudo apt-get install yoursystem' and it's specced up nicely. This is a Good Thing.) Chris Angelico From wbai at camiant.com Thu May 19 22:54:57 2011 From: wbai at camiant.com (William) Date: Fri, 20 May 2011 10:54:57 +0800 Subject: Inheriting Object In-Reply-To: References: Message-ID: <4DD5D801.80408@camiant.com> Hi Nav: Here is the long why. http://www.python.org/download/releases/2.2.3/descrintro/ I guess for most programs, there is no big difference, but if you use some special features that might be different. Say, could use super when using type() instead of class(), also, when using multiple inheritance, you can't multiply inherit from different built-in types. Some new features such as property() is not supported in type either. BRs William On 01/-9/-28163 03:59 AM, Navkirat Singh wrote: > Hi Guys, > > I have been wondering for a while now as to why some classes inherit > Object? And what does it really do for the class? Can anyone shed some > light on this? > > Regards, > Nav From python at mrabarnett.plus.com Thu May 19 22:55:45 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 20 May 2011 03:55:45 +0100 Subject: Inheriting Object In-Reply-To: References: Message-ID: <4DD5D831.4020308@mrabarnett.plus.com> On 20/05/2011 03:13, Navkirat Singh wrote: > Hi Guys, > > I have been wondering for a while now as to why some classes inherit > Object? And what does it really do for the class? Can anyone shed some > light on this? > Read section 3.3 "New-style and classic classes" in the Python docs. From wbai at camiant.com Thu May 19 23:00:36 2011 From: wbai at camiant.com (William) Date: Fri, 20 May 2011 11:00:36 +0800 Subject: Inheriting Object In-Reply-To: References: Message-ID: <4DD5D954.8080101@camiant.com> Hi Nav: Here is the long why. http://www.python.org/download/releases/2.2.3/descrintro/ I guess for most programs, there is no big difference. But in term of some new added features in python, you might not be able to work. Say, you could not use super in type, also you can't multiply inherit from different built-in types, what's more you could not use some builtin feature such as property. BRs William On 01/-9/-28163 03:59 AM, Navkirat Singh wrote: > Hi Guys, > > I have been wondering for a while now as to why some classes inherit > Object? And what does it really do for the class? Can anyone shed some > light on this? > > Regards, > Nav From William.Bai at tekelec.com Thu May 19 23:01:13 2011 From: William.Bai at tekelec.com (William.Bai) Date: Fri, 20 May 2011 11:01:13 +0800 Subject: Inheriting Object In-Reply-To: References: Message-ID: <4DD5D979.8050804@tekelec.com> Hi Nav: Here is the long why. http://www.python.org/download/releases/2.2.3/descrintro/ I guess for most programs, there is no big difference. But in term of some new added features in python, you might not be able to work. Say, you could not use super in type, also you can't multiply inherit from different built-in types, what's more you could not use some builtin feature such as property. BRs William On 01/-9/-28163 03:59 AM, Navkirat Singh wrote: > Hi Guys, > > I have been wondering for a while now as to why some classes inherit > Object? And what does it really do for the class? Can anyone shed some > light on this? > > Regards, > Nav From n4vpython at gmail.com Fri May 20 00:11:49 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Fri, 20 May 2011 09:41:49 +0530 Subject: Inheriting Object In-Reply-To: <4DD5D831.4020308@mrabarnett.plus.com> References: <4DD5D831.4020308@mrabarnett.plus.com> Message-ID: On Fri, May 20, 2011 at 8:25 AM, MRAB wrote: > On 20/05/2011 03:13, Navkirat Singh wrote: > >> Hi Guys, >> >> I have been wondering for a while now as to why some classes inherit >> Object? And what does it really do for the class? Can anyone shed some >> light on this? >> >> Read section 3.3 "New-style and classic classes" in the Python docs. > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks Guys...I will look deeper into this. I thought I read somewhere that it was required in older python releases, but in newer releases it is not. I might be wrong though. Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at gmail.com Fri May 20 00:15:48 2011 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 20 May 2011 14:15:48 +1000 Subject: turn monitor off and on In-Reply-To: References: Message-ID: On Mon, May 16, 2011 at 7:29 PM, Gabriel Genellina wrote: > > Your script worked fine for me, 2.6 and XP also. Perhaps your monitor > device driver is buggy or does not implement the required functionality. > Mine is from Philips. > > I'm actually using windows 7. Maybe its the difference in OS? Anyway, yes, the monitor turns back on if the keys are pressed. I've gone with a pygame/autoit hack which doesn't turn the monitor off (just black) and then removes the black screen (no offence). Thanks again for the helps -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at gmail.com Fri May 20 00:21:17 2011 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 20 May 2011 14:21:17 +1000 Subject: starting a separate thread in maya Message-ID: Hi, I'm using python2.5 in maya 2009 x64 (in linux). I have a script running and somewhere in the script, I want to start another python script that might not return and i don't want the main maya python script to wait for it to finish, even more, after the second script started, I'd like the main script to continue processing. I've tried using threading and maya.utils.executeInMainThread and os.popen and os.spawn, none seem to work this way. Is it not possible to do this in python2.5? Thanks again for any help. Cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: From hg at schaathun.net Fri May 20 00:28:05 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Fri, 20 May 2011 05:28:05 +0100 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On Thu, 19 May 2011 23:21:30 +0200, Rikishi42 wrote: : On 2011-05-18, Hans Georg Schaathun wrote: : > Now Mac OS X has maintained the folder concept of older mac generations, : > and Windows has cloned it. They do not want the user to understand : > recursive data structures, and therefore, naturally, avoid the word. : : You imply they want to keep their users ignorant of these structures, as if : to keep something valuable from them. Wouldn't it be more honest, more to : the point and much simpler to state they don't NEED the user to understand : recursive - or indeed any other - data structures? And that the user doesn't : NEED to understand or know about them, just to use them? Admittedly, my wording had unintended implictions. Mac OS X /targets/ users who do not need to understand the underlying structure. However, the system also has users who do. : After all they are users. They use their system for fun, learning or work. : Even a very competent or advanced use of a tool (computer, car, mobile phone, : fridge, TV, radio, toilet) in no way implies an understanding of it's inner : workings. Nor the need, nor the desire. For a general purpose computer, that is simply not true in general. : PS: Isn't this thread much ado about nothing? :-) Most threads are. : It starts with the misconception (or should I say confusion?) between : performing a recursive job and using a recursive tool to do it. And then it : blazes off in these huge discusions about semantics to define a definition : of an abstraction of a alleady theoretical problem. And explaining the source of the misconception and the varying use would be irrelevant? : And PPS: the P(P)S's don't specifically refer to your posting. Thanks :-) -- :-- Hans Georg From hg at schaathun.net Fri May 20 00:48:50 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Fri, 20 May 2011 05:48:50 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: On Thu, 19 May 2011 17:56:12 -0700, geremy condra wrote: : TL;DR version: large systems have indeed been verified for their : security properties. : (...) : Yup. Nothing is safe from idiots. The difficult part is mapping those properties to actual requirements and threat models. Formal methods do not help on that step. It takes more than a non-idiot to avoid misunderstandings on the interface betweeen professions. Either way, the assumption that your system will not be handled by idiots is only reasonable if you yourself is the only user. -- :-- Hans Georg From rustompmody at gmail.com Fri May 20 01:05:23 2011 From: rustompmody at gmail.com (rusi) Date: Thu, 19 May 2011 22:05:23 -0700 (PDT) Subject: Recursion in Computer Science Message-ID: <725020f8-3a73-4a8a-a587-e4c4996bcb04@z15g2000prn.googlegroups.com> There have been a number of unrelated discussions regarding recursion on this list. I believe that recursion occurs in a wider spread of areas than is usually recognised. Heres a list of some such areas. Please note I am using recursion in a broad and somewhat fuzzy sense. Narrow specific definitions would lead to conclusions like: -- Prolog has no functions or procedures so it has no recursion -- Since recursion is equivalent to stack + iteration therefore Fortran supports recursion. Heres (an initial approx to) such a list: ------------------------------------------------------- recursive functions recursive data -- eg linked lists, trees nesting self reference -- Y combinator well founded induction structural induction bootstrapping language to describe language -- syntax - yacc in yacc language to describe language -- semantics - lisp in lisp -- metacircularity Goedel's theorem <- meta-mathematics <- ordinary math undecidability <- universal TM <- Turing machine as ordinary computer reentrancy [An OS-like program fails to be reentrant for the same reason that Fortan-like language fails to support recursion -- Non use of stack] virtualization in OS Introspection in modern languages Models to metamodels corecursion - laziness, infinite datastructures - semantics of generators/iterators in python Von Neuman machine - code is data -- therefore quondam hardware becomes software - data can be code -- viruses From rustompmody at gmail.com Fri May 20 01:13:14 2011 From: rustompmody at gmail.com (rusi) Date: Thu, 19 May 2011 22:13:14 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On May 20, 2:21?am, Rikishi42 wrote: > On 2011-05-18, Hans Georg Schaathun wrote: > > > Now Mac OS X has maintained the folder concept of older mac generations, > > and Windows has cloned it. ?They do not want the user to understand > > recursive data structures, and therefore, naturally, avoid the word. > > You imply they want to keep their users ignorant of these structures, as if > to keep something valuable from them. Wouldn't it be more honest, more to > the point and much simpler to state they don't NEED the user to understand > recursive - or indeed any other - data structures? And that the user doesn't > NEED to understand or know about them, just to use them? > > After all they are users. They use their system for fun, learning or work. > Even a very competent or advanced use of a tool (computer, car, mobile phone, > fridge, TV, radio, toilet) in no way implies an understanding of it's inner > workings. Nor the need, nor the desire. > > PS: Isn't this thread much ado about nothing? ?:-) > It starts with the misconception (or should I say confusion?) between > performing a recursive job and using a recursive tool to do it. And then it > blazes off in these huge discusions about semantics to define a definition > of an abstraction of a alleady theoretical problem. > > Glorious, just frelling glorious. ? ?:-) > We have an expression for that. But I'll avoid using it, since it has the > word 'masturbation' in it... > > And PPS: the P(P)S's don't specifically refer to your posting. > > -- > When in doubt, use brute force. > ? ? ? ? ? ? ? ? -- Ken Thompson Well... I was rethinking my earlier argument with Ian Kelly about the similarity/differences between recursion in theory and in CS. On rethinking my position I come to the conclusion that I am arguing like an chimp -- and therefore not making my real point which is that that recursion is more widespread in computer science than is recognised. This is discussed separately here http://groups.google.com/group/comp.lang.python/browse_thread/thread/212e6477262125e9# [I agree with you Xah that recursion is a technical word that should not be foisted onto lay users.] From rosuav at gmail.com Fri May 20 01:18:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 15:18:50 +1000 Subject: Recursion in Computer Science In-Reply-To: <725020f8-3a73-4a8a-a587-e4c4996bcb04@z15g2000prn.googlegroups.com> References: <725020f8-3a73-4a8a-a587-e4c4996bcb04@z15g2000prn.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 3:05 PM, rusi wrote: > ?- data can be code -- viruses It's not JUST viruses. There's plenty of legitimate reasons for your data to actually be code... that's how compilers work! :) Chris Angelico From rustompmody at gmail.com Fri May 20 01:22:49 2011 From: rustompmody at gmail.com (rusi) Date: Thu, 19 May 2011 22:22:49 -0700 (PDT) Subject: Recursion in Computer Science References: <725020f8-3a73-4a8a-a587-e4c4996bcb04@z15g2000prn.googlegroups.com> Message-ID: On May 20, 10:18?am, Chris Angelico wrote: > On Fri, May 20, 2011 at 3:05 PM, rusi wrote: > > ?- data can be code -- viruses > > It's not JUST viruses. There's plenty of legitimate reasons for your > data to actually be code... that's how compilers work! :) > > Chris Angelico Yes sure Thanks. An exhaustive list would be much longer (and I got tired of typing) From ericsnowcurrently at gmail.com Fri May 20 01:33:12 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Thu, 19 May 2011 23:33:12 -0600 Subject: validating a class against an ABC at definition time Message-ID: Thinking about class APIs and validating a class against an API. The abc module provides the tools to do some of this. One thing I realized, that I hadn't noticed before, is that the abstractness of a class is measured when instances of the class are created. This happens in object.__new__ (pyobject.c). Validating thus when a class is defined would not be as helpful, since there is no guarantee that the class is not meant to be abstract as well. However, I have found that it is sometimes nice to validate a class at definition time. This is particularly true for a class that does not inherit from the abstract base class (but registers instead). Taking cues from abc.py and pyobject.c, here is a stab at a class decorator that validates a class against another. def validate(abc): if not isinstance(abc, type): raise TypeError("Can only validate against classes") def decorator(cls): if not __debug__: return cls if not isinstance(cls, type): raise TypeError("Can only validate classes") abstracts = set() for name in getattr(abc, "__abstractmethods__", set()): value = getattr(cls, name, None) if not value: abstracts.add(name) elif getattr(value, "__isabstractmethod__", False): abstracts.add(name) if abstracts: sorted_methods = sorted(abstracts) joined = ", ".join(sorted_methods) msg = "Class {} does not implement abstract methods {} of class {}" raise TypeError(msg.format(cls.__name__, joined, abc.__name__)) return cls return decorator Stack this with the ABCMeta.register method and you can ensure that your class is compliant with the ABC at the time you register it on that ABC. Does anyone find this irrelevant or superfluous? I know that it would be a good idea to stay on top of your class's implementation of an ABC's abstract methods. However, this seems like a good way of doing that programmatically. Does anyone know a better way to do ABC validation at definition time? Thanks. -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri May 20 01:43:43 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 19 May 2011 22:43:43 -0700 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> Message-ID: <4DD5FF8F.604@stoneleaf.us> Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me what horrible thing will happen if this isn't the case? Here's a toy example of a class I'm thinking of writing that will compare equal with int's, but hash differently: --> class Wierd(): ... def __init__(self, value): ... self.value = value ... def __eq__(self, other): ... return self.value == other ... def __hash__(self): ... return hash((self.value + 13) ** 3) ... --> one = Wierd(1) --> two = Wierd(2) --> three = Wierd(3) --> one --> one == 1 True --> one == 2 False --> two == 2 True --> three == 3 True --> d = dict() --> d[one] = '1' --> d[two] = '2' --> d[three] = '3' --> d {: '1', : '3', : '2'} --> d[1] = '1.0' --> d[2] = '2.0' --> d[3] = '3.0' --> d {: '3', 1: '1.0', 2: '2.0', 3: '3.0', : '2', : '1'} --> d[2] '2.0' --> d[two] '2' All information greatly appreciated! ~Ethan~ From steve+comp.lang.python at pearwood.info Fri May 20 01:58:04 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2011 05:58:04 GMT Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 May 2011 09:37:59 +1000, Chris Angelico wrote: > On Fri, May 20, 2011 at 8:47 AM, Steven D'Aprano > wrote: >> On Tue, 17 May 2011 10:02:21 -0700, geremy condra wrote: >> >>> or O(1): >>> >>> ? = (1 + sqrt(5)) / 2 >>> ? ? numerator = (?**n) - (1 - ?)**n >> >> I'd just like to point out that, strictly speaking, it's only O(1) if >> you assume that exponentiation is O(1). Computer scientists often like >> to make this simplifying assumption, and it might even be true for >> floats, but for long ints and any numeric data types with unlimited >> precision, it won't be. >> >> > Python doesn't have arbitrary precision non-integers, does it? So this > is going to be done with floats. Sure, which is why the above fib() function will become increasing inaccurate beyond some given n, by memory about n=71 or so. Er, at least the fib() function that *was* above until you deleted most of it :) If you want an *accurate* fib() function using exponentiation of ?, you need arbitrary precision non-integers. Nevertheless, at some point you will hit the limit of floats, which thanks to the exponential growth of the Fibonacci sequence won't take that long: it takes roughly 1475 iterations to exceed the range of Python floats. -- Steven From rosuav at gmail.com Fri May 20 02:06:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 16:06:40 +1000 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 3:58 PM, Steven D'Aprano wrote: > ... until you deleted most of it :) Minimalist quoting practice! :) > If you want an *accurate* fib() function using exponentiation of ?, you > need arbitrary precision non-integers. I believe the 'bc' command-line calculator can do a-p non-i, and I know REXX can, but it seems to be quite an unusual thing. Is it that much harder than a-p integer that it's just not worthwhile? It seems strange to smoothly slide from native integer to long integer and just keep on going, and yet to be unable to do the same if there's a fractional part on it. Chris Angelico From harrismh777 at charter.net Fri May 20 02:17:44 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 20 May 2011 01:17:44 -0500 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: geremy condra wrote: >> Anonymous, "Maximum Linux Security: A Hacker's Guide to Protecting >> > Your Linux Server and Workstation," Indianapolis: >> > Sams Publishing, 2000. > This is a good volume, but very dated. I'd probably pass on it. Actually, although dated, its still a very good manual for concepts, and much of it... believe it or not... is still just as valid as the day it was written. Some things of course have changed, like web security and protocols. Some of the linux admin stuff has now been automated with reasonable defaults, *but not all*... Appendix D is good-- additional resources bibliography ! Maybe try to buy or borrow a used copy [ or just skip it... ] PS I really have hoped that Anonymous would be putting out a second edition, but I can't find it... so not yet... kind regards, m harris From harrismh777 at charter.net Fri May 20 02:26:47 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 20 May 2011 01:26:47 -0500 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > I believe the 'bc' command-line calculator can do a-p non-i, and I > know REXX can Yes, bc is wonderful in this regard. Actually, bc does this sort of thing in 'circles' around Python. This is one of Python's weaknesses for some problem solving... no arbitrary precision. And its not just that bc does arbitrary precision--- its that it does it fast! Actually, it should be relatively easy to incorporate parts of bc into Python as C extensions. On the other hand, when needing specialized math work from bc, its probably just better to use bc and leave Python alone. On the other hand, most of the time (and I mean 99.999% of the time) floats are going to work just fine... usually folks don't even need doubles.... :) With fifteen or twenty digits of PI we can calculate the circumference of the visible universe to within the width of a proton... er, I mean hadron... and you know what... how many folks need to do that anyway?? Don't get me wrong... I absolutely love playing around with bignums, but then, I'm a math geek... ;-) kind regards, m harris From ssonaldd at gmail.com Fri May 20 02:31:31 2011 From: ssonaldd at gmail.com (SONAL ...) Date: Fri, 20 May 2011 12:01:31 +0530 Subject: Problem running pylons webtests. ImportError and TestController is not defined error. Message-ID: I have directory structure as gnukhata/tests/functional. In functional folder I have web tests files. Following is the sample tests: *from gnukhata.tests import * class TestVendorController(TestController): def test_index(self): response = self.app.get(url(controller='vendor', action='index'**))* After running tests, it gives me following error: *Traceback (most recent call last): File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 651, in loadByNames things.append(self.findByName(name)) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 460, in findByName return filenameToModule(name) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 98, in filenameToModule return _importFromFile(fn) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 117, in _importFromFile module = imp.load_source(moduleName, fn, fd) File "test_vendor.py", line 1, in from gnukhata.tests import * exceptions.ImportError: No module named tests* Instead of gnukhata.tests if I write gnukhata then it shows the following error: *Traceback (most recent call last): File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 651, in loadByNames things.append(self.findByName(name)) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 460, in findByName return filenameToModule(name) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 98, in filenameToModule return _importFromFile(fn) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 117, in _importFromFile module = imp.load_source(moduleName, fn, fd) File "test_vendor.py", line 3, in class TestVendorController(TestController): exceptions.NameError: name 'TestController' is not defined * How to remove these errors??? Suggest me solution... Thanks in advance... -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Fri May 20 02:33:46 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 20 May 2011 08:33:46 +0200 Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> Message-ID: <0deha8-6u9.ln1@satorlaser.homedns.org> Ethan Furman wrote: > Several folk have said that objects that compare equal must hash equal, > and the docs also state this > http://docs.python.org/dev/reference/datamodel.html#object.__hash__ > > I'm hoping somebody can tell me what horrible thing will happen if this > isn't the case? If you were familiar with what a hash map is, you wouldn't ask. The thing is that the hash is used to look up the place in the map where the thing is stored. If two equal objects have different hashes, they will be stored in different places in the hash map. Looking for object1 will then not turn up with object2, even though they are equal. If this is something you don't care about, and all you care about is identity, then I'd derive the hash from each object's ID. This ID has another property which is something that is assumed for hashes, and your code seems a bit to get that wrong, too, and that is that the hash must not change. Again, the reason is that if the hash changes, the position in the hash map changes, too. If you then try to look up the changed object, it will look for it in the new place, but it won't be found because it is in the old place. For that reason, it is generally useful to use immutable types like integers, floats, strings and tuples thereof as keys. Since you can't change them, you basically have the guarantee that they hash the same. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From __peter__ at web.de Fri May 20 02:38:30 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 May 2011 08:38:30 +0200 Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> Message-ID: Ethan Furman wrote: > Several folk have said that objects that compare equal must hash equal, > and the docs also state this > http://docs.python.org/dev/reference/datamodel.html#object.__hash__ > > I'm hoping somebody can tell me what horrible thing will happen if this > isn't the case? Here's a toy example of a class I'm thinking of writing > that will compare equal with int's, but hash differently: > > --> class Wierd(): > ... def __init__(self, value): > ... self.value = value > ... def __eq__(self, other): > ... return self.value == other > ... def __hash__(self): > ... return hash((self.value + 13) ** 3) > ... Try this: >>> d = {Wierd(1): 0} >>> 1 in d False >>> 1 in d.keys() True From clp2 at rebertia.com Fri May 20 02:44:59 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 19 May 2011 23:44:59 -0700 Subject: hash values and equality In-Reply-To: <4DD5FF8F.604@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD5FF8F.604@stoneleaf.us> Message-ID: On Thu, May 19, 2011 at 10:43 PM, Ethan Furman wrote: > Several folk have said that objects that compare equal must hash equal, and > the docs also state this > http://docs.python.org/dev/reference/datamodel.html#object.__hash__ > > I'm hoping somebody can tell me what horrible thing will happen if this > isn't the case? ?Here's a toy example of a class I'm thinking of writing > that will compare equal with int's, but hash differently: > > --> class Wierd(): > ... ? ? def __init__(self, value): > ... ? ? ? ? self.value = value > ... ? ? def __eq__(self, other): > ... ? ? ? ? return self.value == other > ... ? ? def __hash__(self): > ... ? ? ? ? return hash((self.value + 13) ** 3) > ... > --> one = Wierd(1) > --> two = Wierd(2) > --> three = Wierd(3) > --> one > > --> one == 1 > True > --> one == 2 > False > --> two == 2 > True > --> three == 3 > True > --> d = dict() > --> d[one] = '1' > --> d[two] = '2' > --> d[three] = '3' > --> d > {: '1', > ?: '3', > ?: '2'} > --> d[1] = '1.0' > --> d[2] = '2.0' > --> d[3] = '3.0' This is the part considered "horrible": > --> d > {: '3', > ?1: '1.0', > ?2: '2.0', > ?3: '3.0', > ?: '2', > ?: '1'} Compare: >>> x = {5.0 : 'foo'} >>> x[5] 'foo' Here's a more common/plausible "horrible" case closer to what the docs writers had in mind: >>> class Naughty(object): ... def __init__(self, n): ... self.n = n ... def __eq__(self, other): ... return self.n == other.n ... >>> Naughty(5) == Naughty(5) True >>> Naughty(5) is Naughty(5) False >>> bad = Naughty(3) >>> y = {bad : 'foo'} >>> y[bad] # just happens to work 'foo' >>> del bad >>> # ok, how do we get to 'foo' now? >>> y[Naughty(3)] # try the obvious way Traceback (most recent call last): File "", line 1, in KeyError: <__main__.Naughty object at 0x2a1cb0> >>> # We're screwed. Naughty instances (and similar) can't be used sensibly as hash keys (unless you /only/ care about object identity; this is often not the case). Cheers, Chris -- http://rebertia.com From my.spamtrap at verizon.net Fri May 20 02:50:23 2011 From: my.spamtrap at verizon.net (Roland Hutchinson) Date: Fri, 20 May 2011 06:50:23 +0000 (UTC) Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: On Wed, 18 May 2011 07:19:08 +0200, Pascal J. Bourguignon wrote: > Roland Hutchinson writes: > >> Sorry to have to contradict you, > > Don't be sorry. > > >> but it really is a textbook example of recursion. Try this psuedo-code >> on for size: >> >> FUNCTION DIR-DELETE (directory) >> FOR EACH entry IN directory >> IF entry IS-A-DIRECTORY THEN DIR-DELETE (entry). >> >> Well, now that's not just recursion; it's tail recursion. > > It's not tail recursion. If you had indented your code properly, you'd > see why it's not: > > (defun dir-delete (directory) > (loop for entry in directory > do (if (is-a-directory entry) > (dir-delete entry)))) > You are right, of course. Thanks for the correction. > (I put parentheses, so my editor knows what I mean and can do the > indentation for me). My editor would have done that, too--if I had bothered to be thinking clearly. > That's why walking a directory is done with a recursive procedure, > instead of an iterative one: it's much simplier. To implement an > iterative procedure, you would have to manage a stack yourself, instead > of using the implicit stack of the recursive procedure. Got it! Thanks again. -- Roland Hutchinson He calls himself "the Garden State's leading violist da gamba," ... comparable to being ruler of an exceptionally small duchy. --Newark (NJ) Star Ledger ( http://tinyurl.com/RolandIsNJ ) From ian.g.kelly at gmail.com Fri May 20 02:53:57 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 00:53:57 -0600 Subject: Inheriting Object In-Reply-To: References: <4DD5D831.4020308@mrabarnett.plus.com> Message-ID: On Thu, May 19, 2011 at 10:11 PM, Navkirat Singh wrote: > Thanks Guys...I will look deeper into this. I thought I read somewhere that > it was required in older python releases, but in newer releases it is not. I > might be wrong though. In Python 3.x all classes inherit from object by default, so "class Foo(object):" and "class Foo:" are equivalent. In Python 2.x they are not equivalent, and you should use "class Foo(object):" unless you have a specific reason not to. Cheers, Ian From rosuav at gmail.com Fri May 20 02:54:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 16:54:06 +1000 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 4:26 PM, harrismh777 wrote: > Actually, it should be relatively easy to incorporate parts of bc into > Python as C extensions. On the other hand, when needing specialized math > work from bc, its probably just better to use bc and leave Python alone. If someone has time to kill (as if!), it'd be awesome to get a new numeric type that uses bc's code; any other numeric type (int, long, float) could autopromote to it, removing the dilemma of which to promote out of long and float. Hmm... Python 4.0, 'bc' is the new default integer and everything else is a performance optimization? Heh. > On the other hand, most of the time (and I mean 99.999% of the time) floats > are going to work just fine... usually folks don't even need doubles.... > :) 99.9% of the time int will work fine, too. Most people don't need arbitrary precision OR floating point. > Don't get me wrong... I absolutely love playing around with bignums, but > then, I'm a math geek... ? ?;-) Absolutely. Bring on the geekiness. I've used bignums for things other than straight arithmetic, actually. In REXX, where everything is a string, I've done some fascinating (and completely useless) analyses that involve taking internal digits from a number, performing arithmetic on them, getting huge numbers back, and then searching for substrings (ie digit strings) in the result. What's the lowest power of 2 that has 5 consecutive digits in it? All 10 digits? (That is, it has '0123456789' somewhere in its decimal representation.) Like I said, completely useless... but how many of you immediately pondered which language to implement the search in? Chris Angelico From my.spamtrap at verizon.net Fri May 20 02:54:09 2011 From: my.spamtrap at verizon.net (Roland Hutchinson) Date: Fri, 20 May 2011 06:54:09 +0000 (UTC) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> Message-ID: On Wed, 18 May 2011 12:59:45 -0500, Victor Eijkhout wrote: > Harrison Hill wrote: > >> No need - I have the Dictionary definition of recursion here: >> >> Recursion: (N). See recursion. > > If you tell a joke, you have to tell it right. > > Recursion: (N). See recursion. See also tail recursion. Very good! -- Roland Hutchinson He calls himself "the Garden State's leading violist da gamba," ... comparable to being ruler of an exceptionally small duchy. --Newark (NJ) Star Ledger ( http://tinyurl.com/RolandIsNJ ) From steve+comp.lang.python at pearwood.info Fri May 20 02:55:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2011 06:55:35 GMT Subject: English Idiom in Unix: Directory Recursively References: Message-ID: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: > [I agree with you Xah that recursion is a technical word that should not > be foisted onto lay users.] I think that is a patronizing remark that under-estimates the intelligence of lay people and over-estimates the difficulty of understanding recursion. Any person who has ever been to a barber or hairdresser with mirrors on two parallel walls will be familiar with recursion: a reflection of the reflection of the reflection of the reflection, forever. In 1970, an extremely low-brow comedy "Carry On Up The Jungle" was about the search for an imaginary bird that flies in smaller and small circles until it disappears up it's own rear end, a type of recursion: http://en.wikipedia.org/wiki/Carry_On_Up_the_Jungle The bird in question goes back in folklore since at least 1854: http://en.wikipedia.org/wiki/Oozlum_bird Trust me on this, if the audience of Carry On films could understand recursion, anyone can! -- Steven From J.deBoynePollard-newsgroups at NTLWorld.COM Fri May 20 03:00:58 2011 From: J.deBoynePollard-newsgroups at NTLWorld.COM (Jonathan de Boyne Pollard) Date: Fri, 20 May 2011 08:00:58 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: > ?English Idiom in Unix: Directory Recursively? > http://xahlee.org/comp/idiom_directory_recursively.html > > ------------------------------------------ > English Idiom in Unix: Directory Recursively > > Xah Lee, 2011-05-17 > > Today, let's discuss something in the category of lingustics. > > You know how in unix tools, when you want to delete the whole > directory and all sub-directories and files in it, it's referred as > ?recursive?? > > [...] > > Though, if you think about it, it's not exactly a correct description. > ?Recursive?, or ?recursion?, refers to a particular type of algorithm, > [...] Indeed. And the algorithms that are employed to perform the operations so described are recursive. From steve+comp.lang.python at pearwood.info Fri May 20 03:04:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2011 07:04:27 GMT Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 May 2011 05:48:50 +0100, Hans Georg Schaathun wrote: > Either way, the assumption that your system will not be handled by > idiots is only reasonable if you yourself is the only user. Nonsense. How do you (generic "you", not any specific person) know that you are not an idiot? If you are an idiot, you obviously shouldn't trust your own judgment -- although of course idiots do trust their own judgment when they shouldn't, and the less they know, the less they realise how little they know: http://en.wikipedia.org/wiki/Dunning?Kruger_effect So if you think that you're not an idiot, you might be an idiot who is unaware of being an idiot. Your own opinion is the last opinion you should pay attention to. The world is full of people with delusions of superiority -- only an idiot would trust their own opinion of themselves. You can listen to others, but only so long as you don't surround yourself with idiots. But how do you know if the people around you are idiots? You certainly can't trust your judgment, nor can you trust theirs. If you're an idiot, you (still talking about generic "you") and your idiot friends are probably all congratulating yourselves for not being idiots. In contrast, if you're not an idiot, then you probably are aware (and if not, you should be) of all the cognitive biases human beings are prone to, of all the mental and emotional weaknesses that we all suffer from, which cause us to act in idiotic ways. If you're not an idiot, then you know your limitations, that like everyone, you can be fooled or foolish, that you can make mistakes, that you sometimes operate equipment when you are not at the optimum level of alertness, when your attention to detail is below normal or you are a little more careless than you should be. In short, that everyone, including yourself, can be an idiot, and the more intelligent you are, the more astonishingly stupid your mistakes may be. Any moron can accidentally burn themselves with a match, but it takes a first-class genius to give chronic lead poisoning to tens of millions *and* nearly destroy the ozone layer of the entire world: http://en.wikipedia.org/wiki/Thomas_Midgley,_Jr. So... if you think you are not an idiot, you are, and if you think you are an idiot, you are. Either way, even if your software is only being used by yourself, you should still attempt to make it as idiot-proof as an idiot like yourself can make it. -- Steven From J.deBoynePollard-newsgroups at NTLWorld.COM Fri May 20 03:07:08 2011 From: J.deBoynePollard-newsgroups at NTLWorld.COM (Jonathan de Boyne Pollard) Date: Fri, 20 May 2011 08:07:08 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: > AFAICS what emacs calls "recursive delete" is what the ordinary person > would simply call "delete". Presumably the non-recursive delete is > called simply "delete" but is actually something more complicated than > delete, and you're supposed to know what that is. > The "non-recursive delete" would be simply calling the rmdir() system call, which of course fails if the directory is non-empty. One has to empty the directory of its contents, if any, first. That, of course, involves potentially recursively removing any subdirectories, in exactly the same way. From rustompmody at gmail.com Fri May 20 03:08:36 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 20 May 2011 00:08:36 -0700 (PDT) Subject: embedding and extending on windows Message-ID: <990aa453-4471-4af9-8dd0-cdf5f54e6f43@l14g2000pro.googlegroups.com> A client wants to 'be lectured' on extending and embedding python on windows. I am familiar with this (or was until python2.3 or thereabouts) on linux -- never done it on windows. Can some kind soul point me to some link on the issues/pitfalls re this? I see three choices: 1. Us MS C for the C extensions 2. Use cygwin Recompile python from sources Use gcc for the extensions 3. Mix gcc extension + precompiled python (and pray!) -- If we use ctypes do we need to rely less on prayer? -- What goes wrong with python compiled with gcc? [Ok let me guess I have to compile everything else thereafter? Any other warnings?] From steve+comp.lang.python at pearwood.info Fri May 20 03:10:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2011 07:10:45 GMT Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: <4dd613f5$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 May 2011 17:56:12 -0700, geremy condra wrote: > TL;DR version: large systems have indeed been verified for their > security properties. How confident are we that the verification software is sufficiently bug- free that we should trust their results? How confident are we that the verification software tests every possible vulnerability, as opposed to merely every imaginable one? -- Steven From J.deBoynePollard-newsgroups at NTLWorld.COM Fri May 20 03:10:45 2011 From: J.deBoynePollard-newsgroups at NTLWorld.COM (Jonathan de Boyne Pollard) Date: Fri, 20 May 2011 08:10:45 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: > I think what happens is that the ?recursive? has become a idiom associated with directory to such a degree that the unix people don't know what the fuck they are talking about. They just simply use the word to go with directory whever they mean the whole directory. > > In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it possibly mean by the word ?recursive? there? Like, it might delete the > directory but not delete all files in it? It might *try* to delete the directory but not any of its contents, yes. If such functionality is not offered, then putting the word in the user interface is redundant, and possibly not the best way to warn the user of potentially a massive loss of files and directories. But the algorithm employed is indeed recursive. From rosuav at gmail.com Fri May 20 03:10:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 17:10:49 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> Message-ID: On Wed, 18 May 2011 12:59:45 -0500, Victor Eijkhout wrote: > Recursion: (N). See recursion. See also tail recursion. caching proxy (n): If you already know what recursion is, this is the same. Otherwise, see recursion. ChrisA From ian.g.kelly at gmail.com Fri May 20 03:26:49 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 01:26:49 -0600 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 19, 2011 at 11:58 PM, Steven D'Aprano wrote: > Sure, which is why the above fib() function will become increasing > inaccurate beyond some given n, by memory about n=71 or so. Er, at least > the fib() function that *was* above until you deleted most of it :) > > If you want an *accurate* fib() function using exponentiation of ?, you > need arbitrary precision non-integers. This seems to work for arbitrary n, although I only tested it out to about n=2000. from decimal import Decimal, localcontext from math import sqrt def fib(n): if n <= 70: return fib_float(n) else: return fib_decimal(n) phi_float = (1 + sqrt(5)) / 2 def fib_float(n): numerator = (phi_float ** n) - (1 - phi_float) ** n denominator = sqrt(5) return int(round(numerator / denominator)) def fib_decimal(n): with localcontext() as ctx: ctx.prec = n // 4 + 1 sqrt_5 = Decimal('5').sqrt() phi = (1 + sqrt_5) / 2 numerator = (phi ** n) - (1 - phi) ** n return int((numerator / sqrt_5).to_integral_value()) Cheers, Ian From ian.g.kelly at gmail.com Fri May 20 03:32:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 01:32:52 -0600 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2011/5/20 Ian Kelly : > def fib_decimal(n): > ? ?with localcontext() as ctx: > ? ? ? ?ctx.prec = n // 4 + 1 > ? ? ? ?sqrt_5 = Decimal('5').sqrt() > ? ? ? ?phi = (1 + sqrt_5) / 2 > ? ? ? ?numerator = (phi ** n) - (1 - phi) ** n > ? ? ? ?return int((numerator / sqrt_5).to_integral_value()) Note that I believe this is O(n) since the necessary precision grows linearly with n. From PointedEars at web.de Fri May 20 03:38:48 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 20 May 2011 09:38:48 +0200 Subject: connect SIGINT to custom interrupt handler References: <1691845.hkbZ0PkbqX@PointedEars.de> Message-ID: <1905065.XAFRqVoOGU@PointedEars.de> Christoph Scheingraber wrote: > On 2011-05-15, Thomas 'PointedEars' Lahn wrote: >> Obviously. `signal' refers to an `int' object, probably by something >> like >> >> signal = 42 >> >> before. E.g. `print' or a debugger will tell you, as you have not showed >> the relevant parts of the code. > > The problem is that I am running someone else's module which seems to > use signal, I guess that means I have to create a child method? > Is it correct anyway to have > > signal.siginterrupt(signal.SIGINT, False) > > in my custom interrupt_handler function Only if `signal' is not the name of an int argument. > or should it be outside but > after signal.signal(signal.SIGINT, interrupt_handler)? In the meantime, Chris Angelico has pointed out the cause of the problem. Please follow his advice, i.e. rename your argument. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From mail at timgolden.me.uk Fri May 20 04:21:54 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 20 May 2011 09:21:54 +0100 Subject: os.access giving incorrect results on Windows In-Reply-To: <4DD5803A.4080208@gmail.com> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> <4DD572FB.2010809@timgolden.me.uk> <4DD575E1.9060801@gmail.com> <4DD578AF.3000001@timgolden.me.uk> <4DD5803A.4080208@gmail.com> Message-ID: <4DD624A2.2030503@timgolden.me.uk> On 19/05/2011 21:40, Andrew Berg wrote: > On 2011.05.19 03:08 PM, Tim Golden wrote: >> * A R_OK check always succeeds if the file's attributes can be read >> at all > So is this the same as F_OK then, or does it return false if the user > isn't allowed to read permissions? >> * A W_OK check fails if the file has its DOS read-only attribute set > DOS attribute? >> * A W_OK check always succeeds for a directory (because read-only means >> something else for directories). >> >> Would you care to propose some wording for the docs? I'm quite happy >> to commit if we can come to an agreement. > I'm a beginner when it comes to Python, but I could give it a shot. A > big red warning box explaining how the code under Windows doesn't use > ACLs under the os.access() entry (above the notes) seems appropriate. A > warning box under os.W_OK saying something like "Under Windows, access() > will always indicate that a directory is writable." would also fit. You > know more about this than I do. I'm running Windows 7 right now and I > have a Python 3.2 interpreter window open if you want me to test/confirm > something. :-) (Sorry; just got back to this this morning). I might raise this on python-dev. It seems to me that the docs for os.access: http://docs.python.org/library/os.html#os.access are already fairly involved. And we try not to make the official docs too confusing. That said, there's clearly an issue here, albeit one which doesn't raise its head too often. There's a case for re-assessing the patch I proposed in issue2528 to see whether to apply it appropriately (reworked). TJG From hg at schaathun.net Fri May 20 04:48:47 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Fri, 20 May 2011 09:48:47 +0100 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 20 May 2011 06:55:35 GMT, Steven D'Aprano wrote: : On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: : : > [I agree with you Xah that recursion is a technical word that should not : > be foisted onto lay users.] : : I think that is a patronizing remark that under-estimates the : intelligence of lay people and over-estimates the difficulty of : understanding recursion. Could we then say that ?recursion is a technical word that should not /unnecessarily/ be foisted onto lay users?? -- :-- Hans Georg From mail at timgolden.me.uk Fri May 20 04:53:53 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 20 May 2011 09:53:53 +0100 Subject: os.access giving incorrect results on Windows In-Reply-To: <4DD624A2.2030503@timgolden.me.uk> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> <4DD572FB.2010809@timgolden.me.uk> <4DD575E1.9060801@gmail.com> <4DD578AF.3000001@timgolden.me.uk> <4DD5803A.4080208@gmail.com> <4DD624A2.2030503@timgolden.me.uk> Message-ID: <4DD62C21.5090304@timgolden.me.uk> On 20/05/2011 09:21, Tim Golden wrote: [... re os.access on Windows ...] > (Sorry; just got back to this this morning). I might raise this on > python-dev. If you want to follow, my post is here: http://mail.python.org/pipermail/python-dev/2011-May/111530.html TJG From hg at schaathun.net Fri May 20 04:54:46 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Fri, 20 May 2011 09:54:46 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 20 May 2011 07:04:27 GMT, Steven D'Aprano wrote: : On Fri, 20 May 2011 05:48:50 +0100, Hans Georg Schaathun wrote: : : > Either way, the assumption that your system will not be handled by : > idiots is only reasonable if you yourself is the only user. : : Nonsense. How do you (generic "you", not any specific person) know that : you are not an idiot? You don't, but if you are, you cannot trust any of the other assumptions either, and making this assumption is reasonable by being less of a leap than anything else you have done. -- :-- Hans Georg From antti.ylikoski at tkk.fi Fri May 20 05:00:33 2011 From: antti.ylikoski at tkk.fi (Antti J Ylikoski) Date: Fri, 20 May 2011 12:00:33 +0300 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <87pqnemcj4.fsf@kuiper.lan.informatimago.com> References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <8762p7omzu.fsf@kuiper.lan.informatimago.com> <87pqnemcj4.fsf@kuiper.lan.informatimago.com> Message-ID: On 20.5.2011 3:38, Pascal J. Bourguignon wrote: > tar at sevak.isi.edu (Thomas A. Russ) writes: > >> "Pascal J. Bourguignon" writes: >> >>> tar at sevak.isi.edu (Thomas A. Russ) writes: >>>> >>>> This will only work if there is a backpointer to the parent. >>> >>> No, you don't need backpointers; some cases have been mentionned in the >>> other answer, but in general: >>> >>> (defun parent (tree node) >>> (if (member node (children tree)) >>> tree >>> (some (lambda (child) (parent child node)) (children tree)))) >>> >>> Yes, the question wasn't about time complexity. >> >> :-p >> >> Um, this is a recursive function. Inside PARENT, there is another call >> to PARENT. > > Feel free to derecursive it. > In the general case, to derecursive a function necessitates programming a stack, among other things............. Antti "Andy" Ylikoski From discmagnet at gmail.com Fri May 20 05:19:04 2011 From: discmagnet at gmail.com (Disc Magnet) Date: Fri, 20 May 2011 14:49:04 +0530 Subject: obviscating python code for distribution In-Reply-To: <4DD09BD5.9070405@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4DD09BD5.9070405@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 9:06 AM, Littlefield, Tyler wrote: > I'm putting lots of work into this. I would rather not have some script > kiddy dig through it, yank out chunks and do whatever he wants. I just want > to distribute the program as-is, not distribute it and leave it open to > being hacked. Obfuscating the code won't help here. Remember, "the enemy knows the system." From andreas.tawn at ubisoft.com Fri May 20 05:21:20 2011 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 20 May 2011 11:21:20 +0200 Subject: starting a separate thread in maya In-Reply-To: References: Message-ID: <654D9D97DA51AD479973BC2D5578603C0BEAB0FFEF@PDC-MAIL-CMS01.ubisoft.org> > Hi, > I'm using python2.5 in maya 2009 x64 (in linux). For Maya/Python stuff you'll probably have more success at http://www.tech-artists.org/ Cheers, Drea From jack.krieger at gmail.com Fri May 20 05:54:43 2011 From: jack.krieger at gmail.com (Jack Krieger) Date: Fri, 20 May 2011 02:54:43 -0700 (PDT) Subject: turn monitor off and on In-Reply-To: Message-ID: <0e005ec6-bf18-457b-9f39-fdbc56f37dfa@glegroupsg2000goo.googlegroups.com> > def turnOffMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) This code does not return control to you, so programm still locked. In my opinion it due broadcasting message. But I do not know how to send message to monitor directly. From jack.krieger at gmail.com Fri May 20 05:54:43 2011 From: jack.krieger at gmail.com (Jack Krieger) Date: Fri, 20 May 2011 02:54:43 -0700 (PDT) Subject: turn monitor off and on In-Reply-To: Message-ID: <0e005ec6-bf18-457b-9f39-fdbc56f37dfa@glegroupsg2000goo.googlegroups.com> > def turnOffMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) This code does not return control to you, so programm still locked. In my opinion it due broadcasting message. But I do not know how to send message to monitor directly. From LeotisBuchanan at exterbox.com Fri May 20 06:37:31 2011 From: LeotisBuchanan at exterbox.com (Leotis buchanan) Date: Fri, 20 May 2011 05:37:31 -0500 Subject: turn monitor off and on In-Reply-To: References: Message-ID: @Astan If you really want to turn your monitor on and off, you should probably try pyserial are pyparrallel(http://pyserial.sourceforge.net/pyparallel.html), along with a solid state relay. That worked for me on linux not sure about windowXP,but it should work. On Sat, May 14, 2011 at 1:08 AM, Astan Chee wrote: > Hi, > I'm trying to turn off my monitor, pause and then turn it on again. > I'm doing this in python 2.6 and windows xp. Here is my script so far > (that doesn't work): > > import time > import win32gui > import win32con > import win32api > > def turnOffMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) > > def turnOnMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > if __name__ == "__main__": > turnOffMonitor() > time.sleep(5) > turnOnMonitor() > > For some reason, the script doesn't turn the monitor back on. What am > I doing wrong here or are there any other alternative? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards Leotis Buchanan -------------- next part -------------- An HTML attachment was scrubbed... URL: From sigmundv at gmail.com Fri May 20 06:53:34 2011 From: sigmundv at gmail.com (SigmundV) Date: Fri, 20 May 2011 03:53:34 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6826bb7e-67e1-4b22-ba4c-a20216a271a7@h9g2000yqk.googlegroups.com> There is a nice matrix representation of consecutive Fibonacci numbers: [[1, 1], [1, 0]] ** n = [[F_n+1, F_n], [F_n, F_n-1]]. Using the third party mpmath module, which uses arbitrary precision floating point arithmetic, we can calculate the n'th Fibonacci number for an arbitrary n as follows: import mpmath A = mpmath.matrix([[1, 1], [1, 0]]) F = A ** n The n'th Fibonacci number is then found as the elements [0, 1] and [1, 0] in the matrix F. This is more expensive than the formula involving the golden ratio, but I like the compact representation. From ayaskanta.swain at altair.com Fri May 20 07:26:19 2011 From: ayaskanta.swain at altair.com (Ayaskanta Swain) Date: Fri, 20 May 2011 16:56:19 +0530 Subject: os.access giving incorrect results on Windows Message-ID: <21581D39FA3BDF40904D75AF9653CE26065680B9@blrex.prog.altair.com> Hi Tim, Thanks for the reply and suggestions. I followed the patch provided by you in issue 2528, but the code looks very tricky to me. Anyways I wrote my Test.py script & tried only the def test_access_w(self): test case which is defined under class FileTests(unittest.TestCase) by providing my own directory path to check the write permissions on it. I executed my But it failed with the following errors - > python Test.py C:\temp\my_dir test_access_w (__main__.FileTests) ... ERROR ====================================================================== ERROR: test_access_w (__main__.FileTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "Test.py", line 14, in test_access_w f = os.open(dirpath, os.O_CREAT) OSError: [Errno 13] Permission denied: 'C:\\temp\\my_dir' ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (errors=1) Basically the os.open() function is failing to open a directory (In this case my_dir). The directory has write permissions for the user. Attached herewith is my Test script. Can you please suggest some simple python code which checks the write permissions of a directory in a straight forward way (Not by using unit tests) Thanks Ayaskant- Bangalore -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Test.py Type: application/octet-stream Size: 1577 bytes Desc: Test.py URL: From erichcart at gmail.com Fri May 20 07:37:21 2011 From: erichcart at gmail.com (ErichCart ErichCart) Date: Fri, 20 May 2011 04:37:21 -0700 (PDT) Subject: Python sets which support multiple same elements Message-ID: Many times when I am writing some program in python, I notice that I could transform my list into set, then use the set methods like union, intersection, set equality etc. , and it will solve my problem easily. But then I realize that if I transform my list into set, it will remove duplicates of elements in the list and so I will lose information from my original list. For example, I was writing a program to detect whether two strings are anagrams of each other. I had to write it like this: def isAnagram(w1, w2): w2=list(w2) for c in w1: if c not in w2: return False else: w2.remove(c) return True But if there was a data structure in python which supported duplicate elements(lets call it dset), then I could just write: def inAnagram(w1,w2): return dset(w1)==dset(w2) Example of some dset methods: {1,2,3,3} intersection {4,1,2,3,3,3} == {1,2,3,3} {1,2,3,3} union {4,1,2,3,3,3} == {1,2,3,3,3,4} {4,1,2,3,3,3} difference {1,2,3,3} == {4,3} Do you think that it would be a good idea to add this kind of data structure to python? Or did I overlook some other easy way to solve this kind of problems? From shunichi_wakabayashi at yahoo.co.jp Fri May 20 07:49:31 2011 From: shunichi_wakabayashi at yahoo.co.jp (Shunichi Wakabayashi) Date: Fri, 20 May 2011 04:49:31 -0700 (PDT) Subject: Python sets which support multiple same elements In-Reply-To: Message-ID: > Many times when I am writing some program in python, I notice that I > could transform my list into set, then use the set methods like union, > intersection, set equality etc. , and it will solve my problem easily. > But then I realize that if I transform my list into set, it will > remove duplicates of elements in the list and so I will lose > information from my original list. > > For example, I was writing a program to detect whether two strings are > anagrams of each other. I had to write it like this: > > def isAnagram(w1, w2): > w2=list(w2) > for c in w1: > if c not in w2: > return False > else: > w2.remove(c) > return True > > But if there was a data structure in python which supported duplicate > elements(lets call it dset), then I could just write: > > def inAnagram(w1,w2): > return dset(w1)==dset(w2) > > Example of some dset methods: > {1,2,3,3} intersection {4,1,2,3,3,3} == {1,2,3,3} > {1,2,3,3} union {4,1,2,3,3,3} == {1,2,3,3,3,4} > {4,1,2,3,3,3} difference {1,2,3,3} == {4,3} > > Do you think that it would be a good idea to add this kind of data > structure to python? Or did I overlook some other easy way to solve > this kind of problems? I think collections.Counter object may be useful for your purpose. http://docs.python.org/py3k/library/collections.html#collections.Counter From andreas.tawn at ubisoft.com Fri May 20 07:53:55 2011 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 20 May 2011 13:53:55 +0200 Subject: Python sets which support multiple same elements In-Reply-To: References: Message-ID: <654D9D97DA51AD479973BC2D5578603C0BEAB10101@PDC-MAIL-CMS01.ubisoft.org> > For example, I was writing a program to detect whether two strings are > anagrams of each other. I had to write it like this: > > def isAnagram(w1, w2): > w2=list(w2) > for c in w1: > if c not in w2: > return False > else: > w2.remove(c) > return True > > But if there was a data structure in python which supported duplicate > elements(lets call it dset), then I could just write: > > def inAnagram(w1,w2): > return dset(w1)==dset(w2) > > Example of some dset methods: > {1,2,3,3} intersection {4,1,2,3,3,3} == {1,2,3,3} > {1,2,3,3} union {4,1,2,3,3,3} == {1,2,3,3,3,4} > {4,1,2,3,3,3} difference {1,2,3,3} == {4,3} > > Do you think that it would be a good idea to add this kind of data > structure to python? Or did I overlook some other easy way to solve > this kind of problems? Just to do the anagram problem you could do... def isAnagram(w1, w2): return sorted(w1) == sorted(w2) To do the set-like operations, I guess that unless there's some itertools witchcraft available, you'd have to make your own dset type that inherits from list. Then you can define your own intersection/union etc. methods. Cheers, Drea From rosuav at gmail.com Fri May 20 07:57:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 21:57:44 +1000 Subject: Python sets which support multiple same elements In-Reply-To: References: Message-ID: On Fri, May 20, 2011 at 9:37 PM, ErichCart ErichCart wrote: > For example, I was writing a program to detect whether two strings are > anagrams of each other. I had to write it like this: > > def isAnagram(w1, w2): > ?w2=list(w2) > ?for c in w1: > ? ?if c not in w2: > ? ? ?return False > ? ?else: > ? ? ?w2.remove(c) > ?return True You may find it helpful to simply sort the lists, keeping them as lists. If they're anagrams of each other, their sorted versions will be equal. Chris Angelico From erichcart at gmail.com Fri May 20 08:10:29 2011 From: erichcart at gmail.com (ErichCart ErichCart) Date: Fri, 20 May 2011 05:10:29 -0700 (PDT) Subject: Python sets which support multiple same elements References: Message-ID: <174adc6b-64b3-4b50-94fd-142570caba01@q12g2000prb.googlegroups.com> I see! How could I overlook sorting )) It seems that collections.Counter is what I was talking about. It seems to support all the set operations. Also I realized that the data structure which i was describing is called miltiset, and collections.Counter is python implementation of multiset. From nobody at nowhere.net.no Fri May 20 11:19:38 2011 From: nobody at nowhere.net.no (TheSaint) Date: Fri, 20 May 2011 23:19:38 +0800 Subject: how to get PID from subprocess library References: Message-ID: Miki Tebeka wrote: > The best module for doing such things is subprocess. And the Popen object > has a pid attribute I knew that, it's my fault that I'm not good to manage with popen. I found simplier to use subprocess.getstatusoutput. Maybe this function doesn't return the child pid, so I should adopt to work with Popen :( -- goto /dev/null From python at mrabarnett.plus.com Fri May 20 11:50:02 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 20 May 2011 16:50:02 +0100 Subject: hash values and equality In-Reply-To: <0deha8-6u9.ln1@satorlaser.homedns.org> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> Message-ID: <4DD68DAA.9050209@mrabarnett.plus.com> On 20/05/2011 07:33, Ulrich Eckhardt wrote: > Ethan Furman wrote: >> Several folk have said that objects that compare equal must hash equal, >> and the docs also state this >> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >> >> I'm hoping somebody can tell me what horrible thing will happen if this >> isn't the case? > > If you were familiar with what a hash map is, you wouldn't ask. The thing is > that the hash is used to look up the place in the map where the thing is > stored. If two equal objects have different hashes, they will be stored in > different places in the hash map. [snip] Is this strictly true? I thought that the hash value, an integer, is moduloed (Is that how you spell it? Looks weird!) with the number of array elements to give an index into the array, so different hashes could give the same index, and objects with different hashes could be stored in the same 'bucket'. From rosuav at gmail.com Fri May 20 12:20:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 May 2011 02:20:04 +1000 Subject: hash values and equality In-Reply-To: <4DD68DAA.9050209@mrabarnett.plus.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: On Sat, May 21, 2011 at 1:50 AM, MRAB wrote: > [snip] > Is this strictly true? I thought that the hash value, an integer, is > moduloed (Is that how you spell it? Looks weird!) with the number of > array elements to give an index into the array, so different hashes > could give the same index, and objects with different hashes could be > stored in the same 'bucket'. There can always be hash collisions between different objects, but the assumption is that two identical objects will _always_ "collide". Chris Angelico From debatem1 at gmail.com Fri May 20 12:26:28 2011 From: debatem1 at gmail.com (geremy condra) Date: Fri, 20 May 2011 09:26:28 -0700 Subject: obviscating python code for distribution In-Reply-To: <4dd613f5$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd613f5$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 12:10 AM, Steven D'Aprano wrote: > On Thu, 19 May 2011 17:56:12 -0700, geremy condra wrote: > >> TL;DR version: large systems have indeed been verified for their >> security properties. > > How confident are we that the verification software is sufficiently bug- > free that we should trust their results? Pretty confident. Most formal verification systems are developed in terms of a provably correct kernel bootstrapping the larger system. The important thing is that since that kernel doesn't need to be complete (only correct) it can typically be easily verified, and in some cases exhaustively tested. There are also techniques which generate certificates of correctness for verifiers that aren't provably correct, but that isn't an area I know much about, and I don't know if that gets used in practice. The bigger risk is really that the model you're feeding it is wrong. > How confident are we that the verification software tests every possible > vulnerability, as opposed to merely every imaginable one? Formal provers typically don't work by just throwing a bunch of input at a piece of software and then certifying it. They take a set of specifications (the model), a set of assumptions, and the program in question, and provide a proof (in the mathematical sense) that the program is exactly equivalent to the model given the assumptions. Testing the assumptions and model are typically part of the development process, though, and that's definitely a possible source of errors. Geremy Condra From ckaynor at zindagigames.com Fri May 20 12:36:00 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 20 May 2011 09:36:00 -0700 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: On Fri, May 20, 2011 at 9:20 AM, Chris Angelico wrote: > On Sat, May 21, 2011 at 1:50 AM, MRAB wrote: > > [snip] > > Is this strictly true? I thought that the hash value, an integer, is > > moduloed (Is that how you spell it? Looks weird!) with the number of > > array elements to give an index into the array, so different hashes > > could give the same index, and objects with different hashes could be > > stored in the same 'bucket'. > > There can always be hash collisions between different objects, but the > assumption is that two identical objects will _always_ "collide". I think the question was: can this dummy code ever produce a set containing less then itemCount items (for 0 < itemCount < 2**32)? itemCount = 100 import itertools counter = itertools.count().next class Test(object): def __init__(self): self.hash = counter() def __hash__(self): return self.hash def __eq__(self, other): return True set((Test() for i in xrange(itemCount))) > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From beliavsky at aol.com Fri May 20 12:39:51 2011 From: beliavsky at aol.com (Beliavsky) Date: Fri, 20 May 2011 09:39:51 -0700 (PDT) Subject: Why did Quora choose Python for its development? Message-ID: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> I thought this essay on why one startup chose Python was interesting. http://www.quora.com/Why-did-Quora-choose-Python-for-its-development PHP was out of the question. Facebook is stuck on that for legacy reasons, not because it's the best choice right now.[1] Our main takeaway from that experience is that programming language choice is very important and is extremely costly to change. Python was a language that Charlie and I both knew reasonably well (though I know it a lot better now than I did when we started). We also briefly considered C#, Java, and Scala. The biggest issues with Python are speed and the lack of typechecking. C# seemed pretty promising. As a programming language, it's great, but: ?We didn't want to be on the Microsoft stack. We were up for learning something new, and MS SQL Server actually seemed pretty good, but we knew we'd need to integrate with lots of open source code that has only second-class support for .NET, if it supports it at all. Also, most of the best engineers these days are used to open source stuff. ?We didn't want to take the risk of being on Mono (an open source implementation of C#/.NET). It's not clear how long funding will be around for that project, and I'd heard of various performance problems. Plus, it seemed like everything else in the C# ecosystem would assume we were on the Microsoft stack. For a lot of little reasons, Java programs end up being longer and more painful to write than the equivalent Python programs. It's also harder to interoperate with non-Java stuff. Scala had a lot of the downsides of Java and the JVM, although it wasn't quite as bad. The language seemed a little too new and like it would bring some unnecessary risk (for example, who knows how good will support be in 10 years). Two other languages we very briefly thought about were OCaml and Haskell (neither had big enough ecosystems or good enough standard libraries, and both were potentially too hard for some designers/data analysts/non-engineers who might need to write code). We decided that Python was fast enough for most of what we need to do (since we push our performance-critical code to backend servers written in C++ whenever possible). As far as typechecking, we ended up writing very thorough unit tests which are worth writing anyway, and achieve most of the same goals. We also had a lot of confidence that Python would continue to evolve in a direction that would be good for the life of our codebase, having watched it evolve over the last 5 years. So far, we've been pretty happy with the choice. There's a small selection bias, but all of the employees who'd been working with other languages in the past have been happy to transition to Python, especially those coming from PHP. Since starting the following things have happened: ?Python 2.6 got to the point where enough of the libraries we used were compatible with it, and we made a very easy transition to it. ?Tornado (web framework) was released as open source, and we moved our live updating web service to that. ?PyPy got to the point where it looks like it will eventually be usable and will give us a significant speedup. All together, these give us confidence that the language and ecosystem is moving in a good direction. [1] What are the horrors of PHP? and Do Facebook engineers enjoy programming in PHP? and Why hasn't Facebook migrated away from PHP? and What are some of the advantages of PHP over other programming languages? for more on that. Via Nizameddin Ha?im Ordulu and JR Ignacio. From steve+comp.lang.python at pearwood.info Fri May 20 13:07:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2011 17:07:25 GMT Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dd69fcd$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 May 2011 16:54:06 +1000, Chris Angelico wrote: > If someone has time to kill (as if!), it'd be awesome to get a new > numeric type that uses bc's code; any other numeric type (int, long, > float) could autopromote to it, removing the dilemma of which to promote > out of long and float. Hmm... Python 4.0, 'bc' is the new default > integer and everything else is a performance optimization? Heh. The problem is, it isn't *just* a performance optimization, there is a semantic difference too. Consider: >>> x = 1e-300 >>> x*x == 0 True But using something with more precision: >>> from fractions import Fraction >>> x = Fraction(10)**-300 >>> x*x == 0 False So you get different behaviour between floats and arbitrary precision numbers. -- Steven From rustompmody at gmail.com Fri May 20 13:21:11 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 20 May 2011 10:21:11 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6c3af321-599c-4ee0-8da6-cf47af0728ed@z13g2000prk.googlegroups.com> On May 20, 1:48?pm, Hans Georg Schaathun wrote: > On 20 May 2011 06:55:35 GMT, Steven D'Aprano? wrote: > > : ?On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: > : > : > [I agree with you Xah that recursion is a technical word that should not > : > be foisted onto lay users.] > : > : ?I think that is a patronizing remark that under-estimates the > : ?intelligence of lay people and over-estimates the difficulty of > : ?understanding recursion. > > Could we then say that ?recursion is a technical word that should > not /unnecessarily/ be foisted onto lay users?? Yes. Steven is talking about the fact that the intelligent lay user may be intelligent. I was referring to the fact that the intelligent lay user is a lay user. [Not my main point except to say that dragging in alt.usage.english into a discussion of recursion seemed a tad unnecessary and unfair] So the ILU may understand recursion He may not know "recursion" From nobody at nowhere.com Fri May 20 13:48:10 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 20 May 2011 18:48:10 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd613f5$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 20 May 2011 07:10:45 +0000, Steven D'Aprano wrote: > How confident are we that the verification software tests every possible > vulnerability, Formal verification is based upon mathematical proof, not empirical results. As Dijkstra said: "Program testing can be used to show the presence of bugs, but never to show their absence". For complex algorithms, it may be infeasible to cover even all of the "interesting" cases, let alone a representative sample of all possible cases. For concurrent (multi-threaded) code, it's often impractical to methodically test various interleavings. From ethan at stoneleaf.us Fri May 20 13:56:02 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 May 2011 10:56:02 -0700 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD5FF8F.604@stoneleaf.us> Message-ID: <4DD6AB32.7030306@stoneleaf.us> Chris Rebert wrote: > On Thu, May 19, 2011 at 10:43 PM, Ethan Furman wrote: >> Several folk have said that objects that compare equal must hash equal, and >> the docs also state this >> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >> >> I'm hoping somebody can tell me what horrible thing will happen if this >> isn't the case? Here's a toy example of a class I'm thinking of writing >> that will compare equal with int's, but hash differently: > > This is the part considered "horrible": >> --> d >> {: '3', >> 1: '1.0', >> 2: '2.0', >> 3: '3.0', >> : '2', >> : '1'} > > Compare: >>>> x = {5.0 : 'foo'} >>>> x[5] > 'foo' > > Here's a more common/plausible "horrible" case closer to what the docs > writers had in mind: >--> class Naughty(object): > ... def __init__(self, n): > ... self.n = n > ... def __eq__(self, other): > ... return self.n == other.n > ... >--> Naughty(5) == Naughty(5) > True >--> Naughty(5) is Naughty(5) > False >--> bad = Naughty(3) >--> y = {bad : 'foo'} >--> y[bad] # just happens to work > 'foo' >--> del bad >--> # ok, how do we get to 'foo' now? >--> y[Naughty(3)] # try the obvious way > Traceback (most recent call last): > File "", line 1, in > KeyError: <__main__.Naughty object at 0x2a1cb0> >--> # We're screwed. > > Naughty instances (and similar) can't be used sensibly as hash keys > (unless you /only/ care about object identity; this is often not the > case). I tried this sequence (using Python 3, BTW -- forgot to mention that little tidbit -- sorry!): --> del two --> two Traceback (most recent call last): File "", line 1, in NameError: name 'two' is not defined --> d {<__main__.Wierd object at 0x00C0C950>: '3', 1: '1.0', 2: '2.0', 3: '3.0', <__main__.Wierd object at 0x00B3AC10>: '2', <__main__.Wierd object at 0x00B32E90>: '1'} --> new_two = Wierd(2) --> d[new_two] '2' ~Ethan~ From bahamutzero8825 at gmail.com Fri May 20 13:56:45 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 20 May 2011 12:56:45 -0500 Subject: List of WindowsError error codes and meanings Message-ID: <4DD6AB5D.1040707@gmail.com> This is probably somewhat off-topic, but where would I find a list of what each error code in WindowsError means? WindowsError is so broad that it could be difficult to decide what to do in an except clause. Fortunately, sys.exc_info()[1][0] holds the specific error code, so I could put in an if...elif...else clause inside the except clause if I needed to, but I don't know what all the different errors are. From ethan at stoneleaf.us Fri May 20 13:57:42 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 May 2011 10:57:42 -0700 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> Message-ID: <4DD6AB96.2040307@stoneleaf.us> Peter Otten wrote: > Ethan Furman wrote: > >> Several folk have said that objects that compare equal must hash equal, >> and the docs also state this >> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >> >> I'm hoping somebody can tell me what horrible thing will happen if this >> isn't the case? Here's a toy example of a class I'm thinking of writing >> that will compare equal with int's, but hash differently: >> >> --> class Wierd(): >> ... def __init__(self, value): >> ... self.value = value >> ... def __eq__(self, other): >> ... return self.value == other >> ... def __hash__(self): >> ... return hash((self.value + 13) ** 3) >> ... > > Try this: > >>>> d = {Wierd(1): 0} >>>> 1 in d > False >>>> 1 in d.keys() > True > My apologies -- I'm trying this in Python3: --> two in d True --> two in d.keys() True --> --> 2 in d True --> 2 in d.keys() True ~Ethan~ From ian.g.kelly at gmail.com Fri May 20 13:59:44 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 11:59:44 -0600 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: On Fri, May 20, 2011 at 10:36 AM, Chris Kaynor wrote: > I think the question was: can this dummy code ever produce a set containing > less then itemCount items (for 0 < itemCount < 2**32)? In CPython, no. Even when you get a hash collision, the code checks to see whether the hashes are actually equal before it calls the rich comparison, the former check being a much faster operation since the hash values are cached. I'm not sure whether this can be counted on for all Python implementations, though. From gsowww at yahoo.co.uk Fri May 20 14:03:09 2011 From: gsowww at yahoo.co.uk (GSO) Date: Fri, 20 May 2011 19:03:09 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <6c3af321-599c-4ee0-8da6-cf47af0728ed@z13g2000prk.googlegroups.com> References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <6c3af321-599c-4ee0-8da6-cf47af0728ed@z13g2000prk.googlegroups.com> Message-ID: On 20 May 2011 18:21, rusi wrote: > On May 20, 1:48 pm, Hans Georg Schaathun wrote: > > On 20 May 2011 06:55:35 GMT, Steven D'Aprano < > steve+comp.lang.pyt... at pearwood.info> wrote: > > > > : On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: > > : > > : > [I agree with you Xah that recursion is a technical word that should > not > > : > be foisted onto lay users.] > > : > > : I think that is a patronizing remark that under-estimates the > > : intelligence of lay people and over-estimates the difficulty of > > : understanding recursion. > > > > Could we then say that ?recursion is a technical word that should > > not /unnecessarily/ be foisted onto lay users?? > > Yes. > Steven is talking about the fact that the intelligent lay user may be > intelligent. > I was referring to the fact that the intelligent lay user is a lay > user. [Not my main point except to say that dragging in > alt.usage.english into a discussion of recursion seemed a tad > unnecessary and unfair] > > So the ILU may understand recursion > He may not know "recursion" > -- > > As a trainer there is an issue as to whether or not you should use words that your trainees will not understand, the argument being that if you don't use new words your trainees will not learn any new words. It is also very much a Unix philosophy that if you want idiots, feed them idiot food, so think very carefully about what you put on the menu. I think recursion was very much a list processing concept for list processing languages. I like the purity of LISP, but COBOL for business applications any day. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at mellowood.ca Fri May 20 14:03:16 2011 From: bob at mellowood.ca (bvdp) Date: Fri, 20 May 2011 11:03:16 -0700 (PDT) Subject: TK program problem Message-ID: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> I've just done an update to my system here to Ubuntu 11.04. Mostly no problems ... but I have an important (to me) python/TK program that's stopped working. Well, it works ... mostly. The python version is 2.7.1+ (no idea what the + means!). I _think_ I have traced the problem to certain menus which call a class. The calls appear to be ignored. Basically, what I have is a line like: bf = makeButtonBar(root, row=0, column=0, buttons=( ("Quit", self.quitall ), ("Stop", self.stopPmidi ), ("New Dir", self.chd), ("Load Playlist", self.playList), ("Favorites", selectFav), ("Options", setOptions) ) ) To create a menu bar. The function makeButtonBar() creates the buttons with: for txt, cmd in buttons: Button(bf, text=txt, height=1, command=cmd).grid(column=c, row=0, pady=5) All this is fine (and worked perfectly before my upgrade). The menu items which are ordinary functions continue to work. BUT the callbacks which are classes are just ignored when they are clicked. A cut from one of the ignored classes: class selectFav: def __init__(self): ... And I've inserted some prints in the __init__() and nothing is printed. Also, converted the class to new-style () but no change there either. Either python/tk has changed or my system is totally $*(#*#. Suggestions welcome! From stef.mientki at gmail.com Fri May 20 14:27:56 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 20 May 2011 20:27:56 +0200 Subject: maybe useful : datetime conversion Message-ID: <4DD6B2AC.10704@gmail.com> hello, using datetimes from a lot of different sources, in many languages, I had about 30 python helper routines, which I now packed in one class, much simpler. Although I used the Delphi date-format as the base, it shouldn't be difficult to rewrite the class for another type. The input can be one of the following types : - None : the current date-time is used - 30000.9 : a Delphi datetime - 30000 : a Delphi datetime - "30000.9" : a Delphi datetime as a string - "30000,9" : a Delphi datetime as a (Dutch) string - "20-5-11" : short year notation - "20-05-2011" : long year notation - "2009-09-24 10:12:24" : Access string - datetime.datetime ( 2011, 1, 15 ) - time.struct_time - wx.DateTime - time.time() (through method from_time) Maybe someone can use it. cheers, Stef -------------- next part -------------- A non-text attachment was scrubbed... Name: module1.py Type: text/x-python Size: 4880 bytes Desc: not available URL: From ethan at stoneleaf.us Fri May 20 14:38:41 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 May 2011 11:38:41 -0700 Subject: hash values and equality In-Reply-To: <0deha8-6u9.ln1@satorlaser.homedns.org> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> Message-ID: <4DD6B531.3080300@stoneleaf.us> Ulrich Eckhardt wrote: > Ethan Furman wrote: >> Several folk have said that objects that compare equal must hash equal, >> and the docs also state this >> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >> >> I'm hoping somebody can tell me what horrible thing will happen if this >> isn't the case? > > If you were familiar with what a hash map is, you wouldn't ask. The thing is > that the hash is used to look up the place in the map where the thing is > stored. If two equal objects have different hashes, they will be stored in > different places in the hash map. Looking for object1 will then not turn up > with object2, even though they are equal. In this case this is the behavior I want. > If this is something you don't > care about, and all you care about is identity, then I'd derive the hash > from each object's ID. This won't work, as objects of the same type that compare equal should (and do, in my code) hash equal. > This ID has another property which is something that is assumed for hashes, > and your code seems a bit to get that wrong, too, and that is that the hash > must not change. The hash does not change on the instances, and is the same for all instances of my type that compare equal. ~Ethan~ From debatem1 at gmail.com Fri May 20 14:43:43 2011 From: debatem1 at gmail.com (geremy condra) Date: Fri, 20 May 2011 11:43:43 -0700 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd69fcd$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd69fcd$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 10:07 AM, Steven D'Aprano wrote: > On Fri, 20 May 2011 16:54:06 +1000, Chris Angelico wrote: > >> If someone has time to kill (as if!), it'd be awesome to get a new >> numeric type that uses bc's code; any other numeric type (int, long, >> float) could autopromote to it, removing the dilemma of which to promote >> out of long and float. Hmm... Python 4.0, 'bc' is the new default >> integer and everything else is a performance optimization? Heh. > > The problem is, it isn't *just* a performance optimization, there is a > semantic difference too. Consider: > >>>> x = 1e-300 >>>> x*x == 0 > True > > But using something with more precision: > >>>> from fractions import Fraction >>>> x = Fraction(10)**-300 >>>> x*x == 0 > False > > > So you get different behaviour between floats and arbitrary precision > numbers. And this shows up in the above implementation; reimplementing it using Fractions and a truncated continuing fraction approximation of phi and the square root of 5 gets us up to about 500, at the cost of a very long computation time. Geremy Condra From ethan at stoneleaf.us Fri May 20 14:46:08 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 May 2011 11:46:08 -0700 Subject: hash values and equality In-Reply-To: <4DD5FF8F.604@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD5FF8F.604@stoneleaf.us> Message-ID: <4DD6B6F0.8050700@stoneleaf.us> Ethan Furman wrote: > Several folk have said that objects that compare equal must hash equal, > and the docs also state this > http://docs.python.org/dev/reference/datamodel.html#object.__hash__ Two things I didn't make clear originally: I'm using Python3. My objects (of type Wierd) obey the premise of comparing equal also meaning hashing equal (with other objects of type Wierd). Perhaps my question could be narrowed down to: Should the docs actually say that "objects of the same *type* that compare equal must hash equal", or is there an underlying reason that objects of *different types* that happen to compare equal *must not* have different hashes? In other words, is the fact that everything tried so far in Python3 to break my toy code has failed to do so just an implementation detail of Python3? ~Ethan~ From clp2 at rebertia.com Fri May 20 15:00:43 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 20 May 2011 12:00:43 -0700 Subject: hash values and equality In-Reply-To: <4DD6AB32.7030306@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD5FF8F.604@stoneleaf.us> <4DD6AB32.7030306@stoneleaf.us> Message-ID: On Fri, May 20, 2011 at 10:56 AM, Ethan Furman wrote: > Chris Rebert wrote: >> On Thu, May 19, 2011 at 10:43 PM, Ethan Furman wrote: >>> Several folk have said that objects that compare equal must hash equal, >>> and >>> the docs also state this >>> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >>> >>> I'm hoping somebody can tell me what horrible thing will happen if this >>> isn't the case? >> Here's a more common/plausible "horrible" case closer to what the docs >> writers had in mind: >> --> class Naughty(object): >> ... ? ? def __init__(self, n): >> ... ? ? ? ? self.n = n >> ... ? ? def __eq__(self, other): >> ... ? ? ? ? return self.n == other.n >> ... >> --> Naughty(5) == Naughty(5) >> True >> --> Naughty(5) is Naughty(5) >> False >> --> bad = Naughty(3) >> --> y = {bad : 'foo'} >> --> y[bad] # just happens to work >> 'foo' >> --> del bad >> --> # ok, how do we get to 'foo' now? >> --> y[Naughty(3)] # try the obvious way >> Traceback (most recent call last): >> ?File "", line 1, in >> KeyError: <__main__.Naughty object at 0x2a1cb0> >> --> # We're screwed. >> >> Naughty instances (and similar) can't be used sensibly as hash keys >> (unless you /only/ care about object identity; this is often not the >> case). > > I tried this sequence (using Python 3, BTW -- forgot to mention that little > tidbit -- sorry!): Doesn't matter anyway. > --> del two > --> two > Traceback (most recent call last): > ?File "", line 1, in > NameError: name 'two' is not defined > --> d > {<__main__.Wierd object at 0x00C0C950>: '3', > ?1: '1.0', > ?2: '2.0', > ?3: '3.0', > ?<__main__.Wierd object at 0x00B3AC10>: '2', > ?<__main__.Wierd object at 0x00B32E90>: '1'} > --> new_two = Wierd(2) > --> d[new_two] > '2' Right, this is why I went to the trouble of writing Naughty instead of using Wierd. Wierd's exact problem is less common and less severe. The "equality implies identical hash" rule is not a universal one; some other languages instead impose the lesser requirement of "equality and same (or related) types implies identical hash". In Ruby for instance: irb(main):001:0> 1 == 1.0 => true irb(main):002:0> a = {1.0 => 'hi'} # float key => {1.0=>"hi"} irb(main):003:0> a[1] = 'bye' # int key => "bye" irb(main):004:0> a # notice how they don't collide: => {1=>"bye", 1.0=>"hi"} (Contrast this with my earlier analogous Python example.) Basically, Naughty is fundamentally broken [hash(Naughty(2)) != hash(Naughty(2))], whereas Wierd merely defies convention [hash(2) != hash(Wierd(2)) but hash(Wierd(2)) == hash(Wierd(2))]. Cheers, Chris -- http://rebertia.com From lists at cheimes.de Fri May 20 15:01:22 2011 From: lists at cheimes.de (Christian Heimes) Date: Fri, 20 May 2011 21:01:22 +0200 Subject: hash values and equality In-Reply-To: <4DD68DAA.9050209@mrabarnett.plus.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: Am 20.05.2011 17:50, schrieb MRAB: > Is this strictly true? I thought that the hash value, an integer, is > moduloed (Is that how you spell it? Looks weird!) with the number of > array elements to give an index into the array, so different hashes > could give the same index, and objects with different hashes could be > stored in the same 'bucket'. I don't think 'moduloed' is an existing word but your description is mostly correct. The hash of the object and length of the hash table are used to calculate the position in the hash table. However Python's implementation doesn't use buckets to reduce memory usage and pointer dereferencing. If a slot in the hash table is already filled with an object that is not equal to the new object (a collision), the hash is shifted and the new slot is checked. The implementation detail is well described in Modules/dictobject.c. Christian From ericsnowcurrently at gmail.com Fri May 20 15:13:45 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 20 May 2011 13:13:45 -0600 Subject: ABC validation strictly on an instance Message-ID: The current ABC implementation in Python implies that the class of a conformant instance complies with the ABC. The implication does not carry down to the compliance of the instance itself. This means that if you inherit from an ABC that has an abstract property, your subclass must have a matching name to that property, or you will get a TypeError. (Same goes for abstract methods--a matching name must be bound, even if not to a function). For example: class X(metaclass=ABCMeta): @abstractproperty def id(self): pass class Y(X): id = 1 class Z(X): def __init__(self, id): self._id = id @property def id(self): return self._id class Fail(X): def __init__(self, id): self.id = id So classes Y and Z will work fine, but class Fail will raise a TypeError when you instantiate [1] Fail, even though it "implemented" id in the instance __init__ [2]. I looked at this all yesterday and did not see a great way to approach this. The best I could come up with was the following: class X(metaclass=ABCMeta): @abstractproperty def id(self): pass @X.register class Y: def __init__(self, id): self.id = id So this is a promise that Y comforms to X without any of the automatic validation. However, you don't get _any_ validation. You also lose any otherwise inherited features, so it is more like an interface than an abstract class. I am not so sure about that above solution because it seems like such a loose constraint. I discussed the validation problem in another email [1]. I am not sure if there is a way to bake into Python an effective check that an instance (not the class of the instance) is compliant with an ABC. However, it would be cool if there was. The current checking mechanism for ABCs happens in object.__new__ at instantiation time. At that point it has no knowledge of what names your instance will have, other than those that come from the class. I spent a while looking at this whole problem yesterday and came up with a bunch of approaches for that Fail situation above. However, they mostly seem like overkill to me. I have included them below. If anyone has ideas on how to approach the problem of using an ABC but satisfying it with instance names, I would love to hear it. Thanks! -eric [1] In this case it would be nice to know at definition time that the class is missing the abstract "method". You don't want an exception at definition time for every subclass, though, since some you may want to keep abstract. I wrote up a decorator that allows you to validate at definition time in an email yesterday ( http://mail.python.org/pipermail/python-list/2011-May/1272541.html). [2] A related issue opened just yesterday: http://bugs.python.org/issue12128 ################################################################ 1 - properties, with a getter and setter. At definition time. This seems like overkill: class X(object): __metaclass__ = ABCMeta @abstractproperty def name(self): pass class Y(X): def __init__(self, name): self._name = name super(Y, self).__init__() @property def name(self): return self._name @name.setter def name(self, val): self._name = val 2 - getter/setter functions. At definition time. This does not guarantee the name, only access around it: class X(object): __metaclass__ = ABCMeta @abstractmethod def get_name(self): pass @abstractmethod def set_name(self): pass class Y(X): def __init__(self, name): self.name = name super(Y, self).__init__() def get_name(self): return self.name def set_name(self, val): self.name = val 3 - descriptors directly. At definition time. Like the properties example: class Name(object): def __get__(self, obj, cls): if obj is None: return self return obj._name def __set__(self, obj, val): obj._name = val class X(object) __metaclass__ = ABCMeta @abstractproperty def name(self): pass class Y(X): name = Name() def __init__(self, name): self.name = name super(Y, self).__init__() 4 - getattribute. At run time. More overkill: class Enforcer(object): API = () def __getattribute__(self, attr): if attr in API and attr not in dir(self): raise TypeError("Expected attribute: %s" % attr) return object.__getattribute__(self, attr) def __setattr(self, attr, val): if attr in API and attr not in dir(self): raise TypeError("Expected attribute: %s" % attr) object.__setattribute__(self, attr, val) class X(Enforcer): API = ("name",) class Y(X): def __init__(self, name): self.name = name super(Y, self).__init__() 5 - metaclass. At instantiation time. Overkill again: class Enforcer(object): class SomeMeta(type): def enforces_API(f): def __init__(self, *args, **kwargs): f(self, *args, **kwargs) for name in self.API: if name not in dir(self): raise TypeError("Expected attribute: %s" % attr) __init__.__doc__ = f.__doc__ return __init__ def __new__(self, name, bases, namespace): cls = super(SomeMeta, self).__new__(self, name, bases, namespace) __init__ = namespace.get("__init__") if not __init__: def __init__(self, *args, **kwargs): super(cls, self).__init__(*args, **kwargs) namespace["__init__"] = self.enforces_API(__init__) return cls API = () class X(Enforcer): API = ("name",) class Y(X): def __init__(self, name): self.name = name super(Y, self).__init__() 6 - decorator. At instantiation time. Apply to the __init__ of each class that must enforce the API or to the base __init__ and call super after the assignments... class Enforcer(object): API = () def enforces_API(f): def __init__(self, *args, **kwargs): f(self, *args, **kwargs) for name in self.API: if name not in dir(self): raise TypeError("Expected attribute: %s" % attr) __init__.__doc__ = f.__doc__ return __init__ class X(Enforcer): API = ("name",) class Y(X): @X.enforces_API def __init__(self, name): self.name = name super(Y, self).__init__() 7 - class decorator. At definition time. Apply to each class that must enforce the API... class Enforcer(object): API = () def enforces_API(cls): def __init__decorator(f): def __init__(self, *args, **kwargs): f(self, *args, **kwargs) for name in self.API: if name not in dir(self): raise TypeError("Expected attribute: %s" % attr) __init__.__doc__ = f.__doc__ return __init__ __init__ = cls__dict__.get("__init__") if not __init__: def __init__(self, *args, **kwargs): super(cls, self).__init__(*args, **kwargs) cls.__init__ = self.enforces_API(__init__) @Enforcer.enforces_API class X(Enforcer): API = ("name",) @Enforcer.enforces_API class Y(X): def __init__(self, name): self.name = name super(Y, self).__init__() -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri May 20 15:20:17 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 13:20:17 -0600 Subject: TK program problem In-Reply-To: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 12:03 PM, bvdp wrote: > All this is fine (and worked perfectly before my upgrade). The menu > items which are ordinary functions continue to work. BUT the callbacks > which are classes are just ignored when they are clicked. I'm not a tk user, but it sounds like it has regressed from accepting arbitrary callables as callbacks to accepting functions specifically. What happens if you replace: ("Favorites", selectFav), with: ("Favorites", lambda: selectFav()), From genstein at invalid.invalid Fri May 20 15:47:29 2011 From: genstein at invalid.invalid (Genstein) Date: Fri, 20 May 2011 20:47:29 +0100 Subject: List of WindowsError error codes and meanings In-Reply-To: References: Message-ID: On 20/05/2011 18:56, Andrew Berg wrote: > This is probably somewhat off-topic, but where would I find a list of > what each error code in WindowsError means? Assuming it's a Win32 error code, winerror.h from the Platform SDK holds the answer. One version is linked below, it's in theory out of date (2003) but all the best known codes are present. http://msdn.microsoft.com/en-us/library/ms819773.aspx http://msdn.microsoft.com/en-us/library/ms819775.aspx For example, "WindowsError [error 5] Access is denied" matches ERROR_ACCESS_DENIED (5L). HRESULTS may also crop up (e.g. E_FAIL, 0x80040005) which are harder to list exhaustively since subsystems and COM components may roll their own codes of various sorts; but common ones are present in winerror.h. All the best, -eg. From python at mrabarnett.plus.com Fri May 20 16:17:29 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 20 May 2011 21:17:29 +0100 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: <4DD6CC59.6070908@mrabarnett.plus.com> On 20/05/2011 20:01, Christian Heimes wrote: > Am 20.05.2011 17:50, schrieb MRAB: >> Is this strictly true? I thought that the hash value, an integer, is >> moduloed (Is that how you spell it? Looks weird!) with the number of >> array elements to give an index into the array, so different hashes >> could give the same index, and objects with different hashes could be >> stored in the same 'bucket'. > > I don't think 'moduloed' is an existing word but your description is > mostly correct. The hash of the object and length of the hash table are > used to calculate the position in the hash table. However Python's > implementation doesn't use buckets to reduce memory usage and pointer > dereferencing. If a slot in the hash table is already filled with an > object that is not equal to the new object (a collision), the hash is > shifted and the new slot is checked. The implementation detail is well > described in Modules/dictobject.c. > A brief search on the web found a use of the word in 1982. From mail at timgolden.me.uk Fri May 20 16:18:14 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 20 May 2011 21:18:14 +0100 Subject: List of WindowsError error codes and meanings In-Reply-To: <4DD6AB5D.1040707@gmail.com> References: <4DD6AB5D.1040707@gmail.com> Message-ID: <4DD6CC86.3090101@timgolden.me.uk> On 20/05/2011 18:56, Andrew Berg wrote: > This is probably somewhat off-topic, but where would I find a list of > what each error code in WindowsError means? WindowsError is so broad > that it could be difficult to decide what to do in an except clause. > Fortunately, sys.exc_info()[1][0] holds the specific error code, so I > could put in an if...elif...else clause inside the except clause if I > needed to, but I don't know what all the different errors are. Ultimately, only MSDN can tell you :) But to be going on with, a combination of Python's built-in errno module: http://docs.python.org/library/errno.html and the pywin32 package's winerror module: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/236b256c13bf/win32/Lib/winerror.py should help TJG From harrismh777 at charter.net Fri May 20 16:24:45 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 20 May 2011 15:24:45 -0500 Subject: obviscating python code for distribution In-Reply-To: <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Nonsense. How do you (generic "you", not any specific person) know that > you are not an idiot? lol Sum, ergo Idiot cogitat. Reminds me of a philosophical story I heard one time from my religion professor... ... as it goes, De Carte leads his horse into town ;-) and having hitched it to the rail outside the local saloon and sauntering up to the bar, the tender asks, "Would you be hav'in an ale sir?" ... De Carte replies, "I think not..." ... and then disappeared. :) From __peter__ at web.de Fri May 20 16:25:27 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 May 2011 22:25:27 +0200 Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD6AB96.2040307@stoneleaf.us> Message-ID: Ethan Furman wrote: > Peter Otten wrote: >> Ethan Furman wrote: >> >>> Several folk have said that objects that compare equal must hash equal, >>> and the docs also state this >>> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >>> >>> I'm hoping somebody can tell me what horrible thing will happen if this >>> isn't the case? Here's a toy example of a class I'm thinking of writing >>> that will compare equal with int's, but hash differently: >>> >>> --> class Wierd(): >>> ... def __init__(self, value): >>> ... self.value = value >>> ... def __eq__(self, other): >>> ... return self.value == other >>> ... def __hash__(self): >>> ... return hash((self.value + 13) ** 3) >>> ... >> >> Try this: >> >>>>> d = {Wierd(1): 0} >>>>> 1 in d >> False >>>>> 1 in d.keys() >> True >> > > My apologies -- I'm trying this in Python3: Then you have to convert the keys to a list explicitly: >>> class Weird: ... def __init__(self, value): ... self.value = value ... def __eq__(self, other): ... return self.value == other ... def __hash__(self): ... return hash((self.value + 13) **3) ... >>> d = {Weird(1): 0} >>> 1 in d False >>> 1 in d.keys() False >>> 1 in list(d.keys()) True From dotancohen at gmail.com Fri May 20 16:47:15 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 20 May 2011 23:47:15 +0300 Subject: Why did Quora choose Python for its development? In-Reply-To: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 19:39, Beliavsky wrote: > I thought this essay on why one startup chose Python was interesting. > > http://www.quora.com/Why-did-Quora-choose-Python-for-its-development > > PHP was out of the question. Facebook is stuck on that for legacy > reasons, not because it's the best choice right now.[1] Our main > takeaway from that experience is that programming language choice is > very important and is extremely costly to change. > > Python was a language that Charlie and I both knew reasonably well > (though I know it a lot better now than I did when we started). We > also briefly considered C#, Java, and Scala. The biggest issues with > Python are speed and the lack of typechecking. > > C# seemed pretty promising. As a programming language, it's great, > but: > > ?We didn't want to be on the Microsoft stack. We were up for learning > something new, and MS SQL Server actually seemed pretty good, but we > knew we'd need to integrate with lots of open source code that has > only second-class support for .NET, if it supports it at all. Also, > most of the best engineers these days are used to open source stuff. > ?We didn't want to take the risk of being on Mono (an open source > implementation of C#/.NET). It's not clear how long funding will be > around for that project, and I'd heard of various performance > problems. Plus, it seemed like everything else in the C# ecosystem > would assume we were on the Microsoft stack. > > For a lot of little reasons, Java programs end up being longer and > more painful to write than the equivalent Python programs. It's also > harder to interoperate with non-Java stuff. Scala had a lot of the > downsides of Java and the JVM, although it wasn't quite as bad. The > language seemed a little too new and like it would bring some > unnecessary risk (for example, who knows how good will support be in > 10 years). > > Two other languages we very briefly thought about were OCaml and > Haskell (neither had big enough ecosystems or good enough standard > libraries, and both were potentially too hard for some designers/data > analysts/non-engineers who might need to write code). > > We decided that Python was fast enough for most of what we need to do > (since we push our performance-critical code to backend servers > written in C++ whenever possible). As far as typechecking, we ended up > writing very thorough unit tests which are worth writing anyway, and > achieve most of the same goals. We also had a lot of confidence that > Python would continue to evolve in a direction that would be good for > the life of our codebase, having watched it evolve over the last 5 > years. > > So far, we've been pretty happy with the choice. There's a small > selection bias, but all of the employees who'd been working with other > languages in the past have been happy to transition to Python, > especially those coming from PHP. Since starting the following things > have happened: > > > ?Python 2.6 got to the point where enough of the libraries we used > were compatible with it, and we made a very easy transition to it. > ?Tornado (web framework) was released as open source, and we moved our > live updating web service to that. > ?PyPy got to the point where it looks like it will eventually be > usable and will give us a significant speedup. > > All together, these give us confidence that the language and ecosystem > is moving in a good direction. > > [1] What are the horrors of PHP? and Do Facebook engineers enjoy > programming in PHP? and Why hasn't Facebook migrated away from PHP? > and What are some of the advantages of PHP over other programming > languages? for more on that. > Via Nizameddin Ha?im Ordulu and JR Ignacio. > -- > http://mail.python.org/mailman/listinfo/python-list > They considered Haskell and OCaml and not a single mention of Perl? -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From albert at spenarnc.xs4all.nl Fri May 20 16:56:40 2011 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 20 May 2011 20:56:40 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <92f70aF9pqU1@mid.individual.net> Message-ID: In article , Chris Angelico wrote: >On Sat, May 7, 2011 at 7:21 PM, Gregory Ewing > wrote: >> Hans Georg Schaathun wrote: >> >>> You cannot reference nor manipulate a reference in python, and that IMHO >>> makes them more abstract. >> >> You can manipulate them just fine by moving them >> from one place to another: > >I think "manipulate" here means things like pointer arithmetic, which >are perfectly normal and common in C and assembly, but not in >languages where they're references. Adding an integer to a reference to an array element could have been perfectly well-defined in Algol: ref real operator+(ref real, int) That is called overloading of the plus operator not "pointer arithmetic". It is a misconception that these manipulation are dirty or ill-defined or unsafe. A similar extension would be possible in Python. Allusion to assembler where one adds a number to a register and can't tell whether the register contains an address or data are misleading. [This is not to say that I think it is advisable]. > >Chris Angelico Groetjes Albert. -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From albert at spenarnc.xs4all.nl Fri May 20 17:17:50 2011 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 20 May 2011 21:17:50 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <92f70aF9pqU1@mid.individual.net> Message-ID: In article <4dc7fa2f$0$29991$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: >On Mon, 09 May 2011 12:52:27 +1200, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >> >>> Since you haven't explained what you think is happening, I can only >>> guess. >> >> Let me save you from guessing. I'm thinking of a piece of paper with a >> little box on it and the name 'a' written beside it. There is an arrow >> from that box to a bigger box. >> >> +-------------+ >> +---+ | | >> a | --+---------------->| | >> +---+ | | >> +-------------+ >> >> There is another little box labelled 'b'. After executing 'a = b', both >> little boxes have arrows pointing to the same big box. >[...] >> In this model, a "reference" is an arrow. Manipulating references >> consists of rubbing out the arrows and redrawing them differently. > >All very good, but that's not what takes place at the level of Python >code. It's all implementation. I think Hans Georg Schaathun made a good >objection to the idea that "Python has references": > > In Pascal a pointer is a distinct data type, and you can > have variables of a given type or of type pointer to that > given type. That makes the pointer a concrete concept > defined by the language. > >The same can't be said of "references" in Python. It's not part of Python >the language, although it might be part of Python's implementation. > > > >> Also >> in this model, a "variable" is a little box. It's *not* the same thing >> as a name; a name is a label for a variable, not the variable itself. > >That's essentially the same model used when dealing with pointers. I've >used it myself, programming in Pascal. The "little box" named a or b is >the pointer variable, and the "big box" is the data that the pointer >points to. > >It's not an awful model for Python: a name binding a = obj is equivalent >to sticking a reference (a pointer?) in box a that points to obj. >Certainly there are advantages to it. > >But one problem is, the model is ambiguous with b = a. You've drawn >little boxes a and b both pointing to the big box (which I deleted for >brevity). But surely, if a = 1234 creates a reference from a to the big >box 1234, then b = a should create a reference from b to the box a? There are cleaner languages. Algol 68 , Forth. This is Forth. VARIABLE A VARIABLE B 1234 ( anonymous "object" created by the language ) A ! A @ B ! ( Copy the content, equivalent of B=A). Algol 68 B:=A compiler : THINK ! THINK ! A is a "ref int" so it can't be stored into b which is a "ref int" which is the name of a place where an int can be stored (not where a ref int could be stored.) Solution: Algol dereferences A into an int, by getting its content. But it is a rule, very explicitly explained in the language definition. (If you are that clean you can handle "ref ref int q" where q is the name of a place where a "ref int" can be stored.) "real a" is in fact an abbreviation of "ref real a=loc real" meaning "a" is a reference to a local real, that is anonymous. The = means that the connection between a and that real is an identity, i.e. the connection can't be broken. (Forget about C++, "casting away const", yuck! ) In Forth and in Algol 68 storing a constant into a variable is very different from copying the content of a variable to some other variable. > >-- >Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From ethan at stoneleaf.us Fri May 20 17:48:27 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 May 2011 14:48:27 -0700 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD6AB96.2040307@stoneleaf.us> Message-ID: <4DD6E1AB.4050603@stoneleaf.us> Peter Otten wrote: > Ethan Furman wrote: > >> Peter Otten wrote: >>> Ethan Furman wrote: >>> >>>> Several folk have said that objects that compare equal must hash equal, >>>> and the docs also state this >>>> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >>>> >>>> --> class Wierd(): >>>> ... def __init__(self, value): >>>> ... self.value = value >>>> ... def __eq__(self, other): >>>> ... return self.value == other >>>> ... def __hash__(self): >>>> ... return hash((self.value + 13) ** 3) >>>> ... >>> Try this: >>> >>>>>> d = {Wierd(1): 0} >>>>>> 1 in d >>> False >>>>>> 1 in d.keys() >>> True >>> >> My apologies -- I'm trying this in Python3: > > Then you have to convert the keys to a list explicitly: > >>>> class Weird: > ... def __init__(self, value): > ... self.value = value > ... def __eq__(self, other): > ... return self.value == other > ... def __hash__(self): > ... return hash((self.value + 13) **3) > ... >>>> d = {Weird(1): 0} >>>> 1 in d > False >>>> 1 in d.keys() > False >>>> 1 in list(d.keys()) > True Ah!! The light finally dawned! Many thanks for everyone's input. So if Wierd has a need to compare equal to some other type, it should implement a .equals() method. Gotcha. Likewise, if two different type's instances can compare equal, then for the most part they should be interchangeable. ~Ethan~ From bahamutzero8825 at gmail.com Fri May 20 17:55:01 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 20 May 2011 16:55:01 -0500 Subject: List of WindowsError error codes and meanings In-Reply-To: References: Message-ID: <4DD6E335.9090100@gmail.com> On 2011.05.20 02:47 PM, Genstein wrote: > On 20/05/2011 18:56, Andrew Berg wrote: > > This is probably somewhat off-topic, but where would I find a list of > > what each error code in WindowsError means? > > Assuming it's a Win32 error code, winerror.h from the Platform SDK holds > the answer. One version is linked below, it's in theory out of date > (2003) but all the best known codes are present. > > http://msdn.microsoft.com/en-us/library/ms819773.aspx > http://msdn.microsoft.com/en-us/library/ms819775.aspx > > For example, "WindowsError [error 5] Access is denied" matches > ERROR_ACCESS_DENIED (5L). I wasn't really sure if/how the codes in a WindowsError message mapped to something I would find on MSDN. That's really helpful, and I actually was able to find something more up-to-date: http://msdn.microsoft.com/en-us/library/ms681381%28v=VS.85%29.aspx > HRESULTS may also crop up (e.g. E_FAIL, 0x80040005) which are harder to > list exhaustively since subsystems and COM components may roll their own > codes of various sorts; but common ones are present in winerror.h. That's good to know. Thanks! From bob at mellowood.ca Fri May 20 18:12:31 2011 From: bob at mellowood.ca (bvdp) Date: Fri, 20 May 2011 15:12:31 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> > I'm not a tk user, but it sounds like it has regressed from accepting > arbitrary callables as callbacks to accepting functions specifically. > > What happens if you replace: > > ("Favorites", selectFav), > > with: > > ("Favorites", lambda: selectFav()), Okay, this works. Great and thanks! Seems to me that the way I was doing it should be alright ... and I've got some other programs exhibiting the same problem. Before I go "fixing" the issue ... is this known or even a bug? From ian.g.kelly at gmail.com Fri May 20 18:33:40 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 16:33:40 -0600 Subject: TK program problem In-Reply-To: <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 4:12 PM, bvdp wrote: > Okay, this works. Great and thanks! Seems to me that the way I was > doing it should be alright ... and I've got some other programs > exhibiting the same problem. > > Before I go "fixing" the issue ... is this known or even a bug? The docs [1] say that a callback is a function, so I guess that if it worked before it was just luck. You should bring it up on the tkinter list and see what they have to say about it, though. I'm a bit confused about why you would want to use a class as a callback anyway. It looks like when the button is clicked it instantiates the class and then throws it away? [1] http://docs.python.org/library/tkinter.html#tk-option-data-types From debatem1 at gmail.com Fri May 20 18:45:03 2011 From: debatem1 at gmail.com (geremy condra) Date: Fri, 20 May 2011 15:45:03 -0700 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 1:24 PM, harrismh777 wrote: > Steven D'Aprano wrote: >> >> Nonsense. How do you (generic "you", not any specific person) know that >> you are not an idiot? > > lol ? ? Sum, ergo Idiot cogitat. > > > Reminds me of a philosophical story I heard one time from my religion > professor... > > ... as it goes, De Carte leads his horse into town ? ;-) ?and having hitched > it to the rail outside the local saloon and sauntering up to the bar, ?the > tender asks, "Would you be hav'in an ale sir?" > > ... De Carte replies, "I think not..." ? ? ... and then disappeared. At risk of being pedantic, I think you mean Descartes rather than De Carte. Geremy Condra From ericsnowcurrently at gmail.com Fri May 20 18:55:49 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 20 May 2011 16:55:49 -0600 Subject: validating a class against an ABC at definition time In-Reply-To: References: Message-ID: On Thu, May 19, 2011 at 11:33 PM, Eric Snow wrote: > Thinking about class APIs and validating a class against an API. The abc > module provides the tools to do some of this. One thing I realized, that I > hadn't noticed before, is that the abstractness of a class is measured when > instances of the class are created. This happens in object.__new__ > (pyobject.c). Validating thus when a class is defined would not be as > helpful, since there is no guarantee that the class is not meant to be > abstract as well. > > However, I have found that it is sometimes nice to validate a class at > definition time. This is particularly true for a class that does not > inherit from the abstract base class (but registers instead). > > Taking cues from abc.py and pyobject.c, here is a stab at a class decorator > that validates a class against another. > > def validate(abc): > if not isinstance(abc, type): > raise TypeError("Can only validate against classes") > def decorator(cls): > if not __debug__: > return cls > if not isinstance(cls, type): > raise TypeError("Can only validate classes") > abstracts = set() > for name in getattr(abc, "__abstractmethods__", set()): > value = getattr(cls, name, None) > if not value: > abstracts.add(name) > elif getattr(value, "__isabstractmethod__", False): > abstracts.add(name) > if abstracts: > sorted_methods = sorted(abstracts) > joined = ", ".join(sorted_methods) > msg = "Class {} does not implement abstract methods {} of class > {}" > raise TypeError(msg.format(cls.__name__, joined, abc.__name__)) > return cls > return decorator > > Stack this with the ABCMeta.register method and you can ensure that your > class is compliant with the ABC at the time you register it on that ABC. > > Does anyone find this irrelevant or superfluous? I know that it would be a > good idea to stay on top of your class's implementation of an ABC's abstract > methods. However, this seems like a good way of doing that > programmatically. > > Does anyone know a better way to do ABC validation at definition time? > > Thanks. > > -eric > > > > > I have revised this and made a recipe for it: http://code.activestate.com/recipes/577711-validating-classes-and-objects-against-an-abstract/ The question remains of what alternatives exist to this solution. Thanks! -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at mellowood.ca Fri May 20 19:07:39 2011 From: bob at mellowood.ca (bvdp) Date: Fri, 20 May 2011 16:07:39 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> Message-ID: Probably the fix is to use a function :) > The docs [1] say that a callback is a function, so I guess that if it > worked before it was just luck. ?You should bring it up on the tkinter > list and see what they have to say about it, though. > > I'm a bit confused about why you would want to use a class as a > callback anyway. ?It looks like when the button is clicked it > instantiates the class and then throws it away? I have no idea why I used a class like this, expect that it seemed to work at the time. Yes, the class is instantiated when the button is clicked. Then, the user stays in the class and uses its methods until he hits in the class. So, I guess what's happening is that I'm treating the button click much like a call to a new program/window which sets some options, etc. in the main program. You mention the tkinter group. Ummm, what group is that??? Best, From ian.g.kelly at gmail.com Fri May 20 19:29:05 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 17:29:05 -0600 Subject: TK program problem In-Reply-To: References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 5:07 PM, bvdp wrote: > You mention the tkinter group. Ummm, what group is that??? http://tkinter.unpythonic.net/wiki/TkinterDiscuss From bob at mellowood.ca Fri May 20 19:34:27 2011 From: bob at mellowood.ca (bvdp) Date: Fri, 20 May 2011 16:34:27 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> Message-ID: On May 20, 4:29?pm, Ian Kelly wrote: > On Fri, May 20, 2011 at 5:07 PM, bvdp wrote: > > You mention the tkinter group. Ummm, what group is that??? > > http://tkinter.unpythonic.net/wiki/TkinterDiscuss Thanks. New one for me. I'll subscribe and see if they know about this. Best, From rantingrick at gmail.com Fri May 20 19:37:08 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 20 May 2011 16:37:08 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> Message-ID: <136b3435-a6bd-45fa-9c8c-5602ea23c861@s2g2000yql.googlegroups.com> On May 20, 6:07?pm, bvdp wrote: > Probably the fix is to use a function :) > > > The docs [1] say that a callback is a function, so I guess that if it > > worked before it was just luck. ?You should bring it up on the tkinter > > list and see what they have to say about it, though. > > > I'm a bit confused about why you would want to use a class as a > > callback anyway. ?It looks like when the button is clicked it > > instantiates the class and then throws it away? > > I have no idea why I used a class like this, expect that it seemed to > work at the time. Yes, the class is instantiated when the button is > clicked. Then, the user stays in the class and uses its methods until > he hits in the class. Thats sounds to me a lot like hammering square pegs though round holes... Perhaps you should explain first in "plain english" what problem your application is intended to solve, then how it is expected to interact with the user, and finally, what exactly is NOT working correctly. I would suffix such a documentary with the current source code, verbatim. From ericsnowcurrently at gmail.com Fri May 20 20:05:58 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 20 May 2011 18:05:58 -0600 Subject: validating a class against an ABC at definition time In-Reply-To: References: Message-ID: On Fri, May 20, 2011 at 4:55 PM, Eric Snow wrote: > > I have revised this and made a recipe for it: > > > http://code.activestate.com/recipes/577711-validating-classes-and-objects-against-an-abstract/ > > I also added this: http://code.activestate.com/recipes/577712-adding-__implements__-to-subclasses-during-abcmeta/ > The question remains of what alternatives exist to this solution. Thanks! > > -eric > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri May 20 20:44:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 May 2011 10:44:35 +1000 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd69fcd$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd69fcd$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 21, 2011 at 3:07 AM, Steven D'Aprano wrote: > On Fri, 20 May 2011 16:54:06 +1000, Chris Angelico wrote: > >> If someone has time to kill (as if!), it'd be awesome to get a new >> numeric type that uses bc's code; any other numeric type (int, long, >> float) could autopromote to it, removing the dilemma of which to promote >> out of long and float. Hmm... Python 4.0, 'bc' is the new default >> integer and everything else is a performance optimization? Heh. > > The problem is, it isn't *just* a performance optimization, there is a > semantic difference too. Consider: Sure, but I'm thinking here that the "gold standard" is accuracy, with other types allowing a programmer to forfeit some accuracy in favour of performance. (Oh, and I should have said "new default numeric type".) And, of course, I was thinking in a stupid hypothetical way that's extremely unlikely ever to happen. Chris Angelico From steve+comp.lang.python at pearwood.info Fri May 20 20:47:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 May 2011 00:47:56 GMT Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: <4dd70bbc$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 May 2011 21:17:29 +0100, MRAB wrote: > On 20/05/2011 20:01, Christian Heimes wrote: >> Am 20.05.2011 17:50, schrieb MRAB: >>> Is this strictly true? I thought that the hash value, an integer, is >>> moduloed (Is that how you spell it? Looks weird!) ... >> >> I don't think 'moduloed' is an existing word but your description is >> mostly correct. ... >> > A brief search on the web found a use of the word in 1982. All that means is that two people, three decades apart, used the same non- word :) I think you are treating "modulo" as a verb, equivalent to division, hence: a/b => a is divided by b a%b => a is "moduloed" by b But modulo is not a verb. It is a preposition, a modifier word. Just as you might say "the cat sat on the mat" (cat on mat) or "the Princess found a pea underneath her mattress" (pea underneath mattress) so mathematicians will say "a is taken modulo b" (a modulo b). English verbs nouns at the drop of a hat, but I've never heard of it verbing propositions: "The princess underneathed the pea." No, I don't think so. English does use "remainder" as a verb, although not in the mathematical sense; I think that: a%b => a is remaindered by b is at least grammatical, although still ugly and awkward. I'm afraid that in English, the best way to say what you are trying to say is moderately verbose: "the hash value, an integer, is taken modulo ..." -- Steven From barry at python.org Fri May 20 20:53:14 2011 From: barry at python.org (Barry Warsaw) Date: Fri, 20 May 2011 20:53:14 -0400 Subject: Python 2.6.7 release candidate 2 now available Message-ID: <20110520205314.1be39eec@neurotica.wooz.org> Hello to all you Pythoneers and Pythonistas, I'm happy to announce the availability of Python 2.6.7 release candidate 2. Release candidate 1 was not widely announced due to a mismatch between the Mercurial and Subversion branches. Barring any unforeseen issues, this will be the last release candidate before 2.6.7 final, which is currently scheduled for June 3, 2011. As previously announced, Python 2.6 is in security-fix only mode. This means that general bug fix maintenance has ended, and only critical security fixes are supported. We will support Python 2.6 in security-fix only mode until October 2013. Also, this is a source-only release; no installers for Windows or Mac OS X will be provided. Please download and test this release candidate. http://www.python.org/download/releases/2.6.7/ The NEWS file contains a list of changes since 2.6.6. http://www.python.org/download/releases/2.6.7/NEWS.txt Many thanks go out to the entire Python community for their contributions great and small. Enjoy, -Barry (on behalf of the Python development community) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: From steve+comp.lang.python at pearwood.info Fri May 20 20:54:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 May 2011 00:54:01 GMT Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dd70d29$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 May 2011 15:45:03 -0700, geremy condra wrote: > On Fri, May 20, 2011 at 1:24 PM, harrismh777 > wrote: >> ... as it goes, De Carte leads his horse into town ? ;-) ?and having >> hitched it to the rail outside the local saloon and sauntering up to >> the bar, ?the tender asks, "Would you be hav'in an ale sir?" >> >> ... De Carte replies, "I think not..." ? ? ... and then disappeared. > > At risk of being pedantic, I think you mean Descartes rather than De > Carte. Being a drunken old fart, I can't imagine Descartes turning down an ale... http://www.bbc.co.uk/dna/h2g2/A3651545 -- Steven From python at mrabarnett.plus.com Fri May 20 21:02:48 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 21 May 2011 02:02:48 +0100 Subject: hash values and equality In-Reply-To: <4dd70bbc$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> <4dd70bbc$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DD70F38.2080700@mrabarnett.plus.com> On 21/05/2011 01:47, Steven D'Aprano wrote: > On Fri, 20 May 2011 21:17:29 +0100, MRAB wrote: > >> On 20/05/2011 20:01, Christian Heimes wrote: >>> Am 20.05.2011 17:50, schrieb MRAB: >>>> Is this strictly true? I thought that the hash value, an integer, is >>>> moduloed (Is that how you spell it? Looks weird!) ... >>> >>> I don't think 'moduloed' is an existing word but your description is >>> mostly correct. ... >>> >> A brief search on the web found a use of the word in 1982. > > All that means is that two people, three decades apart, used the same non- > word :) > [snip] There were other uses. That's just the earliest one I found. From steve+comp.lang.python at pearwood.info Fri May 20 21:55:18 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 May 2011 01:55:18 GMT Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> <4dd70bbc$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dd71b85$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 May 2011 02:02:48 +0100, MRAB wrote: > On 21/05/2011 01:47, Steven D'Aprano wrote: >> On Fri, 20 May 2011 21:17:29 +0100, MRAB wrote: >> >>> On 20/05/2011 20:01, Christian Heimes wrote: >>>> Am 20.05.2011 17:50, schrieb MRAB: >>>>> Is this strictly true? I thought that the hash value, an integer, is >>>>> moduloed (Is that how you spell it? Looks weird!) ... >>>> >>>> I don't think 'moduloed' is an existing word but your description is >>>> mostly correct. ... >>>> >>> A brief search on the web found a use of the word in 1982. >> >> All that means is that two people, three decades apart, used the same >> non- word :) >> > [snip] > There were other uses. That's just the earliest one I found. Nevertheless, it is still ungrammatical and incorrect usage. I'm not a prescriptivist, but not everything people write down is a word, otherwise we'd be forcefied to say evert typlo and mystake wsa an actul wrd. -- Steven From harrismh777 at charter.net Sat May 21 00:26:17 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 20 May 2011 23:26:17 -0500 Subject: Python 2.6.7 release candidate 2 now available In-Reply-To: References: Message-ID: Barry Warsaw wrote: > We will support Python 2.6 in security-fix only mode until > October 2013. Where can I read about the criteria for security-fix only? Who decides whether the security fix is critical? thanks, kind regards, m harris From harrismh777 at charter.net Sat May 21 00:26:24 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 20 May 2011 23:26:24 -0500 Subject: obviscating python code for distribution In-Reply-To: <4dd70d29$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd70d29$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >>> ... as it goes, De Carte leads his horse into town;-) and having >>> >> hitched it to the rail outside the local saloon and sauntering up to >>> >> the bar, the tender asks, "Would you be hav'in an ale sir?" >>> >> >>> >> ... De Carte replies, "I think not..." ... and then disappeared. >> > >> > At risk of being pedantic, I think you mean Descartes rather than De >> > Carte. > Being a drunken old fart, I can't imagine Descartes turning down an ale... > > http://www.bbc.co.uk/dna/h2g2/A3651545 > > .. .uh, yes... playing on 'de carte before de horse...' ... as for Steven's link: And Rene Descartes was a drunken old fart: "I drink, therefore I am", Ren? Descartes (1596-1650) I am not sure about Descartes drinking habits, but he was one true philosopher and mathematician... so we honor him... with jokes ! :) (how many of you guys are they going to be joking about 450 years from now ?) From kushal.kumaran+python at gmail.com Sat May 21 01:16:41 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sat, 21 May 2011 10:46:41 +0530 Subject: how to get PID from subprocess library In-Reply-To: References: Message-ID: On Thu, May 19, 2011 at 9:32 PM, TheSaint wrote: > hello, > > I'm using to launch a program by subprocess.getstatusoutput. I'd like to > know whether I can get the program ID, in order to avoid another launch. > > For clarity sake, I'm calling aria2 (the download manager for linux) and I > wouldn't like to call one more instance of it. So what will I use to find > the PID of the launched program? > The getstatusoutput function will only return when the command has finished. That's how it is able to give you the status. So, if you are using getstatusoutput, you will have only one instance of your command running. -- regards, kushal From cs at zip.com.au Sat May 21 01:40:20 2011 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 21 May 2011 15:40:20 +1000 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: <20110521054020.GA32313@cskk.homeip.net> On 11May2011 13:37, James Mills wrote: | On Tue, May 10, 2011 at 7:34 PM, Jean-Michel Pichavant | wrote: | > You can reraise the exception without loosing the stack trace. | > | > try: | > ... | > except SomeException, exc: | > log(exc) | > print 'Hello world' | > raise # "raise exc" would loose the original stack trace | | Valid point :) However I was referring to real experience | where I've seen code that "catches all any any exception" | and simply logs it. I've put code like that in a worker thread occasionally, because there's nobody "outside" to catch it; the submitter's attention is elsewhere. These days I think I'd use a LateFunction (a facility of my own which is a lot like the futures module) which returns a callable when you submit a function; the worker thread runs the submitted function and catches the return value or raised exception. Anyone who calls the returned callable later gets the return value or the exception reraised as appropriate, so one can avoid the dangerous "catch everything and log" scenario. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Observing the first balloon ascent in Paris, [Ben] Franklin heard a scoffer ask, "What good is it?" He spoke for a generation of scientists in his retort, "What good is a newly born infant?" - John F. Kasson From nad at acm.org Sat May 21 01:54:35 2011 From: nad at acm.org (Ned Deily) Date: Fri, 20 May 2011 22:54:35 -0700 Subject: Python 2.6.7 release candidate 2 now available References: Message-ID: In article , harrismh777 wrote: > Barry Warsaw wrote: > > We will support Python 2.6 in security-fix only mode until > > October 2013. > Where can I read about the criteria for security-fix only? You can read about the Python development cycle and security branches in the Python Developer's Guide: http://docs.python.org/devguide/devcycle.html#security-branches > Who decides whether the security fix is critical? Anyone can propose a security fix but the final decision is up to the release manager in charge of the branch. For 2.6.x, that is Barry. -- Ned Deily, nad at acm.org From prologic at shortcircuit.net.au Sat May 21 03:08:18 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Sat, 21 May 2011 17:08:18 +1000 Subject: Overuse of try/except/else? In-Reply-To: <20110521054020.GA32313@cskk.homeip.net> References: <20110521054020.GA32313@cskk.homeip.net> Message-ID: On Sat, May 21, 2011 at 3:40 PM, Cameron Simpson wrote: > These days I think I'd use a LateFunction (a facility of my own which is > a lot like the futures module) which returns a callable when you submit > a function; the worker thread runs the submitted function and catches the > return value or raised exception. Anyone who calls the returned callable > later gets the return value or the exception reraised as appropriate, > so one can avoid the dangerous "catch everything and log" scenario. I like this :) I guess you call this a Proxy Object although your calling it a LateFunction seems more "fitting" :) cheers James -- -- James Mills -- -- "Problems are solved by method" From __peter__ at web.de Sat May 21 04:18:59 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 21 May 2011 10:18:59 +0200 Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: bvdp wrote: > I've just done an update to my system here to Ubuntu 11.04. Mostly no > problems ... but I have an important (to me) python/TK program that's > stopped working. Well, it works ... mostly. > > The python version is 2.7.1+ (no idea what the + means!). > > I _think_ I have traced the problem to certain menus which call a > class. The calls appear to be ignored. > > Basically, what I have is a line like: > > bf = makeButtonBar(root, row=0, column=0, buttons=( > ("Quit", self.quitall ), > ("Stop", self.stopPmidi ), > ("New Dir", self.chd), > ("Load Playlist", self.playList), > ("Favorites", selectFav), > ("Options", setOptions) ) ) > > To create a menu bar. The function makeButtonBar() creates the buttons > with: > > for txt, cmd in buttons: > Button(bf, text=txt, height=1, command=cmd).grid(column=c, > row=0, pady=5) > > > All this is fine (and worked perfectly before my upgrade). The menu > items which are ordinary functions continue to work. BUT the callbacks > which are classes are just ignored when they are clicked. > > A cut from one of the ignored classes: > > > class selectFav: > > def __init__(self): > ... > > And I've inserted some prints in the __init__() and nothing is > printed. Also, converted the class to new-style () but no change there > either. > > Either python/tk has changed or my system is totally $*(#*#. > Suggestions welcome! Here's a minimal script to reproduces the problem: $ cat tkcallclass.py import Tkinter as tk root = tk.Tk() root.withdraw() class Classic: def __init__(self): print "hello" button = tk.Button(root, command=Classic) button.invoke() $ python2.6 tkcallclass.py hello $ python2.7 tkcallclass.py Traceback (most recent call last): File "tkcallclass.py", line 11, in button.invoke() File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 2081, in invoke return self.tk.call(self._w, 'invoke') _tkinter.TclError: invalid command name "__main__.Classic" $ In 2.7 the Tkinter code was changed to use hasattr(obj, "__call__") instead of callable(obj) to recognize callbacks. This gives different results for oldstyle classes >>> class A: pass ... >>> callable(A) True >>> hasattr(A, "__call__") False ...and they are no longer registered automatically with Tkinter. In theory you could register them explicitly yourself $ cat tkcallclass2.py import Tkinter as tk root = tk.Tk() root.withdraw() class Classic: def __init__(self): print "hello" button = tk.Button(root, command=root.register(Classic)) button.invoke() $ python2.7 tkcallclass2.py hello but in practice changing them to newstyle (i. e. have them inherit from object) or wrapping them in a lambda appears convenient. Personally, I would reconsider whether using a class as a callback is really necessary. Replacing the class with a function should be a straightforward process. From greg.ewing at canterbury.ac.nz Sat May 21 04:24:21 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 21 May 2011 20:24:21 +1200 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> Message-ID: <93pb5nF3gtU1@mid.individual.net> Ethan Furman wrote: > Ulrich Eckhardt wrote: > >> If two equal objects have different hashes, they >> will be stored in different places in the hash map. Looking for >> object1 will then not turn up with object2, even though they are equal. > > In this case this is the behavior I want. You can't rely on it, though. The hash value gets reduced modulo the size of the dict, so even if two objects have different hashes, in some cases they will land on the same dict slot anyway. So an object such as you're postulating would behave unpredictably when used as a dict key. Sometimes a lookup using a different but equal object would find it, and sometimes not, seemingly at random. -- Greg From franck at ditter.org Sat May 21 04:30:41 2011 From: franck at ditter.org (Franck Ditter) Date: Sat, 21 May 2011 10:30:41 +0200 Subject: Python in CS1 Message-ID: Except at MIT, who knows some good CS1 references for teaching Python ? Thanks, franck From J.deBoynePollard-newsgroups at NTLWorld.COM Sat May 21 04:32:01 2011 From: J.deBoynePollard-newsgroups at NTLWorld.COM (Jonathan de Boyne Pollard) Date: Sat, 21 May 2011 09:32:01 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> Message-ID: > The supposed inefficiency of recursive implementations is based > largely on the properties of hardware that is now obsolete. With > modern processors there's no great efficiency hit. In some of the > smaller microcontrollers, it's true, you do have to worry about stack > overflow; but the ARM processors, for example, provide plenty of stack > space. > > In the microcontroller world, the big performance hits come from the > fact that the only available compilers are for C and sometimes C++. > (And nobody uses assembly language except for the very little jobs.) > The nature of the C language prevents compilers from doing > optimisations that are standard in compilers for high-level languages. > Most C compilers will, for example, always pass parameters on the > stack, despite the generous supply of registers available in newer > hardware. > However, some C compilers will *also* have one or more "go faster" calling conventions that pass parameters in registers, which can be employed. Over in the PC world, such "go faster" calling conventions are even the default calling convention if no calling convention is explicitly specified, for some C and C++ compilers. http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Compiler http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Optlink http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Watcall From wbsoft at xs4all.nl Sat May 21 04:42:40 2011 From: wbsoft at xs4all.nl (Wilbert Berendsen) Date: Sat, 21 May 2011 10:42:40 +0200 Subject: distutils on windows ignoring package_data Message-ID: <201105211042.41201.wbsoft@xs4all.nl> Hi, I have created a distutils setup.py script that installs a list of packages (all subpackages of one main package). Some packages have package_data files (icons, translations, etc). Running setup.py install on my Linux system (python 2.6) perfectly installs all package data, but on Windows (tested with both 2.6 and 2.7) the package_data is not installed at all. Also not picked up in build, or bdist_wininst, etc. Only the Python files in the packages are installed. The setup.py file can be seen at https://github.com/wbsoft/frescobaldi/blob/master/setup.py I later added the package_dir incantation, but it doesn't help on Windows and on Linux it worked perfectly without. Does anybody have a clue why Python distutils on Windows ignore the package_data? (Note: sdist perfectly works as the data files are also listed in MANIFEST.in) tia, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ From greg.ewing at canterbury.ac.nz Sat May 21 04:49:33 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 21 May 2011 20:49:33 +1200 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <93pcl0Fe1nU1@mid.individual.net> Chris Angelico wrote: > It seems > strange to smoothly slide from native integer to long integer and just > keep on going, and yet to be unable to do the same if there's a > fractional part on it. The trouble is that if you always compute exact results by default, the number of digits required can blow up very quickly. There's a story that ABC (the predecessor to Python) calculated everything using rationals. People found that sometimes a calculation would take an unexpectedly long time, and it turned out to be because internally it was creating fractions with huge numerators and denominators. As a consequence, Guido decided that Python would *not* use rationals by default. The same problem doesn't arise with ints, because the only time you get an int with a large number of digits is when you genuinely need a large int. So expanding ints automatically to however many digits is needed doesn't do any harm. In Python 2.6 and later, there's a fractions module for when you need it. -- Greg From __peter__ at web.de Sat May 21 05:24:40 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 21 May 2011 11:24:40 +0200 Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <93pb5nF3gtU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > Ethan Furman wrote: >> Ulrich Eckhardt wrote: >> >>> If two equal objects have different hashes, they >>> will be stored in different places in the hash map. Looking for >>> object1 will then not turn up with object2, even though they are equal. >> >> In this case this is the behavior I want. > > You can't rely on it, though. The hash value gets reduced > modulo the size of the dict, so even if two objects have > different hashes, in some cases they will land on the same > dict slot anyway. > > So an object such as you're postulating would behave > unpredictably when used as a dict key. Sometimes a lookup > using a different but equal object would find it, and > sometimes not, seemingly at random. I think for every potential match the current dict implementation checks identity, then hashes -- and equality only if the hash values are equal. The relevant function is lookdict() in dictobject.c. While that means that the problem you describe cannot occur a simple approach that avoids relying on an implementation detail (?) would be to use (hash(obj), obj) tuples instead of just obj as the key. From lars.enderin at telia.com Sat May 21 05:52:48 2011 From: lars.enderin at telia.com (Lars Enderin) Date: Sat, 21 May 2011 11:52:48 +0200 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> Message-ID: <4DD78B70.9090804@telia.com> 2011-05-21 10:32, Jonathan de Boyne Pollard skrev: >> The supposed inefficiency of recursive implementations is based >> largely on the properties of hardware that is now obsolete. With >> modern processors there's no great efficiency hit. In some of the >> smaller microcontrollers, it's true, you do have to worry about stack >> overflow; but the ARM processors, for example, provide plenty of stack >> space. >> >> In the microcontroller world, the big performance hits come from the >> fact that the only available compilers are for C and sometimes C++. >> (And nobody uses assembly language except for the very little jobs.) >> The nature of the C language prevents compilers from doing >> optimisations that are standard in compilers for high-level languages. >> Most C compilers will, for example, always pass parameters on the >> stack, despite the generous supply of registers available in newer >> hardware. >> > However, some C compilers will *also* have one or more "go faster" > calling conventions that pass parameters in registers, which can be > employed. Over in the PC world, such "go faster" calling conventions > are even the default calling convention if no calling convention is > explicitly specified, for some C and C++ compilers. > > > http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Compiler > > > http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Optlink > > > http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Watcall > Please include attributions, in this case for Peter Moylan and rusi! From lars.enderin at telia.com Sat May 21 05:54:22 2011 From: lars.enderin at telia.com (Lars Enderin) Date: Sat, 21 May 2011 11:54:22 +0200 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <4DD78B70.9090804@telia.com> References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> <4DD78B70.9090804@telia.com> Message-ID: <4DD78BCE.50708@telia.com> 2011-05-21 11:52, Lars Enderin skrev: > > Please include attributions, in this case for Peter Moylan and rusi! Just Peter Moylan, sorry! From lars.enderin at telia.com Sat May 21 05:56:23 2011 From: lars.enderin at telia.com (Lars Enderin) Date: Sat, 21 May 2011 11:56:23 +0200 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <4DD78BCE.50708@telia.com> References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> <4DD78B70.9090804@telia.com> <4DD78BCE.50708@telia.com> Message-ID: <4DD78C47.5020406@telia.com> 2011-05-21 11:54, Lars Enderin skrev: > 2011-05-21 11:52, Lars Enderin skrev: >> >> Please include attributions, in this case for Peter Moylan and rusi! > > Just Peter Moylan, sorry! Ignore the above. From inigoserna at gmail.com Sat May 21 07:25:31 2011 From: inigoserna at gmail.com (=?UTF-8?B?ScOxaWdvIFNlcm5h?=) Date: Sat, 21 May 2011 13:25:31 +0200 Subject: ANN: lfm v2.3 Message-ID: Hi, new version of lfm. Note that it requires python v2.5+ now, and it's incompatible with v3.x. Description: ========== Last File Manager is a powerful file manager for the UNIX console. It has a curses interface and it's written in Python. Licensed under GNU Public License version 3. Some of the features you could find in lfm: - console-based file manager for UNIX platforms - 1-pane or 2-pane view - tabs - bookmarks - history - vfs for compressed files - dialogs with entry completion - PowerCLI, a command line interface with advanced features - fast access to the shell - direct integration of find/grep, df and other tools - color files by extension - fast file viewer with text and binary modes - ...and many others Download it from: =============== http://inigo.katxi.org/devel/lfm (home server) or http://code.google.com/p/lfm/ or from http://www.terra.es/personal7/inigoserna/lfm when crap ISP updates its cache. Changes since last version: ====================== + About the code - lfm needs python version 2.5 or upper now + New features - PowerCLI, an advanced command line interface with completion, persistent history, variable substitution and many other useful features. As this is a very powerful tool, read the documentation for examples - history . use different types of history lists: path, file, glob, grep, exec, cli for the different forms and actions . persistent history between sessions => ~/.lfm_history . controlled by a flag in configuration - find/grep . configuration options for ignorecase and regex . sort results . show results as FILE:lineno . much faster - show diff between xxx.orig and xxx files - tar files compress/uncompress - messages.EntryLine has been rewritten, with many new key shorcuts. This is the core behind most of the forms lfm shows when asking for anything. Consult the documentation + Minor changes - reorganize "un/compress file" and "compress directory xxx" in file_menu - config: sort entries when saving - improve load/save handling of new options not present in ~/.lfmrc - added new extensions - messages.error rewritten to offer better messages - added some new key shortcuts messages.SelectItem + Documentation - added a note about python v2.5+ is needed from now on - 'lfm' shell function: change "$*" to "$@" to properly handle paths containg spaces - FAQ: added information about fuse to mount ssh, ftp, smb and webdav - reorganized and fixed key bindings section - documented .lfmrc contents - added link to public BitBucket repository + lots of bugs fixed: - pyview: . last char is not shown if file size is small . last line and wrap: cursor_down or page_next . when number of lines == window height - ncurses v5.8 doesn't accept 0 as width or height - UI crashes: . time string could contain non-ascii characters (reported by Martin Steigerwald) . when filenane length is large in full pane mode . MenuWin, SelectItem: ellipsize entries if bigger than screen width - find or find&grep: . pass "-type f" to find as ".#filename" are temporary emacs files/links that break search . show wrong matches if results contain directories or files with spaces . file->goto_file: move to correct page - copy/move "/file" to "/anydir/anyplace" fails, trying to copy/move to "/" - executing non-ascii programname or args - convoluted issue with link to directory in corner cases (reported by Xin Wang) - rename/backup ".." crashes - we should not compress ".." - create_link, edit_link: don't show error if canceled - only store one copy of the same entry in history - tree: "disable" colors of active panel, "enable" at end - Config.save: work with unicode, only convert to encoding when saving Of course, all comments, suggestions, etc. are welcome. Best regards, I?igo Serna From jjl at pobox.com Sat May 21 07:46:26 2011 From: jjl at pobox.com (John J Lee) Date: Sat, 21 May 2011 12:46:26 +0100 Subject: List of WindowsError error codes and meanings References: Message-ID: <8762p48eel.fsf@pobox.com> Andrew Berg writes: > This is probably somewhat off-topic, but where would I find a list of > what each error code in WindowsError means? WindowsError is so broad > that it could be difficult to decide what to do in an except clause. > Fortunately, sys.exc_info()[1][0] holds the specific error code, so I > could put in an if...elif...else clause inside the except clause if I > needed to, but I don't know what all the different errors are. Since Python 2.5, the errno attribute maps the Windows error to error codes that match the attributes of module errno. http://docs.python.org/library/exceptions.html#exceptions.WindowsError So for some purposes you can use the same UNIXy error codes you can use on most other platforms. Example: import errno try: operation() except WindowsError, exc: if exc.errno != errno.ENOENT: raise print "file/directory does not exist" Obviously whether this is useful depends on the error cases you need to handle. Undocumented: when there's no useful mapping to errno, you get errno.EINVAL. John From nobody at nowhere.net.no Sat May 21 08:50:58 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 21 May 2011 20:50:58 +0800 Subject: how to get PID from subprocess library References: Message-ID: Kushal Kumaran wrote: > That's how it is able to give you the status. So, if you > are using getstatusoutput, you will have only one instance of your > command running. My intent is to launch only one program instance, which will goes as daemon. To avoid a second call I'd like rather to use Python than ==============================code========================================= def start(self): '''try to start aria2c as a daemon and return its handle to where it can proceed to issue commands''' # aria2c is running, then don't try it again if (chkout('ps -A |grep aria2c')[0] > 0): try: chkout(self.ARIA_CMD) except: raise SystemExit('aria2c is not working as deamon') elif self.handle: return self.handle # everything is good, it will return an handle self.handle= \ xmlrpclib.ServerProxy('http://localhost:%s/rpc' %int(self.numport)) return self.handle ==============================code========================================= Here I've named subprocess.getstatusoutput as chkout, I'm calling 2 more programs to find whether there's a running instance of aria2c. I think it's not nice, python libraries should get the matter done. -- goto /dev/null From jjl at pobox.com Sat May 21 09:01:38 2011 From: jjl at pobox.com (John J Lee) Date: Sat, 21 May 2011 14:01:38 +0100 Subject: application level monitoring for python References: <7281a33b-a32c-4eba-8646-82d9cef459b1@m10g2000yqd.googlegroups.com> Message-ID: <871uzs8ax9.fsf@pobox.com> Walter Chang writes: > Hi > > is there any open source library for python that can allow application > level monitoring ? For example,application can send per request level/ > aggregated monitoring events and some remote server dump it and show > in the monitoring graph in real time ? What's best way of doing > that ? Zenoss is a popular tool for that kind of thing. Here's an example of sending a Zenoss event over XML-RPC: http://dancingpenguinsoflight.com/2009/05/send-events-to-zenoss-from-scripts/ Presumably you can send it evnts over other transports somehow (e.g. UDP). Zenoss is itself implemented in Python. John From dan.kluev at gmail.com Sat May 21 09:33:33 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 22 May 2011 00:33:33 +1100 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: On Tue, May 10, 2011 at 11:40 AM, Kyle T. Jones wrote: > > It has been hard for me to determine what would constitute overuse. > Good example of abuse is catching KeyboardInterrupt or SystemExit inside some library code. PycURL does it, and its truly annoying. -- With best regards, Daniel Kluev From wbsoft at xs4all.nl Sat May 21 09:57:52 2011 From: wbsoft at xs4all.nl (Wilbert Berendsen) Date: Sat, 21 May 2011 15:57:52 +0200 Subject: SOLVED Re: distutils on windows ignoring package_data In-Reply-To: <201105211042.41201.wbsoft@xs4all.nl> References: <201105211042.41201.wbsoft@xs4all.nl> Message-ID: <18a3dd09c99482abc3386f35e0db9cc3.squirrel@webmail.xs4all.nl> Solved: the problem was right there in the packagelist() function, it replaced '/' with dots instead of using os.sep ... I'm very sorry for the noise, although it's surprising everything else works without dots in the packages names :-) with regard, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ From jjl at pobox.com Sat May 21 10:06:57 2011 From: jjl at pobox.com (John J Lee) Date: Sat, 21 May 2011 15:06:57 +0100 Subject: Parsing a graph image References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> Message-ID: <87wrhk6tby.fsf@pobox.com> Bastian Ballmann writes: > Hi, > > the project sounds like the exact tool that i need but regarding the > user manual one has to mark the points on the graph manually. Therefore > it's more work to get the data out than doing it without a tool. Or may > I miss something here? > Greets Read the documentation more carefully: it has features that allow extracting points from line charts automatically. If you want something fully automated, you just want jam on it ;-) John From kb1pkl at aim.com Sat May 21 10:19:59 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sat, 21 May 2011 10:19:59 -0400 Subject: Python in CS1 In-Reply-To: References: Message-ID: <4DD7CA0F.2090009@aim.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/21/2011 04:30 AM, Franck Ditter wrote: > Except at MIT, who knows some good CS1 references for teaching Python ? > Thanks, > > franck Check out http://www.python.org/community/sigs/current/edu-sig/, and if nothing there satisfies you jump over onto the edu-sig list. - -- Corey Richardson -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iQEcBAEBAgAGBQJN18oPAAoJEAFAbo/KNFvp9MwH/0zXSTTaxAwYPLSxhyirqr3X DUxyulE5HRn+NIarWyomlDfoayip3boyUBG1GQDDKh+sIIzPT9ETfL7+ep9rwkL4 VA7XSDMLu+4DtUlnFjGlfxCz1REYKVvS4m/9w68F0kRflh5XZzDRBbTz0nXMiMM8 /UPBV8cX1XDq+RYis1baIlMSaro6sK3mHW5avBd9RxO4+IzH0TtKw510EWfRvZ8e ssdEUXZwxHmI0eRwYovynJ7VdLWwY/FLKuuoKl1IOpRwbAH8LtLtAAudHDZKOo9X ctwYfwGPCg39gz+fuJFFUGI6oYw8dkqiDi2su/QwN8JsaMXv4xeOc2ZXkZVYMiM= =7xLM -----END PGP SIGNATURE----- From jjl at pobox.com Sat May 21 10:46:01 2011 From: jjl at pobox.com (John J Lee) Date: Sat, 21 May 2011 15:46:01 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> Message-ID: <87r57s6riu.fsf@pobox.com> Gregory Ewing writes: > Hans Georg Schaathun wrote: >> 0 is a number as real and existent as any other, >> one would think that the empty list is also as real and existent as >> any other list. > > 0 does have some special properties, though, such as > being the additive identity and not having a multiplicative > inverse. Adding falseness as another special property isn't > too much of a stretch and turns out to be useful. > > Likewise, it's useful to treat empty containers as having > a similar special property, since they're often a base or > terminating case in algorithms. > > It's especially useful in a dynamic language where any > additional operations such as finding the length or > comparing with zero has a run-time cost. > > Yes, you have to learn it, but it's a small thing to > learn with a considerable payoff. (apologies if somebody already bikeshedded this argument in this thread) In the absence of an explicit interface declaration (have any standards emerged for that in Python 3, BTW?), the use of len() does give you some information about the interface, which sometimes makes it easier to change the function. I'm sure you fully understand this, but I'll spell it out. Consider this function: def xyzzy(x): if x: print "yes" Let's say I've read the function, and I've seen this call site: xyzzy(["spam", "eggs"]) Now I want to change xyzzy: def xyzzy(x): if x: print "probably" if len(x) == 1: print "definitely" But there may be many call sites. Perhaps xyzzy even implements part of a poorly-documented external API. So can x be None? There's no way to know short of checking all call sites, which may be impossible. It may not even be feasible to check the *only* call site, if you're implementing somebody else's poorly documented closed-source API (a situation I came across at work only yesterday, when that situation resulted in a bug report). If it's written this way, it's clear that it can't be None: def xyzzy(x): if len(x) != 0: print "yes" John From patty at cruzio.com Sat May 21 11:24:47 2011 From: patty at cruzio.com (Patty) Date: Sat, 21 May 2011 08:24:47 -0700 Subject: Python in CS1 References: <4DD7CA0F.2090009@aim.com> Message-ID: <66E3768F137647C2B2AD4993007E43D2@mycomputer> ----- Original Message ----- From: "Corey Richardson" To: Sent: Saturday, May 21, 2011 7:19 AM Subject: Re: Python in CS1 > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 05/21/2011 04:30 AM, Franck Ditter wrote: >> Except at MIT, who knows some good CS1 references for teaching Python ? >> Thanks, >> >> franck > > Check out http://www.python.org/community/sigs/current/edu-sig/, and if > nothing there satisfies you jump over onto the edu-sig list. > > - -- > Corey Richardson > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.17 (GNU/Linux) > > iQEcBAEBAgAGBQJN18oPAAoJEAFAbo/KNFvp9MwH/0zXSTTaxAwYPLSxhyirqr3X > DUxyulE5HRn+NIarWyomlDfoayip3boyUBG1GQDDKh+sIIzPT9ETfL7+ep9rwkL4 > VA7XSDMLu+4DtUlnFjGlfxCz1REYKVvS4m/9w68F0kRflh5XZzDRBbTz0nXMiMM8 > /UPBV8cX1XDq+RYis1baIlMSaro6sK3mHW5avBd9RxO4+IzH0TtKw510EWfRvZ8e > ssdEUXZwxHmI0eRwYovynJ7VdLWwY/FLKuuoKl1IOpRwbAH8LtLtAAudHDZKOo9X > ctwYfwGPCg39gz+fuJFFUGI6oYw8dkqiDi2su/QwN8JsaMXv4xeOc2ZXkZVYMiM= > =7xLM > -----END PGP SIGNATURE----- > -- > http://mail.python.org/mailman/listinfo/python-list > Thank you for forwarding this link Corey! It is very interesting and informative. Regards, Patty From invalid at invalid.invalid Sat May 21 11:34:18 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 21 May 2011 15:34:18 +0000 (UTC) Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> Message-ID: On 2011-05-19, Peter Moylan wrote: > In the microcontroller world, the big performance hits come from the > fact that the only available compilers are for C and sometimes C++. > (And nobody uses assembly language except for the very little jobs.) > The nature of the C language prevents compilers from doing optimisations > that are standard in compilers for high-level languages. Most C > compilers will, for example, always pass parameters on the stack, > despite the generous supply of registers available in newer hardware. I've been doing microcontroller stuff for 25+ years, almost all in C, and I don't think I've never seen such a compiler. Even on the register-starved 6800 architecture, the first parameter was passed in a register. On architectures with more registers (H8, MSP430, ARM, etc.) It's usually the first 3 or so parameters that are found in registers. -- Grant Edwards grant.b.edwards Yow! Gee, I feel kind of at LIGHT in the head now, gmail.com knowing I can't make my satellite dish PAYMENTS! From genstein at invalid.invalid Sat May 21 11:35:18 2011 From: genstein at invalid.invalid (Genstein) Date: Sat, 21 May 2011 16:35:18 +0100 Subject: List of WindowsError error codes and meanings In-Reply-To: <8762p48eel.fsf@pobox.com> References: <8762p48eel.fsf@pobox.com> Message-ID: > Andrew Berg writes: > Since Python 2.5, the errno attribute maps the Windows error to error > codes that match the attributes of module errno. Good point, I completely misread that. At least the Windows error code is still available as the winerror attribute. As an aside - call me stupid, but I don't quite follow the purpose of that errno mapping. Surely if the error number can be mapped successfully then the error isn't Windows specific and an OSError should logically be thrown instead? And if it can't be mapped successfully then errno will never be valid so the mapping is pointless? I guess if the mapping is imprecise then it makes some sense as errno is a convenience to avoid people having to grasp the meaning of the many and various winerror.h values. So perhaps I've answered my own question. From mount.sarah at gmail.com Sat May 21 11:37:21 2011 From: mount.sarah at gmail.com (Sarah Mount) Date: Sat, 21 May 2011 16:37:21 +0100 Subject: Python in CS1 In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 09:30, Franck Ditter wrote: > Except at MIT, who knows some good CS1 references for teaching Python ? James Shuttleworth and I did a lot of this at Coventry, the book Python for Rookies came from that. We don't use Python in CS1 at Wolverhampton, but James is still actively using our old syllabus (or a variant). You can reach him here: http://dis-dot-dat.net/ Sarah -- Sarah Mount, Senior Lecturer, University of Wolverhampton website:? http://www.snim2.org/ twitter: @snim2 From jjl at pobox.com Sat May 21 11:49:50 2011 From: jjl at pobox.com (John J Lee) Date: Sat, 21 May 2011 16:49:50 +0100 Subject: Abandoning Python Message-ID: <87ipt46okh.fsf@pobox.com> I still like Python after using it for over a decade, but there are things I don't like. What are your favourite up-and-coming languages of the moment? Here's my wishlist (not really in any order): * A widely used standard for (optional) interface declaration -- or something better. I want it to be easier to know what interface an object has when reading code, and which objects provide that interface. * Lower memory usage and faster execution speed. Yes, this has been a price worth paying. But I do want jam on it, please: give me a language where I get most of Python's advantages but don't have to pay it. * Better support for writing correct programs in the form of better support for things like non-imperative programming, DBC, etc. (with the emphasis on "etc"). * Perhaps better built-in support for common tasks in common application domains. Concurrency, persistence, database queries come to mind. * Better refactoring tools, better code analysis tools (lint, search, etc.). * An even larger user base, contributing more and better free and commercial software. I'm prepared to compromise on the last one. Obviously, it should do all that while preserving all the nice features of Python -- surely an easy task. John From emile at fenx.com Sat May 21 11:52:43 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 21 May 2011 08:52:43 -0700 Subject: checking if a list is empty In-Reply-To: <87r57s6riu.fsf@pobox.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: On 5/21/2011 7:46 AM John J Lee said... > Gregory Ewing writes: > >> Hans Georg Schaathun wrote: >>> 0 is a number as real and existent as any other, >>> one would think that the empty list is also as real and existent as >>> any other list. >> >> 0 does have some special properties, though, such as >> being the additive identity and not having a multiplicative >> inverse. Adding falseness as another special property isn't >> too much of a stretch and turns out to be useful. >> >> Likewise, it's useful to treat empty containers as having >> a similar special property, since they're often a base or >> terminating case in algorithms. >> >> It's especially useful in a dynamic language where any >> additional operations such as finding the length or >> comparing with zero has a run-time cost. >> >> Yes, you have to learn it, but it's a small thing to >> learn with a considerable payoff. > > (apologies if somebody already bikeshedded this argument in this thread) > > In the absence of an explicit interface declaration (have any standards > emerged for that in Python 3, BTW?), the use of len() does give you some > information about the interface, which sometimes makes it easier to > change the function. > > I'm sure you fully understand this, but I'll spell it out. Consider > this function: > > def xyzzy(x): > if x: > print "yes" > > > Let's say I've read the function, and I've seen this call site: > > xyzzy(["spam", "eggs"]) > > > Now I want to change xyzzy: > > def xyzzy(x): > if x: > print "probably" > if len(x) == 1: > print "definitely" > > > But there may be many call sites. Perhaps xyzzy even implements part of > a poorly-documented external API. So can x be None? There's no way to > know short of checking all call sites, which may be impossible. It may > not even be feasible to check the *only* call site, if you're > implementing somebody else's poorly documented closed-source API (a > situation I came across at work only yesterday, when that situation > resulted in a bug report). If it's written this way, it's clear that it > can't be None: qualified: "...without having been trapped or crashing" so if I found this function in running code it would be clear to me that, given that the app is running and hasn't been crashing, either it hasn't yet been None, or the code isn't accessed at all. Emile > > def xyzzy(x): > if len(x) != 0: > print "yes" > > > John From swavijay at gmail.com Sat May 21 11:56:50 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Sat, 21 May 2011 21:26:50 +0530 Subject: Problem in using subprocess module and communicate() Message-ID: Hi Gurus, I'm having some problem in using the communicate() along with the subprocess.I would like to invoke a command prompt and pass on a .bat file to execute. I went through the subprocess module and understood that using communicate, we can send the send data to stdin. According to the documentation http://docs.python.org/library/subprocess.html#subprocess.call, it says, if you want to send data to the process?s stdin, you need to create the Popen object with stdin=PIPE. so based on this, I have used the below function but it does not seem to work. Am I missing something here? import subprocess import threading import time def runMonitor(command): retcode = subprocess.Popen([command, '\k', 'dir'], cwd= 'C:\Python26\WorkSpace\FunctionExamples\src', stdin = subprocess.PIPE, creationflags=subprocess.CREATE_NEW_CONSOLE) retcode.wait() retcode.communicate('scripts_to_execute.bat') t = threading.Thread(target = runMonitor, args = ("cmd.exe",)) t.start() while t.is_alive(): print 'Thread is still alive' time.sleep(0.5) else: print 'Thread is dead' Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Sat May 21 12:00:15 2011 From: john at castleamber.com (John Bokma) Date: Sat, 21 May 2011 11:00:15 -0500 Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: <87boywavsg.fsf@castleamber.com> John J Lee writes: > > > I still like Python after using it for over a decade, but there are > things I don't like. > > What are your favourite up-and-coming languages of the moment? > > Here's my wishlist (not really in any order): > > * A widely used standard for (optional) interface declaration -- or > something better. I want it to be easier to know what interface an > object has when reading code, and which objects provide that > interface. > * Lower memory usage and faster execution speed. Yes, this has been a > price worth paying. But I do want jam on it, please: give me a > language where I get most of Python's advantages but don't have to > pay it. > * Better support for writing correct programs in the form of better > support for things like non-imperative programming, DBC, etc. (with > the emphasis on "etc"). > * Perhaps better built-in support for common tasks in common application > domains. Concurrency, persistence, database queries come to mind. > * Better refactoring tools, better code analysis tools (lint, search, > etc.). > * An even larger user base, contributing more and better free and > commercial software. > > I'm prepared to compromise on the last one. Obviously, it should do all > that while preserving all the nice features of Python -- surely an easy > task. A language I want to give a serious try the coming months is Haskell. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From sigzero at gmail.com Sat May 21 12:19:30 2011 From: sigzero at gmail.com (Robert) Date: Sat, 21 May 2011 09:19:30 -0700 (PDT) Subject: [Book] Python 3 Web Development Beginner's Guide Message-ID: Has anyone read this one? If so, what did you think? -- Bob From irmen.NOSPAM at xs4all.nl Sat May 21 12:22:37 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 21 May 2011 18:22:37 +0200 Subject: experiments with dictionary attacks against password hashes, in Python Message-ID: <4dd7e6cd$0$49176$e4fe514c@news.xs4all.nl> Hi, I've been experimenting a little with dictionary attacks against password hashes. It turned out that Python is plenty fast for this task, if you use precomputed hash databases. I used a few rather large dictionary files (most of the words of the English language, and most of the words of the Dutch language including derived forms) for a total of almost 600,000 precomputed hashes. With that the program can "crack" 10,000 password hashes in under a second on my 3 year old PC. I've also used a list of 600 'most commonly used' passwords that I gathered from a few sources. That list is used to generate a couple of variations, such as prefixing them with a digit, or typing the word in uppercase, etc. I did this to be able to quickly scan for the most common passwords, but it turned out that using all of the 600,000 precomputed hashes isn't much slower for the experiments that I did. The variations however increase the hit rate because words like "Jennifer9" are not in a normal dictionary file. This one however *is* part of the 'most common' list. So if that is your password, go change it right now ;-) I thought the code I wrote might interest other people as well, so I share it here: (It should run on Python 2.6 and up, including Python 3.x.) Download: http://www.razorvine.net/download/dictionary_attack/ Or by Subversion: svn://svn.razorvine.net/Various/PythonStuff/trunk/dictionaryattack Have fun, Irmen de Jong From wallenpb at gmail.com Sat May 21 14:40:40 2011 From: wallenpb at gmail.com (Bill Allen) Date: Sat, 21 May 2011 13:40:40 -0500 Subject: Abandoning Python In-Reply-To: <87ipt46okh.fsf@pobox.com> References: <87ipt46okh.fsf@pobox.com> Message-ID: You have ideas, a text editor, and a computer - best get to coding. What's stopping you? You largely want Python, with modifications. Join the development team and help implement those changes, or fork your own flavor and do what you wish. Right? You imagine it's an easy task, so get after it. Also, quit saying "give me". I realize that was a troll post, but I hear people say so many things like this about lots of things. Sick of it. Shut up and do something constructive instead. Contribute with effort, rather than a lot of "wishlist" and "give me" talk. On Sat, May 21, 2011 at 10:49, John J Lee wrote: > > > I still like Python after using it for over a decade, but there are > things I don't like. > > What are your favourite up-and-coming languages of the moment? > > Here's my wishlist (not really in any order): > > * A widely used standard for (optional) interface declaration -- or > something better. I want it to be easier to know what interface an > object has when reading code, and which objects provide that > interface. > * Lower memory usage and faster execution speed. Yes, this has been a > price worth paying. But I do want jam on it, please: give me a > language where I get most of Python's advantages but don't have to > pay it. > * Better support for writing correct programs in the form of better > support for things like non-imperative programming, DBC, etc. (with > the emphasis on "etc"). > * Perhaps better built-in support for common tasks in common application > domains. Concurrency, persistence, database queries come to mind. > * Better refactoring tools, better code analysis tools (lint, search, > etc.). > * An even larger user base, contributing more and better free and > commercial software. > > I'm prepared to compromise on the last one. Obviously, it should do all > that while preserving all the nice features of Python -- surely an easy > task. > > > John > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen.NOSPAM at xs4all.nl Sat May 21 15:28:20 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 21 May 2011 21:28:20 +0200 Subject: referring to package scope from module, using relative import? Message-ID: <4dd81254$0$49046$e4fe514c@news.xs4all.nl> Hi, I have a package with several modules in it. The package also has some objects created in the package scope (done in the package __init__.py). Is it possible to access those package scope objects from the modules, with relative imports or something? So that I don't have to import the package itself in its own submodules? Example: A/ __init__.py -> creates A.something thing.py -> needs to do "import A" to access A.something would like to not have to import A I think it's something simple I'm missing... Irmen From clp2 at rebertia.com Sat May 21 15:38:54 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 21 May 2011 12:38:54 -0700 Subject: Problem in using subprocess module and communicate() In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 8:56 AM, vijay swaminathan wrote: > Hi? Gurus, > > I'm having some problem in using the communicate() along with the > subprocess.I would like to invoke a command prompt and pass? on a .bat file > to execute. I went through the subprocess module and understood that using > communicate, we can send the send data to stdin. > > According to the documentation > http://docs.python.org/library/subprocess.html#subprocess.call, it says, > > if you want to send data to the process?s stdin, you need to create the > Popen object with stdin=PIPE. > > so based on this, I have used the below function but it does not seem to > work. Am I missing something here? > > import subprocess > import threading > import time > > def runMonitor(command): > ??? retcode = subprocess.Popen([command, '\k', 'dir'], Shouldn't that be /k, not \k? > ?????????????????????????????? cwd= > 'C:\Python26\WorkSpace\FunctionExamples\src', Sidenote: You really should use forward-slashes in paths like this (or double-up the backslashes). > ?????????????????????????????? stdin = subprocess.PIPE, > ?????????????????????????????? creationflags=subprocess.CREATE_NEW_CONSOLE) > > ??? retcode.wait() > > ??? retcode.communicate('scripts_to_execute.bat') Several issues here: - .wait() waits for the subprocess to terminate; there's reason for the shell to terminate here, so your program will hang forever on the .wait() call. - It makes no sense to call .communicate() after .wait(), since the subprocess will have already terminated; you can't communicate with a dead process. - .communicate() blocks until the subprocess terminates anyway, so calling .wait() is pointless. - I would think a newline is needed in you input to the shell. When one runs a command in the shell manually, one presses Enter after typing it, no? - `retcode` seems a rather poor variable name, since it's holding a Popen object rather than an integer exit code. Putting this all together, here's an improved version: def runMonitor(command): proc = subprocess.Popen([command, '/k', 'dir'], cwd='C:/Python26/WorkSpace/FunctionExamples/src', stdin=subprocess.PIPE, creationflags=subprocess.CREATE_NEW_CONSOLE) input_data = 'scripts_to_execute.bat\n' + 'exit\n' stdout_data, stderr_data = proc.communicate(input_data) I can't test it since I don't run Windows. Cheers, Chris -- http://rebertia.com From ian.g.kelly at gmail.com Sat May 21 16:00:12 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 21 May 2011 14:00:12 -0600 Subject: referring to package scope from module, using relative import? In-Reply-To: <4dd81254$0$49046$e4fe514c@news.xs4all.nl> References: <4dd81254$0$49046$e4fe514c@news.xs4all.nl> Message-ID: On Sat, May 21, 2011 at 1:28 PM, Irmen de Jong wrote: > Hi, > > I have a package with several modules in it. The package also has some objects created > in the package scope (done in the package __init__.py). > > Is it possible to access those package scope objects from the modules, with relative > imports or something? So that I don't have to import the package itself in its own > submodules? > > > Example: > > A/ > ? __init__.py ? ?-> ?creates A.something > ? thing.py ? ? ? -> ?needs to do "import A" ?to access A.something > ? ? ? ? ? ? ? ? ? ? ?would like to not have to import A You can do the relative import like this: from . import something Or if something were defined in A/otherthing.py, then: from .otherthing import something Note that PEP 8 discourages relative imports and encourages absolute imports, though. This would be the preferred way to do it: from A import something Cheers, Ian From tjreedy at udel.edu Sat May 21 16:11:55 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 21 May 2011 16:11:55 -0400 Subject: checking if a list is empty In-Reply-To: <87r57s6riu.fsf@pobox.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: On 5/21/2011 10:46 AM, John J Lee wrote: > In the absence of an explicit interface declaration (have any standards > emerged for that in Python 3, BTW?), the use of len() does give you some > information about the interface, which sometimes makes it easier to > change the function. > > I'm sure you fully understand this, but I'll spell it out. Consider > this function: > > def xyzzy(x): > if x: > print "yes" To me, this trivial procedure (it is not a mathematical function) is too unrealistic to be a basis for argument. > Let's say I've read the function, and I've seen this call site: > > xyzzy(["spam", "eggs"]) > > Now I want to change xyzzy: > > def xyzzy(x): > if x: > print "probably" > if len(x) == 1: > print "definitely" You are not changing xyzzy, you are replacing a procedure whose domain is all python objects with a new procedure with a much reduced domain. In other words, you are changing (and contracting) the idea of the procedure. This is a somewhat crazy thing to do and if Python developers did something like that in the stdlib, I would expect multiple protest posting ;-). (Adding code to *expand* the domain is a different matter.) If xyzzy were really about sized collections, then 1. That should be documented *before* it is ever used in permanent code. 2. There should be code in the first production version that uses that fact and which would raise an error on other inputs. > But there may be many call sites. Perhaps xyzzy even implements part of > a poorly-documented external API. So can x be None? There's no way to > know short of checking all call sites, which may be impossible. It may > not even be feasible to check the *only* call site, if you're > implementing somebody else's poorly documented closed-source API (a > situation I came across at work only yesterday, when that situation > resulted in a bug report). If it's written this way, it's clear that it > can't be None: > > def xyzzy(x): > if len(x) != 0: > print "yes" I agree that the domain of a function should be defined from the start (and only expanded in the future). This means considering from the start, or certainly once it runs correctly for intended inputs, what will happen for other inputs. For instance, I believe functions defined on counts (0, 1, 2, ...) should be written to avoid infinite looping on other inputs, in particular, fractional and negative numbers. I can imagine in theory that a gratuitous call to len() might be useful for defining an interface, but as explained above, I am dubious about that in practice and do not find thid example convincing. -- Terry Jan Reedy From irmen.NOSPAM at xs4all.nl Sat May 21 17:32:50 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 21 May 2011 23:32:50 +0200 Subject: referring to package scope from module, using relative import? In-Reply-To: References: <4dd81254$0$49046$e4fe514c@news.xs4all.nl> Message-ID: <4dd82f83$0$49042$e4fe514c@news.xs4all.nl> On 21-5-2011 22:00, Ian Kelly wrote: > Note that PEP 8 discourages relative imports and encourages absolute > imports, though. This would be the preferred way to do it: > > from A import something Right. I got rid of the silly relative import stuff. As an added bonus, this makes my original question irrelevant :) Irmen From thorsten at thorstenkampe.de Sat May 21 17:53:16 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 21 May 2011 23:53:16 +0200 Subject: Customize help output from optparse (or argparse) References: <2635961.LZWGnKmheA@PointedEars.de> Message-ID: * Thomas 'PointedEars' Lahn (Thu, 12 May 2011 22:22:20 +0200) > Thorsten Kampe wrote: > > I'm using optparse for a little Python script. > > > > 1. The output from "--help" is: > > """ > > Usage: script.py > > > > script.py does something > > > > Options: > > -h, --help show this help message and exit > > """ > > > > I would prefer to have the description before the usage, like... > > """ > > script.py does something > > > > Usage: script.py > > > > Options: > > -h, --help show this help message and exit > > """ > > [...] > > Is that possible with either optparse or the "new kid on the block" > > argparse. If so how? > > You can easily have #1 with optparse.OptionParser(usage="?")?, but optparse > is deprecated in favor of argparse.ArgumentParser. I'm already using usage. That's where optparse has it from. Putting the usage message into the description and vice versa is of course not a viable way to go. Thorsten From nagle at animats.com Sat May 21 18:55:56 2011 From: nagle at animats.com (John Nagle) Date: Sat, 21 May 2011 15:55:56 -0700 Subject: hash values and equality In-Reply-To: <0deha8-6u9.ln1@satorlaser.homedns.org> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> Message-ID: <4dd84324$0$2192$742ec2ed@news.sonic.net> On 5/19/2011 11:33 PM, Ulrich Eckhardt wrote: > For that reason, it is generally useful to use immutable types like > integers, floats, strings and tuples thereof as keys. Since you can't change > them, you basically have the guarantee that they hash the same. Right. It's something of a lack that Python doesn't have user-defined immutable objects. John Nagle From irmen.NOSPAM at xs4all.nl Sat May 21 19:07:28 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 22 May 2011 01:07:28 +0200 Subject: hash values and equality In-Reply-To: <4dd84324$0$2192$742ec2ed@news.sonic.net> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4dd84324$0$2192$742ec2ed@news.sonic.net> Message-ID: <4dd845b0$0$49047$e4fe514c@news.xs4all.nl> On 22-5-2011 0:55, John Nagle wrote: > On 5/19/2011 11:33 PM, Ulrich Eckhardt wrote: > >> For that reason, it is generally useful to use immutable types like >> integers, floats, strings and tuples thereof as keys. Since you can't change >> them, you basically have the guarantee that they hash the same. > > Right. It's something of a lack that Python doesn't > have user-defined immutable objects. > > John Nagle > collections.namedtuple is rather powerful though... and can be used as key AFAIK. Irmen From bob at mellowood.ca Sat May 21 20:03:12 2011 From: bob at mellowood.ca (bvdp) Date: Sat, 21 May 2011 17:03:12 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: Thanks, Peter, for the detailed explanation. I was going to write a bit of sample/minimal code to demo this, but you nicely beat me to it! > Here's a minimal script to reproduces the problem: > > $ cat tkcallclass.py > import Tkinter as tk > > root = tk.Tk() > root.withdraw() > > class Classic: > ? ? def __init__(self): > ? ? ? ? print "hello" > > button = tk.Button(root, command=Classic) > button.invoke() > $ python2.6 tkcallclass.py > hello > $ python2.7 tkcallclass.py > Traceback (most recent call last): > ? File "tkcallclass.py", line 11, in > ? ? button.invoke() > ? File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 2081, in invoke > ? ? return self.tk.call(self._w, 'invoke') > _tkinter.TclError: invalid command name "__main__.Classic" > $ Any idea why I'm not getting any traceback in my program? It just runs and appears to ignore the callback. > In 2.7 the Tkinter code was changed to use hasattr(obj, "__call__") instead > of callable(obj) to recognize callbacks. This gives different results for > oldstyle classes > > >>> class A: pass > ... > >>> callable(A) > True > >>> hasattr(A, "__call__") > > False > > ...and they are no longer registered automatically with Tkinter. In theory > you could register them explicitly yourself > > $ cat tkcallclass2.py > import Tkinter as tk > > root = tk.Tk() > root.withdraw() > > class Classic: > ? ? def __init__(self): > ? ? ? ? print "hello" > > button = tk.Button(root, command=root.register(Classic)) > button.invoke() > $ python2.7 tkcallclass2.py > hello > > but in practice changing them to newstyle (i. e. have them inherit from > object) or wrapping them in a lambda appears convenient. Yes, I can confirm that both the lambda and setting the class to: class selectFav(object): works. > Personally, I would reconsider whether using a class as a callback is really > necessary. Replacing the class with a function should be a straightforward > process. IIRC, I used the class method since it nicely encapsulates a set of operations: - create/raise a window - list a set of configurable options - have and buttons, both of which destroy the window. Having a function as the callback certainly works as well. Not sure which is the best method in the long run ... I'm trying to use classes more in my programming since it's nice to wrap a bunch of functions up like this. Thanks again. From bob at mellowood.ca Sat May 21 20:07:30 2011 From: bob at mellowood.ca (bvdp) Date: Sat, 21 May 2011 17:07:30 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> <136b3435-a6bd-45fa-9c8c-5602ea23c861@s2g2000yql.googlegroups.com> Message-ID: On May 20, 4:37?pm, rantingrick wrote: > Thats sounds to me a lot like hammering square pegs though round > holes... Perhaps you should explain first in "plain english" what Ahh, but what fun would the Internet, Usenet and programming be without round holes and square pegs. I thought my English was pretty good. > problem your application is intended to solve, then how it is expected I'm trying very much to focus on the problem I'm having with a particular bit of python code. I'm not trying to have the community solve my coding problems. > to interact with the user, and finally, what exactly is NOT working > correctly. I would suffix such a documentary with the current source > code, verbatim. You want me to attach several hundred/thousand lines of source code to demonstrate that a particular bit of python has changed behavior between versions? From steve+comp.lang.python at pearwood.info Sat May 21 20:24:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 May 2011 00:24:35 GMT Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4dd84324$0$2192$742ec2ed@news.sonic.net> Message-ID: <4dd857c3$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 May 2011 15:55:56 -0700, John Nagle wrote: > On 5/19/2011 11:33 PM, Ulrich Eckhardt wrote: > >> For that reason, it is generally useful to use immutable types like >> integers, floats, strings and tuples thereof as keys. Since you can't >> change them, you basically have the guarantee that they hash the same. > > Right. It's something of a lack that Python doesn't > have user-defined immutable objects. Although it's not that hard to write your own immutable (-ish) objects. http://northernplanets.blogspot.com/2007/01/immutable-instances-in-python.html Or see the Decimal and Fraction classes in the standard library. -- Steven From tjreedy at udel.edu Sat May 21 20:33:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 21 May 2011 20:33:22 -0400 Subject: TK program problem In-Reply-To: References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: On 5/21/2011 8:03 PM, bvdp wrote: > Yes, I can confirm that both the lambda and setting the class to: > > class selectFav(object): One of the purposes and advantages of Python 3 is having only one class system. Best to always use new-style classes in Python 2.2+ unless you understand and need old-style classes (and need should be never for most people). -- Terry Jan Reedy. From steve+comp.lang.python at pearwood.info Sat May 21 21:02:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 May 2011 01:02:25 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: <4dd860a1$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 May 2011 15:46:01 +0100, John J Lee wrote: > In the absence of an explicit interface declaration (have any standards > emerged for that in Python 3, BTW?), the use of len() does give you some > information about the interface, which sometimes makes it easier to > change the function. Er, yes? But in any realistic example (your trivial function xyzzyx below is not very realistic) you'll almost certainly get additional hints in the function body. If you have your stereotypical badly-documented function that does this: def spam(x): if x: print("no") # ... x.append(42) # ... that's a hint that x is actually meant to be a list. If instead it says x += 42 that's a good hint that x should not be a list. In either case, changing the test from "if x" to "if x == []" or "if len(x) == 0" or "if x == 0" doesn't gain you anything except a slightly longer average line length. If you're being paid by the character, that's an advantage, but otherwise, why bother? True, if the function is sufficiently trivial, as in your xyzzyx example, then there won't be any such hints as to what sort of input the function expects. If that's the case, then chances are that the function accepts *any* object: > def xyzzy(x): > if x: > print "yes" and changing its semantics to only accept (say) lists, as in your example, is a risky thing to do. It is *much* safer to leave that function untouched, create a new one: def my_xyzzy(alist): if alist: print "probably" if len(alist) == 1: print "definitely" and then change the calls to xyzzyx into my_xyzzyx when and as you determine that it is safe to do so. That will ensure that if you miss a call of xyzzyx(42) somewhere deep in the library, the code will continue to run. If not, you'll have a dead function. You can always take it out later, once you are confident that it is indeed dead code. [...] > If it's written this way, it's clear that it can't be None: > > def xyzzy(x): > if len(x) != 0: > print "yes" But you're assuming that the function actually is intended to accept only objects with a __len__ method. If that is the author's intention, there are better ways of signaling that fact. I'm not entirely sure what your point is... is it to encourage lazy programmers to write "len(x)==0" instead of documentation and meaningful names, or are you just pointing out the occasional silver-lining to a practice which is generally and usually unnecessary? -- Steven From dan.kluev at gmail.com Sat May 21 21:25:21 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 22 May 2011 12:25:21 +1100 Subject: Abandoning Python In-Reply-To: <87ipt46okh.fsf@pobox.com> References: <87ipt46okh.fsf@pobox.com> Message-ID: On Sun, May 22, 2011 at 2:49 AM, John J Lee wrote: > Here's my wishlist (not really in any order): How come pony is not listed there? Language cannot be better than python without pony! > ?* An even larger user base, contributing more and better free and > ? commercial software. According to all language popularity indexes [1-10], C# and Objective-C are only languages which have any chance to fulfill these requirements, but they arguably less flexible than python and have copyright/patent complications. As there is rather heavy inertia in software development community, expecting some language to acquire "even larger user base" is hopeless. Also, most of these complaints could be solved by using correct python dialect for particular task - RPython, Cython and so on. -- With best regards, Daniel Kluev From dan.kluev at gmail.com Sat May 21 21:27:08 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 22 May 2011 12:27:08 +1100 Subject: Abandoning Python In-Reply-To: References: <87ipt46okh.fsf@pobox.com> Message-ID: On Sun, May 22, 2011 at 12:25 PM, Daniel Kluev wrote: > According to all language popularity indexes [1-10], C# and Forgot to include references, although everyone probably already knows them, [1] https://www.ohloh.net/languages?query=&sort=projects [2] http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html [3] http://libresoft.es/debian-counting/lenny/index.php?menu=Statistics [4] http://lang-index.sourceforge.net/ [5] http://langpop.com/ and so on -- With best regards, Daniel Kluev From drsalists at gmail.com Sat May 21 21:39:23 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 21 May 2011 18:39:23 -0700 Subject: Abandoning Python In-Reply-To: <87ipt46okh.fsf@pobox.com> References: <87ipt46okh.fsf@pobox.com> Message-ID: On Sat, May 21, 2011 at 8:49 AM, John J Lee wrote: > > > I still like Python after using it for over a decade, but there are > things I don't like. > > What are your favourite up-and-coming languages of the moment? > > Here's my wishlist (not really in any order): > > * A widely used standard for (optional) interface declaration -- or > something better. I want it to be easier to know what interface an > object has when reading code, and which objects provide that > interface. > I do miss this sometimes, but pylint takes things far enough for me. > * Lower memory usage and faster execution speed. Yes, this has been a > price worth paying. But I do want jam on it, please: give me a > language where I get most of Python's advantages but don't have to > pay it. > PyPy has quite good speed. Memory use, I'm willing to ignore. > * Better support for writing correct programs in the form of better > support for things like non-imperative programming, DBC, etc. (with > the emphasis on "etc"). > And here I thought Python had pretty good functional programming facilities. What do you miss? AFAIK, DBC in terms of "if condition: raise AssertionError" (or assert). What _is_ the "etc"? > * Perhaps better built-in support for common tasks in common application > domains. Concurrency, persistence, database queries come to mind. > http://wiki.python.org/moin/Concurrency/ For persistence, I tend to use gdbm or the dohdbm I just wrote. But there are at least a few other options. For database queries, why build it in? What's wrong with using a module? > * Better refactoring tools, better code analysis tools (lint, search, > etc.). > I find pylint excellent. My idea of a refactoring tool is vim's n.n.n., but have you looked at PyCharm? > * An even larger user base, contributing more and better free and > commercial software. > Gee, you want a scripting language with a larger userbase? > I'm prepared to compromise on the last one. Obviously, it should do all > that while preserving all the nice features of Python -- surely an easy > task. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sat May 21 21:40:52 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 21 May 2011 18:40:52 -0700 Subject: Abandoning Python In-Reply-To: <87boywavsg.fsf@castleamber.com> References: <87ipt46okh.fsf@pobox.com> <87boywavsg.fsf@castleamber.com> Message-ID: On Sat, May 21, 2011 at 9:00 AM, John Bokma wrote: > > A language I want to give a serious try the coming months is Haskell. > > Haskell is indeed interesting. However, do any of Haskell's implementations exploit the opportunities for parallelism that Haskell's definition allows? -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sat May 21 21:43:25 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 21 May 2011 18:43:25 -0700 Subject: Abandoning Python In-Reply-To: References: <87ipt46okh.fsf@pobox.com> Message-ID: On Sat, May 21, 2011 at 6:25 PM, Daniel Kluev wrote: > Also, most of these complaints could be solved by using correct python > dialect for particular task - RPython, Cython and so on. > Cython is an interesting dialect that I use now and then. RPython is probably just as well avoided. PyPy, which is written in RPython and Python, supports Python 2.7 nicely - there's no need to drop down to the level of RPython to get significant performance benefits from PyPy. -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sat May 21 21:50:03 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 21 May 2011 18:50:03 -0700 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 1:47 PM, Dotan Cohen wrote: > They considered Haskell and OCaml and not a single mention of Perl? > Perl is like 10 languages smushed together. To write it, you need only learn one of the 10. To read someone else's, you don't know what subset of those 10 they've used until you get deep into the code. IOW, it's a kitchen sink language - the kind, I believe, that my comparative languages professor would have described as "offensive". -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at mellowood.ca Sat May 21 22:20:22 2011 From: bob at mellowood.ca (bvdp) Date: Sat, 21 May 2011 19:20:22 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: <42561028-39ce-4543-8e3c-b021e3a2b067@34g2000pru.googlegroups.com> > One of the purposes and advantages of Python 3 is having only one class > system. Best to always use new-style classes in Python 2.2+ unless you > understand and need old-style classes (and need should be never for most > people). > Thanks for this. I'll keep it in mind! One thing I really don't understand ... is there a difference between the old/new forms: class foo: class foo(): In cases where I've played with them, they _appear_ to work the same? Also, where does one find the magic that says that for a tkinter class you should use: class foo(object): Not really sure where "object" comes from. Thanks and best, From rosuav at gmail.com Sat May 21 22:56:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 May 2011 12:56:03 +1000 Subject: checking if a list is empty In-Reply-To: <4dd860a1$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> <4dd860a1$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 22, 2011 at 11:02 AM, Steven D'Aprano wrote: > On Sat, 21 May 2011 15:46:01 +0100, John J Lee wrote: > > Er, yes? But in any realistic example (your trivial function xyzzyx below > is not very realistic) you'll almost certainly get additional hints in > the function body. True, but sometimes those hints will be buried in nested calls, making it less obvious. It might well take some digging to figure out just what sort of object it's meant to be accepting. That's why I prefer to have some sort of type declarations; or alternatively, a good docstring / autodoc comment that says what the function wants and gives. Chris Angelico From rustompmody at gmail.com Sat May 21 23:02:03 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 21 May 2011 20:02:03 -0700 (PDT) Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: On May 22, 1:11?am, Terry Reedy wrote: > I agree that the domain of a function should be defined from the start > (and only expanded in the future). I dont understand... I dont always write correct code -- otherwise called 'a bug' -- though I never let the damn bug lose intentionally. And when I see 'the bug' scampering around to my distress the only way of catching it sometimes is to strengthen an (perhaps earlier unthought, unspecified) invariant or precondition. Which amounts to contracting the domain. > This is a somewhat crazy thing to do and if Python developers > did something like that in the stdlib, I would expect multiple protest > posting ;-). That such protests happen is evidence (I dont say proof) that such contractions are sometimes necessary. In fact when I pick up some code marked as 'alpha' I understand it as saying: Please try this and send us (the developers) bug reports. But in no case are we committed to the current API. [Sometimes this is explicitly said. It is always implied by the 'alpha'] When I see 'Beta' I understand: We think this works and we will not make gratuitous changes but no guarantees. When I see 'Stable' I understand: The API is fixed (ie we will not change it) and we accept the inevitable consequence [Seventh Lehman- Belady law: http://en.wikipedia.org/wiki/Lehman%27s_laws_of_software_evolution ] Why is the C library in linux called libc6 and not just libc? From rosuav at gmail.com Sat May 21 23:52:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 May 2011 13:52:05 +1000 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: On Sun, May 22, 2011 at 1:02 PM, rusi wrote: > Why is the C library in linux called libc6 and not just libc? I assume you mean this? http://www.linux-m68k.org/faq/glibcinfo.html When you dynamically link against a shared object, you save on executable size, but you have to have that shared object on the target system. That's completely different from API changes. I could compile my code using half a dozen different compilers, and use dynamic linking each time, and then those six binaries would expect six implementations of libc on the target computer. They're incompatible with each other. But they will all have a size_t strlen(const char *) that tells me how long my string is. Everyone has a different way of handling incompatible API changes. The most common is to simply deprecate the old function and create a new one. It's simple and effective. With your original xyzzy function, create a my_xyzzy as per Steven's suggestion; job done. (I'd assume that a function called "my_xyzzy" is a local override, in the same way that I might write a "my_malloc" that does some statisticking and then returns malloc(sz), but that's one of the consequences of trivia - you can't really name it descriptively.) Chris Angelico From ladasky at my-deja.com Sat May 21 23:58:10 2011 From: ladasky at my-deja.com (John Ladasky) Date: Sat, 21 May 2011 20:58:10 -0700 (PDT) Subject: Multiprocessing: don't push the pedal to the metal? Message-ID: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> Hello again, everyone. I'm developing some custom neural network code. I'm using Python 2.6, Numpy 1.5, and Ubuntu Linux 10.10. I have an AMD 1090T six-core CPU. About six weeks ago, I asked some questions about multiprocessing in Python, and I got some very helpful responses from you all. http://groups.google.com/group/comp.lang.python/browse_frm/thread/374e1890efbcc87b Now I'm back with a new question. I have gotten comfortable with cProfile, and with multiprocessing's various Queues (I've graduated from Pool). I just ran some extensive tests of my newest code, and I've learned some surprising things. I have a pretty picture here (be sure to view the full-size image): http://www.flickr.com/photos/15579975 at N00/5744093219 I'll quickly ask my question first, to avoid a TL;DR problem: when you have a multi-core CPU with N cores, is it common to see the performance peak at N-1, or even N-2 processes? And so, should you avoid using quite as many processes as there are cores? I was expecting diminishing returns for each additional core -- but not outright declines. That's what I think my data shows for many of my trial runs. I've tried running this test twice. Once, I was reading a few PDFs and web pages while my speed test was running. But even when I wasn't using the computer for these other (light) tasks, I saw the same performance drops. Perhaps this is due to the OS overhead? The load average on my system monitor looks pretty quiet to me when I'm not running my program. OK, if you care to read further, here's some more detail... My graphs show the execution times of my neural network evaluation routine as a function of: - the size of my neural network (six sizes were tried -- with varying numbers of inputs, outputs and hidden nodes), - the subprocess configuration (either not using a subprocess, or using 1-6 subprocesses), and - the size of the input data vector (from 7 to 896 sets of inputs -- I'll explain the rationale for the exact numbers I chose if anyone cares to know). Each graph is normalized to the execution time that running the evaluation routine takes on a single CPU, without invoking a subprocess. Obviously, I'm looking for the conditions which yield performance gains above that baseline. (I'll be running this particular piece of code millions of times!) I tried 200 repetitions for each combination network size, input data size, and number of CPU cores. Even so, there was substantial irregularity in the timing graphs. So, rather than connecting the dots directly, which would lead to some messy crossing lines which are a bit hard to read, I fit B-spline curves to the data. As I anticipated, there is a performance penalty that is incurred just for parceling out the data to the multiple processes and collating the results at the end. When the data set is small, it's faster to send it to a single CPU, without invoking a subprocess. In fact, dividing a small task among 3 processes can underperform a two-process approach, and so on! See the leftmost two panels in the top row, and the rightmost two panels in the bottom row. When the networks increase in complexity, the size of the data set for which break-even performance is achieved drops accordingly. I'm more concerned about optimizing these bigger problems, obviously, because they take the longest to run. What I did not anticipate was finding that performance reversal with added computing power for large data sets. Comments are appreciated! From rustompmody at gmail.com Sun May 22 00:32:05 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 21 May 2011 21:32:05 -0700 (PDT) Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: <6bf36a0d-f259-48ad-8f89-2d5688758bf6@l14g2000pro.googlegroups.com> On May 22, 8:52?am, Chris Angelico wrote: > On Sun, May 22, 2011 at 1:02 PM, rusi wrote: > > Why is the C library in linux called libc6 and not just libc? > > I assume you mean this?http://www.linux-m68k.org/faq/glibcinfo.html Ha Ha! Thanks for that link! I quote: > You should not be using libc4 for anything any more. If you do use it, we will hunt you > down and execute you as an example to others. (Not really, but you get the point...) Recently on the emacs list there was a big flame-fest because the behavior (aka interface) of return/newline changed. The argument for change: Can we have emacs behave a little more like a 21st century application? Against: Somebody's scripting code broke badly. You may take any side you like. From rosuav at gmail.com Sun May 22 01:01:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 May 2011 15:01:59 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: On Sun, May 22, 2011 at 11:50 AM, Dan Stromberg wrote: > Perl is like 10 languages smushed together.? To write it, you need only > learn one of the 10. ? To read someone else's, you don't know what subset of > those 10 they've used until you get deep into the code. +1 QOTW. Perl: The Swiss Army Knife of programming languages, including the bit where you can never find the right blade to open up. Chris Angelico From rosuav at gmail.com Sun May 22 01:16:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 May 2011 15:16:35 +1000 Subject: checking if a list is empty In-Reply-To: <6bf36a0d-f259-48ad-8f89-2d5688758bf6@l14g2000pro.googlegroups.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> <6bf36a0d-f259-48ad-8f89-2d5688758bf6@l14g2000pro.googlegroups.com> Message-ID: On Sun, May 22, 2011 at 2:32 PM, rusi wrote: > Recently on the emacs list there was a big flame-fest because the > behavior (aka interface) of return/newline changed. > The argument for change: Can we have emacs behave a little more like a > 21st century application? > Against: Somebody's scripting code broke badly. > > You may take any side you like. The side I take is: If you want emacs, use emacs. If you want SciTE, use SciTE. If you want nano, use nano. And sometimes, you might have special circumstances that demand a different choice (can't use SciTE over ssh, afaik), so it's worth learning more than one. Chris Angelico From hansmeetschool at gmail.com Sun May 22 01:16:51 2011 From: hansmeetschool at gmail.com (Hansmeet Singh) Date: Sat, 21 May 2011 22:16:51 -0700 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: i think we should end our butchering of perl on a light note (you may have already read this): EXTERIOR: DAGOBAH -- DAY With Yoda strapped to his back, Luke climbs up one of the many thick vines that grow in the swamp until he reaches the Dagobah statistics lab. Panting heavily, he continues his exercises -- grepping, installing new packages, logging in as root, and writing replacements for two-year-old shell scripts in Python. YODA: Code! Yes. A programmer's strength flows from code maintainability. But beware of Perl. Terse syntax... more than one way to do it... default variables. The dark side of code maintainability are they. Easily they flow, quick to join you when code you write. If once you start down the dark path, forever will it dominate your destiny, consume you it will. LUKE: Is Perl better than Python? YODA: No... no... no. Quicker, easier, more seductive. LUKE: But how will I know why Python is better than Perl? YODA: You will know. When your code you try to read six months from now. On Sat, May 21, 2011 at 10:01 PM, Chris Angelico wrote: > On Sun, May 22, 2011 at 11:50 AM, Dan Stromberg > wrote: > > Perl is like 10 languages smushed together. To write it, you need only > > learn one of the 10. To read someone else's, you don't know what subset > of > > those 10 they've used until you get deep into the code. > > +1 QOTW. > > Perl: The Swiss Army Knife of programming languages, including the bit > where you can never find the right blade to open up. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jstroud at mbi.ucla.edu Sun May 22 02:02:24 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 21 May 2011 23:02:24 -0700 Subject: count strangeness Message-ID: tal 65% python2.7 Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. py> class C(object): ... def __init__(self): ... self.data = [] ... def doit(self, count=0): ... for c in self.data: ... count += c.doit(count) ... count += 1 ... print count ... return count ... py> c = C() py> c.data.extend([C() for i in xrange(10)]) py> c.doit() 1 2 4 8 16 32 64 128 256 512 1024 1024 WTF? James From crebert at ucsd.edu Sun May 22 02:27:31 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Sat, 21 May 2011 23:27:31 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 11:02 PM, James Stroud wrote: > tal 65% python2.7 > Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > py> class C(object): > ... ? def __init__(self): > ... ? ? self.data = [] > ... ? def doit(self, count=0): > ... ? ? for c in self.data: > ... ? ? ? count += c.doit(count) > ... ? ? count += 1 > ... ? ? print count > ... ? ? return count > ... > py> c = C() > py> c.data.extend([C() for i in xrange(10)]) > py> c.doit() > 1 > 2 > 4 > 8 > 16 > 32 > 64 > 128 > 256 > 512 > 1024 > 1024 > > WTF? Assuming your question is "Why is 1024 there twice?", the answer is that it was the return value of the initial c.doit() call, and the interactive interpreter outputs all non-None expression results; for example: [In the Python REPL] >>> 5 + 5 10 >>> So, you explicitly print the 1024 in your function once, and the interpreter implicitly outputs it the second time. Notice what happens when we use a statement instead of an expression: >>> final = c.doit() 1 2 4 8 16 32 64 128 256 512 1024 >>> final 1024 >>> And if we comment out the `print` in C.doit() and run your example again: >>> c = C() >>> c.data = [C() for i in xrange(10)] >>> c.doit() 1024 >>> Cheers, Chris -- http://rebertia.com From sganapathy.subramanium at gmail.com Sun May 22 02:28:51 2011 From: sganapathy.subramanium at gmail.com (Ganapathy Subramanium) Date: Sun, 22 May 2011 11:58:51 +0530 Subject: Is there a better way to solve this? Message-ID: Hello, I'm a new bie to python programming and on the processing of learning python programming. I have coded my first program of fibonnaci generation and would like to know if there are better ways of achieving the same. I still feel quite a few things to be improved. Just wanted experts thoughts on this. try: length = input('Enter the length till which you want to generate the fibonnaci series: \n') print type(length) except: print 'Invalid input detected' exit(0) if type(length) is int: result = [] a = 0 b = 1 result.append(a) result.append(b) if length > 2: count = 2 while count < length: c = a + b a = b b = c result.append(c) count += 1 else: print result print 'The lenght of result is : ' , len(result) else: print 'Fibonacci series could not be generated !!!' -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sun May 22 02:31:24 2011 From: __peter__ at web.de (Peter Otten) Date: Sun, 22 May 2011 08:31:24 +0200 Subject: count strangeness References: Message-ID: James Stroud wrote: > tal 65% python2.7 > Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > py> class C(object): > ... def __init__(self): > ... self.data = [] > ... def doit(self, count=0): > ... for c in self.data: > ... count += c.doit(count) > ... count += 1 > ... print count > ... return count > ... > py> c = C() > py> c.data.extend([C() for i in xrange(10)]) > py> c.doit() > 1 > 2 > 4 > 8 > 16 > 32 > 64 > 128 > 256 > 512 > 1024 > 1024 > > > > WTF? Put the code into a file, run it -- and be enlightened ;) From jstroud at mbi.ucla.edu Sun May 22 02:32:31 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 21 May 2011 23:32:31 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: Chris Rebert wrote: >> WTF? > > Assuming your question is "Why is 1024 there twice?", the answer is The question is "Why is 1024 there at all?" It should be 10. James From jstroud at mbi.ucla.edu Sun May 22 02:34:56 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 21 May 2011 23:34:56 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: Peter Otten wrote: > James Stroud wrote: >> WTF? > > Put the code into a file, run it -- and be enlightened ;) tal 72% python2.7 eraseme.py 1 2 4 8tal 73% cat eraseme.py #! /usr/bin/env python class C: def __init__(self): self.data = [] def doit(self, count=0): for c in self.data: count += c.doit(count) count += 1 print count return count c = C() c.data.extend([C() for i in xrange(10)]) c.doit() tal 74% python2.7 eraseme.py 1 2 4 8 16 32 64 128 256 512 1024 Hmmm. It's still 1024. What am I missing? James From jstroud at mbi.ucla.edu Sun May 22 02:39:41 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 21 May 2011 23:39:41 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: James Stroud wrote: > Chris Rebert wrote: >>> WTF? >> >> Assuming your question is "Why is 1024 there twice?", the answer is > > The question is "Why is 1024 there at all?" It should be 10. > > James I mean 11, not 10--but you get the point. James From clp2 at rebertia.com Sun May 22 02:42:00 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 21 May 2011 23:42:00 -0700 Subject: Is there a better way to solve this? In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 11:28 PM, Ganapathy Subramanium wrote: > Hello, > > I'm a new bie to python programming and on the processing of learning python > programming. I have coded my first program of fibonnaci generation and would > like to know if there are better ways of achieving the same. > > I still feel quite a few things to be improved. Just wanted experts thoughts > on this. > > try: > > ??? length = input('Enter the length till which you want to generate the > fibonnaci series: \n') > ??? print type(length) > > except: > ??? print 'Invalid input detected' > ??? exit(0) Never use the input() function in Python 2.x; it does an eval(), which is evil. Always use raw_input() and an explicit conversion instead; e.g. Q = 'Enter the length till which you want to generate the fibonnaci series: \n' try: length = int(raw_input(Q)) except ValueError: print 'Invalid input detected' exit(0) Also, as a sidenote: > if type(length) is int: Is normally written: if isinstance(length, int): Cheers, Chris -- http://rebertia.com From crebert at ucsd.edu Sun May 22 02:55:46 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Sat, 21 May 2011 23:55:46 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 11:32 PM, James Stroud wrote: > Chris Rebert wrote: >>> >>> WTF? >> >> Assuming your question is "Why is 1024 there twice?", the answer is > > The question is "Why is 1024 there at all?" It should be 10. Ah. This is why it's better to be more explicit about what your question is than a mere "WTF?". In that case, I believe you meant to write: count += c.doit() rather than: count += c.doit(count) Recall that count is continually increasing as you go through your loop. Although you'll then get 11, not 10, but the cause of that is obvious (`count += 1`). Cheers, Chris -- http://rebertia.com From jstroud at mbi.ucla.edu Sun May 22 02:56:36 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 21 May 2011 23:56:36 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: Peter Otten wrote: > James Stroud wrote: >> WTF? > > Put the code into a file, run it -- and be enlightened ;) Compare the follower to the last. tal 77% cat eraseme.py #! /usr/bin/env python class C: def __init__(self): self.data = [] def doit(self, count=[0]): for c in self.data: c.doit() count[0] += 1 print count[0] c = C() c.data.extend([C() for i in xrange(10)]) c.doit() tal 78% python2.7 eraseme.py 1 2 3 4 5 6 7 8 9 10 11 James From jstroud at mbi.ucla.edu Sun May 22 03:03:05 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 22 May 2011 00:03:05 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: Chris Rebert wrote: > On Sat, May 21, 2011 at 11:32 PM, James Stroud wrote: >> Chris Rebert wrote: >>>> WTF? >>> Assuming your question is "Why is 1024 there twice?", the answer is >> The question is "Why is 1024 there at all?" It should be 10. > > Ah. This is why it's better to be more explicit about what your > question is than a mere "WTF?". > > In that case, I believe you meant to write: > count += c.doit() > rather than: > count += c.doit(count) I get it. Thank you. James From __peter__ at web.de Sun May 22 03:13:44 2011 From: __peter__ at web.de (Peter Otten) Date: Sun, 22 May 2011 09:13:44 +0200 Subject: count strangeness References: Message-ID: James Stroud wrote: > Peter Otten wrote: >> James Stroud wrote: >>> WTF? >> >> Put the code into a file, run it -- and be enlightened ;) > > > tal 72% python2.7 eraseme.py > 1 > 2 > 4 > 8tal 73% cat eraseme.py > #! /usr/bin/env python > > class C: > def __init__(self): > self.data = [] > def doit(self, count=0): > for c in self.data: > count += c.doit(count) > count += 1 > print count > return count > > c = C() > c.data.extend([C() for i in xrange(10)]) > c.doit() > tal 74% python2.7 eraseme.py > 1 > 2 > 4 > 8 > 16 > 32 > 64 > 128 > 256 > 512 > 1024 > > > Hmmm. It's still 1024. > > What am I missing? > > James Like Chris I assumed that you wondered why 1024 appeared twice. It turns out WTF is not a got a good problem description. Now for a complete run-through, the inner c.doit() has len(c.data) == 0, so count += c.doit(count) just adds count + 1 and you get 10 iterations: (1) count=0, print 1, add 1 (2) count=1, print 2, add 2 (3) count=3, print 4, add 4 (4) count=7, print 8, add 8 (5) you get the idea Another way to look at it: in your special case the inner loop can be rewritten as for c in self.data: print count + 1 count += count + 1 From orasnita at gmail.com Sun May 22 03:44:18 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Sun, 22 May 2011 10:44:18 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: <9CDC4B2CD1F445E994119A50F65155DF@teddy> From: "Hansmeet Singh" >i think we should end our butchering of perl on a light note (you may have > already read this): > EXTERIOR: DAGOBAH -- DAY > With Yoda strapped to his back, Luke climbs up one of > the many thick vines that grow in the swamp until he > reaches the Dagobah statistics lab. Panting heavily, he > continues his exercises -- grepping, installing new > packages, logging in as root, and writing replacements for > two-year-old shell scripts in Python. > > YODA: Code! Yes. A programmer's strength flows from code > maintainability. But beware of Perl. Terse syntax... more > than one way to do it... default variables. The dark side > of code maintainability are they. Easily they flow, quick > to join you when code you write. If once you start down the > dark path, forever will it dominate your destiny, consume > you it will. > > LUKE: Is Perl better than Python? > > YODA: No... no... no. Quicker, easier, more seductive. > > LUKE: But how will I know why Python is better than Perl? > > YODA: You will know. When your code you try to read six months > from now. > I've noticed that on many Perl mailing lists the list members talk very rarely about Python, but only on this Python mailing list I read many discussions about Perl, in which most of the participants use to agree that yes, Python is better, as it shouldn't be obvious that most of the list members prefer Python. If Python would be so great, you wouldn't talk so much about how bad are other languages, or if these discussions are not initiated by envy, you would be also talking about how bad is Visual Basic, or Pascal, or Delphi, or who knows other languages. A few months ago I have asked how can I create a dictionary from a list, and there were so many techniques that I think that it is just a buzzword that in Perl there are many ways to do it, while in Python there is a single way. In Python I found from the messages I received on this mailing list that there are a lot of ways, without even beeing a "recommended" way, while in Perl there is a single way, of course much shorter and clearer. A bad program can be written in any language, no matter if it is so strict and forces the programmer to use spaces as a way of defining the blocks of code, so the fact that Perl is very flexible is an advantage for the programmer who writes the code. Perl offers the module Perl::Critic which offers a command line that checks the code for different levels of syntax errors which don't respect the good practices (which are also published in a book) so if the program has to be used by more programmers, it is very simple to bring it to a very standard syntax. Perl also has Perl::Tidy that offers another command line which re-arrange the code to a standard way, including the indentation type, the placement of parenthesis, spacing and other things, so the programs can look visually the same. And these are advantages for those that need to read the code by others also. Because of its flexibility, Perl offers more advanced modules and libraries which are not available for Python. For example, Catalyst web framework is much powerful and flexible than any other Python framework, because it can be used with any ORM, with any templating system, with any form processor, with any type of configuration files (Apache style, ini, JSON, XML, perl data structures, yaml), and it can run with its own web server, or with mod_perl, FastCGI, cgi, psgi without any change, and it has a very clean and flexible URL dispatcher that doesn't need to do (and maintain) the URL mapping in a distinct module made only for this. A Catalyst based application is very easy to maintain because it has a very clean structure and the command lines that can be used to automaticly generate the base for controllers, models or views also generate the base test files and also create a few basic tests for the created modules, beeing very easy to add new tests. And DBIx::Class ORM is a very powerful ORM and Template-Toolkit a great templating system, and Moose can be used to create a very powerful object model, and there are a lot of other very good modules which are not available for other languages. It can be hard to find the good quality Perl code while you don't know where to look for though. This is right, because the web is full of old-style Perl code since the era of Matt's Perl script archive, and the web is also full of pirated books about using CGI, but talking about that bad style code shows just that you are talking about something you don't know. Somebody told that C# and Objective C are good languages. They might be good, but they are proprietary, and not only that they are proprietary, but they need to be ran under platforms that cannot be used freely, so from the freedom point of view, Perl, Ruby, Python and Java are the ways to go. Octavian From rustompmody at gmail.com Sun May 22 04:13:04 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 22 May 2011 01:13:04 -0700 (PDT) Subject: more than just ipython broken in windows Message-ID: Earlier I asked about a problem with ipython in windows which does not seem to be there in linux. Now I find that a similar problem surfaces with turtle -- so it seemingly is not so much an ipython problem. The problem can be seen thus: Lets say I want to try out some turtle commands such as: ---------------- from turtle import * forward(100) left(90) forward(200) ------------- Run from a file there's no issue. Likewise I can run these commands one after the other from an interactive prompt in a shell and they work as expected. But if I run these commands one after another at the interactive prompt inside emacs, it hangs after the first forward(100) ie the canvas and a line and arrow come up but control does not seem to return to the prompt. ---------------- More general question: When a question was asked: "Which IDE you use for python development?", 'emacs' was a frequent response. Are any of you emacs+python users on windows? [Or am I a dinosaur?] From dan.kluev at gmail.com Sun May 22 04:20:49 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 22 May 2011 19:20:49 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <9CDC4B2CD1F445E994119A50F65155DF@teddy> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> Message-ID: On Sun, May 22, 2011 at 6:44 PM, Octavian Rasnita wrote: > Because of its flexibility, Perl offers more advanced modules and libraries which are not available for Python. What 'flexibility' are you talking about? This seem to be very biased statement, based on lack of according python experience. There are many python web frameworks which allow you to use w/e interfaces, template languages and ORMs you want - Pyramid/Pylons is good example. 'Very powerful' and 'great' are 'very useless' descriptions of these modules. Please, show us what exactly is so 'advanced' about them which cannot be done in python. -- With best regards, Daniel Kluev From hobson42 at gmail.com Sun May 22 05:20:00 2011 From: hobson42 at gmail.com (Ian) Date: Sun, 22 May 2011 10:20:00 +0100 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4DCAF95B.60307@gmail.com> Message-ID: <4DD8D540.7020703@gmail.com> On 12/05/2011 04:51, Chris Angelico wrote: > On Thu, May 12, 2011 at 7:02 AM, Ian wrote: >> In the "real world" lists of zero items do not exist. >> You don't go shopping with a shopping list of zero items. > Actually, yes you do. You maintain your shopping list between trips; > whenever you need something, you put it on the list immediately. Then > when you go shopping, you just take the list with you (if you're > lucky, you don't need to move or copy it at all, you just get another > reference to it). Once you're done, you empty the list - you now have > a shopping list with zero items (until you get home and realize you > forgot something). > > Chris Angelico He He. I didn't claim an empty list was not useful! If you maintain it between trips, then yes, you arrive back with an empty list. Ian From kushal.kumaran+python at gmail.com Sun May 22 06:04:08 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sun, 22 May 2011 15:34:08 +0530 Subject: how to get PID from subprocess library In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 6:20 PM, TheSaint wrote: > Kushal Kumaran wrote: > >> That's how it is able to give you the status. ?So, if you >> are using getstatusoutput, you will have only one instance of your >> command running. > > My intent is to launch only one program instance, which will goes as daemon. > To avoid a second call I'd like rather to use Python than > ==============================code========================================= > ? ?def start(self): > ? ? ? ?'''try to start aria2c as a daemon and return its handle to where it > can > ? ? ? ?proceed to issue commands''' > > ? ? ? ?# aria2c is running, then don't try it again > ? ? ? ?if (chkout('ps -A |grep aria2c')[0] > 0): > ? ? ? ? ? ?try: > ? ? ? ? ? ? ? ?chkout(self.ARIA_CMD) > ? ? ? ? ? ?except: > ? ? ? ? ? ? ? ?raise SystemExit('aria2c is not working as deamon') > ? ? ? ?elif self.handle: return self.handle > ? ? ? ?# everything is good, it will return an handle > ? ? ? ?self.handle= \ > ? ? ? ?xmlrpclib.ServerProxy('http://localhost:%s/rpc' %int(self.numport)) > ? ? ? ?return self.handle > ==============================code========================================= > > Here I've named subprocess.getstatusoutput as chkout, I'm calling 2 more > programs to find whether there's a running instance of aria2c. I think it's > not nice, python libraries should get the matter done. > Unfortunately, because of the way daemons work, you will not be able to do this (there's some trickery with ptrace and similar tools, but surely there must be simpler ways for you). Here's a very simplified view of a typical daemon's startup: - your process (let's call it pid1) starts a program which says it will daemonize (let's call it pid2). - pid2 forks an additional process (pid3), then pid2 exits - pid1 gets the exit status of its own child (pid2) Accordingly, even if you get a PID, it will only be pid2, which is not the PID of the daemon process. You will need some other way of getting at the daemon's PID. You could look for a way to make aria2c not become a daemon and use subprocess.Popen to start it. That gives you the PID and ways to see if the process is still running. -- regards, kushal From orasnita at gmail.com Sun May 22 08:47:33 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Sun, 22 May 2011 15:47:33 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy> Message-ID: <12225671E9654FECB49613D915FAEC19@teddy> From: "Daniel Kluev" > On Sun, May 22, 2011 at 6:44 PM, Octavian Rasnita wrote: >> Because of its flexibility, Perl offers more advanced modules and libraries which are not available for Python. > > What 'flexibility' are you talking about? This seem to be very biased > statement, based on lack of according python experience. I am talking about that flexibility which was criticized in the previous messages telling that this flexibility allows any programmer to use his own way. Perl doesn't force anyone to indent the code, don't force the programmer to define a hash element before using it, allow the programmer to interpret the variables in strings directly. These things should be not used always, but if in some cases if the programmer wants to use them, he can use them with no problems. And this means flexibility. > There are many python web frameworks which allow you to use w/e > interfaces, template languages and ORMs you want - Pyramid/Pylons is > good example. > 'Very powerful' and 'great' are 'very useless' descriptions of these > modules. Please, show us what exactly is so 'advanced' about them > which cannot be done in python. Every language can do almost anything, so this is not important, because the Python programmers didn't chose Python because it can do what other languages cannot do. It is important how easy is to create an app with it, and while Python offers helpful features for creating desktop apps, for creating web apps Perl is better. Here is a text from the documentation of Pyramid/Pylons: "We finally need to add some routing elements to our application configuration if we want our view functions to be matched to application URLs. ... # routes setup config.add_route('list', '/') config.add_route('new', '/new') config.add_route('close', '/close/{id}') " ... First, this is a bad style of mapping urls, because this list must be maintained every time the programmer changes something in a controller that makes the app need to use other urls. Catalyst don't need this overhead and don't need to specify the url mapping in a separate module. If the controllers change, then the url dispatching also changes. Second, this way of url dispatching is not so flexible, because it doesn't allow as many types of url mappings. Catalyst allows to dispatch the urls to actions based on controllers and subroutines names, globally or locally (based on the current controller), it allows dispatching based on regular expressions, it allows a chained dispatch where more actions are executed in a certain order on a single request, and all these without typing code outside of the subroutines that do the actions. The module DBIx::Class which is used usually as an ORM can create the class files for all the tables from a database (MySQL, Oracle, PostgreSQL, SQLite, MS SQL, etc), and it can be used to search using unions, sub-selects, can define views at ORM level, can accept to insert different types of objects like DateTime objects and can also return those type of objects, and many other things, and most of the things it can do can be done without using SQL code at all, but only standard Perl code and Perl data structures. HTML::FormFu form processor is one of the most used form processors in Catalyst applications and it can generate and parse forms created directly in the code of the application, or as external configuration files defined using JSON, or YAML, or Apache configuration style, or Perl data structures, or XML... The forms defined are very easy to create and the elements from those forms, for example the list of elements in a combo box can be taken directly from a database by specifying just a few configuration elements. The results of a form submit can be also inserted in a database using a connector with DBIx::Class without specifying any database table column name in the programming code, and for doing this are required just a few lines of code that checks if the $form->submitted_and_valid() and that does the redirection after the submit, the insertion in the database requiring just: $form->model->create; or $form->model->update( $db_record ); ...after that record was defined using just something like: my $db_record = $c->model( 'DB::TableName' )->find( $record_id ); And HTML::FormFu can do filtering based on many conditions, impose the specified constraints, specify different inflators/deflators from the inserted strings to their corresponding object types, do a validation eventualy based on a database query that checks for duplicates or other things, transform the data automaticly after the form was processed, can use I18N for displaying the field labels or values translated in the active language, have its own rendering engine or can render custom form fields made using Template-Toolkit, etc. Yes, for web apps I have seen more things which can be done much better in Perl, much easier and clear, with less code, and not because the programmer needs to do not-recommended tricks for shortening the code, but because there are very many modules on CPAN that do the hard work. Octavian From roy at panix.com Sun May 22 09:36:51 2011 From: roy at panix.com (Roy Smith) Date: Sun, 22 May 2011 09:36:51 -0400 Subject: count strangeness References: Message-ID: In article , James Stroud wrote: > tal 65% python2.7 > Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > py> class C(object): > ... def __init__(self): > ... self.data = [] > ... def doit(self, count=0): > ... for c in self.data: > ... count += c.doit(count) > ... count += 1 > ... print count > ... return count > ... > py> c = C() > py> c.data.extend([C() for i in xrange(10)]) > py> c.doit() I have no idea what this is *supposed* to be doing, so let me toss out some general debugging ideas; 1) What do you expect [C() for i in xrange(10)] to return? Does it? Run that part in isolation and see if it does. 2) What do you expect c.data.extend([...]) to return? Does it? 3) What do you expect c.doit() to return for trivial inputs? Does it? Try calling it with a count of 0, 1, and 2, and see if you get the result you expect. In other words, break the problem down into smaller pieces and make sure each piece works in isolation. When you find some little piece which isn't doing what you expect, it'll be much easier to debug than trying to debug the whole thing at once. From nobody at nowhere.net.no Sun May 22 09:41:50 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 22 May 2011 21:41:50 +0800 Subject: how to get PID from subprocess library References: Message-ID: Kushal Kumaran wrote: > You could look for a way to make aria2c not become a daemon and use > subprocess.Popen to start it. That gives you the PID and ways to see > if the process is still running I see. It's a step that I've to get on my account. Unfortunately I'll have to study it some more. BTW. I removed grep from the command. Python does it with the *in* statement :) -- goto /dev/null From s.selvamsiva at gmail.com Sun May 22 09:42:08 2011 From: s.selvamsiva at gmail.com (Selvam) Date: Sun, 22 May 2011 19:12:08 +0530 Subject: Hotshoting recursive function Message-ID: Hi, I am using hotshot module to profile my python function. I used the details from ( http://code.activestate.com/recipes/576656-quick-python-profiling-with-hotshot/ ). The function I profile is a recursive one and I am getting the following error, "ProfilerError: profiler already active" I guess this is due to the recursive call to the profiling function. I would like to get some suggestions. -- Regards, S.Selvam SG E-ndicus Infotech Pvt Ltd. http://e-ndicus.com/ " I am because we are " -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Sun May 22 10:03:29 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 22 May 2011 07:03:29 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: <5a309bd1-71e1-4c78-a304-24552b1c5da5@m40g2000vbt.googlegroups.com> On May 21, 7:03?pm, bvdp wrote: > IIRC, I used the class method since it nicely encapsulates a set of > operations: > > ? ?- create/raise a window > ? ?- list a set of configurable options > ? ?- have and buttons, both of which destroy the > window. Ok NOW we are getting somewhere! It is amazing how helpful people can be when you explain your problem in "plain English". What you are describing here is a dialog (be it modal or not). However your earlier description of... """Yes, the class is instantiated when the button is clicked. Then, the user stays in the class and uses its methods until he hits in the class. """ ... was about as effective as the "orb of confusion" on Patrick... *drool* > Having a function as the callback certainly works as well. Not sure > which is the best method in the long run ... I'm trying to use classes > more in my programming since it's nice to wrap a bunch of functions up > like this. Yes you ABSOLUTELY SHOULD encapsulate the dialog code in a class! THEN create an instance of the class inside a "easy to call" function. class MyDialog(blah): blah,blah,blah def show_dialog(*args): d = MyDialog(*args) return d.result result = show_dialog() ...and they all lived happily ever after ;-) From rosuav at gmail.com Sun May 22 10:25:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 00:25:06 +1000 Subject: TK program problem In-Reply-To: <5a309bd1-71e1-4c78-a304-24552b1c5da5@m40g2000vbt.googlegroups.com> References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <5a309bd1-71e1-4c78-a304-24552b1c5da5@m40g2000vbt.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 12:03 AM, rantingrick wrote: > ... was about as effective as the "orb of confusion" on Patrick... > *drool* > That sounds like a Dungeons and Dragons artifact item... invoking the orb of confusion is a standard action that does not provoke an Attack of Opportunity. > class MyDialog(blah): > blah,blah,blah > > def show_dialog(*args): > d = MyDialog(*args) > return d.result > > result = show_dialog() I don't really see why it shouldn't be valid to use the class itself in this way. Once the constructor returns, the object IS the return value. But then, my opinion may not be valid. I've done weird things in C++ where, for instance, the invocation of a modeless dialog is: new FoobarDialog(params); And somewhere it has an event (eg when the window is destroyed) that executes: delete this; I'm a little mad and generally silly, so my opinion doesn't matter (matter matter matter matter). But it did work, and the code was nice and clean! Chris Angelico From bahamutzero8825 at gmail.com Sun May 22 10:35:58 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 22 May 2011 09:35:58 -0500 Subject: List of WindowsError error codes and meanings In-Reply-To: <8762p48eel.fsf@pobox.com> References: <8762p48eel.fsf@pobox.com> Message-ID: <4DD91F4E.3050206@gmail.com> On 2011.05.21 06:46 AM, John J Lee wrote: > Since Python 2.5, the errno attribute maps the Windows error to error > codes that match the attributes of module errno. I was able to whip up a nifty little function that takes the output of sys.exc_info() after a WindowsError and return the error code. I was mistaken in my earlier post about sys.exc_info()[1][0] - I hadn't noticed the 'WindowsError' bit before the opening parenthesis and mistook it for a tuple (it's a WindowsError object). Anyway: > def find_win_error_no(error_msg): > """ > error_msg is a string with the error message - typically > sys.exc_info()[1] from a WindowsError exception > Returns the number as a string, not an int > """ > win_error_re = re.compile('\[Error \d{1,5}\]') > win_error_num_re = re.compile('\d{1,5}') > win_error = win_error_re.findall(error_msg)[0] > return win_error_num_re.findall(win_error)[0] I call it here: > def make_prog_dir(dir): > try: > os.mkdir(dir) > except WindowsError: > error_info = str(sys.exc_info()[1]) > num = find_win_error_no(error_msg=error_info) > if num == '183': # Error 183 = 'Cannot create a file when that > file already exists' > logger.debug(dir + ' exists.') # Ignore the error, but > make a note > elif num == '5': # Error 5 = 'Access is denied' > logger.critical('Could not create', dir, '\(access denied\).') > else: > logger.critical('Could not create', dir, '-', error_info) Errors 183 and 5 are going to be the most common, but I'll look at the lists on MSDN to see if there's anything else worth adding (and familiarize myself with any more common errors). From felipe.vinturini at gmail.com Sun May 22 11:45:22 2011 From: felipe.vinturini at gmail.com (GMail Felipe) Date: Sun, 22 May 2011 12:45:22 -0300 Subject: how to get PID from subprocess library In-Reply-To: References: Message-ID: <70742457-7202-4DB7-B970-8E5568081521@gmail.com> On 22/05/2011, at 10:41, TheSaint wrote: > Kushal Kumaran wrote: > >> You could look for a way to make aria2c not become a daemon and use >> subprocess.Popen to start it. That gives you the PID and ways to see >> if the process is still running > > I see. It's a step that I've to get on my account. Unfortunately I'll have > to study it some more. > > BTW. I removed grep from the command. Python does it with the *in* statement > :) > > > -- > goto /dev/null > -- > http://mail.python.org/mailman/listinfo/python-list Hi, For the "ps" command, have you seen the psuti module? The link to it is: http://code.google.com/p/psutil/ Regards, Felipe. From jjl at pobox.com Sun May 22 11:58:09 2011 From: jjl at pobox.com (John J Lee) Date: Sun, 22 May 2011 16:58:09 +0100 Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: <87sjs6enhq.fsf@pobox.com> Daniel Kluev writes: > On Sun, May 22, 2011 at 2:49 AM, John J Lee wrote: >> Here's my wishlist (not really in any order): > > How come pony is not listed there? Language cannot be better than > python without pony! Pony, absolutely. I took that as read. >> ?* An even larger user base, contributing more and better free and >> ? commercial software. [...] > As there is rather heavy inertia in software development community, > expecting some language to acquire "even larger user base" is > hopeless. I did say I was prepared to compromise on that one. After all, when I started using Python it was a lot smaller that it is now. If a language is good enough to tempt me away from Python, probably the same is true for other people too -- as it was with Python a decade or so ago. > Also, most of these complaints could be solved by using correct python > dialect for particular task - RPython, Cython and so on. Different topic. John From jjl at pobox.com Sun May 22 13:11:17 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 17:11:17 +0000 (UTC) Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: Bill Allen gmail.com> writes: > You have ideas, a text editor, and a computer - best get to coding. > What's stopping you? You largely want Python, with modifications. > Join the development team and help implement those changes, or fork > your own flavor and do what you wish. Right? You imagine it's an > easy task, so get after it. [...] Is it possible that my calling it an easy task was a joke? Honestly, I'd thought it safe with that one to leave out the smiley -- but then I've been away from newsgroups for quite a while! John From jjl at pobox.com Sun May 22 13:33:29 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 17:33:29 +0000 (UTC) Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: Dan Stromberg gmail.com> writes: > On Sat, May 21, 2011 at 8:49 AM, John J Lee pobox.com> wrote: > > I still like Python after using it for over a decade, but there are > things I don't like. > What are your favourite up-and-coming languages of the moment? > Here's my wishlist (not really in any order): > ?* A widely used standard for (optional) interface declaration -- or > ? something better. ?I want it to be easier to know what interface an > ? object has when reading code, and which objects provide that > ? interface. > > > I do miss this sometimes, but pylint takes things far enough for me.? Pylint? Does it provide some kind of guessed-at-type that has been integrated with IDEs? [...] > And here I thought Python had pretty good functional programming facilities. > What do you miss?AFAIK, DBC in terms of "if condition: raise AssertionError" > (or assert).What _is_ the "etc"? [...more of the same...] You tell me: I'm here to fish for interesting pointers rather than to evangelize. I mention those specific things as examples because I know they have often been both the focus of research (well, perhaps not integration of queries), and pain points in software development. It's not plausible to me that there is not room for major improvement, but in any case the only way to know is to try. > ?* Better refactoring tools, better code analysis tools (lint, search, > ? etc.). > > I find pylint excellent.? My idea of a refactoring tool is vim's n.n.n.,? but have you looked at PyCharm?? In this thread, I'm asking about the views of Python programmers on languages other than Python. Thanks for the link, though (does PyCharm provide reliable refactoring tools that are useable from emacs?). > ?* An even larger user base, contributing more and better free and > ? commercial software. > > Gee, you want a scripting language with a larger userbase?? I don't want a scripting language, necessarily. John From jjl at pobox.com Sun May 22 13:55:04 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 17:55:04 +0000 (UTC) Subject: List of WindowsError error codes and meanings References: <8762p48eel.fsf@pobox.com> Message-ID: Genstein invalid.invalid> writes: > > > Andrew Berg gmail.com> writes: > > Since Python 2.5, the errno attribute maps the Windows error to error > > codes that match the attributes of module errno. > > Good point, I completely misread that. At least the Windows error code > is still available as the winerror attribute. > > As an aside - call me stupid, but I don't quite follow the purpose of > that errno mapping. Surely if the error number can be mapped > successfully then the error isn't Windows specific and an OSError should > logically be thrown instead? And if it can't be mapped successfully then > errno will never be valid so the mapping is pointless? Since WindowsError is a subclass of OSError, .errno has to be there (and it must contain the UNIXy error code). You could then ask why it's a subclass in the first place. I think part of the answer is that the docs are wrong -- presumably actual usage is that WindowsError is raised when a Windows API call is made that *may* result in an exception that has no corresponding errno value ("presumably" because I'm writing on Linux & sourceforge is too slow for me today to grab pywin32). In other words, code that raises WindowsError doesn't try to test the error code so that it can raise OSError instead some of the time. I don't think there would be any benefit in doing that, and it would have the disadvantage that with those calls, you'd have to deal with a mixture of Windows and UNIXy error codes. The presence of .errno, aside from being required (to satisfy LSP), does mean you don't have to deal with the Windows codes if you're only interested in cases covered by module errno. John From stefan_ml at behnel.de Sun May 22 13:55:25 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 22 May 2011 19:55:25 +0200 Subject: Abandoning Python In-Reply-To: <87sjs6enhq.fsf@pobox.com> References: <87ipt46okh.fsf@pobox.com> <87sjs6enhq.fsf@pobox.com> Message-ID: John J Lee, 22.05.2011 17:58: > Daniel Kluev writes: >> Also, most of these complaints could be solved by using correct python >> dialect for particular task - RPython, Cython and so on. > > Different topic. Why? Stefan From jjl at pobox.com Sun May 22 14:26:42 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 18:26:42 +0000 (UTC) Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> <87sjs6enhq.fsf@pobox.com> Message-ID: Stefan Behnel behnel.de> writes: > > John J Lee, 22.05.2011 17:58: > > Daniel Kluev writes: > >> Also, most of these complaints could be solved by using correct python > >> dialect for particular task - RPython, Cython and so on. > > > > Different topic. > > Why? The intended focus was "things other than Python". RPython and Cython are languages other than Python, but I regard them as part of the Python, er, ecosystem. They have advantages and drawbacks that a lot of us are already familiar with (even though in your position I imagine you notice the misconceptions more than the correct ones). The thought behind my question was to get Pythonista's opinions about things outside of that. John From patrick.just4fun at gmail.com Sun May 22 14:34:38 2011 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Sun, 22 May 2011 20:34:38 +0200 Subject: Dealing with name clashes in pypi Message-ID: <4DD9573E.8010509@gmail.com> I wanted to register my project (epdb) in pypi. Unfortunately there already exists a project with the same name. It is not possible for me to change the name of the project, because I used it in multiple writings. Any ideas how I can deal with the situation? Is it possible to register a project under a different name in pypi than the actual project name? -- Patrick From stef.mientki at gmail.com Sun May 22 15:23:03 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 22 May 2011 21:23:03 +0200 Subject: and becomes or and or becomes and Message-ID: <4DD96297.5010909@gmail.com> hello, must of us will not use single bits these days, but at first sight, this looks funny : >>> a=2 >>> b=6 >>> a and b 6 >>> a & b 2 >>> a or b 2 >>> a | b 6 cheers, Stef From e_d_k at yahoo.com Sun May 22 16:01:03 2011 From: e_d_k at yahoo.com (Ed Keith) Date: Sun, 22 May 2011 13:01:03 -0700 (PDT) Subject: Abandoning Python In-Reply-To: Message-ID: <595378.58400.qm@web120504.mail.ne1.yahoo.com> Have you looked at Falcon (http://www.falconpl.org/)? It seems to have a lot of what you are looking for. I do not have much experience with it but I like what I've seen so far, except that there are not any third party tools or libraries libraries. Which is where Python shines. -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From zdoor at xs4all.nl Sun May 22 16:13:07 2011 From: zdoor at xs4all.nl (Alex van der Spek) Date: Sun, 22 May 2011 22:13:07 +0200 Subject: Tkinter FileDialog Message-ID: <4dd96e57$0$49044$e4fe514c@news.xs4all.nl> Trying to bring up a simple File or Directory chooser using Tkinter. Right now I use pywin32 as Mark Hammond's extensions are somewhat more familiar to an (ex)VB programmer who started way back with Fortran. On Windows Vista with Python 2.7. The examples from Mark Lutz' book "Programming Python" do not immediately apply. The book describes Python 3.x only. This is what I do (in IDLE): import tkFileDialog as tk file2open=tk.Open().show() This works. But it also brings up a persistent Tk window. Killing this window forces a restart in IDLE, which is not desirable. There does not appear to be a way to multiselect files? I am probably missing a whole lot. Please point me to a simple example of GUI file manipulations. I can save myself with os.path.walk and os.listdir but the users I try to serve cannot. Regards, Alex van der Spek From xahlee at gmail.com Sun May 22 16:22:15 2011 From: xahlee at gmail.com (Xah Lee) Date: Sun, 22 May 2011 13:22:15 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> Xah wrote: ?In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it possibly mean by the word ?recursive? there? Like, it might delete the directory but not delete all files in it? ? Jonathan de Boyne Pollard wrote: > It might *try* to delete the directory but not any of its contents, > yes. you mean theoretically you see a possibility if the dir is implement as stilted as unix, but never in your life you find yourself might want to do it? Xah From drsalists at gmail.com Sun May 22 16:32:11 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 22 May 2011 13:32:11 -0700 Subject: Abandoning Python In-Reply-To: References: <87ipt46okh.fsf@pobox.com> Message-ID: On Sun, May 22, 2011 at 10:33 AM, John Lee wrote: > Dan Stromberg gmail.com> writes: > > > On Sat, May 21, 2011 at 8:49 AM, John J Lee pobox.com> wrote: > > > > I still like Python after using it for over a decade, but there are > > things I don't like. > > What are your favourite up-and-coming languages of the moment? > > Here's my wishlist (not really in any order): > > * A widely used standard for (optional) interface declaration -- or > > something better. I want it to be easier to know what interface an > > object has when reading code, and which objects provide that > > interface. > > > > > > I do miss this sometimes, but pylint takes things far enough for me. > > Pylint? Does it provide some kind of guessed-at-type that has been > integrated > with IDEs? > Pylint does type inferencing - I find it very valuable on large projects, and even some not-so-large projects. I doubt Pylint's been integrated into any IDE's, but ISTR that there's an IDE out there that has pyflakes in it. I suspect PyCharm does its own type stuff. I've heard (but not tried) that vim can have pyflakes integrated into it. For emacs, I really don't know. I'm more of a vim perrson, but I've considered switching to PyCharm by JetBrains - people in the Java world really seem to like what JetBrains did for Java, and PyCharm purportedly has vi keybindings, so I shouldn't end up typing way too many keystrokes for the same tasks. > > > * Better refactoring tools, better code analysis tools (lint, search, > > etc.). > > > > I find pylint excellent. My idea of a refactoring tool is vim's n.n.n., > but > have you looked at PyCharm? > > > In this thread, I'm asking about the views of Python programmers on > languages > other than Python. Thanks for the link, though (does PyCharm provide > reliable > refactoring tools that are useable from emacs?). > > I'm inclined to doubt that emacs can swallow PyCharm (or PyCharm be swallowed by emacs). But PyCharm probably has refactoring. For a bolt-on to vim or emacs, you might look at "Rope". -------------- next part -------------- An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sun May 22 16:41:34 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sun, 22 May 2011 22:41:34 +0200 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 11.05.2011 23:02 schrieb Ian: > On 11/05/2011 20:13, Hans Georg Schaathun wrote: >> Lists do not have truth values in the >> application domain, and therefore truth values in the >> implementation domain is complicated. >> > Exactly. Its just a convention. If it exists, its true, if if doesn't > its false. Right. And not only that: Python objects resp. classes not claiming to have a truth value (__nonzero__), but a length (__len__) are judged by that concerning their truth value: iff the length is 0, their truth value is False. Thomas From jjl at pobox.com Sun May 22 17:01:00 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 21:01:00 +0000 (UTC) Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: Dan Stromberg gmail.com> writes: [...] > Pylint does type inferencing - I find it very valuable on large projects, and > even some not-so-large projects.I doubt Pylint's been integrated into any > IDE's, [...] That's interesting, thanks. I see this is a different pylint than the old logilab pylint. Unfortunate choice of name, since it makes it hard to find IDE integration work that's already done. > But PyCharm probably has refactoring.? For a bolt-on to vim or > emacs, you might look at "Rope". TBH, I'm not interested in Python refactoring tools until everybody starts shouting that they're reliable and useful (because it seems like a hard problem to solve, so I guess most implementations will be more trouble than they're worth). John From ladasky at my-deja.com Sun May 22 17:06:33 2011 From: ladasky at my-deja.com (John Ladasky) Date: Sun, 22 May 2011 14:06:33 -0700 (PDT) Subject: Multiprocessing: don't push the pedal to the metal? References: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> Message-ID: <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> Following up to my own post... Flickr informs me that quite a few of you have been looking at my graphs of performance vs. the number of sub-processes employed in a parallelizable task: On May 21, 8:58?pm, John Ladasky wrote: > http://www.flickr.com/photos/15579975 at N00/5744093219 [...] > I'll quickly ask my question first, to avoid a TL;DR problem: when you > have a multi-core CPU with N cores, is it common to see the > performance peak at N-1, or even N-2 processes? ?And so, should you > avoid using quite as many processes as there are cores? ?I was > expecting diminishing returns for each additional core -- but not > outright declines. But no one has offered any insight yet? Well, I slept on it, and I had a thought. Please feel free to shoot it down. If I spawn N worker sub-processes, my application in fact has N+1 processes in all, because there's also the master process itself. If the master process has anything significant to do (and mine does, and I would surmise that many multi-core applications would be that way), then the master process may sometimes find itself competing for time on a CPU core with a worker sub-process. This could impact performance even when the demands from the operating system and/or other applications are modest. I'd still appreciate hearing from anyone else who has more experience with multiprocessing. If there are general rules about how to do this best, I haven't seen them posted anywhere. This may not be a Python- specific issue, of course. Tag, you're it! From jjl at pobox.com Sun May 22 17:13:44 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 21:13:44 +0000 (UTC) Subject: Abandoning Python References: <595378.58400.qm@web120504.mail.ne1.yahoo.com> Message-ID: Ed Keith yahoo.com> writes: > > Have you looked at Falcon (http://www.falconpl.org/)? It seems to have a lot > of what you are looking for. I'm more interested in other people's opinions than my own "looking for"s. What *should* I be looking for (other than Python itself)? What's interesting, widely applicable, and new(ish)? Falcon fails my personal book-by-its-cover test. There are too many languages to do without that test, unfortunately. John From tjreedy at udel.edu Sun May 22 17:17:37 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 May 2011 17:17:37 -0400 Subject: TK program problem In-Reply-To: <42561028-39ce-4543-8e3c-b021e3a2b067@34g2000pru.googlegroups.com> References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <42561028-39ce-4543-8e3c-b021e3a2b067@34g2000pru.googlegroups.com> Message-ID: On 5/21/2011 10:20 PM, bvdp wrote: > >> One of the purposes and advantages of Python 3 is having only one class >> system. Best to always use new-style classes in Python 2.2+ unless you >> understand and need old-style classes (and need should be never for most >> people). >> > > Thanks for this. I'll keep it in mind! > > One thing I really don't understand ... is there a difference between > the old/new forms: > > class foo: > class foo(): > > In cases where I've played with them, they _appear_ to work the same? I believe they are. Same is true in 3.x except that the result in a new-style class. > Also, where does one find the magic that says that for a tkinter class > you should use: > > class foo(object): Perhaps nowhere. It may have been an unintended side-effect of the change in callable check, or intentional but not documented. > Not really sure where "object" comes from. It is the base class of all (new-style) classes. >>> object() -- Terry Jan Reedy From jjl at pobox.com Sun May 22 17:19:39 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 21:19:39 +0000 (UTC) Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: John Lee pobox.com> writes: [...] > That's interesting, thanks. I see this is a different pylint than the old > logilab pylint. Unfortunate choice of name, since it makes it hard to find > IDE integration work that's already done. Hmm, I see the last release was in 2003 :-( John From tjreedy at udel.edu Sun May 22 17:23:59 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 May 2011 17:23:59 -0400 Subject: Dealing with name clashes in pypi In-Reply-To: <4DD9573E.8010509@gmail.com> References: <4DD9573E.8010509@gmail.com> Message-ID: On 5/22/2011 2:34 PM, Patrick Sabin wrote: > I wanted to register my project (epdb) in pypi. Unfortunately there > already exists a project with the same name. It is not possible for me > to change the name of the project, because I used it in multiple > writings. Any ideas how I can deal with the situation? Is it possible to > register a project under a different name in pypi than the actual > project name? I presume so. How would pypi know the 'actual' name? However, there is a catalog sig list (mirrored as gmane.comp.python.catalog) where you might get specific suggestions on how to handle this. -- Terry Jan Reedy From PointedEars at web.de Sun May 22 17:57:11 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 22 May 2011 23:57:11 +0200 Subject: and becomes or and or becomes and References: Message-ID: <2708393.dWV9SEqChM@PointedEars.de> Stef Mientki wrote: > must of us will not use single bits these days, > but at first sight, this looks funny : > >>>> a=2 >>>> b=6 >>>> a and b > 6 >>>> a & b > 2 >>>> a or b > 2 >>>> a | b > 6 Change the order of the operands and see what happens. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From tjreedy at udel.edu Sun May 22 18:01:56 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 May 2011 18:01:56 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <9CDC4B2CD1F445E994119A50F65155DF@teddy> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> Message-ID: On 5/22/2011 3:44 AM, Octavian Rasnita wrote: > I've noticed that on many Perl mailing lists the list members talk > very rarely about Python, Interesting. I learned about Python on comp.lang.perl, but that was over a decade ago. > but only on this Python mailing list I read > many discussions about Perl, in which most of the participants use to > agree that yes, Python is better, as it shouldn't be obvious that > most of the list members prefer Python. This list really has very little other-language bashing. > A few months ago I have asked how can I create a dictionary from a > list, and there were so many techniques that I think that it is just > a buzzword that in Perl there are many ways to do it, while in Python > there is a single way. In Python I found from the messages I received > on this mailing list that there are a lot of ways, without even > beeing a "recommended" way, while in Perl there is a single way, of > course much shorter and clearer. I forget the exact question you asked, but this list is not the doc. The doc section on dicts gives dict(list_of_key_value_pairs) as the one true way, given such an input. The Perl way cannot be clearer and can only be shorted if it uses something shorter that dict(). If the list is a flat list of alternating keys and values, then yes, they must be paired, and there are several ways to do that, partly depending on the exact specifications, including allowed input and how an odd key left over should be treated. In any case, unpaired keys and values strikes me as an unusual input format for a dict. They typically would have been paired as some point and in Python, should not need to be unpaired. -- Terry Jan Reedy From tjreedy at udel.edu Sun May 22 18:14:15 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 May 2011 18:14:15 -0400 Subject: and becomes or and or becomes and In-Reply-To: <2708393.dWV9SEqChM@PointedEars.de> References: <2708393.dWV9SEqChM@PointedEars.de> Message-ID: On 5/22/2011 5:57 PM, Thomas 'PointedEars' Lahn wrote: > Stef Mientki wrote: > >> must of us will not use single bits these days, >> but at first sight, this looks funny : >> >>>>> a=2 >>>>> b=6 >>>>> a and b >> 6 >>>>> a& b >> 2 >>>>> a or b >> 2 >>>>> a | b >> 6 > > Change the order of the operands and see what happens. or change a,b to 1,2 -- Terry Jan Reedy From timr at probo.com Sun May 22 18:39:33 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 22 May 2011 15:39:33 -0700 Subject: and becomes or and or becomes and References: Message-ID: Stef Mientki wrote: > >must of us will not use single bits these days, >but at first sight, this looks funny : > >>>> a=2 >>>> b=6 >>>> a and b >6 >>>> a & b >2 >>>> a or b >2 >>>> a | b >6 That IS funny. Interesting how a careful choice of arugments will fool us. One of my favorite math jokes is like that. A teacher asked a student to reduce the following fraction: 16 ---- 64 He says "all I have to do is cancel out the sixes, so the answer is 1/4". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From sunrrrise at gmail.com Sun May 22 18:43:53 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Sun, 22 May 2011 15:43:53 -0700 (PDT) Subject: Strange behaviour of input() function (Python 3.2) Message-ID: <1dc07caf-c938-42d0-8ba4-4fc9564af84e@glegroupsg2000goo.googlegroups.com> Hello, this is my first post. I'm trying to learn Python language which I find great, but I have a big problem with its editors/IDEs. I have tested IDLE (which installed with Python3 from ActiveState), Notepad++ and finally Komodo EDIT. I don't like IDLE GUI, but Notepad++ and Komodo EDIT looks nice for me. Unfortunatelly there is something wrong with input() command when I'm using Komodo or Notepad. For example this code: a = input("Wprowadz zmienna a: ") b = input("Wprowadz zmienna b: ") print("a to: ", a) print("b to: ", b) print(int(a) + int(b)) works well in IDLE, but when I'm switching to Notepad/Komodo I'm getting something like this: Wprowadz zmienna a: 3 Wprowadz zmienna b: 2 a to: 3 b to: Wprowadz zmienna b: 2 Traceback (most recent call last): File "c:\users\sunrrrise\Desktop\test.py", line 9, in print(int(a) + int(b)) ValueError: invalid literal for int() with base 10: 'Wprowadz zmienna b: 2' I don't know what is going on. Any ideas or, better, solutions? My OS: Windows 7 64bit, ActiveState Python 3.2, Notepad++ 5.9, Komodo Edit 6.1, coding: UTF-8 Regards, sunrrrise From rosuav at gmail.com Sun May 22 18:46:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 08:46:26 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 6:22 AM, Xah Lee wrote: > Xah wrote: > ?In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it > possibly mean by the word ?recursive? there? Like, it might delete the > directory but not delete all files in it? > ? > > Jonathan de Boyne Pollard wrote: >> It might *try* to delete the directory but not any of its contents, >> yes. > > you mean theoretically you see a possibility if the dir is implement > as stilted as unix, but never in your life you find yourself might > want to do it? There's a difference between working with a directory itself and working with files inside it. Generally, if you copy or delete a directory, you will want to recurse. But if you want to, for instance, wipe out all files whose names end with a tilde, then you might want to recurse and you might not. So it makes sense to offer the user a choice, and if recursive action is the only one that makes sense, at least acknowledge that the operation might take an arbitrarily long time. (Ever done a recursive operation on / on a large file system? Takes just a little bit longer than a non-recursive one under the same circumstances...) Chris Angelico From xahlee at gmail.com Sun May 22 18:47:53 2011 From: xahlee at gmail.com (Xah Lee) Date: Sun, 22 May 2011 15:47:53 -0700 (PDT) Subject: Functional Programing: stop using recursion, cons. Use map & vectors Message-ID: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> this is important but i think most lispers and functional programers still don't know it. Functional Programing: stop using recursion, cons. Use map & vectors. ?Guy Steele on Parallel Programing? http://xahlee.org/comp/Guy_Steele_parallel_computing.html btw, lists (as cons, car, cdr) in the lisp world has always been some kinda cult. Like, if you are showing some code example and you happened to use lisp vector datatype and not cons (lists) and it doesn't really matter in your case, but some lisper will always rise up to bug you, either as innocent curious question or attacking you for not ?understanding? lisp. (just as other idiocies happen in other lang that lispers see but other langs don't see) it's interesting to me that all other high level langs: Mathematica, perl, python, php, javascript, all don't have linked list as lisp's list. It's also curious that somehow lispers never realises this. I've been having problems with lisp's cons ever since i'm learning Scheme Lisp in 1998 (but mostly the reason is language design at syntax and lack of abstraction level in calling ?cons, car, cdr? stuff, without indexing mechanism). Realizing the algorithmic property and parallel- execution issues of linked list is only recent years. Xah From rosuav at gmail.com Sun May 22 18:49:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 08:49:17 +1000 Subject: Strange behaviour of input() function (Python 3.2) In-Reply-To: <1dc07caf-c938-42d0-8ba4-4fc9564af84e@glegroupsg2000goo.googlegroups.com> References: <1dc07caf-c938-42d0-8ba4-4fc9564af84e@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 8:43 AM, sunrrrise wrote: > Hello, > this is my first post. I'm trying to learn Python language which I find great, but I have a big problem with its editors/IDEs. Welcome! > b to: ?Wprowadz zmienna b: 2 This looks wrong. Are you copying and pasting several lines, or simply pressing the 2 key followed by Enter? It's showing a lengthy string in the variable 'b', which - quite correctly - cannot be cast to int. Chris Angelico From brendan.simon at etrix.com.au Sun May 22 18:58:55 2011 From: brendan.simon at etrix.com.au (Brendan Simon (eTRIX)) Date: Mon, 23 May 2011 08:58:55 +1000 Subject: Abandoning Python In-Reply-To: References: Message-ID: <4DD9952F.4080100@etrix.com.au> On 23/05/11 7:17 AM, python-list-request at python.org wrote: > Subject: > Re: Abandoning Python > From: > John Lee > Date: > Sun, 22 May 2011 21:13:44 +0000 (UTC) > > >> > >> > Have you looked at Falcon (http://www.falconpl.org/)? It seems to have a lot >> > of what you are looking for. > I'm more interested in other people's opinions than my own "looking for"s. > > What *should* I be looking for (other than Python itself)? What's interesting, > widely applicable, and new(ish)? > > Falcon fails my personal book-by-its-cover test. There are too many languages > to do without that test, unfortunately. Take a look at Cobra. http://cobra-language.com/docs/python/ http://cobra-language.com/ It is similar to Python, but with a quite a few nice extras and few improved things (eg. no "self", no ":", ...) Possible negatives are: * Requires either .NET or Mono frameworks. * lack of 3rd party libraries ?? Cheers, Brendan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sunrrrise at gmail.com Sun May 22 18:59:06 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Sun, 22 May 2011 15:59:06 -0700 (PDT) Subject: Odp: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: <724378fc-9848-406f-9b44-165132c49a56@glegroupsg2000goo.googlegroups.com> Thank you for quick response! English is not my native language so I'm going to keep my explanations simple. This really simple script asks me for two variables called "a" and "b". For example, I type "4" for "a" and "3" for "b" and IDLE gives me that: Wprowadz zmienna a: 4 Wprowadz zmienna b: 3 a to: 4 b to: 3 7 Works fine! But when I'm using Notepad (or Komodo) I get this: Wprowadz zmienna a: 4 Wprowadz zmienna b: 3 Traceback (most recent call last): File "c:\users\sunrrrise\Desktop\test.py", line 7, in print(int(a) + int(b)) ValueError: invalid literal for int() with base 10: 'Wprowadz zmienna b: 3' a to: 4 b to: Wprowadz zmienna b: 3 This is exactly the same script from the same file. I really don't get it. From sunrrrise at gmail.com Sun May 22 18:59:06 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Sun, 22 May 2011 15:59:06 -0700 (PDT) Subject: Odp: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: <724378fc-9848-406f-9b44-165132c49a56@glegroupsg2000goo.googlegroups.com> Thank you for quick response! English is not my native language so I'm going to keep my explanations simple. This really simple script asks me for two variables called "a" and "b". For example, I type "4" for "a" and "3" for "b" and IDLE gives me that: Wprowadz zmienna a: 4 Wprowadz zmienna b: 3 a to: 4 b to: 3 7 Works fine! But when I'm using Notepad (or Komodo) I get this: Wprowadz zmienna a: 4 Wprowadz zmienna b: 3 Traceback (most recent call last): File "c:\users\sunrrrise\Desktop\test.py", line 7, in print(int(a) + int(b)) ValueError: invalid literal for int() with base 10: 'Wprowadz zmienna b: 3' a to: 4 b to: Wprowadz zmienna b: 3 This is exactly the same script from the same file. I really don't get it. From dan.kluev at gmail.com Sun May 22 19:16:46 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 10:16:46 +1100 Subject: Abandoning Python In-Reply-To: References: <87ipt46okh.fsf@pobox.com> Message-ID: On Mon, May 23, 2011 at 4:33 AM, John Lee wrote: > Pylint? ?Does it provide some kind of guessed-at-type that has been integrated > with IDEs? WingIDE Pro has both Pylint integration and advanced type-guessing. -- With best regards, Daniel Kluev From xahlee at gmail.com Sun May 22 19:17:52 2011 From: xahlee at gmail.com (Xah Lee) Date: Sun, 22 May 2011 16:17:52 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> Message-ID: <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> On May 22, 3:46?pm, Chris Angelico wrote: > On Mon, May 23, 2011 at 6:22 AM, Xah Lee wrote: > > Xah wrote: > > ?In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it > > possibly mean by the word ?recursive? there? Like, it might delete the > > directory but not delete all files in it? > > ? > > > Jonathan de Boyne Pollard wrote: > >> It might *try* to delete the directory but not any of its contents, > >> yes. > > > you mean theoretically you see a possibility if the dir is implement > > as stilted as unix, but never in your life you find yourself might > > want to do it? > > There's a difference between working with a directory itself and > working with files inside it. Generally, if you copy or delete a > directory, you will want to recurse. But if you want to, for instance, > wipe out all files whose names end with a tilde, then you might want > to recurse and you might not. So it makes sense to offer the user a > choice, and if recursive action is the only one that makes sense, at > least acknowledge that the operation might take an arbitrarily long > time. (Ever done a recursive operation on / on a large file system? > Takes just a little bit longer than a non-recursive one under the same > circumstances...) the context is this: In emacs directory manager (aka dired), when you call dired-do-delete on a directory, emacs prompts, this way: ?Recursive delete of xx? (y or n)? Xah From rosuav at gmail.com Sun May 22 19:21:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 09:21:28 +1000 Subject: Strange behaviour of input() function (Python 3.2) In-Reply-To: <724378fc-9848-406f-9b44-165132c49a56@glegroupsg2000goo.googlegroups.com> References: <724378fc-9848-406f-9b44-165132c49a56@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 8:59 AM, sunrrrise wrote: > Thank you for quick response! > > English is not my native language so I'm going to keep my explanations simple. No problem, your English is far better than my Polish. (I used Google Translate to figure out what "Wprowadz zmienna" means.) I tried copying and pasting your exact code, even down to using Notepad, but it worked fine. The interpreter I used was a freshly-downloaded Python 3.2, listing itself as r32:88445 dated Feb 20 2011, 21:29:03. This may be a really specific bug. Can you email me the actual Python file you're having problems with, please? Off-list, as this list doesn't like attachments. I'll try running it on my system and see if it's any different. Chris Angelico From rosuav at gmail.com Sun May 22 19:28:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 09:28:40 +1000 Subject: and becomes or and or becomes and In-Reply-To: References: Message-ID: On Mon, May 23, 2011 at 8:39 AM, Tim Roberts wrote: > That IS funny. ?Interesting how a careful choice of arugments will fool us. > One of my favorite math jokes is like that. ?A teacher asked a student to > reduce the following fraction: > ?16 > ?---- > ?64 > > He says "all I have to do is cancel out the sixes, so the answer is 1/4". I like. :) But in the OP, the difference between "and" and "&", or "or" and "|", is subtle yet absolute. They are completely different operators. The bitwise operators function like the arithmetic operators - evaluate both operands, then do something that combines them into one value. The logical operators, though, are more like the if statement: q = a and b is similar to: if a: q = a else: q = b (Pedants, please note that I said "similar" not "equivalent".) They happen to do similar things, but they're completely different in operation. I do like the humour value from the careful selection of operands though! Chris Angelico From rosuav at gmail.com Sun May 22 19:32:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 09:32:27 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 9:17 AM, Xah Lee wrote: > the context is this: In emacs directory manager (aka dired), when you > call dired-do-delete on a directory, emacs prompts, this way: > ?Recursive delete of xx? (y or n)? But in order to make your point (such as it is), you are ignoring the fact that there are other uses of the term 'recurse' or 'recursive', and consistency and clarity are important. I don't see emacs offering me a chance to do a non-recursive delete; the only issue here seems to be that it's explicit that it is going to destroy an entire branch of the directory tree. If this is such a problem, grab the emacs sources and change that string - it probably occurs in exactly one place in the code. Voila! You now have The One True Perfect Emacs, the ultimate text editor, because it no longer tells you that it's working recursively. *removes tongue from cheek after saying that last sentence* Chris Angelico From dan.kluev at gmail.com Sun May 22 19:42:50 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 10:42:50 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <12225671E9654FECB49613D915FAEC19@teddy> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> Message-ID: On Sun, May 22, 2011 at 11:47 PM, Octavian Rasnita wrote: > From: "Daniel Kluev" > I am talking about that flexibility which was criticized in the previous messages telling that this flexibility allows any programmer to use his own way. > Perl doesn't force anyone to indent the code, don't force the programmer to define a hash element before using it, allow the programmer to interpret the variables in strings directly. These things should be not used always, but if in some cases if the programmer wants to use them, he can use them with no problems. And this means flexibility. This is syntax-level flexibility, which, IMHO, does not affect 'advanceness' of modules at all. At language level, python is far more flexible than perl with its magic methods and hooks, allowing to overload any underlying language principles and protocols. > First, this is a bad style of mapping urls, because this list must be maintained every time the programmer changes something in a controller that makes the app need to use other urls. Explicit is better than implicit. One of reasons why I chose Pylons/Pyramid as my standard toolkit is that it allowed me to define mappers in any way I needed them to. If you want automatically defined mappers, there are lots of other python frameworks and modules which do exactly that. Moreover, even Routes itself (module, which does url mapping in Pylons) allows you to use automated mappers, via :controller/:action tokens. It allows pretty much everything you listed as 'features' of catalyst mappings. If you prefer to stuff routing logic into controllers and have default routing based on controllers and method names, you can use TurboGears framework, which has exactly that mindset, or you can use its mapping modules in Pyramid application. > The module DBIx::Class which is used usually as an ORM can create the class files for all the tables from a database (MySQL, Oracle, PostgreSQL, SQLite, MS SQL, etc), and it can be used to search using unions, sub-selects, can define views at ORM level, can accept to insert different types of objects like DateTime objects and can also return those type of objects, and many other things, and most of the things it can do can be done without using SQL code at all, but only standard Perl code and Perl data structures. There are lots of Python modules which do exactly this and much more. SQLAlchemy, SQLObject, Web2Py's DAL, and so on. They are integrated into frameworks by default. > HTML::FormFu form processor is one of the most used form processors in Catalyst applications and it can generate and parse forms created directly in the code of the application, or as external configuration files defined using JSON, or YAML, or Apache configuration style, or Perl data structures, or XML... > The forms defined are very easy to create and the elements from those forms, for example the list of elements in a combo box can be taken directly from a database by specifying just a few configuration elements. The results of a form submit can be also inserted in a database using a connector with DBIx::Class without specifying any database table column name in the programming code, and for doing this are required just a few lines of code that checks if the $form->submitted_and_valid() and that does the redirection after the submit, the insertion in the database requiring just: Once again, there are dozens of such modules in python. FormAlchemy integrates directly with SQLAlchemy, for example, and does all form generation, parsing, validation, and instance updating/inserting for you. > Yes, for web apps I have seen more things which can be done much better in Perl, much easier and clear, with less code, and not because the programmer needs to do not-recommended tricks for shortening the code, but because there are very many modules on CPAN that do the hard work. I doubt you had enough experience with python frameworks like Pyramid/Pylons or Web2Py. They have all features you listed, and code is as trivial and clean, as it could ever be. Its surprising that you present trivial ORM as 'advanced modules and libraries which are not available for Python', while in fact it have been done long time ago and in several flavors. -- With best regards, Daniel Kluev From john at castleamber.com Sun May 22 19:55:11 2011 From: john at castleamber.com (John Bokma) Date: Sun, 22 May 2011 18:55:11 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> Message-ID: <877h9i5m00.fsf@castleamber.com> Terry Reedy writes: > I forget the exact question you asked, but this list is not the > doc. The doc section on dicts gives dict(list_of_key_value_pairs) as > the one true way, given such an input. The Perl way cannot be clearer > and can only be shorted if it uses something shorter that dict(). my %hash = @list_of_key_value_pairs; -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From steve+comp.lang.python at pearwood.info Sun May 22 20:30:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 May 2011 00:30:37 GMT Subject: and becomes or and or becomes and References: Message-ID: <4dd9aaac$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 22 May 2011 15:39:33 -0700, Tim Roberts wrote: > Stef Mientki wrote: >> >>must of us will not use single bits these days, but at first sight, this >>looks funny : >> >>>>> a=2 >>>>> b=6 >>>>> a and b >>6 >>>>> a & b >>2 >>>>> a or b >>2 >>>>> a | b >>6 > > That IS funny. Interesting how a careful choice of arugments will fool > us. One of my favorite math jokes is like that. A teacher asked a > student to reduce the following fraction: > 16 > ---- > 64 > > He says "all I have to do is cancel out the sixes, so the answer is > 1/4". One of my favourite variations on this is by Abbott and Costello, where Costello proves that 13*7 = 28 in three different ways. http://www.youtube.com/watch?v=rLprXHbn19I -- Steven From rosuav at gmail.com Sun May 22 20:32:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 10:32:32 +1000 Subject: Multiprocessing: don't push the pedal to the metal? In-Reply-To: <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> References: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 7:06 AM, John Ladasky wrote: > If I spawn N worker sub-processes, my application in fact has N+1 > processes in all, because there's also the master process itself. This would definitely be correct. How much impact the master process has depends on how much it's doing. > I'd still appreciate hearing from anyone else who has more experience > with multiprocessing. ?If there are general rules about how to do this > best, I haven't seen them posted anywhere. ?This may not be a Python- > specific issue, of course. I don't have much experience with Python's multiprocessing model, but I've done concurrent programming on a variety of platforms, and there are some common issues. Each CPU (or core) has its own execution cache. If you can keep one thread running on the same core all the time, it will benefit more from that cache than if it has to keep flitting from one to another. You undoubtedly will have other processes in the system, too. As well as your master, there'll be processes over which you have no control (unless you're on a bare-bones system). Some of them may preempt your processes. Leaving one CPU/core available for "everything else" may allow the OS to keep each thread on its own core. Having as many workers as cores means that every time there's something else to do, one of your workers has to be kicked off its nice warm CPU and sent out into the cold for a while. If all your workers are at the same priority, it will then grab a timeslice off one of the other cores, kicking its incumbent off... rinse and repeat. This is a tradeoff, though. If the rest of your system is going to use 0.01 of a core, then 1% thrashing is worth having one more core available 99% of the time. If the numbers are reversed, it's equally obvious that you should leave one core available. In your case, it's probably turning out that the contention causes more overhead than the extra worker is worth. That's just some general concepts, without an in-depth analysis of your code and your entire system. It's probably easier to analyse by results rather than inspection. Chris Angelico From greg.ewing at canterbury.ac.nz Sun May 22 21:11:40 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 23 May 2011 13:11:40 +1200 Subject: Abandoning Python In-Reply-To: References: Message-ID: <93tqifFnb2U1@mid.individual.net> Ed Keith wrote: > Have you looked at Falcon (http://www.falconpl.org/)? This paragraph on the first page doesn't exactly fire me with enthuiasm: > Falcon provides six integrated programming paradigms: procedural, object > oriented, prototype oriented, functional, tabular and message oriented. And you > don't have to master all of them; ...until you want to read someone *else's* code, that is. -- Greg From cjns1989 at gmail.com Sun May 22 21:32:06 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Sun, 22 May 2011 21:32:06 -0400 Subject: No subject Message-ID: <20110523013206.GA17789@pavo.local> From cjns1989 at gmail.com Sun May 22 21:32:09 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Sun, 22 May 2011 21:32:09 -0400 Subject: No subject Message-ID: <20110523013209.GA17846@pavo.local> From d.awlberg at hotmail.invalid Sun May 22 22:29:26 2011 From: d.awlberg at hotmail.invalid (Deeyana) Date: Mon, 23 May 2011 02:29:26 +0000 (UTC) Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On Sun, 22 May 2011 15:47:53 -0700, Xah Lee wrote: > this is important but i think most lispers and functional programers > still don't know it. > > Functional Programing: stop using recursion, cons. Use map & vectors. > > ?Guy Steele on Parallel Programing? > http://xahlee.org/comp/Guy_Steele_parallel_computing.html > > btw, lists (as cons, car, cdr) in the lisp world has always been some > kinda cult. Like, if you are showing some code example and you happened > to use lisp vector datatype and not cons (lists) and it doesn't really > matter in your case, but some lisper will always rise up to bug you, > either as innocent curious question or attacking you for not > ?understanding? lisp. (just as other idiocies happen in other lang that > lispers see but other langs don't see) > > it's interesting to me that all other high level langs: Mathematica, > perl, python, php, javascript, all don't have linked list as lisp's > list. It's also curious that somehow lispers never realises this. I've > been having problems with lisp's cons ever since i'm learning Scheme > Lisp in 1998 (but mostly the reason is language design at syntax and > lack of abstraction level in calling ?cons, car, cdr? stuff, without > indexing mechanism). Realizing the algorithmic property and parallel- > execution issues of linked list is only recent years. You might be interested in Clojure, then. Lists are more abstracted, like in Scheme, and vectors and also dictionaries/maps and sets are first class citizens along side lists. And unlike Scheme, Clojure has good library/host interop support. You can write real-world applications in it without spontaneously combusting. From shunichi_wakabayashi at yahoo.co.jp Sun May 22 22:48:13 2011 From: shunichi_wakabayashi at yahoo.co.jp (Shunichi Wakabayashi) Date: Sun, 22 May 2011 19:48:13 -0700 (PDT) Subject: Writing multiple files with with-context Message-ID: <5142852e-bab9-4e39-a49b-0229e900e97d@glegroupsg2000goo.googlegroups.com> To write onto multiple files on the same time (a number of files are variable), I'd like to code as follows, for example, IF I can do, LIST_LEN = 4 with [ open('list_%d.txt' % i, 'w') for i in range(LIST_LEN) ] as fobjlist: for i in range(1000): fobjlist[random.randrange(LIST_LEN)].write(str(i)+"\n") or using a dict object, DICT_KEYS = ('foo', 'bar', 'baz') with { k: open('dict_%s.txt' % k, 'w') for k in DICT_KEYS } as fobjdict: for i in range(1000): fobjdict[random.choice(DICT_KEYS)].write(str(i)+"\n") However, list and dict don't has __exit__ method and so they cannot run. One idea is using contextlib.nested(), from contextlib import nested with nested(*[open('list_%d.txt' % i, 'w') for i in range(LIST_LEN)]) as fobjlist: for i in range(1000): fobjlist[random.randrange(LIST_LEN)].write(str(i)+"\n") with nested(*[open('dict_%s.txt' % k, 'w') for k in DICT_KEYS]) as fobjlist: fobjdict = dict(zip(DICT_KEYS, fobjlist)) #convert list to dict for i in range(1000): fobjdict[random.choice(DICT_KEYS)].write(str(i)+"\n") On Python2.x, this is OK. but 3.x warns that nested() is deprecated. Moreover, on using dict, it is required to convert list to dict. Another idea is to make container classes having __exit__() myself. class MyList(list): def __enter__(self): return [ v.__enter__() for v in self ] def __exit__(self, exc_type, exc_value, traceback): ret = False for v in self: if v.__exit__(exc_type, exc_value, traceback): ret = True exc_type = exc_value = traceback = None return ret class MyDict(dict): def __enter__(self): return { k: v.__enter__() for k, v in self.items() } def __exit__(self, exc_type, exc_value, traceback): ret = False for v in self.values(): if v.__exit__(exc_type, exc_value, traceback): ret = True exc_type = exc_value = traceback = None return ret with MyList( open('list_%d.txt' % i, 'w') for i in range(LIST_LEN) ) as fobjlist: for i in range(1000): fobjlist[random.randrange(LIST_LEN)].write(str(i)+"\n") with MyDict( (k, open('dict_%s.txt' % k, 'w')) for k in DICT_KEYS ) as fobjdict: for i in range(1000): fobjdict[random.choice(DICT_KEYS)].write(str(i)+"\n") I think this is smarter a little than others, but it cannot guaranteed to call __exit__() of members in containers if members are changed during with-context. So, do you have another, more smart and pythonic way? Thanks From rosuav at gmail.com Sun May 22 23:01:19 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 13:01:19 +1000 Subject: Building Python: static library "3.2m" Message-ID: Hi! Just a quickie, I hope, where someone will probably be able to answer off the top of his head. I downloaded the 3.2 sources with the intention of building that instead of using Ubuntu's default Python 2.6.6. Ran ./configure, make, sudo make install, and then fiddled with a few things like make all, make libinstall, make libainstall. Eventually got a libpython3.2m.a in /usr/local/lib. Question: Why "3.2m"? What does that m mean? It seems to have come up a couple of times in the build process. Thanks in advance! Chris Angelico From nad at acm.org Mon May 23 00:01:27 2011 From: nad at acm.org (Ned Deily) Date: Sun, 22 May 2011 21:01:27 -0700 Subject: Building Python: static library "3.2m" References: Message-ID: In article , Chris Angelico wrote: > Question: Why "3.2m"? What does that m mean? It seems to have come up > a couple of times in the build process. It's a new feature in Python 3.2 to allow multiple versions of shared C object files that differ in configure options (i.e. ones that affect the Python C ABI) to co-exist in one Python installation. "m" means that they were built with pymalloc. Other flags are "d" for debug, and "u" for wide-unicode. http://docs.python.org/py3k/whatsnew/3.2.html#pep-3149-abi-version-tagged -so-files -- Ned Deily, nad at acm.org From rosuav at gmail.com Mon May 23 00:08:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 14:08:53 +1000 Subject: Building Python: static library "3.2m" In-Reply-To: References: Message-ID: On Mon, May 23, 2011 at 2:01 PM, Ned Deily wrote: > It's a new feature in Python 3.2 to allow multiple versions of shared C > object files that differ in configure options (i.e. ones that affect the > Python C ABI) to co-exist in one Python installation. ?"m" means that > they were built with pymalloc. ?Other flags are "d" for debug, and "u" > for wide-unicode. Ahh, thank you! I was planning to just statically link to my executable to reduce deployment effort, but either way works. Currently I'm puzzling over an inordinate number of symbol-not-found errors, even though it does seem to be finding the header files. It's weird. Chris Angelico From rosuav at gmail.com Mon May 23 00:32:11 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 14:32:11 +1000 Subject: Building Python: static library "3.2m" In-Reply-To: References: Message-ID: On Mon, May 23, 2011 at 2:08 PM, Chris Angelico wrote: > Currently I'm puzzling over an inordinate number of symbol-not-found > errors, even though it does seem to be finding the header files. It's > weird. And.... I think I've just figured out why. PyString_* functions are no longer supported - it's all PyUnicode now. Yes, I really am capable of forgetting basics like that! Chris Angelico From orasnita at gmail.com Mon May 23 01:31:06 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 08:31:06 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> Message-ID: <21A740B7AC6644248476DFADDF726C73@octavian> From: "Dennis Lee Bieber" >Since indentation seems so crucial to easy comprehension of the logical >structure of a program, > making it a mandatory syntactical structure becomes a desirable feature > for code that must be maintained (by others, in many cases). Why "in many cases"? I wrote hundreads of programs which are working fine and which are maintained only by me. (But they would be very easy to maintain by other people if it would be necessary). So in that case, why to be forced to use a strict indentation? > As for the dictionary from list... Do not confuse /algorithms/ > selected by the programmer from what is part of the native language. > Otherwise one could complain that there is more than one way to code a > spam-filter using Python... Exactly, I am not talking about a complex task that can be done in many ways in all programming languages. I am talking about a simple way of creating a hash/dict from an array, which is so simple that there should be really a single way to do it, or very few. Octavian From orasnita at gmail.com Mon May 23 02:06:16 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 09:06:16 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> Message-ID: <2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> From: "Daniel Kluev" > On Sun, May 22, 2011 at 11:47 PM, Octavian Rasnita > wrote: >> From: "Daniel Kluev" >> I am talking about that flexibility which was criticized in the previous >> messages telling that this flexibility allows any programmer to use his >> own way. >> Perl doesn't force anyone to indent the code, don't force the programmer >> to define a hash element before using it, allow the programmer to >> interpret the variables in strings directly. These things should be not >> used always, but if in some cases if the programmer wants to use them, he >> can use them with no problems. And this means flexibility. > > This is syntax-level flexibility, which, IMHO, does not affect > 'advanceness' of modules at all. At language level, python is far more > flexible than perl with its magic methods and hooks, allowing to > overload any underlying language principles and protocols. This means that you are forgetting Moose objects in Perl, right? Moose is a very advanced object type system that will be the default type in Perl 6, but which was also implemented in Perl 5, which offers a lot of features for introspections in the object structure. And the flexibility do offer the possibility of coding much easier and offering more features. There are more, but a single eloquent feature is the possibility of interpreting variables in strings which cannot be done so nice in Python. >> First, this is a bad style of mapping urls, because this list must be >> maintained every time the programmer changes something in a controller >> that makes the app need to use other urls. > > Explicit is better than implicit. This is false. Explicit in this case means to write code in 2 places for doing a certain thing, and maintaining means changing the code in 2 places, which is harder and prone to errors. > One of reasons why I chose Pylons/Pyramid as my standard toolkit is that > it allowed me to define > mappers in any way I needed them to. In Catalyst you can also define the url mappings in any way you need, not only based on controller/actions locations, but you don't need to do this by creating code in 2 places so it would be easier to maintain. In Catalyst all the mappers are done "automaticly", but they can be done in any way you like, even in more ways that under Pylons/Pyramid as I shown (unless in Pylons/Pyramid can be also defined chained mappings and mappings based on regular expressions). > > If you want automatically defined mappers, there are lots of other > python frameworks and modules which do exactly that. Moreover, even > Routes itself (module, which does url mapping in Pylons) allows you to > use automated mappers, via :controller/:action tokens. It allows > pretty much everything you listed as 'features' of catalyst mappings. > If you prefer to stuff routing logic into controllers and have default > routing based on controllers and method names, you can use TurboGears > framework, which has exactly that mindset, or you can use its mapping > modules in Pyramid application. Yes, the single difference is that Catalyst supports all of them, and it also supports using any templating system, and any ORM and any form processor, while some of the Python web frameworks don't support absolutely everything and you need to abandon some preferred modules for beeing able to use some other modules which are supported. >> The module DBIx::Class which is used usually as an ORM can create the >> class files for all the tables from a database (MySQL, Oracle, >> PostgreSQL, SQLite, MS SQL, etc), and it can be used to search using >> unions, sub-selects, can define views at ORM level, can accept to insert >> different types of objects like DateTime objects and can also return >> those type of objects, and many other things, and most of the things it >> can do can be done without using SQL code at all, but only standard Perl >> code and Perl data structures. > > There are lots of Python modules which do exactly this and much more. > SQLAlchemy, SQLObject, Web2Py's DAL, and so on. They are integrated > into frameworks by default. I've checked the documentation for some of them and I've seen that most of them don't support sub-selects and some of them require using plain SQL code in their construct for more complex queries. Please tell me which of them supports sub-selects, and are able to return objects for date and datetime fields that have methods for beeing able to print just the year or day, or the months names in the specified locale because it would be useful. >> Yes, for web apps I have seen more things which can be done much better >> in Perl, much easier and clear, with less code, and not because the >> programmer needs to do not-recommended tricks for shortening the code, >> but because there are very many modules on CPAN that do the hard work. > > I doubt you had enough experience with python frameworks like > Pyramid/Pylons or Web2Py. They have all features you listed, and code > is as trivial and clean, as it could ever be. Its surprising that you > present trivial ORM as 'advanced modules and libraries which are not > available for Python', while in fact it have been done long time ago > and in several flavors. Please tell me which of those ORMS can do what DBIx::Class can do as I asked above, before calling it "trivial", and which are those aditional features it can do but DBIx::Class cannot, because otherwise it would be very simple for anyone to just say "go to read the documentation and see how great it is". Octavian From godson.g at gmail.com Mon May 23 02:32:17 2011 From: godson.g at gmail.com (Godson Gera) Date: Mon, 23 May 2011 12:02:17 +0530 Subject: Tkinter FileDialog In-Reply-To: <4dd96e57$0$49044$e4fe514c@news.xs4all.nl> References: <4dd96e57$0$49044$e4fe514c@news.xs4all.nl> Message-ID: Hi, You can try the following from Tkinter import* root = Tk() root.withdraw() #this will hide the main window import tkFileDialog as tkf f = tkf.Open().show() tkFileDialog, requires a main window to be existing before it can show the file dialog. If there are no main windows then it will create its own. On Mon, May 23, 2011 at 1:43 AM, Alex van der Spek wrote: > Trying to bring up a simple File or Directory chooser using Tkinter. Right > now I use pywin32 as Mark Hammond's extensions are somewhat more familiar > to an (ex)VB programmer who started way back with Fortran. > > On Windows Vista with Python 2.7. The examples from Mark Lutz' book > "Programming Python" do not immediately apply. The book describes Python 3.x > only. > > This is what I do (in IDLE): > > import tkFileDialog as tk > file2open=tk.Open().show() > > This works. But it also brings up a persistent Tk window. Killing this > window forces a restart in IDLE, which is not desirable. There does not > appear to be a way to multiselect files? > > I am probably missing a whole lot. Please point me to a simple example of > GUI file manipulations. I can save myself with os.path.walk and os.listdir > but the users I try to serve cannot. > > Regards, > Alex van der Spek > -- > http://mail.python.org/mailman/listinfo/python-list > -- Thanks & Regards, Godson Gera FreeSWITCH & Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon May 23 02:33:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 May 2011 06:33:37 GMT Subject: Abandoning Python References: <93tqifFnb2U1@mid.individual.net> Message-ID: <4dd9ffc1$0$29988$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 May 2011 13:11:40 +1200, Gregory Ewing wrote: > Ed Keith wrote: >> Have you looked at Falcon (http://www.falconpl.org/)? > > This paragraph on the first page doesn't exactly fire me with enthuiasm: > >> Falcon provides six integrated programming paradigms: procedural, >> object oriented, prototype oriented, functional, tabular and message >> oriented. And you don't have to master all of them; > > ...until you want to read someone *else's* code, that is. The same might be said about Python, which supports procedural, OO and functional styles out of the box. Prototype-oriented is so close to OO that you can fake it in Python: http://stackoverflow.com/questions/4629224/prototypal-programming-in-python I'm not sure what they mean by tabular, perhaps something like Resolver System's Python-in-a-spreadsheet? http://www.resolversystems.com/products/resolver-one/ And presumably anyone who has played around with GUI programming in Python will have run into message oriented coding. -- Steven From rosuav at gmail.com Mon May 23 02:37:10 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 16:37:10 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <21A740B7AC6644248476DFADDF726C73@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> Message-ID: On Mon, May 23, 2011 at 3:31 PM, Octavian Rasnita wrote: > From: "Dennis Lee Bieber" >> >> Since indentation seems so crucial to easy comprehension of the logical >> structure of a program, >> making it a mandatory syntactical structure becomes a desirable feature >> for code that must be maintained (by others, in many cases). > > Why "in many cases"? I wrote hundreads of programs which are working fine > and which are maintained only by me. (But they would be very easy to > maintain by other people if it would be necessary). > So in that case, why to be forced to use a strict indentation? The reason for clear code is maintenance, not maintenance-by-others. If you come back to something in a year, you'll appreciate proper variable names, indentation, etc. That said, though, I still do not believe in Python's philosophy of significant whitespace. I like to be able, if I choose, to put one entire "logical unit" on one line, such that it can be commented out with a single comment marker, or duplicated to another line and one copy commented out, or whatever. To that end, I sometimes want to put an if, its associated else, and sometimes a statement for both branches, all in the one line. And that's not possible when whitespace alone defines the end of an if/else block (the one-line form of a Python 'if' can't have a non-conditional statement after it at all), but is quite easy when things are delimited with braces. Bug report: The "from __future__ import braces" statement isn't working properly. Pls fix, kthxbye. :) But I still like Python overall. There's no such thing as a perfect language, and when it comes to syntax disagreements, I dislike Python's significant whitespace far less than I dislike PHP's adorned variable names. And Python, under the hood, is a very good engine for doing what I need to do. Chris Angelico From tjreedy at udel.edu Mon May 23 02:37:45 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 May 2011 02:37:45 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <21A740B7AC6644248476DFADDF726C73@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> Message-ID: On 5/23/2011 1:31 AM, Octavian Rasnita wrote: > I am talking about a simple way of creating a hash/dict from an array, > which is so simple that there should be really a single way to do it, or > very few. Again, Python has such: >>> dict([['one',1],['two', 2]]) {'two': 2, 'one': 1} -- Terry Jan Reedy From pavlovevidence at gmail.com Mon May 23 02:46:48 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 22 May 2011 23:46:48 -0700 (PDT) Subject: Why did Quora choose Python for its development? In-Reply-To: Message-ID: <47fd1b4b-ef7a-4f8c-95be-44e7a93ffacc@glegroupsg2000goo.googlegroups.com> On Sunday, May 22, 2011 12:44:18 AM UTC-7, Octavian Rasnita wrote: > I've noticed that on many Perl mailing lists the list members talk very > rarely about Python, but only on this Python mailing list I read many > discussions about Perl, in which most of the participants use to agree that > yes, Python is better, as it shouldn't be obvious that most of the list > members prefer Python. Evidently Perl users choose to bash other languages in those languages' own mailing lists. > If Python would be so great, you wouldn't talk so much about how bad are > other languages, Sure we would. Sometimes it's fun to sit on your lofty throne and scoff at the peasantry. > or if these discussions are not initiated by envy, you would > be also talking about how bad is Visual Basic, or Pascal, or Delphi, or who > knows other languages. I would suggest that envy isn't the reason, the reason is that Perl is just that much worse than Visual Basic, Pascal, and Delphi. We only make fun of the really, really bad langauges. (Or, less cynically, it's because Perl and Python historically filled the same niche, whereas VB, Pascal, and Delphi were often used for different sorts of programming.) What I'm trying to say here is your logic is invalid. People have all kinds of reasons to badmouth other languages; that some mailing list has a culture that is a bit more or a bit less approving of it than some other list tells us nothing. In any case it's ridiculous to claim envy as factor nowadays, as Python is clearly on the rise while Perl is on the decline. Few people are choosing Perl for new projects. Carl Banks From pavlovevidence at gmail.com Mon May 23 02:46:48 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 22 May 2011 23:46:48 -0700 (PDT) Subject: Why did Quora choose Python for its development? In-Reply-To: Message-ID: <47fd1b4b-ef7a-4f8c-95be-44e7a93ffacc@glegroupsg2000goo.googlegroups.com> On Sunday, May 22, 2011 12:44:18 AM UTC-7, Octavian Rasnita wrote: > I've noticed that on many Perl mailing lists the list members talk very > rarely about Python, but only on this Python mailing list I read many > discussions about Perl, in which most of the participants use to agree that > yes, Python is better, as it shouldn't be obvious that most of the list > members prefer Python. Evidently Perl users choose to bash other languages in those languages' own mailing lists. > If Python would be so great, you wouldn't talk so much about how bad are > other languages, Sure we would. Sometimes it's fun to sit on your lofty throne and scoff at the peasantry. > or if these discussions are not initiated by envy, you would > be also talking about how bad is Visual Basic, or Pascal, or Delphi, or who > knows other languages. I would suggest that envy isn't the reason, the reason is that Perl is just that much worse than Visual Basic, Pascal, and Delphi. We only make fun of the really, really bad langauges. (Or, less cynically, it's because Perl and Python historically filled the same niche, whereas VB, Pascal, and Delphi were often used for different sorts of programming.) What I'm trying to say here is your logic is invalid. People have all kinds of reasons to badmouth other languages; that some mailing list has a culture that is a bit more or a bit less approving of it than some other list tells us nothing. In any case it's ridiculous to claim envy as factor nowadays, as Python is clearly on the rise while Perl is on the decline. Few people are choosing Perl for new projects. Carl Banks From rosuav at gmail.com Mon May 23 02:49:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 16:49:32 +1000 Subject: Abandoning Python In-Reply-To: References: <93tqifFnb2U1@mid.individual.net> <4dd9ffc1$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 23, 2011 at 4:33 PM, Steven D'Aprano wrote: > And presumably anyone who has played around with GUI programming in > Python will have run into message oriented coding. > GUI code almost always involves a main loop somewhere that consists of: while not time_to_terminate: ?get_message() ?dispatch_message() Voila, you've just implemented message-oriented code in an imperative way. Doesn't make the language inherently message-oriented. If you're going to read someone else's code, then, you not only need to know the language, you need to know the environment in which it runs. I found that out the hard way when I tried to read some PHP code that was designed to run inside Joomla - it's quite quite different from standalone PHP. I believe assembly language offers as many paradigms as anything else you might want. With judicious use of constructs like the Intel "JMP [BP+SI]" and a nice table of jump targets, you could do message passing, OOP/inheritance, procedures, and next-programmer-brain-destruction, and hey, it's tabular too! Chris Angelico From rosuav at gmail.com Mon May 23 03:32:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 17:32:29 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <47fd1b4b-ef7a-4f8c-95be-44e7a93ffacc@glegroupsg2000goo.googlegroups.com> References: <47fd1b4b-ef7a-4f8c-95be-44e7a93ffacc@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 4:46 PM, Carl Banks wrote: > On Sunday, May 22, 2011 12:44:18 AM UTC-7, Octavian Rasnita wrote: >> If Python would be so great, you wouldn't talk so much about how bad are >> other languages, > > Sure we would. ?Sometimes it's fun to sit on your lofty throne and scoff at the peasantry. It's also fun, and sometimes productive, to sit on many different lofty thrones, and then to have a Jedi Council meeting in which we discuss which thrones are hard to climb onto, which ones are easy for a child to sit on but hard to get any work done on, and which ones are really comfortable and ergonomic, but have just that one little hard bit to the right of where your arm wants to rest, but if you're careful it won't jab into you too badly... and in those discussions, Perl is a literal Swiss Army Knife. :) > I would suggest that envy isn't the reason, the reason is that Perl is just that much worse than Visual Basic, Pascal, and Delphi. ?We only make fun of the really, really bad langauges. I'm not sure that Perl deserves to be put alongside Visual Basic. I'm not sure that ANY language deserves that... Chris Angelico From asandroq at gmail.com Mon May 23 03:52:07 2011 From: asandroq at gmail.com (asandroq) Date: Mon, 23 May 2011 00:52:07 -0700 (PDT) Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On May 23, 4:29?am, Deeyana wrote: > > You might be interested in Clojure, then. Lists are more abstracted, like > in Scheme, and vectors and also dictionaries/maps and sets are first > class citizens along side lists. And unlike Scheme, Clojure has good > library/host interop support. You can write real-world applications in it > without spontaneously combusting. Nonsense. Several Scheme systems have excellent FFIs with more than "good library/host interop support". -alex From dan.kluev at gmail.com Mon May 23 04:05:14 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 19:05:14 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> Message-ID: On Mon, May 23, 2011 at 5:06 PM, Octavian Rasnita wrote: > There are more, but a single eloquent feature is the possibility of > interpreting variables in strings which cannot be done so nice in Python. I've should probably mentioned it earlier, but I'm not Perl expert, not following its development and can't be bothered to read its docs. Could you please provide examples of features you mention with expected result, so I could suggest reasonable Python analogue? > This is false. Explicit in this case means to write code in 2 places for > doing a certain thing, and maintaining means changing the code in 2 places, > which is harder and prone to errors. Not sure what do you mean by 'write code in 2 places'. All mapping code is located in routes config, including all needed args validation. But if you want to couple it with controller code, there, as I said, are numerous ways to do it. You can even do something like this: class SomeController(BaseController): ... @map(conditions=dict(method='GET')) def some_method(self, arg1:int, arg2:str): ... so it would be called via /somecontroller/some-method/1/blabla with trivial decorator. > (unless in Pylons/Pyramid can be also defined chained mappings and mappings > based on regular expressions). Not sure what do you mean by "based on regular expressions". Routes paths ARE regular expressions. Conditions are regexes too. As for chained mappings - no idea, never had the need in such thing. > Yes, the single difference is that Catalyst supports all of them, and it > also supports using any templating system, and any ORM and any form > processor, while some of the Python web frameworks don't support absolutely > everything and you need to abandon some preferred modules for beeing able to > use some other modules which are supported. Pyramid and Pylons let you use pretty much any templating package and ORM as well. There is nothing in them that would block such modules. > I've checked the documentation for some of them and I've seen that most of > them don't support sub-selects and some of them require using plain SQL code > in their construct for more complex queries. > Please tell me which of them supports sub-selects, and are able to return > objects for date and datetime fields that have methods for beeing able to > print just the year or day, or the months names in the specified locale > because it would be useful. Python has builtin type for DateTime, and SQLAlchemy, for example, returns exactly that: #> python Python 2.7.1 (r271:86832, May 17 2011, 19:31:41) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sadt import Test, Session >>> import datetime >>> Test(1) >>> Test(2) >>> t1 = Session.query(Test).filter(Test.val == 1).one() >>> t1 >>> t1.date datetime.datetime(2011, 5, 23, 18, 53, 39, 459054) >>> t1.date.year 2011 >>> t1.date.month 5 >>> print Session.query(Test).filter(Test.date == datetime.datetime(2011, 5, 23, 18, 53, 39, 459054)).one() >>> print Session.query(Test).filter(Test.date > datetime.date(2010, 1, 1)).all() [, ] sadt sources here if interesting: http://pastebin.ca/2067372 So as you see, datetime is not only returned properly, but you can also do queries with either date or datetime values, including comparison and range. Subqueries are fully supported too: >>> ... >>> Session.query(Test).from_self().all() 2011-05-23 19:07:02,662 INFO sqlalchemy.engine.base.Engine.0x...552c SELECT anon_1.test_id AS anon_1_test_id, anon_1.test_val AS anon_1_test_val, anon_1.test_date AS anon_1_test_date FROM (SELECT test.id AS test_id, test.val AS test_val, test.date AS test_date FROM test) AS anon_1 2011-05-23 19:07:02,662 INFO sqlalchemy.engine.base.Engine.0x...552c () [, , , , ] This is most trivial example of subqueries, since I'm too lazy to produce proper tables to demonstrate it, but SQLAlchemy has very good subquery support, as its typical way to deal with one-to-many relations (but it does support other loading strategies as well, including inner/outer joins or lazy loading). > it can do but DBIx::Class cannot, because otherwise it would be very simple > for anyone to just say "go to read the documentation and see how great it > is". But "go to read the docs" argument works both ways - I have zero knowledge of DBIx::Class, so obviously I cannot say what features it lacks compared to SQLA. However this is what I wanted to highlight - you cannot simply state that "Perl offers more advanced modules and libraries which are not available for Python" if you don't have reasonable experience with according Python modules. -- With best regards, Daniel Kluev From mail at timgolden.me.uk Mon May 23 04:38:13 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 23 May 2011 09:38:13 +0100 Subject: Problem in using subprocess module and communicate() In-Reply-To: References: Message-ID: <4DDA1CF5.60103@timgolden.me.uk> On 21/05/2011 16:56, vijay swaminathan wrote: > I'm having some problem in using the communicate() along with the > subprocess.I would like to invoke a command prompt and pass on a .bat > file to execute. I went through the subprocess module and understood > that using communicate, we can send the send data to stdin. I'm afraid you're running the risk of giving us too little information here, Vijay. You've pointed to the docs you've read and provided code, which is A Good Thing. Unfortunately, the code you've provided is clearly not what you'll ultimately be running (unless you're in the game for a convoluted means of getting a directory listing) and, as Chris touched on in his response, is probably not even what you're running now, as you're passing the wrong kind of "/k" to cmd.exe. OK, let's see if I've understood correctly from this and from your previous posts: * You have a set of batch scripts you want to launch from Python * You want to launch them in parallel (possibly different scripts, not sure) so you're setting up threads. You seem to be trying to meet these requirements by opening a command shell with an arbitrary command, leaving it open and feeding its stdin with the batch script name so that it runs, and then polling it until it finishes. In short, you're making a mountain out of a molehill. If you need to run batch scripts from a command shell, then use subprocess.call with the name of the batch script and shell=True (the last isn't always necessary; it seems to depend on the C runtime, but it won't harm to have it there): import subprocess result = subprocess.call ("name-of-script.bat", shell=True) If you want to run that in a thread: import subprocess import threading def run_script (path_to_script): subprocess.call (path_to_script, shell=True) t = threading.Thread (target=run_script, args=("name-of-script.bat,")) t.start () while True: # do stuff if t.isAlive (): print "still running" You might, as you have above, want to launch a new console with each subprocess or the output could get quite messy. There are lots of variations on this theme: you could use a Queue to get the success or failure back from the threads. It's not clear whether you actually need to feed input into your batch scripts, as the only reason you're using .communicate above is to actually *run* the batch scripts. I could go on guessing what your use-case is, assuming that it doesn't involve a command shell with the output from a "dir" command, but it'll be easier if you can describe how closely what I've written above matches your need. TJG From orasnita at gmail.com Mon May 23 04:49:40 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 11:49:40 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> Message-ID: <629DAC3611EA49B0A36BCF70151CDE2F@octavian> From: "Terry Reedy" > On 5/23/2011 1:31 AM, Octavian Rasnita wrote: > > >> I am talking about a simple way of creating a hash/dict from an array, >> which is so simple that there should be really a single way to do it, or >> very few. > > Again, Python has such: > > >>> dict([['one',1],['two', 2]]) > {'two': 2, 'one': 1} That is not an array, but a list. An array has a name and we can't do something like the following simple statement in Python: l = (1, 2) d = dict(l) While in Perl we can do: @l = (1, 2); %d = @l; But let's remember from what this discussion started. This is not a Python critique, because each language has its own ways. I just wanted to show that the fact that "there is more than one way to do it" in Perl and that "there is a single way" in Python are just buzzwords, because this was an example where in Python there are many ways to do it while in Perl there is a single way used usually, which is also more simple. Octavian From torbenm at diku.dk Mon May 23 04:51:44 2011 From: torbenm at diku.dk (Torben Ægidius Mogensen) Date: Mon, 23 May 2011 10:51:44 +0200 Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: <7zpqn9re8v.fsf@ask.diku.dk> Xah Lee writes: > Functional Programing: stop using recursion, cons. Use map & vectors. > > ?Guy Steele on Parallel Programing? > http://xahlee.org/comp/Guy_Steele_parallel_computing.html This is more or less what Backus said in his Turing Award lecture about FP. Torben From alex at a13x.net Mon May 23 04:52:24 2011 From: alex at a13x.net (Aleksandar Radulovic) Date: Mon, 23 May 2011 08:52:24 +0000 Subject: Why did Quora choose Python for its development? In-Reply-To: <9CDC4B2CD1F445E994119A50F65155DF@teddy> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> Message-ID: Hi, I'm going to skip the Perl vs. Python flame-bait and correct your one statement. On Sun, May 22, 2011 at 7:44 AM, Octavian Rasnita wrote: > Somebody told that C# and Objective C are good languages. They might be good, but they are proprietary, and not only that they are proprietary, but they need to be ran under platforms that cannot be used freely, so from the freedom point of view, Perl, Ruby, Python and Java are the ways to go. Neither of those are proprietary and can, in fact, be used freely. GNU compiler compiles objective-c code with no problem and then there's Mono for C# and .NET development on multiple platforms. But if by proprietary you mean the libraries and APIs that complement those languages, the it's worth noting that Mono implements most of .NET framework and it is free. If you want "free" Cocoa APIs (or other Obj-C frameworks) look into GnuSTEP. Best regards, alex. -- a lex 13 x http://www.a13x.info From orasnita at gmail.com Mon May 23 05:01:35 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 12:01:35 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian> Message-ID: <012186634A924F38862902F52B2EF799@octavian> From: "Chris Angelico" > On Mon, May 23, 2011 at 3:31 PM, Octavian Rasnita > wrote: >> From: "Dennis Lee Bieber" >>> >>> Since indentation seems so crucial to easy comprehension of the logical >>> structure of a program, >>> making it a mandatory syntactical structure becomes a desirable feature >>> for code that must be maintained (by others, in many cases). >> >> Why "in many cases"? I wrote hundreads of programs which are working fine >> and which are maintained only by me. (But they would be very easy to >> maintain by other people if it would be necessary). >> So in that case, why to be forced to use a strict indentation? > > The reason for clear code is maintenance, not maintenance-by-others. > If you come back to something in a year, you'll appreciate proper > variable names, indentation, etc. > > That said, though, I still do not believe in Python's philosophy of > significant whitespace. I like to be able, if I choose, to put one > entire "logical unit" on one line, such that it can be commented out > with a single comment marker, or duplicated to another line and one > copy commented out, or whatever. To that end, I sometimes want to put > an if, its associated else, and sometimes a statement for both > branches, all in the one line. And that's not possible when whitespace > alone defines the end of an if/else block (the one-line form of a > Python 'if' can't have a non-conditional statement after it at all), > but is quite easy when things are delimited with braces. Yes I also agree with that, and I also prefer *in some cases* to write short code in a single line like: print "..." if $var; print $var == 123 ? "abcd" : "cedf"; print $var =~ /foo/ ? "abc" : "cdef"; ...instead of writing a few lines of code. These constructs are not recommended for Perl either, and Perl::Critic would give a warning when it will be used with a certain level of errors checking, but it is preferable to be able to do what you want how you or your team want, not as the creator of the programming language wants. And I don't think that there are programmers that find the lines above hard to understand or maintain. Octavian From info at egenix.com Mon May 23 05:35:23 2011 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 23 May 2011 11:35:23 +0200 Subject: ANN: eGenix mx Base Distribution 3.2.0 (mxDateTime, mxTextTools, etc.) Message-ID: <4DDA2A5B.301@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mx Base Distribution Version 3.2.0 for Python 2.4 - 2.7 Open Source Python extensions providing important and useful services for Python programmers. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.0-GA.html ________________________________________________________________________ ABOUT The eGenix.com mx Base Distribution for Python is a collection of professional quality software tools which enhance Python's usability in many important areas such as fast text searching, date/time processing and high speed data types. The tools have a proven record of being portable across many Unix and Windows platforms. You can write applications which use the tools on Windows and then run them on Unix platforms without change due to the consistent platform independent interfaces. Contents of the distribution: * mxDateTime - Easy to use Date/Time Library for Python * mxTextTools - Fast Text Parsing and Processing Tools for Python * mxProxy - Object Access Control for Python * mxBeeBase - On-disk B+Tree Based Database Kit for Python * mxURL - Flexible URL Data-Type for Python * mxUID - Fast Universal Identifiers for Python * mxStack - Fast and Memory-Efficient Stack Type for Python * mxQueue - Fast and Memory-Efficient Queue Type for Python * mxTools - Fast Everyday Helpers for Python All available packages have proven their stability and usefulness in many mission critical applications and various commercial settings all around the world. For more information, please see the distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.1.3 release of the eGenix mx Base Distribution is the latest release of our open-source Python extensions. The new version provides major enhancements of the included packages. To highlight a few: * Added support for Python 2.7 on all supported platforms. * Added native Window x64 support. * Included many news features in mxDateTime to enhance interoperability with Python's datetime module and to increase overall performance: o Mixed type support to allow operations between mxDateTime objects and Python's datetime module o New constructor methods on the objects to easily switch from mxDateTime objects to datetime module objects. o New constructor support to easily switch back from datetime module objects to mxDateTime objects * Added new mx.Misc.Daemon module which provides abstractions to implement Unix daemon processes. * Added code cleanups and switched to Python's own memory allocator, which results in performance enhancements across all subpackages. * Added back easy_install support and included pip support. As always, we are providing pre-built binaries for all common platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac OS X 32/64-bit. Source code archives are available for installation on all other Python platforms, such as Solaris, AIX, HP-UX, etc. To simplify installation in Zope/Plone and other egg-based systems, we have also precompiled egg distributions for all platforms. These are available on our own PyPI-style index server for easy and automatic download. Whether you are using a pre-built package or the source distribution, installation is a simple "python setup.py install" command in all cases. The only difference is that the pre-built packages do not require a compiler or the Python development packages to be installed. For a list of changes, please refer to the eGenix mx Base Distribution change log at http://www.egenix.com/products/python/mxBase/changelog.html and the change logs of the various included Python packages. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the packages can be found on the eGenix mx Base Distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ LICENSE The eGenix mx Base package is distributed under the eGenix.com Public License 1.1.0 which is an Open Source license similar to the Python license. You can use the packages in both commercial and non-commercial settings without fee or charge. The package comes with full source code ________________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, May 23 2011) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2011-06-20: EuroPython 2011, Florence, Italy 28 days to go ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From orasnita at gmail.com Mon May 23 05:41:56 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 12:41:56 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> Message-ID: From: "Daniel Kluev" > On Mon, May 23, 2011 at 5:06 PM, Octavian Rasnita > wrote: >> There are more, but a single eloquent feature is the possibility of >> interpreting variables in strings which cannot be done so nice in Python. > > I've should probably mentioned it earlier, but I'm not Perl expert, > not following its development and can't be bothered to read its docs. > Could you please provide examples of features you mention with > expected result, so I could suggest reasonable Python analogue? The ones that bash other languages on the mailing list for their prefered language should provide good comparisons and not just make false statements, considering that it is enough, since most of the list members will agree because they like Python more than other languages anyway. If they think that what they say is true, why don't they make those statements on Perl mailing lists, but again, offering valid comparisons. > But if you want to couple it with controller code, there, as I said, > are numerous ways to do it. You can even do something like this: > > class SomeController(BaseController): > ... > @map(conditions=dict(method='GET')) > def some_method(self, arg1:int, arg2:str): > ... > so it would be called via /somecontroller/some-method/1/blabla with > trivial decorator. Is the url something like /some_controller/some_method? Or the underlines are deleted from the name of the controller and replaced with "-" in the name of the method? Is it possible to also add a configuration here to call this some_method when the url /some_controller/some-method-string is accessed? (define another string than the name of the method) Is it possible to configure it to access this subroutine only if a certain number of parameters are sent in the URL? If yes, it means that its dispatcher is better than I've seen in the short tutorial on the web. >> (unless in Pylons/Pyramid can be also defined chained mappings and >> mappings >> based on regular expressions). > > Not sure what do you mean by "based on regular expressions". Routes > paths ARE regular expressions. Conditions are regexes too. > > As for chained mappings - no idea, never had the need in such thing. The chained dispatcher is one of the best thing offered by Catalyst, because with it the same code should not be used twice. For example, one can define a subroutine in which a certain record is selected from the DB and is placed in stash. Then there may be other subroutines for different tasks, one for editing that record, one for deleting that record and so on. One chain can start with the base subroutine that makes the selection from the DB then executes the subroutine that makes the deletion and another chain can start with the base subroutine that makes the selection than continues with the one that starts the editting. Of course, the chain can have more links, not only 2, but this was just a very short example. >> I've checked the documentation for some of them and I've seen that most >> of >> them don't support sub-selects and some of them require using plain SQL >> code >> in their construct for more complex queries. >> Please tell me which of them supports sub-selects, and are able to return >> objects for date and datetime fields that have methods for beeing able to >> print just the year or day, or the months names in the specified locale >> because it would be useful. > > Python has builtin type for DateTime, and SQLAlchemy, for example, > returns exactly that: >>>> t1.date.month > 5 Can it also set the current locale, for example romanian, and print the name of the current month? ...something like t1.date.set_locale('ro').month_name? > SELECT anon_1.test_id AS anon_1_test_id, anon_1.test_val AS > anon_1_test_val, anon_1.test_date AS anon_1_test_date > FROM (SELECT test.id AS test_id, test.val AS test_val, test.date AS > test_date > FROM test) AS anon_1 As I said, that ORM is not able to do those SQL constructs without using literal SQL code, but only Python variables and data structures... An ORM is usually prefered exactly because it doesn't force the programmer to concatenate strings for generating the SQL code, but he/she can use just standard Perl/Python code. Or this is possible in another way without using SQL code? >> it can do but DBIx::Class cannot, because otherwise it would be very >> simple >> for anyone to just say "go to read the documentation and see how great it >> is". > > But "go to read the docs" argument works both ways - I have zero > knowledge of DBIx::Class, so obviously I cannot say what features it > lacks compared to SQLA. Yes you are perfectly right, but not those programmers that also use Perl started to say that Perl can do this and Python can't, or that in Perl this is shorter and nicer than in Python. I just wanted to show that anything Python can do can be done in Perl also, and in some fields Python is better, in other fields Perl is better, and we should use whatever we like the most, and not say bad words about other languages or about those who use other languages, especially in a coward-way, on the group of programmers that prefer the praised language. Octavian From awilliam at whitemice.org Mon May 23 05:50:31 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 23 May 2011 05:50:31 -0400 Subject: Multiprocessing: don't push the pedal to the metal? In-Reply-To: References: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> Message-ID: <1306144231.11345.10.camel@linux-yu4c.site> On Mon, 2011-05-23 at 10:32 +1000, Chris Angelico wrote: > On Mon, May 23, 2011 at 7:06 AM, John Ladasky wrote: > > If I spawn N worker sub-processes, my application in fact has N+1 > > processes in all, because there's also the master process itself. > > I'd still appreciate hearing from anyone else who has more experience > > with multiprocessing. If there are general rules about how to do this > > best, I haven't seen them posted anywhere. This may not be a Python- > > specific issue, of course. > I don't have much experience with Python's multiprocessing model, but > I've done concurrent programming on a variety of platforms, and there > are some common issues. I develop an app that uses multiprocessing heavily. Remember that all these processes are processes - so you can use all the OS facilities regarding processes on them. This includes setting nice values, schedular options, CPU pinning, etc... > Each CPU (or core) has its own execution cache. If you can keep one > thread running on the same core all the time, it will benefit more > from that cache than if it has to keep flitting from one to another. +1 > You undoubtedly will have other processes in the system, too. As well > as your master, there'll be processes over which you have no control > (unless you're on a bare-bones system). Some of them may preempt your > processes. This is very true. You get a benefit from dividing work up to the correct number of processes - but too many processes will quickly take back all the benefit. One good trick is to have the parent monitor the load average and only spawn additional workers when that value is below a certain value. From dan.kluev at gmail.com Mon May 23 05:58:51 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 20:58:51 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <629DAC3611EA49B0A36BCF70151CDE2F@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> Message-ID: On Mon, May 23, 2011 at 7:49 PM, Octavian Rasnita wrote: > That is not an array, but a list. An array has a name and we can't do > something like the following simple statement in Python: > > l = (1, 2) > d = dict(l) > An array has a name What? In python there is no difference whether your object has any names mapped to it or not. Its all the same, and object itself does not even know. Moreover, (1, 2) is tuple rather than 'array'. If you mean array as implemented as array, then list is what you want. If you mean array literally, there is special type 'array' somewhere in stdlib. As for "can't do": >>> a = [1,2] >>> dict([a]) {1: 2} >>> a = (1,2) >>> dict([a]) {1: 2} -- With best regards, Daniel Kluev From dan.kluev at gmail.com Mon May 23 06:16:42 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 21:16:42 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> Message-ID: On Mon, May 23, 2011 at 8:41 PM, Octavian Rasnita wrote: > From: "Daniel Kluev" > As I said, that ORM is not able to do those SQL constructs without using > literal SQL code, but only Python variables and data structures... > An ORM is usually prefered exactly because it doesn't force the programmer > to concatenate strings for generating the SQL code, but he/she can use just > standard Perl/Python code. > Or this is possible in another way without using SQL code? Did you actually read the code? SQL there is debug output of SQLAlchemy for python code `Session.query(Test).from_self().all()`, I left it there to just show you that it emits subquery to RDBMS. All code in REPL is prefixed by `>>> `. Other lines are just output. > Can it also set the current locale, for example romanian, and print the name of the current month? > ...something like t1.date.set_locale('ro').month_name? There is separate module for date localization. You can pass datetime object to it and it will give you needed value. > The ones that bash other languages on the mailing list for their prefered language should provide good comparisons and not just make false statements That would be valid if I would 'bash other languages', but I just responded to your claim that Perl has advanced modules which are not available for Python, esp. in web frameworks, as I find it one of areas where Python shines most. Sure Python has drawbacks, esp. its performance and poor threads support (GIL), but flexibility and modules of all flavors and types are not among them. Introduction of parameter annotations should make these modules even greater, once python 3.x is widely adopted. -- With best regards, Daniel Kluev From jldunn2000 at gmail.com Mon May 23 06:32:49 2011 From: jldunn2000 at gmail.com (loial) Date: Mon, 23 May 2011 03:32:49 -0700 (PDT) Subject: Python 2.6 and timezones Message-ID: <46c24750-ac9b-4d75-835c-5403ff2ea959@d28g2000yqf.googlegroups.com> Does python have an equivalent of the java Timezone object? I need to be able to get offsets for timezones (only U.S. time zones at the moment) From patrick.just4fun at gmail.com Mon May 23 06:41:08 2011 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Mon, 23 May 2011 12:41:08 +0200 Subject: Dealing with name clashes in pypi In-Reply-To: References: <4DD9573E.8010509@gmail.com> Message-ID: <4DDA39C4.1010300@gmail.com> On 2011-05-22 23:23, Terry Reedy wrote: > On 5/22/2011 2:34 PM, Patrick Sabin wrote: >> I wanted to register my project (epdb) in pypi. Unfortunately there >> already exists a project with the same name. It is not possible for me >> to change the name of the project, because I used it in multiple >> writings. Any ideas how I can deal with the situation? Is it possible to >> register a project under a different name in pypi than the actual >> project name? > > I presume so. How would pypi know the 'actual' name? > However, there is a catalog sig list (mirrored as > gmane.comp.python.catalog) where you might get specific suggestions on > how to handle this. > Thanks for the tip. I will try it there. -- Patrick From robin at reportlab.com Mon May 23 06:45:35 2011 From: robin at reportlab.com (Robin Becker) Date: Mon, 23 May 2011 11:45:35 +0100 Subject: Abandoning Python In-Reply-To: <87ipt46okh.fsf@pobox.com> References: <87ipt46okh.fsf@pobox.com> Message-ID: <4DDA3ACF.9050408@chamonix.reportlab.co.uk> On 21/05/2011 16:49, John J Lee wrote: > > > I still like Python after using it for over a decade, but there are > things I don't like. ...... a relatively new one that's going about is cobra, http://cobra-language.com/, it appears to have some of the features you indicate eg speed, some kind of interfaces (contracts I think), but it needs net or mono. -- Robin Becker From dan.kluev at gmail.com Mon May 23 06:48:05 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 21:48:05 +1100 Subject: Python 2.6 and timezones In-Reply-To: <46c24750-ac9b-4d75-835c-5403ff2ea959@d28g2000yqf.googlegroups.com> References: <46c24750-ac9b-4d75-835c-5403ff2ea959@d28g2000yqf.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 9:32 PM, loial wrote: > Does python have an equivalent of the java Timezone object? > > I need to be able to get offsets for timezones (only U.S. time zones > at the moment) Depends on what exactly do you want. If you need to convert timezone name into current offset, you should use [1] or [2]. If you just need to handle known offsets for datetime objects, there is tzinfo class in datetime module, [3]. [1] http://pypi.python.org/pypi/PosixTimeZone/0.9.4 [2] http://pypi.python.org/pypi/pytz/2011g [3] http://docs.python.org/library/datetime.html#tzinfo-objects -- With best regards, Daniel Kluev From floris.bruynooghe at gmail.com Mon May 23 06:53:05 2011 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Mon, 23 May 2011 03:53:05 -0700 (PDT) Subject: Condition.wait(timeout) oddities Message-ID: <94d1d127-b423-4bd4-853c-d92da9ac7588@glegroupsg2000goo.googlegroups.com> Hi all I'm a little confused about the corner cases of Condition.wait() with a timeout parameter in the threading module. When looking at the code the first thing that I don't quite get is that the timeout should never work as far as I understand it. .wait() always needs to return while holding the lock, therefore it does an .acquire() on the lock in a finally clause. Thus pretty much ignoring the timeout value. The second issue is that while looking around for this I found two bug reports: http://bugs.python.org/issue1175933 and http://bugs.python.org/issue10218. Both are proposing to add a return value indicating whether the .wait() timed out or not similar to the other .wait() methods in threading. However the first was rejected after some (seemingly inconclusive) discussion. While the latter had minimal discussion and and was accepted without reference to the earlier attempt. Not sure if this was a process oversight or what, but it does leave the situation confusing. But regardless I don't understand how the return value can be used currently: yes you did time out but you're still promised to hold the lock thanks to the .acquire() call on the lock in the finally block. In my small brain I just can't figure out how Condition.wait() can both respect a timeout parameter and the promise to hold the lock on return. It seems to me that the only way to handle the timeout is to raise an exception rather then return a value because when you get an exception you can break the promise of holding the lock. But maybe I'm missing something important or obvious, so I'd be happy to be enlightened! Regards Floris From ulrich.eckhardt at dominolaser.com Mon May 23 06:56:45 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 23 May 2011 12:56:45 +0200 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: Octavian Rasnita wrote: > Somebody told that C# and Objective C are good languages. They might be > good, but they are proprietary, and not only that they are proprietary, > but they need to be ran under platforms that cannot be used freely, so > from the freedom point of view, Perl, Ruby, Python and Java are the ways > to go. Ahem, is this Java the language that a certain, well-known service provider is getting screwed over hard currently, because they forgot to read the fineprint in the declaration of freedom? And this Objective C, isn't this the language that GCC had support for since before it properly supported C++, and that on a multitude of targets? I'm probably just confusedly feeding flames here, but I like it snug and warm. (: Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From nobody at nowhere.net.no Mon May 23 07:06:07 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 23 May 2011 19:06:07 +0800 Subject: how to get PID from subprocess library References: Message-ID: GMail Felipe wrote: > For the "ps" command, have you seen the psuti module? > > The link to it is: http://code.google.com/p/psutil/ You gave a brand new start :) I bit of additional program to include into the package ;) -- goto /dev/null From orasnita at gmail.com Mon May 23 07:10:55 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 14:10:55 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian> Message-ID: <57C0AB91B42743E89456ACCC8751CF78@octavian> From: "Daniel Kluev" a = [1,2] dict([a]) Yes, but d = dict([a]) is not so nice as $d = @a; because it has exactly those numerous number of params and brackets which is used as a reason for bashing Perl and an aditional "dict" word. Octavian From orasnita at gmail.com Mon May 23 07:17:59 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 14:17:59 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> Message-ID: <46EA3D502B204937A4EE89E34471BC0F@octavian> From: "Daniel Kluev" ... >> Can it also set the current locale, for example romanian, and print the >> name of the current month? >> ...something like t1.date.set_locale('ro').month_name? > > There is separate module for date localization. You can pass datetime > object to it and it will give you needed value. Aha, so with other words that ORM doesn't have that feature. DBIX::Class also use the DateTime module, but it can use it directly, without needing to write more code for that, and it can also return localized dates. >> The ones that bash other languages on the mailing list for their prefered >> language should provide good comparisons and not just make false >> statements > > That would be valid if I would 'bash other languages', but I just > responded to your claim that Perl has advanced modules which are not No you haven't responded because you haven't shown any thing that can be done by the web framework and the ORM you are praising but can't be done by Catalyst and DBIx::Class, however I have shown you that DBIx::Class can return DateTime objects directly, without needing to load the DateTime module manually and to initialize the DateTime object manually... And don't take my words out of the context, because I have also answered to another list member that was bashing Perl without offering other helpful information than just that kind of jokes which are usually made by teenagers under 30. Octavian From duncan.booth at invalid.invalid Mon May 23 07:28:29 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 May 2011 11:28:29 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: Ulrich Eckhardt wrote: > Ahem, is this Java the language that a certain, well-known service > provider is getting screwed over hard currently, because they forgot > to read the fineprint in the declaration of freedom? That would be the case where the plaintiff has been ordered to drop all but 3 of their 132 claims? It isn't at all obvious yet who is going to be 'screwed over hard'. -- Duncan Booth http://kupuguy.blogspot.com From dan.kluev at gmail.com Mon May 23 07:32:44 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 22:32:44 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <46EA3D502B204937A4EE89E34471BC0F@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> <46EA3D502B204937A4EE89E34471BC0F@octavian> Message-ID: On Mon, May 23, 2011 at 10:17 PM, Octavian Rasnita wrote: > From: "Daniel Kluev" > Aha, so with other words that ORM doesn't have that feature. > DBIX::Class also use the DateTime module, but it can use it directly, > without needing to write more code for that, and it can also return > localized dates. Once again. ORMs return _python builtin type_. Localization is not their responsibility, and plugging it there is code bloat, rather than feature. Sure you may ask ORM to handle JSONRPC requests on its own, but ORM responsibility is to map RDBMS features to language objects. All good python packages limit their functionality to specific field, so you could choose one you prefer for each different task independently. > without needing to load the DateTime module manually and to initialize the DateTime object manually... This is basically stating that you didn't read the code I posted. Where did you ever find "initialize the DateTime object manually"? Sorry, but its pointless to discuss anything if you don't want to even read properly examples you receive. -- With best regards, Daniel Kluev From jldunn2000 at gmail.com Mon May 23 07:56:29 2011 From: jldunn2000 at gmail.com (loial) Date: Mon, 23 May 2011 04:56:29 -0700 (PDT) Subject: Python 2.6 and timezones References: <46c24750-ac9b-4d75-835c-5403ff2ea959@d28g2000yqf.googlegroups.com> Message-ID: <932c351d-0dbd-4d5b-8151-e695b4b83fe1@z37g2000vbl.googlegroups.com> Thanks...but being a python newbie I am struggling to understand how to do this. How can I use tzinfo to do the equivalent of what I do in Java, which is : TimeZone tz1 = TimeZone.getDefault(); long localOffset = tz1.getOffset(date.getTime()); TimeZone tz2 = TimeZone.getTimeZone("EST"); long remoteOffset = tz2.getOffset(date.getTime()); Any help appreciated On May 23, 11:48?am, Daniel Kluev wrote: > On Mon, May 23, 2011 at 9:32 PM, loial wrote: > > Does python have an equivalent of the java Timezone object? > > > I need to be able to get offsets for timezones (only U.S. time zones > > at the moment) > > Depends on what exactly do you want. If you need to convert timezone > name into current offset, you should use [1] or [2]. > If you just need to handle known offsets for datetime objects, there > is tzinfo class in datetime module, [3]. > > [1]http://pypi.python.org/pypi/PosixTimeZone/0.9.4 > [2]http://pypi.python.org/pypi/pytz/2011g > [3]http://docs.python.org/library/datetime.html#tzinfo-objects > > -- > With best regards, > Daniel Kluev From cjw at ncf.ca Mon May 23 08:20:16 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Mon, 23 May 2011 08:20:16 -0400 Subject: and becomes or and or becomes and In-Reply-To: <4DD96297.5010909@gmail.com> References: <4DD96297.5010909@gmail.com> Message-ID: On 22-May-11 15:23 PM, Stef Mientki wrote: > hello, > > must of us will not use single bits these days, > but at first sight, this looks funny : > >>>> a=2 >>>> b=6 >>>> a and b > 6 >>>> a& b > 2 >>>> a or b > 2 >>>> a | b > 6 > > cheers, > Stef 5.2. Boolean Operations ? and, or, not These are the Boolean operations, ordered by ascending priority: Operation Result Notes x or y if x is false, then y, else x (1) x and y if x is false, then x, else y (2) not x if x is false, then True, else False (3) The second line is puzzling at first look, but consistent. It is analogous to the Conditional Expression. See: http://docs.python.org/reference/expressions.html#conditional-expressions Colin W. From dan.kluev at gmail.com Mon May 23 08:33:40 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 23:33:40 +1100 Subject: Python 2.6 and timezones In-Reply-To: <932c351d-0dbd-4d5b-8151-e695b4b83fe1@z37g2000vbl.googlegroups.com> References: <46c24750-ac9b-4d75-835c-5403ff2ea959@d28g2000yqf.googlegroups.com> <932c351d-0dbd-4d5b-8151-e695b4b83fe1@z37g2000vbl.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 10:56 PM, loial wrote: > Thanks...but being a python newbie I am struggling to understand how > to do this. > > How can I use tzinfo to do the equivalent of what I do in Java, which > is : > > TimeZone tz1 = TimeZone.getDefault(); > > long localOffset = tz1.getOffset(date.getTime()); > > TimeZone tz2 = TimeZone.getTimeZone("EST"); > > long remoteOffset = tz2.getOffset(date.getTime()); > >>> from pytz import timezone, FixedOffset >>> import time >>> from datetime import datetime >>> local_tz = FixedOffset(-time.timezone/60) time.timezone returns local timezone in seconds and negative sign. FixedOffset converts it into tzinfo object. >>> now = datetime.now() >>> local_tz.utcoffset(now) datetime.timedelta(0, 36000) utcoffset() returns timedelta object as offset. It requires datetime object as first parameter due to weird API of base tzinfo class, but it is not used in calculation, and you can pass any other object, including None instead, like `local_tz.utcoffset(None)` >>> remote_tz = timezone("EST") >>> remote_tz.utcoffset(now) datetime.timedelta(-1, 68400) You can add or substract these timedelta objects directly from datetime objects or use astimezone(): >>> now = datetime.now(local_tz) >>> now datetime.datetime(2011, 5, 23, 22, 41, 48, 398685, tzinfo=pytz.FixedOffset(600)) >>> now.astimezone(remote_tz) datetime.datetime(2011, 5, 23, 7, 41, 48, 398685, tzinfo=) -- With best regards, Daniel Kluev From zdoor at xs4all.nl Mon May 23 09:00:53 2011 From: zdoor at xs4all.nl (Alex van der Spek) Date: Mon, 23 May 2011 15:00:53 +0200 Subject: Multiple file select with tkFileDialog passes back 'decorated' strings (sometimes) Message-ID: <4dda5a89$0$49175$e4fe514c@news.xs4all.nl> I switched from Mark Hammonds pywin32 extensions for file choosers as the multiselect there seems to crash on me when selecting more than a few dozen. Using Tk now. Works well but the resulting string passed back seems to 'decorated' when the files are on local disk and not decorated when retrieved over a USB interface from an external disk? I do this: >From local disk I get back: '{file1.bin} {file2.bin}' >From external disk I get back: 'file1.bin file2.bin' I can handle/parse both, not an issue but it raises the question: Are these the only two possibilities? Is it the same across platforms (I use Python 2.7 on Win Vista)? See code below. Thanks for the insight! Alex van der Spek +++++++++++++++++++ from Tkinter import * import tkFileDialog as tkf tkroot=Tk() tkroot.withdraw() initdir=os.environ['HOME'] filetype=[('Binary Timeseries','*.bin'),('All files','*.*')] filenames=tkf.askopenfilenames(parent=tkroot,initialdir=initdir,filetypes=filetype) tkroot.destroy() From miki.tebeka at gmail.com Mon May 23 09:06:25 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 23 May 2011 06:06:25 -0700 (PDT) Subject: Python 2.6 and timezones In-Reply-To: Message-ID: <93bd4afe-ba6d-4b0c-a239-ad0b877c577e@glegroupsg2000goo.googlegroups.com> > [1] http://pypi.python.org/pypi/PosixTimeZone/0.9.4 > [2] http://pypi.python.org/pypi/pytz/2011g > [3] http://docs.python.org/library/datetime.html#tzinfo-objects Also http://labix.org/python-dateutil#head-587bd3efc48f897f55c179abc520a34330ee0a62 HTH -- Miki Tebeka http://pythonwise.blogspot.com From miki.tebeka at gmail.com Mon May 23 09:06:25 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 23 May 2011 06:06:25 -0700 (PDT) Subject: Python 2.6 and timezones In-Reply-To: Message-ID: <93bd4afe-ba6d-4b0c-a239-ad0b877c577e@glegroupsg2000goo.googlegroups.com> > [1] http://pypi.python.org/pypi/PosixTimeZone/0.9.4 > [2] http://pypi.python.org/pypi/pytz/2011g > [3] http://docs.python.org/library/datetime.html#tzinfo-objects Also http://labix.org/python-dateutil#head-587bd3efc48f897f55c179abc520a34330ee0a62 HTH -- Miki Tebeka http://pythonwise.blogspot.com From pjb at informatimago.com Mon May 23 09:39:11 2011 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 23 May 2011 15:39:11 +0200 Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> <7zpqn9re8v.fsf@ask.diku.dk> Message-ID: <87tyclk03k.fsf@kuiper.lan.informatimago.com> torbenm at diku.dk (Torben ?gidius Mogensen) writes: > Xah Lee writes: > > >> Functional Programing: stop using recursion, cons. Use map & vectors. >> >> ?Guy Steele on Parallel Programing? >> http://xahlee.org/comp/Guy_Steele_parallel_computing.html > > This is more or less what Backus said in his Turing Award lecture about > FP. Stop inflating his ego! Next he'll quote Nobel prize winners... -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From mail at timgolden.me.uk Mon May 23 11:13:38 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 23 May 2011 16:13:38 +0100 Subject: Problem in using subprocess module and communicate() In-Reply-To: References: <4DDA1CF5.60103@timgolden.me.uk> Message-ID: <4DDA79A2.7060602@timgolden.me.uk> [cc-ing back to the list; please keep the conversation over there...] On 23/05/2011 13:11, vijay swaminathan wrote: > What I want to achieve is, I want to run a batch file on a command prompt. > > The reason for using thread is not for running multiple scripts > simultaneously. It is just to monitor my script running in command > prompt. only on closing the command prompt, I like to perform some more > actions. so I look to monitor my thread. Hope it is clear until now. Ok. That's perfectly clear. > > the below mentioned code does not invoke the command prompt at all. Does > the subprocess.call take care of invoking the command prompt? Adding shell=True invokes %COMSPEC% (usually cmd.exe) under the covers. How do you know it's not invoking the command prompt? Does your batch file generate output? And is that output generated? Without the CREATE_NEW_CONSOLE flag, you won't see an extra box pop up, but unless you specifically want one, then don't bother. OK, baby steps. Here's a batch file: @echo Hello and here's a Python script which runs it: import subprocess subprocess.call ("tjg.bat", shell=True) I opened a console (cmd.exe), ran tjg.py and, as expected, "Hello" appears in the same console. Note that, if I hadn't made the .bat file generate some output I wouldn't have seen anything but it would still have worked. I now make the .bat file do something more long-winded, such as fire up a Python session which waits for five seconds and then completes: @echo off echo Starting python -c "import time; time.sleep (5)" echo Finished When I run tjg.py again, I see "Starting" and then a pause of 5 seconds, and then "Finished". Now let's make the Python program monitor to see when that batch has finished by watching the isAlive status and then sleeping for a second: import subprocess import threading import time def run_tjg (): subprocess.call ("tjg.bat", shell=True) t = threading.Thread (target=run_tjg) t.start () while t.isAlive (): print "is alive" time.sleep (1) print "Thread is complete" When I run this, I get a mixture of output, depending on what gets to the console first, but essentially I see the batch file starting, I get a series of about 5 "is alive" messages, then the batch file "Finished" message and the Python "Thread is complete" message. Does that work for you? TJG From john at castleamber.com Mon May 23 11:26:56 2011 From: john at castleamber.com (John Bokma) Date: Mon, 23 May 2011 10:26:56 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> Message-ID: <87pqn95tfj.fsf@castleamber.com> Chris Angelico writes: > That said, though, I still do not believe in Python's philosophy of > significant whitespace. I like to be able, if I choose, to put one > entire "logical unit" on one line, such that it can be commented out > with a single comment marker, Use an editor that can with a single command comment out a selection (and revert this), like Emacs. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From arayapablo93 at hotmail.com Mon May 23 11:29:39 2011 From: arayapablo93 at hotmail.com (pablo araya) Date: Mon, 23 May 2011 09:29:39 -0600 Subject: python help In-Reply-To: References: , Message-ID: > > Hi I'm tryin to create a game but I have a question in how to save > > (saveasfile) the value of a global variable.. and then load the same value > > with openfile. > > Also for example you have a main label and a botton on the left.... so when > > you click the left bottom the label will change or refresh to another label, > > and when you return to the original label show or refresh to the original > > one. All the works is with matrix in python 3.2 and also tkinter. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Mon May 23 11:30:25 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 23 May 2011 08:30:25 -0700 (PDT) Subject: and becomes or and or becomes and References: <4dd9aaac$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <71ab1ccc-c2c0-474f-b7bb-1000754317e4@z13g2000prk.googlegroups.com> On May 23, 5:30?am, Steven D'Aprano wrote: > On Sun, 22 May 2011 15:39:33 -0700, Tim Roberts wrote: > > Stef Mientki wrote: > > >>must of us will not use single bits these days, but at first sight, this > >>looks funny : > > >>>>> a=2 > >>>>> b=6 > >>>>> a and b > >>6 > >>>>> a & b > >>2 > >>>>> a or b > >>2 > >>>>> a | b > >>6 > > > That IS funny. ?Interesting how a careful choice of arugments will fool > > us. One of my favorite math jokes is like that. ?A teacher asked a > > student to reduce the following fraction: > > ? 16 > > ?---- > > ? 64 > > > He says "all I have to do is cancel out the sixes, so the answer is > > 1/4". > > One of my favourite variations on this is by Abbott and Costello, where > Costello proves that 13*7 = 28 in three different ways. > > http://www.youtube.com/watch?v=rLprXHbn19I Ha Ha! [You're hired Steven] From rustompmody at gmail.com Mon May 23 11:47:36 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 23 May 2011 08:47:36 -0700 (PDT) Subject: Tkinter bug? Message-ID: <5790ee23-37d1-4cdd-b88b-a63c2b627c41@k15g2000pri.googlegroups.com> If I start turtle from idle, and issue commands from there, there are all kinds of strange behaviors. I cant pin down any properly but they all look like IO issues. -- If the turtle window is hidden by the tkinter interpreter window, none of what is drawn appears -- If the turtle window is killed I get a this window is not responding box -- The window always shows as 'Non responding' I therefore guess that the emacs-related behavior I asked about earlier has little to do with emacs and more to do with tkinter on windows. Can someone confirm/deny this? http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f55b4cb77653115/6543ed65bbb51c09?lnk=gst&q=rusi#6543ed65bbb51c09 http://groups.google.com/group/comp.lang.python/browse_thread/thread/36e757567f28368e/8737ab250b9f657a?lnk=gst&q=rusi+ipython#8737ab250b9f657a From antti.ylikoski at tkk.fi Mon May 23 12:36:20 2011 From: antti.ylikoski at tkk.fi (Antti J Ylikoski) Date: Mon, 23 May 2011 19:36:20 +0300 Subject: Functional Programing: stop using recursion, cons. Use map & vectors In-Reply-To: <87tyclk03k.fsf@kuiper.lan.informatimago.com> References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> <7zpqn9re8v.fsf@ask.diku.dk> <87tyclk03k.fsf@kuiper.lan.informatimago.com> Message-ID: On 23.5.2011 16:39, Pascal J. Bourguignon wrote: > torbenm at diku.dk (Torben ?gidius Mogensen) writes: > >> Xah Lee writes: >> >> >>> Functional Programing: stop using recursion, cons. Use map& vectors. >>> >>> ?Guy Steele on Parallel Programing? >>> http://xahlee.org/comp/Guy_Steele_parallel_computing.html >> >> This is more or less what Backus said in his Turing Award lecture about >> FP. > > Stop inflating his ego! Next he'll quote Nobel prize winners... > Well said.... That inspired me to note: LISP without recursion would be like a jet airplane without wings.... Recursion is an important part of the functional programming paradigm (yes, I do know that LISP is not a purely functional language...) LISP denotes, List Processing. List Processing without cons ????? Ugh. regards, andy From nad at acm.org Mon May 23 12:55:15 2011 From: nad at acm.org (Ned Deily) Date: Mon, 23 May 2011 09:55:15 -0700 Subject: Tkinter bug? References: <5790ee23-37d1-4cdd-b88b-a63c2b627c41@k15g2000pri.googlegroups.com> Message-ID: In article <5790ee23-37d1-4cdd-b88b-a63c2b627c41 at k15g2000pri.googlegroups.com>, rusi wrote: > If I start turtle from idle, and issue commands from there, there are > all kinds of strange behaviors. Have you tried starting IDLE with the "-n" switch? http://docs.python.org/library/turtle.html -- Ned Deily, nad at acm.org From tjreedy at udel.edu Mon May 23 13:08:58 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 May 2011 13:08:58 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <629DAC3611EA49B0A36BCF70151CDE2F@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> Message-ID: On 5/23/2011 4:49 AM, Octavian Rasnita wrote: > But let's remember from what this discussion started. This is not a > Python critique, because each language has its own ways. > I just wanted to show that the fact that "there is more than one way to > do it" in Perl and that "there is a single way" in Python are just > buzzwords, Agreed. The latter is simply incorrect for Python and I don't know why people say that. The statement from the Zen of Python is as follows: "There should be one-- and preferably only one --obvious way to do it." where 'it' is some reasonable common operation. This is a statement of *intent* that is opposed to "All possible ways of doing things should be included". The key word that people too often omit is *obvious* (once one learns Python). There are usually, of necessity, multiple ways to do something, but for common operations, there should be one way that is obvious to the experienced Python programmer. For instance, if you want to process the items of a collections, you can use normal recursion, tail recursion, while iteration, or for iteration. For the first three, you can use explicit or implicit conditions for flow control. (Implicit conditions are by try-except.) One can use various access methods to get the items. However, the one obvious, compact, and efficient way is 'for item in collection:'. This works with *any* collection with a proper __iter__ method.\ People accustomed to using tail recursion for this in other languages sometimes request that tail-call space optimization be added to make tail recursion a second 'obvious' way. Guido has refused because 1) there are real problems with the idea and 2) one obvious way is enough. Similarly, the obvious way to define a function is a def statement. One alternative, which Guido allowed to be added for the specific purpose of passing simple functions as arguments in function calls, is a lambda expression. Guido has rejected requests to expand lambda expressions to general function definitions. Again, there are real problems and one obvious way is enough. > because this was an example where in Python there are many > ways to do it while in Perl there is a single way used usually, which is > also more simple. Here I disagree. As I replied before, you are either ignoring the obvious Python way or talking about a rare need. -- Terry Jan Reedy From ian.g.kelly at gmail.com Mon May 23 13:31:22 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 23 May 2011 11:31:22 -0600 Subject: Writing multiple files with with-context In-Reply-To: <5142852e-bab9-4e39-a49b-0229e900e97d@glegroupsg2000goo.googlegroups.com> References: <5142852e-bab9-4e39-a49b-0229e900e97d@glegroupsg2000goo.googlegroups.com> Message-ID: On Sun, May 22, 2011 at 8:48 PM, Shunichi Wakabayashi wrote: > One idea is using contextlib.nested(), > > from contextlib import nested > > with nested(*[open('list_%d.txt' % i, 'w') for i in range(LIST_LEN)]) as fobjlist: > ?for i in range(1000): > ? ?fobjlist[random.randrange(LIST_LEN)].write(str(i)+"\n") > > with nested(*[open('dict_%s.txt' % k, 'w') for k in DICT_KEYS]) as fobjlist: > ?fobjdict = dict(zip(DICT_KEYS, fobjlist)) #convert list to dict > ?for i in range(1000): > ? ?fobjdict[random.choice(DICT_KEYS)].write(str(i)+"\n") > > On Python2.x, this is OK. but 3.x warns that nested() is deprecated. Not merely deprecated. It has already been removed in 3.2. > Another idea is to make container classes having __exit__() myself. > > class MyList(list): > ?def __enter__(self): > ? ?return [ v.__enter__() for v in self ] > ?def __exit__(self, exc_type, exc_value, traceback): > ? ?ret = False > ? ?for v in self: > ? ? ?if v.__exit__(exc_type, exc_value, traceback): > ? ? ? ?ret = True > ? ? ? ?exc_type = exc_value = traceback = None > ? ?return ret This has a number of subtle bugs in it: 1) Each context manager's __exit__ method is not loaded before the corresponding __enter__ method is invoked. 2) If the second context manager's __enter__ method raises an exception, the first context manager's __exit__ method is never called, breaking the with statement guarantee. 3) The __exit__ methods are called in the same order that the __enter__ methods were called. Since they form a stack, they should be called in the reverse order. These highlight the complexity of handling context managers correctly, which I think suggests that a custom implementation is probably a bad idea. > So, do you have another, more smart and pythonic way? Copy the implementation of contextlib.nested to your own custom module and use that. The last revision prior to its removal is here: http://hg.python.org/cpython/file/45506be44514/Lib/contextlib.py From nospam at torek.net Mon May 23 13:32:19 2011 From: nospam at torek.net (Chris Torek) Date: 23 May 2011 17:32:19 GMT Subject: Condition.wait(timeout) oddities References: <94d1d127-b423-4bd4-853c-d92da9ac7588@glegroupsg2000goo.googlegroups.com> Message-ID: In article <94d1d127-b423-4bd4-853c-d92da9ac7588 at glegroupsg2000goo.googlegroups.com> Floris Bruynooghe wrote: >I'm a little confused about the corner cases of Condition.wait() with a >timeout parameter in the threading module. > >When looking at the code the first thing that I don't quite get is that >the timeout should never work as far as I understand it. .wait() always >needs to return while holding the lock, therefore it does an .acquire() >on the lock in a finally clause. Thus pretty much ignoring the timeout >value. It does not do a straight acquire, it uses self._acquire_restore(), which for a condition variable, does instead: self.__block.acquire() self.__count = count self.__owner = owner (assuming that you did not override the lock argument or passed in a threading.RLock() object as the lock), due to this bit of code in _Condition.__init__(): # If the lock defines _release_save() and/or _acquire_restore(), # these override the default implementations (which just call # release() and acquire() on the lock). Ditto for _is_owned(). [snippage] try: self._acquire_restore = lock._acquire_restore except AttributeError: pass That is, lock it holds is the one on the "blocking lock" (the __block of the underlying RLock), which is the same one you had to hold in the first place to call the .wait() function. To put it another way, the lock that .wait() waits for is a new lock allocated for the duration of the .wait() operation: waiter = _allocate_lock() waiter.acquire() self.__waiters.append(waiter) saved_state = self._release_save() self._acquire_restore(saved_state) # the last stmt is the "finally" clause, I've just un-indented it which is entirely different from the lock that .wait() re-acquires (and which you held when you called .wait() initially) before it returns. >The second issue is that while looking around for this I found two bug >reports: http://bugs.python.org/issue1175933 and >http://bugs.python.org/issue10218. Both are proposing to add a return >value indicating whether the .wait() timed out or not similar to the >other .wait() methods in threading. However the first was rejected >after some (seemingly inconclusive) discussion. Tim Peters' reply seemed pretty conclusive to me. :-) >While the latter had >minimal discussion and and was accepted without reference to the earlier >attempt. Not sure if this was a process oversight or what, but it does >leave the situation confusing. >But regardless I don't understand how the return value can be used >currently: yes you did time out but you're still promised to hold the >lock thanks to the .acquire() call on the lock in the finally block. The return value is not generally useful for the reasons Tim Peters noted originally. Those are all still true even in the second discussion. >In my small brain I just can't figure out how Condition.wait() can both >respect a timeout parameter and the promise to hold the lock on return. Remember, "two different locks". :-) There is a lock on the state of the condition variable itself, and then there is a lock on which one actually waits. On both entry to and return from .wait(), you (the caller) hold the lock on the state of the condition variable, so you may inspect it and proceed based on the result. In between, you give up that lock, so that other threads may obtain it and change the state of the condition variable. >It seems to me that the only way to handle the timeout is to raise an >exception rather then return a value because when you get an exception >you can break the promise of holding the lock. That *would* be a valid way to implement a timeout -- to return with the condition variable lock itself no longer held -- but that would require changing lots of other code structure. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From varunaseneviratna at gmail.com Mon May 23 14:08:02 2011 From: varunaseneviratna at gmail.com (Varuna Seneviratna) Date: Mon, 23 May 2011 23:38:02 +0530 Subject: I installed Python 3 on Fedora 14 By Downloading python3.2 bziped source tarball and install it according to the README, Now How shall I uninstalled python 3.2? Message-ID: I installed Python 3 By Downloading python3.2 bziped source tarball and install it according to the README, Now How shall I uninstalled python 3.2? The README instructions are as below Build Instructions ------------------ On Unix, Linux, BSD, OSX, and Cygwin: ./configure make make test sudo make install From skunkworks at rikishi42.net Mon May 23 14:48:13 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Mon, 23 May 2011 20:48:13 +0200 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On 2011-05-20, Hans Georg Schaathun wrote: >: It starts with the misconception (or should I say confusion?) between >: performing a recursive job and using a recursive tool to do it. And then it >: blazes off in these huge discusions about semantics to define a definition >: of an abstraction of a alleady theoretical problem. > > And explaining the source of the misconception and the varying use > would be irrelevant? It usually is, yes. And boring. -- When in doubt, use brute force. -- Ken Thompson From kracethekingmaker at gmail.com Mon May 23 14:55:08 2011 From: kracethekingmaker at gmail.com (kracekumar ramaraju) Date: Mon, 23 May 2011 11:55:08 -0700 (PDT) Subject: Is there a better way to solve this? In-Reply-To: Message-ID: You can use sizeof function, >>> a=12234 >>> b=23456.8 >>> a.__sizeof__() 12 >>> b.__sizeof__() 16 So sizeof int is 12 bytes and float is 16 bytes From kracethekingmaker at gmail.com Mon May 23 14:55:08 2011 From: kracethekingmaker at gmail.com (kracekumar ramaraju) Date: Mon, 23 May 2011 11:55:08 -0700 (PDT) Subject: Is there a better way to solve this? In-Reply-To: Message-ID: You can use sizeof function, >>> a=12234 >>> b=23456.8 >>> a.__sizeof__() 12 >>> b.__sizeof__() 16 So sizeof int is 12 bytes and float is 16 bytes From skunkworks at rikishi42.net Mon May 23 14:56:03 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Mon, 23 May 2011 20:56:03 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <37nqa8-lpa.ln1@murmur.very.softly> On 2011-05-20, Steven D'Aprano wrote: > On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: > >> [I agree with you Xah that recursion is a technical word that should not >> be foisted onto lay users.] > > I think that is a patronizing remark that under-estimates the > intelligence of lay people and over-estimates the difficulty of > understanding recursion. Why would you presume this to be related to intelligence? The point was not about being *able* to understand, but about *needing* to understand in order to use. -- When in doubt, use brute force. -- Ken Thompson From orasnita at gmail.com Mon May 23 15:05:28 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 22:05:28 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> Message-ID: <9F00F2A19C304079A16D8E4EDD6030C0@teddy> From: "Terry Reedy" > On 5/23/2011 4:49 AM, Octavian Rasnita wrote: > >> But let's remember from what this discussion started. This is not a >> Python critique, because each language has its own ways. >> I just wanted to show that the fact that "there is more than one way to >> do it" in Perl and that "there is a single way" in Python are just >> buzzwords, > > Agreed. The latter is simply incorrect for Python and I don't know why > people say that. The statement from the Zen of Python is as follows: > "There should be one-- and preferably only one --obvious way to do it." > where 'it' is some reasonable common operation. This is a statement of > *intent* that is opposed to "All possible ways of doing things should be > included". The key word that people too often omit is *obvious* (once > one learns Python). There are usually, of necessity, multiple ways to do > something, but for common operations, there should be one way that is > obvious to the experienced Python programmer. Yes you are right. And it is exactly the same in case of experienced Perl programmers. There is even a Perl book regarding the best practices, with many recommendations for the obvious way to do various things, and there is the module Perl::Critic with its command line percritic that follows those best practices very closely, so it is also just a buzzword that "there is more than one way to do it" for experienced Perl programmers. > > because this was an example where in Python there are many >> ways to do it while in Perl there is a single way used usually, which is >> also more simple. > > Here I disagree. As I replied before, you are either ignoring the > obvious Python way or talking about a rare need. I was talking about the method of creating a dictionary from an array which is much shorter and clear in Perl than in Python, and if you are using this very rarely, others might need to use it often. Octavian From ladasky at my-deja.com Mon May 23 15:51:36 2011 From: ladasky at my-deja.com (John Ladasky) Date: Mon, 23 May 2011 12:51:36 -0700 (PDT) Subject: Multiprocessing: don't push the pedal to the metal? References: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> Message-ID: <84e77cd9-9003-4053-a231-fe7d4bdbfef2@k15g2000pri.googlegroups.com> On May 23, 2:50?am, Adam Tauno Williams wrote: > I develop an app that uses multiprocessing heavily. ?Remember that all > these processes are processes - so you can use all the OS facilities > regarding processes on them. ?This includes setting nice values, > schedular options, CPU pinning, etc... That's interesting. Does code exist in the Python library which allows the adjustment of CPU pinning and nice levels? I just had another look at the multiprocessing docs, and also at os.subprocess. I didn't see anything that pertains to these issues. > > Each CPU (or core) has its own execution cache. If you can keep one > > thread running on the same core all the time, it will benefit more > > from that cache than if it has to keep flitting from one to another. > > +1 From sunrrrise at gmail.com Mon May 23 16:04:19 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Mon, 23 May 2011 13:04:19 -0700 (PDT) Subject: Odp: Re: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: Hello, I have checked another computer (WinXP, 32b) with Komodo Edit 6.1 and ActiveState Python 3.2 - problem still occurs. Have you received my email? s. From sunrrrise at gmail.com Mon May 23 16:04:19 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Mon, 23 May 2011 13:04:19 -0700 (PDT) Subject: Odp: Re: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: Hello, I have checked another computer (WinXP, 32b) with Komodo Edit 6.1 and ActiveState Python 3.2 - problem still occurs. Have you received my email? s. From drobinow at gmail.com Mon May 23 16:27:58 2011 From: drobinow at gmail.com (David Robinow) Date: Mon, 23 May 2011 16:27:58 -0400 Subject: Is there a better way to solve this? In-Reply-To: References: Message-ID: On Mon, May 23, 2011 at 2:55 PM, kracekumar ramaraju wrote: > You can use sizeof function, >>>> a=12234 >>>> b=23456.8 >>>> a.__sizeof__() > 12 >>>> b.__sizeof__() > 16 > So sizeof int is 12 bytes and float is 16 bytes I'm not sure what you're trying to show here, but try the following in Python 3.2 >>> a = 9999 >>> for i in range(5): ... a*= 100000 ... a.__sizeof__() ... From awilliam at whitemice.org Mon May 23 16:46:34 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 23 May 2011 16:46:34 -0400 Subject: Multiprocessing: don't push the pedal to the metal? In-Reply-To: <84e77cd9-9003-4053-a231-fe7d4bdbfef2@k15g2000pri.googlegroups.com> References: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> <84e77cd9-9003-4053-a231-fe7d4bdbfef2@k15g2000pri.googlegroups.com> Message-ID: <1306183594.2945.5.camel@linux-yu4c.site> On Mon, 2011-05-23 at 12:51 -0700, John Ladasky wrote: > On May 23, 2:50 am, Adam Tauno Williams > wrote: > > I develop an app that uses multiprocessing heavily. Remember that all > > these processes are processes - so you can use all the OS facilities > > regarding processes on them. This includes setting nice values, > > schedular options, CPU pinning, etc... > That's interesting. Does code exist in the Python library which > allows the adjustment of CPU pinning and nice levels? I just had > another look at the multiprocessing docs, and also at os.subprocess. > I didn't see anything that pertains to these issues. "in the Python library" - no. All these types of behaviors are platform specific. For example you can set the "nice" (priority) of a UNIX/LINUX process using the nice method from the os module. Our workflow engine does this on all worker processes it starts - it sends the workers to the lowest priority. from os import nice as os_priority ... try: os_priority(20) except Exception, e: ... I'm not aware of a tidy way to call sched_setaffinity from Python; but my own testing indicates that the LINUX kernel is very good at figuring this out on its own so long as it isn't swamped. Queuing, rather than starting, additional workflows if load average exceeds X.Y and setting the process priority of workers to very-low seems to work very well. There is for setting affinity, but I haven't used it. From floris.bruynooghe at gmail.com Mon May 23 17:43:19 2011 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Mon, 23 May 2011 14:43:19 -0700 (PDT) Subject: Condition.wait(timeout) oddities In-Reply-To: Message-ID: <8cbdbf97-b9c8-4ae4-8573-89e9a5354a58@glegroupsg2000goo.googlegroups.com> On Monday, 23 May 2011 17:32:19 UTC, Chris Torek wrote: > In article > <94d1d127-b423-4bd4... at glegroupsg2000goo.googlegroups.com> > Floris Bruynooghe wrote: > >I'm a little confused about the corner cases of Condition.wait() with a > >timeout parameter in the threading module. > > > >When looking at the code the first thing that I don't quite get is that > >the timeout should never work as far as I understand it. .wait() always > >needs to return while holding the lock, therefore it does an .acquire() > >on the lock in a finally clause. Thus pretty much ignoring the timeout > >value. > > It does not do a straight acquire, it uses self._acquire_restore(), > which for a condition variable, does instead: > > self.__block.acquire() > self.__count = count > self.__owner = owner > > (assuming that you did not override the lock argument or passed > in a threading.RLock() object as the lock), due to this bit of > code in _Condition.__init__(): > > # If the lock defines _release_save() and/or _acquire_restore(), > # these override the default implementations (which just call > # release() and acquire() on the lock). Ditto for _is_owned(). > [snippage] > try: > self._acquire_restore = lock._acquire_restore > except AttributeError: > pass Ah, I missed this bit in the __init__() and the fact that RLock provides the _acquire_restore() and _release_save(). I was wondering why they jumped around via self._acquire_restore() and self._release_save(), it seemed rather a lot of undocumented effort for custom locks. > That is, lock it holds is the one on the "blocking lock" (the > __block of the underlying RLock), which is the same one you had > to hold in the first place to call the .wait() function. > > To put it another way, the lock that .wait() waits for is > a new lock allocated for the duration of the .wait() operation: That makes more sense now. I knew that really, just never quite realised until you wrote this here so clearly. Thanks. So essentially the condition's lock is only meant to lock the internal state of the condition and not meant to be acquired for long times outside that as .wait() calls will not be able to return. My confusion started from looking at queue.Queue which replaces the lock with a regular lock and uses it to lock the Queue's resource. I guess the Queue's mutex satisfies the requirement of never being held for long times. > >The second issue is that while looking around for this I found two bug > >reports: http://bugs.python.org/issue1175933 and > >http://bugs.python.org/issue10218. Both are proposing to add a return > >value indicating whether the .wait() timed out or not similar to the > >other .wait() methods in threading. However the first was rejected > >after some (seemingly inconclusive) discussion. > > Tim Peters' reply seemed pretty conclusive to me. :-) Which is why I'm surprised that it now does. Cheers Floris From tjreedy at udel.edu Mon May 23 18:06:36 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 May 2011 18:06:36 -0400 Subject: Is there a better way to solve this? In-Reply-To: References: Message-ID: On 5/23/2011 2:55 PM, kracekumar ramaraju wrote: > You can use sizeof function, Appears not to be in manuals, that I could find. As a special method, it is intended to be called through sys.getsizeof. >>>> a=12234 >>>> b=23456.8 >>>> a.__sizeof__() > 12 >>>> b.__sizeof__() > 16 > So sizeof int is 12 bytes and float is 16 bytes Depends on system. On my winxp machine, ints are 14 bytes. >>> import sys >>> size = sys.getsizeof >>> size(1) 14 >>> size(1.0) 16 >>> size([]) 36 >>> size([1,2,3]) 48 -- Terry Jan Reedy From d.awlberg at hotmail.invalid Mon May 23 18:27:11 2011 From: d.awlberg at hotmail.invalid (Deeyana) Date: Mon, 23 May 2011 22:27:11 +0000 (UTC) Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On Mon, 23 May 2011 00:52:07 -0700, asandroq wrote: > On May 23, 4:29?am, Deeyana wrote: >> >> You might be interested in Clojure, then. Lists are more abstracted, >> like in Scheme, and vectors and also dictionaries/maps and sets are >> first class citizens along side lists. And unlike Scheme, Clojure has >> good library/host interop support. You can write real-world >> applications in it without spontaneously combusting. > > Nonsense. Classic unsubstantiated and erroneous claim. Nothing that I write is ever "nonsense". > Several Scheme systems have excellent FFIs with more than "good library/ > host interop support". Classic unsubstantiated and erroneous claim. Scheme does not come OOTB with any suitable libraries for host interop and though it can make calls to C libraries, doing so is awkward and involves difficulties with the impedance mismatch between Scheme's data structures and C's char *, void *, int, double, array, etc. types. To top it off, C lacks automatic memory management, which means you'll have to concern yourself with manually disposing of allocated data structures used in interop. (Or, worse, things will get garbage collected by the Scheme runtime that the Scheme code no longer references, but the C library is still using, and bam! SIGSEGV.) And then you gain what, the diverse mix of platform-specific, unportable, sometimes-wonky C libraries? Versus Clojure immediately granting simple, easy to use access to a large standard Java library that works more or less the same across a broad range of host platforms, as well as the rest of the JVM library ecosystem, which mostly has the same qualities. Clojure being designed for the JVM, there's much less of an impedance mismatch with Java's types, and the interop call syntax is easy to master and won't set your hair on fire. From andrius.a at gmail.com Mon May 23 18:30:59 2011 From: andrius.a at gmail.com (Andrius) Date: Mon, 23 May 2011 15:30:59 -0700 (PDT) Subject: Unit testing beginner question Message-ID: Hello, would be gratefull for the explonation. I did a simple test case: def setUp(self): self.testListNone = None def testListSlicing(self): self.assertRaises(TypeError, self.testListNone[:1]) and I am expecting test to pass, but I am getting exception: Traceback (most recent call last): self.assertRaises(TypeError, self.testListNone[:1]) TypeError: 'NoneType' object is unsubscriptable I thought that assertRaises will pass since TypeError exception will be raised? Ta, Andrius From rosuav at gmail.com Mon May 23 18:42:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 May 2011 08:42:14 +1000 Subject: Strange behaviour of input() function (Python 3.2) In-Reply-To: References: Message-ID: On Tue, May 24, 2011 at 1:44 AM, Aleksander Pietkiewicz wrote: > Hello, > I have googled your email address, I hope it is not a problem. > Thank you for your help! I figured you would get it from my post, but either way works! My email address is fairly well known. Sorry for the delay in response; you caught me while I was asleep. :) I'm now responding on-list so that other people can help. > I agree that can be very specific bug, I suspect it is matter of coding. I'm > emailing you a *.py file as you asked and screenshot showing script being > run. Unfortunately my Windows install doesn't have internationalization support, which may be an issue here. I ran your 'couting.py' and got errors back: Traceback (most recent call last): File "foo.py", line 11, in n=input("Naci\u015bnij Enter aby zako\u0144czy\u0107...") File "C:\python32\lib\encodings\cp437.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character '\u015b' in position 4: character maps to So I'm guessing that codepage 437 is just plain wrong. But that shouldn't affect your system. > As you can see this problem occurs only with 3rd party software (like Komodo > Edit). > In, addition when I'm using Komodo or Notepad++ and input() function, Python > miscount bytes. See attached. > Once again thank you for your help! > Kind regards, > Aleksander Pietkiewicz My suspicion here is that your editor is saving using one encoding, and Python is expecting another. I recommend you put an encoding marker at the top of your source file: # coding=utf-8 See http://www.python.org/dev/peps/pep-0263/ for details. With this in place, you should be able to guarantee that the bytestream is parsed the same way by editor and interpreter. Unfortunately that's all I could offer; I was unable to duplicate the exact problem you were seeing. The contents of 'couting.py' are simple enough, so I'll paste here in case anyone can spot a problem: s = (input('Enter something : ')) z = input('Enter something : ') print('Length of the string s is', len(s)) print('Length of the string z is', len(z)) print(s) print(z) Point to note: On my Windows XP, the string lengths are one higher than expected, and they include a \r at the end. Is there any way that this could trigger a Unicode parse failure?? Chris Angelico From ian.g.kelly at gmail.com Mon May 23 18:46:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 23 May 2011 16:46:52 -0600 Subject: Unit testing beginner question In-Reply-To: References: Message-ID: On Mon, May 23, 2011 at 4:30 PM, Andrius wrote: > and I am expecting test to pass, but I am getting exception: > Traceback (most recent call last): > ? ?self.assertRaises(TypeError, self.testListNone[:1]) > TypeError: 'NoneType' object is unsubscriptable > > I thought that assertRaises will pass since TypeError exception will > be raised? The second argument to assertRaises must be a function that assertRaises will call. assertRaises can't catch the error above because it is raised when the argument is evaluated, before assertRaises has even been called. This would work: self.assertRaises(TypeError, lambda: self.testListNone[:1]) Cheers, Ian From andrius.a at gmail.com Mon May 23 18:49:48 2011 From: andrius.a at gmail.com (Andrius A) Date: Mon, 23 May 2011 23:49:48 +0100 Subject: Unit testing beginner question In-Reply-To: References: Message-ID: That was quick! Thanks Ian On 23 May 2011 23:46, Ian Kelly wrote: > On Mon, May 23, 2011 at 4:30 PM, Andrius wrote: > > and I am expecting test to pass, but I am getting exception: > > Traceback (most recent call last): > > self.assertRaises(TypeError, self.testListNone[:1]) > > TypeError: 'NoneType' object is unsubscriptable > > > > I thought that assertRaises will pass since TypeError exception will > > be raised? > > The second argument to assertRaises must be a function that > assertRaises will call. assertRaises can't catch the error above > because it is raised when the argument is evaluated, before > assertRaises has even been called. > > This would work: > > self.assertRaises(TypeError, lambda: self.testListNone[:1]) > > Cheers, > Ian > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon May 23 20:03:17 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 May 2011 00:03:17 GMT Subject: Is there a better way to solve this? References: Message-ID: <4ddaf5c4$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 May 2011 11:55:08 -0700, kracekumar ramaraju wrote: > You can use sizeof function, Who are you talking to, and what question did they ask? Please always quote enough of the post that you are replying to to establish context. >>>> a=12234 >>>> b=23456.8 >>>> a.__sizeof__() > 12 >>>> b.__sizeof__() > 16 > So sizeof int is 12 bytes and float is 16 bytes You shouldn't be calling special methods directly (except under unusual circumstances). That's like calling s.__len__() instead of len(s). The public function for getting the size of an object is in the sys module: sys.getsizeof(a) -- Steven From greg.ewing at canterbury.ac.nz Mon May 23 20:04:53 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 24 May 2011 12:04:53 +1200 Subject: Abandoning Python In-Reply-To: <4dd9ffc1$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <93tqifFnb2U1@mid.individual.net> <4dd9ffc1$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <940b18Fc0pU1@mid.individual.net> Steven D'Aprano wrote: > On Mon, 23 May 2011 13:11:40 +1200, Gregory Ewing wrote: > >>...until you want to read someone *else's* code, that is. > > The same might be said about Python, which supports procedural, OO and > functional styles out of the box. But it only uses *one* syntax and core set of concepts to cover all of those. Unlike, apparently, Falcon... take a look at this page concerning how Falcon approaches functional programming (but don't look for too long or your eyes may begin to bleed...) http://falconpl.org/index.ftd?page_id=sitewiki&prj_id=_falcon_site&sid=wiki&pwid=Survival%20Guide&wid=Survival%3AFunctional+programming Falcon seems to collect programming paradigms the way Perl collects language features, i.e. by just munging them all together and bending parts until they fit. -- Greg From steve+comp.lang.python at pearwood.info Mon May 23 20:18:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 May 2011 00:18:19 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> Message-ID: <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 May 2011 20:56:03 +0200, Rikishi42 wrote: > On 2011-05-20, Steven D'Aprano > wrote: >> On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: >> >>> [I agree with you Xah that recursion is a technical word that should >>> not be foisted onto lay users.] >> >> I think that is a patronizing remark that under-estimates the >> intelligence of lay people and over-estimates the difficulty of >> understanding recursion. > > Why would you presume this to be related to intelligence? The point was > not about being *able* to understand, but about *needing* to understand > in order to use. Maybe they don't "need" to understand recursion. So what? Recursion is a perfectly good English word, no more technical than "accelerate" or "incinerate" or "dissolve" or "combustion". Do people need to know the word "combustion" when they could say "burn" instead? Do they need to know the words "microwave oven" when they could be saying "invisible rays cooking thing"? I wonder whether physicists insist that cars should have a "go faster pedal" because ordinary people don't need to understand Newton's Laws of Motion in order to drive cars? Who are you to say that people shouldn't be exposed to words you deem that they don't need to know? -- Steven From roy at panix.com Mon May 23 20:19:01 2011 From: roy at panix.com (Roy Smith) Date: Mon, 23 May 2011 20:19:01 -0400 Subject: Unit testing beginner question References: Message-ID: In article , Ian Kelly wrote: > This would work: > > self.assertRaises(TypeError, lambda: self.testListNone[:1]) If you're using the version of unittest from python 2.7, there's an even nicer way to write this: with self.assertRaises(TypeError): self.testListNone[:1] From rantingrick at gmail.com Mon May 23 20:21:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 23 May 2011 17:21:50 -0700 (PDT) Subject: Abandoning Python References: <93tqifFnb2U1@mid.individual.net> <4dd9ffc1$0$29988$c3e8da3$5496439d@news.astraweb.com> <940b18Fc0pU1@mid.individual.net> Message-ID: <89109704-1682-4516-9fd9-66116668e4c3@k16g2000yqm.googlegroups.com> On May 23, 7:04?pm, Gregory Ewing wrote: > Falcon seems to collect programming paradigms the way Perl > collects language features, i.e. by just munging them all > together and bending parts until they fit. Not that i am picking on anyone here... but... Why is okay to rip apart Perl with jagged metal teeth (and not that i am complaining mind you) however if anyone even hints about Ruby being somewhat ...oh let's say "asinine" or how about "redundant"... all the Ruby trolls crawl out the woodwork and start bashing you in the head with a recursive iterator? Do they not understand that Ruby is nothing more than Perl's "mini-me" bent on displacing the glory of Python with Perl style obfuscation, squiggly variable decorators, and redundant syntaxes so horrific that even Tim Toady would blush in embarrassment? From gagsl-py2 at yahoo.com.ar Mon May 23 20:41:06 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 May 2011 21:41:06 -0300 Subject: Multiple file select with tkFileDialog passes back 'decorated' strings (sometimes) References: <4dda5a89$0$49175$e4fe514c@news.xs4all.nl> Message-ID: En Mon, 23 May 2011 10:00:53 -0300, Alex van der Spek escribi?: > I switched from Mark Hammonds pywin32 extensions for file choosers as > the multiselect there seems to crash on me when selecting more than a > few dozen. Using Tk now. Works well but the resulting string passed back > seems to 'decorated' when the files are on local disk and not decorated > when retrieved over a USB interface from an external disk? > > I do this: > >> From local disk I get back: > > '{file1.bin} {file2.bin}' > >> From external disk I get back: > > 'file1.bin file2.bin' > > I can handle/parse both, not an issue but it raises the question: Are > these the only two possibilities? Is it the same across platforms (I use > Python 2.7 on Win Vista)? An old bug. See http://bugs.python.org/issue5712 for a workaround. -- Gabriel Genellina From dan.kluev at gmail.com Mon May 23 23:34:52 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 24 May 2011 14:34:52 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <57C0AB91B42743E89456ACCC8751CF78@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> Message-ID: On Mon, May 23, 2011 at 10:10 PM, Octavian Rasnita wrote: > is not so nice as > > $d = @a; It is 'not so nice' only in your perception. Python clearly defines dict as container of (key, value) pairs, and therefore its constructor expects such pairs. Adding unjustified arbitrary ways to guess such pairs out of linear list is exactly what is being bashed here. Is is considered to be wrong and bad. Moreover, you are comparing apples to oranges here, and then complaining that apples somehow turned out to be not oranges. If we take python way of defining dicts and check it in perl, we find that it is not supported, so obviously perl is non-intuitive and does not support clear and easy way of defining hashes from list of key-value pairs: @l = ([1, 2], [3, 4],); %d = @l; for $k ( keys %d ) { print "$k\n"; } which outputs single ARRAY(0x804e158) instead of proper 1, 3, as it does in python: >>> dict([[1,2], [3,4]]).keys() [1, 3] This is yet another example that you are just trolling here, making silly and unbacked claims, and ignoring any valid arguments you receive. -- With best regards, Daniel Kluev From xahlee at gmail.com Tue May 24 00:20:22 2011 From: xahlee at gmail.com (Xah Lee) Date: Mon, 23 May 2011 21:20:22 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: On May 22, 4:32?pm, Chris Angelico wrote: > On Mon, May 23, 2011 at 9:17 AM, Xah Lee wrote: > > the context is this: In emacs directory manager (aka dired), when you > > call dired-do-delete on a directory, emacs prompts, this way: > > ?Recursive delete of xx? (y or n)? > > But in order to make your point (such as it is), you are ignoring the > fact that there are other uses of the term 'recurse' or 'recursive', > and consistency and clarity are important. I don't see emacs offering > me a chance to do a non-recursive delete; the only issue here seems to > be that it's explicit that it is going to destroy an entire branch of > the directory tree. If this is such a problem, grab the emacs sources > and change that string - it probably occurs in exactly one place in > the code. Voila! You now have The One True Perfect Emacs, the ultimate > text editor, because it no longer tells you that it's working > recursively. > > *removes tongue from cheek after saying that last sentence* > > Chris Angelico why don't you file a bug report? In GNU Emacs 23.2, it's under the Help menu. I suppose it's the same in other emacs distro. Xah From rosuav at gmail.com Tue May 24 00:28:13 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 May 2011 14:28:13 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: On Tue, May 24, 2011 at 2:20 PM, Xah Lee wrote: > why don't you file a bug report? In GNU Emacs 23.2, it's under the > Help menu. I suppose it's the same in other emacs distro. > Because I do not consider its behaviour to be errant. And I suspect its main developers won't either. That's why I suggested you grab the sources and make The Perfect Emacs. Chris Angelico From john at castleamber.com Tue May 24 01:17:55 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 00:17:55 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> Message-ID: <87sjs44qyk.fsf@castleamber.com> "Octavian Rasnita" writes: > From: "Daniel Kluev" > a = [1,2] > dict([a]) > > Yes, but > > d = dict([a]) > > is not so nice as > > $d = @a; That will give you the number of elements in @a. What you (probably) mean is %hash = @array; -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From jussij at zeusedit.com Tue May 24 01:19:23 2011 From: jussij at zeusedit.com (JussiJ) Date: Mon, 23 May 2011 22:19:23 -0700 (PDT) Subject: Make Python "portable" by default! (Re: Python IDE/text-editor) References: <8739lij2h7.fsf@benfinney.id.au> <87r59269y4.fsf@castleamber.com> <8739licppk.fsf@castleamber.com> <4da9f850$0$3947$426a74cc@news.free.fr> <87sjthlu78.fsf@castleamber.com> <1302993113.2774.0.camel@localhost.localdomain> <20110417111325.4fa995b0.feliphil@gmx.net> Message-ID: On Apr 17, 7:13 pm, Wolfgang Keller wrote: > > You can't run Python programs without a Python interpreter installed. > > Wrong. > > See e.g.http://www.portablepython.com/ In this case Python is still installed on the machine. It may not be installled on the PC's hard disk but it is certainly is installed on the USB stick. In other words the act of inserting the USB actually results in the software being 'Installed' (i.e. being made available) on the PC. Jussi From orasnita at gmail.com Tue May 24 01:25:42 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 08:25:42 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: From: "Ulrich Eckhardt" > Ahem, is this Java the language that a certain, well-known service > provider > is getting screwed over hard currently, because they forgot to read the > fineprint in the declaration of freedom? And this Objective C, isn't this > the language that GCC had support for since before it properly supported > C++, and that on a multitude of targets? Someone also said that C# can be used under Mono and even though this is true, C# still remains a proprietary language that can be totally changed if MS wants that, as well as Objective C can be changed if Apple wants that. So what matters is if the most important developers for a specific language/platform are releasing the code as open source or they keep it proprietary and I don't see a big number of programmers developing code in C# and Objective C. About Java... you may be right. :-) Octavian From orasnita at gmail.com Tue May 24 01:39:42 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 08:39:42 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><2EA88E7D68664EB3A4A49FA332E0E7EB@octavian><46EA3D502B204937A4EE89E34471BC0F@octavian> Message-ID: From: "Daniel Kluev" > On Mon, May 23, 2011 at 10:17 PM, Octavian Rasnita > wrote: >> From: "Daniel Kluev" >> Aha, so with other words that ORM doesn't have that feature. >> DBIX::Class also use the DateTime module, but it can use it directly, >> without needing to write more code for that, and it can also return >> localized dates. > > Once again. ORMs return _python builtin type_. Localization is not > their responsibility, and plugging it there is code bloat, rather than > feature. Sure you may ask ORM to handle JSONRPC requests on its own, > but ORM responsibility is to map RDBMS features to language objects. Who said that? The ORM responsability is to map RDBMS to the objects you need, not to the language objects. If the ORM can do that directly by just adding a configuration instead of needing to manually use of other modules, why is this bloat? You add that configuration only if you need it, not always, and it is much more simple. > All good python packages limit their functionality to specific field, > so you could choose one you prefer for each different task > independently. All the Perl modules do the same, but some of the Perl modules accept plugins that make easier the collaboration of different modules which are needed often, and the need of localizing the date is a feature used often. >> without needing to load the DateTime module manually and to initialize >> the DateTime object manually... > > This is basically stating that you didn't read the code I posted. > Where did you ever find "initialize the DateTime object manually"? > Sorry, but its pointless to discuss anything if you don't want to even > read properly examples you receive. You told that you need to use another module for localizing the date because the ORM returns just a language date object that doesn't do that. Octavian From orasnita at gmail.com Tue May 24 02:00:14 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 09:00:14 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian><57C0AB91B42743E89456ACCC8751CF78@octavian> Message-ID: <2C6966D5AB6541E3BCE920FE7883A05B@octavian> From: "Daniel Kluev" > Moreover, you are comparing apples to oranges here, and then > complaining that apples somehow turned out to be not oranges. > If we take python way of defining dicts and check it in perl, we find > that it is not supported, so obviously perl is non-intuitive and does > not support clear and easy way of defining hashes from list of > key-value pairs: > @l = ([1, 2], [3, 4],); > %d = @l; > for $k ( keys %d ) { print "$k\n"; } > > which outputs single ARRAY(0x804e158) instead of proper 1, 3, as it > does in python: > >>>> dict([[1,2], [3,4]]).keys() > [1, 3] > > This is yet another example that you are just trolling here, making > silly and unbacked claims, and ignoring any valid arguments you > receive. You are showing a code but tell another thing. If it would be as you said, I should have said that if in Perl a dictionary is made from a list using %d = @l; then in Python it should be l = d because it would be more nice. But I didn't say that. I said that it would be nice to be able to use something like d = dict(l) using the Python "dict" statement for creating dicts. And OK, Python needs another pair of brackets for doing that and this is no problem, but the result is that the Python's syntax is not as shorter and nice as Perl's, for the same thing. This is what that I said. And you are telling that in Perl should be used an even more complicated and ugly syntax just for beeing the same as in Python just for showing that I am wrong, but I was comparing just the shortness and cleraness of the code. So, again, in Perl is just: %d = @l; Please tell me if Python has a syntax which is more clear than this for doing this thing. It doesn't matter if it is different or if it follows another syntax. And again, I am not trolling anything. I am just defending a language which has a clearer syntax for doing some things, and a shorter code for other things, and which uses less braces and brackets than Python for other things, and which has a single-recommended way for doing some things, even though other list members were trolling about Perl, but nobody said something against. Octavian From stefan_ml at behnel.de Tue May 24 02:23:55 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 24 May 2011 08:23:55 +0200 Subject: Why did Quora choose Python for its development? In-Reply-To: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: Beliavsky, 20.05.2011 18:39: > I thought this essay on why one startup chose Python was interesting. Since everyone seems to be hot flaming at their pet languages in this thread, let me quickly say this: Thanks for sharing the link. Stefan From orasnita at gmail.com Tue May 24 04:08:17 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 11:08:17 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> Message-ID: From: "John Bokma" > "Octavian Rasnita" writes: > >> From: "Daniel Kluev" >> a = [1,2] >> dict([a]) >> >> Yes, but >> >> d = dict([a]) >> >> is not so nice as >> >> $d = @a; > > That will give you the number of elements in @a. What you (probably) > mean is %hash = @array; Of course. Thank you for correction. Octavian From orasnita at gmail.com Tue May 24 04:10:36 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 11:10:36 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: <141C5F3E5EA34913884EE6007F95A1E0@octavian> From: "Stefan Behnel" > Beliavsky, 20.05.2011 18:39: >> I thought this essay on why one startup chose Python was interesting. > > Since everyone seems to be hot flaming at their pet languages in this > thread, let me quickly say this: > > Thanks for sharing the link. Maybe I have missed a message, but if I didn't, please provide that link. I am always interested to find the best solutions. Thanks. Octavian From rosuav at gmail.com Tue May 24 04:20:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 May 2011 18:20:44 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <141C5F3E5EA34913884EE6007F95A1E0@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <141C5F3E5EA34913884EE6007F95A1E0@octavian> Message-ID: On Tue, May 24, 2011 at 6:10 PM, Octavian Rasnita wrote: > From: "Stefan Behnel" >> >> Beliavsky, 20.05.2011 18:39: >>> >>> I thought this essay on why one startup chose Python was interesting. >> >> Since everyone seems to be hot flaming at their pet languages in this >> thread, let me quickly say this: >> >> Thanks for sharing the link. > > > Maybe I have missed a message, but if I didn't, please provide that link. > I am always interested to find the best solutions. At the beginning of the thread, three days and forty-odd messages ago, this was posted: http://www.quora.com/Why-did-Quora-choose-Python-for-its-development It's the reason for the thread title, regardless of the current thread content :) Chris Angelico From nambo4jb at gmail.com Tue May 24 04:31:37 2011 From: nambo4jb at gmail.com (Cathy James) Date: Tue, 24 May 2011 03:31:37 -0500 Subject: NEED HELP- read file contents, while loop to accept user input, and enter to exit Message-ID: dear mentor, I need help with my code: 1) my program won't display file contents upon opening 2) my program is not writing to file 3) my program is not closing when user presses enter- gow do I do this with a while loop? please see my attempt below and help: #1) open file and display current file contents: f = open ('c:/testing.txt'', 'r') f.readlines() #2) and 3) use while loop to write user input to file, save to file, close when press enter: while True: s = input ('enter name: ').strip() f = open ('c:/testing.txt', 'a') if f.writable(): f.write(s) break else: f = open ('c:/testing.txt', 'r') f.readlines() for line in f: print (line) -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue May 24 04:46:11 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 May 2011 09:46:11 +0100 Subject: NEED HELP- read file contents, while loop to accept user input, and enter to exit In-Reply-To: References: Message-ID: <4DDB7053.4080109@timgolden.me.uk> On 24/05/2011 09:31, Cathy James wrote: > dear mentor, > I need help with my code: > 1) my program won't display file contents upon opening > #1) open file and display current file contents: > f = open ('c:/testing.txt'', 'r') > f.readlines() If you're running this in an interactive interpreter, I would expect it to show a list of lines (assuming c:/testing.txt has something in it...). If you're running it as a program, though, it won't show anything: you need to actually output the result of the expression f.readlines (). It only happens at the interpreter as a development convenience: f = open ("c:/testing.txt", "r") print f.readlines () # or print (f.readlines ()) if you're in Python 3 TJG From rosuav at gmail.com Tue May 24 04:46:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 May 2011 18:46:32 +1000 Subject: NEED HELP- read file contents, while loop to accept user input, and enter to exit In-Reply-To: References: Message-ID: On Tue, May 24, 2011 at 6:31 PM, Cathy James wrote: > ??? s = input ('enter name: ').strip() Are you using Python 2 or Python 3? If it's Python 2, this should be raw_input(). > ??? f = open ('c:/testing.txt', 'a') > ... > ??????? f = open ('c:/testing.txt', 'r') You may be having trouble here as a result of not closing the file and then trying to reopen it. Also, at some point you have to check if 's' (the user's inputted string) is empty. You can then leave the loop using the 'break' statement. Hope that helps! Best of luck with your homework. Chris Angelico From harrismh777 at charter.net Tue May 24 04:47:31 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 24 May 2011 03:47:31 -0500 Subject: I installed Python 3 on Fedora 14 By Downloading python3.2 bziped source tarball and install it according to the README, Now How shall I uninstalled python 3.2? In-Reply-To: References: Message-ID: Varuna Seneviratna wrote: > Now How shall I uninstalled > python 3.2? > Now, how shall I remove Python 3.2 ? ... very carefully. It might be nice if there were a label in the Makefile so this would work: sudo make removeall ... but alas, why do you want to un-install Python3.2 ? From dan.kluev at gmail.com Tue May 24 04:55:40 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 24 May 2011 19:55:40 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <2C6966D5AB6541E3BCE920FE7883A05B@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: On Tue, May 24, 2011 at 5:00 PM, Octavian Rasnita wrote: > And you are telling that in Perl should be used an even more complicated and > ugly syntax just for beeing the same as in Python just for showing that I am > wrong, but I was comparing just the shortness and cleraness of the code. > > So, again, in Perl is just: > > %d = @l; Once again. Suppose we have array of key-value pairs (two-dimensional array), `l`. In python, converting it to dict is as simple as d = dict(l). In perl, %d = @l; produces meaningless value. Following your logic, this means that perl has ugly syntax. -- With best regards, Daniel Kluev From clp2 at rebertia.com Tue May 24 04:58:25 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 24 May 2011 01:58:25 -0700 Subject: NEED HELP- read file contents, while loop to accept user input, and enter to exit In-Reply-To: References: Message-ID: On Tue, May 24, 2011 at 1:31 AM, Cathy James wrote: > dear mentor, > > I need help with my code: In addition to what others have already said... > please see my attempt below and help: > > #1) open file and display current file contents: > f = open ('c:/testing.txt'', 'r') > f.readlines() > #2)? and 3) use while loop? to write user input to file, save to file, close > when press enter: > while True: > ??? s = input ('enter name: ').strip() > ??? f = open ('c:/testing.txt', 'a') > ??? if f.writable(): Since you *just* opened the file in append mode, this condition will *always* be true (append mode implies writability), so your `else` clause will *never* be executed. > ??????? f.write(s) > ??????? break > ??? else: > ??????? f = open ('c:/testing.txt', 'r') > ??????? f.readlines() > ??????? for line in f: > ??????????? print (line) Similar beginner questions would be best directed to Python's Tutor mailinglist: http://mail.python.org/mailman/listinfo/tutor Cheers, Chris From rosuav at gmail.com Tue May 24 05:07:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 May 2011 19:07:21 +1000 Subject: [Savoynet] More 'vast heavin' In-Reply-To: <4DDB7455.6060607@threelittlemaids.co.uk> References: <145486.48144.qm@web125410.mail.ne1.yahoo.com> <4DDB7455.6060607@threelittlemaids.co.uk> Message-ID: On Tue, May 24, 2011 at 7:03 PM, Larry Simons wrote: > On Tue 24/05/2011 04:11, Libby Moyer wrote: >> >> And the rhymes in Mikado! > > Are you referring to ablutioner, diminutioner and ?you shun her? all rhymed > with executioner? > Can't deny that they're grin-worthy! (Or groan-worthy, I always get those two mixed up.) ChrisA From harrismh777 at charter.net Tue May 24 05:09:24 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 24 May 2011 04:09:24 -0500 Subject: I installed Python 3 on Fedora 14 By Downloading python3.2 bziped source tarball and install it according to the README, Now How shall I uninstalled python 3.2? In-Reply-To: References: Message-ID: <7BKCp.14174$241.932@newsfe07.iad> Varuna Seneviratna wrote: > Now How shall I uninstalled > python 3.2? What --prefix did you use? default? From jeanmichel at sequans.com Tue May 24 05:22:58 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 24 May 2011 11:22:58 +0200 Subject: NEED HELP- read file contents, while loop to accept user input, and enter to exit In-Reply-To: References: Message-ID: <4DDB78F2.2050804@sequans.com> Cathy James wrote: > > f = open ('c:/testing.txt'', 'r') replace the double quote by a single quote. JM From claudiu at virtuamagic.com Tue May 24 06:01:24 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Tue, 24 May 2011 13:01:24 +0300 Subject: File access denied after subprocess completion on Windows platform Message-ID: <201105241301.28431.claudiu@virtuamagic.com> Hello, I have a program that uses pyside for an QT interface and a thread that downloads a lot of files. The thread is created with QThread object. But my problem I don't think it's QT related. The thread retrieves with pycurl a file that contains a list of files and start to downloads them. The downloading is done as following: - instantiate a Curl object - open the file on local filesystem for write in binary mode (in a try block), with the name suffixed with .part. - pass the description to the curl object for save. - curl retrieve and save it. It has also a callback function that updates the interface, sending a QT signal to the interface. (1) - use os.rename to rename the file with .part sufix to the final file. On my interface I have 3 buttons. One of the buttons runs an .exe file. One button closes the interface and one is deactivated. On the button that runs the exe I have a callback function that uses subprocess.Popen (for not waiting) for running a program (.exe) and returns. For now I configured to run calc.exe. The callback is not defined inside the downloader thread. It's defined globally (nor in QMainWindow object). The problem appears when I close the called program (in our case calc.exe). The (1) part (the call of os.rename) raise an exception: (32, 'The process cannot access the file because it is being used by another process') [Error 32] The process cannot access the file because it is being used by another process Question is why? And how to avoid this issue? The same program on Linux works very fine (that's because Linux doesn't has this violation access)! If I remove (1) part the program works fine. Somehow after closing the spawned process (calc.exe - you see, it has nothing to do with a open file somewhere else) the thread losses the acces to the current opened file by itself. -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From darcy at druid.net Tue May 24 06:05:35 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 24 May 2011 06:05:35 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <2C6966D5AB6541E3BCE920FE7883A05B@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: <20110524060535.64cfa0ec.darcy@druid.net> On Tue, 24 May 2011 09:00:14 +0300 "Octavian Rasnita" wrote: > So, again, in Perl is just: > > %d = @l; > > Please tell me if Python has a syntax which is more clear than this for > doing this thing. How is that clear? "Shorter" != "clearer." A Python programmer looking at that sees line noise. A Perl programmer looking at "d = dict ([a])" (or even "d = dict(a,)") sees something that has something to do with creating a dictionary. At least he would know in which section of the manual to look for more information. > And again, I am not trolling anything. I am just defending a language which > has a clearer syntax for doing some things, and a shorter code for other Are Perl programmers aware of some imminent worldwide shortage of electrons that Python programmers are not? Why is there this obsession with shortness? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Tue May 24 06:09:27 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 24 May 2011 06:09:27 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <87sjs44qyk.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> Message-ID: <20110524060927.778a4a6a.darcy@druid.net> On Tue, 24 May 2011 00:17:55 -0500 John Bokma wrote: > > $d = @a; > > That will give you the number of elements in @a. What you (probably) > mean is %hash = @array; If I was even considering using Perl, this one exchange would send me screaming in the opposite direction. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From as at sci.fi Tue May 24 06:45:09 2011 From: as at sci.fi (Anssi Saari) Date: Tue, 24 May 2011 13:45:09 +0300 Subject: how to get PID from subprocess library References: Message-ID: TheSaint writes: > self.handle= \ > xmlrpclib.ServerProxy('http://localhost:%s/rpc' %int(self.numport)) Couldn't you just try to call something via this handle, like self.handle.aria2.getVersion()? If there's an error, then start aria2 as a daemon and try again. From markrrivet at aol.com Tue May 24 08:01:26 2011 From: markrrivet at aol.com (markrrivet at aol.com) Date: Tue, 24 May 2011 08:01:26 -0400 Subject: Python 3.2 Idle doesn't start. No error message. Message-ID: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> Hello all. I have Python 2.71 installed on my Windows 7 laptop and it runs fine. I was having a problem with Python 3.2, 32bit, not starting with an error message saying this application has quit abnormally. That was fixed when I took the PYTHONPATH statement out of my environment variables. However, now when I try to start Idle, I can see some hard drive activity, but Idle for Python 3.2 does not start; nothing happens. Any clues as to the problem here? From mail at timgolden.me.uk Tue May 24 09:09:02 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 May 2011 14:09:02 +0100 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: <201105241301.28431.claudiu@virtuamagic.com> References: <201105241301.28431.claudiu@virtuamagic.com> Message-ID: <4DDBADEE.9060800@timgolden.me.uk> On 24/05/2011 11:01, Claudiu Nicolaie CISMARU wrote: > The problem appears when I close the called program (in our case > calc.exe). The (1) part (the call of os.rename) raise an exception: > > > (32, 'The process cannot access the file because it is being used by > another process') > [Error 32] The process cannot access the file because it is being used > by another process Try running procexp to see if it can see what's happening to the handle. It's possible it's a virus checker / indexer, although they'd tend to allow the file to be deleted out from under them. It's not quite clear from your description above whether you can be sure that the called subprocess has closed all its handles by the time the os.rename runs. TJG From k.sahithi2862 at gmail.com Tue May 24 09:13:58 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 24 May 2011 06:13:58 -0700 (PDT) Subject: GOOD STUDY METERIAL Message-ID: GOOD STUDY MATERIAL FOR KIDS http://studymaterialforu.blogspot.com UNIX INTERVIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/unix-interview-questions.html JAVA INTERVIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/java-interview-questions.html C ++ INTERVIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/c-interview-questions.html CIVILS INTERCIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/civils-interview-questions-and-answers.html DIGITAL LOGIC INTERCIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/digital-logic-design-interview.html MICROPROCESSOR INTERVIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/microprocessor-interview-questions.html From tlikonen at iki.fi Tue May 24 09:18:21 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Tue, 24 May 2011 16:18:21 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: <8762p0kzj6.fsf@mithlond.arda> * 2011-05-24T06:05:35-04:00 * D'Arcy J. M. Cain wrote: > On Tue, 24 May 2011 09:00:14 +0300 > "Octavian Rasnita" wrote: >> %d = @l; >> >> Please tell me if Python has a syntax which is more clear than this >> for doing this thing. > > How is that clear? "Shorter" != "clearer." A Python programmer looking > at that sees line noise. I'm a Lisp programmer who sees (some) Python code as line noise. >> I am just defending a language which has a clearer syntax for doing >> some things, and a shorter code for other > > Are Perl programmers aware of some imminent worldwide shortage of > electrons that Python programmers are not? Why is there this obsession > with shortness? I don't know but from the point of view of a Lisp programmer Python has the same obsession. Not trolling, I just wanted to point out that these are just point of views. I don't actually care that much about these things. From nobody at nowhere.net.no Tue May 24 09:36:40 2011 From: nobody at nowhere.net.no (TheSaint) Date: Tue, 24 May 2011 21:36:40 +0800 Subject: how to get PID from subprocess library References: Message-ID: Anssi Saari wrote: > Couldn't you just try to call something via this handle, like > self.handle.aria2.getVersion()? If there's an error, then start aria2 > as a daemon and try again. > Very good, you're right. Furthermore I should avoid to call that function several times. I think to join it with __init__ function The program on exit must tell aria2c to quit. -- goto /dev/null From kw at codebykevin.com Tue May 24 10:09:19 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 24 May 2011 10:09:19 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: <88a86$4ddbbc22$4275d90a$404@FUSE.NET> On 5/22/11 3:44 AM, Octavian Rasnita wrote: > Somebody told that C# and Objective C are good languages. They might be good, but they are proprietary, and not only that they are proprietary, but they need to be ran under platforms that cannot be used freely, so from the freedom point of view, Perl, Ruby, Python and Java are the ways to go. Proprietary? Licensing options for C# in its Mono (Free Platform) implementation: http://www.mono-project.com/Licensing Licensing options for Objective-C in its GNUStep (Free Platform) implementaiton http://www.gnustep.org/information/aboutGNUstep.html It may be true that these languages are more widely used on their originating platforms (Windows, OS X) than on Linux, but these implementations are definitely open source. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From mail at timgolden.me.uk Tue May 24 10:40:53 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 May 2011 15:40:53 +0100 Subject: os.access giving incorrect results on Windows In-Reply-To: <21581D39FA3BDF40904D75AF9653CE26065680B9@blrex.prog.altair.com> References: <21581D39FA3BDF40904D75AF9653CE26065680B9@blrex.prog.altair.com> Message-ID: <4DDBC375.3020303@timgolden.me.uk> On 20/05/2011 12:26, Ayaskanta Swain wrote: > Thanks for the reply and suggestions. I followed the patch provided by > you in issue 2528, but the code looks very tricky to me. OK, first a summary of the discussion on the python-dev thread. Essentially it was felt that os.access was sufficiently shaky and unuseful on Windows that it was better to deprecate it and to discourage its use. So I'll be making that change when I can get round to it. As to your particular problem here... Does my_dir already exist? If it does then os.open won't be able to create it. If it doesn't then I can't see any reason why the code should fail there. I just ran it myself and it fails, as expected on an unpatched Python, on the assert on line 17 where the check is made for the result of os.access for W_OK. I don't have the time right now but if no-one else gets there first I hope to be able to post back with a standalone example of the AccessCheck API TJG Anyways I wrote > my Test.py script & tried only the def test_access_w(self): test case > which is defined under class FileTests(unittest.TestCase) by providing > my own directory path to check the write permissions on it. > > I executed my But it failed with the following errors ? > > *> python Test.py C:\temp\my_dir* > > test_access_w (__main__.FileTests) ... ERROR > > ====================================================================== > > ERROR: test_access_w (__main__.FileTests) > > ---------------------------------------------------------------------- > > Traceback (most recent call last): > > File "Test.py", line 14, in test_access_w > > f = os.open(dirpath, os.O_CREAT) > > OSError: [Errno 13] Permission denied: 'C:\\temp\\my_dir' > > ---------------------------------------------------------------------- > > Ran 1 test in 0.000s > > FAILED (errors=1) > > Basically the os.open() function is failing to open a directory (In this > case my_dir). The directory has write permissions for the user. Attached > herewith is my Test script. Can you please suggest some simple python > code which checks the write permissions of a directory in a straight > forward way (Not by using unit tests) > > Thanks > > Ayaskant- > > Bangalore > From rosuav at gmail.com Tue May 24 10:43:11 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 00:43:11 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <88a86$4ddbbc22$4275d90a$404@FUSE.NET> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <88a86$4ddbbc22$4275d90a$404@FUSE.NET> Message-ID: On Wed, May 25, 2011 at 12:09 AM, Kevin Walzer wrote: > Proprietary? > > Licensing options for C# in its Mono (Free Platform) implementation: > > http://www.mono-project.com/Licensing > > Licensing options for Objective-C in its GNUStep (Free Platform) > implementaiton > > http://www.gnustep.org/information/aboutGNUstep.html Just a side point: Are these *languages* free, or merely these *implementations*? Chris Angelico From kw at codebykevin.com Tue May 24 10:50:49 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 24 May 2011 10:50:49 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: <4e51c$4ddbc676$4275d90a$30907@FUSE.NET> On 5/24/11 2:23 AM, Stefan Behnel wrote: > Beliavsky, 20.05.2011 18:39: >> I thought this essay on why one startup chose Python was interesting. > > Since everyone seems to be hot flaming at their pet languages in this > thread, let me quickly say this: > > Thanks for sharing the link. > > Stefan > I kind of thought that other posters might also chime in on why they chose Python instead of . Since no one else has, I'll bite. I've been programming for about seven years, and am basically self-taught. I got my first taste of writing code when trying do to some basic hacking on my (then) shiny new G3 iBook. (Even though it was a Mac, I was enthralled by its Unix underpinnings.) C was too hard for a programming newbie, and (at the time) I only understood shell to be a sequential series of commands. (cd ~/.Trash; ls; rm *) My goal was to write desktop GUI apps, and looking around at the available languages, libraries, and toolkits for Unix and the Mac, I settled on Tk as the UI toolkit, since it seemed to be the simplest one out there, and on Tcl and Python as the programming languages. (A brief detour with AppleScript convinced me that it is a useful scripting language for hooking into various parts of OS X, but it is not very powerful.) While Tcl doesn't get a lot of love or respect on this list, it is quite powerful in its way, and an understanding of Tcl is quite useful in particular for understanding Tk and its Python wrapper, Tkinter. After becoming productive with Tcl and writing a couple of applications in it, I turned to Python in earnest and set about learning its capabilities as well, and have since released a couple of Python desktop apps on the Mac (commercial apps, using Tk as the toolkit). With that background, here are my reasons for keeping Python in my toolbox: 1. Its core libraries and third-party packages address nearly every imaginable need. The size of its community is a real asset here. Tcl is a more compact language, with a smaller core library and fewer third-party packages (no library comparable to Mark Pilgrim's feedparser, for instance), which means that for some use cases, using Tcl would mean more work. 2. Python has excellent tools for deployment of desktop apps. Since I only work on the Mac, I'm not that familiar with py2exe, but py2app and bundlebuilder have always allowed me to wrap up my apps with an embedded Python interpreter with a minimum of fuss. Tcl also excels in deployment of desktop apps; other languages, such as Perl and Ruby, seem to lag behind in this respect. (I could find no actively-maintained, open-source, Mac-viable desktop app bundling tools for either Ruby or Perl, which cooled my interest in them considerably.) 3. Python's binding to Tk makes writing GUI apps a straightforward process. Since I already knew Tk quite well, learning its Python bindings was much simpler than learning another GUI toolkit such as PyQt or wxPython. The strategies I learned from Tcl to develop sophisticated Tk-based UI's translate quite well to Python. Python isn't perfect; for some instances, I find Tcl a more lightweight and accessible tool to use. I also spend a lot of time digging into Tcl and Tk's C API to extend their capabilities in certain ways; this also allows my Python apps to access such enhancements, via Tkinter. But all in all I'm a happy user of Python, and it will continue to have a primary place in my toolbox. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From akekhofananaye at yahoo.co.uk Tue May 24 11:17:12 2011 From: akekhofananaye at yahoo.co.uk (SKHUMBUZO ZIKHALI) Date: Tue, 24 May 2011 16:17:12 +0100 (BST) Subject: Codes do not run Message-ID: <213250.48589.qm@web24004.mail.ird.yahoo.com> Hi: I am learning Python on my own using a " Guide to Programming with Python" book.?Author of the book is Micheal?Dawson and I am using version 2.3.5 of python. ?When I try to run the code?I do?not get required results. The picture could not be loaded. I get trackback message regarding undefined module.The example from the book is as follows: from liveswires import games games.init(screen_width = 640, screen_height = 480, fps = 50) wall_image = games.load_image("wall.jpg", transparent = False) games.screen.background = wall_image games.screen.mainloop() Can anyone please assist me. Thank you Sikhumbuzo -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 24 11:24:23 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 01:24:23 +1000 Subject: Codes do not run In-Reply-To: <213250.48589.qm@web24004.mail.ird.yahoo.com> References: <213250.48589.qm@web24004.mail.ird.yahoo.com> Message-ID: On Wed, May 25, 2011 at 1:17 AM, SKHUMBUZO ZIKHALI wrote: > The example from the book is as follows: > > from liveswires import games I think this might be meant to say "livewires". Presumably you did install this package? If not, it won't work (but even if you have, it won't work as "liveswires"). http://www.livewires.org.uk/python/package Hope that helps! Chris Angelico From rvince99 at gmail.com Tue May 24 11:36:18 2011 From: rvince99 at gmail.com (RVince) Date: Tue, 24 May 2011 08:36:18 -0700 (PDT) Subject: Obtaining a full path name from file Message-ID: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> s = "C:\AciiCsv\Gravity_Test_data\A.csv" f = open(s,"r") How do I obtain the full pathname given the File, f? (which should equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff and am just not finding it. Any help greatly appreciated ! From tim at johnsons-web.com Tue May 24 11:37:09 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Tue, 24 May 2011 07:37:09 -0800 Subject: Codes do not run In-Reply-To: <213250.48589.qm@web24004.mail.ird.yahoo.com> References: <213250.48589.qm@web24004.mail.ird.yahoo.com> Message-ID: <20110524153709.GN15519@johnsons-web.com> * SKHUMBUZO ZIKHALI [110524 07:26]: > Hi: > > I am learning Python on my own using a " Guide to Programming with Python" > book.?Author of the book is Micheal?Dawson and I am using version 2.3.5 of > python. ?When I try to run the code?I do?not get required results. The picture > could not be loaded. I get trackback message regarding undefined module.The > example from the book is as follows: > > from liveswires import games > > games.init(screen_width = 640, screen_height = 480, fps = 50) > wall_image = games.load_image("wall.jpg", transparent = False) > games.screen.background = wall_image > > games.screen.mainloop() > > Can anyone please assist me. You should provide 1)the traceback itself. 2)Version of python 3)Operating system 4)All relevant code Also Do the following : import sys print(sys.path) Do you see the liveswires module in the path? -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From mail at timgolden.me.uk Tue May 24 11:52:33 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 May 2011 16:52:33 +0100 Subject: Obtaining a full path name from file In-Reply-To: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: <4DDBD441.3070105@timgolden.me.uk> On 24/05/2011 16:36, RVince wrote: > s = "C:\AciiCsv\Gravity_Test_data\A.csv" > f = open(s,"r") > > How do I obtain the full pathname given the File, f? (which should > equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff > and am just not finding it. Any help greatly appreciated ! You're going to kick yourself: f.name TJG From rvince99 at gmail.com Tue May 24 12:04:12 2011 From: rvince99 at gmail.com (RVince) Date: Tue, 24 May 2011 09:04:12 -0700 (PDT) Subject: Obtaining a full path name from file References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> Ha! You;re right -- but is there a way to get it without the filename appended at the end? On May 24, 11:52?am, Tim Golden wrote: > On 24/05/2011 16:36, RVince wrote: > > > s = "C:\AciiCsv\Gravity_Test_data\A.csv" > > f = open(s,"r") > > > How do I obtain the full pathname given the File, f? (which should > > equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff > > and am just not finding it. Any help greatly appreciated ! > > You're going to kick yourself: > > f.name > > TJG From mwilson at the-wire.com Tue May 24 12:04:40 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 24 May 2011 12:04:40 -0400 Subject: Obtaining a full path name from file References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: Tim Golden wrote: > On 24/05/2011 16:36, RVince wrote: >> s = "C:\AciiCsv\Gravity_Test_data\A.csv" >> f = open(s,"r") >> >> How do I obtain the full pathname given the File, f? (which should >> equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff >> and am just not finding it. Any help greatly appreciated ! > > You're going to kick yourself: > > f.name There's trouble there, though: 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. >>> f = open ('xyzzy.txt') >>> f.name 'xyzzy.txt' >>> import os >>> os.getcwd() '/home/mwilson' >>> os.chdir('sandbox') >>> f.name 'xyzzy.txt' If you open a file and don't get a full path from os.path.abspath right away, the name in the file instance can get out-of-date. Mel. From rosuav at gmail.com Tue May 24 12:08:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 02:08:16 +1000 Subject: Obtaining a full path name from file In-Reply-To: <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> Message-ID: On Wed, May 25, 2011 at 2:04 AM, RVince wrote: > Ha! You;re right -- but is there a way to get it without the filename > appended at the end? Parse the file name with the os.path functions: http://docs.python.org/library/os.path.html Chris Angelico From orasnita at gmail.com Tue May 24 12:10:41 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 19:10:41 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian><57C0AB91B42743E89456ACCC8751CF78@octavian><2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: From: "Daniel Kluev" > On Tue, May 24, 2011 at 5:00 PM, Octavian Rasnita wrote: >> And you are telling that in Perl should be used an even more complicated and >> ugly syntax just for beeing the same as in Python just for showing that I am >> wrong, but I was comparing just the shortness and cleraness of the code. >> >> So, again, in Perl is just: >> >> %d = @l; > > Once again. Suppose we have array of key-value pairs (two-dimensional > array), This is a forced example to fit the way Python can do it with a clean syntax, but I don't think there are cases in which somebody wants to create hashes/dictionaries where the key is not a plain string but an array. This is not a rare case, but a case that probably nobody needs, ever. Octavian From mail at timgolden.me.uk Tue May 24 12:10:44 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 May 2011 17:10:44 +0100 Subject: Obtaining a full path name from file In-Reply-To: <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> Message-ID: <4DDBD884.4010006@timgolden.me.uk> On 24/05/2011 17:04, RVince wrote: > Ha! You;re right -- but is there a way to get it without the filename > appended at the end? Well, just use the functions in os.path, specifically os.path.dirname... TJG From orasnita at gmail.com Tue May 24 12:10:50 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 19:10:50 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian><57C0AB91B42743E89456ACCC8751CF78@octavian><2C6966D5AB6541E3BCE920FE7883A05B@octavian> <20110524060535.64cfa0ec.darcy@druid.net> Message-ID: From: "D'Arcy J.M. Cain" > On Tue, 24 May 2011 09:00:14 +0300 > "Octavian Rasnita" wrote: >> So, again, in Perl is just: >> >> %d = @l; >> >> Please tell me if Python has a syntax which is more clear than this for >> doing this thing. > > How is that clear? "Shorter" != "clearer." A Python programmer > looking at that sees line noise. A Perl programmer looking at "d = dict > ([a])" (or even "d = dict(a,)") sees something that has something to do > with creating a dictionary. At least he would know in which section of > the manual to look for more information. The Perl programmers usually don't need to look in the dictionary when they are creating programs. Perl is harder to learn, but it is easier to use. > Are Perl programmers aware of some imminent worldwide shortage of > electrons that Python programmers are not? Why is there this obsession > with shortness? A shorter code can be typed faster, obviously, and there are fewer possibility of appearing errors, but the shortage is not the most important thing. The most important thing is that the chars @, $, or % are the same in all languages, while the English words used by the languages that use many such words are harder to remember especially for the non-native English speakers. Python is not a very bad language from this perspective like Java is though. :-) In Perl the programmers can also use English words for some things, like $OUTPUT_AUTOFLUSH, but personally I never liked those things. Using $| instead is much shorter and clear, because I don't need to remember the English words like autoflush, or maybe it was just flush, or it was autoflush_output, or output_flush... something like $| can't be forgotten. Yes, I know that the guys from Google would never like that since these chars are not "Googleable" :-) Octavian From orasnita at gmail.com Tue May 24 12:10:56 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 19:10:56 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian><87sjs44qyk.fsf@castleamber.com> <20110524060927.778a4a6a.darcy@druid.net> Message-ID: From: "D'Arcy J.M. Cain" > On Tue, 24 May 2011 00:17:55 -0500 > John Bokma wrote: >> > $d = @a; >> >> That will give you the number of elements in @a. What you (probably) >> mean is %hash = @array; > > If I was even considering using Perl, this one exchange would send me > screaming in the opposite direction. If you didn't consider to change the language you prefer it means that you are closed minded and use to fell in love with the tools you use. Don't make me tell here how many things I don't like in Perl. I use to tell those things on Perl mailing lists and make upset their members. :-) Similarly, if you don't like something in Perl, why don't you tell them what you don't like to the Perl programmers community and not just have the guts to tell that in a group where the majority share your preferences. I came here on the list to find good things about Python and to learn some things and use its good parts, and not to hear bashing about other programming languages. Octavian From orasnita at gmail.com Tue May 24 12:11:01 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 19:11:01 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <88a86$4ddbbc22$4275d90a$404@FUSE.NET> Message-ID: From: "Kevin Walzer" > On 5/22/11 3:44 AM, Octavian Rasnita wrote: >> Somebody told that C# and Objective C are good languages. They might be good, but they are proprietary, and not only that they are proprietary, but they need to be ran under platforms that cannot be used freely, so from the freedom point of view, Perl, Ruby, Python and Java are the ways to go. > > Proprietary? > > Licensing options for C# in its Mono (Free Platform) implementation: > > http://www.mono-project.com/Licensing > > Licensing options for Objective-C in its GNUStep (Free Platform) > implementaiton > > http://www.gnustep.org/information/aboutGNUstep.html > > It may be true that these languages are more widely used on their > originating platforms (Windows, OS X) than on Linux, but these > implementations are definitely open source. Exactly, this is why I said that it matters only the distributions used by the most users. Octavian From jeanmichel at sequans.com Tue May 24 12:13:20 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 24 May 2011 18:13:20 +0200 Subject: Obtaining a full path name from file In-Reply-To: <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> Message-ID: <4DDBD920.8060001@sequans.com> RVince wrote: > Ha! You;re right -- but is there a way to get it without the filename > appended at the end? > > On May 24, 11:52 am, Tim Golden wrote: > >> On 24/05/2011 16:36, RVince wrote: >> >> >>> s = "C:\AciiCsv\Gravity_Test_data\A.csv" >>> f = open(s,"r") >>> >>> How do I obtain the full pathname given the File, f? (which should >>> equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff >>> and am just not finding it. Any help greatly appreciated ! >>> >> You're going to kick yourself: >> >> f.name >> >> TJG >> > > path, fileName = os.path.split(os.path.abspath(f.name)) JM From orasnita at gmail.com Tue May 24 12:18:38 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 19:18:38 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <4e51c$4ddbc676$4275d90a$30907@FUSE.NET> Message-ID: Subject: Re: Why did Quora choose Python for its development? > I've been programming for about seven years, and am basically > self-taught. I got my first taste of writing code when trying do to some > basic hacking on my (then) shiny new G3 iBook. (Even though it was a > Mac, I was enthralled by its Unix underpinnings.) C was too hard for a > programming newbie, and (at the time) I only understood shell to be a > sequential series of commands. (cd ~/.Trash; ls; rm *) > > My goal was to write desktop GUI apps, and looking around at the > available languages, libraries, and toolkits for Unix and the Mac, I > settled on Tk as the UI toolkit, since it seemed to be the simplest one > out there, and on Tcl and Python as the programming languages. (A brief > detour with AppleScript convinced me that it is a useful scripting > language for hooking into various parts of OS X, but it is not very > powerful.) > > While Tcl doesn't get a lot of love or respect on this list, it is quite > powerful in its way, and an understanding of Tcl is quite useful in > particular for understanding Tk and its Python wrapper, Tkinter. After > becoming productive with Tcl and writing a couple of applications in it, > I turned to Python in earnest and set about learning its capabilities as > well, and have since released a couple of Python desktop apps on the Mac > (commercial apps, using Tk as the toolkit). > > With that background, here are my reasons for keeping Python in my toolbox: > > 1. Its core libraries and third-party packages address nearly every > imaginable need. The size of its community is a real asset here. Tcl is > a more compact language, with a smaller core library and fewer > third-party packages (no library comparable to Mark Pilgrim's > feedparser, for instance), which means that for some use cases, using > Tcl would mean more work. > > 2. Python has excellent tools for deployment of desktop apps. Since I > only work on the Mac, I'm not that familiar with py2exe, but py2app and > bundlebuilder have always allowed me to wrap up my apps with an embedded > Python interpreter with a minimum of fuss. Tcl also excels in deployment > of desktop apps; other languages, such as Perl and Ruby, seem to lag > behind in this respect. (I could find no actively-maintained, > open-source, Mac-viable desktop app bundling tools for either Ruby or > Perl, which cooled my interest in them considerably.) > > 3. Python's binding to Tk makes writing GUI apps a straightforward > process. Since I already knew Tk quite well, learning its Python > bindings was much simpler than learning another GUI toolkit such as PyQt > or wxPython. The strategies I learned from Tcl to develop sophisticated > Tk-based UI's translate quite well to Python. > > Python isn't perfect; for some instances, I find Tcl a more lightweight > and accessible tool to use. I also spend a lot of time digging into Tcl > and Tk's C API to extend their capabilities in certain ways; this also > allows my Python apps to access such enhancements, via Tkinter. But all > in all I'm a happy user of Python, and it will continue to have a > primary place in my toolbox. > > --Kevin Hi Kevin, Thanks for your message. It is helpful to know why some programmers prefer a certain OS, programming language, module or program, because this way the newbies can find its benefits rapidly. Yes there are packiging solutions for Perl under Mac, but I haven't tried them because I never used a Mac, however, I agree that python is better than Perl for creating desktop apps, because the modules which are used for creating GUIs are better developed. Too bad that you prefer Tk-based GUIs, because they are simple to use, I agree, but they create and promote discrimination because they are not accessible at all for the screen readers used by the blind. The standard Win32 GUIS/MFC or the libs that use those GUIs like Java SWT and wxWIDGETS used by WxPerl, WxPython... are much better accessible. Somebody told that he will try to make Tk accessible, but just as I expected, I haven't heard anything until now about any kind of success of that project. Octavian From tjreedy at udel.edu Tue May 24 12:50:47 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 May 2011 12:50:47 -0400 Subject: Python 3.2 Idle doesn't start. No error message. In-Reply-To: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> References: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> Message-ID: On 5/24/2011 8:01 AM, markrrivet at aol.com wrote: > Hello all. I have Python 2.71 installed on my Windows 7 laptop and it > runs fine. I was having a problem with Python 3.2, 32bit, not starting > with an error message saying this application has quit abnormally. > That was fixed when I took the PYTHONPATH statement out of my > environment variables. However, now when I try to start Idle, I can > see some hard drive activity, but Idle for Python 3.2 does not start; > nothing happens. Any clues as to the problem here? How do you try to start it? -- Terry Jan Reedy From john at castleamber.com Tue May 24 12:50:55 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 11:50:55 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <8762p0kzj6.fsf@mithlond.arda> Message-ID: <874o4kvy8g.fsf@castleamber.com> Teemu Likonen writes: > * 2011-05-24T06:05:35-04:00 * D'Arcy J. M. Cain wrote: > >> On Tue, 24 May 2011 09:00:14 +0300 >> "Octavian Rasnita" wrote: >>> %d = @l; >>> >>> Please tell me if Python has a syntax which is more clear than this >>> for doing this thing. >> >> How is that clear? "Shorter" != "clearer." A Python programmer looking >> at that sees line noise. > > I'm a Lisp programmer who sees (some) Python code as line noise. Exactly, and glad to see there are also non-extremists in this group. I have been programming Perl for well over 17 years. I've been trying to switch to Python /several times/ but yet, with all its shortcomings Perl somehow still suits me better. To D'Arcy and other Pythonistas -- doesn't that sound like an extermistic organization or what -- it might look like a cat had an accident involving a keyboard but to me, and all those other people who do enjoy coding Perl it's beauty. The whole Python is so beatiful & perfect sounds to me like people who have embraced the latin alphabet calling Devanagari unreadable chicken scratches made by backwards and poor people. To me it's a writing system of beauty. > I don't know but from the point of view of a Lisp programmer Python has > the same obsession. Not trolling, I just wanted to point out that these > are just point of views. I don't actually care that much about these > things. Wise words. And I agree. To me Python vs. Perl has nothing to do with being a fanboy (unlike many other posters here). I like both languages, I have invested a lot of time in learning Python and I am really not dense. Yet, even though I can program in Python sufficient enough very often I just pick Perl. Now why is that? -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From john at castleamber.com Tue May 24 12:52:39 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 11:52:39 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> Message-ID: <87zkmcujl4.fsf@castleamber.com> "D'Arcy J.M. Cain" writes: > On Tue, 24 May 2011 00:17:55 -0500 > John Bokma wrote: >> > $d = @a; >> >> That will give you the number of elements in @a. What you (probably) >> mean is %hash = @array; > > If I was even considering using Perl, this one exchange would send me > screaming in the opposite direction. To me as silly as all those people who give Python a wide berth because of significant whitespace. I am glad that I am not so limited in that respect. To me programming languages are like writing systems used by humans; each has its short comings and each has its beauty. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From claudiu at virtuamagic.com Tue May 24 13:17:25 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Tue, 24 May 2011 20:17:25 +0300 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: References: Message-ID: <201105242017.27919.claudiu@virtuamagic.com> I'm quoting a message that I received on personal address and wasn't sent to list: > > try adding argument close_fds=True to subprocess.Popen > > harish > And Tim's message: > It's not quite clear from your description above whether you > can be sure that the called subprocess has closed all its handles > by the time the os.rename runs. Seems that close_fds did the trick. Anyway, I read that description on the documentation last night but I think I was so tired that I understood that in Windows has no effect... :) Thank you, all. -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From darcy at druid.net Tue May 24 13:22:13 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 24 May 2011 13:22:13 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <20110524060927.778a4a6a.darcy@druid.net> Message-ID: <20110524132213.4387ae6b.darcy@druid.net> On Tue, 24 May 2011 19:10:56 +0300 "Octavian Rasnita" wrote: > > If I was even considering using Perl, this one exchange would send me > > screaming in the opposite direction. > > If you didn't consider to change the language you prefer it means > that you are closed minded and use to fell in love with the tools you Now you are just bordering on rudeness. I never made any disparaging remarks about you. I only talked about a tool that you seem to like and I don't. In fact, I did consider and investigate Perl many years ago along with may other languages before I settled on Python. I didn't like it then and I don't like it now. However, I have never called someone "close minded" for preferring a different tool to me. > Don't make me tell here how many things I don't like in Perl. Trust me, there is no need. > I use to tell those things on Perl mailing lists and make upset their Good for you. I also have talked about things in Python that I don't like on this list. No one has ever accused me of being afraid to speak my mind. That facet of my personality has got me in a lot of trouble in my life from parents, teachers, bosses and I have even been known to speak out against the police while they were holding automatic rifles to my head. I doubt that there will ever be enough peer pressure on a mailing list to trump that. > Similarly, if you don't like something in Perl, why don't you tell > them what you don't like to the Perl programmers community and not just > have the guts to tell that in a group where the majority share your > preferences. Because I am not a missionary. Someone came to my house and told me why their way was better so I spoke up. Same thing when the JW come to my front door but I have no interest in going to their Kingdom Hall to tell them why they are wrong. > I came here on the list to find good things about Python and to learn > some things and use its good parts, and not to hear bashing about other > programming languages. Same here but someone (I don't even know who started it) felt that it was necessary to tell us all why their language was better. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rosuav at gmail.com Tue May 24 13:30:00 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 03:30:00 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <874o4kvy8g.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <8762p0kzj6.fsf@mithlond.arda> <874o4kvy8g.fsf@castleamber.com> Message-ID: On Wed, May 25, 2011 at 2:50 AM, John Bokma wrote: > Wise words. And I agree. To me Python vs. Perl has nothing to do with > being a fanboy (unlike many other posters here). I like both languages, > I have invested a lot of time in learning Python and I am really not > dense. Yet, even though I can program in Python sufficient enough very > often I just pick Perl. Now why is that? To me, a language is a tool. The more tools you have competence with, the easier it will be to select the right one for any job. There are very few tools that have no use whatsoever; even Ook might be useful (although I have yet to be asked to port any code to OrangutanOS). This differs from the notion of having ten paradigms in one language, in that most source files will identify themselves fairly early on (possibly even out-of-band, such as filename extensions). Chris Angelico From darcy at druid.net Tue May 24 13:39:02 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 24 May 2011 13:39:02 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <87zkmcujl4.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> Message-ID: <20110524133902.b5ad22b1.darcy@druid.net> On Tue, 24 May 2011 11:52:39 -0500 John Bokma wrote: > >> > $d = @a; > >> > >> That will give you the number of elements in @a. What you (probably) > >> mean is %hash = @array; > > > > If I was even considering using Perl, this one exchange would send me > > screaming in the opposite direction. > > To me as silly as all those people who give Python a wide berth because > of significant whitespace. I am glad that I am not so limited in that > respect. To me programming languages are like writing systems used by > humans; each has its short comings and each has its beauty. My point was that even proponents of the language can make a significant error based on the way the variable is named. It's like the old Fortran IV that I first learned where the name of the variable determined whether it was an integer or a floating point. One of my favorite quotes (not sure if it was about Perl or APL) is "I refuse to use a programming language where the proponents of it stick snippets under each other's nose and say 'I bet you can't guess what this does.'" When I first looked at Perl it looked like line noise. When I first looked at Python it looked like pseudo-code. Look, I couldn't care less what other people use. I just don't see any reason for someone to come into a Python group and start proselytizing about why their tool is better than ours any more than I would feel any need to go to a Perl group and start trying to convert them. Bottom line - they did a study once (sorry, can't point to it any more) to determine the best tool for development. Turns out that the most productive tool was generally the one that the user believed was the most productive. In hindsight I think that that was rather obvious. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From xahlee at gmail.com Tue May 24 13:40:55 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 24 May 2011 10:40:55 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: On May 23, 9:28?pm, Chris Angelico wrote: > On Tue, May 24, 2011 at 2:20 PM, Xah Lee wrote: > > why don't you file a bug report? In GNU Emacs 23.2, it's under the > > Help menu. I suppose it's the same in other emacs distro. > > Because I do not consider its behaviour to be errant. And I suspect > its main developers won't either. That's why I suggested you grab the > sources and make The Perfect Emacs. why don't you try http://ergoemacs.org/ ? Xah From john at castleamber.com Tue May 24 13:56:30 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 12:56:30 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <8762p0kzj6.fsf@mithlond.arda> <874o4kvy8g.fsf@castleamber.com> Message-ID: <871uzougmp.fsf@castleamber.com> Chris Angelico writes: > On Wed, May 25, 2011 at 2:50 AM, John Bokma wrote: >> Wise words. And I agree. To me Python vs. Perl has nothing to do with >> being a fanboy (unlike many other posters here). I like both languages, >> I have invested a lot of time in learning Python and I am really not >> dense. Yet, even though I can program in Python sufficient enough very >> often I just pick Perl. Now why is that? > > To me, a language is a tool. To me, and to a lot of Perl programmers it's not different. > The more tools you have competence with, the easier it will be to > select the right one for any job. There are very few tools that have > no use whatsoever; even Ook might be useful (although I have yet to be > asked to port any code to OrangutanOS). This differs from the notion > of having ten paradigms in one language, If this is referring to Perl: the myths surrounding "there is more than one way" are even more crazy than "there is only one way", maybe because "more than one" makes it so much easier to make those myths up? On top of that: how many paradigms does Python support? And which paradigms does Perl support and Python doesn't? Roughly there are two dialects of Perl [1]: what people who never took the time to learn it write, and the rest. Also, having more than one way to code something doesn't mean that there are no preferrences. Python has also several ways to do certain things; yet most skilled programmers have a preference for one way. It's not that different with Perl; in my experience exactly the same even. Of course one can say a lot about Perl; I can. But I have never had a rough time reading someone else's code, unless the person had no clue about programming to begin with [2]. If Perl is really such a disaster, why are people using it? Or are they all short-sighted idiots who don't know better? Several Perl programmers I know, including myself, are fully aware of Python and other programming languages. Yet, somehow they still program in Perl... [1] http://www.bofh.org.uk/2010/07/25/a-tale-of-two-languages [2] I once had to port a piece of Pascal code and after some studying it turned out that the 100+ lines or so did some variant of bubble sort and near the end reversed the order in a separate loop. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From john at castleamber.com Tue May 24 14:17:54 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 13:17:54 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> Message-ID: <87sjs4t12l.fsf@castleamber.com> "D'Arcy J.M. Cain" writes: > On Tue, 24 May 2011 11:52:39 -0500 > John Bokma wrote: >> >> > $d = @a; >> >> >> >> That will give you the number of elements in @a. What you (probably) >> >> mean is %hash = @array; >> > >> > If I was even considering using Perl, this one exchange would send me >> > screaming in the opposite direction. >> >> To me as silly as all those people who give Python a wide berth because >> of significant whitespace. I am glad that I am not so limited in that >> respect. To me programming languages are like writing systems used by >> humans; each has its short comings and each has its beauty. > > My point was that even proponents of the language can make a > significant error based on the way the variable is named. And someone can't misspell dict, for example? Are we now going to judge a language on a typo someone just made? > When I first looked at Perl it looked like line noise. When I first > looked at Python it looked like pseudo-code. When people who are used to a latin alpabeth look at Devanagari they probably see scratches make by chickens. I saw beauty (and still see it). To someone fluent in Devanagari the latin alpabeth might look like Perl ;-). Anyway, I have been exposed to pseudo-code a lot before I picked up Perl, and yet, Perl somehow stuck with me. I learned about Python a little later (IIRC), and have tried to pick it up several times over the years that followed. Last year I have been more serious about picking it up; and I even did some paid for work in it. I /can/ program in Python, I do /like/ Python, but somehow I like Perl more; even when I am fully aware of its shortcommings each time I use it. As for line noise: very often it turns out that people mean the regular expressions by this. But a similar dialect is used by many other programming languages that I know of. The difference is that Perl has dedicated operators for it. A Perl programmer will call this line noise: double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", re.IGNORECASE) for match in double_word_re.finditer(text): print ("{0} is duplicated".format(match.group("word")) (p500 of Programming in Python 3, 2nd edition, any typos by me). > Look, I couldn't care less what other people use. In that case you're an exception here. Or maybe the weekly Perl bashers are way more vocal here and drown people like you out. One thing I hate about comp.lang.perl.misc is the ivory tower attitude there. One thing I hate about comp.lang.python is the weekly Perl bashing; to me it makes those people look like extremists (Pythonistas, what's in a word), and to be honest, it does affect how I view Python. > I just don't see any reason for someone to come into a Python group > and start proselytizing about why their tool is better than ours any > more than I would feel any need to go to a Perl group and start trying > to convert them. Yet it seems to be accepted behavoir here to weekly bash Perl... > Bottom line - they did a study once (sorry, can't point to it any more) > to determine the best tool for development. Turns out that the most > productive tool was generally the one that the user believed was the > most productive. In hindsight I think that that was rather obvious. Doesn't surprise me. I did switch to Emacs a few years back (used Textpad for many years) but I don't think I now produce more code / hour. But I am able to do some things way easier compared to using Textpad, and that gives me pleasure. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From nambo4jb at gmail.com Tue May 24 14:19:56 2011 From: nambo4jb at gmail.com (Cathy James) Date: Tue, 24 May 2011 13:19:56 -0500 Subject: NEED HELP- read file contents, while loop to accept user Message-ID: TJG- that solved the printing issue!! Many thanks:) Thanks to Chris and Jean Michel for your hints. On Tue, May 24, 2011 at 4:07 AM, 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. Re: Why did Quora choose Python for its development? > (Stefan Behnel) > 2. Re: Why did Quora choose Python for its development? > (Octavian Rasnita) > 3. Re: Why did Quora choose Python for its development? > (Chris Angelico) > 4. NEED HELP- read file contents, while loop to accept user > input, and enter to exit (Cathy James) > 5. Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit (Tim Golden) > 6. Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit (Chris Angelico) > 7. Re: I installed Python 3 on Fedora 14 By Downloading > python3.2 bziped source tarball and install it according to the > README, Now How shall I uninstalled python 3.2? (harrismh777) > 8. Re: Why did Quora choose Python for its development? > (Daniel Kluev) > 9. Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit (Chris Rebert) > 10. Re: [Savoynet] More 'vast heavin' (Chris Angelico) > > > ---------- Forwarded message ---------- > From: Stefan Behnel > To: python-list at python.org > Date: Tue, 24 May 2011 08:23:55 +0200 > Subject: Re: Why did Quora choose Python for its development? > Beliavsky, 20.05.2011 18:39: > >> I thought this essay on why one startup chose Python was interesting. >> > > Since everyone seems to be hot flaming at their pet languages in this > thread, let me quickly say this: > > Thanks for sharing the link. > > Stefan > > > > > ---------- Forwarded message ---------- > From: "Octavian Rasnita" > To: > Date: Tue, 24 May 2011 11:10:36 +0300 > Subject: Re: Why did Quora choose Python for its development? > From: "Stefan Behnel" > >> Beliavsky, 20.05.2011 18:39: >> >>> I thought this essay on why one startup chose Python was interesting. >>> >> >> Since everyone seems to be hot flaming at their pet languages in this >> thread, let me quickly say this: >> >> Thanks for sharing the link. >> > > > Maybe I have missed a message, but if I didn't, please provide that link. > I am always interested to find the best solutions. > > Thanks. > > Octavian > > > > > ---------- Forwarded message ---------- > From: Chris Angelico > To: python-list at python.org > Date: Tue, 24 May 2011 18:20:44 +1000 > Subject: Re: Why did Quora choose Python for its development? > On Tue, May 24, 2011 at 6:10 PM, Octavian Rasnita > wrote: > > From: "Stefan Behnel" > >> > >> Beliavsky, 20.05.2011 18:39: > >>> > >>> I thought this essay on why one startup chose Python was interesting. > >> > >> Since everyone seems to be hot flaming at their pet languages in this > >> thread, let me quickly say this: > >> > >> Thanks for sharing the link. > > > > > > Maybe I have missed a message, but if I didn't, please provide that link. > > I am always interested to find the best solutions. > > At the beginning of the thread, three days and forty-odd messages ago, > this was posted: > > http://www.quora.com/Why-did-Quora-choose-Python-for-its-development > > It's the reason for the thread title, regardless of the current thread > content :) > > Chris Angelico > > > > ---------- Forwarded message ---------- > From: Cathy James > To: python-list at python.org > Date: Tue, 24 May 2011 03:31:37 -0500 > Subject: NEED HELP- read file contents, while loop to accept user input, > and enter to exit > dear mentor, > > I need help with my code: > 1) my program won't display file contents upon opening > 2) my program is not writing to file > 3) my program is not closing when user presses enter- gow do I do this with > a while loop? > > please see my attempt below and help: > > #1) open file and display current file contents: > f = open ('c:/testing.txt'', 'r') > f.readlines() > #2) and 3) use while loop to write user input to file, save to file, > close when press enter: > while True: > s = input ('enter name: ').strip() > f = open ('c:/testing.txt', 'a') > if f.writable(): > f.write(s) > break > else: > f = open ('c:/testing.txt', 'r') > f.readlines() > for line in f: > print (line) > > > ---------- Forwarded message ---------- > From: Tim Golden > To: > Date: Tue, 24 May 2011 09:46:11 +0100 > Subject: Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit > On 24/05/2011 09:31, Cathy James wrote: > >> dear mentor, >> I need help with my code: >> 1) my program won't display file contents upon opening >> > > #1) open file and display current file contents: >> f = open ('c:/testing.txt'', 'r') >> f.readlines() >> > > If you're running this in an interactive interpreter, I would > expect it to show a list of lines (assuming c:/testing.txt has > something in it...). If you're running it as a program, though, > it won't show anything: you need to actually output the result > of the expression f.readlines (). It only happens at the > interpreter as a development convenience: > > f = open ("c:/testing.txt", "r") > print f.readlines () > # or print (f.readlines ()) if you're in Python 3 > > TJG > > > > ---------- Forwarded message ---------- > From: Chris Angelico > To: python-list at python.org > Date: Tue, 24 May 2011 18:46:32 +1000 > Subject: Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit > On Tue, May 24, 2011 at 6:31 PM, Cathy James wrote: > > s = input ('enter name: ').strip() > > Are you using Python 2 or Python 3? If it's Python 2, this should be > raw_input(). > > > f = open ('c:/testing.txt', 'a') > > ... > > f = open ('c:/testing.txt', 'r') > > You may be having trouble here as a result of not closing the file and > then trying to reopen it. > > Also, at some point you have to check if 's' (the user's inputted > string) is empty. You can then leave the loop using the 'break' > statement. > > Hope that helps! Best of luck with your homework. > > Chris Angelico > > > > ---------- Forwarded message ---------- > From: harrismh777 > To: python-list at python.org > Date: Tue, 24 May 2011 03:47:31 -0500 > Subject: Re: I installed Python 3 on Fedora 14 By Downloading python3.2 > bziped source tarball and install it according to the README, Now How shall > I uninstalled python 3.2? > Varuna Seneviratna wrote: > >> Now How shall I uninstalled >> python 3.2? >> >> > Now, how shall I remove Python 3.2 ? > > > ... very carefully. > > > It might be nice if there were a label in the Makefile so this would work: > > sudo make removeall > > ... but alas, why do you want to un-install Python3.2 ? > > > > > > > > > ---------- Forwarded message ---------- > From: Daniel Kluev > To: python-list at python.org > Date: Tue, 24 May 2011 19:55:40 +1100 > Subject: Re: Why did Quora choose Python for its development? > On Tue, May 24, 2011 at 5:00 PM, Octavian Rasnita > wrote: > > And you are telling that in Perl should be used an even more complicated > and > > ugly syntax just for beeing the same as in Python just for showing that I > am > > wrong, but I was comparing just the shortness and cleraness of the code. > > > > So, again, in Perl is just: > > > > %d = @l; > > Once again. Suppose we have array of key-value pairs (two-dimensional > array), `l`. In python, converting it to dict is as simple as d = > dict(l). In perl, %d = @l; produces meaningless value. Following your > logic, this means that perl has ugly syntax. > > -- > With best regards, > Daniel Kluev > > > > ---------- Forwarded message ---------- > From: Chris Rebert > To: Cathy James > Date: Tue, 24 May 2011 01:58:25 -0700 > Subject: Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit > On Tue, May 24, 2011 at 1:31 AM, Cathy James wrote: > > dear mentor, > > > > I need help with my code: > > > In addition to what others have already said... > > > please see my attempt below and help: > > > > #1) open file and display current file contents: > > f = open ('c:/testing.txt'', 'r') > > f.readlines() > > #2) and 3) use while loop to write user input to file, save to file, > close > > when press enter: > > while True: > > s = input ('enter name: ').strip() > > f = open ('c:/testing.txt', 'a') > > if f.writable(): > > Since you *just* opened the file in append mode, this condition will > *always* be true (append mode implies writability), so your `else` > clause will *never* be executed. > > > f.write(s) > > break > > else: > > f = open ('c:/testing.txt', 'r') > > f.readlines() > > for line in f: > > print (line) > > Similar beginner questions would be best directed to Python's Tutor > mailinglist: http://mail.python.org/mailman/listinfo/tutor > > Cheers, > Chris > > > > ---------- Forwarded message ---------- > From: Chris Angelico > To: python-list at python.org > Date: Tue, 24 May 2011 19:07:21 +1000 > Subject: Re: [Savoynet] More 'vast heavin' > On Tue, May 24, 2011 at 7:03 PM, Larry Simons > wrote: > > On Tue 24/05/2011 04:11, Libby Moyer wrote: > >> > >> And the rhymes in Mikado! > > > > Are you referring to ablutioner, diminutioner and ?you shun her? all > rhymed > > with executioner? > > > > Can't deny that they're grin-worthy! > > (Or groan-worthy, I always get those two mixed up.) > > ChrisA > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimsyyap at gmail.com Tue May 24 15:12:53 2011 From: jimsyyap at gmail.com (Jim Syyap) Date: Wed, 25 May 2011 07:12:53 +1200 Subject: subscribef Message-ID: -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrmakent at gmail.com Tue May 24 15:13:33 2011 From: mrmakent at gmail.com (Michael Kent) Date: Tue, 24 May 2011 12:13:33 -0700 (PDT) Subject: Obtaining a full path name from file In-Reply-To: Message-ID: <7a8900d5-a241-4233-a0b4-13f6b9ca67e7@glegroupsg2000goo.googlegroups.com> If a filename does not contain a path component, os.path.abspath will prepend the current directory path onto it. From adsquaired at gmail.com Tue May 24 16:10:37 2011 From: adsquaired at gmail.com (ad) Date: Tue, 24 May 2011 13:10:37 -0700 (PDT) Subject: Code Review Message-ID: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> Hello all, Please review the code pasted below. I am wondering what other ways there are of performing the same tasks. This was typed using version 3.2. The script is designed to clean up a directory (FTP, Logs, etc.) Basically you pass two arguments. The first argument is an number of days old to delete. The second argument is the directory where the files and folders should be deleted. I imagine one enhancement would be to create a function out of some of this. ### BEGIN ### import os import time import shutil import argparse CurrentTime = time.time() epocDay = 86400 # seconds parser = argparse.ArgumentParser(description = "Delete files and folders in a directory N days old", add_help=False, prog='directorycleaner', usage='%(prog)s 7 c:\\temp') parser.add_argument('days', type=int, help="Numeric value: delete files and folders older then N days") parser.add_argument('directory', help="delete files and folders in this directory") parser.print_help() args = parser.parse_args() dictKeys = (vars(args)) HowManyDays = dictKeys['days'] WhatDirectory = dictKeys['directory'] print (HowManyDays) print (WhatDirectory) DaysToDelete = HowManyDays * epocDay dirExists = os.path.exists(WhatDirectory) if dirExists == False: print ("The directory is missing") DirListing = os.listdir(WhatDirectory) for files in DirListing: # Get the absolute path of the file name abspath = (os.path.join(WhatDirectory, files)) # Get the current creation time of the file in epoc format (midnight 1/1/1970) FileCreationTime = (os.path.getctime(abspath)) # time.ctime converts epoch to a normal date #print (time.ctime(CurrentTime)) # Get the date from seven days ago WeekOldFileDate = CurrentTime - DaysToDelete #print (CurrentTime) #print (FileCreationTime) #print (WeekOldFileDate) #If the file is older than seve days doe something if FileCreationTime < WeekOldFileDate: #check if the object is a file if os.path.isfile(abspath): os.remove(abspath) # It is not a file it is a directory elif os.path.isdir(abspath): shutil.rmtree(abspath) ##### END #### From markrrivet at aol.com Tue May 24 16:12:43 2011 From: markrrivet at aol.com (markrrivet at aol.com) Date: Tue, 24 May 2011 16:12:43 -0400 Subject: Python 3.2 Idle doesn't start. No error message. References: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> Message-ID: <4o3ot6h6efljelmtvqu6fcu6o9vqpfjoec@4ax.com> On Tue, 24 May 2011 12:50:47 -0400, Terry Reedy wrote: >On 5/24/2011 8:01 AM, markrrivet at aol.com wrote: >> Hello all. I have Python 2.71 installed on my Windows 7 laptop and it >> runs fine. I was having a problem with Python 3.2, 32bit, not starting >> with an error message saying this application has quit abnormally. >> That was fixed when I took the PYTHONPATH statement out of my >> environment variables. However, now when I try to start Idle, I can >> see some hard drive activity, but Idle for Python 3.2 does not start; >> nothing happens. Any clues as to the problem here? > >How do you try to start it? >From start|programs|python and clicking on the idle icon. From claudiu at virtuamagic.com Tue May 24 16:18:28 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Tue, 24 May 2011 23:18:28 +0300 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: <201105242017.27919.claudiu@virtuamagic.com> References: <201105242017.27919.claudiu@virtuamagic.com> Message-ID: <201105242318.32306.claudiu@virtuamagic.com> > Seems that close_fds did the trick. Anyway, I read that description on > the documentation last night but I think I was so tired that I > understood that in Windows has no effect... :) Now. There is one more issue. Seems that on faster computers and/or Windows 7 (the Win32 thing I have tested on a HVM Xen machine with Windows XP) the os.rename is too fast after fp.close() and generates the same Exception. The code follows: curl.close() fp.close() os.rename(tfile, actualfile) Where, tfile is the .part file, actual file is the real destination, fp was opened with open(..., "wb") and the descriptor passed to curl. I have solved the issue with self.msleep(10) - msleep is a method of QThread. But I don't think it's an elegant and normal solution. Did fp.close() is delayed, or? I mean, I don't want to rely on a "sleep" in order to workaround the access issue. On this issue there is no more process spawn, nothing, just the downloader thread and the main window. And the access denied appears at random time. -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From sunrrrise at gmail.com Tue May 24 16:27:52 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Tue, 24 May 2011 13:27:52 -0700 (PDT) Subject: Odp: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: Ok, another time I'd like to thank you for your help. I gave up, I'm going to get used to IDLE GUI... at least this one works! From sunrrrise at gmail.com Tue May 24 16:27:52 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Tue, 24 May 2011 13:27:52 -0700 (PDT) Subject: Odp: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: Ok, another time I'd like to thank you for your help. I gave up, I'm going to get used to IDLE GUI... at least this one works! From asandroq at gmail.com Tue May 24 16:39:15 2011 From: asandroq at gmail.com (asandroq) Date: Tue, 24 May 2011 13:39:15 -0700 (PDT) Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On May 24, 12:27?am, Deeyana wrote: > > Classic unsubstantiated and erroneous claim. Scheme does not come OOTB > with any suitable libraries for host interop and though it can make calls > to C libraries, doing so is awkward and involves difficulties with the > impedance mismatch between Scheme's data structures and C's char *, void > *, int, double, array, etc. types. To top it off, C lacks automatic > memory management, which means you'll have to concern yourself with > manually disposing of allocated data structures used in interop. (Or, > worse, things will get garbage collected by the Scheme runtime that the > Scheme code no longer references, but the C library is still using, and > bam! SIGSEGV.) > Classic unsubstantiated and erroneous claim. From rosuav at gmail.com Tue May 24 17:53:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 07:53:24 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <871uzougmp.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <8762p0kzj6.fsf@mithlond.arda> <874o4kvy8g.fsf@castleamber.com> <871uzougmp.fsf@castleamber.com> Message-ID: On Wed, May 25, 2011 at 3:56 AM, John Bokma wrote: > Chris Angelico writes: >> To me, a language is a tool. > > To me, and to a lot of Perl programmers it's not different. > >> The more tools you have competence with, the easier it will be to >> select the right one for any job. There are very few tools that have >> no use whatsoever; even Ook might be useful (although I have yet to be >> asked to port any code to OrangutanOS). ?This differs from the notion >> of having ten paradigms in one language, > > If this is referring to Perl: the myths surrounding "there is more than > one way" are even more crazy than "there is only one way", maybe because > "more than one" makes it so much easier to make those myths up? > > On top of that: how many paradigms does Python support? ?And which > paradigms does Perl support and Python doesn't? You miss my point. To me, BOTH Perl AND Python are tools; there is a time and a place for each. Also in my toolkit are C, C++, Pike, REXX, &c, &c, &c. Even Java and ActionScript/Flash (both of which I detest for several reasons) have their place - browser-based applications that aren't limited to HTTP (try writing an in-browser MUD client in Javascript). Every language has its downsides; every language has its unique feature that makes it special. And every language I've ever used has taught me something. Know both. Bash both (if you feel so inclined). Use both. Chris Angelico From tjreedy at udel.edu Tue May 24 17:53:53 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 May 2011 17:53:53 -0400 Subject: Python 3.2 Idle doesn't start. No error message. In-Reply-To: <4o3ot6h6efljelmtvqu6fcu6o9vqpfjoec@4ax.com> References: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> <4o3ot6h6efljelmtvqu6fcu6o9vqpfjoec@4ax.com> Message-ID: On 5/24/2011 4:12 PM, markrrivet at aol.com wrote: > On Tue, 24 May 2011 12:50:47 -0400, Terry Reedy >> How do you try to start it? > >> From start|programs|python and clicking on the idle icon. OK. Works fine for me on winxp desktop and win7 laptop. 3.2.1 will be out soon. Whether or not you find a fix before that, download it, install, and try again. I think I would uninstall 3.2.0 first. You could, of course, try re-installing. I just tried C:\Documents and Settings\Terry>set PYTHONPATH Environment variable PYTHONPATH not defined so undefining that should not be the problem. The icon properties are not helpful as to how it starts IDLE. Perhaps is uses ../python32/Lib/idlelib/idle.bat @echo off rem Start IDLE using the appropriate Python interpreter set CURRDIR=%~dp0 start "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 %7 %8 %9 In a command prompt window you could directly try something like C:\Programs\Python32>pythonw Lib\idlelib\idle.pyw which works for me. Make sure idlelib and idle.pyw are present. Also check tcl/ and Lib/tkinter/ idle.pyw has ======================= try: import idlelib.PyShell except ImportError: # IDLE is not installed, but maybe PyShell is on sys.path: try: from . import PyShell except ImportError: raise else: import os idledir = os.path.dirname(os.path.abspath(PyShell.__file__)) if idledir != os.getcwd(): # We're not in the IDLE directory, help the subprocess find run.py pypath = os.environ.get('PYTHONPATH', '') if pypath: os.environ['PYTHONPATH'] = pypath + ':' + idledir else: os.environ['PYTHONPATH'] = idledir PyShell.main() else: idlelib.PyShell.main() ========================== PYTHONPATH does come into play if but only if two imports fail. You could make a copy of that and add prints to see what does and does not execute. -- Terry Jan Reedy From john at castleamber.com Tue May 24 18:00:52 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 17:00:52 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <8762p0kzj6.fsf@mithlond.arda> <874o4kvy8g.fsf@castleamber.com> <871uzougmp.fsf@castleamber.com> Message-ID: <87vcwzsqqz.fsf@castleamber.com> Chris Angelico writes: > On Wed, May 25, 2011 at 3:56 AM, John Bokma wrote: >> Chris Angelico writes: >>> To me, a language is a tool. >> >> To me, and to a lot of Perl programmers it's not different. >> >>> The more tools you have competence with, the easier it will be to >>> select the right one for any job. There are very few tools that have >>> no use whatsoever; even Ook might be useful (although I have yet to be >>> asked to port any code to OrangutanOS). ?This differs from the notion >>> of having ten paradigms in one language, >> >> If this is referring to Perl: the myths surrounding "there is more than >> one way" are even more crazy than "there is only one way", maybe because >> "more than one" makes it so much easier to make those myths up? >> >> On top of that: how many paradigms does Python support? ?And which >> paradigms does Perl support and Python doesn't? > > You miss my point. Could be, English is my second language. But to me "ten paradigms in one language" smelled of Perl bashing (or maybe Falcon bashing). My apologies if that was not the intent. > To me, BOTH Perl AND Python are tools; there is a time and a place for > each. Also in my toolkit are C, C++, Pike, REXX, &c, &c, &c. Even Java > and ActionScript/Flash (both of which I detest for several reasons) > have their place - browser-based applications that aren't limited to > HTTP (try writing an in-browser MUD client in Javascript). Every > language has its downsides; every language has its unique feature that > makes it special. And every language I've ever used has taught me > something. > > Know both. Bash both (if you feel so inclined). Use both. Can't agree more with you, thanks for the clarification. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From rosuav at gmail.com Tue May 24 18:01:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 08:01:38 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <20110524133902.b5ad22b1.darcy@druid.net> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain wrote: > My point was that even proponents of the language can make a > significant error based on the way the variable is named. ?It's like > the old Fortran IV that I first learned where the name of the variable > determined whether it was an integer or a floating point. I believe that's the origin of one of the proofs that God is real (unless declared integer). And hey, I can't hate something that gave us the classic use of i, j, k as loop indices! > One of my favorite quotes (not sure if it was about Perl or APL) is "I > refuse to use a programming language where the proponents of it stick > snippets under each other's nose and say 'I bet you can't guess what > this does.'" Yes, I believe that was Perl. And an amusing quote. But most of the point of it comes from the fact that Perl uses punctuation for most of its keywords, whereas (say) Python uses English words; it's a lot more fun to crunch something down when you can use $| and friends than when you have to put "x and y", complete with spaces, for a simple boolean. But that says nothing about which language is actually better for working with... beyond the fact that Perl can get more mileage out of an 80-character line! > When I first looked at Perl it looked like line noise. ?When I first > looked at Python it looked like pseudo-code. When I first looked at assembly language it looked like random junk left behind in memory. When I first looked at COBOL it looked like ... COBOL. Doesn't make either of them better or worse. Pseudo-code is not a viable language for a computer to parse, but it's a good language for scribbling down comments in. That doesn't necessarily mean that a programming language that's "closer to" pseudo-code is good. And verbosity doesn't necessarily equate to quality; for instance, when I'm working in both Python and PHP, I find it FAR tidier to use Python's {1:2,3:4] notation than PHP's array(1=>2,3=>4) - but on the flip side, I would prefer to have program structure defined by keywords like "if" and "while" than obscure random line noise. (Fortunately, most sane languages do indeed use keywords there.) Chris Angelico From tjreedy at udel.edu Tue May 24 18:03:42 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 May 2011 18:03:42 -0400 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: <201105242318.32306.claudiu@virtuamagic.com> References: <201105242017.27919.claudiu@virtuamagic.com> <201105242318.32306.claudiu@virtuamagic.com> Message-ID: On 5/24/2011 4:18 PM, Claudiu Nicolaie CISMARU wrote: >> Seems that close_fds did the trick. Anyway, I read that description on >> the documentation last night but I think I was so tired that I >> understood that in Windows has no effect... :) > > Now. There is one more issue. Seems that on faster computers and/or > Windows 7 (the Win32 thing I have tested on a HVM Xen machine with > Windows XP) the os.rename is too fast after fp.close() and generates the > same Exception. The code follows: > > curl.close() > fp.close() > os.rename(tfile, actualfile) > > Where, tfile is the .part file, actual file is the real destination, fp > was opened with open(..., "wb") and the descriptor passed to curl. > > I have solved the issue with self.msleep(10) - msleep is a method of > QThread. But I don't think it's an elegant and normal solution. Did > fp.close() is delayed, or? I mean, I don't want to rely on a "sleep" in > order to workaround the access issue. > > On this issue there is no more process spawn, nothing, just the > downloader thread and the main window. And the access denied appears at > random time. I would go with what works. In my experience, mysterious and seemingly buggy error messages, including Access Denied are not unusual on Windows. -- Terry Jan Reedy From skunkworks at rikishi42.net Tue May 24 18:06:06 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Wed, 25 May 2011 00:06:06 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-24, Steven D'Aprano wrote: >>> I think that is a patronizing remark that under-estimates the >>> intelligence of lay people and over-estimates the difficulty of >>> understanding recursion. >> >> Why would you presume this to be related to intelligence? The point was >> not about being *able* to understand, but about *needing* to understand >> in order to use. > > Maybe they don't "need" to understand recursion. So what? I think you should read the earlier posts again, this is drifting so far from what I intended. What I mean is: I'm certain that over the years I've had more than one person come to me and ask what 'Do you wish to delete this directory recursively?' meant. BAut never have I been asked to explain what 'Do you wish to delete this directory and it's subdirs/with all it's contents?' meant. Never. > Recursion is a perfectly good English word, no more technical than > "accelerate" or "incinerate" or "dissolve" or "combustion". Do people > need to know the word "combustion" when they could say "burn" instead? It wasn't about the word, but about the nature of the function. Besides, if the chance exists of a confusion between a recursive job and the fact the job is done using a recursive function... I would try staying away from the expression. Why not use 'delete a directory'. It's obvious the content gets binned, too. Do you know many people who incinerate leaves and branches in their garden? I burn them. > Do they need to know the words "microwave oven" when they could be saying > "invisible rays cooking thing"? The word oven has existed for ages, microwave is just a name for the type of oven. Not even a description, just a name. > I wonder whether physicists insist that cars should have a "go faster > pedal" because ordinary people don't need to understand Newton's Laws of > Motion in order to drive cars? Gas pedal. Pedal was allraedy known when the car was invented. The simple addition of gas solved that need. Oh, and it's break pedal, not descellarator. (sp?) > Who are you to say that people shouldn't be exposed to words you deem > that they don't need to know? I'm one of the 'people'. You say exposed to, I say bothered/bored with. I have nothing against the use of a proper, precise term. And that word can be a complex one with many, many sylables (seems to add value, somehow). But I'm not an academic, so I don't admire the pedantic use of terms that need to be explained to 'lay' people. Especially if there is a widespread, usually shorter and much simpler one for it. A pointless effort if pointless, even when comming from a physicist. :-) -- When in doubt, use brute force. -- Ken Thompson From markrrivet at aol.com Tue May 24 18:06:33 2011 From: markrrivet at aol.com (markrrivet at aol.com) Date: Tue, 24 May 2011 18:06:33 -0400 Subject: Python 3.2 Idle doesn't start. No error message. References: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> <4o3ot6h6efljelmtvqu6fcu6o9vqpfjoec@4ax.com> Message-ID: On Tue, 24 May 2011 17:53:53 -0400, Terry Reedy wrote: >On 5/24/2011 4:12 PM, markrrivet at aol.com wrote: >> On Tue, 24 May 2011 12:50:47 -0400, Terry Reedy >>> How do you try to start it? >> >>> From start|programs|python and clicking on the idle icon. > >OK. Works fine for me on winxp desktop and win7 laptop. >3.2.1 will be out soon. Whether or not you find a fix before that, >download it, install, and try again. I think I would uninstall 3.2.0 >first. You could, of course, try re-installing. > >I just tried >C:\Documents and Settings\Terry>set PYTHONPATH >Environment variable PYTHONPATH not defined > >so undefining that should not be the problem. > >The icon properties are not helpful as to how it starts IDLE. >Perhaps is uses ../python32/Lib/idlelib/idle.bat > >@echo off >rem Start IDLE using the appropriate Python interpreter >set CURRDIR=%~dp0 >start "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 >%7 %8 %9 > >In a command prompt window you could directly try something like >C:\Programs\Python32>pythonw Lib\idlelib\idle.pyw >which works for me. Make sure idlelib and idle.pyw are present. >Also check tcl/ and Lib/tkinter/ > >idle.pyw has >======================= >try: > import idlelib.PyShell >except ImportError: > # IDLE is not installed, but maybe PyShell is on sys.path: > try: > from . import PyShell > except ImportError: > raise > else: > import os > idledir = os.path.dirname(os.path.abspath(PyShell.__file__)) > if idledir != os.getcwd(): > # We're not in the IDLE directory, help the subprocess find >run.py > pypath = os.environ.get('PYTHONPATH', '') > if pypath: > os.environ['PYTHONPATH'] = pypath + ':' + idledir > else: > os.environ['PYTHONPATH'] = idledir > PyShell.main() >else: > idlelib.PyShell.main() >========================== > >PYTHONPATH does come into play if but only if two imports fail. >You could make a copy of that and add prints to see what does and does >not execute. Thanks Terry, I will do what I can. I'll let you know how it works out. But thanks again. Every little bit helps me get closer to the solution. From rosuav at gmail.com Tue May 24 18:14:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 08:14:27 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: On Wed, May 25, 2011 at 3:40 AM, Xah Lee wrote: > On May 23, 9:28?pm, Chris Angelico wrote: >> Because I do not consider its behaviour to be errant. And I suspect >> its main developers won't either. That's why I suggested you grab the >> sources and make The Perfect Emacs. > > why don't you try http://ergoemacs.org/ ? You miss my point. I am not desiring of a different emacs; you were the one complaining about its shortcomings. Chris Angelico From lew1716 at gmail.com Tue May 24 18:17:17 2011 From: lew1716 at gmail.com (Lew Schwartz) Date: Tue, 24 May 2011 18:17:17 -0400 Subject: Beginner needs advice Message-ID: Here's my background: I'm a Windows based Visual FoxPro developer, and I want to start programming in Python. I'll be sticking to Windows (XP & 7) and my immediate needs are to manage & display large groups of jpg's, tiff's etc... so I need form based & graphics capable libraries (in addition to basic programming skills, of course). So Python 2 or 3? Add on packages/libraries? Tutorials? Thanks! -Lew -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 24 18:38:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 08:38:07 +1000 Subject: Functional Programing: stop using recursion, cons. Use map & vectors In-Reply-To: References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On Tue, May 24, 2011 at 8:27 AM, Deeyana wrote: > Classic unsubstantiated and erroneous claim. Scheme does not come OOTB > with any suitable libraries for host interop and though it can make calls > to C libraries, doing so is awkward and involves difficulties with the > impedance mismatch between Scheme's data structures and C's char *, void > *, int, double, array, etc. types. To top it off, C lacks automatic > memory management, which means you'll have to concern yourself with > manually disposing of allocated data structures used in interop. (Or, > worse, things will get garbage collected by the Scheme runtime that the > Scheme code no longer references, but the C library is still using, and > bam! SIGSEGV.) How is this fundamentally different from Python calling into C? Chris Angelico From john at castleamber.com Tue May 24 19:16:06 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 18:16:06 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: <87mxibsn9l.fsf@castleamber.com> Chris Angelico writes: > On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain wrote: >> My point was that even proponents of the language can make a >> significant error based on the way the variable is named. ?It's like >> the old Fortran IV that I first learned where the name of the variable >> determined whether it was an integer or a floating point. > > I believe that's the origin of one of the proofs that God is real > (unless declared integer). And hey, I can't hate something that gave > us the classic use of i, j, k as loop indices! > >> One of my favorite quotes (not sure if it was about Perl or APL) is "I >> refuse to use a programming language where the proponents of it stick >> snippets under each other's nose and say 'I bet you can't guess what >> this does.'" > > Yes, I believe that was Perl. And an amusing quote. But most of the > point of it comes from the fact that Perl uses punctuation for most of > its keywords, For example? > whereas (say) Python uses English words; it's a lot more > fun to crunch something down when you can use $| That's not a keyword but a special (global) variable. On top of that, you don't have to use it [1] and most people most likely encounter this in (badly) written CGI scripts originating in the last century. Yes, Perl is fantastic for writing hard to read obfuscated code. And yes, newbies are great at writing this from the very start, especially since they seem to copy paste examples written by other newbies (often written in the previous century...). But Perl doesn't force one to write unreadable code. If Perl was really so unreadable, why haven't I /still/ not switched to Python? What keeps me going back to Perl? > and friends than when you have to put "x and y", complete with spaces, > for a simple boolean. Perl has also the and logical operator. This is legal Perl: if ( $x and $y ) { print "yes\n"; } [1] You can use $OUTPUT_AUTOFLUSH (use English;), or use IO::Handle and use the autoflush method [2]. [2] In Perl 5.14 IO::File is now loaded on demand: http://search.cpan.org/dist/perl/pod/perldelta.pod#Filehandle_method_calls_load_IO::File_on_demand -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From rosuav at gmail.com Tue May 24 19:38:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 09:38:08 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <87mxibsn9l.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87mxibsn9l.fsf@castleamber.com> Message-ID: On Wed, May 25, 2011 at 9:16 AM, John Bokma wrote: > Chris Angelico writes: > >> Yes, I believe that was Perl. And an amusing quote. But most of the >> point of it comes from the fact that Perl uses punctuation for most of >> its keywords, > > For example? > >> whereas (say) Python uses English words; it's a lot more >> fun to crunch something down when you can use $| > > That's not a keyword but a special (global) variable. On top of that, > you don't have to use it [1] and most people most likely encounter this in > (badly) written CGI scripts originating in the last century. Okay, poor example. But there's a lot of Perl that uses concise notation for things that in Python are keyworded; for instance, regular expressions. I'm insufficiently fluent in Perl to quote good examples; mainly what I'm referring to is the notion of operators that are separators, as opposed to keywords that get blank-delimited. I generally prefer syntactic elements to be punctuation (eg { } rather than BEGIN and END (or DO and END)). It does also make things easier to crunch, for better or for worse. >> and friends than when you have to put "x and y", complete with spaces, >> for a simple boolean. > > Perl has also the and logical operator. This is legal Perl: > > if ( $x and $y ) { > ?print "yes\n"; > } That's at a completely different precedence level, isn't it? For operators up where you expect them to be, there's && and ||. A bit of digging (why isn't this sort of thing always the first hit for " operator precedence" in Google?) brought up: http://perldoc.perl.org/perlop.html For instance: $a = $b && $c ? $e : $f; # versus $a = $b and $c ? $e : $f; The first one is an assignment to $a, conditional on two variables. The second is an unconditional assignment to $a, and then based on that, evaluates either $e or $f and does nothing with it. Python: a = e if b and c else f It's pretty similar, actually (although, coming from a C background, I do prefer to have the condition first); but I could crunch the first one down a lot, while the last one is almost as tight as it can be. $a=$b&&$c?$e:$f; a=e if b and c else f It's that crunched appearance that makes Perl look like line noise, and the open keyworded appearance that makes Python look like pseudocode. But that's not necessarily a good thing; a courteous programmer can space out Perl to keep it readable, and he then has the option of crunching pieces that are 'logically one' and spacing out the parts that aren't: $a= $b&&$c ? $e : $f; Silly, contrived example, but in production code I've often had situations where it makes sense to space out one part of an expression and crunch another. And when everything's an English word, that's not an available option. Oh, and that's ignoring the issue that not everyone is fluent in English. That said, though, I do find Python a lot easier for reading other people's code in. A LOT easier. Chris Angelico From python at rcn.com Tue May 24 19:44:21 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 24 May 2011 16:44:21 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> Message-ID: On May 17, 8:50?am, RJB wrote: > I noticed some discussion of recursion..... the trick is to find a > formula where the arguments are divided, not decremented. > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > for a couple of years in C++ but just for fun rewrote it > in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! > > def fibo(n): > ? ? ? ? """A Faster recursive Fibonaci function > Use a formula from Knuth Vol 1 page 80, section 1.2.8: > ? ? ? ? ? ?If F[n] is the n'th Fibonaci number then > ? ? ? ? ? ? ? ? ? ?F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. > ? First set m = n+1 > ? ?F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. > > ? Then put m = n in Knuth's formula, > ? ? ? ? ? ?F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], > ? ?and replace F[n+1] by F[n]+F[n-1], > ? ? ? ? ? ?F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). > """ > ? ? ? ? if n<=0: > ? ? ? ? ? ? ? ? return 0 > ? ? ? ? elif n<=2: > ? ? ? ? ? ? ? ? return 1 > ? ? ? ? elif n%2==0: > ? ? ? ? ? ? ? ? half=n//2 > ? ? ? ? ? ? ? ? f1=fibo(half) > ? ? ? ? ? ? ? ? f2=fibo(half-1) > ? ? ? ? ? ? ? ? return f1*(f1+2*f2) > ? ? ? ? else: > ? ? ? ? ? ? ? ? nearhalf=(n-1)//2 > ? ? ? ? ? ? ? ? f1=fibo(nearhalf+1) > ? ? ? ? ? ? ? ? f2=fibo(nearhalf) > ? ? ? ? ? ? ? ? return f1*f1 + f2*f2 > > RJB the Lurkerhttp://www.csci.csusb.edu/dick/cs320/lab/10.html There are many ways to write this function. The one I like shows-off a general purpose dynamic programming technique while staying *very* close to a common textbook definition of a fibonacci number: @functools.lru_cache() def fibo(n): return 1 if n < 2 else fibo(n-1) + fibo(n-2) Raymond From d.awlberg at hotmail.invalid Tue May 24 20:03:17 2011 From: d.awlberg at hotmail.invalid (Deeyana) Date: Wed, 25 May 2011 00:03:17 +0000 (UTC) Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On Tue, 24 May 2011 13:39:15 -0700, asandroq wrote: > On May 24, 12:27?am, Deeyana wrote: >> >> Classic unsubstantiated and erroneous claim. Scheme does not come OOTB >> with any suitable libraries for host interop and though it can make >> calls to C libraries, doing so is awkward and involves difficulties >> with the impedance mismatch between Scheme's data structures and C's >> char *, void *, int, double, array, etc. types. To top it off, C lacks >> automatic memory management, which means you'll have to concern >> yourself with manually disposing of allocated data structures used in >> interop. (Or, worse, things will get garbage collected by the Scheme >> runtime that the Scheme code no longer references, but the C library is >> still using, and bam! SIGSEGV.) > > Classic unsubstantiated and erroneous claim. On your part, asandroq. From rosuav at gmail.com Tue May 24 20:16:00 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 10:16:00 +1000 Subject: Link errors embedding Python 3.2 Message-ID: I'm starting to feel incredibly stupid here. Hopefully someone can point out a really obvious thing that I've missed, thus enabling me to move forward! Up until now, I've been embedding Python 2.6.6 in my C++ program, by compiling with "-I/usr/include/python2.6 -lpython2.6", and all has been well. The Python I use was installed as part of Ubuntu's setup, and is managed by apt-get. Now, I'm trying to switch to using Python 3. so I downloaded the 3.2 sources and did the usual './configure; make; sudo make install', then snooped to see where it had put things. I'm now compiling with "-I/usr/local/include/python3.2m -lpython3.2m", and it's compiling successfully (now that I've changed the function names eg PyString --> PyBytes), but the link fails with heaps of undefined references - as far as I can tell, every single Py* reference is failing. There is a libpython3.2m.a accessible, and poking around with ar and nm shows that it does contain object files with the necessary symbols. If I deliberately misspell the -lpython3.2m option, the link bombs immediately, so presumably it IS finding the library. Explicitly naming the library as ~/Python-3.2/libpython3.2m.a (or using ar to extract them and then linking against the whole directoryful of .o files, which does the same thing) cures the undefined references to Py* functions, but brings in undefined refs to dlsym and openpty and family. Is/are there additional library/ies that I need to be linking against for Python 3? And why is the usual -lpython3.2m not working as normal? Is there a problem with C++ and Python? (I tried surrounding #include "Python.h" with extern "C" { }, but to no avail.) Hoping that someone has already done this! Chris Angelico From jimmy at retzlaff.com Tue May 24 20:26:00 2011 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Tue, 24 May 2011 17:26:00 -0700 Subject: Subject: mrjob v0.2.6 released Message-ID: What is mrjob? ----------------- mrjob is a Python package that helps you write and run Hadoop Streaming jobs. mrjob fully supports Amazon's Elastic MapReduce (EMR) service, which allows you to buy time on a Hadoop cluster on an hourly basis. It also works with your own Hadoop cluster. Some important features: * Run jobs on EMR, your own Hadoop cluster, or locally (for testing). * Write multi-step jobs (one map-reduce step feeds into the next) * Duplicate your production environment inside Hadoop * Upload your source tree and put it in your job's $PYTHONPATH * Run make and other setup scripts * Set environment variables (e.g. $TZ) * Easily install python packages from tarballs (EMR only) * Setup handled transparently by mrjob.conf config file * Automatically interpret error logs from EMR * SSH tunnel to hadoop job tracker on EMR * Minimal setup * To run on EMR, set $AWS_ACCESS_KEY_ID and $AWS_SECRET_ACCESS_KEY * To run on your Hadoop cluster, install simplejson and make sure $HADOOP_HOME is set. More info: * Install mrjob: python setup.py install * Documentation: http://packages.python.org/mrjob/ * PyPI: http://pypi.python.org/pypi/mrjob * Development is hosted at github: http://github.com/Yelp/mrjob What's new? ------------- v0.2.6, 2011-05-24 -- fix bootstrapping mrjob ?* Set Hadoop to run on EMR with --hadoop-version (Issue #71). ? * Default is still 0.18, but will change to 0.20 in mrjob v0.3.0. ?* New inline runner, for testing locally with a debugger ?* New --strict-protocols option, to catch unencodable data (Issue #76) ?* Added steps_python_bin option (for use with virtualenv) ?* mrjob no longer chokes when asked to run on an EMR job flow running Hadoop 0.20 (Issue #110) ?* mrjob no longer chokes on job flows with no LogUri (Issue #112) From memilanuk at gmail.com Tue May 24 20:34:18 2011 From: memilanuk at gmail.com (memilanuk) Date: Tue, 24 May 2011 17:34:18 -0700 Subject: Beginner needs advice In-Reply-To: References: Message-ID: On 05/24/2011 03:17 PM, Lew Schwartz wrote: > Here's my background: > > I'm a Windows based Visual FoxPro developer, and I want to start > programming in Python. I'll be sticking to Windows (XP & 7) and my > immediate needs are to manage & display large groups of jpg's, tiff's > etc... so I need form based & graphics capable libraries (in addition to > basic programming skills, of course). > > So Python 2 or 3? Add on packages/libraries? Tutorials? > > Thanks! > > -Lew > If Visual Foxpro is your thing, maybe Dabo (www.dabodev.com) would be of interest to you. The developers are former Visual Foxpro programmers... From rosuav at gmail.com Tue May 24 20:40:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 10:40:22 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 25, 2011 at 8:06 AM, Rikishi42 wrote: > On 2011-05-24, Steven D'Aprano wrote: > Why not use 'delete a directory'. It's obvious the content gets binned, too. Which is why I raised the issue with regard to other operations. Manipulating files matching a glob can be done recursively or nonrecursively, and both make perfect sense. > Do you know many people who incinerate leaves and branches in their garden? > I burn them. We used to incinerate ours (until we stopped using rapid exothermic oxidation as a means of DECREFfing our garden waste). It's a cultural thing, I guess. >> Do they need to know the words "microwave oven" when they could be saying >> "invisible rays cooking thing"? > > The word oven has existed for ages, microwave is just a name for the type of > oven. Not even a description, just a name. It's funny how a single piece of jargon can go incredibly mainstream. "Microwave" (with or without "oven" after it) is well known, but plenty else remains obscure. >> I wonder whether physicists insist that cars should have a "go faster >> pedal" because ordinary people don't need to understand Newton's Laws of >> Motion in order to drive cars? > > Gas pedal. Pedal was allraedy known when the car was invented. The simple > addition of gas solved that need. Oh, and it's break pedal, not > descellarator. (sp?) Americans might call it a gas pedal. We call it an accelerator. You don't have a "decelerator pedal" though, because it's more accurately called a "brake pedal" because it controls the brakes. Personally, I'm of the opinion that people *should* have some basic understanding of Newton's laws before they take charge of a ton of high-powered machinery. At very least, some basic comprehension of kinetic energy, and the way a high speed train has a *LOT* of it. Might result in drivers with a little more respect for trains and trucks. >> Who are you to say that people shouldn't be exposed to words you deem >> that they don't need to know? > > I'm one of the 'people'. You say exposed to, I say bothered/bored with. > > I have nothing against the use of a proper, precise term. And that word can > be a complex one with many, many sylables (seems to add value, somehow). > > But I'm not an academic, so I don't admire the pedantic use of terms that > need to be explained to 'lay' people. Especially if there is a widespread, > usually shorter and much simpler one for it. A pointless effort if > pointless, even when comming from a physicist. ?:-) In any industry, you can find jargon in several different categories: 1) Terms that describe unique objects/effects/etc, where you would be using a lengthy phrase otherwise (eg "URL") 2) Terms that are clearer or more precise than the less-jargonny equivalents, but where you could get away with dodging jargon if you wanted to (eg "recursive operation") 3) Words and phrases that have little value to an end user, but can be used to show off your skill (eg "Network Destabilisation from Low Voltage Fluorescent Lamp Spikes"). I would never apologise for using terms in the first category. Just explain them (in a footnote if necessary) and expect people to be accurate. The third category is mainly used for invoking Dummy Mode (if you don't know what that is, google my example - it's vintage BOFH), and should be avoided. It's the middle lot that are harder. Do you use it and risk people not understanding, or avoid it and risk people misunderstanding? Tough choice, especially since those who misunderstand often won't know why. If we forever aim to the stupidest of humans, the human race will get stupider. If we forever aim way above people's heads, they won't bother to communicate. An eternal dilemma. Chris Angelico From john at castleamber.com Tue May 24 21:48:30 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 20:48:30 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87mxibsn9l.fsf@castleamber.com> Message-ID: <87ipszsg7l.fsf@castleamber.com> Chris Angelico writes: > On Wed, May 25, 2011 at 9:16 AM, John Bokma wrote: >> Chris Angelico writes: >> >>> Yes, I believe that was Perl. And an amusing quote. But most of the >>> point of it comes from the fact that Perl uses punctuation for most of >>> its keywords, >> >> For example? >> >>> whereas (say) Python uses English words; it's a lot more >>> fun to crunch something down when you can use $| >> >> That's not a keyword but a special (global) variable. On top of that, >> you don't have to use it [1] and most people most likely encounter this in >> (badly) written CGI scripts originating in the last century. > > Okay, poor example. But there's a lot of Perl that uses concise > notation for things that in Python are keyworded; for instance, > regular expressions. Perl does have indeed operators for matching and substitution. It's: ( my $foo = $bar ) =~ s/ ... / ... /; versus foo = re.sub(r" ... ", " ... ", bar ) and: my $foo = qr/ ... /xi; versus: foo = re.compile(r""" ... """, re.IGNORECASE|re.VERBOSE) It's just a matter of taste IMO. The regular expression noise stays the same ;-). >>> and friends than when you have to put "x and y", complete with spaces, >>> for a simple boolean. >> >> Perl has also the and logical operator. This is legal Perl: >> >> if ( $x and $y ) { >> ?print "yes\n"; >> } > > That's at a completely different precedence level, isn't it? Yes, /but/ in this case it doesn't matter. Of course there are cases that it /does/ matter: > For instance: > > $a = $b && $c ? $e : $f; > # versus > $a = $b and $c ? $e : $f; > > The first one is an assignment to $a, conditional on two variables. > The second is an unconditional assignment to $a, and then based on > that, evaluates either $e or $f and does nothing with it. > > Python: > a = e if b and c else f Yes, "recently" added to the language, before that you had to and or your way out of it (or use lambdas). > It's pretty similar, actually (although, coming from a C background, I > do prefer to have the condition first); but I could crunch the first > one down a lot, while the last one is almost as tight as it can be. > > $a=$b&&$c?$e:$f; > a=e if b and c else f > > It's that crunched appearance that makes Perl look like line noise, So you just agree with what I earlier wrote: one /can/ write harder to read in Perl, like you can jump off a cliff. And I have seen a lot of extremely badly written Perl code, but never seen a disaster like the one above ;-). > and the open keyworded appearance that makes Python look like > pseudocode. But that's not necessarily a good thing; a courteous > programmer can space out Perl to keep it readable, and he then has the > option of crunching pieces that are 'logically one' and spacing out > the parts that aren't: > > $a= $b&&$c ? $e : $f; > > Silly, contrived example, but in production code I've often had > situations where it makes sense to space out one part of an expression > and crunch another. And when everything's an English word, that's not > an available option. I would write it like $a = ( $b and $c ) ? $e : $f; > That said, though, I do find Python a lot easier for reading other > people's code in. A LOT easier. Like I wrote earlier: I find Perl easier to read. And honestly, I don't know why. Partially it might have a lot to do with having been exposed to it much more. But many years back, when I could pick between several languages, Perl was the one that stuck with me. And that was before everybody and his mom was hacking CGI scripts in Perl (badly). And while I do want to switch to Python (or use it more often), for one reason or another it's hard. Maybe it's for similar reasons that one loves Spanish but hates German as a second language (or vice versa)? Both Perl and Python are evolving. Perl has a lot of bagage from the beginning, and more so since a lot got slapped on later on. Things are changing, but you just can't make major changes since people, like me I guess, are used to how things are right now. I now and then have peeks at Perl 6 and each time my first reaction is: this is Perl only in name; it's very, very different. On the other hand it still shares what I consider warts with Perl 5. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From no.email at nospam.invalid Wed May 25 00:45:06 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 24 May 2011 21:45:06 -0700 Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: <7xy61v5qy5.fsf@ruckus.brouhaha.com> John Lee writes: > In this thread, I'm asking about the views of Python programmers on > languages other than Python. I sympathize with what you're looking for but I don't think there's a really good answer at this time. Things IMO are converging in the direction of functional languages like Haskell but it seems to me that there is a big gap between the current academic ideas and what makes sense for working programmers. The academics aren't all that concerned with practicality, but good solutions really have to incorporate their ideas since the rest of us are rather badly behind the times. Haskell probably has the most vibrant development community at the moment but its learning curve is quite steep, and it has various shortcomings some of which are being worked on but others of which may be insurmountable. If you like the Java ecosystem but not the Java language, check out Scala. You could look for the article "The Next Mainstream Programming Languages" by Tim Sweeney. It discusses similar issues to what I think you are facing. From xahlee at gmail.com Wed May 25 02:05:16 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 24 May 2011 23:05:16 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3f6ff490-3dfd-4b77-9e6d-5da168b3dadd@e17g2000prj.googlegroups.com> On May 24, 3:06?pm, Rikishi42 wrote: > On 2011-05-24, Steven D'Aprano wrote: > > >>> I think that is a patronizing remark that under-estimates the > >>> intelligence of lay people and over-estimates the difficulty of > >>> understanding recursion. > > >> Why would you presume this to be related to intelligence? The point was > >> not about being *able* to understand, but about *needing* to understand > >> in order to use. > > > Maybe they don't "need" to understand recursion. So what? > > I think you should read the earlier posts again, this is drifting so far > from what I intended. > > What I mean is: I'm certain that over the years I've had more than one > person come to me and ask what 'Do you wish to delete this directory > recursively?' meant. BAut never have I been asked to explain what 'Do you > wish to delete this directory and it's subdirs/with all it's contents?' > meant. Never. > > > Recursion is a perfectly good English word, no more technical than > > "accelerate" or "incinerate" or "dissolve" or "combustion". Do people > > need to know the word "combustion" when they could say "burn" instead? > > It wasn't about the word, but about the nature of the function. Besides, if > the chance exists of a confusion between a recursive job and the fact the > job is done using a recursive function... I would try staying away from the > expression. ? > > Why not use 'delete a directory'. It's obvious the content gets binned, too. > > Do you know many people who incinerate leaves and branches in their garden? > I burn them. > > > Do they need to know the words "microwave oven" when they could be saying > > "invisible rays cooking thing"? > > The word oven has existed for ages, microwave is just a name for the type of > oven. Not even a description, just a name. > > > I wonder whether physicists insist that cars should have a "go faster > > pedal" because ordinary people don't need to understand Newton's Laws of > > Motion in order to drive cars? > > Gas pedal. Pedal was allraedy known when the car was invented. The simple > addition of gas solved that need. Oh, and it's break pedal, not > descellarator. (sp?) > > > Who are you to say that people shouldn't be exposed to words you deem > > that they don't need to know? > > I'm one of the 'people'. You say exposed to, I say bothered/bored with. > > I have nothing against the use of a proper, precise term. And that word can > be a complex one with many, many sylables (seems to add value, somehow). > > But I'm not an academic, so I don't admire the pedantic use of terms that > need to be explained to 'lay' people. Especially if there is a widespread, > usually shorter and much simpler one for it. A pointless effort if > pointless, even when comming from a physicist. ?:-) very well said, Rikishi42. this one is probably the most intelligent post in this thread. Xah From lew1716 at gmail.com Wed May 25 02:22:14 2011 From: lew1716 at gmail.com (Lew Schwartz) Date: Wed, 25 May 2011 02:22:14 -0400 Subject: Beginner needs advice In-Reply-To: <4DDC7938.5000900@gmail.com> References: <4DDC7938.5000900@gmail.com> Message-ID: So, if I read between the lines correctly, you recommend Python 3? Does the windows version install with a development environment? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Wed May 25 02:36:11 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 25 May 2011 08:36:11 +0200 Subject: Obtaining a full path name from file References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: RVince wrote: > s = "C:\AciiCsv\Gravity_Test_data\A.csv" > f = open(s,"r") > > How do I obtain the full pathname given the File, f? Apart from the issue that the 'name' attribute is only the name used to open the file, there is another issue, though not on the platform you're using: Multiple directory entries can point to the same file, all of which can be changed (including deletion!) even while you have the file open. I'm not sure what problem you're trying to solve, but I'm afraid your approach is at least limited. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From mail at timgolden.me.uk Wed May 25 03:17:38 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 25 May 2011 08:17:38 +0100 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: <201105242318.32306.claudiu@virtuamagic.com> References: <201105242017.27919.claudiu@virtuamagic.com> <201105242318.32306.claudiu@virtuamagic.com> Message-ID: <4DDCAD12.4050203@timgolden.me.uk> On 24/05/2011 21:18, Claudiu Nicolaie CISMARU wrote: > Now. There is one more issue. Seems that on faster computers and/or > Windows 7 (the Win32 thing I have tested on a HVM Xen machine with > Windows XP) the os.rename is too fast after fp.close() and generates the > same Exception. The code follows: > > curl.close() > fp.close() > os.rename(tfile, actualfile) > > Where, tfile is the .part file, actual file is the real destination, fp > was opened with open(..., "wb") and the descriptor passed to curl. > > I have solved the issue with self.msleep(10) - msleep is a method of > QThread. But I don't think it's an elegant and normal solution. Did > fp.close() is delayed, or? I mean, I don't want to rely on a "sleep" in > order to workaround the access issue. There used to be a problem with subprocess fds being held by a traceback. IIRC, the problem could be triggered by having an except clause around a subprocess call within which something attempted to, eg, remove one of the affected files. I'm sorry if that's a bit of a woolly description but if you think this might be biting you I'll dive in and look at the code. What version of Python are you using? (That said, the fact that the behaviour varies between faster and slower computers makes that cause unlikely. Maybe we're back to looking at virus checkers and the like...) TJG From __peter__ at web.de Wed May 25 03:22:31 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 25 May 2011 09:22:31 +0200 Subject: Code Review References: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> Message-ID: ad wrote: > Please review the code pasted below. I am wondering what other ways > there are of performing the same tasks. This was typed using version > 3.2. The script is designed to clean up a directory (FTP, Logs, etc.) > Basically you pass two arguments. The first argument is an number of > days old to delete. The second argument is the directory where the > files and folders should be deleted. I imagine one enhancement would > be to create a function out of some of this. > CurrentTime = time.time() Read PEP 8 on naming conventions etc., see http://python.org/dev/peps/pep-0008/ > > epocDay = 86400 # seconds > > > > > > parser = argparse.ArgumentParser(description = "Delete files and What's the purpose of those many empty lines? > folders in a directory N days old", add_help=False, > prog='directorycleaner', usage='%(prog)s 7 c:\\temp') > > parser.add_argument('days', type=int, help="Numeric value: delete > files and folders older then N days") > > parser.add_argument('directory', help="delete files and folders in > this directory") > > parser.print_help() What's the idea behind add_help=False and the explicit print_help()? > dictKeys = (vars(args)) > HowManyDays = dictKeys['days'] This can be simplified to HowManyDays = args.days > if dirExists == False: print ("The directory is missing") if x == False: ... is normally written as if not x: ... > DirListing = os.listdir(WhatDirectory) > for files in DirListing: You might write this as for filename in os.listdir(WhatDirectory): ... or even for filename in os.listdir(args.directory): ... Personally I would put this stuff in a separate function like def remove_old_files_and_folders(parent_directory, age_in_seconds): ... > # time.ctime converts epoch to a normal date > > #print (time.ctime(CurrentTime)) > > # Get the date from seven days ago > > WeekOldFileDate = CurrentTime - DaysToDelete > > #print (CurrentTime) > > #print (FileCreationTime) > > #print (WeekOldFileDate) Don't let out-commented code eclipse the actual code; remove it. If you want to preserve it for eternity, have a look at version control systems, e. g. Mercurial. From thorsten at thorstenkampe.de Wed May 25 03:26:11 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 25 May 2011 09:26:11 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Rikishi42 (Wed, 25 May 2011 00:06:06 +0200) > > On 2011-05-24, Steven D'Aprano wrote: > >>> I think that is a patronizing remark that under-estimates the > >>> intelligence of lay people and over-estimates the difficulty of > >>> understanding recursion. > >> > >> Why would you presume this to be related to intelligence? The point was > >> not about being *able* to understand, but about *needing* to understand > >> in order to use. > > > > Maybe they don't "need" to understand recursion. So what? > > I think you should read the earlier posts again, this is drifting so far > from what I intended. > > What I mean is: I'm certain that over the years I've had more than one > person come to me and ask what 'Do you wish to delete this directory > recursively?' meant. BAut never have I been asked to explain what 'Do you > wish to delete this directory and it's subdirs/with all it's contents?' > meant. Never. Naming something in the terms of its implementation details (in this case recursion) is a classical WTF. On the other hand, it's by far not the only WTF in Unix. For instance, how often have you read "unlink" instead of "delete"? Or "directory" instead of "folder", pointing out that "directory" is the correct term because a directory is just a listing and does not "contain" the actual files. Of course these implementation details will never matter to anyone except under the rarest conditions. Thorsten From mail at timgolden.me.uk Wed May 25 03:29:11 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 25 May 2011 08:29:11 +0100 Subject: Obtaining a full path name from file In-Reply-To: References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: <4DDCAFC7.7060201@timgolden.me.uk> On 25/05/2011 07:36, Ulrich Eckhardt wrote: > RVince wrote: >> s = "C:\AciiCsv\Gravity_Test_data\A.csv" >> f = open(s,"r") >> >> How do I obtain the full pathname given the File, f? > > Apart from the issue that the 'name' attribute is only the name used to open > the file, there is another issue, though not on the platform you're using: > Multiple directory entries can point to the same file, all of which can be > changed (including deletion!) even while you have the file open. FWIW that's true even on Windows. (Although arguably less common). > I'm not sure what problem you're trying to solve, but I'm afraid your > approach is at least limited. Depends on what the requirement is. If it is, essentially: "give me at least one of the names this file had when I opened it", then this approach is surely adequate. Certainly, things could have happened in the meantime. Obviously, only the OP can know the circumstances he's dealing with, but ISTM that far and away the most common case will be that the file has exactly one name and that it hasn't changed. TJG From thorsten at thorstenkampe.de Wed May 25 03:31:33 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 25 May 2011 09:31:33 +0200 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: * Chris Angelico (Wed, 25 May 2011 08:01:38 +1000) > > On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain wrote: > > One of my favorite quotes (not sure if it was about Perl or APL) is "I > > refuse to use a programming language where the proponents of it stick > > snippets under each other's nose and say 'I bet you can't guess what > > this does.'" > > Yes, I believe that was Perl. And an amusing quote. But most of the > point of it comes from the fact that Perl uses punctuation for most of > its keywords, whereas (say) Python uses English words; it's a lot more > fun to crunch something down when you can use $| and friends than when > you have to put "x and y", complete with spaces, for a simple boolean. > But that says nothing about which language is actually better for > working with... [...] It does say something about readibility. And yes, "readability counts". And yes, readability says a lot about how good a language is for reading and working with. Thorsten From nospam at torek.net Wed May 25 03:37:51 2011 From: nospam at torek.net (Chris Torek) Date: 25 May 2011 07:37:51 GMT Subject: Code Review References: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> Message-ID: In article <37ba7b40-3663-4094-b507-696fc598bf48 at l26g2000yqm.googlegroups.com> ad wrote: >Please review the code pasted below. I am wondering what other ways >there are of performing the same tasks. ... I imagine one enhancement >would be to create a function out of some of this. Indeed -- "recommended styles" include defining a main() function and calling main at the bottom, e.g., with: if __name__ == '__main__': main() or: if __name__ == '__main__': main(sys.argv) Something has also double-spaced your code; I will undo that below. >import os >import time >import shutil >import argparse So far so good. Let me start by putting the next parts into main(). I will use the no-argument format since we can simply let parser.parse_args() fetch sys.argv the same way you did (we could def main(argv) and pass argv; this is sometimes useful for testing purposes, but here it makes little difference one way or another). def main(): > CurrentTime = time.time() > epocDay = 86400 # seconds (You could write 24 * 60 * 60, but again this is sort of a six-of-one half-a-dozen-of-the-other situation.) What is not clear is why you are setting these now, rather than later, closer to where they are going to be used. Many style guides, including Guido's and pylint's, dislike UppercaseVariableName and camelCase style names within functions. (UppercaseNames are reserved to classes.) I am leaving these alone for now though. > parser = argparse.ArgumentParser(description = "Delete files and > folders in a directory N days old", add_help=False, > prog='directorycleaner', usage='%(prog)s 7 c:\\temp') Line wrap has done bad things to this. Still, there is something odd about it other than the line wrap: - sometimes you write: param_name = value but sometimes you use: param_name=value and in one case you even use both: usage= [string] - you switch back and forth between single and double quoted strings, without much reason. Consistency is not *required* but it is generally a good idea. (This is also minor, like deciding between 86400 or 24*60*60. Eventually, though, lots of minor things add up.) (I have to admit here that I tend to switch back and forth on quotes too. :-) ) Another "sixes" case occurs here with the backslashes: to get a literal backslash in a string, you can use "raw strings". Here it makes no difference but I will go ahead and do it just for illustration: parser = argparse.ArgumentParser( description='Delete files and folders in a directory N days old', add_help=False, prog='directorycleaner', usage=r'%(prog)s 7 c:\temp') Finally, I am not sure why you do not want to allow a -h / --help option (but if you take out the add_help=False, it's probably best to take out the call to parser.print_help() too), and there is no need to supply a usage= argument at all -- argparse() will build one for you. > parser.add_argument('days', type=int, help="Numeric value: delete > files and folders older then N days") > parser.add_argument('directory', help="delete files and folders in > this directory") (Again, line wrap has broken these; the fixes are obvious so I skip over them here.) > parser.print_help() > args = parser.parse_args() (So far so good, although again, you probably want to remove the call to print_help() if you allow argparse to add a -h / --help option, at least.) > dictKeys = (vars(args)) There is no *need* to do this, although it is documented as allowed. I prefer to just use args. myself: > HowManyDays = dictKeys['days'] > WhatDirectory = dictKeys['directory'] so this would become: HowManyDays = args.days WhatDirectory = args.directory > print (HowManyDays) > print (WhatDirectory) These are presumably debug statements and should be removed, but until then, it might be good to prefix the output with what is being printed (i.e., a debug message). (I have taken them out of my copy, for output shown below.) (In a fancier program, you could use the logging module and logging.debug().) > DaysToDelete = HowManyDays * epocDay Right before this would be a good place to create epocDay. > dirExists = os.path.exists(WhatDirectory) > if dirExists == False: print ("The directory is missing") An explicit "if expr == False" is generally a bad idea -- if an expression can be "considered boolean" (and the return value of os.path.exists certainly can), just write "if not expr". Most style guides suggest putting subsequent statements on new lines, rather than right after the ":". Checking that the directory exists seems reasonable enough. However, after printing that it does not, you continue on with code that is going to immediately raise an OSError exception: > DirListing = os.listdir(WhatDirectory) In general, it is better to try to do the operation, and catch the failure and do something about it at that point, than to test to see if the operation is going to succeed. (Among other things, this avoids a "race" between program 1 that says "does some directory exist" and program 2 that says "delete the directory". If program 1 "wins" this race, the directory does exist at the point of the test, then program 2 deletes it, then program 1 goes on to access the now-deleted directory ... and crashes.) I am using a Unix-like system so what I get may not be quite the same as what you would get on a Windows-like system, but: % cd /tmp % python foo.py 1 /tmp/nosuchdir The directory is missing Traceback (most recent call last): ... OSError: [Errno 2] No such file or directory: '/tmp/nosuchdir' % More significantly, consider this: % python foo.py 1 /tmp/foo.py Traceback (most recent call last): ... OSError: [Errno 20] Not a directory: '/tmp/foo.py' % So instead of the three previous lines, consider: try: DirListing = os.listdir(WhatDirectory) except OSError as err: sys.exit("can't read %s: %s" % (WhatDirectory, err)) (you will need to "import sys", and I am using an older version of Python and the "except OSError, err" syntax, but the effect is the same). Now the second example results in: % python foo.py 1 /tmp/foo.py can't read /tmp/foo.py: [Errno 20] Not a directory: '/tmp/foo.py' % > for files in DirListing: > # Get the absolute path of the file name > abspath = (os.path.join(WhatDirectory, files)) This is not necessarily an absolute path -- for instance, if the program is run as: python foo.py 7 rel\ative\path the joined file names (on a Windows-like system) will be things like "rel\ative\path\file.txt" and so on. I would suggest shortening the variable name to just "path". The outermost set of parentheses are unnecessary, too. > # Get the current creation time of the file in epoc format > # (midnight 1/1/1970) > FileCreationTime = (os.path.getctime(abspath)) Beware: on Unix-like systems, this gets a "time of last change" rather than a "time of create". Even if you are sure you will use Windows you may wish to use the file's mtime (time of last "modification"; on Unix-like systems, the distinction between a "modification" and a "change" is that "change" covers alterations to the file's meta-data as well as the data, e.g., "chmod a-w file", making it read-only, changes its ctime but not its mtime, while "echo foo >> file" changes both its ctime and its mtime -- provided it is not read-only, of course :-) ). Again, the outermost parentheses here are unnecessary. > # time.ctime converts epoch to a normal date > #print (time.ctime(CurrentTime)) > # Get the date from seven days ago > WeekOldFileDate = CurrentTime - DaysToDelete > #print (CurrentTime) > #print (FileCreationTime) > #print (WeekOldFileDate) > > #If the file is older than seve days doe something Apparently, the program has evolved somewhat: originally you had "seven days" hardcoded, now you have a variable number. The comments, however, have not changed -- and the final variable name is no longer appropriate. It is probably also time to ditch the commented-out debug print statements (and fix the comments, including the typo on the last one above). > if FileCreationTime < WeekOldFileDate: > #check if the object is a file > if os.path.isfile(abspath): os.remove(abspath) > # It is not a file it is a directory > elif os.path.isdir(abspath): shutil.rmtree(abspath) Again, the comment and code do not quite agree: the comment says "if it is not a file it *is* a directory" but the code says "if it is not a file, check to see if it is a directory", which leaves open the possibility that it is some other kind of entity (this is definitely possible on a Unix-like system, where it could be a socket, symbolic link, or device node, for instance). In this particular program, written the way it is, there is no actual benefit (yet) to doing this, but I suggest moving the guts of the "clean out a directory" process into a function. What this allows is the ability to list more than one directory, provided of course you also change the argument parser a bit. Having put this all together (and neutered the actual file-or-directory removing code) gives me the code below. There are still plenty of things you could do with it -- for instance, exiting partway through processing a list of directories if one in the middle does not exist is perhaps not optimal: % python foo.py 7 /tmp/dir1 /tmp/oops /tmp/dir2 (where /tmp/dir1 and /tmp/dir2 do exist, but /tmp/oops does not) will clean out /tmp/dir1 but then exit without ever processing /tmp/dir2. (There are lots of ways to handle this; you would have to choose one and implement it.) Or, instead of the kind of processing done here, you could generalize it into a Unix-like "find" command. (Perhaps with a less-ugly syntax. :-) ) The "find" command can do what this script does: find DIRLIST -ctime +N ( -type d -o -type f ) -exec rm -rf {} \; but can also a great deal more since (a) it has many other options than just -ctime, and (b) -exec will execute any arbitrary command. --------------------------- import os import time import shutil import argparse import sys def main(): """ main program: parse arguments, and clean out directories. """ parser = argparse.ArgumentParser( description="Delete files and folders in a directory N days old", prog="directorycleaner") parser.add_argument("days", type=int, help="Numeric value: delete files and folders older than N days") parser.add_argument("directory", nargs="+", help="delete files and folders in this directory") args = parser.parse_args() for dirname in args.directory: clean_dir(dirname, args.days) def clean_dir(dirname, n_days): """ Clean one directory of files / subdirectories older than the given number of days. """ time_to_live = n_days * 86400 # 86400 = seconds-per-day current_time = time.time() try: contents = os.listdir(dirname) except OSError, err: sys.exit("can't read %s: %s" % (dirname, err)) for filename in contents: # Get the path of the file name path = os.path.join(dirname, filename) # Get the creation time of the file # NOTE: this only works on Windows-like systems when_created = os.path.getctime(path) # If the file/directory has expired, remove it if when_created + time_to_live < current_time: if os.path.isfile(path): print "os.remove(%s)" % path # It is not a file it is a directory elif os.path.isdir(path): print "shutil.rmtree(%s)" % path if __name__ == "__main__": main() -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From shobadevi75 at gmail.com Wed May 25 03:40:50 2011 From: shobadevi75 at gmail.com (shoba kasthuri) Date: Wed, 25 May 2011 00:40:50 -0700 (PDT) Subject: BEST WAY TO EARN DOLLARS FROM COMPANY JUST SUBSCRIBE AND SEE , JOIN NOW Message-ID: <2f426438-5f64-4c92-af0a-64dae01b3bce@l14g2000pro.googlegroups.com> shoba.1915 at rediffmail.com From xahlee at gmail.com Wed May 25 03:51:47 2011 From: xahlee at gmail.com (Xah Lee) Date: Wed, 25 May 2011 00:51:47 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <84d8a4d0-d3ca-474c-9f25-8198804e1972@18g2000prd.googlegroups.com> On May 25, 12:26?am, Thorsten Kampe wrote: > * Rikishi42 (Wed, 25 May 2011 00:06:06 +0200) > > > > > > > > > > > > > On 2011-05-24, Steven D'Aprano wrote: > > >>> I think that is a patronizing remark that under-estimates the > > >>> intelligence of lay people and over-estimates the difficulty of > > >>> understanding recursion. > > > >> Why would you presume this to be related to intelligence? The point was > > >> not about being *able* to understand, but about *needing* to understand > > >> in order to use. > > > > Maybe they don't "need" to understand recursion. So what? > > > I think you should read the earlier posts again, this is drifting so far > > from what I intended. > > > What I mean is: I'm certain that over the years I've had more than one > > person come to me and ask what 'Do you wish to delete this directory > > recursively?' meant. BAut never have I been asked to explain what 'Do you > > wish to delete this directory and it's subdirs/with all it's contents?' > > meant. Never. > > Naming something in the terms of its implementation details (in this > case recursion) is a classical WTF. > > On the other hand, it's by far not the only WTF in Unix. For instance, > how often have you read "unlink" instead of "delete"? Or "directory" > instead of "folder", pointing out that "directory" is the correct term > because a directory is just a listing and does not "contain" the actual > files. Of course these implementation details will never matter to > anyone except under the rarest conditions. > > Thorsten well said. half of posts in this thread are from idiots. just incredible, but again, its newsgroups ... what am i thinking ... Xah From rosuav at gmail.com Wed May 25 03:59:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 17:59:24 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <84d8a4d0-d3ca-474c-9f25-8198804e1972@18g2000prd.googlegroups.com> References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <84d8a4d0-d3ca-474c-9f25-8198804e1972@18g2000prd.googlegroups.com> Message-ID: On Wed, May 25, 2011 at 5:51 PM, Xah Lee wrote: > well said. > > half of posts in this thread are from idiots. just incredible, but > again, its newsgroups ... what am i thinking ... > > ?Xah > Thank you. As soon as we figure out which half of us you just publicly insulted, we'll see about getting offended. Until then, thank you for your contribution and please, have a nice day. Chris Angelico removing tongue from cheek From ulrich.eckhardt at dominolaser.com Wed May 25 04:06:39 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 25 May 2011 10:06:39 +0200 Subject: Code Review References: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> Message-ID: ad wrote: > Please review the code pasted below. I am wondering what other ways > there are of performing the same tasks. On a unix system, you would call "find" with according arguments and then handle the found files with "-exec rm ..." or something like that, but I see you are on MS Windows. > args = parser.parse_args() > > dictKeys = (vars(args)) The first of these looks okay, while I don't get the additional brackets in the second one. Another habit I observe here is the Hungarian notation of prefixing the type to the name and using camelCaps. PEP 8 (IIRC) has something to say on the preferred naming. I'm not 100% against encoding the type in the variable name in Python, since it lacks static type checking, I would have chosen "key_dict" here though, or, due to the small size of the overall program just "keys". > print (HowManyDays) This puzzled me at first, again the useless additional brackets I thought. However, in Python 3, "print" is a function, so that is correct. Still, it should be "print(foo)" not "print (foo)". > for files in DirListing: > > # Get the absolute path of the file name > abspath = (os.path.join(WhatDirectory, files)) "files" is just the name of a single file, right? In that case the name is a bit confusing. > # Get the date from seven days ago > WeekOldFileDate = CurrentTime - DaysToDelete You are repeating this calculation for every file in the loop. > if FileCreationTime < WeekOldFileDate: > #check if the object is a file > if os.path.isfile(abspath): os.remove(abspath) > # It is not a file it is a directory > elif os.path.isdir(abspath): shutil.rmtree(abspath) I'm not sure, but I believe you could use shutil.rmtree() for both files and directories. In any case, be prepared for the file still being open or otherwise read-only, i.e. for having to handle errors. Also, what if a directory is old but the content is new? Would this cause the non-old content to be deleted? Cheers! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From affdfsdfdsfsd at b.com Wed May 25 04:18:48 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: Wed, 25 May 2011 10:18:48 +0200 Subject: pyGTK identify a button Message-ID: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Hi all, i'm trying to write a simple windows with two button in GTK, i need a way to identify wich button is pressed. Consider that: the two button are connected (when clicked) to infoButton(self, widget, data=None) infoButton() is something like this infoButton(self, widget, data=None): # discover wich button was pressed ... # say hello to the button if button1pressed: print "Hi, button1!" else: print "Hi, button2!" so, how can I know wich button was pressed without using data and without reading the label of the button (i could have buttons with the same label) If data is needed, can someone pls tell me how to set it properly in glade 3.8 thanks Nico From claudiu at virtuamagic.com Wed May 25 04:20:45 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Wed, 25 May 2011 11:20:45 +0300 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: <4DDCAD12.4050203@timgolden.me.uk> References: <201105242318.32306.claudiu@virtuamagic.com> <4DDCAD12.4050203@timgolden.me.uk> Message-ID: <201105251120.47996.claudiu@virtuamagic.com> > There used to be a problem with subprocess fds being held by > a traceback. IIRC, the problem could be triggered by having > an except clause around a subprocess call within which something > attempted to, eg, > remove one of the affected files. I have no subprocess call.. in this last issue. And I didn't triggered one (disabled the Button that runs the subprocess). try: for line in t.splitlines(): [...] ret = self.downloadFileToDisk(filename, do_rename) if not ret: print "DEBUG: Problema la download" raise Exception() (1) except Exception as inst: print type(inst) print inst.args self.updateText.emit("EROARE: Eroare la descarcare") self.updateStatusBar.emit("EROARE: Eroare la descaracare fisiere") return Where downloadFileToDisk(): def downloadFileToDisk(self, filename, final_rename=True): dfilename = os.path.join(saveBasePATH, filename) sfilename = dfilename + ".part" dfolder = os.path.dirname(sfilename) if dfolder != "": if not os.path.isdir(dfolder): os.makedirs(dfolder) try: fp = open(sfilename, "wb") except: return False curl = pycurl.Curl() curl.setopt(pycurl.URL, baseUpdateURL + "/client/" + filename) curl.setopt(pycurl.CONNECTTIMEOUT, 30) curl.setopt(pycurl.NOPROGRESS, 0) curl.setopt(pycurl.FOLLOWLOCATION, 1) curl.setopt(pycurl.MAXREDIRS, 5) curl.setopt(pycurl.PROGRESSFUNCTION, self.updateFileProgress) curl.setopt(pycurl.WRITEDATA, fp) curl.setopt(pycurl.BUFFERSIZE, 4194304) curl.setopt(pycurl.NOSIGNAL, 1) curl.perform() retcode = curl.getinfo(pycurl.HTTP_CODE) curl.close() fp.close() if retcode != 200: (2) os.unlink(sfilename) return False self.msleep(10) if final_rename: os.rename(sfilename, dfilename) return True Without self.msleep(10), (1) catches WindowsError: file access ... blah blah. Maybe at (2) can be an access violation, but it wasn't triggered yet in tests. I will move the sleep after fp.close(). Yes, I know that what it've done with raise Exception() is UGLY, since this program it's more a quick hack solution to a problem :). Anyway the Exception that is catched is not rised by my code (it's a WindowsError). > I'm sorry if that's a bit > of a woolly description but if you think this might be > biting you I'll dive in and look at the code. What version > of Python are you using? Last 2.7.x. Well, if os.rename is instead a subprocess call, then it's subprocess based. I'm new to Python but 99% I think it's a system call :) > (That said, the fact that the behaviour varies between faster > and slower computers makes that cause unlikely. Maybe we're > back to looking at virus checkers and the like...) On that virtual machine there is no virus checker. On the faster machine I disabled and closed the antivirus. -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From claudiu at virtuamagic.com Wed May 25 04:44:12 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Wed, 25 May 2011 11:44:12 +0300 Subject: pyGTK identify a button In-Reply-To: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Message-ID: <201105251144.15257.claudiu@virtuamagic.com> > the two button are connected (when clicked) to infoButton(self, > widget, > data=None) From documentation: handler_id = object.connect(name, func, func_data) So: button1.connect(when is pressed, your_function, 1) button2.connect(when is pressed, your_function, 2) (This code is conception, I don't really know how is done in GTK). On the callback: infoButton(self, widget, data=None): # discover wich button was pressed ... # say hello to the button if data == 1: print "Hi, button1!" else: print "Hi, button2!" -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From gagsl-py2 at yahoo.com.ar Wed May 25 04:50:44 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 May 2011 05:50:44 -0300 Subject: Hotshoting recursive function References: Message-ID: En Sun, 22 May 2011 10:42:08 -0300, Selvam escribi?: > I am using hotshot module to profile my python function. > > I used the details from ( > http://code.activestate.com/recipes/576656-quick-python-profiling-with-hotshot/ > ). > > The function I profile is a recursive one and I am getting the following > error, > > "ProfilerError: profiler already active" > > I guess this is due to the recursive call to the profiling function. > > I would like to get some suggestions. The recursive call inside your function should call the undecorated function, not the decorated function again. Decorator syntax is not convenient anymore. Using the same names as in the recipe example: # a recursive function def my_slow_function(n): ... return my_slow_function(n-1) my_profiled_slow_function = hotshotit(my_slow_function) my_profiled_slow_function(n) This works, in the sense that it does not raise ProfileError anymore. Interpreting profile data is up to you... -- Gabriel Genellina From affdfsdfdsfsd at b.com Wed May 25 04:51:50 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: Wed, 25 May 2011 10:51:50 +0200 Subject: pyGTK identify a button In-Reply-To: References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Message-ID: <4ddcc326$0$18248$4fafbaef@reader2.news.tin.it> On 25/05/2011 10:44, Claudiu Nicolaie CISMARU wrote: >> the two button are connected (when clicked) to infoButton(self, >> widget, >> data=None) > > From documentation: > handler_id = object.connect(name, func, func_data) > > So: > > button1.connect(when is pressed, your_function, 1) > button2.connect(when is pressed, your_function, 2) > (This code is conception, I don't really know how is done in GTK). thanks but, as i've sayed before, i can't use func_data 'cause i don't know how to set it on glade3.8, that is the program i use to create the GUI. Anyway, i think this is the only way to identify the button :-/ From rosuav at gmail.com Wed May 25 04:53:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 18:53:20 +1000 Subject: Link errors embedding Python 3.2 In-Reply-To: References: Message-ID: Followup. I'm now using Python 3.3 straight from Mercurial, and am seeing the same issues. I've managed to get the compilation step to succeed by naming the library for full inclusion and adding -lutil -ldl (sounding rather Donizetti there), and my program runs. However, it's unable to import all its modules. I can happily import re, string, and sys, but importing math or time results in an ImportError citing "undefined symbol: PyExc_ValueError". I think there's still something I'm mucking up in the link process. The exception is ImportError, with text: '/usr/local/lib/python3.3/lib-dynload/time.cpython-33m.so: undefined symbol: PyExc_ValueError' Any ideas? Chris Angelico From rosuav at gmail.com Wed May 25 04:58:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 18:58:16 +1000 Subject: pyGTK identify a button In-Reply-To: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Message-ID: On Wed, May 25, 2011 at 6:18 PM, Tracubik wrote: > Hi all, > i'm trying to write a simple windows with two button in GTK, i need a way to > identify wich button is pressed. > Consider that: > > the two button are connected (when clicked) to infoButton(self, widget, > data=None) I'm not terribly familiar with GTK, but I believe the 'widget' parameter is the button that was clicked on. Whatever means you have for distinguishing them (saving another reference to each object in a named variable, etc), you should be able to do with that parameter. Chris Angelico From claudiu at virtuamagic.com Wed May 25 05:19:00 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Wed, 25 May 2011 12:19:00 +0300 Subject: pyGTK identify a button In-Reply-To: <4ddcc326$0$18248$4fafbaef@reader2.news.tin.it> References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> <4ddcc326$0$18248$4fafbaef@reader2.news.tin.it> Message-ID: <201105251219.02700.claudiu@virtuamagic.com> > thanks but, as i've sayed before, i can't use func_data 'cause i don't > know how to set it on glade3.8, that is the program i use to create > the > GUI. > Anyway, i think this is the only way to identify the button :-/ Hack into the generated source! -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From jeanmichel at sequans.com Wed May 25 05:22:52 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 25 May 2011 11:22:52 +0200 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> Message-ID: <4DDCCA6C.5020204@sequans.com> Lew Schwartz wrote: > So, if I read between the lines correctly, you recommend Python 3? > Does the windows version install with a development environment? If you want to use python 3, make sure before that all the good stuff you need (==modules) have been ported to python 3. If you are a complete beginner, I would advise python 2.7. JM From gagsl-py2 at yahoo.com.ar Wed May 25 05:45:17 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 May 2011 06:45:17 -0300 Subject: pexpect: TIMEOUT no longer clears child.before References: Message-ID: En Thu, 19 May 2011 08:29:21 -0300, Adrian Casey escribi?: > The behaviour of pexpect has changed between version 2.1 and 2.3. In > version 2.1, the following code would result in child.before being > cleared -: > > >>>child.expect(pexpect.TIMEOUT,1) > In version 2.3, this is no longer the case. No matter how many times > the above code is run, child.before continues to hold the output from > previous commands. It is important to be able to clear the contents of > child.before between each command. What is the correct way to do this > in version 2.3? Try contacting the author: www.noah.org -- Gabriel Genellina From srini605 at gmail.com Wed May 25 06:03:03 2011 From: srini605 at gmail.com (srinivasan munisamy) Date: Wed, 25 May 2011 15:33:03 +0530 Subject: [pyodbc] Setting values to SQL_* constants while creating a connection Message-ID: Hi, I would like to know how to set values to values to SQL_* constants while creating a db connection through pyodbc module. For example, i am getting a connection object like below: In [27]: dbh1 = pyodbc.connect("DSN=;UID= ;PWD=;DATABASE=;APP=") In [28]: dbh1.getinfo(pyodbc.SQL_DESCRIBE_PARAMETER) Out[28]: True I want to set this SQL_DESCRIBE_PARAMETER to false for this connection object. How could i do that? Please help me in figuring it out. Thanks, Srini -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed May 25 06:15:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 10:15:53 GMT Subject: English Idiom in Unix: Directory Recursively References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: <4ddcd6d8$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 08:14:27 +1000, Chris Angelico wrote: > On Wed, May 25, 2011 at 3:40 AM, Xah Lee wrote: >> On May 23, 9:28?pm, Chris Angelico wrote: >>> Because I do not consider its behaviour to be errant. And I suspect >>> its main developers won't either. That's why I suggested you grab the >>> sources and make The Perfect Emacs. >> >> why don't you try http://ergoemacs.org/ ? > > You miss my point. I am not desiring of a different emacs; you were the > one complaining about its shortcomings. It's Xah Lee. Of course he misses your point. He refuses to stop spamming newsgroups even after being banned by his ISP, and he refuses to listen to any opinion that doesn't agree with his own. Everyone else is an idiot. -- Steven From davea at ieee.org Wed May 25 07:05:16 2011 From: davea at ieee.org (Dave Angel) Date: Wed, 25 May 2011 07:05:16 -0400 Subject: Obtaining a full path name from file In-Reply-To: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: <4DDCE26C.10305@ieee.org> On 01/-10/-28163 02:59 PM, RVince wrote: > s = "C:\AciiCsv\Gravity_Test_data\A.csv" > f = open(s,"r") > > How do I obtain the full pathname given the File, f? (which should > equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff > and am just not finding it. Any help greatly appreciated ! > I saw lots of responses, but I don't think anybody pointed out that the filename is probably invalid. This particular string will work, but if you have a directory that starts with a T or an N, you may get some surprises. The backslash is treated specially in a literal string. When building a Windows directory name in a literal string, you generally need to do one of three things: 1) use raw literals 2) double the backslash 3) use a forward slash DaveA From info at egenix.com Wed May 25 07:24:13 2011 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 25 May 2011 13:24:13 +0200 Subject: ANN: eGenix mxODBC - Python ODBC Database Interface 3.1.1 Message-ID: <4DDCE6DD.2060601@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC - Python ODBC Database Interface Version 3.1.1 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Mac OS X, Unix and BSD platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.1.1-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more: http://www.egenix.com/products/python/mxODBC/ The "eGenix mxODBC - Python ODBC Database Interface" product is a commercial extension to our open-source eGenix mx Base Distribution: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS mxODBC 3.1 Update ----------------- The mxODBC 3.1.1 patch level release adds compatibility to our new eGenix.com mx Base Distribution 3.2.0, which includes Windows x64 support. If you are currently using the combinations mxODBC 3.1.0 + mx Base 3.1.3, please consider upgrading to our latest releases mxODBC 3.1.1 + mx Base 3.2.0. Licenses for mxODBC 3.1.0 remain valid for mxODBC 3.1.1 as well. Release Highlights ------------------ * We've added Python 2.7 support and builds for all platforms. * mxODBC 3.1 adds native support for the Windows 64-bit platforms as well as the Mac OS X 10.6 (Snow Leopard) 64-bit builds of Python. * mxODBC now fully supports the Oracle Instant Client ODBC driver. * We have updated the support for the latest IBM DB2 9.7 ODBC drivers and enhanced compatibility of mxODBC with the MS SQL Server Native Client ODBC driver on Windows and the Sybase ASE 15 ODBC drivers on Unix. * mxODBC 3.1 adds support for large-scale data warehouse databases Netezza and Teradata. * In addition to the Windows, Mac OS X, iODBC and unixODBC ODBC driver managers, we now also include support for the DataDirect ODBC manager. * The 64-bit support on Unix platforms was updated to support the new unixODBC 2.3.0 version. * We've improved the documentation on how to connect to various popular databases and now include many tips & tricks for each database/driver. * The Python 2.7 memoryview object is now supported as binary data container. * We have simplified handling of database warnings using a new customizable .warningformat attribute. * The catalog methods now accept both Unicode and 8-bit strings as parameters. * You can now select whether to use ANSI (8-bit) or Unicode ODBC APIs in the ODBC drivers, removing unnecessary data conversions and enhancing ODBC driver compatibility. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html Feature Highlights ------------------ * Python Database API 2.0 Compliance: the mxODBC API is fully Python DB-API 2.0 compatible and implements a large number of powerful extensions. * Support for all popular ODBC Drivers: mxODBC includes adjustments and work-arounds to support MS SQL Server Native Client, MS SQL Server ODBC Driver, FreeTDS ODBC Driver, Oracle Instant Client ODBC Driver, IBM DB2 ODBC Driver, Sybase ASE ODBC Driver, Netezza ODBC Driver, Teradata ODBC Driver, PostgreSQL ODBC Driver, MySQL ODBC Driver, .MaxDB ODBC Driver as well as the ODBC driver sets of EasySoft, DataDirect, OpenLink, Actual Technologies. * Support for all popular ODBC Driver Managers: mxODBC comes with subpackages for the native Windows and Mac OS X ODBC managers, as well as the ODBC managers unixODBC, iODBC and DataDirect, which are commonly used on Unix systems. * Stable, robust and reliable:the mxODBC API has been in active production use for more than 10 years. * Full Python Support: mxODBC works with Python 2.4, 2.5, 2.6 and 2.7. * Full 64-bit Support: mxODBC runs on the following 64-bit platforms: Windows, Linux, FreeBSD and Mac OS X. For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features New mxODBC Editions ------------------- Due to popular demand, we have extended the set of available mxODBC editions and included a new low-cost standard edition. mxODBC is now available in thesethree editions: * The low-cost Standard Edition which provides data connectivity to a selected set of database backends. * The Professional Edition, which gives full access to all mxODBC features. * The Product Development Edition, which allows including mxODBC in applications you develop. At the same time we have simplified our license terms to clarify the situation on multi-core and virtual machines. In most cases, you no longer need to purchase more than one license per processor or virtual machine, scaling down the overall license costs significantly compared to earlier mxODBC releases. For a complete overview of the new editions, please see the product page. http://www.egenix.com/products/python/mxODBC/#mxODBCEditions ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC release to benefit from the new features and updated ODBC driver support. We have taken special care, not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. Customers who have purchased mxODBC 3.1 license can continue to use their licenses with this patch level release. Customers who have purchased mxODBC 2.0, 2.1 or 3.0 licenses can upgrade their licenses using the mxODBC Professional Edition Upgrade License. If you want to try the new release before purchace, you can request 30-day evaluation licenses by visiting our web-site http://www.egenix.com/products/python/mxODBC/#Evaluation or by writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, May 25 2011) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2011-05-23: Released eGenix mx Base 3.2.0 http://python.egenix.com/ 2011-05-25: Released mxODBC 3.1.1 http://python.egenix.com/ 2011-06-20: EuroPython 2011, Florence, Italy 26 days to go ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From roy at panix.com Wed May 25 07:36:40 2011 From: roy at panix.com (Roy Smith) Date: Wed, 25 May 2011 07:36:40 -0400 Subject: Why did Quora choose Python for its development? References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: In article , Dennis Lee Bieber wrote: > On Tue, 24 May 2011 13:39:02 -0400, "D'Arcy J.M. Cain" > declaimed the following in gmane.comp.python.general: > > > > My point was that even proponents of the language can make a > > significant error based on the way the variable is named. It's like > > the old Fortran IV that I first learned where the name of the variable > > determined whether it was an integer or a floating point. > > > Only if one didn't declare the type ahead of time... > > And even then it wasn't that hard to remember (using a non-PC > mnemonic): Indian's are integer (variables starting I to N inclusive > were integers) Remembering that I, J, K, L, M, and N were integer was trivial if you came from a math background. And, of course, Fortran was all about math, so that was natural. Those letters are commonly used for integers in formulae. If I write $ x sub i $, anybody who knows math would immediately assume that the range of x was reals and the range of i was integers. From rosuav at gmail.com Wed May 25 07:55:10 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 21:55:10 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: On Wed, May 25, 2011 at 9:36 PM, Roy Smith wrote: > Remembering that I, J, K, L, M, and N were integer was trivial if you > came from a math background. ?And, of course, Fortran was all about > math, so that was natural. ?Those letters are commonly used for integers > in formulae. ?If I write $ x sub i $, anybody who knows math would > immediately assume that the range of x was reals and the range of i was > integers. When I studied maths, x and y were reals, and i wasn't. But it wasn't integer either... :) Chris Angelico From john at castleamber.com Wed May 25 07:58:28 2011 From: john at castleamber.com (John Bokma) Date: Wed, 25 May 2011 06:58:28 -0500 Subject: Why did Quora choose Python for its development? References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <20110524060535.64cfa0ec.darcy@druid.net> Message-ID: <87zkmbyot7.fsf@castleamber.com> Dennis Lee Bieber writes: > Python books than after six months of trying to understand PERL... And Perl is the language, and perl is what runs Perl. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From john at castleamber.com Wed May 25 08:01:07 2011 From: john at castleamber.com (John Bokma) Date: Wed, 25 May 2011 07:01:07 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: <87vcwzyoos.fsf@castleamber.com> Thorsten Kampe writes: > * Chris Angelico (Wed, 25 May 2011 08:01:38 +1000) >> >> On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain wrote: >> > One of my favorite quotes (not sure if it was about Perl or APL) is > "I >> > refuse to use a programming language where the proponents of it stick >> > snippets under each other's nose and say 'I bet you can't guess what >> > this does.'" >> >> Yes, I believe that was Perl. And an amusing quote. But most of the >> point of it comes from the fact that Perl uses punctuation for most of >> its keywords, whereas (say) Python uses English words; it's a lot more >> fun to crunch something down when you can use $| and friends than when >> you have to put "x and y", complete with spaces, for a simple boolean. >> But that says nothing about which language is actually better for >> working with... [...] > > It does say something about readibility. And yes, "readability counts". > And yes, readability says a lot about how good a language is for reading > and working with. To people used to the latin alphabet languages using a different script are unreadable. So readability has a lot to do with what one is used to. Like I already stated before: if Python is really so much better than Python readability wise, why do I have such a hard time dropping Perl and moving on? -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From erichcart at gmail.com Wed May 25 08:16:40 2011 From: erichcart at gmail.com (ErichCart ErichCart) Date: Wed, 25 May 2011 05:16:40 -0700 (PDT) Subject: Unable to make ironpython run in browser with silverlight Message-ID: <715e82a9-3761-4d82-9df4-1c5f39633160@h36g2000pro.googlegroups.com> Basically i am following this tutorial: http://blog.jimmy.schementi.com/2010/03/pycon-2010-python-in-browser.html According to it, this code should run fine: And in fact, it does, for example here: http://ironpython.net/browser/examples/pycon2010/start.html You will see it if you have silverlight installed. But the problem is that when I try to make the same code run on my PC, I can't do it. I create a text file, copy this code there, save it as test.html, and run with firefox, but nothing happens. Code does not execute, i just get a blank page. I can't understand the reason why the same code runs here: http://ironpython.net/browser/examples/pycon2010/start.html, but not on my PC, given that it is a client side code, and not the server side. And there is nothing written in firefox error console, when I run it locally. But if I host it on my webhosting account, then I get this error: Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http:// sitename .com/silverlighttest.html :: DLR_DownloadResource :: line 15" data: no] I uploaded the html file I am using here: http://www.filedropper.com/silverlighttest But it just a text file with that code with extension changed to .html. What can I do? From brightstarvijay at gmail.com Wed May 25 08:16:53 2011 From: brightstarvijay at gmail.com (Vijayakumar Vijayakumar) Date: Wed, 25 May 2011 05:16:53 -0700 (PDT) Subject: ghret Message-ID: website --> www.srilakshmi.info From brightstarvijay at gmail.com Wed May 25 08:21:02 2011 From: brightstarvijay at gmail.com (Vijayakumar Vijayakumar) Date: Wed, 25 May 2011 05:21:02 -0700 (PDT) Subject: ghraic Message-ID: <318a042b-d342-425e-ada1-7cbe409c2bcd@z13g2000prk.googlegroups.com> website --> www.srilakshmi.info From brightstarvijay at gmail.com Wed May 25 08:24:08 2011 From: brightstarvijay at gmail.com (Vijayakumar Vijayakumar) Date: Wed, 25 May 2011 05:24:08 -0700 (PDT) Subject: mresh Message-ID: <11ea43f0-81f6-4032-8153-edb4732502c5@q12g2000prb.googlegroups.com> website --> www.srilakshmi.infoinyohyou From roy at panix.com Wed May 25 08:25:09 2011 From: roy at panix.com (Roy Smith) Date: Wed, 25 May 2011 08:25:09 -0400 Subject: Why did Quora choose Python for its development? References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: In article , Chris Angelico wrote: > On Wed, May 25, 2011 at 9:36 PM, Roy Smith wrote: > > Remembering that I, J, K, L, M, and N were integer was trivial if you > > came from a math background. ?And, of course, Fortran was all about > > math, so that was natural. ?Those letters are commonly used for integers > > in formulae. ?If I write $ x sub i $, anybody who knows math would > > immediately assume that the range of x was reals and the range of i was > > integers. > > When I studied maths, x and y were reals, and i wasn't. But it wasn't > integer either... :) I was talking of i in the context of a variable, not as a constant. If I write $ 3 + 7i $ in one place and $ x sub i $ in another, most people will figure out from the context which is which. From brightstarvijay at gmail.com Wed May 25 08:28:04 2011 From: brightstarvijay at gmail.com (Vijayakumar Vijayakumar) Date: Wed, 25 May 2011 05:28:04 -0700 (PDT) Subject: trep Message-ID: website --> www.srilakshmi.info From cjw at ncf.ca Wed May 25 08:57:50 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Wed, 25 May 2011 08:57:50 -0400 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> Message-ID: On 25-May-11 02:22 AM, Lew Schwartz wrote: > So, if I read between the lines correctly, you recommend Python 3? Does > the windows version install with a development environment? > It would be safer to stick with Python 2.7 initially and then consider the transition to 3.2 later. No, there is not more than Idle. PyScripter provides an excellent development environment. See: http://en.wikipedia.org/wiki/PyScripter Colin W. From msarro at gmail.com Wed May 25 09:06:02 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 25 May 2011 09:06:02 -0400 Subject: Newbie string questions Message-ID: Hey everyone, This is a super noob question, so please be gentle. I am working my way through "Learn Python the Hard Way" using both python 2.7 and python 3.1 (I want to get a handle on the differences between the two - the intention to write things in python 3 but be able to understand things from python 2). The first quarter or so of the book details lots of stuff about strings. Most of the learning is by doing, with less of an emphasis on the theory behind what certain things actually do. The issue is, I can't seem to find some of the items in the documentation. Right now what is stumping me... what exactly does %r do? I can't find it in the documentation anywhere. -Matty From rosuav at gmail.com Wed May 25 09:09:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 23:09:45 +1000 Subject: Newbie string questions In-Reply-To: References: Message-ID: On Wed, May 25, 2011 at 11:06 PM, Matty Sarro wrote: > Right now what is stumping me... what exactly does %r do? You're talking about the formatting operator? It's like the repr function: http://docs.python.org/library/functions.html#repr Chris Angelico From chris at theguidrys.us Wed May 25 09:13:34 2011 From: chris at theguidrys.us (Chris Guidry) Date: Wed, 25 May 2011 06:13:34 -0700 (PDT) Subject: Newbie string questions In-Reply-To: Message-ID: <997e06dd-55dc-4b45-9ff2-97f24dd49908@glegroupsg2000goo.googlegroups.com> On Wednesday, May 25, 2011 9:06:02 AM UTC-4, Matty Sarro wrote: > can't seem to find some of the items in the documentation. Right now > what is stumping me... what exactly does %r do? I can't find it in the > documentation anywhere. Matty, %r in a format string is very much like %s. %s calls str(your_object) in order to produce the resulting string. %r calls repr(your_object). Generally, you'd want to use %s for strings that will surface to a user, while %r is great for debugging and logging. Also, if you haven't come across repr(), you should be able to find that in the docs; it's also considered good practice to overload repr() in your own classes in order to provide a useful representation for your objects. From chris at theguidrys.us Wed May 25 09:13:34 2011 From: chris at theguidrys.us (Chris Guidry) Date: Wed, 25 May 2011 06:13:34 -0700 (PDT) Subject: Newbie string questions In-Reply-To: Message-ID: <997e06dd-55dc-4b45-9ff2-97f24dd49908@glegroupsg2000goo.googlegroups.com> On Wednesday, May 25, 2011 9:06:02 AM UTC-4, Matty Sarro wrote: > can't seem to find some of the items in the documentation. Right now > what is stumping me... what exactly does %r do? I can't find it in the > documentation anywhere. Matty, %r in a format string is very much like %s. %s calls str(your_object) in order to produce the resulting string. %r calls repr(your_object). Generally, you'd want to use %s for strings that will surface to a user, while %r is great for debugging and logging. Also, if you haven't come across repr(), you should be able to find that in the docs; it's also considered good practice to overload repr() in your own classes in order to provide a useful representation for your objects. From msarro at gmail.com Wed May 25 09:21:29 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 25 May 2011 09:21:29 -0400 Subject: Newbie string questions In-Reply-To: <997e06dd-55dc-4b45-9ff2-97f24dd49908@glegroupsg2000goo.googlegroups.com> References: <997e06dd-55dc-4b45-9ff2-97f24dd49908@glegroupsg2000goo.googlegroups.com> Message-ID: Thanks guys! I appreciate it. I was wondering why %r was always showing things enclosed in single-quotes. On Wed, May 25, 2011 at 9:13 AM, Chris Guidry wrote: > On Wednesday, May 25, 2011 9:06:02 AM UTC-4, Matty Sarro wrote: >> can't seem to find some of the items in the documentation. Right now >> what is stumping me... what exactly does %r do? I can't find it in the >> documentation anywhere. > > Matty, %r in a format string is very much like %s. ?%s calls str(your_object) in order to produce the resulting string. ?%r calls repr(your_object). ?Generally, you'd want to use %s for strings that will surface to a user, while %r is great for debugging and logging. > > Also, if you haven't come across repr(), you should be able to find that in the docs; it's also considered good practice to overload repr() in your own classes in order to provide a useful representation for your objects. > -- > http://mail.python.org/mailman/listinfo/python-list > From shawntahenman83562 at hotmail.com Wed May 25 09:30:19 2011 From: shawntahenman83562 at hotmail.com (Shawnta Henman) Date: Wed, 25 May 2011 09:30:19 -0400 Subject: FW: python Message-ID: python We should take a look at how this latest good fortune is going to change your lifestyle. Don't you remember all of those times I said how hard it's been just to get by? Alright you know what?, Your computer is going to be your very best pal once you try out this thing for one month's time. There's really no way in hell I'd wind up where I am these days if it all wasn't for this. You can give thanks to me soon. The couple of people I sometimes will need to deal with help to make everything far more easy on me that I couldn't have this another way. I can't wait to meet you once again and show you lots more. If you fail to build an income with this method, you're probably stupid. I'm sorry if that offends you, but I recognize you're capable and this is extremely straight forward! http://jesus21news.com Right here is the chance of your life. When you're ready to transform your way of life around, I'm going to be right here to assist. So whaddaya think, python, think you're prepared for a change? -------------- next part -------------- An HTML attachment was scrubbed... URL: From erichcart at gmail.com Wed May 25 09:33:45 2011 From: erichcart at gmail.com (ErichCart ErichCart) Date: Wed, 25 May 2011 06:33:45 -0700 (PDT) Subject: Unable to make ironpython run in browser with silverlight References: <715e82a9-3761-4d82-9df4-1c5f39633160@h36g2000pro.googlegroups.com> Message-ID: Here is how it looks on free webhosting account: http://silverlighttest.zzl.org/silverlighttest.html It is supposed to show a window with "Hello from python", but it shows smth else completely. From adsquaired at gmail.com Wed May 25 09:44:47 2011 From: adsquaired at gmail.com (ad) Date: Wed, 25 May 2011 06:44:47 -0700 (PDT) Subject: Code Review References: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> Message-ID: <072d3db3-82fe-4520-a520-db7ac5312edd@l14g2000pro.googlegroups.com> On May 25, 4:06?am, Ulrich Eckhardt wrote: > ad wrote: > > Please review the code pasted below. I am wondering what other ways > > there are of performing the same tasks. > > On a unix system, you would call "find" with according arguments and then > handle the found files with "-exec rm ..." or something like that, but I see > you are on MS Windows. > > > args = parser.parse_args() > > > dictKeys = (vars(args)) > > The first of these looks okay, while I don't get the additional brackets in > the second one. Another habit I observe here is the Hungarian notation of > prefixing the type to the name and using camelCaps. PEP 8 (IIRC) has > something to say on the preferred naming. I'm not 100% against encoding the > type in the variable name in Python, since it lacks static type checking, I > would have chosen "key_dict" here though, or, due to the small size of the > overall program just "keys". > > > print (HowManyDays) > > This puzzled me at first, again the useless additional brackets I thought. > However, in Python 3, "print" is a function, so that is correct. Still, it > should be "print(foo)" not "print (foo)". > > > for files in DirListing: > > > ? ? # Get the absolute path of the file name > > ? ? abspath = (os.path.join(WhatDirectory, files)) > > "files" is just the name of a single file, right? In that case the name is a > bit confusing. > > > ? ? # Get the date from seven days ago > > ? ? WeekOldFileDate = CurrentTime - DaysToDelete > > You are repeating this calculation for every file in the loop. > > > ? ? if FileCreationTime < WeekOldFileDate: > > ? ? ? ? #check if the object is a file > > ? ? ? ? if os.path.isfile(abspath): os.remove(abspath) > > ? ? ? ? # It is not a file it is a directory > > ? ? ? ? elif os.path.isdir(abspath): shutil.rmtree(abspath) > > I'm not sure, but I believe you could use shutil.rmtree() for both files and > directories. In any case, be prepared for the file still being open or > otherwise read-only, i.e. for having to handle errors. > > Also, what if a directory is old but the content is new? Would this cause > the non-old content to be deleted? > > Cheers! > > Uli > > -- > Domino Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 Thank you guys very much for the excellent points. I will use this information as a reference as I write more code and fix up the existing script. Chris, thank you for putting so much time into your post! Until we type again........... From bfocus at tznic.or.tz Wed May 25 10:15:28 2011 From: bfocus at tznic.or.tz (Bryton) Date: Wed, 25 May 2011 17:15:28 +0300 Subject: Cherrypy Message-ID: <4DDD0F00.30708@tznic.or.tz> Is anyone having a step by step tutorial of cherrypy(or book title).I have used the tutorial in their site as well as the book (cherrypy essentials) and I would like to have a one that is a bit more step by step...Please help... -- Regards, Bryton. From darcy at druid.net Wed May 25 10:23:59 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 25 May 2011 10:23:59 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: <20110525102359.eb6f4b93.darcy@druid.net> On Wed, 25 May 2011 07:36:40 -0400 Roy Smith wrote: > Remembering that I, J, K, L, M, and N were integer was trivial if you > came from a math background. And, of course, Fortran was all about The easiest way to remember was that the first two letters of INteger gave you the range. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rosuav at gmail.com Wed May 25 10:26:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 00:26:32 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <20110525102359.eb6f4b93.darcy@druid.net> References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <20110525102359.eb6f4b93.darcy@druid.net> Message-ID: On Thu, May 26, 2011 at 12:23 AM, D'Arcy J.M. Cain wrote: > The easiest way to remember was that the first two letters of INteger > gave you the range. > G for Green and R for Right, which are the first two letters of Green. (I wonder how many Pythonistas are familiar with that?) Chris Angelico From iainking at gmail.com Wed May 25 10:26:57 2011 From: iainking at gmail.com (Iain King) Date: Wed, 25 May 2011 07:26:57 -0700 (PDT) Subject: Code Review References: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> <072d3db3-82fe-4520-a520-db7ac5312edd@l14g2000pro.googlegroups.com> Message-ID: On May 25, 2:44?pm, ad wrote: > On May 25, 4:06?am, Ulrich Eckhardt > wrote: > > > > > ad wrote: > > > Please review the code pasted below. I am wondering what other ways > > > there are of performing the same tasks. > > > On a unix system, you would call "find" with according arguments and then > > handle the found files with "-exec rm ..." or something like that, but I see > > you are on MS Windows. > > > > args = parser.parse_args() > > > > dictKeys = (vars(args)) > > > The first of these looks okay, while I don't get the additional brackets in > > the second one. Another habit I observe here is the Hungarian notation of > > prefixing the type to the name and using camelCaps. PEP 8 (IIRC) has > > something to say on the preferred naming. I'm not 100% against encoding the > > type in the variable name in Python, since it lacks static type checking, I > > would have chosen "key_dict" here though, or, due to the small size of the > > overall program just "keys". > > > > print (HowManyDays) > > > This puzzled me at first, again the useless additional brackets I thought. > > However, in Python 3, "print" is a function, so that is correct. Still, it > > should be "print(foo)" not "print (foo)". > > > > for files in DirListing: > > > > ? ? # Get the absolute path of the file name > > > ? ? abspath = (os.path.join(WhatDirectory, files)) > > > "files" is just the name of a single file, right? In that case the name is a > > bit confusing. > > > > ? ? # Get the date from seven days ago > > > ? ? WeekOldFileDate = CurrentTime - DaysToDelete > > > You are repeating this calculation for every file in the loop. > > > > ? ? if FileCreationTime < WeekOldFileDate: > > > ? ? ? ? #check if the object is a file > > > ? ? ? ? if os.path.isfile(abspath): os.remove(abspath) > > > ? ? ? ? # It is not a file it is a directory > > > ? ? ? ? elif os.path.isdir(abspath): shutil.rmtree(abspath) > > > I'm not sure, but I believe you could use shutil.rmtree() for both files and > > directories. In any case, be prepared for the file still being open or > > otherwise read-only, i.e. for having to handle errors. > > > Also, what if a directory is old but the content is new? Would this cause > > the non-old content to be deleted? > > > Cheers! > > > Uli > > > -- > > Domino Laser GmbH > > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 > > Thank you guys very much for the excellent points. I will use this > information as a reference as I write more code and fix up the > existing script. > > Chris, thank you for putting so much time into your post! > > Until we type again........... Wrote something to do the same basic thing a little while ago. Less verbose than yours, and it only does files, not folders. If I was going to do folders though, I'd do them by recursing into them and pruning files, and not go by the folder modify date, which I don't think changes the way you think it changes (for example, if a file inside a folder got updated such that it shouln't be deleted it still will be with your code if the folder modify date is old [this is on Windows]) import os, glob, time, sys if len(sys.argv) < 3: print "USAGE: %s " % sys.argv[0] sys.exit(1) pattern = sys.argv[1] days = int(sys.argv[2]) threshold = days * 24 * 60 * 60 t = time.time() for f in glob.glob(pattern): if t - os.stat(f)[9] > threshold: print f os.remove(f) From steve+comp.lang.python at pearwood.info Wed May 25 10:56:11 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 14:56:11 GMT Subject: Why did Quora choose Python for its development? References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: <4ddd188b$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 10:23:59 -0400, D'Arcy J.M. Cain wrote: > On Wed, 25 May 2011 07:36:40 -0400 > Roy Smith wrote: >> Remembering that I, J, K, L, M, and N were integer was trivial if you >> came from a math background. And, of course, Fortran was all about > > The easiest way to remember was that the first two letters of INteger > gave you the range. Huh. I never knew that. I just learned from use that I, J, K, M and N were traditionally integers. I never used L for an integer variable, and don't know anyone who does. I for integer is obvious. If you need a second one, you use the next letter J, and if you need a third, the one after that, K. If you need four, you're probably doing something wrong. Likewise, N for number (as in, *counting* number). If you need two, using N and O is stupid, because O can be confused with 0, so you go backwards and use M. However, using P and Q for integers is merely arbitrary convention. -- Steven From msarro at gmail.com Wed May 25 11:40:22 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 25 May 2011 11:40:22 -0400 Subject: Kind of OT - Books on software development? Message-ID: Hey everyone, I am looking at some projects coming up, which may or may not involve python. So I figured I would throw the question out there and see what everyone thinks. I am looking for some books on software engineering/development... something that discusses techniques from ideation, up through testing, QA, production, and then maintenance. Is there such a book? -Matthew From msarro at gmail.com Wed May 25 11:43:20 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 25 May 2011 11:43:20 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <4ddd188b$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <4ddd188b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: I hate using L for anything, namely because if you type it lowercase you always have to wonder if its an l or a 1 in a terminal window. -Matthew On Wed, May 25, 2011 at 10:56 AM, Steven D'Aprano wrote: > On Wed, 25 May 2011 10:23:59 -0400, D'Arcy J.M. Cain wrote: > >> On Wed, 25 May 2011 07:36:40 -0400 >> Roy Smith wrote: >>> Remembering that I, J, K, L, M, and N were integer was trivial if you >>> came from a math background. ?And, of course, Fortran was all about >> >> The easiest way to remember was that the first two letters of INteger >> gave you the range. > > Huh. I never knew that. I just learned from use that I, J, K, M and N > were traditionally integers. I never used L for an integer variable, and > don't know anyone who does. > > I for integer is obvious. If you need a second one, you use the next > letter J, and if you need a third, the one after that, K. If you need > four, you're probably doing something wrong. > > Likewise, N for number (as in, *counting* number). If you need two, using > N and O is stupid, because O can be confused with 0, so you go backwards > and use M. > > However, using P and Q for integers is merely arbitrary convention. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From e_d_k at yahoo.com Wed May 25 11:45:37 2011 From: e_d_k at yahoo.com (Ed Keith) Date: Wed, 25 May 2011 08:45:37 -0700 (PDT) Subject: Kind of OT - Books on software development? In-Reply-To: Message-ID: <315461.27473.qm@web120501.mail.ne1.yahoo.com> I do not have my library with me, but I remember a book that fits the bill exactly, is was from Microsoft Press, I think it was called "Writing Solid Code" Hope this helps, -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com --- On Wed, 5/25/11, Matty Sarro wrote: > From: Matty Sarro > Subject: Kind of OT - Books on software development? > To: "Python list" > Date: Wednesday, May 25, 2011, 11:40 AM > Hey everyone, > I am looking at some projects coming up, which may or may > not involve > python. So I figured I would throw the question out there > and see what > everyone thinks. > I am looking for some books on software > engineering/development... > something that discusses techniques from ideation, up > through testing, > QA, production, and then maintenance. Is there such a > book? > -Matthew > -- > http://mail.python.org/mailman/listinfo/python-list > From greg.kujawa at gmail.com Wed May 25 12:11:13 2011 From: greg.kujawa at gmail.com (gregarican) Date: Wed, 25 May 2011 09:11:13 -0700 (PDT) Subject: Kind of OT - Books on software development? References: Message-ID: <13d34170-8dd3-4d7c-8b0d-374b069b653f@k16g2000yqm.googlegroups.com> On May 25, 11:45?am, Ed Keith wrote: > I do not have my library with me, but I remember a book that fits the bill exactly, is was from Microsoft Press, I think it was called "Writing Solid Code" > > Hope this helps, > > ? ?-EdK > > Ed Keith > e_... at yahoo.com > > Blog: edkeith.blogspot.com > > --- On Wed, 5/25/11, Matty Sarro wrote: > > > > > From: Matty Sarro > > Subject: Kind of OT - Books on software development? > > To: "Python list" > > Date: Wednesday, May 25, 2011, 11:40 AM > > Hey everyone, > > I am looking at some projects coming up, which may or may > > not involve > > python. So I figured I would throw the question out there > > and see what > > everyone thinks. > > I am looking for some books on software > > engineering/development... > > something that discusses techniques from ideation, up > > through testing, > > QA, production, and then maintenance. Is there such a > > book? > > -Matthew > > -- > >http://mail.python.org/mailman/listinfo/python-list- Hide quoted text - > > - Show quoted text - If you are talking about general concepts in efficient, effective OO programming I'd suggest "Smalltalk Best Practice Patterns" by Kent Beck. I've developed in Java, C#, Python, Ruby, Smalltalk, and other languages and this book is an eye opener! From tdldev at gmail.com Wed May 25 12:19:12 2011 From: tdldev at gmail.com (Verde Denim) Date: Wed, 25 May 2011 12:19:12 -0400 Subject: Kind of OT - Books on software development? In-Reply-To: <315461.27473.qm@web120501.mail.ne1.yahoo.com> References: <315461.27473.qm@web120501.mail.ne1.yahoo.com> Message-ID: Hey everyone, I am looking at some projects coming up, which may or may not involve python. So I figured I would throw the question out there and see what everyone thinks. I am looking for some books on software engineering/development... something that discusses techniques from ideation, up through testing, QA, production, and then maintenance. Is there such a book? -Matthew On Wed, May 25, 2011 at 11:45 AM, Ed Keith wrote: > I do not have my library with me, but I remember a book that fits the bill > exactly, is was from Microsoft Press, I think it was called "Writing Solid > Code" > Matt - Roger Pressman - Software Engineering, A Practicioner's Approach is a good one. Donald E. Knuth. - The Art of Computer Programming (5 Volumes) - http://www-cs-faculty.stanford.edu/~uno/taocp.html Horowitz - Fundamentals of Computer Algorithms Dowd, Macdonald, Shuh - The Art of Software Security Assessments Good Basic Reference Library for engineering, designing, writing, and SECURING code. I've got lots more titles on various aspects of engineering and OOA/OOD construction, design methods, etc., but these are (imo) a good foundation. Regards Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From cousinstanley at gmail.com Wed May 25 12:22:36 2011 From: cousinstanley at gmail.com (Cousin Stanley) Date: Wed, 25 May 2011 16:22:36 +0000 (UTC) Subject: pyGTK identify a button References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Message-ID: Tracubik wrote: > Hi all, > i'm trying to write a simple windows with two button in GTK, > i need a way to identify wich button is pressed. > .... #!/usr/bin/env python import gtk def console_display( button , args ) : a0 , a1 , a2 = args print ' %s .... %s %s ' % ( a0 , a1 , a2 ) window = gtk.Window() window.set_title( "gtk.buttons.01" ) window.set_size_request( 300 , -1 ) window.set_position( gtk.WIN_POS_CENTER ) window.connect( "destroy" , gtk.main_quit ) # Create VBox and add in Window vbox = gtk.VBox() window.add( vbox ) # Create buttons dict_buttons = { 12 : [ 'OneTwo' , 'Buckle ' , 'My Shoe' ] , 34 : [ 'TreFor' , 'Shut ' , 'The Door' ] , 56 : [ 'FivSix' , 'Pick ' , 'Up Sticks' ] , 78 : [ 'SvnAte' , 'Lay ' , 'Them Straight' ] , 910 : [ 'NinTen' , 'Big ' , 'Fat Hen' ] } list_keys = dict_buttons.keys() list_keys.sort() for this_button in list_keys : this_name = dict_buttons[ this_button ][ 0 ] b = gtk.Button( this_name ) b.set_name( this_name ) b.connect( "clicked" , console_display , dict_buttons[ this_button ] ) vbox.pack_start( b ) window.show_all() gtk.main() -- Stanley C. Kitching Human Being Phoenix, Arizona From tjreedy at udel.edu Wed May 25 12:54:32 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 25 May 2011 12:54:32 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <87vcwzyoos.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> Message-ID: On 5/25/2011 8:01 AM, John Bokma wrote: > to. Like I already stated before: if Python is really so much better > than Python readability wise, why do I have such a hard time dropping > Perl and moving on? [you meant 'than Perl'] You are one of the people whose brain fits Perl (or vice versa) better than most. So enjoy it. Ignore anyone who says otherwise. -- Terry Jan Reedy From ethan at stoneleaf.us Wed May 25 13:17:15 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 25 May 2011 10:17:15 -0700 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> Message-ID: <4DDD399B.5050501@stoneleaf.us> Terry Reedy wrote: > On 5/25/2011 8:01 AM, John Bokma wrote: > >> to. Like I already stated before: if Python is really so much better >> than Python readability wise, why do I have such a hard time dropping >> Perl and moving on? > > [you meant 'than Perl'] You are one of the people whose brain fits Perl > (or vice versa) better than most. So enjoy it. Ignore anyone who says > otherwise. +1 If everybody's brain worked the same, we wouldn't have so many different languages to choose from. ~Ethan~ From e_d_k at yahoo.com Wed May 25 13:32:40 2011 From: e_d_k at yahoo.com (Ed Keith) Date: Wed, 25 May 2011 10:32:40 -0700 (PDT) Subject: Kind of OT - Books on software development? In-Reply-To: <315461.27473.qm@web120501.mail.ne1.yahoo.com> Message-ID: <920356.25261.qm@web120508.mail.ne1.yahoo.com> --- On Wed, 5/25/11, Ed Keith wrote: > I do not have my library with me, but > I remember a book that fits the bill exactly, is was from > Microsoft Press, I think it was called "Writing Solid Code" I have done some research at amazon.com, and while "Writing Solid Code" is an excellent book that I would also recommend highly, the book I was thinking of was "Code Complete". -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From jess.austin at gmail.com Wed May 25 13:54:11 2011 From: jess.austin at gmail.com (Jess Austin) Date: Wed, 25 May 2011 10:54:11 -0700 (PDT) Subject: super() in class defs? Message-ID: I may be attempting something improper here, but maybe I'm just going about it the wrong way. I'm subclassing http.server.CGIHTTPRequestHandler, and I'm using a decorator to add functionality to several overridden methods. def do_decorate(func): . def wrapper(self): . if appropriate(): . return func() . complain_about_error() . return wrapper class myHandler(CGIHTTPRequestHandler): . @do_decorate . def do_GET(self): . return super().do_GET() . # also override do_HEAD and do_POST My first thought was that I could just replace that whole method definition with one line: class myHandler(CGIHTTPRequestHandler): . do_GET = do_decorate(super().do_GET) That generates the following error: SystemError: super(): __class__ cell not found So I guess that when super() is called in the context of a class def rather than that of a method def, it doesn't have the information it needs. Now I'll probably just say: do_GET = do_decorate(CGIHTTPRequestHandler.do_GET) but I wonder if there is a "correct" way to do this instead? Thanks! From listas.programacao at gmail.com Wed May 25 14:17:04 2011 From: listas.programacao at gmail.com (Jayme Proni Filho) Date: Wed, 25 May 2011 15:17:04 -0300 Subject: Newbie question about SQLite + Python and twitter Message-ID: Helo guys, I'm building a local application for twitter for my brother's store. I'm in the beginning and I have some newbie problems, so: I create a table called tb_messages with int auto increment and varchar(140) fields; I did three SQL funcionts, insert_tweet, delete_tweet, select_tweet select_tweet is use for getting messages for sending them to twitter; My problem is: How can i make my select_tweet works at the same time that insert or delete funcions. I just got to work when I stop select function. I would like to do my app works all the time. --------------------------------------------------------------------------------------- Jayme Proni Filho Skype: jaymeproni Twitter: @jaymeproni Phone: +55 - 17 - 3631 - 6576 Mobile: +55 - 17 - 9605 - 3560 e-Mail: jaymeproni at yahoo dot com dot br --------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed May 25 14:31:33 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 May 2011 12:31:33 -0600 Subject: super() in class defs? In-Reply-To: References: Message-ID: On Wed, May 25, 2011 at 11:54 AM, Jess Austin wrote: > So I guess that when super() is called in the context of a class def > rather than that of a method def, it doesn't have the information it > needs. Now I'll probably just say: > > ? ?do_GET = do_decorate(CGIHTTPRequestHandler.do_GET) > > but I wonder if there is a "correct" way to do this instead? Thanks! I would recommend against using super() in general. http://fuhm.net/super-harmful/ Cheers, Ian From john at castleamber.com Wed May 25 15:14:15 2011 From: john at castleamber.com (John Bokma) Date: Wed, 25 May 2011 14:14:15 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> Message-ID: <87mxiasid4.fsf@castleamber.com> Ethan Furman writes: > Terry Reedy wrote: >> On 5/25/2011 8:01 AM, John Bokma wrote: >> >>> to. Like I already stated before: if Python is really so much better >>> than Python readability wise, why do I have such a hard time dropping >>> Perl and moving on? >> >> [you meant 'than Perl'] You are one of the people whose brain fits >> Perl (or vice versa) better than most. So enjoy it. Ignore anyone >> who says otherwise. > > +1 > > If everybody's brain worked the same, we wouldn't have so many > different languages to choose from. So, this means that in general language readability is not as clear cut as some seem to advertise ;-). -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From wbsoft at xs4all.nl Wed May 25 15:28:17 2011 From: wbsoft at xs4all.nl (Wilbert Berendsen) Date: Wed, 25 May 2011 21:28:17 +0200 Subject: bdist_wininst: install_script not run on uninstall Message-ID: <201105252128.17504.wbsoft@xs4all.nl> Hi, according to the docs the installer bdist_wininst creates will run the install-script on install with -install (which works perfectly) and on uninstall with the -remove argument (which seemingly never happens). However I want to cleanup some registry stuff on uninstall so I want the uninstall script to work. Studying the source code of the installer[1] in the Run_RemoveScript function... [1] http://svn.python.org/view/python/trunk/PC/bdist_wininst/install.c ... it checks for the line '%d Run Script: %s' in the log, which is there. But can anybody find out why the install script is not run? with best regards, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi From tkpmep at hotmail.com Wed May 25 15:33:39 2011 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: Wed, 25 May 2011 12:33:39 -0700 (PDT) Subject: Python 3.2 bug? Reading the last line of a file Message-ID: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> The following function that returns the last line of a file works perfectly well under Python 2.71. but fails reliably under Python 3.2. Is this a bug, or am I doing something wrong? Any help would be greatly appreciated. import os def lastLine(filename): ''' Returns the last line of a file file.seek takes an optional 'whence' argument which allows you to start looking at the end, so you can just work back from there till you hit the first newline that has anything after it Works perfectly under Python 2.7, but not under 3.2! ''' offset = -50 with open(filename) as f: while offset > -1024: offset *= 2 f.seek(offset, os.SEEK_END) lines = f.readlines() if len(lines) > 1: return lines[-1] If I execute this with a valid filename fn. I get the following error message: >>> lastLine(fn) Traceback (most recent call last): File "", line 1, in lastLine(fn) File "", line 13, in lastLine f.seek(offset, os.SEEK_END) io.UnsupportedOperation: can't do nonzero end-relative seeks Sincerely Thomas Philips From python at mrabarnett.plus.com Wed May 25 16:00:18 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 25 May 2011 21:00:18 +0100 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> Message-ID: <4DDD5FD2.8040607@mrabarnett.plus.com> On 25/05/2011 20:33, tkpmep at hotmail.com wrote: > The following function that returns the last line of a file works > perfectly well under Python 2.71. but fails reliably under Python 3.2. > Is this a bug, or am I doing something wrong? Any help would be > greatly appreciated. > > > import os > > def lastLine(filename): > ''' > Returns the last line of a file > file.seek takes an optional 'whence' argument which allows you > to > start looking at the end, so you can just work back from there > till > you hit the first newline that has anything after it > Works perfectly under Python 2.7, but not under 3.2! > ''' > offset = -50 > with open(filename) as f: > while offset> -1024: > offset *= 2 > f.seek(offset, os.SEEK_END) > lines = f.readlines() > if len(lines)> 1: > return lines[-1] > > If I execute this with a valid filename fn. I get the following error > message: > >>>> lastLine(fn) > Traceback (most recent call last): > File "", line 1, in > lastLine(fn) > File "", line 13, in lastLine > f.seek(offset, os.SEEK_END) > io.UnsupportedOperation: can't do nonzero end-relative seeks > You're opening the file in text mode, and seeking relative to the end of the file is not allowed in text mode, presumably because the file contents have to be decoded, and, in general, seeking to an arbitrary position within a sequence of encoded bytes can have undefined results when you attempt to decode to Unicode starting from that position. The strange thing is that you _are_ allowed to seek relative to the start of the file. Try opening the file in binary mode and do the decoding yourself, catching the DecodeError exceptions if/when they occur. From Catherine.M.Moroney at jpl.nasa.gov Wed May 25 16:27:19 2011 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 25 May 2011 13:27:19 -0700 Subject: using masks and numpy record arrays Message-ID: Hello, I am trying to work with a structured array and a mask, and am encountering some problems. For example: >>> xtype = numpy.dtype([("n", numpy.int32), ("x", numpy.float32)]) >>> a = numpy.zeros((4), dtype=xtype) >>> b = numpy.arange(0,4) >>> a2 = numpy.zeros((4), dtype=xtype) >>> mask = numpy.where(b%2 == 0) >>> a2[:]["n"] += b ! this changes the values of a2 >>> a[mask]["n"] += b[mask] ! this does not change the values of a >>> a2 array([(0, 0.0), (1, 0.0), (2, 0.0), (3, 0.0)], dtype=[('n', '>> a array([(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)], dtype=[('n', '>> a = numpy.zeros((4)) >>> a[mask] += b[mask] >>> a array([ 0., 0., 2., 0.]) What is it about a numpy record array that prevents the mask statement from working, and how do I get around this? Thanks, Catherine From ericsnowcurrently at gmail.com Wed May 25 16:49:07 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 25 May 2011 14:49:07 -0600 Subject: super() in class defs? In-Reply-To: References: Message-ID: On Wed, May 25, 2011 at 12:31 PM, Ian Kelly wrote: > On Wed, May 25, 2011 at 11:54 AM, Jess Austin > wrote: > > So I guess that when super() is called in the context of a class def > > rather than that of a method def, it doesn't have the information it > > needs. Now I'll probably just say: > > > > do_GET = do_decorate(CGIHTTPRequestHandler.do_GET) > > > > but I wonder if there is a "correct" way to do this instead? Thanks! > > I would recommend against using super() in general. > > That position is understandable. However, super is fine for single inheritance, and works fine in cooperative multiple inheritance. You can just as easily argue that multiple inheritance is more harmful than super is. If fact, I would generally recommend against using multiple inheritance if you can avoid it (though it has its place). Personally, I find super to make maintenance and refactoring easier, since I don't have to fiddle with the base class name, or with passing self. Cheers, -eric > http://fuhm.net/super-harmful/ > > Cheers, > Ian > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed May 25 16:54:25 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 May 2011 14:54:25 -0600 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <4DDD5FD2.8040607@mrabarnett.plus.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> Message-ID: On Wed, May 25, 2011 at 2:00 PM, MRAB wrote: > You're opening the file in text mode, and seeking relative to the end > of the file is not allowed in text mode, presumably because the file > contents have to be decoded, and, in general, seeking to an arbitrary > position within a sequence of encoded bytes can have undefined results > when you attempt to decode to Unicode starting from that position. > > The strange thing is that you _are_ allowed to seek relative to the > start of the file. I think that with text files seek() is only really meant to be called with values returned from tell(), which may include the decoder state in its return value. From msarro at gmail.com Wed May 25 17:19:57 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 25 May 2011 17:19:57 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <87mxiasid4.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> Message-ID: On Wed, May 25, 2011 at 3:14 PM, John Bokma wrote: > Ethan Furman writes: > >> Terry Reedy wrote: >>> On 5/25/2011 8:01 AM, John Bokma wrote: >>> >>>> to. Like I already stated before: if Python is really so much better >>>> than Python readability wise, why do I have such a hard time dropping >>>> Perl and moving on? >>> >>> [you meant 'than Perl'] You are one of the people whose brain fits >>> Perl (or vice versa) better than most. So enjoy it. Ignore anyone >>> who says otherwise. >> >> +1 >> >> If everybody's brain worked the same, we wouldn't have so many >> different languages to choose from. > > So, this means that in general language readability is not as clear cut > as some seem to advertise ;-). > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > Blog: http://johnbokma.com/ ? ? ? ?Perl Consultancy: http://castleamber.com/ > Perl for books: ? ?http://johnbokma.com/perl/help-in-exchange-for-books.html > -- > http://mail.python.org/mailman/listinfo/python-list > General readability is a farce. If it was true we would only have one section to the library. Different people enjoy reading, and can comprehend better in different ways. THat's why some people are super verbose - hell, just look at this here post! :) From robert.kern at gmail.com Wed May 25 17:22:50 2011 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 25 May 2011 16:22:50 -0500 Subject: using masks and numpy record arrays In-Reply-To: References: Message-ID: On 5/25/11 3:27 PM, Catherine Moroney wrote: > Hello, > > I am trying to work with a structured array and a mask, and am encountering some > problems. You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists > For example: > > >>> xtype = numpy.dtype([("n", numpy.int32), ("x", numpy.float32)]) > >>> a = numpy.zeros((4), dtype=xtype) > >>> b = numpy.arange(0,4) > >>> a2 = numpy.zeros((4), dtype=xtype) > >>> mask = numpy.where(b%2 == 0) > >>> a2[:]["n"] += b ! this changes the values of a2 > >>> a[mask]["n"] += b[mask] ! this does not change the values of a > >>> a2 > array([(0, 0.0), (1, 0.0), (2, 0.0), (3, 0.0)], > dtype=[('n', ' >>> a > array([(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)], > dtype=[('n', ' > Why do the values of a2 get updated, and yet the values of a do not? Only the final [] on the left-hand side of the assignment actually turns into a .__setitem__() call to the object that is the result of the expression to its left. a[mask] makes a copy while a2[:] makes a view. You could do a["n"][mask] += b[mask] since a["n"] will also make a view and the .__setitem__() on it will propagate back to the original memory. -- 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 thegist at nospam.net Wed May 25 17:30:48 2011 From: thegist at nospam.net (thegist at nospam.net) Date: Wed, 25 May 2011 17:30:48 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> Message-ID: <72183$4ddd7506$ce534406$5707@news.eurofeeds.com> On 5/24/2011 1:39 PM, D'Arcy J.M. Cain wrote: [snip] > One of my favorite quotes (not sure if it was about Perl or APL) is "I > refuse to use a programming language where the proponents of it stick > snippets under each other's nose and say 'I bet you can't guess what > this does.'" I dunno. That sounds about like how most programming course exams are written, no? The point is that puzzling through arcane bits of code are crucial to learning any language. It's a valuable exercise. From steve+comp.lang.python at pearwood.info Wed May 25 17:40:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 21:40:32 GMT Subject: super() in class defs? References: Message-ID: <4ddd774f$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 12:31:33 -0600, Ian Kelly wrote: > I would recommend against using super() in general. > > http://fuhm.net/super-harmful/ If you actually read that article, carefully, without being fooled by the author's provocative ex-title and misleading rhetoric, you will discover that super is not harmful. What is harmful is making unjustified assumptions about what super does, and about the code you are calling, and hence misusing super. You have to read all the way to the bottom of the article to see the author say in the TODO section: "Give some examples of why super really is necessary sometimes" Even before that, you will read why *not* using super often fails badly. If James Knight, the author, is correct that super is harmful, it seems that you're in trouble because *not using super* is also harmful. If you search the mailing lists of python-dev at python.org, you will find a debate between James and Guido van Russum where James eventually acknowledges that he is wrong to call super harmful. There's a reason that he has changed the title of the page from "Python's Super Considered Harmful" to the damning-with-faint-praise "Python's Super is nifty, but you can't use it". The new title is also *simply wrong*, because you can use it. James even tells you what you need to do to use it correctly. The truth is that for multiple inheritance, you better be using super or your code is probably buggy (unless you manually duplicate what super does for you). And for single inheritance, it makes no difference whether you use super or not. -- Steven From python at mrabarnett.plus.com Wed May 25 17:52:39 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 25 May 2011 22:52:39 +0100 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> Message-ID: <4DDD7A27.60602@mrabarnett.plus.com> On 25/05/2011 21:54, Ian Kelly wrote: > On Wed, May 25, 2011 at 2:00 PM, MRAB wrote: >> You're opening the file in text mode, and seeking relative to the end >> of the file is not allowed in text mode, presumably because the file >> contents have to be decoded, and, in general, seeking to an arbitrary >> position within a sequence of encoded bytes can have undefined results >> when you attempt to decode to Unicode starting from that position. >> >> The strange thing is that you _are_ allowed to seek relative to the >> start of the file. > > I think that with text files seek() is only really meant to be called > with values returned from tell(), which may include the decoder state > in its return value. What do you mean by "may include the decoder state in its return value"? It does make sense that the values returned from tell() won't be in the middle of an encoded sequence of bytes. From steve+comp.lang.python at pearwood.info Wed May 25 17:59:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 21:59:58 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 09:26:11 +0200, Thorsten Kampe wrote: > Naming something in the terms of its implementation details (in this > case recursion) is a classical WTF. *If* that's true, it certainly doesn't seem to apply to real-world objects. Think about the exceptions: microwave oven vacuum cleaner oven fries electric car chain saw flintlock rifle air gun vulcanised rubber kerosene heater aluminium foil diamond saw gas stove wood stove four-wheel drive car incandescent light bulb electric razor unleaded petrol to mention only a few. Naming the thing after the implementation would often seem to be *good advice*, not bad. We often do care about implementations. You really do need to know whether the car you drive uses leaded or unleaded. Being able to swap implementations without changing the interface is an abstraction that doesn't apply all the time, in either code or real life. -- Steven From steve+comp.lang.python at pearwood.info Wed May 25 18:58:21 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 22:58:21 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 00:06:06 +0200, Rikishi42 wrote: > On 2011-05-24, Steven D'Aprano > wrote: >>>> I think that is a patronizing remark that under-estimates the >>>> intelligence of lay people and over-estimates the difficulty of >>>> understanding recursion. >>> >>> Why would you presume this to be related to intelligence? The point >>> was not about being *able* to understand, but about *needing* to >>> understand in order to use. >> >> Maybe they don't "need" to understand recursion. So what? > > I think you should read the earlier posts again, this is drifting so far > from what I intended. > > What I mean is: I'm certain that over the years I've had more than one > person come to me and ask what 'Do you wish to delete this directory > recursively?' meant. BAut never have I been asked to explain what 'Do > you wish to delete this directory and it's subdirs/with all it's > contents?' meant. Never. I know many people who have no idea what a directory is, let alone a subdirectory, unless it's the phone directory. They're non-computer users. Once they start using computers, they quickly work out what the word means in context, or they ask and get told, and then they've learned a new word and never need ask again. This is a good thing. The idiom of "recursively delete" is no different. Of course some people will have to learn a new term in order to make sense of it. So what? > Do you know many people who incinerate leaves and branches in their > garden? I burn them. I know many people who incinerate leaves in an incinerator. Or at least they used to, until the government here banned it. It might only have been a 44 gallon drum with holes punched in the side, but they still called it an incinerator. I learned that word from my father, who left school at 14 to work in a shoe shop. He isn't especially educated, doesn't read much beyond the daily tabloid, and thinks Benny Hill is the height of wit. But he's not an idiot and even at 72 is capable of learning new words. >> Do they need to know the words "microwave oven" when they could be >> saying "invisible rays cooking thing"? > > The word oven has existed for ages, microwave is just a name for the > type of oven. Not even a description, just a name. Why do you think they're called "microwave ovens" instead of "fizzbaz ovens"? Could it possibly have something to do with the fact that they cook with microwaves? So not actually "just a name" at all. It's a jargon description of the implementation of the oven. >> I wonder whether physicists insist that cars should have a "go faster >> pedal" because ordinary people don't need to understand Newton's Laws >> of Motion in order to drive cars? > > Gas pedal. Pedal was allraedy known when the car was invented. The > simple addition of gas solved that need. What's a gas pedal? Is that some strange American term for what most of the English-speaking world knows as the accelerator? *wink* > Oh, and it's break pedal, not descellarator. (sp?) That would be brake, and decelerator. >> Who are you to say that people shouldn't be exposed to words you deem >> that they don't need to know? > > I'm one of the 'people'. You say exposed to, I say bothered/bored with. You can't force people to learn new words, although you would be surprised how even the most disinterested, lazy speaker manages to pick up vocabulary without even being aware of it. But nor do you have to pander to the slackers. They can learn the word, or not, I don't care. If I'm writing for an audience of children, or English as a second language, or the otherwise linguistically challenged, I'll simplify my vocabulary appropriately. For everyone else, I'll use an ordinary adult vocabulary, and that includes the word "recursion" or "recursive". It's hardly technical jargon -- I've found a discussion of gangsta rap that uses it. Even children understand the concept of recursion (self-reference). People put it in comedies like Blazing Saddles and Space Balls! How difficult is it to put a name to the concept? > I have nothing against the use of a proper, precise term. And that word > can be a complex one with many, many sylables (seems to add value, > somehow). > > But I'm not an academic, so I don't admire the pedantic use of terms > that need to be explained to 'lay' people. Pedantic... that's another one of those academic words that need to be explained to lay people, isn't it? As is academic itself, and in fact "lay people". Who uses "lay people" in conversation? Conversation -- another one of those four syllable words that should be avoided, since we have "talk". I don't remember that last time I've heard Bazza or Jimbo say "I was on the Internet having a conversation on Jabber", do you? Oh, actually I do. So much for that argument. > widespread, usually shorter and much simpler one for it. A pointless > effort if pointless, even when comming from a physicist. :-) I think you *grossly* underestimate how many words people know, particularly if you include so-called "passive vocabulary" (words people can understand in context, but not define precisely). See, for example: http://www.worldwidewords.org/articles/howmany.htm -- Steven From steve+comp.lang.python at pearwood.info Wed May 25 19:01:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 23:01:32 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> Message-ID: <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 07:01:07 -0500, John Bokma wrote: > if Python is really so much better than Python [Perl] > readability wise, why do I have such a hard time dropping > Perl and moving on? My guess is that you have an adversarial view of computer languages, therefore after investing so much time and energy and, most importantly, self-image into becoming a Perl programmer, dropping it and moving on would be tantamount to admitting to yourself that you were "wrong" to have wasted so many years on the wrong language. Whether it is objectively "wrong" or not rarely enters into these things. That *you personally* can't or won't let go of Perl says nothing about the relative readability of Perl and Python code. -- Steven From steve+comp.lang.python at pearwood.info Wed May 25 19:25:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 23:25:14 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: <4ddd8fd9$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 08:01:38 +1000, Chris Angelico wrote: > On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain > wrote: >> When I first looked at Perl it looked like line noise. ?When I first >> looked at Python it looked like pseudo-code. > > When I first looked at assembly language it looked like random junk left > behind in memory. When I first looked at COBOL it looked like ... COBOL. > Doesn't make either of them better or worse. Er, yes it does. Writing code is primarily for *human readers*. Once you've compiled the code once, the computer never need look at it again, but human being come back to read it over and over again, to learn from it, or for maintenance. We rightfully value our own time and convenience as more valuable than that of the computer's, which is why we use programming languages at all, instead of having custom-made hardware built for every task we want the computer to do: "I have to rename a file before August 2015, but the rename itself needs to be done in under a picosecond. Know any bespoke chip manufacturers who do small runs?" >From that perspective, COBOL is an improvement on assembly, which is why there are probably still more COBOL programmers around than people who work exclusively on assembly. Sometimes we compromise, or even subvert, that trade-off: for speed critical code where we do care more about the computer's time than our own, or for esoteric languages designed to be as hard to read as possible. My personal favourites, Oook and Whitespace. But generally, people spend more time reading code than writing it, therefore we should weigh "ease of reading" higher than "ease of writing". (My guess is, the weights should be about 5:1.) > Pseudo-code is not a viable language for a computer to parse, Only because "pseudo-code" implies that the code is ambiguous or otherwise cannot be parsed. If it could be, it wouldn't be *pseudo*, it would be real code (possibly for some compiler that hasn't been written yet). > but it's a > good language for scribbling down comments in. That doesn't necessarily > mean that a programming language that's "closer to" pseudo-code is good. That depends on the nature of pseudo-code. "Pseudo-assembly" has all the disadvantages of assembly with none of the advantages, i.e. it doesn't actually work. So in that sense, pseudo-code is not necessarily a good thing nor a bad thing. But in general conversation, pseudo-code is usually implied to mean that the language is as close to human language as you can make it, while still be parsable by a compiler. > And verbosity doesn't necessarily equate to quality; for instance, when > I'm working in both Python and PHP, I find it FAR tidier to use Python's > {1:2,3:4] notation than PHP's array(1=>2,3=>4) - but on the flip side, I > would prefer to have program structure defined by keywords like "if" and > "while" than obscure random line noise. (Fortunately, most sane > languages do indeed use keywords there.) True. That's one of the limitations of the xtalk family of languages derived from Apple's (defunct) Hypertalk: it's awfully verbose, which is good for newbies but not quite so good for experts. -- Steven From tkpmep at hotmail.com Wed May 25 19:25:55 2011 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: Wed, 25 May 2011 16:25:55 -0700 (PDT) Subject: Python 3.2 bug? Reading the last line of a file References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> Message-ID: <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> Thanks for the guidance - it was indeed an issue with reading in binary vs. text., and I do now succeed in reading the last line, except that I now seem unable to split it, as I demonstrate below. Here's what I get when I read the last line in text mode using 2.7.1 and in binary mode using 3.2 respectively under IDLE: 2.7.1 Name 31/12/2009 0 0 0 3.2 b'Name\t31/12/2009\t0\t0\t0\r\n' if, under 2.7.1 I read the file in text mode and write >>> x = lastLine(fn) I can then cleanly split the line to get its contents >>> x.split('\t') ['Name', '31/12/2009', '0', '0', '0\n'] but under 3.2, with its binary read, I get >>> x.split('\t') Traceback (most recent call last): File "", line 1, in x.split('\t') TypeError: Type str doesn't support the buffer API If I remove the '\t', the split now works and I get a list of bytes literals >>> x.split() [b'Name', b'31/12/2009', b'0', b'0', b'0'] Looking through the docs did not clarify my understanding of the issue. Why can I not split on '\t' when reading in binary mode? Sincerely Thomas Philips From pavlovevidence at gmail.com Wed May 25 19:26:34 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 25 May 2011 16:26:34 -0700 (PDT) Subject: super() in class defs? In-Reply-To: Message-ID: <1e953311-915e-4fce-89f7-dbcba6f403ee@glegroupsg2000goo.googlegroups.com> On Wednesday, May 25, 2011 10:54:11 AM UTC-7, Jess Austin wrote: > I may be attempting something improper here, but maybe I'm just going > about it the wrong way. I'm subclassing > http.server.CGIHTTPRequestHandler, and I'm using a decorator to add > functionality to several overridden methods. > > def do_decorate(func): > . def wrapper(self): > . if appropriate(): > . return func() > . complain_about_error() > . return wrapper > > class myHandler(CGIHTTPRequestHandler): > . @do_decorate > . def do_GET(self): > . return super().do_GET() > . # also override do_HEAD and do_POST > > My first thought was that I could just replace that whole method > definition with one line: > > class myHandler(CGIHTTPRequestHandler): > . do_GET = do_decorate(super().do_GET) > > That generates the following error: > > SystemError: super(): __class__ cell not found > > So I guess that when super() is called in the context of a class def > rather than that of a method def, it doesn't have the information it > needs. Right. Actually the class object itself doesn't even exist yet when super() is invoked. (It won't be created until after the end of the class statement block.) > Now I'll probably just say: > > do_GET = do_decorate(CGIHTTPRequestHandler.do_GET) > > but I wonder if there is a "correct" way to do this instead? Thanks! Well, since the class object isn't created until after the end of the class statement block, it's impossible to invoke super() on the class from inside the block. So there's only two ways to invoke super(): 1. like you did above, by calling it inside a method, and 2. call it beyond the end of the class statement, like this: class myHandler(CGIHTTPRequestHandler): pass myHandler.do_GET = do_decorate(super(myHandler).do_GET) I wouldn't call that correct, though. (I'm not even sure it'll work, since I don't have Python 3 handy to test it, but as far as I can tell it will.) It's just one of the quirks of Python's type system. I don't agree with Ian's recommendation not to use super() in general, but I'd probably agree that one should stick to using it only in its intended way (to invoke base-class methods directly). Carl Banks From ian.g.kelly at gmail.com Wed May 25 19:31:51 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 May 2011 17:31:51 -0600 Subject: super() in class defs? In-Reply-To: <4ddd774f$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4ddd774f$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 25, 2011 at 3:40 PM, Steven D'Aprano wrote: > If you actually read that article, carefully, without being fooled by the > author's provocative ex-title and misleading rhetoric, you will discover > that super is not harmful. What is harmful is making unjustified > assumptions about what super does, and about the code you are calling, > and hence misusing super. Yes. As others have noted, the problem is really multiple inheritance, not super. Super can be a useful tool, but unless you have taken some time to learn its intricacies, I think that it is best avoided so that it is not misused. > You have to read all the way to the bottom of the article to see the > author say in the TODO section: > > "Give some examples of why super really is necessary sometimes" > > Even before that, you will read why *not* using super often fails badly. > If James Knight, the author, is correct that super is harmful, it seems > that you're in trouble because *not using super* is also harmful. Essentially, super can fail when you use it inconsistently. Not using super can fail when you have a diamond inheritance situation, or when you mix it with super. In this case, the OP is using super while inheriting from http.server.CGIHTTPServer, which does not use super, and so is inconsistent. > If you search the mailing lists of python-dev at python.org, you will find a > debate between James and Guido van Russum where James eventually > acknowledges that he is wrong to call super harmful. There's a reason > that he has changed the title of the page from "Python's Super Considered > Harmful" to the damning-with-faint-praise "Python's Super is nifty, but > you can't use it". Thanks. I found this quote from James that pretty much sums up my position perfectly: """ This is where I'm coming from: In my own code, it is very rare to have diamond inheritance structures. And if there are, even more rare that both sides need to cooperatively override a method. Given that, super has no necessary advantage. And it has disadvantages. - Backwards compatibility issues - Going along with that, inadvertent mixing of paradigms (you have to remember which classes you use super with and which you don't or your code might have hard-to-find errors). - Take your choice of: a) inability to add optional arguments to your methods, or b) having to use *args, **kwargs on every method and call super with those. - Having to try/catch AttributeErrors from super if you use interfaces instead of a base class to define the methods in use. """ > The new title is also *simply wrong*, because you can use it. James even > tells you what you need to do to use it correctly. Yes, you need to fundamentally alter the structure of your code to throw away any semblance of run-time argument checking by having every method that might conceivably be cooperatively inherited take *args, **kwargs. You also need to take care to always call super from such methods, even when it appears to be unnecessary. And don't forget to catch the AttributeError if the method is something other than __new__ or __init__ and the current class turns out to be the last one in the MRO that has it. In short, if you're using super and don't feel burdened by it, then you're probably using it incorrectly. > The truth is that for multiple inheritance, you better be using super or > your code is probably buggy (unless you manually duplicate what super > does for you). No. For diamond inheritance, you better be using super or your code is probably buggy. For typical diamond-less multiple inheritance, super is both unnecessary and tricky to use correctly. > And for single inheritance, it makes no difference whether > you use super or not. Right. It's unnecessary, so why saddle yourself with it? From python at rcn.com Wed May 25 19:45:29 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 25 May 2011 16:45:29 -0700 (PDT) Subject: super() in class defs? References: <4ddd774f$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 25, 4:31?pm, Ian Kelly wrote: > Right. ?It's unnecessary, so why saddle yourself with it? FWIW, I expect to release a blog post tomorrow about the principal use cases for super() and how to use it effectively. With just a little bit of know-how, it can be an important tool in your Python toolkit. If any of the comp.lang.python readers want to review and comment on my latest draft, please email me and I'll send it to you directly. Cheers, Raymond Hettinger my email address is listed at http://users.rcn.com/python/download/Descriptor.htm From skippy.hammond at gmail.com Wed May 25 19:46:55 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 26 May 2011 09:46:55 +1000 Subject: bdist_wininst: install_script not run on uninstall In-Reply-To: <201105252128.17504.wbsoft@xs4all.nl> References: <201105252128.17504.wbsoft@xs4all.nl> Message-ID: <4DDD94EF.6010804@gmail.com> On 26/05/2011 5:28 AM, Wilbert Berendsen wrote: > Hi, > > according to the docs the installer bdist_wininst creates will run the > install-script on install with -install (which works perfectly) and on > uninstall with the -remove argument (which seemingly never happens). > > However I want to cleanup some registry stuff on uninstall so I want the > uninstall script to work. > > Studying the source code of the installer[1] in the Run_RemoveScript > function... > > [1] http://svn.python.org/view/python/trunk/PC/bdist_wininst/install.c > > ... it checks for the line '%d Run Script: %s' in the log, which is there. But > can anybody find out why the install script is not run? Works for me in the pywin32 install script - maybe you should make the smallest possible example that doesn't work and post the entire thing here? Mark From steve+comp.lang.python at pearwood.info Wed May 25 19:52:28 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 23:52:28 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <72183$4ddd7506$ce534406$5707@news.eurofeeds.com> Message-ID: <4ddd963c$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 17:30:48 -0400, thegist at nospam.net wrote: > On 5/24/2011 1:39 PM, D'Arcy J.M. Cain wrote: [snip] >> One of my favorite quotes (not sure if it was about Perl or APL) is "I >> refuse to use a programming language where the proponents of it stick >> snippets under each other's nose and say 'I bet you can't guess what >> this does.'" > I dunno. That sounds about like how most programming course exams are > written, no? > The point is that puzzling through arcane bits of code are crucial to > learning > any language. It's a valuable exercise. You seem to miss the point that a good language shouldn't make it possible to write arcane code that needs to be puzzled out. Although in fairness, what's arcane to me might be straightforward to you... and vice versa. In that sense, there probably aren't any "good languages", because it is impractical to have a language that cannot be obfuscated in any way. Nevertheless, we can distinguish "less good" from "more good" in languages in the sense of readability. The fact that some languages not just allow such obfuscation but encourage it makes the language great for puzzles but not so good for when you actually want to get work done and have to deal with code written by someone else. *Especially* if they're significantly smarter, or dumber, than you. Worst of all is dealing with code written by somebody who *thinks* they're smarter but is actually dumber. -- Steven From python at mrabarnett.plus.com Wed May 25 19:56:52 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 May 2011 00:56:52 +0100 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> Message-ID: <4DDD9744.1010002@mrabarnett.plus.com> On 26/05/2011 00:25, tkpmep at hotmail.com wrote: > Thanks for the guidance - it was indeed an issue with reading in > binary vs. text., and I do now succeed in reading the last line, > except that I now seem unable to split it, as I demonstrate below. > Here's what I get when I read the last line in text mode using 2.7.1 > and in binary mode using 3.2 respectively under IDLE: > > 2.7.1 > Name 31/12/2009 0 0 0 > > 3.2 > b'Name\t31/12/2009\t0\t0\t0\r\n' > > if, under 2.7.1 I read the file in text mode and write >>>> x = lastLine(fn) > I can then cleanly split the line to get its contents >>>> x.split('\t') > ['Name', '31/12/2009', '0', '0', '0\n'] > > but under 3.2, with its binary read, I get >>>> x.split('\t') > Traceback (most recent call last): > File "", line 1, in > x.split('\t') > TypeError: Type str doesn't support the buffer API > > If I remove the '\t', the split now works and I get a list of bytes > literals >>>> x.split() > [b'Name', b'31/12/2009', b'0', b'0', b'0'] > > Looking through the docs did not clarify my understanding of the > issue. Why can I not split on '\t' when reading in binary mode? > x.split('\t') tries to split on '\t', a string (str), but x is a bytestring (bytes). Do x.split(b'\t') instead. From ethan at stoneleaf.us Wed May 25 19:58:55 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 25 May 2011 16:58:55 -0700 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> Message-ID: <4DDD97BF.4060605@stoneleaf.us> tkpmep at hotmail.com wrote: > Thanks for the guidance - it was indeed an issue with reading in > binary vs. text., and I do now succeed in reading the last line, > except that I now seem unable to split it, as I demonstrate below. > Here's what I get when I read the last line in text mode using 2.7.1 > and in binary mode using 3.2 respectively under IDLE: > > 3.2 > b'Name\t31/12/2009\t0\t0\t0\r\n' > > under 3.2, with its binary read, I get >--> x.split('\t') > Traceback (most recent call last): > File "", line 1, in > x.split('\t') > TypeError: Type str doesn't support the buffer API You are trying to split a bytes object with a str object -- the two are not compatible. Try splitting with the bytes object b'\t'. ~Ethan~ From andrei.avk at gmail.com Wed May 25 20:15:09 2011 From: andrei.avk at gmail.com (RainyDay) Date: Wed, 25 May 2011 17:15:09 -0700 (PDT) Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> Message-ID: <8984a70f-449e-40a4-b962-0e93ba8c4071@m40g2000vbt.googlegroups.com> On May 25, 3:14?pm, John Bokma wrote: > Ethan Furman writes: > > Terry Reedy wrote: > >> On 5/25/2011 8:01 AM, John Bokma wrote: > > >>> to. Like I already stated before: if Python is really so much better > >>> than Python readability wise, why do I have such a hard time dropping > >>> Perl and moving on? > > >> [you meant 'than Perl'] You are one of the people whose brain fits > >> Perl (or vice versa) better than most. So enjoy it. Ignore anyone > >> who says otherwise. > > > +1 > > > If everybody's brain worked the same, we wouldn't have so many > > different languages to choose from. > > So, this means that in general language readability is not as clear cut > as some seem to advertise ;-). > I only know a tiny bit of Perl but I think you may prefer it because it gives you some advantages in short term but you have to pay more than it's worth (arguably) in the long term. When you sit down to write a new program, it's easier to do than in python because it's quicker to type and, of the proverbial "many ways", you chose the ones that suit your taste better. However, when you sit down to read someone else's code, it's harder to read because you don't know the intent of their authors. If they had different taste for idioms or formatting style than you do, you will chalk it up to them being bad programmers and having bad coding or formatting style, so it's not perceived as a perl's failing. Python way has more of an emphasis on everyone agreeing on some preferred, standard idioms so that everyone can pick up each others' code quickly. Similarly, when we write in english, we have conventions of, for instance, capitalizing at the start of a sentence and having a period at the end of it, and following rules of grammar. However, if I'm writing notes for my own use, I might write: similarly when we write in english we have conventions of eg capitalizing at start of sentence and having period at the end & following rules of grammar but since i'm writing for my own use maybe it's easier to write in lower caps and use 3 spaces at the end of sentences, since no-ones has to read it but me? From ethan at stoneleaf.us Wed May 25 20:32:58 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 25 May 2011 17:32:58 -0700 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <4DDD9744.1010002@mrabarnett.plus.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> <4DDD9744.1010002@mrabarnett.plus.com> Message-ID: <4DDD9FBA.8000103@stoneleaf.us> MRAB wrote: > On 26/05/2011 00:25, tkpmep at hotmail.com wrote: >> Thanks for the guidance - it was indeed an issue with reading in >> binary vs. text., and I do now succeed in reading the last line, >> except that I now seem unable to split it, as I demonstrate below. >> Here's what I get when I read the last line in text mode using 2.7.1 >> and in binary mode using 3.2 respectively under IDLE: >> >> 2.7.1 >> Name 31/12/2009 0 0 0 >> >> 3.2 >> b'Name\t31/12/2009\t0\t0\t0\r\n' >> >> if, under 2.7.1 I read the file in text mode and write >>>>> x = lastLine(fn) >> I can then cleanly split the line to get its contents >>>>> x.split('\t') >> ['Name', '31/12/2009', '0', '0', '0\n'] >> >> but under 3.2, with its binary read, I get >>>>> x.split('\t') >> Traceback (most recent call last): >> File "", line 1, in >> x.split('\t') >> TypeError: Type str doesn't support the buffer API >> >> If I remove the '\t', the split now works and I get a list of bytes >> literals >>>>> x.split() >> [b'Name', b'31/12/2009', b'0', b'0', b'0'] >> >> Looking through the docs did not clarify my understanding of the >> issue. Why can I not split on '\t' when reading in binary mode? >> > x.split('\t') tries to split on '\t', a string (str), but x is a > bytestring (bytes). > > Do x.split(b'\t') instead. Instances of the bytes class are more appropriately called 'bytes objects' rather than 'bytestrings' as they are really lists of integers. Accessing a single element of a bytes object does not return a bytes object, but rather the integer at that location; i.e. --> b'xyz'[1] 121 Contrast that with the str type where --> 'xyz'[1] 'y' ~Ethan~ From jschementi at gmail.com Wed May 25 20:44:38 2011 From: jschementi at gmail.com (Jimmy Schementi) Date: Thu, 26 May 2011 00:44:38 GMT Subject: Unable to make ironpython run in browser with silverlight References: <715e82a9-3761-4d82-9df4-1c5f39633160@h36g2000pro.googlegroups.com> Message-ID: <2011525204432usenet@terrranews.com> You need to run it from a web-server; it doesn't work when running from file:// due to Silverlight's security sandbox. Read the comments on my blog-post, it mentions the web-server there. From r.richardparker at comcast.net Wed May 25 20:58:39 2011 From: r.richardparker at comcast.net (Richard Parker) Date: Wed, 25 May 2011 17:58:39 -0700 Subject: Python-list Digest, Vol 92, Issue 221 In-Reply-To: References: Message-ID: > Writing code is primarily for *human readers*. Once you've compiled the > code once, the computer never need look at it again, but human being come > back to read it over and over again, to learn from it, or for > maintenance. We rightfully value our own time and convenience as more > valuable than that of the computer's, which is why we use programming > languages at all, instead of having custom-made hardware built for every > task we want the computer to do: Not only the code itself, but, hopefully, embedded comments help even non-authors of the code to understand, maintain and improve it. Programming books that include examples often spend many pages dissecting even short segments of the code to tutor would-be developers how it works and what it does. Well written code in any language, with accompanying comments, is invaluable for anyone who has the need or interest to Understand and maintain it. My (ancient) books about object-oriented programming were used to teach hundreds of computer science students in universities all over the world, and the stressed the importance of embedded comments. How many times has any programmer looked at (even inscrutable) code with accompanying comments and hasn't said to themselves "so that's how to do it, or that's what it does". It's time to stop having flame wars about languages and embrace programmers who care enough about possible future readers of their code to thoroughly comment it. Comments are far more valuable than the actual language in which the code is written, IMHO. Sent from my iPad. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed May 25 21:06:04 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 May 2011 19:06:04 -0600 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <4DDD7A27.60602@mrabarnett.plus.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <4DDD7A27.60602@mrabarnett.plus.com> Message-ID: On Wed, May 25, 2011 at 3:52 PM, MRAB wrote: > What do you mean by "may include the decoder state in its return value"? > > It does make sense that the values returned from tell() won't be in the > middle of an encoded sequence of bytes. If you take a look at the source code, tell() returns a long that includes decoder state data in the upper bytes. For example: >>> data = b' ' + '\u0302a'.encode('utf-16') >>> data b' \xff\xfe\x02\x03a\x00' >>> f = open('test.txt', 'wb') >>> f.write(data) 7 >>> f.close() >>> f = open('test.txt', 'r', encoding='utf-16') >>> f.read() Traceback (most recent call last): File "", line 1, in File "c:\python32\lib\codecs.py", line 300, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) File "c:\python32\lib\encodings\utf_16.py", line 61, in _buffer_decode codecs.utf_16_ex_decode(input, errors, 0, final) UnicodeDecodeError: 'utf16' codec can't decode bytes in position 6-6: truncated data The problem of course is the initial space, throwing off the decoder. We can try to seek past it: >>> f.seek(1) 1 >>> f.read() '\ufeff\u0302a' But notice that since we're not reading from the beginning of the file, the BOM has now been interpreted as data. However: >>> f.seek(1 + (2 << 65)) 73786976294838206465 >>> f.read() '\u0302a' And you can see that instead of reading from position 73786976294838206465 it has read from position 1 starting in the "read a BOM" state. Note that I wouldn't recommend doing anything remotely like this in production code, not least because the value that I passed into seek() is platform-dependent. This is just a demonstration of how the seek() value can include decoder state. Cheers, Ian From philip at semanchuk.com Wed May 25 21:08:14 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 25 May 2011 21:08:14 -0400 Subject: Newbie question about SQLite + Python and twitter In-Reply-To: References: Message-ID: <2BE08035-7495-47FD-8FDA-D5B7025ED45F@semanchuk.com> On May 25, 2011, at 2:17 PM, Jayme Proni Filho wrote: > Helo guys, > > I'm building a local application for twitter for my brother's store. I'm in > the beginning and I have some newbie problems, so: > > I create a table called tb_messages with int auto increment and varchar(140) > fields; > I did three SQL funcionts, insert_tweet, delete_tweet, select_tweet > > select_tweet is use for getting messages for sending them to twitter; > > My problem is: How can i make my select_tweet works at the same time that > insert or delete funcions. I just got to work when I stop select function. > > I would like to do my app works all the time. Hi Jayme, You need to provide a lot more information for us to be able to help you. Some suggestions -- http://www.istf.com.br/perguntas/#beprecise bye Philip From akabaila at pcug.org.au Wed May 25 21:27:33 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Thu, 26 May 2011 11:27:33 +1000 Subject: Odp: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: References: Message-ID: <201105261127.33624.akabaila@pcug.org.au> On Wednesday 25 May 2011 06:27:52 sunrrrise wrote: > Ok, another time I'd like to thank you for your help. I gave > up, I'm going to get used to IDLE GUI... at least this one > works! With IDLE, after any changes to the program, you are asked to "save file". IDLE knows that a file in python needs to be saved before it can be run! If you use Notepad, it does not know that Python programs need to be saved to disk before they can be executed. So you should remember to save them first. To use IDLE is a good choice, particularly if you are a beginner! OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From miki.tebeka at gmail.com Wed May 25 21:29:46 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 25 May 2011 18:29:46 -0700 (PDT) Subject: Cherrypy In-Reply-To: Message-ID: <1a2f27a7-3b1b-4b5e-84bf-9103e615f84c@glegroupsg2000goo.googlegroups.com> I wrote http://drdobbs.com/showArticle.jhtml?articleID=199102936&queryText=query way back then. It might be of some help. If you have any specific questions, feel free to post them to the group. From miki.tebeka at gmail.com Wed May 25 21:29:46 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 25 May 2011 18:29:46 -0700 (PDT) Subject: Cherrypy In-Reply-To: Message-ID: <1a2f27a7-3b1b-4b5e-84bf-9103e615f84c@glegroupsg2000goo.googlegroups.com> I wrote http://drdobbs.com/showArticle.jhtml?articleID=199102936&queryText=query way back then. It might be of some help. If you have any specific questions, feel free to post them to the group. From gvagif at gmail.com Wed May 25 21:59:41 2011 From: gvagif at gmail.com (Sunny) Date: Wed, 25 May 2011 18:59:41 -0700 (PDT) Subject: Unable to make ironpython run in browser with silverlight References: <715e82a9-3761-4d82-9df4-1c5f39633160@h36g2000pro.googlegroups.com> <2011525204432usenet@terrranews.com> Message-ID: <73261820-78c6-4448-a75b-019c197f9832@f31g2000pri.googlegroups.com> On May 26, 9:44?am, Jimmy Schementi wrote: > You need to run it from a web-server; it doesn't work when running from file:// due to Silverlight's security sandbox. Read the comments on my blog-post, it mentions the web-server there. I see.. But here: http://silverlighttest.zzl.org/silverlighttest.html , it runs from a web server, but still gives error. And it has the same source code as your example, except that I replace repl.py with the direct link, as you advise on your blog. I think the problem is with this part: Because when I delete it, it runs properly. Do you know why is that? From erichcart at gmail.com Wed May 25 22:07:39 2011 From: erichcart at gmail.com (ErichCart ErichCart) Date: Wed, 25 May 2011 19:07:39 -0700 (PDT) Subject: Unable to make ironpython run in browser with silverlight References: <715e82a9-3761-4d82-9df4-1c5f39633160@h36g2000pro.googlegroups.com> <2011525204432usenet@terrranews.com> Message-ID: <22405da5-439d-42be-8f2d-65090d3e5679@22g2000prx.googlegroups.com> On May 26, 9:44 am, Jimmy Schementi wrote: > You need to run it from a web-server; it doesn't work when running from file:// due to Silverlight's security sandbox. Read the comments on my blog-post, it mentions the web-server there. I see.. But here: http://silverlighttest.zzl.org/silverlighttest.html , it runs from a web server, but still gives error. And it has the same source code as your example, except that I replace repl.py with the direct link, as you advise on your blog. I think the problem is with this part: Because when I delete it, it runs properly. Do you know why is that? From john at castleamber.com Wed May 25 23:00:33 2011 From: john at castleamber.com (John Bokma) Date: Wed, 25 May 2011 22:00:33 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <874o4i17zi.fsf@castleamber.com> Steven D'Aprano writes: > On Wed, 25 May 2011 07:01:07 -0500, John Bokma wrote: > >> if Python is really so much better than Python [Perl] >> readability wise, why do I have such a hard time dropping >> Perl and moving on? > > My guess is that you have an adversarial view of computer languages, Well, it's clear that you are indeed the fuckwit I suspected you are. What's a pity is that you are so vocal in this group and to me at least makes it a way less pleasant experience to read this group. Get a life. Or better, just fuck off and die. It will improve both the world and the Python community, of which you are nothing but a little, smelly shitstain. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From rosuav at gmail.com Thu May 26 00:00:23 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 14:00:23 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 26, 2011 at 8:58 AM, Steven D'Aprano wrote: > ... For everyone else, I'll use an > ordinary adult vocabulary, and that includes the word "recursion" or > "recursive". Overheard yesterday: "Our conversation was recursing..." I don't know what they were talking about, but I'm pretty sure it wasn't the technical details of a function's implementation, given that one of the people concerned was anything but a computer programmer (I don't know about the other). It's a perfectly good word, useful in many contexts. Chris Angelico From rosuav at gmail.com Thu May 26 00:06:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 14:06:56 +1000 Subject: Python-list Digest, Vol 92, Issue 221 In-Reply-To: References: Message-ID: On Thu, May 26, 2011 at 10:58 AM, Richard Parker wrote: > It's time to stop having flame wars about languages and embrace programmers > who care enough about possible future readers of their code to thoroughly > comment it. Comments are far more valuable than the actual language in which > the code is written, IMHO. The problem with comments (and documentation in general) is that they are often imperfect. If the code is absolutely opaque but it has a comment next to it, you still have that niggling doubt: has the comment been updated whenever the code has? Was it even accurate in the first place? (Comments often say what a piece of code _ought_ to do, but the code might have a bug in it. And sometimes, that bug ends up being part of the function's definition, and people depend on it.) I'd rather have both - reasonably readable code AND a comment, where the comment explains the intent behind the code. // allow space for frobnostication height += BTN_HEIGHT; Chris Angelico From ben at benfinney.id.au Thu May 26 00:25:43 2011 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 26 May 2011 14:25:43 +1000 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> Message-ID: <87oc2qay0o.fsf@benfinney.id.au> > Get a life. Or better, just fuck off and die. It will improve both the > world and the Python community, of which you are nothing but a little, > smelly shitstain. That abuse is entirely unwelcome in this community, against any person. Please desist. If you find any contributing members so difficult to deal with, please don't respond at all. -- \ ?We have met the enemy and he is us.? ?Walt Kelly, _Pogo_ | `\ 1971-04-22 | _o__) | Ben Finney From ben at benfinney.id.au Thu May 26 00:38:31 2011 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 26 May 2011 14:38:31 +1000 Subject: Parse config file and command-line arguments, to get a single collection of options Message-ID: <87k4deaxfc.fsf@benfinney.id.au> Howdy all, Python's standard library has modules for configuration file parsing (configparser) and command-line argument parsing (optparse, argparse). I want to write a program that does both, but also: * Has a cascade of options: default option values, overridden by config file options, overridden by command-line options. * Reads a different, or even additional, configuration file if specified on the command-line (e.g. --config-file foo.conf) and yet still obeys the above cascade. * Allows a single definition of an option (e.g. logging level) to define the same option for parsing from configuration files and the command line. * Unifies the parsed options into a single collection for the rest of the program to access without caring where they came from. How can I achieve this with minimum deviation from the Python standard library? (For anyone interested in gaining StackOverflow points, I'm also asking this as a question there so feel free to post answers on that site .) -- \ ?Apologize, v. To lay the foundation for a future offense.? | `\ ?Ambrose Bierce, _The Devil's Dictionary_, 1906 | _o__) | Ben Finney From bgreen at nycap.rr.com Thu May 26 00:46:45 2011 From: bgreen at nycap.rr.com (Uncle Ben) Date: Wed, 25 May 2011 21:46:45 -0700 (PDT) Subject: Puzzled by list-appending behavior Message-ID: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> In playing with lists of lists, I found the following: (In 3.1, but the same happens also in 2.7) list = [1,2,3] list.append ( [4,5,6] ) x = list x -> [1,2,3,[4,5,6]] as expected. But the shortcut fails: list=[1,2,3] x = list.append( [4,5,6] ) x -> nothing Can someone explain this to me? Uncle Ben From jpiitula at ling.helsinki.fi Thu May 26 01:09:34 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 26 May 2011 08:09:34 +0300 Subject: Python 3.2 bug? Reading the last line of a file References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> Message-ID: tkpmep at hotmail.com writes: > Looking through the docs did not clarify my understanding of the > issue. Why can I not split on '\t' when reading in binary mode? You can split on b'\t' to get a list of byteses, which you can then decode if you want them as strings. You can decode the bytes to get a string and then split on '\t' to get strings. >>> b'tic\ttac\ttoe'.split(b'\t') [b'tic', b'tac', b'toe'] >>> b'tic\ttac\ttoe'.decode('utf-8').split('\t') ['tic', 'tac', 'toe'] From ben+python at benfinney.id.au Thu May 26 01:11:56 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 May 2011 15:11:56 +1000 Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: <87ei3mavvn.fsf@benfinney.id.au> Uncle Ben writes: > Can someone explain this to me? Yes, the documentation for that function (?list.append?) can explain it. In short: if a method modifies the instance, that method does not return the instance. This policy holds for the built-in types, and should be followed for user-defined types also. -- \ ?[I]t is impossible for anyone to begin to learn that which he | `\ thinks he already knows.? ?Epictetus, _Discourses_ | _o__) | Ben Finney From python at rcn.com Thu May 26 01:15:35 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 25 May 2011 22:15:35 -0700 (PDT) Subject: Parse config file and command-line arguments, to get a single collection of options References: <87k4deaxfc.fsf@benfinney.id.au> Message-ID: <5872e7ac-de37-438f-a2da-147ff466f8f1@z15g2000prn.googlegroups.com> On May 25, 9:38?pm, Ben Finney wrote: > Howdy all, > > Python's standard library has modules for configuration file parsing > (configparser) and command-line argument parsing (optparse, argparse). I > want to write a program that does both, but also: > > * Has a cascade of options: default option values, overridden by config > ? file options, overridden by command-line options. > > * Reads a different, or even additional, configuration file if specified > ? on the command-line (e.g. --config-file foo.conf) and yet still obeys > ? the above cascade. > > * Allows a single definition of an option (e.g. logging level) to define > ? the same option for parsing from configuration files and the command > ? line. > > * Unifies the parsed options into a single collection for the rest of > ? the program to access without caring where they came from. > > How can I achieve this with minimum deviation from the Python standard > library? One thought is start with something like ChainMap, http://code.activestate.com/recipes/305268-chained-map-lookups/?in=user-178123 , or some variant to unify multiple mapping objects into a single prioritized collection. A mapping for command line args can be made by using vars() on an argparse namespace to create a dictionary. ConfigParser's mapping is accessible via its get() method. With a ChainMap style object you can add other option sources such as os.environ. This should get you started on your grand unified, do- everything-at-once vision with minimal deviation from the standard library. Raymond From clp2 at rebertia.com Thu May 26 01:17:45 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 25 May 2011 22:17:45 -0700 Subject: Puzzled by list-appending behavior In-Reply-To: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: On Wed, May 25, 2011 at 9:46 PM, Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] > list.append ( [4,5,6] ) Note the lack of output after this line. This indicates that list.append([4,5,6]) returned None. Contrast this with, say, list.pop(). > x = list > x ? -> > ? ?[1,2,3,[4,5,6]] > as expected. > > But the shortcut fails: > > list=[1,2,3] > x = list.append( [4,5,6] ) > x ? -> > ? nothing > > Can someone explain this to me? The append() method does *not* return the now-appended-to list. It is a mutator method that modifies the list object in-place; per convention, it therefore returns None to reinforce its side-effecting nature to the user (the interactive interpreter by default does not display None expression results); analogous methods in other languages return void. list.remove(), list.sort(), and list.extend() similarly return None rather than the now-modified list. Cheers, Chris -- http://rebertia.com From r.richardparker at comcast.net Thu May 26 02:40:30 2011 From: r.richardparker at comcast.net (Richard Parker) Date: Wed, 25 May 2011 23:40:30 -0700 Subject: Python-list Digest, Vol 92, Issue 223 In-Reply-To: References: Message-ID: > > On Thu, May 26, 2011 at 10:58 AM, Richard Parker > wrote: >> It's time to stop having flame wars about languages and embrace programmers >> who care enough about possible future readers of their code to thoroughly >> comment it. Comments are far more valuable than the actual language in which >> the code is written, IMHO. > > The problem with comments (and documentation in general) is that they > are often imperfect. If the code is absolutely opaque but it has a > comment next to it, you still have that niggling doubt: has the > comment been updated whenever the code has? Was it even accurate in > the first place? (Comments often say what a piece of code _ought_ to > do, but the code might have a bug in it. And sometimes, that bug ends > up being part of the function's definition, and people depend on it.) > I'd rather have both - reasonably readable code AND a comment, where > the comment explains the intent behind the code. Gee...I absolutely agree! I have no problem with anything you said. My intent in writing at all was to express that comments (along with well-written code) are more important than the language in which the code is written. There's no doubt that sometimes comments aren't updated when code is changed and sometimes comments express what the code is attempting to implement; however, code in any language written without accompanying comments is much harder to understand AND maintain. If, given a chunk of readable Python code written by someone else without accompanying comments, I would be scratching my head far longer trying to understand, modify, or maintain it, than if it also had (even imperfect) accompanying comments. So--we agree that reasonably readable code AND a comment that explains the intent of the code is what we should all strive to produce. -------------- next part -------------- An HTML attachment was scrubbed... URL: From akabaila at pcug.org.au Thu May 26 03:18:36 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Thu, 26 May 2011 17:18:36 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: <201105261718.36646.akabaila@pcug.org.au> On Thursday 26 May 2011 14:46:45 Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] > list.append ( [4,5,6] ) > x = list > x -> > [1,2,3,[4,5,6]] > as expected. > > But the shortcut fails: > > list=[1,2,3] > x = list.append( [4,5,6] ) > x -> > nothing > > Can someone explain this to me? > > Uncle Ben And why do you insist on calling and instance of list, "list"? Even a human reader will confuse which is which. What you are showing is an example how confusing things become when a keyword (list) is over-written (with list instance). Why don't you just say lst = [1, 2, 3] rather than list =... It may be permissible, but it is not a good idea! Old (practical) Al. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 26 03:20:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 17:20:53 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 2:46 PM, Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] Ben Finney has already answered the main question, but as a side point, I would generally avoid creating a variable called 'list'. That's the name of the type (Python 2) or class (Python 3) of all lists, so it might result in confusion if you have an actual list with that name. If you want the behaviour of joining two lists (or adding something to a list) and saving the result elsewhere, you can use the plain addition: a=[1,2,3] b=a+[[4,5,6]] Note that you have to add a list, and it will append the contents of that list. Chris Angelico From rosuav at gmail.com Thu May 26 03:23:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 17:23:01 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 5:20 PM, Chris Angelico wrote: > > Ben Finney has already answered the main question Giving credit where credit's due, it was more Chris Rebert's post that answered the question. Sorry Chris! Chris Angelico From bgreen at nycap.rr.com Thu May 26 03:33:44 2011 From: bgreen at nycap.rr.com (Uncle Ben) Date: Thu, 26 May 2011 00:33:44 -0700 (PDT) Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: On May 26, 12:46?am, Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] > list.append ( [4,5,6] ) > x = list > x ? -> > ? ? [1,2,3,[4,5,6]] > as expected. > > But the shortcut fails: > > list=[1,2,3] > x = list.append( [4,5,6] ) > x ? -> > ? ?nothing > > Can someone explain this to me? > > Uncle Ben Thank you all. It is wonderful to have this community as a resource. Uncle Ben From s.selvamsiva at gmail.com Thu May 26 04:00:18 2011 From: s.selvamsiva at gmail.com (Selvam) Date: Thu, 26 May 2011 13:30:18 +0530 Subject: Hotshoting recursive function In-Reply-To: References: Message-ID: On Wed, May 25, 2011 at 2:20 PM, Gabriel Genellina wrote: > En Sun, 22 May 2011 10:42:08 -0300, Selvam > escribi?: > > > I am using hotshot module to profile my python function. >> >> I used the details from ( >> >> http://code.activestate.com/recipes/576656-quick-python-profiling-with-hotshot/ >> ). >> >> The function I profile is a recursive one and I am getting the following >> error, >> >> "ProfilerError: profiler already active" >> >> I guess this is due to the recursive call to the profiling function. >> >> I would like to get some suggestions. >> > > The recursive call inside your function should call the undecorated > function, not the decorated function again. Decorator syntax is not > convenient anymore. > > Using the same names as in the recipe example: > > > # a recursive function > def my_slow_function(n): > ... > return my_slow_function(n-1) > > > my_profiled_slow_function = hotshotit(my_slow_function) > my_profiled_slow_function(n) > > > This works, in the sense that it does not raise ProfileError anymore. > Interpreting profile data is up to you... > > > Thanks Gabriel, it makes more sense ! > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards, S.Selvam SG E-ndicus Infotech Pvt Ltd. http://e-ndicus.com/ " I am because we are " -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu May 26 04:09:42 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 May 2011 01:09:42 -0700 Subject: Puzzled by list-appending behavior In-Reply-To: References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 12:23 AM, Chris Angelico wrote: > On Thu, May 26, 2011 at 5:20 PM, Chris Angelico wrote: >> >> Ben Finney has already answered the main question > > Giving credit where credit's due, it was more Chris Rebert's post that > answered the question. Sorry Chris! Eh, one can't fight chronology! I'm just surprised that the docstring doesn't explicitly state "Returns None." by this point, given that this is such a common point of newbie confusion. Cheers, Chris From thorsten at thorstenkampe.de Thu May 26 04:24:06 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 26 May 2011 10:24:06 +0200 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> Message-ID: * John Bokma (Wed, 25 May 2011 07:01:07 -0500) > Thorsten Kampe writes: > > * Chris Angelico (Wed, 25 May 2011 08:01:38 +1000) > >> > >> On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain wrote: > >> > One of my favorite quotes (not sure if it was about Perl or APL) is > > "I > >> > refuse to use a programming language where the proponents of it stick > >> > snippets under each other's nose and say 'I bet you can't guess what > >> > this does.'" > >> > >> Yes, I believe that was Perl. And an amusing quote. But most of the > >> point of it comes from the fact that Perl uses punctuation for most of > >> its keywords, whereas (say) Python uses English words; it's a lot more > >> fun to crunch something down when you can use $| and friends than when > >> you have to put "x and y", complete with spaces, for a simple boolean. > >> But that says nothing about which language is actually better for > >> working with... [...] > > > > It does say something about readibility. And yes, "readability counts". > > And yes, readability says a lot about how good a language is for reading > > and working with. > > To people used to the latin alphabet languages using a different script > are unreadable. So readability has a lot to do with what one is used > to. You've made that "alphabet" argument more than once. Nevertheless it's nonsense (sorry). Perl uses the same alphabet as Python. Only the "words" Perl uses ("$|" for instance) are only found in a Perl dictionary not in a English or math dictionary like the one that Python uses. That's why you can /read/ Python but you have to /decode/ Perl to understand the source code. > Like I already stated before: if Python is really so much better than > Python readability wise, why do I have such a hard time dropping Perl > and moving on? What kind of argument is that? Thorsten From thorsten at thorstenkampe.de Thu May 26 04:48:07 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 26 May 2011 10:48:07 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Steven D'Aprano (25 May 2011 21:59:58 GMT) > On Wed, 25 May 2011 09:26:11 +0200, Thorsten Kampe wrote: > > > Naming something in the terms of its implementation details (in this > > case recursion) is a classical WTF. > > *If* that's true, it certainly doesn't seem to apply to real-world > objects. Think about the exceptions: > > microwave oven > vacuum cleaner > oven fries > electric car > chain saw > flintlock rifle > air gun > vulcanised rubber > kerosene heater > aluminium foil > diamond saw > gas stove > wood stove > four-wheel drive car > incandescent light bulb > electric razor > unleaded petrol > > to mention only a few. > > Naming the thing after the implementation would often seem to be *good > advice*, not bad. We often do care about implementations. You really do > need to know whether the car you drive uses leaded or unleaded. That's exactly the point. You don't need to know whether "include sub- directories" was implemented recursively. It's absolutely pointless. But not to digress, the /real/ problem with commands or idioms like "rm -r" is /not/ their choice of option names but that they explain these options in the exact same terms. No one would have a problem with "-r, --recursive -- remove directories including all sub-directories" instead of "-r, --recursive -- remove directories and their contents recursively". Thorsten From thorsten at thorstenkampe.de Thu May 26 04:59:19 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 26 May 2011 10:59:19 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Steven D'Aprano (25 May 2011 22:58:21 GMT) > > On Wed, 25 May 2011 00:06:06 +0200, Rikishi42 wrote: > > > What I mean is: I'm certain that over the years I've had more than one > > person come to me and ask what 'Do you wish to delete this directory > > recursively?' meant. BAut never have I been asked to explain what 'Do > > you wish to delete this directory and it's subdirs/with all it's > > contents?' meant. Never. > > I know many people who have no idea what a directory is, let alone a > subdirectory, unless it's the phone directory. They're non-computer > users. Once they start using computers, they quickly work out what the > word means in context, or they ask and get told, and then they've learned > a new word and never need ask again. This is a good thing. > > The idiom of "recursively delete" is no different. Of course some people > will have to learn a new term in order to make sense of it. So what? It's not just a "new term". It tries to describe something which could be easily described in the terms of what is already known. If someone has learned what a directory or folder is, you don't have to explain what "include sub-folders" means. Instead of creating a new mysterious term ("recursively delete"), you simply explain stuff by re- using an already existing term. It's just that simple. Thorsten From steve+comp.lang.python at pearwood.info Thu May 26 06:06:44 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 May 2011 10:06:44 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dde2634$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 10:48:07 +0200, Thorsten Kampe wrote: > But not to digress, the /real/ problem with commands or idioms like "rm > -r" is /not/ their choice of option names but that they explain these > options in the exact same terms. No one would have a problem with "-r, > --recursive -- remove directories including all sub-directories" instead > of "-r, --recursive -- remove directories and their contents > recursively". I think you are understanding the description "remove directories and their contents recursively" as a description of the *mechanism* by which rm removes the directory, i.e. some recursive tree-walking function that visits each node and deletes it. I don't believe that's how the description is meant to be understood. I understand it as describing the effect, not the implementation. If the tree-walker was re-written to be iterative, the description would not need to be changed. It is meant to be understood as: rm -r foo * deletes foo * deletes things inside foo * if any of those things inside foo are directories, delete them too, in exactly the same way (i.e. "recursively"). Notice that, strictly speaking, the description is impossible. You can't delete the top level directory first. But that's how the human reader will understand it: * delete the directory you point it at, plus the things inside it in the same way rather than how the implementation (probably) does it: * drill down all the way to the bottom, start deleting like mad, and work your way back up the stack, deleting as you go. You're interpreting the reference to "recursive" as a nod to the implementation. I'm not, and therefore your arguments don't convince me. -- Steven From steve+comp.lang.python at pearwood.info Thu May 26 06:07:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 May 2011 10:07:24 GMT Subject: Python-list Digest, Vol 92, Issue 221 References: Message-ID: <4dde265c$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 14:06:56 +1000, Chris Angelico wrote: > On Thu, May 26, 2011 at 10:58 AM, Richard Parker > wrote: >> It's time to stop having flame wars about languages and embrace >> programmers who care enough about possible future readers of their code >> to thoroughly comment it. Comments are far more valuable than the >> actual language in which the code is written, IMHO. > > The problem with comments (and documentation in general) is that they > are often imperfect. [snip more stuff I agree with] It's not the lack of perfection, since no code is perfect, but that comments are frequently missing, obsolete, incorrect, or inane: i.e. actively harmful rather than just imperfect. The classic example of what not to write as a comment: x += 1 # add one to x One of the regulars here -- Aahz -- often has this quote as his sig: "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'." -- Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22 My experience is that comments in Python are of relatively low usefulness. (For avoidance of doubt: not *zero* usefulness, merely low.) I can name variables, functions and classes with sensible, self- documenting names. Why write: x = get_results(arg) # x is a list of 1 or more results [... much later] for y in x: # process each result in turn do_something_with(y) when I can write this? results = get_results(arg) [...] for result in results: do_something_with(result) It's better to write self-documenting code, than code + comments. Another use for comments is to explain *why* rather than *what*. No matter how readable your code is, if you don't understand why it is done, you can't effectively maintain it. If the why is obvious, you don't need a comment. But for me, the main reason # comments are of relatively little use in Python for me is because I write *tons* of docstrings and doctests. Any comment which could be useful to know at run-time goes into the docstring; what's left over, if anything, becomes a # comment. Between self-documenting code and docstrings, I hardly write any # comments. -- Steven From rosuav at gmail.com Thu May 26 06:25:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 20:25:29 +1000 Subject: Python-list Digest, Vol 92, Issue 221 In-Reply-To: <4dde265c$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4dde265c$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 26, 2011 at 8:07 PM, Steven D'Aprano wrote: > Another use for comments is to explain *why* rather than *what*. No > matter how readable your code is, if you don't understand why it is done, > you can't effectively maintain it. If the why is obvious, you don't need > a comment. That's what my (contrived) example was. I also often have comments that are leftovers from the pseudocode stage; for instance, iteration 1: //TODO: Look up foo in some table and figure out which bar should be used. Iteration 2: //TODO: Look up foo in the bar_foo table and figure out which bar should be used. legal_bar = bar_foo[foo]; bar=legal_bar[0]; Iteration 3: //Figure out which bar should be used legal_bar = bar_foo[foo]; ... some algorithmic way of figuring out the best one ... When it leaves TODO status, anything that's inherently obvious ("Look up foo in the bar_foo table") gets trimmed, but the statements of purpose tend to remain. Especially if the "figuring out the best one" is several lines of code, it makes sense to keep that comment. But because of the organic growth of the code, the comment will usually still bracket the "look up foo in table" part, even though the comment doesn't have anything to do with that. Is the comment inappropriate? I don't think so. Is it perfect? Definitely not. But it's still generally worth keeping. But I absolutely agree. The code ought to be self-documenting to the greatest extent possible (but no further - don't just create variables/constants for absolutely no reason than to embody documentation). Docstrings and autodoc comments are superior to general comments, although IMHO all three are pretty much the same thing. Chris Angelico From claird271 at gmail.com Thu May 26 06:27:13 2011 From: claird271 at gmail.com (Cameron Laird) Date: Thu, 26 May 2011 03:27:13 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (May 26) Message-ID: <384a86e5-191a-4cbf-b46a-75be7cf15341@gu8g2000vbb.googlegroups.com> [This edition drafted by Gabriel Genellina.] QOTW: "They did a study once to determine the best tool for development. Turns out that the most productive tool was generally the one that the user believed was the most productive. In hindsight I think that that was rather obvious." - D'Arcy J.M. Cain, 2011-05-24 Python 2.6.7 release candidate 2 now available: http://groups.google.com/group/comp.lang.python/t/ebbd57431bb084b2/ Amazing logic: and becomes or and or becomes and http://groups.google.com/group/comp.lang.python/t/b13e786438a609dd/ Equal objects must have equal hashes - but how strong is that requirement? http://groups.google.com/group/comp.lang.python/t/f23f72cf633892f9/ Do secure systems exist? http://groups.google.com/group/comp.lang.python/t/f887168ca476618f/7503714d82b1789b?#7503714d82b1789b os.access() returns totally useless results on Windows, always has, and nobody cares: http://groups.google.com/group/comp.lang.python/t/aa3d9b21c77fa7d7/ Is this PAAS Python mind-blowingly important, or pointless, or a mix of the two? http://www.activestate.com/cloud contextlib.nested() is deprecated - and this example shows why a custom implementation is hard to write well: http://groups.google.com/group/comp.lang.python/t/d6b090b7fd4a92c6/ Why one startup chose Python for development: http://groups.google.com/group/comp.lang.python/t/17dca3bf467c9001/ And more reasons another developer chose it: http://groups.google.com/group/comp.lang.python/t/17dca3bf467c9001/83a7be235c113dac?#83a7be235c113dac And now, things people do *not* like about Python: http://groups.google.com/group/comp.lang.python/t/fff2826d44ea336/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From thorsten at thorstenkampe.de Thu May 26 06:46:58 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 26 May 2011 12:46:58 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde2634$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Steven D'Aprano (26 May 2011 10:06:44 GMT) > > On Thu, 26 May 2011 10:48:07 +0200, Thorsten Kampe wrote: > > > But not to digress, the /real/ problem with commands or idioms like "rm > > -r" is /not/ their choice of option names but that they explain these > > options in the exact same terms. No one would have a problem with "-r, > > --recursive -- remove directories including all sub-directories" instead > > of "-r, --recursive -- remove directories and their contents > > recursively". > > I think you are understanding the description "remove directories and > their contents recursively" as a description of the *mechanism* by which > rm removes the directory, i.e. some recursive tree-walking function that > visits each node and deletes it. > > I don't believe that's how the description is meant to be understood. I > understand it as describing the effect, not the implementation. It doesn't matter how I interprete the explanation "-r = recursively delete". What matters is that I have to explain (interpret, translate the explanation. > You're interpreting the reference to "recursive" as a nod to the > implementation. I'm not, and therefore your arguments don't convince > me. No one understands what "recursively delete" means until someone explains ("translates") it to him. This is not an argument but a simple fact. I experienced it many times, others here in the thread did and probably you, too. "recursively delete" is completely unneccessary because there is already a simple explanation that everyone understands without translation ("delete including subdirectories"). It's unnecessary bullshit buzzword bingo from nerds which adds or helps or explains nothing. It's just that simple. Thorsten From C.Sanders at DeleteThis.Bom.GOV.AU Thu May 26 06:58:35 2011 From: C.Sanders at DeleteThis.Bom.GOV.AU (Charles) Date: Thu, 26 May 2011 20:58:35 +1000 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> "Thorsten Kampe" wrote in message news:MPG.284834d227e3acd1989813 at news.individual.de... > > If someone has learned what a directory or folder is, you don't have to > explain what "include sub-folders" means. Instead of creating a new > mysterious term ("recursively delete"), you simply explain stuff by re- > using an already existing term. It's just that simple. I'm a native english speaker, and to me there is a difference between "delete directory and sub-directories" (or folders and sub-folders if you follow Microsoft's naming conventions) and "recursively delete". I know english is very ambiguous, but to me "directory and sub-directories" does not necessarily imply sub-directories of sub-directories and so on, while "recursively delete" does carry the connotation of deleting the sub-directories of sub-directories and sub-directories of sub-directories of sub-directories and so on. Charles From rosuav at gmail.com Thu May 26 07:12:39 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 21:12:39 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: I just conducted a rapid poll of a non-technical userbase. (Okay, I just asked my sister who happens to be sitting here. But she's nontechnical.) She explained "recursive" as "it repeats until it can't go any further". I think that's a fair, if not perfectly accurate, explanation. Actually... if we accept that one iteration is deleting all files from one depth level, then yes, the algorithm repeats that operation. And I'm using "iteration" here without implying that it's an iterative function. Chris Angelico From thorsten at thorstenkampe.de Thu May 26 07:20:43 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 26 May 2011 13:20:43 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: * Charles (Thu, 26 May 2011 20:58:35 +1000) > "Thorsten Kampe" wrote in message > news:MPG.284834d227e3acd1989813 at news.individual.de... > > > > If someone has learned what a directory or folder is, you don't have > > to explain what "include sub-folders" means. Instead of creating a > > new mysterious term ("recursively delete"), you simply explain stuff > > by re- using an already existing term. It's just that simple. > > I'm a native english speaker, and to me there is a difference between > "delete directory and sub-directories" (or folders and sub-folders if > you follow Microsoft's naming conventions) and "recursively delete". I > know english is very ambiguous, but to me "directory and > sub-directories" does not necessarily imply sub-directories of > sub-directories and so on, Are we playing word games here? You can easily improve my example to "delete directory and all sub-directories beneath". Or "delete directory and all sub-directories beneath and all content". Or "delete directory and all files and directories within". > while "recursively delete" does carry the connotation of deleting the > sub-directories of sub-directories and sub-directories of > sub-directories of sub-directories and so on. Sure. Because you already know what it means (someone has already translated it to you long time ago). Did your mom tell you to "recursively clean up your room"?. Does my file manager ask me "are you sure you want to recursively delete the folder?"? No, it asks 'are you sure you want to remove folder "folder name" and all its contents?'. Thorsten From rosuav at gmail.com Thu May 26 07:28:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 21:28:20 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: On Thu, May 26, 2011 at 9:20 PM, Thorsten Kampe wrote: > Did your mom tell you to "recursively clean up your room"?. > Considering that I don't have a wardrobe with a portal to Narnia, no, she has never had to tell me to clean up the room inside my room. Anyway, my room's full. There's no room in it anywhere. :) Chris Angelico From truongxuanquang at yahoo.com Thu May 26 07:48:34 2011 From: truongxuanquang at yahoo.com (truongxuan quang) Date: Thu, 26 May 2011 04:48:34 -0700 (PDT) Subject: Question about isodate Message-ID: <324535.36827.qm@web114716.mail.gq1.yahoo.com> Hello list, I am installing and testing istSOS wrote base on Python with its extension like gdal, isodate, easy istall, setuptool, psycopg. I have already installed all these stuff when I was using method POST the error appear is "No module named mx.DateTime.ISO" , could you please give me your command and advice. Many thanks Quang -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Thu May 26 08:44:47 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 26 May 2011 12:44:47 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> Message-ID: <94709uF99gU5@mid.individual.net> On 2011-05-25, Matty Sarro wrote: > General readability is a farce. If it was true we would only > have one section to the library. Different people enjoy > reading, and can comprehend better in different ways. THat's > why some people are super verbose - hell, just look at this > here post! :) Despite individual proclivities, there remain standards of readability enshrined in our dictionaries and grammar handbooks. Claiming that code readability of code is to be judged solely subjectively by each individual absolves code of the responsibility to communicate to more than just its author. -- Neil Cerutti From roy at panix.com Thu May 26 08:51:48 2011 From: roy at panix.com (Roy Smith) Date: Thu, 26 May 2011 08:51:48 -0400 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> <94709uF99gU5@mid.individual.net> Message-ID: In article <94709uF99gU5 at mid.individual.net>, Neil Cerutti wrote: > On 2011-05-25, Matty Sarro wrote: > > General readability is a farce. If it was true we would only > > have one section to the library. Different people enjoy > > reading, and can comprehend better in different ways. THat's > > why some people are super verbose - hell, just look at this > > here post! :) > > Despite individual proclivities, there remain standards of > readability enshrined in our dictionaries and grammar handbooks. > Claiming that code readability of code is to be judged solely > subjectively by each individual absolves code of the > responsibility to communicate to more than just its author. Also, the purpose of source code is to transmit information (to both the compiler and to human readers). That is a much narrower purpose than is served by books in a library, many of which are written as entertainment. Sometimes, the real enjoyment (in literature) comes in figuring out what the author really meant. From ben+python at benfinney.id.au Thu May 26 09:11:09 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 May 2011 23:11:09 +1000 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> <94709uF99gU5@mid.individual.net> Message-ID: <874o4hbo9e.fsf@benfinney.id.au> Roy Smith writes: > Also, the purpose of source code is to transmit information (to both > the compiler and to human readers). And the relative importance of readability for those two purposes is often misunderstood. Composing source code so that the *machine* will understand it is one thing, and can be unambiguously verified. Composing the same source code so that its meaning will be clearly transmitted to *other humans* is quite another matter: certainly more difficult, and arguably far more important: ?Programs must be written for people to read, and only incidentally for machines to execute.? ?Abelson & Sussman, _Structure and Interpretation of Computer Programs_ > Sometimes, the real enjoyment (in literature) comes in figuring out > what the author really meant. Right. Unlike that kind of writing, in functional code like a computer program, ambiguity of meaning is a curse. Programmers, if you feel the urge to be subtle and clever and nuanced, take up poetry or literature as a separate pursuit. In your program source code, please be as straightforward and unambiguous and predictable as possible. -- \ ?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 Thu May 26 09:35:10 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 May 2011 13:35:10 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> <94709uF99gU5@mid.individual.net> Message-ID: <4dde570e$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 12:44:47 +0000, Neil Cerutti wrote: > On 2011-05-25, Matty Sarro wrote: >> General readability is a farce. If it was true we would only have one >> section to the library. Different people enjoy reading, and can >> comprehend better in different ways. THat's why some people are super >> verbose - hell, just look at this here post! :) > > Despite individual proclivities, there remain standards of readability > enshrined in our dictionaries and grammar handbooks. Claiming that code > readability of code is to be judged solely subjectively by each > individual absolves code of the responsibility to communicate to more > than just its author. Bravo! +1 Quote of the Thread -- Steven From theller at ctypes.org Thu May 26 11:02:30 2011 From: theller at ctypes.org (Thomas Heller) Date: Thu, 26 May 2011 17:02:30 +0200 Subject: List of WindowsError error codes and meanings In-Reply-To: References: Message-ID: <9478c6Fr09U1@mid.individual.net> Am 20.05.2011 19:56, schrieb Andrew Berg: > This is probably somewhat off-topic, but where would I find a list of > what each error code in WindowsError means? WindowsError is so broad > that it could be difficult to decide what to do in an except clause. > Fortunately, sys.exc_info()[1][0] holds the specific error code, so I > could put in an if...elif...else clause inside the except clause if I > needed to, but I don't know what all the different errors are. On Windows, you can use ctypes.FormatError(code) to map error codes to strings: >>> import ctypes >>> ctypes.FormatError(32) 'Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird.' >>> For HRESULT codes, you (unfortunately) have to subtract 2**32-1 from the error code: >>> ctypes.FormatError(0x80040005) Traceback (most recent call last): File "", line 1, in OverflowError: long int too large to convert to int >>> ctypes.FormatError(0x80040005 - (2**32-1)) 'Kein Cache zum Verarbeiten vorhanden.' >>> Thomas From thegist at nospam.net Thu May 26 11:05:56 2011 From: thegist at nospam.net (thegist at nospam.net) Date: Thu, 26 May 2011 11:05:56 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <4ddd963c$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <72183$4ddd7506$ce534406$5707@news.eurofeeds.com> <4ddd963c$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1ec5d$4dde6c53$ce534406$30768@news.eurofeeds.com> On 5/25/2011 7:52 PM, Steven D'Aprano wrote: > On Wed, 25 May 2011 17:30:48 -0400, thegist at nospam.net wrote: > >> On 5/24/2011 1:39 PM, D'Arcy J.M. Cain wrote: [snip] >>> One of my favorite quotes (not sure if it was about Perl or APL) is "I >>> refuse to use a programming language where the proponents of it stick >>> snippets under each other's nose and say 'I bet you can't guess what >>> this does.'" >> I dunno. That sounds about like how most programming course exams are >> written, no? >> The point is that puzzling through arcane bits of code are crucial to >> learning >> any language. It's a valuable exercise. > > You seem to miss the point that a good language shouldn't make it > possible to write arcane code that needs to be puzzled out. You seem to be inventing a new point. Try to stay focused please. Perl hackers show each other arcane bits of code because such impractical puzzle programs are good for learning. Such puzzles can be created in any language. For example, I have had formal coursework in a number of languages (Pascal, C++, ML, Scheme, and others) and in each one an important exercise was to puzzle through arcane bits of code in each of those languages. The post I was replying to seemed to question the value of such 'I bet you can't guess what this does.' type challenges. From john at castleamber.com Thu May 26 11:36:30 2011 From: john at castleamber.com (John Bokma) Date: Thu, 26 May 2011 10:36:30 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> Message-ID: <878vttv5hd.fsf@castleamber.com> Ben Finney writes: >> Get a life. Or better, just fuck off and die. It will improve both the >> world and the Python community, of which you are nothing but a little, >> smelly shitstain. > > That abuse is entirely unwelcome in this community, against any person. > Please desist. You should have spoken up sooner, especially as the spokes person of "this" community. But every bully has is fan club. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From thegist at nospam.net Thu May 26 11:52:36 2011 From: thegist at nospam.net (thegist at nospam.net) Date: Thu, 26 May 2011 11:52:36 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: <8a22e$4dde7742$ce534406$29334@news.eurofeeds.com> So when quora.com fails we can all say it is Python's fault? Maybe they should have focused more on content instead of the bits under the hood? From python at mrabarnett.plus.com Thu May 26 11:58:25 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 May 2011 16:58:25 +0100 Subject: Puzzled by list-appending behavior In-Reply-To: References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: <4DDE78A1.9070305@mrabarnett.plus.com> On 26/05/2011 06:17, Chris Rebert wrote: > On Wed, May 25, 2011 at 9:46 PM, Uncle Ben wrote: >> In playing with lists of lists, I found the following: >> >> (In 3.1, but the same happens also in 2.7) >> >> list = [1,2,3] >> list.append ( [4,5,6] ) > > Note the lack of output after this line. This indicates that > list.append([4,5,6]) returned None. Contrast this with, say, > list.pop(). > >> x = list >> x -> >> [1,2,3,[4,5,6]] >> as expected. >> >> But the shortcut fails: >> >> list=[1,2,3] >> x = list.append( [4,5,6] ) >> x -> >> nothing >> >> Can someone explain this to me? > > The append() method does *not* return the now-appended-to list. It is > a mutator method that modifies the list object in-place; per > convention, it therefore returns None to reinforce its side-effecting > nature to the user (the interactive interpreter by default does not > display None expression results); analogous methods in other languages > return void. > > list.remove(), list.sort(), and list.extend() similarly return None > rather than the now-modified list. > I'd just like to point out that it's a convention, not a rigid rule. Sometimes it's not followed, for example, dict.setdefault. From rosuav at gmail.com Thu May 26 12:04:00 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 02:04:00 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: <4DDE78A1.9070305@mrabarnett.plus.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <4DDE78A1.9070305@mrabarnett.plus.com> Message-ID: On Fri, May 27, 2011 at 1:58 AM, MRAB wrote: > I'd just like to point out that it's a convention, not a rigid rule. > Sometimes it's not followed, for example, dict.setdefault. dict.setdefault is more like dict.get but it also stores the result. It's probably more a name issue than a protocol issue. Chris Angelico From ethan at stoneleaf.us Thu May 26 12:18:12 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 26 May 2011 09:18:12 -0700 Subject: Why did Quora choose Python for its development? In-Reply-To: <874o4i17zi.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> Message-ID: <4DDE7D44.3000409@stoneleaf.us> John, You say English is not your first language. Let me assure you that the words you chose to use in reply to Stephen were vulgar as well as rude, and did more to lesson the overall friendliness of this forum than Stephen's adversarial style. You usually have interesting and informative posts -- please don't resort to this tactic. ~Ethan~ From nagle at animats.com Thu May 26 12:29:54 2011 From: nagle at animats.com (John Nagle) Date: Thu, 26 May 2011 09:29:54 -0700 Subject: Newbie question about SQLite + Python and twitter In-Reply-To: References: Message-ID: <4dde8006$0$2159$742ec2ed@news.sonic.net> On 5/25/2011 6:08 PM, Philip Semanchuk wrote: > > On May 25, 2011, at 2:17 PM, Jayme Proni Filho wrote: > >> Helo guys, >> >> I'm building a local application for twitter for my brother's store. I'm in >> the beginning and I have some newbie problems, so: >> >> I create a table called tb_messages with int auto increment and varchar(140) >> fields; >> I did three SQL funcionts, insert_tweet, delete_tweet, select_tweet >> >> select_tweet is use for getting messages for sending them to twitter; >> >> My problem is: How can i make my select_tweet works at the same time that >> insert or delete funcions. I just got to work when I stop select function. >> >> I would like to do my app works all the time. > > Hi Jayme, > You need to provide a lot more information for us to be able to help you. I suspect that the original poster's problem is that he's trying to delete items from a table while reading the results from a SELECT on the same table. SQL systems don't allow that. It has the same problem as, in Python, deleting from a dict while iterating over it. One way to do this properly is something like loop START TRANSACTION SELECT itemid, item FROM tablename WITH ... LIMIT 1 get one item if no item, break do whatever needs to be done with item DELETE FROM tablename WHERE itemid = %s END TRANSACTION Also, it sounds like he's writing a spam program for Twitter. John Nagle From python at rcn.com Thu May 26 12:31:18 2011 From: python at rcn.com (Raymond Hettinger) Date: Thu, 26 May 2011 09:31:18 -0700 (PDT) Subject: Python's super() considered super! Message-ID: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> I just posted a tutorial and how-to guide for making effective use of super(). One of the reviewers, David Beazley, said, "Wow, that's really great! I see this becoming the definitive post on the subject" The direct link is: http://rhettinger.wordpress.com/2011/05/26/super-considered-super/ It would also be great if some of you would upvote it on HackerNews. Raymond Hettinger ----------------------- follow my python tips on twitter: @raymondh From python at rcn.com Thu May 26 12:39:42 2011 From: python at rcn.com (Raymond Hettinger) Date: Thu, 26 May 2011 09:39:42 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> > It would also be great if some of you would upvote it on HackerNews. Here's a link to the super() how-to-guide and commentary: bit.ly/ iFm8g3 Raymod From alister.ware at ntlworld.com Thu May 26 13:50:41 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Thu, 26 May 2011 17:50:41 GMT Subject: pyGTK identify a button References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Message-ID: On Wed, 25 May 2011 10:18:48 +0200, Tracubik wrote: > Hi all, > i'm trying to write a simple windows with two button in GTK, i need a > way to identify wich button is pressed. Consider that: > > the two button are connected (when clicked) to infoButton(self, widget, > data=None) > > infoButton() is something like this > > infoButton(self, widget, data=None): > # discover wich button was pressed > ... > # say hello to the button > if button1pressed: > print "Hi, button1!" > else: > print "Hi, button2!" > > so, how can I know wich button was pressed without using data and > without reading the label of the button (i could have buttons with the > same label) > > If data is needed, can someone pls tell me how to set it properly in > glade 3.8 > > thanks > Nico This looks similar to a question I posted about 2 weeks ago In gtk 2.1.6 (i think) & earlier you could use widget.get_name() to return the id of the widget. this no-longer works since 2.1.7 the pygtk forum suggests this is because widget id's are not necessarily unique & caused problems elsewhere, to be honest most of the explanation went above my head. I did find a work around & that was to use gtk.buildable.get_name(widget) but is is probably cleaner to use a discrete callback for each button. -- Disco is to music what Etch-A-Sketch is to art. From dotancohen at gmail.com Thu May 26 14:13:09 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Thu, 26 May 2011 21:13:09 +0300 Subject: Python's super() considered super! In-Reply-To: <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 19:39, Raymond Hettinger wrote: >> It would also be great if some of you would upvote it on HackerNews. > > > Here's a link to the super() how-to-guide and commentary: ?bit.ly/ > iFm8g3 > Is that the same link as in the OP? I don't click on blind links, so if it isn't then please post a direct link. Thanks. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From ladasky at my-deja.com Thu May 26 14:27:35 2011 From: ladasky at my-deja.com (John Ladasky) Date: Thu, 26 May 2011 11:27:35 -0700 (PDT) Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> On May 25, 9:46?pm, Uncle Ben wrote: > list = [1,2,3] Somewhat unrelated, but... is it a good idea to name your list "list"? Isn't that the name of Python's built-in list constructor method? Shadowing a built-in has contributed to more than one subtle bug in my code, and I've learned to avoid it. From ian.g.kelly at gmail.com Thu May 26 14:38:22 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 26 May 2011 12:38:22 -0600 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 12:13 PM, Dotan Cohen wrote: > On Thu, May 26, 2011 at 19:39, Raymond Hettinger wrote: >>> It would also be great if some of you would upvote it on HackerNews. >> >> >> Here's a link to the super() how-to-guide and commentary: ?bit.ly/ >> iFm8g3 >> > > Is that the same link as in the OP? I don't click on blind links, so > if it isn't then please post a direct link. Thanks. It's a link to ycombinator: http://news.ycombinator.com/item?id=2588262 From tjreedy at udel.edu Thu May 26 14:44:52 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 May 2011 14:44:52 -0400 Subject: Puzzled by list-appending behavior In-Reply-To: <201105261718.36646.akabaila@pcug.org.au> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <201105261718.36646.akabaila@pcug.org.au> Message-ID: On 5/26/2011 3:18 AM, Algis Kabaila wrote: > And why do you insist on calling an instance of list, "list"? Even a > human reader will confuse which is which. What you are showing is an > example how confusing things become when a keyword (list) is > over-written (with list instance). (Minor note: 'list' is not a keyword (if it were, it could not be over-ridden) but it is a builtin.) You are correct, it is confusing. Such usage will also lead to bugs if one ever tries to access the class as 'list' later in the program. Here is a legitimate usage of builtins masking: import builtins def list(iterable): print('building list from {}: {}'.format(type(iterable),iterable)) return builtins.list(iterable) a = list((1,2,3)) b = list({1,2,3}) ### building list from : (1, 2, 3) building list from : {1, 2, 3} -- Terry Jan Reedy From r.richardparker at comcast.net Thu May 26 14:50:25 2011 From: r.richardparker at comcast.net (Richard Parker) Date: Thu, 26 May 2011 11:50:25 -0700 Subject: The worth of comments In-Reply-To: References: Message-ID: <1CCA9F21-28E8-43CF-BBE0-D4080D1E6993@comcast.net> On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: > My experience is that comments in Python are of relatively low > usefulness. (For avoidance of doubt: not *zero* usefulness, merely low.) > I can name variables, functions and classes with sensible, self- > documenting names. Why write: > > x = get_results(arg) # x is a list of 1 or more results > [... much later] > for y in x: > # process each result in turn > do_something_with(y) (It occurred to me that I should use a specific subject for this discussion.) I'm less inclined to use comments on each line, or selected lines, but rather use block comments instead. They require more thought and time to write; however, the intended functionality of the code that follows can be described in full. From dotancohen at gmail.com Thu May 26 14:56:50 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Thu, 26 May 2011 21:56:50 +0300 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 21:38, Ian Kelly wrote: > It's a link to ycombinator: > > http://news.ycombinator.com/item?id=2588262 > Thanks. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From ramit.prasad at jpmchase.com Thu May 26 15:34:01 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Thu, 26 May 2011 15:34:01 -0400 Subject: Puzzled by list-appending behavior In-Reply-To: References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <201105261718.36646.akabaila@pcug.org.au> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B0D00@EMARC112VS01.exchad.jpmchase.net> >> And why do you insist on calling an instance of list, "list"? Even a >> human reader will confuse which is which. What you are showing is an >> example how confusing things become when a keyword (list) is >> over-written (with list instance). > (Minor note: 'list' is not a keyword (if it were, it could not be >over-ridden) but it is a builtin.) You are correct, it is confusing. >Such usage will also lead to bugs if one ever tries to access the >class >as 'list' later in the program. An example of overriding built-ins you *really* do not want to happen (python 2.6.4): >>> True = False >>> True == False True >>> print True False From what I can tell, this does not work in Python 3.x (at least not in Python 3.1.1) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From peterirbizon at gmail.com Thu May 26 15:46:02 2011 From: peterirbizon at gmail.com (miamia) Date: Thu, 26 May 2011 12:46:02 -0700 (PDT) Subject: python urllib2 data post over https Message-ID: <8b67a6e5-7a28-4e2c-af2f-f3ff3ccc4da2@k16g2000yqm.googlegroups.com> hello, I am using this code to send data over https with post method: params='tieto data idu na sevrer\n' kamodoslat = "https://domena.tld/script.php" req = urllib2.Request(kamodoslat) req.add_header('User-Agent', 'agent') resp = urllib2.urlopen(req, params) how can I make sure that data were really sent over secured protocol https and all communcation went through https? From tjreedy at udel.edu Thu May 26 16:03:58 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 May 2011 16:03:58 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <878vttv5hd.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> Message-ID: On 5/26/2011 11:36 AM, John Bokma wrote: > Ben Finney writes: >>>> [impolite comment not quoted] >>> Get a life. Or better, just fuck off and die. It will improve both the >>> world and the Python community, of which you are nothing but a little, >>> smelly shitstain. >> >> That abuse is entirely unwelcome in this community, against any person. >> Please desist. > > You should have spoken up sooner, especially as the spokes person of > "this" community. But every bully has is fan club. I agree that the original impolite comment was just that -- impolite -- and perhaps enough so that it should have been spoken out against. But I also agree that the quoted response is at least three times as bad, enough so to understandably push someone to respond. Both comments are atypical here. -- Terry Jan Reedy From tjreedy at udel.edu Thu May 26 16:15:57 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 May 2011 16:15:57 -0400 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> Message-ID: On 5/26/2011 2:13 PM, Dotan Cohen wrote: > On Thu, May 26, 2011 at 19:39, Raymond Hettinger wrote: >>> It would also be great if some of you would upvote it on HackerNews. >> >> >> Here's a link to the super() how-to-guide and commentary: bit.ly/ >> iFm8g3 >> > > Is that the same link as in the OP? I don't click on blind links, so > if it isn't then please post a direct link. Thanks. It is a link to HackerNews http://news.ycombinator.com/item?id=2588262 -- Terry Jan Reedy From karim.liateni at free.fr Thu May 26 16:27:54 2011 From: karim.liateni at free.fr (Karim) Date: Thu, 26 May 2011 22:27:54 +0200 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> Message-ID: <4DDEB7CA.9040601@free.fr> On 05/26/2011 10:03 PM, Terry Reedy wrote: > On 5/26/2011 11:36 AM, John Bokma wrote: >> Ben Finney writes: > > >>>> [impolite comment not quoted] >>>> Get a life. Or better, just fuck off and die. It will improve both the >>>> world and the Python community, of which you are nothing but a little, >>>> smelly shitstain. >>> >>> That abuse is entirely unwelcome in this community, against any person. >>> Please desist. >> >> You should have spoken up sooner, especially as the spokes person of >> "this" community. But every bully has is fan club. > > I agree that the original impolite comment was just that -- impolite > -- and perhaps enough so that it should have been spoken out against. > But I also agree that the quoted response is at least three times as > bad, enough so to understandably push someone to respond. Both > comments are atypical here. > Original one impolite perhaps but only truth could cause such hatred. Cheers From patty at cruzio.com Thu May 26 16:30:10 2011 From: patty at cruzio.com (Patty) Date: Thu, 26 May 2011 13:30:10 -0700 Subject: The worth of comments References: <1CCA9F21-28E8-43CF-BBE0-D4080D1E6993@comcast.net> Message-ID: <763810B8E88E410983404CCEC542FDF0@mycomputer> ----- Original Message ----- From: "Richard Parker" To: Sent: Thursday, May 26, 2011 11:50 AM Subject: The worth of comments > On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: > >> My experience is that comments in Python are of relatively low >> usefulness. (For avoidance of doubt: not *zero* usefulness, merely low.) >> I can name variables, functions and classes with sensible, self- >> documenting names. Why write: >> >> x = get_results(arg) # x is a list of 1 or more results >> [... much later] >> for y in x: >> # process each result in turn >> do_something_with(y) > > (It occurred to me that I should use a specific subject for this > discussion.) > > I'm less inclined to use comments on each line, or selected lines, but > rather use block comments instead. They require more thought and time to > write; however, the intended functionality of the code that follows can be > described in full. > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hello Richard - I was recently complimented in a phone screen interview for including comment blocks exactly as you describe above. Regards, Patty From dan.kluev at gmail.com Thu May 26 17:33:52 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Fri, 27 May 2011 08:33:52 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: On Wed, May 25, 2011 at 3:10 AM, Octavian Rasnita wrote: >> Once again. Suppose we have array of key-value pairs (two-dimensional >> array), > > This is a forced example to fit the way Python can do it with a clean syntax, but I don't think there are cases in which somebody wants to create hashes/dictionaries where the key is not a plain string but an array. > > This is not a rare case, but a case that probably nobody needs, ever. This is far more popular case than converting flat lists into dicts in Python world. In fact, I *never* had need to convert flat list instead of properly structured one. Thats why we have both lists and tuples, after all. Sure, since perl does not support it at all, perl programmers do not use it and resort to idea of "guess which values are keys by index" due to lack of better approach, with need of obscure "=>" pseudo-syntax to cover it up. -- With best regards, Daniel Kluev From tjreedy at udel.edu Thu May 26 17:36:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 May 2011 17:36:22 -0400 Subject: Puzzled by list-appending behavior In-Reply-To: <4DDE78A1.9070305@mrabarnett.plus.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <4DDE78A1.9070305@mrabarnett.plus.com> Message-ID: On 5/26/2011 11:58 AM, MRAB wrote: > On 26/05/2011 06:17, Chris Rebert wrote: >> list.remove(), list.sort(), and list.extend() similarly return None >> rather than the now-modified list. > I'd just like to point out that it's a convention, not a rigid rule. > Sometimes it's not followed, for example, dict.setdefault. The rule for builtin collections is that mutation methods do not return the collection. If there is a member of the collection to return, they return that. Otherwise they return None. list/set.pop and dict.popitem are other mutation methods that have a (former) member to return. The rule applies to special methods like __getitem__ (returns an item) and __setitem__ (returns None). Since a.append(item) is *conceptually* equivalent to a.__setitem(len(a), item) (I know, it raises) and *actually* defined as a.__setitem(len(a):len(a), item), it should not be surprising that all three return None. I think the above should be better documented. http://bugs.python.org/issue12192 has some proposals. Comments there welcome. In another post On 5/26/2011 4:09 AM, Chris Rebert wrote: > I'm just surprised that the docstring doesn't explicitly state > "Returns None." by this point, given that this is such a common point > of newbie confusion. I never noticed. After reading the above, I added this to the proposal above. -- Terry Jan Reedy From salmig99 at gmail.com Thu May 26 17:50:32 2011 From: salmig99 at gmail.com (sal migondis) Date: Thu, 26 May 2011 17:50:32 -0400 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: On Thu, May 26, 2011 at 12:28 PM, sal migondis wrote: > From: Thorsten Kampe > Subject: Re: English Idiom in Unix: Directory Recursively > Date: Thu, 26 May 2011 12:46:58 +0200 > To: python-list at python.org > > * Steven D'Aprano (26 May 2011 10:06:44 GMT) >> >> On Thu, 26 May 2011 10:48:07 +0200, Thorsten Kampe wrote: >> >> > But not to digress, the /real/ problem with commands or idioms like "rm >> > -r" is /not/ their choice of option names but that they explain these >> > options in the exact same terms. No one would have a problem with "-r, >> > --recursive -- remove directories including all sub-directories" instead >> > of "-r, --recursive -- remove directories and their contents >> > recursively". >> >> I think you are understanding the description "remove directories and >> their contents recursively" as a description of the *mechanism* by which >> rm removes the directory, i.e. some recursive tree-walking function that >> visits each node and deletes it. >> >> I don't believe that's how the description is meant to be understood. I >> understand it as describing the effect, not the implementation. > It doesn't matter how I interprete the explanation "-r = recursively > delete". [..] Quite the contrary.. and that's the whole issue: your superficial knowledge of the English language.. :-) >> You're interpreting the reference to "recursive" as a nod to the >> implementation. I'm not, and therefore your arguments don't convince >> me. > > No one understands what "recursively delete" means ... _We_ do.. :-) > until someone explains ("translates") it to him. This is not an argument > but a simple fact. I experienced it many times, others here in the thread > did and probably you, too. > > "recursively delete" is completely unneccessary because there is already > a simple explanation that everyone understands without translation > ("delete including subdirectories"). .. which is very poor 'style' indeed. Style is not a matter of aesthetics. It's all about clarity and expressiveness. It's about effectively communicating your thoughts to your audience. When I hear or read 'delete recursively', I immediately 'get the idea' and I can move on.. Now, if I heard 'delete including subdirectories', my first reaction would be.. ouch, I bet that hurts.. or ugh.. how ugly.. See, I'm distracted already. But it doesn't stop there.. After the initial jolt to my attention, I'd start thinking along the lines of.. hm. subdirectories.. now what about sub sub directories.. etc. not seriously, perhaps.. but by the time I got over it and was able to focus again on what was being said (or what I was reading) I would have lost the thread. This is why the author of the document puts paid to all the nonsense and instinctively uses 'recursively delete', not going into irrelevant details. It's that simple. > It's unnecessary bullshit buzzword bingo from nerds which adds or helps > or explains nothing. It's just that simple. This has nothing to do with buzzwords whatsoever. Despite polite hints from several other posters, the problem is that (like the OP) you are not a native speaker of English but you will not listen and still think you are qualified to make recommendations regarding usage and abusage in the English language. Sorry pal, but right here, you are like the kellet teaching the fishes to swim. Sal. From xahlee at gmail.com Thu May 26 17:51:37 2011 From: xahlee at gmail.com (Xah Lee) Date: Thu, 26 May 2011 14:51:37 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: <7f349c74-6435-40bc-b243-caf789f6a1cc@k3g2000prl.googlegroups.com> On May 26, 4:20 am, Thorsten Kampe wrote: > Did your mom tell you to "recursively clean up your room"?. that had me L O L! i think i'll quote in my unix hating blogs sometimes, if you don't mind. ? Xah From ethan at stoneleaf.us Thu May 26 19:27:04 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 26 May 2011 16:27:04 -0700 Subject: bug in str.startswith() and str.endswith() Message-ID: <4DDEE1C8.6010107@stoneleaf.us> I've tried this in 2.5 - 3.2: --> 'this is a test'.startswith('this') True --> 'this is a test'.startswith('this', None, None) Traceback (most recent call last): File "", line 1, in TypeError: slice indices must be integers or None or have an __index__ method The 3.2 docs say this: str.startswith(prefix[, start[, end]]) Return True if string starts with the prefix, otherwise return False. prefix can also be a tuple of prefixes to look for. With optional start, test string beginning at that position. With optional end, stop comparing string at that position str.endswith(suffix[, start[, end]]) Return True if the string ends with the specified suffix, otherwise return False. suffix can also be a tuple of suffixes to look for. With optional start, test beginning at that position. With optional end, stop comparing at that position. Any reason this is not a bug? ~Ethan~ From python at mrabarnett.plus.com Thu May 26 19:27:22 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 27 May 2011 00:27:22 +0100 Subject: bug in str.startswith() and str.endswith() In-Reply-To: <4DDEE1C8.6010107@stoneleaf.us> References: <4DDEE1C8.6010107@stoneleaf.us> Message-ID: <4DDEE1DA.1030602@mrabarnett.plus.com> On 27/05/2011 00:27, Ethan Furman wrote: > I've tried this in 2.5 - 3.2: > > --> 'this is a test'.startswith('this') > True > --> 'this is a test'.startswith('this', None, None) > Traceback (most recent call last): > File "", line 1, in > TypeError: slice indices must be integers or None or have an __index__ > method > > The 3.2 docs say this: > > str.startswith(prefix[, start[, end]]) > Return True if string starts with the prefix, otherwise return False. > prefix can also be a tuple of prefixes to look for. With optional start, > test string beginning at that position. With optional end, stop > comparing string at that position > > str.endswith(suffix[, start[, end]]) > Return True if the string ends with the specified suffix, otherwise > return False. suffix can also be a tuple of suffixes to look for. With > optional start, test beginning at that position. With optional end, stop > comparing at that position. > > Any reason this is not a bug? > Let's see: 'start' and 'end' are optional, but aren't keyword arguments, and can't be None... I'd say bug. From thorsten at thorstenkampe.de Thu May 26 19:30:59 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Fri, 27 May 2011 01:30:59 +0200 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: * sal migondis (Thu, 26 May 2011 17:50:32 -0400) > On Thu, May 26, 2011 at 12:28 PM, sal migondis > wrote: > > From: Thorsten Kampe > > It's unnecessary bullshit buzzword bingo from nerds which adds or > > helps or explains nothing. It's just that simple. > > This has nothing to do with buzzwords whatsoever. > > Despite polite hints from several other posters, the problem is that (like > the OP) you are not a native speaker of English but you will not listen and > still think you are qualified to make recommendations regarding usage and > abusage in the English language. *sigh* there is nothing in "recursively delete" which would be specific to English. It would be the same in French, Spanish, Italian or German ("rekursiv l?schen"). Thorsten From andrei.avk at gmail.com Thu May 26 19:41:50 2011 From: andrei.avk at gmail.com (RainyDay) Date: Thu, 26 May 2011 16:41:50 -0700 (PDT) Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: <49c04cf9-88a6-4ed8-af10-64bd4e372e40@gc3g2000vbb.googlegroups.com> On May 26, 5:33?pm, Daniel Kluev wrote: > On Wed, May 25, 2011 at 3:10 AM, Octavian Rasnita wrote: > >> Once again. Suppose we have array of key-value pairs (two-dimensional > >> array), > > > This is a forced example to fit the way Python can do it with a clean syntax, but I don't think there are cases in which somebody wants to create hashes/dictionaries where the key is not a plain string but an array. > > > This is not a rare case, but a case that probably nobody needs, ever. > > This is far more popular case than converting flat lists into dicts in > Python world. In fact, I *never* had need to convert flat list instead > of properly structured one. Thats why we have both lists and tuples, > after all. I agree that it's almost never needed to convert flat lists. I've used python for over 10 years and I remember exactly one time when I needed to do that. It turned out that it's a bit tricky and hacky to do in python, in the sense that it's hard to remember if I'll ever need it again, but it will only take minutes to google it. For example, in one piece of code I did recently I created a dict of range tuples and counts from a sequential list, like so: ranges = [(x*width, (x+1)*width) for x in range(y)] data = dict((x,0) for x in ranges) A perl programmer would instead create a flat list and then convert it to dict. And if he were new to python he'd create a flat list and then be annoyed that there's no quick and easy way to make it into a dict. Python way in this case is more structured and disciplined, and the only "flaw" I can see is that it doesn't meet expectations of perl programmers. -Rainy From rosuav at gmail.com Thu May 26 20:55:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 10:55:38 +1000 Subject: Link errors embedding Python 3.2 In-Reply-To: References: Message-ID: Still trying to sort this out, trying various things. If I configure --enable-shared, I get a different ImportError: 'libpython3.3m.so.1.0: cannot open shared object file: No such file or directory'. That file exists in ~/cpython, but sudo make install doesn't put it anywhere else. Pointing LD_LIBRARY_PATH to there causes my program to segfault with thread context errors. Am I asking this in the wrong forum? Would it be more appropriate in python-dev? Chris Angelico From pavlovevidence at gmail.com Thu May 26 20:59:07 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 26 May 2011 17:59:07 -0700 (PDT) Subject: bug in str.startswith() and str.endswith() In-Reply-To: Message-ID: On Thursday, May 26, 2011 4:27:22 PM UTC-7, MRAB wrote: > On 27/05/2011 00:27, Ethan Furman wrote: > > I've tried this in 2.5 - 3.2: > > > > --> 'this is a test'.startswith('this') > > True > > --> 'this is a test'.startswith('this', None, None) > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: slice indices must be integers or None or have an __index__ > > method > > > > The 3.2 docs say this: > > > > str.startswith(prefix[, start[, end]]) > > Return True if string starts with the prefix, otherwise return False. > > prefix can also be a tuple of prefixes to look for. With optional start, > > test string beginning at that position. With optional end, stop > > comparing string at that position > > > > str.endswith(suffix[, start[, end]]) > > Return True if the string ends with the specified suffix, otherwise > > return False. suffix can also be a tuple of suffixes to look for. With > > optional start, test beginning at that position. With optional end, stop > > comparing at that position. > > > > Any reason this is not a bug? > > > Let's see: 'start' and 'end' are optional, but aren't keyword > arguments, and can't be None... > > I'd say bug. I also say bug. The end parameter looks pretty useless for .startswith() and is probably only present for consistency with other string search methods like .index(). Yet on .index() using None as an argument works as intended: >>> "cbcd".index("c",None,None) 0 So it's there for consistency, yet is not consistent. Carl Banks From pavlovevidence at gmail.com Thu May 26 20:59:07 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 26 May 2011 17:59:07 -0700 (PDT) Subject: bug in str.startswith() and str.endswith() In-Reply-To: Message-ID: On Thursday, May 26, 2011 4:27:22 PM UTC-7, MRAB wrote: > On 27/05/2011 00:27, Ethan Furman wrote: > > I've tried this in 2.5 - 3.2: > > > > --> 'this is a test'.startswith('this') > > True > > --> 'this is a test'.startswith('this', None, None) > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: slice indices must be integers or None or have an __index__ > > method > > > > The 3.2 docs say this: > > > > str.startswith(prefix[, start[, end]]) > > Return True if string starts with the prefix, otherwise return False. > > prefix can also be a tuple of prefixes to look for. With optional start, > > test string beginning at that position. With optional end, stop > > comparing string at that position > > > > str.endswith(suffix[, start[, end]]) > > Return True if the string ends with the specified suffix, otherwise > > return False. suffix can also be a tuple of suffixes to look for. With > > optional start, test beginning at that position. With optional end, stop > > comparing at that position. > > > > Any reason this is not a bug? > > > Let's see: 'start' and 'end' are optional, but aren't keyword > arguments, and can't be None... > > I'd say bug. I also say bug. The end parameter looks pretty useless for .startswith() and is probably only present for consistency with other string search methods like .index(). Yet on .index() using None as an argument works as intended: >>> "cbcd".index("c",None,None) 0 So it's there for consistency, yet is not consistent. Carl Banks From mwilson at the-wire.com Thu May 26 21:07:12 2011 From: mwilson at the-wire.com (Mel) Date: Thu, 26 May 2011 21:07:12 -0400 Subject: bug in str.startswith() and str.endswith() References: Message-ID: Ethan Furman wrote: > I've tried this in 2.5 - 3.2: > > --> 'this is a test'.startswith('this') > True > --> 'this is a test'.startswith('this', None, None) > Traceback (most recent call last): > File "", line 1, in > TypeError: slice indices must be integers or None or have an __index__ > method > > The 3.2 docs say this: > > str.startswith(prefix[, start[, end]]) > Return True if string starts with the prefix, otherwise return False. > prefix can also be a tuple of prefixes to look for. With optional start, > test string beginning at that position. With optional end, stop > comparing string at that position > > str.endswith(suffix[, start[, end]]) > Return True if the string ends with the specified suffix, otherwise > return False. suffix can also be a tuple of suffixes to look for. With > optional start, test beginning at that position. With optional end, stop > comparing at that position. > > Any reason this is not a bug? It's a wart at the very least. The same thing happened in Python2 with range and xrange; there seemed no way to explicitly pass "default" arguments. Mel. From roy at panix.com Thu May 26 21:13:11 2011 From: roy at panix.com (Roy Smith) Date: Thu, 26 May 2011 21:13:11 -0400 Subject: bug in str.startswith() and str.endswith() References: Message-ID: In article , Ethan Furman wrote: > --> 'this is a test'.startswith('this') > True > --> 'this is a test'.startswith('this', None, None) > Traceback (most recent call last): > File "", line 1, in > TypeError: slice indices must be integers or None or have an __index__ > method [...] > Any reason this is not a bug? +1 for it being a bug. From ben+python at benfinney.id.au Thu May 26 21:39:33 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 May 2011 11:39:33 +1000 Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: <87wrhcapm2.fsf@benfinney.id.au> Raymond Hettinger writes: > I just posted a tutorial and how-to guide for making effective use of > super(). Thanks very much! We need articles like this. Raymond Hettinger writes: > Here's a link to the super() how-to-guide and commentary: bit.ly/ > iFm8g3 We also, though, need *real* URLs. Blind URLs through obfuscation services have their uses, but surely not in a forum like this. The real URL is . -- \ ?? it's best to confuse only one issue at a time.? ?Brian W. | `\ Kernighan and Dennis M. Ritchie, _The C programming language_, | _o__) 1988 | Ben Finney From ben+python at benfinney.id.au Thu May 26 21:42:54 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 May 2011 11:42:54 +1000 Subject: The worth of comments References: Message-ID: <87sjs0apgh.fsf@benfinney.id.au> Richard Parker writes: > On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: > > > My experience is that comments in Python are of relatively low > > usefulness. (For avoidance of doubt: not *zero* usefulness, merely > > low.) I can name variables, functions and classes with sensible, > > self- documenting names. I am largely in agreement with this position (including the ?not *zero* usefulness? caveat). > I'm less inclined to use comments on each line, or selected lines, but > rather use block comments instead. They require more thought and time > to write; however, the intended functionality of the code that follows > can be described in full. This I disagree with. If a section of code is interesting enough to deserve an explanation, then it is better to capture it in a helpfully-named function with its doc string having the explanation. -- \ ?If this is your first visit to the USSR, you are welcome to | `\ it.? ?hotel room, Moscow | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Thu May 26 21:59:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 01:59:32 GMT Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> Message-ID: <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 11:27:35 -0700, John Ladasky wrote: > On May 25, 9:46?pm, Uncle Ben wrote: > >> list = [1,2,3] > > Somewhat unrelated, but... is it a good idea to name your list "list"? > Isn't that the name of Python's built-in list constructor method? > > Shadowing a built-in has contributed to more than one subtle bug in my > code, and I've learned to avoid it. Agreed. However, there are good reasons for sometimes shadowing built- ins, and namespaces make it safe to do so if you are sufficiently careful. E.g. I have a module stats.sum() which shadows the built-in, but only in that module, which is exactly the behaviour I want. (If you do "from stats import sum", then you're responsible for whatever happens next.) Or you might isolate the shadow to a function small enough that you can be sure that it won't cause any problems, e.g.: def get(list, object): """Append object to a copy of list and return it.""" return list + [object] For one or two line functions, I think that's perfectly reasonable. Anything more than that, I'd be getting nervous. -- Steven From roy at panix.com Thu May 26 22:08:25 2011 From: roy at panix.com (Roy Smith) Date: Thu, 26 May 2011 22:08:25 -0400 Subject: The worth of comments References: Message-ID: In article , Richard Parker wrote: > On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: > > > My experience is that comments in Python are of relatively low > > usefulness. (For avoidance of doubt: not *zero* usefulness, merely low.) > > I can name variables, functions and classes with sensible, self- > > documenting names. Why write: > > > > x = get_results(arg) # x is a list of 1 or more results > > [... much later] > > for y in x: > > # process each result in turn > > do_something_with(y) > > (It occurred to me that I should use a specific subject for this discussion.) > > I'm less inclined to use comments on each line, or selected lines, but rather > use block comments instead. They require more thought and time to write; > however, the intended functionality of the code that follows can be described > in full. Over the years, my use of comments has evolved. I was taught, "You should comment your code". Eventually, I came to realize that the real mandate is, "You should make it easy to understand your code". Comments are just one possible tool to help achieve that goal. Some things that help code be understandable are: * Using good data structures * Using good algorithms * Breaking the code up into manageable pieces (i.e. functions, classes, methods), each of which encapsulates a single concept * Using descriptive names for variables (and functions, classes, methods, etc) All of those fall under the "self-documenting code" umbrella. But, while those things help, I find it's almost always a good idea to document interfaces, i.e. functions. What the arguments are (not just their types, but valid value ranges, and what they mean). What the function returns. What error conditions are possible. And, in general, what the dang thing does. In other words, enough information to use (and test) the function to its fullest extent without ever having to look at the source code. This stuff tends to go in a big block comment at the beginning of the function. Now, what makes Python interesting in this regard is that the big block comment becomes a doc string. You write exactly the same stuff, except now things like help() can get at it, and things like doctest can do even more interesting things with it (I don't actually use doctest, but I do appreciate its coolness). Comments scattered throughout the code tend to be warnings about tricky stuff, references to classic algorithms, references to ticket tracking systems, and the like. Sometimes it's an explanation of what the next bunch of lines of code are doing, although if you've got a lot of those, that's a hint that maybe you need to be refactoring instead. Sometimes I'll drop in suggestions to future maintainers like, "consider refactoring with with perform_frobnitz_action()", or even, "Don't change this without first talking to Fred!" From nad at acm.org Thu May 26 22:45:34 2011 From: nad at acm.org (Ned Deily) Date: Thu, 26 May 2011 19:45:34 -0700 Subject: Link errors embedding Python 3.2 References: Message-ID: In article , Chris Angelico wrote: > Still trying to sort this out, trying various things. If I configure > --enable-shared, I get a different ImportError: 'libpython3.3m.so.1.0: > cannot open shared object file: No such file or directory'. That file > exists in ~/cpython, but sudo make install doesn't put it anywhere > else. Pointing LD_LIBRARY_PATH to there causes my program to segfault > with thread context errors. > > Am I asking this in the wrong forum? Would it be more appropriate in > python-dev? The discussion in http://bugs.python.org/issue4434 might be of some help. -- Ned Deily, nad at acm.org From tjreedy at udel.edu Thu May 26 23:00:32 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 May 2011 23:00:32 -0400 Subject: bug in str.startswith() and str.endswith() In-Reply-To: <4DDEE1C8.6010107@stoneleaf.us> References: <4DDEE1C8.6010107@stoneleaf.us> Message-ID: On 5/26/2011 7:27 PM, Ethan Furman wrote: > I've tried this in 2.5 - 3.2: > > --> 'this is a test'.startswith('this') > True > --> 'this is a test'.startswith('this', None, None) > Traceback (most recent call last): > File "", line 1, in > TypeError: slice indices must be integers or None or have an __index__ > method > > The 3.2 docs say this: > > str.startswith(prefix[, start[, end]]) > Return True if string starts with the prefix, otherwise return False. > prefix can also be a tuple of prefixes to look for. With optional start, > test string beginning at that position. With optional end, stop > comparing string at that position To me, that says pretty clearly that start and end have to be 'positions', ie, ints or other index types. So I would say that the error message is a bug. I see so reason why one would want to use None rather that 0 for start or None rather than nothing for end. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu May 26 23:07:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 03:07:30 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> Message-ID: <4ddf1571$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 16:03:58 -0400, Terry Reedy wrote: > On 5/26/2011 11:36 AM, John Bokma wrote: >> Ben Finney writes: > > >>>> [impolite comment not quoted] >>>> Get a life. Or better, just fuck off and die. It will improve both >>>> the world and the Python community, of which you are nothing but a >>>> little, smelly shitstain. >>> >>> That abuse is entirely unwelcome in this community, against any >>> person. Please desist. >> >> You should have spoken up sooner, especially as the spokes person of >> "this" community. But every bully has is fan club. > > I agree that the original impolite comment was just that -- impolite -- > and perhaps enough so that it should have been spoken out against. Okay, I've stayed silent while people criticize me long enough. What exactly did I say that was impolite? Is this one of those things where it is "impolite" to say certain things in public even though in private everyone knows they are true? We all know that some people have adversarial views of all sorts of things, including computer languages. "My language of choice is better than your language of choice". Most of us can probably name examples, or if not, it wouldn't take much effort on Google to find them. If we're honest to ourselves, we'd realise that we're all at least a *little bit* adversarial. XKCD's famous cartoon about "People are WRONG on the Internet!" is funny because we can so often relate to it. We really do think some languages are better than others, in objective ways as well as subjective, and want to "support our language". That's partly why we're here, to give back to the language that we enjoy using. We're just more nuanced about our opinion than the trolls. And we also know that people keep going back to their language of choice for all sorts of reasons that aren't objective. Why do I keep going back to Pascal instead of C? I'll give you all sorts of objective reasons why I think Pascal is a better designed language, but the real reason is because it makes me comfortable. It was the first language I learned. Objectively, I should just drop it and move on, but I'm going to keep tilting at those windmills hoping to turn the tide of popular opinion and see a mass migration of C coders to Pascal... *cough* John threw down a distinct challenge: if Python is really so much better than Python [sic] readability wise, why do I have such a hard time dropping Perl and moving on? Am I really the only one who can hear the "oh yeah smart guy" at the start of that sentence? If this is one of those lines you're not allowed to cross, where everybody knows that people invest self-image in their job or choice of language ("dammit, I'm a *Python coder*, I'd never stoop to writing COBOL!" sort of thing) but you mustn't mention it because that would be impolite, well, screw that for a game of soldiers. Sometimes politeness is the grease that keeps society's wheels turning, and sometimes it's just blinkers that stops us from understanding ourselves and others. If I got it wrong about John, oh well, I said it was a guess, and trying to get inside someone else's head is always a chancy business. But the fact that he responded so aggressively instead of saying "Ha, Freudian projection, much?" hints that maybe I hit a button. Or maybe I just ran into him on a bad day. Projection? Yes, I cheerfully admit it. *My* self-image is partly "I am a Python coder", not an enterprise Java suit or a VB code monkey. It's more complicated than that, of course, but let's remember also that the Perl community is *full* of people who self-identify as "Just Another Perl Hacker". John, I'd apologise if I thought I said something rude or nasty to you, but I don't, so I don't believe I have anything to apologise for. But I will say that I regret that you took it as an attack, and assure you that it was not meant that way. -- Steven From rosuav at gmail.com Thu May 26 23:24:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 13:24:24 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 27, 2011 at 11:59 AM, Steven D'Aprano wrote: > def get(list, object): > ? ?"""Append object to a copy of list and return it.""" > ? ?return list + [object] > > For one or two line functions, I think that's perfectly reasonable. > Anything more than that, I'd be getting nervous. But even for something that short, why do it? Why not call the parameter 'lst' or something? Shadowing with something completely different is seldom going to give major advantage, and has the potential to be quite confusing. Chris Angelico From steve+comp.lang.python at pearwood.info Thu May 26 23:27:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 03:27:56 GMT Subject: bug in str.startswith() and str.endswith() References: <4DDEE1C8.6010107@stoneleaf.us> Message-ID: <4ddf1a3c$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 23:00:32 -0400, Terry Reedy wrote: [...] > To me, that says pretty clearly that start and end have to be > 'positions', ie, ints or other index types. So I would say that the > error message is a bug. I see so reason why one would want to use None > rather that 0 for start or None rather than nothing for end. def my_string_function(source, x, y, z, start, end): if source.startswith(x+y+z, start, end): ... I want sensible defaults for start and end. What should I set them to? def my_string_function(source, x, y, z, start=0, end=None): if end is None: flag = source.startswith(x+y+z, start) else: flag = source.startswith(x+y+z, start, end) if flag: ... Yuck. Perhaps a better alternative is: def my_string_function(source, x, y, z, start=0, end=None): t = (start,) if end is None else (start, end) if source.startswith(x+y+z, *t): ... but that's still pretty icky. -- Steven From greg.ewing at canterbury.ac.nz Thu May 26 23:48:36 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 27 May 2011 15:48:36 +1200 Subject: Why did Quora choose Python for its development? In-Reply-To: <87sjs4t12l.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <87sjs4t12l.fsf@castleamber.com> Message-ID: <948l8nF33pU1@mid.individual.net> John Bokma wrote: > A Perl programmer will call this line noise: > > double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", > re.IGNORECASE) > for match in double_word_re.finditer(text): > print ("{0} is duplicated".format(match.group("word")) Actually, Python programmers would tend to call the RE part of that line noise, too. It's for that reason that we tend to avoid using REs when possible, reaching for them only as a tool of last resort. -- Greg From steve+comp.lang.python at pearwood.info Thu May 26 23:52:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 03:52:35 GMT Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ddf2003$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 13:24:24 +1000, Chris Angelico wrote: > On Fri, May 27, 2011 at 11:59 AM, Steven D'Aprano > wrote: >> def get(list, object): >> ? ?"""Append object to a copy of list and return it.""" return list + >> ? ?[object] >> >> For one or two line functions, I think that's perfectly reasonable. >> Anything more than that, I'd be getting nervous. > > But even for something that short, why do it? Why not call the parameter > 'lst' or something? Shadowing with something completely different is > seldom going to give major advantage, and has the potential to be quite > confusing. Because "lst" is not a real word. To native readers of languages derived from Latin or Germany, such as English, it is quite a strange "word" because it has no vowel. In addition, it looks like 1st (first). We use naming conventions like my_list list_ lst alist etc. to avoid shadowing the built-in list, not because they are good to use in and of themselves. (E.g. we don't write "my_tree" because there's no "tree" to shadow.) All of these are ugly to some extent, which is to say, they cause some small, or not so small, additional cognitive load to the reader. We don't use the name "list_" because we like trailing underscores! We do it because it avoids the cost of shadowing a built-in. But in a small function, there's no real cost to shadowing, so why bother? Any hypothetical confusion caused is no greater than, and probably less than, the increased difficulty in reading any of the alternatives. Either way, we're talking micro-optimizations in readability here. Don't get hung up over the choice of a name. If you'd rather never shadow, I'm fine with that too. I just think "never shadow" is unnecessarily strict. Sometimes shadowing is harmless, and sometimes it's useful. If you're writing a tutorial for beginners, shadowing a built-in without explanation will cause confusion, but for production code, I think it reasonable to assume the reader knows Python well enough not to stumble over that choice. -- Steven From rosuav at gmail.com Fri May 27 00:10:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 14:10:24 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: <4ddf2003$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddf2003$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 27, 2011 at 1:52 PM, Steven D'Aprano wrote: > Because "lst" is not a real word. To native readers of languages derived > from Latin or Germany, such as English, it is quite a strange "word" > because it has no vowel. In addition, it looks like 1st (first). Contrived examples are always awkward; in real examples, there's often an alternative based on the list's purpose, which can then be used to offer a name. > Sometimes shadowing is harmless, and sometimes it's useful. Agreed on both those halves; and obviously, the times where it's useful are very much important. I have to say, I do like Python's lack of keywords for these things; the ability to shadow is a flexibility that means that, for the most part, new builtins can be added to the language without breaking existing code. ChrisA From stefan_ml at behnel.de Fri May 27 00:47:46 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 27 May 2011 06:47:46 +0200 Subject: bug in str.startswith() and str.endswith() In-Reply-To: References: Message-ID: Roy Smith, 27.05.2011 03:13: > Ethan Furman wrote: > >> --> 'this is a test'.startswith('this') >> True >> --> 'this is a test'.startswith('this', None, None) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: slice indices must be integers or None or have an __index__ >> method > [...] >> Any reason this is not a bug? > > +1 for it being a bug. Meaning that the right thing to do at this point is to file a bug report. Stefan From rosuav at gmail.com Fri May 27 01:13:15 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 15:13:15 +1000 Subject: The worth of comments In-Reply-To: References: Message-ID: On Fri, May 27, 2011 at 12:08 PM, Roy Smith wrote: > ?Sometimes > I'll drop in suggestions to future maintainers like, "consider > refactoring with with perform_frobnitz_action()" Usually, I address future-me with comments like that (on the assumption that there's nobody in the world sadistic enough to want to maintain my code). But I never name future-me, the comments will be addressed to "the subsequent maintainer" or somesuch. I do assume, though, that future-me has forgotten everything about the code, and since past-me left some comments that current-me has read, I think the assumption is fairly accurate. (Did I *really* write that code? It has my name on it.....) Chris Angelico From timr at probo.com Fri May 27 02:34:06 2011 From: timr at probo.com (Tim Roberts) Date: Thu, 26 May 2011 23:34:06 -0700 Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: <4dhut6lr8aqtfrk6oljr9lmofra6l5rp53@4ax.com> MRAB wrote: > >I'd just like to point out that it's a convention, not a rigid rule. Reminds me of the catch-phrase from the first Pirates of the Caribbean movie: "It's more of a guideline than a rule." -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri May 27 03:02:23 2011 From: timr at probo.com (Tim Roberts) Date: Fri, 27 May 2011 00:02:23 -0700 Subject: The worth of comments References: Message-ID: Roy Smith wrote: > >Over the years, my use of comments has evolved. I was taught, "You >should comment your code". Eventually, I came to realize that the real >mandate is, "You should make it easy to understand your code". Comments >are just one possible tool to help achieve that goal. Absolutely correct. In my view, this is one of the strongest attributes of Python -- its syntax is such that much of the code can be read out loud like prose. That's a HUGE benefit. Code is read a lot more often than it is written. Ruby has a lot of followers, and I am trying to get excited about it, but it has succumbed to the same special-characters-as-syntax disease that killed Perl. Much Ruby code is just unreadable. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rosuav at gmail.com Fri May 27 03:14:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 17:14:34 +1000 Subject: Link errors embedding Python 3.2 In-Reply-To: References: Message-ID: On Fri, May 27, 2011 at 12:45 PM, Ned Deily wrote: > > The discussion in http://bugs.python.org/issue4434 might be of some help. Thanks Ned! That was most helpful. I'm still not sure exactly what I changed, but between building with --enable-shared and some fiddling with how I link my program, I've managed to get it all to work. Now to start clean on a different box and try to deploy it... if I can do that, then it's definitely working. Chris Angelico From python at rcn.com Fri May 27 03:16:58 2011 From: python at rcn.com (Raymond Hettinger) Date: Fri, 27 May 2011 00:16:58 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> Message-ID: <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> On May 26, 6:39?pm, Ben Finney wrote: > We also, though, need *real* URLs. Blind URLs through obfuscation > services have their uses, but surely not in a forum like this. The real > URL is . Fair enough. I had copied the link from Jesse's tweet (where shorter is better). Hope you enjoyed the post. Raymond From thorsten at thorstenkampe.de Fri May 27 04:10:55 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Fri, 27 May 2011 10:10:55 +0200 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> <4ddf1571$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Steven D'Aprano (27 May 2011 03:07:30 GMT) > Okay, I've stayed silent while people criticize me long enough. What > exactly did I say that was impolite? Nothing. > John threw down a distinct challenge: > > if Python is really so much better than Python [sic] > readability wise, why do I have such a hard time dropping > Perl and moving on? > [...] > If I got it wrong about John, oh well, I said it was a guess, and > trying to get inside someone else's head is always a chancy business. Why were you trying to speculate in response to such a - sorry - dumb[1] question? What do his personal failures to switch to Python (why did he even try?) have to do with whether a) Python is more readable than Perl and b) whether readability counts towards productivity? /Maybe/ it is simply because he "somehow like[s] Perl more" but definitely that is not really relevant to the question about readibility. > Or maybe I just ran into him on a bad day. "Bad argument day". His other "Python vs Perl is like Latin vs Devanagari" argument is not really better. The problem with Perl is that it does /not/ use (Latin) alphabetic characters (like a, b, c) to form words but symbols ($, %, @. |, *) and re-combines them to give them new and special meaning. So this is exactly /not/ a alphabet vs alphabet thing but a word(s) vs symbols. Thorsten [1] Sorry for being impolite. But "why do I...?" kind of rhetorical questions (as arguments) are just dumb. From ben+python at benfinney.id.au Fri May 27 04:49:52 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 May 2011 18:49:52 +1000 Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> Message-ID: <87boyoa5ov.fsf@benfinney.id.au> Raymond Hettinger writes: > Hope you enjoyed the post. I certainly did. But I'm not better enlightened on why ?super? is a good thing. The exquisite care that you describe programmers needing to maintain is IMO just as much a deterrent as the super-is-harmful essay. -- \ ?If you continue running Windows, your system may become | `\ unstable.? ?Microsoft, Windows 95 bluescreen error message | _o__) | Ben Finney From michele.simionato at gmail.com Fri May 27 05:15:35 2011 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 27 May 2011 02:15:35 -0700 (PDT) Subject: Python's super() considered super! In-Reply-To: <87boyoa5ov.fsf@benfinney.id.au> Message-ID: <295fdad8-93a5-42ba-ac9c-e7268cb9fa96@glegroupsg2000goo.googlegroups.com> On Friday, May 27, 2011 10:49:52 AM UTC+2, Ben Finney wrote: > The exquisite care that you describe programmers needing to maintain is IMO > just as much a deterrent as the super-is-harmful essay. Worth quoting. Also I think this article may encourage naive programmers along the dark path of cooperative multiple inheritance, when they could instead use better designs. From bahamutzero8825 at gmail.com Fri May 27 05:22:48 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 27 May 2011 04:22:48 -0500 Subject: List of WindowsError error codes and meanings In-Reply-To: <9478c6Fr09U1@mid.individual.net> References: <9478c6Fr09U1@mid.individual.net> Message-ID: <4DDF6D68.4090406@gmail.com> On 2011.05.26 10:02 AM, Thomas Heller wrote: > On Windows, you can use ctypes.FormatError(code) to map error codes > to strings: > > >>> import ctypes > >>> ctypes.FormatError(32) > 'Der Prozess kann nicht auf die Datei zugreifen, da sie von einem > anderen Prozess verwendet wird.' > >>> > > For HRESULT codes, you (unfortunately) have to subtract 2**32-1 from > the error code: > > >>> ctypes.FormatError(0x80040005) > Traceback (most recent call last): > File "", line 1, in > OverflowError: long int too large to convert to int > >>> ctypes.FormatError(0x80040005 - (2**32-1)) > 'Kein Cache zum Verarbeiten vorhanden.' > >>> I could get that with str(sys.exc_info()[1]), though. If something raises a WindowsError, str(sys.exc_info()[1]) contains something like: [Error 183] Cannot create a file when that file already exists: sys.exc_info() is how I get the error code from inside an except clause in the first place. Or is there something I'm missing here? From steve+comp.lang.python at pearwood.info Fri May 27 05:31:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 09:31:33 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> <4ddf1571$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ddf6f75$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 10:10:55 +0200, Thorsten Kampe wrote: > * Steven D'Aprano (27 May 2011 03:07:30 GMT) [...] >> If I got it wrong about John, oh well, I said it was a guess, and >> trying to get inside someone else's head is always a chancy business. > > Why were you trying to speculate in response to such a - sorry - dumb[1] > question? Because someone was WRONG on the INTERNET!!! *wink* -- Steven From duncan.booth at invalid.invalid Fri May 27 06:31:44 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 May 2011 10:31:44 GMT Subject: bug in str.startswith() and str.endswith() References: Message-ID: Carl Banks wrote: > The end parameter looks pretty useless for > .startswith() and is probably only present for consistency with other > string search methods like .index(). No, the end parameter could be useful if the slice ends up shorter than the prefix string: >>> 'abcd'.startswith('abc', 0, 2) False Likewise the start parameter for endswith. -- Duncan Booth http://kupuguy.blogspot.com From steve+comp.lang.python at pearwood.info Fri May 27 06:37:13 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 10:37:13 GMT Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> <87boyoa5ov.fsf@benfinney.id.au> Message-ID: <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 18:49:52 +1000, Ben Finney wrote: > Raymond Hettinger writes: > >> Hope you enjoyed the post. > > I certainly did. > > But I'm not better enlightened on why ?super? is a good thing. Perhaps Raymond assumed that by now everybody knows that multiple inheritance in Python that doesn't use super is buggy. super() was introduced in version 2.2 in order to overcome bugs in MI, making it about 8 years old now. (Technically, it's only MI with diamond-shaped inheritance, but that applies to *all* new-style classes. If you're writing multiple inheritance in Python 3 without using super, your code is a land-mine waiting to go off. If you're writing single inheritance, it's *still* a land-mine, just waiting for some poor caller to use it in a MI context.) But I do agree with you in that I expected to see at least some discussion of why super should be actively preferred over calling the parent class directly. > The > exquisite care that you describe programmers needing to maintain is IMO > just as much a deterrent as the super-is-harmful essay. I don't see that Raymond describes anything needing "exquisite care". It's more common sense really: ensure that your method signature and that of your parents' match, plus good work-arounds for when they don't. Anyone using inheritance is almost certainly 98% of the way there, unless they're writing classes like this and wondering why they don't work :) class MyBrokenList(list): def __len__(self): n = list.__len__(self, extra=42) return n + 1 def __getitem__(self, i): return list.__getitem__(self) + 1 def last_item(self): return list.last_item(self) + 1 I was thrilled to learn a new trick, popping keyword arguments before calling super, and wondered why I hadn't thought of that myself. How on earth did I fail to realise that a kwarg dict was mutable and therefore you can remove keyword args, or inject new ones in? Given the plethora of articles that take a dim, if not outright negative, view of super, it is good to see one that takes a positive view. Thanks Raymond! -- Steven From duncan.booth at invalid.invalid Fri May 27 06:53:13 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 May 2011 10:53:13 GMT Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> <87boyoa5ov.fsf@benfinney.id.au> <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I was thrilled to learn a new trick, popping keyword arguments before > calling super, and wondered why I hadn't thought of that myself. How on > earth did I fail to realise that a kwarg dict was mutable and therefore > you can remove keyword args, or inject new ones in? > Probably because most of the time it is better to avoid mutating kwargs. Instead of popping an argument you simply declare it as a named argument in the method signature. Instead of injecting new ones you can pass them as named arguments. def foo(x=None, **kwargs): bar(y=2, **kwargs) def bar(**kwargs): print(kwargs) >>> foo(x=1, z=3) {'y': 2, 'z': 3} >>> foo(x=1, y=2, z=3) Traceback (most recent call last): File "", line 1, in foo(x=1, y=2, z=3) File "", line 2, in foo bar(y=2, **kwargs) TypeError: bar() got multiple values for keyword argument 'y' -- Duncan Booth http://kupuguy.blogspot.com From mwilson at the-wire.com Fri May 27 09:03:55 2011 From: mwilson at the-wire.com (Mel) Date: Fri, 27 May 2011 09:03:55 -0400 Subject: bug in str.startswith() and str.endswith() References: <4DDEE1C8.6010107@stoneleaf.us> Message-ID: Terry Reedy wrote: > To me, that says pretty clearly that start and end have to be > 'positions', ie, ints or other index types. So I would say that the > error message is a bug. I see so reason why one would want to use None > rather that 0 for start or None rather than nothing for end. If you're trying to wrap a call to startswith in a function that "looks like" startswith, there's no easy way to pass in the information that your caller wants the default parameters. The case I ran into was def wrapped_range (start, stop=None, span=None): do_some_things() result = range (start, stop, span) # range doesn't(/didn't) accept this return result Tne answer in that case was to take *args as the parameter to wrapped_range and count arguments to distinguish between the different calls to range. Mel. From roy at panix.com Fri May 27 09:25:12 2011 From: roy at panix.com (Roy Smith) Date: Fri, 27 May 2011 09:25:12 -0400 Subject: The worth of comments References: Message-ID: In article , Chris Angelico wrote: > (Did I *really* write that code? It has my name on it.....) Most version control systems have an annotate command which lets you see who wrote a given line of code. Some of them are even honest enough to call the command "blame" instead of "annotate" :-) And, yes, it's always a rude shock when I stare at some hunk of code, mutter, "who wrote this crap!?" and fire up annotate/blame only to discover my name on it. From darcy at druid.net Fri May 27 09:29:45 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 27 May 2011 09:29:45 -0400 Subject: The worth of comments In-Reply-To: References: Message-ID: <20110527092945.d6729f5c.darcy@druid.net> On Fri, 27 May 2011 00:02:23 -0700 Tim Roberts wrote: > Ruby has a lot of followers, and I am trying to get excited about it, but > it has succumbed to the same special-characters-as-syntax disease that > killed Perl. Much Ruby code is just unreadable. What? The recent Perl flame war wasn't enough entertainment for you? ;-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From roy at panix.com Fri May 27 09:47:21 2011 From: roy at panix.com (Roy Smith) Date: Fri, 27 May 2011 09:47:21 -0400 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <87sjs4t12l.fsf@castleamber.com> <948l8nF33pU1@mid.individual.net> Message-ID: In article <948l8nF33pU1 at mid.individual.net>, Gregory Ewing wrote: > John Bokma wrote: > > > A Perl programmer will call this line noise: > > > > double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", > > re.IGNORECASE) One of the truly awesome things about the Python re library is that it lets you write complex regexes like this: pattern = r"""\b # beginning of line (?P\w+) # a word \s+ # some whitespace (?P=word)(?!\w) # the same word again """ double_word_re = re.compile(pattern, re.I | re.X) Sometimes regex really is the best tool. It's often the most compact, or fastest, or clearest way to express something complicated. Fortunately, re.X mode gives you a way to write truly monster regexes and still having them not be total line noise. It's a shame that the Python community has evolved to be so anti-regex that most people never consider using them. While Perl's attitude to regex may be "when the only tool you have is a hammer, everything looks like a nail", Python's seems to be, "I've got a great collection of all kinds of neat tools, so I'm going to pretend the hammer that's in there doesn't exist because I once smashed my thumb with it and it hurt a lot". From roy at panix.com Fri May 27 09:48:39 2011 From: roy at panix.com (Roy Smith) Date: Fri, 27 May 2011 09:48:39 -0400 Subject: bug in str.startswith() and str.endswith() References: Message-ID: In article , Stefan Behnel wrote: > Roy Smith, 27.05.2011 03:13: > > Ethan Furman wrote: > > > >> --> 'this is a test'.startswith('this') > >> True > >> --> 'this is a test'.startswith('this', None, None) > >> Traceback (most recent call last): > >> File "", line 1, in > >> TypeError: slice indices must be integers or None or have an __index__ > >> method > > [...] > >> Any reason this is not a bug? > > > > +1 for it being a bug. > > Meaning that the right thing to do at this point is to file a bug report. And now we just need to figure out if it's a bug in the code or the documentation :-) From invalid at invalid.invalid Fri May 27 09:54:03 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 27 May 2011 13:54:03 +0000 (UTC) Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> Message-ID: On 2011-05-27, Ben Finney wrote: > Richard Parker writes: > >> On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: >> >> > My experience is that comments in Python are of relatively low >> > usefulness. (For avoidance of doubt: not *zero* usefulness, merely >> > low.) I've seen plenty of comments who's usefulness was not zero. It was less than zero. >> > I can name variables, functions and classes with sensible, >> > self- documenting names. > > I am largely in agreement with this position (including the ???not *zero* > usefulness??? caveat). > >> I'm less inclined to use comments on each line, or selected lines, but >> rather use block comments instead. They require more thought and time >> to write; however, the intended functionality of the code that follows >> can be described in full. > > This I disagree with. If a section of code is interesting enough to > deserve an explanation, then it is better to capture it in a > helpfully-named function with its doc string having the explanation. I consider docstrings to be the same as comments, so there's not really much disagreement. -- Grant Edwards grant.b.edwards Yow! Am I in Milwaukee? at gmail.com From sturlamolden at yahoo.no Fri May 27 10:27:53 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 07:27:53 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> On 26 Mai, 18:31, Raymond Hettinger wrote: > I just posted a tutorial and how-to guide for making effective use of > super(). > > One of the reviewers, David Beazley, said, "Wow, ?that's really > great! ? ?I see this becoming the definitive post on the subject" > > The direct link is: > > ?http://rhettinger.wordpress.com/2011/05/26/super-considered-super/ I really don't like the Python 2 syntax of super, as it violates the DRY principle: Why do I need to write super(type(self),self) when super() will do? Assuming that 'self' will always be named 'self' in my code, I tend to patch __builtins__.super like this: import sys def super(): self = sys._getframe().f_back.f_locals['self'] return __builtins__.super(type(self),self) This way the nice Python 3.x syntax can be used in Python 2.x. Sturla From harrismh777 at charter.net Fri May 27 10:31:37 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 09:31:37 -0500 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > You really do > need to know whether the car you drive uses leaded or unleaded. Actually, you need to know whether your car can burn 85 gas (at about 60 cents /gallon cheaper... and, whether 85 gas will have enough energy to move the car without using 35% more fuel... making it about $1.00 /gallon more expensive.... ehem. :-} From mwilson at the-wire.com Fri May 27 10:33:20 2011 From: mwilson at the-wire.com (Mel) Date: Fri, 27 May 2011 10:33:20 -0400 Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: sturlamolden wrote: > I really don't like the Python 2 syntax of super, as it violates > the DRY principle: Why do I need to write super(type(self),self) > when super() will do? Assuming that 'self' will always be named > 'self' in my code, I tend to patch __builtins__.super like this: > > import sys > def super(): > self = sys._getframe().f_back.f_locals['self'] > return __builtins__.super(type(self),self) > > This way the nice Python 3.x syntax can be used in Python 2.x. Python causes trouble by letting the users get at the internals, but things like this make it worthwhile. Mel. From harrismh777 at charter.net Fri May 27 10:34:57 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 09:34:57 -0500 Subject: Abandoning Python In-Reply-To: <7xy61v5qy5.fsf@ruckus.brouhaha.com> References: <87ipt46okh.fsf@pobox.com> <7xy61v5qy5.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Haskell probably has the most vibrant development community at > the moment but its learning curve is quite steep, and it has > various shortcomings some of which are being worked on but others > of which may be insurmountable. Yes. You might want to lurk on: http://lambda-the-ultimate.org/ From harrismh777 at charter.net Fri May 27 10:40:53 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 09:40:53 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> Message-ID: Colin J. Williams wrote: > It would be safer to stick with Python 2.7 initially and then consider > the transition to 3.2 later. I must disagree with Colin's statement. If you are a complete beginner with Python... then there is going to a learning curve for you... and that curve should be 3.2--- period. It is true that some modules are not ready for 3.x, and it is also true that many installed systems (probably most) do not have 3.x installed. But that is not the point. The point is that 3.x is completely incompatible with 2.x (some call it a dialect, but that is a lie). Python3 is the future of the language, and if you're new to Python, then learn 3.x, move forward and don't look back... seriously. kind regards, m harris From steve+comp.lang.python at pearwood.info Fri May 27 10:49:08 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 14:49:08 GMT Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: <4ddfb9e4$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 10:33:20 -0400, Mel wrote: > sturlamolden wrote: > >> I really don't like the Python 2 syntax of super, as it violates the >> DRY principle: Why do I need to write super(type(self),self) when >> super() will do? Assuming that 'self' will always be named 'self' in my >> code, I tend to patch __builtins__.super like this: >> >> import sys >> def super(): >> self = sys._getframe().f_back.f_locals['self'] >> return __builtins__.super(type(self),self) >> >> This way the nice Python 3.x syntax can be used in Python 2.x. > > Python causes trouble by letting the users get at the internals, but > things like this make it worthwhile. Only if by "worthwhile" you mean "buggy as hell". >>> import sys >>> >>> def super(): ... self = sys._getframe().f_back.f_locals['self'] ... return __builtins__.super(type(self),self) ... >>> class A(object): ... def __init__(self): ... super().__init__() ... >>> class B(A): ... def __init__(self): ... super().__init__() ... >>> a = A() >>> b = B() Traceback (most recent call last): File "", line 1, in File "", line 3, in __init__ [...] File "", line 3, in __init__ RuntimeError: maximum recursion depth exceeded Do not use super(type(self), self), because it does not do what you think it does: b = B() calls B.__init__(self) ... which calls super(type(self), self) = super(B, self) ... which calls A.__init__(self) ... which calls super(type(self), self) = super(B, self) *not* A ... which loops forever type(self) does not return B inside B methods and A inside A methods, it returns the class of the instance. -- Steven From michele.simionato at gmail.com Fri May 27 10:51:05 2011 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 27 May 2011 07:51:05 -0700 (PDT) Subject: Python's super() considered super! In-Reply-To: <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: The fact that even experienced programmers fail to see that super(type(self),self) in Python 2 is NOT equivalent to super() in Python 3 is telling something. From duncan.booth at invalid.invalid Fri May 27 11:05:21 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 May 2011 15:05:21 GMT Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: sturlamolden wrote: > On 26 Mai, 18:31, Raymond Hettinger wrote: >> I just posted a tutorial and how-to guide for making effective use of >> super(). >> >> One of the reviewers, David Beazley, said, "Wow, ?that's really >> great! ? ?I see this becoming the definitive post on the subject" >> >> The direct link is: >> >> ?http://rhettinger.wordpress.com/2011/05/26/super-considered-super/ > > I really don't like the Python 2 syntax of super, as it violates > the DRY principle: Why do I need to write super(type(self),self) > when super() will do? Assuming that 'self' will always be named > 'self' in my code, I tend to patch __builtins__.super like this: > > import sys > def super(): > self = sys._getframe().f_back.f_locals['self'] > return __builtins__.super(type(self),self) > > This way the nice Python 3.x syntax can be used in Python 2.x. > > Oh dear, you haven't thought this one through. After your code above, try this: >>> class A(object): def foo(self): print "A.foo" >>> class B(A): def foo(self): print "B.foo" super().foo() >>> B().foo() B.foo A.foo So far so good. Now try this: >>> class C(B): pass >>> C().foo() ... infinite recursion follows ... Oops. There's a reason why Python 2 requires you to be explicit about the class; you simply cannot work it out automatically at run time. Python 3 fixes this by working it out at compile time, but for Python 2 there is no way around it. -- Duncan Booth http://kupuguy.blogspot.com From harrismh777 at charter.net Fri May 27 11:07:25 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 10:07:25 -0500 Subject: Python's super() considered super! In-Reply-To: <4ddfb9e4$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <4ddfb9e4$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> Python causes trouble by letting the users get at the internals, but >> > things like this make it worthwhile. > Only if by "worthwhile" you mean "buggy as hell". I *don't* believe this... the king of metaphors and bogus analogies has come up with 'buggy as hell' !!? No no, you might have buggy as grubs-under-a-damp-log, or buggy as 'moths-around-an-incandecent-lamp' , or you could have 'hot-as-hell,' but 'buggy-as-hell' just doesn't say what needs say'in... ... I'm just saying.... :) From sturlamolden at yahoo.no Fri May 27 11:11:19 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 08:11:19 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: On 27 Mai, 16:27, sturlamolden wrote: > Assuming that 'self' will always be named > 'self' in my code, I tend to patch __builtins__.super like this: > > import sys > def super(): > ? ? self = sys._getframe().f_back.f_locals['self'] > ? ? return __builtins__.super(type(self),self) A monkey-patch to __builtins__.super would probably also work. Assuming the first argument to the callee is 'self' or 'cls': import sys _super = __builtins__.super def monkeypatch(*args, **kwargs): if (args == ()) and (kwargs=={}): try: obj = sys._getframe().f_back.f_locals['self'] except KeyError: obj = sys._getframe().f_back.f_locals['cls'] return _super(type(obj),obj) else: return _super(*args, **kwargs) class patcher(object): def __init__(self): __builtins__.super = monkeypatch def __del__(self): __builtins__.super = _super _patch = patcher() Sturla From sturlamolden at yahoo.no Fri May 27 11:24:52 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 08:24:52 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: <439eb0a6-ad3c-4049-b35b-22abc1bd8b00@d1g2000yqm.googlegroups.com> On 27 Mai, 17:05, Duncan Booth wrote: > >>> class C(B): pass > >>> C().foo() > > ... infinite recursion follows ... That's true :( From sturlamolden at yahoo.no Fri May 27 11:31:40 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 08:31:40 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> On 27 Mai, 17:05, Duncan Booth wrote: > Oops. There's a reason why Python 2 requires you to be explicit about > the class; you simply cannot work it out automatically at run time. > Python 3 fixes this by working it out at compile time, but for Python 2 > there is no way around it. Then it should be a keyword, not a function. Sturla From steve+comp.lang.python at pearwood.info Fri May 27 11:52:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 15:52:14 GMT Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> Message-ID: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 09:40:53 -0500, harrismh777 wrote: > 3.x is completely incompatible with 2.x (some call it a dialect, > but that is a lie). "Completely incompatible"? A "lie"? import math import random my_list = [3, 5, 7, 9] n = random.choice(my_list) if n%3: func = math.sin else: func = math.cos y = func(math.pi/n)*10 L = ['spam']*(int(y)) for item in L: print(item) is valid syntax in every version of Python from 1.5 to 3.2, and it does the same thing in all of them. Would you care to revise your claims? -- Steven From miki.tebeka at gmail.com Fri May 27 11:57:08 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 27 May 2011 08:57:08 -0700 (PDT) Subject: The worth of comments In-Reply-To: Message-ID: https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw ;) From miki.tebeka at gmail.com Fri May 27 11:57:08 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 27 May 2011 08:57:08 -0700 (PDT) Subject: The worth of comments In-Reply-To: Message-ID: https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw ;) From python at mrabarnett.plus.com Fri May 27 12:02:01 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 27 May 2011 17:02:01 +0100 Subject: Puzzled by list-appending behavior In-Reply-To: <4dhut6lr8aqtfrk6oljr9lmofra6l5rp53@4ax.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <4dhut6lr8aqtfrk6oljr9lmofra6l5rp53@4ax.com> Message-ID: <4DDFCAF9.7080002@mrabarnett.plus.com> On 27/05/2011 07:34, Tim Roberts wrote: > MRAB wrote: >> >> I'd just like to point out that it's a convention, not a rigid rule. > > Reminds me of the catch-phrase from the first Pirates of the Caribbean > movie: "It's more of a guideline than a rule." Much like the Zen of Python. From steve+comp.lang.python at pearwood.info Fri May 27 12:06:05 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 16:06:05 GMT Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> Message-ID: <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 08:31:40 -0700, sturlamolden wrote: > On 27 Mai, 17:05, Duncan Booth wrote: > >> Oops. There's a reason why Python 2 requires you to be explicit about >> the class; you simply cannot work it out automatically at run time. >> Python 3 fixes this by working it out at compile time, but for Python 2 >> there is no way around it. > > Then it should be a keyword, not a function. Why? The fault is not that super is a function, or that you monkey- patched it, or that you used a private function to do that monkey- patching. The fault was that you made a common, but silly, mistake when reasoning about type(self) inside a class. I made the same mistake: assume that type(self) will always be the same class as that the method is defined in. But of course it won't be. With the luxury of hindsight, it is a silly mistake to make, but I promise you that you're not the first, and won't be the last, to make it. -- Steven From python at mrabarnett.plus.com Fri May 27 12:21:50 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 27 May 2011 17:21:50 +0100 Subject: [Python-ideas] Adding 'bytes' as alias for 'latin_1' codec. In-Reply-To: References: <87k4dc8r9j.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: <4DDFCF9E.4050204@mrabarnett.plus.com> On 27/05/2011 10:27, Nick Coghlan wrote: > On Fri, May 27, 2011 at 6:46 PM, Stephen J. Turnbull wrote: >> > What method is invoked to convert the numbers to text? What encoding >> > is used to convert those numbers to text? How does this operation >> > avoid also converting the *bytes* object to text and then reencoding >> > it? >> >> OTOH, Nick, aren't you making this harder than it needs to be? After >> all, > > To me, the defining feature of str.format() over str.__mod__() is the > ability for types to provide their own __format__ methods, rather than > being limited to a predefined set of types known to the interpreter. > If bytes were to reuse the same name, then I'd want to see similar > flexibility. > > Now, a *different* bytes method (bytes.interpolate, perhaps?), limited > to specific types may make sense, but such an alternative *shouldn't* > be conflated with the text formatting API. > > However, proponents of such an addition need to clearly articulate > their use cases and proposed solution in a PEP to make it clear that > they aren't merely trying to perpetuate the bytes/text confusion that > plagues 2.x 8-bit strings. > > We can almost certainly do better when it comes to constructing byte > sequences from component parts, but simply saying "oh, just add a > format() method to bytes objects" doesn't cut it, since the associated > magic methods for str.format are all string based, and bytes > interpolation also needs to address encoding issues for anything that > isn't already a byte sequence. > I would've thought that a "format" (or equivalent) method for bytes would work like struct.pack, so b"{0}".format(23) wouldn't return b'23', but you could have: >>> b'{0:b}'.format(23) b'\x17' From r.richardparker at comcast.net Fri May 27 12:51:25 2011 From: r.richardparker at comcast.net (Richard Parker) Date: Fri, 27 May 2011 09:51:25 -0700 Subject: Python-list Digest, Vol 92, Issue 232 In-Reply-To: References: Message-ID: <60CEF6B3-B9FA-4088-9680-6B063C99B2B6@comcast.net> Sometimes >> I'll drop in suggestions to future maintainers like, "consider >> refactoring with with perform_frobnitz_action()" > > Usually, I address future-me with comments like that (on the > assumption that there's nobody in the world sadistic enough to want to > maintain my code). But I never name future-me, the comments will be > addressed to "the subsequent maintainer" or somesuch. I do assume, > though, that future-me has forgotten everything about the code, and > since past-me left some comments that current-me has read, I think the > assumption is fairly accurate. (Did I *really* write that code? It has > my name on it.....) > > Chris Angelico > Rather than sadistic, one would likely be masochistic to undertake the maintenance of my code :-) I have had many moments where I have later asked the question "Did I write this code?." From irmen at -NOSPAM-xs4all.nl Fri May 27 13:05:02 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Fri, 27 May 2011 19:05:02 +0200 Subject: The worth of comments In-Reply-To: References: <87sjs0apgh.fsf@benfinney.id.au> Message-ID: <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> On 27-05-11 15:54, Grant Edwards wrote: > On 2011-05-27, Ben Finney wrote: >> Richard Parker writes: >> >>> On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: >>> >>>> My experience is that comments in Python are of relatively low >>>> usefulness. (For avoidance of doubt: not *zero* usefulness, merely >>>> low.) > > I've seen plenty of comments who's usefulness was not zero. It was > less than zero. Someone once taught me, "There is one thing worse than having no comments in the source code: having incorrect (or 'lying') comments in the code." Grant, I guess you hint at such comments? Irmen. From ethan at stoneleaf.us Fri May 27 13:12:07 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 10:12:07 -0700 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> <4ddf1571$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DDFDB67.80500@stoneleaf.us> Thorsten Kampe wrote: > * Steven D'Aprano (27 May 2011 03:07:30 GMT) >> Okay, I've stayed silent while people criticize me long enough. What >> exactly did I say that was impolite? > > Nothing. > >> John threw down a distinct challenge: >> >> if Python is really so much better than Python [sic] >> readability wise, why do I have such a hard time dropping >> Perl and moving on? >> [...] >> If I got it wrong about John, oh well, I said it was a guess, and >> trying to get inside someone else's head is always a chancy business. > > Why were you trying to speculate in response to such a - sorry - dumb[1] > question? He asked the question not once, but multiple times (IIRC at least three, possible more) -- after a while it stops being rhetorical. I would say also, if you don't want an answer, don't ask the question. ~Ethan~ From ethan at stoneleaf.us Fri May 27 13:14:44 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 10:14:44 -0700 Subject: bug in str.startswith() and str.endswith() In-Reply-To: <4DDEE1C8.6010107@stoneleaf.us> References: <4DDEE1C8.6010107@stoneleaf.us> Message-ID: <4DDFDC04.3030203@stoneleaf.us> Ethan Furman wrote: > Any reason this is not a bug? Looks like someone else beat me to filing: http://bugs.python.org/issue11828 Looks like they fixed it as well. ~Ethan~ From ethan at stoneleaf.us Fri May 27 13:42:16 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 10:42:16 -0700 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> <87boyoa5ov.fsf@benfinney.id.au> <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DDFE278.8010306@stoneleaf.us> Duncan Booth wrote: > Steven D'Aprano wrote: > >> I was thrilled to learn a new trick, popping keyword arguments before >> calling super, and wondered why I hadn't thought of that myself. How on >> earth did I fail to realise that a kwarg dict was mutable and therefore >> you can remove keyword args, or inject new ones in? >> > Probably because most of the time it is better to avoid mutating kwargs. > Instead of popping an argument you simply declare it as a named argument in > the method signature. Instead of injecting new ones you can pass them as > named arguments. > > > def foo(x=None, **kwargs): > bar(y=2, **kwargs) > > > def bar(**kwargs): > print(kwargs) > >>>> foo(x=1, z=3) > {'y': 2, 'z': 3} >>>> foo(x=1, y=2, z=3) > Traceback (most recent call last): > File "", line 1, in > foo(x=1, y=2, z=3) > File "", line 2, in foo > bar(y=2, **kwargs) > TypeError: bar() got multiple values for keyword argument 'y' And the above error is exactly why you don't want to use named arguments in MI -- because you don't know in what order the methods will be called, you cannot know which named arguments to supply to the method that super() will call next. ~Ethan~ From invalid at invalid.invalid Fri May 27 13:49:40 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 27 May 2011 17:49:40 +0000 (UTC) Subject: The worth of comments References: Message-ID: On 2011-05-27, Miki Tebeka wrote: > https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw ;) I just realized that Usenet is sort of like radio. After hearing/reading somebody for years, I don't seem to have a detailed image of them in my head, but when I finally do see a picture of them, my initial reaction is almost always "no, that's not at all what I thought he/she looked like". Odd. -- Grant Edwards grant.b.edwards Yow! I demand IMPUNITY! at gmail.com From invalid at invalid.invalid Fri May 27 13:53:15 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 27 May 2011 17:53:15 +0000 (UTC) Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: On 2011-05-27, Irmen de Jong wrote: > On 27-05-11 15:54, Grant Edwards wrote: >> On 2011-05-27, Ben Finney wrote: >>> Richard Parker writes: >>> >>>> On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: >>>> >>>>> My experience is that comments in Python are of relatively low >>>>> usefulness. (For avoidance of doubt: not *zero* usefulness, merely >>>>> low.) >> >> I've seen plenty of comments who's usefulness was not zero. It was >> less than zero. > > Someone once taught me, "There is one thing worse than having no > comments in the source code: having incorrect (or 'lying') comments > in the code." > > Grant, I guess you hint at such comments? Yes. :) When trying to find a bug in code written by sombody else, I often first go through and delete all of the comments so as not to be mislead. The comments reflect what the author _thought_ the code did _at_some_point_in_the_past_. What matters is what the code actually does at the present. -- Grant Edwards grant.b.edwards Yow! ... If I had heart at failure right now, gmail.com I couldn't be a more fortunate man!! From ericsnowcurrently at gmail.com Fri May 27 13:56:29 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 27 May 2011 11:56:29 -0600 Subject: Python's super() considered super! In-Reply-To: <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> <87boyoa5ov.fsf@benfinney.id.au> <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 27, 2011 at 4:37 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Fri, 27 May 2011 18:49:52 +1000, Ben Finney wrote: > > > Raymond Hettinger writes: > > > >> Hope you enjoyed the post. > > > > I certainly did. > > > > But I'm not better enlightened on why ?super? is a good thing. > > Perhaps Raymond assumed that by now everybody knows that multiple > inheritance in Python that doesn't use super is buggy. super() was > introduced in version 2.2 in order to overcome bugs in MI, making it > about 8 years old now. > > (Technically, it's only MI with diamond-shaped inheritance, but that > applies to *all* new-style classes. If you're writing multiple > inheritance in Python 3 without using super, your code is a land-mine > waiting to go off. If you're writing single inheritance, it's *still* a > land-mine, just waiting for some poor caller to use it in a MI context.) > > But I do agree with you in that I expected to see at least some > discussion of why super should be actively preferred over calling the > parent class directly. > > Seems like he does just that for most of the first section. > > > The > > exquisite care that you describe programmers needing to maintain is IMO > > just as much a deterrent as the super-is-harmful essay. > > I don't see that Raymond describes anything needing "exquisite care". > It's more common sense really: ensure that your method signature and that > of your parents' match, plus good work-arounds for when they don't. > Anyone using inheritance is almost certainly 98% of the way there, unless > they're writing classes like this and wondering why they don't work :) > > class MyBrokenList(list): > def __len__(self): > n = list.__len__(self, extra=42) > return n + 1 > def __getitem__(self, i): > return list.__getitem__(self) + 1 > def last_item(self): > return list.last_item(self) + 1 > > > I was thrilled to learn a new trick, popping keyword arguments before > calling super, and wondered why I hadn't thought of that myself. How on > earth did I fail to realise that a kwarg dict was mutable and therefore > you can remove keyword args, or inject new ones in? > > Given the plethora of articles that take a dim, if not outright negative, > view of super, it is good to see one that takes a positive view. Thanks > Raymond! > > +1 -eric > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmchase.com Fri May 27 13:58:14 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Fri, 27 May 2011 13:58:14 -0400 Subject: Puzzled by list-appending behavior In-Reply-To: References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddf2003$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1ADD@EMARC112VS01.exchad.jpmchase.net> >I have to say, I do like Python's lack of keywords for these things I thought True/False were among the list of keywords in Python 3.x ? Or are those the only keywords? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From ramit.prasad at jpmchase.com Fri May 27 14:10:11 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Fri, 27 May 2011 14:10:11 -0400 Subject: Python's super() considered super! In-Reply-To: <87wrhcapm2.fsf@benfinney.id.au> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1B2C@EMARC112VS01.exchad.jpmchase.net> >>We also, though, need *real* URLs. Blind URLs through obfuscation >>services have their uses, but surely not in a forum like this. The real >>URL is . I remember reading a news article where a man was arrested (or was it fired) for pornography because he clicked a link. I would *REALLY* prefer not to be 4chan-ed into jail (or fired) because I could not safely tell what a shortened URL really pointed to. Besides, shortened URLs do not live as long and are more likely to fail when people search the archives. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From ethan at stoneleaf.us Fri May 27 14:14:23 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 11:14:23 -0700 Subject: The worth of comments In-Reply-To: References: Message-ID: <4DDFE9FF.4010403@stoneleaf.us> Miki Tebeka wrote: > https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw ;) +1 That was hilarious. ~Ethan~ From ramit.prasad at jpmchase.com Fri May 27 14:17:54 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Fri, 27 May 2011 14:17:54 -0400 Subject: The worth of comments In-Reply-To: References: Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1B6D@EMARC112VS01.exchad.jpmchase.net> >(Did I *really* write that code? It has my name on it.....) Damn those ninja programmers who stole your name and coded something! Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From patty at cruzio.com Fri May 27 14:21:51 2011 From: patty at cruzio.com (Patty) Date: Fri, 27 May 2011 11:21:51 -0700 Subject: The worth of comments References: <4DDFE9FF.4010403@stoneleaf.us> Message-ID: <4AD8771B534548D786F67994517997F0@mycomputer> ----- Original Message ----- From: "Ethan Furman" To: Sent: Friday, May 27, 2011 11:14 AM Subject: Re: The worth of comments > Miki Tebeka wrote: >> https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw ;) > > +1 > > That was hilarious. > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > > I know - since I am not working right now, it totally made me wonder why I put comments in Python code at all -- or even have anything to do with code -- and plans being made to spend the rest of the day laying around in the hammock :) Patty From ian.g.kelly at gmail.com Fri May 27 14:31:14 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 27 May 2011 12:31:14 -0600 Subject: Python's super() considered super! In-Reply-To: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 10:31 AM, Raymond Hettinger wrote: > I just posted a tutorial and how-to guide for making effective use of > super(). I posted this already on the HackerNews thread but it seems to have largely gone unnoticed, so I'm reposting it here. It seems to me that the example of combining built-in dictionary classes is naively optimistic. For starters, OrderedDict, as it happens, does not use super! It calls the dict super-class methods directly. Since dict luckily happens to be the next class in the MRO, this doesn't really matter for the purpose of this example, but I can envision a scenario where some plucky programmer inherits from both OrderedCounter and some other dict subclass, and the result doesn't work because OrderedDict does the wrong thing. And OrderedDict isn't the only one. Maybe for some reason I would like to have an OrderedCounter where all the counts default to 42. So I do this: class DefaultOrderedCounter(defaultdict, OrderedCounter): pass doc = DefaultOrderedCounter(lambda: 42) doc.update('abracadabra') Which results in: Traceback (most recent call last): File "", line 1, in File "c:\python32\lib\collections.py", line 507, in update _count_elements(self, iterable) File "c:\python32\lib\collections.py", line 63, in __setitem__ self.__map[key] = link = Link() AttributeError: 'DefaultOrderedCounter' object has no attribute '_OrderedDict__map' Whoops! Apparently defaultdict doesn't use super either. Of course a better way to do this would be to subclass OrderedCounter and just override the __missing__ method by hand, but that's not the point. The article goes into "How to Incorporate a Non-cooperative Class", which basically says "wrap it up in a proxy class". But that's not really going to work here, since the result would be two separate dicts, with the defaultdictwrapper methods operating on one dict, and the other methods operating on the other. From martin at v.loewis.de Fri May 27 14:38:19 2011 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 27 May 2011 20:38:19 +0200 Subject: [ANN] Python 2.5.6 released Message-ID: <4DDFEF9B.4060000@v.loewis.de> On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.5.6. There were no changes since the release candidate. This is a source-only release that only includes security fixes. The last full bug-fix release of Python 2.5 was Python 2.5.4. Users are encouraged to upgrade to the latest release of Python 2.7 (which is 2.7.1 at this point). This release is most likely the final release of Python 2.5; under the current release policy, no security issues in Python 2.5 will be fixed after October, 2011. This releases fixes issues with the urllib, urllib2, SimpleHTTPServer, and audiop modules. See the release notes at the website (also available as Misc/NEWS in the source distribution) for details of bugs fixed. For more information on Python 2.5.6, including download links for various platforms, release notes, and known issues, please see: http://www.python.org/2.5.6 Highlights of the previous major Python releases are available from the Python 2.5 page, at http://www.python.org/2.5/highlights.html Enjoy this release, Martin Martin v. Loewis martin at v.loewis.de Python Release Manager (on behalf of the entire python-dev team) From rosuav at gmail.com Fri May 27 14:40:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 May 2011 04:40:17 +1000 Subject: Python's super() considered super! In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1B2C@EMARC112VS01.exchad.jpmchase.net> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1B2C@EMARC112VS01.exchad.jpmchase.net> Message-ID: On Sat, May 28, 2011 at 4:10 AM, Prasad, Ramit wrote: >>>We also, though, need *real* URLs. Blind URLs through obfuscation >>>services have their uses, but surely not in a forum like this. The real >>>URL is . > > I remember reading a news article where a man was arrested (or was it fired) for pornography because he clicked a link. I would *REALLY* prefer not to be 4chan-ed into jail (or fired) because I could not safely tell what a shortened URL really pointed to. Besides, shortened URLs do not live as long and are more likely to fail when people search the archives. I've seen FAR more dead links than dead URL shortening services. It's a lot more likely that the destination will go down than that the tinyurl service will lose its data. If you're worried about where you're going, grab a URL renderer; TinyURL.com has "preview mode" which you can set with a cookie, and for others, all you need is something which takes a URL off the clipboard, requests it, gets the Location: header, and puts that on the clipboard for you. I coded such a facility into my MUD client (RosMud), because shortened URLs are important when lines are limited to 80 characters (less some overhead); it'd be quite easy to build a little Python-GTK or Python-TK app that gives you a nice window and makes it easy. Chris Angelico From rosuav at gmail.com Fri May 27 14:46:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 May 2011 04:46:12 +1000 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: On Sat, May 28, 2011 at 4:31 AM, Ian Kelly wrote: > It seems to me that the example of combining built-in dictionary > classes is naively optimistic. So... Can anyone offer a non-trivial example of multiple inheritance that *doesn't* have pitfalls? From what I've seen, MI always seems to require cooperation from the authors of all involved classes. It may be a useful tool when you control everything, but whenever you use someone else's code, there seems to be this massive barrier of risk (if that makes sense). For the DefaultOrderedCounter, I would be strongly inclined to inherit singly, and then manually implement the other half (whichever half is easier); in this case that happens to be trivial (override __missing__), but even were it not, it would be a means of being certain that things won't break. Chris Angelico From ethan at stoneleaf.us Fri May 27 14:56:04 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 11:56:04 -0700 Subject: Puzzled by list-appending behavior In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1ADD@EMARC112VS01.exchad.jpmchase.net> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddf2003$0$29996$c3e8da3$5496439d@news.astraweb.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1ADD@EMARC112VS01.exchad.jpmchase.net> Message-ID: <4DDFF3C4.8070400@stoneleaf.us> Prasad, Ramit wrote: >> I have to say, I do like Python's lack of keywords for these things > > I thought True/False were among the list of keywords in Python 3.x ? Or are those the only keywords? http://docs.python.org/py3k/reference/lexical_analysis.html#keywords False class finally is return None continue for lambda try True def from nonlocal while and del global not with as elif if or yield assert else import pass break except in raise ~Ethan~ From tkpmep at hotmail.com Fri May 27 15:21:53 2011 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: Fri, 27 May 2011 12:21:53 -0700 (PDT) Subject: Python 3.2 bug? Reading the last line of a file References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> Message-ID: This is exactly what I want to do - I can then pick up various elements of the list and turn them into floats, ints, etc. I have not ever used decode, and will look it up in the docs to better understand it. I can't thank everyone enough for the generous serving of help and guidance - I certainly would not have discovered all this on my own. Sincerely Thomas Philips From karim.liateni at free.fr Fri May 27 16:10:30 2011 From: karim.liateni at free.fr (Karim) Date: Fri, 27 May 2011 22:10:30 +0200 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <87sjs4t12l.fsf@castleamber.com> <948l8nF33pU1@mid.individual.net> Message-ID: <4DE00536.2070705@free.fr> On 05/27/2011 03:47 PM, Roy Smith wrote: > In article<948l8nF33pU1 at mid.individual.net>, > Gregory Ewing wrote: > >> John Bokma wrote: >> >>> A Perl programmer will call this line noise: >>> >>> double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", >>> re.IGNORECASE) > One of the truly awesome things about the Python re library is that it > lets you write complex regexes like this: > > pattern = r"""\b # beginning of line > (?P\w+) # a word > \s+ # some whitespace > (?P=word)(?!\w) # the same word again > """ > double_word_re = re.compile(pattern, re.I | re.X) > > Sometimes regex really is the best tool. It's often the most compact, > or fastest, or clearest way to express something complicated. > Fortunately, re.X mode gives you a way to write truly monster regexes > and still having them not be total line noise. > > It's a shame that the Python community has evolved to be so anti-regex > that most people never consider using them. While Perl's attitude to > regex may be "when the only tool you have is a hammer, everything looks > like a nail", Python's seems to be, "I've got a great collection of all > kinds of neat tools, so I'm going to pretend the hammer that's in there > doesn't exist because I once smashed my thumb with it and it hurt a lot". HAHAHAHAHAHA Very funny! This thread is awsome. Cheers Karim From thorsten at thorstenkampe.de Fri May 27 16:38:50 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Fri, 27 May 2011 22:38:50 +0200 Subject: sys.tracebacklimit not working in Python 3.2? Message-ID: Hi, > type test.py import sys sys.tracebacklimit = 0 import doesnotexist > python test.py ImportError: No module named doesnotexist > python3 test.py Traceback (most recent call last): File "test.py", line 4, in import doesnotexist ImportError: No module named doesnotexist The 3.2 documentation says "When set to 0 or less, all traceback information is suppressed and only the exception type and value are printed". Bug? Thorsten From harrismh777 at charter.net Fri May 27 16:40:53 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 15:40:53 -0500 Subject: Beginner needs advice In-Reply-To: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Would you care to revise your claims? No. You have erected a straw-man... once again. Most 2.x code *will not* run correctly in 3.x/ Most of the best improvements and enhancements of 3.x will not back-port to below 2.7, and almost none of them will back-port before 2.6 (class decorations, for instance). Some interfaces have changed! cmp keyword, but lets not bring that up again.... Many syntaxes have changed or have disappeared... ... and some commands (like reload for instance) either don't exist in 3.x, or have been hidden, replaced, or changed... All of these things are for the better, I must add. But, the point is that 3.x is completely incompatible with 2.x in real ways. Arguing that this is *not true* because you are able to create a code block that just happens 'to work' in all versions (and that hasn't been verified yet) does not in *any* way 'prove' that 3.x is a compatible dialect--- far from it... its a straw-man argument. kind regards, m harris From nagle at animats.com Fri May 27 16:47:54 2011 From: nagle at animats.com (John Nagle) Date: Fri, 27 May 2011 13:47:54 -0700 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: <4de00dfd$0$2133$742ec2ed@news.sonic.net> On 5/27/2011 11:46 AM, Chris Angelico wrote: > On Sat, May 28, 2011 at 4:31 AM, Ian Kelly wrote: >> It seems to me that the example of combining built-in dictionary >> classes is naively optimistic. > > So... Can anyone offer a non-trivial example of multiple inheritance > that *doesn't* have pitfalls? From what I've seen, MI always seems > to require cooperation from the authors of all involved classes. Good point. Multiple inheritance is messy enough when the structure is just a tree. When the structure is allowed to be a directed acyclic graph, the whole thing just gets too complicated. It doesn't even necessarily do what you want. If, say, you have two classes that need dictionaries, and were implemented by inheriting from "dict", a class that imports both has one "dict", not two - something that was not anticipated in the design of the original classes. That ought to be an error, not a single "dict" shared by two unconnected classes. What causes this kind of mess is a determination not to report anything as an error if it can be given some kind of meaningful semantics, even if the semantics have marginal value. That's the kind of thinking which leads to [1,2] * 2 returning [1,2,1,2] John Nagle From pythoniks at gmail.com Fri May 27 17:21:46 2011 From: pythoniks at gmail.com (Pascal Chambon) Date: Fri, 27 May 2011 23:21:46 +0200 Subject: GIL in alternative implementations Message-ID: <4DE015EA.4040600@gmail.com> Hello everyone, I've already read quite a bit about the reasons for the GIL in CPython, i.e to summarize, that a more-fine graine locking, allowing real concurrency in multithreaded applications, would bring too much overhead for single-threaded python applications. However, I've also heard that other python implementations (ironpython, jython...) have no GIL, and yet nobody blames them for performance penalties that would be caused by that lack (I especially think about IronPython, whose performances compare quite well to CPython). So I'd like to know: how do these other implementations handle concurrency matters for their primitive types, and prevent them from getting corrupted in multithreaded programs (if they do) ? I'm not only thinking about python types, but also primitive containers and types used in .Net and Java VMs, which aren't atomic elements either at an assembly-level point of view. Do these VMs have some GIL-like limitations, that aren't spoken about ? Are there functionings completely different from the CPython VM, so that the question is not relevant ? Do people consider that they always concern multithreaded applications, and so accept performance penalties that they wouldn't allow in their CPython scripts ? I think you in advance for your lights on these questions. Regards, Pkl [[ Important Note: this is a serious question, trolls and emotionally disturbed persons had better go on their way. ]] -------------- next part -------------- An HTML attachment was scrubbed... URL: From suresh.amritapuri at gmail.com Fri May 27 17:25:52 2011 From: suresh.amritapuri at gmail.com (suresh) Date: Fri, 27 May 2011 14:25:52 -0700 (PDT) Subject: changing current dir and executing a shell script Message-ID: Hi, I want to execute the following command line stuff from inside python. $cd directory $./executable I tried the following but I get errors import subprocess subprocess.check_call('cd dir_name;./executable') Due to filename path issues, I cannot try this version. subprocess.check_call('./dir_name/executable') Any suggestions? thanks suresh From ethan at stoneleaf.us Fri May 27 17:33:38 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 14:33:38 -0700 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> Message-ID: <4DE018B2.2050508@stoneleaf.us> Lew Schwartz wrote: > So, if I read between the lines correctly, you recommend Python 3? Does > the windows version install with a development environment? Dabo, last I checked, uses wxPython, which uses wxWidgets (sp?), which is not yet ported to Python 3. So if you got that route you'll need to stay with 2.7. ~Ethan~ From stefan_ml at behnel.de Fri May 27 17:49:37 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 27 May 2011 23:49:37 +0200 Subject: Python's super() considered super! In-Reply-To: <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 27.05.2011 18:06: > On Fri, 27 May 2011 08:31:40 -0700, sturlamolden wrote: > >> On 27 Mai, 17:05, Duncan Booth wrote: >> >>> Oops. There's a reason why Python 2 requires you to be explicit about >>> the class; you simply cannot work it out automatically at run time. >>> Python 3 fixes this by working it out at compile time, but for Python 2 >>> there is no way around it. >> >> Then it should be a keyword, not a function. > > Why? I think Sturla is referring to the "compile time" bit. CPython cannot know that the builtin super() will be called at runtime, even if it sees a "super()" function call. CPython doesn't evaluate the super call at compile time, it only keeps a reference to the surrounding class in the code object of the method. So super() without arguments basically inherits the class argument from the context the method was found in at compile time. This has two quirks: 1) Copying a method from one class to another keeps the original context. So the class argument to super() is basically fixed at compile time, regardless of the class the method will be executed on at runtime. 2) The class is only kept as a reference when CPython sees a function call that looks like "super" at compile time, which isn't much more than a heuristic. The PEP doesn't mention the first issue, but it is actually explicit about the second issue: http://www.python.org/dev/peps/pep-3135/ """ While super is not a reserved word, the parser recognizes the use of super in a method definition and only passes in the __class__ cell when this is found. Thus, calling a global alias of super without arguments will not necessarily work. """ And the prove: >>> _super = super >>> class T(object): ... def test(self): print('TEST') ... >>> class B(T): ... def meth(self): _super().test() ... >>> B().meth() Traceback (most recent call last): SystemError: super(): __class__ cell not found I assume this is done in order to reduce the chance of accidentally keeping a class object alive for eternity, only because a method was originally defined therein that inherits the class reference in its code object. So it's a tradeoff between memory overhead and usability issues. While I think that the tradeoff is generally ok, I agree with Sturla that a keyword would have been the correct solution, whereas this is a clear "works only in the common cases" approach. Stefan From drsalists at gmail.com Fri May 27 18:14:35 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 27 May 2011 15:14:35 -0700 Subject: changing current dir and executing a shell script In-Reply-To: References: Message-ID: Each command will be run in a distinct subprocess. A CWD is typically local to a given subprocess. So after the first command/subprocess exits, your cd's change is no longer there. Try doing it in one command, with the two original commands separated by a semicolon. On Fri, May 27, 2011 at 2:25 PM, suresh wrote: > Hi, > I want to execute the following command line stuff from inside python. > $cd directory > $./executable > > I tried the following but I get errors > import subprocess > subprocess.check_call('cd dir_name;./executable') > > Due to filename path issues, I cannot try this version. > subprocess.check_call('./dir_name/executable') > > Any suggestions? > thanks > suresh > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thorsten at thorstenkampe.de Fri May 27 18:18:53 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 28 May 2011 00:18:53 +0200 Subject: changing current dir and executing a shell script References: Message-ID: * suresh (Fri, 27 May 2011 14:25:52 -0700 (PDT)) > I want to execute the following command line stuff from inside python. > $cd directory > $./executable > > I tried the following but I get errors > import subprocess > subprocess.check_call('cd dir_name;./executable') > > Due to filename path issues, I cannot try this version. > subprocess.check_call('./dir_name/executable') os.chdir? From marduk at letterboxes.org Fri May 27 18:19:22 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 27 May 2011 18:19:22 -0400 Subject: changing current dir and executing a shell script In-Reply-To: References: Message-ID: <1306534762.116297.3.camel@localhost.localdomain> On Fri, 2011-05-27 at 14:25 -0700, suresh wrote: > Hi, > I want to execute the following command line stuff from inside python. > $cd directory > $./executable > > I tried the following but I get errors > import subprocess > subprocess.check_call('cd dir_name;./executable') > > Due to filename path issues, I cannot try this version. > subprocess.check_call('./dir_name/executable') > You don't want to do this because "cd" is a built-in shell command, and subprocess does not execute within a shell (by default). The proper way to do this is to use the "cwd" keyword argument to subprocess calls, i.e.: >>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir") -a From ethan at stoneleaf.us Fri May 27 18:24:59 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 15:24:59 -0700 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: <4DE024BB.5070902@stoneleaf.us> I suspect the larger issue is that Multiple Inheritance is complex, but folks don't appreciate that. Ask anyone about meta-classes and their eyes bug-out, but MI? Simple! NOT. On the other hand, perhaps the docs should declare that the built-in objects are not designed for MI, so that that, at least, would be one less bug waiting to happen. ~Ethan~ From dinov at microsoft.com Fri May 27 18:52:08 2011 From: dinov at microsoft.com (Dino Viehland) Date: Fri, 27 May 2011 22:52:08 +0000 Subject: GIL in alternative implementations In-Reply-To: <4DE015EA.4040600@gmail.com> References: <4DE015EA.4040600@gmail.com> Message-ID: <6C7ABA8B4E309440B857D74348836F2E15BFF919@TK5EX14MBXC292.redmond.corp.microsoft.com> In IronPython we have fine grained locking on our mutable data structures. In particular we have a custom dictionary type which is designed to allow lock-free readers on common operations while writers take a lock. Our list implementation is similar but in some ways that's trickier to pull off due to features like slicing so if I recall correctly we only have lock-free reads when accessing a single element. For .NET data structures they follow the .NET convention which is up to the data structure. So if you wanted to get every last bit of performance out of your app you could handle thread safety yourself and switch to using the .NET dictionary or list types (although they're a lot less friendly to Python developers). Because of these locks on micro-benchmarks that involve simple list/dict manipulations you do see noticeably worse performance in IronPython vs. CPython. http://ironpython.codeplex.com/wikipage?title=IP27A1VsCPy27Perf&referringTitle=IronPython%20Performance - See the SimpleListManipulation and SimpleDictManipulation as the core examples here. Also CPython's dictionary is so heavily tuned it's hard to beat anyway, but this is a big factor. Finally one of the big differences with both Jython and IronPython is that we have good garbage collectors which don't rely upon reference counting. So one area where CPython gains from having a GIL is a non-issue for us as we don't need to protect ref counts or use interlocked operations for ref counting. From: python-list-bounces+dinov=exchange.microsoft.com at python.org [mailto:python-list-bounces+dinov=exchange.microsoft.com at python.org] On Behalf Of Pascal Chambon Sent: Friday, May 27, 2011 2:22 PM To: python-list at python.org >> Python List Subject: GIL in alternative implementations Hello everyone, I've already read quite a bit about the reasons for the GIL in CPython, i.e to summarize, that a more-fine graine locking, allowing real concurrency in multithreaded applications, would bring too much overhead for single-threaded python applications. However, I've also heard that other python implementations (ironpython, jython...) have no GIL, and yet nobody blames them for performance penalties that would be caused by that lack (I especially think about IronPython, whose performances compare quite well to CPython). So I'd like to know: how do these other implementations handle concurrency matters for their primitive types, and prevent them from getting corrupted in multithreaded programs (if they do) ? I'm not only thinking about python types, but also primitive containers and types used in .Net and Java VMs, which aren't atomic elements either at an assembly-level point of view. Do these VMs have some GIL-like limitations, that aren't spoken about ? Are there functionings completely different from the CPython VM, so that the question is not relevant ? Do people consider that they always concern multithreaded applications, and so accept performance penalties that they wouldn't allow in their CPython scripts ? I think you in advance for your lights on these questions. Regards, Pkl [[ Important Note: this is a serious question, trolls and emotionally disturbed persons had better go on their way. ]] -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri May 27 19:09:11 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 May 2011 09:09:11 +1000 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 28, 2011 at 6:40 AM, harrismh777 wrote: > Most 2.x code *will not* run correctly in 3.x/ ?Most of the best > improvements and enhancements of 3.x will not back-port to below 2.7, and > almost none of them will back-port before 2.6 (class decorations, for > instance). What's with the "below 2.7"? If you're comparing 3.x and 2.x, wouldn't it be most plausible to compare 3.2 and 2.7? And, the biggest reason for 2.x code not running on 3.x is probably the print function. (Guess made without any data beyond my own personal corpus of Python 2 code.) That's something that can be corrected by, oh, I dunno, the 2to3 translator maybe? And the __future__ import makes 2.6+ work the same way as 3.x. > All of these things are for the better, I must add. ?But, the point is that > 3.x is completely incompatible with 2.x in real ways. ?Arguing that this is > *not true* because you are able to create a code block that just happens 'to > work' in all versions (and that hasn't been verified yet) does not in *any* > way 'prove' that 3.x is a compatible dialect--- ?far from it... its a > straw-man argument. You're correct that one code block does not prove the point. But your argument is just as flimsy. To say that "most" 2.x code is incompatible with 3.x is to deny the 2to3 utility, and you're ignoring the people who deliberately write code that can cross-execute on either version - which is really not that difficult, if you take some care and use __future__ directives. Chris Angelico From sturlamolden at yahoo.no Fri May 27 19:57:16 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 16:57:16 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <72ac409d-8e13-4541-a56b-e9bbbc0e4472@s9g2000yqm.googlegroups.com> On 27 Mai, 23:49, Stefan Behnel wrote: > I think Sturla is referring to the "compile time" bit. CPython cannot know > that the builtin super() will be called at runtime, even if it sees a > "super()" function call. Yes. And opposite: CPython cannot know that builtin super() is not called, even if it does not see the name 'super'. I can easily make foo() alias super(). In both cases, the cure is a keyword -- or make sure that __class__ is always defined. If super is to be I keyword, we could argue that self and cls should be keywords as well, and methods should always be bound. That speaks in favour of a super() function. But then it should always be evaluated at run- time, without any magic from the parser. Magic functions belong in Perl, not Python. Sturla From ryan at rfk.id.au Fri May 27 19:57:56 2011 From: ryan at rfk.id.au (Ryan Kelly) Date: Sat, 28 May 2011 09:57:56 +1000 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: <1306540676.2113.4.camel@durian> On Fri, 2011-05-27 at 15:05 +0000, Duncan Booth wrote: > sturlamolden wrote: > > I really don't like the Python 2 syntax of super, as it violates > > the DRY principle: Why do I need to write super(type(self),self) > > when super() will do? Assuming that 'self' will always be named > > 'self' in my code, I tend to patch __builtins__.super like this: > > > > import sys > > def super(): > > self = sys._getframe().f_back.f_locals['self'] > > return __builtins__.super(type(self),self) > > > > This way the nice Python 3.x syntax can be used in Python 2.x. > > > > > Oh dear, you haven't thought this one through. > > ...snip... > > >>> C().foo() > ... infinite recursion follows ... > > Oops. There's a reason why Python 2 requires you to be explicit about > the class; you simply cannot work it out automatically at run time. > Python 3 fixes this by working it out at compile time, but for Python 2 > there is no way around it. Oh? There's not much that can't be done at runtime if you're willing to work hard enough. Let me propose the following awful awful hack: import sys _builtin_super = __builtins__.super _sentinel = object() def _auto_super(typ=_sentinel,type_or_obj=_sentinel): """Automagically call correct super() at runtime""" # Infer the correct call if used without arguments. if typ is _sentinel: # We'll need to do some frame hacking. f = sys._getframe(1) # Get the first positional argument of the function. type_or_obj = f.f_locals[f.f_code.co_varnames[0]] # Get the MRO for investigation try: mro = type_or_obj.__mro__ except AttributeError: try: mro = type_or_obj.__class__.__mro__ except AttributeError: raise RuntimeError("super() used with old-style class") # Now, find the class owning the currently-executing method. for typ in mro: for meth in typ.__dict__.itervalues(): if not isinstance(meth,type(_auto_super)): continue if meth.func_code is f.f_code: # Aha! Found you. break else: continue break else: raise RuntimeError("super() called outside a method") # Now just dispatch to builtin super. if type_or_obj is not _sentinel: return _builtin_super(typ,type_or_obj) return _builtin_super(typ) Now, try is with the following: class Base(object): def hello(self,msg): print "hello", msg class Sub1(Base): def hello(self,msg): print "gunna say it" super().hello(msg) class Sub2(Base): def hello(self,msg): print "yes I am" super().hello(msg) class Diamond(Sub1,Sub2): def hello(self,msg): print "here we go..." super().hello(msg) d = Diamond() d.hello("autosuper!") And you get the expected output: here we go... gunna say it yes I am hello autosuper! There may well be some cases where this breaks down, but it seems to do the right thing in simple cases. Not that I'm recommending anyone use this, of course... Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From sturlamolden at yahoo.no Fri May 27 20:04:00 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 17:04:00 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27 Mai, 18:06, Steven D'Aprano wrote: > Why? The fault is not that super is a function, or that you monkey- > patched it, or that you used a private function to do that monkey- > patching. The fault was that you made a common, but silly, mistake when > reasoning about type(self) inside a class. That was indeed a silly mistake, but not what I am talking about. See Stefan's reponse. Sturla From harrismh777 at charter.net Fri May 27 21:02:39 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 20:02:39 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > To say that "most" 2.x code is > incompatible with 3.x is to deny the 2to3 utility, Oh, yes absolutely. Please don't misunderstand... anyone... I'm not saying that code cannot be migrated... migration can usually occur between incompatible releases and and between languages!... all I'm saying is that 3.x is not compatible with 2.x code (completely not compatible), and if you're a noob there is no reason to learn 2.x/ Learn 3.x and pickup whatever needs to be gained from 2.x if it comes up... we're talking about learning python as a newbie--- go with 3.x and never look back... seriously... > and you're ignoring > the people who deliberately write code that can cross-execute on > either version - which is really not that difficult, That's what I do... but I'm not a newbie. I have existing code that needs to be migrated, and I have an interest in creating research apps that will run on existing 2.x systems but will be ready and waiting for the time when the system moves to 3.x. I need to know both 2.6 and 3.2 very well. And I'll be honest about this, it is very frustrating. There are literally hundreds of changes and variations (its all in the details). Many Pythonists are not honest about this... because they don't want to scare folks away from 3.x, and I don't really blame them. But the true picture is that 3.x is (way better) and completely incompatible with 2.x. Lying about this isn't helpful to anyone coming on board with Python. Just tell them the truth... kind regards, m harris From drsalists at gmail.com Fri May 27 21:23:19 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 27 May 2011 18:23:19 -0700 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> Message-ID: On Fri, May 27, 2011 at 7:40 AM, harrismh777 wrote: > Colin J. Williams wrote: > >> It would be safer to stick with Python 2.7 initially and then consider >> the transition to 3.2 later. >> > > I must disagree with Colin's statement. If you are a complete beginner with > Python... then there is going to a learning curve for you... and that curve > should be 3.2--- period. > I almost agree with this, but not quite: A newbie should start with 3.2, but regrettably fall back to 2.7 -=IF=- there's a necessary dependency that hasn't been updated for whatever project(s) they're working on. > > The point is that 3.x is completely incompatible with 2.x (some call it a > dialect, but that is a lie). Python3 is the future of the language, and if > you're new to Python, then learn 3.x, move forward and don't look back... > seriously. > 3.x and 2.x are not that extremely incompatible. You usually can't just take 2.x code and run it, unmodified, on 3.x. However, there is a common subset that is pretty viable. EG: http://stromberg.dnsalias.org/~dstromberg/backshift/ Backshift is a relatively substantial piece of code (4400 lines and counting), but it runs fine on CPython 2.x, CPython 3.x, PyPy and Jython (Jython just slightly post-2.5.2 - they aren't planning to cut a new release that's compatible, but it's in their SCM), without any help from 2to3 or 3to2. It was written from the start with the intent of being very portable. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri May 27 21:30:03 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 18:30:03 -0700 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DE0501B.8030901@stoneleaf.us> harrismh777 wrote: > Chris Angelico wrote: >> To say that "most" 2.x code is >> incompatible with 3.x is to deny the 2to3 utility, > > all I'm > saying is that 3.x is not compatible with 2.x code (completely not > compatible) > >> and you're ignoring >> the people who deliberately write code that can cross-execute on >> either version - which is really not that difficult, > > That's what I do... > > Lying about this isn't helpful to anyone coming > on board with Python. Just tell them the truth... Um -- how can you have on the one hand "completely not compatible" and on the other "code that can cross-execute on either version"? ~Ethan~ From suresh.amritapuri at gmail.com Fri May 27 21:33:18 2011 From: suresh.amritapuri at gmail.com (suresh) Date: Fri, 27 May 2011 18:33:18 -0700 (PDT) Subject: changing current dir and executing a shell script In-Reply-To: Message-ID: <609187f7-7100-4641-a185-08b93283bad9@glegroupsg2000goo.googlegroups.com> On Friday, May 27, 2011 3:19:22 PM UTC-7, Albert Hopkins wrote: > On Fri, 2011-05-27 at 14:25 -0700, suresh wrote: > > Hi, > > I want to execute the following command line stuff from inside python. > > $cd directory > > $./executable > > > > I tried the following but I get errors > > import subprocess > > subprocess.check_call('cd dir_name;./executable') > > > > Due to filename path issues, I cannot try this version. > > subprocess.check_call('./dir_name/executable') > > > > You don't want to do this because "cd" is a built-in shell command, and > subprocess does not execute within a shell (by default). > > The proper way to do this is to use the "cwd" keyword argument to > subprocess calls, i.e.: > > >>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir") > > -a It works. thank you very much. I have been struggling with this for a veryyyyy long time. suresh From suresh.amritapuri at gmail.com Fri May 27 21:33:18 2011 From: suresh.amritapuri at gmail.com (suresh) Date: Fri, 27 May 2011 18:33:18 -0700 (PDT) Subject: changing current dir and executing a shell script In-Reply-To: Message-ID: <609187f7-7100-4641-a185-08b93283bad9@glegroupsg2000goo.googlegroups.com> On Friday, May 27, 2011 3:19:22 PM UTC-7, Albert Hopkins wrote: > On Fri, 2011-05-27 at 14:25 -0700, suresh wrote: > > Hi, > > I want to execute the following command line stuff from inside python. > > $cd directory > > $./executable > > > > I tried the following but I get errors > > import subprocess > > subprocess.check_call('cd dir_name;./executable') > > > > Due to filename path issues, I cannot try this version. > > subprocess.check_call('./dir_name/executable') > > > > You don't want to do this because "cd" is a built-in shell command, and > subprocess does not execute within a shell (by default). > > The proper way to do this is to use the "cwd" keyword argument to > subprocess calls, i.e.: > > >>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir") > > -a It works. thank you very much. I have been struggling with this for a veryyyyy long time. suresh From dan.kluev at gmail.com Fri May 27 22:06:43 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sat, 28 May 2011 13:06:43 +1100 Subject: GIL in alternative implementations In-Reply-To: <4DE015EA.4040600@gmail.com> References: <4DE015EA.4040600@gmail.com> Message-ID: > So I'd like to know: how do these other implementations handle concurrency > matters for their primitive types, and prevent them from getting corrupted > in multithreaded programs (if they do) ? I'm not only thinking about python > types, but also primitive containers and types used in .Net and Java VMs, > which aren't atomic elements either at an assembly-level point of view. Well, they definitely have some shortcomings: test.py: from threading import Thread class X(object): pass obj = X() obj.x = 0 def f(*args): for i in range(10000): obj.x += 1 threads = [] for i in range(100): t = Thread(target=f) threads.append(t) t.start() for t in threads: while t.isAlive(): t.join(1) print(obj.x) > python test.py 1000000 > pypy test.py 1000000 > jython-2.5 test.py 19217 > ipy test.py 59040 Not that this thing is reasonable to do in real code, but cpython and other implementations with GIL at least give you some safety margin. -- With best regards, Daniel Kluev From mhammond at skippinet.com.au Fri May 27 22:10:36 2011 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 28 May 2011 12:10:36 +1000 Subject: bdist_wininst: install_script not run on uninstall In-Reply-To: <201105261000.04741.wbsoft@xs4all.nl> References: <201105252128.17504.wbsoft@xs4all.nl> <4DDD94EF.6010804@gmail.com> <201105261000.04741.wbsoft@xs4all.nl> Message-ID: <4DE0599C.9010103@skippinet.com.au> On 26/05/2011 6:00 PM, Wilbert Berendsen wrote: > Op donderdag 26 mei 2011 schreef Mark: > >> Wilbert wrote: >> >>> can anybody find out why the install script is not run? >> >> Works for me in the pywin32 install script - maybe you should make the >> smallest possible example that doesn't work and post the entire thing here? Sorry, I was wrong. It apparently does *not* work for me either :( This is a bug in distutils/bdist_wininst - I just created http://bugs.python.org/issue12200 with the details and your samples, and sadly I can't think of a work around you can use until this is fixed (which I might get to soon, but not this weekend...) Cheers, Mark From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sat May 28 01:06:53 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sat, 28 May 2011 07:06:53 +0200 Subject: Beginner needs advice In-Reply-To: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 27.05.2011 17:52 schrieb Steven D'Aprano: > On Fri, 27 May 2011 09:40:53 -0500, harrismh777 wrote: > >> 3.x is completely incompatible with 2.x (some call it a dialect, >> but that is a lie). > > "Completely incompatible"? A "lie"? Hard word, but it is true. Many things can and will fall on your feet when moving. There are very many subtle differences. > import math > import random > my_list = [3, 5, 7, 9] > n = random.choice(my_list) > if n%3: > func = math.sin > else: > func = math.cos > > y = func(math.pi/n)*10 > L = ['spam']*(int(y)) > for item in L: > print(item) > > > is valid syntax in every version of Python from 1.5 to 3.2, and it does > the same thing in all of them. C and C++ guys complain if these languages are intermixed. Even there it is possible to write a program which is valid in both of them. Nevertheless, they are two different languages. So are Py2 and Py3, IMHO. Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sat May 28 01:29:48 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sat, 28 May 2011 07:29:48 +0200 Subject: Python's super() considered super! In-Reply-To: <72ac409d-8e13-4541-a56b-e9bbbc0e4472@s9g2000yqm.googlegroups.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> <72ac409d-8e13-4541-a56b-e9bbbc0e4472@s9g2000yqm.googlegroups.com> Message-ID: Am 28.05.2011 01:57 schrieb sturlamolden: > Yes. And opposite: CPython cannot know that builtin super() is not > called, > even if it does not see the name 'super'. I can easily make foo() > alias super(). Another alternative would have been to make use of __xxx magic. If every class had an "automatically available" attribute, e. g. ___classname which thus could be accessed via __classname from inside, keeping the 2.x syntax would have been the best, using super(__classname, self). > In both cases, the cure is a keyword -- or make sure that __class__ > is always defined. > > If super is to be I keyword, we could argue that self and cls should > be keywords as well, and methods should always be bound. That speaks in > favour of a super() function. But then it should always be evaluated at run- > time, without any magic from the parser. > > Magic functions belong in Perl, not Python. ACK. Thomas From pavlovevidence at gmail.com Sat May 28 01:32:03 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 27 May 2011 22:32:03 -0700 (PDT) Subject: Why did Quora choose Python for its development? In-Reply-To: Message-ID: On Friday, May 27, 2011 6:47:21 AM UTC-7, Roy Smith wrote: > In article <948l8n... at mid.individual.net>, > Gregory Ewing wrote: > > > John Bokma wrote: > > > > > A Perl programmer will call this line noise: > > > > > > double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", > > > re.IGNORECASE) > > One of the truly awesome things about the Python re library is that it > lets you write complex regexes like this: > > pattern = r"""\b # beginning of line > (?P\w+) # a word > \s+ # some whitespace > (?P=word)(?!\w) # the same word again > """ > double_word_re = re.compile(pattern, re.I | re.X) Perl has the X flag as well, in fact I'm pretty sure Perl originated it. Just saying. Carl Banks From steve+comp.lang.python at pearwood.info Sat May 28 01:40:15 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 May 2011 05:40:15 GMT Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de08abe$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 20:02:39 -0500, harrismh777 wrote: > But the true picture is that 3.x is (way better) and completely > incompatible with 2.x. Lying about this isn't helpful to anyone coming > on board with Python. Just tell them the truth... Take your own advice and stop accusing others of lying when it is you spreading falsehoods about Python 3. It is simply NOT TRUE that Python 3 is "completely incompatible" with Python 2. You keep making this accusation, but even the most cursory look at Python syntax, keywords, built-in objects, execution model, and standard library show that most things keep the same interface, and most of the remainder change in backward compatible ways. There are some backwards incompatibilities, but nearly all of them can be resolved by an automated fixer, no human intelligence required. Far from being "completely incompatible", the truth is that Python 2.7 and 3.2 are more like 99% compatible. This is why there are 168 identical .py files in the Python 2.7 and 3.2a standard libraries. [steve at sylar ~]$ diff -rqbs --exclude="*.py[co]" /usr/local/lib/ python2.7/ /usr/local/lib/python3.2/ | grep identical | grep \\.py | wc -l 168 Calling Python 2 and Python 3 "different languages", as you have done, is simply wrong. Lisp and Python are different languages; Ruby and Python are different languages. Forth and Python are different languages. Python 2 and 3 are not. They are the same language that share nearly everything in common but have a few significant differences. Calling them "completely incompatible" is completely inaccurate. -- Steven From davids at webmaster.com Sat May 28 01:56:42 2011 From: davids at webmaster.com (David Schwartz) Date: Fri, 27 May 2011 22:56:42 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On May 20, 12:00?am, Jonathan de Boyne Pollard wrote: > Indeed. And the algorithms that are employed to perform the operations > so described are recursive. Actually, they almost never are. Iterative algorithms are almost always used to avoid a stack explosion. However, the terminology is still correct. When you are asked if the operation should be performed recursively, it is asking whether you want the same effect you would get if a recursive algorithm was used. Essentially, there is an implied 'as if' rule. The user doesn't care how the program accomplishes the task, the user just needs to specify what task the program should accomplish. This is common throughout the discipline of programming. (Most standards have an explicit 'as if' rule that says that when the standard specifies X, they don't literally mean that X must happen. They mean the behavior must be indistinguishable from X happening.) DS From steve+comp.lang.python at pearwood.info Sat May 28 02:15:52 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 May 2011 06:15:52 GMT Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 15:40:53 -0500, harrismh777 wrote: > Steven D'Aprano wrote: >> Would you care to revise your claims? > > No. > > > You have erected a straw-man... once again. You keep using that term, but it is clear to me that you don't have the foggiest idea of what the straw-man fallacy is. A straw man is not when somebody points out holes in your argument, or unwanted implications that you didn't realise were there. It is when somebody makes claims on your behalf that you did not make to discredit you, not because you don't understand the implications of your own argument. You stated that Python 2 and Python 3 are COMPLETELY INCOMPATIBLE -- your words, not mine. You have repeated that claim, in this very post, and others, despite having been shown that they are not completely incompatible at all, that it is possible to write both forward and backward compatible code that works in every version of Python from 1.5 through 3.2 inclusive. Yes, it is true that you can also write code that works in 2.5 but not 3.2, but so what? You can also write code that works in 2.5 but not 2.6: raise "some error" # works in 2.5 and older Or 2.4 and 2.5: True = 23 # works in 2.4 and older or 2.3 and 2.4: None = 42 # works in 2.3 and older Do you think that Python 2.3, 2.4, 2.5 and 2.6 are four completely different languages, and if not, why not? Python 3 is not the first backwards incompatible version of Python. [...] > All of these things are for the better, I must add. But, the point is > that 3.x is completely incompatible with 2.x in real ways. And you've done it again, despite the fact that you can write compatible code that works in all versions of Python from 1.5 to 3.2, and easily write non-trivial code that works in 2.7 and 3.2. For larger projects, it's probably better to keep a separate 2.x and 3.x fork, but that's for convenience, nothing more: numpy, for example, supports 2 and 3 out of a single code base. http://www.mail-archive.com/numpy-discussion%40scipy.org/msg26524.html Perhaps you don't understand what "completely" means and are confusing it with "slightly". -- Steven From thorsten at thorstenkampe.de Sat May 28 02:38:54 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 28 May 2011 08:38:54 +0200 Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Thomas Rachel (Sat, 28 May 2011 07:06:53 +0200) > Am 27.05.2011 17:52 schrieb Steven D'Aprano: > > On Fri, 27 May 2011 09:40:53 -0500, harrismh777 wrote: > >> 3.x is completely incompatible with 2.x (some call it a dialect, > >> but that is a lie). > > > > "Completely incompatible"? A "lie"? > > Hard word, but it is true. Many things can and will fall on your feet > when moving. I think we should stop talking about (in)compatability because everyone seems to associate something different with that term (incompatible = "no Python2 to code will run with Python3", "not all Python2 code will run with Python3"). The question is: if you want (or have) to run your code under Python3, how likely is that it will run unmodified? My experience is: unless the code is especially written with Python3 compatability or just a short snippet, it's actually quite unlikely that it will run. I modified three programs/modules (none of them written with Python3 in mind - I was thinking that Python 3000 would come out some day after Perl 6, PHP 6 and GNU Hurd; how could I know that the Python developers actually mean business?) One is a tool box kind of module. I had to insert lots of "list()" and add a complete function that would deal with the different behaviour of "sort". Probably easy to find the problems if you have extensive unit tests but without it was a tedious nightmare. The second a kind of script template. gettext.install has no "unicode = True". Easy fix but I wondered why Python 3 does not ignore the keyword simply. The third, a more real world complete application using PyQt. Took me about a day to fix. The problem was not just with the code but also with the tools (pyuic4, pyrcc4). Without the PyQt mailing list this wouldn't have been possible. Still: a complete workday (or even more) for 150 lines of code. Thorsten From thorsten at thorstenkampe.de Sat May 28 02:42:21 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 28 May 2011 08:42:21 +0200 Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Thorsten Kampe (Sat, 28 May 2011 08:38:54 +0200) > My experience is: unless the code is especially written with Python3 > compatability [...] Oops, I meant "unless the code is specifically written with Python3 compatability in mind [...]" Thorsten From rosuav at gmail.com Sat May 28 02:44:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 May 2011 16:44:47 +1000 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 28, 2011 at 4:38 PM, Thorsten Kampe wrote: > The question is: if you want (or have) to run your code under Python3, > how likely is that it will run unmodified? My experience is: unless the > code is especially written with Python3 compatability or just a short > snippet, it's actually quite unlikely that it will run. > But what about the 2to3 tool? If you use that, then how much more is there to deal with? I installed Python 3 and found that a little bandwidth monitor stopped working. After running it through 2to3, there were only a couple of things needing fixing, including the HTTPS library (it didn't like my Unicode strings, I had to go b" " for them), but the bulk of it was fine. Chris Angelico From __peter__ at web.de Sat May 28 03:41:55 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 28 May 2011 09:41:55 +0200 Subject: changing current dir and executing a shell script References: Message-ID: Albert Hopkins wrote: > On Fri, 2011-05-27 at 14:25 -0700, suresh wrote: >> I want to execute the following command line stuff from inside python. >> $cd directory >> $./executable >> >> I tried the following but I get errors >> import subprocess >> subprocess.check_call('cd dir_name;./executable') >> >> Due to filename path issues, I cannot try this version. >> subprocess.check_call('./dir_name/executable') > You don't want to do this because "cd" is a built-in shell command, and > subprocess does not execute within a shell (by default). The problem is not that cd is built-in, but that there is no shell at all. You can change that with shell=True: >>> subprocess.check_call("cd /usr/share; pwd; cd /usr/lib; pwd", shell=True) /usr/share /usr/lib But I agree with you that > The proper way to do this is to use the "cwd" keyword argument to > subprocess calls, i.e.: > >>>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir") From steve+comp.lang.python at pearwood.info Sat May 28 04:13:52 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 May 2011 08:13:52 GMT Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de0aebf$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 28 May 2011 08:38:54 +0200, Thorsten Kampe wrote: > * Thomas Rachel (Sat, 28 May 2011 07:06:53 +0200) >> Am 27.05.2011 17:52 schrieb Steven D'Aprano: >> > On Fri, 27 May 2011 09:40:53 -0500, harrismh777 wrote: >> >> 3.x is completely incompatible with 2.x (some call it a dialect, but >> >> that is a lie). >> > >> > "Completely incompatible"? A "lie"? >> >> Hard word, but it is true. Many things can and will fall on your feet >> when moving. > > I think we should stop talking about (in)compatability because everyone > seems to associate something different with that term (incompatible = > "no Python2 to code will run with Python3", "not all Python2 code will > run with Python3"). There is a difference between "completely incompatible" and merely "incompatible to some degree". It just takes *one* tiny incompatibility to stop a program running, so "will it run unmodified?" is hardly a good measure of the degree of incompatibility. Python 2.5 and 2.6 are incompatible to some degree. I recently had to port a client's program from 2.3 to 2.6. I did it in two steps: about two hours to get it working in 2.5, then the same to get it working in 2.6, and then about a day of effort to iron out all the display issues in Tkinter (such as text being shown in giant letters). Judging by the binary Yes/No "does it run unmodified?" test, I'd have to say that Python 2.3, 2.5 and 2.6 are "completely different" -- which would be foolish. Nobody sensible applies such a simple-minded, overly strict test to minor releases, or even between major releases like 1.5 versus 2.0. What would be the point? It is not the least bit helpful to learn that your 2.3 code doesn't run unmodified in 2.6. (Learning that it does, on the other hand, is useful. But such code is in a minority.) And yet some people are willing to throw commonsense away and apply such an obviously unsuitable test to Python 3. These people vehemently insist that the differences between Python 2.7 and 3.2 are of the same qualitative kind as between Ruby and PHP (they're *different languages* you see, not merely different dialects of the same language, and anyone who tells you different is not just mistaken but *lying*). > The question is: if you want (or have) to run your code under Python3, > how likely is that it will run unmodified? That's not a useful question. The useful question is to ask how much effort is it to make the code run in the new version. The effort might be zero (but probably isn't), or it might be a minute, or an hour, or a day, or six months... that depends partly on the complexity of your code and partly on the differences between Python 2.x and 3.x. A trivial app might take three minutes to port from Python 2.5 to 3.2. A complicated app might take three months to port from 2.5 to 2.6. What generalization do we make from this? > My experience is: unless the > code is especially written with Python3 compatability or just a short > snippet, it's actually quite unlikely that it will run. You describe taking a full day to upgrade a 150 line PyQt application. Only it wasn't a 150 line application, was it? By your own admission, much of the problems were in the library, PyQt, so it was more like 150,000 lines. (Or whatever the size of PyQt is...) Rather than "it took a full day to upgrade 150 lines to use Python 3, that's terrible!", it is more like "it only took a day to upgrade my 150 line app *and* work around a whole lot of problems with a huge library, that's really great!" -- Steven From greg.ewing at canterbury.ac.nz Sat May 28 04:30:15 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 28 May 2011 20:30:15 +1200 Subject: The worth of comments In-Reply-To: References: Message-ID: <94bq4pFoadU1@mid.individual.net> Grant Edwards wrote: > After hearing/reading somebody for years, I don't seem to have a > detailed image of them in my head, but when I finally do see a picture > of them, my initial reaction is almost always "no, that's not at all > what I thought he/she looked like". It works the other way, too. I've known what Terry Pratchett looks like for many years from the pictures on his books. When I heard him on the radio for the first time recently, I thought, "Wait a minute, that's not what his voice is supposed to sound like!" -- Greg From usenet at solar-empire.de Sat May 28 05:55:34 2011 From: usenet at solar-empire.de (Marc Christiansen) Date: Sat, 28 May 2011 11:55:34 +0200 Subject: GIL in alternative implementations References: <4DE015EA.4040600@gmail.com> Message-ID: Daniel Kluev wrote: > test.py: > > from threading import Thread > class X(object): > pass > obj = X() > obj.x = 0 > > def f(*args): > for i in range(10000): > obj.x += 1 > > threads = [] > for i in range(100): > t = Thread(target=f) > threads.append(t) > t.start() > > for t in threads: > while t.isAlive(): > t.join(1) > > print(obj.x) > >> python test.py > 1000000 >> pypy test.py > 1000000 >> jython-2.5 test.py > 19217 >> ipy test.py > 59040 > > Not that this thing is reasonable to do in real code, but cpython and > other implementations with GIL at least give you some safety margin. > Sure? ;) > for p in python2.4 python2.5 python2.6 python2.7 python3.1 python3.2; do echo $p; $p /tmp/test.py; $p /tmp/test.py; done python2.4 525369 736202 python2.5 449496 551023 python2.6 903405 937335 python2.7 885834 910144 python3.1 866557 766842 python3.2 1000000 1000000 So even CPython (at least < 3.2) isn't safe. And I wouldn't rely on 3.2 not to break. Marc From __peter__ at web.de Sat May 28 07:09:44 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 28 May 2011 13:09:44 +0200 Subject: GIL in alternative implementations References: <4DE015EA.4040600@gmail.com> Message-ID: Daniel Kluev wrote: >> So I'd like to know: how do these other implementations handle >> concurrency matters for their primitive types, and prevent them from >> getting corrupted in multithreaded programs (if they do) ? I'm not only >> thinking about python types, but also primitive containers and types used >> in .Net and Java VMs, which aren't atomic elements either at an >> assembly-level point of view. > > Well, they definitely have some shortcomings: > > test.py: > > from threading import Thread > class X(object): > pass > obj = X() > obj.x = 0 > > def f(*args): > for i in range(10000): > obj.x += 1 > > threads = [] > for i in range(100): > t = Thread(target=f) > threads.append(t) > t.start() > > for t in threads: > while t.isAlive(): > t.join(1) > > print(obj.x) > >> python test.py > 1000000 >> pypy test.py > 1000000 >> jython-2.5 test.py > 19217 >> ipy test.py > 59040 > > Not that this thing is reasonable to do in real code, but cpython and > other implementations with GIL at least give you some safety margin. The problem with your code is that it gives the wrong result when a thread reads obj.x, then suspends, then another thread reads obj.x and finally both threads store the same value+1 back. That problem has nothing to do with the GIL which just prohibits that two threads can run at the same time, on different cores. It occurs because obj.x += 1 is not an atomic operation. That lack of atomicity should be obvious if you take a look at the byte-code: >>> def f(): ... obj.x += 1 ... >>> dis.dis(f) 2 0 LOAD_GLOBAL 0 (obj) 3 DUP_TOP 4 LOAD_ATTR 1 (x) 7 LOAD_CONST 1 (1) 10 INPLACE_ADD 11 ROT_TWO 12 STORE_ATTR 1 (x) 15 LOAD_CONST 0 (None) 18 RETURN_VALUE [Marc Christiansen] > So even CPython (at least < 3.2) isn't safe. And I wouldn't rely on 3.2 > not to break. I don't know why it /seems/ to work in 3.2 more often than in 2.x, but in general bugs that occur only sporadically are typical for multithreaded code... From wolfgang at rohdewald.de Sat May 28 07:16:30 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Sat, 28 May 2011 13:16:30 +0200 Subject: GIL in alternative implementations In-Reply-To: References: <4DE015EA.4040600@gmail.com> Message-ID: <201105281316.30715.wolfgang@rohdewald.de> On Samstag 28 Mai 2011, Marc Christiansen wrote: > And I wouldn't rely on 3.2 > not to break. it breaks too like it should, but only rarely like one out of 10 times i5:/pub/src/gitgames/kajongg/src$ python3.2 test.py 1000000 i5:/pub/src/gitgames/kajongg/src$ python3.2 test.py 1000000 i5:/pub/src/gitgames/kajongg/src$ python3.2 test.py 980000 i5:/pub/src/gitgames/kajongg/src$ python3.2 test.py 1000000 -- Wolfgang From cjw at ncf.ca Sat May 28 08:26:06 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 28 May 2011 08:26:06 -0400 Subject: Question about isodate In-Reply-To: <324535.36827.qm@web114716.mail.gq1.yahoo.com> References: <324535.36827.qm@web114716.mail.gq1.yahoo.com> Message-ID: On 26-May-11 07:48 AM, truongxuan quang wrote: > Hello list, > > I am installing and testing istSOS wrote base on Python with its > extension like gdal, isodate, easy istall, setuptool, psycopg. I have > already installed all these stuff when I was using method POST the error > appear is "_No module named mx.DateTime.ISO_" , could you please give me > your command and advice. > > Many thanks > > Quang > Does this help? http://www.google.com/url?sa=t&source=web&cd=1&ved=0CB0QFjAA&url=http%3A%2F%2Fwww.egenix.com%2Fproducts%2Fpython%2FmxBase%2FmxDateTime%2F&rct=j&q=mxdatetime&ei=eengTYf5MM6EtgfdzeSoBw&usg=AFQjCNEsnznUS1kZ_zAzbSxGlP2IF6BsTg&sig2=3GgXQ9caWtvHTwzZoJOBuQ&cad=rja Colin W. From bch.itbgcthate at gmail.com Sat May 28 08:27:52 2011 From: bch.itbgcthate at gmail.com (bch) Date: Sat, 28 May 2011 05:27:52 -0700 (PDT) Subject: and becomes or and or becomes and References: <4dd9aaac$0$29996$c3e8da3$5496439d@news.astraweb.com> <71ab1ccc-c2c0-474f-b7bb-1000754317e4@z13g2000prk.googlegroups.com> Message-ID: <22197160-095a-4285-8dc4-1814e00a8181@s41g2000prb.googlegroups.com> On May 23, 11:30?pm, rusi wrote: > On May 23, 5:30?am, Steven D'Aprano > > > +comp.lang.pyt... at pearwood.info> wrote: > > On Sun, 22 May 2011 15:39:33 -0700, Tim Roberts wrote: > > > Stef Mientki wrote: > > > >>must of us will not use single bits these days, but at first sight, this > > >>looks funny : > > > >>>>> a=2 > > >>>>> b=6 > > >>>>> a and b > > >>6 > > >>>>> a & b > > >>2 > > >>>>> a or b > > >>2 > > >>>>> a | b > > >>6 > > > > That IS funny. ?Interesting how a careful choice of arugments will fool > > > us. One of my favorite math jokes is like that. ?A teacher asked a > > > student to reduce the following fraction: > > > ? 16 > > > ?---- > > > ? 64 > > > > He says "all I have to do is cancel out the sixes, so the answer is > > > 1/4". > > > One of my favourite variations on this is by Abbott and Costello, where > > Costello proves that 13*7 = 28 in three different ways. > > >http://www.youtube.com/watch?v=rLprXHbn19I > > Ha Ha! [You're hired Steven] And of course, a programmer cannot tell the difference between Halloween and Christmas day. From roy at panix.com Sat May 28 08:37:11 2011 From: roy at panix.com (Roy Smith) Date: Sat, 28 May 2011 08:37:11 -0400 Subject: Why did Quora choose Python for its development? References: Message-ID: In article , Carl Banks wrote: > On Friday, May 27, 2011 6:47:21 AM UTC-7, Roy Smith wrote: > > One of the truly awesome things about the Python re library is that it > > lets you write complex regexes like this: > > > > pattern = r"""\b # beginning of line > > (?P\w+) # a word > > \s+ # some whitespace > > (?P=word)(?!\w) # the same word again > > """ > > Perl has the X flag as well, in fact I'm pretty sure Perl originated it. > Just saying. Heh. Didn't know that. I wish people would use it more. From darcy at druid.net Sat May 28 08:38:21 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 28 May 2011 08:38:21 -0400 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110528083821.e239a2b9.darcy@druid.net> On Sat, 28 May 2011 07:06:53 +0200 Thomas Rachel wrote: > > "Completely incompatible"? A "lie"? > > Hard word, but it is true. Many things can and will fall on your feet > when moving. > > There are very many subtle differences. The space between "Completely incompatible" and "many subtle differences" is about the size of the Grand Canyon. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rosuav at gmail.com Sat May 28 08:50:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 May 2011 22:50:40 +1000 Subject: and becomes or and or becomes and In-Reply-To: <22197160-095a-4285-8dc4-1814e00a8181@s41g2000prb.googlegroups.com> References: <4dd9aaac$0$29996$c3e8da3$5496439d@news.astraweb.com> <71ab1ccc-c2c0-474f-b7bb-1000754317e4@z13g2000prk.googlegroups.com> <22197160-095a-4285-8dc4-1814e00a8181@s41g2000prb.googlegroups.com> Message-ID: On Sat, May 28, 2011 at 10:27 PM, bch wrote: > And of course, a programmer cannot tell the difference between > Halloween and Christmas day. Well known, of course. But a lot of modern programmers don't speak octal, they only use another power-of-two base; it's as though someone's cast a hex on them. Chris Angelico From irmen.NOSPAM at xs4all.nl Sat May 28 09:09:52 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 28 May 2011 15:09:52 +0200 Subject: The worth of comments In-Reply-To: References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: <4de0f420$0$49047$e4fe514c@news.xs4all.nl> On 27-5-2011 19:53, Grant Edwards wrote: > On 2011-05-27, Irmen de Jong wrote: >> On 27-05-11 15:54, Grant Edwards wrote: >>> On 2011-05-27, Ben Finney wrote: >>>> Richard Parker writes: >>>> >>>>> On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: >>>>> >>>>>> My experience is that comments in Python are of relatively low >>>>>> usefulness. (For avoidance of doubt: not *zero* usefulness, merely >>>>>> low.) >>> >>> I've seen plenty of comments who's usefulness was not zero. It was >>> less than zero. >> >> Someone once taught me, "There is one thing worse than having no >> comments in the source code: having incorrect (or 'lying') comments >> in the code." >> >> Grant, I guess you hint at such comments? > > Yes. :) > > When trying to find a bug in code written by sombody else, I often > first go through and delete all of the comments so as not to be > mislead. > > The comments reflect what the author _thought_ the code did > _at_some_point_in_the_past_. What matters is what the code actually > does at the present. > I'm going to share this thread, and the funny slideshow about Uncomment your code, with my team at work :-) We're not a Python shop so I'm probably the only one reading this, but as usual there is a lot of wisdom going on in this newgroup that is not only applicable to Python. Irmen From nobody at nowhere.com Sat May 28 09:31:52 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 28 May 2011 14:31:52 +0100 Subject: and becomes or and or becomes and References: Message-ID: On Sun, 22 May 2011 15:39:33 -0700, Tim Roberts wrote: > That IS funny. Interesting how a careful choice of arugments will fool us. > One of my favorite math jokes is like that. A teacher asked a student to > reduce the following fraction: > 16 > ---- > 64 > > He says "all I have to do is cancel out the sixes, so the answer is 1/4". Not Python, but: #define SIX 1 + 5 #define NINE 8 + 1 ... printf("six times nine is: %d\n", SIX * NINE); From python at bdurham.com Sat May 28 09:34:03 2011 From: python at bdurham.com (python at bdurham.com) Date: Sat, 28 May 2011 09:34:03 -0400 Subject: The worth of comments In-Reply-To: <4de0f420$0$49047$e4fe514c@news.xs4all.nl> References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de0f420$0$49047$e4fe514c@news.xs4all.nl> Message-ID: <1306589643.10031.1457018105@webmail.messagingengine.com> Irmen, > I'm going to share this thread, and the funny slideshow about Uncomment your code, with my team at work :-) We're not a Python shop so I'm probably the only one reading this Same here! > but as usual there is a lot of wisdom going on in this new[s]group that is not only applicable to Python. +1 QOTW Malcolm From yuvaraj1302 at gmail.com Sat May 28 09:36:10 2011 From: yuvaraj1302 at gmail.com (YUVI RAJ) Date: Sat, 28 May 2011 06:36:10 -0700 (PDT) Subject: join this group Message-ID: <84e8bb36-868f-4145-9acd-b6bea11c9e03@l2g2000prg.googlegroups.com> http://123maza.com/65/Cape201/ From roy at panix.com Sat May 28 09:36:43 2011 From: roy at panix.com (Roy Smith) Date: Sat, 28 May 2011 09:36:43 -0400 Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: In article , Grant Edwards wrote: > When trying to find a bug in code written by sombody else, I often > first go through and delete all of the comments so as not to be > mislead. I've heard people say that before. While I get the concept, I don't like doing things that way myself. >> The comments reflect what the author _thought_ the code did > _at_some_point_in_the_past_. What matters is what the code actually > does at the present. I don't look at it that way. Most of the comments I write are to document interfaces, i.e. what the code is supposed to do. That's the contract between you and the code. If you call me with arguments that meet these conditions, this is what I promise I'll return to you (and what side effects I'll perform). One reasonable definition of a bug is something the code actually does which differs from the documented interface. Unless you know what the code is supposed to do, how can you possibly look at it and say whether it has a bug or not? For example, take this function: def foo(): l = [1, 2, 3] return l[3] Is this code correct? I'll bet most people would look at this and say, "I'm not sure what he had in mind, but whatever it was, this has to be a bug because he's indexing past the end of the list". Well, what if I showed you the interface contract: def foo(): "Raise IndexError. This is useful as a testing fixture." l = [1, 2, 3] return l[3] Now it's obvious that the function does exactly what it's supposed to do (even if it's not the best way to do it). From yuvaraj1302 at gmail.com Sat May 28 09:37:14 2011 From: yuvaraj1302 at gmail.com (YUVI RAJ) Date: Sat, 28 May 2011 06:37:14 -0700 (PDT) Subject: join this group Message-ID: <50317910-2307-4001-83b9-7556d6b00fc9@k3g2000prl.googlegroups.com> http://123maza.com/65/Cape201/ From ryan at rfk.id.au Sat May 28 09:42:18 2011 From: ryan at rfk.id.au (Ryan Kelly) Date: Sat, 28 May 2011 23:42:18 +1000 Subject: PyCon Australia 2011: Early Bird Closing Soon Message-ID: <1306590138.2129.20.camel@durian> Hi Everyone, A reminder that Early Bird Registrations for PyCon Australia 2011 will be closing soon. There are only a few days left to get your tickets at the discounted rate. PyCon Australia is Australia's only conference dedicated exclusively to the Python programming language, and will be held at the Sydney Masonic Center over the weekend of August 20 and 21. See below for more information and updates on: 1. Early-Bird Registration Closing Soon 2. Presentations Selected 3. More Sponsors Announced Please pass this message on to those you feel may be interested. Early-Bird Registration Closing Soon ==================================== Early-bird registration closes at the end of May, so you've only got a few days left to get your tickets at the special discounted rate. We offer three levels of registration for PyCon Australia 2011. Registration provides access to two full days of technical content presented by Python enthusiasts from around the country, as well as the new classroom track and a seat at the conference dinner. Full (Early Bird) - $165 This is the registration rate for regular attendees. We are offering a limited Early Bird rate for the first 50 registrations until the end of May. Once the early-bird period ends, Full Registration will be $198. Corporate - $440 If your company is paying for you to attend PyCon, please register at the corporate rate. You'll be helping to keep the conference affordable for all. Student - $44 For students able to present a valid student card we're offering this reduced rate, which does not include the conference dinner. All prices include GST. For more information or to register, please visit the conference website. Register here: http://pycon-au.org/reg Presentations Selected ====================== We have had a fantastic response to our Call For Proposals this year. While the detailed talk schedule is still being finalised, we are pleased to announce that the following presentations have been selected for the conference: Standard Talks: A Python on the Couch (Mark Rees) Behaviour Driven Development (Malcolm Tredinnick) Benchmarking stuff made ridiculously easy (Tennessee Leeuwenburg) Bytecode: What, Why, and How to Hack it (Ryan Kelly) Developing Scientific Software in Python (Duncan Gray) Fun with App Engine 1.5.0 (Greg Darke) Hosting Python Web Applications (Graham Dumpleton) How Python Evolves (and How You Can Help Make It Happen) (Nick Coghlan) Infinite 8-bit Platformer (Chris McCormick) Networking Libraries in Python. (Senthil Kumaran) Pants - Network Programming Made Easy (Evan Davis) Say What You Mean: Meta-Programming a Declarative API (Ryan Kelly) State of CPython and Python Ecosystem (Senthil Kumaran) Sysadmins vs Developers, a take from the other side of the fence (Benjamin Smith) Teaching Python to the young and impressionable (Katie Bell) The NCSS Challenge: teaching programming via automated testing (Tim Dawborn) Weather field warping using Python. (Nathan Faggian) Zookeepr: Home-grown conference management software (Brianna Laugher) In-Depth Talks: Ah! I see you have the machine that goes "BING"! (Graeme Cross) Easy site migration using Diazo and Funnelweb (Adam Terrey) How to maintain big app stacks without losing your mind (Dylan Jay) Introduction to the Geospatial Web with GeoDjango (Javier Candeira) Panel: Python 3 (Richard Jones) Panel: Python in the webs (Richard Jones) Pyramid: Lighter, faster, better web apps (Dylan Jay) Web micro-framework battle (Richard Jones) Classroom Track: Meta-matters: using decorators for better Python programming (Graeme Cross) Python 101+ (Peter Lovett) Python's dark corners - the bad bits in Python and how to avoid them (Peter Lovett) Python for Science and Engineering, Part 1 (Edward Schofield) Python for Science and Engineering, Part 2 (Edward Schofield) The Zen of Python (Richard Jones) Thanks again to everyone who submitted a proposal. More Sponsors Announced ======================= We are delighted to announce that WingWare and Superior Recruitment have joined as Silver Sponsors. Thank you to the following companies for their continuing support of Python and for helping to make PyCon Australia 2011 a reality: Gold: Google Gold: ComOps Silver: Anchor Silver: Enthought Silver: Python Software Foundation Silver: WingWare Silver: Superior Recruitment Thanks also to Linux Australia, who provide the overarching legal and organisational structure for PyCon Australia. Ryan Kelly PyCon Australia 2011 From rosuav at gmail.com Sat May 28 10:02:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 00:02:57 +1000 Subject: The worth of comments In-Reply-To: References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: On Sat, May 28, 2011 at 11:36 PM, Roy Smith wrote: > def foo(): > ? "Raise IndexError. ?This is useful as a testing fixture." > ? l = [1, 2, 3] > ? return l[3] A quite useful thing, on occasion. I have a couple of variants of this, actually. In one of my C++ programs: extern char *death1; extern int death2; //Globals for killing things with // further down, inside a function: case "death1": *death1=42; break; //Die by dereferencing NULL case "death2": return 42/death2; //Die by dividing by zero They were designed to verify the parent-process code that was meant to catch process termination and identify the cause, so I wanted two quite different ways of blowing up the program. (The variables were extern and defined in another file to ensure that the compiler couldn't outsmart me with a compilation error.) In the Python code, that would be unnecessary with the *list* type, but it might be of value with your own class (eg subclass of list). Although, I'd put that sort of thing into a dedicated unit testing section, where everyone _knows_ that you're trying to break stuff. Chris Angelico From rosuav at gmail.com Sat May 28 10:04:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 00:04:03 +1000 Subject: and becomes or and or becomes and In-Reply-To: References: Message-ID: On Sat, May 28, 2011 at 11:31 PM, Nobody wrote: > Not Python, but: > > ? ? ? ?#define SIX ?1 + 5 > ? ? ? ?#define NINE 8 + 1 > ? ? ? ?... > ? ? ? ?printf("six times nine is: %d\n", SIX * NINE); *AWESOME*!! That is brilliant! DNA FTW. ChrisA From irmen.NOSPAM at xs4all.nl Sat May 28 10:05:18 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 28 May 2011 16:05:18 +0200 Subject: The worth of comments In-Reply-To: References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: <4de1011f$0$49184$e4fe514c@news.xs4all.nl> On 28-5-2011 15:36, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> When trying to find a bug in code written by sombody else, I often >> first go through and delete all of the comments so as not to be >> mislead. > > I've heard people say that before. While I get the concept, I don't > like doing things that way myself. > >>> The comments reflect what the author _thought_ the code did >> _at_some_point_in_the_past_. What matters is what the code actually >> does at the present. > > I don't look at it that way. Most of the comments I write are to > document interfaces, i.e. what the code is supposed to do. That's the > contract between you and the code. If you call me with arguments that > meet these conditions, this is what I promise I'll return to you (and > what side effects I'll perform). I don't see how that is opposed to what Grant was saying. It's that these 'contracts' tend to change and that people forget or are too lazy to update the comments to reflect those changes. The comments you are writing, saying what the code is supposed to do, are only saying what the code is supposed to do at the moment in time that you were writing the comment and/or the code, are they not? > One reasonable definition of a bug is something the code actually does > which differs from the documented interface. Unless you know what the > code is supposed to do, how can you possibly look at it and say whether > it has a bug or not? For example, take this function: > > def foo(): > l = [1, 2, 3] > return l[3] > > Is this code correct? Unit tests should tell you. > I'll bet most people would look at this and say, > "I'm not sure what he had in mind, but whatever it was, this has to be a > bug because he's indexing past the end of the list". I do agree that reading just that piece of code without other information, makes me think that it is fishy. But: > Well, what if I > showed you the interface contract: > > def foo(): > "Raise IndexError. This is useful as a testing fixture." > l = [1, 2, 3] > return l[3] > > Now it's obvious that the function does exactly what it's supposed to do > (even if it's not the best way to do it). A month later the requirement changes: it should raise a ZeroDevisionError instead. Someone modifies the code but leaves the comment (for whatever reason). def foo(): "Raise IndexError. This is useful as a testing fixture." return 1//0 Unless there is a way to force people to update the code comment as well (which I'm not aware of.. Doctests? dunno...), you now have a comment that lies about the the intended working. In my opinion that is worse than what we had before (the function without comment). That being said, I do write code comments myself. Some of them are like notes, directed to future-me or other future readers (remember that we do this because blabla, don't change this to such-and-such because it will probably break xyz) and some of them are stating the contract of the code (like you wrote above, about documenting interfaces). I always try to avoid writing comments that duplicate the working of the code itself in pseudo code or text phrases. But humans make mistakes and forget things so after enough modifications my code probably contains lies as well... :( Irmen de Jong From nobody at nowhere.net.no Sat May 28 12:01:56 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 29 May 2011 00:01:56 +0800 Subject: How to catch a line with Popen Message-ID: Hello. I'm looking into subprocess.Popen docs. I've launch the program with its arguments and that's smooth. I'm expecting to read the output by *comunicate()* at every line that prgram may blow during the process, but the output is given only when the child process is ended. I'd like to process the lines to display an information in percentage during the running time of the child. Sorry but I'm poor of know-how, so I'm stuck over to find a clue. -- goto /dev/null From nagle at animats.com Sat May 28 12:39:08 2011 From: nagle at animats.com (John Nagle) Date: Sat, 28 May 2011 09:39:08 -0700 Subject: GIL in alternative implementations In-Reply-To: References: <4DE015EA.4040600@gmail.com> Message-ID: <4de1252d$0$2203$742ec2ed@news.sonic.net> On 5/27/2011 7:06 PM, Daniel Kluev wrote: >> So I'd like to know: how do these other implementations handle concurrency >> matters for their primitive types, and prevent them from getting corrupted >> in multithreaded programs (if they do) ? I'm not only thinking about python >> types, but also primitive containers and types used in .Net and Java VMs, >> which aren't atomic elements either at an assembly-level point of view. "+=" is not guaranteed to be atomic in most languages. Some C and C++ implementations have "atomic_inc", etc., which is guaranteed to execute as an atomic operation. How do most safe languages handle concurrency? For the unboxed primitive types, like numbers, the hardware handles it. For memory allocation, there's a lock. Most don't allow patching code on the fly. Concurrent garbage collection prevents deleting something if there's a pointer to it anywhere. This was all worked out for LISP and SELF decades ago. Python allows patching code while the code is executing. This implies a sizable performance penalty, and causes incredible complexity in PyPy. John Nagle From steve+comp.lang.python at pearwood.info Sat May 28 13:05:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 May 2011 17:05:16 GMT Subject: GIL in alternative implementations References: <4DE015EA.4040600@gmail.com> <4de1252d$0$2203$742ec2ed@news.sonic.net> Message-ID: <4de12b4b$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 28 May 2011 09:39:08 -0700, John Nagle wrote: > Python allows patching code while the code is executing. Can you give an example of what you mean by this? If I have a function: def f(a, b): c = a + b d = c*3 return "hello world"*d how would I patch this function while it is executing? -- Steven From bgreen at nycap.rr.com Sat May 28 14:57:10 2011 From: bgreen at nycap.rr.com (Uncle Ben) Date: Sat, 28 May 2011 11:57:10 -0700 (PDT) Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> Message-ID: <11eb08a3-9cea-462f-ad1b-bf01d53f687a@z13g2000yqg.googlegroups.com> On May 27, 5:33?pm, Ethan Furman wrote: > Lew Schwartz wrote: > > So, if I read between the lines correctly, you recommend Python 3? Does > > the windows version install with a development environment? > > Dabo, last I checked, uses wxPython, which uses wxWidgets (sp?), which > is not yet ported to Python 3. ?So if you got that route you'll need to > stay with 2.7. > > ~Ethan~ Just this past Tuesday, I blindly downloaded 3.1 and found that at the level I am workloing, all it took to get my 2.7 code to run was to put parens around the print arguments and double the slashes in integer division. I didn't even use the 2to3 automation. But I am a noob to Python, which is my tenth computer language. Maybe when I get more ambitious I will find more serious differences. From harrismh777 at charter.net Sat May 28 15:21:32 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 28 May 2011 14:21:32 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0XbEp.24071$oq.16802@newsfe17.iad> Ethan Furman wrote: > Um -- how can you have on the one hand "completely not compatible" and > on the other "code that can cross-execute on either version"? Great question ! .. .it has to do with education. ... if you learn 2.x (only) and attempt to program on the 3.x platform, (without helps, education, migration tools, etc) you will fail... and you will be frustrated. Why? 3.x is not compatible with 2.x knowledge. If you learn 3.2 (only) and attempt to program on 2.x you will fail, and you will be frustrated. Why? Because the two languages are different and incompatible. Now then, can you learn both?... sure. Can you migrate one to the other with enough knowledge and effort?... yup. Is it possible (with enough cleverness) to write code that will run on "both" without modification... yes... Are the two languages compatible? No! Where this really counts of course is real-world apps. It is relatively easy to write trivial code blocks that demonstrate that nothing has changed in 3.x/ ... and they are *all* misleading. The truth is that hundreds of details have changed making the two 'versions' actually different languages. If I use the '89 version (1) K&R to write a C program, and compile it on the current gcc without mods it will run. If I use the 2.5 python manual to write a python program and try to run it on 3.2 it will fail (for many, many reasons). This is my definition of completely incompatible. The two languages are different; period. The problem is that they "look" similar. :) kind regards, m harris From skunkworks at rikishi42.net Sat May 28 15:36:30 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Sat, 28 May 2011 21:36:30 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-25, Steven D'Aprano wrote: > I know many people who have no idea what a directory is, let alone a > subdirectory, unless it's the phone directory. They're non-computer > users. Once they start using computers, they quickly work out what the > word means in context, or they ask and get told, and then they've learned > a new word and never need ask again. This is a good thing. > > The idiom of "recursively delete" is no different. Of course some people > will have to learn a new term in order to make sense of it. So what? OK, but the addition of recursive, is not really usefull, is it? Deleting the directory says it, doesn't it? >> Do you know many people who incinerate leaves and branches in their >> garden? I burn them. > > I know many people who incinerate leaves in an incinerator. Or at least > they used to, until the government here banned it. It might only have > been a 44 gallon drum with holes punched in the side, but they still > called it an incinerator. > > I learned that word from my father, who left school at 14 to work in a > shoe shop. He isn't especially educated, doesn't read much beyond the > daily tabloid, and thinks Benny Hill is the height of wit. But he's not > an idiot and even at 72 is capable of learning new words. Is it that widespread? I figured most people woul speak of burning. OK, my bad if it is. >>> Do they need to know the words "microwave oven" when they could be >>> saying "invisible rays cooking thing"? >> >> The word oven has existed for ages, microwave is just a name for the >> type of oven. Not even a description, just a name. > > Why do you think they're called "microwave ovens" instead of "fizzbaz > ovens"? Could it possibly have something to do with the fact that they > cook with microwaves? > > So not actually "just a name" at all. It's a jargon description of the > implementation of the oven. True, but I meant that they just use it as a name. I don't think many people would actually try to find out what a microwave is. >>> I wonder whether physicists insist that cars should have a "go faster >>> pedal" because ordinary people don't need to understand Newton's Laws >>> of Motion in order to drive cars? >> >> Gas pedal. Pedal was allraedy known when the car was invented. The >> simple addition of gas solved that need. > > What's a gas pedal? Is that some strange American term for what most of > the English-speaking world knows as the accelerator? *wink* Oh, come one. I'm sure I've heard that often enough NOT to have imagined it. >> Oh, and it's break pedal, not descellarator. (sp?) > That would be brake, and decelerator. Sorry. But I actually have a excuse for those. (see below) ;-) >> I'm one of the 'people'. You say exposed to, I say bothered/bored with. > > You can't force people to learn new words, although you would be > surprised how even the most disinterested, lazy speaker manages to pick > up vocabulary without even being aware of it. I know, I'm one. > But nor do you have to pander to the slackers. They can learn the word, > or not, I don't care. If I'm writing for an audience of children, or > English as a second language, or the otherwise linguistically challenged, Third, actually. But I do try. ;-) > I'll simplify my vocabulary appropriately. For everyone else, I'll use an > ordinary adult vocabulary, and that includes the word "recursion" or > "recursive". It's hardly technical jargon -- I've found a discussion of > gangsta rap that uses it. Even children understand the concept of > recursion (self-reference). People put it in comedies like Blazing > Saddles and Space Balls! How difficult is it to put a name to the concept? > > >> I have nothing against the use of a proper, precise term. And that word >> can be a complex one with many, many sylables (seems to add value, >> somehow). >> >> But I'm not an academic, so I don't admire the pedantic use of terms >> that need to be explained to 'lay' people. > > Pedantic... that's another one of those academic words that need to be > explained to lay people, isn't it? As is academic itself, and in fact > "lay people". Who uses "lay people" in conversation? That (lay people) was atually a quote, from someone who actually used it in this thread. >> widespread, usually shorter and much simpler one for it. A pointless >> effort if pointless, even when comming from a physicist. :-) > > I think you *grossly* underestimate how many words people know, > particularly if you include so-called "passive vocabulary" (words people > can understand in context, but not define precisely). See, for example: > > http://www.worldwidewords.org/articles/howmany.htm Got a point, there. -- When in doubt, use brute force. -- Ken Thompson From rosuav at gmail.com Sat May 28 15:47:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 05:47:31 +1000 Subject: Beginner needs advice In-Reply-To: <0XbEp.24071$oq.16802@newsfe17.iad> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> Message-ID: On Sun, May 29, 2011 at 5:21 AM, harrismh777 wrote: > The problem is that they "look" similar. ? ? :) C looks like every other bracey language in the world. Is that a problem? According to Wikipedia, there's quite a lot of them: http://en.wikipedia.org/wiki/List_of_programming_languages_by_category#Curly-bracket_languages I would say that the difference between the difference between Python 2 and Python 3 and the difference between C and Javascript (there, parse THAT one without parentheses!) is that the latter have a fundamentally different data philosophy. Both versions of Python are the same language, because they "think" the same way; high level objects that can be multiply-referenced, and are disposed of when no longer needed. (That sounds like an implementation detail - refcounting - but I don't really care how it does it under the hood, as long as I can have multiple variables pointing to the same object, and have objects not need explicit deallocation.) Little syntactic differences like whether 'print' is a function or a statement, and whether the simple slash operator between two ints returns a float, and the fact that Unicode is the default string type, are comparatively minor; on 'most every philosophical point, the two dialects agree. Chris Angelico From python at rcn.com Sat May 28 15:55:20 2011 From: python at rcn.com (Raymond Hettinger) Date: Sat, 28 May 2011 12:55:20 -0700 (PDT) Subject: Class decorators might also be super too Message-ID: <1ef87095-2153-4c34-acf4-cfd1380bbcdd@z15g2000prn.googlegroups.com> David Beazley wrote a class decorator blog post that is worth reading: http://dabeaz.blogspot.com/2011/05/class-decorators-might-also-be-super.html Raymond From rosuav at gmail.com Sat May 28 15:58:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 05:58:01 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 29, 2011 at 5:36 AM, Rikishi42 wrote: > Is it [the term 'incinerate'] that widespread? I figured most people > woul speak of burning. OK, my bad if it is. I think it's geographic. This list covers a lot of geography; I'm in Australia, there are quite a few Brits, and probably the bulk of posts come from either the US or Europe. (And yes, I did deliberately fold all of Europe down to one entity, and I did also deliberately leave Great Britain out of that entity.) > True, but I meant that they just use it as a name. I don't think many people > would actually try to find out what a microwave is. Most things work out that way. A thing gets a name based either on its implementation or on the brand name of the first/most popular one. If the only microwave oven ever produced had been made by Foobar Corp, and that company were not known for anything else, then quite possibly everyone would call them "foobar ovens". >> Pedantic... that's another one of those academic words that need to be >> explained to lay people, isn't it? As is academic itself, and in fact >> "lay people". Who uses "lay people" in conversation? > > That (lay people) was atually a quote, from someone who actually used it in > this thread. "Lay person"/"lay people" is a fairly common expression, although "laity" (which ought to mean the same thing) seems only to have meaning in a church context (as in, the non-clergy). Geeks tend to have larger vocabularies than non-geeks, on average; probably akin to our love of word games and precision (two distinct notions that bridge surprisingly often). Chris Angelico From wbsoft at xs4all.nl Sat May 28 17:09:11 2011 From: wbsoft at xs4all.nl (Wilbert Berendsen) Date: Sat, 28 May 2011 23:09:11 +0200 Subject: bdist_wininst: install_script not run on uninstall In-Reply-To: <4DE0599C.9010103@skippinet.com.au> References: <201105252128.17504.wbsoft@xs4all.nl> <201105261000.04741.wbsoft@xs4all.nl> <4DE0599C.9010103@skippinet.com.au> Message-ID: <201105282309.11794.wbsoft@xs4all.nl> Op zaterdag 28 mei 2011 schreef Mark: > This is a bug in distutils/bdist_wininst - I just created > http://bugs.python.org/issue12200 with the details and your samples, and > sadly I can't think of a work around you can use until this is fixed > (which I might get to soon, but not this weekend...) Great that you found the cause of the bug! I looked for hours in the install.c but I didn't find it :-) Looking forward to a fix, which will make bdist_wininst much more usable! thanks! Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi From gsowww at yahoo.co.uk Sat May 28 17:25:43 2011 From: gsowww at yahoo.co.uk (GSO) Date: Sat, 28 May 2011 22:25:43 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: The beginning of wisdom is to call things by their right names. - Chinese Proverb (So I'm told at least, I'd check with the Chinese first though ;) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat May 28 17:28:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 07:28:47 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 29, 2011 at 7:25 AM, GSO wrote: > The beginning of wisdom is to call things by their right names. - Chinese > Proverb (So I'm told at least, I'd check with the Chinese first though ;) See, I thought it was "The fear of the Lord is the beginning of wisdom", but the Chinese don't worship Yahweh, so I guess they wouldn't say that. Proverbs chapter 9 verse 10, in any case. :) Chris Angelico yes, bit of a Bible geek as well as a programming geek From marduk at letterboxes.org Sat May 28 17:52:55 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 28 May 2011 17:52:55 -0400 Subject: changing current dir and executing a shell script In-Reply-To: References: Message-ID: <1306619575.87010.4.camel@localhost.localdomain> On Sat, 2011-05-28 at 09:41 +0200, Peter Otten wrote: > > You don't want to do this because "cd" is a built-in shell command, > and > > subprocess does not execute within a shell (by default). > > The problem is not that cd is built-in, but that there is no shell at > all. > You can change that with shell=True: This is exactly what I said, but using different words. From nobody at nowhere.com Sat May 28 18:15:06 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 28 May 2011 23:15:06 +0100 Subject: How to catch a line with Popen References: Message-ID: On Sun, 29 May 2011 00:01:56 +0800, TheSaint wrote: > I'm looking into subprocess.Popen docs. I've launch the program with its > arguments and that's smooth. I'm expecting to read the output by > *comunicate()* at every line that prgram may blow during the process, but > the output is given only when the child process is ended. .communicate() reads until EOF, .wait()s for the process to terminate, then returns the output as a pair of strings. If you want to read data while the process is running, use the process' .stdout and/or .stderr members, e.g.: p = subprocess.Popen(...) for line in p.stdout: ... p.wait() Don't forget to .wait() on the process when you're done, regardless of whether you actually need the exit code. From tjreedy at udel.edu Sat May 28 18:18:56 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 28 May 2011 18:18:56 -0400 Subject: Beginner needs advice In-Reply-To: <11eb08a3-9cea-462f-ad1b-bf01d53f687a@z13g2000yqg.googlegroups.com> References: <4DDC7938.5000900@gmail.com> <11eb08a3-9cea-462f-ad1b-bf01d53f687a@z13g2000yqg.googlegroups.com> Message-ID: On 5/28/2011 2:57 PM, Uncle Ben wrote: > Just this past Tuesday, I blindly downloaded 3.1 and found that at the > level I am workloing, all it took to get my 2.7 code to run was to put > parens around the print arguments and double the slashes in integer > division. I didn't even use the 2to3 automation. 1//2 works in 2.7 and earlier. from __future__ import division gives 1/2 == 0.5 and in 3.x print('abc') is the same as print 'abc' The parens only make a difference with 2 or more items. -- Terry Jan Reedy From rzantow at gmail.com Sat May 28 19:12:04 2011 From: rzantow at gmail.com (rzed) Date: Sat, 28 May 2011 23:12:04 +0000 Subject: Parse config file and command-line arguments, to get a single collection of options References: <87k4deaxfc.fsf@benfinney.id.au> Message-ID: Ben Finney wrote in news:87k4deaxfc.fsf at benfinney.id.au: > Howdy all, > > Python's standard library has modules for configuration file > parsing (configparser) and command-line argument parsing > (optparse, argparse). I want to write a program that does both, > but also: > > * Has a cascade of options: default option values, overridden by > config > file options, overridden by command-line options. > > * Reads a different, or even additional, configuration file if > specified > on the command-line (e.g. --config-file foo.conf) and yet still > obeys the above cascade. > > * Allows a single definition of an option (e.g. logging level) to > define > the same option for parsing from configuration files and the > command line. > > * Unifies the parsed options into a single collection for the > rest of > the program to access without caring where they came from. > > How can I achieve this with minimum deviation from the Python > standard library? > > > (For anyone interested in gaining StackOverflow points, I'm also > asking this as a question there so feel free to post answers on > that site > and-command-line-arguments-to-get-a-single-collection-of-optio>.) > This seems vaguely similar to a module I wrote and use all the time. It allows default value specification, categorization of command-line options, in-line parsing of further spec file[s] and overrides of values in the the sequence you define, pretty much. It doesn't deal with the "logging level" item. I'm not sure what that would mean. The idea of the module is to create a namespace object (though it could as easily be a dict) that contains whatever values are specified. in the program it would be invoked like this: ctx = Cmdline( outfname='test.out', size=(250,400), ... ) (or whatever). The command line can contain switches, prefixed by hyphens, spec file names, prefixed by @, untagged names, or key=value pairs. The values will be parsed as (tuples), [lists], or {dicts}, ints, floats, or strings. I did not, I am ashamed to say, resist the temptation to guess. 'Ctx' will contain the result of all this. Switches, if any are in a list named ctx._switches, unadorned arguments are in a list named ctx._vars, and the other stuff is pretty much as you would expect. It expects configuration files to be in a sort of ini-file format. Here's an example: --------------------------- test.spec: log=test.log count=10 size=(400,200) group1={key=value,a=alpha} group2={b=beta,name=doogie howser} # temp=[1,2,5,11,22] sub=(al,becky,carl,diane,edwin,fran) --------------------------- test.py: from Cmdline import Cmdline c = Cmdline( count=5, log='pink.tank') c.show() --------------------------- >python test.py log=friend.txt @test.spec count=32 name=waldo ... yields: count = 32 sub = ('al', 'becky', 'carl', 'diane', 'edwin', 'fran') log = 'test.log' temp = [1, 2, 5, 11, 22] group1 = {'a': 'alpha', 'key': 'value'} group2 = {'b': 'beta', 'name': 'doogie howser'} size = (400, 200) name = 'waldo' ... while >python @test.spec count=32 name=waldo temp=Vitalis sub='' dream -k count = 32 _vars = ['dream'] log = 'test.log' temp = 'Vitalis' _switches = ['k'] name = 'waldo' group1 = {'a': 'alpha', 'key': 'value'} group2 = {'b': 'beta', 'name': 'doogie howser'} size = (400, 200) sub = '' What the program does with the results is up to it, of course. -- rzed From news1234 at free.fr Sat May 28 19:23:18 2011 From: news1234 at free.fr (News123) Date: Sun, 29 May 2011 01:23:18 +0200 Subject: portable way of sending notifying a process Message-ID: <4de183e7$0$26108$426a74cc@news.free.fr> Hi, I'm looking for a portable way (windows XP / Windows Vista and Linux ) to send a signal from any python script to another one (one signa would be enough) I have several python scripts started from different parent processes occasionally some of the scripts want to tell another to reread it's config file ( kill -HUP) It seems, that neither the signals HUP / USR1 are implemented under windows. What would be a light weight portable way, that one process can tell another to do something? The main requirement would be to have no CPU impact while waiting (thus no polling) Thanks for any suggestion of small portable libraries or code snippets. The options, that I found so far seem to be a little too big or not portable: - sending the HUP signal doesn't work under win - inotify doesn't work under win - pyro seems to be a little too big for such a 'trivial' task - watchdog might be a solution, but requires three other non standard libraries to be installed. So I'm not sure it's really lightweight If nothing exists I might just write a wrapper around pyinotify and (Tim Goldens code snippet allowing to watch a directory for file changes) http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html and use a marker file in a marker directory but I wanted to be sure of not reinventing the wheel. From timr at probo.com Sat May 28 19:32:42 2011 From: timr at probo.com (Tim Roberts) Date: Sat, 28 May 2011 16:32:42 -0700 Subject: How to catch a line with Popen References: Message-ID: TheSaint wrote: > >I'm looking into subprocess.Popen docs. >I've launch the program with its arguments and that's smooth. I'm expecting >to read the output by *comunicate()* at every line that prgram may blow >during the process, but the output is given only when the child process is >ended. >I'd like to process the lines to display an information in percentage during >the running time of the child. Are you specifying a buffer size in the Popen command? If not, then the Python side of things is unbuffered. It's possible that the application you are launching is buffering its output, so that it doesn't SEND until the application ends. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python at mrabarnett.plus.com Sat May 28 19:41:16 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 29 May 2011 00:41:16 +0100 Subject: float("nan") in set or as key Message-ID: <4DE1881C.8000701@mrabarnett.plus.com> Here's a curiosity. float("nan") can occur multiple times in a set or as a key in a dict: >>> {float("nan"), float("nan")} {nan, nan} except that sometimes it can't: >>> nan = float("nan") >>> {nan, nan} {nan} From max at alcyone.com Sat May 28 20:16:50 2011 From: max at alcyone.com (Erik Max Francis) Date: Sat, 28 May 2011 17:16:50 -0700 Subject: float("nan") in set or as key In-Reply-To: References: Message-ID: MRAB wrote: > Here's a curiosity. float("nan") can occur multiple times in a set or as > a key in a dict: > > >>> {float("nan"), float("nan")} > {nan, nan} > > except that sometimes it can't: > > >>> nan = float("nan") > >>> {nan, nan} > {nan} It's fundamentally because NaN is not equal to itself, by design. Dictionaries and sets rely on equality to test for uniqueness of keys or elements. >>> nan = float("nan") >>> nan == nan False In short, don't do that. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis There was never a good war or a bad peace. -- Benjamin Franklin, 1706-1790 From steve+comp.lang.python at pearwood.info Sat May 28 20:26:07 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 00:26:07 GMT Subject: float("nan") in set or as key References: Message-ID: <4de1929f$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 00:41:16 +0100, MRAB wrote: > Here's a curiosity. float("nan") can occur multiple times in a set or as > a key in a dict: > > >>> {float("nan"), float("nan")} > {nan, nan} That's an implementation detail. Python is free to reuse the same object when you create an immutable object twice on the same line, but in this case doesn't. (I don't actually know if it ever does, but it could.) And since NAN != NAN always, you can get two NANs in the one set, since they're unequal. > when you write float('nan') > > except that sometimes it can't: > > >>> nan = float("nan") > >>> {nan, nan} > {nan} But in this case, you try to put the same NAN in the set twice. Since sets optimize element testing by checking for identity before equality, the NAN only goes in once. -- Steven From marduk at letterboxes.org Sat May 28 20:28:46 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 28 May 2011 20:28:46 -0400 Subject: float("nan") in set or as key In-Reply-To: <4DE1881C.8000701@mrabarnett.plus.com> References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: <1306628926.168355.5.camel@localhost.localdomain> On Sun, 2011-05-29 at 00:41 +0100, MRAB wrote: > Here's a curiosity. float("nan") can occur multiple times in a set or as > a key in a dict: > > >>> {float("nan"), float("nan")} > {nan, nan} > These two nans are not equal (they are two different nans) > except that sometimes it can't: > > >>> nan = float("nan") > >>> {nan, nan} > {nan} This is the same nan, so it is equal to itself. Two "nan"s are not equal in the manner that 1.0 and 1.0 are equal: >>> 1.0 == 1.0 True >>> float("nan") == float("nan") False I can't cite this in a spec, but it makes sense (to me) that two things which are nan are not necessarily the same nan. From timothy.c.delaney at gmail.com Sat May 28 20:29:42 2011 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Sun, 29 May 2011 10:29:42 +1000 Subject: float("nan") in set or as key In-Reply-To: References: Message-ID: On 29 May 2011 10:16, Erik Max Francis wrote: > MRAB wrote: > >> Here's a curiosity. float("nan") can occur multiple times in a set or as a >> key in a dict: >> >> >>> {float("nan"), float("nan")} >> {nan, nan} >> >> except that sometimes it can't: >> >> >>> nan = float("nan") >> >>> {nan, nan} >> {nan} >> > > It's fundamentally because NaN is not equal to itself, by design. > Dictionaries and sets rely on equality to test for uniqueness of keys or > elements. > > > >>> nan = float("nan") > >>> nan == nan > False > > In short, don't do that. There's a second part the mystery - sets and dictionaries (and I think lists) assume that identify implies equality (hence the second result). This was recently discussed on python-dev, and the decision was to leave things as-is. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat May 28 20:32:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 10:32:43 +1000 Subject: float("nan") in set or as key In-Reply-To: <1306628926.168355.5.camel@localhost.localdomain> References: <4DE1881C.8000701@mrabarnett.plus.com> <1306628926.168355.5.camel@localhost.localdomain> Message-ID: On Sun, May 29, 2011 at 10:28 AM, Albert Hopkins wrote: > This is the same nan, so it is equal to itself. > Actually, they're not. But it's possible the dictionary uses an 'is' check to save computation, and if one thing 'is' another, it is assumed to equal it. That's true of most well-behaved objects, but nan is not well-behaved :) Chris Angelico From drsalists at gmail.com Sat May 28 20:37:19 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 28 May 2011 17:37:19 -0700 Subject: How to catch a line with Popen In-Reply-To: References: Message-ID: On Sat, May 28, 2011 at 4:32 PM, Tim Roberts wrote: > TheSaint wrote: > > > >I'm looking into subprocess.Popen docs. > >I've launch the program with its arguments and that's smooth. I'm > expecting > >to read the output by *comunicate()* at every line that prgram may blow > >during the process, but the output is given only when the child process is > >ended. > >I'd like to process the lines to display an information in percentage > during > >the running time of the child. > > Are you specifying a buffer size in the Popen command? If not, then the > Python side of things is unbuffered. It's possible that the application > you are launching is buffering its output, so that it doesn't SEND until > the application ends. > I believe there are 4 normal ways, and 1 special way of getting output from a buffered application: 1) As you mentioned, the program could terminate 2) Also, the program could just have written enough to fill its buffer, so it outputs the content of the buffer before starting to fill it again 3) Also, the program could call flush 4) Also, the program could use an unbuffered file, like stderr - not all file in an application are astonishingly likely to be buffered the same way And the special one: 1) Sometimes you can take a buffered program and get it to be unbuffered (or at least line buffered) by running it on a pty. -------------- next part -------------- An HTML attachment was scrubbed... URL: From max at alcyone.com Sat May 28 20:44:56 2011 From: max at alcyone.com (Erik Max Francis) Date: Sat, 28 May 2011 17:44:56 -0700 Subject: float("nan") in set or as key In-Reply-To: References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: Albert Hopkins wrote: > On Sun, 2011-05-29 at 00:41 +0100, MRAB wrote: >>>> 1.0 == 1.0 > True >>>> float("nan") == float("nan") > False > > I can't cite this in a spec, but it makes sense (to me) that two things > which are nan are not necessarily the same nan. It's part of the IEEE standard. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis There was never a good war or a bad peace. -- Benjamin Franklin, 1706-1790 From greg.ewing at canterbury.ac.nz Sat May 28 20:47:52 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 29 May 2011 12:47:52 +1200 Subject: The worth of comments In-Reply-To: <4de1011f$0$49184$e4fe514c@news.xs4all.nl> References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> Message-ID: <94djdoFt6U1@mid.individual.net> Irmen de Jong wrote: > I don't see how that is opposed to what Grant was saying. It's that these 'contracts' > tend to change and that people forget or are too lazy to update the comments to reflect > those changes. However, I can't see that deleting the comment documenting the contract can be the right response to the situation. If the contract comment doesn't match what code does, then there are two possibilities -- the comment is wrong, or the code is wrong. The appropriate response is to find out which one is wrong and fix it. If you simply delete the comment, then you're left with no redundancy to catch the fact that something is wrong. -- Greg From steve+comp.lang.python at pearwood.info Sat May 28 20:49:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 00:49:01 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de197fd$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 05:58:01 +1000, Chris Angelico wrote: > Geeks tend to have larger vocabularies than non-geeks, on average; > probably akin to our love of word games and precision (two distinct > notions that bridge surprisingly often). And also because more educated people in general tend to have larger vocabularies than less educated people: both for the number of words they actually use, and those they can interpret in context. Geeks sometimes tend to forget that they're not the only smart, educated people who use "hard" (big, technical, complicated) words. -- Steven From greg.ewing at canterbury.ac.nz Sat May 28 21:04:32 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 29 May 2011 13:04:32 +1200 Subject: float("nan") in set or as key In-Reply-To: References: Message-ID: <94dkd3F7k4U1@mid.individual.net> MRAB wrote: > float("nan") can occur multiple times in a set or as > a key in a dict: > > >>> {float("nan"), float("nan")} > {nan, nan} > > except that sometimes it can't: > > >>> nan = float("nan") > >>> {nan, nan} > {nan} NaNs are weird. They're not equal to themselves: Python 2.7 (r27:82500, Oct 15 2010, 21:14:33) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> nan = float("nan") >>> nan == nan False This confuses the daylights out of Python's dict lookup machinery, which assumes that two references to the same object can't possibly compare unequal, so it doesn't bother calling __eq__ on them. -- Greg From ben+python at benfinney.id.au Sat May 28 21:41:44 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 29 May 2011 11:41:44 +1000 Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> Message-ID: <877h9a9tbb.fsf@benfinney.id.au> Gregory Ewing writes: > If the contract comment doesn't match what code does, then there are > two possibilities -- the comment is wrong, or the code is wrong. The > appropriate response is to find out which one is wrong and fix it. You omit the common third possibility: *both* the comment and the code are wrong. That's the one that I bet on whenever I notice code and comment don't match. -- \ ?Anyone can do any amount of work provided it isn't the work he | `\ is supposed to be doing at the moment.? ?Robert Benchley | _o__) | Ben Finney From irmen.NOSPAM at xs4all.nl Sat May 28 21:49:22 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 29 May 2011 03:49:22 +0200 Subject: The worth of comments In-Reply-To: <94djdoFt6U1@mid.individual.net> References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> Message-ID: <4de1a624$0$49178$e4fe514c@news.xs4all.nl> On 29-5-2011 2:47, Gregory Ewing wrote: > Irmen de Jong wrote: > >> I don't see how that is opposed to what Grant was saying. It's that these 'contracts' >> tend to change and that people forget or are too lazy to update the comments to reflect >> those changes. > > However, I can't see that deleting the comment documenting the > contract can be the right response to the situation. > > If the contract comment doesn't match what code does, then > there are two possibilities -- the comment is wrong, or the > code is wrong. The appropriate response is to find out which > one is wrong and fix it. Fair enough. Certainly I won't be deleting every source code comment encountered from now on, but I do think we should keep in mind the risks already mentioned. In some situations I can very well imagine it is best to simply delete any comments and go with just the code. > If you simply delete the comment, then you're left with no > redundancy to catch the fact that something is wrong. You are right, if you don't have a Unit test for it. Then again, faulty unit tests are a problem in their own right... Irmen de Jong From harrismh777 at charter.net Sat May 28 22:02:47 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 28 May 2011 21:02:47 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> Message-ID: Chris Angelico wrote: > Both versions of Python are > the same language, because they "think" the same way; I appreciate your thought. And there is an obvious continuity in philosophy between 2.x and 3.x; in fact even a cursory study of the history of python demonstrates a concerted effort to build on the best points of 2.x while eliminating the worst. 3.x builds upon and adds to 2.x, as (loosely) C++ builds on and adds to C. Perhaps python3 should have been named Python+ ! ( I think I've already told yous guys that I invoke python3 on my desk machine with--- Anaconda I see your point. But, knowing that 3.x "thinks" like 2.x is not helpful when we all know that languages don't think, people do. People need to be able to understand the 'details' of the language in order to be able to think with it... > Little syntactic > differences like whether 'print' is a function or a statement, and > whether the simple slash operator between two ints returns a float, > and the fact that Unicode is the default string type, are > comparatively minor; on 'most every philosophical point, the two > dialects agree. Minor, yes, .... until you need to make something work--- only to be frustrated to find that a detail that was not expected has risen to bite a sensitive place... :) I am amazed at how many folks are not using 3.x/ Why? (beats me), but how do I know they're not using it...? Because, if they were trying to use it with 2.x knowledge they would be complaining bloody murder.. for instance, how do we reload a module in 2.x... with, um, reload. This has always been the way... every book says so, and every one of us has re-invoked a .py file by using relaod. Reload doesn't even work on 3.x without an import. If you don't know that, well, you're sol until you figure it out, read it, or somebody tells you. This ought not to be. Even the environments of these two languages are incompatible (partially) :) PS Something nobody has pointed out yet is that "completely incompatible" is redundant. ... its like saying totally destroyed. I was trying to be funny, but nobody unpinned it... I'm disappointed. Some of the posts here are referring to the two languages as partially incompatible.... reminds me of that line from Princess Bride... "... he's not dead, hes only mostly dead!... and mostly dead is partly alive!" To say that 3.x is partly compatible with 2.x is silly, but to say that 3.x 'thinks' the same way as 2.x is almost pythonesque... I almost like that... :) kind regards, m harris From invalid at invalid.invalid Sat May 28 22:25:55 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 29 May 2011 02:25:55 +0000 (UTC) Subject: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: On 2011-05-29, Albert Hopkins wrote: > On Sun, 2011-05-29 at 00:41 +0100, MRAB wrote: >> Here's a curiosity. float("nan") can occur multiple times in a set or as >> a key in a dict: >> >> >>> {float("nan"), float("nan")} >> {nan, nan} >> > These two nans are not equal (they are two different nans) > >> except that sometimes it can't: >> >> >>> nan = float("nan") >> >>> {nan, nan} >> {nan} > > This is the same nan, so it is equal to itself. No, it's not. >>> x = float("nan") >>> y = x >>> x is y True >>> x == y False > I can't cite this in a spec, but it makes sense (to me) that two things > which are nan are not necessarily the same nan. Even if they _are_ the same nan, it's still not equal to itself. -- Grant From rosuav at gmail.com Sat May 28 22:26:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 12:26:34 +1000 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> Message-ID: On Sun, May 29, 2011 at 12:02 PM, harrismh777 wrote: > Chris Angelico wrote: >> Both versions of Python are >> the same language, because they "think" the same way; > ? ? I see your point. But, knowing that 3.x "thinks" like 2.x is not helpful > when we all know that languages don't think, people do. I was being (deliberately) sloppy with the English language there, but I was referring to the fundamental philosophies of Python, which are common across both versions (and, presumably, most/all of them can be seen in Python 1 too; I've never used Python 1). >> Little syntactic >> differences like whether 'print' is a function or a statement, and >> whether the simple slash operator between two ints returns a float, >> and the fact that Unicode is the default string type, are >> comparatively minor; on 'most every philosophical point, the two >> dialects agree. > > ? Minor, yes, .... until you need to make something work--- only to be > frustrated to find that a detail that was not expected has risen to bite a > sensitive place... ? :) I get far worse than those when I switch between languages and forget operator precedence, or forget that function X has its parameters the other way around, or whatever. They are minor, and if you're not 100% familiar with the language you're writing in, you should probably have its docs handy anyway. The print function will bite you instantly, you'll know what's wrong as soon as you try to run it. Unicode strings, too, will usually throw a nice tidy exception. The only one that's going to really sting you is division, and it's so easy to deal with that one as you code (always use // for flooring). > instance, how do we reload a module in 2.x... ?with, um, reload. ? This has > always been the way... every book says so, and every one of us has > re-invoked a .py file by using relaod. ?Reload doesn't even work on 3.x > without an import. >From what I gather, Python simply isn't designed with that sort of "live reload" in mind. Just terminate it and start over, it's easier. If you want a system where you reload parts of it without bringing things down, either build it manually (loading another piece of code, and maybe reassigning some state variables that have your functions), or pick a different language - Pike does this excellently. That's not an indictment of Python; it's simply that Python is not everything. > Some of the posts here are referring to the two languages as partially > incompatible.... ? reminds me of that line from Princess Bride... "... he's > not dead, hes only mostly dead!... and mostly dead is partly alive!" ?To say > that 3.x is partly compatible with 2.x is silly, but to say that 3.x > 'thinks' the same way as 2.x is almost pythonesque... ?I almost like that... Mostly compatible is still partly incompatible? Sure. But "mostly compatible" is Python 2.6.6 and Python 2.7.1, too. It's easy to write one codebase that runs under multiple Python versions; certainly it's a lot easier than writing one source file that's both Python and C, for instance. And the same lines of code will be doing the same work (unlike most polyglottisms, where one language's code is another language's comments). There is a subset of Python 2 that is also a subset of Python 3, and this intersection is quite large. Chris Angelico From harrismh777 at charter.net Sat May 28 22:33:33 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 28 May 2011 21:33:33 -0500 Subject: Beginner needs advice In-Reply-To: <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2giEp.236$QL2.62@newsfe04.iad> Steven D'Aprano wrote: > A straw man is not when somebody points out holes in your argument, or > unwanted implications that you didn't realise were there. It is when > somebody makes claims on your behalf that you did not make to discredit > you, not because you don't understand the implications of your own > argument. The straw-man fallacy is when you erect a "straw man" to "represent" the actual man (or idea) which can be easily knocked down, and then you proceed to knock it down (the straw-man) as though the "straw man" was the actual man, or idea... proving your point as-it-were against your opponent when in fact you have only just knocked down the straw-man... leaving the real man standing. This fallacy has a couple of nuances (sometimes combined with metaphor or analogy fallacy) and you are a master at presenting both... thankfully you usually don't try to present both at the same time! :) In this present case the straw-man was not "me," rather the straw-man was the python language itself. You chose a code-snippet (one small puny dangle that doesn't prove a thing) and used it to speak for the entire language! As though one code-block is enough to demonstrate compatibility for the entire language in all of its nuances and details. To prove something positive with a test case requires that you provide *all* test cases, or that you provide an algorithm that accounts for *all* test cases... you cannot prove compatibility with a code-snippet. On the other hand, all you have to do to prove incompatibility is to show "one" (1) test case where compatibility fails... and of course for the present case there are many that can be shown, in fact, hundreds of them. The thing that nobody has presented here yet is that *all* the books declare that 3.x is incompatible with 2.x/ ... some of them go out of their way to tell the reader that they are only going to deal with 3.x and not 2.x in any way... and others go out of their way to point out the hundreds of nuances in details between the two languages. (and a good thing too, for those of us who must work with both! ) So this fact is not alluding the press... the point being not to bust anybody in the chops, but to point out that it is not helpful to move the community forward with a new language and get mass adoption (not just early adopters) to lie about the differences between the two sets... yes, for trivial code blocks that use prime constructs, integer math, and the print statement, not much has changed. But in real world applications of the language there are many hundreds of details that have changed or been added (deleted) which will make life difficult for the uninitiated. Don't mislead people by saying that very little has changed. Tell them that the philosophy is the same (what Chris called python 'think' ) but be honest about the details of syntax, environment, layout, and morphology. kind regards, m harris kind regards, m harris From dotancohen at gmail.com Sun May 29 01:46:21 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Sun, 29 May 2011 08:46:21 +0300 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 27, 2011 at 23:40, harrismh777 wrote: > You have erected a straw-man... once again. > I think that is a red herring, not a strawman. > Most 2.x code *will not* run correctly in 3.x/ ?Most of the best > improvements and enhancements of 3.x will not back-port to below 2.7, and > almost none of them will back-port before 2.6 (class decorations, for > instance). > Although it is true that 2.x code will not run in a 3.x environment, the changes to the code are minimal. This would be akin to saying that a 2008 Peugeot 407 will not drive on a Canadian road because the license plate is a different shape. Just go an put a different plastic license plate holder on the Peugeot and it will run fine on the Canadian road. The changes to bring Python 2 code into Python 3 code are minimal, and it would be a terrific learning experience for the OP to go back and revise his old code to do just that. Furthermore, the OP is not just learning Python for the fun of learning Python. If that were the case, then I would agree that Python 3 is the way to go. The OP needs to use imaging libraries which may not yet work in Python 3 (I have not checked, but it is very likely that they do not). Therefore Python 3 is a non-starter in any case. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From nagle at animats.com Sun May 29 02:12:54 2011 From: nagle at animats.com (John Nagle) Date: Sat, 28 May 2011 23:12:54 -0700 Subject: float("nan") in set or as key In-Reply-To: <94dkd3F7k4U1@mid.individual.net> References: <94dkd3F7k4U1@mid.individual.net> Message-ID: <4de1e3e7$0$2195$742ec2ed@news.sonic.net> On 5/28/2011 6:04 PM, Gregory Ewing wrote: > MRAB wrote: >> float("nan") can occur multiple times in a set or as a key in a dict: >> >> >>> {float("nan"), float("nan")} >> {nan, nan} >> >> except that sometimes it can't: >> >> >>> nan = float("nan") >> >>> {nan, nan} >> {nan} > > NaNs are weird. They're not equal to themselves: > > Python 2.7 (r27:82500, Oct 15 2010, 21:14:33) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> nan = float("nan") > >>> nan == nan > False > > This confuses the daylights out of Python's dict lookup machinery, > which assumes that two references to the same object can't possibly > compare unequal, so it doesn't bother calling __eq__ on them. Right. The correct answer to "nan == nan" is to raise an exception, because you have asked a question for which the answer is nether True nor False. The correct semantics for IEEE floating point look something like this: 1/0 INF INF + 1 INF INF - INF NaN INF == INF unordered NaN == NaN unordered INF and NaN both have comparison semantics which return "unordered". The FPU sets a bit for this, which most language implementations ignore. But you can turn on floating point exception traps, and on x86 machines, they're exact - the exception will occur exactly at the instruction which triggered the error. In superscalar CPUs, a sizable part of the CPU handles the unwinding necessary to do that. x86 does it, because it's carefully emulating non-superscalar machines. Most RISC machines don't bother. Python should raise an exception on unordered comparisons. Given that the language handles integer overflow by going to arbitrary-precision integers, checking the FPU status bits is cheap. The advantage of raising an exception is that the logical operations still work. For example, not (a == b) a != b will always return the same results if exceptions are raised for unordered comparison results. Also, exactly one of a = b a < b a > b is always true - something sorts tend to assume. If you get an unordered comparison exception, your program almost certainly was getting wrong answers. (I used to do dynamics simulation engines, where this mattered.) John Nagle From michele.simionato at gmail.com Sun May 29 02:33:02 2011 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 28 May 2011 23:33:02 -0700 (PDT) Subject: Class decorators might also be super too In-Reply-To: <1ef87095-2153-4c34-acf4-cfd1380bbcdd@z15g2000prn.googlegroups.com> Message-ID: <462eb546-0089-48fa-bf10-ac5a6b0b9ed4@glegroupsg2000goo.googlegroups.com> He is basically showing that using mixins for implementing logging is not such a good idea, i.e. you can get the same effect in a better way by making use of other Python features. I argued the same thing many times in the past. I even wrote a module once (strait) to reimplement 99% of multiple inheritance without multiple inheritance, just to show that in can be done in few lines of code in a language as powerful as Python. From ian.g.kelly at gmail.com Sun May 29 04:06:54 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 29 May 2011 02:06:54 -0600 Subject: Beginner needs advice In-Reply-To: <2giEp.236$QL2.62@newsfe04.iad> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: On Sat, May 28, 2011 at 8:33 PM, harrismh777 wrote: > In this present case the straw-man was not "me," rather the straw-man was > the python language itself. You chose a code-snippet (one small puny dangle > that doesn't prove a thing) and used it to speak for the entire language! > ?As though one code-block is enough to demonstrate compatibility for the > entire language in all of its nuances and details. ?To prove something > positive with a test case requires that you provide *all* test cases, or > that you provide an algorithm that accounts for *all* test cases... you > cannot prove compatibility with a code-snippet. You have just misrepresented Steven's argument, which is rather ironic considering that you're the one who brought up straw-men. Steven did not use one code snippet to demonstrate that Python 2 and Python 3 are fully compatible. The code snippet merely demonstrated that Python 2 and 3 are not "totally incompatible" as you had claimed. I realize you are now asserting that compatibility is a boolean condition, and that "totally incompatible" is a redundant phrase that you tossed out as a joke. I don't know whether you're sincere or backpedaling, but in any case this assertion is flatly ludicrous. Following your definition, *nothing* is compatible with anything else. If you disagree, then I invite you to list one example of two different things that are compatible. And finally, would you please just knock off the fallacy crap? If you assert something, and another person counters with a straw-man, and you respond by dismissing his argument as a straw-man, your response is valid. But if you assert something, and another person makes a counter-argument, to whom you invariably respond by crying "Straw-man!" or "False analogy!" (or in your case, "Analogy!"; you seem to view all analogies as false) regardless of what that person actually said -- even if that person does *sometimes* actually commit those fallacies -- then you yourself are employing an ad hominem. From wolfgang at rohdewald.de Sun May 29 04:27:14 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Sun, 29 May 2011 10:27:14 +0200 Subject: float("nan") in set or as key In-Reply-To: References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: <201105291027.15056.wolfgang@rohdewald.de> On Sonntag 29 Mai 2011, Tim Delaney wrote: > There's a second part the mystery - sets and dictionaries (and > I think lists) assume that identify implies equality (hence > the second result). This was recently discussed on > python-dev, and the decision was to leave things as-is. On Sonntag 29 Mai 2011, Grant Edwards wrote: > Even if they are the same nan, it's still not equal to itself. if I understand this thread correctly, they are not equal to itself as specified by IEEE but Python treats them equal in sets and dictionaries for performance reasons -- Wolfgang From henry.olders at mcgill.ca Sun May 29 04:30:52 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Sun, 29 May 2011 04:30:52 -0400 Subject: scope of function parameters Message-ID: I just spent a considerable amount of time and effort debugging a program. The made-up code snippet below illustrates the problem I encountered: def main(): a = ['a list','with','three elements'] print a print fnc1(a) print a def fnc1(b): return fnc2(b) def fnc2(c): c[1] = 'having' return c This is the output: ['a list', 'with', 'three elements'] ['a list', 'having', 'three elements'] ['a list', 'having', 'three elements'] I had expected the third print statement to give the same output as the first, but variable a had been changed by changing variable c in fnc2. It seems that in Python, a variable inside a function is global unless it's assigned. This rule has apparently been adopted in order to reduce clutter by not having to have global declarations all over the place. I would have thought that a function parameter would automatically be considered local to the function. It doesn't make sense to me to pass a global to a function as a parameter. One workaround is to call a function with a copy of the list, eg in fnc1 I would have the statement "return fnc2(b[:]". But this seems ugly. Are there others who feel as I do that a function parameter should always be local to the function? Or am I missing something here? Henry From steve+comp.lang.python at pearwood.info Sun May 29 04:51:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 08:51:33 GMT Subject: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> <1306628926.168355.5.camel@localhost.localdomain> Message-ID: <4de20915$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 10:32:43 +1000, Chris Angelico wrote: > On Sun, May 29, 2011 at 10:28 AM, Albert Hopkins > wrote: >> This is the same nan, so it is equal to itself. >> >> > Actually, they're not. But it's possible the dictionary uses an 'is' > check to save computation, and if one thing 'is' another, it is assumed > to equal it. That's true of most well-behaved objects, but nan is not > well-behaved :) *Exactly* correct. NAN != NAN even if they are the same NAN, by design. This makes NANs ill- behaved, but usefully so. Most (all?) Python built-ins assume that any object X is equal to itself, so they behave strangely with NANs. -- Steven From narkewoody at gmail.com Sun May 29 04:53:44 2011 From: narkewoody at gmail.com (narke) Date: Sun, 29 May 2011 03:53:44 -0500 Subject: Error: child process close a socket inherited from parent Message-ID: Hi, As illustrated in the following simple sample: import sys import os import socket class Server: def __init__(self): self._listen_sock = None def _talk_to_client(self, conn, addr): text = 'The brown fox jumps over the lazy dog.\n' while True: conn.send(text) data = conn.recv(1024) if not data: break conn.close() def listen(self, port): self._listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._listen_sock.bind(('', port)) self._listen_sock.listen(128) self._wait_conn() def _wait_conn(self): while True: conn, addr = self._listen_sock.accept() if os.fork() == 0: self._listen_sock.close() # line x self._talk_to_client(conn, addr) else: conn.close() if __name__ == '__main__': Server().listen(int(sys.argv[1])) Unless I comment out the line x, I will get a 'Bad file descriptor' error when my tcp client program (e.g, telnet) closes the connection to the server. But as I understood, a child process can close a unused socket (file descriptor). Do you know what's wrong here? -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From wolfgang at rohdewald.de Sun May 29 05:47:26 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Sun, 29 May 2011 11:47:26 +0200 Subject: scope of function parameters In-Reply-To: References: Message-ID: <201105291147.26545.wolfgang@rohdewald.de> On Sonntag 29 Mai 2011, Henry Olders wrote: > It seems that in Python, a variable inside a function is > global unless it's assigned. no, they are local > I would have thought that a function parameter would > automatically be considered local to the function. It doesn't > make sense to me to pass a global to a function as a > parameter. it is local. But consider what you actually passed: You did not pass a copy of the list but the list itself. You could also say you passed a reference to the list. All python variables only hold a pointer (the id) to an object. This object has a reference count and is automatically deleted when there are no more references to it. If you want a local copy of the list you can either do what you called being ugly or do just that within the function itself - which I think is cleaner and only required once. def fnc2(c): c = c[:] c[1] = 'having' return c -- Wolfgang From crebert at ucsd.edu Sun May 29 06:01:52 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Sun, 29 May 2011 03:01:52 -0700 Subject: scope of function parameters In-Reply-To: References: Message-ID: On Sun, May 29, 2011 at 1:30 AM, Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a program. The made-up code snippet below illustrates the problem I encountered: > > def main(): > ? ? ? ?a = ['a list','with','three elements'] > ? ? ? ?print a > ? ? ? ?print fnc1(a) > ? ? ? ?print a > > def fnc1(b): > ? ? ? ?return fnc2(b) > > def fnc2(c): > ? ? ? ?c[1] = 'having' > ? ? ? ?return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same output as the first, but variable a had been changed by changing variable c in fnc2. To be more accurate, the list object referred to by `a` was modified through c, due to the fact that a, b, and c all refer to the very same object in this case. > It seems that in Python, a variable inside a function is global unless it's assigned. This rule has apparently been adopted in order to reduce clutter by not having to have global declarations all over the place. > > I would have thought that a function parameter would automatically be considered local to the function. > Are there others who feel as I do that a function parameter should always be local to the function? Or am I missing something here? Function parameters *are* local variables. Function parameters are indeed local in that *rebinding* them has no effect outside of the function: def foo(a): a = 42 def bar(): b = 1 foo(b) print b bar() #=> outputs 1 As you've observed, *mutating* the object a variable refers to is another matter entirely. Python does not use call-by-value and does not copy objects unless explicitly requested to, as you've encountered. But it does not use call-by-reference either, as my example demonstrates. Like several other popular contemporary languages, Python uses call-by-object for parameter passing; a good explanation of this model can be found at http://effbot.org/zone/call-by-object.htm It's well worth reading. Cheers, Chris From nobody at nowhere.net.no Sun May 29 06:02:43 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 29 May 2011 18:02:43 +0800 Subject: How to catch a line with Popen References: Message-ID: Tim Roberts wrote: > Are you specifying a buffer size in the Popen command? If not, then the > Python side of things is unbuffered The buffer is as per default. The program reports one line around 1/2 second time. I think I'll look into the option as Nobody states: p = subprocess.Popen(...) for line in p.stdout: ... p.wait() It is strange that would take a for cycle, rather than catching the line on- the-fly. I can judge it now, I'm going to try it out. -- goto /dev/null From clp2 at rebertia.com Sun May 29 06:26:49 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 29 May 2011 03:26:49 -0700 Subject: How to catch a line with Popen In-Reply-To: References: Message-ID: On Sun, May 29, 2011 at 3:02 AM, TheSaint wrote: > Tim Roberts wrote: > >> Are you specifying a buffer size in the Popen command? ?If not, then the >> Python side of things is unbuffered > > The buffer is as per default. The program reports one line around 1/2 second > time. > I think I'll look into the option as Nobody states: > > ? ? ? ?p = subprocess.Popen(...) > ? ? ? ?for line in p.stdout: > ? ? ? ? ? ?... > ? ? ? ?p.wait() > > It is strange that would take a for cycle, rather than catching the line on- > the-fly. I can judge it now, I'm going to try it out. What do you mean by "on-the-fly" in this context? Cheers, Chris From steve+comp.lang.python at pearwood.info Sun May 29 06:29:28 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 10:29:28 GMT Subject: float("nan") in set or as key References: <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> Message-ID: <4de22007$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 28 May 2011 23:12:54 -0700, John Nagle wrote: > The correct answer to "nan == nan" is to raise an exception, because > you have asked a question for which the answer is nether True nor False. Wrong. The correct answer to "nan == nan" is False, they are not equal. Just as None != "none", and 42 != [42], or a teacup is not equal to a box of hammers. Asking whether NAN < 0 could arguably either return "unordered" (raise an exception) or return False ("no, NAN is not less than zero; neither is it greater than zero"). The PowerPC Macintishes back in the 1990s supported both behaviours. But that's different to equality tests. > The correct semantics for IEEE floating point look something like > this: > > 1/0 INF > INF + 1 INF > INF - INF NaN > INF == INF unordered Wrong. Equality is not an order comparison. -- Steven From greg.ewing at canterbury.ac.nz Sun May 29 07:05:48 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 29 May 2011 23:05:48 +1200 Subject: The worth of comments In-Reply-To: <877h9a9tbb.fsf@benfinney.id.au> References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> <877h9a9tbb.fsf@benfinney.id.au> Message-ID: <94enkcFj5mU1@mid.individual.net> Ben Finney wrote: > You omit the common third possibility: *both* the comment and the code > are wrong. In that case, the correct response is to fix both of them. :-) -- Greg From vinay_sajip at yahoo.co.uk Sun May 29 07:29:06 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 29 May 2011 04:29:06 -0700 (PDT) Subject: Class decorators might also be super too References: <462eb546-0089-48fa-bf10-ac5a6b0b9ed4@glegroupsg2000goo.googlegroups.com> Message-ID: <8f14c08e-2c52-4c8d-9777-ba11d483c707@h9g2000yqk.googlegroups.com> On May 29, 7:33?am, Michele Simionato wrote: > He is basically showing that using mixins for implementingloggingis not such a good idea, I don't think he was particularly advocating implementing logging this way, but rather just using logging for illustrative purposes. Regards, Vinay Sajip From bahamutzero8825 at gmail.com Sun May 29 07:45:30 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 06:45:30 -0500 Subject: Weird problem matching with REs Message-ID: <4DE231DA.7050503@gmail.com> I have an RE that should work (it even works in Kodos [1], but not in my code), but it keeps failing to match characters after a newline. I'm writing a little program that scans the webpage of an arbitrary application and gets the newest version advertised on the page. test3.py: > # -*- coding: utf-8 -*- > > import configparser > import re > import urllib.request > import os > import sys > import logging > import collections > > > class CouldNotFindVersion(Exception): > def __init__(self, app_name, reason, exc_value): > self.value = 'The latest version of ' + app_name + ' could not > be determined because ' + reason > self.cause = exc_value > def __str__(self): > return repr(self.value) > > class AppUpdateItem(): > def __init__(self, config_file_name, config_file_section): > self.section = config_file_section > self.name = self.section['Name'] > self.url = self.section['URL'] > self.filename = self.section['Filename'] > self.file_re = re.compile(self.section['FileURLRegex']) > self.ver_re = re.compile(self.section['VersionRegex']) > self.prev_ver = self.section['CurrentVersion'] > try: > self.page = str(urllib.request.urlopen(self.url).read(), > encoding='utf-8') > self.file_URL = self.file_re.findall(self.page)[0] #here > is where it fails > self.last_ver = self.ver_re.findall(self.file_URL)[0] > except urllib.error.URLError: > self.error = str(sys.exc_info()[1]) > logging.info('[' + self.name + ']' + ' Could not load URL: > ' + self.url + ' : ' + self.error) > self.success = False > raise CouldNotFindVersion(self.name, self.error, > sys.exc_info()[0]) > except IndexError: > logging.warning('Regex did not return a match.') > def update_ini(self): > self.section['CurrentVersion'] = self.last_ver > with open(config_file_name, 'w') as configfile: > config.write(configfile) > def rollback_ini(self): > self.section['CurrentVersion'] = self.prev_ver > with open(config_file_name, 'w') as configfile: > config.write(configfile) > def download_file(self): > self.__filename = self.section['Filename'] > with open(self.__filename, 'wb') as file: > self.__file_req = urllib.request.urlopen(self.file_URL).read() > file.write(self.__file_req) > > > if __name__ == '__main__': > config = configparser.ConfigParser() > config_file = 'checklist.ini' > config.read(config_file) > queue = collections.deque() > for section in config.sections(): > try: > queue.append(AppUpdateItem(config_file, config[section])) > except CouldNotFindVersion as exc: > logging.warning(exc.value) > for elem in queue: > if elem.last_ver != elem.prev_ver: > elem.update_ini() > try: > elem.download_file() > except IOError: > logging.warning('[' + elem.name + '] Download failed.') > except: > elem.rollback_ini() > print(elem.name + ' succeeded.') checklist.ini: > [x264_64] > name = x264 (64-bit) > filename = x264.exe > url = http://x264.nl/x264_main.php > fileurlregex = > http://x264.nl/x264/64bit/8bit_depth/revision\n{0,3}[0-9]{4}\n{0,3}/x264\n{0,3}.exe > versionregex = [0-9]{4} > currentversion = 1995 The part it's supposed to match in http://x264.nl/x264_main.php: > Message-ID: Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a program. > The made-up code snippet below illustrates the problem I encountered: > > def main(): > a = ['a list','with','three elements'] > print a > print fnc1(a) > print a > > def fnc1(b): > return fnc2(b) > > def fnc2(c): > c[1] = 'having' > return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same output as the > first, but variable a had been changed by changing variable c in fnc2. > > It seems that in Python, a variable inside a function is global unless > it's assigned. This rule has apparently been adopted in order to reduce > clutter by not having to have global declarations all over the place. > > I would have thought that a function parameter would automatically be > considered local to the function. It doesn't make sense to me to pass a > global to a function as a parameter. It doesn't look like a question of local or global. fnc2 is passed a container object and replaces item 1 in that container. You see the results when fnc2 prints the object it knows as `c`, and you see again when main prints the object it knows as `a`. Python doesn't pass parameters by handing around copies that can be thought of as local or global. Python passes parameters by binding objects to names in the callee's namespace. In your program the list known as `a` in main is identically the same list as the one known as `c` in fnc2, and what happens happens. Mel. From steve+comp.lang.python at pearwood.info Sun May 29 08:47:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 12:47:01 GMT Subject: scope of function parameters References: Message-ID: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 11:47:26 +0200, Wolfgang Rohdewald wrote: > On Sonntag 29 Mai 2011, Henry Olders wrote: >> It seems that in Python, a variable inside a function is global unless >> it's assigned. > > no, they are local I'm afraid you are incorrect. Names inside a function are global unless assigned to somewhere. >>> a = 1 >>> def f(): ... print a # Not local, global. ... >>> f() 1 By default, names inside a function must be treated as global, otherwise you couldn't easily refer to global functions: def f(x): print len(x) because len would be a local name, which doesn't exist. In Python, built- in names are "variables" just like any other. Python's scoping rule is something like this: If a name is assigned to anywhere in the function, treat it as a local, and look it up in the local namespace. If not found, raise UnboundLocalError. If a name is never assigned to, or if it is declared global, then look it up in the global namespace. If not found, look for it in the built-ins. If still not found, raise NameError. Nested scopes (functions inside functions) make the scoping rules a little more complex. If a name is a function parameter, that is equivalent to being assigned to inside the function. -- Steven From ben+python at benfinney.id.au Sun May 29 09:00:18 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 29 May 2011 23:00:18 +1000 Subject: Weird problem matching with REs References: Message-ID: <8739jxacgt.fsf@benfinney.id.au> Andrew Berg writes: > I was able to make a regex that matches in my code, but it shouldn't: > http://x264.nl/x264/64bit/8bit_depth/revision.\n{1,3}[0-9]{4}.\n{1,3}/x264.\n{1,3}.\n{1,3}.exe > I have to add a dot before each "\n". There is no character not > accounted for before those newlines, but I don't get a match without the > dots. I also need both those ".\n{1,3}" sequences before the ".exe". I'm > really confused. > > Using Python 3.2 on Windows, in case it matters. You are aware that most text-emitting processes on Windows, and Internet text protocols like the HTTP standard, use the two-character ?CR LF? sequence (U+000C U+000A) for terminating lines? -- \ ?What I have to do is see, at any rate, that I do not lend | `\ myself to the wrong which I condemn.? ?Henry Thoreau, _Civil | _o__) Disobedience_ | Ben Finney From ben+python at benfinney.id.au Sun May 29 09:03:41 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 29 May 2011 23:03:41 +1000 Subject: Weird problem matching with REs References: <8739jxacgt.fsf@benfinney.id.au> Message-ID: <87y61p8xqq.fsf@benfinney.id.au> Ben Finney writes: > the two-character ?CR LF? sequence (U+000C U+000A) > As detailed in that Wikipedia article, the characters are of course U+000D U+000A. -- \ ?You say ?Carmina?, and I say ?Burana?, You say ?Fortuna?, and | `\ I say ?cantata?, Carmina, Burana, Fortuna, cantata, Let's Carl | _o__) the whole thing Orff.? ?anonymous | Ben Finney From steve+comp.lang.python at pearwood.info Sun May 29 09:09:47 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 13:09:47 GMT Subject: Weird problem matching with REs References: Message-ID: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 06:45:30 -0500, Andrew Berg wrote: > I have an RE that should work (it even works in Kodos [1], but not in my > code), but it keeps failing to match characters after a newline. Not all regexes are the same. Different regex engines accept different symbols, and sometimes behave differently, or have different default behavior. That your regex works in Kodos but not Python might mean you're writing a Kodus regex instead of a Python regex. > I'm writing a little program that scans the webpage of an arbitrary > application and gets the newest version advertised on the page. Firstly, most of the code you show is irrelevant to the problem. Please simplify it to the shortest, most simple example you can give. That would be a simplified piece of text (not the entire web page!), the regex, and the failed attempt to use it. The rest of your code is just noise for the purposes of solving this problem. Secondly, you probably should use a proper HTML parser, rather than a regex. Resist the temptation to use regexes to rip out bits of text from HTML, it almost always goes wrong eventually. > I was able to make a regex that matches in my code, but it shouldn't: > http://x264.nl/x264/64bit/8bit_depth/revision.\n{1,3}[0-9]{4}.\n{1,3}/ x264.\n{1,3}.\n{1,3}.exe What makes you think it shouldn't match? By the way, you probably should escape the dots, otherwise it will match strings containing any arbitrary character, rather than *just* dots: http://x264Znl ...blah blah blah -- Steven From bahamutzero8825 at gmail.com Sun May 29 09:29:13 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 08:29:13 -0500 Subject: Weird problem matching with REs In-Reply-To: <8739jxacgt.fsf@benfinney.id.au> References: <8739jxacgt.fsf@benfinney.id.au> Message-ID: <4DE24A29.9080006@gmail.com> On 2011.05.29 08:00 AM, Ben Finney wrote: > You are aware that most text-emitting processes on Windows, and Internet > text protocols like the HTTP standard, use the two-character ?CR LF? > sequence (U+000C U+000A) for terminating lines? Yes, but I was not having trouble with just '\n' before, and the pattern did match in Kodos, so I figured Python was doing its newline magic like it does with the write() method for file objects. http://x264.nl/x264/64bit/8bit_depth/revision[\r\n]{1,3}[0-9]{4}[\r\n]{1,3}/x264[\r\n]{1,3}.exe does indeed match. One thing that confuses me, though (and one reason I dismissed the possibility of it being a newline issue): isn't '.' supposed to not match '\r'? From bahamutzero8825 at gmail.com Sun May 29 09:41:16 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 08:41:16 -0500 Subject: Weird problem matching with REs In-Reply-To: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DE24CFC.3020107@gmail.com> On 2011.05.29 08:09 AM, Steven D'Aprano wrote: > On Sun, 29 May 2011 06:45:30 -0500, Andrew Berg wrote: > > > I have an RE that should work (it even works in Kodos [1], but not in my > > code), but it keeps failing to match characters after a newline. > > Not all regexes are the same. Different regex engines accept different > symbols, and sometimes behave differently, or have different default > behavior. That your regex works in Kodos but not Python might mean you're > writing a Kodus regex instead of a Python regex. Kodos is written in Python and uses Python's regex engine. In fact, it is specifically intended to debug Python regexes. > Firstly, most of the code you show is irrelevant to the problem. Please > simplify it to the shortest, most simple example you can give. That would > be a simplified piece of text (not the entire web page!), the regex, and > the failed attempt to use it. The rest of your code is just noise for the > purposes of solving this problem. I wasn't sure how much would be relevant since it could've been a problem with other code. I do apologize for not putting more effort into trimming it down, though. > Secondly, you probably should use a proper HTML parser, rather than a > regex. Resist the temptation to use regexes to rip out bits of text from > HTML, it almost always goes wrong eventually. I find this a much simpler approach, especially since I'm dealing with broken HTML. I guess I don't see how the effort put into learning a parser and adding the extra code to use it pays off in this particular endeavor. > > I was able to make a regex that matches in my code, but it shouldn't: > > http://x264.nl/x264/64bit/8bit_depth/revision.\n{1,3}[0-9]{4}.\n{1,3}/ > x264.\n{1,3}.\n{1,3}.exe > > What makes you think it shouldn't match? AFAIK, dots aren't supposed to match carriage returns or any other whitespace characters. > By the way, you probably should escape the dots, otherwise it will match > strings containing any arbitrary character, rather than *just* dots: You're right; I overlooked the dots in the URL. From nobody at nowhere.net.no Sun May 29 09:52:22 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 29 May 2011 21:52:22 +0800 Subject: How to catch a line with Popen References: Message-ID: Chris Rebert wrote: > What do you mean by "on-the-fly" in this context I just suppose to elaborate the latest line, as soon it's written on the pipe, and print some result on the screen. Imaging something like p= Popen(['ping','-c40','www.google.com'], stdout=PIPE) for line in p.stdout: print(str(line).split()[7]) I'd like to see something like *time=54.4* This is just an example, where if we remove the "-c40" on the command line, I'd expect to read the latest line(s), until the program will be killed. -- goto /dev/null From narkewoody at gmail.com Sun May 29 09:52:45 2011 From: narkewoody at gmail.com (narke) Date: Sun, 29 May 2011 08:52:45 -0500 Subject: Error: child process close a socket inherited from parent References: Message-ID: On 2011-05-29, narke wrote: > Hi, > > As illustrated in the following simple sample: > > import sys > import os > import socket > > class Server: > def __init__(self): > self._listen_sock = None > > def _talk_to_client(self, conn, addr): > text = 'The brown fox jumps over the lazy dog.\n' > while True: > conn.send(text) > data = conn.recv(1024) > if not data: > break > conn.close() > > def listen(self, port): > self._listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > self._listen_sock.bind(('', port)) > self._listen_sock.listen(128) > self._wait_conn() > > def _wait_conn(self): > while True: > conn, addr = self._listen_sock.accept() > if os.fork() == 0: > self._listen_sock.close() # line x > self._talk_to_client(conn, addr) > else: > conn.close() > > if __name__ == '__main__': > Server().listen(int(sys.argv[1])) > > Unless I comment out the line x, I will get a 'Bad file descriptor' > error when my tcp client program (e.g, telnet) closes the connection to > the server. But as I understood, a child process can close a unused > socket (file descriptor). > > Do you know what's wrong here? > > I forgot to say, it's Python 2.6.4 running on linux 2.6.33 -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From steve+comp.lang.python at pearwood.info Sun May 29 10:09:46 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 14:09:46 GMT Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> Message-ID: <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 28 May 2011 21:02:47 -0500, harrismh777 wrote: > Minor, yes, .... until you need to make something work--- only to be > frustrated to find that a detail that was not expected has risen to bite > a sensitive place... :) Just like when migrating from Python 2.3 to 2.6. And 1.5 and 2.0, and 2.0 and 2.2, and 2.2 and 2.3. > I am amazed at how many folks are not using 3.x/ Why? (beats me), Because: (1) the major operating systems either don't provide Python at all (Windows), or are conservatively still using Python 2.6 or even 2.5 (Mac OS, most Linux distros); (2) the Python website still recommends that "Python 2.x is the status quo, Python 3.x is the shiny new thing" ; and (3) the most of the big frameworks and libraries have either just recently been upgraded to support 3.x, or haven't yet been upgraded. There's very little mystery about it. Migration to 3.x is going according to plan. The majority aren't expected to migrate until probably 3.4 or even 3.5. > but how do I know they're not using it...? Because, if they were > trying to use it with 2.x knowledge they would be complaining bloody > murder.. for instance, how do we reload a module in 2.x... with, um, > reload. This has always been the way... every book says so, *Every* book? Even these? http://diveintopython3.org/ http://www.qtrac.eu/py3book.html http://www.mindviewinc.com/Books/Python3Patterns/Index.php Please quote chapter and verse. [...] > PS Something nobody has pointed out yet is that "completely > incompatible" is redundant. That's because it is not redundant. There is a difference between 1% compatible and 99% compatible and 100% incompatible. > ... its like saying totally destroyed. I > was trying to be funny, but nobody unpinned it... I'm disappointed. > > Some of the posts here are referring to the two languages as partially > incompatible.... reminds me of that line from Princess Bride... "... > he's not dead, hes only mostly dead!... and mostly dead is partly > alive!" To say that 3.x is partly compatible with 2.x is silly, What a ridiculous statement, and one which flies in the face of major projects like numpy which support 2.x and 3.x out of a single code base. I invite you to consider the difference between a legally dead person moments before being resuscitated by a paramedic, versus a chicken that has just been beheaded and is still running around the yard, versus a million-year-old fossilized bone that has turned to stone. Who could possibly justify saying that all three are equally dead? Beware the tyranny of the discontinuous mind. http://www.sciencemusings.com/2007/07/tyranny-of-discontinuous-mind.html Both life and compatibility are matters of degree, not binary states. For proper operation, an electrical device might require a 6V 250mA transformer, but it might work well enough with one that provides just 5V and 240mA, provided you don't stress the device too much. We often design our physical devices to force compatibility to be all-or- nothing, e.g. you can't fit a USB plug into an audio jack, no matter how you try. But that's enforced by the design, not because compatibility is inherently true/false. Compatibility is inherently continuous, a matter of degree. This is especially true when it comes to languages, both natural and programming. British English and American English are perhaps 99.5% compatible, but "table a motion" means completely opposite things in British and American English. (In Britain, it means to deal with it immediately; in the USA, it means to postpone it.) Should we conclude from this that British and American English are "different languages" and "completely incompatible"? The differences between Python 2 and 3 are less than those between American and British English. To describe them as "different languages", as if going from Python 2 to 3 was like translating English to Italian, is absurd. -- Steven From nobody at nowhere.net.no Sun May 29 10:13:14 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 29 May 2011 22:13:14 +0800 Subject: How to catch a line with Popen References: Message-ID: TheSaint wrote: > I just suppose to elaborate the latest line, as soon it's written on the > pipe, and print some result on the screen. I think some info is also here: http://alexandredeverteuil.blogspot.com/ -- goto /dev/null From steve+comp.lang.python at pearwood.info Sun May 29 10:18:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 14:18:16 GMT Subject: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 08:41:16 -0500, Andrew Berg wrote: > On 2011.05.29 08:09 AM, Steven D'Aprano wrote: [...] > Kodos is written in Python and uses Python's regex engine. In fact, it > is specifically intended to debug Python regexes. Fair enough. >> Secondly, you probably should use a proper HTML parser, rather than a >> regex. Resist the temptation to use regexes to rip out bits of text >> from HTML, it almost always goes wrong eventually. > > I find this a much simpler approach, especially since I'm dealing with > broken HTML. I guess I don't see how the effort put into learning a > parser and adding the extra code to use it pays off in this particular > endeavor. The temptation to take short-cuts leads to the Dark Side :) Perhaps you're right, in this instance. But if you need to deal with broken HTML, try BeautifulSoup. >> What makes you think it shouldn't match? > > AFAIK, dots aren't supposed to match carriage returns or any other > whitespace characters. They won't match *newlines* \n unless you pass the DOTALL flag, but they do match whitespace: >>> re.search('abc.efg', '----abc efg----').group() 'abc efg' >>> re.search('abc.efg', '----abc\refg----').group() 'abc\refg' >>> re.search('abc.efg', '----abc\nefg----') is None True -- Steven From bahamutzero8825 at gmail.com Sun May 29 10:35:19 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 09:35:19 -0500 Subject: Weird problem matching with REs In-Reply-To: <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DE259A7.4030209@gmail.com> On 2011.05.29 09:18 AM, Steven D'Aprano wrote: > >> What makes you think it shouldn't match? > > > > AFAIK, dots aren't supposed to match carriage returns or any other > > whitespace characters. > > They won't match *newlines* \n unless you pass the DOTALL flag, but they > do match whitespace: > > >>> re.search('abc.efg', '----abc efg----').group() > 'abc efg' > >>> re.search('abc.efg', '----abc\refg----').group() > 'abc\refg' > >>> re.search('abc.efg', '----abc\nefg----') is None > True I got things mixed up there (was thinking whitespace instead of newlines), but I thought dots aren't supposed to match '\r' (carriage return). Why is '\r' not considered a newline character? From invalid at invalid.invalid Sun May 29 10:41:13 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 29 May 2011 14:41:13 +0000 (UTC) Subject: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: On 2011-05-29, Wolfgang Rohdewald wrote: > On Sonntag 29 Mai 2011, Tim Delaney wrote: >> There's a second part the mystery - sets and dictionaries (and >> I think lists) assume that identify implies equality (hence >> the second result). This was recently discussed on >> python-dev, and the decision was to leave things as-is. > > On Sonntag 29 Mai 2011, Grant Edwards wrote: >> Even if they are the same nan, it's still not equal to itself. > > if I understand this thread correctly, they are not equal to itself > as specified by IEEE And Python follows that convention. > but Python treats them equal in sets and dictionaries for performance > reasons It treats them as identical (not sure if that's the right word). The implementation is checking for ( A is B or A == B ). Presumably, the assumpting being that all objects are equal to themselves. That assumption is not true for NaN objects, so the buggy behavior is observed. -- Grant From invalid at invalid.invalid Sun May 29 10:43:57 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 29 May 2011 14:43:57 +0000 (UTC) Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> <877h9a9tbb.fsf@benfinney.id.au> <94enkcFj5mU1@mid.individual.net> Message-ID: On 2011-05-29, Gregory Ewing wrote: > Ben Finney wrote: > >> You omit the common third possibility: *both* the comment and the code >> are wrong. > > In that case, the correct response is to fix both of them. :-) Only as a last resort. IMO, the best option is to fix the code so it's purpose and operation is obvious from the code, and then delete the comment. -- Grant From roy at panix.com Sun May 29 11:19:11 2011 From: roy at panix.com (Roy Smith) Date: Sun, 29 May 2011 11:19:11 -0400 Subject: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Andrew Berg wrote: > Kodos is written in Python and uses Python's regex engine. In fact, it > is specifically intended to debug Python regexes. Named after the governor of Tarsus IV? From bahamutzero8825 at gmail.com Sun May 29 11:31:43 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 10:31:43 -0500 Subject: Weird problem matching with REs In-Reply-To: References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DE266DF.2080602@gmail.com> On 2011.05.29 10:19 AM, Roy Smith wrote: > Named after the governor of Tarsus IV? Judging by the graphic at http://kodos.sourceforge.net/help/kodos.html , it's named after the Simpsons character. From roy at panix.com Sun May 29 11:39:19 2011 From: roy at panix.com (Roy Smith) Date: Sun, 29 May 2011 11:39:19 -0400 Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> <877h9a9tbb.fsf@benfinney.id.au> <94enkcFj5mU1@mid.individual.net> Message-ID: In article , Grant Edwards wrote: > On 2011-05-29, Gregory Ewing wrote: > > Ben Finney wrote: > > > >> You omit the common third possibility: *both* the comment and the code > >> are wrong. > > > > In that case, the correct response is to fix both of them. :-) > > Only as a last resort. IMO, the best option is to fix the code so it's > purpose and operation is obvious from the code, and then delete the > comment. This is a plausible(*) strategy for internal use software where all users have easy access to all code which depends on yours and are free to change interfaces willy-nilly. That's not always the case. Even on open-source projects, having stand-alone documentation is critical for usability, and certainly having stable interfaces is critical if you expect people to adopt your system and build on it. (*)And, even in the case where it's internal code and everybody on the project has full and unfettered access to all the source, documenting interfaces adds to usability. I've seen plenty of code which looks like this (pseudo-code): Class1::f1() { return Class2::f2(); } Class2::f2() { return Class3::f3(); } Class3::f3() { return Class4::f4(); } If you're trying to figure out what type of object f1() returns, you've got to chase down a long string of, "Well, f1 returns whatever f2 returns, and f2 returns whatever f3 returns, and f3 returns whatever f4 returns, and...." Each step in that process might involve figuring out just where the heck the code for ClassN is. And Cthulhu help you if some step along the way involves an indirectly referenced class or function so you can't even grep the source tree for the name you're looking for. From jstrickler at gmail.com Sun May 29 11:48:34 2011 From: jstrickler at gmail.com (John S) Date: Sun, 29 May 2011 08:48:34 -0700 (PDT) Subject: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> On May 29, 10:35?am, Andrew Berg wrote: > On 2011.05.29 09:18 AM, Steven D'Aprano wrote:> >> What makes you think it shouldn't match? > > > > AFAIK, dots aren't supposed to match carriage returns or any other > > > whitespace characters. > > I got things mixed up there (was thinking whitespace instead of > newlines), but I thought dots aren't supposed to match '\r' (carriage > return). Why is '\r' not considered a newline character? Dots don't match end-of-line-for-your-current-OS is how I think of it. While I almost usually nod my head at Steven D'Aprano's comments, in this case I have to say that if you just want to grab something from a chunk of HTML, full-blown HTML parsers are overkill. True, malformed HTML can throw you off, but they can also throw a parser off. I could not make your regex work on my Linux box with Python 2.6. In your case, and because x264 might change their HTML, I suggest the following code, which works great on my system.YMMV. I changed your newline matches to use \s and put some capturing parentheses around the date, so you could grab it. >>> import urllib2 >>> import re >>> >>> content = urllib2.urlopen("http://x264.nl/x264_main.php").read() >>> >>> rx_x264version= re.compile(r"http://x264\.nl/x264/64bit/8bit_depth/revision\s*(\d{4})\s*/x264\s*\.exe") >>> >>> m = rx_x264version.search(content) >>> if m: ... print m.group(1) ... 1995 >>> \s is your friend -- matches space, tab, newline, or carriage return. \s* says match 0 or more spaces, which is what's needed here in case the web site decides to *not* put whitespace in the middle of a URL... As Steven said, when you want match a dot, it needs to be escaped, although it will work by accident much of the time. Also, be sure to use a raw string when composing REs, so you don't run into backslash issues. HTH, John Strickler From bahamutzero8825 at gmail.com Sun May 29 12:16:35 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 11:16:35 -0500 Subject: Weird problem matching with REs In-Reply-To: <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> Message-ID: <4DE27163.3080104@gmail.com> On 2011.05.29 10:48 AM, John S wrote: > Dots don't match end-of-line-for-your-current-OS is how I think of > it. IMO, the docs should say the dot matches any character except a line feed ('\n'), since that is more accurate. > True, malformed > HTML can throw you off, but they can also throw a parser off. That was part of my point. html.parser.HTMLParser from the standard library will definitely not work on x264.nl's broken HTML, and fixing it requires lxml (I'm working with Python 3; I've looked into BeautifulSoup, and does not work with Python 3 at all). Admittedly, fixing x264.nl's HTML only requires one or two lines of code, but really nasty HTML might require quite a bit of work. > In your case, and because x264 might change their HTML, I suggest the > following code, which works great on my system.YMMV. I changed your > newline matches to use \s and put some capturing parentheses around > the date, so you could grab it. I've been meaning to learn how to use parenthesis groups. > Also, be sure to > use a raw string when composing REs, so you don't run into backslash > issues. How would I do that when grabbing strings from a config file (via the configparser module)? Or rather, if I have a predefined variable containing a string, how do change it into a raw string? From jstrickler at gmail.com Sun May 29 12:45:02 2011 From: jstrickler at gmail.com (John S) Date: Sun, 29 May 2011 09:45:02 -0700 (PDT) Subject: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> Message-ID: <4a265c16-52fb-4483-8bc2-a853c6d18220@dr5g2000vbb.googlegroups.com> On May 29, 12:16?pm, Andrew Berg wrote: > > I've been meaning to learn how to use parenthesis groups. > > Also, be sure to > > use a raw string when composing REs, so you don't run into backslash > > issues. > > How would I do that when grabbing strings from a config file (via the > configparser module)? Or rather, if I have a predefined variable > containing a string, how do change it into a raw string? When reading the RE from a file it's not an issue. Only literal strings can be raw. If the data is in a file, the data will not be parsed by the Python interpreter. This was just a general warning to anyone working with REs. It didn't apply in this case. --john strickler From ppearson at nowhere.invalid Sun May 29 13:21:11 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 29 May 2011 17:21:11 GMT Subject: scope of function parameters References: Message-ID: <94fdk7FihlU1@mid.individual.net> On Sun, 29 May 2011 04:30:52 -0400, Henry Olders wrote: [snip] > def main(): > a = ['a list','with','three elements'] > print a > print fnc1(a) > print a > > def fnc1(b): > return fnc2(b) > > def fnc2(c): > c[1] = 'having' > return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same > output as the first, but variable a had been changed by > changing variable c in fnc2. For what it's worth, I've noticed that use of the word "variable" is correlated with a misunderstanding of Python's way of doing things. "Variable" seems to connote a box that has something in it, so when fnc1 passes b to fnc2 which calls it c, you think you have a box named b and a box named c, and you wonder whether the contents of those boxes are the same or different. Python works in terms of objects having names, and one object can have many names. In your example, fnc1 works with an object that it calls b, and which it passes to fnc2, but fnc2 chooses to call that same object c. The names b and c aren't boxes that hold things, they are -- in the words of one of this group's old hands -- sticky-note labels that have been slapped on the same object. -- To email me, substitute nowhere->spamcop, invalid->net. From alister.ware at ntlworld.com Sun May 29 13:26:16 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Sun, 29 May 2011 17:26:16 GMT Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> Message-ID: On Sun, 29 May 2011 12:47:52 +1200, Gregory Ewing wrote: > Irmen de Jong wrote: > >> I don't see how that is opposed to what Grant was saying. It's that >> these 'contracts' tend to change and that people forget or are too lazy >> to update the comments to reflect those changes. > > However, I can't see that deleting the comment documenting the contract > can be the right response to the situation. > > If the contract comment doesn't match what code does, then there are two > possibilities -- the comment is wrong, or the code is wrong. The > appropriate response is to find out which one is wrong and fix it. > > If you simply delete the comment, then you're left with no redundancy to > catch the fact that something is wrong. "if the comments & code disagree then both are probably wrong" -- Most public domain software is free, at least at first glance. From python at mrabarnett.plus.com Sun May 29 13:44:08 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 29 May 2011 18:44:08 +0100 Subject: float("nan") in set or as key In-Reply-To: References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: <4DE285E8.4080801@mrabarnett.plus.com> On 29/05/2011 15:41, Grant Edwards wrote: > On 2011-05-29, Wolfgang Rohdewald wrote: >> On Sonntag 29 Mai 2011, Tim Delaney wrote: >>> There's a second part the mystery - sets and dictionaries (and >>> I think lists) assume that identify implies equality (hence >>> the second result). This was recently discussed on >>> python-dev, and the decision was to leave things as-is. >> >> On Sonntag 29 Mai 2011, Grant Edwards wrote: >>> Even if they are the same nan, it's still not equal to itself. >> >> if I understand this thread correctly, they are not equal to itself >> as specified by IEEE > > And Python follows that convention. > >> but Python treats them equal in sets and dictionaries for performance >> reasons > > It treats them as identical (not sure if that's the right word). The > implementation is checking for ( A is B or A == B ). Presumably, the > assumpting being that all objects are equal to themselves. That > assumption is not true for NaN objects, so the buggy behavior is > observed. > Would there be any advantage to making NaN a singleton? I'm thinking that it could make checking for it cheaper in the implementation of sets and dicts. Or making NaN unhashable? From rosuav at gmail.com Sun May 29 13:50:15 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 03:50:15 +1000 Subject: float("nan") in set or as key In-Reply-To: <4DE285E8.4080801@mrabarnett.plus.com> References: <4DE1881C.8000701@mrabarnett.plus.com> <4DE285E8.4080801@mrabarnett.plus.com> Message-ID: On Mon, May 30, 2011 at 3:44 AM, MRAB wrote: > Would there be any advantage to making NaN a singleton? I'm thinking > that it could make checking for it cheaper in the implementation of > sets and dicts. Or making NaN unhashable? Doesn't matter. It still wouldn't be equal to itself, even though it 'is' itself, which will greatly confuse anything that optimizes that away. Numbers are well-behaved; NaN is not a number; NaN is not well-behaved. It makes sense... in a way. Chris Angelico From rosuav at gmail.com Sun May 29 13:53:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 03:53:24 +1000 Subject: scope of function parameters In-Reply-To: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 29, 2011 at 10:47 PM, Steven D'Aprano wrote: > If a name is assigned to anywhere in the function, treat it as a local, > and look it up in the local namespace. If not found, raise > UnboundLocalError. > Wait wha? I've never seen this... wouldn't it just create it in the local namespace? Can you give example code that will trigger this error? I'm curious, now... Chris Angelico From rosuav at gmail.com Sun May 29 13:57:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 03:57:38 +1000 Subject: Weird problem matching with REs In-Reply-To: <4DE27163.3080104@gmail.com> References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> <4DE27163.3080104@gmail.com> Message-ID: On Mon, May 30, 2011 at 2:16 AM, Andrew Berg wrote: >> Also, be sure to >> use a raw string when composing REs, so you don't run into backslash >> issues. > How would I do that when grabbing strings from a config file (via the > configparser module)? Or rather, if I have a predefined variable > containing a string, how do change it into a raw string? > "Raw string" is slightly inaccurate. The Python "raw string literal" syntax is just another form of string literal: 'apostrophe-delimited string' "quote-delimited string" """triple-quote string which may go over multiple lines""" '''triple-apostrophe string''' r'raw apostrophe string' r"raw quote string" They're all equivalent once you have the string object. The only difference is how they appear in your source code. If you read something from a config file, you get a string object directly, and you delimit it with something else (end of line, or XML closing tag, or whatever), so you don't have to worry about string quotes. Chris Angelico From clp2 at rebertia.com Sun May 29 14:01:18 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 29 May 2011 11:01:18 -0700 Subject: scope of function parameters In-Reply-To: References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 29, 2011 at 10:53 AM, Chris Angelico wrote: > On Sun, May 29, 2011 at 10:47 PM, Steven D'Aprano > wrote: >> If a name is assigned to anywhere in the function, treat it as a local, >> and look it up in the local namespace. If not found, raise >> UnboundLocalError. >> > > Wait wha? I've never seen this... wouldn't it just create it in the > local namespace? > > Can you give example code that will trigger this error? I'm curious, now... def foo(): print bar bar = 42 foo() ===> Traceback (most recent call last): File "", line 1, in File "", line 2, in foo UnboundLocalError: local variable 'bar' referenced before assignment Cheers, Chris From lists at cheimes.de Sun May 29 14:05:07 2011 From: lists at cheimes.de (Christian Heimes) Date: Sun, 29 May 2011 20:05:07 +0200 Subject: float("nan") in set or as key In-Reply-To: <4DE285E8.4080801@mrabarnett.plus.com> References: <4DE1881C.8000701@mrabarnett.plus.com> <4DE285E8.4080801@mrabarnett.plus.com> Message-ID: Am 29.05.2011 19:44, schrieb MRAB: > Would there be any advantage to making NaN a singleton? I'm thinking > that it could make checking for it cheaper in the implementation of > sets and dicts. Or making NaN unhashable? It can't be a singleton, because IEEE 754 specifies millions of millions of different NaN values. There are positive and negative NaNs, quiet NaNs and signaling NaNs. 50 of 52 mantissa bits can vary freely, one bit makes the difference between signaling and quiet NaNs and at least one bit must be non-zero. Christian From steve+comp.lang.python at pearwood.info Sun May 29 14:27:08 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 18:27:08 GMT Subject: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: <4de28ffc$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 18:44:08 +0100, MRAB wrote: > Would there be any advantage to making NaN a singleton? Absolutely not. That would be a step backwards. NANs can carry payload (a code indicating what sort of NAN it represents -- log(-1) and 1/INF are not the same). So although Python currently has no easy way to access that payload (you can do it with the struct module), it does exist and for serious work you would want to be able to set and get it. > I'm thinking > that it could make checking for it cheaper in the implementation of sets > and dicts. I don't see how would it be cheaper, but even if it were, talk about a micro-optimization! I'd really *love* to see the code where the time it takes to insert a NAN in a set was the bottleneck! > Or making NaN unhashable? I could live with that, although I don't think it is necessary. What actual problem are you hoping to solve here? -- Steven From steve+comp.lang.python at pearwood.info Sun May 29 14:28:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 18:28:20 GMT Subject: scope of function parameters References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de29043$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 03:53:24 +1000, Chris Angelico wrote: > On Sun, May 29, 2011 at 10:47 PM, Steven D'Aprano > wrote: >> If a name is assigned to anywhere in the function, treat it as a local, >> and look it up in the local namespace. If not found, raise >> UnboundLocalError. >> >> > Wait wha? I've never seen this... wouldn't it just create it in the > local namespace? > > Can you give example code that will trigger this error? I'm curious, > now... def f(): print a # a is not yet defined, i.e. unbound a = 1 # this makes a local -- Steven From rosuav at gmail.com Sun May 29 14:38:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 04:38:26 +1000 Subject: scope of function parameters In-Reply-To: References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 30, 2011 at 4:01 AM, Chris Rebert wrote: > def foo(): > ? ?print bar > ? ?bar = 42 > > foo() > > ===> > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 2, in foo > UnboundLocalError: local variable 'bar' referenced before assignment Wow I thought it basically functioned top-down. You get a different error on the print line if there's a "bar = 42" *after* it. This could make debugging quite confusing. Guess it's just one of the consequences of eschewing variable declarations. Sure it's easier, but there's complications down the road. Chris Angelico From steve+comp.lang.python at pearwood.info Sun May 29 14:46:54 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 18:46:54 GMT Subject: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> <4DE285E8.4080801@mrabarnett.plus.com> Message-ID: <4de2949e$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 20:05:07 +0200, Christian Heimes wrote: > Am 29.05.2011 19:44, schrieb MRAB: >> Would there be any advantage to making NaN a singleton? I'm thinking >> that it could make checking for it cheaper in the implementation of >> sets and dicts. Or making NaN unhashable? > > It can't be a singleton, because IEEE 754 specifies millions of millions > of different NaN values. A million-millioneton then? *wink* > There are positive and negative NaNs, I've never quite understood that. NANs are unordered, and therefore cannot be said to be larger than zero (positive) or less than zero (negative). So even if a NAN has the sign bit set, surely the right way to think about that is to treat the sign bit as part of the payload? It seems to me that talking about signed NANs is inaccurate and adds confusion. NANs cause enough confusion as it is, without adding to it... (I would expect the copysign function to honour the sign bit, so I suppose in that sense one might describe NANs as signed.) -- Steven From steve+comp.lang.python at pearwood.info Sun May 29 14:53:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 18:53:06 GMT Subject: scope of function parameters References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de29612$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 04:38:26 +1000, Chris Angelico wrote: > On Mon, May 30, 2011 at 4:01 AM, Chris Rebert wrote: >> def foo(): >> ? ?print bar >> ? ?bar = 42 >> >> foo() >> >> ===> >> Traceback (most recent call last): >> ?File "", line 1, in >> ?File "", line 2, in foo >> UnboundLocalError: local variable 'bar' referenced before assignment > > Wow > > I thought it basically functioned top-down. You get a different error on > the print line if there's a "bar = 42" *after* it. This could make > debugging quite confusing. UnboundLocalError is a subclass of NameError, so it will still be caught by try...except NameError. If you're crazy enough to be catching NameError :) Go back to Python1.5, and there was no UnboundLocalError. It was introduced because people were confused when they got a NameError after forgetting to declare something global: >>> def f(): ... print a ... a = a + 1 ... >>> a = 42 >>> f() Traceback (innermost last): File "", line 1, in ? File "", line 2, in f NameError: a While UnboundLocalError is jargon, and not the easiest error message to comprehend, at least it confuses in a different way :) -- Steven From PointedEars at web.de Sun May 29 15:06:53 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 29 May 2011 21:06:53 +0200 Subject: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4248834.rdbgypaU67@PointedEars.de> Andrew Berg wrote: > On 2011.05.29 10:19 AM, Roy Smith wrote: >> Named after the governor of Tarsus IV? > Judging by the graphic at http://kodos.sourceforge.net/help/kodos.html , > it's named after the Simpsons character. I don't think that's a coincidence; both are from other planets and both are rather evil[tm]. Kodos the Executioner, arguably human, became a dictator who had thousands killed (by his own account, not to let the rest die of hunger); Kodos the slimy extra-terrestrial is a conqueror (and he likes to zap humans as well ;-)) [BTW, Tarsus IV, a planet where thousands (would) have died of hunger and have died in executions was probably yet another hidden Star Trek euphemism. I have found out that Tarsus is, among other things, the name of a collection of bones in the human foot next to the heel. Bones as a reference to death aside, see also Achilles for the heel. But I'm only speculating here.] -- \\//, PointedEars (F'up2 trek) Bitte keine Kopien per E-Mail. / Please do not Cc: me. From ian.g.kelly at gmail.com Sun May 29 15:12:16 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 29 May 2011 13:12:16 -0600 Subject: scope of function parameters In-Reply-To: References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 29, 2011 at 12:38 PM, Chris Angelico wrote: > I thought it basically functioned top-down. You get a different error > on the print line if there's a "bar = 42" *after* it. This could make > debugging quite confusing. > > Guess it's just one of the consequences of eschewing variable > declarations. Sure it's easier, but there's complications down the > road. It's also a consequence of local variable access being optimized with different bytecode: the type of storage has to be determined at compile time. The compiler could in principle figure out that "bar" cannot be bound at that point and make it a global reference, but it is easy to concoct situations involving loops or conditionals where the storage cannot be determined at compile time, and so the compiler follows the simple rule of making everything local unless it's never assigned. Cheers, Ian From rosuav at gmail.com Sun May 29 15:20:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 05:20:51 +1000 Subject: scope of function parameters In-Reply-To: <4de29612$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de29612$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 30, 2011 at 4:53 AM, Steven D'Aprano wrote: > UnboundLocalError is a subclass of NameError, so it will still be caught > by try...except NameError. > > If you're crazy enough to be catching NameError :) Ah okay. So it is still NameError, it just doesn't look like one. > While UnboundLocalError is jargon, and not the easiest error message to > comprehend, at least it confuses in a different way :) I have nothing against jargon, and specific errors are better than generic ones (imagine if every error were thrown as Exception with a string parameter... oh wait, that's what string exceptions are). It still seems a little odd that a subsequent line can affect this one. But Python's mostly doing what would be expected of it; the worst I can come up with is this: def f(): print(foo) # reference a global ... for foo in bar: # variable only used in loop pass If you're used to C++ and declaring variables inside a for loop eg "for (int i=0;i<10;++i)", you might not concern yourself with the fact that 'foo' is masking a global; it's not an issue, because you don't need that global inside that loop, right? And it would be fine, except that that global IS used somewhere else in the function. It'd be a bit confusing to get the UnboundLocalError up on the print(foo) line (the one that's meant to be using the global), since that line isn't wrong; and the "obvious fix", adding an explicit "global foo" to the top of the function, would be worse (because it would mean that the for loop overwrites the global). This is why I would prefer to declare variables. The Zen of Python says that explicit is better than implicit, but in this instance, Python goes for DWIM, guessing whether you meant global or local. It guesses fairly well, though. Chris Angelico From tack at urandom.ca Sun May 29 15:28:46 2011 From: tack at urandom.ca (Jason Tackaberry) Date: Sun, 29 May 2011 15:28:46 -0400 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: <4DE29E6E.7040309@urandom.ca> On 11-05-29 04:06 AM, Ian Kelly wrote: > I realize you are now asserting that compatibility is a boolean > condition, and that "totally incompatible" is a redundant phrase that > you tossed out as a joke. As a casual lurker reading this thread, I believe he is equating "completely incompatible" with "not completely compatible." At least, his arguments make more sense if I read him as arguing from the "not completely compatible" position. It's possible he is intentionally equivocating for dramatic effect. But they are different -- both connotatively and denotatively -- and to argue against the claim that Python 2 and 3 are "completely incompatible" it seems to me sufficient to provide a single non-trivial counter-example, which Steven has already done. Cheers, Jason. From rantingrick at gmail.com Sun May 29 16:16:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:16:50 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: On May 18, 7:19?am, Peter Moylan wrote: > It's interesting to note that the definitions of 'recursive' to be found > in Wikipedia and Wiktionary have very little in common with the > definitions to be found in the dictionaries covered by Onelook. ?No > wonder experts in different areas have trouble communicating with one > another. Yes, and when you extrapolate that conclusion into the current hodge podge of natural languages you begin to understand the genesis of human beings selfish nature. From henry.olders at mcgill.ca Sun May 29 16:19:11 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Sun, 29 May 2011 16:19:11 -0400 Subject: scope of function parameters In-Reply-To: <201105291147.26545.wolfgang@rohdewald.de> References: <201105291147.26545.wolfgang@rohdewald.de> Message-ID: <371A067F-540A-46C3-820C-4348B9815AB9@mcgill.ca> Henry On 2011-05-29, at 5:47 , Wolfgang Rohdewald wrote: > On Sonntag 29 Mai 2011, Henry Olders wrote: >> It seems that in Python, a variable inside a function is >> global unless it's assigned. > > no, they are local > >> I would have thought that a function parameter would >> automatically be considered local to the function. It doesn't >> make sense to me to pass a global to a function as a >> parameter. > > it is local. But consider what you actually passed: > You did not pass a copy of the list but the list itself. > You could also say you passed a reference to the list. > All python variables only hold a pointer (the id) to > an object. This object has a reference count and is > automatically deleted when there are no more references > to it. > > If you want a local copy of the list you can either > do what you called being ugly or do just that within > the function itself - which I think is cleaner and > only required once. > > def fnc2(c): > c = c[:] > c[1] = 'having' > return c Thank you, Wolfgang. That certainly works, but to me it is still a workaround to deal with the consequence of a particular decision. From my perspective, a function parameter should be considered as having been assigned (although the exact assignment will not be known until runtime), and as an assigned variable, it should be considered local. Henry From tjreedy at udel.edu Sun May 29 16:27:17 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 May 2011 16:27:17 -0400 Subject: scope of function parameters In-Reply-To: References: Message-ID: On 5/29/2011 7:59 AM, Mel wrote: > Henry Olders wrote: > >> I just spent a considerable amount of time and effort debugging a program. >> The made-up code snippet below illustrates the problem I encountered: >> >> def main(): >> a = ['a list','with','three elements'] >> print a >> print fnc1(a) >> print a >> >> def fnc1(b): >> return fnc2(b) >> >> def fnc2(c): >> c[1] = 'having' >> return c >> >> This is the output: >> ['a list', 'with', 'three elements'] >> ['a list', 'having', 'three elements'] >> ['a list', 'having', 'three elements'] >> >> I had expected the third print statement to give the same output as the >> first, but variable a had been changed by changing variable c in fnc2. >> >> It seems that in Python, a variable inside a function is global unless >> it's assigned. This rule has apparently been adopted in order to reduce >> clutter by not having to have global declarations all over the place. >> >> I would have thought that a function parameter would automatically be >> considered local to the function. Function *parameters* are names, the first *local names* of the function. >> It doesn't make sense to me to pass a global to a function as a parameter. You are right, in a way;-). Global *names* are just names. When you call a function, you pass *objects* as *arguments*. Of course, you may refer to the object by a global name to pass it, or you can pass a string object that contains a global name. > > It doesn't look like a question of local or global. fnc2 is passed a > container object and replaces item 1 in that container. You see the results > when fnc2 prints the object it knows as `c`, and you see again when main > prints the object it knows as `a`. Python doesn't pass parameters by > handing around copies that can be thought of as local or global. Python > passes parameters by binding objects to names in the callee's namespace. In > your program the list known as `a` in main is identically the same list as > the one known as `c` in fnc2, and what happens happens. Right. Python has one unnamed 'objectspace'. It has many, many namespaces: builtins, globals for each module, locals for each function and class, and attributes for some instances. Each name and each collection slot is associated with one object. Each object can have multiple associations, as in the example above. -- Terry Jan Reedy From rantingrick at gmail.com Sun May 29 16:28:12 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:28:12 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> Message-ID: <15e794b2-df2e-4dae-8f49-ae7dfe1f21d7@x1g2000yqb.googlegroups.com> On May 18, 12:59?pm, s... at sig.for.address (Victor Eijkhout) wrote: > Harrison Hill wrote: > > No need - I have the Dictionary definition of recursion here: > > > Recursion: (N). See recursion. > > If you tell a joke, you have to tell it right. Jeez, speaking of bad colloquialisms... """if you're going to "share" a joke you should at least "recite" it CORRECTLY.""" Thank you. From rantingrick at gmail.com Sun May 29 16:28:47 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:28:47 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> Message-ID: <497db348-1f28-486c-abf3-0385c721d16c@d1g2000yqm.googlegroups.com> On May 18, 12:59?pm, s... at sig.for.address (Victor Eijkhout) wrote: > Harrison Hill wrote: > > No need - I have the Dictionary definition of recursion here: > > > Recursion: (N). See recursion. > > If you tell a joke, you have to tell it right. Jeez, speaking of bad colloquialisms... """if you're going to "share" a joke you should at least "recite" it CORRECTLY.""" Thank you. From rantingrick at gmail.com Sun May 29 16:32:08 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:32:08 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: <0322ba69-f7ec-4c62-ab68-deaeadbd7a9a@x1g2000yqb.googlegroups.com> On May 18, 3:00?pm, Xah Lee wrote: > In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it > possibly mean by the word ?recursive? there? Like, it might delete the > directory but not delete all files in it? Actually i think this case is more for "scare factor" than anything. As in... Do you really want to destroy all these files FOREVER AND EVER or did your mouse finger slip... again? From rantingrick at gmail.com Sun May 29 16:39:49 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:39:49 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8f16b7ff-1ab5-4a9a-b4f5-002ef0ce6037@28g2000yqu.googlegroups.com> On May 20, 1:55?am, Steven D'Aprano wrote: > Trust me on this, if the audience of Carry On films could understand > recursion, anyone can! Well we could also say that this pathetic display of metal masturbation is recursive also. From rantingrick at gmail.com Sun May 29 16:58:18 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:58:18 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 24, 5:06?pm, Rikishi42 wrote: > On 2011-05-24, Steven D'Aprano wrote: > > I wonder whether physicists insist that cars should have a "go faster > > pedal" because ordinary people don't need to understand Newton's Laws of > > Motion in order to drive cars? > > Gas pedal. Pedal was allraedy known when the car was invented. The simple > addition of gas solved that need. Oh, and it's break pedal, not > descellarator. (sp?) Yes "Gas Pedal"... that clears up all the confusion . However i would have thought if the vehicle had a "decelerator petal" it would at least sport a complimentary "accelerator petal". You know the whole "equal and opposite thing"? > > Who are you to say that people shouldn't be exposed to words you deem > > that they don't need to know? > > I'm one of the 'people'. You say exposed to, I say bothered/bored with. > > I have nothing against the use of a proper, precise term. And that word can > be a complex one with many, many sylables (seems to add value, somehow). > > But I'm not an academic, so I don't admire the pedantic use of terms that > need to be explained to 'lay' people. Especially if there is a widespread, > usually shorter and much simpler one for it. A pointless effort if > pointless, even when comming from a physicist. ?:-) You may be "right", but then again, who knows, you may be left? In this upside down world of layperson colloquialisms -- which ironic-ly enough are devised to "ease communication"... right? I mean i "used to" think that choosing words that clearly described my intentions was a good idea but heck, i would hate to think that those poor laypeople had to languish though such tongue twisting syllable gymnastics just for the sake of clear communications. From rantingrick at gmail.com Sun May 29 17:18:15 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 14:18:15 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6d31d8da-e767-4b05-888e-5db5d42d8f5d@v10g2000yqn.googlegroups.com> On May 24, 7:40?pm, Chris Angelico wrote: > On Wed, May 25, 2011 at 8:06 AM, Rikishi42 wrote: > > On 2011-05-24, Steven D'Aprano wrote: > >> I wonder whether physicists insist that cars should have a "go faster > >> pedal" because ordinary people don't need to understand Newton's Laws of > >> Motion in order to drive cars? > > > Gas pedal. Pedal was allraedy known when the car was invented. The simple > > addition of gas solved that need. Oh, and it's break pedal, not > > descellarator. (sp?) > > Americans might call it a gas pedal. We call it an accelerator. You > don't have a "decelerator pedal" though, because it's more accurately > called a "brake pedal" because it controls the brakes. Actually the same argument could be applied to your observation of the driver to vehicle interface. You say "brake petal" simple because it controls the brakes. Well then what does the "accelerator" control then? Most wise observers would blubber... "I know, I know, it controls the gas!"...and while partially correct they would be mostly wrong. Yes it does control the "gas" but not in a direct way. Of course technically it depends on implementation (a favorite word around c.l.py it seems *rolls-eyes*). In the days of carburetors the "accelerator" actually controlled a big flap. This "big flap" (An attribute of which many round here seem to posses and use generously) is opened to allow air to enter and the gas is mixed into the air by secondary effect. So if we really wanted to get pedantic we should call it an "air petal"? However considering that any vehicle made after the early nineties is fuel injected (which is controlled by a computer!) then we may want to call it a "puter petal" to be precise. Note: The remainder of your post was lucid and informative. From rantingrick at gmail.com Sun May 29 17:19:15 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 14:19:15 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <28b4a038-cb6e-4dd6-881b-9eead5211277@d1g2000yqm.googlegroups.com> On May 24, 7:40?pm, Chris Angelico wrote: > On Wed, May 25, 2011 at 8:06 AM, Rikishi42 wrote: > > On 2011-05-24, Steven D'Aprano wrote: > >> I wonder whether physicists insist that cars should have a "go faster > >> pedal" because ordinary people don't need to understand Newton's Laws of > >> Motion in order to drive cars? > > > Gas pedal. Pedal was allraedy known when the car was invented. The simple > > addition of gas solved that need. Oh, and it's break pedal, not > > descellarator. (sp?) > > Americans might call it a gas pedal. We call it an accelerator. You > don't have a "decelerator pedal" though, because it's more accurately > called a "brake pedal" because it controls the brakes. Actually the same argument could be applied to your observation of the driver to vehicle interface. You say "brake petal" simple because it controls the brakes. Well then what does the "accelerator" control then? Most wise observers would blubber... "I know, I know, it controls the gas!"...and while partially correct they would be mostly wrong. Yes it does control the "gas" but not in a direct way. Of course technically it depends on implementation (a favorite word around c.l.py it seems *rolls-eyes*). In the days of carburetors the "accelerator" actually controlled a big flap. This "big flap" (An attribute of which many round here seem to posses and use generously) is opened to allow air to enter and the gas is mixed into the air by secondary effect. So if we really wanted to get pedantic we should call it an "air petal"? However considering that any vehicle made after the early nineties is fuel injected (which is controlled by a computer!) then we may want to call it a "puter petal" to be precise. Note: The remainder of your post was lucid and informative. From nobody at nowhere.com Sun May 29 17:19:49 2011 From: nobody at nowhere.com (Nobody) Date: Sun, 29 May 2011 22:19:49 +0100 Subject: float("nan") in set or as key References: <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> <4de22007$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 29 May 2011 10:29:28 +0000, Steven D'Aprano wrote: >> The correct answer to "nan == nan" is to raise an exception, because >> you have asked a question for which the answer is nether True nor False. > > Wrong. That's overstating it. There's a good argument to be made for raising an exception. Bear in mind that an exception is not necessarily an error, just an "exceptional" condition. > The correct answer to "nan == nan" is False, they are not equal. There is no correct answer to "nan == nan". Defining it to be false is just the "least wrong" answer. Arguably, "nan != nan" should also be false, but that would violate the invariant "(x != y) == !(x == y)". From rosuav at gmail.com Sun May 29 17:27:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 07:27:59 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 30, 2011 at 6:58 AM, rantingrick wrote: > Yes "Gas Pedal"... that clears up all the confusion . > However i would have thought if the vehicle had a "decelerator petal" > it would at least sport a complimentary "accelerator petal". You know > the whole "equal and opposite thing"? Call the go-faster pedal the "Newton's Second Law pedal", and the oops-here-comes-an-obstacle pedal the "Newton's Third Law pedal", because if you hit that thing, you'll see the third law in action. We then need a demonstration of Newton's First Law, which I think is the ignition key. We should turn it into a pedal to be consistent. For the humour-blind: Chris Angelico From rantingrick at gmail.com Sun May 29 17:38:24 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 14:38:24 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: On May 26, 6:12?am, Chris Angelico wrote: > I just conducted a rapid poll of a non-technical userbase. > > (Okay, I just asked my sister who happens to be sitting here. But > she's nontechnical.) > > She explained "recursive" as "it repeats until it can't go any > further". I think that's a fair, if not perfectly accurate, > explanation. Yes but understanding of this sort is very general ESPECIALLY in the case of destroying data! What are the limits of the recursion? What forces can act on the recursion to stop it? If (for example) I know that a "while loop" will continue forever until "something" stops it then i really don't know enough about while loops to start using them safely do i? I need to know what a "break" will do or god forbid what if an exception is thrown? What about if a condition is explicitly passed? I need to know how to interpret the condition and it's consequences. Crikey, this is getting complicated 8-O! PS: Of course i could just cross my fingers, run the code, and hope for the best but i'm not a Perl hacker. From rantingrick at gmail.com Sun May 29 17:38:30 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 14:38:30 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: <7ec80ef6-ca5e-46e7-a6e4-36d3652c7205@r20g2000yqd.googlegroups.com> On May 26, 6:12?am, Chris Angelico wrote: > I just conducted a rapid poll of a non-technical userbase. > > (Okay, I just asked my sister who happens to be sitting here. But > she's nontechnical.) > > She explained "recursive" as "it repeats until it can't go any > further". I think that's a fair, if not perfectly accurate, > explanation. Yes but understanding of this sort is very general ESPECIALLY in the case of destroying data! What are the limits of the recursion? What forces can act on the recursion to stop it? If (for example) I know that a "while loop" will continue forever until "something" stops it then i really don't know enough about while loops to start using them safely do i? I need to know what a "break" will do or god forbid what if an exception is thrown? What about if a condition is explicitly passed? I need to know how to interpret the condition and it's consequences. Crikey, this is getting complicated 8-O! PS: Of course i could just cross my fingers, run the code, and hope for the best but i'm not a Perl hacker. From ray at aarden.us Sun May 29 17:41:47 2011 From: ray at aarden.us (ray) Date: Sun, 29 May 2011 14:41:47 -0700 (PDT) Subject: How to Use Setuptools, Alternatives? Message-ID: <01045077-543f-4b8d-a5a2-4cde190c3294@v8g2000yqb.googlegroups.com> I have Python 2.7 on Win7 Pro on a tightly locked down desktop. I would like to install Networkx from an egg. From what I have read, Setuptools can be used for this. I don't know how to install Setuptools. The exe will not work. On execution, it reports that the Python version is not included in the registry. Further, I can not input the version and location on the subsequent installation screen, the fields will not accept focus so I can not input the values. Since the exe will not install, I considered using the Setuptools egg. But it requires Setuptools. It appears to be a circle. What are some suggestions for installing this? Thanks, ray From ben+python at benfinney.id.au Sun May 29 17:42:19 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 May 2011 07:42:19 +1000 Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> Message-ID: <87tycd89qc.fsf@benfinney.id.au> Peter Pearson writes: > Python works in terms of objects having names, and one > object can have many names. Or no names. So it's less accurate (though better than talking of ?variables?) to speak of Python objects ?having names?. > The names b and c aren't boxes that hold things, they are -- in the > words of one of this group's old hands -- sticky-note labels that have > been slapped on the same object. Right. And in that analogy, the object *still* doesn't ?have a name? (since that implies the false conclusion that the object knows its own name); rather, the name is bound to the object, and the object is oblivious of this. I prefer to talk not of sticky notes, but paper tags with string; the string leading from tag to object is an important part, and the paper tag might not even have a name written on it, allowing the same analogy to work for other non-name references like list indices etc. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but where are we going to find a duck and a hose at this | _o__) hour?? ?_Pinky and The Brain_ | Ben Finney From rosuav at gmail.com Sun May 29 17:46:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 07:46:55 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: On Mon, May 30, 2011 at 7:38 AM, rantingrick wrote: > Yes but understanding of this sort is very general ESPECIALLY in the > case of destroying data! > > What are the limits of the recursion? What forces can act on the > recursion to stop it? If (for example) I know that a "while loop" will > continue forever until "something" stops it then i really don't know > enough about while loops to start using them safely do i? That's true of anything. If I turn on the light switch, I expect there to be a limit to the amount of light it produces; I don't want a household fluro to produce the intensity of the worklights in a theatre. Ought I to get the technical specs and find out exactly how many lumens will be produced, or can I safely power it on in the expectation that it will do the obvious thing? Chris Angelico PS. Why am I responding to rantingrick? I'm sure I'm going to regret this. From chead at is.invalid Sun May 29 17:48:53 2011 From: chead at is.invalid (Christopher Head) Date: Sun, 29 May 2011 14:48:53 -0700 Subject: scope of function parameters References: <201105291147.26545.wolfgang@rohdewald.de> Message-ID: <20110529144853.2adff584@kruskal.chead> On Sun, 29 May 2011 16:19:11 -0400 Henry Olders wrote: > > def fnc2(c): > > c = c[:] > > c[1] = 'having' > > return c > > Thank you, Wolfgang. That certainly works, but to me it is still a > workaround to deal with the consequence of a particular decision. > From my perspective, a function parameter should be considered as > having been assigned (although the exact assignment will not be known > until runtime), and as an assigned variable, it should be considered > local. > > Henry This has nothing to do with function parameters and everything to do with what a "variable name" actually means. You can get the same effect with only globals: >>> x=[1,2,3] >>> y=x >>> x.append(7) >>> y [1, 2, 3, 7] Why in the world does "y" end with 7, even though it was appended to "x"? Simple: because "x" and "y" are two names for the same list, as Henry explained. No functions involved, no locals, no parameters, no scoping. Again, if "y=x" were instead "y=x[:]" then the output would be "[1,2,3]" because "y" would refer to a copy of the list rather than the same list. Chris From ray at aarden.us Sun May 29 17:49:28 2011 From: ray at aarden.us (ray) Date: Sun, 29 May 2011 14:49:28 -0700 (PDT) Subject: Alternatives to PythonPath Message-ID: I am using Win7 on a tightly locked down desktop. Is there an alternative to using PythonPath? What are the trade-offs? Thanks, ray From rantingrick at gmail.com Sun May 29 18:15:31 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 15:15:31 -0700 (PDT) Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: <3820a126-2173-4a3a-b345-17220dce3c9e@q32g2000yqn.googlegroups.com> On May 28, 9:33?pm, harrismh777 wrote: > Steven D'Aprano wrote: > > A straw man is not when somebody points out holes in your argument, or > > unwanted implications that you didn't realise were there. It is when > > somebody makes claims on your behalf that you did not make to discredit > > you, not because you don't understand the implications of your own > > argument. > > The straw-man fallacy is when you erect a "straw man" to "represent" the > actual man (or idea) which can be easily knocked down, and then you > proceed to knock it down (the straw-man) as though the "straw man" was > the actual man, or idea... proving your point as-it-were against your > opponent when in fact you have only just knocked down the straw-man... > leaving the real man standing. > > This fallacy has a couple of nuances (sometimes combined with metaphor > or analogy fallacy) and you are a master at presenting both... > thankfully you usually don't try to present both at the same time! ?:) > > In this present case the straw-man was not "me," rather the straw-man > was the python language itself. You chose a code-snippet (one small puny > dangle that doesn't prove a thing) and used it to speak for the entire > language! ?As though one code-block is enough to demonstrate > compatibility for the entire language in all of its nuances and details. > ? To prove something positive with a test case requires that you provide > *all* test cases, or that you provide an algorithm that accounts for > *all* test cases... you cannot prove compatibility with a code-snippet. > > On the other hand, all you have to do to prove incompatibility is to > show "one" (1) test case where compatibility fails... and of course for > the present case there are many that can be shown, in fact, hundreds of > them. > > The thing that nobody has presented here yet is that *all* the books > declare that 3.x is incompatible with 2.x/ ? ... some of them go out of > their way to tell the reader that they are only going to deal with 3.x > and not 2.x in any way... and others go out of their way to point out > the hundreds of nuances in details between the two languages. (and a > good thing too, for those of us who must work with both! ) ?So this fact > is not alluding the press... the point being not to bust anybody in the > chops, but to point out that it is not helpful to move the community > forward with a new language and get mass adoption (not just early > adopters) to lie about the differences between the two sets... yes, for > trivial code blocks that use prime constructs, integer math, and the > print statement, not much has changed. ?But in real world applications > of the language there are many hundreds of details that have changed or > been added (deleted) which will make life difficult for the uninitiated. > Don't mislead people by saying that very little has changed. ?Tell them > that the philosophy is the same (what Chris called python 'think' ) but > be honest about the details of syntax, environment, layout, and > morphology. Bravo! PS: And yes, Steven is a master at the straw man fallacy. From tjreedy at udel.edu Sun May 29 18:20:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 May 2011 18:20:30 -0400 Subject: scope of function parameters In-Reply-To: <371A067F-540A-46C3-820C-4348B9815AB9@mcgill.ca> References: <201105291147.26545.wolfgang@rohdewald.de> <371A067F-540A-46C3-820C-4348B9815AB9@mcgill.ca> Message-ID: On 5/29/2011 4:19 PM, Henry Olders wrote: > From my perspective, a function parameter should be considered as > having been assigned (although the exact assignment will not be known > until runtime), and as an assigned variable, it should be considered > local. That is exactly the case for Python functions. >>> def f(a,b): c,d = 3,4 print(locals()) >>> f.__code__.co_varnames # local names ('a', 'b', 'c', 'd') >>> f(1,2) {'a': 1, 'c': 3, 'b': 2, 'd': 4} The requirement for a function call is that all parameters get an assignment and that all args are used in assignments (either directly by position or keyname or as part of a *args or **kwds assignment). -- Terry Jan Reedy From irmen.NOSPAM at xs4all.nl Sun May 29 18:30:08 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 30 May 2011 00:30:08 +0200 Subject: How to Use Setuptools, Alternatives? In-Reply-To: <01045077-543f-4b8d-a5a2-4cde190c3294@v8g2000yqb.googlegroups.com> References: <01045077-543f-4b8d-a5a2-4cde190c3294@v8g2000yqb.googlegroups.com> Message-ID: <4de2c8f1$0$49182$e4fe514c@news.xs4all.nl> On 29-5-2011 23:41, ray wrote: > I have Python 2.7 on Win7 Pro on a tightly locked down desktop. I > would like to install Networkx from an egg. From what I have read, > Setuptools can be used for this. What does 'tightly locked down' mean? > I don't know how to install Setuptools. The exe will not work. On > execution, it reports that the Python version is not included in the > registry. That can be fixed by repairing the Python installation through its .msi. Also, are you sure you used the python 2.7 setuptools exe? > Further, I can not input the version and location on the > subsequent installation screen, the fields will not accept focus so I > can not input the values. > > Since the exe will not install, I considered using the Setuptools > egg. But it requires Setuptools. It appears to be a circle. > > What are some suggestions for installing this? > > Thanks, > ray Perhaps you can try VirtualEnv and PiP instead. Irmen From irmen.NOSPAM at xs4all.nl Sun May 29 18:31:08 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 30 May 2011 00:31:08 +0200 Subject: Alternatives to PythonPath In-Reply-To: References: Message-ID: <4de2c92d$0$49182$e4fe514c@news.xs4all.nl> On 29-5-2011 23:49, ray wrote: > I am using Win7 on a tightly locked down desktop. > > Is there an alternative to using PythonPath? > What do you mean by "using PythonPath"? What doesn't work that you want to have an alternative for? Irmen From benjamin at python.org Sun May 29 18:44:58 2011 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 29 May 2011 17:44:58 -0500 Subject: [RELEASE] 3.1.4 release candidate 1 Message-ID: On behalf of the Python development team, I'm happy as a swallow to announce a release candidate for the fourth bugfix release for the Python 3.1 series, Python 3.1.4. 3.1.4 will the last bug fix release in the 3.1 series before 3.1. After 3.1.4, 3.1 will be in security-only fix mode. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. This is a testing release. To download Python 3.1.4rc1 visit: http://www.python.org/download/releases/3.1.4/ A list of changes in 3.1.4 can be found here: http://hg.python.org/cpython/file/35419f276c60/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.4's contributors) From benjamin at python.org Sun May 29 18:47:42 2011 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 29 May 2011 17:47:42 -0500 Subject: [RELEASE] Python 2.7.2 release candidate 1 Message-ID: On behalf of the Python development team, I'm happy to announce the immediate availability of Python 2.7.2 release candidate 1. 2.7.2 is the second in bugfix release for the Python 2.7 series. 2.7 is the last major verison of the 2.x line and will be receiving bug fixes while new feature development focuses on 3.x. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, auto-numbering of fields in the str/unicode format method, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7.2rc1 visit: http://www.python.org/download/releases/2.7.1/ The 2.7.2 changelog is at: http://hg.python.org/cpython/file/439396b06416/Misc/NEWS 2.7 documentation can be found at: http://docs.python.org/2.7/ This is a preview release. Assuming no major problems, 2.7.2 will be released in two weeks. Please report any bugs you find to http://bugs.python.org/ Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7.2's contributors) From rantingrick at gmail.com Sun May 29 18:54:12 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 15:54:12 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: <0af840cd-0ece-4345-853d-775be12aa12f@k16g2000yqm.googlegroups.com> On May 29, 4:46?pm, Chris Angelico wrote: > On Mon, May 30, 2011 at 7:38 AM, rantingrick wrote: > > Yes but understanding of this sort is very general ESPECIALLY in the > > case of destroying data! > > > What are the limits of the recursion? What forces can act on the > > recursion to stop it? If (for example) I know that a "while loop" will > > continue forever until "something" stops it then i really don't know > > enough about while loops to start using them safely do i? > > That's true of anything. If I turn on the light switch, I expect there > to be a limit to the amount of light it produces; I don't want a > household fluro to produce the intensity of the worklights in a > theatre. Ought I to get the technical specs and find out exactly how > many lumens will be produced, or can I safely power it on in the > expectation that it will do the obvious thing? That is a very good argument however it does not consider the fact of "technical users" verses "non-technical users". Anyone can be expected to understand the consequenses of switching on a lightbulb (even a child) because the action requires no logical thinking abilites... simply flip it and forget it. HOWEVER not everyone understands the consequeses of recursively deleting a directory... or whatever that means in the current context. From rantingrick at gmail.com Sun May 29 19:00:06 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 16:00:06 -0700 (PDT) Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: <60c7d496-e099-4cd2-8fa5-5f395cf4b21a@e35g2000yqc.googlegroups.com> On May 29, 2:28?pm, Jason Tackaberry wrote: > On 11-05-29 04:06 AM, Ian Kelly wrote: > > > I realize you are now asserting that compatibility is a boolean > > condition, and that "totally incompatible" is a redundant phrase that > > you tossed out as a joke. > > As a casual lurker reading this thread, I believe he is equating > "completely incompatible" with "not completely compatible." ?At least, > his arguments make more sense if I read him as arguing from the "not > completely compatible" position. ?It's possible he is intentionally > equivocating for dramatic effect. > > But they are different -- both connotatively and denotatively -- and to > argue against the claim that Python 2 and 3 are "completely > incompatible" it seems to me sufficient to provide a single non-trivial > counter-example, which Steven has already done. Python 2.x and Pythin 3.x are two different dialects just like Humans (Python 3.x) and Chimpanzees (Python 2.x) are similar (compatible) but very different versions of talking apes (languages). Sure humans (Python 3.x) and chimps (Python 2.x) share some similarities (much more than say humans (Python3.x) and fish (Lisp) do) however there are many incompatible differences. From rosuav at gmail.com Sun May 29 19:31:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 09:31:16 +1000 Subject: Beginner needs advice In-Reply-To: <60c7d496-e099-4cd2-8fa5-5f395cf4b21a@e35g2000yqc.googlegroups.com> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> <60c7d496-e099-4cd2-8fa5-5f395cf4b21a@e35g2000yqc.googlegroups.com> Message-ID: On Mon, May 30, 2011 at 9:00 AM, rantingrick wrote: > Python 2.x and Pythin 3.x are two different dialects just like Humans > (Python 3.x) and Chimpanzees (Python 2.x) are similar (compatible) but > very different versions of talking apes (languages). Sure humans > (Python 3.x) and chimps (Python 2.x) share some similarities (much > more than say humans (Python3.x) and fish (Lisp) do) however there are > many incompatible differences. > Chimpanzees do not use language in the same way that humans do, and in any case, it's pretty ridiculous to talk of the 'Human language' in anything other than a fantasy roleplaying game. It's more comparable to call Py2 "scientific English"and Py3 "medical English". There are differences (what's a calorie?), but for the most part, they are the same language. Chris Angelico From steve+comp.lang.python at pearwood.info Sun May 29 19:31:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 23:31:19 GMT Subject: float("nan") in set or as key References: <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> <4de22007$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 22:19:49 +0100, Nobody wrote: > On Sun, 29 May 2011 10:29:28 +0000, Steven D'Aprano wrote: > >>> The correct answer to "nan == nan" is to raise an exception, >>> because >>> you have asked a question for which the answer is nether True nor >>> False. >> >> Wrong. > > That's overstating it. There's a good argument to be made for raising an > exception. If so, I've never heard it, and I cannot imagine what such a good argument would be. Please give it. (I can think of *bad* arguments, like "NANs confuse me and I don't understand the reason for their existence, therefore I'll give them behaviours that make no sense and aren't useful". But you did state there is a *good* argument.) > Bear in mind that an exception is not necessarily an error, > just an "exceptional" condition. True, but what's your point? Testing two floats for equality is not an exceptional condition. >> The correct answer to "nan == nan" is False, they are not equal. > > There is no correct answer to "nan == nan". Why on earth not? > Defining it to be false is just the "least wrong" answer. So you say, but I think you are incorrect. > Arguably, "nan != nan" should also be false, > but that would violate the invariant "(x != y) == !(x == y)". I cannot imagine what that argument would be. Please explain. -- Steven From nospam at torek.net Sun May 29 19:37:17 2011 From: nospam at torek.net (Chris Torek) Date: 29 May 2011 23:37:17 GMT Subject: Error: child process close a socket inherited from parent References: Message-ID: In article narke wrote: >As illustrated in the following simple sample: > >import sys >import os >import socket > >class Server: > def __init__(self): > self._listen_sock = None > > def _talk_to_client(self, conn, addr): > text = 'The brown fox jumps over the lazy dog.\n' > while True: > conn.send(text) > data = conn.recv(1024) > if not data: > break > conn.close() > > def listen(self, port): > self._listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > self._listen_sock.bind(('', port)) > self._listen_sock.listen(128) > self._wait_conn() > > def _wait_conn(self): > while True: > conn, addr = self._listen_sock.accept() > if os.fork() == 0: > self._listen_sock.close() # line x > self._talk_to_client(conn, addr) > else: > conn.close() > >if __name__ == '__main__': > Server().listen(int(sys.argv[1])) > >Unless I comment out the line x, I will get a 'Bad file descriptor' >error when my tcp client program (e.g, telnet) closes the connection to >the server. But as I understood, a child process can close a unused >socket (file descriptor). It can. >Do you know what's wrong here? The problem turns out to be fairly simple. The routine listen() forks, and the parent process (with nonzero pid) goes into the "else" branch of _wait_conn(), hence closes the newly accepted socket and goes back to waiting on the accept() call, which is all just fine. Meanwhile, the child (with pid == 0) calls close() on the listening socket and then calls self._talk_to_client(). What happens when the client is done and closes his end? Well, take a look at the code in _talk_to_client(): it reaches the "if not data" clause and breaks out of its loop, and calls close() on the accepted socket ... and then returns to its caller, which is _wait_conn(). What does _wait_conn() do next? It has finished "if" branch in the "while True:" loops, so it must skip the "else" branch and go around the loop again. Which means its very next operation is to call accept() on the listening socket it closed just before it called self._talk_to_client(). If that socket is closed, you get an EBADF error raised. If not, the child and parent compete for the next incoming connection. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From steve+comp.lang.python at pearwood.info Sun May 29 19:46:00 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 23:46:00 GMT Subject: scope of function parameters References: Message-ID: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 04:30:52 -0400, Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a > program. The made-up code snippet below illustrates the problem I > encountered: [...] > Are there others who feel as I do that a function parameter should > always be local to the function? Or am I missing something here? The nature of Henry's misunderstanding is a disguised version of the very common "is Python call by reference or call by value?" question that periodically crops up. I wrote a long, but I hope useful, explanation for the tutor at python.org mailing list, which I'd like to share here: http://mail.python.org/pipermail/tutor/2010-December/080505.html Constructive criticism welcome. -- Steven From nospam at torek.net Sun May 29 20:02:02 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 00:02:02 GMT Subject: float("nan") in set or as key References: <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> Message-ID: Incidentally, note: $ python ... >>> nan = float("nan") >>> nan nan >>> nan is nan True >>> nan == nan False In article <4de1e3e7$0$2195$742ec2ed at news.sonic.net> John Nagle wrote: > The correct answer to "nan == nan" is to raise an exception, because >you have asked a question for which the answer is nether True nor False. Well, in some sense, the "correct answer" depends on which question you *meant* to ask. :-) Seriously, some (many?) instruction sets have two kinds of comparison instructions: one that raises an exception here, and one that does not. > The correct semantics for IEEE floating point look something like >this: > > 1/0 INF > INF + 1 INF > INF - INF NaN > INF == INF unordered > NaN == NaN unordered > >INF and NaN both have comparison semantics which return >"unordered". The FPU sets a bit for this, which most language >implementations ignore. Again, this depends on the implementation. This is similar to (e.g.) the fact that on the MIPS, there are two different integer add instructions ("addi" and "addiu"): one raises an overflow exception, the other performs C "unsigned" style arithmetic (where, e.g., 0xffffffff + 1 = 0, in 32 bits). >Python should raise an exception on unordered comparisons. >Given that the language handles integer overflow by going to >arbitrary-precision integers, checking the FPU status bits is >cheap. I could go for that myself. But then you also need a "don't raise exception but give me an equality test result" operator (for various special-case purposes at least) too. Of course a simple "classify this float as one of normal, subnormal, zero, infinity, or NaN" operator would suffice here (along with the usual "extract sign" and "differentiate between quiet and signalling NaN" operations). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From pavlovevidence at gmail.com Sun May 29 20:55:22 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 May 2011 17:55:22 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> On Sunday, May 29, 2011 4:31:19 PM UTC-7, Steven D'Aprano wrote: > On Sun, 29 May 2011 22:19:49 +0100, Nobody wrote: > > > On Sun, 29 May 2011 10:29:28 +0000, Steven D'Aprano wrote: > > > >>> The correct answer to "nan == nan" is to raise an exception, > >>> because > >>> you have asked a question for which the answer is nether True nor > >>> False. > >> > >> Wrong. > > > > That's overstating it. There's a good argument to be made for raising an > > exception. > > If so, I've never heard it, and I cannot imagine what such a good > argument would be. Please give it. Floating point arithmetic evolved more or less on languages like Fortran where things like exceptions were unheard of, and defining NaN != NaN was a bad trick they chose for testing against NaN for lack of a better way. If exceptions had commonly existed in that environment there's no chance they would have chosen that behavior; comparison against NaN (or any operation with NaN) would have signaled a floating point exception. That is the correct way to handle exceptional conditions. The only reason to keep NaN's current behavior is to adhere to IEEE, but given that Python has trailblazed a path of correcting arcane mathematical behavior, I definitely see an argument that Python should do the same for NaN, and if it were done Python would be a better language. Carl Banks From nospam at torek.net Sun May 29 21:02:41 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 01:02:41 GMT Subject: How to catch a line with Popen References: Message-ID: In article TheSaint wrote: >Chris Rebert wrote: >I just suppose to elaborate the latest line, as soon it's written on the >pipe, and print some result on the screen. >Imaging something like > > p= Popen(['ping','-c40','www.google.com'], stdout=PIPE) > for line in p.stdout: > print(str(line).split()[7]) > >I'd like to see something like *time=54.4* >This is just an example, where if we remove the "-c40" on the command line, >I'd expect to read the latest line(s), until the program will be killed. In at least some versions of Python 2, file-like object "next" iterators do not "work right" with unbuffered (or line-buffered) pipe-file-objects. (This may or may not be fixed in Python 3.) A simple workaround is a little generator using readline(): def line_at_a_time(fileobj): """ Return one line at a time from a file-like object. Works around the iter behavior of pipe files in Python 2.x, e.g., instead of "for line in file" you can write "for line in line_at_a_time(file)". """ while True: line = fileobj.readline() if not line: return yield line Adding this to your sample code gives something that works for me, provided I fiddle with it to make sure that the only lines examined are those with actual ping times: p = subprocess.Popen(["ping", "-c5", "www.google.com"], stdout = subprocess.PIPE) for lineno, line in enumerate(line_at_a_time(p.stdout)): if 1 <= lineno <= 5: print line.split()[6] else: print line.rstrip('\n') p.wait() # discard final result (Presumably the enumerate() trick would not be needed in whatever you really use.) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From pavlovevidence at gmail.com Sun May 29 21:07:50 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 May 2011 18:07:50 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: Message-ID: <3cb7d86d-0928-4052-adbd-771ce29de780@glegroupsg2000goo.googlegroups.com> On Sunday, May 29, 2011 7:41:13 AM UTC-7, Grant Edwards wrote: > It treats them as identical (not sure if that's the right word). The > implementation is checking for ( A is B or A == B ). Presumably, the > assumpting being that all objects are equal to themselves. That > assumption is not true for NaN objects, so the buggy behavior is > observed. Python makes this assumption in lots of common situations (apparently in an implementation-defined manner): >>> nan = float("nan") >>> nan == nan False >>> [nan] == [nan] True Therefore, I'd recommend never to rely on NaN != NaN except in casual throwaway code. It's too easy to forget that it will stop working when you throw an item into a list or tuple. There's a function, math.isnan(), that should be the One Obvious Way to test for NaN. NaN should also never be used as a dictionary key or in a set (of course). If it weren't for compatibility with IEEE, there would be no sane argument that defining an object that is not equal to itself isn't a bug. But because there's a lot of code out there that depends on NaN != NaN, Python has to tolerate it. Carl Banks From rosuav at gmail.com Sun May 29 21:14:58 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 11:14:58 +1000 Subject: float("nan") in set or as key In-Reply-To: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> References: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 30, 2011 at 10:55 AM, Carl Banks wrote: > If exceptions had commonly existed in that environment there's no chance they would have chosen that behavior; comparison against NaN (or any operation with NaN) would have signaled a floating point exception. ?That is the correct way to handle exceptional conditions. > > The only reason to keep NaN's current behavior is to adhere to IEEE, but given that Python has trailblazed a path of correcting arcane mathematical behavior, I definitely see an argument that Python should do the same for NaN, and if it were done Python would be a better language. If you're going to change behaviour, why have a floating point value called "nan" at all? Other than being a title for one's grandmother, what meaning does that string have, and why should it be able to be cast as floating point? Lifting from http://en.wikipedia.org/wiki/NaN a list of things that can return a NaN (I've removed non-ASCII characters from this snippet): * Operations with a NaN as at least one operand. (you need to bootstrap that somehow, so we can ignore this - it just means that nan+1 = nan) * The divisions 0/0 and infinity/infinity * The multiplications 0*infinity and infinity*0 * The additions +inf + (-inf), (-inf) + +inf and equivalent subtractions * The standard pow function and the integer exponent pown function define 0**0, 1**inf, and inf**0 as 1. * The powr function define all three indeterminate forms as invalid operations and so returns NaN. * The square root of a negative number. * The logarithm of a negative number * The inverse sine or cosine of a number that is less than -1 or greater than +1. Rather than having comparisons with NaN trigger exceptions, wouldn't it be much cleaner to have all these operations trigger exceptions? And, I would guess that they probably already do. NaN has an additional use in that it can be used like a "null pointer"; a floating-point variable can store 1.0, or 0.000000000005, or "no there's no value that I'm storing in this variable". Since a Python variable can contain None instead of a float, this use is unnecessary too. So, apart from float("nan"), are there actually any places where real production code has to handle NaN? I was unable to get a nan by any of the above methods, except for operations involving inf; for instance, float("inf")-float("inf") == nan. All the others raised an exception rather than return nan. Chris Angelico From hammer777123 at gmail.com Sun May 29 21:26:16 2011 From: hammer777123 at gmail.com (hammer777123 at gmail.com) Date: Sun, 29 May 2011 18:26:16 -0700 (PDT) Subject: Seven Months!...$51,724.00 a Month! { Retired?} Sign-Up Free!.... Message-ID: <0ff07a1a-e220-408e-a78e-3abcaff3d69e@g28g2000yqa.googlegroups.com> Seven Months!...$51,724.00 a Month! { Retired?} Sign-Up Free!.... http://tinyurl.com/3eybq2t Create wealth automatically! A simple system, no selling or recruiting. Fully Automated. The highest pay-out in the world. It's working for me and thousands because of the Upgrade Income Booster Enjoy a FR.EE trial and motivational audio. Sign-Up Free and get $5.00! http://tinyurl.com/3eybq2t Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Need Traffic?......FREE 250,000,000 Visitors to your Website! http://tinyurl.com/6aooafd One Dollar Per Click! $1000.00 in 53 Minutes http://tinyurl.com/68hdx3b Need Traffic?____Generated Up To 283,424 Visitors a Day____Free! http://tinyurl.com/3c9b33h Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Promote your website to over 700,000 Search Engines, Directories, Link Pages, Online Malls, Classified Sites! 100% Automated - A Complete Traffic Generating Machine!!! http://ezwebsubmissions.com/clickthru.pl?id=wct3777 http://tinyurl.com/3eybq2t Seven Months!...$51,724.00 a Month! { Retired?} Sign-Up Free!.... http://tinyurl.com/3eybq2t Create wealth automatically! A simple system, no selling or recruiting. Fully Automated. The highest pay-out in the world. It's working for me and thousands because of the Upgrade Income Booster Enjoy a FR.EE trial and motivational audio. Sign-Up Free and get $5.00! http://tinyurl.com/3eybq2t Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Need Traffic?......FREE 250,000,000 Visitors to your Website! http://tinyurl.com/6aooafd One Dollar Per Click! $1000.00 in 53 Minutes http://tinyurl.com/68hdx3b Need Traffic?____Generated Up To 283,424 Visitors a Day____Free! http://tinyurl.com/3c9b33h Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Promote your website to over 700,000 Search Engines, Directories, Link Pages, Online Malls, Classified Sites! 100% Automated - A Complete Traffic Generating Machine!!! http://ezwebsubmissions.com/clickthru.pl?id=wct3777 http://tinyurl.com/3eybq2t Seven Months!...$51,724.00 a Month! { Retired?} Sign-Up Free!.... http://tinyurl.com/3eybq2t Create wealth automatically! A simple system, no selling or recruiting. Fully Automated. The highest pay-out in the world. It's working for me and thousands because of the Upgrade Income Booster Enjoy a FR.EE trial and motivational audio. Sign-Up Free and get $5.00! http://tinyurl.com/3eybq2t Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Need Traffic?......FREE 250,000,000 Visitors to your Website! http://tinyurl.com/6aooafd One Dollar Per Click! $1000.00 in 53 Minutes http://tinyurl.com/68hdx3b Need Traffic?____Generated Up To 283,424 Visitors a Day____Free! http://tinyurl.com/3c9b33h Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Promote your website to over 700,000 Search Engines, Directories, Link Pages, Online Malls, Classified Sites! 100% Automated - A Complete Traffic Generating Machine!!! http://ezwebsubmissions.com/clickthru.pl?id=wct3777 http://tinyurl.com/3eybq2t From ben+python at benfinney.id.au Sun May 29 21:31:33 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 May 2011 11:31:33 +1000 Subject: scope of function parameters References: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87pqn17z4a.fsf@benfinney.id.au> Steven D'Aprano writes: > http://mail.python.org/pipermail/tutor/2010-December/080505.html > > > Constructive criticism welcome. Informative, but it ?buries the lead? as our friends in the press corps would say. Instead you should write as though you have no idea where the reader will stop reading, and still give them the most useful part. Write the most important information first, and don't bury it at the end. In this case, I'd judge the most important information to be ?what is the Python passing model?? Give it a short name; the effbot's ?pass by object? sounds good to me. Then explain what that means. Then, only after giving the actual information you want the reader to go away with, you can spend the rest of the essay giving a history behind the craziness. More on this style: -- \ Moriarty: ?Forty thousand million billion dollars? That money | `\ must be worth a fortune!? ?The Goon Show, _The Sale of | _o__) Manhattan_ | Ben Finney From nospam at torek.net Sun May 29 21:44:17 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 01:44:17 GMT Subject: portable way of sending notifying a process References: <4de183e7$0$26108$426a74cc@news.free.fr> Message-ID: In article <4de183e7$0$26108$426a74cc at news.free.fr> News123 wrote: >I'm looking for a portable way (windows XP / Windows Vista and Linux ) >to send a signal from any python script to another one >(one signa would be enough) This turns out to be pretty hard to do reliably-and-securely even *without* crossing the Windows / Linux barrier. >It seems, that neither the signals HUP / USR1 are implemented under windows. Signals are also very messy and easy to get wrong on Unix, with earlier Python versions missing a few key items to make them entirely reliable (such as the sigblock/sigsetmask/sigpause suite, and/or setting interrupt-vs-resume behavior on system calls). >What would be a light weight portable way, that one process can tell >another to do something? > >The main requirement would be to have no CPU impact while waiting (thus >no polling) Your best bet here is probably to use sockets. Both systems have ways to create service sockets and to connect to a socket as a client. Of course, making these secure can be difficult: you must decide what sort of attack(s) could occur and how much effort to put into defending against them. (For instance, even if there is only a "wake up, I have done something you should look at" signal that you can transmit by connecting to a server and then closing the connection, what happens if someone inside or outside your local network decides to repeatedly poke that port in the hopes of causing a Denial of Service by making the server use lots of CPU time?) >If nothing exists I might just write a wrapper around >pyinotify and (Tim Goldens code snippet allowing to watch a directory >for file changes) >http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html > >and use a marker file in a marker directory >but I wanted to be sure of not reinventing the wheel. It really sounds like you are writing client/server code in which the client writes a file into a queue directory. In this case, that may be the way to go -- or you could structure it as an actual client and server, i.e., the client connects to the server and writes the request directly (but then you have to decide about security considerations, which the OS's local file system may provide more directly). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From rosuav at gmail.com Sun May 29 21:56:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 11:56:27 +1000 Subject: scope of function parameters In-Reply-To: <87pqn17z4a.fsf@benfinney.id.au> References: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> <87pqn17z4a.fsf@benfinney.id.au> Message-ID: On Mon, May 30, 2011 at 11:31 AM, Ben Finney wrote: > ? I agree with the gist of that. My take on this is: When I'm talking to my boss, I always assume that the phone will ring ten seconds into my explanation. Ten seconds is enough for "Dad, I'm OK; the bull is dead", it's enough for "I've solved Problem X, we can move on now"; it's enough for "Foo is crashing, can't ship till I debug it". If fortune is smiling on me and the phone isn't ringing, I can explain that Problem X was the reason Joe was unable to demo his new module, or that the crash in Foo is something that I know I'll be able to pin down in a one-day debugging session, but even if I don't, my boss knows enough to keep going with. Of course, there's a significant difference between a mailing list post and a detailed and well copyedited article. Quite frequently I'll ramble on list, in a way quite inappropriate to a publication that would be linked to as a "hey guys, here's how it is" page. Different media, different standards. Chris Angelico "Forty thousand million billion THEGS quotes? That must be worth a fortune!" -- definitely a fan of THEGS -- From rosuav at gmail.com Sun May 29 22:03:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 12:03:21 +1000 Subject: portable way of sending notifying a process In-Reply-To: References: <4de183e7$0$26108$426a74cc@news.free.fr> Message-ID: On Mon, May 30, 2011 at 11:44 AM, Chris Torek wrote: >>What would be a light weight portable way, that one process can tell >>another to do something? >> >>The main requirement would be to have no CPU impact while waiting (thus >>no polling) > > Your best bet here is probably to use sockets. ?Both systems have > ways to create service sockets and to connect to a socket as a > client. Further to this: If your two processes are going to start up, then run concurrently for some time, and during that time alert each other (or one alerts the other) frequently, a socket is an excellent choice. Use a TCP socket on Windows, and either a TCP socket or a Unix socket on Linux (I'd just use TCP on both for simplicity, but Unix sockets are faster), and simply write a byte to it whenever you want to alert the other side. You can largely guarantee that no other process can accidentally or maliciously wake you, as long as you have some kind of one-off handshake on connection - even something really simple like sending a random nonce, having the other end send hash(nonce + password), and compare. Chris Angelico Huge fan of TCP sockets (hello MUDs!) From ben+python at benfinney.id.au Sun May 29 22:08:46 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 May 2011 12:08:46 +1000 Subject: scope of function parameters References: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> <87pqn17z4a.fsf@benfinney.id.au> Message-ID: <87lixp7xe9.fsf@benfinney.id.au> Chris Angelico writes: > Of course, there's a significant difference between a mailing list > post and a detailed and well copyedited article. Quite frequently I'll > ramble on list, in a way quite inappropriate to a publication that > would be linked to as a "hey guys, here's how it is" page. Different > media, different standards. Right. But Steven specifically asked for constructive criticism, which I took as permission to treat the referenced post as an article in need of copy editing :-) -- \ ?The truth is the most valuable thing we have. Let us economize | `\ it.? ?Mark Twain, _Following the Equator_ | _o__) | Ben Finney From pavlovevidence at gmail.com Sun May 29 22:17:01 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 May 2011 19:17:01 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: Message-ID: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> On Sunday, May 29, 2011 6:14:58 PM UTC-7, Chris Angelico wrote: > On Mon, May 30, 2011 at 10:55 AM, Carl Banks > wrote: > > If exceptions had commonly existed in that environment there's no chance they would have chosen that behavior; comparison against NaN (or any operation with NaN) would have signaled a floating point exception. ?That is the correct way to handle exceptional conditions. > > > > The only reason to keep NaN's current behavior is to adhere to IEEE, > > but given that Python has trailblazed a path of correcting arcane > > mathematical behavior, I definitely see an argument that Python > > should do the same for NaN, and if it were done Python would be a > > better language. > > If you're going to change behaviour, why have a floating point value > called "nan" at all? If I were designing a new floating-point standard for hardware, I would consider getting rid of NaN. However, with the floating point standard that exists, that almost all floating point hardware mostly conforms to, there are certain bit pattern that mean NaN. Python could refuse to construct float() objects out of NaN (I doubt it would even be a major performance penalty), but there's reasons why you wouldn't, the main one being to interface with other code that does use NaN. It's better, then, to recognize the NaN bit patterns and do something reasonable when trying to operate on it. Carl Banks From rustompmody at gmail.com Sun May 29 22:26:49 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 29 May 2011 19:26:49 -0700 (PDT) Subject: Alternatives to PythonPath References: Message-ID: On May 30, 2:49?am, ray wrote: > I am using Win7 on a tightly locked down desktop. > > Is there an alternative to using PythonPath? > > What are the trade-offs? > > Thanks, > ray Externally: 1. PYTHONPATH 2. .pth files http://bob.pythonmac.org/archives/2005/02/06/using-pth-files-for-python-development/ http://docs.python.org/library/site.html And of course there the internal sys.path From rosuav at gmail.com Sun May 29 22:37:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 12:37:30 +1000 Subject: scope of function parameters In-Reply-To: <87lixp7xe9.fsf@benfinney.id.au> References: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> <87pqn17z4a.fsf@benfinney.id.au> <87lixp7xe9.fsf@benfinney.id.au> Message-ID: On Mon, May 30, 2011 at 12:08 PM, Ben Finney wrote: > Chris Angelico writes: > >> Of course, there's a significant difference between a mailing list >> post and a detailed and well copyedited article. Quite frequently I'll >> ramble on list, in a way quite inappropriate to a publication that >> would be linked to as a "hey guys, here's how it is" page. Different >> media, different standards. > > Right. But Steven specifically asked for constructive criticism, which I > took as permission to treat the referenced post as an article in need of > copy editing :-) Indeed. Was just saying that there are times when you need to get the slug out first, and times when it's okay to be a little less impactual (if that's a word). Although it's still important to deliver your message promptly. Of course, there are other contexts where you specifically do NOT want to give everything away at the beginning. Certain styles of rhetoric demand that you set the scene, build your situation, and only at the climax reveal what it is you are trying to say. Ahh! wordsmithing, how we love thee. Chris Angelico From rosuav at gmail.com Sun May 29 22:53:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 12:53:59 +1000 Subject: float("nan") in set or as key In-Reply-To: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> References: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 30, 2011 at 12:17 PM, Carl Banks wrote: > If I were designing a new floating-point standard for hardware, I would consider getting rid of NaN. ?However, with the floating point standard that exists, that almost all floating point hardware mostly conforms to, there are certain bit pattern that mean NaN. > > Python could refuse to construct float() objects out of NaN (I doubt it would even be a major performance penalty), but there's reasons why you wouldn't, the main one being to interface with other code that does use NaN. ?It's better, then, to recognize the NaN bit patterns and do something reasonable when trying to operate on it. Okay, here's a question. The Python 'float' value - is it meant to be "a Python representation of an IEEE double-precision floating point value", or "a Python representation of a real number"? For the most part, Python's data types are defined by their abstract concepts - a list isn't defined as a linked list of pointers, it's defined as an ordered collection of objects. Python 3 removes the distinction between 'int' and 'long', where 'int' is <2**32 and 'long' isn't, so now a Py3 integer is... any integer. The sys.float_info struct exposes details of floating point representation. In theory, a Python implementation that uses bignum floats could quite happily set all those values to extremes and work with enormous precision (or could use a REXX-style "numeric digits 100" command to change the internal rounding, and automatically update sys.float_info). And in that case, there would be no NaN value. If Python is interfacing with some other code that uses NaN, that code won't be using Python 'float' objects - it'll be using IEEE binary format, probably. So all it would need to entail is a special return value from an IEEE Binary to Python Float converter function (maybe have it return None), and NaN is no longer a part of Python. The real question is: Would NaN's removal be beneficial? And if so, would it be worth the effort? Chris Angelico From rustompmody at gmail.com Sun May 29 23:08:35 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 29 May 2011 20:08:35 -0700 (PDT) Subject: float("nan") in set or as key References: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> Message-ID: <841029ac-f41e-49ac-861b-be2b0691c030@17g2000prr.googlegroups.com> On May 30, 7:53?am, Chris Angelico wrote: > On Mon, May 30, 2011 at 12:17 PM, Carl Banks wrote: > > If I were designing a new floating-point standard for hardware, I would consider getting rid of NaN. ?However, with the floating point standard that exists, that almost all floating point hardware mostly conforms to, there are certain bit pattern that mean NaN. > > > Python could refuse to construct float() objects out of NaN (I doubt it would even be a major performance penalty), but there's reasons why you wouldn't, the main one being to interface with other code that does use NaN. ?It's better, then, to recognize the NaN bit patterns and do something reasonable when trying to operate on it. > > Okay, here's a question. The Python 'float' value - is it meant to be > "a Python representation of an IEEE double-precision floating point > value", or "a Python representation of a real number"? For the most > part, Python's data types are defined by their abstract concepts - a > list isn't defined as a linked list of pointers, it's defined as an > ordered collection of objects. Python 3 removes the distinction > between 'int' and 'long', where 'int' is <2**32 and 'long' isn't, so > now a Py3 integer is... any integer. > > The sys.float_info struct exposes details of floating point > representation. In theory, a Python implementation that uses bignum > floats could quite happily set all those values to extremes and work > with enormous precision (or could use a REXX-style "numeric digits > 100" command to change the internal rounding, and automatically update > sys.float_info). And in that case, there would be no NaN value. > > If Python is interfacing with some other code that uses NaN, that code > won't be using Python 'float' objects - it'll be using IEEE binary > format, probably. So all it would need to entail is a special return > value from an IEEE Binary to Python Float converter function (maybe > have it return None), and NaN is no longer a part of Python. > > The real question is: Would NaN's removal be beneficial? And if so, > would it be worth the effort? > > Chris Angelico nan in floating point is like null in databases It may be worthwhile to have a look at what choices SQL has made http://en.wikipedia.org/wiki/Null_%28SQL%29 From narkewoody at gmail.com Sun May 29 23:52:43 2011 From: narkewoody at gmail.com (narke) Date: Sun, 29 May 2011 22:52:43 -0500 Subject: Error: child process close a socket inherited from parent References: Message-ID: On 2011-05-29, Chris Torek wrote: > In article > narke wrote: >>As illustrated in the following simple sample: >> >>import sys >>import os >>import socket >> >>class Server: >> def __init__(self): >> self._listen_sock = None >> >> def _talk_to_client(self, conn, addr): >> text = 'The brown fox jumps over the lazy dog.\n' >> while True: >> conn.send(text) >> data = conn.recv(1024) >> if not data: >> break >> conn.close() >> >> def listen(self, port): >> self._listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >> self._listen_sock.bind(('', port)) >> self._listen_sock.listen(128) >> self._wait_conn() >> >> def _wait_conn(self): >> while True: >> conn, addr = self._listen_sock.accept() >> if os.fork() == 0: >> self._listen_sock.close() # line x >> self._talk_to_client(conn, addr) >> else: >> conn.close() >> >>if __name__ == '__main__': >> Server().listen(int(sys.argv[1])) >> >>Unless I comment out the line x, I will get a 'Bad file descriptor' >>error when my tcp client program (e.g, telnet) closes the connection to >>the server. But as I understood, a child process can close a unused >>socket (file descriptor). > > It can. > >>Do you know what's wrong here? > > The problem turns out to be fairly simple. > > The routine listen() forks, and the parent process (with nonzero pid) > goes into the "else" branch of _wait_conn(), hence closes the newly > accepted socket and goes back to waiting on the accept() call, which > is all just fine. > > Meanwhile, the child (with pid == 0) calls close() on the listening > socket and then calls self._talk_to_client(). > > What happens when the client is done and closes his end? Well, > take a look at the code in _talk_to_client(): it reaches the > "if not data" clause and breaks out of its loop, and calls close() > on the accepted socket ... and then returns to its caller, which > is _wait_conn(). > > What does _wait_conn() do next? It has finished "if" branch in > the "while True:" loops, so it must skip the "else" branch and go > around the loop again. Which means its very next operation is > to call accept() on the listening socket it closed just before > it called self._talk_to_client(). > > If that socket is closed, you get an EBADF error raised. If not, > the child and parent compete for the next incoming connection. Chris, Thanks, you helped to find out a bug in my code. From steve+comp.lang.python at pearwood.info Sun May 29 23:59:49 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 03:59:49 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> Message-ID: <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 17:55:22 -0700, Carl Banks wrote: > Floating point arithmetic evolved more or less on languages like Fortran > where things like exceptions were unheard of, I'm afraid that you are completely mistaken. Fortran IV had support for floating point traps, which are "things like exceptions". That's as far back as 1966. I'd be shocked if earlier Fortrans didn't also have support for traps. http://www.bitsavers.org/pdf/ibm/7040/C28-6806-1_7040ftnMathSubrs.pdf The IEEE standard specifies that you should be able to control whether a calculation traps or returns a NAN. That's how Decimal does it, that's how Apple's (sadly long abandoned) SANE did it, and floats should do the same thing. Serious numeric languages like Fortran have supported traps long before exceptions were invented. > and defining NaN != NaN > was a bad trick they chose for testing against NaN for lack of a better > way. That's also completely wrong. The correct way to test for a NAN is with the IEEE-mandated function isnan(). The NAN != NAN trick is exactly that, a trick, used by programmers when their language or compiler doesn't support isnan(). Without support for isinf(), identifying an INF is just as hard as identifying an NAN, and yet their behaviour under equality is the complete opposite: >>> inf = float('inf') >>> inf == inf True > If exceptions had commonly existed in that environment there's no chance > they would have chosen that behavior; They did exist, and they did choose that behaviour. > comparison against NaN (or any > operation with NaN) would have signaled a floating point exception. > That is the correct way to handle exceptional conditions. > > The only reason to keep NaN's current behavior is to adhere to IEEE, And because the IEEE behaviour is far more useful than the misguided reliance on exceptions for things which are not exceptional. Before spreading any more misinformation about IEEE 754 and NANs, please learn something about it: http://grouper.ieee.org/groups/754/ http://www.cs.berkeley.edu/~wkahan/ieee754status/ieee754.ps I particularly draw your attention to the FAQ about NANs: http://grouper.ieee.org/groups/754/faq.html#exceptions [quote] The 754 model encourages robust programs. It is intended not only for numerical analysts but also for spreadsheet users, database systems, or even coffee pots. The propagation rules for NaNs and infinities allow inconsequential exceptions to vanish. Similarly, gradual underflow maintains error properties over a precision's range. When exceptional situations need attention, they can be examined immediately via traps or at a convenient time via status flags. Traps can be used to stop a program, but unrecoverable situations are extremely rare. Simply stopping a program is not an option for embedded systems or network agents. More often, traps log diagnostic information or substitute valid results. Flags offer both predictable control flow and speed. Their use requires the programmer be aware of exceptional conditions, but flag stickiness allows programmers to delay handling exceptional conditions until necessary. [end quote] -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 00:15:11 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 04:15:11 GMT Subject: float("nan") in set or as key References: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> Message-ID: <4de319cf$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 11:14:58 +1000, Chris Angelico wrote: > So, apart from float("nan"), are there actually any places where real > production code has to handle NaN? I was unable to get a nan by any of > the above methods, except for operations involving inf; for instance, > float("inf")-float("inf") == nan. All the others raised an exception > rather than return nan. That's Python's poor design, due to reliance on C floating point libraries that have half-hearted support for IEEE-754, and the obstruction of people who don't understand the usefulness of NANs. They shouldn't raise unless the caller specifies that he wants exceptions. The default behaviour should be the most useful one, namely quiet (propagating) NANs, rather than halting the calculation because of something which may or may not be an error and may or may not be recoverable. Even Apple's Hypertalk supported them better in the late 1980s than Python does now, and that was a language aimed at non-programmers! The Decimal module is a good example of what floats should do. All flags are supported, so you can choose whether you want exceptions or NANs. I don't like Decimal's default settings, but at least they can be changed. -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 00:22:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 04:22:25 GMT Subject: float("nan") in set or as key References: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> Message-ID: <4de31b81$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 12:53:59 +1000, Chris Angelico wrote: > Okay, here's a question. The Python 'float' value - is it meant to be "a > Python representation of an IEEE double-precision floating point value", Yes. > or "a Python representation of a real number"? No. Floats are not real numbers. Many fundamental properties of the reals are violated by floats, and I'm not talking about "weird" things like NANs and INFs, but ordinary numbers: >>> a, b = 0.1, 0.7 >>> a + b - b == a False > For the most part, > Python's data types are defined by their abstract concepts - a list > isn't defined as a linked list of pointers, Nor is it implemented as a linked list of pointers. > The sys.float_info struct exposes details of floating point > representation. In theory, a Python implementation that uses bignum > floats could quite happily set all those values to extremes and work > with enormous precision (or could use a REXX-style "numeric digits 100" > command to change the internal rounding, and automatically update > sys.float_info). And in that case, there would be no NaN value. NANs aren't for overflow, that's what INFs are for. Even if you had infinite precision floats and could get rid of INFs, you would still need NANs. > The real question is: Would NaN's removal be beneficial? No, it would be another step backwards to the bad old days before the IEEE standard. -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 00:23:44 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 04:23:44 GMT Subject: scope of function parameters References: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> <87pqn17z4a.fsf@benfinney.id.au> Message-ID: <4de31bd0$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 11:31:33 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> http://mail.python.org/pipermail/tutor/2010-December/080505.html >> >> >> Constructive criticism welcome. > > Informative, but it ?buries the lead? as our friends in the press corps > would say. Thank you, that's a good point. [...] > More on this style: > > Or as they say in the fiction-writing trade, "shoot the sheriff on the first page". -- Steven From nagle at animats.com Mon May 30 00:25:04 2011 From: nagle at animats.com (John Nagle) Date: Sun, 29 May 2011 21:25:04 -0700 Subject: float("nan") in set or as key In-Reply-To: <4de319cf$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de319cf$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de31c20$0$2134$742ec2ed@news.sonic.net> On 5/29/2011 9:15 PM, Steven D'Aprano wrote: > On Mon, 30 May 2011 11:14:58 +1000, Chris Angelico wrote: > >> So, apart from float("nan"), are there actually any places where real >> production code has to handle NaN? Yes. I used to write dynamic simulation engines. There were situations that produced floating point overflow, leading to NaN values. This wasn't an error; it just meant that the timestep had to be reduced to handle some heavy object near the moment of first collision. Note that the difference between two INF values is a NaN. It's important that ordered comparisons involving NaN and INF raise exceptions so that you don't lose an invalid value. If you're running with non-signaling NaNs, the idea is supposed to be that, at the end of the computation, you check all your results for INF and NaN values, to make sure you didn't overflow somewhere during the computation. If, within the computation, there are branches based on ordered comparisons, and those don't raise an exception when the comparison result is unordered, you can reach the end of the computation with valid-looking but wrong values. John Nagle From python at rcn.com Mon May 30 00:27:37 2011 From: python at rcn.com (Raymond Hettinger) Date: Sun, 29 May 2011 21:27:37 -0700 (PDT) Subject: Class decorators might also be super too References: <462eb546-0089-48fa-bf10-ac5a6b0b9ed4@glegroupsg2000goo.googlegroups.com> Message-ID: <9fa08a82-0ade-4a2a-bce1-62e0c0a3504e@s41g2000prb.googlegroups.com> On May 28, 11:33?pm, Michele Simionato wrote: > He is basically showing that using mixins for implementing logging is not such a good idea, i.e. you can get the same effect in a better way by making use of other Python features. I argued the same thing many times in the past. I even wrote a module once (strait) to reimplement 99% of multiple inheritance without multiple inheritance, just to show that in can be done in few lines of code in a language as powerful as Python. More importantly, anyone who reads posts such as David' will walk away with a deeper understanding of class decorators, mixins, and inheritance. That makes the post worthwhile even if someone never ends up using those particular coding technique. Raymond From nospam at torek.net Mon May 30 00:29:19 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 04:29:19 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4de31635$0$29990$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: >That's also completely wrong. The correct way to test for a NAN is with >the IEEE-mandated function isnan(). The NAN != NAN trick is exactly that, >a trick, used by programmers when their language or compiler doesn't >support isnan(). Perhaps it would be reasonable to be able to do: x.isnan() when x is a float. >Without support for isinf(), identifying an INF is just as hard as >identifying an NAN, and yet their behaviour under equality is the >complete opposite: > >>>> inf = float('inf') >>>> inf == inf >True Fortunately: def isnan(x): return x != x _inf = float("inf") def isinf(x): return x == _inf del _inf both do the trick here. I would like to have both modes (non-exception-ing and exception-ing) of IEEE-style float available in Python, and am not too picky about how they would be implemented or which one would be the default. Python could also paper over the brokenness of various actual implementations (where signalling vs quiet NaNs, and so on, do not quite work right in all cases), with some performance penalty on non-conformant hardware. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From python at rcn.com Mon May 30 00:49:14 2011 From: python at rcn.com (Raymond Hettinger) Date: Sun, 29 May 2011 21:49:14 -0700 (PDT) Subject: float("nan") in set or as key References: Message-ID: On May 28, 4:41?pm, MRAB wrote: > Here's a curiosity. float("nan") can occur multiple times in a set or as > a key in a dict: Which is by design. NaNs intentionally have multiple possible instances (some implementations even include distinct payload values). Sets and dicts intentionally recognize an instance as being equal to itself (identity-implies-equality); otherwise, you could put a NaN in a set/dict but not be able to retrieve it. Basic invariants would fail -- such as: assert all(elem in container for elem in container). The interesting thing is that people experimenting with exotic objects (things with random hash functions, things with unusual equality or ordering relations, etc) are "surprised" when those objects display their exotic behaviors. To me, the "NaN curiousities" are among the least interesting. It's more fun to break sort algorithms with sets (which override the ordering relations with subset/superset relations) or with an object that mutates a list during the sort. Now, that is curious :-) Also, Dr Mertz wrote a Charming Python article full of these curiosities: http://gnosis.cx/publish/programming/charming_python_b25.txt IMO, equality and ordering are somewhat fundamental concepts. If a class is written that twists those concepts around a bit, then it should be no surprise if curious behavior emerges. Heck, I would venture to guess that something as simple as assuming the speed of light is constant might yield twin paradoxes and other curiousities ;-) Raymond From python at rcn.com Mon May 30 00:52:25 2011 From: python at rcn.com (Raymond Hettinger) Date: Sun, 29 May 2011 21:52:25 -0700 (PDT) Subject: 3.1.4 release candidate 1 References: Message-ID: On May 29, 3:44?pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm happy as a swallow to announce a > release candidate for the fourth bugfix release for the Python 3.1 > series, Python > 3.1.4. The Pi release of Python :-) Raymond P.S. For the most part, if you have a choice, then you are much better off using Py3.2 than any release (even a bugfix release) of Py3.1 From xi at resolvent.net Mon May 30 01:09:21 2011 From: xi at resolvent.net (Kirill Simonov) Date: Mon, 30 May 2011 01:09:21 -0400 Subject: [ANN] PyYAML-3.10: YAML parser and emitter for Python Message-ID: <4DE32681.4050903@resolvent.net> ======================== Announcing PyYAML-3.10 ======================== A new bug fix release of PyYAML is now available: http://pyyaml.org/wiki/PyYAML Changes ======= * Do not try to build LibYAML bindings on platforms other than CPython (Thank to olt(at)bogosoft(dot)com). * Clear cyclic references in the parser and the emitter (Thank to kristjan(at)ccpgames(dot)com). * LibYAML bindings are rebuilt with the latest version of Cython. * Dropped support for Python 2.3 and 2.4; currently supported versions are 2.5 to 3.2. Resources ========= PyYAML homepage: http://pyyaml.org/wiki/PyYAML PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation TAR.GZ package: http://pyyaml.org/download/pyyaml/PyYAML-3.10.tar.gz ZIP package: http://pyyaml.org/download/pyyaml/PyYAML-3.10.zip Windows installers: http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.5.exe http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.6.exe http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py3.0.exe http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py3.1.exe http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py3.2.exe PyYAML SVN repository: http://svn.pyyaml.org/pyyaml Submit a bug report: http://pyyaml.org/newticket?component=pyyaml YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML ============ YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistance. Example ======= >>> import yaml >>> yaml.load(""" ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: http://pyyaml.org/wiki/PyYAML ... keywords: [YAML, serialization, configuration, persistance, pickle] ... """) {'keywords': ['YAML', 'serialization', 'configuration', 'persistance', 'pickle'], 'homepage': 'http://pyyaml.org/wiki/PyYAML', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} >>> print yaml.dump(_) name: PyYAML homepage: http://pyyaml.org/wiki/PyYAML description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistance, pickle] Copyright ========= The PyYAML module is written by Kirill Simonov . PyYAML is released under the MIT license. From nospam at torek.net Mon May 30 01:53:33 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 05:53:33 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article I wrote, in part: > _inf = float("inf") > def isinf(x): > return x == _inf > del _inf Oops, take out the del, or otherwise fix the obvious problem, e.g., perhaps: def isinf(x): return x == isinf._inf isinf._inf = float("inf") (Of course, if something like this were adopted properly, it would all be in the base "float" type anyway.) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From steve+comp.lang.python at pearwood.info Mon May 30 02:13:31 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 06:13:31 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de3358b$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 04:29:19 +0000, Chris Torek wrote: > In article <4de31635$0$29990$c3e8da3$5496439d at news.astraweb.com>, Steven > D'Aprano wrote: >>That's also completely wrong. The correct way to test for a NAN is with >>the IEEE-mandated function isnan(). The NAN != NAN trick is exactly >>that, a trick, used by programmers when their language or compiler >>doesn't support isnan(). > > Perhaps it would be reasonable to be able to do: > > x.isnan() > > when x is a float. Better than a float method is a function which takes any number as argument: >>> import math, fractions, decimal >>> math.isnan(fractions.Fraction(2, 3)) False >>> math.isnan(decimal.Decimal('nan')) True You can even handle complex NANs with the cmath module: >>> import cmath >>> cmath.isnan(complex(1, float('nan'))) True -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 02:14:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 06:14:53 GMT Subject: float("nan") in set or as key References: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de319cf$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de335dd$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 04:15:11 +0000, Steven D'Aprano wrote: > On Mon, 30 May 2011 11:14:58 +1000, Chris Angelico wrote: > >> So, apart from float("nan"), are there actually any places where real >> production code has to handle NaN? I was unable to get a nan by any of >> the above methods, except for operations involving inf; for instance, >> float("inf")-float("inf") == nan. All the others raised an exception >> rather than return nan. > > That's Python's poor design, due to reliance on C floating point > libraries that have half-hearted support for IEEE-754, and the > obstruction of people who don't understand the usefulness of NANs. That last comment mine is a bit harsh, and I'd like to withdraw it as unnecessarily confrontational. -- Steven From moky.math at gmail.com Mon May 30 03:12:50 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Mon, 30 May 2011 09:12:50 +0200 Subject: scope of function parameters In-Reply-To: <87tycd89qc.fsf@benfinney.id.au> References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> Message-ID: Le 29/05/2011 23:42, Ben Finney a ?crit : > Peter Pearson writes: > >> Python works in terms of objects having names, and one >> object can have many names. > > Or no names. So it's less accurate (though better than talking of > ?variables?) to speak of Python objects ?having names?. Could you give an example of an object that has no name ? I've missed something ... Laurent From clp2 at rebertia.com Mon May 30 03:27:17 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 May 2011 00:27:17 -0700 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> Message-ID: On Mon, May 30, 2011 at 12:12 AM, Laurent Claessens wrote: > Le 29/05/2011 23:42, Ben Finney a ?crit : >> Peter Pearson ?writes: >> >>> ?Python works in terms of objects having names, and one >>> ?object can have many names. >> >> Or no names. So it's less accurate (though better than talking of >> ?variables?) to speak of Python objects ?having names?. > > Could you give an example of an object that has no name ? I've missed > something ... def foo(): return 5 print(foo()) The int object 5 has no name here. Cheers, Chris From moky.math at gmail.com Mon May 30 03:38:05 2011 From: moky.math at gmail.com (Laurent) Date: Mon, 30 May 2011 09:38:05 +0200 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> Message-ID: <4DE3495D.9080309@gmail.com> >> Could you give an example of an object that has no name ? I've missed >> something ... > > def foo(): > return 5 > > print(foo()) > > The int object 5 has no name here. Cool. I was thinking that "5" was the name, but >>> 5.__add__(6) File "", line 1 5.__add__(6) ^ SyntaxError: invalid syntax while >>> a=5 >>> a.__add__(6) 11 Very well. I learned something today. Thanks Laurent From dan.kluev at gmail.com Mon May 30 04:10:22 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 30 May 2011 19:10:22 +1100 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> Message-ID: On Mon, May 30, 2011 at 6:12 PM, Laurent Claessens wrote: > Could you give an example of an object that has no name ? I've missed > something ... >>> object() -- With best regards, Daniel Kluev From alain at dpt-info.u-strasbg.fr Mon May 30 05:01:32 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 30 May 2011 11:01:32 +0200 Subject: 3.1.4 release candidate 1 References: Message-ID: <87mxi4sgsz.fsf@dpt-info.u-strasbg.fr> Raymond Hettinger writes: > On May 29, 3:44?pm, Benjamin Peterson wrote: >> On behalf of the Python development team, I'm happy as a swallow to announce a >> release candidate for the fourth bugfix release for the Python 3.1 >> series, Python >> 3.1.4. > > The Pi release of Python :-) And the same day we get the e release of Python... -- Alain. From tjreedy at udel.edu Mon May 30 05:02:36 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 05:02:36 -0400 Subject: scope of function parameters In-Reply-To: <4DE3495D.9080309@gmail.com> References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> Message-ID: On 5/30/2011 3:38 AM, Laurent wrote: > Cool. I was thinking that "5" was the name, but > >>> 5.__add__(6) > File "", line 1 > 5.__add__(6) Try 5 .__add__(6) Modules, classes, and functions have a .__name__ attribute (I call it their 'definition name') used to print a representation. As best I can remember, other builtin objects do not. -- Terry Jan Reedy From moky.math at gmail.com Mon May 30 05:08:23 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Mon, 30 May 2011 11:08:23 +0200 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> Message-ID: <4DE35E87.8060208@gmail.com> Le 30/05/2011 11:02, Terry Reedy a ?crit : > On 5/30/2011 3:38 AM, Laurent wrote: > >> Cool. I was thinking that "5" was the name, but >> >>> 5.__add__(6) >> File "", line 1 >> 5.__add__(6) > > > Try 5 .__add__(6) What is the rationale behind the fact to add a space between "5" and ".__add__" ? Why does it work ? Laurent From snoopy.67.z at googlemail.com Mon May 30 05:11:32 2011 From: snoopy.67.z at googlemail.com (Gabriel) Date: Mon, 30 May 2011 02:11:32 -0700 (PDT) Subject: Best way to compute length of arbitrary dimension vector? Message-ID: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> Well, the subject says it almost all: I'd like to write a small Vector class for arbitrary-dimensional vectors. I am wondering what would be the most efficient and/or most elegant way to compute the length of such a Vector? Right now, I've got def length(self): # x.length() = || x || total = 0.0 for k in range(len(self._coords)): d = self._coords[k] total += d*d return sqrt(total) However, that seems a bit awkward to me (at least in Python ;-) ). I know there is the reduce() function, but I can't seem to find a way to apply that to the case here (at least, not without jumping through too many hoops). I have also googled a bit, but found nothing really elegant. Any ideas? Best regards, Gabriel. From steve+comp.lang.python at pearwood.info Mon May 30 05:14:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 09:14:39 GMT Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: <4de35fff$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 11:08:23 +0200, Laurent Claessens wrote: > Le 30/05/2011 11:02, Terry Reedy a ?crit : >> On 5/30/2011 3:38 AM, Laurent wrote: >> >>> Cool. I was thinking that "5" was the name, but >>> >>> 5.__add__(6) >>> File "", line 1 >>> 5.__add__(6) >> >> >> Try 5 .__add__(6) > > What is the rationale behind the fact to add a space between "5" and > ".__add__" ? > Why does it work ? Because . is an operator just like + * & etc. >>> s = "hello world" >>> s . upper ( ) 'HELLO WORLD' In the case of integer literals, you need the space, otherwise Python will parse 5. as a float: >>> 5. 5.0 >>> 5.__add__ File "", line 1 5.__add__ ^ SyntaxError: invalid syntax >>> 5 .__add__ -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 05:16:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 09:16:27 GMT Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> Message-ID: <4de3606b$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 09:12:50 +0200, Laurent Claessens wrote: > Could you give an example of an object that has no name ? I've missed > something ... >>> mylist = [None, 42, "something"] The list object has a name, mylist. The three objects inside the list have no names. -- Steven From ben+python at benfinney.id.au Mon May 30 05:17:32 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 May 2011 19:17:32 +1000 Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: <87ei3g8s43.fsf@benfinney.id.au> Laurent Claessens writes: > Le 30/05/2011 11:02, Terry Reedy a ?crit : > > Try 5 .__add__(6) > > What is the rationale behind the fact to add a space between "5" and > ".__add__" ? > Why does it work ? Try asking it the other way around. Why doesn't ?5.__add__(6)?, without the space, work? -- \ ?Telling pious lies to trusting children is a form of abuse, | `\ plain and simple.? ?Daniel Dennett, 2010-01-12 | _o__) | Ben Finney From duncan.booth at invalid.invalid Mon May 30 05:18:26 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 May 2011 09:18:26 GMT Subject: Python's super() considered super! References: Message-ID: Ethan Furman wrote: >>>>> foo(x=1, y=2, z=3) >> Traceback (most recent call last): >> File "", line 1, in >> foo(x=1, y=2, z=3) >> File "", line 2, in foo >> bar(y=2, **kwargs) >> TypeError: bar() got multiple values for keyword argument 'y' > > And the above error is exactly why you don't want to use named arguments > in MI -- because you don't know in what order the methods will be > called, you cannot know which named arguments to supply to the method > that super() will call next. > No, it just means you have to be careful how you do it: if you want to pass 'y' to a super call then you must pop it out of the arguments. This can be done as easily with a named argument as with an explicit 'pop()' on kwargs. What using a named argument does it to change the default action from silently overwriting any argumement passing up the chain to raising an error if you attempt to overwrite it without first checking whether it exists. -- Duncan Booth http://kupuguy.blogspot.com From news1234 at free.fr Mon May 30 05:18:30 2011 From: news1234 at free.fr (News123) Date: Mon, 30 May 2011 11:18:30 +0200 Subject: portable way of sending notifying a process In-Reply-To: References: <4de183e7$0$26108$426a74cc@news.free.fr> Message-ID: <4de360e6$0$4325$426a74cc@news.free.fr> Thanks for all your feedback. Well, I'll play a little and go either for a wrapper around ways to detecth a file change or for a tiny socket solution. Thanks again. On 05/30/2011 04:03 AM, Chris Angelico wrote: > On Mon, May 30, 2011 at 11:44 AM, Chris Torek wrote: >>> What would be a light weight portable way, that one process can tell >>> another to do something? >>> >>> The main requirement would be to have no CPU impact while waiting (thus >>> no polling) >> >> Your best bet here is probably to use sockets. Both systems have >> ways to create service sockets and to connect to a socket as a >> client. > > Further to this: If your two processes are going to start up, then run > concurrently for some time, and during that time alert each other (or > one alerts the other) frequently, a socket is an excellent choice. Use > a TCP socket on Windows, and either a TCP socket or a Unix socket on > Linux (I'd just use TCP on both for simplicity, but Unix sockets are > faster), and simply write a byte to it whenever you want to alert the > other side. You can largely guarantee that no other process can > accidentally or maliciously wake you, as long as you have some kind of > one-off handshake on connection - even something really simple like > sending a random nonce, having the other end send hash(nonce + > password), and compare. > > Chris Angelico > Huge fan of TCP sockets (hello MUDs!) From clp2 at rebertia.com Mon May 30 05:24:17 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 May 2011 02:24:17 -0700 Subject: Best way to compute length of arbitrary dimension vector? In-Reply-To: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> References: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> Message-ID: On Mon, May 30, 2011 at 2:11 AM, Gabriel wrote: > Well, the subject says it almost all: I'd like to write a small Vector > class for arbitrary-dimensional vectors. > > I am wondering what would be the most efficient and/or most elegant > way to compute the length of such a Vector? > > Right now, I've got > > ?def length(self): ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # x.length() = || x || > ? ?total = 0.0 > ? ?for k in range(len(self._coords)): > ? ? ?d = self._coords[k] > ? ? ?total += d*d > ? ?return sqrt(total) > > However, that seems a bit awkward to me (at least in Python ;-) ). > > I know there is the reduce() function, but I can't seem to find a way > to apply that to the case here (at least, not without jumping through > too many hoops). > > I have also googled a bit, but found nothing really elegant. > > Any ideas? def length(self): return sqrt(sum(coord*coord for coord in self._coords)) Cheers, Chris -- http://rebertia.com From __peter__ at web.de Mon May 30 05:41:17 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 May 2011 11:41:17 +0200 Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: Laurent Claessens wrote: > Le 30/05/2011 11:02, Terry Reedy a ?crit : >> On 5/30/2011 3:38 AM, Laurent wrote: >> >>> Cool. I was thinking that "5" was the name, but >>> >>> 5.__add__(6) >>> File "", line 1 >>> 5.__add__(6) >> >> >> Try 5 .__add__(6) > > What is the rationale behind the fact to add a space between "5" and > ".__add__" ? > Why does it work ? It's a hint for the tokenizer. $ cat show_tokens.py import sys from tokenize import generate_tokens from cStringIO import StringIO from token import tok_name _name_width = max(len(name) for name in tok_name.itervalues()) def show_tokens(s): for token in generate_tokens(StringIO(s).readline): name = tok_name[token[0]] value = token[1] print "%-*s %r" % (_name_width, name, value) if __name__ == "__main__": show_tokens(" ".join(sys.argv[1:])) $ python show_tokens.py 5.__add__ NUMBER '5.' NAME '__add__' ENDMARKER '' $ python show_tokens.py 5 .__add__ NUMBER '5' OP '.' NAME '__add__' ENDMARKER '' From __peter__ at web.de Mon May 30 05:46:01 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 May 2011 11:46:01 +0200 Subject: Best way to compute length of arbitrary dimension vector? References: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> Message-ID: Gabriel wrote: > Well, the subject says it almost all: I'd like to write a small Vector > class for arbitrary-dimensional vectors. > > I am wondering what would be the most efficient and/or most elegant > way to compute the length of such a Vector? > > Right now, I've got > > def length(self): # x.length() = || x || > total = 0.0 > for k in range(len(self._coords)): > d = self._coords[k] > total += d*d > return sqrt(total) > > However, that seems a bit awkward to me (at least in Python ;-) ). > > I know there is the reduce() function, but I can't seem to find a way > to apply that to the case here (at least, not without jumping through > too many hoops). > > I have also googled a bit, but found nothing really elegant. >>> class Vector(object): ... def __init__(self, *coords): ... self._coords = coords ... def __abs__(self): ... return math.sqrt(sum(x*x for x in self._coords)) ... >>> import math >>> abs(Vector(1,1)) 1.4142135623730951 >>> abs(Vector(3,4)) 5.0 From moky.math at gmail.com Mon May 30 06:10:11 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Mon, 30 May 2011 12:10:11 +0200 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: <4DE36D03.8050201@gmail.com> >> What is the rationale behind the fact to add a space between "5" and >> ".__add__" ? >> Why does it work ? > > It's a hint for the tokenizer. I didn't know the tokenizer. Now I understand. Thanks Laurent From moky.math at gmail.com Mon May 30 06:10:26 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Mon, 30 May 2011 12:10:26 +0200 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: >> What is the rationale behind the fact to add a space between "5" and >> ".__add__" ? >> Why does it work ? > > It's a hint for the tokenizer. I didn't know the tokenizer. Now I understand. Thanks Laurent From secretelf77 at gmail.com Mon May 30 06:15:49 2011 From: secretelf77 at gmail.com (John Thornton) Date: Mon, 30 May 2011 20:15:49 +1000 Subject: python in school notebooks/laptops Message-ID: Hello Is it a waste of time to try to get school admins to put python in their school laptops? OK. Here's the crib for the rest[!] of the world. Here in Australia most secondary schools [that is kids from age approx 12-18] have some sort of netbook/laptop program. I have looked at a few schools and they put visual basic in but not python. [unless of course it's a mac where python may already be in it] . This is a curious omission when Blender needs python to run. So, I emailed a school admin and told him about python, gimp, inkscape and blender. Have I wasted my time? -------------- next part -------------- An HTML attachment was scrubbed... URL: From piotr.kaminski at poczta.onet.eu Mon May 30 06:37:43 2011 From: piotr.kaminski at poczta.onet.eu (=?utf-8?B?UGlvdHIgS2FtacWEc2tp?=) Date: Mon, 30 May 2011 12:37:43 +0200 Subject: Abandoning Python In-Reply-To: References: <4DD9952F.4080100@etrix.com.au> Message-ID: I'm sorry, I wanted to send the message below to the list and instead I sent it to just one user. Piotr Dnia 23-05-2011 o 10:29:24 Piotr Kami?ski napisa?(a): > Dnia 23-05-2011 o 00:58:55 Brendan Simon (eTRIX) napisa?(a): > > ... >> Take a look at Cobra. >> >> http://cobra-language.com/docs/python/ >> >> http://cobra-language.com/ >> >> It is similar to Python, but with a quite a few nice extras and few improved things (eg. no "self", no ":", ...) >> >> Possible negatives are: >> * Requires either .NET or Mono frameworks. >> * lack of 3rd party libraries ?? >> >> >> Cheers, Brendan. >> > > > One more piece of information and a link: "...It supports both static and dynamic typing..." http://en.wikipedia.org/wiki/Cobra_(programming_language_from_Cobra_Language_LLC) > > HTH, > > Piotr From jpiitula at ling.helsinki.fi Mon May 30 06:40:19 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 30 May 2011 13:40:19 +0300 Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: Laurent Claessens writes: > Le 30/05/2011 11:02, Terry Reedy a ?crit : > > On 5/30/2011 3:38 AM, Laurent wrote: > > > >> Cool. I was thinking that "5" was the name, but > >> >>> 5.__add__(6) > >> File "", line 1 > >> 5.__add__(6) > > > > > > Try 5 .__add__(6) > > What is the rationale behind the fact to add a space between "5" and > ".__add__" ? > Why does it work ? Oh joy. >>> [5][0].__add__([6][-1]) 11 The parser just needs the help to detect the intended token boundary instead of another, unintened one. As the others already say. From hackingkk at gmail.com Mon May 30 07:09:01 2011 From: hackingkk at gmail.com (hackingKK) Date: Mon, 30 May 2011 16:39:01 +0530 Subject: python in school notebooks/laptops In-Reply-To: References: Message-ID: <4DE37ACD.9040300@gmail.com> On 30/05/11 15:45, John Thornton wrote: > Hello > Is it a waste of time to try to get school admins to put > python in their school laptops? > > OK. Here's the crib for the rest[!] of the world. Here in > Australia most secondary schools [that is kids from age approx 12-18] > have some sort of netbook/laptop program. I have looked at a few > schools and they put visual basic in but not python. [unless of > course it's a mac where python may already be in it] . This is a > curious omission when Blender needs python to run. Even better, try convincing them to use Ubuntu instead of a virus called Where I Never Do Operations With Safety, or WINDOWS for short. That way Python will come by default and VB will be out of question Happy hacking. Krishnakant. From secretelf77 at gmail.com Mon May 30 07:16:11 2011 From: secretelf77 at gmail.com (John Thornton) Date: Mon, 30 May 2011 21:16:11 +1000 Subject: python in school notebooks/laptops In-Reply-To: <4DE37ACD.9040300@gmail.com> References: <4DE37ACD.9040300@gmail.com> Message-ID: I agree fully. Linux is better and safer. But they seem hellbent on getting their students to use Windows. For laughs the kids in year 7 start off with this on their school netbook: Individual software packages MS Office Professional 2010 $80.30 (Word, Excel, PowerPoint, Access, Outlook, Publisher, OneNote) (EULA needs to be signed) DyKnow $47.00 Microworlds EX Robotics (PC/Mac) $27.50 Inspiration V8 (PC/Mac) $50.60 Graphmatica $4.40 Sophos Anti-virus $30.00 Network Cable $6.00 Labels for laptop and bag $1.00 Additional Software Home Studio (Yr 7 and 8 Music) $50.00 Upgrade from Vista Business to Windows 7 Professional $103.40 Software packages also installed (either free of charge or cost covered by School) are ArtRage, Acrobat Reader, Cite Ace, Mavis Beacon Typing, Scratch, Wordweb, Kahootz, Comic Life, Ni Hao, French Gamemaker, NewsMaker, Yenka Science, Autodesk Inventor. ******* Gimp? Python? Linux? Inkscape? Blender? That software may as well be on the moon. [sobs into beer...oh well, at least they get to buy anti-virus gear...:)] John On Mon, May 30, 2011 at 9:09 PM, hackingKK wrote: > > On 30/05/11 15:45, John Thornton wrote: > >> Hello >> Is it a waste of time to try to get school admins to put python in >> their school laptops? >> >> OK. Here's the crib for the rest[!] of the world. Here in Australia >> most secondary schools [that is kids from age approx 12-18] have some sort >> of netbook/laptop program. I have looked at a few schools and they put >> visual basic in but not python. [unless of course it's a mac where python >> may already be in it] . This is a curious omission when Blender needs python >> to run. >> > > Even better, try convincing them to use Ubuntu instead of a virus called > Where I Never Do Operations With Safety, or WINDOWS for short. > That way Python will come by default and VB will be out of question > Happy hacking. > Krishnakant. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phd at phdru.name Mon May 30 07:19:45 2011 From: phd at phdru.name (Oleg Broytman) Date: Mon, 30 May 2011 15:19:45 +0400 Subject: SQLObject 1.0.1 Message-ID: <20110530111945.GC12650@iskra.aviel.ru> Hello! I'm pleased to announce version 1.0.1, a bugfix release of branch 1.0 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/1.0.1 News and changes: http://sqlobject.org/News.html What's New ========== * A syntax incompatibility was fixed in SQLiteConnection that prevented SQLObject to be used with Python 2.4. For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From invalid at peter.pmoylan.org.invalid Mon May 30 08:58:02 2011 From: invalid at peter.pmoylan.org.invalid (Peter Moylan) Date: Mon, 30 May 2011 22:58:02 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: rantingrick wrote: > On May 18, 7:19 am, Peter Moylan > wrote: > >> It's interesting to note that the definitions of 'recursive' to be found >> in Wikipedia and Wiktionary have very little in common with the >> definitions to be found in the dictionaries covered by Onelook. No >> wonder experts in different areas have trouble communicating with one >> another. > > Yes, and when you extrapolate that conclusion into the current hodge > podge of natural languages you begin to understand the genesis of > human beings selfish nature. I do? -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. From vinograd19 at gmail.com Mon May 30 08:58:31 2011 From: vinograd19 at gmail.com (vino19) Date: Mon, 30 May 2011 05:58:31 -0700 (PDT) Subject: searching in list Message-ID: I want to make a function that is called only once per one argument. I mean I want to store data of function calling to prevent calling it again if there is no need. How to make it? For example I can make a global list that just consist of tuples [(arg1, res1), (arg2, res2), ...]. Ok, how to search if an arg135 in that list? Thanks for answering From invalid at peter.pmoylan.org.invalid Mon May 30 09:02:35 2011 From: invalid at peter.pmoylan.org.invalid (Peter Moylan) Date: Mon, 30 May 2011 23:02:35 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <15e794b2-df2e-4dae-8f49-ae7dfe1f21d7@x1g2000yqb.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> <15e794b2-df2e-4dae-8f49-ae7dfe1f21d7@x1g2000yqb.googlegroups.com> Message-ID: rantingrick wrote: > On May 18, 12:59 pm, s... at sig.for.address (Victor Eijkhout) wrote: >> Harrison Hill wrote: >>> No need - I have the Dictionary definition of recursion here: >>> Recursion: (N). See recursion. >> If you tell a joke, you have to tell it right. > > Jeez, speaking of bad colloquialisms... > > """if you're going to "share" a joke you should at least "recite" it > CORRECTLY.""" He was her man But he was doing her incorrectly. I'm not convinced that this new meaning of "share" has contributed anything of value to the language. Which is possibly why people stopped using it in about the 1980s. -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. From davea at ieee.org Mon May 30 09:27:33 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 30 May 2011 09:27:33 -0400 Subject: searching in list In-Reply-To: References: Message-ID: <4DE39B45.3090903@ieee.org> On 01/-10/-28163 02:59 PM, vino19 wrote: > I want to make a function that is called only once per one argument. I mean I want to store data of function calling to prevent calling it again if there is no need. > How to make it? For example I can make a global list that just consist of tuples > [(arg1, res1), (arg2, res2), ...]. Ok, how to search if an arg135 in that list? > > Thanks for answering > Usual answer is to use a dict. You can convert a list of tuples to a dict by dict(mylist) Second choice is to keep the list sorted, and use the bisect module. But usually a dictionary is better. DaveA From rosuav at gmail.com Mon May 30 09:28:19 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 23:28:19 +1000 Subject: python in school notebooks/laptops In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 8:15 PM, John Thornton wrote: > Hello > ??????? Is it a waste of time to try to get school admins to put python in > their school laptops? Two halves to this question. 1) Would it be of value if the school admins were to put Python on the school laptops? 2) If you ask them to, would they? The answer to #1 is "Undoubtedly". Cost? A tiny bit of disk space. Benefit? Even if only one student in a thousand picked it up and learned it, that's a huge number of people who've been exposed to a better language than VB. But the answer to #2, based on my cynical view of these things, is "Unlikely". You could ask the school admins, but they'll point to some policy from upstairs that says what they need to provide. And I don't know who formulates that policy, but more than likely it's a committee. Who pays for all that software? I'm guessing it's part of one of those perversities where something is valued more if it costs more ("We spend $X million teaching our students modern computing"). Replacing the netbook packageset with Ubuntu and a whole swathe of free software (the significant part here being free-as-in-beer, but it would be free-as-in-speech software too) would cut $400 per student off their boast according to the figures you posted - but that doesn't seem to include the OS itself, so possibly even more. The other part of the problem is a huge lock-in involving grade schools, tertiary education, and company employment agencies, all of whom think that "computer skill" means "knows how to change cell color in Excel". And that is not an exaggeration - my brother says that when he was applying for jobs that required computing skills, the recruitment agency wanted to know his ability level with Word 2003 and Excel 2003. Getting past that is not going to be easy. But if you can just get a smidge of extra software put on the laptops (some nice easy tiny stuff - Python, 7-Zip, InfraRecorder - skip OO because it's too heavy), nobody would notice the extra disk space usage (even a cheap netbook will have storage measured in hundreds of gig), and it gives them a chance to learn something decent. Bored student browsing the Start menu... might not happen very often, but if even one person learns Python, that'd be worth it! Possibly the best way to encourage Python deployment would be to require it to run some internal script. Then the interpreter will be put on the laptops ("it's so tiny, won't cost anything to put it there"), and IDLE will be available for anyone who wants it. Now the question is, how can you get into a position where you can have a script that's needed for every student... Chris Angelico From snoopy.67.z at googlemail.com Mon May 30 09:38:53 2011 From: snoopy.67.z at googlemail.com (Gabriel) Date: Mon, 30 May 2011 06:38:53 -0700 (PDT) Subject: Best way to compute length of arbitrary dimension vector? References: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> Message-ID: Thanks a lot to both of you, Chris & Peter! (I knew the solution would be simple ... ;-) ) From rosuav at gmail.com Mon May 30 09:41:00 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 23:41:00 +1000 Subject: searching in list In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 10:58 PM, vino19 wrote: > I want to make a function that is called only once per one argument. I mean I want to store data of function calling to prevent calling it again if there is no need. > How to make it? For example I can make a global list that just consist of tuples > [(arg1, res1), (arg2, res2), ...]. Ok, how to search if an arg135 in that list? > > Thanks for answering If you're always going to look them up by the argument, the best way would be to use a dictionary: cache={arg1: res1, arg2: res2, ...} Then you can search with a simple: cache[arg135] You can add things with: cache[arg135]=res135 This works best if the argument is an immutable and fairly simple type. For instance, you could calculate Fibonacci numbers in a naive and straightforward way: def fib(n,cache={}): if n in cache: return cache[n] ret=n if n<2 else fib(n-1)+fib(n-2) # This bit actually calculates fib(n) cache[n]=ret return ret Of course, this is a poor algorithm for calculating Fibonacci numbers, but it does demonstrate the cache. It's recursive, meaning that if it has fib(50) in its cache and it is asked for fib(60), it will find and make use of the cached element. (Note the sneaky way of storing a cache dictionary. A function's default arguments are evaluated once, so this will use the same dictionary for every call.) Chris Angelico From vinograd19 at gmail.com Mon May 30 09:50:00 2011 From: vinograd19 at gmail.com (vino19) Date: Mon, 30 May 2011 06:50:00 -0700 (PDT) Subject: searching in list In-Reply-To: Message-ID: <81cbfee3-a0a6-4aa0-97e7-1073332ab6cf@glegroupsg2000goo.googlegroups.com> Thanks. It seems that dictionary is a sorted list of tuples, so the procedure of searching an element is quite quick. From vinograd19 at gmail.com Mon May 30 09:50:00 2011 From: vinograd19 at gmail.com (vino19) Date: Mon, 30 May 2011 06:50:00 -0700 (PDT) Subject: searching in list In-Reply-To: Message-ID: <81cbfee3-a0a6-4aa0-97e7-1073332ab6cf@glegroupsg2000goo.googlegroups.com> Thanks. It seems that dictionary is a sorted list of tuples, so the procedure of searching an element is quite quick. From wxjmfauth at gmail.com Mon May 30 10:30:00 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 30 May 2011 07:30:00 -0700 (PDT) Subject: python in school notebooks/laptops References: Message-ID: <2edff4f4-64db-4f39-b822-6f8d2c41eddd@h12g2000pro.googlegroups.com> On 30 mai, 13:09, hackingKK wrote: [...] > > Even better, try convincing them to use Ubuntu instead of ?a virus > called Where I Never Do Operations With Safety, or WINDOWS for short. > That way Python will come by default ?and VB will be out of question > Happy hacking. > Krishnakant. Do you mean one of these os's, where Python (2) is not working properly because the *defaultencoding* is set to utf-8? jmf From rosuav at gmail.com Mon May 30 10:48:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 00:48:49 +1000 Subject: searching in list In-Reply-To: <81cbfee3-a0a6-4aa0-97e7-1073332ab6cf@glegroupsg2000goo.googlegroups.com> References: <81cbfee3-a0a6-4aa0-97e7-1073332ab6cf@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 30, 2011 at 11:50 PM, vino19 wrote: > Thanks. > > It seems that dictionary is a sorted list of tuples, so the procedure of searching an element is quite quick. Not sorted - it's hashed, so it's even faster. Yep, sounds like a dictionary is everything you want! Chris Angelico From nobody at nowhere.net.no Mon May 30 11:29:07 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 30 May 2011 23:29:07 +0800 Subject: How to catch a line with Popen References: Message-ID: Chris Torek wrote: > In at least some versions of Python 2 I'm with P3k :P. However thank you for your guidelines. Last my attempt was to use a *for* p.wait() , as mentioned earlier That looks good enough. I noted some little delay for the first lines, mostly sure Popen assign some buffer even it is not set. Haven't you try a perpetual ping, how would be the line_at_a_time ? -- goto /dev/null From ian.g.kelly at gmail.com Mon May 30 12:32:27 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 May 2011 10:32:27 -0600 Subject: searching in list In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 7:41 AM, Chris Angelico wrote: > If you're always going to look them up by the argument, the best way > would be to use a dictionary: > cache={arg1: res1, arg2: res2, ...} > > Then you can search with a simple: cache[arg135] > > You can add things with: cache[arg135]=res135 > > This works best if the argument is an immutable and fairly simple > type. For instance, you could calculate Fibonacci numbers in a naive > and straightforward way: > > def fib(n,cache={}): > ?if n in cache: return cache[n] > ?ret=n if n<2 else fib(n-1)+fib(n-2) # This bit actually calculates fib(n) > ?cache[n]=ret > ?return ret > > Of course, this is a poor algorithm for calculating Fibonacci numbers, > but it does demonstrate the cache. It's recursive, meaning that if it > has fib(50) in its cache and it is asked for fib(60), it will find and > make use of the cached element. > > (Note the sneaky way of storing a cache dictionary. A function's > default arguments are evaluated once, so this will use the same > dictionary for every call.) If you're using Python 3.2, the functools.lru_cache decorator will do the caching for you, and without modifying the function arguments. By default it stores only the 100 most recent results, but you can make the storage unbounded by passing in the argument maxsize=None. Then the Fibonacci example becomes: @functools.lru_cache(maxsize=None) def fib(n): if n < 2: return n return fib(n-2) + fib(n-1) From tjreedy at udel.edu Mon May 30 12:49:26 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 12:49:26 -0400 Subject: scope of function parameters In-Reply-To: <4DE35E87.8060208@gmail.com> References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: On 5/30/2011 5:08 AM, Laurent Claessens wrote: > Le 30/05/2011 11:02, Terry Reedy a ?crit : >> On 5/30/2011 3:38 AM, Laurent wrote: >> >>> Cool. I was thinking that "5" was the name, but >>> >>> 5.__add__(6) >>> File "", line 1 >>> 5.__add__(6) >> >> >> Try 5 .__add__(6) > > What is the rationale behind the fact to add a space between "5" and > ".__add__" ? > Why does it work ? Others have given you specific answers, here is the bigger picture. For decades, text interpreter/compilers have generally run in two phases: 1. a lexer/tokenizer that breaks the stream of characters into tokens; 2. a parser that recognizes higher-level syntax and takes appropriate action. Lexers are typically based on regular grammars and implemented as very simple and fast deterministic finite-state automata. In outline (leaving out error handling and end-of-stream handling), something like: def lexer(stream, lookup, initial_state): state = initial_state buffer = [] for char in stream: state,out = lookup[state,char] if out: yield output(buffer) # convert list of chars to token expected by parser, clear buffer buffer += char There is no backup and no lookahead (except for the fact that output excludes the current char). For python, lookup[start,'5'] == in_number,False, and lookup[in_number,'.'] == in_float,False. >>> 5..__add__(6) 11.0 works because lookup[in_float,'.'] == start,True, because buffer now contains a completed float ready to output and '.' signals the start of a new token. I believe we read natural language text similarly, breaking it into words and punctuation. I believe the ability to read programs depends on being able to adjust the internal lexer a bit. Python is easier to read than some other algorithm languages because it tends to have at most one punctuation-like symbol unit between words, as is the case in the code above. -- Terry Jan Reedy From python at bdurham.com Mon May 30 13:57:06 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 30 May 2011 13:57:06 -0400 Subject: 3rd party tree/outline data structure module? Message-ID: <1306778226.14588.1457628701@webmail.messagingengine.com> Before I reinvent the wheel, I'm wondering if anyone can recommend a 3rd party tree data structure module? (I do not need a GUI component) I've looked at ElementTree but I think(?) need something more flexible. I have a parser that reads a proprietary file format which defines an outline-like structure. (The file format is based on a legacy product). I need to create a tree data structure that supports the ability to dynamically, add, delete, and move nodes/branches. I would like the nodes to be based on my own node class. I also need to to walk the tree structure in various ways including given a node, find its previous and next nodes including moving up and down branches to find the next logical node and the ability to quickly find an element by its unique id. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From pythoniks at gmail.com Mon May 30 14:27:06 2011 From: pythoniks at gmail.com (Pascal Chambon) Date: Mon, 30 May 2011 20:27:06 +0200 Subject: GIL in alternative implementations In-Reply-To: <6C7ABA8B4E309440B857D74348836F2E15BFF919@TK5EX14MBXC292.redmond.corp.microsoft.com> References: <4DE015EA.4040600@gmail.com> <6C7ABA8B4E309440B857D74348836F2E15BFF919@TK5EX14MBXC292.redmond.corp.microsoft.com> Message-ID: <4DE3E17A.3080706@gmail.com> Thanks for the details on IronPython's implementation B-) Hopefully Pypy will eventually get rid of its own Gil, since it doesn't do refcounting either. Regards, Pascal Le 28/05/2011 00:52, Dino Viehland a ?crit : > > In IronPython we have fine grained locking on our mutable data > structures. In particular we have a custom dictionary type which is > designed to allow lock-free readers on common operations while writers > take a lock. Our list implementation is similar but in some ways > that's trickier to pull off due to features like slicing so if I > recall correctly we only have lock-free reads when accessing a single > element. > > For .NET data structures they follow the .NET convention which is up > to the data structure. So if you wanted to get every last bit of > performance out of your app you could handle thread safety yourself > and switch to using the .NET dictionary or list types (although > they're a lot less friendly to Python developers). > > Because of these locks on micro-benchmarks that involve simple > list/dict manipulations you do see noticeably worse performance in > IronPython vs. CPython. > http://ironpython.codeplex.com/wikipage?title=IP27A1VsCPy27Perf&referringTitle=IronPython%20Performance > > - See the SimpleListManipulation and SimpleDictManipulation as the > core examples here. Also CPython's dictionary is so heavily tuned > it's hard to beat anyway, but this is a big factor. > > Finally one of the big differences with both Jython and IronPython is > that we have good garbage collectors which don't rely upon reference > counting. So one area where CPython gains from having a GIL is a > non-issue for us as we don't need to protect ref counts or use > interlocked operations for ref counting. > > *From:* python-list-bounces+dinov=exchange.microsoft.com at python.org > [mailto:python-list-bounces+dinov=exchange.microsoft.com at python.org] > *On Behalf Of *Pascal Chambon > *Sent:* Friday, May 27, 2011 2:22 PM > *To:* python-list at python.org >> Python List > *Subject:* GIL in alternative implementations > > Hello everyone, > > I've already read quite a bit about the reasons for the GIL in > CPython, i.e to summarize, that a more-fine graine locking, allowing > real concurrency in multithreaded applications, would bring too much > overhead for single-threaded python applications. > > However, I've also heard that other python implementations > (ironpython, jython...) have no GIL, and yet nobody blames them for > performance penalties that would be caused by that lack (I especially > think about IronPython, whose performances compare quite well to CPython). > > So I'd like to know: how do these other implementations handle > concurrency matters for their primitive types, and prevent them from > getting corrupted in multithreaded programs (if they do) ? I'm not > only thinking about python types, but also primitive containers and > types used in .Net and Java VMs, which aren't atomic elements either > at an assembly-level point of view. > > Do these VMs have some GIL-like limitations, that aren't spoken about > ? Are there functionings completely different from the CPython VM, so > that the question is not relevant ? Do people consider that they > always concern multithreaded applications, and so accept performance > penalties that they wouldn't allow in their CPython scripts ? > > I think you in advance for your lights on these questions. > > Regards, > > Pkl > > [[ Important Note: this is a serious question, trolls and emotionally > disturbed persons had better go on their way. ]] > -------------- next part -------------- An HTML attachment was scrubbed... URL: From doug.hellinger at hotmail.com Mon May 30 14:48:55 2011 From: doug.hellinger at hotmail.com (dough) Date: Mon, 30 May 2011 11:48:55 -0700 (PDT) Subject: How to Use Setuptools, Alternatives? References: <01045077-543f-4b8d-a5a2-4cde190c3294@v8g2000yqb.googlegroups.com> Message-ID: <3e848108-9b22-4ad8-83ed-e563f8346486@28g2000yqu.googlegroups.com> On May 29, 10:41?pm, ray wrote: > I have Python 2.7 on Win7 Pro on a tightly locked down desktop. ?I > would like to install Networkx from an egg. ?From what I have read, > Setuptools can be used for this. > > I don't know how to install Setuptools. ?The exe will not work. ?On > execution, it reports that the Python version is not included in the > registry. ?Further, I can not input the version and location on the > subsequent installation screen, the fields will not accept focus so I > can not input the values. > > Since the exe will not install, I considered using the Setuptools > egg. ?But it requires Setuptools. ?It appears to be a circle. > You're right. Since Setuptools is distributed as an egg, and Python doesn't natively support eggs, there can be a "chicken-and-egg" situation. > What are some suggestions for installing this? > > Thanks, > ray You can try downloading ezsetup.py and running it as a python script (i.e. python ezsetup.py). It will locate and download the latest version of Setuptools for your platform and install it. If HTTP access is blocked, just place the desired egg in the same folder as ezsetup.py and run the script again. Assuming you can get Setuptools installed correctly, it puts a program called easy_install.exe in your \Scripts folder. You can then just run (from the command line): easy_install It will hunt, download and install the latest version of the package for your platform. You may want to add the path to the Scripts folder to your PATH environment variable so you can just run easy_install from any current working directory. Hope that helps, Doug From gagsl-py2 at yahoo.com.ar Mon May 30 15:01:08 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 30 May 2011 16:01:08 -0300 Subject: Best way to compute length of arbitrary dimension vector? References: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> Message-ID: En Mon, 30 May 2011 06:46:01 -0300, Peter Otten <__peter__ at web.de> escribi?: > Gabriel wrote: > >> Well, the subject says it almost all: I'd like to write a small Vector >> class for arbitrary-dimensional vectors. >> > >>>> class Vector(object): > ... def __init__(self, *coords): > ... self._coords = coords > ... def __abs__(self): > ... return math.sqrt(sum(x*x for x in self._coords)) > ... >>>> import math >>>> abs(Vector(1,1)) > 1.4142135623730951 >>>> abs(Vector(3,4)) > 5.0 Using math.fsum instead of sum may improve accuracy, specially when len(coords)?2 py> import math py> py> def f1(*args): ... return math.sqrt(sum(x*x for x in args)) ... py> def f2(*args): ... return math.sqrt(math.fsum(x*x for x in args)) ... py> pi=math.pi py> args=[pi]*16 py> abs(f1(*args)/4 - pi) 4.4408920985006262e-16 py> abs(f2(*args)/4 - pi) 0.0 -- Gabriel Genellina From nospam at torek.net Mon May 30 15:58:35 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 19:58:35 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> <4de3358b$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4de3358b$0$29990$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: >Better than a float method is a function which takes any number as >argument: > >>>> import math, fractions, decimal >>>> math.isnan(fractions.Fraction(2, 3)) >False >>>> math.isnan(decimal.Decimal('nan')) >True Ah, apparently someone's been using Larry Wall's time machine. :-) I should have looked at documentation. In my case, though: $ python Python 2.5.1 (r251:54863, Dec 16 2010, 14:12:43) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> math.isnan Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'isnan' >You can even handle complex NANs with the cmath module: > >>>> import cmath >>>> cmath.isnan(complex(1, float('nan'))) >True Would it be appropriate to have isnan() methods for Fraction, Decimal, and complex, so that you do not need to worry about whether to use math.isnan() vs cmath.isnan()? (I almost never work with complex numbers so am not sure if the "or" behavior -- cmath.isinf and cmath.isnan return true if either real or complex part are Infinity or NaN respectively -- is appropriate in algorithms that might be working on any of these types of numbers.) It might also be appropriate to have trivial always-False isinf and isnan methods for integers. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From skunkworks at rikishi42.net Mon May 30 17:04:41 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Mon, 30 May 2011 23:04:41 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9cddb8-viv.ln1@murmur.very.softly> On 2011-05-28, Chris Angelico wrote: > I think it's geographic. This list covers a lot of geography; I'm in > Australia, there are quite a few Brits, and probably the bulk of posts > come from either the US or Europe. (And yes, I did deliberately fold > all of Europe down to one entity, and I did also deliberately leave > Great Britain out of that entity.) I allways found that odd. Especially if you're talking geography, not politics. I can understand they want to be seen as independant, even they are in it enough to allways opose anything someone else suggests. :-) To me, saying the UK isn't part of Europe, is like saying Japan isn't part of Asia. Oh by the way, I'm Belgian. > Most things work out that way. A thing gets a name based either on its > implementation or on the brand name of the first/most popular one. If > the only microwave oven ever produced had been made by Foobar Corp, > and that company were not known for anything else, then quite possibly > everyone would call them "foobar ovens". Yeah, when I was a kid a photo camera was called a Kodak. -- When in doubt, use brute force. -- Ken Thompson From skunkworks at rikishi42.net Mon May 30 17:10:14 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Mon, 30 May 2011 23:10:14 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-28, Chris Angelico wrote: > Chris Angelico > yes, bit of a Bible geek as well as a programming geek So you don't believe in genetic algorithms, then ? (ducking for cover) -- When in doubt, use brute force. -- Ken Thompson From nospam at torek.net Mon May 30 17:33:16 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 21:33:16 GMT Subject: How to catch a line with Popen References: Message-ID: >Chris Torek wrote: >> In at least some versions of Python 2 [the "file"-type object iterators behave badly with pipes] (This may still be true in Python 3, I just have no experience with Py3k. "At least some version of Python 2" means "the ones I have access to, and have tried." :-) ) In article TheSaint wrote: >I'm with P3k :P. However thank you for your guidelines. >Last my attempt was to use a *for* p.wait() , as mentioned earlier If you have a process that has not yet terminated and that you must stop from your own python program, calling the wait() method will wait forever (because you are now waiting for yourself, in effect -- waiting for yourself to terminate the other process). The only time to call p.wait() (or p.communicate(), which itself calls the wait() method) is when you believe the subprocess is on its wao to terminating -- in this case, after you force it to do so. >That looks good enough. I noted some little delay for the first lines, >mostly sure Popen assign some buffer even it is not set. According to the documentation, the default buffer size of Python 2 is 0, which is passed to fdopen() and makes the resulting files unbuffered. I recall some sort of changes discussed for Py3k though. >Haven't you try a perpetual ping, how would be the line_at_a_time ? Since it is a generator that only requests another line when called, it should be fine. (Compare to the itertools "cycle" and "repeat" generators, for instance, which "return" an infinite sequence.) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From WolfgangMeiners01 at web.de Mon May 30 17:40:57 2011 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Mon, 30 May 2011 23:40:57 +0200 Subject: sqlalchemy and Unicode strings: errormessage Message-ID: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> Hi, I am trying to build an application using sqlalchemy. in principle i have the structure #============================================== from sqlalchemy import * from sqlalchemy.orm import * metadata = MetaData('sqlite://') a_table = Table('tf_lehrer', metadata, Column('id', Integer, primary_key=True), Column('Kuerzel', Text), Column('Name', Text)) A_class = Class(object): def __init__(self, Kuerzel, Name) self.Kuerzel=Kuerzel self.Name=Name mapper(A_class, a_table) A_record = A_class('BUM', 'B?umer') Session = sessionmaker() session = Session() session.add(A_record) session.flush() #================================================ At this time it runs to the line session.flush() where i get the following errormessage: sqlalchemy.exc.ProgrammingError: (ProgrammingError) You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings. u'INSERT INTO tf_lehrer ("Kuerzel", "Name") VALUES (?, ?)' ('BUM', 'B\xc3\xa4umer') but where can i switch my application to Unicode strings? Thank you for all hints Wolfgang From irmen.NOSPAM at xs4all.nl Mon May 30 18:15:06 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 31 May 2011 00:15:06 +0200 Subject: python in school notebooks/laptops In-Reply-To: <2edff4f4-64db-4f39-b822-6f8d2c41eddd@h12g2000pro.googlegroups.com> References: <2edff4f4-64db-4f39-b822-6f8d2c41eddd@h12g2000pro.googlegroups.com> Message-ID: <4de416eb$0$49174$e4fe514c@news.xs4all.nl> On 30-5-2011 16:30, jmfauth wrote: > On 30 mai, 13:09, hackingKK wrote: > > [...] > >> >> Even better, try convincing them to use Ubuntu instead of a virus >> called Where I Never Do Operations With Safety, or WINDOWS for short. >> That way Python will come by default and VB will be out of question >> Happy hacking. >> Krishnakant. > > Do you mean one of these os's, where Python (2) is not > working properly because the *defaultencoding* is set > to utf-8? > > jmf Huh? On all of my machines, including windows and Ubuntu 11.04, sys.getdefaultencoding() returns 'ascii'. Irmen From fzadrozny at appcelerator.com Mon May 30 18:38:07 2011 From: fzadrozny at appcelerator.com (Fabio Zadrozny) Date: Mon, 30 May 2011 19:38:07 -0300 Subject: Pydev 2.1.0 Released Message-ID: Hi All, Pydev 2.1.0 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- Code Analysis By default, only the currently opened editor will be analyzed (resulting in much shorter build times). Added action to force the analysis on a given folder or file. Showing error markers for PyDev elements in the tree. New option to remove error markers when the editor is closed (default). Editor Override method completions (Ctrl+Space after a 'def ') . Completions starting with '_' now have lower priority. Fixed major issue when replacing markers which could make errors appear when they shouldn't appear anymore Auto-linking on close parens is now optional (and disabled by default). Code coverage No longer looses the selection on a refresh. Fixed issue where coverage was not working properly when running with multiple processes. Added orientation options PyUnit Added feature to relaunch the last launch when file changes (with option to relaunch only errors). setUpClass was not called when running with the pydev test runner F12 makes the editor active even if there's a tooltip active in the PyUnit view. The PyUnit tooltip is now properly restoring the focus of the previous active control. Added orientation options And a bunch of other bug-fixes. Note: Java 1.4 is no longer supported (at least Java 5 is required now). 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 Appcelerator http://appcelerator.com/ Aptana http://aptana.com/ Pydev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From steve+comp.lang.python at pearwood.info Mon May 30 19:17:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 23:17:45 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <9cddb8-viv.ln1@murmur.very.softly> Message-ID: <4de42598$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 23:04:41 +0200, Rikishi42 wrote: > On 2011-05-28, Chris Angelico wrote: >> I think it's geographic. This list covers a lot of geography; I'm in >> Australia, there are quite a few Brits, and probably the bulk of posts >> come from either the US or Europe. (And yes, I did deliberately fold >> all of Europe down to one entity, and I did also deliberately leave >> Great Britain out of that entity.) > > I allways found that odd. Especially if you're talking geography, not > politics. I can understand they want to be seen as independant, even > they are in it enough to allways opose anything someone else suggests. > :-) > > To me, saying the UK isn't part of Europe, is like saying Japan isn't > part of Asia. Oh by the way, I'm Belgian. In my experience, the Japanese have the same attitude towards Asia as the British have towards Europe: they will claim membership, or deny it, depending on whichever suits their mood at the time. >> Most things work out that way. A thing gets a name based either on its >> implementation or on the brand name of the first/most popular one. If >> the only microwave oven ever produced had been made by Foobar Corp, and >> that company were not known for anything else, then quite possibly >> everyone would call them "foobar ovens". > > Yeah, when I was a kid a photo camera was called a Kodak. Sometimes brand names do become generic. "Personal Computer" once was a specific IBM model, not just a description. Elevator and escalator were once brandnames. In some parts of the southern USA, "coke" is used as a word for any softdrink, not just Coca Cola. -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 19:22:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 23:22:01 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> <4de3358b$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de42698$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 19:58:35 +0000, Chris Torek wrote: > In article <4de3358b$0$29990$c3e8da3$5496439d at news.astraweb.com> Steven > D'Aprano wrote: >>Better than a float method is a function which takes any number as >>argument: >> >>>>> import math, fractions, decimal >>>>> math.isnan(fractions.Fraction(2, 3)) >>False >>>>> math.isnan(decimal.Decimal('nan')) >>True > > Ah, apparently someone's been using Larry Wall's time machine. :-) He has one too? Just like Guido van Rossum. > I should have looked at documentation. In my case, though: > > $ python > Python 2.5.1 (r251:54863, Dec 16 2010, 14:12:43) [GCC 4.0.1 (Apple > Inc. build 5465)] on darwin Type "help", "copyright", "credits" or > "license" for more information. Python 2.5 is two major releases behind! I feel your pain, though, because 2.5 is the system python on my desktop as well. (And 2.4 is the system python on my server, ouch!) You should consider installing 2.7 and/or 3.2 in parallel with the system python. > Would it be appropriate to have isnan() methods for Fraction, Decimal, > and complex, so that you do not need to worry about whether to use > math.isnan() vs cmath.isnan()? Probably not. From a purely object-oriented, Java-esque viewpoint, yes, all number types should support isnan and isinf methods, but Python uses a more mixed style, and a function that accepts multiple types is appropriate. Unless you're using complex numbers, you don't need to care about complex numbers. *wink* Hence for "normal" numeric use, stick to the math module. If you do need complex numbers, cmath.isnan works perfectly fine with non- complex arguments: >>> cmath.isnan(42) False >>> cmath.isnan(float('nan')) True -- Steven From henry.olders at mcgill.ca Mon May 30 20:28:34 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Mon, 30 May 2011 20:28:34 -0400 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On 2011-05-29, at 4:30 , Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a program. The made-up code snippet below illustrates the problem I encountered: > > def main(): > a = ['a list','with','three elements'] > print a > print fnc1(a) > print a > > def fnc1(b): > return fnc2(b) > > def fnc2(c): > c[1] = 'having' > return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same output as the first, but variable a had been changed by changing variable c in fnc2. > > It seems that in Python, a variable inside a function is global unless it's assigned. This rule has apparently been adopted in order to reduce clutter by not having to have global declarations all over the place. > > I would have thought that a function parameter would automatically be considered local to the function. It doesn't make sense to me to pass a global to a function as a parameter. > > One workaround is to call a function with a copy of the list, eg in fnc1 I would have the statement "return fnc2(b[:]". But this seems ugly. > > Are there others who feel as I do that a function parameter should always be local to the function? Or am I missing something here? > My thanks to all the people who responded - I've learned a lot. Sadly, I feel that the main issue that I was trying to address, has not been dealt with. Perhaps I didn't explain myself properly; if so, my apologies. I am trying to write python programs in a more-or-less functional programming mode, ie functions without side effects (except for print statements, which are very helpful for debugging). This is easiest when all variables declared in functions are local in scope (it would also be nice if variables assigned within certain constructs such as for loops and list comprehensions were local to that construct, but I can live without it). It appears, from my reading of the python documentation, that a deliberate decision was made to have variables that are referenced but not assigned in a function, have a global scope. I quote from the python FAQs: "In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function?s body, it?s assumed to be a local. If a variable is ever assigned a new value inside the function, the variable is implicitly local, and you need to explicitly declare it as ?global?. Though a bit surprising at first, a moment?s consideration explains this. On one hand, requiring global for assigned variables provides a bar against unintended side-effects. On the other hand, if global was required for all global references, you?d be using global all the time. You?d have to declare as global every reference to a built-in function or to a component of an imported module. This clutter would defeat the usefulness of the global declaration for identifying side-effects." (http://docs.python.org/faq/programming.html) This suggests that the decision to make unassigned (ie "free" variables) have a global scope, was made somewhat arbitrarily to prevent clutter. But I don't believe that the feared clutter would materialize. My understanding is that when a variable is referenced, python first looks for it in the function's namespace, then the module's, and finally the built-ins. So why would it be necessary to declare references to built-ins as globals? What I would like is that the variables which are included in the function definition's parameter list, would be always treated as local to that function (and of course, accessible to nested functions) but NOT global unless explicitly defined as global. This would prevent the sort of problems that I encountered as described in my original post. I may be wrong here, but it seems that the interpreter/compiler should be able to deal with this, whether the parameter passing is by value, by reference, by object reference, or something else. If variables are not assigned (or bound) at compile time, but are included in the parameter list, then the binding can be made at runtime. And I am NOT talking about variables that are only referenced in the body of a function definition; I am talking about parameters (or arguments) in the function's parameter list. As I stated before, there is no need to include a global variable in a parameter list, and if you want to have an effect outside of the function, that's what the return statement is for. I don't believe I'm the only person who thinks this way. Here is a quote from wikipedia: "It is considered good programming practice to make the scope of variables as narrow as feasible so that different parts of a program do not accidentally interact with each other by modifying each other's variables. Doing so also prevents action at a distance. Common techniques for doing so are to have different sections of a program use different namespaces, or to make individual variables "private" through either dynamic variable scoping or lexical variable scoping." (http://en.wikipedia.org/wiki/Variable_(programming)#Scope_and_extent). It also seems that other languages suitable for functional programming take the approach I think python should use. Here is another quote from the wikipedia entry for Common Lisp: "the use of lexical scope isolates program modules from unwanted interactions. Due to their restricted visibility, lexical variables are private. If one module A binds a lexical variable X, and calls another module B, references to X in B will not accidentally resolve to the X bound in A. B simply has no access to X. For situations in which disciplined interactions through a variable are desirable, Common Lisp provides special variables. Special variables allow for a module A to set up a binding for a variable X which is visible to another module B, called from A. Being able to do this is an advantage, and being able to prevent it from happening is also an advantage; consequently, Common Lisp supports both lexical and dynamic scope. (http://en.wikipedia.org/wiki/Common_Lisp#Determiners_of_scope). If making python behave this way is impossible, then I will just have to live with it. But if it's a question of "we've always done it this way", or, " why change? I'm not bothered by it", then I will repeat my original question: Are there others who feel as I do that a function parameter should always be local to the function? And again, thank you all for taking the time to respond. Henry From harrismh777 at charter.net Mon May 30 20:32:01 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 30 May 2011 19:32:01 -0500 Subject: Beginner needs advice In-Reply-To: <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6GWEp.38791$Vp.28176@newsfe14.iad> Steven D'Aprano wrote: LOL > I invite you to consider the difference between a legally dead person > moments before being resuscitated by a paramedic, ( ... alive ) > versus a chicken that > has just been beheaded and is still running around the yard, ( ... alive ) > versus a > million-year-old fossilized bone that has turned to stone. ( ... mostly 'dead' ) > Who could > possibly justify saying that all three are equally dead? LOL ( the first two [ roflol ] are 'partly' alive... ) ( the third is just mostly dead... ) > > Beware the tyranny of the discontinuous mind. > Sic Semper Tyrannus ! > Compatibility is inherently continuous, a matter > of degree. Compatible by degrees is incompatible. Just 'how' incompatible determines whether the factor(s) are utterly useless, or just difficult to negotiate. (uh, oh,... me suspects another analogy fallacy coming up... ) > This is especially true when it comes to languages, both natural and > programming. ( Yup... analogy fallacy for ?nglisc speakers... ) > British English and American English are perhaps 99.5% > compatible, but "table a motion" means completely opposite things in > British and American English. (In Britain, it means to deal with it > immediately; in the USA, it means to postpone it.) Should we conclude > from this that British and American English are "different languages" and > "completely incompatible"? We Americans have not spoken 'English' in well over two hundred years... :) roflol However, I guarantee that if I'm dumped unaided in Piccadilly I'll be able to hail a cab, pay my ?12.00 and get myself to Liverpool Street Station, find the bathroom, and be on the correct train just in time for dinner, all without looking into the English dictionary. On the other hand (playing along with this analogy fallacy) if I dump a python newbie unaided in the middle of 2.5 and ask them to format a simple polytonic Greek unicode string and output it with print to stdout (redirected to a file) they will fail... maybe even if they have a dictionary ! > > The differences between Python 2 and 3 are less than those between > American and British English. absurd and unsubstantiated claim... quickly now call the bobbies, call the bobbies !!! To describe them as "different languages", > as if going from Python 2 to 3 was like translating English to Italian, > is absurd. ... no, um, its more like migrating ye old ?nglisc... (the ?nglisc of say, "Beowulf" ) to modern English.... still assuming the English analogy fallacy holds... which,... it doesn't... Ever tried to read Beowulf in the original? Ever tried to write ?nglisc ? kind regards, m harris From harrismh777 at charter.net Mon May 30 20:43:33 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 30 May 2011 19:43:33 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: Ian Kelly wrote: > You have just misrepresented Steven's argument, which is rather ironic > considering that you're the one who brought up straw-men. Steven did > not use one code snippet to demonstrate that Python 2 and Python 3 are > fully compatible. The code snippet merely demonstrated that Python 2 > and 3 are not "totally incompatible" as you had claimed. Ian gets the Christmas turkey for pinning the irony on me fair 'n square... 'demonstrating' the straw-man is intimately and infinitely more delicious than just defining it... besides, the tables must be turned me thinks... :) > > I realize you are now asserting that compatibility is a boolean > condition, and that "totally incompatible" is a redundant phrase that > you tossed out as a joke. I don't know whether you're sincere or > backpedaling, but in any case this assertion is flatly ludicrous. > Following your definition,*nothing* is compatible with anything else. > If you disagree, then I invite you to list one example of two > different things that are compatible. one man, and one woman.... > > And finally, . . . you > seem to view all analogies as false) regardless of what that person > actually said ... all analogies are argumentative fallacy. Now, the analogy event (or ontological state of the analogy) may in fact be true... but that event or state can *never* be used to assert truth in 'different event' or fact of 'another state' as the 'same thing(s)'. The truth or fallacy of an argument should never be asserted by the use of an analogy regardless how well the analogy illustrates the point. Some folks believe that a good illustration of a point can be used to prove the point true (or false), when in fact the illustration (the analogy event) is often nothing more than entertaining explanation (Steven's are some of the best, I admit !) -- even if that person does*sometimes* actually commit > those fallacies -- then you yourself are employing an ad hominem. ... oh ho ho... lol yes... again... guilty as charged. kind regards, m harris From harrismh777 at charter.net Mon May 30 20:44:44 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 30 May 2011 19:44:44 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: <0SWEp.5868$cs1.671@newsfe15.iad> Jason Tackaberry wrote: > At least, > his arguments make more sense if I read him as arguing from the "not > completely compatible" position. It's possible he is intentionally > equivocating for dramatic effect. yes From benjamin.kaplan at case.edu Mon May 30 20:52:27 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 30 May 2011 17:52:27 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 5:28 PM, Henry Olders wrote: > > On 2011-05-29, at 4:30 , Henry Olders wrote: > >> I just spent a considerable amount of time and effort debugging a program. The made-up code snippet below illustrates the problem I encountered: >> >> def main(): >> ? ? ? a = ['a list','with','three elements'] >> ? ? ? print a >> ? ? ? print fnc1(a) >> ? ? ? print a >> >> def fnc1(b): >> ? ? ? return fnc2(b) >> >> def fnc2(c): >> ? ? ? c[1] = 'having' >> ? ? ? return c >> >> This is the output: >> ['a list', 'with', 'three elements'] >> ['a list', 'having', 'three elements'] >> ['a list', 'having', 'three elements'] >> >> I had expected the third print statement to give the same output as the first, but variable a had been changed by changing variable c in fnc2. >> >> It seems that in Python, a variable inside a function is global unless it's assigned. This rule has apparently been adopted in order to reduce clutter by not having to have global declarations all over the place. >> >> I would have thought that a function parameter would automatically be considered local to the function. It doesn't make sense to me to pass a global to a function as a parameter. >> >> One workaround is to call a function with a copy of the list, eg in fnc1 I would have the statement "return fnc2(b[:]". But this seems ugly. >> >> Are there others who feel as I do that a function parameter should always be local to the function? Or am I missing something here? >> > > My thanks to all the people who responded - I've learned a lot. Sadly, I feel that the main issue that I was trying to address, has not been dealt with. Perhaps I didn't explain myself properly; if so, my apologies. > > I am trying to write python programs in a more-or-less functional programming mode, ie functions without side effects (except for print statements, which are very helpful for debugging). This is easiest when all variables declared in functions are local in scope (it would also be nice if variables assigned within certain constructs such as for loops and list comprehensions were local to that construct, but I can live without ?it). > > It appears, from my reading of the python documentation, that a deliberate decision was made to have variables that are referenced but not assigned in a function, have a global scope. I quote from the python FAQs: "In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function?s body, it?s assumed to be a local. If a variable is ever assigned a new value inside the function, the variable is implicitly local, and you need to explicitly declare it as ?global?. > Though a bit surprising at first, a moment?s consideration explains this. On one hand, requiring global for assigned variables provides a bar against unintended side-effects. On the other hand, if global was required for all global references, you?d be using global all the time. You?d have to declare as global every reference to a built-in function or to a component of an imported module. This clutter would defeat the usefulness of the global declaration for identifying side-effects." (http://docs.python.org/faq/programming.html) > > This suggests that the decision to make unassigned (ie "free" variables) have a global scope, was made somewhat arbitrarily to ?prevent clutter. But I don't believe that the feared clutter would materialize. My understanding is that when a variable is referenced, python first looks for it in the function's namespace, then the module's, and finally the built-ins. So why would it be necessary to declare references to built-ins as globals? > > What I would like is that the variables which are included in the function definition's parameter list, would be always treated as local to that function (and of course, accessible to nested functions) but NOT global unless explicitly defined as global. This would prevent the sort of problems that I encountered as described in my original post. I may be wrong here, but it seems that the interpreter/compiler should be able to deal with this, whether the parameter passing is by value, by reference, by object reference, or something else. If variables are not assigned (or bound) at compile time, but are included in the parameter list, then the binding can be made at runtime. > And I am NOT talking about variables that are only referenced in the body of a function definition; I am talking about parameters (or arguments) in the function's parameter list. As I stated before, there is no need to include a global variable in a parameter list, and if you want to have an effect outside of the function, that's what the return statement is for. > > I don't believe I'm the only person who thinks this way. Here is a quote from wikipedia: "It is considered good programming practice to make the scope of variables as narrow as feasible so that different parts of a program do not accidentally interact with each other by modifying each other's variables. Doing so also prevents action at a distance. Common techniques for doing so are to have different sections of a program use different namespaces, or to make individual variables "private" through either dynamic variable scoping or lexical variable scoping." (http://en.wikipedia.org/wiki/Variable_(programming)#Scope_and_extent). > > It also seems that other languages suitable for functional programming take the approach I think python should use. Here is another quote from the wikipedia entry for Common Lisp: "the use of lexical scope isolates program modules from unwanted interactions. Due to their restricted visibility, lexical variables are private. If one module A binds a lexical variable X, and calls another module B, references to X in B will not accidentally resolve to the X bound in A. B simply has no access to X. For situations in which disciplined interactions through a variable are desirable, Common Lisp provides special variables. Special variables allow for a module A to set up a binding for a variable X which is visible to another module B, called from A. Being able to do this is an advantage, and being able to prevent it from happening is also an advantage; consequently, Common Lisp supports both lexical and dynamic scope. (http://en.wikipedia.org/wiki/Common_Lisp#Determiners_of_scope). > > > If making python behave this way is impossible, then I will just have to live with it. But if it's a question of "we've always done it this way", or, " why change? I'm not bothered by it", then I will repeat my original question: Are there others who feel as I do that a function parameter should always be local to the function? > > And again, thank you all for taking the time to respond. > > Henry Python doesn't have true globals. When we say "global" what we mean is "module or built-in". Also, consider this code from math import sin def redundant_sin(x) : return sin(x) In Python, everything is an object. That includes functions. By your definition, that function would either have to be written as def redundant_sin(sin, x) : and you would have to pass the function in every time you wanted to call it or have a "global sin" declaration in your function. And you would need to do that for every single function that you call in your function body. > -- > http://mail.python.org/mailman/listinfo/python-list > From harrismh777 at charter.net Mon May 30 20:57:21 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 30 May 2011 19:57:21 -0500 Subject: python in school notebooks/laptops In-Reply-To: References: Message-ID: Chris Angelico wrote: >> Is it a waste of time to try to get school admins to put python in >> > their school laptops? No, absolutely no... Python advocacy is necessary in this venue ! > Possibly the best way to encourage Python deployment would be to > require it to run some internal script. Chris has a great idea here... but I think more along the lines of an app that benefits school admins in terms of networking registration, accountability, or messaging. In other words, if I understand Chris correctly, make the script / app necessarily useful to the admins you are trying to advocate to, so that the students reap the benefits of having the interpretor installed and ready...?!? Great idea... kind regards, m harris From rhodri at wildebst.demon.co.uk Mon May 30 20:58:17 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 31 May 2011 01:58:17 +0100 Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> Message-ID: On Tue, 31 May 2011 01:32:01 +0100, harrismh777 wrote: > Steven D'Aprano wrote: >> Compatibility is inherently continuous, a matter >> of degree. > > Compatible by degrees is incompatible. Just 'how' incompatible > determines whether the factor(s) are utterly useless, or just difficult > to negotiate. > > (uh, oh,... me suspects another analogy fallacy coming up... ) > >> This is especially true when it comes to languages, both natural and >> programming. > > ( Yup... analogy fallacy for ?nglisc speakers... ) I don't know about you, but I speak English not "Anglish". This is how an aesc is pronounced, after all. >> British English and American English are perhaps 99.5% >> compatible, but "table a motion" means completely opposite things in >> British and American English. (In Britain, it means to deal with it >> immediately; in the USA, it means to postpone it.) Should we conclude >> from this that British and American English are "different languages" >> and >> "completely incompatible"? > > We Americans have not spoken 'English' in well over two hundred > years... :) roflol Quite the contrary, in fact. Much American usage of English actually better preserves the styles of eighteenth century English usage, having managed to avoid some of the "corrections" of Victorian grammarians. > However, I guarantee that if I'm dumped unaided in Piccadilly I'll > be able to hail a cab, pay my ?12.00 and get myself to Liverpool Street > Station, find the bathroom, and be on the correct train just in time for > dinner, all without looking into the English dictionary. And I guarantee that you'd get odd looks for at least one of those. You may not notice; we Brits are used to translating the large amount of US TV we get back into British English. > On the other hand (playing along with this analogy fallacy) if I > dump a python newbie unaided in the middle of 2.5 and ask them to format > a simple polytonic Greek unicode string and output it with print to > stdout (redirected to a file) they will fail... maybe even if they have > a dictionary ! Now this is an analogy fallacy, and an obvious one at that. -- Rhodri James *-* Wildebeest Herder to the Masses From dan.kluev at gmail.com Mon May 30 21:11:17 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 12:11:17 +1100 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 11:28 AM, Henry Olders wrote: > What I would like is that the variables which are included in the function definition's parameter list, would be always treated as local to that function You still mis-reading docs and explanations you received from the list. Let me try again. First, there are objects and names. Calling either of them as 'variables' is leading to this mis-understanding. Name refers to some object. Object may be referenced by several names or none. Second, when you declare function `def somefunc(a, b='c')` a and b are both local to this function. Even if there are some global a and b, they are 'masked' in somefunc scope. Docs portion you cited refer to other situation, when there is no clear indicator of 'locality', like this: def somefunc(): print a In this - and only in this - case a is considered global. Third, when you do function call like somefunc(obj1, obj2) it uses call-by-sharing model. It means that it assigns exactly same object, that was referenced by obj1, to name a. So both obj1 and _local_ a reference same object. Therefore when you modify this object, you can see that obj1 and a both changed (because, in fact, obj1 and a are just PyObject*, and point to exactly same thing, which changed). However, if you re-assign local a or global obj1 to other object, other name will keep referencing old object: obj1 = [] def somefunc(a): a.append(1) # 'a' references to the list, which is referenced by obj1, and calls append method of this list, which modifies itself in place global obj1 obj1 = [] # 'a' still references to original list, which is [1] now, it have no relation to obj1 at all somefunc(obj1) -- With best regards, Daniel Kluev From tjreedy at udel.edu Mon May 30 21:12:44 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 21:12:44 -0400 Subject: python in school notebooks/laptops In-Reply-To: <4de416eb$0$49174$e4fe514c@news.xs4all.nl> References: <2edff4f4-64db-4f39-b822-6f8d2c41eddd@h12g2000pro.googlegroups.com> <4de416eb$0$49174$e4fe514c@news.xs4all.nl> Message-ID: On 5/30/2011 6:15 PM, Irmen de Jong wrote: >> Do you mean one of these os's, where Python (2) is not >> working properly because the *defaultencoding* is set >> to utf-8? > Huh? On all of my machines, including windows and Ubuntu 11.04, sys.getdefaultencoding() > returns 'ascii'. For me, WINXP, 2.7 >>> sys.getdefaultencoding() 'ascii' winxp, 3.2: >>> sys.getdefaultencoding() 'utf-8' Both are what one would want. -- Terry Jan Reedy From ian.g.kelly at gmail.com Mon May 30 21:16:23 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 May 2011 19:16:23 -0600 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: On Mon, May 30, 2011 at 6:43 PM, harrismh777 wrote: >> I realize you are now asserting that compatibility is a boolean >> condition, and that "totally incompatible" is a redundant phrase that >> you tossed out as a joke. ?I don't know whether you're sincere or >> backpedaling, but in any case this assertion is flatly ludicrous. >> Following your definition,*nothing* ?is compatible with anything else. >> ?If you disagree, then I invite you to list one example of two >> different things that are compatible. > > ? one man, and one woman.... Now you're equivocating. The discussion has been about whether Python 2 and Python 3 are compatible in the "interchangeable" sense, not in the "capable of functioning together" sense. From tjreedy at udel.edu Mon May 30 21:30:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 21:30:39 -0400 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On 5/30/2011 8:28 PM, Henry Olders wrote: > Sadly, I feel that the main issue that I was trying to address, has > not been dealt with. False. Please go back and read what I and others wrote before. ... > What I would like is that the variables which are included in the > function definition's parameter list, would be always treated as > local to that function (and of course, accessible to nested > functions) You would like Python to be the way it is. Fine. For the Nth time, PARAMATER NAMES ARE LOCAL NAMES. Period. > but NOT global unless explicitly defined as global. PARAMETER NAMES **CANNOT** BE DEFINED AS GLOBAL. >>> def f(a): global a SyntaxError: name 'a' is parameter and global Again, go back and reread what I and other wrote. I believe that you are, in part, hypnotized by the work 'variable'. Can you define the word? There are 10 to 20 possible variations, and yours is probably wrong for Python. > quote from wikipedia: "It is considered good programming practice to > make the scope of variables as narrow as feasible so that different > parts of a program do not accidentally interact with each other by > modifying each other's variables. From 'import this': "Namespaces are one honking great idea -- let's do more of those! Python is loaded with namespaces. > Doing so also prevents action at a > distance. Common techniques for doing so are to have different > sections of a program use different namespaces, or to make individual > variables "private" through either dynamic variable scoping or > lexical variable scoping." > (http://en.wikipedia.org/wiki/Variable_(programming)#Scope_and_extent). Python is lexically scoped. > another quote from the wikipedia entry for Common Lisp: "the use of > lexical scope isolates program modules from unwanted interactions. Python is lexically scoped. > If making python behave this way is impossible, How do you expect us to respond when you say "Please make Python the way it is."? Or is you say "If making Python the way it is is impossible..."? Now, if you actually want Python to drastically change its mode of operation and break most existing programs, do not bother asking. > Are there others who feel as I do that a > function parameter should always be local to the function? Yes, we all do, and they are. -- Terry Jan Reedy From tjreedy at udel.edu Mon May 30 21:34:09 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 21:34:09 -0400 Subject: Beginner needs advice In-Reply-To: <6GWEp.38791$Vp.28176@newsfe14.iad> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> Message-ID: On 5/30/2011 8:32 PM, harrismh777 wrote: > Ever tried to read Beowulf in the original? Ever tried to write ?nglisc ? I have, and it is a lot further from modern American than Python 2 and 3 are from each other. -- Terry Jan Reedy From tjreedy at udel.edu Mon May 30 21:47:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 21:47:30 -0400 Subject: Beginner needs advice In-Reply-To: <6GWEp.38791$Vp.28176@newsfe14.iad> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> Message-ID: On 5/30/2011 8:32 PM, harrismh777 wrote: > > However, I guarantee that if I'm dumped unaided in Piccadilly I'll be > able to hail a cab, pay my ?12.00 and get myself to Liverpool Street > Station, find the bathroom, and be on the correct train just in time for > dinner, all without looking into the English dictionary. Because natural language is redundant and most speakers are forgiving, while computer language are stripped on much redundancy and their interpreters tend to be unforgiving, so a single missing comma or space can raise a SyntaxError. Python is designed to do so, and allow/require correction, rather than guess and go on. This is not so bad; what if the cabbie does not understand you but say OK, guesses the destination, ignores any protestations, and asks for ?30 at the wrong destination. Following people who deafly say OK and take you whereever is a real hazard in some countries. Some tourist guides even warn about the practice. Anyway, 'L i v e r p o o l S t r e e t S t a t i o n' is such a trivial utterance as to not be comparable to anything as complicated as a typical 5-line function. -- Terry Jan Reedy From dan.kluev at gmail.com Mon May 30 21:48:10 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 12:48:10 +1100 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 12:30 PM, Terry Reedy wrote: > Again, go back and reread what I and other wrote. I believe that you are, in > part, hypnotized by the work 'variable'. Can you define the word? There are > 10 to 20 possible variations, and yours is probably wrong for Python. On a sidenote, I wonder what is the reason to keep word 'variable' in python documentation at all. I believe word 'name' represents concept better, and those, who come from other languages, would be less likely to associate wrong definitions with it. -- With best regards, Daniel Kluev From rosuav at gmail.com Mon May 30 22:27:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 12:27:33 +1000 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: On Tue, May 31, 2011 at 11:16 AM, Ian Kelly wrote: > On Mon, May 30, 2011 at 6:43 PM, harrismh777 wrote: >>> ?If you disagree, then I invite you to list one example of two >>> different things that are compatible. >> >> ? one man, and one woman.... > > Now you're equivocating. ?The discussion has been about whether Python > 2 and Python 3 are compatible in the "interchangeable" sense, not in > the "capable of functioning together" sense. Indeed. If a man has a scripting language, and a woman has a scripting language, the two would differ because there are things each can do that the other cannot. But there's a lot of things that both can do, so the two languages would be highly similar in purpose and functionality. Hmm. If you did write those two scripting languages, we would finally be able to type "man woman" to get docs on how to talk to women... Chris Angelico From rosuav at gmail.com Mon May 30 22:53:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 12:53:24 +1000 Subject: python in school notebooks/laptops In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 10:57 AM, harrismh777 wrote: > Chris Angelico wrote: >> Possibly the best way to encourage Python deployment would be to >> require it to run some internal script. > > ? Chris has a great idea here... but I think more along the lines of an app > that benefits school admins in terms of networking registration, > accountability, or messaging. In other words, if I understand Chris > correctly, make the script / app ?necessarily useful to the admins you are > trying to advocate to, so that the students reap the benefits of having the > interpretor installed and ready...?!? Precisely. If there is some kind of need for a script to be deployed on all students' laptops (even if it's just part of some installer, and not necessary post-setup), then write it in Python and put the interpreter on there. This is not shenanigans, but simply the use of a quality tool; it's no different from the eComStation installers making extensive use of VX-REXX, and thus mandating its installation as part of the eCS install. Chris Angelico From harrismh777 at charter.net Mon May 30 23:02:56 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 30 May 2011 22:02:56 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: Chris Angelico wrote: > Hmm. If you did write those two scripting languages, we would finally > be able to type "man woman" to get docs on how to talk to women... Which just wouldn't be fair, because her use of man man would lead her no closer to understanding how men speak... (er, think, um... ) :) > From rosuav at gmail.com Mon May 30 23:05:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 13:05:25 +1000 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 10:28 AM, Henry Olders wrote: > I don't believe I'm the only person who thinks this way. Here is a quote from wikipedia: "It is considered good programming practice to make the scope of variables as narrow as feasible so that different parts of a program do not accidentally interact with each other by modifying each other's variables. Doing so also prevents action at a distance. Common techniques for doing so are to have different sections of a program use different namespaces, or to make individual variables "private" through either dynamic variable scoping or lexical variable scoping." (http://en.wikipedia.org/wiki/Variable_(programming)#Scope_and_extent). > Side point, on variable scope. There is a philosophical split between declaring variables and not declaring them. Python is in the latter camp; you are not required to put "int a; char *b; float c[4];" before you use the integer, string, and list/array variables a, b, and c. This simplifies code significantly, but forces the language to have an unambiguous scoping that doesn't care where you assign to a variable. Example: def f(): x=1 # x is function-scope if cond: # cond is global x=2 # Same function-scope x as above print(x) # Function-scope, will be 2 if cond is true This is fine, and is going to be what you want. Another example: def f(): print(x) # global # .... way down, big function, you've forgotten what you're doing for x in list_of_x: x.frob() By using x as a loop index, you've suddenly made it take function scope, which stops it from referencing the global. Granted, you shouldn't be using globals with names like 'x', but it's not hard to have duplication of variable names. As a C programmer, I'm accustomed to being able to declare a variable in an inner block and have that variable cease to exist once execution leaves that block; but that works ONLY if you declare the variables where you want them. Infinitely-nested scoping is simply one of the casualties of a non-declarative language. Chris Angelico From dan.kluev at gmail.com Mon May 30 23:18:49 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 14:18:49 +1100 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 2:05 PM, Chris Angelico wrote: > Infinitely-nested scoping is simply one of the casualties of a > non-declarative language. Well, this is not accurate, as you can have 'infinitely-nested scoping' in python, in form of nested functions. For example, you can use map(lambda x: , list_of_x), and you will have your isolated scopes. Although due to lambdas supporting only expressions, following this style leads to awkward and complicated code (and/or instead if, map instead for, and so on). -- With best regards, Daniel Kluev From rosuav at gmail.com Mon May 30 23:34:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 13:34:43 +1000 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 1:18 PM, Daniel Kluev wrote: > On Tue, May 31, 2011 at 2:05 PM, Chris Angelico wrote: >> Infinitely-nested scoping is simply one of the casualties of a >> non-declarative language. > > Well, this is not accurate, as you can have 'infinitely-nested > scoping' in python, in form of nested functions. For example, you can > use map(lambda x: map/filter/reduce/lambda's>, list_of_x), and you will have your > isolated scopes. Although due to lambdas supporting only expressions, > following this style leads to awkward and complicated code (and/or > instead if, map instead for, and so on). That's an incredibly messy workaround, and would get ridiculous if you tried going many levels in. It's like saying that a C-style 'switch' statement can be implemented in Python using a dictionary of lambdas... and then trying to implement fall-through. But you're right; a lambda does technically create something of a nested scope - albeit one in which the only internal variables are its parameters. Chris Angelico From prakash.stack at gmail.com Tue May 31 00:05:17 2011 From: prakash.stack at gmail.com (prakash jp) Date: Tue, 31 May 2011 09:35:17 +0530 Subject: pydev ant build Message-ID: Hi all, Could any one provide relevant url/s on the usage of *pyant* scripts and its setup as well Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue May 31 00:35:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 May 2011 04:35:35 GMT Subject: scope of function parameters (take two) References: Message-ID: <4de47016$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 20:28:34 -0400, Henry Olders wrote: > I am trying to write python programs in a more-or-less functional > programming mode, ie functions without side effects (except for print > statements, which are very helpful for debugging). This is easiest when > all variables declared in functions are local in scope They are. > (it would also be > nice if variables assigned within certain constructs such as for loops > and list comprehensions were local to that construct, but I can live > without it). for loop variables are local to the function, by design. List comprehension variables leak outside the comprehension. That is an accident that is fixed in Python 3. Generator expression variables never leaked. > It appears, from my reading of the python documentation, that a > deliberate decision was made to have variables that are referenced but > not assigned in a function, have a global scope. [...] > This suggests that the decision to make unassigned (ie "free" variables) > have a global scope, was made somewhat arbitrarily to prevent clutter. > But I don't believe that the feared clutter would materialize. Then you haven't understood the problem at all. > My > understanding is that when a variable is referenced, python first looks > for it in the function's namespace, then the module's, and finally the > built-ins. So why would it be necessary to declare references to > built-ins as globals? How else would the functions be found if they were ONLY treated as local? Consider this code: def spam(): print a_name print len(a_name) This includes two names: "a_name" and "len". They both follow the same lookup rules. Functions in Python are first-class values, just like ints, strings, or any other type. You don't want spam() to see any global "a_name" without it being declared. But how then can it see "len"? Don't think that Python could change the rules depending on whether you're calling a name or not. Consider this: def spam(): print a_name print a_name(len) Do you expect the first lookup to fail, and the second to succeed? > What I would like is that the variables which are included in the > function definition's parameter list, would be always treated as local > to that function (and of course, accessible to nested functions) but NOT > global unless explicitly defined as global. They are. Always have been, always will be. > This would prevent the sort > of problems that I encountered as described in my original post. No it wouldn't. You are confused by what you are seeing, and interpreting it wrongly. I believe that what you want is pass-by-value semantics, in the old- school Pascal sense, where passing a variable to a function makes a copy of it. This is not possible in Python. As a design principle, Python never copies objects unless you as it to. > I may > be wrong here, but it seems that the interpreter/compiler should be able > to deal with this, whether the parameter passing is by value, by > reference, by object reference, or something else. Of course. You could create a language that supports any passing models you want. Pascal and VB support pass-by-value ("copy on pass") and pass- by-reference. Algol supports pass-by-value and (I think) pass-by-name. There's no reason why you couldn't create a language to support pass-by- value and pass-by-object. Whether this is a good idea is another story. However, that language is not Python. > If variables are not > assigned (or bound) at compile time, but are included in the parameter > list, then the binding can be made at runtime. Er, yes? That already happens. > And I am NOT talking > about variables that are only referenced in the body of a function > definition; I am talking about parameters (or arguments) in the > function's parameter list. You keep bring up the function parameter list as if that made a difference. It doesn't. Perhaps this will enlighten you: >>> alist = [1, 2, 3, 4] >>> blist = alist >>> blist[0] = -999 >>> alist [-999, 2, 3, 4] Passing alist to a function is no different to any other name binding. It doesn't make a copy of the list, it doesn't pass a reference to the name "alist", it passes the same object to a new scope. > As I stated before, there is no need to > include a global variable in a parameter list, and if you want to have > an effect outside of the function, that's what the return statement is > for. Function parameters are never global. You are misinterpreting what you see if you think they are. [...] > If making python behave this way is impossible, then I will just have to > live with it. But if it's a question of "we've always done it this way", > or, " why change? I'm not bothered by it", then I will repeat my > original question: Are there others who feel as I do that a function > parameter should always be local to the function? They are. You are misinterpreting what you see. -- Steven From drsalists at gmail.com Tue May 31 00:35:57 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 30 May 2011 21:35:57 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 5:28 PM, Henry Olders wrote: > What I would like is that the variables which are included in the function > definition's parameter list, would be always treated as local to that > function (and of course, accessible to nested functions) but NOT global > unless explicitly defined as global. > If you don't want any globals other than callables and modules and builtins, then don't define any. I normally code that way, other than an infrequent (EG) HAVE_CSTRINGIO global or similar (which is module-global, not program-global) - that is, for variables describing what sorts of optional modules are available. Be careful not to conflate global scoping or global lifetime, with mutability or pure, side-effect-free functions (callables). It sounds like what you want is immutability and/or freedom from side effects, which is found most often in (pure) functional languages - which is not what Python is, nor does it attempt to be so. In Python, and in many other languages, if you pass a scalar (or more generally, an object of an immutable type) to a function, and then change the scalar in that function, you only change the scalar within that function, not within the caller. However, if you pass an aggregate type like a list (array) or dictionary (hash table), then the formal argument itself that you've passed is still only changeable within that function, however what it points off at _is_ changeable via that formal argument. This is of course because otherwise passing a 1 gigabyte dictionary to a function would either have to copy the whole dictionary, or implement some sort of Copy-on-Write semantics, or make it somehow readonly. If you need side effect-free functions in Python, you'd probably best copy your aggregates, EG: import copy def main(): a = ['a list','with','three elements'] print a print fnc1(a) print a def fnc1(b): b = copy.deepcopy(b) return fnc2(b) def fnc2(c): c = copy.deepcopy(c) c[1] = 'having' return c main() Or use Haskell. Please don't try to turn Python into Haskell. Each has its own interesting tradeoffs, and we don't really need two Pythons, and we don't really need two Haskells. HTH. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue May 31 01:03:06 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 31 May 2011 07:03:06 +0200 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: Am 31.05.2011 02:28 schrieb Henry Olders: > This suggests that the decision to make unassigned (ie "free" > variables) have a global scope, was made somewhat arbitrarily to > prevent clutter. But I don't believe that the feared clutter would > materialize. My understanding is that when a variable is referenced, > python first looks for it in the function's namespace, then the > module's, and finally the built-ins. So why would it be necessary to > declare references to built-ins as globals? Not for the builtins, but for the global ones. Suppose you have a module def f(x): return 42 def g(x, y): return f(x) + f(y) Would you really want to need a "global f" inside g? Besides, this doesn't have to do with your original problem at all. Even then, a def h(x): x.append(5) return x would clobber the given object, because x is just a name for the same object which the caller has. > What I would like is that the variables which are included in the > function definition's parameter list, would be always treated as > local to that function (and of course, accessible to nested > functions) They are - in terms of name binding. In Python, you always have objects which can be referred to from a variety of places under different names. Maybe what you want are immutable objects (tuples) instead of mutable ones (lists)... > I don't believe I'm the only person who thinks this way. Here is a > quote from wikipedia: "It is considered good programming practice to > make the scope of variables as narrow as feasible Again: It is the way here. Think of C: there you can have a int f(int * x) { *x = 42; return x; } The scope of the variable x is local here. Same in Python. The object referred to by *x is "somewhere else", by design. Same in Python. > If making python behave this way is impossible, then I will just have > to live with it. Even if I still think that you are confusing "scope of a name binding" and "scope of an object", it is a conceptual thing. Surely it would have been possible to do otherwise, but then it would be a different language. Objects can be mutable, period. In MATLAB, e.g., you have what you desire here: you always have to pass your object around and get another ne back, even if you just add or remove a field of a struct or change the value of a field. HTH, Thomas From wolfgang at rohdewald.de Tue May 31 01:13:24 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Tue, 31 May 2011 07:13:24 +0200 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: <201105310713.24842.wolfgang@rohdewald.de> On Dienstag 31 Mai 2011, Henry Olders wrote: > What I would like is that the variables which are included in > the function definition's parameter list, would be always > treated as local to that function (and of course, accessible > to nested functions) but NOT global unless explicitly defined > as global. This would prevent the sort of problems that I > encountered as described in my original post. the parameter is local but it points to an object from an outer scope - that could be the scope of the calling function or maybe the global scope. So if you change the value of this parameter, you change that object from outer scope. But the parameter itself is still local. If you do def fnc2(c): c = 5 the passed object will not be changed, c now points to another object. This is different from other languages where the "global" c would change (when passing c by reference) what you really seem to want is that a function by default cannot have any side effects (you have a side effect if a function changes things outside of its local scope). But that would be a very different language than python did you read the link Steven gave you? http://mail.python.org/pipermail/tutor/2010-December/080505.html -- Wolfgang From ben+python at benfinney.id.au Tue May 31 01:20:12 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 31 May 2011 15:20:12 +1000 Subject: scope of function parameters (take two) References: Message-ID: <871uzf8n03.fsf@benfinney.id.au> Daniel Kluev writes: > On a sidenote, I wonder what is the reason to keep word 'variable' in > python documentation at all. I believe word 'name' represents concept > better, and those, who come from other languages, would be less likely > to associate wrong definitions with it. I agree, but the term ?variable? is used freely within the Python development team to refer to Python's name-to-object bindings, and that usage isn't likely to stop through our efforts. So the burden is unfortunately on us to teach each newbie that this often-used term means something other than what they might expect. -- \ ?In case you haven't noticed, [the USA] are now almost as | `\ feared and hated all over the world as the Nazis were.? ?Kurt | _o__) Vonnegut, 2004 | Ben Finney From benjamin.kaplan at case.edu Tue May 31 01:35:01 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 30 May 2011 22:35:01 -0700 Subject: Beginner needs advice In-Reply-To: References: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> Message-ID: On Mon, May 30, 2011 at 10:20 PM, Dennis Lee Bieber wrote: > On Mon, 30 May 2011 21:34:09 -0400, Terry Reedy > declaimed the following in gmane.comp.python.general: > >> On 5/30/2011 8:32 PM, harrismh777 wrote: >> >> > Ever tried to read Beowulf in the original? Ever tried to write ?nglisc ? >> >> I have, and it is a lot further from modern American than Python 2 and 3 >> are from each other. >> > ? ? ? ?Heck... Python 2 and 3 are modern vs Shakespearian English... > Chaucer is closer to Python vs Ruby... Beowulf? Might as well be APL... > -- No, Python 2 vs 3 is more of American English vs British English. People who speak one of them work under the philosophy that "if y'all would just speak English we wouldn't have these problems" From dan.kluev at gmail.com Tue May 31 01:36:33 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 16:36:33 +1100 Subject: scope of function parameters (take two) In-Reply-To: <201105310713.24842.wolfgang@rohdewald.de> References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: On Tue, May 31, 2011 at 4:13 PM, Wolfgang Rohdewald wrote: > what you really seem to want is that a function by default > cannot have any side effects (you have a side effect if a > function changes things outside of its local scope). But > that would be a very different language than python This can be done in Python (to some degree), like this @copy_args def somefunc(a, b, c): ... where copy_args would explicitly call deepcopy() on all args passed to the function. Or, to save some performance, wrap them in some CopyOnEdit proxy (although this is tricky, as getattr/getitem can modify object too if class overrides them). Obviously it would not save you from functions which use global/globals() or some other ways to change state outside their scope. -- With best regards, Daniel Kluev From ben+python at benfinney.id.au Tue May 31 01:48:34 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 31 May 2011 15:48:34 +1000 Subject: Beginner needs advice References: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> Message-ID: <87wrh7774d.fsf@benfinney.id.au> Dennis Lee Bieber writes: > Well... He did say "find the bathroom", not ask for directions to > whatever euphemism is in current usage (water closet, W/C, loo ?) The room which contains the bath is the bathroom. Assuming that the toilet is in the same room as the bath is parochial. If he wants the toilet, ?bathroom? is a euphemism, and he should instead ask for directions to the toilet. -- \ ?When we talk to God, we're praying. When God talks to us, | `\ we're schizophrenic.? ?Jane Wagner, via Lily Tomlin, 1985 | _o__) | Ben Finney From nitinpawar432 at gmail.com Tue May 31 02:11:58 2011 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 31 May 2011 11:41:58 +0530 Subject: How to Use Setuptools, Alternatives? In-Reply-To: <3e848108-9b22-4ad8-83ed-e563f8346486@28g2000yqu.googlegroups.com> References: <01045077-543f-4b8d-a5a2-4cde190c3294@v8g2000yqb.googlegroups.com> <3e848108-9b22-4ad8-83ed-e563f8346486@28g2000yqu.googlegroups.com> Message-ID: there is a very good article on python packaging http://www.aosabook.org/en/packaging.html On Tue, May 31, 2011 at 12:18 AM, dough wrote: > On May 29, 10:41 pm, ray wrote: > > I have Python 2.7 on Win7 Pro on a tightly locked down desktop. I > > would like to install Networkx from an egg. From what I have read, > > Setuptools can be used for this. > > > > I don't know how to install Setuptools. The exe will not work. On > > execution, it reports that the Python version is not included in the > > registry. Further, I can not input the version and location on the > > subsequent installation screen, the fields will not accept focus so I > > can not input the values. > > > > Since the exe will not install, I considered using the Setuptools > > egg. But it requires Setuptools. It appears to be a circle. > > > > You're right. Since Setuptools is distributed as an egg, and Python > doesn't natively support eggs, > there can be a "chicken-and-egg" situation. > > > What are some suggestions for installing this? > > > > Thanks, > > ray > > You can try downloading ezsetup.py and running it as a python script > (i.e. python ezsetup.py). > It will locate and download the latest version of Setuptools for your > platform and install it. > If HTTP access is blocked, just place the desired egg in the same > folder as ezsetup.py and run > the script again. > > Assuming you can get Setuptools installed correctly, it puts a program > called easy_install.exe > in your \Scripts folder. You can then just run (from the > command line): > > easy_install > > It will hunt, download and install the latest version of the package > for your platform. > You may want to add the path to the Scripts folder to your PATH > environment variable so > you can just run easy_install from any current working directory. > > Hope that helps, > > Doug > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From henry.olders at mcgill.ca Tue May 31 02:37:47 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Tue, 31 May 2011 02:37:47 -0400 Subject: scope of function parameters (take two) In-Reply-To: <201105310713.24842.wolfgang@rohdewald.de> References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: On 2011-05-31, at 1:13 , Wolfgang Rohdewald wrote: > > what you really seem to want is that a function by default > cannot have any side effects (you have a side effect if a > function changes things outside of its local scope). But > that would be a very different language than python You're partially right - what I want is a function that is free of side effects back through the parameters passed in the function call. Side effects via globals or print statements is fine by me. python seems to be undergoing changes all the time. List comprehensions were added in python 2.0, according to wikipedia. I like list comprehensions and use them all the time because they are powerful and concise. > > did you read the link Steven gave you? > http://mail.python.org/pipermail/tutor/2010-December/080505.html Yes, I did, thanks. Henry From harrismh777 at charter.net Tue May 31 02:48:05 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 31 May 2011 01:48:05 -0500 Subject: Something is rotten in Denmark... Message-ID: >>> fs=[] >>> fs = [(lambda n: i + n) for i in range(10)] >>> [fs[i](1) for i in range(10)] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good ( that was a big surprise! . . . ) ( let's try it another way . . . ) >>> fs =[] >>> def g(i): return (lambda n: i + n) >>> fs = [g(i) for i in range(10)] >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (aaah, that's better . . . ) (hmmm, let's try another . . . ) >>> fs =[] >>> for i in range(10): fs.append(lambda n, i=i: i + n) >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (aaaah, that works too . . . ) (... and another... ) >>> fs=[] >>> fs = [(lambda n, i=i: i + n) for i in range(10)] >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (great! . . . ) (now then, what's wrong with this picture ?) lambda? closure? scope? bug? What is going on with the binding in the first construct... this seems to reduce the usefulness of lambda to a considerable extent? kind regards, m harris From clp2 at rebertia.com Tue May 31 02:54:09 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 May 2011 23:54:09 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: On Mon, May 30, 2011 at 11:37 PM, Henry Olders wrote: > On 2011-05-31, at 1:13 , Wolfgang Rohdewald wrote: >> >> what you really seem to want is that a function by default >> cannot have any side effects (you have a side effect if a >> function changes things outside of its local scope). But >> that would be a very different language than python > > You're partially right - what I want is a function that is free of side effects back through the parameters passed in the function call. Side effects via globals or print statements is fine by me. So, you have no problem with *global* side effects, but side effects with a /more constrained/ scope bother you? That's kinda odd, IMO. Cheers, Chris From henry.olders at mcgill.ca Tue May 31 02:57:24 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Tue, 31 May 2011 02:57:24 -0400 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On 2011-05-30, at 20:52 , Benjamin Kaplan wrote: > On Mon, May 30, 2011 at 5:28 PM, Henry Olders wrote: >> >> On 2011-05-29, at 4:30 , Henry Olders wrote: >> > > Python doesn't have true globals. When we say "global" what we mean is > "module or built-in". Also, consider this code > > from math import sin > def redundant_sin(x) : > return sin(x) > > In Python, everything is an object. That includes functions. By your > definition, that function would either have to be written as > def redundant_sin(sin, x) : > and you would have to pass the function in every time you wanted to > call it or have a "global sin" declaration in your function. And you > would need to do that for every single function that you call in your > function body. > I don't believe so. Within redundant_sin, x is local, so if I change x, it will not change any objects named x outside of the function. As far as sin is concerned, if it were passed to redundant_sin via the parameter list, then it would be local, but otherwise sin would be looked for in the function definition; if not found there, it would be looked for in the module, where it would be found. I am not suggesting any changes to how names are looked up or scoped. Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue May 31 03:00:04 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 31 May 2011 00:00:04 -0700 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 11:48 PM, harrismh777 wrote: >>>> fs=[] >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] > > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] ? ? ? ? <=== not good > > ? ?( that was a big surprise! . . . ) > ? ? lambda? ?closure? ?scope? ? bug? > > ? ? What is going on with the binding in the first construct... this seems > to reduce the usefulness of lambda to a considerable extent? http://stackoverflow.com/questions/233673/lexical-closures-in-python (See 1st and 2nd answers) Cheers, Chris From henry.olders at mcgill.ca Tue May 31 03:17:44 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Tue, 31 May 2011 03:17:44 -0400 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> On 2011-05-31, at 24:35 , Dan Stromberg wrote: > > On Mon, May 30, 2011 at 5:28 PM, Henry Olders wrote: > > Be careful not to conflate global scoping or global lifetime, with mutability or pure, side-effect-free functions (callables). It sounds like what you want is immutability and/or freedom from side effects, which is found most often in (pure) functional languages - which is not what Python is, nor does it attempt to be so. I think you're right, I've been conflating scoping with side effects caused by passing mutable objects. > > In Python, and in many other languages, if you pass a scalar (or more generally, an object of an immutable type) to a function, and then change the scalar in that function, you only change the scalar within that function, not within the caller. > > However, if you pass an aggregate type like a list (array) or dictionary (hash table), then the formal argument itself that you've passed is still only changeable within that function, however what it points off at _is_ changeable via that formal argument. This is of course because otherwise passing a 1 gigabyte dictionary to a function would either have to copy the whole dictionary, or implement some sort of Copy-on-Write semantics, or make it somehow readonly. > > If you need side effect-free functions in Python, you'd probably best copy your aggregates, EG: > > import copy > > def main(): > a = ['a list','with','three elements'] > print a > print fnc1(a) > print a > > def fnc1(b): > b = copy.deepcopy(b) > return fnc2(b) > > def fnc2(c): > c = copy.deepcopy(c) > c[1] = 'having' > return c Clearly, making a copy within the function eliminates the possibility of the side effects caused by passing in mutable objects. Would having the compiler/interpreter do this automatically make python so much different? What if it were optional, like nested scopes were in python 2.1 until they became standard in 2.2? Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 31 03:35:27 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 01:35:27 -0600 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 12:48 AM, harrismh777 wrote: > ? ? What is going on with the binding in the first construct... this seems > to reduce the usefulness of lambda to a considerable extent? I don't see why; as you've shown there are a couple of simple ways to avoid this problem. The trick is just to recognize that when you have a closure around a variable, and that variable needs to change, but the value in the closure needs to be constant, then what you really need are two separate variables -- the cell variable needs to be promoted to a local. How you accomplish that is not terribly important. One other technique that is sometimes preferable is functools.partial, e.g.: fs = [functools.partial(operator.add, i) for i in range(10)] Tangentially, I'd like to point out that this line: [fs[i](1) for i in range(10)] is more naturally written as: [f(1) for f in fs] From dan.kluev at gmail.com Tue May 31 03:38:40 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 18:38:40 +1100 Subject: scope of function parameters (take two) In-Reply-To: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 6:17 PM, Henry Olders wrote: > Clearly, making a copy within the function eliminates the possibility of the > side effects caused by passing in mutable objects. Would having the > compiler/interpreter do this automatically make python so much different? As I've pointed, you can make decorator to do that. Adding @copy_args to each function you intend to be pure is not that hard. import decorator import copy @decorator.decorator def copy_args(f, *args, **kw): nargs = [] for arg in args: nargs.append(copy.deepcopy(arg)) nkw = {} for k,v in kw.iteritems(): nkw[k] = copy.deepcopy(v) return f(*nargs, **nkw) @copy_args def test(a): a.append(1) return a >>> l = [0] >>> test(l) [0, 1] >>> l [0] >>> inspect.getargspec(test) ArgSpec(args=['a'], varargs=None, keywords=None, defaults=None) So this decorator achieves needed result and preserves function signatures. -- With best regards, Daniel Kluev From cocohjy2003 at yahoo.com.cn Tue May 31 03:39:02 2011 From: cocohjy2003 at yahoo.com.cn (kiyo) Date: Tue, 31 May 2011 00:39:02 -0700 (PDT) Subject: welcome to visit our website:http://www.yooobuy.com Message-ID: <7df9b643-894c-405f-a0a1-09797290a9e2@y27g2000prb.googlegroups.com> welcome to visit our website:http://www.yooobuy.com prices such as: NIKE AIR JORDAN(http://www.yooobuy.com) Here is the most favorable product, the most attentive service, the most efficient means of transport. If you have any question, our staff will give you a reply in the first time. Wish you happy shopping. From rosuav at gmail.com Tue May 31 04:04:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 18:04:29 +1000 Subject: scope of function parameters (take two) In-Reply-To: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 5:17 PM, Henry Olders wrote: > Clearly, making a copy within the function eliminates the possibility of the > side effects caused by passing in mutable objects. Would having the > compiler/interpreter do this automatically make python so much different? Yes, it would make Python quite different. If suddenly you couldn't pass a mutable object to a function to get it muted (that sounds wrong), then code will break. Also, there's a fairly serious performance penalty to copying everything when it's not necessary. As has been suggested, you can specifically and deliberately cause this effect for any function(s) you wish to "protect" in this way; there's no need to change the language's fundamentals to do it. Chris Angelico From michal.bulla at gmail.com Tue May 31 04:21:17 2011 From: michal.bulla at gmail.com (michal.bulla) Date: Tue, 31 May 2011 01:21:17 -0700 (PDT) Subject: BadValueError: Property title is required Message-ID: <8106c94d-04f5-4b36-a7dc-be3cff7fecff@b42g2000yqi.googlegroups.com> Hello, I'm trying to create simple method to create category. I set the model category: class Category(db.Model): title = db.StringProperty(required=True) clashes_count = db.IntegerProperty(default=0) And the class New Category as well : class NewCategoryPage(webapp.RequestHandler): def get(self): categories = Category.all().order('-title') template_values = { } path = os.path.join(os.path.dirname(__file__), 'templates', 'category_new.html') self.response.out.write(template.render(path, template_values)) def post(self): category = Category() category.title = self.request.get('title') category.put() self.redirect('/') Here is the template: {%extends "base.html"%} {%block body%}

Add New Category

Title:
{%endblock%} The problem is that I'm getting an error BadValueError: Property title is required. Can you help me with that ? Thanks From clp2 at rebertia.com Tue May 31 04:32:54 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 31 May 2011 01:32:54 -0700 Subject: BadValueError: Property title is required In-Reply-To: <8106c94d-04f5-4b36-a7dc-be3cff7fecff@b42g2000yqi.googlegroups.com> References: <8106c94d-04f5-4b36-a7dc-be3cff7fecff@b42g2000yqi.googlegroups.com> Message-ID: On Tue, May 31, 2011 at 1:21 AM, michal.bulla wrote: > Hello, > > I'm trying to create simple method to create category. I set the model > category: > > class Category(db.Model): > ?title = db.StringProperty(required=True) > ?clashes_count = db.IntegerProperty(default=0) > The problem is that I'm getting an error BadValueError: Property title > is required. Can you help me with that ? Thanks Try asking on the Django mailing list: http://groups.google.com/group/django-users Cheers, Chris From wolfgang at rohdewald.de Tue May 31 04:37:50 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Tue, 31 May 2011 10:37:50 +0200 Subject: scope of function parameters (take two) In-Reply-To: References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: <201105311037.50726.wolfgang@rohdewald.de> On Dienstag 31 Mai 2011, Henry Olders wrote: > You're partially right - what I want is a function that is > free of side effects back through the parameters passed in > the function call. I don't know any object oriented language where it is not possible to change objects passed in as parameters. It is up to the passed object (a list in your case) to allow or disallow manipulations no matter how they are invocated, and the object is the same in the calling code and in the called function. -- Wolfgang From chris at simplistix.co.uk Tue May 31 05:55:14 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 31 May 2011 10:55:14 +0100 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4DE4BB02.2070900@simplistix.co.uk> Hi Wolfgang, On 30/05/2011 22:40, Wolfgang Meiners wrote: > I am trying to build an application using sqlalchemy. You're likely to get much better help here: http://www.sqlalchemy.org/support.html#mailinglist When you post there, make sure you include: - what python version you're using - what sqlalchemy version you're using cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From jpiitula at ling.helsinki.fi Tue May 31 06:08:24 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 31 May 2011 13:08:24 +0300 Subject: Something is rotten in Denmark... References: Message-ID: harrismh777 writes: > >>> fs=[] > >>> fs = [(lambda n: i + n) for i in range(10)] > >>> [fs[i](1) for i in range(10)] > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good > > ( that was a big surprise! . . . ) > ( let's try it another way . . . ) The ten functions share the same i. The list comprehension changes the value of that i. At the time when the functions are called, the value is 9. A different list comprehension mechanism could create a fresh i for each element instead of changing the value of one i. Then each of the functions would have a private i which would have the value it had at the time of the creation of the closure. That is not the Python mechanism. The same sharing-an-i thing happens here: >>> fs = [] >>> for i in range(4): ... fs.append(lambda n : i + n) ... >>> fs[0](0) 3 And the different private-j thing happens here: >>> gs = [] >>> for i in range(4): ... gs.append((lambda j : lambda n : j + n)(i)) ... >>> gs[0](0) 0 You used the lambda itself to introduce its private i in your other examples, in (lambda n, i=i : i + n). In its i=i, the i to the left is a different i - will be a fresh i every time the function is called, I think - while the i to the right gets resolved to the value of the i that the list comprehension is stepping at the time when the closure is created. > What is going on with the binding in the first > construct... this seems to reduce the usefulness of lambda to a > considerable extent? The lambda is doing its lambda thing exactly. The list comprehension just updates the one i in whatever you call it that each of the ten closures remember, and they all observe the updates, so to say. It's a bit subtle. Using different names might help, like I used j. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue May 31 06:48:39 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 31 May 2011 12:48:39 +0200 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: Am 31.05.2011 12:08 schrieb Jussi Piitulainen: > The same sharing-an-i thing happens here: > >>>> fs = [] >>>> for i in range(4): > ... fs.append(lambda n : i + n) > ... >>>> fs[0](0) > 3 > > And the different private-j thing happens here: > >>>> gs = [] >>>> for i in range(4): > ... gs.append((lambda j : lambda n : j + n)(i)) > ... >>>> gs[0](0) > 0 There is a simpler way: with >>>> fs = [] >>>> for i in range(4): > ... fs.append(lambda n, i=i: i + n) > ... you give each lambda a different default argument. >>>> fs[0](0) > 0 Thomas From mohangk at gmail.com Tue May 31 07:25:31 2011 From: mohangk at gmail.com (Mohanaraj Gopala Krishnan) Date: Tue, 31 May 2011 19:25:31 +0800 Subject: Load averages and Python threads on different Linux cloud provider setup Message-ID: Hello, Apologies if this post is off topic. We have a Python application that polls directories using threads and inotify watchers. We have always run this application in a cloud server provided by Voxel (http://www.voxel.net). We are currently testing a different cloud server provider StormOnDemand (http://stormondemand.com) and when we ran our application, our load averages were a lot higher then they were when they were running on the Voxel cloud server despite the specs being about the same (Refer below for more details on setup). We have also ensured then when testing the server was not handling any other loads. I have written a simple test application (test_threads.py - attached, or refer to http://pastebin.com/xGQU7JD0) that simulates the issues we are seeing by starting up threads that loops, sleeping for a user defined time on each loop. It takes 2 parameters, the amount of threads to start and the interval period. When I run, "python test_threads.py 50 0.1" for about 10 minutes Load average results: StormOnDemand: $ uptime 18:46:22 up 7:29, 6 users, load average: 4.43, 4.16, 2.93 voxel.net $ uptime 18:48:14 up 9 days, 15:09, 9 users, load average: 0.51, 0.47, 0.43 The load average on the StormOnDemand server is a lot higher. Python version: StormOnDemand - 2.6.5 Voxel - 2.6.5 Server spec: StormOnDemand - 8 x Intel(R) Xeon(R) CPU E5506 @ 2.13GHz; 16GB RAM; 230GB HDD (Storm Bare Metal servers) Voxel - 7 x Intel(R) Xeon(R) CPU L5640 @ 2.27GHz; 14GB RAM; 200GB HDD (VoxCloud servers) OS: StormOnDemand - Ubuntu 10.04 - 2.6.36-rc8101910 #1 SMP Tue Oct 19 19:18:34 UTC 2010 x86_64 GNU/Linux Voxel - Ubuntu 10.04 - 2.6.32-31-server #61-Ubuntu SMP Fri Apr 8 19:44:42 UTC 2011 x86_64 GNU/Linux Virtualisation method: StormOnDemand - Not 100% sure, but I think they use Xen Voxel - Not sure, but the image that we are using looks to us like a stock standard Ubuntu 10.04 server Any suggestion on why the load would be a lot higher or how I could debug this further is greatly appreciated. -- Mohan -------------- next part -------------- A non-text attachment was scrubbed... Name: test_threads.py Type: text/x-python Size: 1560 bytes Desc: not available URL: From dan.kluev at gmail.com Tue May 31 07:32:25 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 22:32:25 +1100 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> Message-ID: On Tue, May 31, 2011 at 8:40 AM, Wolfgang Meiners wrote: > metadata = MetaData('sqlite://') > a_table = Table('tf_lehrer', metadata, > ? ?Column('id', Integer, primary_key=True), > ? ?Column('Kuerzel', Text), > ? ?Column('Name', Text)) Use UnicodeText instead of Text. > A_record = A_class('BUM', 'B?umer') If this is python2.x, use u'B?umer' instead. -- With best regards, Daniel Kluev From nobody at nowhere.net.no Tue May 31 07:33:03 2011 From: nobody at nowhere.net.no (TheSaint) Date: Tue, 31 May 2011 19:33:03 +0800 Subject: How to catch a line with Popen References: Message-ID: Chris Torek wrote: > Since it is a generator that only requests another line when called, > it should be fine Is it, then, that until the new itaration, the callee is on pause? -- goto /dev/null From jpiitula at ling.helsinki.fi Tue May 31 08:15:21 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 31 May 2011 15:15:21 +0300 Subject: Something is rotten in Denmark... References: Message-ID: Thomas Rachel writes: > Am 31.05.2011 12:08 schrieb Jussi Piitulainen: > > > The same sharing-an-i thing happens here: > > > >>>> fs = [] > >>>> for i in range(4): > > ... fs.append(lambda n : i + n) > > ... > >>>> fs[0](0) > > 3 > > > > And the different private-j thing happens here: > > > >>>> gs = [] > >>>> for i in range(4): > > ... gs.append((lambda j : lambda n : j + n)(i)) > > ... > >>>> gs[0](0) > > 0 > > There is a simpler way: with > > >>>> fs = [] > >>>> for i in range(4): > > ... fs.append(lambda n, i=i: i + n) > > ... > > you give each lambda a different default argument. > > >>>> fs[0](0) > > 0 I know, and harrismh777 knows. I find it an unnecessary distraction when explaining why the different closures in the initial example behave identically, but I did discuss it at the end of my post. From saranyamsamy at gmail.com Tue May 31 09:46:28 2011 From: saranyamsamy at gmail.com (success all) Date: Tue, 31 May 2011 06:46:28 -0700 (PDT) Subject: HOT CINEMA NEWS AND ACTRESS STORYS AVAILABLE CLICK HERE Message-ID: http://startamilcinema.blogspot.com/ http://startamilcinema.blogspot.com/ http://startamilcinema.blogspot.com/ http://startamilcinema.blogspot.com/ http://startamilcinema.blogspot.com/ From rosuav at gmail.com Tue May 31 10:22:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 00:22:07 +1000 Subject: Load averages and Python threads on different Linux cloud provider setup In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 9:25 PM, Mohanaraj Gopala Krishnan wrote: > Any suggestion on why the load would be a lot higher or how I could > debug this further is greatly appreciated. > First off, an easy question: Is system load low and comparable on both systems when this script is _not_ running? Chris Angelico From bruno.desthuilliers at gmail.com Tue May 31 10:28:43 2011 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 31 May 2011 07:28:43 -0700 (PDT) Subject: BadValueError: Property title is required References: <8106c94d-04f5-4b36-a7dc-be3cff7fecff@b42g2000yqi.googlegroups.com> Message-ID: <25b882f1-b921-4b3c-a3e0-a7b7c248329d@s16g2000prf.googlegroups.com> On May 31, 10:32?am, Chris Rebert wrote: > On Tue, May 31, 2011 at 1:21 AM, michal.bulla wrote: > > Hello, > > > I'm trying to create simple method to create category. I set the model > > category: > > > class Category(db.Model): > > ?title = db.StringProperty(required=True) > > ?clashes_count = db.IntegerProperty(default=0) > > Not "obviously" Django at all. > > The problem is that I'm getting an error BadValueError: Property title > > is required. Can you help me with that ? Thanks > > Try asking on the Django mailing list:http://groups.google.com/group/django-users Arf ! I just told the guy he was on the wrong group when he (re?)posted this on django-users. From neilc at norwich.edu Tue May 31 10:47:19 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 31 May 2011 14:47:19 GMT Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: <94kdbmFi80U2@mid.individual.net> On 2011-05-28, Roy Smith wrote: > One reasonable definition of a bug is something the code > actually does which differs from the documented interface. > Unless you know what the code is supposed to do, how can you > possibly look at it and say whether it has a bug or not? For > example, take this function: > > def foo(): > l = [1, 2, 3] > return l[3] > > Is this code correct? I'll bet most people would look at this > and say, "I'm not sure what he had in mind, but whatever it > was, this has to be a bug because he's indexing past the end of > the list". Well, what if I showed you the interface contract: > > def foo(): > "Raise IndexError. This is useful as a testing fixture." > l = [1, 2, 3] > return l[3] > > Now it's obvious that the function does exactly what it's > supposed to do (even if it's not the best way to do it). That's an excellent illustration of bad code hid by a bad comment. Perhaps better: def foo(): raise IndexError() -- Neil Cerutti From WolfgangMeiners01 at web.de Tue May 31 11:45:01 2011 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Tue, 31 May 2011 17:45:01 +0200 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> Am 31.05.11 13:32, schrieb Daniel Kluev: > On Tue, May 31, 2011 at 8:40 AM, Wolfgang Meiners > wrote: >> metadata = MetaData('sqlite://') >> a_table = Table('tf_lehrer', metadata, >> Column('id', Integer, primary_key=True), >> Column('Kuerzel', Text), >> Column('Name', Text)) > > Use UnicodeText instead of Text. > >> A_record = A_class('BUM', 'B?umer') > > If this is python2.x, use u'B?umer' instead. > > Thank you Daniel. So i came a little bit closer to the solution. Actually i dont write the strings in a python program but i read them from a file, which is utf8-encoded. So i changed the lines for line in open(file,'r'): line = line.strip() first to for line in open(file,'r'): line = unicode(line.strip()) and finally to for line in open(file,'r'): line = unicode(line.strip(),'utf8') and now i get really utf8-strings. It does work but i dont know why it works. For me it looks like i change an utf8-string to an utf8-string. By the way: when i run a python program from eclipse, then print sys.getdefaultencoding() returns utf-8 and when i run the same python program from the command line, then print sys.getdefaultencoding() returns ascii but my locale is set to $ locale LANG="de_DE.UTF-8" LC_COLLATE="de_DE.UTF-8" LC_CTYPE="de_DE.UTF-8" LC_MESSAGES="de_DE.UTF-8" LC_MONETARY="de_DE.UTF-8" LC_NUMERIC="de_DE.UTF-8" LC_TIME="de_DE.UTF-8" LC_ALL="de_DE.UTF-8" I think, utf8 is somewhat confusing in python - at least to me. Wolfgang From WolfgangMeiners01 at web.de Tue May 31 11:47:14 2011 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Tue, 31 May 2011 17:47:14 +0200 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4de50d82$0$6538$9b4e6d93@newsspool4.arcor-online.net> Am 31.05.11 11:55, schrieb Chris Withers: > Hi Wolfgang, > > On 30/05/2011 22:40, Wolfgang Meiners wrote: >> I am trying to build an application using sqlalchemy. > > You're likely to get much better help here: > > http://www.sqlalchemy.org/support.html#mailinglist > > When you post there, make sure you include: > > - what python version you're using > - what sqlalchemy version you're using > > cheers, > > Chris > Thank you for pointing me to this list. I will have a look to it. At the moment i think i am really struggeling with python and uft8. Wolfgang From tjreedy at udel.edu Tue May 31 11:59:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 May 2011 11:59:21 -0400 Subject: scope of function parameters (take two) In-Reply-To: References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: On 5/31/2011 2:37 AM, Henry Olders wrote: > what I want is a function that is free of side effects back through > the parameters passed in the function call. You can get that by refraining from mutating parameter objects. Simple as that. Just do not expect Python to enforce that discipline on everyone else. To be really functional, and never mutate objects, do not use Python lists, which are arrays. Use linked-list trees, like Lisp languages and perhaps others do. One can easily do this with tuples, or a subclass of tuples, or a class wrapping tuples. Linked-lists and functional programming go together because prepending to a linked list creates a new object while appending to a Python list mutates an existing list. Similarly, popping from a linked list retrieves an item and an existing sublist while popping from a Python list retrieves and item and mutates the list. -- Terry Jan Reedy From WolfgangMeiners01 at web.de Tue May 31 12:10:43 2011 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Tue, 31 May 2011 18:10:43 +0200 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4de51303$0$6557$9b4e6d93@newsspool4.arcor-online.net> I just found a second method on http://docs.python.org/howto/unicode you can use tho module codecs and then simply write import codecs f = codecs.open('unicode.rst', encoding='utf-8') for line in f: print repr(line) Wolfgang From tjreedy at udel.edu Tue May 31 12:15:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 May 2011 12:15:21 -0400 Subject: scope of function parameters (take two) In-Reply-To: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On 5/31/2011 3:17 AM, Henry Olders wrote: > Clearly, making a copy within the function eliminates the possibility of > the side effects caused by passing in mutable objects. Mutable objects and mutating methods and functions are a *feature* of Python. If you do not like them, do not use them. > Would having the compiler/interpreter do this automatically > make python so much different? Yes. How would you then write a function like list.sort or list.pop? It is fundamental that parameters are simply local names that must be bound as part of the calling process. After that, they are nothing special. Python is a language for adults that take responsibility for what they do. If you do not like argument-mutating functions, then do not write them and do not use them (without making a copy yourself). Python was not designed to model timeless immutable mathematics. It is an information-object manipulation language and in real life, we mutate collections and associations all the time. -- Terry Jan Reedy From ian.g.kelly at gmail.com Tue May 31 12:16:12 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 10:16:12 -0600 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 1:38 AM, Daniel Kluev wrote: > @decorator.decorator > def copy_args(f, *args, **kw): > ? ?nargs = [] > ? ?for arg in args: > ? ? ? ?nargs.append(copy.deepcopy(arg)) > ? ?nkw = {} > ? ?for k,v in kw.iteritems(): > ? ? ? ?nkw[k] = copy.deepcopy(v) > ? ?return f(*nargs, **nkw) There is no "decorator" module in the standard library. This must be some third-party module. The usual way to do this would be: def copy_args(f): @functools.wraps(f) def wrapper(*args, **kw): nargs = map(copy.deepcopy, args) nkw = dict(zip(kw.keys(), map(copy.deepcopy, kw.values()))) return f(*nargs, **nkw) return wrapper Note that this will always work, whereas the "decorator.decorator" version will break if the decorated function happens to take a keyword argument named "f". Cheers, Ian From ramit.prasad at jpmchase.com Tue May 31 12:31:36 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Tue, 31 May 2011 12:31:36 -0400 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2E33300F5D@EMARC112VS01.exchad.jpmchase.net> >line = unicode(line.strip(),'utf8') >and now i get really utf8-strings. It does work but i dont know why it works. For me it looks like i change an utf8-string to an utf8-string. I would like to point out that UTF-8 is not exactly "Unicode". From what I understand, Unicode is a standard while UTF-8 is like an implementation of that standard (called an encoding). Being able to convert to Unicode (the standard) should mean you are then able to convert to any encoding that supports the Unicode characters used. As you can see below a string in UTF-8 is actually not Unicode. (decode converts to Unicode, encode converts away from Unicode) >>> type(u'test'.encode('utf8')) >>> type('test'.decode('utf8')) >>> type('test'.encode('utf8')) >>> type(u'test') Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From ckaynor at zindagigames.com Tue May 31 12:34:34 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 31 May 2011 09:34:34 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 9:16 AM, Ian Kelly wrote: > On Tue, May 31, 2011 at 1:38 AM, Daniel Kluev wrote: > > @decorator.decorator > > def copy_args(f, *args, **kw): > > nargs = [] > > for arg in args: > > nargs.append(copy.deepcopy(arg)) > > nkw = {} > > for k,v in kw.iteritems(): > > nkw[k] = copy.deepcopy(v) > > return f(*nargs, **nkw) > > There is no "decorator" module in the standard library. This must be > some third-party module. The usual way to do this would be: > > def copy_args(f): > @functools.wraps(f) > def wrapper(*args, **kw): > nargs = map(copy.deepcopy, args) > nkw = dict(zip(kw.keys(), map(copy.deepcopy, kw.values()))) > return f(*nargs, **nkw) > return wrapper > > Is there any reason not to simplify this to: def copy_args(f): @functools.wraps(f) def wrapper(*args, **kw): nargs = copy.deepcopy(args) nkw = copy.deepcopy(kw) return f(*nargs, **nkw) return wrapper It means you will copy the keys as well, however they will (almost) certainly be strings which is effectively a no-op. > Note that this will always work, whereas the "decorator.decorator" > version will break if the decorated function happens to take a keyword > argument named "f". > > Cheers, > Ian > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Tue May 31 12:42:45 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 31 May 2011 09:42:45 -0700 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On Tue, May 31, 2011 at 8:45 AM, Wolfgang Meiners wrote: > Am 31.05.11 13:32, schrieb Daniel Kluev: >> On Tue, May 31, 2011 at 8:40 AM, Wolfgang Meiners >> wrote: >>> metadata = MetaData('sqlite://') >>> a_table = Table('tf_lehrer', metadata, >>> ? ?Column('id', Integer, primary_key=True), >>> ? ?Column('Kuerzel', Text), >>> ? ?Column('Name', Text)) >> >> Use UnicodeText instead of Text. >> >>> A_record = A_class('BUM', 'B?umer') >> >> If this is python2.x, use u'B?umer' instead. >> >> > > Thank you Daniel. > So i came a little bit closer to the solution. Actually i dont write the > strings in a python program but i read them from a file, which is > utf8-encoded. > > So i changed the lines > > ? ?for line in open(file,'r'): > ? ? ? ?line = line.strip() > > first to > > ? ?for line in open(file,'r'): > ? ? ? ?line = unicode(line.strip()) > > and finally to > > ? ?for line in open(file,'r'): > ? ? ? ?line = unicode(line.strip(),'utf8') > > and now i get really utf8-strings. It does work but i dont know why it > works. For me it looks like i change an utf8-string to an utf8-string. > There's no such thing as a UTF-8 string. You have a list of bytes (byte string) and you have a list of characters (unicode). UTF-8 is a function that can convert bytes into characters (and the reverse). You may recognize that the list of bytes was encoded using UTF-8 but the computer does not unless you explicitly tell it to. Does that help clear it up? From rustompmody at gmail.com Tue May 31 12:46:19 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 31 May 2011 09:46:19 -0700 (PDT) Subject: scope of function parameters References: Message-ID: <0ae4faae-35ff-403d-944c-5e620a37b326@y27g2000prb.googlegroups.com> On May 29, 1:30?pm, Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a program. The made-up code snippet below illustrates the problem I encountered: > > def main(): > ? ? ? ? a = ['a list','with','three elements'] > ? ? ? ? print a > ? ? ? ? print fnc1(a) > ? ? ? ? print a > > def fnc1(b): > ? ? ? ? return fnc2(b) > > def fnc2(c): > ? ? ? ? c[1] = 'having' > ? ? ? ? return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same output as the first, but variable a had been changed by changing variable c in fnc2. > > It seems that in Python, a variable inside a function is global unless it's assigned. This rule has apparently been adopted in order to reduce clutter by not having to have global declarations all over the place. > > I would have thought that a function parameter would automatically be considered local to the function. It doesn't make sense to me to pass a global to a function as a parameter. > > One workaround is to call a function with a copy of the list, eg in fnc1 I would have the statement "return fnc2(b[:]". But this seems ugly. > > Are there others who feel as I do that a function parameter should always be local to the function? Or am I missing something here? > > Henry You want a functional language. You can simulate that in python by using tuples in place of lists. fnc2(c): c[1] = 'having' return c will of course then give you an error that tuples are not assignable (which seems to be what you want?) So you then use (something like) fnc2(c): return c[0:1] + c[2:] From mohangk at gmail.com Tue May 31 12:53:52 2011 From: mohangk at gmail.com (Mohan) Date: Tue, 31 May 2011 09:53:52 -0700 (PDT) Subject: Load averages and Python threads on different Linux cloud provider setup References: Message-ID: On May 31, 10:22?pm, Chris Angelico wrote: > On Tue, May 31, 2011 at 9:25 PM, Mohanaraj Gopala Krishnan > > wrote: > > Any suggestion on why the load would be a lot higher or how I could > > debug this further is greatly appreciated. > > First off, an easy question: Is system load low and comparable on both > systems when this script is _not_ running? Yes, they both are are < 0.5 (for all averages) and comparable. > > Chris Angelico From python at mrabarnett.plus.com Tue May 31 12:59:56 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 31 May 2011 17:59:56 +0100 Subject: Beginner needs advice In-Reply-To: <87wrh7774d.fsf@benfinney.id.au> References: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> <87wrh7774d.fsf@benfinney.id.au> Message-ID: <4DE51E8C.3060705@mrabarnett.plus.com> On 31/05/2011 06:48, Ben Finney wrote: > Dennis Lee Bieber writes: > >> Well... He did say "find the bathroom", not ask for directions to >> whatever euphemism is in current usage (water closet, W/C, loo ?) > > The room which contains the bath is the bathroom. > > Assuming that the toilet is in the same room as the bath is parochial. > > If he wants the toilet, ?bathroom? is a euphemism, and he should instead > ask for directions to the toilet. > "Toilet" is also a euphemism, as are "water closet", "WC", "loo", etc. From mister270 at gmail.com Tue May 31 13:02:48 2011 From: mister270 at gmail.com (Mike) Date: Tue, 31 May 2011 10:02:48 -0700 (PDT) Subject: nosend missing in suds 0.4? Message-ID: Looks like the nosend attribute is not available in 0.4. Any reason for this? Any plans to add it back and what is the most recent release that does have the nosend option? From ian.g.kelly at gmail.com Tue May 31 13:10:58 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 11:10:58 -0600 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 10:34 AM, Chris Kaynor wrote: > Is there any reason not to simplify this to: > def copy_args(f): > ? ?@functools.wraps(f) > ? ?def wrapper(*args, **kw): > ? ? ? ?nargs = copy.deepcopy(args) > ? ? ? ?nkw = copy.deepcopy(kw) > ? ? ? ?return f(*nargs, **nkw) > ? ?return wrapper No reason, good call. > It means you will copy the keys as well, however they will (almost) > certainly be strings which is effectively a no-op. I think the keys will certainly be strings. Is there any scenario where they might not be? From tjreedy at udel.edu Tue May 31 13:11:43 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 May 2011 13:11:43 -0400 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: On 5/31/2011 2:48 AM, harrismh777 wrote: >>>> fs=[] Irrelevant here since you immediately rebind 'fs'. >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] Same as [f(1) for f in fs] > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good > > ( that was a big surprise! . . . ) You have been hypnotizeed by lambda. (lambda n: i+n) is a *constant expression*, so you get 10 'equal' functions. To see this better fs = [(lambda n: i + n) for i in range(10)] from dis import dis for f in fs: dis(f) 1 0 LOAD_DEREF 0 (i) 3 LOAD_FAST 0 (n) 6 BINARY_ADD 7 RETURN_VALUE 1 0 LOAD_DEREF 0 (i) 3 LOAD_FAST 0 (n) 6 BINARY_ADD 7 RETURN_VALUE ... All have the same bytecode and all retrieve the same last value of i in the nonlocal listcomp scope when you call them *after* the listcomp scope has otherwise disappeared. Your code is equivalent to fs = [] for i in range(10): fs.append(lambda n: i + n) print([f(1) for f in fs]) which is equivalent (except for naming the functions) to fs = [] for i in range(10): def f(n): return i + n fs.append(f) print([f(1) for f in fs]) Does [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] still surprise? Because the def is a constant expression, we can move it out of the loop, and get the equivalent (except for identity) def f(n): return i + n fs = [] for i in range(10): fs.append(f) print([f(1) for f in fs]) This in turn is equivalent to def f(n): return i + n fs = [] for _ in range(10): fs.append(f) i=9 print([f(1) for f in fs]) which in turn is equivalent in output to def f(n): return i + n i = 9 print([f(1) for _ in range(10)]) Note that: def f(n): return i+n # or f = lambda n: i+n fs = [f for i in range(10)] print([f(1) for f in fs]) works in 2.7, with the same output, but not in 3.2 because in 3.x, i is local to the list comp and the later call raises unbound global error. > ( let's try it another way . . . ) All these other ways create 10 *different* (unequal) functions that are different because they have captured 10 different values of i when defined instead of deferring lookup of i to when they are called. def g(i): return (lambda n: i + n) fs = [g(i) for i in range(10)] print([f.__closure__[0].cell_contents for f in fs]) fs = [(lambda n, i=i: i + n) for i in range(10)] print([f.__defaults__[0] for f in fs]) # CPython 3.2 dependent code !!! [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] -- Terry Jan Reedy From rosuav at gmail.com Tue May 31 13:19:52 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 03:19:52 +1000 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2E33300F5D@EMARC112VS01.exchad.jpmchase.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> <0604E20B5F6F2F4784C9C8C71C5DD4DD2E33300F5D@EMARC112VS01.exchad.jpmchase.net> Message-ID: On Wed, Jun 1, 2011 at 2:31 AM, Prasad, Ramit wrote: >>line = unicode(line.strip(),'utf8') >>and now i get really utf8-strings. It does work but i dont know why it works. For me it looks like i change an utf8-string to an utf8-string. > > > I would like to point out that UTF-8 is not exactly "Unicode". From what I understand, Unicode is a standard while UTF-8 is like an implementation of that standard (called an encoding). Being able to convert to Unicode (the standard) should mean you are then able to convert to any encoding that supports the Unicode characters used. Unicode defines characters; UTF-8 is one way (of many) to represent those characters in bytes. UTF-16 and UTF-32 are other ways of representing those characters in bytes, and internally, Python probably uses one of them - but there is no guarantee, and you should never need to know. Unicode strings can be stored in memory and manipulated in various ways, but they're a high level construct on par with lists and dictionaries - they can't be stored on disk or transmitted to another computer without using an encoding system. UTF-8 is an efficient way to translate Unicode text consisting primarily of low codepoint characters into bytes. It's not so much an implementation of Unicode as a means of converting a mythical concept of "Unicode characters" into a concrete stream of bytes. Hope that clarifies things a little! Chris Angelico From rustompmody at gmail.com Tue May 31 13:33:39 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 31 May 2011 10:33:39 -0700 (PDT) Subject: scope of function parameters References: <0ae4faae-35ff-403d-944c-5e620a37b326@y27g2000prb.googlegroups.com> Message-ID: <97dd84e0-c164-4d5e-a485-0fb356eece3a@34g2000pru.googlegroups.com> On May 31, 9:46?pm, rusi wrote: > So you then use (something like) > > fnc2(c): ?return c[0:1] + c[2:] Er sorry -- that should have been def fnc2(c): return c[0:1] + ('having',) + c[2:] From dotancohen at gmail.com Tue May 31 13:56:39 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 31 May 2011 20:56:39 +0300 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: > ?If you disagree, then I invite you to list one example of two > different things that are compatible. > Men and women. MS Office and Open Office. IE6 and HTML. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From ian.g.kelly at gmail.com Tue May 31 14:29:14 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 12:29:14 -0600 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: On Tue, May 31, 2011 at 11:56 AM, Dotan Cohen wrote: >> ?If you disagree, then I invite you to list one example of two >> different things that are compatible. >> > > Men and women. This is a slightly different sense of the word compatible than we have been discussing: able to work together to perform a function, not interchangeable. > MS Office and Open Office. Nope. Remember, the assertion by harrismh777 was that "all you have to do to prove incompatibility is to show 'one' (1) test case where compatibility fails". As one example, any Calc document that uses the EASTERSUNDAY function will fail in Excel, since Excel does not provide it. I could easily come up with other examples (let's not even get into the differences in macros), but one is all I need. > IE6 and HTML. :-) From dotancohen at gmail.com Tue May 31 14:42:26 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 31 May 2011 21:42:26 +0300 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: On Tue, May 31, 2011 at 21:29, Ian Kelly wrote: > On Tue, May 31, 2011 at 11:56 AM, Dotan Cohen wrote: >>> ?If you disagree, then I invite you to list one example of two >>> different things that are compatible. >>> >> >> Men and women. > > This is a slightly different sense of the word compatible than we have > been discussing: able to work together to perform a function, not > interchangeable. > >> MS Office and Open Office. > > Nope. ?Remember, the assertion by harrismh777 was that "all you have > to do to prove incompatibility is to show 'one' (1) test case where > compatibility fails". ?As one example, any Calc document that uses the > EASTERSUNDAY function will fail in Excel, since Excel does not provide > it. ?I could easily come up with other examples (let's not even get > into the differences in macros), but one is all I need. > >> IE6 and HTML. > > :-) > Ian, I'm surprised, you of all people might have noticed that my sarcasm was intended to point out exactly that no two things are compatible, least of all those things designed with compatibility as a design spec! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From WolfgangMeiners01 at web.de Tue May 31 15:52:24 2011 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Tue, 31 May 2011 21:52:24 +0200 Subject: Thanks for all responses In-Reply-To: <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4de546f8$0$6556$9b4e6d93@newsspool4.arcor-online.net> I think it helped me very much to understand the problem. So if i deal with nonascii strings, i have a 'list of bytes' and need an encoding to interpret this list and transform it to a meaningful unicode string. Decoding does the opposite. Whenever i 'cross the border' of my program, i have to encode the 'list of bytes' to an unicode string or decode the unicode string to a 'list of bytes' which is meaningful to the world outside. So encode early, decode lately means, to do it as near to the border as possible and to encode/decode i need a coding system, for example 'utf8' That means, there should be an encoding/decoding possibility to every interface i can use: files, stdin, stdout, stderr, gui (should be the most important ones). While trying to understand this, i wrote the following program. Maybe someone can give me a hint, how to print correctly: ###################################################### #! python # -*- coding: utf-8 -*- class EncTest: def __init__(self,Name=None): self.Name=unicode(Name, encoding='utf8') def __repr__(self): return u'My name is %s' % self.Name if __name__ == '__main__': a = EncTest('M?ller') # this does work print a.__repr__() # throws an error if default encoding is ascii # but works if default encoding is utf8 print a # throws an error because a is not a string print unicode(a, encoding='utf8') ###################################################### Wolfgang From ethan at stoneleaf.us Tue May 31 16:00:19 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 31 May 2011 13:00:19 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: <4DE548D3.1010101@stoneleaf.us> Henry Olders wrote: > [...] what I want is a function that is free of side effects [...] Shoot, that's easy! Just write your function to not have any! ~Ethan~ From ethan at stoneleaf.us Tue May 31 16:01:48 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 31 May 2011 13:01:48 -0700 Subject: scope of function parameters (take two) In-Reply-To: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: <4DE5492C.8020300@stoneleaf.us> Henry Olders wrote: > Clearly, making a copy within the function eliminates the possibility of > the side effects caused by passing in mutable objects. Would having the > compiler/interpreter do this automatically make python so much > different? It would be a different language. ~Ethan~ From harrismh777 at charter.net Tue May 31 16:18:37 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 31 May 2011 15:18:37 -0500 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: Terry Reedy wrote: > You have been hypnotizeed by lambda. (lambda n: i+n) is a *constant > expression*, so you get 10 'equal' functions. 'hypnotized' indeed! ... ok, so let me see if I get this... the lambda defers lookup|bind of its references until such time as the lambda is 'called' and not at the time (as I thought) that the anonymous function(s) are returned? If I'm understanding that correctly, then that means lambda is working as designed, and that there are very subtle nuances to be aware of. In my little case (lambda n: i + n) ... if the i goes out of scope before the anonymous function gets called then we have a problem... or if i as a reference is mutable or refers to a different object before the anonymous function is called then we have a problem? What I am discovering is that 'yes' I can use lambda syntactically where I might not be able to code a def statement; however, if I do use it (as in a list comprehension) then I may get unexpected results if any of my lambda's references go out of scope or are mutable...(?) Question: What are the ramifications of making the lookup|binding happen at the time the anonymous function is 'returned' vs 'called'? Has anyone suggested this? Is this PEP-able....? Are there side-effects in the other direction? PS Thanks Chris, Ian, Jussi, Thomas, Terry... I appreciate your teaching and patience ! kind regards, m harris From ckaynor at zindagigames.com Tue May 31 16:28:54 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 31 May 2011 13:28:54 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: I was thinking you could do something strange like: kw = {object(): None} def test(**kw): print kw test(**kw) however, upon testing it (in Python 2.6), I found that it errors while trying to unpack the kw dict stating that they must all be strings. Perhaps making a custom class derived off basestring, str, unicode, or bytes might allow some oddness and possibly slightly worse performance. Chris On Tue, May 31, 2011 at 10:10 AM, Ian Kelly wrote: > On Tue, May 31, 2011 at 10:34 AM, Chris Kaynor > wrote: > > Is there any reason not to simplify this to: > > def copy_args(f): > > @functools.wraps(f) > > def wrapper(*args, **kw): > > nargs = copy.deepcopy(args) > > nkw = copy.deepcopy(kw) > > return f(*nargs, **nkw) > > return wrapper > > No reason, good call. > > > It means you will copy the keys as well, however they will (almost) > > certainly be strings which is effectively a no-op. > > I think the keys will certainly be strings. Is there any scenario > where they might not be? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmanns at gmx.net Tue May 31 17:14:56 2011 From: mmanns at gmx.net (Martin Manns) Date: Tue, 31 May 2011 23:14:56 +0200 Subject: Something is rotten in Denmark... References: Message-ID: <20110531231456.44d388d7@Fuddel> On Tue, 31 May 2011 01:48:05 -0500 harrismh777 wrote: > >>> fs=[] > >>> fs = [(lambda n: i + n) for i in range(10)] > >>> [fs[i](1) for i in range(10)] > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good > > ( that was a big surprise! . . . ) > ( let's try it another way . . . ) After being confused I figured out it is a 3.x example: ---- $ python Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> fs=[] >>> fs = [(lambda n: i + n) for i in range(10)] >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ---- $ python3.1 Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> fs=[] >>> fs = [(lambda n: i + n) for i in range(10)] >>> [fs[i](1) for i in range(10)] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] ---- Is this fixed automatically by 2to3? Martin From ericsnowcurrently at gmail.com Tue May 31 17:46:49 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 31 May 2011 15:46:49 -0600 Subject: returning NotImplemented Message-ID: Looking at the ABC code [1], I noticed that Mapping's __eq__ method can return NotImplemented. This got me curious as to why you would return NotImplemented and not raise a TypeError or a NotImplementedError. There was an issue regarding this last year [2] that indicated the reason for Mapping's behavior. Also, I found a thread from python-dev [3] which talks about the use of NotImplemented (the thread relates to numeric coercion). I found some older documentation on informal coercion guidelines that helped [4]. My understanding is that NotImplemented is used for binary operators: the right hand side of the operator should be tried if the left hand side returns NotImplemented. So it's more like DoNotKnowHowToHandleArgumentOfThatType. I think the name may have added to my confusion. (BTW, I learned that NotImplemented is a singleton, like None). Is binary operators the only place that NotImplemented is used under the hood? Is it all binary operators, and if not, where does it say which operators use NotImplemented? This would have bearing on when I would need to return it. In the python-dev thread [3], MRAB indicates NotImplemented is used instead of exceptions for performance reasons. Is raising NotImplementedError or TypeError that big a difference? I expect if you are using the operator on a large loop it could matter, but how much? Guido indicates earlier in the thread that NotImplemented is used so that you know that it came from the function that you directly called, and not from another call inside that function. Why does it matter if it came directly from the function or not? And couldn't the NotImplemented still have come from a call inside the operator, rather than directly? As an aside, don't we have that same situation all over the place. For instance, using __getattribute__, how do you know if an AttributeError means that the attribute was not found on the object? It could mean that __getattribute__ called something that raised the exception (and perhaps it should have handled it). Does it matter? Is there a good way to tell the difference, or would it be good practice to always handle explicitly in a function any exception type that you may be raising there? Thanks, -eric [1] http://hg.python.org/cpython/file/29e08a98281d/Lib/collections/abc.py#l398 [2] http://bugs.python.org/issue8729 [3] http://mail.python.org/pipermail/python-dev/2005-March/051835.html [4] http://docs.python.org/release/2.5.2/ref/coercion-rules.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 31 17:47:33 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 15:47:33 -0600 Subject: Something is rotten in Denmark... In-Reply-To: <20110531231456.44d388d7@Fuddel> References: <20110531231456.44d388d7@Fuddel> Message-ID: On Tue, May 31, 2011 at 3:14 PM, Martin Manns wrote: > $ python > Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> fs=[] >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] This works by accident. >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> [fs[0](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> [f(1) for f in fs] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] The i variable is part of the global scope, and as you iterate over range(10) again it coincidentally takes on the same values as in the original list comprehension. You don't see this in Python 3 because the scope of i is limited to the list comprehension, not global. Cheers, Ian From harrismh777 at charter.net Tue May 31 17:53:13 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 31 May 2011 16:53:13 -0500 Subject: Something is rotten in Denmark... In-Reply-To: <20110531231456.44d388d7@Fuddel> References: <20110531231456.44d388d7@Fuddel> Message-ID: Martin Manns wrote: > After being confused I figured out it is a 3.x example: Actually, it is a compatibility example between 2.x and 3.x, compare below for different behavior from two seemingly identical compatible constructs, one from 3.2, and the other from 2.6.4: > Python 3.2 (r32:88445, Mar 29 2011, 21:33:57) > [GCC 4.3.3] on linux2 >>>> fs=[] >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=========== compare >>>> > Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) > [GCC 4.4.1] on linux2 >>>> fs=[] >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] <=========== compare >>>> Having compared the two, someone please tell me whether the two are incompatible, mostly compatible, completely incompatible, or different languages... ,.,, I realize how 3.2 is working (at the moment) but as compared with the books, and the behavior of 2.6, it sure looks 'broke' to me... ... why would we want to defer lookup of the 'i' in range(10) until the anonymous function is called, instead of the time that the function object is returned... inquiring minds want to know... PS Ian calls the second construct "working by mistake..." kind regards, m harris From ericsnowcurrently at gmail.com Tue May 31 17:55:45 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 31 May 2011 15:55:45 -0600 Subject: returning NotImplemented In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 3:46 PM, Eric Snow wrote: > Looking at the ABC code [1], I noticed that Mapping's __eq__ method can > return NotImplemented. This got me curious as to why you would return > NotImplemented and not raise a TypeError or a NotImplementedError. > > There was an issue regarding this last year [2] that indicated the reason > for Mapping's behavior. Also, I found a thread from python-dev [3] which > talks about the use of NotImplemented (the thread relates to numeric > coercion). I found some older documentation on informal coercion guidelines > that helped [4]. My understanding is that NotImplemented is used for binary > operators: the right hand side of the operator should be tried if the left > hand side returns NotImplemented. So it's more like > DoNotKnowHowToHandleArgumentOfThatType. I think the name may have added to > my confusion. (BTW, I learned that NotImplemented is a singleton, like > None). > > Is binary operators the only place that NotImplemented is used under the > hood? Is it all binary operators, and if not, where does it say which > operators use NotImplemented? This would have bearing on when I would need > to return it. > > In the python-dev thread [3], MRAB indicates NotImplemented is used instead > of exceptions for performance reasons. Is raising NotImplementedError or > TypeError that big a difference? I expect if you are using the operator on > a large loop it could matter, but how much? > > Guido indicates earlier in the thread that NotImplemented is used so that > you know that it came from the function that you directly called, and not > from another call inside that function. Why does it matter if it came > directly from the function or not? And couldn't the NotImplemented still > have come from a call inside the operator, rather than directly? > > As an aside, don't we have that same situation all over the place. For > instance, using __getattribute__, how do you know if an AttributeError means > that the attribute was not found on the object? It could mean that > __getattribute__ called something that raised the exception (and perhaps it > should have handled it). Does it matter? Is there a good way to tell the > difference, or would it be good practice to always handle explicitly in a > function any exception type that you may be raising there? > > Thanks, > > -eric > > [1] > http://hg.python.org/cpython/file/29e08a98281d/Lib/collections/abc.py#l398 > [2] http://bugs.python.org/issue8729 > [3] http://mail.python.org/pipermail/python-dev/2005-March/051835.html > [4] http://docs.python.org/release/2.5.2/ref/coercion-rules.html > I'm guessing that http://docs.python.org/reference/datamodel.html is the only place in the docs that talks about the use of NotImplemented. -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 31 17:56:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 07:56:24 +1000 Subject: Thanks for all responses In-Reply-To: <4de546f8$0$6556$9b4e6d93@newsspool4.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> <4de546f8$0$6556$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On Wed, Jun 1, 2011 at 5:52 AM, Wolfgang Meiners wrote: > Whenever i 'cross the border' of my program, i have to encode the 'list > of bytes' to an unicode string or decode the unicode string to a 'list > of bytes' which is meaningful to the world outside. Most people use "encode" and "decode" the other way around; you encode a string as UTF-8, and decode UTF-8 into a Unicode string. But yes, you're correct. > So encode early, decode lately means, to do it as near to the border as > possible and to encode/decode i need a coding system, for example 'utf8' Correct on both counts. > That means, there should be an encoding/decoding possibility to every > interface i can use: files, stdin, stdout, stderr, gui (should be the > most important ones). The file objects (as returned by open()) have an encoding, which (IMHO) defaults to "utf8". GUI work depends on your GUI toolkit, and might well accept Unicode strings directly - check the docs. > ? ?def __repr__(self): > ? ? ? ?return u'My name is %s' % self.Name This means that repr() will return a Unicode string. > ? ?# this does work > ? ?print a.__repr__() > > ? ?# throws an error if default encoding is ascii > ? ?# but works if default encoding is utf8 > ? ?print a > > ? ?# throws an error because a is not a string > ? ?print unicode(a, encoding='utf8') The __repr__ function is supposed to return a string object, in Python 2. See http://docs.python.org/reference/datamodel.html#object.__repr__ for that and other advice on writing __repr__. The problems you're seeing are a result of the built-in repr() function calling a.__repr__() and then treating the return value as an ASCII str, not a Unicode string. This would work: ? ?def __repr__(self): ? ? ? ?return (u'My name is %s' % self.Name).encode('utf8') Alternatively, migrate to Python 3, where the default is Unicode strings. I tested this in Python 3.2 on Windows, but it should work on anything in the 3.x branch: class NoEnc: def __init__(self,Name=None): self.Name=Name def __repr__(self): return 'My name is %s' % self.Name if __name__ == '__main__': a = NoEnc('M?ller') # this will still work (print is now a function, not a statement) print(a.__repr__()) # this will work in Python 3.x print(a) # 'unicode' has been renamed to 'str', but it's already unicode so this makes no sense print(str(a, encoding='utf8')) # to convert it to UTF-8, convert it to a string with str() or repr() and then print: print(str(a).encode('utf8')) ############################ Note that the last one will probably not do what you expect. The Python 3 'print' function (it's not a statement any more, so you need parentheses around its argument) wants a Unicode string, so you don't need to encode it. When you encode a Unicode string as in the last example, it returns a bytes string (an array of bytes), which looks like this: b'My name is M\xc3\xbcller' The print function wants Unicode, though, so it takes this unexpected object and calls str() on it, hence the odd display. Hope that helps! Chris Angelico From harrismh777 at charter.net Tue May 31 18:06:40 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 31 May 2011 17:06:40 -0500 Subject: Something is rotten in Denmark... In-Reply-To: References: <20110531231456.44d388d7@Fuddel> Message-ID: harrismh777 wrote: > PS Ian calls the second construct "working by mistake..." oops, actually he called it, "working by accident... " From ericsnowcurrently at gmail.com Tue May 31 18:11:20 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 31 May 2011 16:11:20 -0600 Subject: returning NotImplemented In-Reply-To: <4DE56933.4050404@stoneleaf.us> References: <4DE56933.4050404@stoneleaf.us> Message-ID: On Tue, May 31, 2011 at 4:18 PM, Ethan Furman wrote: > Eric Snow wrote: > >> Looking at the ABC code [1], I noticed that Mapping's __eq__ method can >> return NotImplemented. This got me curious as to why you would return >> NotImplemented and not raise a TypeError or a NotImplementedError. >> > > My understanding is that if your object does not know how to perform the > desired action you should return NotImplemented; Python will then give the > other object a chance to perform the operation (after all, it may know how), > and if the other object also returns NotImplemented then Python itself will > raise a TypeError. > > If the first object were to raise TypeError (or any exception), the second > object would not get the chance to try. > > RIght. But the operator code could very well handle the appropriate exception instead of handling a return value of NotImplemented. Hence my further questions regarding performance and identifiability. My guess is that it's ultimately because of speed. -eric > ~Ethan~ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue May 31 18:18:27 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 31 May 2011 15:18:27 -0700 Subject: returning NotImplemented In-Reply-To: References: Message-ID: <4DE56933.4050404@stoneleaf.us> Eric Snow wrote: > Looking at the ABC code [1], I noticed that Mapping's __eq__ method can > return NotImplemented. This got me curious as to why you would return > NotImplemented and not raise a TypeError or a NotImplementedError. My understanding is that if your object does not know how to perform the desired action you should return NotImplemented; Python will then give the other object a chance to perform the operation (after all, it may know how), and if the other object also returns NotImplemented then Python itself will raise a TypeError. If the first object were to raise TypeError (or any exception), the second object would not get the chance to try. ~Ethan~ From ian.g.kelly at gmail.com Tue May 31 18:24:27 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 16:24:27 -0600 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 2:18 PM, harrismh777 wrote: > If I'm understanding that correctly, then that means lambda is working as > designed, and that there are very subtle nuances to be aware of. In my > little case > > ? (lambda n: i + n) > > ? ... if the ?i ?goes out of scope before the anonymous function gets called > then we have a problem... or if ?i ? as a reference is mutable or refers to > a different object before the anonymous function is called then we have a > problem? Actually, if i merely goes out of scope, there is no problem. It just creates a closure. It's only when the i within that scope is modified that we run into problems. In fact, in Python 3 the scope of a list comprehension variable is the list comprehension itself, so in your original post i was already out of scope by the time you started calling the lambda functions. Cheers, Ian From rosuav at gmail.com Tue May 31 18:39:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 08:39:16 +1000 Subject: Something is rotten in Denmark... In-Reply-To: References: <20110531231456.44d388d7@Fuddel> Message-ID: On Wed, Jun 1, 2011 at 7:53 AM, harrismh777 wrote: > ? ? Having compared the two, someone please tell me whether the two are > incompatible, mostly compatible, completely incompatible, or different > languages... > By implication, every version of Python is incompatible with every other. The 2.7.1 revision notes include: - Issue #1713: Fix os.path.ismount(), which returned true for symbolic links across devices. Suppose some program were depending on this bug. It works under 2.7.0, fails under 2.7.1. Does that mean that 2.7.1 is incompatible with 2.7.0? Chris Angelico From rosuav at gmail.com Tue May 31 18:40:02 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 08:40:02 +1000 Subject: Something is rotten in Denmark... In-Reply-To: References: <20110531231456.44d388d7@Fuddel> Message-ID: On Wed, Jun 1, 2011 at 8:39 AM, Chris Angelico wrote: > - Issue #1713: Fix os.path.ismount(), which returned true for symbolic links > ?across devices. PS. I know nothing about this particular issue, I just skimmed down the release notes and stopped when something caught my eye. Choose another example if you know of a better one. Chris Angelico From peterirbizon at gmail.com Tue May 31 18:44:24 2011 From: peterirbizon at gmail.com (miamia) Date: Tue, 31 May 2011 15:44:24 -0700 (PDT) Subject: hide gtk warning Message-ID: <8081ec79-c19e-4adf-9b0c-dcfde21e3b1f@hg8g2000vbb.googlegroups.com> I am getting gtkwarning: gdk_property_change: assertion window ! =Null failed gtk.main() it is gdk bug but not fixed yet.How could I simply "not show/hide" this error warning? so user should never see it. thank you From tjreedy at udel.edu Tue May 31 19:14:09 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 May 2011 19:14:09 -0400 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: On 5/31/2011 4:18 PM, harrismh777 wrote: > Terry Reedy wrote: >> You have been hypnotizeed by lambda. (lambda n: i+n) is a *constant >> expression*, so you get 10 'equal' functions. > 'hypnotized' indeed! I say 'hypnotized' ;-) because people have posted examples almost exactly like the one you did, with a list of 10 (usually) lambda-defined functions, at least yearly for over a decade. Never have I seen the same puzzlement when the functions are defined with def statements instead. What you did differently is to continue investigating and discover some of the alternatives for yourself. Hence you get more effort from others in response. I think part of the problem with lambda is this: the body of a def statement is indented and nicely set apart from surrounding code. The body of a lambda expression is prefixed by the header but there is no terminator to visually indicate the end of the nested scope. I think there should have been. I often add unneeded parens, as you did, but that is not lambda specific. Generator expressions have to be set apart with parentheses, and other comprehensions are all fenced. There also seems to be a bit of lambda (oc)cultism and mystique of the anonymous. However, if a function raises an exception, anonymity is a defect. What you did differently is to continue investigating and discover some of the alternatives for yourself. > ... ok, so let me see if I get this... the lambda > defers lookup|bind of its references until such time as the lambda is > 'called' and not at the time (as I thought) that the anonymous > function(s) are returned? In Python, there are no lambda objects to be called. A def statement, when executed, produces an instance of the user-defined function class. Its .__name__ attribute is the one given in the header of the statement. A lambda expression, when executed, produces an instance of the user-defined function class. Its .__name__ attribute is '' (at least in CPython). See the single difference? The objects produced by equivalent def statements and lambda expressions are otherwise exactly the same. statement with lambda arg-list: expression is an abbreviation for def new-name(arg-list): return expression statement with new-name assuming that the lambda in in the same scope as the statement and not nested in another scope-creating expression > If I'm understanding that correctly, then that means lambda is working > as designed, and that there are very subtle nuances to be aware of. I would say that there is no subtle nuance. Except for not providing a name, a lambda expression is purely an optional syntactic abbreviation. > In my little case > > (lambda n: i + n) > > ... if the i goes out of scope before the anonymous function gets called > then we have a problem... There was no problem; nonlocal names and their associations with objects get saved (in 'cells', for CPython) association with the function than needs them. One of my examples showed how to retrieve them. > or if i as a reference is mutable Objects are mutable, names can be rebound. > or refers to a different object before the anonymous function > is called then we have a problem? Anonymity is completely irrelevant to all of the above. Everything is the same as for def f(n): return i + n. When a function is compiled, each name is classified as local, non-local, or global. When the function is called and a name is evaluated, the corresponding object from its scope is retrieved, if there is one, or an error is raised. > What I am discovering is that 'yes' I can use lambda syntactically where > I might not be able to code a def statement; If the lambda expression is nested in an abbreviated nested scope (lambda or comprehension), then you have to unabbreviate the outer nesting before you can unabbreviate the lambda. Several example of this have been shown. > however, if I do use it (as in a list comprehension) then I may get > unexpected results if any of my > lambda's references go out of scope or are mutable...(?) Nothing needed goes out of scope and all names are rebindable (not mutable). > What are the ramifications of making the lookup|binding happen at the > time the anonymous function is 'returned' vs 'called'? This is early-binding versus late-binding. Python is a late-binding language. Are you asking about changing all function compilation or only when functions are defined with lambda expressions? The latter *would* make there be a 'suble nuance' that Python now lacks and does not need. > Has anyone suggested this? Of course, more than once, in multiple variations. All have so far been rejected, more than once. The most sensible ideas are for earlier binding of builtins to make Python run faster. You have already discovered and been given some of the solutions. Another is to define a class with a __call__ statement and save the desired early bindings as instance data attributes. Your g(i): return lambda ... as well as the default arg trick are functional equivalents of the same idea. In general, if you want to immediately grab and save an object, then explicity grab and save the object. -- Terry Jan Reedy From dan.kluev at gmail.com Tue May 31 20:04:10 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Wed, 1 Jun 2011 11:04:10 +1100 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Wed, Jun 1, 2011 at 3:16 AM, Ian Kelly wrote: > > There is no "decorator" module in the standard library. ?This must be > some third-party module. ?The usual way to do this would be: Yes, but its very useful for decorators and provides some not-readily-available functionality. http://pypi.python.org/pypi/decorator/3.3.1 > Note that this will always work, whereas the "decorator.decorator" > version will break if the decorated function happens to take a keyword > argument named "f". No, it will not. Its the magic of decorator library, it is signature-preserving, while your variant breaks function signature and causes problems to any code that relies on signatures (happens with Pylons, for example). >>> @copy_args ... def test(a, f=None): ... print f ... >>> test([], f=123) 123 Basically decorator.decorator uses exec to create new function, with signature of function you pass to your decorator, so it does not matter what names you used for args in decorator itself. -- With best regards, Daniel Kluev From harrismh777 at charter.net Tue May 31 20:09:38 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 31 May 2011 19:09:38 -0500 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: Terry Reedy wrote: > This is early-binding versus late-binding. Python is a late-binding > language. ok ... > Are you asking about changing all function compilation or only when > functions are defined with lambda expressions? At least lambda expressions, but (see below) any other built-in where 'early-binding' makes sense for intuitive results or performance--- possibly, not commenting. The latter *would* make > there be a 'suble nuance' that Python now lacks and does not need. How so, and why not? >> Has anyone suggested this? > Of course, more than once, in multiple variations. All have so far been > rejected, more than once. The most sensible ideas are for earlier > binding of builtins to make Python run faster. At the moment I'm only speaking about my OP and that particular list comprehension... the thing that happened (at least for me) is that the intuitive sense that each 'i' somehow becomes a part of the anonymous function (I know, not so) is built-in. There is little to nothing indicating in the docs that this is not so. Again, what we have here is the 'i' being saved in a cell and looked up at call time (an implementation detail, 'late-binding') that is critical for the user-coder to understand. This *may* be true for other built-ins also, I'm not commenting on that, but it seems to me that if lambda is going to remain in the language at all that 'early-binding' in the lambda specific case would make sense; at least make the lambda more useful generally. ... just saying, kind regards, m harris From ethan at stoneleaf.us Tue May 31 20:30:18 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 31 May 2011 17:30:18 -0700 Subject: returning NotImplemented In-Reply-To: References: Message-ID: <4DE5881A.7010908@stoneleaf.us> Eric Snow wrote: > Guido indicates earlier in the thread that NotImplemented is used so > that you know that it came from the function that you directly called, > and not from another call inside that function. Why does it matter if > it came directly from the function or not? And couldn't the > NotImplemented still have come from a call inside the operator, rather > than directly? An exception can bubble up from several levels below the original call. Returning NotImplemented (even if returned from another internal function) still has to be deliberately done by the original method. Later in the thread it is also stated that while exception handling performance is not too different in C code, it is very much more expensive in Python code. As to why it would matter if whether the return was from the directly called method vs some nested method... not sure, but I would hazard a guess that by returning NotImplented the interpreter knows everything worked as it should have (assuming no bugs, of course); whereas an exception could easily _not_ have come from the directly called method. Imagine if the methods raised exceptions to signal normal behavior, and some object was buggy -- for __eq__ we'd end up with a False result, instead of getting the exception propagated. (!) ~Ethan~ From chrisjames95129 at gmail.com Tue May 31 20:44:55 2011 From: chrisjames95129 at gmail.com (Christopher James) Date: Tue, 31 May 2011 17:44:55 -0700 Subject: Python hoodie Message-ID: Hi all! I LOVE Python, and want to spread the word by sporting this awesome sweater shown at: http://www.freewear.org/?page=show_item&id=FW0067 which I found by looking on the merchandise page of python.org. However, I live in the United States and before checking out I noticed that on top of the US$40 it was going to cost an additional US$45 for SHIPPING! I guess because of customs and such. Anyway, where can I get one of these sweatshirts sent to me for a reasonable shipping price in the U.S.? I would be happy to buy one and show my love for Python, but US$85 is a little steep for a hoodie for me. Cheers! Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmanns at gmx.net Tue May 31 20:57:52 2011 From: mmanns at gmx.net (Martin Manns) Date: Wed, 1 Jun 2011 02:57:52 +0200 Subject: Something is rotten in Denmark... In-Reply-To: References: <20110531231456.44d388d7@Fuddel> Message-ID: <20110601025752.676f0ec8@Fuddel> On Tue, 31 May 2011 15:47:33 -0600 Ian Kelly wrote: > The i variable is part of the global scope, and as you iterate over > range(10) again it coincidentally takes on the same values as in the > original list comprehension. You don't see this in Python 3 because > the scope of i is limited to the list comprehension, not global. I read about the scope change. However, list comprehension scope being global still feels "right" for me because I am still using Python 2. I feel that I should start worrying more about future migration issues. Cheers Martin From ian.g.kelly at gmail.com Tue May 31 21:14:26 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 19:14:26 -0600 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 6:04 PM, Daniel Kluev wrote: > On Wed, Jun 1, 2011 at 3:16 AM, Ian Kelly wrote: >> >> There is no "decorator" module in the standard library. ?This must be >> some third-party module. ?The usual way to do this would be: > > Yes, but its very useful for decorators and provides some > not-readily-available functionality. > http://pypi.python.org/pypi/decorator/3.3.1 > >> Note that this will always work, whereas the "decorator.decorator" >> version will break if the decorated function happens to take a keyword >> argument named "f". > > No, it will not. Its the magic of decorator library, it is > signature-preserving, while your variant breaks function signature and > causes problems to any code that relies on signatures (happens with > Pylons, for example). Ah, I see. I assumed it was much simpler than it is. I found a way to break it with Python 3, though: >>> @copy_args ... def test(*, f): ... return f ... >>> test(f=1) Traceback (most recent call last): File "", line 1, in File "", line 2, in test File "", line 6, in copy_args TypeError: test() needs keyword-only argument f The interesting thing here is that the decorated function has exactly the correct function signature; it just doesn't work. Cheers, Ian From ericsnowcurrently at gmail.com Tue May 31 21:28:19 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 31 May 2011 19:28:19 -0600 Subject: returning NotImplemented In-Reply-To: <4DE5881A.7010908@stoneleaf.us> References: <4DE5881A.7010908@stoneleaf.us> Message-ID: On Tue, May 31, 2011 at 6:30 PM, Ethan Furman wrote: > Eric Snow wrote: > >> Guido indicates earlier in the thread that NotImplemented is used so that >> you know that it came from the function that you directly called, and not >> from another call inside that function. Why does it matter if it came >> directly from the function or not? And couldn't the NotImplemented still >> have come from a call inside the operator, rather than directly? >> > > An exception can bubble up from several levels below the original call. > Returning NotImplemented (even if returned from another internal function) > still has to be deliberately done by the original method. > > Later in the thread it is also stated that while exception handling > performance is not too different in C code, it is very much more expensive > in Python code. > > As to why it would matter if whether the return was from the directly > called method vs some nested method... not sure, but I would hazard a guess > that by returning NotImplented the interpreter knows everything worked as it > should have (assuming no bugs, of course); whereas an exception could easily > _not_ have come from the directly called method. Imagine if the methods > raised exceptions to signal normal behavior, and some object was buggy -- > for __eq__ we'd end up with a False result, instead of getting the exception > propagated. (!) > > Thanks Ethan. That was insightful. I hadn't considered the case where we would want a TypeError or NotImplementedError or whatever to propagate. So simply catching any old exception doesn't cut it. The alternative is to have something like a CouldNotHandleTypeError that inherits just from BaseException, that is only used in the NotImplemented situation. Then the specificity resolves that problem. You're right that performance still suffers for python code, but the current NotImplemented handling stuff is in the C code that handles operators. I guess where it would hit is where you raise the Exception in the __eq__ method (or wherever), instead of returning NotImplemented. So, my understanding is that NotImplemented is sort of a special case of raising "exceptions" through return values for performance reasons, where normally we use exceptions. Here is an example of the equivalence that I am seeing: class X: def __eq__(self, other): return NotImplemented result = X().__eq__(1) if result is NotImplemented: raise TypeError - vs - class X: def __eq__(self, other): raise CouldNotHandleTypeError try: result = X().__eq__(1) except CouldNotHandleTypeError: raise TypeError I'm fine with this. It's probably one of those practicality beats purity things. And at the C level it's practically the same thing. As I have thought about this I've realized that it's really isolated to a specific place, namely operator handling for numeric and comparison operators, so no big deal. -eric ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Tue May 31 22:17:50 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 31 May 2011 21:17:50 -0500 Subject: Sanitizing filename strings across platforms Message-ID: <4DE5A14E.5090009@tim.thechases.com> Scenario: a file-name from potentially untrusted sources may have odd filenames that need to be sanitized for the underlying OS. On *nix, this generally just means "don't use '/' or \x00 in your string", while on Win32, there are a host of verboten characters and file-names. Then there's also checking the abspath/normpath of the resulting name to make sure it's still in the intended folder. I've read through [1] and have started to glom together various bits from that thread. My current course of action is something like SACRED_WIN32_FNAMES = set( ['CON', 'PRN', 'CLOCK$', 'AUX', 'NUL'] + ['LPT%i' % i for i in range(32)] + ['CON%i' % i for i in range(32)] + def sanitize_filename(fname): sane = set(string.letters + string.digits + '-_.[]{}()$') results = ''.join(c for c in fname if c in sane) # might have to check sans-extension if results.upper() in SACRED_WIN32_FNAMES: results = "_" + results return results but if somebody already has war-hardened code they'd be willing to share, I'd appreciate any thoughts. Thanks, -tkc [1] http://stackoverflow.com/questions/295135/turn-a-string-into-a-valid-filename-in-python From python at rcn.com Tue May 31 22:44:07 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 31 May 2011 19:44:07 -0700 (PDT) Subject: Updated blog post on how to use super() Message-ID: <80476fba-1b57-4bb1-9d7d-391edaf3042d@22g2000prx.googlegroups.com> I've tightened the wording a bit, made much better use of keyword arguments instead of kwds.pop(arg), and added a section on defensive programming (protecting a subclass from inadvertently missing an MRO requirement). Also, there is an entry on how to use assertions to validate search order requirements and make them explicit. http://bit.ly/py_super or http://rhettinger.wordpress.com/2011/05/26/super-considered-super/ Any further suggestions are welcome. I'm expecting this to evolve into how-to guide to be included in the regular Python standard documentation. The goal is to serve as a reliable guide to using super and how to design cooperative classes in a way that lets subclasses compose and extent them. Raymond Hettinger -------- follow my python tips on twitter: @raymondh From pavlovevidence at gmail.com Tue May 31 22:45:01 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 31 May 2011 19:45:01 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <678acba6-e8fd-42fc-bed0-118034897497@glegroupsg2000goo.googlegroups.com> On Sunday, May 29, 2011 8:59:49 PM UTC-7, Steven D'Aprano wrote: > On Sun, 29 May 2011 17:55:22 -0700, Carl Banks wrote: > > > Floating point arithmetic evolved more or less on languages like Fortran > > where things like exceptions were unheard of, > > I'm afraid that you are completely mistaken. > > Fortran IV had support for floating point traps, which are "things like > exceptions". That's as far back as 1966. I'd be shocked if earlier > Fortrans didn't also have support for traps. > > http://www.bitsavers.org/pdf/ibm/7040/C28-6806-1_7040ftnMathSubrs.pdf Fine, it wasn't "unheard of". I'm pretty sure the existence of a few high end compiler/hardware combinations that supported traps doesn't invalidate my basic point. NaN was needed because few systems had a separate path to deal with exceptional situations like producing or operating on something that isn't a number. When they did exist few programmers used them. If floating-point were standardized today it might not even have NaN (and definitely wouldn't support the ridiculous NaN != NaN), because all modern systems can be expected to support exceptions, and modern programmers can be expected to use them. > The IEEE standard specifies that you should be able to control whether a > calculation traps or returns a NAN. That's how Decimal does it, that's > how Apple's (sadly long abandoned) SANE did it, and floats should do the > same thing. If your aim is to support every last clause of IEEE for better or worse, then yes that's what Python should do. If your aim is to make Python the best language it can be, then Python should reject IEEE's obsolete notions, and throw exceptions when operating on NaN. Carl Banks From pavlovevidence at gmail.com Tue May 31 22:59:15 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 31 May 2011 19:59:15 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: Message-ID: On Sunday, May 29, 2011 7:53:59 PM UTC-7, Chris Angelico wrote: > Okay, here's a question. The Python 'float' value - is it meant to be > "a Python representation of an IEEE double-precision floating point > value", or "a Python representation of a real number"? The former. Unlike the case with integers, there is no way that I know of to represent an abstract real number on a digital computer. Python also includes several IEEE-defined operations in its library (math.isnan, math.frexp). Carl Banks From rosuav at gmail.com Tue May 31 23:05:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 13:05:43 +1000 Subject: float("nan") in set or as key In-Reply-To: References: Message-ID: On Wed, Jun 1, 2011 at 12:59 PM, Carl Banks wrote: > On Sunday, May 29, 2011 7:53:59 PM UTC-7, Chris Angelico wrote: >> Okay, here's a question. The Python 'float' value - is it meant to be >> "a Python representation of an IEEE double-precision floating point >> value", or "a Python representation of a real number"? > > The former. ?Unlike the case with integers, there is no way that I know of to represent an abstract real number on a digital computer. This seems peculiar. Normally Python seeks to define its data types in the abstract and then leave the concrete up to the various implementations - note, for instance, how Python 3 has dispensed with 'int' vs 'long' and just made a single 'int' type that can hold any integer. Does this mean that an implementation of Python on hardware that has some other type of floating point must simulate IEEE double-precision in all its nuances? I'm glad I don't often need floating point numbers. They can be so annoying! Chris Angelico From calderone.jeanpaul at gmail.com Tue May 31 23:17:50 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Tue, 31 May 2011 20:17:50 -0700 (PDT) Subject: Sanitizing filename strings across platforms References: Message-ID: <65ba3cf2-5163-473d-b8b3-b6321c47d6a5@dn9g2000vbb.googlegroups.com> On May 31, 10:17?pm, Tim Chase wrote: > Scenario: a file-name from potentially untrusted sources may have > odd filenames that need to be sanitized for the underlying OS. > On *nix, this generally just means "don't use '/' or \x00 in your > string", while on Win32, there are a host of verboten characters > and file-names. ?Then there's also checking the abspath/normpath > of the resulting name to make sure it's still in the intended folder. > > I've read through [1] and have started to glom together various > bits from that thread. ?My current course of action is something like > > ? SACRED_WIN32_FNAMES = set( > ? ? ['CON', 'PRN', 'CLOCK$', 'AUX', 'NUL'] + > ? ? ['LPT%i' % i for i in range(32)] + > ? ? ['CON%i' % i for i in range(32)] + > > ? def sanitize_filename(fname): > ? ? sane = set(string.letters + string.digits + '-_.[]{}()$') > ? ? results = ''.join(c for c in fname if c in sane) > ? ? # might have to check sans-extension > ? ? if results.upper() in SACRED_WIN32_FNAMES: > ? ? ? results = "_" + results > ? ? return results > > but if somebody already has war-hardened code they'd be willing > to share, I'd appreciate any thoughts. > There's http://pypi.python.org/pypi/filepath/0.1 (taken from twisted.python.filepath). Jean-Paul From pavlovevidence at gmail.com Tue May 31 23:30:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 31 May 2011 20:30:30 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: Message-ID: On Tuesday, May 31, 2011 8:05:43 PM UTC-7, Chris Angelico wrote: > On Wed, Jun 1, 2011 at 12:59 PM, Carl Banks > wrote: > > On Sunday, May 29, 2011 7:53:59 PM UTC-7, Chris Angelico wrote: > >> Okay, here's a question. The Python 'float' value - is it meant to be > >> "a Python representation of an IEEE double-precision floating point > >> value", or "a Python representation of a real number"? > > > > The former. ?Unlike the case with integers, there is no way that I know of to represent an abstract real number on a digital computer. > > This seems peculiar. Normally Python seeks to define its data types in > the abstract and then leave the concrete up to the various > implementations - note, for instance, how Python 3 has dispensed with > 'int' vs 'long' and just made a single 'int' type that can hold any > integer. Does this mean that an implementation of Python on hardware > that has some other type of floating point must simulate IEEE > double-precision in all its nuances? I think you misunderstood what I was saying. It's not *possible* to represent a real number abstractly in any digital computer. Python couldn't have an "abstract real number" type even it wanted to. (Math aside: Real numbers are not countable, meaning they cannot be put into one-to-one correspondence with integers. A digital computer can only represent countable things exactly, for obvious reasons; therefore, to model non-countable things like real numbers, one must use a countable approximation like floating-point.) You might be able to get away with saying float() merely represents an "abstract floating-point number with provisions for nan and inf", but pretty much everyone uses IEEE format, so what's the point? And no it doesn't mean Python has to support every nuance (and it doesn't). Carl Banks From pavlovevidence at gmail.com Tue May 31 23:30:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 31 May 2011 20:30:30 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: Message-ID: On Tuesday, May 31, 2011 8:05:43 PM UTC-7, Chris Angelico wrote: > On Wed, Jun 1, 2011 at 12:59 PM, Carl Banks > wrote: > > On Sunday, May 29, 2011 7:53:59 PM UTC-7, Chris Angelico wrote: > >> Okay, here's a question. The Python 'float' value - is it meant to be > >> "a Python representation of an IEEE double-precision floating point > >> value", or "a Python representation of a real number"? > > > > The former. ?Unlike the case with integers, there is no way that I know of to represent an abstract real number on a digital computer. > > This seems peculiar. Normally Python seeks to define its data types in > the abstract and then leave the concrete up to the various > implementations - note, for instance, how Python 3 has dispensed with > 'int' vs 'long' and just made a single 'int' type that can hold any > integer. Does this mean that an implementation of Python on hardware > that has some other type of floating point must simulate IEEE > double-precision in all its nuances? I think you misunderstood what I was saying. It's not *possible* to represent a real number abstractly in any digital computer. Python couldn't have an "abstract real number" type even it wanted to. (Math aside: Real numbers are not countable, meaning they cannot be put into one-to-one correspondence with integers. A digital computer can only represent countable things exactly, for obvious reasons; therefore, to model non-countable things like real numbers, one must use a countable approximation like floating-point.) You might be able to get away with saying float() merely represents an "abstract floating-point number with provisions for nan and inf", but pretty much everyone uses IEEE format, so what's the point? And no it doesn't mean Python has to support every nuance (and it doesn't). Carl Banks From rustompmody at gmail.com Tue May 31 23:33:19 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 31 May 2011 20:33:19 -0700 (PDT) Subject: float("nan") in set or as key References: <678acba6-e8fd-42fc-bed0-118034897497@glegroupsg2000goo.googlegroups.com> Message-ID: <7363ec97-1aa2-4105-922a-a8ccb01d0f10@d19g2000prh.googlegroups.com> On Jun 1, 7:45?am, Carl Banks wrote: > On Sunday, May 29, 2011 8:59:49 PM UTC-7, Steven D'Aprano wrote: > > On Sun, 29 May 2011 17:55:22 -0700, Carl Banks wrote: > > > > Floating point arithmetic evolved more or less on languages like Fortran > > > where things like exceptions were unheard of, > > > I'm afraid that you are completely mistaken. > > > Fortran IV had support for floating point traps, which are "things like > > exceptions". That's as far back as 1966. I'd be shocked if earlier > > Fortrans didn't also have support for traps. > > >http://www.bitsavers.org/pdf/ibm/7040/C28-6806-1_7040ftnMathSubrs.pdf > > Fine, it wasn't "unheard of". ?I'm pretty sure the existence of a few high end compiler/hardware combinations that supported traps doesn't invalidate my basic point. ?NaN was needed because few systems had a separate path to deal with exceptional situations like producing or operating on something that isn't a number. ?When they did exist few programmers used them. ?If floating-point were standardized today it might not even have NaN (and definitely wouldn't support the ridiculous NaN != NaN), because all modern systems can be expected to support exceptions, and modern programmers can be expected to use them. > > > The IEEE standard specifies that you should be able to control whether a > > calculation traps or returns a NAN. That's how Decimal does it, that's > > how Apple's (sadly long abandoned) SANE did it, and floats should do the > > same thing. > > If your aim is to support every last clause of IEEE for better or worse, then yes that's what Python should do. ?If your aim is to make Python the best language it can be, then Python should reject IEEE's obsolete notions, and throw exceptions when operating on NaN. > > Carl Banks Why can python not have an fpu object (class?) where one can go and turn on/off the button that makes nan signalling? In short, cant we have the cake and eat it too? From roy at panix.com Tue May 31 23:43:09 2011 From: roy at panix.com (Roy Smith) Date: Tue, 31 May 2011 23:43:09 -0400 Subject: float("nan") in set or as key References: Message-ID: In article Carl Banks wrote: > pretty much everyone uses IEEE format Is there *any* hardware in use today which supports floating point using a format other than IEEE? From gagsl-py2 at yahoo.com.ar Tue May 31 23:54:08 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 01 Jun 2011 00:54:08 -0300 Subject: Alternatives to PythonPath References: Message-ID: En Sun, 29 May 2011 18:49:28 -0300, ray escribi?: > I am using Win7 on a tightly locked down desktop. > > Is there an alternative to using PythonPath? > > What are the trade-offs? Usually there is no need to define the PYTHONPATH variable; I never use it. There is a per-user site-packages directory (2.6 and up), on Windows it is located at %APPDATA%\Python\PythonXX\site-packages. Every user gets its own %APPDATA% directory, with read and write permissions. -- Gabriel Genellina From rosuav at gmail.com Tue May 31 23:57:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 13:57:57 +1000 Subject: float("nan") in set or as key In-Reply-To: References: Message-ID: On Wed, Jun 1, 2011 at 1:30 PM, Carl Banks wrote: > I think you misunderstood what I was saying. > > It's not *possible* to represent a real number abstractly in any digital computer. ?Python couldn't have an "abstract real number" type even it wanted to. True, but why should the "non-integer number" type be floating point rather than (say) rational? Actually, IEEE floating point could mostly be implemented in a two-int rationals system (where the 'int' is arbitrary precision, so it'd be Python 2's 'long' rather than its 'int'); in a sense, the mantissa is the numerator, and the scale defines the denominator (which will always be a power of 2). Yes, there are very good reasons for going with the current system. But are those reasons part of the details of implementation, or are they part of the definition of the data type? > (Math aside: Real numbers are not countable, meaning they cannot be put into one-to-one correspondence with integers. ?A digital computer can only represent countable things exactly, for obvious reasons; therefore, to model non-countable things like real numbers, one must use a countable approximation like floating-point.) Right. Obviously a true 'real number' representation can't be done. But there are multiple plausible approximations thereof (the best being rationals). Not asking for Python to be changed, just wondering why it's defined by what looks like an implementation detail. It's like defining that a 'character' is an 8-bit number using the ASCII system, which then becomes problematic with Unicode. (Ohai, C, didn't notice you standing there.) Chris Angelico From dineshmishra.patil at gmail.com Sun May 1 00:37:35 2011 From: dineshmishra.patil at gmail.com (DINESH PATIL) Date: Sat, 30 Apr 2011 21:37:35 -0700 (PDT) Subject: click Message-ID: http://123maza.com/65/born511/ From harpreet442 at yahoo.co.in Sun May 1 02:43:35 2011 From: harpreet442 at yahoo.co.in (harryjatt) Date: Sat, 30 Apr 2011 23:43:35 -0700 (PDT) Subject: Zope with mySQL In-Reply-To: <00or88-n7n.ln1@hawthorn.home> References: <31499628.post@talk.nabble.com> <00or88-n7n.ln1@hawthorn.home> Message-ID: <31515759.post@talk.nabble.com> SORRY, i think that you are not happy with my elaboration. I am trying to generate a code for uploading and downloading the pdf files to mysql by web application through zope. but i can not make it right. I want your assistance in this. Tony Middleton wrote: > > Could you provide more details of what you are trying to do and what > help you need? > > On 28/04/11 20:19, harryjatt wrote: >> >> Hi, i am doing web development with Zope. My connected database is mySQL. >> I >> am new to this combination.I have to upload the files to mySQL with >> programming in zope and then downloading them via zope.Can you help me in >> this regard? I will be very thankfull to you. >> Regards, Harry > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://old.nabble.com/Zope-with-mySQL-tp31499628p31515759.html Sent from the Python - python-list mailing list archive at Nabble.com. From pmilin at gmail.com Sun May 1 04:17:11 2011 From: pmilin at gmail.com (neocortex) Date: Sun, 1 May 2011 01:17:11 -0700 (PDT) Subject: Getting number of hits from Google Message-ID: <2a808127-4e81-4746-9eaf-d96a3cee70b4@w24g2000yqb.googlegroups.com> Hello! For quite some time, I am looking for a solution to the problem of getting number of hits for a list of, let say, 200-300 words, from a search engine. I would prefer Google, but this seems not possible. I tried with the PyGoogle (from http://code.google.com/p/pygoogle/), but it stops delivering number of hits after 20-50 words. Please, can anyone help me with this. I am starting to be desperate. Sincerely, PM From hg at schaathun.net Sun May 1 04:18:36 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Sun, 1 May 2011 09:18:36 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> Message-ID: On Sat, 30 Apr 2011 15:40:24 +0100, Paul Rudin wrote: : Anytime you have enough data... there are plenty of things that are natural to : represent as recursive data structures, and often you don't know in : advance how much data your code is going to have to deal with. Sure, but one would think that if you can fit the data in memory, then you can also fit the call stack. I can also /imagine/ that one might run into a limit, but I cannot see any concrete examples where it is likely. -- :-- Hans Georg From steve+comp.lang.python at pearwood.info Sun May 1 04:45:51 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2011 08:45:51 GMT Subject: What other languages use the same data model as Python? Message-ID: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Python uses a data model of "name binding" and "call by object" (also known as "call by sharing"). I trust I don't need to define my terms, but just in case: http://effbot.org/zone/call-by-object.htm http://effbot.org/zone/python-objects.htm Now, this is different from languages like C and Pascal, which is based on variables, or Forth, which explicitly manipulates a stack. Quite often, when people want to impress upon others that Python is not C, they will say: "Python's data model is different from other languages" which is perfectly correct, if you think of C as "other languages". But it's equally correct to say that Python's data model is the same as other languages. As I understand it, Python and Ruby have the same data model. So does Java, so long as you only consider objects and ignore unboxed native values. I believe (but could be wrong) that another language of about the same vintage as Python, Emerald, also uses the same model. That's not surprising, because I believe that Emerald (just like Python) was strongly influenced by CLU. What other languages use the same, or mostly similar, data model as Python? -- Steven From PointedEars at web.de Sun May 1 04:59:37 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 01 May 2011 10:59:37 +0200 Subject: Python competitions and learnings References: Message-ID: <1922818.XAFRqVoOGU@PointedEars.de> harrismh777 wrote: > Terry Reedy wrote: >>> And Im looking for feedback from peoples who best in python. Here I >>> make some video tutorial about this service http://checkio.blip.tv/ >>> >>> What do you think about it? >> >> Pretty impressive. My main disappointment is that you are using 2.7 >> instead of 3.2, as I feel that beginners should learn Py 3 now. Also, >> that is what I routinely use ;-). >> >> In any case, the home page should say Python 2.7, not just Python, > > I agree on all points, as well I would offer the suggestion to have > parallel examples (in some cases) to help those trying to merge over to > Python3. > > But the most important point is that new users should start with 3.x, > and should be encouraged to in that direction alone. I am finding it > very frustrating trying to make all of the details changes solid in my > mind for 3.x because there are so many of them for one, and for another > because the details are so similar all at the same time. *Do not* > confuse new learners with 2.x unless there is a point to it... for > instance in our previous discussion of iterables-- noting that next() is > the same for both versions, but in 2.x next(N) means N.next() and in > version 3.x next(N) means N.__next__(). > > Otherwise, have new students hit 3.x running and never look back. A more down-to-earth recommendation can be found at The bottom line of this for me is that while Python 3 has its advantages, at this point not only you cannot use Py3 everywhere, but also you still cannot do everything in Py3 that you can do in Py2 (most notably, you cannot create or process images, as PIL? is not yet Py3-ready). Meaning that it would be a mistake to exclude Python 2 from education at this point. _____ ? -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From alec.taylor6 at gmail.com Sun May 1 04:59:52 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 1 May 2011 18:59:52 +1000 Subject: Deditor In-Reply-To: References: <74a2f743-aa0a-4beb-8c62-3e32b6ac7489@k22g2000yqh.googlegroups.com> <75a7cd73-50c9-4dc0-a88d-68051f1e3795@k22g2000yqh.googlegroups.com> <761080e3-bbda-4c3b-a38b-f9e0b1e4dcad@a10g2000vbz.googlegroups.com> <2cc05cc3-2c8a-42ba-bb7b-348206546378@k11g2000yqc.googlegroups.com> <35348319-4042-4929-a81c-2e1cec7de3f3@b19g2000yqg.googlegroups.com> Message-ID: Maybe I'm missing something, but I downloaded the zip file and ran each .py and .pyc file in turn, but none brought up the nice deditor GUI I've seen screenshots of... On the other subject, did you have a preference to what installer I should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi) From alec.taylor6 at gmail.com Sun May 1 05:00:27 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 1 May 2011 19:00:27 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: I think ruby does On Sun, May 1, 2011 at 6:45 PM, Steven D'Aprano wrote: > Python uses a data model of "name binding" and "call by object" (also > known as "call by sharing"). I trust I don't need to define my terms, but > just in case: > > http://effbot.org/zone/call-by-object.htm > http://effbot.org/zone/python-objects.htm > > > Now, this is different from languages like C and Pascal, which is based > on variables, or Forth, which explicitly manipulates a stack. Quite > often, when people want to impress upon others that Python is not C, they > will say: > > "Python's data model is different from other languages" > > which is perfectly correct, if you think of C as "other languages". But > it's equally correct to say that Python's data model is the same as other > languages. As I understand it, Python and Ruby have the same data model. > So does Java, so long as you only consider objects and ignore unboxed > native values. I believe (but could be wrong) that another language of > about the same vintage as Python, Emerald, also uses the same model. > That's not surprising, because I believe that Emerald (just like Python) > was strongly influenced by CLU. > > What other languages use the same, or mostly similar, data model as > Python? > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From clp2 at rebertia.com Sun May 1 05:04:20 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 1 May 2011 02:04:20 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 1, 2011 at 1:45 AM, Steven D'Aprano wrote: > Python uses a data model of "name binding" and "call by object" (also > known as "call by sharing"). > As I understand it, Python and Ruby have the same data model. > So does Java, so long as you only consider objects and ignore unboxed > native values. I believe (but could be wrong) that another language of > about the same vintage as Python, Emerald, also uses the same model. > That's not surprising, because I believe that Emerald (just like Python) > was strongly influenced by CLU. > > What other languages use the same, or mostly similar, data model as > Python? According to http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing , besides those you already listed: Scheme, OCaml, AppleScript, and possibly VB, among "many other languages". I can't personally vouch for the accuracy of this. Cheers, Chris From steve+comp.lang.python at pearwood.info Sun May 1 05:04:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2011 09:04:27 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> Message-ID: <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 May 2011 09:18:36 +0100, Hans Georg Schaathun wrote: > On Sat, 30 Apr 2011 15:40:24 +0100, Paul Rudin > wrote: > : Anytime you have enough data... there are plenty of things that are > natural to : represent as recursive data structures, and often you > don't know in : advance how much data your code is going to have to > deal with. > > Sure, but one would think that if you can fit the data in memory, then > you can also fit the call stack. I can also /imagine/ that one might > run into a limit, but I cannot see any concrete examples where it is > likely. Why? You might have 4000 MB of main memory, and only 2 MB (say?) of call stack allocated. The call stack can't grow indefinitely. If it does, you get a stack overflow: http://www.ehow.com/list_6572027_reasons-stack-overflow.html which, if you're lucky, will just crash the process. If you're unlucky, it will lead to an exploit that malware can use to compromise your machine. In Python, the virtual machine protects you against stack overflow. Before the stack overflows, Python raises RecursionError. You can experiment by using sys.getrecursionlimit and sys.setrecursionlimit, but be careful, if you increase the limit too high, a deeply recursive function will overflow the stack. -- Steven From hg at schaathun.net Sun May 1 05:27:14 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Sun, 1 May 2011 10:27:14 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01 May 2011 09:04:27 GMT, Steven D'Aprano wrote: : Why? You might have 4000 MB of main memory, and only 2 MB (say?) of call : stack allocated. The call stack can't grow indefinitely. If it does, you : get a stack overflow: Of course you do, but you are still only saying that there might be an application where this might happen because of excessive although logically correct recursion. You have not given a single example where it actually happened. : In Python, the virtual machine protects you against stack overflow. : Before the stack overflows, Python raises RecursionError. You can : experiment by using sys.getrecursionlimit and sys.setrecursionlimit, but : be careful, if you increase the limit too high, a deeply recursive : function will overflow the stack. But the recursion limit is mainly there to protect you against faulty base cases. Obviously, since it measures the number of items on the stack and not their size. -- :-- Hans Georg From bthate at gmail.com Sun May 1 07:43:10 2011 From: bthate at gmail.com (Bart Thate) Date: Sun, 1 May 2011 04:43:10 -0700 (PDT) Subject: JSONBOT 0.7 RELEASED Message-ID: 0.7 RELEASE NOTES ================= Hello world, greetings to all and everybody on this little planet ;] Today I am releasing version 0.7 of JSONBOT, hope you like it. I want to dedicate this release to Annemiek, Kirsten, Danny and Doscha, i would not have a live without you. changes in this release ----------------------- * we got jsonbot.org running .. see http://jsonbot.org ;] * convore support * refactored core * reloadable config files * revamped web console * resource files (contain commands the bot can execute) * file change detection for myplugs plugins * rebooting is fixed * fixed relaying in jabber conference rooms * added color.py plugin to color certain words * added geo.py, googletranslate.py and imdb.py (thnx melmoth) * chatlog plugin now uses the logging module .. log file rotates every day * many other bugfixes If you have programmed your own plugin see http://jsonbot.org/handbook/UPGRADE.html for upgrade notes. Todo ---- 1) fix runtime setting of loglevel 2) add flood control 3) docs docs docs docs docs 4) fix bugs see http://code.google.com/p/jsonbot/issues/list Source ------ * tarball - http://jsonbot.googlecode.com * mercurial - http://jsonbot.googlecode.com/hg * github - https://github.com/jsonbot Demo ---- * webconsole - http://jsonbot.appspot.com * xmpp - jsonbot at jsonbot.org (shell) and jsonbot at appspot.com (GAE) * IRC - jsonbot on irc.freenode.net * Convore - https://convore.com/convore-8/welcome-to-convore/ relaying with #convore on irc.freenode.net Docs ---- * new jsonbot.org site .. http://jsonbot.org * GAE backup docs .. http://jsonbot.appspot.com/docs Contact ------- * twitter: https://twitter.com/#!/jsonbot * facebook: http://tinyurl.com/jsonbot * email: bthate at gmail.com * IRC: dunker in channel #dunkbots / irc.freenode.net* xmpp: bthate at gmail.com and bart at jsonbot.org About ----- 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 and Convore 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 shell Convore 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 Install ------- You dont need to run the bot on GAE when you just want to use the shell bots of JSONBOT. JSONBOT can best be run from the bot dir, the bot is self contained and has all the dependancies that are needed: * "hg clone http://jsonbot.googlecode.com/hg mybot" or download and untar the tarball. * cd into the bot dir and run "./bin/jsb" .. if the bot is working correctly you will get the console version of JSONBOT * same can be done for "./bin/jsb-xmpp", "./bin/jsb-convore" etc. .. check the bin dir for programs you can start * try the --help option to a program to see what command line options are available. * you DONT need root for this Ofcourse you can always run "python setup.py install" or "easy_install -U jsb" when you do want to install the bot globaly. Debian packages are on their way, but might still take time as the ftpmeisters need to approve ;] Thats it ! hope you enjoy this version of JSONBOT ;] Bart From steve+comp.lang.python at pearwood.info Sun May 1 07:56:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2011 11:56:57 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 May 2011 10:27:14 +0100, Hans Georg Schaathun wrote: > On 01 May 2011 09:04:27 GMT, Steven D'Aprano > wrote: > : Why? You might have 4000 MB of main memory, and only 2 MB (say?) of > call : stack allocated. The call stack can't grow indefinitely. If it > does, you : get a stack overflow: > > Of course you do, but you are still only saying that there might be an > application where this might happen because of excessive although > logically correct recursion. You have not given a single example where > it actually happened. Just google on "stack overflow crash". > : In Python, the virtual machine protects you against stack overflow. : > Before the stack overflows, Python raises RecursionError. You can : > experiment by using sys.getrecursionlimit and sys.setrecursionlimit, but > : be careful, if you increase the limit too high, a deeply recursive : > function will overflow the stack. > > But the recursion limit is mainly there to protect you against faulty > base cases. Obviously, since it measures the number of items on the > stack and not their size. The Python virtual machine knows how big each entry on the stack needs to be. (I don't, but it's got to be at least the size of a pointer.) So "number of items" is just a multiplication away from "size of the items". In practice the main reason that stacks overflow is because of faulty base cases in recursion. That's obvious. But in principle, any sufficiently large number of function calls could overflow the stack. If the call stack is (say) 1 MB (chosen only to make the maths easier), and each function call requires (say) a single four-byte entry on the stack, then you can have a maximum of 250000 function calls before overflowing the stack. If you don't like my numbers -- and you probably shouldn't, since I made them up -- choose your own. But whatever numbers you choose, there *must* be a maximum number of function calls before the stack overflows. Not necessarily recursive function calls either: any nested function call will do. However, it's generally only in recursion that you have more than a few hundred calls on the stack. So even if the base case is correct, you can overflow the stack. Given the naive recursive factorial function: def fact(n): if n <= 1: return 1 return n*fact(n-1) and the theoretical limit above, then fact(250001) will overflow the stack even though the base case is correct. -- Steven From martin at v.loewis.de Sun May 1 08:49:13 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 01 May 2011 14:49:13 +0200 Subject: minimal python27.dll? In-Reply-To: References: <4DB8774C.9080400@v.loewis.de> Message-ID: <4DBD56C9.6070300@v.loewis.de> > I have vague recollections that pythonXY.dll could not be statically > linked on Windows, or that doing so causes some serious loss of > functionality. Was this ever true, and is it still? You'll have to rebuild Python to make use of static linkage, of course, but then: it is certainly possible. The main functionality that you lose is the ability to load extension modules (.pyd files). Whether that's a serious loss or not depends on your application - in cases where you want static linkage, you can often accept not being able to do dynamic linkage. Regards, Martin From martin at v.loewis.de Sun May 1 08:49:13 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 01 May 2011 14:49:13 +0200 Subject: minimal python27.dll? In-Reply-To: References: <4DB8774C.9080400@v.loewis.de> Message-ID: <4DBD56C9.6070300@v.loewis.de> > I have vague recollections that pythonXY.dll could not be statically > linked on Windows, or that doing so causes some serious loss of > functionality. Was this ever true, and is it still? You'll have to rebuild Python to make use of static linkage, of course, but then: it is certainly possible. The main functionality that you lose is the ability to load extension modules (.pyd files). Whether that's a serious loss or not depends on your application - in cases where you want static linkage, you can often accept not being able to do dynamic linkage. Regards, Martin From martin at v.loewis.de Sun May 1 08:51:42 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 01 May 2011 14:51:42 +0200 Subject: minimal python27.dll? In-Reply-To: References: <4DB8774C.9080400@v.loewis.de> Message-ID: > On the CJK issue, why python ship its own codec, not using OS builtin? The OS doesn't provide all the codecs that Python provides. For the one it does provide, it behaves semantically different in border cases from the ones that come with Python. > If I don't need the full Unicode5.1 can I just map python's unicode > functions to some Win32 unicode API? That should be possible - but I doubt it's a matter of "just". Regards, Martin From hg at schaathun.net Sun May 1 09:15:35 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Sun, 1 May 2011 14:15:35 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01 May 2011 11:56:57 GMT, Steven D'Aprano wrote: : Just google on "stack overflow crash". And I get loads of examples of stack overflows, but I could not see anybody linking this to logically correct recursion. Wikipedia, for instance, mentions two common causes, neither of which has anything to do with logically correct recursion. : The Python virtual machine knows how big each entry on the stack needs to : be. (I don't, but it's got to be at least the size of a pointer.) So : "number of items" is just a multiplication away from "size of the items". Does it? In a conventional stack you need to store all the local variables for the function as well. Thus, there is no limit to how much space a single element on the stack may require. : But in principle, any : sufficiently large number of function calls could overflow the stack. : (...) : If you don't like my numbers -- and you probably shouldn't, since I made : them up -- choose your own. But whatever numbers you choose, there *must* : be a maximum number of function calls before the stack overflows. But all of this is in principle, and does not constitute any valid reason to avoid recursion in practice. If you want to argue that recursion is a bad thing in /practice/ you need a /practical/ argument. There is also a limit to how far you can usefully recurse over a limited data structure. : def fact(n): : if n <= 1: return 1 : return n*fact(n-1) : : and the theoretical limit above, then fact(250001) will overflow the : stack even though the base case is correct. Of course that will overflow, but you are now trying to calculate an integer of several /million/ bits. Please suggest me a current-day application where you would want to have and also be able to use such a number. There are many ways to crash a system if you want to. But if you don't deliberately try to crash it, you are much more likely to crash it because you allocate to much memory in each step than because the recursion gets to deep. Consequently, because recursion is usually a clearer form of expression than iterative loops, recursion may actually be /less/ dangerous. -- :-- Hans Georg From roy at panix.com Sun May 1 10:13:50 2011 From: roy at panix.com (Roy Smith) Date: Sun, 01 May 2011 10:13:50 -0400 Subject: skipping one unittest assertion? Message-ID: Is there any way to skip a single assertion in a unittest test method? I know I can @skip or @expectedFailure the method, but I'm looking for something finer-grain than that. There's one particular assertion in a test method which depends on production code that hasn't been written yet. I could factor that out into its own test methods and @skip that, but it would be cleaner to be able to mark the particular assertion. (using python 2.6, but importing unittest2 from 2.7) From ben+python at benfinney.id.au Sun May 1 10:31:35 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 May 2011 00:31:35 +1000 Subject: skipping one unittest assertion? References: Message-ID: <87wriah4qg.fsf@benfinney.id.au> Roy Smith writes: > There's one particular assertion in a test method which depends on > production code that hasn't been written yet. I could factor that out > into its own test methods and @skip that, but it would be cleaner to be > able to mark the particular assertion. I think that's backward. If there are multiple conditions to assert, then it's much cleaner to put them in distinct test case methods. Each test case should be testing one thing: if it fails, it should be for exactly one reason. -- \ ?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 darragh.ssa at gmail.com Sun May 1 10:33:33 2011 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 1 May 2011 07:33:33 -0700 (PDT) Subject: Deditor References: <74a2f743-aa0a-4beb-8c62-3e32b6ac7489@k22g2000yqh.googlegroups.com> <75a7cd73-50c9-4dc0-a88d-68051f1e3795@k22g2000yqh.googlegroups.com> <761080e3-bbda-4c3b-a38b-f9e0b1e4dcad@a10g2000vbz.googlegroups.com> <2cc05cc3-2c8a-42ba-bb7b-348206546378@k11g2000yqc.googlegroups.com> <35348319-4042-4929-a81c-2e1cec7de3f3@b19g2000yqg.googlegroups.com> Message-ID: <7d8e78d2-8a90-431e-8a5d-d9f81d393e40@j26g2000yqa.googlegroups.com> On 1 mei, 10:59, Alec Taylor wrote: > Maybe I'm missing something, but I downloaded the zip file and ran > each .py and .pyc file in turn, but none brought up the nice deditor > GUI I've seen screenshots of... > > On the other subject, did you have a preference to what installer I > should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi) not a msi, for the rest it doesn't matter :), on my windows if you run deditor.py it should launch however you need to have the wxpython-2.8 package installed, what happens if you run deditor.py from console? From mrmakent at gmail.com Sun May 1 11:07:40 2011 From: mrmakent at gmail.com (Michael Kent) Date: Sun, 1 May 2011 08:07:40 -0700 (PDT) Subject: skipping one unittest assertion? In-Reply-To: <87wriah4qg.fsf@benfinney.id.au> Message-ID: I agree that each test should test only one 'thing', but it's also true that testing one 'thing' sometimes/often involves multiple assertions. But in the OP's case, it does sound like the assertion he wants to skip should be broken out into its own test. From trevita2048 at gmail.com Sun May 1 11:39:00 2011 From: trevita2048 at gmail.com (Yico Gaga) Date: Sun, 1 May 2011 23:39:00 +0800 Subject: Python IDE/text-editor In-Reply-To: References: Message-ID: foolDE :)!!! 2011/4/29 Alec Taylor > Your probably right. > > I suppose I'll just wait till I finish my fooIDE project > > > On Fri, Apr 29, 2011 at 2:21 AM, Albert van der Horst > > wrote: > >> In article , > >> Alec Taylor wrote: > >>>Geany I've tried in the past, it's really buggy on my home computer > >>>and at Uni... however from my phone it works wonderfully! (Use it for > >>>C++ projects on Rhobuntu) > >>> > >>>Eric 4 was suggested to me on the #python channel on Freenode... > >>>however I've never been able to get it compiled/working. Too many > >>>dependencies I'm guessing... > >>> > >>>PTK looks great, and does everything I want (from screenshots). > >>>Unfortunately, it doesn't run on my system; Win7 x64, Python 2.7.1 > >>>x64, WxPython 2.8 x64. Install ran as admin. > >>> > >>>Emacs and vim still seem like good alternatives, when I get the time. > >>>However, currently have 3 assignments to start and finish so would > >>>like a simple Notepad2 with python interpreter attached (and keyboard > >>>shortcut to run script) type program. > >>> > >>>Please continue recommending > >>> > >>>Thanks, > >>> > >>>Alec Taylor > >> > >> You will never be satisfied, until you've written something yourself. > >> Start writing now. A friend of mine started writing in 1983, > >> and since 1985 I'm a happy user. The only language that is a candidate > >> to write in is C, however. > >> > >> Groetjes Albert > >> > >> -- > >> -- > >> Albert van der Horst, UTRECHT,THE NETHERLANDS > >> Economic growth -- being exponential -- ultimately falters. > >> albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst > >> > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Sun May 1 11:47:40 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 2 May 2011 01:47:40 +1000 Subject: Python IDE/text-editor In-Reply-To: References: Message-ID: !!! =] http://code.google.com/p/fooide Contact me if you'd like to join the project :D On Mon, May 2, 2011 at 1:39 AM, Yico Gaga wrote: > ? foolDE :)!!! > > 2011/4/29 Alec Taylor >> >> Your probably right. >> >> I suppose I'll just wait till I finish my fooIDE project >> >> > On Fri, Apr 29, 2011 at 2:21 AM, Albert van der Horst >> > wrote: >> >> In article , >> >> Alec Taylor ? wrote: >> >>>Geany I've tried in the past, it's really buggy on my home computer >> >>>and at Uni... however from my phone it works wonderfully! (Use it for >> >>>C++ projects on Rhobuntu) >> >>> >> >>>Eric 4 was suggested to me on the #python channel on Freenode... >> >>>however I've never been able to get it compiled/working. Too many >> >>>dependencies I'm guessing... >> >>> >> >>>PTK looks great, and does everything I want (from screenshots). >> >>>Unfortunately, it doesn't run on my system; Win7 x64, Python 2.7.1 >> >>>x64, WxPython 2.8 x64. Install ran as admin. >> >>> >> >>>Emacs and vim still seem like good alternatives, when I get the time. >> >>>However, currently have 3 assignments to start and finish so would >> >>>like a simple Notepad2 with python interpreter attached (and keyboard >> >>>shortcut to run script) type program. >> >>> >> >>>Please continue recommending >> >>> >> >>>Thanks, >> >>> >> >>>Alec Taylor >> >> >> >> You will never be satisfied, until you've written something yourself. >> >> Start writing now. A friend of mine started writing in 1983, >> >> and since 1985 I'm a happy user. The only language that is a candidate >> >> to write in is C, however. >> >> >> >> Groetjes Albert >> >> >> >> -- >> >> -- >> >> Albert van der Horst, UTRECHT,THE NETHERLANDS >> >> Economic growth -- being exponential -- ultimately falters. >> >> albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst >> >> >> >> -- >> >> http://mail.python.org/mailman/listinfo/python-list >> >> >> > >> -- >> http://mail.python.org/mailman/listinfo/python-list > > From alec.taylor6 at gmail.com Sun May 1 11:50:07 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 2 May 2011 01:50:07 +1000 Subject: Deditor In-Reply-To: <7d8e78d2-8a90-431e-8a5d-d9f81d393e40@j26g2000yqa.googlegroups.com> References: <74a2f743-aa0a-4beb-8c62-3e32b6ac7489@k22g2000yqh.googlegroups.com> <75a7cd73-50c9-4dc0-a88d-68051f1e3795@k22g2000yqh.googlegroups.com> <761080e3-bbda-4c3b-a38b-f9e0b1e4dcad@a10g2000vbz.googlegroups.com> <2cc05cc3-2c8a-42ba-bb7b-348206546378@k11g2000yqc.googlegroups.com> <35348319-4042-4929-a81c-2e1cec7de3f3@b19g2000yqg.googlegroups.com> <7d8e78d2-8a90-431e-8a5d-d9f81d393e40@j26g2000yqa.googlegroups.com> Message-ID: Traceback (most recent call last): File "O:\deditor\deditor\deditor.py", line 7, in import wx, os, datetime, sys, ConfigParser, wx.aui, wx.lib.scrolledpanel File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4 5, in from wx._core import * File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i n import _core_ ImportError: DLL load failed: %1 is not a valid Win32 application. On Mon, May 2, 2011 at 12:33 AM, Kruptein wrote: > On 1 mei, 10:59, Alec Taylor wrote: >> Maybe I'm missing something, but I downloaded the zip file and ran >> each .py and .pyc file in turn, but none brought up the nice deditor >> GUI I've seen screenshots of... >> >> On the other subject, did you have a preference to what installer I >> should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi) > > not a msi, for the rest it doesn't matter :), ?on my windows if you > run deditor.py ? it should launch however you need to have the > wxpython-2.8 package installed, ? what happens if you run deditor.py > from console? > -- > http://mail.python.org/mailman/listinfo/python-list > From roy at panix.com Sun May 1 11:55:29 2011 From: roy at panix.com (Roy Smith) Date: Sun, 01 May 2011 11:55:29 -0400 Subject: skipping one unittest assertion? References: <87wriah4qg.fsf@benfinney.id.au> Message-ID: In article <87wriah4qg.fsf at benfinney.id.au>, Ben Finney wrote: > Roy Smith writes: > > > There's one particular assertion in a test method which depends on > > production code that hasn't been written yet. I could factor that out > > into its own test methods and @skip that, but it would be cleaner to be > > able to mark the particular assertion. > > I think that's backward. If there are multiple conditions to assert, > then it's much cleaner to put them in distinct test case methods. > > Each test case should be testing one thing: if it fails, it should be > for exactly one reason. Well, yeah, that's certainly the XP/unit-test doctrine. In practice however, tests often get written as "do a bunch of stuff to get some result, then make a bunch of assertions about that result". Sure, you could make each of those assertions a distinct method, and factor the "do a bunch of stuff" into setUp(). Which probably means factoring those methods out into a new TestCase subclass. At some point, however practicality trumps doctrine. I notice the Python internal tests adopt exactly the same attitude. Here's an example from 3.2's test_urllib.py: def test_fileno(self): file_num = self.returned_obj.fileno() self.assertIsInstance(file_num, int, "fileno() did not return an int") self.assertEqual(os.read(file_num, len(self.text)), self.text, "Reading on the file descriptor returned by fileno() " "did not return the expected text") I've got a remote API which at some point returns a URL (wrapped up in a larger JSON-ized object). I want to make several assertions about the object. It should be valid JSON. It should unpack to yield an object (well, dict in python) with certain attributes. Those values of those attributes should be of the correct types, etc. So: self.assertIsInstance(station['id'], int) self.assertIsInstance(station['name'], unicode) self.assertIsInstance(station['cover_url'], unicode) The next assertion (the one that I know will fail because the server code hasn't been written yet) is that cover_url refers to a get-able jpeg image. It would be convenient and useful to write the assertion now and mark that I expect it to fail until the server code catches up. Breaking all this up into distinct test methods would be silly. In fact, it would be wrong. If they were different methods, they would not be making multiple assertions against one object retrieved from the external service, they would be making a series of assertions against a series of different objects. And, unlike pure unit-test doctrine would like to believe, external services have state. And per-interaction cost (in our case, real cost; some queries result in us paying a few mili-cents to a third-party data provider :-)) I guess I'll just mark the whole method @expectedFailure and let it go at that. From news at schwertberger.de Sun May 1 12:11:23 2011 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sun, 01 May 2011 18:11:23 +0200 Subject: Development tools and practices for Pythonistas In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> Message-ID: Am 01.05.2011 02:47, schrieb Shawn Milochik: > Look at the big two sites for open-source repositories -- github and > bitbucket. One's git, the other Mercurial. I don't think you can go > wrong picking either one. Can any of those be used from Python as a library, i.e. something like import Hg r = Hg.open(path) When I had a look at Mercurial, which is implemented in Python, it was implemented in a way that I could not do that. It was implemented as rather monolithic program which could be used from os.system(...) only. With a good API, I could easily have integrated it into my development flow. I have a codebase which is shared between different projects and there are many small changes on many different PCs. In theory a distributed VCS is good at supporting that, but in practice I went back to my lightweight synchronization scripts and file storage again. With the API, I could have best of both worlds. Regards, Dietmar From darragh.ssa at gmail.com Sun May 1 12:12:21 2011 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 1 May 2011 09:12:21 -0700 (PDT) Subject: Deditor References: <74a2f743-aa0a-4beb-8c62-3e32b6ac7489@k22g2000yqh.googlegroups.com> <75a7cd73-50c9-4dc0-a88d-68051f1e3795@k22g2000yqh.googlegroups.com> <761080e3-bbda-4c3b-a38b-f9e0b1e4dcad@a10g2000vbz.googlegroups.com> <2cc05cc3-2c8a-42ba-bb7b-348206546378@k11g2000yqc.googlegroups.com> <35348319-4042-4929-a81c-2e1cec7de3f3@b19g2000yqg.googlegroups.com> <7d8e78d2-8a90-431e-8a5d-d9f81d393e40@j26g2000yqa.googlegroups.com> Message-ID: On 1 mei, 17:50, Alec Taylor wrote: > Traceback (most recent call last): > ?File "O:\deditor\deditor\deditor.py", line 7, in e> > ? ?import wx, os, datetime, sys, ConfigParser, wx.aui, wx.lib.scrolledpanel > ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4 > 5, in > ? ?from wx._core import * > ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i > n > ? ?import _core_ > ImportError: DLL load failed: %1 is not a valid Win32 application. > > > > On Mon, May 2, 2011 at 12:33 AM, Kruptein wrote: > > On 1 mei, 10:59, Alec Taylor wrote: > >> Maybe I'm missing something, but I downloaded the zip file and ran > >> each .py and .pyc file in turn, but none brought up the nicededitor > >> GUI I've seen screenshots of... > > >> On the other subject, did you have a preference to what installer I > >> should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi) > > > not a msi, for the rest it doesn't matter :), ?on my windows if you > > rundeditor.py ? it should launch however you need to have the > > wxpython-2.8 package installed, ? what happens if you rundeditor.py > > from console? > > -- > >http://mail.python.org/mailman/listinfo/python-list that looks like you have installed the wxpython module wrongly. Have you downloaded the version that matches your python version? From alexander at lyabah.com Sun May 1 12:15:48 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Sun, 1 May 2011 09:15:48 -0700 (PDT) Subject: Python competitions and learnings References: Message-ID: <51bb0f8c-e789-4c14-8190-0f6b0de038fc@bl1g2000vbb.googlegroups.com> On May 1, 12:29?am, Terry Reedy wrote: > On 4/30/2011 3:22 PM, Alexander Lyabah wrote: > > > I spend a lot of time in writing a new service checkio.org > > > It's all about python, learn python, find the best solution in > > python. > > > And Im looking for feedback from peoples who best in python. Here I > > make some video tutorial about this servicehttp://checkio.blip.tv/ > > > What do you think about it? > > Pretty impressive. My main disappointment is that you are using 2.7 > instead of 3.2, as I feel that beginners should learn Py 3 now. Also, > that is what I routinely use ;-). > > In any case, the home page should say Python 2.7, not just Python, I had > to think to click Console Learn in order to find out what would be legal > when I tried out one of the tasks. > > You might consider offering 3.2 as an alternative. Solutions will be > similar, but details differ. For instance, I noticed that one solution > to 'string split' *depends* on the 2.x leaking of listcomp loop variables. > > > I'm also have a not a very good English, so I need help with it too, > > because some parts of checkio.org ?not in very well English > > Home page: "In the descriptions of this tasks there is always > information from manuals and tutorials," 'these tasks' > > "game.Choice a game " => "game. Choose a game " > "users. Choice a game" => again, 'Choose' > > "and fall into the top " I think you mean "and climb into the top " > > "programs on arena. " => "program in the arena. " > > "By the result of competition formed top of the game. " > This is unclear. perhaps "The best will be chosen by the result of the > competition." > > I see a mailto: link at the bottom of the page, so I will report > anything else I see later. > > -- > Terry Jan Reedy thanks for your translation. It's already published on site. And I will wait for your mail From alexander at lyabah.com Sun May 1 12:22:46 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Sun, 1 May 2011 09:22:46 -0700 (PDT) Subject: Python competitions and learnings References: <2N1vp.21945$vC5.16209@newsfe01.iad> Message-ID: <5e4ec696-4d50-4b88-9fa5-229f293c0639@q21g2000vbs.googlegroups.com> On May 1, 3:26?am, harrismh777 wrote: > Alexander Lyabah wrote: > > What do you think about it? > > > I'm also have a not a very good English, so I need help with it too, > > Alexander, your site is very interesting. I spent some time this > afternoon appreciating your work. Nice job. > > Be encouraged, your English is much better than my Russian! I also > looked over the orphanage site and I appreciate how much you are doing > there in Ukraine for the children. Keep up the good work. > > I too am a little disappointed that Python3 is not being used. I want to > encourage you to work in that direction as well. I may have some time to > volunteer to checkio.org; for help with the English, and maybe with some > help as a tester. We'll see... I have a lot of my own fish to fry here, > as we say in America. > > Blessings on your work, friend. > > m harris I spend a lot of time to make a almost full support of python 2.7 from sandbox. If somebody help me this sandboxed python 3.* i will add support of it on checkio.org with big pleasure. From alexander at lyabah.com Sun May 1 12:49:14 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Sun, 1 May 2011 09:49:14 -0700 (PDT) Subject: Python competitions and learnings References: <2N1vp.21945$vC5.16209@newsfe01.iad> <5e4ec696-4d50-4b88-9fa5-229f293c0639@q21g2000vbs.googlegroups.com> Message-ID: And what do you think about Score Games and competitions? From brenNOSPAMbarn at NObrenSPAMbarn.net Sun May 1 14:14:11 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sun, 1 May 2011 18:14:11 +0000 (UTC) Subject: skipping one unittest assertion? References: Message-ID: Roy Smith wrote: > Is there any way to skip a single assertion in a unittest test > method? I know I can @skip or @expectedFailure the method, but I'm > looking for something finer-grain than that. > > There's one particular assertion in a test method which depends on > production code that hasn't been written yet. I could factor that > out into its own test methods and @skip that, but it would be > cleaner to be able to mark the particular assertion. > > (using python 2.6, but importing unittest2 from 2.7) Can't you just comment out that line? -- --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 roy at panix.com Sun May 1 14:16:24 2011 From: roy at panix.com (Roy Smith) Date: Sun, 01 May 2011 14:16:24 -0400 Subject: skipping one unittest assertion? References: Message-ID: In article , "OKB (not okblacke)" wrote: > Roy Smith wrote: > > > Is there any way to skip a single assertion in a unittest test > > method? I know I can @skip or @expectedFailure the method, but I'm > > looking for something finer-grain than that. > > > > There's one particular assertion in a test method which depends on > > production code that hasn't been written yet. I could factor that > > out into its own test methods and @skip that, but it would be > > cleaner to be able to mark the particular assertion. > > > > (using python 2.6, but importing unittest2 from 2.7) > > Can't you just comment out that line? Sure, but the point of @skip and @expectFailure is that they leave a visible trail in the test output that you need to go back and fix something. From gandalf at shopzeus.com Sun May 1 14:36:13 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sun, 01 May 2011 20:36:13 +0200 Subject: wxGrid, PyGridTableBase, strange SWIG error message! Message-ID: <4DBDA81D.10002@shopzeus.com> I'm trying to create a special widget that is a wx.Grid and also a PyGridTableBase. In my special case of application, I really need to have a grid that uses itself for getting cell data and cell attributes. Here is a test program, demonstrating my problem: import wx from wx.grid import Grid,PyGridTableBase class SpecialGrid(Grid,PyGridTableBase): def __init__(self,*args,**kwargs): PyGridTableBase.__init__(self) Grid.__init__(self,*args,**kwargs) self.SetTable(self) def SetTable(self,table): if table is not self: raise Exception("Grid must be its own table!") else: PyGridTableBase.SetTable(self,self,takeOwnership=False) app=wx.App(redirect=None) frame=wx.Frame(None) g = SpecialGrid(parent=frame) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(g,1,wx.EXPAND) frame.SetSizer(sizer) frame.Show() frame.Maximize() app.MainLoop() This program throws: Traceback (most recent call last): File "test.py", line 18, in g = SpecialGrid(parent=frame) File "test.py", line 6, in __init__ PyGridTableBase.__init__(self) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/grid.py", line 910, in __init__ self._setOORInfo(self);PyGridTableBase._setCallbackInfo(self, self, PyGridTableBase) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 3886, in _setOORInfo val = _core_.EvtHandler__setOORInfo(*args, **kwargs) TypeError: in method 'EvtHandler__setOORInfo', expected argument 1 of type 'wxEvtHandler *' This makes no sense to me. If I swap the constructor calls: def __init__(self,*args,**kwargs): Grid.__init__(self,*args,**kwargs) PyGridTableBase.__init__(self) self.SetTable(self) Then I get this: Traceback (most recent call last): File "test.py", line 18, in g = SpecialGrid(parent=frame) File "test.py", line 7, in __init__ PyGridTableBase.__init__(self) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/grid.py", line 910, in __init__ self._setOORInfo(self);PyGridTableBase._setCallbackInfo(self, self, PyGridTableBase) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 3887, in _setOORInfo args[0].this.own(False) File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 14586, in __getattr__ raise PyDeadObjectError(self.attrStr % self._name) wx._core.PyDeadObjectError: The C++ part of the SpecialGrid object has been deleted, attribute access no longer allowed. What the heck? Thanks, Laszlo From tjreedy at udel.edu Sun May 1 15:10:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 15:10:11 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/1/2011 4:45 AM, Steven D'Aprano wrote: > Python uses a data model of "name binding" and "call by object" > (also known as "call by sharing"). I trust I don't need to define my > terms, but just in case: > > http://effbot.org/zone/call-by-object.htm > http://effbot.org/zone/python-objects.htm > > > Now, this is different from languages like C and Pascal, which is > based on variables, Or Fortran or Basic (and I suspect, but do not know, Algol) and other descendents: Ada?, PL/1?). In statistical languages, user-defined names typically refer to typed data columns (eash a set of storage locations) or user-defined functions. > "Python's data model is different from other languages" > > which is perfectly correct, if you think of C as "other languages". > But it's equally correct to say that Python's data model is the same > as other languages. You defined Python's 'data model' as having two aspects: 'name binding' and 'call by object'. A language could match one but not the other. I believe Lisps have name-binding, but I know not all only have call-object. Macro calls (and earlier predecessors) are call-by-code-text. As I understand it, Python and Ruby have the same > data model. So does Java, so long as you only consider objects and > ignore unboxed native values. I believe (but could be wrong) that > another language of about the same vintage as Python, Emerald, also > uses the same model. That's not surprising, because I believe that > Emerald (just like Python) was strongly influenced by CLU. While Guido does not, that I know of, credit CLU as Python's direct inspiration, I think it (and Barbara Liskov) as the originator of Python's data model. I believe she thought of the call-by-object semantics as something of an innovation. > What other languages use the same, or mostly similar, data model as > Python? Natural languages. That is why I think it is better to think of Python as an algorithm language or information-object manipulation language rather than as just a linear-memory machine language. A linear memory with bytes addressed from 0 to max-int or max-long is an explicit part of the definition of assembly languages and C. It is no part of the definition of Python. Nice begin-a-thread post. -- Terry Jan Reedy From martin.schoon at gmail.com Sun May 1 15:53:08 2011 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 1 May 2011 19:53:08 GMT Subject: [OT] VCS for non-text (was Development tools and practices for Pythonistas) References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <5qqs88-9e7.ln1@svn.schaathun.net> <9222afFmqjU1@mid.individual.net> Message-ID: <925s14FokqU1@mid.individual.net> On 2011-04-30, Tim Chase wrote: > On 04/30/2011 04:15 AM, Martin Sch??n wrote: >> You guys are very code focused, which is natural given where we are. >> >> Having absorbed what I have seen here, looked a little at Mercurial, >> read a little on the webs of Fossil and Bazaar I start to think there >> is great merit in all this VCS stuff for other types of projects. >> >> At work my projects contain very little coding (some Python, some >> matlab/scilab perhaps) but a fair amount of CAD/CAE, written >> reports, presentations (OpenOffice and that other Office), >> spread sheets etc etc. A mixture of ascii-files and various >> proprietary formats most of which is stored in binary form. >> Some of the CAE-work generate pretty big files stored >> in dynamically created subdirectories. > > For non-text blobs, it takes a little bit of insight to get the > most out of them. For OpenDocument (Open/Libre Office > documents), they're zipped files containing text/XML which can be > diff'ed with more meaning. Usually there are custom filters for > git[1], Mercurial[2] and Bazaar[3] which will unpack the zipped > file contents before committing and give you more sensible diffs. > Likewise, for images (gif/jpg/tiff/raw/etc), there are > particular image-diff programs which make it easier to tell what > happened, as the textual diff of binary files is pretty useless. > However some images (such as .svg files) are XML/text inside, > and diff pretty nicely without extra effort. > > I can't speak to CAD/CAE, but it would have to be addressed on a > per-format basis in your given VCS. That said, you *can* store > the binary blobs in each, it's just not as useful without > meaningful comparisons. > > -tkc > > [1] > http://kerneltrap.org/mailarchive/git/2008/9/15/3305014 > > [2] > http://mercurial.selenic.com/wiki/HandlingOpenDocumentFiles > > [3] > http://doc.bazaar.canonical.com/plugins/en/oodiff.html > All very useful information. Thank you for that Tim. /Martin From airween at gmail.com Sun May 1 16:00:36 2011 From: airween at gmail.com (=?utf-8?Q?Heged=C3=BCs?= Ervin) Date: Sun, 1 May 2011 22:00:36 +0200 Subject: Py_INCREF() incomprehension In-Reply-To: References: Message-ID: <20110501200035.GA6310@arxnet.hu> hello, On Wed, Apr 27, 2011 at 11:58:18AM +0200, Thomas Rachel wrote: > Am 26.04.2011 20:44, schrieb Heged?s Ervin: > > >and (maybe) final question: :) > > > >I defined many exceptions: > > > >static PyObject *cibcrypt_error_nokey; > >static PyObject *cibcrypt_error_nofile; > >static PyObject *cibcrypt_error_badpad; > >... > > > >void handle_err(int errcode) { > > switch(errcode) { > > case -1: PyErr_SetString(cibcrypt_error_nokey, "Can't find key."); > > break; > >... > >} > >... > > cibcrypt_error_nokey = PyErr_NewException("cibcrypt.error_nokey", NULL, NULL); > >... > > PyModule_AddObject(o, "error", cibcrypt_error_nokey); > > Then I would not use the name "error" here, but maybe "error_nokey" > or even better "NoKeyException". > > Oops: there is an inconsistency in the docu: on the one hand, it says > > There are exactly two important exceptions to this rule: > PyTuple_SetItem() and PyList_SetItem(). > > stating these are the only ones who take over ownership. > > But PyModule_AddObject() claims to "steal" a reference as well... > > > >I am right, here also no need any Py_INCREF()/Py_DECREF() action, > >based on this doc: > >http://docs.python.org/c-api/arg.html > > I'm not sure: On one hand, you pass ownership of the error objects > to the module. There - one could think - they are until the module > is unloaded. > > But what if someone does "del module.NoKeyException"? In this case, > the object could have been destroyed, and you are using it -> BANG. > > On the other hand, if you keep one instance internally, it is not > possible any longer to unload the module without a memory leak... > > > As already stated - you might want to have a look at some other C > modules and mimic their behaviour... (and hope they are doing it > right...) so, I've checked it - there wasn't any Py_INCREF(), I just calmed down. But. :) My module contains just 4 functions (in C), which translate 3rd party lib to Python. The name would be _mycrypt.so example. I wrapped it a pure Python module, its name is mycrypt.py. Then, I've import pure Python module in a main program, like this: =%= mycrypt.py: import _mycrypt ... =%= =%= userapp.py: import mycrypt ... =%= I've missed out something, and then I didn't get exception, instead there were a segfault. :( I've put it a Py_INCREF() after every PyModule_AddObject(), eg.: PyModule_AddObject(o, "error", cibcrypt_error_nokey); Py_INCREF(cibcrypt_error_nokey); and now if there is some expected exception, I get it. Any explanation? Thanks: a. ps: this is just for my passion, but I would like to understand it very-very much :) From airween at gmail.com Sun May 1 16:14:14 2011 From: airween at gmail.com (=?utf-8?Q?Heged=C3=BCs?= Ervin) Date: Sun, 1 May 2011 22:14:14 +0200 Subject: Compile 32bit C-lib on 64 bit Message-ID: <20110501201413.GB6310@arxnet.hu> Hello, this is not a "clear" Python question - I've wrote a module in C, which uses a 3rd-party lib - it's a closed source, I just get the .so, .a and a header file. Looks like it works on 32bit (on my desktop), but it must be run on 64bit servers. When I'm compiling it on 64bit, gcc says: /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when searching for -l3rdpartyCrypt There _is_ the .so in /lib32 directory: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, stripped What is the correct solution? thank you: a. From rosuav at gmail.com Sun May 1 16:49:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 06:49:41 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 1, 2011 at 11:15 PM, Hans Georg Schaathun wrote: > : ?The Python virtual machine knows how big each entry on the stack needs to > : ?be. (I don't, but it's got to be at least the size of a pointer.) So > : ?"number of items" is just a multiplication away from "size of the items". > > Does it? ?In a conventional stack you need to store all the local > variables for the function as well. ?Thus, there is no limit to how > much space a single element on the stack may require. In anything less than a useless and trivial demo of recursion, there's going to be some kind of local state for each call (in the case of a fibonacci or factorial, that would be the number(s) being multiplied). Whether they go on the stack or elsewhere, that's additional storage that gets multiplied out. > There is also a limit to how far you can usefully recurse over a limited > data structure. Sure. Serialize this Python object in a way that can be given to, say, PHP: foo={"asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo] Recurse from self into the list, recurse from there into a dictionary... Okay, that's a rather naive recursion and fraught with risk, but there are more complex examples. And watching for cyclic references would be O(N*N) as you'd need to maintain a full list of every PyObject* that you've sighted (talking here from the C API, but the same consideration applies whichever way you do it). > There are many ways to crash a system if you want to. > > But if you don't deliberately try to crash it, you are much more > likely to crash it because you allocate to much memory in each step > than because the recursion gets to deep. ?Consequently, because recursion > is usually a clearer form of expression than iterative loops, recursion > may actually be /less/ dangerous. I'm not sure that recursion is clearer. Recursion is a way of expressing the two rules: 1! = 1 n! = n * (n-1)! But iteration is a way of expressing this equivalent rule: n! = 1 * 2 * 3 * ... * n-1 * n It really depends what you're trying to say. Chris Angelico From ryan.morrone at gmail.com Sun May 1 16:50:56 2011 From: ryan.morrone at gmail.com (PyNewbie) Date: Sun, 1 May 2011 13:50:56 -0700 (PDT) Subject: PIL Question Message-ID: Hi, I'm new with Python and PIL. I have a very simple question regarding an image capture function I'm attempting. Here is the code: >>> from PIL import ImageGrab >>> ImageGrab.grab().save("screen_capture.jpg", "JPEG") Question: I can't seem to find the captured image, where does it go? The python Shell IDE does not display an error, and the code appears to have been processed. Additional Info: I'm using Python 2.6, and PIL 1.1.7 for Python 2.6 Windows. From rosuav at gmail.com Sun May 1 16:51:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 06:51:45 +1000 Subject: skipping one unittest assertion? In-Reply-To: References: Message-ID: On Mon, May 2, 2011 at 4:16 AM, Roy Smith wrote: >> ? ? ? Can't you just comment out that line? > > Sure, but the point of @skip and @expectFailure is that they leave a > visible trail in the test output that you need to go back and fix > something. Comment it out and add a line of output manually? Make everything as simple as possible (but no simpler). Chris Angelico From jearl at notengoamigos.org Sun May 1 16:51:56 2011 From: jearl at notengoamigos.org (Jason Earl) Date: Sun, 01 May 2011 14:51:56 -0600 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> Message-ID: <87mxj6kutv.fsf@notengoamigos.org> On Sun, May 01 2011, Dietmar Schwertberger wrote: > Am 01.05.2011 02:47, schrieb Shawn Milochik: >> Look at the big two sites for open-source repositories -- github and >> bitbucket. One's git, the other Mercurial. I don't think you can go >> wrong picking either one. > > Can any of those be used from Python as a library, i.e. something like > import Hg > r = Hg.open(path) > > When I had a look at Mercurial, which is implemented in Python, it was > implemented in a way that I could not do that. It was implemented as > rather monolithic program which could be used from os.system(...) > only. > > With a good API, I could easily have integrated it into my development > flow. I have a codebase which is shared between different projects and > there are many small changes on many different PCs. In theory a > distributed VCS is good at supporting that, but in practice I went > back to my lightweight synchronization scripts and file storage > again. With the API, I could have best of both worlds. You should take a look at Bazaar. I found it fairly easy to use bzrlib from my own Python scripts. http://people.canonical.com/~mwh/bzrlibapi/ Jason From ben+python at benfinney.id.au Sun May 1 17:45:26 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 May 2011 07:45:26 +1000 Subject: skipping one unittest assertion? References: <87wriah4qg.fsf@benfinney.id.au> Message-ID: <87k4eagknd.fsf@benfinney.id.au> Roy Smith writes: > Ben Finney wrote: > > > Each test case should be testing one thing: if it fails, it should be > > for exactly one reason. > > Well, yeah, that's certainly the XP/unit-test doctrine. In practice > however, tests often get written as "do a bunch of stuff to get some > result, then make a bunch of assertions about that result". And the result is an increasingly-difficult maintenance burden for the test suite, as you've discovered. > Sure, you could make each of those assertions a distinct method, and > factor the "do a bunch of stuff" into setUp(). Which probably means > factoring those methods out into a new TestCase subclass. At some > point, however practicality trumps doctrine. Yet practicality, i.e. making your test cases manageable, is exactly what you don't have with your current approach. I'm not quoting doctrine at you; I'm saying that *because of problems like you're encountering*, you should refactor your test cases to do one test per case. -- \ ?Absurdity, n. A statement or belief manifestly inconsistent | `\ with one's own opinion.? ?Ambrose Bierce, _The Devil's | _o__) Dictionary_, 1906 | Ben Finney From ben+python at benfinney.id.au Sun May 1 17:49:40 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 May 2011 07:49:40 +1000 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> Message-ID: <87d3k2gkgb.fsf@benfinney.id.au> Dietmar Schwertberger writes: > Am 01.05.2011 02:47, schrieb Shawn Milochik: > > Look at the big two sites for open-source repositories -- github and > > bitbucket. Note that there are three: Launchpad (backed by Bazaar) is the other ?big site? for free-software project hosting. > Can any of those be used from Python as a library, i.e. something like > import Hg > r = Hg.open(path) I haven't used it, but Launchpad (the Canonical project hosting which uses Bazaar for the VCS) is of course well-supported in the Bazaar libraries. Access to the hosting site is eminently programmable with a good API, by all accounts. -- \ ?It is seldom that liberty of any kind is lost all at once.? | `\ ?David Hume | _o__) | Ben Finney From tjreedy at udel.edu Sun May 1 18:24:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 18:24:30 -0400 Subject: Fibonacci series recursion error In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/1/2011 5:27 AM, Hans Georg Schaathun wrote: > Of course you do, but you are still only saying that there might be > an application where this might happen because of excessive although > logically correct recursion. You have not given a single example where > it actually happened. I will. Stack overflow *can* happen with a bad base case. It *will* happen with correct linear recursion* applied to a large enough collection on a finite-memory machine (as opposed to an 'infinite' memory Turing machine). def count_popable_collection(pop_col): try: pop_col.pop() return count_popable_collection(pop_col) + 1 except (KeyError,IndexError): return 0 print(count_popable_collection({1,2,3})) print(count_popable_collection([1,2,3])) Both calls correctly print 3, but will fail for large enough sets or lists. I call the above body recursion*. A tail-recursive version def count_popable_collection2(pop_col, cnt=0): try: pop_col.pop() return count_popable_collection2(pop_col, cnt + 1) except (KeyError,IndexError): return cnt print(count_popable_collection2({1,2,3})) print(count_popable_collection2([1,2,3])) is less clear to most people, I think, and, executed as written, fails at the same point with the same memory error. Try either of the above with list(range(bignum)) (I am using 3.2). This does not make linear recursion 'bad', just impractical for general use on finite-memory machines. While I consider it very useful for learning, it is unnecessary because it is easy to write an iterative version. So called tail-recursion optimization saves memory by REMOVING RECURSION and replacing it with iteration. def count_popable_collection3(pop_col): cnt = 0 while True: try: pop_col.pop() cnt += 1 except (KeyError,IndexError): return cnt print(count_popable_collection3({1,2,3})) print(count_popable_collection3([1,2,3])) Python does not do this automatically because 1) it can be a semantic change under some circumstances; 2) one who wants the iterative version can just as easily write it directly; and 3) Python has a better way to process collections that removes essentially all the boilerplate in the recursive-call and while-loop versions: def count_popable_collection4(pop_col): cnt = 0 for item in pop_col: cnt += 1 return cnt print(count_popable_collection4({1,2,3})) print(count_popable_collection4([1,2,3])) Binary recursion* is a different case because the exponential growth in leaf number and hence time limits the useful depth of recursion to well below the default of 1000. * linear recursion: usually and at most one recursive call per call * binary recursion: usually and at most two recursive calls per call Fib is the best known example. * tail recursion: base cases return completed calculations * body recursion: base cases return starting values, often constants -- Terry Jan Reedy From tjreedy at udel.edu Sun May 1 18:33:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 18:33:02 -0400 Subject: Python competitions and learnings In-Reply-To: References: <2N1vp.21945$vC5.16209@newsfe01.iad> <5e4ec696-4d50-4b88-9fa5-229f293c0639@q21g2000vbs.googlegroups.com> Message-ID: On 5/1/2011 12:49 PM, Alexander Lyabah wrote: > And what do you think about Score Games and competitions? The rules of the first score game were not clear to me. I could not figure out how to play it interactively myself so I could see how it actually played. -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Sun May 1 18:33:08 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 02 May 2011 10:33:08 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9265d8FtkqU1@mid.individual.net> Steven D'Aprano wrote: > Python uses a data model of "name binding" and "call by object" (also > known as "call by sharing"). It can be summed up in a less jargony way by saying that all data is stored in heap-allocated objects, and variables refer to objects rather than containing them directly. Everything else follows from that. > What other languages use the same, or mostly similar, data model as > Python? Pretty much any dynamically-typed language: Lisp, Scheme, Smalltalk, Snobol, Icon, Postscript, Ruby, Lua, ... Some languages have it for some data types but not others. Java, VB, Objective-C come to mind. -- Greg From greg.ewing at canterbury.ac.nz Sun May 1 18:37:17 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 02 May 2011 10:37:17 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9265kvFv8gU1@mid.individual.net> Terry Reedy wrote: > While Guido does not, that I know of, credit CLU as Python's direct > inspiration, I think it (and Barbara Liskov) as the originator of > Python's data model. I believe she thought of the call-by-object > semantics as something of an innovation. I don't think she can claim credit for that, seeing as as Lisp was built around it. She may have invented the *term* "call by object" (unnecessarily, in my opinion) but the idea wasn't new. -- Greg From greg.ewing at canterbury.ac.nz Sun May 1 18:48:58 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 02 May 2011 10:48:58 +1200 Subject: Py_INCREF() incomprehension In-Reply-To: References: Message-ID: <9266atF3vrU1@mid.individual.net> Heged?s Ervin wrote: > I've put it a Py_INCREF() after every PyModule_AddObject(), eg.: > > PyModule_AddObject(o, "error", cibcrypt_error_nokey); > Py_INCREF(cibcrypt_error_nokey); That looks correct, because PyModule_AddObject is documented as stealing a reference to the object. By the way, it probably doesn't make a difference here, but it's better style to do the Py_INCREF *before* calling a function that steals a reference, to be sure that the object can't get spuriously deallocated. -- Greg From bc at freeuk.com Sun May 1 19:16:08 2011 From: bc at freeuk.com (BartC) Date: Mon, 2 May 2011 00:16:08 +0100 Subject: Fibonacci series recursion error In-Reply-To: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4dbbb7b6$0$29991$c3e8da3$5496439d at news.astraweb.com... > On Sat, 30 Apr 2011 08:32:55 +0200, Peter Otten wrote: > >> harrismh777 wrote: >> >>> Ian Kelly wrote: >>>> since the fact is that if >>>> the function were properly coded, the call stack for fib(20) would >>>> never be more than 20 entries deep at any one time. >>>> >>>> >>> Not so much... and much more !.... >>> >>> >>> ... because each recursion level 'return' calls fib() twice, and each >>> of those calls fib() twice, and you get the point... >> >> I don't understand what you are trying to say -- but it's wrong ;) > > > I don't know what M Harris thinks he is trying to say either, but the > *naive* Fibonacci recursive algorithm is particularly badly performing > and should be avoided. It's ironic that of the two classic algorithms > used for teaching beginner programmers about recursion, neither is useful > in practice. Yes, it generates lots of calls. About 22000 for fib(20), and 330 million for fib(40). That's why it's popular for benchmarks that measure performance of function calls. Using an iterative algorithm wouldn't work quite so well... -- Bartc From david at boddie.org.uk Sun May 1 19:33:00 2011 From: david at boddie.org.uk (David Boddie) Date: Mon, 02 May 2011 01:33:00 +0200 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> Message-ID: On Sunday 01 May 2011 18:11, Dietmar Schwertberger wrote: > Am 01.05.2011 02:47, schrieb Shawn Milochik: >> Look at the big two sites for open-source repositories -- github and >> bitbucket. One's git, the other Mercurial. I don't think you can go >> wrong picking either one. > > Can any of those be used from Python as a library, i.e. something like > import Hg > r = Hg.open(path) > > When I had a look at Mercurial, which is implemented in Python, > it was implemented in a way that I could not do that. It was implemented > as rather monolithic program which could be used from os.system(...) > only. After noting the warnings it contains, see the following page for a description of the Python API for Mercurial: http://mercurial.selenic.com/wiki/MercurialApi Git also has a Python API, which is fairly reasonable to use, though a bit different to the Mercurial one: http://www.samba.org/~jelmer/dulwich/ I've used both with some success. David From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sun May 1 20:59:55 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 02 May 2011 02:59:55 +0200 Subject: Py_INCREF() incomprehension In-Reply-To: References: Message-ID: Am 01.05.2011 22:00, schrieb Heged?s Ervin: > My module contains just 4 functions (in C), which translate 3rd > party lib to Python. The name would be _mycrypt.so example. > > I wrapped it a pure Python module, its name is mycrypt.py. > > Then, I've import pure Python module in a main program, like > this: > > =%= > mycrypt.py: > > import _mycrypt > ... > =%= > > =%= > userapp.py: > > import mycrypt > ... > =%= AFAICS, it looks ok. > I've missed out something, and then I didn't get exception, > instead there were a segfault. :( I guess this is the point where yo should start printf programing. * What happens during module initialization? * What happens n the functions? * Where does the stuff fail? * What are the reference counts of the involved objects? etc. > I've put it a Py_INCREF() after every PyModule_AddObject(), eg.: > > PyModule_AddObject(o, "error", cibcrypt_error_nokey); > Py_INCREF(cibcrypt_error_nokey); > > and now if there is some expected exception, I get it. > Any explanation? I don't have one - I would think that if the module object exists for all the time, it would be enough to have one reference there. But obviously it is not enough - did you at any time del something related to here? The module or one of its attributes? Anyway, it seems safer to do INCREF here - so do it. (As Gregory already stated - it looks cleaner if you do INCREF before AddObject.) > ps: this is just for my passion, but I would like to understand > it very-very much :) Understandable. That's that the printf debugging of the refcounts can be good for - even if you don't really have a problem. Thomas From clp2 at rebertia.com Sun May 1 21:00:26 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 1 May 2011 18:00:26 -0700 Subject: PIL Question In-Reply-To: References: Message-ID: On Sun, May 1, 2011 at 1:50 PM, PyNewbie wrote: > Hi, > > I'm new with Python and PIL. I have a very simple question regarding an image capture function I'm attempting. > > Here is the code: > > >>>> from PIL import ImageGrab >>>> ImageGrab.grab().save("screen_capture.jpg", "JPEG") > > Question: I can't seem to find the captured image, where does it go? ?The python Shell IDE does not display an error, and the code appears to have been processed. > > Additional Info: I'm using Python 2.6, and PIL 1.1.7 for Python 2.6 Windows. I would think to a file named "screen_capture.jpg" in the current working directory. What that is for IDLE, I don't know. You can determine what folder that is by running this in your Python shell: from os import getcwd print(getcwd()) Also, I would suggest using absolute file paths in the future, rather than relative ones; e.g. "C:/Documents and Settings/Your username/Desktop/screen_capture.jpg" rather than just "screen_capture.jpg". Cheers, Chris From steve+comp.lang.python at pearwood.info Sun May 1 21:09:21 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2011 01:09:21 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dbe0440$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 May 2011 14:15:35 +0100, Hans Georg Schaathun wrote: > On 01 May 2011 11:56:57 GMT, Steven D'Aprano > wrote: > : Just google on "stack overflow crash". > > And I get loads of examples of stack overflows, but I could not see > anybody linking this to logically correct recursion. Wikipedia, for > instance, mentions two common causes, neither of which has anything to > do with logically correct recursion. Ah, I see where you're coming from now! You think I'm arguing *against* the use of recursion. Not at all. Earlier in this thread, I said: "Consequently, the naive recursive function is ridiculously slow and memory-hungry. This seems to have give rise to a myth that recursion should be avoided. What needs to be avoided is *badly thought out* recursion." [Emphasis in original.] > : The Python virtual machine knows how big each entry on the stack > needs to : be. (I don't, but it's got to be at least the size of a > pointer.) So : "number of items" is just a multiplication away from > "size of the items". > > Does it? In a conventional stack you need to store all the local > variables for the function as well. Thus, there is no limit to how much > space a single element on the stack may require. To be honest, I don't know what Python does with local variables. But I *guess* it uses a constant-sized record which points to the locals, because that's how I'd do it :) I do know that objects in CPython all live in the heap, not on the stack, so even if local variables are placed directly on the stack, that's only a pointer to the object, not the entire object. [...] > But all of this is in principle, and does not constitute any valid > reason to avoid recursion in practice. If you want to argue that > recursion is a bad thing in /practice/ you need a /practical/ argument. Okay. In *practice*, all else being equal, recursion is less efficient than iteration, especially in Python which doesn't optimize tail- recursion. So if you have a choice between two algorithms which are equally simple and clear, and one is recursive and the other uses iteration, the one with iteration will be more efficient. However, and equally in practice, it's unusual to have two equally simple algorithms. Usually one or the other will be much simpler than the other, and you should avoid "optimizing" code based on hypothetical considerations and instead prefer simple code over complicated, unless absolutely necessary. Given a choice between a complicated iterative algorithm and a simple recursive version, there's no prima facie reason to expect the recursive version to *necessarily* be slower than iteration in Python *merely* because it uses recursion. As always, if speed is an issue, profile and identify the bottlenecks before deciding how to fix them. -- Steven From tjreedy at udel.edu Sun May 1 21:42:45 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 21:42:45 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <9265d8FtkqU1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <9265d8FtkqU1@mid.individual.net> Message-ID: On 5/1/2011 6:33 PM, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> Python uses a data model of "name binding" and "call by object" (also >> known as "call by sharing"). > > It can be summed up in a less jargony way by saying that all > data is stored in heap-allocated objects, This is incomprehensible jargon to some; is only (partly) true of (typical) machine-implementations; and seems not to be true of all objects. I believe that for CPython, builtin objects, including the fixed arrray of ints from -5 to 256, are allocated in another data segment (more CS jargon, which is irrelavant to human interpreters). Evidence 1: >>> id(int) 505285072 >>> id(str) 505233232 >>> id(1) 505493792 >>> id(-5) 505493696 This appears to be initialized data segment. (Someone else could take a white box approach and look at the source. ;-) >>> id(333333) 16512288 >>> id('a') 11227616 This is heap. Evidence 2: Some error messages use 'heap type' to mean 'Python-coded class' >>> 1 .__class__ = str Traceback (most recent call last): File "", line 1, in 1 .__class__ = str TypeError: __class__ assignment: only for heap types http://bugs.python.org/issue4600 > and variables refer to objects rather than containing them directly. > Everything else follows from that. Would you say 'names refer to objects rather than containing them directly'? Surely not. Using 'name' rather than the hugely overloaded tern 'variable' automatically avoids certain misunderstandings. A good summary might be "Python manipulates objects that are accessed through literals, names, and expressions." -- Terry Jan Reedy From benjamin.kaplan at case.edu Sun May 1 22:15:20 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 1 May 2011 22:15:20 -0400 Subject: Compile 32bit C-lib on 64 bit In-Reply-To: <20110501201413.GB6310@arxnet.hu> References: <20110501201413.GB6310@arxnet.hu> Message-ID: On Sun, May 1, 2011 at 4:14 PM, Heged?s Ervin wrote: > Hello, > > this is not a "clear" Python question - I've wrote a module in C, > which uses a 3rd-party lib - it's a closed source, I just get the > .so, .a and a header file. > > Looks like it works on 32bit (on my desktop), but it must be run > on 64bit servers. > > > When I'm compiling it on 64bit, gcc says: > > /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when searching for -l3rdpartyCrypt > > There _is_ the .so in /lib32 directory: > > ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), > dynamically linked, stripped > > > What is the correct solution? > > > thank you: > > > a. You cannot link a 64-bit binary against a 32- bit library. It just won't work. If you can't get a 64-bit copy of that library, you'll have to compile everything (including Python and all its dependencies) as 32-bit. > > -- > http://mail.python.org/mailman/listinfo/python-list > From nobody at nowhere.com Sun May 1 22:20:40 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 02 May 2011 03:20:40 +0100 Subject: Compile 32bit C-lib on 64 bit References: Message-ID: On Sun, 01 May 2011 22:14:14 +0200, Heged?s Ervin wrote: > When I'm compiling it on 64bit, gcc says: > > /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when > searching for -l3rdpartyCrypt > > There _is_ the .so in /lib32 directory: > > ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically > linked, stripped > > > What is the correct solution? You need to build your module for a 32-bit version of Python. On a 64-bit system, each process is either 32-bit or 64-bit process. You can't mix 32-bit code and 64-bit code in a single process. If you have to use that library and you only have a 32-bit version of it, then everything else must also be 32-bit: the Python interpreter, your binary module, and all of the libraries which it uses. From tjreedy at udel.edu Sun May 1 22:30:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 22:30:02 -0400 Subject: Fibonacci series recursion error In-Reply-To: References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/1/2011 7:16 PM, BartC wrote: > Yes, it generates lots of calls. > > About 22000 for fib(20), and 330 million for fib(40). Using the standard double recursion implementation of fib, ncf(n) (number of calls to fib() for fib(n)) requires ncf(n-2) + ncf(n+1) + 1 calls. The +1 is for the call to fib(n) itself). So it grows a bit faster than fib(n). Fib(n) is actually calculated as the sum of fib(n) 1s: 1+1+1....+1 fib(n) times as 1 is the only non-0 base case and there is nothing else added or multiplied in non-base cases. To put it another way, there are fib(n) leaf nodes labeled 1 in the unbalanced tree generated by the recursion. -- Terry Jan Reedy From no.email at nospam.invalid Sun May 1 22:37:26 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 01 May 2011 19:37:26 -0700 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> <87d3k2gkgb.fsf@benfinney.id.au> Message-ID: <7xei4hsu8p.fsf@ruckus.brouhaha.com> >> > Look at the big two sites for open-source repositories -- github and >> > bitbucket. > Note that there are three: Launchpad (backed by Bazaar) is the other > ?big site? for free-software project hosting. There is also patch-tag.com (using darcs) though it is smaller. From tjreedy at udel.edu Sun May 1 22:50:52 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 May 2011 22:50:52 -0400 Subject: PIL Question In-Reply-To: References: Message-ID: On 5/1/2011 9:00 PM, Chris Rebert wrote: > I would think to a file named "screen_capture.jpg" in the current > working directory. What that is for IDLE, I don't know. At least on windows with 3.2, if one just starts up the shell, it is in the Pythonxy directory. If one runs a file from an edit window, it changes to the directory of the file, so it operates much as if one had run with the command python -i file.py in the directory of file.py. > You can > determine what folder that is by running this in your Python shell: > > from os import getcwd; print(getcwd()) Yes, this gives two different answers in the two cases noted above. -- Terry Jan Reedy From rustompmody at gmail.com Sun May 1 23:06:40 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 1 May 2011 20:06:40 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> Message-ID: <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> On Apr 30, 8:21?am, CM wrote: > > A lone developer using such a VCS reaps the benefits of this by getting > > good merging support. > > While we're on the topic, when should a lone developer bother to start > using a VCS? ?At what point in the complexity of a project (say a hobby > project, but > a somewhat seriousish one, around ~5-9k LOC) is the added > complexity of bringing a VCS into it worth it? When you hit your first bug? Ok seriously, when you hit your first serious bug maybe? I am a bit surprised that no one has mentioned rcs so far Not an option if you are not on a *ix system and not something I am specifically recommending. [I grew up on rcs 15 years ago but not used it much of late] You may want to look at rcs if you are in the space where you want: -- something better than tarballs -- no pretensions beyond single-user, single-machine, (almost)single- file usage (ie small scale) -- something that integrates nicely with emacs From ben+python at benfinney.id.au Sun May 1 23:22:44 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 May 2011 13:22:44 +1000 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> Message-ID: <878vuphjln.fsf@benfinney.id.au> rusi writes: > You may want to look at rcs if you are in the space where you want: > -- something better than tarballs > -- no pretensions beyond single-user, single-machine, (almost)single- > file usage (ie small scale) > -- something that integrates nicely with emacs I might have agreed ten years ago; compared to CVS or Subversion, RCS is simpler to use and set up and had lower workflow overhead. But today, Bazaar or Mercurial fill that role just as well: quick simple set up, good tool support (yes, even in Emacs using VC mode), and easy to use for easy things. I really don't see any benefit to using RCS for even a lone hacker tracking files; Bazaar or Mercurial fill that role just as well, and continue to work well as your needs grow. -- \ ?Philosophy is questions that may never be answered. Religion | `\ is answers that may never be questioned.? ?anonymous | _o__) | Ben Finney From rustompmody at gmail.com Sun May 1 23:45:10 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 1 May 2011 20:45:10 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> <878vuphjln.fsf@benfinney.id.au> Message-ID: <5bb8f29f-077c-48f0-a047-ff0977ae0e01@j13g2000pro.googlegroups.com> On May 2, 8:22?am, Ben Finney wrote: > rusi writes: > > You may want to look at rcs if you are in the space where you want: > > -- something better than tarballs > > -- no pretensions beyond single-user, single-machine, (almost)single- > > file usage (ie small scale) > > -- something that integrates nicely with emacs > > I might have agreed ten years ago; compared to CVS or Subversion, RCS is > simpler to use and set up and had lower workflow overhead. > > But today, Bazaar or Mercurial fill that role just as well: quick simple > set up, good tool support (yes, even in Emacs using VC mode), and easy > to use for easy things. > > I really don't see any benefit to using RCS for even a lone hacker > tracking files; Bazaar or Mercurial fill that role just as well, and > continue to work well as your needs grow. In a word: single files. If you have a directory with a number of short unrelated scripts -- python, shell etc -- the philosophy: vcs-manages-projects-not-files is a nuisance not a help. And which is why things like zit http://git.oblomov.eu/zit have arisen: the need to go back from bzr/git/hg to (something like) rcs From drsalists at gmail.com Mon May 2 00:34:47 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 1 May 2011 21:34:47 -0700 Subject: Compile 32bit C-lib on 64 bit In-Reply-To: <20110501201413.GB6310@arxnet.hu> References: <20110501201413.GB6310@arxnet.hu> Message-ID: On Sun, May 1, 2011 at 1:14 PM, Heged?s Ervin wrote: > Hello, > > this is not a "clear" Python question - I've wrote a module in C, > which uses a 3rd-party lib - it's a closed source, I just get the > .so, .a and a header file. > > Looks like it works on 32bit (on my desktop), but it must be run > on 64bit servers. > > > When I'm compiling it on 64bit, gcc says: > > /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when > searching for -l3rdpartyCrypt > > There _is_ the .so in /lib32 directory: > > ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), > dynamically linked, stripped > > > What is the correct solution? > The best solution is to not use a closed source, binary-only, single-sourced (?) security library, especially if it has not been vetted by others from outside the organization from which it was obtained. It costs quite a bit for a company to get such software under enough eyeballs to make it mostly trustworthy, and it puts you at their mercy with regard to an upgrade path. The best security-related algorithms are published and studied by many researchers, and will have multiple interoperating implementations. Rebuilding everything as 32 bit on your 64 bit system (if it's one of those 64 bit systems that can also conveniently run 32 bit binaries - most, but not all, can) may be one of your better options. This of course carries a memory penalty, as you may end up with two copies of your python interpreter and relevant .so's in virtual memory, and hence experience a greater tendency to page. There is no theoretical reason why you cannot use a 32 bit library in a 64 bit application, however it is unlikely to be simple. You could experiment with accessing your 32 bit library via ctypes from a 64 bit interpreter and carefully converting pointers and integers to/from 32 bit and 64 bit (with a significant decrease in usable address space, and the possibility of 64 bit addresses that simply aren't convertible, especially, but not necessarily only, once your process gets large), if you find a way of setting up an appropriate 32 bit stack. You could also emulate a 32 bit CPU in your 64 bit process - this too, is perhaps mostly theoretical - see qemu for an example of something that can, EG, run x86 binaries on a sparc CPU. In short: "You probably could, but it might well be more trouble than it's worth". Another option would be to link your library into a small, 32 bit C program, and then establish some sort of protocol for it to communicate with your 64 bit python interpreter - via a pipe or socket, as examples. Without adequate vendor cooperation, and if you're truly locked in, this may actually be one of your better options for the medium term. Ultimately though, using something like KeyCzar or OpenSSL is probably your best bet. They've been scrutinized copiously, and have very low snake oil factors. That is, assuming KeyCzar or OpenSSL and your binary-only library have overlapping purposes. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon May 2 00:48:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 14:48:27 +1000 Subject: Compile 32bit C-lib on 64 bit In-Reply-To: References: <20110501201413.GB6310@arxnet.hu> Message-ID: On Mon, May 2, 2011 at 2:34 PM, Dan Stromberg wrote: > Another option would be to link your library into a small, 32 bit C program, > and then establish some sort of protocol for it to communicate with your 64 > bit python interpreter - via a pipe or socket, as examples. This is what I would recommend. A Unix socket or pipe or other pure memory IPC mechanism can give some pretty high bandwidth, and it keeps two processes happily isolated, plus it lets the OS handle any conversions necessary (as opposed to your glue code, which is what would happen if you link the 32-bit library to your 64-bit app). Let the operating system do my work for me? Don't mind if I do... Chris Angelico From hg at schaathun.net Mon May 2 01:36:06 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 2 May 2011 06:36:06 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6fs198-8lf.ln1@svn.schaathun.net> On Mon, 2 May 2011 06:49:41 +1000, Chris Angelico wrote: : Sure. Serialize this Python object in a way that can be given to, say, PHP: : foo={"asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo] : Recurse from self into the list, recurse from there into a : dictionary... Okay, that's a rather naive recursion and fraught with : risk, but there are more complex examples. And watching for cyclic : references would be O(N*N) as you'd need to maintain a full list of : every PyObject* that you've sighted (talking here from the C API, but : the same consideration applies whichever way you do it). Wouldn't cyclic references give infinite recursion? And remain infinitive if you recode it iteratively? : I'm not sure that recursion is clearer. Recursion is a way of : expressing the two rules: : : 1! = 1 : n! = n * (n-1)! : : But iteration is a way of expressing this equivalent rule: : : n! = 1 * 2 * 3 * ... * n-1 * n : : It really depends what you're trying to say. True. There is a place for everything. However, in the example above, you can map the recursive definition directly into python without further ado. In order to express the one-liner in python, as iteration, you need to introduce additional elements, namely a state (index variable). Hence, recursion is clearer by being close to the language you would normally use to describe the problem. -- :-- Hans Georg From rosuav at gmail.com Mon May 2 02:28:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 16:28:45 +1000 Subject: Fibonacci series recursion error In-Reply-To: <6fs198-8lf.ln1@svn.schaathun.net> References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> <6fs198-8lf.ln1@svn.schaathun.net> Message-ID: On Mon, May 2, 2011 at 3:36 PM, Hans Georg Schaathun wrote: > On Mon, 2 May 2011 06:49:41 +1000, Chris Angelico > ? wrote: > : ?Sure. Serialize this Python object in a way that can be given to, say, PHP: > : ?foo={"asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo] > > Wouldn't cyclic references give infinite recursion? ?And remain > infinitive if you recode it iteratively? Well, I don't know of a decent non-recursive way to process a recursive structure. Incidentally, this example is almost directly from some working code of ours; I have a C function that recurses over a Python dictionary and aborts as soon as it's found "too much" data (for a fairly arbitrary definition of "too much", but one that's deliberately designed to prevent infinite recursion). Since every element in the dictionary can be a list/dict, and every element of those can be too, there's no non-recursive way to do it, other than by doing the recursion yourself: # partly pseudocode searchme=[foo] while len(searchme): cur=get_next_elem(searchme[-1]) if cur==end_of_list: searchme[-1:]=[] else: if can_be_recursed_into(cur): searchme.append(cur) else: output(cur) This would work, more or less, but it merely trades "true" recursion for the searchme[] stack. Yes, it's iterative. No, it hasn't abolished recursion. > True. ?There is a place for everything. ?However, in the example > above, you can map the recursive definition directly into python > without further ado. ?In order to express the one-liner in python, > as iteration, you need to introduce additional elements, namely > a state (index variable). ?Hence, recursion is clearer by being > close to the language you would normally use to describe the > problem. True, and you could abolish a lot of temporary variables by turning them into parameters to recursive calls. But you've abolished nothing. The recursive factorial is very similar to: reduce(`*,range(1,n+1)) The iterative is very similar to: reduce(`*,xrange(1,n+1)) One of 'em stacks up all the numbers and the other gets 'em as it needs 'em. Fundamentally, there's really not a lot of difference. By piling up the numbers on your stack, you just change the format of your saved state, you don't actually save anything. Chris Angelico From rosuav at gmail.com Mon May 2 02:30:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 16:30:53 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> <6fs198-8lf.ln1@svn.schaathun.net> Message-ID: On Mon, May 2, 2011 at 4:28 PM, Chris Angelico wrote: > reduce(`*,range(1,n+1)) > reduce(`*,xrange(1,n+1)) Whoops, forgot which language I was using. Back-tick functions not being available, these need to be: reduce(operator.mul,range(1,n+1)) reduce(operator.mul,xrange(1,n+1)) Chris Angelico From airween at gmail.com Mon May 2 02:41:14 2011 From: airween at gmail.com (=?utf-8?B?SGVnZWTDvHMs?= Ervin) Date: Mon, 2 May 2011 08:41:14 +0200 Subject: Py_INCREF() incomprehension In-Reply-To: References: Message-ID: <20110502064113.GB2614@arxnet.hu> hello, Thomas, Gregory, thank you for your ansrwers, > I guess this is the point where yo should start printf programing. oh', already done :) > * What happens during module initialization? successfully initialized, > * What happens n the functions? > * Where does the stuff fail? > * What are the reference counts of the involved objects? sorry for the dumb question: how can I controll number of reference in C? > > PyModule_AddObject(o, "error", cibcrypt_error_nokey); > > Py_INCREF(cibcrypt_error_nokey); > > > >and now if there is some expected exception, I get it. > > >Any explanation? > > I don't have one - I would think that if the module object exists > for all the time, it would be enough to have one reference there. > > But obviously it is not enough - did you at any time del something > related to here? The module or one of its attributes? > > Anyway, it seems safer to do INCREF here - so do it. (As Gregory > already stated - it looks cleaner if you do INCREF before > AddObject.) ok, > > >ps: this is just for my passion, but I would like to understand > >it very-very much :) > > Understandable. That's that the printf debugging of the refcounts > can be good for - even if you don't really have a problem. thanks, I'll go to read the docs :) bye: a. From airween at gmail.com Mon May 2 02:43:39 2011 From: airween at gmail.com (=?utf-8?B?SGVnZWTDvHMs?= Ervin) Date: Mon, 2 May 2011 08:43:39 +0200 Subject: Compile 32bit C-lib on 64 bit In-Reply-To: References: Message-ID: <20110502064337.GC2614@arxnet.hu> Hello, thanks for all reply, On Mon, May 02, 2011 at 03:20:40AM +0100, Nobody wrote: > You need to build your module for a 32-bit version of Python. ok, I believed it, I was hoping there is another solution, > On a 64-bit system, each process is either 32-bit or 64-bit process. You > can't mix 32-bit code and 64-bit code in a single process. If you have to > use that library and you only have a 32-bit version of it, then everything > else must also be 32-bit: the Python interpreter, your binary module, and > all of the libraries which it uses. ok, thank you, a. From stefan_ml at behnel.de Mon May 2 03:07:31 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 02 May 2011 09:07:31 +0200 Subject: Py_INCREF() incomprehension In-Reply-To: <20110502064113.GB2614@arxnet.hu> References: <20110502064113.GB2614@arxnet.hu> Message-ID: Heged?s, Ervin, 02.05.2011 08:41: > Thomas, >> I guess this is the point where yo should start printf programing. > > oh', already done :) FWIW, Cython 0.14+ has special support for gdb now, so, in addition to print and printf debugging, you can also use gdb to explore the state of your application, be it at the Python, Cython or C level. http://docs.cython.org/src/userguide/debugging.html Stefan From akabaila at pcug.org.au Mon May 2 03:08:02 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Mon, 2 May 2011 17:08:02 +1000 Subject: Development tools and practices for Pythonistas In-Reply-To: <878vuphjln.fsf@benfinney.id.au> References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> <878vuphjln.fsf@benfinney.id.au> Message-ID: <201105021708.02806.akabaila@pcug.org.au> On Monday 02 May 2011 13:22:44 Ben Finney wrote: > rusi writes: > > You may want to look at rcs if you are in the space where > > But today, Bazaar or Mercurial fill that role just as well: > quick simple set up, good tool support (yes, even in Emacs > using VC mode), and easy to use for easy things. > Actually, Bazaar is more convenient than rcs for a single user, as the repository can be the working directory (with a "hidden" .bzr directory that stores diffs). I had to use git, too, because some projects use git for their version control (viz PySide, Nokia's tool to replace PyQt). IMHO there is not much to pick between git and Bazaar and hg is also rather similar. The remaining doubts are betwwed the Distributed Version Control and the more traditional Subversion, which is also quite nice, even for a single user. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf From rustompmody at gmail.com Mon May 2 03:08:26 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 00:08:26 -0700 (PDT) Subject: Fibonacci series recursion error References: <1zMup.12761$rB2.10164@newsfe21.iad> Message-ID: On Apr 30, 11:14?am, Peter Otten <__pete... at web.de> wrote: > For the record, the one true way to implement the Fibonacci series in Python > is > > >>> def fib(): > > ... ? ? a = b = 1 > ... ? ? while True: > ... ? ? ? ? ? ? yield a > ... ? ? ? ? ? ? a, b = b, a+b # look ma, no temporary variable Not any claim to 'the one true pythonic way' but fib can be written in a clean recursive way with linear space-time behavior asz follows: Dijkstra explained that fib is an 2nd order recurrence -- fib(n) defined in terms of fib (n-1) and fib(n-2) whereas programming loops and recursion are 1st order -- state at iteration n defines state at iteration n+1. Converting the 2nd order fib relation to a 1st order one trivially gives a linear program. The key insight from Dijkstra is that all we need to do is to move from a recursive function returning fibonacci nos to one returning pairs of adjacent ones. def fibpair(n): # returns (fib(n), fib(n+1)) if n==0: return (1,1) else: (a,b) = fibpair(n-1) return (b, a+b) After that fib is just this: def fib(n): a,b = fibpair(n) return a; From rustompmody at gmail.com Mon May 2 03:19:57 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 00:19:57 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> <878vuphjln.fsf@benfinney.id.au> Message-ID: On May 2, 12:08?pm, Algis Kabaila wrote: > > Actually, Bazaar is more convenient than rcs for a single user, > as the repository can be the working directory (with a "hidden" > .bzr directory that stores diffs). ? Dont exactly understand... Is it that you want it specifically hidden? Otherwise rcs will look inside an RCS directory just as bzr will with .bzr git will with .git and so on. From grahn+nntp at snipabacken.se Mon May 2 03:45:20 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 2 May 2011 07:45:20 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 2011-05-01, Terry Reedy wrote: > On 5/1/2011 4:45 AM, Steven D'Aprano wrote: ... >> What other languages use the same, or mostly similar, data model as >> Python? > > Natural languages. That is why I think it is better to think of Python > as an algorithm language or information-object manipulation language > rather than as just a linear-memory machine language.A linear memory > with bytes addressed from 0 to max-int or max-long is an explicit part > of the definition of assembly languages and C. It is no part of the > definition of Python. It's not part of the definition of C either -- C supports segmented memory (pre-386 Intel) and separate code/data address spaces. (Even if most C users tend not to think of it that way.) /Jorgen -- // Jorgen Grahn O o . From ozric at web.de Mon May 2 03:48:09 2011 From: ozric at web.de (christian) Date: Mon, 2 May 2011 00:48:09 -0700 (PDT) Subject: build the "sql where cause" dynamic Message-ID: Hi, from some radio buttons in a django app i concat string like that: But have no idea how i get the or when there different values for a specified p column (# is currently my intended splitter maybe i can concat a better input?). input: "p2=1#p2=2#p1=3#p1=1#p1=5#pc=1#py=1" output: "p2 in ('1','2') and p1 in ('3','1','5') and pc in ('1') and py in ('1')" Many thanks for any starting point Christian From akabaila at pcug.org.au Mon May 2 03:48:31 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Mon, 2 May 2011 17:48:31 +1000 Subject: Development tools and practices for Pythonistas In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <201105021748.31818.akabaila@pcug.org.au> On Monday 02 May 2011 17:19:57 rusi wrote: > On May 2, 12:08 pm, Algis Kabaila wrote: > > Actually, Bazaar is more convenient than rcs for a single > > user, as the repository can be the working directory (with > > a "hidden" .bzr directory that stores diffs). > > Dont exactly understand... > Is it that you want it specifically hidden? > Otherwise rcs will look inside an RCS directory just as bzr > will with .bzr git will with .git and so on. Sorry for not being clear - "ls" will not show directories that start with "." - in that sense these directories are "hidden". They are not really really hidden, as "ls -l" will show them. They simply are not in the way and keep the progressive versions of the program (in form of diffs). Does that make better sense?. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf From nirina.raseliarison at gmail.com Mon May 2 03:48:54 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Mon, 02 May 2011 10:48:54 +0300 Subject: PIL Question In-Reply-To: References: Message-ID: [PyNewbie] > Question: I can't seem to find the captured image, where does it go? for me, it just goes to the current working directory: $ python -i 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 PIL import ImageGrab >>> ImageGrab.grab().save("screen_capture.jpg", "JPEG") >>> import os >>> os.listdir(os.getcwd()) ['.appcfg_cookies', '.appcfg_nag', '.bash_history', '.idlerc', '.inputrc', '.povray', 'bootex.log', 'buildBasicDemo.txt', 'glsample.cpp', 'glsample.o', 'log.txt', 'screen_capture.jpg', 'test.c'] >>> -- nirinA From rosuav at gmail.com Mon May 2 04:13:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 18:13:06 +1000 Subject: build the "sql where cause" dynamic In-Reply-To: References: Message-ID: On Mon, May 2, 2011 at 5:48 PM, christian wrote: > Hi, > > from some radio buttons in a django app i concat ?string like that: > But have no idea how i get the or when there different values > for a specified p column (# is currently my intended splitter maybe i > can concat a better input?). > > input: "p2=1#p2=2#p1=3#p1=1#p1=5#pc=1#py=1" > > output: "p2 in ('1','2') and p1 in ('3','1','5') and pc in ('1') and > py in ('1')" Start by splitting the string and iterating: for el in input.split('#'): (obviously your variable won't want to be called 'input' but you knew that already) Then split on the = sign and add to a list or dictionary. Be wary of elements that don't have an equals sign in them. That looks like the querystring straight from the GET form, where you're using tickboxes. You could quite happily use '&' as your primary delimiter, if that's the case. Chris Angelico From anurag26 at kqinfotech.com Mon May 2 04:19:25 2011 From: anurag26 at kqinfotech.com (Anurag Agarwal) Date: Mon, 2 May 2011 01:19:25 -0700 (PDT) Subject: How to build an application in Django which will handle Multiple servers accross network References: <4eb9697f-6954-4cc0-b2c3-11f3746b049a@a19g2000prj.googlegroups.com> <1304071291.11695.1.camel@linux-yu4c.site> Message-ID: <4b79e1e0-2591-48f2-91f9-ca5c185bc61d@d26g2000prn.googlegroups.com> Hi All, Thanks for the resposes. I think I was not able to communicate my problem very well. Here I am not managing any network devices, what i am doing is getting some info from various servers on netowrk. I don't know how to explain what kind of info is needed, but for the time if you just assume that a driver for windows and linux is already written which has command line interface too which gets certain info about server. Now the information returned by this driver software from each server is to be shown at a common place. For this I am planning a web based application that can connect to each individual server and get the info and show it on UI. For this to happen i need some interface to which my web based application (to be developed in Django and Python) can connect to each server in network and call the driver methods on that server to get the info. I hope now i am clear with my thoughts. Please mail me back if still I am not clear. The solutions I got 1. Using WMI on windows but how it will work on Linux?. 2. Pyro which supports remote objects. 3. Open NMS - it is a java based open source project, we don't have any expertise in java... I want something that can be integrated with python and django. 4. ZenOSS - It is for managing some IP based devices on network.. I don't know how it will help me. Please give me some ideas on python even it needs some development effort. Regards, Anurag On Apr 29, 5:21?pm, Adam Tauno Williams wrote: > On Fri, 2011-04-29 at 13:24 +0200, Paul K?lle wrote: > > Am 29.04.2011 12:01, schrieb Adam Tauno Williams: > > >> 3. The web based application will be used internally in the network to > > >> moniter servers in that network only. > > > You mean like OpenNMS or ZenOSS? > > >> 4. Web based application will be a real time application with a > > >> Database. > > > Like OpenNMS or ZenOSS? > > How can they be realtime if they generate static images? > > All images are static regardless of how much they pretend not to be. > You can refresh as much as you like. ?But a graph shows a progression > over time so there is always an interval. > > > >> 5. Technology I am thingking for web based application is Django and > > >> Python as this web application can also be installed on Windows or > > >> Linux based OS. > > > If you want real-time monitoring you *must* build a service; a 'web app' > > > can *not* do that. > > Do you mean an agent? > > No, just use WMI over the wire. ?Agents are terrible, hard to develop, > unreliable, and everyone hates agents. ?The systems already provide you > access to the information you are talking about. > > > >> 6. Also please suggest which third party tool for chatrs and graphs I > > >> should use with Django (open source + paid) > > > ZenOSS and OpenNMS do graphs using RRD. > > I know this is the "standard" but IMO it's totally backward these days. > > Correlating or selecting/deselecting certain values is painful > >(you have to write a graph def) > > How is it painful? ?Of course you have to create a graph definition - in > your case you are creating a graph definition BY WRITING CODE! ?There > couldn't be a more painful way to just create a graph. > > Have you used recent versions of ZenOSS? ?Graph definitions can be > created right in the UI. > > > . With and modern JS libs like raphael > > there are better ways to do this. Just look at google analytics. > > I've seen it. ?I don't see how it is "better". ?It's a graph. > > > It looks like PCP (http://oss.sgi.com/projects/pcp/features.html) will > > gain a JSON interface shortly. That would be awesome because PCP is > > developed by real engineers and has a proper architecture and is NOT a > > CPU sucking monstrosity of PERL-line-noise + a few hacked-together PHP > > frontends. > > I have no idea where the "PERL-line-noise + a few hacked-together PHP > frontend" comment comes from. ?RRD is written in C. ?OpenNMS is Java and > ZenOSS is Python/ZOPE. > > And as for "CPU sucking monstrosity" that is what everyone says... until > they try to build a monitoring application... and thus create their own > "CPU sucking monstrosity". ?This is a case of > those-who-refuse-to-use-are-doomed-to-reinvent. From emakhmudow at gmail.com Mon May 2 04:21:45 2011 From: emakhmudow at gmail.com (anvar) Date: Mon, 2 May 2011 01:21:45 -0700 (PDT) Subject: HI Message-ID: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> Hello, Could you please help me with the modeling in Python the following problem: (e.g., g_t means g with index t) Min?_(i=1)^n??_(t=1)^l?[s_i (t)-min[s ?_i (t)??_t?exp(g_t ),C_i (t) ] ]^2 subject to s_i (t)=f_i (t)[S_i+f_(i-1) (t)[S_(i-1)+f_(i-2) (t)[S_(i-2)+?f_2 (t) [S_2+f_1 (t) S_1 ]?] ] ][1-f_(i+1) (t)] f_i (t)=F_i (t)-F_i (t-1) F_i (t)=(((1-e^(-(X_i (t)-X_i (0) )(p_i+q_i ) )))/(((q_i?p_i ) e^(- (X_i (t)-X_i (0) )(p_i+q_i ) )+1)), if t??_i and F_i (t)=0 if t0, ?i=1,2,?,n Where s ?_i (t)=p_i S_i +(q_i-p_i ) s_i (t-1)-(q_i/S_i ) [s_i (t-1) ]^2, S_i=?_i (t)M_i From emakhmudow at gmail.com Mon May 2 04:26:52 2011 From: emakhmudow at gmail.com (anvar) Date: Mon, 2 May 2011 01:26:52 -0700 (PDT) Subject: HI References: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> Message-ID: Here we need to estimate p_i, q_i, and ?. Thank you, > Min?_(i=1)^n??_(t=1)^l?[s_i (t)-min[s ?_i (t)??_t?exp(g_t ),C_i > (t) ] ]^2 > subject to > s_i (t)=f_i (t)[S_i+f_(i-1) (t)[S_(i-1)+f_(i-2) (t)[S_(i-2)+?f_2 (t) > [S_2+f_1 (t) S_1 ]?] ] ][1-f_(i+1) (t)] > f_i (t)=F_i (t)-F_i (t-1) > F_i (t)=(((1-e^(-(X_i (t)-X_i (0) )(p_i+q_i ) )))/(((q_i?p_i ) e^(- > (X_i (t)-X_i (0) )(p_i+q_i ) )+1)), if t??_i ? ? and F_i (t)=0 ?if > t X_i (t)=(t-?_i+1)+ln(?pr?_i (t)/?pr?_i (0))? > ?_t?0, ? ? ? g_t=const > 0 S_i>0, > ?i=1,2,?,n > Where > s ?_i (t)=p_i S_i ?+(q_i-p_i ) s_i (t-1)-(q_i/S_i ) [s_i (t-1) ]^2, > S_i=?_i (t)M_i From rustompmody at gmail.com Mon May 2 04:27:39 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 01:27:39 -0700 (PDT) Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 30, 12:18?pm, Steven D'Aprano wrote: > The number of calls is given by a recursive function with a similar form > as that of Fibonacci. As far as I know, it doesn't have a standard name, > but I'll call it R(n): > > R(n) = R(n-1) + R(n-2) + 1, where R(0) = R(1) = 1 Changing your definition slightly to the following: def r(n): if n==0 or n==1: return 0 else: return r(n-1) + r(n-2) + 1 This r counts the number of times the '+' is done in the original (naive) fib. We see it is the same as fib (off by 1) >>> [fib(n) for n in range(10)] [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] >>> [r(n) for n in range(10)] [0, 0, 1, 2, 4, 7, 12, 20, 33, 54] >>> So it does not need a new name :-) From grahn+nntp at snipabacken.se Mon May 2 04:31:37 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 2 May 2011 08:31:37 GMT Subject: Compile 32bit C-lib on 64 bit References: Message-ID: On Sun, 2011-05-01, Heged?s Ervin wrote: > Hello, > > this is not a "clear" Python question - I've wrote a module in C, > which uses a 3rd-party lib - it's a closed source, I just get the > .so, .a and a header file. > > Looks like it works on 32bit (on my desktop), but it must be run > on 64bit servers. > > > When I'm compiling it on 64bit, gcc says: > > /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when searching for -l3rdpartyCrypt A different angle: if you need to use closed-source, non-standard crypto, and the suppliers cannot even be bothered to compile it for the CPU architecture that has been standard for at least 6--7 years, start planning to replace it *now*. /Jorgen -- // Jorgen Grahn O o . From ulrich.eckhardt at dominolaser.com Mon May 2 04:34:11 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 02 May 2011 10:34:11 +0200 Subject: codec for UTF-8 with BOM Message-ID: Hi! I want to write a file starting with the BOM and using UTF-8, and stumbled across some problems: 1. I would have expected one of the codecs to be 'UTF-8 with BOM' or something like that, but I can't find the correct name. Also, I can't find a way to get a list of the supported codecs at all, which strikes me as odd. 2. I couldn't find a way to write the BOM either. Writing codecs.BOM doesn't work, as it is an already encoded byte string. Of course, I can write u'\ufeff', but I'd rather avoid such magic numbers in my code. 3. The docs mention encodings.utf_8_sig, available since 2.5, but I can't locate that thing there either. What's going on here? What would you do? Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From duncan.booth at invalid.invalid Mon May 2 04:43:47 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 2 May 2011 08:43:47 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Dennis Lee Bieber wrote: > As I recall from my programming language design class (only and > intro, it was so small we met in a meeting room rather than classroom), > ALGOL was described as "call by name"; It is true that Algol had 'call by name', but (at least the Algol-W that I learned) also supported 'call by value' and 'call by reference'. The danger of course was that call by name was the default mechanism so you could end up using it accidentally. I remember we had one class where we had to work out (by hand) the output of a program which used call by name to alias I and A[I] in some recursive calls. Not nice. Fortunately even at that time it was mostly being taught as an oddity; real programming was of course done in Algol 68C or BCPL. -- Duncan Booth http://kupuguy.blogspot.com From steve+comp.lang.python at pearwood.info Mon May 2 04:56:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2011 08:56:57 GMT Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 May 2011 01:27:39 -0700, rusi wrote: > On Apr 30, 12:18?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > >> The number of calls is given by a recursive function with a similar >> form as that of Fibonacci. As far as I know, it doesn't have a standard >> name, but I'll call it R(n): >> >> R(n) = R(n-1) + R(n-2) + 1, where R(0) = R(1) = 1 > > Changing your definition slightly to the following: > > def r(n): > if n==0 or n==1: return 0 > else: return r(n-1) + r(n-2) + 1 Except that's not the same as my "R(n)". The base cases should be 1, not 0. That makes rather a big difference to the value: by n = 35, you have R(35) = 29860703 fib(35) = 9227465 or nearly 2.25 times greater. And the difference just keeps getting bigger... > We see it is the same as fib (off by 1) [...] > So it does not need a new name :-) I see your smiley, but there are a number of similar series as Fibonacci, with the same recurrence but different starting values, or similar but slightly different recurrences. E.g. Lucas, primefree, Pell, Padovan and Perrin numbers. (The fact that most of those start with P is almost certainly a coincidence.) -- Steven From rosuav at gmail.com Mon May 2 05:03:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 May 2011 19:03:40 +1000 Subject: Fibonacci series recursion error In-Reply-To: <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 2, 2011 at 6:56 PM, Steven D'Aprano wrote: > (The fact that most of those start with P is almost certainly a > coincidence.) > There's definitely something attractive about that letter. Lots of programming languages' names start with P. I smell a conspiracy. The word "programming" has been secretly attracting related words to its corner of the alphabet... and the government's *covering it up* and pretending there's nothing happening! Chris Angelico From jacek2v at gmail.com Mon May 2 05:09:38 2011 From: jacek2v at gmail.com (jacek2v) Date: Mon, 2 May 2011 02:09:38 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <3a93d484-ca0a-41d9-afdb-509cfdcc918b@e21g2000yqe.googlegroups.com> On May 2, 9:48?am, Algis Kabaila wrote: > On Monday 02 May 2011 17:19:57 rusi wrote: > > > On May 2, 12:08 pm, Algis Kabaila > wrote: > > > Actually, Bazaar is more convenient than rcs for a single > > > user, as the repository can be the working directory (with > > > a "hidden" .bzr directory that stores diffs). > > > Dont exactly understand... > > Is it that you want it specifically hidden? > > Otherwise rcs will look inside an RCS directory just as bzr > > will with .bzr git will with .git and so on. > > Sorry for not being clear - "ls" will not show directories that > start with "." - in that sense these directories are "hidden". ? > They are not really really hidden, as "ls ?-l" will show them. ? > They simply are not in the way and keep the progressive versions > of the program (in form of diffs). "ls -l will not show directories that start with ".". "ls -a" will. Regards Jacek From alec.taylor6 at gmail.com Mon May 2 05:33:30 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 2 May 2011 19:33:30 +1000 Subject: Deditor In-Reply-To: References: <74a2f743-aa0a-4beb-8c62-3e32b6ac7489@k22g2000yqh.googlegroups.com> <75a7cd73-50c9-4dc0-a88d-68051f1e3795@k22g2000yqh.googlegroups.com> <761080e3-bbda-4c3b-a38b-f9e0b1e4dcad@a10g2000vbz.googlegroups.com> <2cc05cc3-2c8a-42ba-bb7b-348206546378@k11g2000yqc.googlegroups.com> <35348319-4042-4929-a81c-2e1cec7de3f3@b19g2000yqg.googlegroups.com> <7d8e78d2-8a90-431e-8a5d-d9f81d393e40@j26g2000yqa.googlegroups.com> Message-ID: Yes On Mon, May 2, 2011 at 2:12 AM, Kruptein wrote: > On 1 mei, 17:50, Alec Taylor wrote: >> Traceback (most recent call last): >> ?File "O:\deditor\deditor\deditor.py", line 7, in > e> >> ? ?import wx, os, datetime, sys, ConfigParser, wx.aui, wx.lib.scrolledpanel >> ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4 >> 5, in >> ? ?from wx._core import * >> ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i >> n >> ? ?import _core_ >> ImportError: DLL load failed: %1 is not a valid Win32 application. >> >> >> >> On Mon, May 2, 2011 at 12:33 AM, Kruptein wrote: >> > On 1 mei, 10:59, Alec Taylor wrote: >> >> Maybe I'm missing something, but I downloaded the zip file and ran >> >> each .py and .pyc file in turn, but none brought up the nicededitor >> >> GUI I've seen screenshots of... >> >> >> On the other subject, did you have a preference to what installer I >> >> should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi) >> >> > not a msi, for the rest it doesn't matter :), ?on my windows if you >> > rundeditor.py ? it should launch however you need to have the >> > wxpython-2.8 package installed, ? what happens if you rundeditor.py >> > from console? >> > -- >> >http://mail.python.org/mailman/listinfo/python-list > > that looks like you have installed the wxpython module wrongly. ?Have > you downloaded the version that matches your python version? > -- > http://mail.python.org/mailman/listinfo/python-list > From hg at schaathun.net Mon May 2 05:41:48 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 2 May 2011 10:41:48 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe0440$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02 May 2011 01:09:21 GMT, Steven D'Aprano wrote: : Ah, I see where you're coming from now! You think I'm arguing *against* : the use of recursion. Not at all. Earlier in this thread, I said: Fair enough. Somebody said something about recursion mainly being a beginner's error. I don't think it was you, but I felt that your argument in context mainly served to reinforce such a view, whether intended or not. : "Consequently, the naive recursive function is ridiculously slow and : memory-hungry. : : This seems to have give rise to a myth that recursion should be avoided. : What needs to be avoided is *badly thought out* recursion." Then we agree. And badly thought-out iteration is as bad as badly thought-out recursion. : To be honest, I don't know what Python does with local variables. But I : *guess* it uses a constant-sized record which points to the locals, : because that's how I'd do it :) Maybe, but would it be able to treat specially C API functions with a large chunk of stack memory used for local variables? : Given a choice between a complicated iterative algorithm and a simple : recursive version, there's no prima facie reason to expect the recursive : version to *necessarily* be slower than iteration in Python *merely* : because it uses recursion. As always, if speed is an issue, profile and : identify the bottlenecks before deciding how to fix them. Then we are on the same page. And it is becoming increasingly clear how bizarre this discussion is in a python context. The overhead which may be caused by recursion in hardware is only one of many sources of overhead which one accepts when opting to use python in order to gain other benefits. -- :-- Hans Georg From clp2 at rebertia.com Mon May 2 05:47:45 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 May 2011 02:47:45 -0700 Subject: codec for UTF-8 with BOM In-Reply-To: References: Message-ID: On Mon, May 2, 2011 at 1:34 AM, Ulrich Eckhardt wrote: > Hi! > > I want to write a file starting with the BOM and using UTF-8, and stumbled > across some problems: > > 1. I would have expected one of the codecs to be 'UTF-8 with BOM' or > something like that, but I can't find the correct name. Also, I can't find a > way to get a list of the supported codecs at all, which strikes me as odd. If nothing else, there's http://docs.python.org/library/codecs.html#standard-encodings The correct name, as you found below and as is corroborated by the webpage, seems to be "utf_8_sig": >>> u"FO?bar".encode('utf_8_sig') '\xef\xbb\xbfFO\xc3\xb8bar' This could definitely be documented more straightforwardly. > 3. The docs mention encodings.utf_8_sig, available since 2.5, but I can't > locate that thing there either. What's going on here? Works for me?: Python 2.6.6 (r266:84292, Jan 12 2011, 13:35:00) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from encodings import utf_8_sig >>> Cheers, Chris -- http://rebertia.com From hg at schaathun.net Mon May 2 05:53:52 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 2 May 2011 10:53:52 +0100 Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02 May 2011 08:56:57 GMT, Steven D'Aprano wrote: : I see your smiley, but there are a number of similar series as Fibonacci, : with the same recurrence but different starting values, or similar but : slightly different recurrences. E.g. Lucas, primefree, Pell, Padovan and : Perrin numbers. Well, Fibonacci isn't one unique sequence. Any sequence satisfying f(n) = f(n-1) + f(n-2) is /a/ Fibonacci sequence. Regardless of starting values. At least according to some authors. Ian Andersen (A First Course in Combinatorial Mathematics) prefer the sequence 1,2,3,5 ... Cormen, Leiserson, Rivest (Introduction to Algorithms) prefer 0,1,1,2, ... (although they also start the indexing at 0). Penguin, Dict. of Mathematics prefer 1,1,2,3,5 but they also suggest 0,1,1,2,3, ... In short, don't assume that a person talking about Fibonacci numbers assume the same base cases as you do. -- :-- Hans Georg From sjmachin at lexicon.net Mon May 2 06:13:44 2011 From: sjmachin at lexicon.net (John Machin) Date: Mon, 2 May 2011 03:13:44 -0700 (PDT) Subject: codec for UTF-8 with BOM In-Reply-To: Message-ID: On Monday, 2 May 2011 19:47:45 UTC+10, Chris Rebert wrote: > On Mon, May 2, 2011 at 1:34 AM, Ulrich Eckhardt > wrote: > The correct name, as you found below and as is corroborated by the > webpage, seems to be "utf_8_sig": > >>> u"FO?bar".encode('utf_8_sig') > '\xef\xbb\xbfFO\xc3\xb8bar' To complete the picture, decoding swallows the BOM: >>> '\xef\xbb\xbfFO\xc3\xb8bar'.decode('utf_8_sig') u'FO\xf8bar' From ozric at web.de Mon May 2 06:13:44 2011 From: ozric at web.de (christian) Date: Mon, 2 May 2011 03:13:44 -0700 (PDT) Subject: build the "sql where cause" dynamic References: Message-ID: <707c9072-6bb5-47d7-8a07-14a4175a26cf@u15g2000vby.googlegroups.com> On 2 Mai, 10:13, Chris Angelico wrote: > On Mon, May 2, 2011 at 5:48 PM, christian wrote: > > Hi, > > > from some radio buttons in a django app i concat ?string like that: > > But have no idea how i get the or when there different values > > for a specified p column (# is currently my intended splitter maybe i > > can concat a better input?). > > > input: "p2=1#p2=2#p1=3#p1=1#p1=5#pc=1#py=1" > > > output: "p2 in ('1','2') and p1 in ('3','1','5') and pc in ('1') and > > py in ('1')" > > Start by splitting the string and iterating: > for el in input.split('#'): > > (obviously your variable won't want to be called 'input' but you knew > that already) > > Then split on the = sign and add to a list or dictionary. Be wary of > elements that don't have an equals sign in them. > > That looks like the querystring straight from the GET form, where > you're using tickboxes. You could quite happily use '&' as your > primary delimiter, if that's the case. > > Chris Angelico Many Thanks Christian From sjmachin at lexicon.net Mon May 2 06:13:44 2011 From: sjmachin at lexicon.net (John Machin) Date: Mon, 2 May 2011 03:13:44 -0700 (PDT) Subject: codec for UTF-8 with BOM In-Reply-To: Message-ID: On Monday, 2 May 2011 19:47:45 UTC+10, Chris Rebert wrote: > On Mon, May 2, 2011 at 1:34 AM, Ulrich Eckhardt > wrote: > The correct name, as you found below and as is corroborated by the > webpage, seems to be "utf_8_sig": > >>> u"FO?bar".encode('utf_8_sig') > '\xef\xbb\xbfFO\xc3\xb8bar' To complete the picture, decoding swallows the BOM: >>> '\xef\xbb\xbfFO\xc3\xb8bar'.decode('utf_8_sig') u'FO\xf8bar' From ulrich.eckhardt at dominolaser.com Mon May 2 06:30:46 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 02 May 2011 12:30:46 +0200 Subject: codec for UTF-8 with BOM References: Message-ID: Chris Rebert wrote: >> 3. The docs mention encodings.utf_8_sig, available since 2.5, but I can't >> locate that thing there either. What's going on here? > > Works for me?: > Python 2.6.6 (r266:84292, Jan 12 2011, 13:35:00) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> from encodings import utf_8_sig >>>> This works for me, too. What I tried and what failed was import encodings encodings.utf_8_sig which raises an AttributeError or dir(encodings), which doesn't show the according element. If I do it your way, the encoding then shows up in the content of the module. Apart from the encoding issue, I don't understand this behaviour. Is the module behaving badly or are my expectations simply flawed? Thanks! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From akabaila at pcug.org.au Mon May 2 06:38:48 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Mon, 2 May 2011 20:38:48 +1000 Subject: Development tools and practices for Pythonistas In-Reply-To: <3a93d484-ca0a-41d9-afdb-509cfdcc918b@e21g2000yqe.googlegroups.com> References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <3a93d484-ca0a-41d9-afdb-509cfdcc918b@e21g2000yqe.googlegroups.com> Message-ID: <201105022038.48171.akabaila@pcug.org.au> On Monday 02 May 2011 19:09:38 jacek2v wrote: > On May 2, 9:48 am, Algis Kabaila wrote: > > On Monday 02 May 2011 17:19:57 rusi wrote: > > > On May 2, 12:08 pm, Algis Kabaila > > > > wrote: > > > > Actually, Bazaar is more convenient than rcs for a > > > > single user, as the repository can be the working > > > > directory (with a "hidden" .bzr directory that stores > > > > diffs). > > > > > > Dont exactly understand... > > > Is it that you want it specifically hidden? > > > Otherwise rcs will look inside an RCS directory just as > > > bzr will with .bzr git will with .git and so on. > > > > Sorry for not being clear - "ls" will not show directories > > that start with "." - in that sense these directories are > > "hidden". They are not really really hidden, as "ls -l" > > will show them. They simply are not in the way and keep > > the progressive versions of the program (in form of > > diffs). > > "ls -l will not show directories that start with ".". > "ls -a" will. > > Regards > Jacek Thanks - you are right - pardon my absent mindedness. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf From ulrich.eckhardt at dominolaser.com Mon May 2 06:38:55 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 02 May 2011 12:38:55 +0200 Subject: HI References: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> Message-ID: <81e298-pd8.ln1@satorlaser.homedns.org> anvar wrote: > Could you please help me with the modeling in Python the following > problem: (e.g., g_t means g with index t) Typically, you would use either a list or a dict to simulate something like that: # list g = [1, 2, 4, 8, 16] print g[3] # dictionary h = {} h[0] = 1 h[1] = 2 h[2] = 4 h[3] = 8 h[4] = 16 print h[3] The difference is that a list needs elements starting at index 0 and without any gaps, while a dictionary can contain "holes". Please refer to any beginners' Python tutorial for info on these types. Concerning the other formulas you posted, those ended up as completely illegible here for the complete lack of formatting. Explaining things in plain English along with the mathematics would be a good idea, IMHO. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From rustompmody at gmail.com Mon May 2 06:40:31 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 03:40:31 -0700 (PDT) Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 2, 2:53?pm, Hans Georg Schaathun wrote: > On 02 May 2011 08:56:57 GMT, Steven D'Aprano? wrote: > > : ?I see your smiley, but there are a number of similar series as Fibonacci, > : ?with the same recurrence but different starting values, or similar but > : ?slightly different recurrences. E.g. Lucas, primefree, Pell, Padovan and > : ?Perrin numbers. > > Well, Fibonacci isn't one unique sequence. ?Any sequence satisfying > f(n) = f(n-1) + f(n-2) is /a/ Fibonacci sequence. ?Regardless of > starting values. ?At least according to some authors. And they all will, when expressed in closed form, be of the form f(n) = phi^n + something of a smaller order where phi = (1 + sqrt(5))/2 Since phi > 1 they are exponential, ignoring lower order terms. From __peter__ at web.de Mon May 2 07:42:55 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 May 2011 13:42:55 +0200 Subject: codec for UTF-8 with BOM References: Message-ID: Ulrich Eckhardt wrote: > Chris Rebert wrote: >>> 3. The docs mention encodings.utf_8_sig, available since 2.5, but I >>> can't locate that thing there either. What's going on here? >> >> Works for me?: >> Python 2.6.6 (r266:84292, Jan 12 2011, 13:35:00) >> [GCC 4.2.1 (Apple Inc. build 5664)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> from encodings import utf_8_sig >>>>> > > This works for me, too. What I tried and what failed was > > import encodings > encodings.utf_8_sig > > which raises an AttributeError or dir(encodings), which doesn't show the > according element. If I do it your way, the encoding then shows up in the > content of the module. > > Apart from the encoding issue, I don't understand this behaviour. Is the > module behaving badly or are my expectations simply flawed? This is standard python package behaviour: >>> import logging >>> logging.handlers Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'handlers' >>> import logging.handlers >>> logging.handlers You wouldn't see the AttributeError only if encodings/__init__.py contained a line from . import utf_8_sig or similar. The most notable package that acts this way is probably os which eagerly imports a suitable path module depending on the platform. As you cannot foresee which encodings are actually needed in a script it makes sense to omit a just-in-case import. From davea at ieee.org Mon May 2 08:50:39 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 02 May 2011 08:50:39 -0400 Subject: Fibonacci series recursion error (slightly OT) In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbd4a88$0$29991$c3e8da3$5496439d@news.astraweb.com> <6fs198-8lf.ln1@svn.schaathun.net> Message-ID: <4DBEA89F.4050302@ieee.org> On 01/-10/-28163 02:59 PM, Chris Angelico wrote: > On Mon, May 2, 2011 at 3:36 PM, Hans Georg Schaathun wrote: >> On Mon, 2 May 2011 06:49:41 +1000, Chris Angelico >> wrote: >> : Sure. Serialize this Python object in a way that can be given to, say, PHP: >> : foo=asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo] >> >> Wouldn't cyclic references give infinite recursion? And remain >> infinitive if you recode it iteratively? > > Well, I don't know of a decent non-recursive way to process a > recursive structure. Incidentally, this example is almost directly > from some working code of ours; I have a C function that recurses over > a Python dictionary and aborts as soon as it's found "too much" data > (for a fairly arbitrary definition of "too much", but one that's > deliberately designed to prevent infinite recursion). > > > Chris Angelico > When iterating over a repeatable, potentially infinite sequence of distinguishable values, you can safely detect infinitude ;-) (cycles) with a linear overhead (rather than n-squared). Given a sequence, create two iterators for it. Start them both at the same point, but iterate the second one twice for every time you iterate the first one. If the two ever get the same value, you have a cycle. In the case of Python objects, you probably want to use an 'is' comparison, rather than comparing id() for equal. But the concept works, and easily. DaveA From jeanmichel at sequans.com Mon May 2 09:06:48 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 02 May 2011 15:06:48 +0200 Subject: HI In-Reply-To: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> References: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> Message-ID: <4DBEAC68.5060101@sequans.com> anvar wrote: > Hello, > > Could you please help me with the modeling in Python the following > problem: (e.g., g_t means g with index t) > > Min?_(i=1)^n??_(t=1)^l?[s_i (t)-min[s ?_i (t)??_t?exp(g_t ),C_i > (t) ] ]^2 > subject to > s_i (t)=f_i (t)[S_i+f_(i-1) (t)[S_(i-1)+f_(i-2) (t)[S_(i-2)+?f_2 (t) > [S_2+f_1 (t) S_1 ]?] ] ][1-f_(i+1) (t)] > f_i (t)=F_i (t)-F_i (t-1) > F_i (t)=(((1-e^(-(X_i (t)-X_i (0) )(p_i+q_i ) )))/(((q_i?p_i ) e^(- > (X_i (t)-X_i (0) )(p_i+q_i ) )+1)), if t??_i and F_i (t)=0 if > t X_i (t)=(t-?_i+1)+ln(?pr?_i (t)/?pr?_i (0))? > ?_t?0, g_t=const > 0 S_i>0, > ?i=1,2,?,n > Where > s ?_i (t)=p_i S_i +(q_i-p_i ) s_i (t-1)-(q_i/S_i ) [s_i (t-1) ]^2, > S_i=?_i (t)M_i > Hi, Nice joke. JM From invalid at invalid.invalid Mon May 2 09:12:45 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 2 May 2011 13:12:45 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-02, Jorgen Grahn wrote: > On Sun, 2011-05-01, Terry Reedy wrote: >> On 5/1/2011 4:45 AM, Steven D'Aprano wrote: > ... >>> What other languages use the same, or mostly similar, data model as >>> Python? >> >> Natural languages. That is why I think it is better to think of Python >> as an algorithm language or information-object manipulation language >> rather than as just a linear-memory machine language.A linear memory >> with bytes addressed from 0 to max-int or max-long is an explicit part >> of the definition of assembly languages and C. It is no part of the >> definition of Python. > > It's not part of the definition of C either -- C supports segmented > memory (pre-386 Intel) and separate code/data address spaces. (Even if > most C users tend not to think of it that way.) Indeed. All the C compilers I used for many years (on both PDP-11 and 80286 under Unix) assumed a segmented memory space with separate data and text addresses spaces. More recently, the same can be said for AVR and many other Harvard architecture machines. The "linear memory with bytes addressed from 0 to max-int or max-long" thing is merely an implicit assumption made by bad C programmers. -- Grant From hg at schaathun.net Mon May 2 09:14:20 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 2 May 2011 14:14:20 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 01 May 2011 18:24:30 -0400, Terry Reedy wrote: : This does not make linear recursion 'bad', just impractical for general : use on finite-memory machines. While I consider it very useful for : learning, it is unnecessary because it is easy to write an iterative : version. So called tail-recursion optimization saves memory by REMOVING : RECURSION and replacing it with iteration. : (...) : Python does not do this automatically because 1) it can be a semantic : change under some circumstances; 2) one who wants the iterative version : can just as easily write it directly; That's the silliest argument I ever heard. The programmer should write the code the way he and application domain experts think, i.e. very often recursively. The compiler should generate code the way the CPU thinks (most optimally), i.e. iteratively. Of course, I am not saying that one should always model problems recursively, and thus also not that one should implement them recursively. Just that when a model is agreed recursively between the stakeholders, one should get a compiler to do the optimisation, not a programmer. I always thought of python as a step forward, in the way it allows direct expression of so many alternative modes of thinking (imperative, functional, recursion, iterators, etc). If what you say is python philosophy, it is a step backward in requiring the programmer to think more about low-level technical matters which even C has managed to leave for the compiler. : and 3) Python has a better way to : process collections that removes essentially all the boilerplate in the : recursive-call and while-loop versions: -- :-- Hans Georg From emakhmudow at gmail.com Mon May 2 09:42:14 2011 From: emakhmudow at gmail.com (anvar) Date: Mon, 2 May 2011 06:42:14 -0700 (PDT) Subject: HI References: <6174739f-a953-4bb9-b850-206e8405bb3d@k27g2000pri.googlegroups.com> Message-ID: Dear Ulrich Eckhardt and Jean-Michel Pichavant! First of all thank you for your attention. I'have never expected to receive response. Actually, I am doing my internship in Marketing Division in small company., I got this assignment yesterday morning. My boss wants perfect technology diffusion based forecasting model. I found the required model, modified it..but cannot solve it (university friend suggested Python because it had special tools for optimization). I will appreciate if you help me to find right tools and give some more advises. Thank you for your precious time. As to problem, I should use nonlinear least-square estimation methodology (to estimate p_i, q_i, and ? parameters) where the objective of the estimation procedure is minimization of the sum of squared error. Here in problem: F_i (t) the cumulative density function at time t for technology generation i f_i (t) the probability density function at time t for technology generation i p_i the proportion of mass media communication for generation i q_i the proportion of word of mouth for generation i ?_i (t) the market share at time t for generation i (data exists) M_i total market potential for generation i, (data exists) S_i total sales potential for generation i, S_i=?_i (t)M_i ?_i the introduction time for generation i, ?_i?1 (data exists) s_i (t) the actual sales of products at time t for generation i (data exists) s ?_i (t) the estimated sales of products at time t for generation i X_i (t) the cumulative market effects ? the effectiveness of the price ?pr?_i (t) the price at time t for generation i (data exists) ?_t the seasonal factor at time t (data exists) g_t the growth rate at time t (data exists) n the number of generations (data exists) l the number of periods (data exists) C_i (t) the capacity restriction regarding the product at time t for generation i (data exists) From efrinut at gmail.com Mon May 2 11:23:21 2011 From: efrinut at gmail.com (Petey) Date: Mon, 2 May 2011 08:23:21 -0700 (PDT) Subject: Development software Message-ID: Hi! I'm new to programming. I started with php earlier and I dropped it for Python. I use Eclipse+PyDev for python, html and css. Which programmes should I start using because they might be useful in the future? Which functions of eclipse are useful but unused/unnoticed by beginners. What do you use and why :) ? From alexander at lyabah.com Mon May 2 12:23:40 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Mon, 2 May 2011 09:23:40 -0700 (PDT) Subject: Python competitions and learnings References: <2N1vp.21945$vC5.16209@newsfe01.iad> <5e4ec696-4d50-4b88-9fa5-229f293c0639@q21g2000vbs.googlegroups.com> Message-ID: <777e558e-2e84-4f6e-ac3f-e3e53346a467@x10g2000vbn.googlegroups.com> On May 1, 7:22?pm, Alexander Lyabah wrote: > On May 1, 3:26?am, harrismh777 wrote: > > > > > > > > > > > Alexander Lyabah wrote: > > > What do you think about it? > > > > I'm also have a not a very good English, so I need help with it too, > > > Alexander, your site is very interesting. I spent some time this > > afternoon appreciating your work. Nice job. > > > Be encouraged, your English is much better than my Russian! I also > > looked over the orphanage site and I appreciate how much you are doing > > there in Ukraine for the children. Keep up the good work. > > > I too am a little disappointed that Python3 is not being used. I want to > > encourage you to work in that direction as well. I may have some time to > > volunteer to checkio.org; for help with the English, and maybe with some > > help as a tester. We'll see... I have a lot of my own fish to fry here, > > as we say in America. > > > Blessings on your work, friend. > > > m harris > > I spend a lot of time to make a almost full support of python 2.7 from > sandbox. > > If somebody help me this sandboxed python 3.* i will add support of it > on checkio.org with big pleasure. Notice about the python 2.7 on main page was added. thanks for advice From steve+comp.lang.python at pearwood.info Mon May 2 12:24:07 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2011 16:24:07 GMT Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dbedaa6$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 May 2011 10:53:52 +0100, Hans Georg Schaathun wrote: > On 02 May 2011 08:56:57 GMT, Steven D'Aprano > wrote: > : I see your smiley, but there are a number of similar series as > Fibonacci, : with the same recurrence but different starting values, or > similar but : slightly different recurrences. E.g. Lucas, primefree, > Pell, Padovan and : Perrin numbers. > > Well, Fibonacci isn't one unique sequence. Any sequence satisfying f(n) > = f(n-1) + f(n-2) is /a/ Fibonacci sequence. Regardless of starting > values. At least according to some authors. According to the references I have, there is one and only one Fibonacci sequence, the usual one invented by Fibonacci to talk about rabbits. (Actually, we should talk about Fibonacci *numbers*, rather than sequence.) Wolfram Mathworld is typical, defining *the* Fibonacci numbers as those with starting conditions f(1)=1, f(2)=1 (or f(0)=0 if you prefer). http://mathworld.wolfram.com/FibonacciNumber.html The Collins Dictionary of Mathematics agrees with Mathworld. The Lucas numbers (related to, but not the same as, the Lucas sequence) obey the same recurrence as the Fibonacci numbers, but with a different set of starting values. So there is certainly precedent in the mathematical literature for giving different names to the same recurrence with different starting values. In any case, whatever you call them, what I call R(n) is not one, as the recurrence is different: R(n) = R(n-1) + R(n-2) + 1 > Penguin, Dict. of Mathematics prefer 1,1,2,3,5 but they also suggest > 0,1,1,2,3, ... This depends on whether you start counting from n=0 or n=1. Even the sequence you quote, from Anderson: 1,2,3,5... is just the usual Fibonacci numbers starting at n=2 instead of 1 or 0. (No matter how confusing something is, there's always at least one person who will try to make it *more* confusing.) > In short, don't assume that a person talking about Fibonacci numbers > assume the same base cases as you do. As far as I'm concerned, there are only two definitions of Fibonacci numbers that have widespread agreement in the mathematical community: 0,1,1,2,3 ... (starting from n=0) 1,1,2,3,5 ... (starting from n=1) Any other definition is rather, shall we say, idiosyncratic. -- Steven From alexander at lyabah.com Mon May 2 12:24:48 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Mon, 2 May 2011 09:24:48 -0700 (PDT) Subject: Python competitions and learnings References: <2N1vp.21945$vC5.16209@newsfe01.iad> <5e4ec696-4d50-4b88-9fa5-229f293c0639@q21g2000vbs.googlegroups.com> Message-ID: On May 2, 1:33?am, Terry Reedy wrote: > On 5/1/2011 12:49 PM, Alexander Lyabah wrote: > > > And what do you think about Score Games and competitions? > > The rules of the first score game were not clear to me. I could not > figure out how to play it interactively myself so I could see how it > actually played. > > -- > Terry Jan Reedy I will add a more detail information how competitions and score games goes. From steve+comp.lang.python at pearwood.info Mon May 2 12:41:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2011 16:41:37 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 May 2011 14:14:20 +0100, Hans Georg Schaathun wrote: > On Sun, 01 May 2011 18:24:30 -0400, Terry Reedy > wrote: > : This does not make linear recursion 'bad', just impractical for > general : use on finite-memory machines. While I consider it very > useful for : learning, it is unnecessary because it is easy to write an > iterative : version. So called tail-recursion optimization saves memory > by REMOVING : RECURSION and replacing it with iteration. : (...) > : Python does not do this automatically because 1) it can be a semantic > : change under some circumstances; 2) one who wants the iterative > version : can just as easily write it directly; > > That's the silliest argument I ever heard. You must be new to the Internet then :) > The programmer should write > the code the way he and application domain experts think, i.e. very > often recursively. The compiler should generate code the way the CPU > thinks (most optimally), i.e. iteratively. Perhaps so, but there can be a huge gulf between what "should" happen and what does happen. The CPython implementation is deliberately a naive, not- very clever compiler. (PyPy seems to be the implementation aiming at cutting-edge cleverness.) Even such simple optimizations as constant folding are very controversial among the CPython developers. They have good reasons for their caution: optimizing compilers are renowned for breaking code, especially floating point code, and there have been cases in Python's history where optimizations have broken existing code and needed to be backed out. The problem is, once you include side-effects, recursion and iteration are *not* identical. Specifically, the opposition to tail-recursion optimization in Python is that it plays havoc with the tracebacks you get in the event of an exception. The argument goes: * Debugging is harder than writing code in the first place, so it is more important to simplify debugging, even at the cost of making some code slightly harder to write. * Recursion doesn't just mean simple recursion where a function calls itself, but mutually recursive functions. You could have (say) five functions that mutually called each other recursively, and in the event of a traceback you need to see the exact calling chain, but that's precisely the information that is blown away by tail-recursion optimization. * Tail-recursion is only a special case of recursion, and not a very common special case either, so it is hardly worth the extra complexity of the compiler to treat it specially. Regardless of whether you agree with the arguments or not, they're hardly "silly". -- Steven From myeates at jpl.nasa.gov Mon May 2 12:45:26 2011 From: myeates at jpl.nasa.gov (Mathew) Date: Mon, 2 May 2011 09:45:26 -0700 Subject: setup.py rebuilds EVERYTHING on windows? Message-ID: Hi I'm trying to build an extension (spice-0.12) on windows. Whenever I change a single file, everything gets rebuilt. ?? Python2.7.1 Windows XP Visual Studio 9 setuptools 0.6c11 -Mathew From kmshafique at yahoo.com Mon May 2 13:21:31 2011 From: kmshafique at yahoo.com (Shafique, M. (UNU-MERIT)) Date: Mon, 2 May 2011 10:21:31 -0700 (PDT) Subject: Running a script with command line arguments Message-ID: <314543.11533.qm@web65402.mail.ac4.yahoo.com> Hi, I'm new to python and trying to run a borrowed script. The error I get suggests that I need to give a proper command to run it. The input file is "c26_1plus.csv" and the intended output file is "c26_1plus_backbone.csv". Can anyone help? BR, Shafique Error log: C:\Users\Shafique>extract_backbone.py c:\python26\c26_1plus.csv c:\python26\c26_1plus_backbone Traceback (most recent call last): File "C:\Python26\extract_backbone.py", line 31, in alpha = float(sys.argv[3]) IndexError: list index out of range Excerpts from code: #!/usr/bin/env python import sys, os import networkx def extract_backbone(G, weights, alpha): blablabla... if __name__ == '__main__': if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]: usage = """python %s input_file output_file backbone_alpha [file delimiter]""" sys.exit(usage) in_file = sys.argv[1] ot_file = sys.argv[2] alpha = float(sys.argv[3]) try: delimiter = sys.argv[4] except: delimiter = "\t" ...blablabla... # save the new edgelist: f = open(ot_file, 'w') for ni,nj in G_backbone.edges(): f.write("%s%s%s\n" % (ni,delimiter,nj) ) f.close() -------------- next part -------------- An HTML attachment was scrubbed... URL: From ms419 at freezone.co.uk Mon May 2 13:23:15 2011 From: ms419 at freezone.co.uk (Jack Bates) Date: Mon, 02 May 2011 10:23:15 -0700 Subject: "raise (type, value, traceback)" and "raise type, value, traceback" Message-ID: <1304356995.4335.2.camel@selene> Hi, anyone know why these two statements aren't equivalent? raise (type, value, traceback) raise type, value, traceback From ameyer2 at yahoo.com Mon May 2 13:30:02 2011 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 02 May 2011 13:30:02 -0400 Subject: Composition instead of inheritance In-Reply-To: References: Message-ID: <4DBEEA1A.6000004@yahoo.com> On 4/28/2011 1:15 PM, Ethan Furman wrote: > For anybody interested in composition instead of multiple inheritance, I > have posted this recipe on ActiveState (for python 2.6/7, not 3.x): > > http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/ > > > Comments welcome! > > ~Ethan~ That looks pretty clever. I tried adding this method to Spam: def test_eggs_02(self): print('testing eggs_02 from spam') and it did just what we wanted. I'm going to have to study this one. Thanks. Alan From python at rcn.com Mon May 2 13:33:31 2011 From: python at rcn.com (Raymond Hettinger) Date: Mon, 2 May 2011 10:33:31 -0700 (PDT) Subject: Coolest Python recipe of all time Message-ID: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> I think it is time to give some visibility to some of the instructive and very cool recipes in ActiveState's python cookbook. My vote for the coolest recipe of all time is: http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ What are your favorites? Raymond twitter: @raymondh From stefan_ml at behnel.de Mon May 2 13:37:19 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 02 May 2011 19:37:19 +0200 Subject: setup.py rebuilds EVERYTHING on windows? In-Reply-To: References: Message-ID: Mathew, 02.05.2011 18:45: > I'm trying to build an extension (spice-0.12) on windows. Whenever I change > a single file, everything gets rebuilt. Did you report this to the authors? I suppose there's a project mailing list? Stefan From news at schwertberger.de Mon May 2 13:40:04 2011 From: news at schwertberger.de (Dietmar Schwertberger) Date: Mon, 02 May 2011 19:40:04 +0200 Subject: Development tools and practices for Pythonistas In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <87ei4ji7eu.fsf@benfinney.id.au> Message-ID: Am 02.05.2011 01:33, schrieb David Boddie: > After noting the warnings it contains, see the following page for a > description of the Python API for Mercurial: > > http://mercurial.selenic.com/wiki/MercurialApi Ah, yes, no need to use os.sytem(), but all in all not much difference from doing so (and usage of CLI is recommended instead of using the API). I had a look at this page in 2009 and came to the conclusion that it's no good idea to use Mercurial as library. Seems that this still holds true. > Git also has a Python API, which is fairly reasonable to use, though a bit > different to the Mercurial one: > > http://www.samba.org/~jelmer/dulwich/ That looks more promising to me. I think I will try this and Bazaar to find which fits my needs better. Regards, Dietmar From python at mrabarnett.plus.com Mon May 2 14:26:34 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 May 2011 19:26:34 +0100 Subject: Running a script with command line arguments In-Reply-To: <314543.11533.qm@web65402.mail.ac4.yahoo.com> References: <314543.11533.qm@web65402.mail.ac4.yahoo.com> Message-ID: <4DBEF75A.2000801@mrabarnett.plus.com> > Hi, > I'm new to python and trying to run a borrowed script. The error I > get suggests that I need to give a proper command to run it. The > input file is "c26_1plus.csv" and the intended output file is > "c26_1plus_backbone.csv". > > Can anyone help? > The usage string in the script says that the required arguments are: input_file output_file backbone_alpha [file delimiter] You're providing "input_file" and "output_file" but not "backbone_alpha". From tjreedy at udel.edu Mon May 2 14:56:13 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 May 2011 14:56:13 -0400 Subject: Fibonacci series recursion error In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/2/2011 9:14 AM, Hans Georg Schaathun wrote: > On Sun, 01 May 2011 18:24:30 -0400, Terry Reedy > : Python does not do this automatically because 1) it can be a semantic > : change under some circumstances; 2) one who wants the iterative version > : can just as easily write it directly; > > That's the silliest argument I ever heard. Calling something silly when you have not really read it and perhaps asked questions to really understand it is, to me, silly. If you want a compiler that can introduce bugs into your program by doing what it thinks you meant, rather than what you said, don't use CPython. > : and 3) Python has a better way to > : process collections that removes essentially all the boilerplate in the > : recursive-call and while-loop versions: To properly use modern Python, one should know and use for loops and iterators. -- Terry Jan Reedy From enleverLesX_XXmcX at XmclavXeauX.com.invalid Mon May 2 14:56:53 2011 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Mon, 02 May 2011 20:56:53 +0200 Subject: ctypes and twain_32.dll References: <844574c2-4ff4-41b8-8cdc-de103437d18f@j31g2000yqe.googlegroups.com> Message-ID: <4dbefe78$0$14685$ba4acef3@reader.news.orange.fr> Hi! On my system, thera are not "twain32.dll" or "twain_32.dll", but "twain.dll" @+ -- Michel Claveau From ian.g.kelly at gmail.com Mon May 2 15:32:45 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 May 2011 13:32:45 -0600 Subject: "raise (type, value, traceback)" and "raise type, value, traceback" In-Reply-To: <1304356995.4335.2.camel@selene> References: <1304356995.4335.2.camel@selene> Message-ID: On Mon, May 2, 2011 at 11:23 AM, Jack Bates wrote: > Hi, anyone know why these two statements aren't equivalent? > > raise (type, value, traceback) > > raise type, value, traceback The latter is the syntax of the raise statement: up to 3 expressions, separated by commas. The former has a single expression that evaluates to a tuple. It's equivalent to this: t = (type, value, traceback) raise t That it accepts the tuple and raises a value-less expression of type `type` surprises me. The docs don't say anything about this, and I would have expected a TypeError, but it appears to be extracting the first element of the tuple and using that as the value of the first expression. From john106henry at hotmail.com Mon May 2 15:48:55 2011 From: john106henry at hotmail.com (John Henry) Date: Mon, 2 May 2011 12:48:55 -0700 (PDT) Subject: Pushing for Pythoncard 1.0 Message-ID: <6d896b66-3933-4743-8eb5-b9754f1ec14f@t19g2000prd.googlegroups.com> Attempt to push Pythoncard to a 1.0 status is now underway. A temporary website has been created at: http://code.google.com/p/pythoncard-1-0/ The official website continues to be http://pythoncard.sourceforge.net/ Pythoncard is such a wonderful package that it would be a shame to allow development for the package to go stagnant. The Python community deserves to continue enjoying the simplicity of Pythoncard for creating a GUI Python application. In the last few years, I've added a number of widgets and functions to the package. The present effort is to simply incorporate all of the changes I've made to the package, create an installer, push it out the door and announce to the world that Pythoncard 1.0 is here, and is here to stay. Here's a partial list of widgets and functions added: Widgets: PDFWindow, FlashWindow, MatplotlibCanvasWindow, MultiSelectionList, Drag-&-drop enabled tree control, IEHTMLWindow Backgrounds: MDIParentWindow, MDIChildWindow, MDISashWindow, multi-panel Background Window, Tools: Updated layoutmanager supporting the newly added widgets, and a revived action manager (provide list of actions or events associated with widgets in a context-sensitive fashion - no more needs to memorize which widget can do what). and others. I realize that there are other GUI packages that enjoyed far more support from the Python community in the last few years and have, as a result, a more extensive feature list, and more modern looks. My hats off to those developers. So, please re-frame from responding to this message or send me emails regarding xyz package and how that one is "better", more "modern" than Pythoncard, or that xyz package had xxx feature already. I like Pythoncard because it's so simple for most GUI applications I build that it's almost laughable. I've benefited tremendously from having Pythoncard around and now it's my turn to chip in and repay a small debt to Pythoncard. For x-Pythoncard users (and particularly developers), if you are unable to lend a helping hand, please at least join or re-join the Pythoncard mailing list and let your voice be heard. From hg at schaathun.net Mon May 2 16:02:43 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 2 May 2011 21:02:43 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <38f398-14h.ln1@svn.schaathun.net> On 02 May 2011 16:41:37 GMT, Steven D'Aprano wrote: : You must be new to the Internet then :) OK. Maybe I heard something worse last time I was an active news users, years ago. Anyway, most of the silly things I hear do not qualify as arguments :-) : The problem is, once you include side-effects, recursion and iteration : are *not* identical. Specifically, the opposition to tail-recursion : optimization in Python is that it plays havoc with the tracebacks you get : in the event of an exception. The argument goes: Thanks for the comprehensive background. I can see the point that python may be harder to optimise correctly during compilation than many other languages. : Regardless of whether you agree with the arguments or not, they're hardly : "silly". I only called one argument silly, namely the one about iterative rewriting being so simple that it is not an issue. Sometimes it isn't, but sometimes it is. The other arguments are valid. And they make me lean more towards more static, compiled languages without the excessive run-time dynamism of python. -- :-- Hans Georg From monaghand.david at gmail.com Mon May 2 16:48:51 2011 From: monaghand.david at gmail.com (David Monaghan) Date: Mon, 02 May 2011 21:48:51 +0100 Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger wrote: >I think it is time to give some visibility to some of the instructive >and very cool recipes in ActiveState's python cookbook. > >My vote for the coolest recipe of all time is: > > http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ Really cool, but wrong. x = 3234.667, not 3236.0 DaveM From ian.g.kelly at gmail.com Mon May 2 16:58:50 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 May 2011 14:58:50 -0600 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: On Mon, May 2, 2011 at 2:48 PM, David Monaghan wrote: > On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger > wrote: > >>I think it is time to give some visibility to some of the instructive >>and very cool recipes in ActiveState's python cookbook. >> >>My vote for the coolest recipe of all time is: >> >> ? ?http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ > > Really cool, but wrong. x = 3234.667, not 3236.0 Nope, I get 3236. Maybe you made a mistake somewhere. From dickinsm at gmail.com Mon May 2 17:18:36 2011 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 2 May 2011 14:18:36 -0700 (PDT) Subject: Fibonacci series recursion error References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> <4dbedaa6$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54067d04-7298-45b0-ab0e-ba22b0758317@w36g2000vbi.googlegroups.com> On May 2, 5:24?pm, Steven D'Aprano wrote: > As far as I'm concerned, there are only two definitions of Fibonacci > numbers that have widespread agreement in the mathematical community: > > 0,1,1,2,3 ... (starting from n=0) > 1,1,2,3,5 ... (starting from n=1) > > Any other definition is rather, shall we say, idiosyncratic. And a concrete reason for preferring the above definition (in either form) is that divisibility properties of the sequence are much neater with this choice: gcd(F_m, F_n) = F_{gcd(m, n)} -- Mark From monaghand.david at gmail.com Mon May 2 17:45:34 2011 From: monaghand.david at gmail.com (David Monaghan) Date: Mon, 02 May 2011 22:45:34 +0100 Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> On Mon, 2 May 2011 14:58:50 -0600, Ian Kelly wrote: >On Mon, May 2, 2011 at 2:48 PM, David Monaghan > wrote: >> On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger >> wrote: >> >>>I think it is time to give some visibility to some of the instructive >>>and very cool recipes in ActiveState's python cookbook. >>> >>>My vote for the coolest recipe of all time is: >>> >>> ? ?http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ >> >> Really cool, but wrong. x = 3234.667, not 3236.0 > >Nope, I get 3236. Maybe you made a mistake somewhere. Oops. What a plonker .Three times I checked and got the same result each time. Now it works fine. Sorry! DaveM From harrismh777 at charter.net Mon May 2 17:50:52 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 02 May 2011 16:50:52 -0500 Subject: Fibonacci series recursion error In-Reply-To: References: Message-ID: <0HFvp.18698$vT3.2042@newsfe06.iad> Thomas Rachel wrote: >> ... because each recursion level 'return' calls fib() twice, and each of >> those calls fib() twice, and you get the point... > > yes - but they are called one after the other, so the "twice" call > counts only for execution speed, not for recursion depth. >>> def fib(n): >>> if n == 1: >>> return(n) >>> else: >>> return (fib(n-1)+fib(n-2)) They *are not* called one after the other in the sense that there is ever only one level of recursion with each call (not at all). Take a closer look. Each call to fib() forces a double head, and each of those forces another double head (now four), and so on... the recursion depth exception of the OP testifies against your theory. The thing about this problem that puzzles me, is why we might consider recursion for a possible solution in the first place. In other words, normally we consider using recursion when we need information further down the stack then we have now... so that recursion is necessary because each head call will not have the information it needs for completion until the tail clean-up (coming back up the stack) provides that information. In the case of the fib() numbers (or the fib sequence) recursion is not necessary for correctly handling of the problem. The simple straight-forward obvious way to handle the problem is to calculate the sequence outright in a straight-forward way. On the other hand, Otten's use of yield (making a generator) makes some sense too, in the case that we want to get the fib numbers over time without taking the time to calculate the entire sequence up-front. Just saying... kind regards, m harris From rosuav at gmail.com Mon May 2 17:56:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 07:56:26 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 2, 2011 at 11:14 PM, Hans Georg Schaathun wrote: > That's the silliest argument I ever heard. ?The programmer should write > the code the way he and application domain experts think, i.e. very > often recursively. ?The compiler should generate code the way the CPU > thinks (most optimally), i.e. iteratively. The CPU can function iteratively or recursively. The main difference between the programmer and the CPU there is that the CPU is always imperative, while a programmer might want to think functionally, or in an event-driven model, and then "under the covers" the compiler translates that into imperative code. But in my opinion, the programmer and the interpreter/compiler are teammates. If you allow programmers to be stupid, you will get a lot of stupid programmers writing code. (I think that's one of PHP's biggest downsides.) If the human and the machine know each other well enough, the resulting code can be orders of magnitude more efficient to run, *without taking any more tme to code* because the programmer already knew the right things to do. Perhaps it will take you four hours to read through something, study it, maybe eyeball the compiler's source code, maybe do some disassembly. If you have a few years of career ahead of you, you'll benefit many times over from those few hours, and without spending extra time, you'll produce better code. THAT is what distinguishes the master from the novice. Chris Angelico From unknownmoss at gmail.com Mon May 2 18:04:58 2011 From: unknownmoss at gmail.com (Unknown Moss) Date: Mon, 2 May 2011 15:04:58 -0700 (PDT) Subject: (beginner question) ConfigParser nuances Message-ID: Hi - Beginner question here. I'm working with ConfigParser. I'd like to take a multiline variable and convert it directly to an array. Seems like a common problem, but I don't see how I can do it without doing a little parsing in my own code. Here's what I'm doing ... >>> import ConfigParser >>> import io >>> sample = """ ... [Example] ... fruit = apple ... orange ... pear ... """ >>> config = ConfigParser.RawConfigParser() >>> config.readfp(io.BytesIO(sample)) >>> config.get("Example", "fruit") 'apple\norange\npear' >>> temp = config.get("Example", "fruit") >>> temp.split() ['apple', 'orange', 'pear'] I'm thinking there's a way to avoid this intermediate temp.split() step. Is there not a way to move a multiline value straight into an array using ConfigParser? Thanks for the help. From rosuav at gmail.com Mon May 2 18:17:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 08:17:35 +1000 Subject: Fibonacci series recursion error In-Reply-To: <0HFvp.18698$vT3.2042@newsfe06.iad> References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Tue, May 3, 2011 at 7:50 AM, harrismh777 wrote: > They *are not* called one after the other in the sense that there is ever > only one level of recursion with each call (not at all). Take a closer look. > Each call to fib() forces a double head, and each of those forces another > double head (now four), and so on... ?the recursion depth exception of the > OP testifies against your theory. def fib(n): if n==1: return n return fib(n-1)+fib(n-2) dis.dis(fib) 2 0 LOAD_FAST 0 (n) 3 LOAD_CONST 1 (1) 6 COMPARE_OP 2 (==) 9 JUMP_IF_FALSE 5 (to 17) 12 POP_TOP 3 13 LOAD_FAST 0 (n) 16 RETURN_VALUE >> 17 POP_TOP 4 18 LOAD_GLOBAL 0 (fib) 21 LOAD_FAST 0 (n) 24 LOAD_CONST 1 (1) 27 BINARY_SUBTRACT 28 CALL_FUNCTION 1 31 LOAD_GLOBAL 0 (fib) 34 LOAD_FAST 0 (n) 37 LOAD_CONST 2 (2) 40 BINARY_SUBTRACT 41 CALL_FUNCTION 1 44 BINARY_ADD 45 RETURN_VALUE The recursion is in the last block. Note that it calls a function, then keeps going. It doesn't fork. There are two CALL_FUNCTION opcodes, called *sequentially*. In terms of the call stack, there is only ever one of those two calls active at any given time. Also, as earlier pointed out, the reason for the stack overflow is that fib(2) will call fib(1) and fib(0), and fib(0) will call fib(-1) and fib(-2), etc. Changing the operator from == to <= in the conditional return will solve this. Chris Angelico From ian.g.kelly at gmail.com Mon May 2 18:22:35 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 May 2011 16:22:35 -0600 Subject: Fibonacci series recursion error In-Reply-To: <0HFvp.18698$vT3.2042@newsfe06.iad> References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Mon, May 2, 2011 at 3:50 PM, harrismh777 wrote: > Thomas Rachel wrote: >>> >>> ... because each recursion level 'return' calls fib() twice, and each of >>> those calls fib() twice, and you get the point... >> >> yes - but they are called one after the other, so the "twice" call >> counts only for execution speed, not for recursion depth. > >>>> def fib(n): >>>> ? ? if n == 1: >>>> ? ? ? ? return(n) >>>> ? ? else: >>>> ? ? ? ? return (fib(n-1)+fib(n-2)) > > They *are not* called one after the other in the sense that there is ever > only one level of recursion with each call (not at all). Take a closer look. > Each call to fib() forces a double head, and each of those forces another > double head (now four), and so on... The branching factor has nothing to do with the maximum stack depth. If you don't believe me, consider this little script: import inspect def maxstack(n): if n <= 0: return len(inspect.stack()) else: return max(maxstack(n-1), maxstack(n-2)) print maxstack(15) This prints "17". Now consider this script, which is similar but singly-recursive: import inspect def maxstack(n): if n <= 0: return len(inspect.stack()) else: return maxstack(n-1) print maxstack(15) This also prints "17". Note: they're the same. > ?the recursion depth exception of the > OP testifies against your theory. The OP's recursion depth exception was because a malformed base case made the recursion infinite. It had nothing to do with the branching factor. From clp2 at rebertia.com Mon May 2 18:25:16 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 May 2011 15:25:16 -0700 Subject: (beginner question) ConfigParser nuances In-Reply-To: References: Message-ID: On Mon, May 2, 2011 at 3:04 PM, Unknown Moss wrote: > Hi - Beginner question here. I'm working with ConfigParser. I'd like > to take a multiline variable and convert it directly to an array. > Seems like a common ?problem, but I don't see how I can do it without > doing a little parsing in my own code. Here's what I'm doing ... > >>>> import ConfigParser >>>> import io >>>> sample = """ > ... [Example] > ... fruit = apple > ... ? ? orange > ... ? ? pear > ... """ >>>> config = ConfigParser.RawConfigParser() >>>> config.readfp(io.BytesIO(sample)) >>>> config.get("Example", "fruit") > 'apple\norange\npear' >>>> temp = config.get("Example", "fruit") >>>> temp.split() > ['apple', 'orange', 'pear'] > > I'm thinking there's a way to avoid this intermediate temp.split() > step. Is there not a way to move a multiline value straight into an > array using ConfigParser? Nope, there is not. I think some might instead use several numbered options to similar effect: # config file [Example] fruit1: apple fruit2: orange fruit3: pear # Python from itertools import count fruits = [] names = ("fruit" + str(i) for i in count(1)) for name in names: if not config.has_option("Example", name): break fruits.append(config.get("Example", name)) Cheers, Chris -- http://rebertia.com From rosuav at gmail.com Mon May 2 18:42:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 08:42:22 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Tue, May 3, 2011 at 8:22 AM, Ian Kelly wrote: >> They *are not* called one after the other in the sense that there is ever >> only one level of recursion with each call (not at all). Take a closer look. >> Each call to fib() forces a double head, and each of those forces another >> double head (now four), and so on... > > The branching factor has nothing to do with the maximum stack depth. > Side point: In a massively parallel environment, branching like this COULD be implemented as a fork. I just don't know of any implementations of Python that do so. (And of course, it works for fib() because it needs/uses no global state, which makes the recursions completely independent. Not all functions are so courteous, and the compiler can't necessarily know the difference.) Chris Angelico From rosuav at gmail.com Mon May 2 19:44:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 09:44:59 +1000 Subject: Development software In-Reply-To: References: Message-ID: On Tue, May 3, 2011 at 1:23 AM, Petey wrote: > Which programmes should I start using because they might be useful in the future? Which functions of eclipse are useful but unused/unnoticed by beginners. > > What do you use and why :) ? You're going to get some extremely disparate responses to that! I'll open with the disclaimer that will apply to everyone's posts: This is personal opinion, not Gospel truth. :) For my development (which is quite polyglot - at the moment, C++/Python/PHP/makefile/Pike/text all up in tabs), I use SciTE and a good makefile. I hit F7 and Scite runs make in the current file's directory. Is it an IDE or an editor? I'm not really sure; it's an editor that lets me scroll through compiler errors with F4/Shift-F4. A well-made makefile is an awesome tool. I strongly recommend getting familiar with your make utility (if you don't currently have one, get GNU make). My make will build either the production or debug version of my code, upload changed files to our deployment server, and in fact do everything except push changes into our git repo (I prefer to do that manually, as I usually want to build lots of times and only then commit the change in git). Chris Angelico From steve+comp.lang.python at pearwood.info Mon May 2 20:21:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 May 2011 00:21:45 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> Message-ID: <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 May 2011 21:02:43 +0100, Hans Georg Schaathun wrote: > The other arguments are valid. And they make me lean more towards more > static, compiled languages without the excessive run-time dynamism of > python. If you value runtime efficiency over development time, sure. There are plenty of languages which have made that decision: Pascal, C, Java, Lisp, Forth, and many more. Python aims at acceptable performance (between 10 and 100 times slower than C) and much easier development (between 10 and 100 times faster than C *wink*). If that tradeoff doesn't suit you, perhaps Python is not the language for you. -- Steven From ryan.morrone at gmail.com Mon May 2 20:23:23 2011 From: ryan.morrone at gmail.com (PyNewbie) Date: Mon, 2 May 2011 17:23:23 -0700 (PDT) Subject: Py / VNC Automation Message-ID: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> Hi, I'm looking for a python class or open source code that is tightly integrated with VNC protocols - any ideas? From rosuav at gmail.com Mon May 2 20:52:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 10:52:04 +1000 Subject: Py / VNC Automation In-Reply-To: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> References: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> Message-ID: On Tue, May 3, 2011 at 10:23 AM, PyNewbie wrote: > Hi, > I'm looking for a python class or open source code that is tightly integrated with VNC protocols - any ideas? It's not a complex protocol; you could fairly readily work it manually. The protocol itself is called RFB - see http://en.wikipedia.org/wiki/RFB_protocol which has links to the official protocol spec. Working it from Python is as simple as creating a socket (import socket; vnc=socket.socket(); vnc.connect(('address',5900))) and sending and receiving binary data. If you're setting things up as a test, I recommend playing around with authentication disabled - it's a lot easier to master the protocol in its simplest form. Chris Angelico From drsalists at gmail.com Mon May 2 21:33:18 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 May 2011 18:33:18 -0700 Subject: Py / VNC Automation In-Reply-To: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> References: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 2, 2011 at 5:23 PM, PyNewbie wrote: > Hi, > I'm looking for a python class or open source code that is tightly > integrated with VNC protocols - any ideas? > -- > http://mail.python.org/mailman/listinfo/python-list > I've not updated this in a while, but it's got a python vnc viewer in the list: http://stromberg.dnsalias.org/~dstromberg/vnc.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Mon May 2 21:48:25 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 18:48:25 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On May 3, 2:50?am, harrismh777 wrote: > The thing about this problem that puzzles me, is why we might consider > recursion for a possible solution in the first place.... This can be answered directly but a bit lengthily. Instead let me ask a seemingly unrelated (but actually much the same) question. Here are two power functions: def powI(x,n): result = 1 for i in range(0,n): result = result * x return result def powR(x,n): return 1 if (n==0) else (x * powR(x, n-1)) What are their space/time complexities? Which do you prefer? From rustompmody at gmail.com Mon May 2 22:04:49 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 19:04:49 -0700 (PDT) Subject: Development software References: Message-ID: On May 2, 8:23?pm, Petey wrote: > Hi! > > I'm new to programming. I started with php earlier and I dropped it for Python. > I use Eclipse+PyDev for python, html and css. > > Which programmes should I start using because they might be useful in the future? > Which functions of eclipse are useful but unused/unnoticed by beginners. > > What do you use and why :) ? Chris talked of a good make tool. Yes this is necessary for more 'in- the-large' programming. But for a beginner its very important to have tight development cycle -- viz. a. Write a function b. Check the function c. Change the definition d. Check that etc with a minimum of keystrokes If eclipse gives that its good... For me its emacs with python-mode: python in one window python file in other jump between the two with one keystroke. Ive heard very good things about ipython (especially for introspection) but not tried it extensively myself From rosuav at gmail.com Mon May 2 22:13:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 12:13:16 +1000 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Tue, May 3, 2011 at 11:48 AM, rusi wrote: > What are their space/time complexities? > Which do you prefer? They're pretty similar actually. If you rework the first one to not use range() but instead have a more classic C style of loop, they'll be almost identical: def powI(x,n): result = 1 while n > 0: result *= x n-=1 return result There's a subtle difference in that powR as you've coded it will infinite-loop if given a negative exponent, while powI in any form will simply return 1 (neither is technically correct, fwiw). Other than that, the only difference is that one keeps its state on the call stack, the other uses a temporary variable. Performance would probably benefit from a special syntax meaning "recurse", which would avoid the LOAD_GLOBAL for the function's name (plus, things break if you pass recursive functions around after compiling them - for instance, powR2=powR; def powR(x,n): os.exit() - but if you do that, then you should expect to see nice bullet-holes in your foot). However, I do not believe that Python would overall benefit from any such thing. Chris Angelico From rosuav at gmail.com Mon May 2 22:16:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 12:16:05 +1000 Subject: Development software In-Reply-To: References: Message-ID: On Tue, May 3, 2011 at 12:04 PM, rusi wrote: > Chris talked of a good make tool. Yes this is necessary for more 'in- > the-large' programming. > But for a beginner its very important to have tight development cycle > -- viz. > a. Write a function > b. Check the function > c. Change the definition > d. Check that > etc > with a minimum of keystrokes a. Write a code file b. Press F7 and see the output in the other window. c, d. Iterate. Most IDEs will give you some such facility. F7 happens to be SciTE's keystroke, others may use Ctrl-F9 or F5 or C-x M-x butterfly, but it's almost certainly going to be there. Chris Angelico From rmorgan466 at gmail.com Mon May 2 22:46:18 2011 From: rmorgan466 at gmail.com (Rita) Date: Mon, 2 May 2011 22:46:18 -0400 Subject: complex data structures in python Message-ID: Hello, I was wondering if anyone has any documentation/recipes for implementing complex data structures. For instance, if you had a dictionary with a list inside a list inside a set. -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From unknownmoss at gmail.com Mon May 2 22:56:06 2011 From: unknownmoss at gmail.com (Unknown Moss) Date: Mon, 2 May 2011 19:56:06 -0700 (PDT) Subject: (beginner question) ConfigParser nuances References: Message-ID: <7d0855fe-5371-4803-8683-366056528c54@z13g2000prk.googlegroups.com> On May 2, 3:25?pm, Chris Rebert wrote: > On Mon, May 2, 2011 at 3:04 PM, Unknown Moss wrote: > > Hi -Beginnerquestionhere. I'm working with ConfigParser. I'd like > > to take a multiline variable and convert it directly to an array. > > Seems like a common ?problem, but I don't see how I can do it without > > doing a little parsing in my own code. Here's what I'm doing ... > > >>>> import ConfigParser > >>>> import io > >>>> sample = """ > > ... [Example] > > ... fruit = apple > > ... ? ? orange > > ... ? ? pear > > ... """ > >>>> config = ConfigParser.RawConfigParser() > >>>> config.readfp(io.BytesIO(sample)) > >>>> config.get("Example", "fruit") > > 'apple\norange\npear' > >>>> temp = config.get("Example", "fruit") > >>>> temp.split() > > ['apple', 'orange', 'pear'] > > > I'm thinking there's a way to avoid this intermediate temp.split() > > step. Is there not a way to move a multiline value straight into an > > array using ConfigParser? > > Nope, there is not. I think some might instead use several numbered > options to similar effect: > > # config file > [Example] > fruit1: apple > fruit2: orange > fruit3: pear > > # Python > from itertools import count > fruits = [] > names = ("fruit" + str(i) for i in count(1)) > for name in names: > ? ? if not config.has_option("Example", name): > ? ? ? ? break > ? ? fruits.append(config.get("Example", name)) > > Cheers, > Chris > --http://rebertia.com Ok, thanks Chris. Maybe I'm getting too lazy in my old age. :-) From rustompmody at gmail.com Mon May 2 23:42:45 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 2 May 2011 20:42:45 -0700 (PDT) Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 3, 5:21?am, Steven D'Aprano wrote: > On Mon, 02 May 2011 21:02:43 +0100, Hans Georg Schaathun wrote: > > The other arguments are valid. ?And they make me lean more towards more > > static, compiled languages without the excessive run-time dynamism of > > python. > > If you value runtime efficiency over development time, sure. There are > plenty of languages which have made that decision: Pascal, C, Java, Lisp, > Forth, and many more. Or Haskell: Succinctness like python Type safety better than C, C++, Java with a minimum of type declarations From clp2 at rebertia.com Mon May 2 23:58:24 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 May 2011 20:58:24 -0700 Subject: complex data structures in python In-Reply-To: References: Message-ID: On Mon, May 2, 2011 at 7:46 PM, Rita wrote: > Hello, > I was wondering if anyone has any documentation/recipes for implementing > complex data structures. For instance, if you had a dictionary with a list > inside a list inside a set. Er, there's no special magic. The datatypes just nest normally. Pretty much the only thing to look out for is immutability/hashability. Dictionary keys and set elements should typically be immutable (and thus sensibly hashable). For this reason, tuples and frozensets are used instead of lists and non-frozen sets (respectively) in those situations (and in other cases where mutability should be disallowed). When creating a custom immutable type, one should override the __eq__(), __ne__(), and __hash__() special methods so that the type's instances can be used as dict keys and set elements. Your particular example combination doesn't work since it violates the aforementioned immutability rule. One should also be aware of the datatypes in the `collections` module, particularly `defaultdict`: http://docs.python.org/library/collections.html Cheers, Chris -- http://rebertia.com From stefan_ml at behnel.de Tue May 3 01:04:47 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 03 May 2011 07:04:47 +0200 Subject: Coolest Python recipe of all time In-Reply-To: <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: David Monaghan, 02.05.2011 23:45: > On Mon, 2 May 2011 14:58:50 -0600, Ian Kelly wrote: > >> On Mon, May 2, 2011 at 2:48 PM, David Monaghan wrote: >>> On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger wrote: >>> >>>> I think it is time to give some visibility to some of the instructive >>>> and very cool recipes in ActiveState's python cookbook. >>>> >>>> My vote for the coolest recipe of all time is: >>>> >>>> http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ >>> >>> Really cool, but wrong. x = 3234.667, not 3236.0 >> >> Nope, I get 3236. Maybe you made a mistake somewhere. > > Oops. What a plonker .Three times I checked and got the same result each > time. Now it works fine. Sorry! The bad thing about this recipe is that it requires quite a bit of background knowledge in order to infer that the code the developer is looking at is actually correct. At first sight, it looks like an evil hack, and the lack of documentation doesn't help either. Stefan From hg at schaathun.net Tue May 3 01:13:07 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 3 May 2011 06:13:07 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3gf498-tuh.ln1@svn.schaathun.net> On 03 May 2011 00:21:45 GMT, Steven D'Aprano wrote: : Python aims at acceptable performance (between 10 and 100 times slower : than C) and much easier development (between 10 and 100 times faster than : C *wink*). If that tradeoff doesn't suit you, perhaps Python is not the : language for you. It isn't the trade-off per se which bothers me, but certain features which seem to make compilation harder without making development any easier. But then, it probably depeds on what kind of development you are doing. -- :-- Hans Georg From ian.g.kelly at gmail.com Tue May 3 01:17:21 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 May 2011 23:17:21 -0600 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On Mon, May 2, 2011 at 11:04 PM, Stefan Behnel wrote: > The bad thing about this recipe is that it requires quite a bit of > background knowledge in order to infer that the code the developer is > looking at is actually correct. At first sight, it looks like an evil hack, > and the lack of documentation doesn't help either. What do you mean, "looks like"? For crying out loud, it abuses complex numbers to represent 2-element vectors, and it passes unvalidated input to eval(). It is *absolutely* an evil hack! Albeit a clever one... From drsalists at gmail.com Tue May 3 01:27:52 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 May 2011 22:27:52 -0700 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Mon, May 2, 2011 at 7:13 PM, Chris Angelico wrote: > On Tue, May 3, 2011 at 11:48 AM, rusi wrote: > > What are their space/time complexities? > > Which do you prefer? > > They're pretty similar actually. If you rework the first one to not > use range() but instead have a more classic C style of loop, they'll > be almost identical: > > def powI(x,n): > result = 1 > while n > 0: > result *= x > n-=1 > return result > > There's a subtle difference in that powR as you've coded it will > infinite-loop if given a negative exponent, while powI in any form > will simply return 1 (neither is technically correct, fwiw). Other > than that, the only difference is that one keeps its state on the call > stack, the other uses a temporary variable. > The recursive solution uses more stack. That is true. But the recursive solution has time complexity of O(logn). The iterative solution has time complexity of O(n). That's a significant difference for large n - a significant benefit of the recursive version. However, an iterative version of a function can always be created from a recursive version. In this case, an iterative version can be constructed that is O(logn) time and O(1) stack. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 3 01:29:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 15:29:51 +1000 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Tue, May 3, 2011 at 3:27 PM, Dan Stromberg wrote: > > But the recursive solution has time complexity of O(logn).? The iterative > solution has time complexity of O(n).? That's a significant difference for > large n - a significant benefit of the recursive version. Are you sure? It will produce n function calls and n multiplications, how is that O(log n)? Chris Angelico From eaglebalti at gmail.com Tue May 3 01:42:16 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Mon, 2 May 2011 22:42:16 -0700 (PDT) Subject: Hello Friends Message-ID: <900970dc-a792-415d-84f9-a4afb1072140@bl1g2000vbb.googlegroups.com> What are you lookink for. Just visit to see what you want www.bollywoodhotactresswallpapers.blogspot.com www.bollywoodhotwallpaperz.blogspot.com www.bollywoodhotactresspicz.blogspot.com www.hottesthitsbollywood.blogspot.com www.bollywoodhotphotoz.blogspot.com From ian.g.kelly at gmail.com Tue May 3 01:46:58 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 May 2011 23:46:58 -0600 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Mon, May 2, 2011 at 11:27 PM, Dan Stromberg wrote: > But the recursive solution has time complexity of O(logn).? The iterative > solution has time complexity of O(n).? That's a significant difference for > large n - a significant benefit of the recursive version. It's linear as written. I think you're talking about an implementation like this one: def powR(x,n): if n < 0: return 1.0 / powR(x, -n) elif n == 0: return 1 else: half_n = n // 2 root = powR(x, half_n) result = root * root if half_n + half_n == n - 1: result = result * x return result That's O(log n), but it was harder to write, and it could just as easily be iterative. In fact it might actually have been a bit simpler to write it iteratively. From patrick.vrijlandt at gmail.com Tue May 3 01:50:13 2011 From: patrick.vrijlandt at gmail.com (Patrick Vrijlandt) Date: Mon, 2 May 2011 22:50:13 -0700 (PDT) Subject: ctypes and twain_32.dll References: <844574c2-4ff4-41b8-8cdc-de103437d18f@j31g2000yqe.googlegroups.com> <4dbefe78$0$14685$ba4acef3@reader.news.orange.fr> Message-ID: <88eb4d02-5273-4ea6-8c50-8f7bcb7e5224@w24g2000yqb.googlegroups.com> On 2 mei, 20:56, "Michel Claveau - MVP" wrote: > Hi! > > On my system, thera are not "twain32.dll" or "twain_32.dll", but "twain.dll" > > @+ > -- > Michel Claveau Hi, I have both. They are correctly installed and working. ctypes gives a different response if it cannot find the requested DLL. Patrick From drsalists at gmail.com Tue May 3 01:51:28 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 May 2011 22:51:28 -0700 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Mon, May 2, 2011 at 10:29 PM, Chris Angelico wrote: > On Tue, May 3, 2011 at 3:27 PM, Dan Stromberg wrote: > > > > But the recursive solution has time complexity of O(logn). The iterative > > solution has time complexity of O(n). That's a significant difference > for > > large n - a significant benefit of the recursive version. > > Are you sure? It will produce n function calls and n multiplications, > how is that O(log n)? > Doh. Usually when someone gives a recursive solution to this problem, it's O(logn), but not this time. Here's a logn one: def power(x, n): if n == 0: return 1 else: half, remainder = divmod(n, 2) if remainder == 1: return power(x, half) ** 2 * x else: return power(x, half) ** 2 -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue May 3 02:00:05 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 May 2011 02:00:05 -0400 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On 5/3/2011 1:04 AM, Stefan Behnel wrote: > The bad thing about this recipe is that it requires quite a bit of > background knowledge in order to infer that the code the developer is > looking at is actually correct. The main math knowledge needed is the trivial fact that if a*x + b = 0, then x = -b/a. The other math knowledge needed is that complex numbers add componentwise. The trick is that replacing x with j and evaluating therefore causes (in Python) all the coefficients of x (now j) to be added together separately from all the constant terms to reduce the linear equation to a*x+b (= 0 implied). -- Terry Jan Reedy From stefan_ml at behnel.de Tue May 3 02:23:58 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 03 May 2011 08:23:58 +0200 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: Terry Reedy, 03.05.2011 08:00: > On 5/3/2011 1:04 AM, Stefan Behnel wrote: > >> The bad thing about this recipe is that it requires quite a bit of >> background knowledge in order to infer that the code the developer is >> looking at is actually correct. > > The main math knowledge needed is the trivial fact that if a*x + b = 0, > then x = -b/a. The other math knowledge needed is that complex numbers add > componentwise. The trick is that replacing x with j and evaluating > therefore causes (in Python) all the coefficients of x (now j) to be added > together separately from all the constant terms to reduce the linear > equation to a*x+b (= 0 implied). As your above paragraph proves, it's the kind of implementation that requires three lines of executing code and at least 6 lines of additional comment. Hopefully accompanied by an excuse of the developer. Stefan From greg.ewing at canterbury.ac.nz Tue May 3 02:29:30 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 May 2011 18:29:30 +1200 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: <929lmdF59lU1@mid.individual.net> Terry Reedy wrote: > The trick is that replacing x with j and evaluating > therefore causes (in Python) all the coefficients of x (now j) to be > added together separately from all the constant terms to reduce the > linear equation to a*x+b (= 0 implied). Hmmm... so if we used quaternions, could we solve systems of linear equations in 3 variables? -- Greg From hg at schaathun.net Tue May 3 03:01:35 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 3 May 2011 08:01:35 +0100 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 3 May 2011 07:56:26 +1000, Chris Angelico wrote: : > often recursively. ?The compiler should generate code the way the CPU : > thinks (most optimally), i.e. iteratively. : : The CPU can function iteratively or recursively. I should have said 'hardware' rather than CPU. Iteratively it is not as optimal as the call contexts have to be stored. : But in my opinion, the programmer and the interpreter/compiler are : teammates. If you allow programmers to be stupid, you will get a lot : of stupid programmers writing code. (I think that's one of PHP's : biggest downsides.) If the human and the machine know each other well : enough, the resulting code can be orders of magnitude more efficient : to run, *without taking any more tme to code* because the programmer : already knew the right things to do. There are situations where that team is essential. However, in many more situation, the programmer has to team primarily with domain experts and work with a language in which the domain expert is fluent. The compiler and hardware are slaves of the engineers, and extra staff to team up with the compiler is an added cost and delay. : Perhaps it will take you four hours to read through something, study : it, maybe eyeball the compiler's source code, maybe do some : disassembly. If you have a few years of career ahead of you, you'll : benefit many times over from those few hours, and without spending : extra time, you'll produce better code. THAT is what distinguishes the : master from the novice. That depends on /what/ your career is, and what you need to master. -- :-- Hans Georg From rafadurancastaneda at gmail.com Tue May 3 03:08:02 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Tue, 3 May 2011 09:08:02 +0200 Subject: Py / VNC Automation In-Reply-To: References: <86fc701c-3627-49af-a731-226329eaddad@glegroupsg2000goo.googlegroups.com> Message-ID: You can check this https://github.com/kanaka/noVNC 2011/5/3 Dan Stromberg > > On Mon, May 2, 2011 at 5:23 PM, PyNewbie wrote: > >> Hi, >> I'm looking for a python class or open source code that is tightly >> integrated with VNC protocols - any ideas? >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > I've not updated this in a while, but it's got a python vnc viewer in the > list: > > http://stromberg.dnsalias.org/~dstromberg/vnc.html > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Tue May 3 03:52:15 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 3 May 2011 00:52:15 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> On May 3, 10:29?am, Chris Angelico wrote: > On Tue, May 3, 2011 at 3:27 PM, Dan Stromberg wrote: > Doh. > Usually when someone gives a recursive solution to this problem, it's > O(logn), but not this time. > Here's a logn one: :-) Ok so you beat me to it :D I was trying to arrive at an answer to the question (by M Harris) about why anyone would do something like fib recursively. I used power since that illustrates the case more easily, viz: A trivial power -- recursive or iterative -- is linear time -- O(n) A more clever power can be O(log(n)) This more clever power can be trivially derived from the recursive one as follows: The recursive O(n) function: def powR(x,n): return 1 if (n==0) else (x * powR(x, n-1)) is just python syntax for the school algebra (or Haskell) equations: x^0 = 1 x^(n+1) = x * x^n Adding one more equation: x^(2*n) = (x^2)^n = (x*x)^n Re-python-ifying we get: def pow(x,n): return 1 if (n==0) else pow(x*x, n/2) if even(n) else x*pow(x,n-1) def even(n): return n % 2 == 0 Can this be done iteratively? Of course but its not so trivial. [If you believe it is, then try writing a log(n) fib iteratively :D ] From duncan.booth at invalid.invalid Tue May 3 04:41:04 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 3 May 2011 08:41:04 GMT Subject: "raise (type, value, traceback)" and "raise type, value, traceback" References: <1304356995.4335.2.camel@selene> Message-ID: Ian Kelly wrote: > t = (type, value, traceback) > raise t > > That it accepts the tuple and raises a value-less expression of type > `type` surprises me. The docs don't say anything about this, and I > would have expected a TypeError, but it appears to be extracting the > first element of the tuple and using that as the value of the first > expression. > Not only that but you can nest tuples and it will drill down as far as necessary through the tuples until it finds something that isn't a tuple. It doesn't appear to be documented, but I think it may be intended to provide some kind of symmetry with 'try...except': when you catch an exception the expression used to catch the exception must be 'compatible' with the exception, i.e. the exception itself, one of its base classes, or a tuple which contains an item 'compatible' with the exception. So my guess would be that since it allows: MyExceptionSpec = (RuntimeError, ValueError) try: ... except MyExceptionSpec: ... the intent is to allow you to also throw 'MyExceptionSpec' from within the 'try'. I would also guess that it is a hangover from the days when exceptions were strings and you couldn't use inheritance to group exceptions. -- Duncan Booth http://kupuguy.blogspot.com From davea at ieee.org Tue May 3 06:32:06 2011 From: davea at ieee.org (Dave Angel) Date: Tue, 03 May 2011 06:32:06 -0400 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> Message-ID: <4DBFD9A6.1040803@ieee.org> On 01/-10/-28163 02:59 PM, rusi wrote: > On May 3, 10:29 am, Chris Angelico wrote: >> On Tue, May 3, 2011 at 3:27 PM, Dan Stromberg wrote: >> Doh. > >> Usually when someone gives a recursive solution to this problem, it's >> O(logn), but not this time. > >> Here's a logn one: > > :-) Ok so you beat me to it :D > > I was trying to arrive at an answer to the question (by M Harris) > about why anyone would do something like fib recursively. I used power > since that illustrates the case more easily, viz: > A trivial power -- recursive or iterative -- is linear time -- O(n) > A more clever power can be O(log(n)) > This more clever power can be trivially derived from the recursive one > as follows: > > The recursive O(n) function: > def powR(x,n): return 1 if (n=) else (x * powR(x, n-1)) > > is just python syntax for the school algebra (or Haskell) equations: > > x^0 = > x^(n+1) = * x^n > > Adding one more equation: > x^(2*n) =x^2)^n = (x*x)^n > Re-python-ifying we get: > > > def pow(x,n): > return 1 if (n=) else pow(x*x, n/2) if even(n) else x*pow(x,n-1) > > def even(n): return n % 2 =0 > > Can this be done iteratively? Of course but its not so trivial. > > [If you believe it is, then try writing a log(n) fib iteratively :D ] > What I'm surprised at is that nobody has pointed out that the logn version is also generally more accurate, given traditional floats. Usually getting the answer accurate (given the constraints of finite precision intermediates) is more important than performance, but in this case they go hand in hand. DaveA From jamesdnld730 at gmail.com Tue May 3 06:48:57 2011 From: jamesdnld730 at gmail.com (James A. Donald) Date: Tue, 3 May 2011 03:48:57 -0700 (PDT) Subject: Installing programs that depend on, or are, python extensions. References: <3d0dee08-e743-4f10-ae79-5d3052c3d0d9@h36g2000pro.googlegroups.com> Message-ID: <7142c2e5-5c54-4f85-a957-2797560fe97f@s41g2000prb.googlegroups.com> On Apr 30, 6:39?pm, David Cournapeau wrote: > On Sat, Apr 30, 2011 at 2:19 PM, James A. Donald wrote: > > > I have noticed that installingpythonprograms tends to be hell, > > particularly underwindows, and installingpythonprograms that rely > > on, or in large part are,pythonextensionswritten in C++ tends to be > > hell on wheels with large spiky knobs and scythes on the wheels. > > > Is this because suchinstallare inherently hard to do and hard to > > write, or is it becauseInstalltends to be done last, and therefore > > not done at all? > > Most likely both. > > Packaging complex application is hard, and I think few programmers > like doing it, so it is rarely done correctly. > > > > > Can anyone suggest any examples of such a program with a cleanwindows > >installthat shows how it was done? > > > Bywindowsinstall, I mean you run setup.exe, and get a program group, > > file types registered, and an entry in the add/remove programs list, I > > do not mean fourteen pages of direly incomplete notes which do not > > actually work for versions later than 1.01, and do not work for > > version 1.01 unless one has already installed the complete developer > > environment. > > Well,pythonitself is a reasonably good example I think. But if you > are interested in having onepythonprogram which is a one clickinstallwithout requiring the user to eveninstallpython, you will > need to look into tools like py2exe which can create all the files > necessary to do so from an existingpythonpackage. Then, you package > those files into a nice installer. I like nsis, which is open source > and relatively well documented, but there are other solutions as well. > > cheers, > > David py2exe would work, but a correct installer would install Python if not present, then install the program. From rustompmody at gmail.com Tue May 3 06:51:16 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 3 May 2011 03:51:16 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> Message-ID: On May 3, 3:32?pm, Dave Angel wrote: > What I'm surprised at is that nobody has pointed out that the logn > version is also generally more accurate, given traditional floats. > Usually getting the answer accurate (given the constraints of finite > precision intermediates) is more important than performance, but in this > case they go hand in hand. Well!! That's a slant that I was not aware of -- though fairly obvious on second thought. Thanks Dave. From rosuav at gmail.com Tue May 3 07:04:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 21:04:07 +1000 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <4DBFD9A6.1040803@ieee.org> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4DBFD9A6.1040803@ieee.org> Message-ID: On Tue, May 3, 2011 at 8:32 PM, Dave Angel wrote: > What I'm surprised at is that nobody has pointed out that the logn version > is also generally more accurate, given traditional floats. Usually getting > the answer accurate (given the constraints of finite precision > intermediates) is more important than performance, but in this case they go > hand in hand. And that, Your Honour, is why I prefer bignums (especially for integers) to floating point. Precision rather than performance. Chris Angelico From hg at schaathun.net Tue May 3 08:39:24 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 3 May 2011 13:39:24 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01 May 2011 08:45:51 GMT, Steven D'Aprano wrote: : Python uses a data model of "name binding" and "call by object" (also : known as "call by sharing"). I trust I don't need to define my terms, but : just in case: Without having the time to get my hand around exactly what this means: Simula has three ways of transmitting arguments, namely transmission by name, by value, and by reference. Is transmission by name the same as call by object? Anyway, I have never seen anyone counting more than three ways of doing this ... -- :-- Hans Georg From steve+comp.lang.python at pearwood.info Tue May 3 08:49:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 May 2011 12:49:50 GMT Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4DBFD9A6.1040803@ieee.org> Message-ID: <4dbff9ed$0$29991$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 May 2011 21:04:07 +1000, Chris Angelico wrote: > And that, Your Honour, is why I prefer bignums (especially for integers) > to floating point. Precision rather than performance. I'm intrigued by your comment "especially for integers", which implies that you might use bignums for non-integers. Out of curiosity, how would you calculate: sin(sqrt(7)*pi/31) using bignums? -- Steven From rosuav at gmail.com Tue May 3 09:02:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 May 2011 23:02:29 +1000 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <4dbff9ed$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4DBFD9A6.1040803@ieee.org> <4dbff9ed$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 3, 2011 at 10:49 PM, Steven D'Aprano wrote: > On Tue, 03 May 2011 21:04:07 +1000, Chris Angelico wrote: > >> And that, Your Honour, is why I prefer bignums (especially for integers) >> to floating point. Precision rather than performance. > > I'm intrigued by your comment "especially for integers", which implies > that you might use bignums for non-integers. Out of curiosity, how would > you calculate: > > sin(sqrt(7)*pi/31) > > using bignums? REXX uses decimal bignums, although I don't have a high-performance math library (for sin) that uses anything more than IEEE double precision. If I coded my own sin algorithm in REXX, I could go to whatever precision memory (and patience) would allow. Chris Angelico From daniel.rentz at gmx.de Tue May 3 09:45:45 2011 From: daniel.rentz at gmx.de (Daniel Rentz) Date: Tue, 03 May 2011 15:45:45 +0200 Subject: Compiling Python 3.2 on Cygwin fails Message-ID: Hello, I've downloaded the 3.2 source tarball from python.org and tried to compile Python from scratch in a Cygwin 1.7.7 environment. Configure works as expected. Make fails with the following message: make: *** No rule to make target `libpython3.2m.dll.a', needed by `python.exe'. Stop. There is a suspicious line in Makefile.pre.in, line 509: $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) Changing that line to $(DLLLIBRARY) $(LDLIBRARY): $(LIBRARY_OBJS) lets make finish, but gives a bunch of other errors and warnings, such as: /usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lpython3.2 collect2: ld returned 1 exit status Python build finished, but the necessary bits to build these modules were not found: _tkinter nis ossaudiodev spwd To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _bisect _codecs_cn _codecs_hk _codecs_iso2022 _codecs_jp _codecs_kr _codecs_tw _csv _ctypes _ctypes_test _curses _curses_panel _datetime _elementtree _gdbm _hashlib _heapq _json _lsprof _multibytecodec _multiprocessing _pickle _posixsubprocess _random _socket _sqlite3 _ssl _struct _testcapi array atexit audioop binascii bz2 cmath crypt fcntl grp math mmap parser pyexpat readline resource select syslog termios time unicodedata zlib Is there something obvious I am missing here? Regards Daniel From hniksic at xemacs.org Tue May 3 09:50:55 2011 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 03 May 2011 15:50:55 +0200 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87aaf351vk.fsf@xemacs.org> Steven D'Aprano writes: > "Python's data model is different from other languages" > > which is perfectly correct, if you think of C as "other languages". But > it's equally correct to say that Python's data model is the same as other > languages. As I understand it, Python and Ruby have the same data model. > So does Java, so long as you only consider objects[...] > What other languages use the same, or mostly similar, data model as > Python? Count in Common Lisp and Scheme. I would say that, considering currently most popular languages and platforms, Python's data model is in the majority. It is only the people coming from a C++ background that tend to be confused by it. From miki.tebeka at gmail.com Tue May 3 09:54:25 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 3 May 2011 06:54:25 -0700 (PDT) Subject: Installing programs that depend on, or are, python extensions. In-Reply-To: <7142c2e5-5c54-4f85-a957-2797560fe97f@s41g2000prb.googlegroups.com> Message-ID: > py2exe would work, but a correct installer would install Python if not > present, then install the program. py2exe packs everything you need, including Python. A program created with py2exe does not depend on installed Python. From wim at go2people.nl Tue May 3 10:02:52 2011 From: wim at go2people.nl (Wim Feijen) Date: Tue, 3 May 2011 16:02:52 +0200 Subject: spf-records Message-ID: Dag mannen, Afgelopen week liepen we tegen het feit op dat Google e-mails afkomstig van onze server als spam markeerde en deze zonder bericht verwijderde. Ik vroeg me af of een van jullie hier wel eens tegenop is gelopen en wil bij deze even waarschuwen dat dat dus zomaar kan gebeuren. Wat voor ons werkte om dit op te lossen, is om een spf-record toe te voegen. In ons geval: v=spf1 a mx ip4:89.31.96.72 ip4:79.170.94.115 include=_spf.google.com ?all Neem dit maar niet over, want ik vraag me af of dit goed is? Voor een precieze uitleg van spf, zie: http://www.openspf.org/ Onze klant meldde dat hij geen mail meer kan ontvangen. Heeft iemand een idee hoe dit kan? Groeten van Wim -- Wim Feijen Algemeen directeur wim at go2people.nl 06 11113316 Go2People Websites Keizersgracht 8 1015 CN Amsterdam 020 7370378 www.go2people.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From listas.programacao at gmail.com Tue May 3 10:09:27 2011 From: listas.programacao at gmail.com (Jayme Proni Filho) Date: Tue, 3 May 2011 11:09:27 -0300 Subject: spf-records In-Reply-To: References: Message-ID: English man English. 2011/5/3 Wim Feijen > Dag mannen, > > Afgelopen week liepen we tegen het feit op dat Google e-mails afkomstig van > onze server als spam markeerde en deze zonder bericht verwijderde. Ik vroeg > me af of een van jullie hier wel eens tegenop is gelopen en wil bij deze > even waarschuwen dat dat dus zomaar kan gebeuren. > > Wat voor ons werkte om dit op te lossen, is om een spf-record toe te > voegen. In ons geval: > v=spf1 a mx ip4:89.31.96.72 ip4:79.170.94.115 include=_spf.google.com ?all > > Neem dit maar niet over, want ik vraag me af of dit goed is? > > Voor een precieze uitleg van spf, zie: http://www.openspf.org/ > > Onze klant meldde dat hij geen mail meer kan > ontvangen. Heeft iemand een idee hoe dit kan? > > Groeten van Wim > > -- > Wim Feijen > Algemeen directeur > wim at go2people.nl > 06 11113316 > > Go2People Websites > Keizersgracht 8 > 1015 CN Amsterdam > 020 7370378 > www.go2people.nl > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- --------------------------------------------------------------------------------------- Jayme Proni Filho Skype: jaymeproni Twitter: @jaymeproni Phone: +55 - 17 - 3631 - 6576 Mobile: +55 - 17 - 9605 - 3560 e-Mail: jaymeproni at yahoo dot com dot br Blogs (Em constru??o) Programandor: http://jaymeproni.wordpress.com Sociedade em A??o: http://sociedaemacao.wordpress.com --------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From listas.programacao at gmail.com Tue May 3 10:11:37 2011 From: listas.programacao at gmail.com (Jayme Proni Filho) Date: Tue, 3 May 2011 11:11:37 -0300 Subject: Hello Friends In-Reply-To: <900970dc-a792-415d-84f9-a4afb1072140@bl1g2000vbb.googlegroups.com> References: <900970dc-a792-415d-84f9-a4afb1072140@bl1g2000vbb.googlegroups.com> Message-ID: This is a place about python man! Python. 2011/5/3 Ashraf Ali > What are you lookink for. Just visit to see what you want > www.bollywoodhotactresswallpapers.blogspot.com > > www.bollywoodhotwallpaperz.blogspot.com > > www.bollywoodhotactresspicz.blogspot.com > > www.hottesthitsbollywood.blogspot.com > > www.bollywoodhotphotoz.blogspot.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- --------------------------------------------------------------------------------------- Jayme Proni Filho Skype: jaymeproni Twitter: @jaymeproni Phone: +55 - 17 - 3631 - 6576 Mobile: +55 - 17 - 9605 - 3560 e-Mail: jaymeproni at yahoo dot com dot br Blogs (Em constru??o) Programandor: http://jaymeproni.wordpress.com Sociedade em A??o: http://sociedaemacao.wordpress.com --------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From pari685 at gmail.com Tue May 3 10:15:18 2011 From: pari685 at gmail.com (Parikshit ..) Date: Tue, 3 May 2011 16:15:18 +0200 Subject: Installing programs that depend on, or are, python extensions. In-Reply-To: References: <7142c2e5-5c54-4f85-a957-2797560fe97f@s41g2000prb.googlegroups.com> Message-ID: Pyinstaller can also be used to create executables. It does not need python installed. We have been able to make executables for windows and mac as well with this. - Parikshit On Tue, May 3, 2011 at 3:54 PM, Miki Tebeka wrote: > > py2exe would work, but a correct installer would install Python if not > > present, then install the program. > py2exe packs everything you need, including Python. A program created with > py2exe does not depend on installed Python. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wim at go2people.nl Tue May 3 10:23:40 2011 From: wim at go2people.nl (Wim Feijen) Date: Tue, 3 May 2011 16:23:40 +0200 Subject: spf-records In-Reply-To: References: Message-ID: Excuse me, this message was sent to the wrong mailing list. Sorry, Wim 2011/5/3 Wim Feijen > Dag mannen, > > Afgelopen week liepen we tegen het feit op dat Google e-mails afkomstig van > onze server als spam markeerde en deze zonder bericht verwijderde. Ik vroeg > me af of een van jullie hier wel eens tegenop is gelopen en wil bij deze > even waarschuwen dat dat dus zomaar kan gebeuren. > > Wat voor ons werkte om dit op te lossen, is om een spf-record toe te > voegen. In ons geval: > v=spf1 a mx ip4:89.31.96.72 ip4:79.170.94.115 include=_spf.google.com ?all > > Neem dit maar niet over, want ik vraag me af of dit goed is? > > Voor een precieze uitleg van spf, zie: http://www.openspf.org/ > > Onze klant meldde dat hij geen mail meer kan > ontvangen. Heeft iemand een idee hoe dit kan? > > Groeten van Wim > > -- > Wim Feijen > Algemeen directeur > wim at go2people.nl > 06 11113316 > > Go2People Websites > Keizersgracht 8 > 1015 CN Amsterdam > 020 7370378 > www.go2people.nl > > -- Wim Feijen Algemeen directeur wim at go2people.nl 06 11113316 Go2People Websites Keizersgracht 8 1015 CN Amsterdam 020 7370378 www.go2people.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue May 3 10:49:04 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 3 May 2011 14:49:04 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-03, Hans Georg Schaathun wrote: > On 01 May 2011 08:45:51 GMT, Steven D'Aprano > wrote: >: Python uses a data model of "name binding" and "call by object" (also >: known as "call by sharing"). I trust I don't need to define my terms, but >: just in case: > > Without having the time to get my hand around exactly what this means: > Simula has three ways of transmitting arguments, namely transmission > by name, by value, and by reference. Is transmission by name the same > as call by object? No. For example, assume the argument is a[i]. In call by object, the expression a[i] is evaluated (i is evaluated, and then used as an index to determine the object that is the ith element of a). The callee's argument name is then bound to that object. In call by name, every time the callee references the argument name, the expression a[i] is evaluated anew. If the value of 'i' or the binding of 'a' has changed since the time of the function call, then the callee's argument now refers to a different object than it did at the time of the the function call. It's rather like a macro language (e.g. cpp) which merely performs a textual substitution of the argument name (the difference between pass-by-name and macro substitution is that the context of the argument evaluation is different). -- Grant Edwards grant.b.edwards Yow! Well, I'm INVISIBLE at AGAIN ... I might as well gmail.com pay a visit to the LADIES ROOM ... From jeanmichel at sequans.com Tue May 3 11:20:34 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 03 May 2011 17:20:34 +0200 Subject: spf-records In-Reply-To: References: Message-ID: <4DC01D42.5040907@sequans.com> Wim Feijen wrote: > Excuse me, this message was sent to the wrong mailing list. > > Sorry, Wim > > 2011/5/3 Wim Feijen > > > Dag mannen, > You're lucky that the native language of our Benevolent Dictator For Life is tolerated in this list. JM From steve+comp.lang.python at pearwood.info Tue May 3 11:20:42 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 May 2011 15:20:42 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc01d4a$0$29991$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 May 2011 13:39:24 +0100, Hans Georg Schaathun wrote: > On 01 May 2011 08:45:51 GMT, Steven D'Aprano > wrote: > : Python uses a data model of "name binding" and "call by object" (also > : known as "call by sharing"). I trust I don't need to define my terms, > but : just in case: > > Without having the time to get my hand around exactly what this means: > Simula has three ways of transmitting arguments, namely transmission by > name, by value, and by reference. Is transmission by name the same as > call by object? Anyway, I have never seen anyone counting more than > three ways of doing this ... You get credit for not falling into the trap of thinking there are only two, call by reference and call by value, but there are *many* more than just three. Wikipedia lists at least 13: http://en.wikipedia.org/wiki/Evaluation_strategy See also: http://effbot.org/zone/call-by-object.htm -- Steven From tjreedy at udel.edu Tue May 3 11:49:01 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 May 2011 11:49:01 -0400 Subject: Coolest Python recipe of all time In-Reply-To: <929lmdF59lU1@mid.individual.net> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> <929lmdF59lU1@mid.individual.net> Message-ID: On 5/3/2011 2:29 AM, Gregory Ewing wrote: > Terry Reedy wrote: >> The trick is that replacing x with j and evaluating therefore causes >> (in Python) all the coefficients of x (now j) to be added together >> separately from all the constant terms to reduce the linear equation >> to a*x+b (= 0 implied). > > Hmmm... so if we used quaternions, could we solve systems > of linear equations in 3 variables? Yes and no. The use of 1*j merely collected and added together all the multipliers of 'x' (and all the constant terms). That is a fairly trivial matter of constant folding. Systems of linear equations are usually presented in that form already. The actual solution to the simple equation is in the formula x = -a/b (where a and b are the sums). The solution formula for three variables would be far more complex. -- Terry Jan Reedy From drsalists at gmail.com Tue May 3 12:10:52 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 3 May 2011 09:10:52 -0700 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <4dbff9ed$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4DBFD9A6.1040803@ieee.org> <4dbff9ed$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 3, 2011 at 5:49 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Tue, 03 May 2011 21:04:07 +1000, Chris Angelico wrote: > > > And that, Your Honour, is why I prefer bignums (especially for integers) > > to floating point. Precision rather than performance. > > I'm intrigued by your comment "especially for integers", which implies > that you might use bignums for non-integers. Out of curiosity, how would > you calculate: > > sin(sqrt(7)*pi/31) > > using bignums? > It's a bit of a stretch, but you could wrap a fixed slash implementation around bignums to do this. http://portal.acm.org/citation.cfm?id=1309566 Fixed slash is like a rational, but you never let the numerator or denominator grow huge, instead reducing the precision of the fraction now and then to keep things manageable. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dunpealer at gmail.com Tue May 3 12:31:06 2011 From: dunpealer at gmail.com (Dun Peal) Date: Tue, 3 May 2011 09:31:06 -0700 (PDT) Subject: Why do directly imported variables behave differently than those attached to imported module? Message-ID: Hi! Here's the demonstrating code: # module foo.py var = 0 def set(): global var var = 1 Script using this module: import foo from foo import * print var, foo.var set() print var, foo.var Script output: 0 0 0 1 Apparently, the `var` we imported from `foo` never got set, but `foo.var` on the imported `foo` - did. Why? Thanks, D. From python at rcn.com Tue May 3 12:32:19 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 3 May 2011 09:32:19 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> <929lmdF59lU1@mid.individual.net> Message-ID: <5099131d-f60d-4c61-b69f-4666fb25c229@f15g2000pro.googlegroups.com> On May 2, 11:29?pm, Gregory Ewing wrote: > Terry Reedy wrote: > > The trick is that replacing x with j and evaluating > > therefore causes (in Python) all the coefficients of x (now j) to be > > added together separately from all the constant terms to reduce the > > linear equation to a*x+b (= 0 implied). > > Hmmm... so if we used quaternions, could we solve systems > of linear equations in 3 variables? Yes :-) The implementation of a Quanternion class and the Quartic equation is left as an exercise for the reader ;-) Raymond @raymondh From mwilson at the-wire.com Tue May 3 12:33:15 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 03 May 2011 12:33:15 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hans Georg Schaathun wrote: > On 01 May 2011 08:45:51 GMT, Steven D'Aprano > wrote: > : Python uses a data model of "name binding" and "call by object" (also > : known as "call by sharing"). I trust I don't need to define my terms, > : but just in case: > > Without having the time to get my hand around exactly what this means: > Simula has three ways of transmitting arguments, namely transmission > by name, by value, and by reference. Is transmission by name the same > as call by object? Anyway, I have never seen anyone counting more than > three ways of doing this ... To illustrate the neither-fish-nor-fowl nature of Python calls: mwilson at tecumseth:~$ python 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. >>> def identify_call (a_list): ... a_list[0] = "If you can see this, you don't have call-by-value" ... a_list = ["If you can see this, you have call-by-reference"] ... >>> my_list = [None] >>> identify_call (my_list) >>> my_list ["If you can see this, you don't have call-by-value"] so it's neither call-by-value nor call-by-reference as (e.g.) C or PL/I programming would have it (don't know about Simula, so I am off topic, actually.) It's not so wrong to think of Python's parameter handling as ordinary assignments from outer namespaces to an inner namespace. Mel. From python at rcn.com Tue May 3 12:43:41 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 3 May 2011 09:43:41 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On May 2, 10:04?pm, Stefan Behnel wrote: > The bad thing about this recipe is that it requires quite a bit of > background knowledge in order to infer that the code the developer is > looking at is actually correct. At first sight, it looks like an evil hack, > and the lack of documentation doesn't help either. The recipe is cool in the same way that a magic trick is cool. A practical recipe would use a more general purpose method (perhaps using finite differences or continued fractions); it would have documentation and tests; it would accept a regular python function instead of a string; and it would avoid an unsanitized eval(). But then it would completely lose its panache, its flourish, and the pleasant gratification that you get when solving the riddle of how it works. We should have a separate thread for the most practical, best documented, least surprising, and most boring recipe ;-) Raymond From stefan.kuzminski at gmail.com Tue May 3 12:48:27 2011 From: stefan.kuzminski at gmail.com (Stefan Kuzminski) Date: Tue, 3 May 2011 12:48:27 -0400 Subject: Pickling extension types Message-ID: Hi all, I have an extension type written in C, but I cannot get it to pickle, any insights would be greatly appreciated. I see in the docs that I should define a __reduce__ method and that does get called, but I don't know specifically the type of the 'callable object' that should be the first thing in the tuple returned by __reduce__. thx, S start listing.. #include "Python.h" static PyObject *mv_new(PyTypeObject *type, PyObject *args, PyObject *kw); static int mv_cmp(PyObject *self, PyObject *other); /* * print MV */ static PyObject *mv_repr(MV *mv){ PyObject *rtn; rtn = PyString_FromFormat("MV(%d)", mv->index); return rtn; } /* * get mv's index */ static PyObject *mv_idx(PyObject *self, PyObject *ags){ MV *mv; mv = (MV*)self; return PyInt_FromLong( (long)mv->index ); } /* * get mv's index as str */ static PyObject *mv_reduce(PyObject *self, PyObject *ags){ MV *mv; mv = (MV*)self; return PyString_FromString( "foo" ); } /* * get mv's index as str */ static PyObject *mv_reduce(PyObject *self, PyObject *ags){ MV *mv; mv = (MV*)self; PyObject *return_tuple; // build the return tuple return_tuple = PyTuple_New(5); // THIS IS THE QUESTION, what to set as "callable object??" // PyTuple_SetItem( return_tuple, 0, mv_new ); PyTuple_SetItem( return_tuple, 1 PyTuple_New()); return return_tuple; } static PyMethodDef mv_methods[] = { {"index", mv_idx, METH_VARARGS}, {"__reduce__", mv_reduce, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; PyTypeObject PyMV_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /* Number of items for varobject */ "MV", /* Name of this type */ sizeof(MV), /* Basic object size */ 0, /* Item size for varobject */ (destructor)PyObject_Del, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ mv_cmp, /* tp_compare */ (reprfunc)mv_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ mv_idx, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ PyObject_GenericSetAttr, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ 0, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ mv_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ mv_new, /* tp_new */ }; /* * cmp MV */ static int mv_cmp(PyObject *mv, PyObject *other){ if( other->ob_type == &PyMV_Type ) { if( ((MV*)mv)->index == ((MV*)other)->index ) { return 0; } else { return -1; } } return -1; } /* * new MV */ static PyObject *mv_new(PyTypeObject *type, PyObject *args, PyObject *kw){ MV *mv; int index; mv = PyObject_New(MV, &PyMV_Type); if (mv == NULL){ return NULL; } // get the args if( !PyArg_ParseTuple( args,(char *)"i:MV", &index )){ return NULL; } // store index mv->index = index; return (PyObject*)mv; } -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Tue May 3 12:51:20 2011 From: debatem1 at gmail.com (geremy condra) Date: Tue, 3 May 2011 09:51:20 -0700 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> <929lmdF59lU1@mid.individual.net> Message-ID: On Tue, May 3, 2011 at 8:49 AM, Terry Reedy wrote: > On 5/3/2011 2:29 AM, Gregory Ewing wrote: >> >> Terry Reedy wrote: >>> >>> The trick is that replacing x with j and evaluating therefore causes >>> (in Python) all the coefficients of x (now j) to be added together >>> separately from all the constant terms to reduce the linear equation >>> to a*x+b (= 0 implied). >> >> Hmmm... so if we used quaternions, could we solve systems >> of linear equations in 3 variables? > > Yes and no. The use of 1*j merely collected and added together all the > multipliers of 'x' (and all the constant terms). That is a fairly trivial > matter of constant folding. Systems of linear equations are usually > presented in that form already. The actual solution to the simple equation > is in the formula x = -a/b (where a and b are the sums). The solution > formula for three variables would be far more complex. Or just use a gauss-jordan solver, which has the advantage of being easy to explain and possible to verify by hand on small instances. Geremy Condra From invalid at invalid.invalid Tue May 3 12:52:26 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 3 May 2011 16:52:26 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-03, Mel wrote: > To illustrate the neither-fish-nor-fowl nature of Python calls: > > mwilson at tecumseth:~$ python > 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. >>>> def identify_call (a_list): > ... a_list[0] = "If you can see this, you don't have call-by-value" > ... a_list = ["If you can see this, you have call-by-reference"] > ... >>>> my_list = [None] >>>> identify_call (my_list) >>>> my_list > ["If you can see this, you don't have call-by-value"] > > so it's neither call-by-value nor call-by-reference as (e.g.) C or PL/I > programming would have it (don't know about Simula, so I am off topic, > actually.) It's not so wrong to think of Python's parameter handling as > ordinary assignments from outer namespaces to an inner namespace. As long as you think of "ordinary assignments" the Python way and not the C or PL/I way. :) -- Grant Edwards grant.b.edwards Yow! So this is what it at feels like to be potato gmail.com salad From dan.kluev at gmail.com Tue May 3 12:57:51 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Wed, 4 May 2011 03:57:51 +1100 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 3:31 AM, Dun Peal wrote: > Apparently, the `var` we imported from `foo` never got set, but > `foo.var` on the imported `foo` - did. Why? Because all names are references to some values, not other names (in CPython, it means all names are PyObject*, and point directly to the objects, not other pointers) When you do `from foo import bar` it assigns globals()['bar'] of current module to reference same value as `foo.bar`. Its now local namespace name, not `foo` namespace, and therefore functions in `foo` cannot modify this namespace. Since ints are immutable, when you do `var = 1` you create new object of type int, and re-assign `var` name to point to new object. `foo.var`, on other hand, is a way to access `foo`'s own namespace, so its exactly same name as globals()['var'] of `foo`. -- With best regards, Daniel Kluev From clp2 at rebertia.com Tue May 3 12:57:53 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 3 May 2011 09:57:53 -0700 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: On Tue, May 3, 2011 at 9:31 AM, Dun Peal wrote: > Hi! > > Here's the demonstrating code: > > ? ?# module foo.py > ? ?var = 0 > > ? ?def set(): > ? ? ? ?global var > ? ? ? ?var = 1 > > Script using this module: > > ? ?import foo > ? ?from foo import * > > ? ?print var, foo.var > ? ?set() > ? ?print var, foo.var > > Script output: > > ? ?0 0 > ? ?0 1 > > Apparently, the `var` we imported from `foo` never got set, but > `foo.var` on the imported `foo` - did. Why? Because imports (and assignments generally) bind names to values, they don't alias names to other names. from foo import * can be thought of as essentially doing: import foo set = foo.set var = foo.var del foo So the new, separate name __main__.var gets the current value of foo.var at import-time, which is the integer 0. You then call foo.set(), which re-binds foo.var to a new value (i.e. 1) rather than mutating the existing value (which would be impossible anyway since integers are immutable). This has absolutely no effect on __main__.var, which is an entirely separate binding. The behavior is comparable to that of function arguments. Values can be mutated, but re-binding names has only local effect: >>> a = 0 >>> def incr(b): ... b = 1 # rebinds local name b ... >>> incr(a) >>> a # outside name unaffected, just like in your example 0 >>> c = [7] >>> def mutate_then_rebind(b): ... b.append(99) # mutates passed-in value ... b = [42] # rebinds local name; has no outside effect ... >>> mutate_then_rebind(c) >>> c # name still references same obj, but that obj has been mutated [7, 99] Cheers, Chris -- http://rebertia.com From mwilson at the-wire.com Tue May 3 13:00:28 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 03 May 2011 13:00:28 -0400 Subject: Why do directly imported variables behave differently than those attached to imported module? References: Message-ID: Dun Peal wrote: > Hi! > > Here's the demonstrating code: > > # module foo.py > var = 0 > > def set(): > global var > var = 1 > > Script using this module: > > import foo > from foo import * > > print var, foo.var > set() > print var, foo.var > > Script output: > > 0 0 > 0 1 > > Apparently, the `var` we imported from `foo` never got set, but > `foo.var` on the imported `foo` - did. Why? They're different because -- they're different. `foo.var` is defined in the namespace of the foo module. Introspectively, you would access it as `foo.__dict__['var']` . Plain `var` is in your script's namespace so you could access it as `globals()['var']` . The values given to the vars are immutable integers, so assignment works by rebinding. The two different bindings in foo.__dict__ and globals() get bound to different integer objects. Note too the possible use of `globals()['foo'].__dict__['var'] . (Hope there are no typos in this post.) Mel. From harrismh777 at charter.net Tue May 3 13:10:04 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 03 May 2011 12:10:04 -0500 Subject: Fibonacci series recursion error In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: Chris Angelico wrote: > The recursion is in the last block. Note that it calls a function, > then keeps going. It doesn't fork. There are two CALL_FUNCTION > opcodes, called*sequentially*. In terms of the call stack, there is > only ever one of those two calls active at any given time. RuntimeError: maximum recursion depth exceeded in comparison [36355 refs] can any one help [ @ Ian, Chris, Thomas ] Thanks, guys, but I think y'all are still missing my point/question, as interesting as these discussions are... something is wrong (might be my understanding)... ... CPython must be making function calls by placing stack-frames on the call stack... which has a relatively small limit. Python does crappy tail optimization (one of the reasons to avoid recursion in Python) and yes, this is an infinite recursion... doh... but the main point for this part of the discussion is that the "maximum recursion depth exceeded in comparison" runtime error is posted because there are more stack-frames being posted to the call stack than there is call-stack to hold them! We might change this with sys.setrecursionlimit, but that's dangerous; but the bottom line is that in order for the recursion depth runtime error to be posted, somebody placed too many stack-frames on the call stack... in this case about 36,355 of them... yes, the base-case is coded wrong and the process is infinite, the point is that tail processing doesn't even get to run... the silly thing pummels the call stack with stack-frames (obviously exceeding 20) and the runtime error is posted. If your point is that the infinite process is the problem, I agree. But my point is that the cpu crunch and the rate at which the call stack is filled has to do with the double call (which never finds tail processing). What am I missing here>? From robert.kern at gmail.com Tue May 3 13:10:23 2011 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 May 2011 12:10:23 -0500 Subject: Pickling extension types In-Reply-To: References: Message-ID: On 5/3/11 11:48 AM, Stefan Kuzminski wrote: > Hi all, > > I have an extension type written in C, but I cannot get it to pickle, any > insights would be greatly appreciated. > > I see in the docs that I should define a __reduce__ method and that does get > called, but I don't know specifically the type of the 'callable object' that > should be the first thing in the tuple returned by __reduce__. It should be a callable PyObject* that takes the arguments given in the rest of the tuple. Often, this is just the type itself. So probably (PyObject*)PyMV_Type, if you give the right arguments in the rest of the tuple. -- 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 Tue May 3 13:13:12 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 May 2011 13:13:12 -0400 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: Your problem is reveal in the subject line. As discussed in many other threads, including a current one, Python does not have 'variables' in the way that many understand the term. Python binds names to objects. Binding statements (assignment, augmented assignment, import, def, class, and others with 'as' clauses) all bind names to objects. Suppose we both have address books. You copy all entries from my book to yours. Afterwards, I update an entry in my book. That does not change the now obsolete entry in your book. On 5/3/2011 12:31 PM, Dun Peal wrote: > # module foo.py > var = 0 > > def set(): > global var > var = 1 Module foo's dict now has two entries for 'var' and 'set' bound to int 0 and a function. Note that 'set' is a builtin class name so not the best choice. > > Script using this module: Script creates module '__main__' > import foo This binds 'foo' to module foo in __main_'s dict. > from foo import * This copies foo's dict to __main__'s dict. > print var, foo.var > set() This changes foo's dict, rebinding 'var' to int 1. It does not change __main__'s dict. How could it? In the same way, 'var = 2' would leave foo's dict unchanged. __main__.var. > print var, foo.var > > Script output: > > 0 0 > 0 1 If instead of 'from foo import *', you had written 'from foo import var as rav', then perhaps you would not have been so surprised that __main__.rav and foo.var have independent fates. You have discovered that using from x import * is a bad idea when module x has global names that get rebound. -- Terry Jan Reedy From harrismh777 at charter.net Tue May 3 13:24:43 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 03 May 2011 12:24:43 -0500 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: Dun Peal wrote: > # module foo.py > var = 0 > > def set(): > global var > var = 1 My two cents to add in addition to the correct accounts of [ Daniel, Chris, Mel] is that you might have a misunderstanding of var, generally. Python has no variables--- in the way you think of them in other languages. Python only has references. Var is not 'set' in the classical sense of the word... var is a 'reference' (think C pointer, sort-of) to an object... '0' and '1' are objects of type int and var=0 means create a reference to object int('0') called var. a=b=0 a is a reference to object '0' b is a reference to object '0' a does not reference b This rest of the discussion has to do with name spaces: See: http://docs.python.org/release/3.0.1/reference/datamodel.html?highlight=namespaces From nicolabranzolihc at gmail.com Tue May 3 13:33:39 2011 From: nicolabranzolihc at gmail.com (Nicola Branzoli) Date: Tue, 3 May 2011 10:33:39 -0700 (PDT) Subject: Python to accept terms and conditions of a website Message-ID: <1ce933c0-57be-44b0-884a-e20e1dae5773@d26g2000prn.googlegroups.com> Hey, I am writing a code in python to access public data online (using BeautifulSoup). The task is relatively easy but the code does not get to the page because I need to accept the terms and condition of the website first (by a standard click 'Accept' button). I need to tell python how to automatically accept the terms and condition and proceed to the web address specified. I am new in pyhton, my guess is that I have to use mechanize because cookielib is not good for this job. Am I right? What other resources can I use? Any link with an example similar to my problem would be super-duper... n From __peter__ at web.de Tue May 3 13:39:27 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 May 2011 19:39:27 +0200 Subject: Pickling extension types References: Message-ID: Stefan Kuzminski wrote: > I have an extension type written in C, but I cannot get it to pickle, any > insights would be greatly appreciated. > > I see in the docs that I should define a __reduce__ method and that does > get called, but I don't know specifically the type of the 'callable > object' that should be the first thing in the tuple returned by > __reduce__. I haven't written a python extension in C, but I would approach the problem by looking for prior art in the stdlib, preferably a simple class: >>> 1j.__reduce__() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/copy_reg.py", line 70, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle complex objects OK, complex does something else... * One grep through the source later: >>> slice(1,2,3).__reduce__() (, (1, 2, 3)) And the implementation seems straightforward: static PyObject * slice_reduce(PySliceObject* self) { return Py_BuildValue("O(OOO)", Py_TYPE(self), self->start, self->stop, self->step); } (*) it uses __getnewargs__ From as at sci.fi Tue May 3 14:19:06 2011 From: as at sci.fi (Anssi Saari) Date: Tue, 03 May 2011 21:19:06 +0300 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> Message-ID: rusi writes: > I am a bit surprised that no one has mentioned rcs so far > Not an option if you are not on a *ix system and not something I am > specifically recommending. I actually use rcs in Windows. Needs a little setup, but works great, from Emacs VC-mode too. From jacek2v at gmail.com Tue May 3 14:31:12 2011 From: jacek2v at gmail.com (jacek2v) Date: Tue, 3 May 2011 11:31:12 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <3a93d484-ca0a-41d9-afdb-509cfdcc918b@e21g2000yqe.googlegroups.com> Message-ID: <6f503249-5f94-4e1b-a966-5e0f2b6e32e6@a18g2000yqj.googlegroups.com> On May 2, 12:38?pm, Algis Kabaila wrote: > On Monday 02 May 2011 19:09:38 jacek2v wrote: > > > > > > > > > > > On May 2, 9:48 am, Algis Kabaila wrote: > > > On Monday 02 May 2011 17:19:57 rusi wrote: > > > > On May 2, 12:08 pm, Algis Kabaila > > > > wrote: > > > > > Actually, Bazaar is more convenient than rcs for a > > > > > single user, as the repository can be the working > > > > > directory (with a "hidden" .bzr directory that stores > > > > > diffs). > > > > > Dont exactly understand... > > > > Is it that you want it specifically hidden? > > > > Otherwise rcs will look inside an RCS directory just as > > > > bzr will with .bzr git will with .git and so on. > > > > Sorry for not being clear - "ls" will not show directories > > > that start with "." - in that sense these directories are > > > "hidden". They are not really really hidden, as "ls ?-l" > > > will show them. They simply are not in the way and keep > > > the progressive versions of the program (in form of > > > diffs). > > > "ls -l will not show directories that start with ".". > > "ls -a" will. > > > Regards > > Jacek > > Thanks - you are right - pardon my absent mindedness. > > -- > Algishttp://akabaila.pcug.org.au/StructuralAnalysis.pdf You're welcome :) From rustompmody at gmail.com Tue May 3 14:50:38 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 3 May 2011 11:50:38 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> Message-ID: On May 3, 11:19?pm, Anssi Saari wrote: > rusi writes: > > I am a bit surprised that no one has mentioned rcs so far > > Not an option if you are not on a *ix system and not something I am > > specifically recommending. > > I actually use rcs in Windows. Needs a little setup, but works great, > from Emacs VC-mode too. Where do you get it? [What google is showing seems to be about 10-15 years old] From dunpealer at gmail.com Tue May 3 14:51:03 2011 From: dunpealer at gmail.com (Dun Peal) Date: Tue, 3 May 2011 11:51:03 -0700 (PDT) Subject: Why do directly imported variables behave differently than those attached to imported module? References: Message-ID: OK, I understand now. `from foo import var` means "create a module-global name `var` inside the current module, and have it point at the object `foo.var` is pointing at (following its evaluation)". Naturally, regardless of whether `foo.var` ever changes, the global `var` of the current module still points at the original object `foo.var` was pointing to at the time of the `var = foo.var` assignment. Thanks, D. From roman.suzi at gmail.com Tue May 3 15:15:16 2011 From: roman.suzi at gmail.com (rnd) Date: Tue, 3 May 2011 12:15:16 -0700 (PDT) Subject: Pushing for Pythoncard 1.0 References: <6d896b66-3933-4743-8eb5-b9754f1ec14f@t19g2000prd.googlegroups.com> Message-ID: <5348cf4b-ffd2-41f0-a7a5-afedc00ed703@b35g2000yqn.googlegroups.com> On May 2, 10:48?pm, John Henry wrote: > Attempt to push Pythoncard to a 1.0 status is now underway. ?A > temporary website has been created at: > > http://code.google.com/p/pythoncard-1-0/ > > The official website continues to behttp://pythoncard.sourceforge.net/ > > Pythoncard is such a wonderful package that it would be a shame to > allow development for the package to go stagnant. ? The Python > community deserves to continue enjoying the simplicity of Pythoncard > for creating a GUI Python application. I was very positively surprised to hear someone talking about PythonCard these days. Even though I've not needed to develop GUI apps for years, I believe its still great idea to revive PythonCard even though everybody is busy developing for "iThings" right now. Regards, Roman Suzi From dunpealer at gmail.com Tue May 3 15:23:15 2011 From: dunpealer at gmail.com (Dun Peal) Date: Tue, 3 May 2011 12:23:15 -0700 (PDT) Subject: Why do directly imported variables behave differently than those attached to imported module? References: Message-ID: <5299438d-611f-4a63-b1d8-4abe039ad5d4@k3g2000prl.googlegroups.com> P.S. now I have to ask: is there a symbolic reference in Python, i.e. a name foo that points to "whatever bar.baz is pointing at"? Thanks, D. From zdoor at xs4all.nl Tue May 3 15:50:31 2011 From: zdoor at xs4all.nl (Alex van der Spek) Date: Tue, 3 May 2011 21:50:31 +0200 Subject: Appending to dictionary of lists Message-ID: <4dc05c8b$0$41117$e4fe514c@news.xs4all.nl> I open a csv file and create a DictReader object. Subsequently, reading lines from this file I try to update a dictionary of lists: csvf=open(os.path.join(root,fcsv),'rb') csvr=csv.DictReader(csvf) refd=dict.fromkeys(csvr.fieldnames,[]) for row in csvr: for (k,v) in row.items(): refd[k].append(v) I do not understand why this appends v to every key k each time. Thanks in advance for any tips you can pass on. Alex van der Spek From dan.kluev at gmail.com Tue May 3 15:55:04 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Wed, 4 May 2011 06:55:04 +1100 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: <5299438d-611f-4a63-b1d8-4abe039ad5d4@k3g2000prl.googlegroups.com> References: <5299438d-611f-4a63-b1d8-4abe039ad5d4@k3g2000prl.googlegroups.com> Message-ID: On Wed, May 4, 2011 at 6:23 AM, Dun Peal wrote: > P.S. now I have to ask: is there a symbolic reference in Python, i.e. > a name foo that points to "whatever bar.baz is pointing at"? Well, you could easily simulate that with proxy object, class SymbolicReference(object): def __init__(self, ns, name): self.__ns = ns self.__name = name def __get(self): return self.__ns[self.__name] def __getattribute__(self, attr): try: return object.__getattribute__(self, attr) except: return self.__get().__getattribute__(attr) def __repr__(self): return self.__get().__repr__() def __str__(self): return self.__get().__str__() >>> a = 1 >>> b = SymbolicReference(globals(), 'a') >>> b 1 >>> a = 10 >>> b 10 -- With best regards, Daniel Kluev From no.email at nospam.invalid Tue May 3 15:56:44 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 03 May 2011 12:56:44 -0700 Subject: Appending to dictionary of lists References: <4dc05c8b$0$41117$e4fe514c@news.xs4all.nl> Message-ID: <7x7ha75zib.fsf@ruckus.brouhaha.com> "Alex van der Spek" writes: > refd=dict.fromkeys(csvr.fieldnames,[]) ... > I do not understand why this appends v to every key k each time. You have initialized every element of refd to the same list. Try refd = dict((k,[]) for k in csvr.fieldnames) instead. From drsalists at gmail.com Tue May 3 16:16:09 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 3 May 2011 13:16:09 -0700 Subject: Appending to dictionary of lists In-Reply-To: <7x7ha75zib.fsf@ruckus.brouhaha.com> References: <4dc05c8b$0$41117$e4fe514c@news.xs4all.nl> <7x7ha75zib.fsf@ruckus.brouhaha.com> Message-ID: On Tue, May 3, 2011 at 12:56 PM, Paul Rubin wrote: > "Alex van der Spek" writes: > > refd=dict.fromkeys(csvr.fieldnames,[]) ... > > I do not understand why this appends v to every key k each time. > > You have initialized every element of refd to the same list. Try > > refd = dict((k,[]) for k in csvr.fieldnames) > > instead. > -- > http://mail.python.org/mailman/listinfo/python-list > Agreed. Here's another way: using a dictionary comprehension - a feature in 2.7 and up: #!/usr/local/cpython-2.7/bin/python import csv import pprint csvf=open('foo.csv','rb') csvr=csv.DictReader(csvf) #refd=dict.fromkeys(csvr.fieldnames, []) refd = { key: [] for key in csvr.fieldnames } for row in csvr: for (k,v) in row.items(): refd[k].append(v) pprint.pprint(refd) -------------- next part -------------- An HTML attachment was scrubbed... URL: From zdoor at xs4all.nl Tue May 3 16:20:00 2011 From: zdoor at xs4all.nl (Alex van der Spek) Date: Tue, 3 May 2011 22:20:00 +0200 Subject: Appending to dictionary of lists In-Reply-To: <7x7ha75zib.fsf@ruckus.brouhaha.com> References: <4dc05c8b$0$41117$e4fe514c@news.xs4all.nl> <7x7ha75zib.fsf@ruckus.brouhaha.com> Message-ID: <4dc06377$0$41110$e4fe514c@news.xs4all.nl> Thank you! Would never have found that by myself. "Paul Rubin" wrote in message news:7x7ha75zib.fsf at ruckus.brouhaha.com... > "Alex van der Spek" writes: >> refd=dict.fromkeys(csvr.fieldnames,[]) ... >> I do not understand why this appends v to every key k each time. > > You have initialized every element of refd to the same list. Try > > refd = dict((k,[]) for k in csvr.fieldnames) > > instead. From hg at schaathun.net Tue May 3 16:47:04 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 3 May 2011 21:47:04 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <876698-vjj.ln1@svn.schaathun.net> On Tue, 03 May 2011 12:33:15 -0400, Mel wrote: : mwilson at tecumseth:~$ python : 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. : >>> def identify_call (a_list): : ... a_list[0] = "If you can see this, you don't have call-by-value" : ... a_list = ["If you can see this, you have call-by-reference"] : ... : >>> my_list = [None] : >>> identify_call (my_list) : >>> my_list : ["If you can see this, you don't have call-by-value"] This looks like plain old transmission by reference to me. I.e. the functions get a reference to an object and make any change to the object. Since the caller and the callee refer to the same object, changes made by the callee are seen by the caller. However, the reference cannot be changed. With transmission by name, you would get what you call call-by-reference; i.e. the variable passed as an argument is changed to refer to a completely new object. In simula this is used for output parameters. And transmission by value is of course a copy of the data. : so it's neither call-by-value nor call-by-reference as (e.g.) C or PL/I I don't know PL/I; that's the sort of thing my mother deals with. Simula explicitely offerts all three. In C you can get each of the three, by using pointers explicitely in different ways. Whether you use C or Simula, transmission by reference, that is what python appears to be doing, seems to be the normal approach for any composite data type. Thus python does not seem to do anything out of the ordinary at all. -- :-- Hans Georg From hg at schaathun.net Tue May 3 17:10:52 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 3 May 2011 22:10:52 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc01d4a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03 May 2011 15:20:42 GMT, Steven D'Aprano wrote: : You get credit for not falling into the trap of thinking there are only : two, call by reference and call by value, but there are *many* more than : just three. Wikipedia lists at least 13: Ah. Those 13 approaches aren't all mutually exclusive though. -- :-- Hans Georg From stefan.kuzminski at gmail.com Tue May 3 17:34:06 2011 From: stefan.kuzminski at gmail.com (Stefan Kuzminski) Date: Tue, 3 May 2011 17:34:06 -0400 Subject: Pickling extension types Message-ID: Thanks for the clues, I made a modification so that reduce returns this.. return Py_BuildValue("O(OOOOO)", Py_TYPE(self), PyTuple_New(0), Py_None, Py_None, Py_None ); and now I get this different error when trying to pickle the type.. ---------------------------------------------------------------------- Traceback (most recent call last): File "test_missing.py", line 16, in test print cPickle.dumps( mv ) PicklingError: Can't pickle : attribute lookup __builtin__.MV failed thx, S One grep through the source later: > > >>> slice(1,2,3).__reduce__() > (, (1, 2, 3)) > > And the implementation seems straightforward: > > static PyObject * > slice_reduce(PySliceObject* self) > { > return Py_BuildValue("O(OOO)", Py_TYPE(self), self->start, self->stop, > self->step); > } > > > > (*) it uses __getnewargs__ > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 3 17:41:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 07:41:32 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Wed, May 4, 2011 at 3:10 AM, harrismh777 wrote: > If your point is that the infinite process is the problem, I agree. But my > point is that the cpu crunch and the rate at which the call stack is filled > has to do with the double call (which never finds tail processing). The double call _does not_ affect it. Failing to terminate recursion _does_. I don't know what you mean by "cpu crunch" but the call stack is going to get n entries. On the Python 2.6 on this system, sys.getrecursionlimit() returns 1000, meaning that you can calculate fib(1000) safely (okay, probably not quite as there'll be a few used for other things, but fib(900) would be safe). Chris Angelico From rosuav at gmail.com Tue May 3 17:47:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 07:47:17 +1000 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 2:57 AM, Chris Rebert wrote: > from foo import * > > can be thought of as essentially doing: > > import foo > set = foo.set > var = foo.var > del foo Here's a side point. What types will hold a reference to the enclosing module (or at least its dictionary)? Would it be possible to use a from import to load a module, then "lose" the module even though you're using objects from it? I am guessing that a function or class will hold such a reference, because otherwise it would be a bit awkward for them to use any sort of module-level state. Or do they not, and instead go look for their module in sys.modules? Chris Angelico From rosuav at gmail.com Tue May 3 17:54:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 07:54:12 +1000 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On Wed, May 4, 2011 at 2:43 AM, Raymond Hettinger wrote: > We should have a separate thread for the most practical, best > documented, least surprising, and most boring recipe ;-) a += b # Adds b to a in-place. Polymorphic - works on a wide variety of types. You didn't say it had to be complicated... Chris Angelico From rosuav at gmail.com Tue May 3 18:00:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 08:00:35 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <876698-vjj.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <876698-vjj.ln1@svn.schaathun.net> Message-ID: On Wed, May 4, 2011 at 6:47 AM, Hans Georg Schaathun wrote: > This looks like plain old transmission by reference to me. > I.e. the functions get a reference to an object and make any > change to the object. "Reference" being exactly what's passed around. There are now two references to that object. Since names always contain references (not objects), it's very easy to share mutable objects (lists/dictionaries/etc). There's an easy way for a caller or callee to guarantee that a mutable is safe - just slice it: identify_call(my_list[:]) That gives the called function a shallow copy of the list, which it can modify to its heart's content, but the original list isn't changed. Callee can do the same, with an assignment command at the top of the function (a_list=a_list[:]). Chris Angelico From robert.kern at gmail.com Tue May 3 18:05:23 2011 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 May 2011 17:05:23 -0500 Subject: Pickling extension types In-Reply-To: References: Message-ID: On 5/3/11 4:34 PM, Stefan Kuzminski wrote: > Thanks for the clues, I made a modification so that reduce returns this.. > > return Py_BuildValue("O(OOOOO)", Py_TYPE(self), PyTuple_New(0), Py_None, > Py_None, Py_None ); > > and now I get this different error when trying to pickle the type.. > > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "test_missing.py", line 16, in test > print cPickle.dumps( mv ) > PicklingError: Can't pickle : attribute lookup __builtin__.MV failed You need to do two things: 1. Set tp_name to something like "mymodule.MV" where "mymodule" is the name of your extension module. 2. Make sure that you add the type object to your module's namespace. PyMODINIT_FUNC initmymodule(void) { ... Py_INCREF(&PyMV_Type); PyModule_AddObject(m, "MV", (PyObject*)&PyMV_Type); } C.f. http://docs.python.org/extending/newtypes.html -- 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 jabba.laci at gmail.com Tue May 3 18:08:27 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 3 May 2011 18:08:27 -0400 Subject: vertical ordering of functions Message-ID: Hi, I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. 5 he says that a function that is called should be below a function that does the calling. This creates a nice flow down from top to bottom. However, when I write a Python script I do just the opposite. I start with the lines if __name__ == "__main__": main() Then I add main() above, which is a control function that contains some function calls that decompose the problem into subproblems. Then I add these functions above, etc. Is there a convention for this? Should main() be at the top and called function below? Thanks, Laszlo From ian.g.kelly at gmail.com Tue May 3 18:10:42 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 May 2011 16:10:42 -0600 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On Tue, May 3, 2011 at 3:54 PM, Chris Angelico wrote: > On Wed, May 4, 2011 at 2:43 AM, Raymond Hettinger wrote: >> We should have a separate thread for the most practical, best >> documented, least surprising, and most boring recipe ;-) > > a += b ? # Adds b to a in-place. Polymorphic - works on a wide variety of types. Too surprising to qualify. For some types it modifies a, while for others it replaces a. From clp2 at rebertia.com Tue May 3 18:11:48 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 3 May 2011 15:11:48 -0700 Subject: Why do directly imported variables behave differently than those attached to imported module? In-Reply-To: References: Message-ID: On Tue, May 3, 2011 at 2:47 PM, Chris Angelico wrote: > On Wed, May 4, 2011 at 2:57 AM, Chris Rebert wrote: >> from foo import * >> >> can be thought of as essentially doing: >> >> import foo >> set = foo.set >> var = foo.var >> del foo > > Here's a side point. What types will hold a reference to the enclosing > module (or at least its dictionary)? Would it be possible to use a > from import to load a module, then "lose" the module even though > you're using objects from it? > > I am guessing that a function or class will hold such a reference, > because otherwise it would be a bit awkward for them to use any sort > of module-level state. Or do they not, and instead go look for their > module in sys.modules? some_python_function.__globals__ is the exact reference you postulated. Classes don't seem to hold such references; their methods do though (by virtue of being function objects), which makes sense. Cheers, Chris -- http://rebertia.com From python at rcn.com Tue May 3 18:19:25 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 3 May 2011 15:19:25 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <018ur6da31iv7us9gm4dpgl7tfl0i6snb2@4ax.com> Message-ID: On May 2, 11:23?pm, Stefan Behnel wrote: > Terry Reedy, 03.05.2011 08:00: > > > On 5/3/2011 1:04 AM, Stefan Behnel wrote: > > >> The bad thing about this recipe is that it requires quite a bit of > >> background knowledge in order to infer that the code the developer is > >> looking at is actually correct. > > > The main math knowledge needed is the trivial fact that if a*x + b = 0, > > then x = -b/a. The other math knowledge needed is that complex numbers add > > componentwise. The trick is that replacing x with j and evaluating > > therefore causes (in Python) all the coefficients of x (now j) to be added > > together separately from all the constant terms to reduce the linear > > equation to a*x+b (= 0 implied). > > As your above paragraph proves, it's the kind of implementation that > requires three lines of executing code and at least 6 lines of additional > comment. Hopefully accompanied by an excuse of the developer. If you found nothing educational, interesting, or amusing about the three-line linear equation solver, then you're *really* going to hate this one: http://groups.google.com/group/comp.lang.python/browse_frm/thread/e46de4596e93188b/ Raymond @raymondh From rosuav at gmail.com Tue May 3 18:31:18 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 08:31:18 +1000 Subject: vertical ordering of functions In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 8:08 AM, Jabba Laci wrote: > Hi, > > I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. > 5 he says that a function that is called should be below a function > that does the calling. This creates a nice flow down from top to > bottom. I prefer to define my terms before I use them. Classes, functions, etc get defined at the top and called down below. It's a stylistic thing, but it ties in with what you would do in a debate or scholarly document; and if you're skimming such a document and you don't understand a term, you know to scan upwards for its definition. It's just a stylistic thing, you can do it whichever way you think best! Chris Angelico From ian.g.kelly at gmail.com Tue May 3 18:31:29 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 May 2011 16:31:29 -0600 Subject: Fibonacci series recursion error In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Tue, May 3, 2011 at 3:41 PM, Chris Angelico wrote: > On Wed, May 4, 2011 at 3:10 AM, harrismh777 wrote: >> If your point is that the infinite process is the problem, I agree. But my >> point is that the cpu crunch and the rate at which the call stack is filled >> has to do with the double call (which never finds tail processing). > > The double call _does not_ affect it. Failing to terminate recursion > _does_. I don't know what you mean by "cpu crunch" but the call stack > is going to get n entries. On the Python 2.6 on this system, > sys.getrecursionlimit() returns 1000, meaning that you can calculate > fib(1000) safely (okay, probably not quite as there'll be a few used > for other things, but fib(900) would be safe). Depends what you mean by "safe". A back-of-the-envelope calculation shows that with modern technology it would take more than 10 ** 257 years to complete. That puts it well into the Dark Era of the universe, long after the black holes will have decayed, when I suspect it will be difficult to find a continued power source for the computer to run. And even if it somehow is still running, the process memory will have been so thoroughly muddled by cosmic rays that the final result of the calculation will be utterly worthless. From python at mrabarnett.plus.com Tue May 3 18:46:59 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 03 May 2011 23:46:59 +0100 Subject: vertical ordering of functions In-Reply-To: References: Message-ID: <4DC085E3.8000807@mrabarnett.plus.com> On 03/05/2011 23:31, Chris Angelico wrote: > On Wed, May 4, 2011 at 8:08 AM, Jabba Laci wrote: >> Hi, >> >> I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. >> 5 he says that a function that is called should be below a function >> that does the calling. This creates a nice flow down from top to >> bottom. > > I prefer to define my terms before I use them. Classes, functions, etc > get defined at the top and called down below. It's a stylistic thing, > but it ties in with what you would do in a debate or scholarly > document; and if you're skimming such a document and you don't > understand a term, you know to scan upwards for its definition. > > It's just a stylistic thing, you can do it whichever way you think best! > You also need to remember that in Python, function and class definitions are _not_ declarations, but statements which have the effect of adding a name to the namespace. If you try to call a function before the flow of control has seen the function definition, you'll get a NameError. From rosuav at gmail.com Tue May 3 19:09:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 09:09:24 +1000 Subject: Fibonacci series recursion error In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> Message-ID: On Wed, May 4, 2011 at 8:31 AM, Ian Kelly wrote: > A back-of-the-envelope calculation > shows that with modern technology it would take more than 10 ** 257 > years to complete. Then I propose that Python be extended to allow for underlying hardware upgrades without terminating a script. This will be essential to the finding of answers to these vital questions. Chris Angelico From akabaila at pcug.org.au Tue May 3 19:25:57 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Wed, 4 May 2011 09:25:57 +1000 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: <201105040925.57912.akabaila@pcug.org.au> On Tuesday 03 May 2011 16:00:05 Terry Reedy wrote: > On 5/3/2011 1:04 AM, Stefan Behnel wrote: > > The bad thing about this recipe is that it requires quite a > > bit of background knowledge in order to infer that the > > code the developer is looking at is actually correct. > > The main math knowledge needed is the trivial fact that if > a*x + b = 0, then x = -b/a. The other math knowledge needed > is that complex numbers add componentwise. The trick is that > replacing x with j and evaluating therefore causes (in > Python) all the coefficients of x (now j) to be added > together separately from all the constant terms to reduce > the linear equation to a*x+b (= 0 implied). But the title of the project is wrong and misleading. In the description it says "linear equations solver" which suggests that it solves systems of linear equations - linalg. As has been pointed out, a "linear" equation can be solved by had in one line... OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Tue May 3 19:58:45 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 May 2011 09:58:45 +1000 Subject: vertical ordering of functions References: Message-ID: <87sjsvfia2.fsf@benfinney.id.au> Jabba Laci writes: > Is there a convention for this? Should main() be at the top and called > function below? No, it's Python convention for both of those to be at the end of the module. I follow the convention described by Guido van Rossum in . Essentially, the mainline code is all in a top-level function, which accepts command-line arguments in its ?argv? parameter, catches any ?SystemExit? exception, and returns the exit code for the program. The ?if __name__ == "__main__"? section does nothing but call that function, passing the ?sys.argv? value, then exit with the return value. This makes the whole behaviour of the program available for calling as a function, while the program works as expected when invoked as a program. Commonly I will name the function ?__main__?, but this is an artefact of my previously-held vain hope that this idiom would become special to Python and called automatically without the ?if __name__ ?? hack. Guido, and most others I've seen use this idiom, simply name the function ?main?. -- \ ?An idea isn't responsible for the people who believe in it.? | `\ ?Donald Robert Perry Marquis | _o__) | Ben Finney From robert.kern at gmail.com Tue May 3 20:17:49 2011 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 May 2011 19:17:49 -0500 Subject: vertical ordering of functions In-Reply-To: <4DC085E3.8000807@mrabarnett.plus.com> References: <4DC085E3.8000807@mrabarnett.plus.com> Message-ID: On 5/3/11 5:46 PM, MRAB wrote: > On 03/05/2011 23:31, Chris Angelico wrote: >> On Wed, May 4, 2011 at 8:08 AM, Jabba Laci wrote: >>> Hi, >>> >>> I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. >>> 5 he says that a function that is called should be below a function >>> that does the calling. This creates a nice flow down from top to >>> bottom. >> >> I prefer to define my terms before I use them. Classes, functions, etc >> get defined at the top and called down below. It's a stylistic thing, >> but it ties in with what you would do in a debate or scholarly >> document; and if you're skimming such a document and you don't >> understand a term, you know to scan upwards for its definition. >> >> It's just a stylistic thing, you can do it whichever way you think best! >> > You also need to remember that in Python, function and class > definitions are _not_ declarations, but statements which have the > effect of adding a name to the namespace. > > If you try to call a function before the flow of control has seen the > function definition, you'll get a NameError. That's not really the issue at hand. The advice is about how to order the definition of functions that call each other, not interspersing function calls at the top level. I'm willing to bet that there is no solid empirical evidence that one ordering would be preferred to another. I am further willing to bet that should any such study be done, the average effect would be much smaller than personal variation (while it may be statistically significant, it won't be clinically significant). My third bet would be that picking any consistent style would have a larger effect over a random arrangement than either one consistent style over the other, and that this effect would be significant in both the statistical and clinical senses. -- 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 Catherine.M.Moroney at jpl.nasa.gov Tue May 3 20:18:33 2011 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Tue, 03 May 2011 17:18:33 -0700 Subject: importing class objects from a pickled file Message-ID: Hello, I have an object of class X that I am writing to a pickled file. The pickling part goes fine, but I am having some problems reading the object back out, as I get complaints about "unable to import module X". The only way I have found around it is to run the read-file code out of the same directory that contains the X.py file, but this is obviously not a portable way of doing things. Even when I put statements into the code such as "from Y.X import X" where Y is the name of the python package that contains the X,py file, the import statement works, but I am still unable to read the object from the pickled file, running into the same "unable to import module X" error. Am I explaining myself properly? Why doesn't the code that loads the object from the pickled file work unless I am sitting in the same directory? The code that writes the pickled file has the statement "from Y.X import X" statement" at the top, as does the reading code, but even though that import statement succeeds, the read still fails with the import error. Thanks for any help, Catherine From roy at panix.com Tue May 3 20:27:38 2011 From: roy at panix.com (Roy Smith) Date: Tue, 03 May 2011 20:27:38 -0400 Subject: vertical ordering of functions References: Message-ID: In article , Jabba Laci wrote: > I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. > 5 he says that a function that is called should be below a function > that does the calling. This creates a nice flow down from top to > bottom. There may have been some logic to this when people read programs on stacks of green-bar or rolls of teletype paper. These days, we have better tools. When I'm reading some code and see a function call I want to explore, I search for the function name in my text editor. People who use an IDE can probably just click on the function name. In either case, the tool takes me where I need to go. I'm generally completely unaware whether it's taken be forward or backward in the file. From john at castleamber.com Tue May 3 20:44:41 2011 From: john at castleamber.com (John Bokma) Date: Tue, 03 May 2011 19:44:41 -0500 Subject: vertical ordering of functions References: <87sjsvfia2.fsf@benfinney.id.au> Message-ID: <87d3jzgupy.fsf@castleamber.com> Ben Finney writes: > Jabba Laci writes: > >> Is there a convention for this? Should main() be at the top and called >> function below? > > No, it's Python convention for both of those to be at the end of the > module. > > I follow the convention described by Guido van Rossum in > . Thanks Ben, very useful link. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From astan.chee at gmail.com Tue May 3 20:45:31 2011 From: astan.chee at gmail.com (Astan Chee) Date: Wed, 4 May 2011 10:45:31 +1000 Subject: Running and killing a process in python Message-ID: Hi, I'm trying to make a python script (in windows 7 x64 using python 2.5) to start a process, and kill it after x minutes/seconds and kill all the descendants of it. Whats the best way of doing this in python? which module is best suited to do this? subprocess? thanks for any help -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue May 3 21:09:39 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 01:09:39 +0000 (UTC) Subject: vertical ordering of functions References: Message-ID: On 2011-05-03, Jabba Laci wrote: > I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. > 5 he says that a function that is called should be below a function > that does the calling. This creates a nice flow down from top to > bottom. I generally expect the opposite: callees above, callers below, main at the bottom. However, that's mostly just a habit left over from C programming where such an ordering avoids having to litter the file with forward declarations for functions. -- Grant From stefan.kuzminski at gmail.com Tue May 3 22:28:51 2011 From: stefan.kuzminski at gmail.com (Stefan Kuzminski) Date: Tue, 3 May 2011 22:28:51 -0400 Subject: Pickling extension types In-Reply-To: References: Message-ID: closer I think 1) I changed tp_name to be 'observation.MV' ( module is named observation.c ) and now I get a new error.. PicklingError: Can't pickle : import of module observation failed 2) here is the init function, sorry I did not include it in the original listing void initobservation(void) { PyObject *m; m = Py_InitModule("observation", observation_methods); Py_INCREF(&PyMV_Type); PyModule_AddObject(m, "MV", (PyObject *)&PyMV_Type); } thx, S On Tue, May 3, 2011 at 6:05 PM, Robert Kern wrote: > On 5/3/11 4:34 PM, Stefan Kuzminski wrote: > >> Thanks for the clues, I made a modification so that reduce returns this.. >> >> return Py_BuildValue("O(OOOOO)", Py_TYPE(self), PyTuple_New(0), Py_None, >> Py_None, Py_None ); >> >> and now I get this different error when trying to pickle the type.. >> >> ---------------------------------------------------------------------- >> Traceback (most recent call last): >> File "test_missing.py", line 16, in test >> print cPickle.dumps( mv ) >> PicklingError: Can't pickle : attribute lookup __builtin__.MV >> failed >> > > You need to do two things: > > 1. Set tp_name to something like "mymodule.MV" where "mymodule" is the name > of your extension module. > > 2. Make sure that you add the type object to your module's namespace. > > PyMODINIT_FUNC > initmymodule(void) { > ... > Py_INCREF(&PyMV_Type); > PyModule_AddObject(m, "MV", (PyObject*)&PyMV_Type); > } > > C.f. > > http://docs.python.org/extending/newtypes.html > > -- > 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 > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Tue May 3 22:29:53 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 4 May 2011 12:29:53 +1000 Subject: importing class objects from a pickled file In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 10:18 AM, Catherine Moroney wrote: > Am I explaining myself properly? ?Why doesn't the code that loads the > object from the pickled file work unless I am sitting in the same directory? > ? The code that writes the pickled file has the statement > "from Y.X import X" statement" at the top, as does the reading code, but > even though that import statement succeeds, the read still fails with the > import error. pickled objects won't work this way unless you "customize" the way in which your class gets serialized. See: http://docs.python.org/library/pickle.html#the-pickle-protocol Any time you want to unpickle a user class, that class must be available. I suggest serializing to a more common format (say JSON) and re-create your class with the data. cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Tue May 3 22:31:06 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 4 May 2011 12:31:06 +1000 Subject: Running and killing a process in python In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 10:45 AM, Astan Chee wrote: > Hi, > I'm trying to make a python script (in windows 7 x64 using python 2.5) to > start a process, and kill it after x minutes/seconds and kill all the > descendants of it. > Whats the best way of doing this in python? which module is best suited to > do this? subprocess? Yes start with the subprocess module: http://docs.python.org/library/subprocess.html cheers James -- -- James Mills -- -- "Problems are solved by method" From angrybaldguy at gmail.com Wed May 4 01:29:11 2011 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Wed, 4 May 2011 01:29:11 -0400 Subject: importing class objects from a pickled file References: Message-ID: <2011050401291149357-angrybaldguy@gmailcom> On 2011-05-03 20:18:33 -0400, Catherine Moroney said: > Hello, > > I have an object of class X that I am writing to a pickled file. The > pickling part goes fine, but I am having some problems reading the > object back out, as I get complaints about "unable to import module X". > > The only way I have found around it is to run the read-file code out of > the same directory that contains the X.py file, but this is obviously > not a portable way of doing things. > > Even when I put statements into the code such as "from Y.X import X" > where Y is the name of the python package that contains the X,py file, > the import statement works, but I am still unable to read the object > from the pickled file, running into the same "unable to import module X" > error. > > Am I explaining myself properly? Why doesn't the code that loads the > object from the pickled file work unless I am sitting in the same directory? That's not the actual requirement. The pickled representation of an instance of a user-defined class contains: * the name of the class * the name of the class's module * the object's attributes, pickled recursively You can have a look at the representation using protocol zero, which is printable and not terribly hard to read. Here's an example, lightly annotated: >>> import pickle >>> class Example(object): ... def __init__(self, x): ... self.x = x ... >>> one = Example(1) >>> print pickle.dumps(one, 0) ccopy_reg _reconstructor p0 module name (c__main__ class name Example p1 c__builtin__ object p2 Ntp3 Rp4 (dp5 field name S'x' p6 field value I1 sb. >>> Obviously, since the pickled representation only contains the *name and location* of the class and not the class itself, you need to have the definition of the class handy when unpickling an object. This means that the module that defines the class must be on the module search path - either because it's in the current directory (or a package in the current directory, or..), or because it's in PYTHONPATH, or because it's somewhere else on sys.path. > The code that writes the pickled file has the statement > "from Y.X import X" statement" at the top, as does the reading code, but > even though that import statement succeeds, the read still fails with > the import error. The unpickle code uses something morally equivalent to __import__ to convert the module name in the pickled data stream into a module object. The symbols defined in the module you called pickle.load from don't matter at all, just like any other function defined in a separate module. Pickle isn't meant for transmitting data between two unrelated programs. It's designed to be a low-development-effort way to preserve and restore objects for a single program or a group of related programs that share libraries. If you want to share data between unrelated programs, use something a little more interoperable - json, xml, or some other program-agnostic representation. -o (And if you were thinking of using pickle over the internet, forget it: the pickle encoding is a small stack-based programming language in its own right, and can be used to invoke semi-arbitrary module-scoped funtions.) From amit.paunikar at gmail.com Wed May 4 02:12:01 2011 From: amit.paunikar at gmail.com (DonAmit) Date: Tue, 3 May 2011 23:12:01 -0700 (PDT) Subject: dll errors in compiled python program In-Reply-To: <56def94c-f0d8-4aa2-b46d-be06138ab5b0@q36g2000prg.googlegroups.com> References: <56def94c-f0d8-4aa2-b46d-be06138ab5b0@q36g2000prg.googlegroups.com> Message-ID: <31538796.post@talk.nabble.com> You can do this easy by adding this to the options dict in setup.py 'dll_excludes': [ "mswsock.dll", "powrprof.dll" ] source: http://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failed -Amit alex23 wrote: > > Alex Hall wrote: >> I am stumped. The compiled version of my project works on my pc, but >> when I put it on a thumb drive and try it on a laptop without python >> installed I get this: >> ImportError: DLL load failed: The specified procedure could not be found. > > Are you using py2exe? If so, are you including the necessary MS > runtime dll[1]? > > 1: http://www.py2exe.org/index.cgi/Tutorial#Step5 > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://old.nabble.com/dll-errors-in-compiled-python-program-tp28407640p31538796.html Sent from the Python - python-list mailing list archive at Nabble.com. From r1chardj0n3s at gmail.com Wed May 4 02:34:43 2011 From: r1chardj0n3s at gmail.com (Richard Jones) Date: Wed, 4 May 2011 16:34:43 +1000 Subject: PyCon Australia 2011 CFP still open Message-ID: Hi all, We're still waiting for some tardy presenters who haven't put in their proposals yet, and it's unfair to give just them an extension so we're leaving the submission system open until next Monday, the 9th of May. Thanks to everyone else who put in their proposals on time, and we'll be starting the review process in the next couple of days. Richard Jones PyCon Au 2011 Program Chair http://pycon-au.org/cfp From pratik.mehta at capgemini.com Wed May 4 03:45:51 2011 From: pratik.mehta at capgemini.com (Mehta, Pratik) Date: Wed, 4 May 2011 13:15:51 +0530 Subject: A very minute correction on PDF Message-ID: <073456261C486944897A62516989111CACBC52EE7D@IN-MUM-MAIL2.corp.capgemini.com> For tutorialPython.pdf Page 17 of the ebook (i.e. page 23 of pdf) under topic 3.2 First Steps towards programming Under while loop, there should be a "," after print b Print b, (a comma after 'b' is missing) Regards, ______________________________________________________________________ [cid:image001.gif at 01CC0988.41BD50B0]Pratik Mehta Associate Consultant | SOGETI - FR TeamPark Support Team Capgemini India | Mumbai II Tel.: +91 022 67 55 7000 - Mob: +91 9323054941 Extension: 225 1922 | www.capgemini.com pratik.mehta at capgemini.com People matter, results count. _______________________________________________________________________ This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.gif Type: image/gif Size: 1616 bytes Desc: image001.gif URL: From duncan.booth at invalid.invalid Wed May 4 04:44:36 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 May 2011 08:44:36 GMT Subject: Why do directly imported variables behave differently than those attached to imported module? References: Message-ID: Chris Angelico wrote: > Here's a side point. What types will hold a reference to the enclosing > module (or at least its dictionary)? Would it be possible to use a > from import to load a module, then "lose" the module even though > you're using objects from it? > > I am guessing that a function or class will hold such a reference, > because otherwise it would be a bit awkward for them to use any sort > of module-level state. Or do they not, and instead go look for their > module in sys.modules? A function object has a reference to the dictionary for the module in which it was defined; it needs this to access global variables. A class holds the name of the module but has no reference to the actual module itself. Yes, it is quite possible to delete a module object, but it won't generally matter since any classes that are still referenced will prevent their methods being deleted and any functions or methods that are still accessible will keep the globals alive as long as required. -- Duncan Booth http://kupuguy.blogspot.com From rosuav at gmail.com Wed May 4 05:02:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 May 2011 19:02:40 +1000 Subject: Aborting Python from C code In-Reply-To: References: Message-ID: On Sat, Apr 30, 2011 at 7:29 PM, Dylan Evans wrote: > I think i see what you are trying to do but it depends on the environment > and your goals. > Generally i think you need to?separate?your code by forking (or perhaps you > have already done that?), > then you can run a check to see if the process died as expected. I don't > know though, this not much > information to go on, but if you are running untrusted code then you need to > be able to isolate and kill it. Well, I've gone with a slight variant on this. If the Python script doesn't terminate in a timely manner, the process will be killed with a longjmp straight from the signal handler (the setjmp having been done long long ago back when the process initialized itself). So Py_Finalize() will be called, but no other Python-related functions _at all_, and the process promptly terminates. I'm assuming that Python will flush out all its state on process termination (that is, it doesn't hang onto any system-global resources). Thanks for the advice! Chris Angelico From jeanmichel at sequans.com Wed May 4 05:47:37 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 04 May 2011 11:47:37 +0200 Subject: Running and killing a process in python In-Reply-To: References: Message-ID: <4DC120B9.3080902@sequans.com> James Mills wrote: > On Wed, May 4, 2011 at 10:45 AM, Astan Chee wrote: > >> Hi, >> I'm trying to make a python script (in windows 7 x64 using python 2.5) to >> start a process, and kill it after x minutes/seconds and kill all the >> descendants of it. >> Whats the best way of doing this in python? which module is best suited to >> do this? subprocess? >> > > Yes start with the subprocess module: > > http://docs.python.org/library/subprocess.html > > cheers > James > > As an alternative, you can have a look at http://codespeak.net/execnet/index.html This module is designed to execute processes on remote machines, but it works great on the local host as well. Among its features are: " - easy creation, handling and termination of multiple processes - fully interoperable between Windows and Unix-ish systems " While it has more feature than what you need, if you do simple things, it stays simple. (I never used subprocess with Windows, so I don't know if killing process is that easy. On *nix system, you should probably choose subprocess, execnet would be overkill) JM From jeanpierreda at gmail.com Wed May 4 05:56:28 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 4 May 2011 02:56:28 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> > To illustrate the neither-fish-nor-fowl nature of Python calls: > > mwilson at tecumseth:~$ python > 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.>>> def identify_call (a_list): > > ... ? a_list[0] = "If you can see this, you don't have call-by-value" > ... ? a_list = ["If you can see this, you have call-by-reference"] > ...>>> my_list = [None] > >>> identify_call (my_list) > >>> my_list > > ["If you can see this, you don't have call-by-value"] > > so it's neither call-by-value nor call-by-reference as (e.g.) C or PL/I > programming would have it (don't know about Simula, so I am off topic, > actually.) ?It's not so wrong to think of Python's parameter handling as > ordinary assignments from outer namespaces to an inner namespace. > > ? ? ? ? Mel. Eh, that example doesn't say what you think it does. It has the same behavior in C: http://ideone.com/Fq09N . Python is pass-by-value in a meaningful sense, it's just that by saying that we say that the values being passed are references/pointers. This is maybe one level of abstraction below what's ideal, but Scheme, Java, etc. share this terminology. (Ruby calls it pass-by-reference AFAIK. Whatever, a rose by any other name...) Devin Jeanpierre From steve+comp.lang.python at pearwood.info Wed May 4 06:51:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 May 2011 10:51:33 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 02:56:28 -0700, Devin Jeanpierre wrote: > Python is pass-by-value in a > meaningful sense, it's just that by saying that we say that the values > being passed are references/pointers. This is maybe one level of > abstraction below what's ideal, "Maybe"? Given the following statement of Python code: >>> x = "spam" what is the value of the variable x? Is it...? (1) The string "spam". (2) Some invisible, inaccessible, unknown data structure deep in the implementation of the Python virtual machine, which the coder cannot access in any way using pure Python code. (Possibly a pointer, but since it's an implementation detail, other implementations may make different choices.) (3) Something else. I argue that any answer except for (1) is (almost always) counter- productive: it adds more confusion than shedding light. It requires thinking at the wrong level, at the implementation level instead of the level of Python code. If we define "value" to mean the invisible, inaccessible reference, then that leaves no word to describe was the string "spam" is. (I say "almost always" counter-productive because abstractions leak, and sometimes you do need to think about implementation.) > but Scheme, Java, etc. share this > terminology. (Ruby calls it pass-by-reference AFAIK. The intellectual contortions that some people will go through to hammer the square peg of actual programming language behaviour into the two round holes of "pass by value" and "pass by reference" never cease to astonish me. > Whatever, a rose by any other name...) Do you really think that roses would be the symbol of romantic love if they were called "disgusting stink-weeds of perversion and death"? "How was the date last night?" "Oh, it was marvelous! He presented me with a single red stink-weed, and then we went to a disgusting little restaurant. I had the swill." When people cannot agree on the definition of words, how can they communicate? Pass by reference Ruby is completely different from the older usage in Pascal, VB and other languages. Likewise, pass by value in Java is completely different from that in older languages. Pass by reference in Ruby, and pass by value in Java, describe the same thing. What were these people thinking? -- Steven From leandrodsferreira at gmail.com Wed May 4 06:52:29 2011 From: leandrodsferreira at gmail.com (LehH Sdsk8) Date: Wed, 4 May 2011 03:52:29 -0700 (PDT) Subject: Handling the log in BaseHTTPServer Message-ID: First, i'm sorry for any inglish error! So, i use the BaseHTTPServer to create a page for monitoring purposes, someone now how to direct the event log to a file? From hg at schaathun.net Wed May 4 06:56:16 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 11:56:16 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On Wed, 4 May 2011 02:56:28 -0700 (PDT), Devin Jeanpierre wrote: : Eh, that example doesn't say what you think it does. It has the same : behavior in C: http://ideone.com/Fq09N . Python is pass-by-value in a : meaningful sense, it's just that by saying that we say that the values : being passed are references/pointers. No, Python is not pass-by-value, because the pointer is abstracted away. You transmit arguments by reference only and cannot access the value of the reference. In C it is pass by value, as the pointer is explicit and do whatever you want with the pointer value. So, even though you have the same mechanism in C and Python, they do not have the same name. In the low-level C you only have pass by value, but you can use the pointer syntax to do whatever you want within pass by value. In the higher-level python, you do not have the flexibility provided by explicit pointers, so you need to explain the semantics without having a pointer concept defined a priori. : This is maybe one level of : abstraction below what's ideal, but Scheme, Java, etc. share this : terminology. (Ruby calls it pass-by-reference AFAIK. Whatever, a rose : by any other name...) Now, this is confusing, because the terminology is not universal and hardly intuitive. What is called transmission by reference in a Simula context (Bj?rn Kirkerud's textbook on OO Programming with Simula for instance) is called object sharing in Wikipedia. What Wikipedia calls call by reference is transmission by name in the Simula context. -- :-- Hans Georg From no.email at nospam.invalid Wed May 4 06:58:51 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 04 May 2011 03:58:51 -0700 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7x62pqn34k.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >>>> x = "spam" > what is the value of the variable x? Is it...? > (1) The string "spam". Python works about the same way as Lisp or Scheme with regard to this sort of thing, and those languages have been described with quite a bit of mathematical formality. So if you want a precise theoretical treatment you might look at the Scheme report. It should be pretty clear how it carries over to Python. From johnroth1 at gmail.com Wed May 4 07:14:09 2011 From: johnroth1 at gmail.com (John Roth) Date: Wed, 4 May 2011 04:14:09 -0700 (PDT) Subject: vertical ordering of functions References: Message-ID: On May 3, 4:08?pm, Jabba Laci wrote: > Hi, > > I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. > 5 he says that a function that is called should be below a function > that does the calling. This creates a nice flow down from top to > bottom. > However, when I write a Python script I do just the opposite. I start > with the lines > > if __name__ == "__main__": > ? ? main() > > Then I add main() above, which is a control function that contains > some function calls that decompose the problem into subproblems. Then > I add these functions above, etc. > > Is there a convention for this? Should main() be at the top and called > function below? > > Thanks, > > Laszlo I order classes and methods as I'd expect someone approaching the program for the first time to want to read it. I think Robert Martin's recommendation of use before declaration makes it easier to read a program for the first time. Some compilers require declaration before use because they need to see the declaration before they see any uses. Python is in between: you can treat Python as if the order you write things doesn't matter, but there are cases where it really does matter. When it does, you have to have the definition before the use. John Roth From jeanpierreda at gmail.com Wed May 4 09:12:14 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 4 May 2011 06:12:14 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 4, 6:51?am, Steven D'Aprano wrote: > On Wed, 04 May 2011 02:56:28 -0700, Devin Jeanpierre wrote: > > Python is pass-by-value in a > > meaningful sense, it's just that by saying that we say that the values > > being passed are references/pointers. This is maybe one level of > > abstraction below what's ideal, > > "Maybe"? > > Given the following statement of Python code: > > >>> x = "spam" > > what is the value of the variable x? Is it...? > > (1) The string "spam". > > (2) Some invisible, inaccessible, unknowndatastructure deep in the > implementation of the Python virtual machine, which the coder cannot > access in any way using pure Python code. > > (Possibly a pointer, but since it's an implementation detail, other > implementations may make different choices.) > > (3) Something else. As I said, a pointer or reference. > I argue that any answer except for (1) is (almost always) counter- > productive: it adds more confusion than shedding light. It requires > thinking at the wrong level, at the implementation level instead of the > level of Python code. If we define "value" to mean the invisible, > inaccessible reference, then that leaves no word to describe was the > string "spam" is. > > (I say "almost always" counter-productive because abstractions leak, and > sometimes you do need to think about implementation.) I don't know why you want to argue that it's counter-productive when all I said was that it was meaningful / worked. I don't think of "pass-by-value" involving references as being an implementation-level thing. It's a way of thinking about Python's behavior: a model. There don't even need to be actual references or anything resembling them inside the implementation in order to apply the model (for example, we probably all accept that Python could be implemented using a turing machine, which lacks references/pointers). Also, the word you suspected did not exist is "object". So if we have var = "spam", var is a variable containing a reference to the object "spam". Alternatively, it's a handle for the object "spam". I think that's the call-by-sharing terminology, anyway. > > but Scheme, Java, etc. share this > > terminology. (Ruby calls it pass-by-reference AFAIK. > > The intellectual contortions that some people will go through to hammer > the square peg of actual programming language behaviour into the two > round holes of "pass by value" and "pass by reference" never cease to > astonish me. It isn't particularly contorted. I learned Python this way and it makes perfect sense. It's just perhaps one level of abstraction away from the ideal of what some programmers would think in. Python's "pass- by-value" conforms exactly to the "pass-by-value" of other languages such as C. The only twist is that you never get to dereference pointers in Python, but you can in C. Not much of a twist if you ask me, but then again, I've been thinking in this model for years. Maybe I'm brainwashed. :) > > Whatever, a rose by any other name...) > > Do you really think that roses would be the symbol of romantic love if > they were called "disgusting stink-weeds of perversion and death"? > > "How was the date last night?" > "Oh, it was marvelous! He presented me with a single red stink-weed, and > then we went to a disgusting little restaurant. I had the swill." Please don't argue with me in this manner. The point is that words don't matter, the meaning behind them does. As long as it's clear what's meant, and what's meant is internally-consistent, I don't have much problem with it. Of course, this is a rule of thumb and you could draw extreme scenarios where it just becomes a bother. Devin Jeanpierre From jeanpierreda at gmail.com Wed May 4 09:13:48 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 4 May 2011 06:13:48 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <1874cca8-1f1f-4d0a-b306-c32f2fa1d8c1@x3g2000yqj.googlegroups.com> On May 4, 6:56?am, Hans Georg Schaathun wrote: > On Wed, 4 May 2011 02:56:28 -0700 (PDT), Devin Jeanpierre? wrote: > > : ?Eh, that example doesn't say what you think it does. It has the same > : ?behavior in C:http://ideone.com/Fq09N. Python is pass-by-value in a > : ?meaningful sense, it's just that by saying that we say that the values > : ?being passed are references/pointers. > > No, Python is not pass-by-value, because the pointer is abstracted > away. ?You transmit arguments by reference only and cannot access the > value of the reference. ?In C it is pass by value, as the pointer > is explicit and do whatever you want with the pointer value. ? The same argument applies to every language I know but two, all of which describe themselves as pass-by-value. What you say certainly has a consistency to it, it's just at odds with how I generally see the term being applied. Forgive me if I don't share the same definition as you, even if I do appreciate its elegance. Devin Jeanpierre From hg at schaathun.net Wed May 4 09:44:07 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 14:44:07 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7q1898-f3l.ln1@svn.schaathun.net> On Wed, 4 May 2011 06:12:14 -0700 (PDT), Devin Jeanpierre wrote: : I don't think of "pass-by-value" involving references as being an : implementation-level thing. It's a way of thinking about Python's : behavior: a model. (...) : It isn't particularly contorted. I learned Python this way and it : makes perfect sense. It's just perhaps one level of abstraction away : from the ideal of what some programmers would think in. Python's "pass- : by-value" conforms exactly to the "pass-by-value" of other languages : such as C. It is contorted and implementation-level because it is one level below the abstraction assumed by the language. It only works by assuming knowledge of C, which is language which has proved unsuitable for complex and abstract data modelling. Digging down into C should be unnecessary to explain Python. By calling it pass-by-value you introduce a new data type which is unknown to Python, namely the pointer. : The only twist is that you never get to dereference : pointers in Python, but you can in C. Not much of a twist if you ask : me, but then again, I've been thinking in this model for years. Maybe : I'm brainwashed. :) You are. You explain Python in terms of C. That's useful when you talk to other speakers of C. If you want to explain the language to a broader audience, you should use terminology from the language's own level of abstraction. -- :-- Hans Georg From lkcl at lkcl.net Wed May 4 10:06:59 2011 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 4 May 2011 15:06:59 +0100 Subject: [ann] pyjamas 0.8alpha1 release Message-ID: after a long delay the pyjamas project - http://pyjs.org - has begun the 0.8 series of releases, beginning with alpha1: https://sourceforge.net/projects/pyjamas/files/pyjamas/0.8/ pyjamas is a suite of projects, including a python-to-javascript compiler with two modes of operation (roughly classified as "python strict" and "Optimised"); a GUI Framework almost identical to that of the GWT Project (1.5 to 1.7); and a "Desktop" version which is similar in concept to Adobe Air, allowing python applications to be run - unmodified - as stand-alone Desktop Applications. pyjamas can therefore be considered to be a Desktop GUI framework - a peer of GTK2 and QT4 - with the startling capability that applications can also be compiled to javascript and run in any modern web browser with absolutely no special plugins required, or it can be considered to be an AJAX Web Framework with the massive advantage that applications are written in python (not javascript) with a "Desktop" mode as well. both descriptions are accurate, making pyjamas the world's only free software python-based platform-independent, browser-independent, GUI-toolkit-independent and OS-independent "Holy Grail" GUI development environment [so there. nyer, nyer to the corporate big boys with access to $m who *still* haven't managed that one] also included are ports of GChart and GWTCanvas, each of which run under all web browsers and all desktop engines (with the exception at present of the python-webkit desktop engines, which presently do not support SVG Canvas). all pyjamas UI libraries are designed to be browser-independent as well as platform independent. the usual "browser foibles", tricks and gotchas are catered for with a transparent "Platform Override" mechanism which ensures that the published API of each UI Library is identical across all platforms (including the Desktop Engines). [no more "If Platform == IE or Platform == Opera...."] due to the sheer number of modern browsers as well as the number of pyjamas-desktop engines required to be supported, the 0.8 series will be ready declared "stable" when sufficient community-led testing has been done. bugreports are in for Opera 11, IE8 and Google Chrome: http://code.google.com/p/pyjamas/issues/detail?id=600 http://code.google.com/p/pyjamas/issues/detail?id=601 http://code.google.com/p/pyjamas/issues/detail?id=597 still requiring testing and confirmation is Opera 9 and 10; Firefox 2, 3, 3.1, 3.5, 3.6 and 4.0; IE6, 7 and 9; Safari 3 and 4, as well as mobile phone browsers Android, Symbian Series 60, iphone, ipad and blackberry OS 4. also requiring testing and confirmation is the Desktop Engines, of which there are now four variants: XulRunner (Firefox Engine), pywebkitgtk, MSHTML and the new addition pywebkitdfb (DirectFB). each browser and each engine requires each of the 70 examples to be run, and in the case of the pyjamas compiler (pyjs), compilation is required with both -O and --strict (with the exception of the LibTest example). the pywebkitdfb engine is a new addition, and merits a particular mention. some time last year, both GTK2 and QT4 independently announced that they were dropping support for DirectFB from future versions, and Enlightenment had not tested the DirectFB port for some considerable time. Webkit-GTK with the older GTK-DirectFB libraries simply would not compile. in the embedded space, where it can take 30 seconds to fire up Webkit-GTK on a 400mhz ARM9 and even longer to start up WebkitQT4, this was something of a disaster. To fix this, a new port of Webkit was created which uses DirectFB directly, using a tiny 50k Widget Toolkit called "Lite". This development coincided with the re-engineering of pywebkitgtk and the creation of the pythonwebkit project, http://www.gnu.org/software/pythonwebkit: pywebkitdfb was therefore also created at the same time. Cutting a long story short, pywebkitdfb now exists and has a startup time on 400mhz ARM9 processors of under 1.5 seconds. The startup time of both WebkitDFB and pywebkitdfb on Dual-Core 2ghz Intel systems is so quick that it's difficult to determine: an estimate is under 0.1 seconds (100ms). WebkitGTK. WebkitEFL and WebkitQT4 have approximately 20 times or longer startup times. So although WebkitDFB is still significantly experimental, it is definitely worthwhile considering, especially for Embedded Systems, but even for use on X-Windows, and even just as a plain (but modern) web browser for those people sick to the back teeth of long startup times on their web browser [and it has python bindings, too. yaay!] summary: developing applications in pyjamas means the application can be made to run just about anywhere, and it's an entirely python-based and a free software framework. it's a community-driven project, so requires *your* input to get it to a proven stable state. http://pyjs.org From rosuav at gmail.com Wed May 4 10:20:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 00:20:34 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <7q1898-f3l.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: On Wed, May 4, 2011 at 11:44 PM, Hans Georg Schaathun wrote: > It is contorted and implementation-level because it is one level below > the abstraction assumed by the language. ?It only works by assuming > knowledge of C, which is language which has proved unsuitable for > complex and abstract data modelling. ?Digging down into C should be > unnecessary to explain Python. Sometimes, to explain Python, you need to dig down to the underlying hardware - even deeper than C, if you like. And that's always going to be the way, because abstractions leak from time to time. Or I should say, they occasionally have confidential briefings with the press. Abstracting everything perfectly is neither possible nor desirable. Chris Angelico From sturla at molden.no Wed May 4 10:28:16 2011 From: sturla at molden.no (sturlamolden) Date: Wed, 4 May 2011 07:28:16 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <87aaf351vk.fsf@xemacs.org> Message-ID: On May 3, 3:50?pm, Hrvoje Niksic wrote: > I would say that, considering currently most popular languages and > platforms, Python's data model is in the majority. ?It is only the > people coming from a C++ background that tend to be confused by it. In C++, one will ususally put class variables (objects) on the stack or in STL containers, and use references instead of pointers. This way one gets deterministic clean-up, and operator overloading will work as expected. It is a common beginner mistake for people coming from Java to use "new" anywhere in C++ code, instead of inside constructors only. Used properly, C++ has a data model for class variables similar to Fortran (pass-by-reference). This is complicated by the ability of C ++ to pass-by-value for backwards compatibility with C, inclusing the use of raw pointers. This hybrid and convoluted data model of C++ is a common source of confusion and programming mistakes, both for programmers coming from C++ to Python or C# or vice versa. Java is somewhat between C and C#, in that it has C semantics for elementary types (e.g. int and float), but not for objects in general. In C# and Python, elementary types are immutable objects, byut thet have no special pass-by-value semantics. Python has the same data model as Scheme. This includes that code is an object in Python (in Python that is byte code not source code, thus no Lisp macros). Variables are names that bind to an object. Objects are passed as references, but names are not. "Dummy arguments" (to use Fortran termininology) are bound to the same objects with which the function was called, but this is not call-by-reference semantics in the style of Fortran and C++: In Python, the "=" operator will rebind in the local scope, as in C, Java and C#. It will not affect anything the the calling scope (as in C ++ and Fortran). Nevertheless, this is not pass-by-value, as no copy are made. A reference in C++ and Fortran is an alias for the variable in the calling scope. In Python it is a new variable pointing to the same value. This is a major difference, but a common source of error for those that don't understand it. ( for those confused about the claimed behavior of "=" in C++: The previous paragraph deals with reference variables in C++, not those passed with C-style pass-by-value sematics. C++ does not always behave as C, sometimes it behaves like Fortran and Pascal.) Thus, Python does not pass-by-value like C or C++, nor does it pass-by- reference like C++ or Fortran. The semantics of Python, C# and Lisp might be described as "pass-by- handle" if we need to put a name on it. From sturla at molden.no Wed May 4 10:44:38 2011 From: sturla at molden.no (sturlamolden) Date: Wed, 4 May 2011 07:44:38 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 3, 6:33?pm, Mel wrote: > def identify_call (a_list): > a_list[0] = "If you can see this, you don't have call-by-value" > a_list = ["If you can see this, you have call-by-reference"] The first one is a mistake. If it were pass-by-value, it would assign the string to a list unseen by the caller -- i.e. a copy of the caller's argument (same value, different object). But that does not happen. The string is assigned to the list seen by the caller. Thus we can exclude call-by-value. The second proposition is correct. This allows us to exclude pass-by-reference similar to C++, Pascal and Fortran. Thus: def identify_call (a_list): a_list[0] = "If you cannot see this, you have call-by-value" a_list = ["If you can see this, you have call-by-reference"] Clearly Python has neither call-by-value nor call-by-reference. Python uses a third mechanism. Sturla From robert.kern at gmail.com Wed May 4 11:06:51 2011 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 04 May 2011 10:06:51 -0500 Subject: Pickling extension types In-Reply-To: References: Message-ID: On 5/3/11 9:28 PM, Stefan Kuzminski wrote: > closer I think > > 1) I changed tp_name to be 'observation.MV' ( module is named observation.c ) > and now I get a new error.. > > PicklingError: Can't pickle : import of module > observation failed > > 2) here is the init function, sorry I did not include it in the original listing > > void initobservation(void) { > > PyObject *m; > m = Py_InitModule("observation", observation_methods); > > Py_INCREF(&PyMV_Type); > PyModule_AddObject(m, "MV", (PyObject *)&PyMV_Type); > > } Without seeing the whole C code, or the Python code you are trying, I can't help much more. -- 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 torriem at gmail.com Wed May 4 11:40:02 2011 From: torriem at gmail.com (Michael Torrie) Date: Wed, 04 May 2011 09:40:02 -0600 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DC17352.2080601@gmail.com> On 05/04/2011 08:44 AM, sturlamolden wrote: > On May 3, 6:33 pm, Mel wrote: > >> def identify_call (a_list): >> a_list[0] = "If you can see this, you don't have call-by-value" >> a_list = ["If you can see this, you have call-by-reference"] > > > The first one is a mistake. If it were pass-by-value, it would > assign the string to a list unseen by the caller -- i.e. a copy > of the caller's argument (same value, different object). > > Clearly Python has neither call-by-value nor call-by-reference. > > Python uses a third mechanism. Which is exactly what the code showed. The first one isn't a mistake. You just read it wrong. From stefan.kuzminski at gmail.com Wed May 4 11:45:50 2011 From: stefan.kuzminski at gmail.com (Stefan Kuzminski) Date: Wed, 4 May 2011 11:45:50 -0400 Subject: Pickling extension types In-Reply-To: References: Message-ID: I got this to work by returning from reduce just the args that the __init__ of the type being pickled requires ( rather than the 5 length tuple described in the pickling docs ), I am not going to argue with it though.. thank you *very* much for the help! S On Wed, May 4, 2011 at 11:06 AM, Robert Kern wrote: > On 5/3/11 9:28 PM, Stefan Kuzminski wrote: > >> closer I think >> >> 1) I changed tp_name to be 'observation.MV' ( module is named >> observation.c ) >> and now I get a new error.. >> >> PicklingError: Can't pickle : import of module >> observation failed >> >> 2) here is the init function, sorry I did not include it in the original >> listing >> >> void initobservation(void) { >> >> PyObject *m; >> m = Py_InitModule("observation", observation_methods); >> >> Py_INCREF(&PyMV_Type); >> PyModule_AddObject(m, "MV", (PyObject *)&PyMV_Type); >> >> } >> > > Without seeing the whole C code, or the Python code you are trying, I can't > help much more. > > > -- > 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 > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lkcl at lkcl.net Wed May 4 11:53:20 2011 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 4 May 2011 16:53:20 +0100 Subject: [ann] pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 3:06 PM, Luke Kenneth Casson Leighton wrote: > after a long delay the pyjamas project - http://pyjs.org - has begun the > 0.8 series of releases, beginning with alpha1: > > https://sourceforge.net/projects/pyjamas/files/pyjamas/0.8/ > > pyjamas is a suite of projects, including a python-to-javascript > compiler with two modes of operation (roughly classified as "python > strict" and "Optimised"); a GUI Framework almost identical to that of > the GWT Project (1.5 to 1.7); oh one other thing - for the 0.8 release, jim washington kindly added an HTML5-compliant "Drag-n-Drop" interface, which, on web engines that do not have HTML5, is emulated. and thus provides the exact same API, regardless of the web browser being used. cool, huh? if i was a java-lover, i'd look forward to that being added some day to GWT. btw - if anyone's at all curious [about GWT "Desktop" possibilities], there *does* exist a sort-of "Desktop" version [not really] - it's basically webkit, it requires execution under the eclipse IDE, and it's still javascript (not Java). i _did_ speak to the GWT Team, raising with them the possibility of doing Java bindings to Webkit [or XulRunner, or MSHTML] and providing a port of GWT that can run GWT applications REALLY as stand-alone Desktop applications, and they basically implied that that'll happen "when hell freezes over". i guess the idea of providing languages other than javascript with direct access to the full and incredible capabilities of DOM and HTML5 is just... too alien. which is funny, because pyjamas desktop shows what can be done: web browser engines can literally be turned into cross-platform GUI engines. l. From tapi at syskall.net Wed May 4 11:55:33 2011 From: tapi at syskall.net (Tapi) Date: Wed, 04 May 2011 16:55:33 +0100 Subject: Handling the log in BaseHTTPServer In-Reply-To: References: Message-ID: Hi, You may create a subclass of (or Mixin for) BaseHTTPRequestHandler to override its log_message() method. Here's a really simple example ; it's perfectible, but it should show you the way : class MyLoggingHTTPRequestHandler(BaseHTTPRequestHandler): def log_message(self, format, *args): open(LOGFILE, "a").write("%s - - [%s] %s\n" % (self.address_string(), self.log_date_time_string(), format%args)) httpd = HTTPServer(ADDR, MyLoggingHTTPRequestHandler) httpd.serve_forever() Simon On Wed, 4 May 2011 03:52:29 -0700 (PDT), LehH Sdsk8 wrote: > First, i'm sorry for any inglish error! > > So, i use the BaseHTTPServer to create a page for monitoring > purposes, > someone now how to direct the event log to a file? From leandrodsferreira at gmail.com Wed May 4 12:09:17 2011 From: leandrodsferreira at gmail.com (LehH Sdsk8) Date: Wed, 4 May 2011 09:09:17 -0700 (PDT) Subject: Handling the log in BaseHTTPServer References: Message-ID: On 4 maio, 12:55, Tapi wrote: > Hi, > > You may create a subclass of (or Mixin for) BaseHTTPRequestHandler to > override its log_message() method. > Here's a really simple example ; it's perfectible, but it should show > you the way : > > class MyLoggingHTTPRequestHandler(BaseHTTPRequestHandler): > ? ? ?def log_message(self, format, *args): > ? ? ? ? ?open(LOGFILE, "a").write("%s - - [%s] %s\n" % > ? ? ? ? ? ? ? ? ? ? ? ? ? (self.address_string(), > ? ? ? ? ? ? ? ? ? ? ? ? ? ?self.log_date_time_string(), > ? ? ? ? ? ? ? ? ? ? ? ? ? ?format%args)) > > httpd = HTTPServer(ADDR, MyLoggingHTTPRequestHandler) > httpd.serve_forever() > > Simon > > > > > > > > On Wed, 4 May 2011 03:52:29 -0700 (PDT), LehH Sdsk8 wrote: > > First, i'm sorry for any inglish error! > > > So, i use the BaseHTTPServer to create a page for monitoring > > purposes, > > someone now how to direct the event log to a file? Thanks dude, this really works, my class is a subclass of basehttprequesthandler, the only thing i have to do is put this function inside. Thanks. From jeanpierreda at gmail.com Wed May 4 12:18:56 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 4 May 2011 09:18:56 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: On May 4, 9:44 am, Hans Georg Schaathun wrote: > : The only twist is that you never get to dereference > : pointers in Python, but you can in C. Not much of a twist if you ask > : me, but then again, I've been thinking in thismodelfor years. Maybe > : I'm brainwashed. :) > > You are. You explain Python in terms of C. That's useful when you > talk to other speakers of C. > > If you want to explain the language to a broader audience, you should > use terminology from the language's own level of abstraction. No, I explained Python in terms of pointers/reference. I don't speak C or come from a C background, I'm primarily a Python programmer. Also, I don't agree with your notions of "should", I have seen it taught this way to plenty of undergraduate students learning Python as their first programming language, and they do fine. The precise notational difference between sharing an object and copying a reference doesn't matter, as long as you can draw a diagram of it and write/read code -- which they can, and they do fine. I'm a bit uncomfortable with the vibe here. It's one thing for me to self-deprecatingly suggest I'm brainwashed (with a smile), and another for you to agree in complete seriousness. Devin Jeanpierre From matthew.moorland at gmail.com Wed May 4 12:34:00 2011 From: matthew.moorland at gmail.com (ETP) Date: Wed, 4 May 2011 09:34:00 -0700 (PDT) Subject: Basic interaction with another program Message-ID: I have a dos program (run in a window) that I would like to control with a script. It needs only text input. For example, I only need to tell it: L u 100 u It will then wait for a file to be created, rename the file, then loop. Simple. I'd like to run this on Lucid Puppy Linux as it will be implemented on a very old laptop, but can probably deal with windows if needed. I only need direction on getting Python to interact with another program; how do I get it to direct text onto another window? From msarro at gmail.com Wed May 4 12:39:41 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 4 May 2011 12:39:41 -0400 Subject: Basic interaction with another program In-Reply-To: References: Message-ID: Look into the pexpect library, it'll make this easy as punch. http://www.noah.org/wiki/pexpect On Wed, May 4, 2011 at 12:34 PM, ETP wrote: > I have a dos program (run in a window) that I would like to control > with a script. ?It needs only text input. ?For example, I only need to > tell it: > > L > u > 100 > u > > It will then wait for a file to be created, rename the file, then > loop. ?Simple. > > I'd like to run this on Lucid Puppy Linux as it will be implemented on > a very old laptop, but can probably deal with windows if needed. > > I only need direction on getting Python to interact with another > program; how do I get it to direct text onto another window? > -- > http://mail.python.org/mailman/listinfo/python-list > From sturla at molden.no Wed May 4 12:40:12 2011 From: sturla at molden.no (sturlamolden) Date: Wed, 4 May 2011 09:40:12 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <29b1bdc8-7bff-445e-b660-53311ef1eb4d@p19g2000yqh.googlegroups.com> On May 4, 5:40?pm, Michael Torrie wrote: > Which is exactly what the code showed. ?The first one isn't a mistake. > You just read it wrong. No, I read "call-by-value" but it does not make a copy. Call-by-value dictates a deep copy or copy-on-write. Python does neither. Python pass a handle to the object, not a handle to a copy of the object. If you want to see call-by-value in practice, take a look at MATLAB, SciLab or Octave; or consider what C++ copy constructors do in function calls with value types. The first one is indeed a mistake. An object has a value. A name binds to an object, not to a value. If Python did pass-by-value, the string would be inserted in an object (here: a list) with the same value (e.g. empty list), it would not modify the same object by which you called the function. I think you understand what Python does, but not what call-by-value would do. C++ tells you the difference: // copy constructor is invoked // x is a copy of the argument's value // this is call-by-value void foobar1(Object x); // no copy is taken // x is a logical alias of the argument // this is call-by-reference void foobar2(Object &x); // x is a pointer, not an object // x is a copy of another pointer // this is similar to Python sematics // the pointer is passed by value, not the pointee // in C, this is sometimes called call-by-reference // as there are no reference types, but it's not void foobar3(Object *x); Sturla From ddneilson at gmail.com Wed May 4 12:51:39 2011 From: ddneilson at gmail.com (Daniel Neilson) Date: Wed, 04 May 2011 10:51:39 -0600 Subject: Hooking into Python's memory management Message-ID: <4DC1841B.2030601@gmail.com> Hello, I'm hoping that there will be someone here with sufficient expertise to answer a question on Python 3 for me. I work in the Computer Science department at a large Canadian University. We are currently doing a feasibility analysis for switching to using Python in our first year major-stream courses. Part of our first year curriculum requires that students be exposed to explicit dynamic memory allocation in the form of C++'s new/delete, C's malloc/free, etc. I realize that Python is garbage collected, and that there is never a need to explicitly allocate & deallocate objects. However, I am trying to determine whether or not it is possible to simulate that behaviour within Python via a module for the purposes of instruction. For these purposes, I would like to know whether it is possible within Python 3 to write a Python-only module that, essentially, hooks into the "constructor" and "destructor" of many of the Python built-in types (specifically list, dictionary, set, tuple, and string) so that the module can: 1) Maintain a list of object id()'s for objects that have been created. Ideally, this list would also contain the file & line number where the object was created. 2) Provide a "deallocate" function that will remove a given object's id() from the list from (1). 3) Print out an error message if the python script terminates with a non-empty list from (1). Preferably with a list of objects that are still "allocated." Baring a Python-only module, would this behaviour be possible to add via a C-language module? A module that hooked in to all memory allocation, and inspected the type of the object being allocated to conditionally add the object's id() to the list would also suffice. In either case, if such a module is possible, any pointers you could provide regarding how to implement such a module would be appreciated. Thank you for your time, Daniel From invalid at invalid.invalid Wed May 4 12:52:58 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 16:52:58 +0000 (UTC) Subject: Basic interaction with another program References: Message-ID: On 2011-05-04, Matty Sarro wrote: > On Wed, May 4, 2011 at 12:34 PM, ETP wrote: >> I have a dos program (run in a window) that I would like to control >> with a script. > Look into the pexpect library, it'll make this easy as punch. I don't think pexpect is going to do the OP much good. Quoting from the web page: "Pexpect does not currently work on the standard Windows Python" > http://www.noah.org/wiki/pexpect Seriously? Yellow on brown text? -- Grant Edwards grant.b.edwards Yow! When this load is at DONE I think I'll wash it gmail.com AGAIN ... From hg at schaathun.net Wed May 4 13:03:05 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 18:03:05 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: <9fd898-0el.ln1@svn.schaathun.net> On Wed, 4 May 2011 09:18:56 -0700 (PDT), Devin Jeanpierre wrote: : I'm a bit uncomfortable with the vibe here. It's one thing for me to : self-deprecatingly suggest I'm brainwashed (with a smile), and another : for you to agree in complete seriousness. I am sorry. It was not meant to be an insult. I do think that you sit tightly in a frame of reference which is obviously not the only one appropriate, and IMNHO not the optimal one for the purpose. "Brainwashed" was not a word I meant to take seriously. Apologies. I should have cut the C reference too; the same frame of reference could be adopted from any number of languages. Note that it was not the use of references as a concept I objected to, but that they might be passed by value. With the references being purely abstract entities and not data objects, the idea that they have values do not make sense. And pass-by-value where the value is a reference is just confusing. -- :-- Hans Georg From hg at schaathun.net Wed May 4 13:09:56 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 18:09:56 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: <4sd898-0el.ln1@svn.schaathun.net> On Thu, 5 May 2011 00:20:34 +1000, Chris Angelico wrote: : Sometimes, to explain Python, you need to dig down to the underlying : hardware - even deeper than C, if you like. Sometimes you may need to narrow down the scope and explain a particular implementation of python with its hardware, OS, and interpreter. However, explaining just python, you do not know what the underlying hardware/OS/interpreter is, and digging down into it is not possible. : And that's always going to : be the way, because abstractions leak from time to time. Or I should : say, they occasionally have confidential briefings with the press. : Abstracting everything perfectly is neither possible nor desirable. Sure, but every language assumes a certain level of abstraction, and when the abstraction breaks the language fails to be unambiguous and/or portable. -- :-- Hans Georg From sturla at molden.no Wed May 4 13:11:33 2011 From: sturla at molden.no (sturlamolden) Date: Wed, 4 May 2011 10:11:33 -0700 (PDT) Subject: Hooking into Python's memory management References: Message-ID: <7e324a8f-1eb8-4e4a-aa2c-f5ed741c7989@f2g2000yqf.googlegroups.com> On May 4, 6:51?pm, Daniel Neilson wrote: > ? In either case, if such a module is possible, any pointers you could > provide regarding how to implement such a module would be appreciated. The gc module will hook into the garbage collector. The del statement will remove an object from the current scope. (Delete the variable name and decrement the reference count.) Python (CPython that is) is reference counted. When the refcount drops to zero, the object is immediately garbage collected. Python is not like Java, where this happen in bouts. The __del__ method is executed deterministically, it's not like a finalizer in Java or C#. Only dead objects involved in reference circles may linger until they are spotted by the GC. And they may not have a __del__ method, or else the GC will ignore them. In fact, if you don't create circular references, the GC can safely be turned off. If you want volatile references, Python allows weak references as well. Sturla From benjamin.kaplan at case.edu Wed May 4 13:15:43 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 4 May 2011 13:15:43 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <29b1bdc8-7bff-445e-b660-53311ef1eb4d@p19g2000yqh.googlegroups.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <29b1bdc8-7bff-445e-b660-53311ef1eb4d@p19g2000yqh.googlegroups.com> Message-ID: On Wed, May 4, 2011 at 12:40 PM, sturlamolden wrote: > > On May 4, 5:40?pm, Michael Torrie wrote: > > > Which is exactly what the code showed. ?The first one isn't a mistake. > > You just read it wrong. > > No, I read "call-by-value" but it does not make a copy. Call-by-value > dictates a deep copy or copy-on-write. Python does neither. Python > pass a handle to the object, not a handle to a copy of the object. If > you want to see call-by-value in practice, take a look at MATLAB, > SciLab or Octave; or consider what C++ copy constructors do in > function calls with value types. You missed a word in the sentence. "If you can see this, you DON'T have call-by-value" From fred.sells at adventistcare.org Wed May 4 13:16:40 2011 From: fred.sells at adventistcare.org (Sells, Fred) Date: Wed, 4 May 2011 13:16:40 -0400 Subject: newbie needs help with cookielib In-Reply-To: References: Message-ID: I'm using Python 2.4 and 2.7 for different apps. I'm happy with a solution for either one. I've got to talk to a url that uses a session cookie. I only need to set this when I'm developing/debugging so I don't need a robust production solution and I'm somewhat confused by the docs on cookielib. I can use urllib2 without cookielib just fine, but need the cookie to add some security. I'm normally using Firefox 4.0 to login to the server and get the cookie. After that I need some way to set the same cookie in my python script. I can do this by editing my code, since I only need it while defeloping from my test W7 box. I was hoping to find something like ...set_cookie('mycookiename', 'myvalue', 'mydomain.org') I've googled this most of the morning and found everything but what I need, or I just don't understand the basic concept. Any pointers would be greatly appreciated. One of my false starts looks like this. But I get a ... File "C:\alltools\python26\lib\urllib2.py", line 518, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 500: Access Deinied def test1(): cj = cookielib.MozillaCookieJar() cj.load('C:/Users/myname/Desktop/cookies.txt') opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) r = opener.open("http://daffyduck.mydomain.org/wsgi/myapp.wsgi") print r.read() return From sturla at molden.no Wed May 4 13:19:50 2011 From: sturla at molden.no (sturlamolden) Date: Wed, 4 May 2011 10:19:50 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <29b1bdc8-7bff-445e-b660-53311ef1eb4d@p19g2000yqh.googlegroups.com> Message-ID: <4b8ec03d-ccec-4b20-86cc-1373fe5a46a6@p18g2000yqj.googlegroups.com> On May 4, 7:15?pm, Benjamin Kaplan wrote: > You missed a word in the sentence. > > "If you can see this, you DON'T have call-by-value" Indeed I did, sorry! Then we agree :) Sturla From ian.g.kelly at gmail.com Wed May 4 13:30:16 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 May 2011 11:30:16 -0600 Subject: Basic interaction with another program In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 10:52 AM, Grant Edwards wrote: > On 2011-05-04, Matty Sarro wrote: >> On Wed, May 4, 2011 at 12:34 PM, ETP wrote: >>> I have a dos program (run in a window) that I would like to control >>> with a script. > >> Look into the pexpect library, it'll make this easy as punch. > > I don't think pexpect is going to do the OP much good. Quoting from > the web page: > > ?"Pexpect does not currently work on the standard Windows Python" The OP said he was running Linux. I gather the DOS program is being run in DOSBox or something similar. From jjcpl.rpo at gmail.com Wed May 4 13:32:47 2011 From: jjcpl.rpo at gmail.com (Jerome jjcpl.rpo) Date: Wed, 4 May 2011 10:32:47 -0700 (PDT) Subject: Python Developers with 5 years of experience Message-ID: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> send resumes to jerome at jjcpl.net One of our client in New Jersey is looking for Python Developers with 5 years of experience. If you have any resumes please send it across. From tjreedy at udel.edu Wed May 4 13:57:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 13:57:02 -0400 Subject: A very minute correction on PDF In-Reply-To: <073456261C486944897A62516989111CACBC52EE7D@IN-MUM-MAIL2.corp.capgemini.com> References: <073456261C486944897A62516989111CACBC52EE7D@IN-MUM-MAIL2.corp.capgemini.com> Message-ID: <4DC1936E.3090304@udel.edu> On 5/4/2011 3:45 AM, Mehta, Pratik wrote: > For tutorialPython.pdf > Page 17 of the ebook (i.e. page 23 of pdf) under topic *3.2 First Steps > towards programming* > Under while loop, there should be a ?,? after print b > > Print b, > > (a comma after ?b? is missing) [You should mention versions when posting. Above is for 2.7] The example is consistent as it is. A trailing comma would suppress the newline after each output, resulting in a single line of output. 1 1 2 3 5 8 While you could argue that the combined change would be better, the author of the example did not think so. This introductory chapter only uses the simplest form of the print statement. -- Terry Jan Reedy From drsalists at gmail.com Wed May 4 14:06:37 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 4 May 2011 11:06:37 -0700 Subject: Hooking into Python's memory management In-Reply-To: <4DC1841B.2030601@gmail.com> References: <4DC1841B.2030601@gmail.com> Message-ID: Sturla had some great comments; I'll add, in no particular order: 1) You could use the ctypes module to call the real malloc and free from Python. 2) Yes, a Python "C extension module" can do explicit memory allocation. 3) Cython provides a language that is a hybrid of Python and C. It might be nice as a way of introducing explicit memory management. 4) You could also build a heap (not the tree kind, but the malloc kind) in pure Python, and give it alloc and destroy operations. Underneath it all, things would still be reference counted/garbage collected, but that wouldn't actually happen until you used your destroy. On Wed, May 4, 2011 at 9:51 AM, Daniel Neilson wrote: Part of our first year curriculum requires that students be exposed to > explicit dynamic memory allocation in the form of C++'s new/delete, C's > malloc/free, etc. I realize that Python is garbage collected, and that there > is never a need to explicitly allocate & deallocate objects. However, I am > trying to determine whether or not it is possible to simulate that behaviour > within Python via a module for the purposes of instruction. > > For these purposes, I would like to know whether it is possible within > Python 3 to write a Python-only module that, essentially, hooks into the > "constructor" and "destructor" of many of the Python built-in types > (specifically list, dictionary, set, tuple, and string) so that the module > can: > 1) Maintain a list of object id()'s for objects that have been created. > Ideally, this list would also contain the file & line number where the > object was created. > 2) Provide a "deallocate" function that will remove a given object's id() > from the list from (1). > 3) Print out an error message if the python script terminates with a > non-empty list from (1). Preferably with a list of objects that are still > "allocated." > > Baring a Python-only module, would this behaviour be possible to add via a > C-language module? > > A module that hooked in to all memory allocation, and inspected the type > of the object being allocated to conditionally add the object's id() to the > list would also suffice. > > In either case, if such a module is possible, any pointers you could > provide regarding how to implement such a module would be appreciated. > > Thank you for your time, > Daniel > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From as at sci.fi Wed May 4 14:06:49 2011 From: as at sci.fi (Anssi Saari) Date: Wed, 04 May 2011 21:06:49 +0300 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> <877hagoa0u.fsf@benfinney.id.au> <00dr88-846.ln1@svn.schaathun.net> <87mxj8ir4u.fsf@benfinney.id.au> <99e9a038-d203-49a9-8e2a-28f9e7d332a7@s16g2000prf.googlegroups.com> Message-ID: rusi writes: >> I actually use rcs in Windows. Needs a little setup, but works great, >> from Emacs VC-mode too. > > Where do you get it? > [What google is showing seems to be about 10-15 years old] As far as I know, RCS hasn't been updated since 5.7 which is about 10 years old now. Linux distributions also package the same version. I use the stuff from rcs57pc1.zip, at ftp://ftp.cs.purdue.edu/pub/RCS/ The package includes also comparison tools cmp, diff, diff3, sdiff as win32 versions. I suppose one would need to recompile if 64-bit versions were needed. The setup I mentioned was just setting RCSINIT to -x,v although I don't remember now why I needed that. From invalid at invalid.invalid Wed May 4 14:07:59 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 18:07:59 +0000 (UTC) Subject: Basic interaction with another program References: Message-ID: On 2011-05-04, Ian Kelly wrote: > On Wed, May 4, 2011 at 10:52 AM, Grant Edwards wrote: >> On 2011-05-04, Matty Sarro wrote: >>> On Wed, May 4, 2011 at 12:34 PM, ETP wrote: >>>> I have a dos program (run in a window) that I would like to control >>>> with a script. >> >>> Look into the pexpect library, it'll make this easy as punch. >> >> I don't think pexpect is going to do the OP much good. Quoting from >> the web page: >> >> ?"Pexpect does not currently work on the standard Windows Python" > > The OP said he was running Linux. My bad. When I saw that he wanted to run a DOS program, I jumped to the conclusion he was running Windows and missed the part about puppy linux. > I gather the DOS program is being run in DOSBox or something similar. If it's running in a window as the OP claims, Pexpect still won't work since when DOSBox or DOSEmu runs in a window it isn't reading commands from a pty but rather from X11. If he can get the program to run on a pty (e.g. console or xterm or whatever) rather than in a window, then Pexpect should work. -- Grant Edwards grant.b.edwards Yow! Are we wet yet? at gmail.com From python at rcn.com Wed May 4 14:17:12 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 4 May 2011 11:17:12 -0700 (PDT) Subject: Today's fun and educational Python recipe Message-ID: Here's a 22-line beauty for a classic and amazing algorithm: http://bit.ly/bloom_filter The wiki article on the algorithm is brief and well-written: http://en.wikipedia.org/wiki/Bloom_filter It turns out that people in the 1970's were pretty smart :-) Raymond ------- follow my other python tips and recipes on twitter: @raymondh From robert.kern at gmail.com Wed May 4 14:30:36 2011 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 04 May 2011 13:30:36 -0500 Subject: Pickling extension types In-Reply-To: References: Message-ID: On 5/4/11 10:45 AM, Stefan Kuzminski wrote: > I got this to work by returning from reduce just the args that the __init__ of > the type being pickled requires ( rather than the 5 length tuple described in > the pickling docs ), I am not going to argue with it though.. Let's take a step back. The documentation says to return a tuple between 2 and 5 elements long. You can omit the optional ones or use Nones in their place. The original code you posted allocated a 5-tuple, but did not insert anything into positions 2, 3, or 4. This was an error. You should have returned a 2-tuple of the type object in the 0-index slot and the argument tuple in the 1-index slot. Are you saying that you just returned the argument tuple? I don't think that would work. -- 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 ethan at stoneleaf.us Wed May 4 14:36:51 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 May 2011 11:36:51 -0700 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <4DC19CC3.30802@stoneleaf.us> Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. Don't know if you are still looking for examples, but I recently came across a thread in Python-Dev which had an example using unittest: Ricardo Kirkner wrote [much snippage]: > I'll give you the example I came upon: > > I have a TestCase class, which inherits from both Django's TestCase > and from some custom TestCases that act as mixin classes. So I have > something like > > class MyTestCase(TestCase, Mixin1, Mixin2): > ... > > Since I explicitely base off 3 classes, I expected all 3 > classes to be initialized, and I expect the setUp method to be called > on all of them. As written this example failed because TestCase (from django) was based on unittest2.TestCase, which was not calling super. I understand, however, that if the mixins were listed before TestCase that it would work. Hope this helps. ~Ethan~ From tjreedy at udel.edu Wed May 4 14:37:14 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 14:37:14 -0400 Subject: [ann] pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: On 5/4/2011 10:06 AM, Luke Kenneth Casson Leighton wrote: > after a long delay the pyjamas project - http://pyjs.org - has begun the > 0.8 series of releases, beginning with alpha1: > > https://sourceforge.net/projects/pyjamas/files/pyjamas/0.8/ > > pyjamas is a suite of projects, including a python-to-javascript > compiler As you well know, there is no such thing as 'python' when it comes to compiling actual code. So please specify both in announcements here and on the project homepage http://sourceforge.net/projects/pyjamas/ which versions are supported. I do not really want to have to download and experiment to determine whether to bother downloading. If you do not yet support 3.x, I request and recommend that you do so, even if only on Windows with comtypes. Since comtypes uses ctypes, I presume it works fine with Python 3 (this is one major advantage of using ctypes.) Like it or not, Python 3 is the future of Python. It is the Python that many Python newcomers learn first, and perhaps ever will. Such students usually have no experience or loyalty to any other GUI package, and I am sure that many would love to be able to develop apps that they can run on their desktop, give to friends to run in a browser, and run on their phones. -- Terry Jan Reedy From tjreedy at udel.edu Wed May 4 14:58:23 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 14:58:23 -0400 Subject: Hooking into Python's memory management In-Reply-To: <4DC1841B.2030601@gmail.com> References: <4DC1841B.2030601@gmail.com> Message-ID: <4DC1A1CF.3070002@udel.edu> On 5/4/2011 12:51 PM, Daniel Neilson wrote: > > Hello, > I'm hoping that there will be someone here with sufficient expertise to > answer a question on Python 3 for me. > > I work in the Computer Science department at a large Canadian > University. We are currently doing a feasibility analysis for switching > to using Python in our first year major-stream courses. If you did, I believe you would be following in the footsteps of MIT. > Part of our first year curriculum requires that students be exposed to > explicit dynamic memory allocation in the form of C++'s new/delete, C's > malloc/free, etc. I realize that Python is garbage collected, and that > there is never a need to explicitly allocate & deallocate objects. > However, I am trying to determine whether or not it is possible to > simulate that behaviour within Python via a module for the purposes of > instruction. The Python ctypes module allows one to invoke compiled C (or C++, I presume) functions in shared libraries (.dll on Windows, .so on *Nix). > For these purposes, I would like to know whether it is possible within > Python 3 to write a Python-only module that, essentially, hooks into the > "constructor" and "destructor" of many of the Python built-in types Python is compiled as a small startup executable (<30 KB). The builtins are all in shared libraries that you can access with ctypes. The functions in those libraries are documented in the Python/C API manual. > (specifically list, dictionary, set, tuple, and string) so that the > module can: > 1) Maintain a list of object id()'s for objects that have been created. > Ideally, this list would also contain the file & line number where the > object was created. > 2) Provide a "deallocate" function that will remove a given object's > id() from the list from (1). > 3) Print out an error message if the python script terminates with a > non-empty list from (1). Preferably with a list of objects that are > still "allocated." I presume you can do all of this easily. For point 3, a script can register an 'atexit' function. As a sidenote, using ctypes 'allows' one to crash (segfault, bluescreen) a program just like when using C ;-). It thus voids the usual guarantee that one cannot do that. > Baring a Python-only module, would this behaviour be possible to add via > a C-language module? I do not think you will *need* to do this, though you might eventually decide to make a custom library with just the functions you want, with the names you want. > A module that hooked in to all memory allocation, and inspected the type > of the object being allocated to conditionally add the object's id() to > the list would also suffice. > > In either case, if such a module is possible, any pointers you could > provide regarding how to implement such a module would be appreciated. I hope the above helps. I think Python is a great learning language. -- Terry Jan Reedy From irmen at -NOSPAM-xs4all.nl Wed May 4 15:02:17 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Wed, 04 May 2011 21:02:17 +0200 Subject: Today's fun and educational Python recipe In-Reply-To: References: Message-ID: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> On 04-05-11 20:17, Raymond Hettinger wrote: > Here's a 22-line beauty for a classic and amazing algorithm: > http://bit.ly/bloom_filter > > The wiki article on the algorithm is brief and well-written: > http://en.wikipedia.org/wiki/Bloom_filter > > It turns out that people in the 1970's were pretty smart :-) > I think that often, the cleverness of people is inversely proportional to the amount of CPU power and RAM that they have in their computer. "Meh, what would I need such a thing for, I could just as well stick everything into a list" Thankfully there are also people for whom this doesn't count. (are they stuck in the '70s?) Also: wasn't there a talk on Pycon in which a bloom filter was mentioned? Irmen From python at rcn.com Wed May 4 15:13:15 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 4 May 2011 12:13:15 -0700 (PDT) Subject: Today's fun and educational Python recipe References: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> Message-ID: <00cf6d1f-518e-4638-abdf-9db2cad0735b@q12g2000prb.googlegroups.com> > > It turns out that people in the 1970's were pretty smart :-) > > I think that often, the cleverness of people is inversely proportional > to the amount of CPU power and RAM that they have in their computer. The Google guys have plenty of CPU power *and* plenty of cleverness :-) According to the wikipedia article, Google BigTable uses Bloom filters to reduce the disk lookups for non-existent rows or column. The Google Chrome web browser also uses Bloom filters to speed up its Safe Browsing service. > Also: wasn't there a talk on Pycon in which a bloom filter was mentioned? Yes! As a matter of fact there was: http://www.slideshare.net/c.titus.brown/pycon-2011-talk-ngram-assembly-with-bloom-filters Raymond ------- follow my other python tips and recipes on twitter: @raymondh From tjreedy at udel.edu Wed May 4 15:15:24 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 15:15:24 -0400 Subject: Basic interaction with another program In-Reply-To: References: Message-ID: On 5/4/2011 12:34 PM, ETP wrote: > I have a dos program (run in a window) that I would like to control > with a script. Look at the subprocess module. You may have to (and be able to) have it start up the window program with the dos program as an argument. It needs only text input. For example, I only need to > tell it: > > L > u > 100 > u > You should be able to send this through a pipe connected to the subprocess. -- Terry Jan Reedy From invalid at invalid.invalid Wed May 4 15:17:19 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 19:17:19 +0000 (UTC) Subject: Today's fun and educational Python recipe References: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> Message-ID: On 2011-05-04, Irmen de Jong wrote: > On 04-05-11 20:17, Raymond Hettinger wrote: >> Here's a 22-line beauty for a classic and amazing algorithm: >> http://bit.ly/bloom_filter >> >> The wiki article on the algorithm is brief and well-written: >> http://en.wikipedia.org/wiki/Bloom_filter >> >> It turns out that people in the 1970's were pretty smart :-) >> > > I think that often, the cleverness of people is inversely > proportional to the amount of CPU power and RAM that they have in > their computer. True. Unfortunately the difficulty in debugging and maintaining code is often directly proportional to the cleverness exhibited by the original programmer. -- Grant Edwards grant.b.edwards Yow! I'm also against at BODY-SURFING!! gmail.com From harrismh777 at charter.net Wed May 4 15:22:38 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 14:22:38 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <7q1898-f3l.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: <3Ihwp.18043$Ot6.11759@newsfe15.iad> Hans Georg Schaathun wrote: > It only works by assuming > knowledge of C, which is language which has proved unsuitable for > complex and abstract data modelling. That statement is untrue; evidenced by the very fact the CPython's complex and abstract data modeling has been very suitably handled by C. You cannot possibly mean what you have asserted... I realize there must be a contextual problem. I have been handling complex data abstractions with C for more than 20 years... its quite well suited to the task... although, I am able to do my research today faster and with less lines of code in CPython. That does not in any way impugn C..;. quite the contrary, given enough time, C is better suited for modeling on a von Neumann processor, period. Here is the thing that everyone forgets... all we have to work with is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). Assembler is still the best language on that processor. 'C' is still the best high-level language on that processor. CPython is implemented in C for a reason: gcc and the von Neumann processor make it a no-brainer. Its silly to claim that one high-level language or another is better suited to complex data abstraction... don't go there. > Digging down into C should be unnecessary to explain Python. huh? You have to be kidding. Why do you suppose we want it to be open-sourced? Use the force Luke, read the source. If you really want to know how Python is working you *must* dig down into the C code which implements it. The folks who document Python should be able to tell us enough to know how to use the language, but to really 'know' you need the implementation source. kind regards, m harris From no.email at nospam.invalid Wed May 4 15:27:48 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 04 May 2011 12:27:48 -0700 Subject: Today's fun and educational Python recipe References: Message-ID: <7xy62mxo3v.fsf@ruckus.brouhaha.com> Raymond Hettinger writes: > Here's a 22-line beauty for a classic and amazing algorithm: > http://bit.ly/bloom_filter The use of pickle to serialize the keys is a little bit suspicious if there might be a reason to dump the filter to disk and re-use it in another run of the program. Pickle representation might change between Python releases, for example. It's just supposed to stay interoperable between versions, not necessarily bitwise-identical. Otherwise it's quite nice. I'd suggest adding a .update() operation that adds keys from a user-supplied iterator. From harrismh777 at charter.net Wed May 4 15:33:34 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 14:33:34 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Hans Georg Schaathun wrote: > In C it is pass by value, as the pointer > is explicit and do whatever you want with the pointer value. You clearly are not a C programmer. Most of my C data abstractions use dual circular linked lists of pointers to structures of pointers. *All* of that is only ever passed (at least in my programming) as references. My code almost never passes data by value. We do not consider passing a pointer as *by value* because its an address; by definition, that is pass-by-reference. We are not passing the *value* of the data, we are passing the memory location (the reference) to the data. Pass by *value* on the other hand actually places the *value* of the data item on the call stack as a parameter. Much of this conversation has more to do with semantics. kind regards, m harris From irmen at -NOSPAM-xs4all.nl Wed May 4 15:35:11 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Wed, 04 May 2011 21:35:11 +0200 Subject: Today's fun and educational Python recipe In-Reply-To: <00cf6d1f-518e-4638-abdf-9db2cad0735b@q12g2000prb.googlegroups.com> References: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> <00cf6d1f-518e-4638-abdf-9db2cad0735b@q12g2000prb.googlegroups.com> Message-ID: <4dc1aa6f$0$41102$e4fe514c@news.xs4all.nl> On 04-05-11 21:13, Raymond Hettinger wrote: >>> It turns out that people in the 1970's were pretty smart :-) >> >> I think that often, the cleverness of people is inversely proportional >> to the amount of CPU power and RAM that they have in their computer. > > The Google guys have plenty of CPU power *and* plenty of > cleverness :-) Haha, true. We need to add a Googlyness factor in the equation. Or perhaps: think what they could achieve if they only had a few machines instead of thousands ;-) >> Also: wasn't there a talk on Pycon in which a bloom filter was mentioned? > > Yes! As a matter of fact there was: > http://www.slideshare.net/c.titus.brown/pycon-2011-talk-ngram-assembly-with-bloom-filters Thanks, that was the one. I didn't attend Pycon but I watched a truckload of talks on blip.tv and that one caught my attention because of its somewhat funny title 'handling ridiculous amounts of data with probabilistic data structures' I didn't understand all of it but the name Bloom Filter stuck, it seems. Adding it to my list of bookmarks of useful-stuff-I-intend-to-use-one-day-in-the-future... Irmen From tjreedy at udel.edu Wed May 4 15:42:33 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 15:42:33 -0400 Subject: Today's fun and educational Python recipe In-Reply-To: References: Message-ID: On 5/4/2011 2:17 PM, Raymond Hettinger wrote: > Here's a 22-line beauty for a classic and amazing algorithm: > http://bit.ly/bloom_filter > > The wiki article on the algorithm is brief and well-written: > http://en.wikipedia.org/wiki/Bloom_filter As I understand the article, the array of num_bits should have num_probes (more or less independent) bits set for each key. But as I understand the code for i in range(self.num_probes): h, array_index = divmod(h, num_words) h, bit_index = divmod(h, 32) yield array_index, 1 << bit_index the same bit is being set or tested num_probes times. The last three lines have no dependence on i that I can see, so they appear to do the same thing each time. This seems like a bug. The article says "For a good hash function with a wide output, there should be little if any correlation between different bit-fields of such a hash, so this type of hash can be used to generate multiple "different" hash functions by slicing its output into multiple bit fields. Alternatively, one can pass k different initial values (such as 0, 1, ..., k ? 1) to a hash function that takes an initial value; or add (or append) these values to the key." I do not see the code doing either of these. -- Terry Jan Reedy From benjamin.kaplan at case.edu Wed May 4 15:46:07 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 4 May 2011 15:46:07 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <3Ihwp.18043$Ot6.11759@newsfe15.iad> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: On Wed, May 4, 2011 at 3:22 PM, harrismh777 wrote: > Hans Georg Schaathun wrote: >> >> It only works by assuming >> knowledge of C, which is language which has proved unsuitable for >> complex and abstract data modelling. > > ? That statement is untrue; evidenced by the very fact the CPython's complex > and abstract data modeling has been very suitably handled by C. > ? You cannot possibly mean what you have asserted... I realize there must be > a contextual problem. ?I have been handling complex data abstractions with C > for more than 20 years... its quite well suited to the task... although, I > am able to do my research today faster and with less lines of code in > CPython. ?That does not in any way impugn C..;. quite the contrary, given > enough time, ?C is better suited for modeling on a von Neumann processor, > period. > > ? Here is the thing that everyone forgets... all we have to work with is a > von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). Assembler is > still the best language on that processor. ?'C' ?is still the best > high-level language on that processor. ?CPython is implemented in C for a > reason: ?gcc and the von Neumann processor make it a no-brainer. > CPython is implemented in C because that's the language chosen. Python is also implemented in Java, C#, Python, and several other languages. And it's not tied to the von Neumann architecture either. Only the current implementations of it are. > ? Its silly to claim that one high-level language or another is better > suited to complex data abstraction... don't go there. > > >> Digging down into C should be unnecessary to explain Python. > > > ? huh? ? You have to be kidding. Why do you suppose we want it to be > open-sourced? ? Use the force Luke, read the source. ? If you really want to > know how Python is working you *must* dig down into the C code which > implements it. ?The folks who document Python should be able to tell us > enough to know how to use the language, but to really 'know' you need the > implementation source. > Reading the CPython sources will show you how CPython works under the hood, but it has nothing to do with how Python works. There are lots of things that CPython does that "Python" does not. For instance, the GIL is not a part of Python. Reference counting is not a part of Python. Caching small integers and strings is not a part of Python. Why not read the Jython sources instead of the CPython? It's the same language, after all. From harrismh777 at charter.net Wed May 4 15:47:35 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 14:47:35 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Devin Jeanpierre wrote: >> "How was the date last night?" >> > "Oh, it was marvelous! He presented me with a single red stink-weed, and >> > then we went to a disgusting little restaurant. I had the swill." > Please don't argue with me in this manner. D'Aprano takes a little getting used to. He likes strawmen, red-hearings, and the venerable bogus analogy. Just read around them, he usually has some good points in there... kind regards, m harris From hg at schaathun.net Wed May 4 15:58:01 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 20:58:01 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <9nn898-dnl.ln1@svn.schaathun.net> On Wed, 04 May 2011 14:22:38 -0500, harrismh777 wrote: : That statement is untrue; evidenced by the very fact the CPython's : complex and abstract data modeling has been very suitably handled by C. That's an implementation. Not modelling. : You cannot possibly mean what you have asserted... I realize there : must be a contextual problem. I have been handling complex data : abstractions with C for more than 20 years... I did not say that it is impossible. On the other hand, you are clearly not talking about abstraction or modelling at all, but rather about computation or data processing. : its quite well suited to : the task... although, I am able to do my research today faster and with : less lines of code in CPython. That does not in any way impugn C..;. : quite the contrary, given enough time, C is better suited for modeling : on a von Neumann processor, period. What has that got to do with abstraction? : Here is the thing that everyone forgets... all we have to work with : is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). : Assembler is still the best language on that processor. 'C' is still : the best high-level language on that processor. CPython is implemented : in C for a reason: gcc and the von Neumann processor make it a no-brainer. Again, what has that got to do with abstraction? : Its silly to claim that one high-level language or another is better : suited to complex data abstraction... don't go there. : : > Digging down into C should be unnecessary to explain Python. : : huh? You have to be kidding. Why do you suppose we want it to be : open-sourced? Python is a /language/. The /implementation/ is may be open-source (and may or may not be written in C). : Use the force Luke, read the source. If you really : want to know how Python is working you *must* dig down into the C code : which implements it. Except that whatever you learn by doing so is only valid for that one interpreter. -- :-- Hans Georg From harrismh777 at charter.net Wed May 4 15:58:38 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 14:58:38 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: Benjamin Kaplan wrote: > CPython is implemented in C because that's the language chosen. Python > is also implemented in Java, C#, Python, and several other languages. True enough. If I used Jython, I would want to take a look at those sources... as well as the Java sources... which were wrtten in, um, C. > And it's not tied to the von Neumann architecture either. Only the > current implementations of it are. Oh, yes they are. That is the $10,000,000 dollar problem... how to extricate ourselves from the von Neumann processor. *Everthing* comes down to that... its hilarious to hear folks talk about lambda the ultimate (especially those guys on Lambda the Ultimate) when there is no such thing until such time as we have lambda the hardware architecture. As long as we are all constrained to funnel data through the von Neumann ALU, that really is *all* that matters. Another way of saying this is that no matter how sophisticated our high level coding gets, it all has to be translated somehow one way or another into von Neumann codes toggling 1's and 0's on and off in the registers of the von Neumann ALU. > Reading the CPython sources will show you how CPython works under the > hood, but it has nothing to do with how Python works. Not conceptually, but practically. For instance, for a C programmer to see that Python's object references are C void pointers, tells the newbie Python ( C programmer ) much about how Python considers variables... as references... to objects. > There are lots > of things that CPython does that "Python" does not. For instance, the > GIL is not a part of Python. Reference counting is not a part of > Python. Caching small integers and strings is not a part of Python. This is not something I was aware of... caching of small ints is unique to CPython implementation only ?? I guess I'll have to go read the "sources" of the other implementations to check that out... ;-) > Why not read the Jython sources instead of the CPython? It's the same > language, after all. Yep. Agreed. .... on both counts. From invalid at invalid.invalid Wed May 4 16:19:05 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 20:19:05 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On 2011-05-04, harrismh777 wrote: > Hans Georg Schaathun wrote: >> In C it is pass by value, as the pointer is explicit and do whatever >> you want with the pointer value. > > You clearly are not a C programmer. > > Most of my C data abstractions use dual circular linked lists of > pointers to structures of pointers. *All* of that is only ever passed > (at least in my programming) as references. My code almost never > passes data by value. > > We do not consider passing a pointer as *by value* because its an > address; by definition, that is pass-by-reference. No, it isn't. It's pass by value. The fact that you are passing a value that is a pointer to another value is not relevent. Pass by reference means that if I call foo(x) And foo looks like this: foo(param) param = 4 Then 'x' in the caller's namespace ends up set to 4. > We are not passing the *value* of the data, we are passing the memory > location (the reference) to the data. You're pass a value. That value is a pointer to some other value. > Pass by *value* on the other hand actually places the *value* of the > data item on the call stack as a parameter. C is pass by value. if I call foo(x) And this is foo: void foo (float param) { param = 1.23 } The value of x in the caller's namespace is not changed. If C used pass by reference, x would change. -- Grant Edwards grant.b.edwards Yow! SHHHH!! I hear SIX at TATTOOED TRUCK-DRIVERS gmail.com tossing ENGINE BLOCKS into empty OIL DRUMS ... From hg at schaathun.net Wed May 4 16:20:54 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 21:20:54 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <62p898-ipl.ln1@svn.schaathun.net> On Wed, 04 May 2011 14:33:34 -0500, harrismh777 wrote: : Hans Georg Schaathun wrote: : > In C it is pass by value, as the pointer : > is explicit and do whatever you want with the pointer value. : : You clearly are not a C programmer. I am not really a programmer period. I am many things and run into programming from many more angles than a typical programmer does. And as to C, I no longer use C when I can avoid it (which I can most but not all of the time). A few words are missing though. C is semantically pass by value. Always. But because you have pointers are data object, you can do whatever you want with them, and pass a pointer by value. Thus you can achieve the effect of transmission by reference or by name, if you want to. : Most of my C data abstractions use dual circular linked lists of : pointers to structures of pointers. *All* of that is only ever passed : (at least in my programming) as references. My code almost never passes : data by value. Not if you do not consider pointers as data, but C does, in the sense that pointers can be manipulated in the same ways as any other kind of data. : We do not consider passing a pointer as *by value* because its an : address; by definition, that is pass-by-reference. We are not passing : the *value* of the data, we are passing the memory location (the : reference) to the data. Pass by *value* on the other hand actually : places the *value* of the data item on the call stack as a parameter. That is a useful viewpoint, but it falls a bit short when you need to explain how to deal with pointers to pointers to pointers. Pointers in C are objects. But mind you, I was not the one to suggested to refer to this as pass by value. I was explaining why it makes more sense to do so for C but not for Python. You simply end up with different wordings if you try to explain how C works, and how to model data in C. We can both be right, you know; we are just addressing the issues at different levels of abstraction. : Much of this conversation has more to do with semantics. Of course. The concepts are used to explain the semantics of the languages. -- :-- Hans Georg From drsalists at gmail.com Wed May 4 16:24:10 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 4 May 2011 13:24:10 -0700 Subject: Basic interaction with another program In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 9:34 AM, ETP wrote: > I have a dos program (run in a window) that I would like to control > with a script. It needs only text input. > > It will then wait for a file to be created, rename the file, then > loop. Simple. > Or not. > I'd like to run this on Lucid Puppy Linux as it will be implemented on > a very old laptop, but can probably deal with windows if needed. > Easiest would probably be to do this on Windows - not because of any inherent value in Windows, but because Microsoft limited what you could do to protect their own interests. I believe I once encountered a DOS emulator that could give curses output for non-graphical (no CGA, Hercules, EGA, or VGA) applications. It was ages ago. It probably was on SCO Xenix. You could try one of these, and then talk to your program over a serial port: http://en.wikipedia.org/wiki/PC_Weasel_2000 ...but I wouldn't count on it working well on a laptop. You could possibly set up a DOS box somewhere, and access it over a network from your laptop - depending on how the DOS program is doing its I/O. If it's writing directly to video RAM, good luck (other than the PC Weasel option), but if it's disciplined enough to use DOS or the BIOS for I/O, it might work pretty well. Your best option, if legally and economically viable, would be to get the source code to your DOS app and port it (or have it ported) to Linux. Back in the DOS days, Some programs were surprisingly easily ported to *ix. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hg at schaathun.net Wed May 4 16:40:43 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 4 May 2011 21:40:43 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: On Wed, 04 May 2011 14:58:38 -0500, harrismh777 wrote: : True enough. If I used Jython, I would want to take a look at those : sources... as well as the Java sources... which were wrtten in, um, C. And then, suddenly, you'll be developing code which fails on CPython instead of code which fails on Jython. Except that it will still fail on Jython too, unless you happen to have the right jvm. Marvelous. : Oh, yes they are. That is the $10,000,000 dollar problem... how to : extricate ourselves from the von Neumann processor. *Everthing* comes : down to that... its hilarious to hear folks talk about lambda the : ultimate (especially those guys on Lambda the Ultimate) when there is no : such thing until such time as we have lambda the hardware architecture. The problem with your approach is that software development does not scale. Assembly worked very well with a few 100 lines of codes half a century ago. C and friends were a great step forward and reduced the complexity to allow another magnitude of lines of codes. Then came further languages further removed from von Neumann, but close enough to human cognition to handle yet a magnitude or too. Of course you can still gain useful understanding by studying assembly or von Neumann, or the instruction set of the CPU you use. And in some projects it may be an optimal strategy. However, there are many skills necessary to make an efficient system and in many projects assembly and hardware skills are far down the list. Virtualisation is there to the cut costs of rethinking solutions for multiple architectures. If you need to understand the implementation to do your programming, you are in fact disregarding one of the most significant achievements deployed in computing the last two decades. : Not conceptually, but practically. For instance, for a C programmer : to see that Python's object references are C void pointers, tells the : newbie Python ( C programmer ) much about how Python considers : variables... as references... to objects. And of course, this is useful as /one/ way to consider python variables. As long as one is aware that this is just an example, one approach out of many, then it enhances understanding. If one blindly extrapolates from one implementation, it enhances misunderstanding. -- :-- Hans Georg From tacyt1007 at gmail.com Wed May 4 17:09:09 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Wed, 4 May 2011 23:09:09 +0200 Subject: Embedding Python's library as zip file Message-ID: Hello, I spent a lot of time googling for a solution of this problem, with no result. I have a C++ application, in which I would like to embed Python interpreter. I don't want to rely on an interpreter being installed on user machine, instead I would like to distribute all the necessary files with my app. As far as I understand, beside of my executable and Python.dll (I am using Python27), I need to provide two folders: - DLLs, - Lib If I place the Lib folder and the contents of the DLLs folder in a directory of my executable, then everything seems to work. However I would like to use a zipped Lib folder. Hence I made an archive (which contains contents of Lib folder) called Python27.zip. Unfortunately the app crashes during execution. I assume the reason might be lack of zlib.pyd. Is that assumption correct? If so, how to obtain it? If not, what am I doing wrong? Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From harrismh777 at charter.net Wed May 4 17:35:50 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 16:35:50 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Grant Edwards wrote: >> We do not consider passing a pointer as*by value* because its an >> > address; by definition, that is pass-by-reference. > No, it isn't. It's pass by value. The fact that you are passing a > value that is a pointer to another value is not relevent. > @ Edwards, &Schaathun You are most definitely mistaken. See: http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr233.htm I understand that semantically some people insist that when C receives parms as pointers that pass-by-reference is only being simulated. But that is the silliness of this argument... because down in the guts of the ALU we only have direct and indirect memory addressing. Period. You either pass a function the memory directly (value) or you pass the data indirectly (reference). Everything above that is high-level semantics. If I want to pass values to my C functions, I can. If I want to pass references to my C functions, I can. If I want to implement a C language that does not use pointers directly (hides them) I can implement pass by reference completely (on the surface). In fact, I can implement the C compiler so that pass by value is not allowed! [ it wouldn't look much like C, but its do-able ] Everyone forgets that their high-level language is not 'really' what's working... gcc does not produce machine code... it produces assembler instructions that are passed to a translator... you can interrupt the process and have it produce the assembly instructions so you can see them if you want to... the point being, after all is said and done, all you can do with today's von Neumann processors is pass data directly (value) or indirectly (reference). Everything else is semantics. From python at rcn.com Wed May 4 17:39:28 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 4 May 2011 14:39:28 -0700 (PDT) Subject: Today's fun and educational Python recipe References: Message-ID: On May 4, 12:42?pm, Terry Reedy wrote: > On 5/4/2011 2:17 PM, Raymond Hettinger wrote: > > > Here's a 22-line beauty for a classic and amazing algorithm: > >http://bit.ly/bloom_filter > > > The wiki article on the algorithm is brief and well-written: > >http://en.wikipedia.org/wiki/Bloom_filter > > As I understand the article, the array of num_bits should have > num_probes (more or less independent) bits set for each key. But as I > understand the code > > ? ? ? ? ?for i in range(self.num_probes): > ? ? ? ? ? ? ?h, array_index = divmod(h, num_words) > ? ? ? ? ? ? ?h, bit_index = divmod(h, 32) > ? ? ? ? ? ? ?yield array_index, 1 << bit_index > > the same bit is being set or tested num_probes times. The last three > lines have no dependence on i that I can see, so they appear to do the > same thing each time. This seems like a bug. The 512 bits in h are progressively eaten-up between iterations. So each pass yields a different (array index, bit_mask) pair. It's easy to use the interactive prompt to show that different probes are produced on each pass: >>> bf = BloomFilter(num_bits=1000, num_probes=8) >>> pprint(list(bf.get_probes('Alabama'))) [(19, 1073741824), (11, 64), (9, 134217728), (25, 1024), (24, 33554432), (6, 16), (7, 16777216), (22, 1048576)] The 512 bits are uncorrelated -- otherwise sha512 wouldn't be much of a cryptographic hash ;) The fifty state example in the recipe is a reasonable demonstration that the recipe works as advertised. It successfully finds all fifty states (the true positives) and it tries 100,000 negatives resulting in only a handful of false negatives. That should be somewhat convincing that it all works. Raymond ------- follow my other python tips and recipes on twitter: @raymondh From ben+python at benfinney.id.au Wed May 4 17:43:59 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 May 2011 07:43:59 +1000 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mxj2f8f4.fsf@benfinney.id.au> Steven D'Aprano writes: > Given the following statement of Python code: > > >>> x = "spam" > > what is the value of the variable x? Mu (?). ?x? is a name. Names are bound to values. Talk of ?variable? only confuses the issue because of the baggage carried with that term. Yes, the Python documentation disagrees with me. > (1) The string "spam". > I argue that any answer except for (1) is (almost always) counter- > productive: it adds more confusion than shedding light. I prefer to respond ?The name ?x? is bound to a string, "spam"?. (If I knew which version of Python we're using, I'd qualify the type as ?a text string? or ?a byte string?.) > It requires thinking at the wrong level, at the implementation level > instead of the level of Python code. If we define "value" to mean the > invisible, inaccessible reference, then that leaves no word to > describe was the string "spam" is. Fine, the value is the string. No problem there. But the data model of Python doesn't fit well with the ideas that the term ?variable? connotes for most programmers: a box, perhaps of a rigid shape (data type) or not, which is labelled ?x? and nothing else. For another variable to have an equal value, that value needs to be copied and put in a separate box; or perhaps some special reference to the original needs to be made and placed in a box. Saying ?variable? and ?has the value? just invites baggage needlessly, and creates many assumptions about Python's data model which has to be un-done, often after much false mental scaffolding has been built on them by the newbie and needs to be dismantled carefully. As we all know, Python doesn't work as the term ?variable? implies for many. Rather, ?x? isn't a container at all, but an identifier only. It's more like a paper tag which can be tied to objects; that brings a bunch of useful implications: * that the paper tag is tied to only one object * that a paper tag tied to no object is rather useless * that many paper tags can be tied to the same object * that the paper tag is only loosely associated with the object and can be removed and tied to a different object, without any change to the objects themselves * that the object doesn't necessarily have any tag at a given point in time * that the tag with its string is useful to find the object even without a name on the tag (the concept of other non-name bindings to objects, e.g. list items) All those implications of the ?paper tag? analogy are helpful in thinking about the Python data model. And those implications don't even have to be explicitly stated in order to help. So instead of inviting confusion with ?variable ?x? has the value "spam"? I prefer to say ?name ?x? is bound to the value "spam"?. > The intellectual contortions that some people will go through to > hammer the square peg of actual programming language behaviour into > the two round holes of "pass by value" and "pass by reference" never > cease to astonish me. I maintain that avoiding the use of the term ?variable?, and gently correcting those who use it in the context of Python (with humility in the face of the fact that the Python documentation liberally uses the term), can short-circuit a lot of that needless confusion. Python isn't pass by anything. Nothing gets copied, nothing gets passed; when a function is called with an object as a parameter, the object stays put, and simply gets a new temporary name bound to it for the function's use. Speaking of objects (or values) with names bound to them helps that explanation in a way that the traditional image of ?variables? does not. > > Whatever, a rose by any other name...) > > Do you really think that roses would be the symbol of romantic love if > they were called "disgusting stink-weeds of perversion and death"? Juliet's point stands, though: they would still smell as sweet, and the term you describe would be unlikely to catch on since it doesn't describe them well at all. -- \ ?I like to fill my bathtub up with water, then turn the shower | `\ on and pretend I'm in a submarine that's been hit.? ?Steven | _o__) Wright | Ben Finney From ben+python at benfinney.id.au Wed May 4 17:46:13 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 May 2011 07:46:13 +1000 Subject: Python Developers with 5 years of experience References: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> Message-ID: <87iptqf8be.fsf@benfinney.id.au> "Jerome jjcpl.rpo" writes: > One of our client in New Jersey is looking for Python Developers with > 5 years of experience. If you have any resumes please send it across. Please do not solicit for jobs here. Instead, the Python Job Board is intended for that purpose. -- \ ?The right to search for truth implies also a duty; one must | `\ not conceal any part of what one has recognized to be true.? | _o__) ?Albert Einstein | Ben Finney From harrismh777 at charter.net Wed May 4 17:49:25 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 16:49:25 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <9nn898-dnl.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <9nn898-dnl.ln1@svn.schaathun.net> Message-ID: Hans Georg Schaathun wrote: > That does not in any way impugn C..;. > : quite the contrary, given enough time, C is better suited for modeling > : on a von Neumann processor, period. > > What has that got to do with abstraction? Everything, really. Folks seem to think that because they are doing abstraction at a high-level (well, they never maybe programmed at a lower level) that abstraction somehow 'requires' a high level language. (not true) Back in the day, our abstractions were encapsulated not in source, but in psuedo-code, flow-charts, diagrams, and sometimes pretty pictures. It all ended up in assembly and machine code. Today, high-level languages like Python (and others) allow programmers to place some of their abstraction into their source code directly. This does not make the high-level language any more 'suited' to abstraction than any other lower-level language; because the abstraction is a mental process not a language feature. It all ends up in assembly and machine code. kind regards, m harris From nagle at animats.com Wed May 4 17:52:11 2011 From: nagle at animats.com (John Nagle) Date: Wed, 04 May 2011 14:52:11 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc1ca92$0$10552$742ec2ed@news.sonic.net> On 5/4/2011 3:51 AM, Steven D'Aprano wrote: > On Wed, 04 May 2011 02:56:28 -0700, Devin Jeanpierre wrote: > >> Python is pass-by-value in a >> meaningful sense, it's just that by saying that we say that the values >> being passed are references/pointers. This is maybe one level of >> abstraction below what's ideal, > > "Maybe"? > > Given the following statement of Python code: > >>>> x = "spam" > > what is the value of the variable x? Is it...? > > (1) The string "spam". > > (2) Some invisible, inaccessible, unknown data structure deep in the > implementation of the Python virtual machine, which the coder cannot > access in any way using pure Python code. > > (Possibly a pointer, but since it's an implementation detail, other > implementations may make different choices.) > > (3) Something else. > > > I argue that any answer except for (1) is (almost always) counter- > productive: it adds more confusion than shedding light. It requires > thinking at the wrong level, at the implementation level instead of the > level of Python code. If we define "value" to mean the invisible, > inaccessible reference, then that leaves no word to describe was the > string "spam" is. > > (I say "almost always" counter-productive because abstractions leak, and > sometimes you do need to think about implementation.) Yes. In Python, the main leak involves the "is" operator and the "id()" function. Consider: >>> x = "spam" >>> y = "spam" >>> x == y True >>> x is y True >>> z = x + 'a' >>> z = z[:4] >>> z 'spam' >>> x is z False >>> x == z True >>> id(x) 30980704 >>> id(y) 30980704 >>> id(z) 35681952 There, the abstraction has broken down. x, y, and z all reference the value "spam", but they reference two, not one or three, instances of it. Arguably, Python should not allow "is" or "id()" on immutable objects. The programmer shouldn't be able to tell when the system decides to optimize an immutable. "is" is more of a problem than "id()"; "id()" is an explicit peek into an implementation detail. The "is" operator is a normal part of the language, and can result in weird semantics. Consider >>> 1 is (1+1-1) True >>> 100000 is (100000+1-1) False That's a quirk of CPython's boxed number implementation. All integers are boxed, but there's a set of canned objects for small integers. CPython's range for this is -5 to +256, incidentally. That's visible through the "is" operator. Arguably, it should not be. John Nagle From python at rcn.com Wed May 4 17:53:35 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 4 May 2011 14:53:35 -0700 (PDT) Subject: Today's fun and educational Python recipe References: <7xy62mxo3v.fsf@ruckus.brouhaha.com> Message-ID: <555ea465-0faf-428b-bfe0-c51efbc2d07f@35g2000prp.googlegroups.com> On May 4, 12:27?pm, Paul Rubin wrote: > Raymond Hettinger writes: > > Here's a 22-line beauty for a classic and amazing algorithm: > >http://bit.ly/bloom_filter > > The use of pickle to serialize the keys is a little bit suspicious if > there might be a reason to dump the filter to disk and re-use it in > another run of the program. ?Pickle representation might change between > Python releases, for example. ?It's just supposed to stay interoperable > between versions, not necessarily bitwise-identical. > > Otherwise it's quite nice. ?I'd suggest adding a .update() operation > that adds keys from a user-supplied iterator. I chose pickle because it solved the problem of turning arbitrary objects into bytes which are needed as inputs to sha512. It seems that this particular choice of hash function is distracting some readers away from the interesting part of how a Bloom filter works. Since the choice of hash functions is completely arbitrary, I'm thinking of substituting something a little more basic. What do you think of this alternative as a way to make it clearer that each successive probe is uncorrelated, yet fully dependent on the key? def get_probes(self, key): hasher = Random(key).randrange num_words = len(self.arr) for _ in range(self.num_probes): array_index = hasher(num_words) bit_index = hasher(32) yield array_index, 1 << bit_index Raymond ------- follow my other python tips and recipes on twitter: @raymondh From invalid at invalid.invalid Wed May 4 17:57:29 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 May 2011 21:57:29 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On 2011-05-04, harrismh777 wrote: > Grant Edwards wrote: >>> We do not consider passing a pointer as*by value* because its an >>> > address; by definition, that is pass-by-reference. >> No, it isn't. It's pass by value. The fact that you are passing a >> value that is a pointer to another value is not relevent. >> > > @ Edwards, &Schaathun > > You are most definitely mistaken. The "pass by value" and "pass by reference" parameter passing mechanisms are pretty well defined, and C uses "pass by value". > I understand that semantically some people insist that when C > receives parms as pointers that pass-by-reference is only being > simulated. And they are right. > If I want to pass values to my C functions, I can. If I want to pass > references to my C functions, I can. We're not talking about what _you_ do. We're talking about what the C _compiler_ does. The C compiler passes by value -- always. > If I want to implement a C language that does not use pointers directly > (hides them) I can implement pass by reference completely (on the > surface). That wouldn't be C. > In fact, I can implement the C compiler so that pass by value is not > allowed! [ it wouldn't look much like C, but its do-able ] If you don't pass by value, it's not a C compiler. > Everyone forgets that their high-level language is not 'really' > what's working... gcc does not produce machine code... it produces > assembler instructions that are passed to a translator... you can > interrupt the process and have it produce the assembly instructions > so you can see them if you want to... the point being, after all is > said and done, all you can do with today's von Neumann processors is > pass data directly (value) or indirectly (reference). I have no idea what your point is. At the machine level, there _is_ nothing but values. You can use a value as an integer, or as a pointer. It's still just a value. But we're talking about parameter passing mechanisms defined by high-level language specifications -- particularly C. -- Grant Edwards grant.b.edwards Yow! It was a JOKE!! at Get it?? I was receiving gmail.com messages from DAVID LETTERMAN!! ! From ian.g.kelly at gmail.com Wed May 4 18:01:39 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 May 2011 16:01:39 -0600 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak wrote: > Hello, > > I spent a lot of time googling for a solution of this problem, with no > result. > > I have a C++ application, in which I would like to embed Python interpreter. > I don't want to rely on an interpreter being installed on user machine, > instead I would like to distribute all the necessary files with my app. > > As far as I understand, beside of my executable and Python.dll (I am using > Python27), I need to provide two folders: > ?- DLLs, > ?- Lib > > If I place the Lib folder and the contents of the DLLs folder in a directory > of my executable, then everything seems to work. > However I would like to use a zipped Lib folder. Hence I made an archive > (which contains contents of Lib folder) called Python27.zip. Unfortunately > the app crashes during execution. > I assume the reason might be lack of zlib.pyd. Is that assumption correct? > If so, how to obtain it? If not, what am I doing wrong? I believe zlib.pyd is statically linked into python27.dll nowadays. Some things to check: Can you import from zip files when running the Python.exe interpreter? Is the zip file included in sys.path? You might need to add this yourself after callying Py_Initialize(). Is there a top-level directory in the zip file that may be throwing the importer off? Are you getting any sort of error message? From matthew.moorland at gmail.com Wed May 4 18:21:33 2011 From: matthew.moorland at gmail.com (ETP) Date: Wed, 4 May 2011 15:21:33 -0700 (PDT) Subject: Basic interaction with another program References: Message-ID: Thanks everyone. I actually ran the program in question using Wine compatibility layer and it seemed to work fine. Terry, that looks like it could be useful, too. I'll give it a shot and let you guys know how it works. From ian.g.kelly at gmail.com Wed May 4 18:22:42 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 May 2011 16:22:42 -0600 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On Wed, May 4, 2011 at 3:35 PM, harrismh777 wrote: > Grant Edwards wrote: >>> >>> We do not consider passing a pointer as*by value* ?because its an >>> > ?address; by definition, that is pass-by-reference. >> >> No, it isn't. ?It's pass by value. ?The fact that you are passing a >> value that is a pointer to another value is not relevent. >> > > @ Edwards, &Schaathun > > You are most definitely mistaken. ? See: > > http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr233.htm That source actually supports the claim that pass-by-pointer falls under pass-by-value. It reads, in part (emphasis added): > In C++, the reference parameters are initialized with the actual arguments when the function is called. In C, the pointer parameters > are initialized with pointer _values_ when the function is called. However, I hope we can all agree that pass-by-pointer shares certain features with both pass-by-value and pass-by-reference, and there are perfectly reasonable arguments for lumping it in either category, yes? From ben+python at benfinney.id.au Wed May 4 19:33:54 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 May 2011 09:33:54 +1000 Subject: Today's fun and educational Python recipe References: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> Message-ID: <87ei4ef3bx.fsf@benfinney.id.au> Grant Edwards writes: > On 2011-05-04, Irmen de Jong wrote: > > I think that often, the cleverness of people is inversely > > proportional to the amount of CPU power and RAM that they have in > > their computer. > > True. > > Unfortunately the difficulty in debugging and maintaining code is > often directly proportional to the cleverness exhibited by the > original programmer. +1 QOTW -- \ ?Without cultural sanction, most or all of our religious | `\ beliefs and rituals would fall into the domain of mental | _o__) disturbance.? ?John F. Schumaker | Ben Finney From prologic at shortcircuit.net.au Wed May 4 20:13:21 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 5 May 2011 10:13:21 +1000 Subject: [OT]: PiCloud - really cool! Message-ID: If anyone hasn't seen this yet, I encourage you to! (I stumbled upon it with some random thoughts and Gooogling) http://www.picloud.com/ Here's a quick test I wrote up that works locally using the simulator and live (I did run it live): #!/usr/bin/env python import cloud def fib(n): a, b, = 1, 1 while n > 1: a, b = b, a + b n -= 1 return b #cloud.start_simulator() jobs = cloud.map(fib, range(100)) print [cloud.result(job) for job in jobs] Enjoy! :) cheers James -- -- James Mills -- -- "Problems are solved by method" From debatem1 at gmail.com Wed May 4 20:19:38 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 4 May 2011 17:19:38 -0700 Subject: [OT]: PiCloud - really cool! In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 5:13 PM, James Mills wrote: > If anyone hasn't seen this yet, I encourage you to! > (I stumbled upon it with some random thoughts and Gooogling) > > http://www.picloud.com/ > > Here's a quick test I wrote up that works locally using the simulator > and live (I did run it live): > > #!/usr/bin/env python > > import cloud > > def fib(n): > ? ?a, b, = 1, 1 > ? ?while n > 1: > ? ? ? ?a, b = b, a + b > ? ? ? ?n -= 1 > ? ?return b > > #cloud.start_simulator() > > jobs = cloud.map(fib, range(100)) > > print [cloud.result(job) for job in jobs] > > Enjoy! :) I was the poster across from them at PyCon two years back. Pretty fun to play with, although last I checked it was hard to do true HPC on it. Geremy Condra From tjreedy at udel.edu Wed May 4 20:26:51 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 May 2011 20:26:51 -0400 Subject: Today's fun and educational Python recipe In-Reply-To: References: Message-ID: On 5/4/2011 5:39 PM, Raymond Hettinger wrote: > The 512 bits in h are progressively eaten-up between iterations. So > each pass yields a different (array index, bit_mask) pair. Yeh, obvious now that I see it. > It's easy to use the interactive prompt to show that different probes > are produced on each pass: > >>>> bf = BloomFilter(num_bits=1000, num_probes=8) >>>> pprint(list(bf.get_probes('Alabama'))) > [(19, 1073741824), > (11, 64), > (9, 134217728), > (25, 1024), > (24, 33554432), > (6, 16), > (7, 16777216), > (22, 1048576)] Should have tried that. > The 512 bits are uncorrelated -- otherwise sha512 wouldn't be much of > a cryptographic hash ;) > The fifty state example in the recipe is a reasonable demonstration > that the recipe works as advertised. It successfully finds all fifty > states (the true positives) and it tries 100,000 negatives resulting > in only a handful of false negatives. I presume you mean 'false positives', as in the program comment and Wikipedia. The test would be more convincing to many with 100000 other geographic names (hard to come by, I know), or other english names or words or even with longer random strings that matched the lengths of the state names. But an average of 5/100000 false positives in 5 runs is good. -- Terry Jan Reedy From prologic at shortcircuit.net.au Wed May 4 20:29:20 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 5 May 2011 10:29:20 +1000 Subject: [OT]: PiCloud - really cool! In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 10:19 AM, geremy condra wrote: > I was the poster across from them at PyCon two years back. Pretty fun > to play with, although last I checked it was hard to do true HPC on > it. Why's that ? And what is true HPC (High Performance Computing) anyway ? I find the API provided to be quite simple robust and potentially very powerful - depending on your application. cheers James -- -- James Mills -- -- "Problems are solved by method" From debatem1 at gmail.com Wed May 4 20:45:21 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 4 May 2011 17:45:21 -0700 Subject: [OT]: PiCloud - really cool! In-Reply-To: References: Message-ID: On Wed, May 4, 2011 at 5:29 PM, James Mills wrote: > On Thu, May 5, 2011 at 10:19 AM, geremy condra wrote: >> I was the poster across from them at PyCon two years back. Pretty fun >> to play with, although last I checked it was hard to do true HPC on >> it. > > Why's that ? And what is true HPC (High Performance Computing) anyway ? > I find the API provided to be quite simple robust and potentially very > powerful - depending on your application. Last time I checked- and again, it's been a while- you were basically just able to run some (probably computationally bound) function on an EC2 instance that they managed for you without having any of the muss and fuss of doing it yourself. That's very cool, but there are problems where you really need more horsepower than a normal EC2 instance can provide, and if your application crosses that boundary after you've written it against PiCloud you're probably in the same hole you would have been without PiCloud. The other limitation is with problems that take a lot of input data, where it's more time intensive to ship the data across to EC2 than it is to just process it locally. Once more for effect: I haven't played with this in a while, the guys who built it seem pretty sharp, and it wouldn't surprise me at all to find out that they have ways of dealing with this better now. Geremy Condra From harrismh777 at charter.net Wed May 4 20:46:57 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 19:46:57 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc1ca92$0$10552$742ec2ed@news.sonic.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> Message-ID: <5smwp.309$BG2.230@newsfe08.iad> John Nagle wrote: > Arguably, Python should not allow "is" or "id()" on > immutable objects. The programmer shouldn't be able to tell when > the system decides to optimize an immutable. > > "is" is more of a problem than "id()"; "id()" is an explicit peek > into an implementation detail. Yes, yes, yes... and I'll go you one more... ... Python should optimize on *all* immutables when possible. For instance: a = (1,2,3) b = (1,2,3) a == b True a is b False To be consistent, in this case and others, a and b should reference the same immutable tuple. Or, as stated earlier, Python should not allow 'is' on immutable objects. kind regards, m harris From harrismh777 at charter.net Wed May 4 20:51:15 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 19:51:15 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <7wmwp.310$BG2.82@newsfe08.iad> Ian Kelly wrote: > However, I hope we can all agree that pass-by-pointer shares certain > features with both pass-by-value and pass-by-reference, and there are > perfectly reasonable arguments for lumping it in either category, yes? Yes. From harrismh777 at charter.net Wed May 4 21:11:02 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 20:11:02 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Grant Edwards wrote: > The "pass by value" and "pass by reference" parameter passing > mechanisms are pretty well defined, and C uses "pass by value". Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that helped define them.... The problem you're having here is that you're thinking of parameter passing 'mechanisms' and not focusing on the definition of the terms. A reference is a pointer (an address). A value is memory (not an address). These definitions go all the way back before the 8080, or the 6502, 8 bit processors. Pass by reference has 'always' meant pass by using a memory address (indirect addressing); a reference has always been a memory pointer. If I call a function in C, and pass-by-value, the data's 'value' is placed on the stack in a stack-frame, as a 'value' parm... its a copy of the actual data in memory. If I call a function in C, and pass-by-reference, the data's 'address' is placed on the stack in a stack-frame, as a 'reference' parm... no data is copied and the function must de-reference the pointer to get to the data.... this is by definition. There may be some language somewhere that does pass-by-reference which is not implemented under the hood as pointers, but I can't think of any... 'cause like I've been saying, way down under the hood, we only have direct and indirect memory addressing in today's processors. EOS. If you pass a parm, you can either pass a copy (value) or pass a reference to its location (not a copy, a reference). kind regards, m harris From python at rcn.com Wed May 4 21:15:05 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 4 May 2011 18:15:05 -0700 (PDT) Subject: Today's fun and educational Python recipe References: Message-ID: <1ba35556-6dd8-4ddb-a9ea-19d3ed3768bc@34g2000pru.googlegroups.com> On May 4, 5:26?pm, Terry Reedy wrote: > The test would be more convincing to many with 100000 other geographic > names (hard to come by, I know), or other english names or words or even > with longer random strings that matched the lengths of the state names. > But an average of 5/100000 false positives in 5 runs is good. I've just posted an update with a spell checker using a large dictionary. That should make it easy to validate against some real world text samples. Raymond From mhammond at skippinet.com.au Wed May 4 22:09:08 2011 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 05 May 2011 12:09:08 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4DC206C4.3070206@skippinet.com.au> On 5/05/2011 11:11 AM, harrismh777 wrote: >> The "pass by value" and "pass by reference" parameter passing >> mechanisms are pretty well defined, and C uses "pass by value". > > Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that helped define them.... Cool - please tell us more about your involvement in that. Obviously lots of people were in the industry then, but only a select few would be able to claim they helped define those terms. > There may be some language somewhere that does pass-by-reference which > is not implemented under the hood as pointers, but I can't think of > any... 'cause like I've been saying, way down under the hood, we only > have direct and indirect memory addressing in today's processors. EOS. What about Python, where passing an integer to a function passes a pointer to an int object, but that function is able to change the value of the variable locally without changing the passed object (indeed, it is impossible to change the passed integer)? So given the definitions above, Python uses a by-reference mechanism but (in some cases) has by-value semantics. While I understand exactly how things work (so don't need an explanation), the point is that for anything close to a high-level language, things aren't as black and white as they are for the low-level languages... Mark From rosuav at gmail.com Wed May 4 22:22:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 12:22:35 +1000 Subject: Today's fun and educational Python recipe In-Reply-To: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> References: <4dc1a2b9$0$41110$e4fe514c@news.xs4all.nl> Message-ID: On Thu, May 5, 2011 at 5:02 AM, Irmen de Jong wrote: > I think that often, the cleverness of people is inversely proportional to > the amount of CPU power and RAM that they have in their computer. As Mark Rosewater is fond of saying, restrictions breed creativity. Lack of computational resources is a major restriction (for an extreme example of RAM shortage, look at how much code you can fit into a boot sector without loading anything more from the disk). Take away all the restrictions, and people will tend to code sloppily. Chris Angelico From greg.ewing at canterbury.ac.nz Wed May 4 22:28:34 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 14:28:34 +1200 Subject: importing class objects from a pickled file In-Reply-To: References: Message-ID: <92egalFbk1U1@mid.individual.net> Catherine Moroney wrote: > I am having some problems reading the > object back out, as I get complaints about "unable to import module X". > > The only way I have found around it is to run the read-file code out of > the same directory that contains the X.py file > > Even when I put statements into the code such as "from Y.X import X" ... > the import statement works, but I am still unable to read the object Is the program that reads the pickle file the same one that was used to write it? If not, what might be happening is that the writing program has module X at the top level instead of inside package Y. Then it will get pickled simply under the name "X" instead of "Y.X", and the reading program will expect to find it at the top level as well. It's important that the reading and writing programs agree about the location of the pickled classes in the package namespace, unless you take steps to customise the pickling process. -- Greg From greg.ewing at canterbury.ac.nz Wed May 4 22:35:41 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 14:35:41 +1200 Subject: Fibonacci series recursion error In-Reply-To: References: <4dbbb7b6$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbe71d9$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92ego0Fe7vU1@mid.individual.net> Chris Angelico wrote: > There's definitely something attractive about that letter. Lots of > programming languages' names start with P. Including one I invented some years ago, that (in the spirit of C and its derivatives) was called simply "P". (I was playing around with Sun's NeWS window server, which was programmed in Postscript, and I got fed up with Forth-like syntax, so I wrote a translator that took an infix language and generated Postscript from it.) -- Greg From rosuav at gmail.com Wed May 4 22:43:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 12:43:04 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <87mxj2f8f4.fsf@benfinney.id.au> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> Message-ID: On Thu, May 5, 2011 at 7:43 AM, Ben Finney wrote: > * that the paper tag is tied to only one object > > * that a paper tag tied to no object is rather useless > > * that many paper tags can be tied to the same object I disagree minorly; a tag tied to no object is quite useful in some circumstances. You can ditch the concept by having a special object that's called "No Object" (Python does this, with None), or you can allow your tag to point nowhere (C does this, with null pointers). The difference is semantic; either way, your tag can point to any object or it can point nowhere. (Pike goes for a slightly different approach; any variable, regardless of its stated types, may legally hold the integer 0. It acts somewhat as a null pointer, but it isn't really.) Chris Angelico From greg.ewing at canterbury.ac.nz Wed May 4 23:16:45 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 15:16:45 +1200 Subject: Hooking into Python's memory management In-Reply-To: References: Message-ID: <92ej51Ft7kU1@mid.individual.net> Daniel Neilson wrote: > 1) Maintain a list of object id()'s for objects that have been created. > Ideally, this list would also contain the file & line number where the > object was created. > 2) Provide a "deallocate" function that will remove a given object's > id() from the list from (1). > 3) Print out an error message if the python script terminates with a > non-empty list from (1). Preferably with a list of objects that are > still "allocated." I don't think this will work out quite the way you seem to be imagining. Consider that Python creates a lot of objects behind the scenes without you doing anything specific to "allocate" them. Examples include the dicts holding module and class namespaces, all the strings representing names in loaded code, ints, floats and strings representing literals in the code, etc. If you automatically add any object of any of these types to the "allocated" list, these implicitly-created objects will all still be present in it when the program terminates, and the student will be told off for failing to deallocate them. An alternative might be to provide an allocate() function which the student is expected to use on any explicitly-created object. But there wouldn't be any way of enforcing this. Personally I think the whole idea is misguided, and it would be better to teach these concepts in the context of a language where they actually matter, which these days more or less means C. If teaching C in the first year in parallel with Python is considered too steep, then leave explicit memory management until later in the curriculum. (It's really a shame that Pascal is not taught any more. It provided a fairly clean environment for teaching about things like this, without getting so close to the machine that you get your nosed rubbed in segfaults.) -- Greg From timr at probo.com Wed May 4 23:23:36 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 04 May 2011 20:23:36 -0700 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: harrismh777 wrote: > >If I call a function in C, and pass-by-value, the data's 'value' is >placed on the stack in a stack-frame, as a 'value' parm... its a copy of >the actual data in memory. > >If I call a function in C, and pass-by-reference, the data's 'address' >is placed on the stack in a stack-frame, as a 'reference' parm... no >data is copied and the function must de-reference the pointer to get to >the data.... this is by definition. This is not correct. Consider an example. int BumpMe( int * a ) { return *a+3; } int Other() { int x = 9; return BumpMe( &x ); } That is not an instance of passing an "int" by reference. That is an instance of passing an "int *" by value. The fact that the parameter "a" in BumpMe happens to be an address is completely irrelevent to the definition of the parameter passing mechanism. C has pass-by-value, exclusively. End of story. >There may be some language somewhere that does pass-by-reference which >is not implemented under the hood as pointers, but I can't think of >any... Fortran had genuine pass-by-reference. In Fortran, you could write a program like this: SUBROUTINE CONFUSION(IVALUE) INTEGER IVALUE IVALUE = IVALUE + 1 END PROGRAM MAIN CONFUSION(4) END That program would actually modify the value of the constant 4. Such an abomination is simply not possible in C. Is that implemented under-the-hood with pointers/addresses? Of course it is. However, that does not change the parameter passing model as defined by the language specification. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From greg.ewing at canterbury.ac.nz Wed May 4 23:48:51 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 15:48:51 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92el16F9kaU1@mid.individual.net> Hans Georg Schaathun wrote: > Is transmission by name the same as call by object? No, it's not. With call-by-name, the caller passes a small function (known as a "thunk") that calculates the address of the parameter. Every time the callee needs to refer to the parameter, it evaluates this function. This allows some neat tricks, but it's massive overkill for most uses. In later languages, the functionality of call-by-name has been replaced by the ability to explicitly pass functions as parameters. > Anyway, I have never seen anyone counting more than > three ways of doing this ... There are other possibilities, such as value-result, where a local copy is made and its final value is copied back before returning. I think Fortran is defined in such a way that this is an acceptable way of implementing parameter passing. It's also the only way of getting anything akin to by-reference over an RPC connection. But for most situations, by-value and by-reference cover anything you might want to do. And if you have a dynamic data model like Python, you don't even need by-reference. -- Greg From harrismh777 at charter.net Thu May 5 00:01:13 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 23:01:13 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Mark Hammond wrote: > What about Python, where passing an integer to a function passes a > pointer to an int object, but that function is able to change the value > of the variable locally without changing the passed object (indeed, it > is impossible to change the passed integer)? > > So given the definitions above, Python uses a by-reference mechanism but > (in some cases) has by-value semantics. Yeah, Mark, the trouble is that the concepts (by-value, or by-reference) have morphed into a concept(s) that say something of what should or should not happen within scopes (or, in the case of Python, namespaces) and says something less about what 'reference' or 'value' mean as terms for data. So, again, its semantics... not black and white, as you say and some of both|and. If C were 'strictly' pass-by-value (that is what the K&R states, sec. 1.8, p27 2nd ed) and had no concept of indirect memory addressing (memory references is what we called them in the early days ca. 1970~) in the form of pointers, then all of this semantic discussion would be mute. But, 'C' does provide for pointers which are used by all 'C' programmers to firmly provide pass-by-reference in their coding (C++ also, by the way). My 'C' functions can most definitely modify the parms passed in from their calling functions by simply 'de-referencing' the parms. This is done all the time--- and a good thing too, since nobody would want to pass a list by value, or worse yet a linked list with a couple of thousand nodes, by value. So, I argue that its silly to say that because the parameter passing 'mechanism' of the 'C' language is pass-by-value (see K&R) that 'C' is a pass-by-value language, when clearly 'C' programmers use pass-by-reference routinely in their 'C' coding. This is quite different than some flavors of Fortran or Pascal where the called routines had access to the original vars--- which had more to do with scope than it did with parameter passing or indirection. In 'C' if I want to I can live with pass-by-value... or, I can live with pass-by-reference nicely... and its up to me... not language constraints. Again, it seems that some folks want to pigeon hole this concept into one or the other (and it clearly can be) but usually it is a combination of the two (both | and). kind regards, m harris From tooscattered at gmail.com Thu May 5 00:06:02 2011 From: tooscattered at gmail.com (scattered) Date: Wed, 4 May 2011 21:06:02 -0700 (PDT) Subject: Hooking into Python's memory management References: Message-ID: <015aefbf-8c86-48ee-aec9-8368b11cca0a@p13g2000yqh.googlegroups.com> On May 4, 12:51?pm, Daniel Neilson wrote: > Hello, > ? I'm hoping that there will be someone here with sufficient expertise > to answer a question on Python 3 for me. > > ? I work in the Computer Science department at a large Canadian > University. We are currently doing a feasibility analysis for switching > to using Python in our first year major-stream courses. > > ? Part of our first year curriculum requires that students be exposed to > explicit dynamic memory allocation in the form of C++'s new/delete, C's > malloc/free, etc. I realize that Python is garbage collected, and that > there is never a need to explicitly allocate & deallocate objects. > However, I am trying to determine whether or not it is possible to > simulate that behaviour within Python via a module for the purposes of > instruction. > > ? For these purposes, I would like to know whether it is possible within > Python 3 to write a Python-only module that, essentially, hooks into the > "constructor" and "destructor" of many of the Python built-in types > (specifically list, dictionary, set, tuple, and string) so that the > module can: > ? 1) Maintain a list of object id()'s for objects that have been > created. Ideally, this list would also contain the file & line number > where the object was created. > ? 2) Provide a "deallocate" function that will remove a given object's > id() from the list from (1). > ? 3) Print out an error message if the python script terminates with a > non-empty list from (1). Preferably with a list of objects that are > still "allocated." > > ? Baring a Python-only module, would this behaviour be possible to add > via a C-language module? > > ? A module that hooked in to all memory allocation, and inspected the > type of the object being allocated to conditionally add the object's > id() to the list would also suffice. > > ? In either case, if such a module is possible, any pointers you could > provide regarding how to implement such a module would be appreciated. > > Thank you for your time, > ? Daniel Maybe you can simulate a heap. Create a heap class where a heap-object maintains an internal list of fixed length (whose length is determined by a constructor)for its heap and a list of free blocks in this heap. It can have methods for allocating and deallocating objects in the heap. Perhaps some sort of dictionary with strings representing pointers as keys and indices of corresponding allocated blocks as values. Subscript-out of range errors in the internal heap would correspond to segmentation errors. The heap-class could catch this error and inform the student. It could also have methods which catch things like dangling pointers and memory leaks. Perhaps a method to display a schematic of the heap. Maybe something as simple as printing something like |||||____|||__|||______||||____________ where ||| represents used blocks and ____ represents free space. Displaying this could show the problem of heap-fragmentation. Once you get the interface down - assign some homework where the students need to implement a simple algorithm which requires dynamic memory alocation. The catch is that the students are forbidden from using things like Python lists directly in their code but instead have to get by with using a single instance of this heap object for their data storage needs. Make a bit of a game out of it. I obviously haven't worked out the details, but I suspect that this sort of thing is both easier and more pedagogically sound (since you can tailor the error messages) then what you were looking for. From nagle at animats.com Thu May 5 00:32:59 2011 From: nagle at animats.com (John Nagle) Date: Wed, 04 May 2011 21:32:59 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <5smwp.309$BG2.230@newsfe08.iad> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> Message-ID: <4dc22882$0$10557$742ec2ed@news.sonic.net> On 5/4/2011 5:46 PM, harrismh777 wrote: > John Nagle wrote: >> Arguably, Python should not allow "is" or "id()" on >> immutable objects. The programmer shouldn't be able to tell when >> the system decides to optimize an immutable. >> >> "is" is more of a problem than "id()"; "id()" is an explicit peek >> into an implementation detail. > > Yes, yes, yes... and I'll go you one more... > > ... Python should optimize on *all* immutables when possible. > > > For instance: > > a = (1,2,3) > b = (1,2,3) > > a == b True > > a is b False > > To be consistent, in this case and others, a and b should reference > the same immutable tuple. Actually, that's not necessarily an "optimization". The cost of looking up small tuples is probably higher than creating them. There's also a potential optimization of duplicating tuples in use by different threads, to reduce locking effort. (CPython's global lock is too dumb to exploit this, but there are other ways to do it.) > > > Or, as stated earlier, Python should not allow 'is' on immutable objects. A reasonable compromise would be that "is" is treated as "==" on immutable objects. John Nagle From harrismh777 at charter.net Thu May 5 00:55:39 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 04 May 2011 23:55:39 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Tim Roberts wrote: > The fact that the parameter "a" > in BumpMe happens to be an address is completely irrelevent to the > definition of the parameter passing mechanism. > > C has pass-by-value, exclusively. End of story. Yeah, Tim, I know... but that's my entire point in a nut-shell... whether the language is pass-by-value or pass-by-reference has less to do with how it is 'defined' (its mechanism--- indirection and stack) and more to do with how it is routinely used with the standard features it provides--- in this case memory indirection--- as pointers. Something new here, just for fun... ... I ran my hello.c program through the gcc compiler and intercepted its assembly source output. Some folks on the list may not know that the gcc compiler used to generate CPython (at least on *nix systems) does not generate object or machine code directly, but generates an intermediate assembly source in AT&T syntax. The assembly code is interesting for the discussion, if you've never seen it. If you have, blow this off. Anyway, I built a small wrapper called 'say()' around the printf function, so that I could pass a string var to say(), and I then called it a couple of times in main(). The assembly source code is listed at the end of this post. The thing to notice here is two things: 1) assembly code is actually being used to generate the machine code, not 'C' (and this is true for Python as well, compiled from sources) In other words, Python interpreter does not do anything more (nor less) than what can be done with assembler (nor machine code for that matter). And, 2) The strings I am 'passing' to the say() function don't get 'passed' anywhere. (I know that most of you know this, bear with me) The strings are set in memory, and through memory indirection pointers (the parenthesis 'references') the string's memory addresses are placed on the stack. The called routine say() has full access to the original strings in memory (via their memory addresses) if necessary. The main point being that the say() function has a 'reference' to the original, and not a local copy of the 'value', and it can change it! The string's addresses are .LC0 and .LC1/ Here is the assembly of my hello.c saved as hello.s with: gcc -Wall -S -o hello.s hello.c .file "hello.c" .section .rodata .LC0: .string "\nhello, world!\n" .align 4 .LC1: .string "...and again I say, hello there, world!\n\n" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp andl $-16, %esp subl $32, %esp movl $0, 28(%esp) movl $.LC0, (%esp) call say movl $.LC1, (%esp) call say movl 28(%esp), %eax leave ret .size main, .-main .section .rodata .LC2: .string "%s" .text .globl say .type say, @function say: pushl %ebp movl %esp, %ebp subl $24, %esp movl $.LC2, %eax movl 8(%ebp), %edx movl %edx, 4(%esp) movl %eax, (%esp) call printf leave ret .size say, .-say .ident "GCC: (Ubuntu 4.4.1-4ubuntu9) 4.4.1" .section .note.GNU-stack,"", at progbits From hg at schaathun.net Thu May 5 00:58:51 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 5 May 2011 05:58:51 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <92el16F9kaU1@mid.individual.net> Message-ID: On Thu, 05 May 2011 15:48:51 +1200, Gregory Ewing wrote: : No, it's not. With call-by-name, the caller passes a : small function (known as a "thunk") that calculates the : address of the parameter. Every time the callee needs to : refer to the parameter, it evaluates this function. Well, call-by-name is not the same as transmission by name either. Transmission by name is what most posters here call call by reference, and transmission by reference is what this thread calls object sharing or call by object. No wonder I started off confused :-) It is better now. -- :-- Hans Georg From harrismh777 at charter.net Thu May 5 01:19:36 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 00:19:36 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Dennis Lee Bieber wrote: >> > We do not consider passing a pointer as*by value* because its an >> > address; by definition, that is pass-by-reference. We are not passing > To most of the world, pass-by-reference means the COMPILER, not the > PROGRAMMER is obtaining and passing the address, and the compiler also > always dereferences the passed "value"... The programmer has no control > over whether to operate on the address or the data referenced by the > address. Who is "most of the world" ? Please see: http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr233.htm From ddneilson at gmail.com Thu May 5 01:30:47 2011 From: ddneilson at gmail.com (Daniel Neilson) Date: Wed, 04 May 2011 23:30:47 -0600 Subject: Hooking into Python's memory management In-Reply-To: <4DC1841B.2030601@gmail.com> References: <4DC1841B.2030601@gmail.com> Message-ID: <4DC23607.1020407@gmail.com> Thanks for the feedback, everyone. I spent some time today playing around with the gc module, and came to the same conclusion that many of you have as well. for o in gc.get_objects(): print(o) was sufficient to convince me that I didn't want to go that route. Writing a simple memory pool/heap that students will have to use to allocate/deallocate objects of a particular type definitely seems the way to go. It will get the ideas across, and allow them to contrast the garbage collection and explicit memory management paradigms. -Daniel From no.email at nospam.invalid Thu May 5 01:50:37 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 04 May 2011 22:50:37 -0700 Subject: Python Developers with 5 years of experience References: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> <87iptqf8be.fsf@benfinney.id.au> Message-ID: <7x1v0dwv9u.fsf@ruckus.brouhaha.com> Ben Finney writes: > Please do not solicit for jobs here. Instead, the Python Job Board > is intended for that purpose. Wow, there's quite a lot of listings there. There had been only a few last time I looked. But, most of them seem to involve Django. From hg at schaathun.net Thu May 5 02:12:16 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 5 May 2011 07:12:16 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <9nn898-dnl.ln1@svn.schaathun.net> Message-ID: <0nr998-oen.ln1@svn.schaathun.net> On Wed, 04 May 2011 16:49:25 -0500, harrismh777 wrote: : Folks seem to think that because they are doing abstraction at a : high-level (well, they never maybe programmed at a lower level) that : abstraction somehow 'requires' a high level language. (not true) I never said 'requires', but when you do high-level modelling, low-level detail is a distraction. Using a low-level language for abstract modelling is therefore harder than it needs to be. : Today, high-level languages like Python (and others) allow programmers : to place some of their abstraction into their source code directly. This : does not make the high-level language any more 'suited' to abstraction : than any other lower-level language; because the abstraction is a mental : process not a language feature. It all ends up in assembly and machine : code. Indeed, except for the contradiction. The fact that you can put more of your abstraction into the source code means that it is better suited to abstraction. Mental processes depend on language; at least when you need to communicate the output. That language does not have to be computer readable (as is the case for your float charts etc). We may very well use a stack of languages and models at different levels of abstraction, but when you move down the stack you are moving away from abstraction and into implementation. C is very rarely suitable at the top of this stack. When I say that C is ill-suited for abstraction, I am not implying that it is ill-suited for implementing according to an abstract model. If you need human input in the lower layers of abstraction, C is a good choice. Using manual work to move down the layers of abstraction is possible, and given sufficient man-power should give the better result, but relying on human input when the work can be automated is ridiculously expensive. Now, python is only one level above C in abstraction, but that's a different matter. -- :-- Hans Georg From srikrishnamohan at gmail.com Thu May 5 02:18:57 2011 From: srikrishnamohan at gmail.com (km) Date: Thu, 5 May 2011 11:48:57 +0530 Subject: Python Developers with 5 years of experience In-Reply-To: <87iptqf8be.fsf@benfinney.id.au> References: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> <87iptqf8be.fsf@benfinney.id.au> Message-ID: probably it is good to post jobs in python-list itself rather than posting it on someother site. Many mailing lists do that. It gives a feel of what jobs we come across for the Python developers. KM On Thu, May 5, 2011 at 3:16 AM, Ben Finney wrote: > "Jerome jjcpl.rpo" writes: > > > One of our client in New Jersey is looking for Python Developers with > > 5 years of experience. If you have any resumes please send it across. > > Please do not solicit for jobs here. Instead, the Python Job Board > is intended for that > purpose. > > -- > \ ?The right to search for truth implies also a duty; one must | > `\ not conceal any part of what one has recognized to be true.? | > _o__) ?Albert Einstein | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hg at schaathun.net Thu May 5 02:34:09 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 5 May 2011 07:34:09 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <10t998-cgn.ln1@svn.schaathun.net> On Wed, 04 May 2011 20:11:02 -0500, harrismh777 wrote: : A reference is a pointer (an address). : : A value is memory (not an address). Sure, and pointers (from a hardware or C perspective) are memory, hence pointers are values. -- :-- Hans Georg From r.drew.davis at gmail.com Thu May 5 04:15:05 2011 From: r.drew.davis at gmail.com (Drew) Date: Thu, 5 May 2011 01:15:05 -0700 (PDT) Subject: python on iPad (PyPad) References: <4d9feaea$0$29996$c3e8da3$5496439d@news.astraweb.com> <57cb7f7c-922c-4913-8603-ccd138e0d3be@r6g2000vbz.googlegroups.com> Message-ID: On Apr 10, 1:48?am, Matt Schinckel wrote: > On Apr 9, 2:13?pm, Jon Dowdall wrote: > > > Hi All, > > > Sorry for the blatant advertising but hope some of you may be interested > > to know that I've created an iPad application containing the python > > interpreter and a simple execution environment. It's available in iTunes > > athttp://itunes.apple.com/us/app/pypad/id428928902?mt=8# > > > I wanted to have python available 'on the go' without carrying a laptop. > > The current implementation is based on my need to test simple python > > functions in an isolated environment. I hope to add more iOS specific > > capabilities if there is enough interest. > > > Enjoy... > > > Jon Dowdall > > I know this sound shallow, but you really need a nicer icon. > > Otherwise, I'm quite excited about this. It will certainly be better > than my current workflow of connecting via ssh to a server just to run > python code. > > Matt. There's a Pypad on SourceForge, but it is flagged as no longer under active development. Dead or just sleeping? Is this Pypad distinct from that old one on SourceForge? Or a revival? OpenSource? Drew From greg.ewing at canterbury.ac.nz Thu May 5 04:55:36 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 20:55:36 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <9fd898-0el.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> Message-ID: <92f70aF9pqU1@mid.individual.net> Hans Georg Schaathun wrote: > With the references being > purely abstract entities and not data objects, It's not clear to me that references are any more abstract than objects, or to put it another way, that objects are any less abstract than references. After all, in normal Python usage you never actually *see* an object -- at best you see some string of characters resulting from the str() or repr() of an object. The object is a mental construct we use to make sense of the behaviour we're seeing, as are references. If you were to look inside the interpreter closely enough to see the concrete representations of objects -- the bit patterns in memory making them up -- then you would also be able to see the bit patterns making up the references. -- Greg From greg.ewing at canterbury.ac.nz Thu May 5 05:08:11 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 21:08:11 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <3Ihwp.18043$Ot6.11759@newsfe15.iad> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <92f7nuFfhhU1@mid.individual.net> harrismh777 wrote: > 'C' is still the best high-level language on that processor. Some would argue that C is actually better than assembler these days, because modern architectures are so freaking complicated that it takes a computer to figure out the best instruction sequence. :-( -- Greg From rosuav at gmail.com Thu May 5 05:12:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 19:12:57 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <92f7nuFfhhU1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <92f7nuFfhhU1@mid.individual.net> Message-ID: On Thu, May 5, 2011 at 7:08 PM, Gregory Ewing wrote: > harrismh777 wrote: >> >> 'C' ?is still the best high-level language on that processor. > > Some would argue that C is actually better than assembler these > days, because modern architectures are so freaking complicated > that it takes a computer to figure out the best instruction > sequence. :-( I use C to hint to the compiler as to what I'd like it to write a program to do. It does all the writing, I just make some vague suggestions - which it's free to ignore if it chooses. GCC and me, we get along jess fine... ChrisA From greg.ewing at canterbury.ac.nz Thu May 5 05:31:52 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 21:31:52 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <92f94aFploU1@mid.individual.net> harrismh777 wrote: > That is the $10,000,000 dollar problem... how to > extricate ourselves from the von Neumann processor. *Everthing* comes > down to that... its hilarious to hear folks talk about lambda the > ultimate (especially those guys on Lambda the Ultimate) when there is no > such thing until such time as we have lambda the hardware architecture. I think there are fundamental problems that go beyond the issue of hardware design. It's easy to reason about a program that does things one step at a time, much harder when lots of things are happening at once. Whether you express the program using lambda calculus or a Turing machine doesn't change that fact. -- Greg From alexander at lyabah.com Thu May 5 05:43:28 2011 From: alexander at lyabah.com (Alexander Lyabah) Date: Thu, 5 May 2011 02:43:28 -0700 (PDT) Subject: Python competitions and learnings References: Message-ID: On May 1, 12:29?am, Terry Reedy wrote: > On 4/30/2011 3:22 PM, Alexander Lyabah wrote: > > > I spend a lot of time in writing a new service checkio.org > > > It's all about python, learn python, find the best solution in > > python. > > > And Im looking for feedback from peoples who best in python. Here I > > make some video tutorial about this servicehttp://checkio.blip.tv/ > > > What do you think about it? > > Pretty impressive. My main disappointment is that you are using 2.7 > instead of 3.2, as I feel that beginners should learn Py 3 now. Also, > that is what I routinely use ;-). > > In any case, the home page should say Python 2.7, not just Python, I had > to think to click Console Learn in order to find out what would be legal > when I tried out one of the tasks. > > You might consider offering 3.2 as an alternative. Solutions will be > similar, but details differ. For instance, I noticed that one solution > to 'string split' *depends* on the 2.x leaking of listcomp loop variables. > > > I'm also have a not a very good English, so I need help with it too, > > because some parts of checkio.org ?not in very well English > > Home page: "In the descriptions of this tasks there is always > information from manuals and tutorials," 'these tasks' > > "game.Choice a game " => "game. Choose a game " > "users. Choice a game" => again, 'Choose' > > "and fall into the top " I think you mean "and climb into the top " > > "programs on arena. " => "program in the arena. " > > "By the result of competition formed top of the game. " > This is unclear. perhaps "The best will be chosen by the result of the > competition." > > I see a mailto: link at the bottom of the page, so I will report > anything else I see later. > > -- > Terry Jan Reedy Terry, Hi, sent a mail to you, couple days ago. From alexander at lyabah.com From greg.ewing at canterbury.ac.nz Thu May 5 06:06:41 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 22:06:41 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc22882$0$10557$742ec2ed@news.sonic.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> Message-ID: <92fb5jFa2lU1@mid.individual.net> John Nagle wrote: > A reasonable compromise would be that "is" is treated as "==" on > immutable objects. That wouldn't work for tuples, which can contain references to other objects that are not immutable. -- Greg From greg.ewing at canterbury.ac.nz Thu May 5 06:19:18 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 May 2011 22:19:18 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <92fbt9FfooU1@mid.individual.net> harrismh777 wrote: > 'C' does provide for pointers which are used by all 'C' > programmers to firmly provide pass-by-reference in their coding Yes, but when they do that, they're building an abstraction of their own on top of the facilities provided by the C language. C itself has no notion of pass-by-reference. If it did, the programmer would be able to use it directly instead of having to insert & and * operators himself. -- Greg From hg at schaathun.net Thu May 5 06:31:41 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 5 May 2011 11:31:41 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> Message-ID: On Thu, 05 May 2011 20:55:36 +1200, Gregory Ewing wrote: : It's not clear to me that references are any more abstract : than objects, or to put it another way, that objects are : any less abstract than references. : : After all, in normal Python usage you never actually : *see* an object Sure, but you can refer directly to objects, pass objects around, and refer to individual objects. This is abstract in the sense that it is far removed from the memory representation. However, the concept of a reference appears only when you explain how objects are handled (semantics). You cannot reference nor manipulate a reference in python, and that IMHO makes them more abstract. -- :-- Hans Georg From tacyt1007 at gmail.com Thu May 5 06:55:05 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Thu, 5 May 2011 12:55:05 +0200 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: Thanks for the reply! > Can you import from zip files when running the Python.exe interpreter? When I zip the folder "Lib" into Python27.zip and later rename it and try to run the python.exe, I receive an error: "Import error: no module named site" > Is the zip file included in sys.path? You might need to add this > yourself after callying Py_Initialize(). Before renaming the "Lib" folder, the path to the python27.zip exists in sys.path. > Is there a top-level directory in the zip file that may be throwing > the importer off? I am testing all the cases so this is not the issue. > Are you getting any sort of error message? When I run my app, it crashes while calling Py_Initialize(). The console closes suddenly. Is it necessary to create zip archive using zipfile.PyZipFile? regards 2011/5/5 Ian Kelly > > On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak wrote: > > Hello, > > > > I spent a lot of time googling for a solution of this problem, with no > > result. > > > > I have a C++ application, in which I would like to embed Python interpreter. > > I don't want to rely on an interpreter being installed on user machine, > > instead I would like to distribute all the necessary files with my app. > > > > As far as I understand, beside of my executable and Python.dll (I am using > > Python27), I need to provide two folders: > > ?- DLLs, > > ?- Lib > > > > If I place the Lib folder and the contents of the DLLs folder in a directory > > of my executable, then everything seems to work. > > However I would like to use a zipped Lib folder. Hence I made an archive > > (which contains contents of Lib folder) called Python27.zip. Unfortunately > > the app crashes during execution. > > I assume the reason might be lack of zlib.pyd. Is that assumption correct? > > If so, how to obtain it? If not, what am I doing wrong? > > I believe zlib.pyd is statically linked into python27.dll nowadays. > Some things to check: > > Can you import from zip files when running the Python.exe interpreter? > Is the zip file included in sys.path? ?You might need to add this > yourself after callying Py_Initialize(). > Is there a top-level directory in the zip file that may be throwing > the importer off? > Are you getting any sort of error message? > -- > http://mail.python.org/mailman/listinfo/python-list From mwilson at the-wire.com Thu May 5 07:44:12 2011 From: mwilson at the-wire.com (Mel) Date: Thu, 05 May 2011 07:44:12 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > On 5/4/2011 5:46 PM, harrismh777 wrote: >> Or, as stated earlier, Python should not allow 'is' on immutable objects. > > A reasonable compromise would be that "is" is treated as "==" on > immutable objects. I foresee trouble testing among float(5), int(5), Decimal(5) ... Mel. From rosuav at gmail.com Thu May 5 07:48:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 21:48:20 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> Message-ID: On Thu, May 5, 2011 at 9:44 PM, Mel wrote: > John Nagle wrote: >> On 5/4/2011 5:46 PM, harrismh777 wrote: >>> Or, as stated earlier, Python should not allow 'is' on immutable objects. >> >> ? ? A reasonable compromise would be that "is" is treated as "==" on >> immutable objects. > > I foresee trouble testing among float(5), int(5), Decimal(5) ... Define 'x is y' as 'type(x)==type(y) and isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then. Chris Angelico From mwilson at the-wire.com Thu May 5 08:09:21 2011 From: mwilson at the-wire.com (Mel) Date: Thu, 05 May 2011 08:09:21 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Tim Roberts wrote: > That is not an instance of passing an "int" by reference. That is an > instance of passing an "int *" by value. The fact that the parameter "a" > in BumpMe happens to be an address is completely irrelevent to the > definition of the parameter passing mechanism. > > C has pass-by-value, exclusively. End of story. Trouble with Turing-complete languages. If it can be done, you can convince a Turing-complete language to do it -- somehow. PL/I was the converse. All parameters were passed by reference, so with some_proc (rocks); the code in some_proc would be working with the address of rocks. If you wanted pass-by-value you wrote some_proc ((rocks)); whereupon the compiler would pass in by reference an unnamed temporary variable whose value was the expression `(rocks)`. I suspect the compiler I used avoided FORTRAN's troubles the same way. Your function could corrupt *a* 4, but it wouldn't corrupt the *only* 4. Mel. From steve+comp.lang.python at pearwood.info Thu May 5 08:14:23 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 12:14:23 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <4dc2949e$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 15:46:07 -0400, Benjamin Kaplan wrote: > On Wed, May 4, 2011 at 3:22 PM, harrismh777 > wrote: [...] >>> Digging down into C should be unnecessary to explain Python. >> >> >> ? huh? ? You have to be kidding. Why do you suppose we want it to be >> open-sourced? ? Use the force Luke, read the source. ? If you really >> want to know how Python is working you *must* dig down into the C code >> which implements it. ?The folks who document Python should be able to >> tell us enough to know how to use the language, but to really 'know' >> you need the implementation source. >> >> > Reading the CPython sources will show you how CPython works under the > hood, but it has nothing to do with how Python works. There are lots of > things that CPython does that "Python" does not. For instance, the GIL > is not a part of Python. Reference counting is not a part of Python. > Caching small integers and strings is not a part of Python. Why not read > the Jython sources instead of the CPython? It's the same language, after > all. More importantly, Python need not be implemented at all. If you're stuck on a desert island without electricity, you could simulate the effect of running any arbitrary Python code merely by understanding the semantics of high-level Python code, without caring the slightest about pointers at the C implementation level, or bit flipping at the hardware level, or von Neumann machines, or ref counting, or garbage collection, or any of a million other implementation details. All you need understand is the declared semantics of the language. Surely I can't be the only one who sometimes tries to work out a tricky bit of Python code by hand-simulating it on pencil and paper? -- Steven From rosuav at gmail.com Thu May 5 08:37:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 May 2011 22:37:28 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2949e$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <4dc2949e$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 5, 2011 at 10:14 PM, Steven D'Aprano wrote: > More importantly, Python need not be implemented at all. If you're stuck > on a desert island without electricity, you could simulate the effect of > running any arbitrary Python code merely by understanding the semantics > of high-level Python code... http://xkcd.com/505/ Chris Angelico From steve+comp.lang.python at pearwood.info Thu May 5 08:49:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 12:49:33 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <4dc29cdd$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 14:22:38 -0500, harrismh777 wrote: > Here is the thing that everyone forgets... all we have to work with > is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). Actually, this is incorrect. Most processors these days are hybrids between that and either the Harvard or Modified Harvard architecture: http://en.wikipedia.org/wiki/Modified_Harvard_architecture http://en.wikipedia.org/wiki/Harvard_architecture http://en.wikipedia.org/wiki/Von_Neumann_architecture > Assembler is still the best language on that processor. Assembly is not "a" language, it is a generic term for dozens or hundreds of different languages. But in any case, it's not clear what you mean by "best language". > 'C' is still the best high-level language on that processor. C is better described as a high-level assembler, or a low-level language. It is too close to the hardware to describe it as high-level, it has no memory management, few data abstractions, and little protection. > Its silly to claim that one high-level language or another is better > suited to complex data abstraction... don't go there. Surely you can't possibly mean that? Surely you don't mean to tell us that the 1957 version of FORTRAN, or unstructured BASIC, or early COBOL, are just as well suited to data abstraction as (say) Haskell? Many implementations of unstructured BASIC didn't even have arrays, only character strings and integers. Or (one of my personal favourites), Apple's Hypertalk? *Everything* is a string in Hypertalk. I love Hypertalk, but good for data abstraction? Don't make me laugh. You should read Paul Graham on the Blub Paradox: http://www.paulgraham.com/avg.html -- Steven From asdrubal.ivan.suarez.rivera at gmail.com Thu May 5 09:11:48 2011 From: asdrubal.ivan.suarez.rivera at gmail.com (=?ISO-8859-1?Q?Asdr=FAbal_Iv=E1n_Su=E1rez_Rivera?=) Date: Thu, 5 May 2011 06:11:48 -0700 (PDT) Subject: : PiCloud - really cool! References: Message-ID: <57a80dce-9a05-4239-ba62-87ba4679aacb@x3g2000yqj.googlegroups.com> On May 4, 8:13?pm, James Mills wrote: > If anyone hasn't seen this yet, I encourage you to! > (I stumbled upon it with some random thoughts and Gooogling) > > http://www.picloud.com/ > > Here's a quick test I wrote up that works locally using the simulator > and live (I did run it live): > > #!/usr/bin/env python > > import cloud > > def fib(n): > ? ? a, b, = 1, 1 > ? ? while n > 1: > ? ? ? ? a, b = b, a + b > ? ? ? ? n -= 1 > ? ? return b > > #cloud.start_simulator() > > jobs = cloud.map(fib, range(100)) > > print [cloud.result(job) for job in jobs] > > Enjoy! :) > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" It looks interesting but unfortunately is not free software :( From neilc at norwich.edu Thu May 5 09:19:43 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 5 May 2011 13:19:43 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> Message-ID: <92fmffFucoU9@mid.individual.net> On 2011-05-04, John Nagle wrote: > That's a quirk of CPython's boxed number implementation. All > integers are boxed, but there's a set of canned objects for > small integers. CPython's range for this is -5 to +256, > incidentally. That's visible through the "is" operator. > Arguably, it should not be. But that's the sole purpose of the is operator. You either expose those details, or you don't have an is operator at all. -- Neil Cerutti From nicogrubert at yahoo.de Thu May 5 09:35:41 2011 From: nicogrubert at yahoo.de (Nico Grubert) Date: Thu, 05 May 2011 15:35:41 +0200 Subject: PIL: The _imaging C module is not installed Message-ID: <4DC2A7AD.5080606@yahoo.de> Hi there I am having trouble to install PIL 1.1.7 on CentOS. I read and followed the instructions from http://effbot.org/zone/pil-imaging-not-installed.htm However, I still get the "The _imaging C module is not installed" error if I run the selftest: $ python selftest.py *** The _imaging C module is not installed Here is what I have tested so far: 1.) $ python -v ... >>> import Image ... dlopen("/usr/local/lib/python2.4/site-packages/PIL/_imaging.so", 2); import _imaging # dynamically loaded from /usr/local/lib/python2.4/site-packages/PIL/_imaging.so ... 2.) $ python ... >>> import _imaging ...success imported! Any idea what might be wrong? Regards Nico From steve+comp.lang.python at pearwood.info Thu May 5 09:59:59 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 13:59:59 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> Message-ID: <4dc2ad5e$0$29991$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 May 2011 21:48:20 +1000, Chris Angelico wrote: > On Thu, May 5, 2011 at 9:44 PM, Mel wrote: >> John Nagle wrote: >>> On 5/4/2011 5:46 PM, harrismh777 wrote: >>>> Or, as stated earlier, Python should not allow 'is' on immutable >>>> objects. >>> >>> ? ? A reasonable compromise would be that "is" is treated as "==" on >>> immutable objects. >> >> I foresee trouble testing among float(5), int(5), Decimal(5) ... > > Define 'x is y' as 'type(x)==type(y) and > isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then. `is` is supposed to be a *fast* operator, not even slower than equality testing. -- Steven From steve+comp.lang.python at pearwood.info Thu May 5 10:10:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 14:10:27 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 20:11:02 -0500, harrismh777 wrote: > These definitions go all the way back before the 8080, or the 6502, 8 > bit processors. Pass by reference has 'always' meant pass by using a > memory address (indirect addressing); a reference has always been a > memory pointer. That's not a definition. That's an implementation. Some day, we'll be using quantum computers without memory addresses, or DNA computers, or some version of Babbage's Difference Engine (perhaps a trillion of them in the volume of a match-head, tiny nano computing devices... who knows?). Whatever it is, whether or not it has concepts of "memory address" or "memory pointer", it will still be possible to represent data indirectly via *some* mechanism. > If I call a function in C, and pass-by-value, the data's 'value' is > placed on the stack in a stack-frame, as a 'value' parm... its a copy > of the actual data in memory. Correct. > If I call a function in C, and pass-by-reference, the data's 'address' C doesn't do pass by reference. There is no way to declare a parameter to a function as a by-reference parameter. You can only simulate it by hand, by passing a pointer as data, pointing to what you *really* want as data, and dereferencing it yourself. But the pointer itself is passed by value: the address is copied onto the stack, just like any other piece of data would be. (The Python equivalent is to pass a list containing the object. If you want call-by-reference behaviour without the convenience of language support for it, you can have it.) Pascal, on the other hand, does do pass by reference. If you declare a "var" parameter, you then call the function with the variable you intend, and the compiler handles everything: function foo(x: int, var y: int): int; begin foo := x + y; y := 0; x := 0; end; a := 1; b := 2; c := foo(a, b); After calling foo, the variable a remains 1, but the variable b is now 0. The compiler is smart enough to figure out what to do behind the scenes to make it all work. We're not discussing what you, the coder, can do. Given any Turing- complete language, you can (with sufficient cleverness and hard-work) do anything any other Turing-complete language can do. We're discussing what the compiler does, and for C, that is purely call by value. Let me put it this way... old, unstructured BASIC has GOTOs and line numbers, correct? And Python doesn't, correct? But you could write a BASIC interpreter in Python, and call that interpreter from your Python code... therefore Python has line numbers and GOTOs, no? No. Of course not. We're discussing *language features*, and GOTO is not a language feature of Python. Neither is call by reference a language feature of C, or Python either for that matter, but it is a language feature of VB and Pascal. The only difference between the two scenarios is that writing a BASIC interpreter is a tad harder than dereferencing a pointer, but that's just a matter of degree, not of kind. -- Steven From alec.taylor6 at gmail.com Thu May 5 10:12:33 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 6 May 2011 00:12:33 +1000 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: ZIP is the wrong format. Use UPX with LZMA On Thu, May 5, 2011 at 8:55 PM, Wojtek Mamrak wrote: > Thanks for the reply! > >> Can you import from zip files when running the Python.exe interpreter? > When I zip the folder "Lib" into Python27.zip and later rename it and > try to run the python.exe, I receive an error: > "Import error: no module named site" > >> Is the zip file included in sys.path? ?You might need to add this >> yourself after callying Py_Initialize(). > Before renaming the "Lib" folder, the path to the python27.zip exists > in sys.path. > >> Is there a top-level directory in the zip file that may be throwing >> the importer off? > I am testing all the cases so this is not the issue. > >> Are you getting any sort of error message? > When I run my app, it crashes while calling Py_Initialize(). The > console closes suddenly. > > Is it necessary to create zip archive using zipfile.PyZipFile? > > regards > > > 2011/5/5 Ian Kelly >> >> On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak wrote: >> > Hello, >> > >> > I spent a lot of time googling for a solution of this problem, with no >> > result. >> > >> > I have a C++ application, in which I would like to embed Python interpreter. >> > I don't want to rely on an interpreter being installed on user machine, >> > instead I would like to distribute all the necessary files with my app. >> > >> > As far as I understand, beside of my executable and Python.dll (I am using >> > Python27), I need to provide two folders: >> > ?- DLLs, >> > ?- Lib >> > >> > If I place the Lib folder and the contents of the DLLs folder in a directory >> > of my executable, then everything seems to work. >> > However I would like to use a zipped Lib folder. Hence I made an archive >> > (which contains contents of Lib folder) called Python27.zip. Unfortunately >> > the app crashes during execution. >> > I assume the reason might be lack of zlib.pyd. Is that assumption correct? >> > If so, how to obtain it? If not, what am I doing wrong? >> >> I believe zlib.pyd is statically linked into python27.dll nowadays. >> Some things to check: >> >> Can you import from zip files when running the Python.exe interpreter? >> Is the zip file included in sys.path? ?You might need to add this >> yourself after callying Py_Initialize(). >> Is there a top-level directory in the zip file that may be throwing >> the importer off? >> Are you getting any sort of error message? >> -- >> http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list > From invalid at invalid.invalid Thu May 5 10:14:22 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:14:22 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On 2011-05-05, harrismh777 wrote: > Grant Edwards wrote: >> The "pass by value" and "pass by reference" parameter passing >> mechanisms are pretty well defined, and C uses "pass by value". > > Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that > helped define them.... I give up. You don't seem to understand the C language defintion or what is commonly meant by "pass by reference". -- Grant Edwards grant.b.edwards Yow! Inside, I'm already at SOBBING! gmail.com From invalid at invalid.invalid Thu May 5 10:17:15 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:17:15 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: On 2011-05-05, Gregory Ewing wrote: > harrismh777 wrote: >> 'C' does provide for pointers which are used by all 'C' >> programmers to firmly provide pass-by-reference in their coding > > Yes, but when they do that, they're building an abstraction > of their own on top of the facilities provided by the C > language. I've pointed that out to him. He's talking about what _he_ does in his program. We're talking about the C language definition and what the compiler does. > C itself has no notion of pass-by-reference. Exactly. C is pass by value. > If it did, the programmer would be able to use it directly > instead of having to insert & and * operators himself. That's what I was trying to say, but probably not as clearly. The "&" operatore returnas a _value_ that the OP passes _by_value_ to a function. That function then uses the "*" operator to use that value to access some data. -- Grant Edwards grant.b.edwards Yow! DIDI ... is that a at MARTIAN name, or, are we gmail.com in ISRAEL? From marduk at letterboxes.org Thu May 5 10:19:53 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 05 May 2011 10:19:53 -0400 Subject: PIL: The _imaging C module is not installed In-Reply-To: <4DC2A7AD.5080606@yahoo.de> References: <4DC2A7AD.5080606@yahoo.de> Message-ID: <1304605193.541346.2.camel@localhost.localdomain> On Thu, 2011-05-05 at 15:35 +0200, Nico Grubert wrote: > Hi there > > I am having trouble to install PIL 1.1.7 on CentOS. > > I read and followed the instructions from > http://effbot.org/zone/pil-imaging-not-installed.htm > > However, I still get the "The _imaging C module is not installed" error > if I run the selftest: > > $ python selftest.py > *** The _imaging C module is not installed > > > Here is what I have tested so far: > > 1.) > > $ python -v > ... > >>> import Image > ... > dlopen("/usr/local/lib/python2.4/site-packages/PIL/_imaging.so", 2); > import _imaging # dynamically loaded from > /usr/local/lib/python2.4/site-packages/PIL/_imaging.so > ... I had this problem earlier this week. Assuming that you pip-installed or similar. PIL will compile and install if you don't have some development libraries and then simply not work or not work up to full steam when used. To avoid this, you need to install the appropriate libraries, among which are: libjpeg-devel freetype-devel libpng-devel Probably others as well. HTH, -a From marduk at letterboxes.org Thu May 5 10:20:24 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 05 May 2011 10:20:24 -0400 Subject: PIL: The _imaging C module is not installed In-Reply-To: <4DC2A7AD.5080606@yahoo.de> References: <4DC2A7AD.5080606@yahoo.de> Message-ID: <1304605224.541346.3.camel@localhost.localdomain> Oh I forgot to say, after installing these libraries, you will need to re-compile (install) PIL. -a From invalid at invalid.invalid Thu May 5 10:21:31 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:21:31 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On 2011-05-05, harrismh777 wrote: > Tim Roberts wrote: >> The fact that the parameter "a" >> in BumpMe happens to be an address is completely irrelevent to the >> definition of the parameter passing mechanism. >> >> C has pass-by-value, exclusively. End of story. > > Yeah, Tim, I know... but that's my entire point in a nut-shell... > whether the language is pass-by-value or pass-by-reference has less to > do with how it is 'defined' (its mechanism--- indirection and stack) No, whether the _language_ is pass by value or pass-by-reference has _entirely_ to do with it's definition. > and more to do with how it is routinely used with the standard > features it provides--- in this case memory indirection--- as > pointers. Now you're talking about how you can implement higher level constructs using a language that doesn't directly implement such constructs. You might as well say that C is a linked-list language like Lisp since you can write a linked list implementation in C. If you said that you'd be just as wrong as saying that C uses call-by-reference. -- Grant Edwards grant.b.edwards Yow! I want another at RE-WRITE on my CEASAR gmail.com SALAD!! From gnarlodious at gmail.com Thu May 5 10:22:12 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Thu, 5 May 2011 07:22:12 -0700 (PDT) Subject: Need to solve the "Stateless HTTP" problem Message-ID: My scripting has grown to the point where the Apache server is a problem. My Python websites run and quit, which means I need to save data and recreate everything next page load. Bulky and slow. What is the simplest solution? I am running Py3 on OSX Server with Apache 2. Essentially I want certain objects to be a "constantly running process" that may timeout after some disuse. I suspect there are already systems for it. Please advise in simple terms, I am not a professional. -- Gnarlie From invalid at invalid.invalid Thu May 5 10:24:37 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:24:37 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <92el16F9kaU1@mid.individual.net> Message-ID: On 2011-05-05, Gregory Ewing wrote: > Hans Georg Schaathun wrote: >> Is transmission by name the same as call by object? > > No, it's not. With call-by-name, the caller passes a > small function (known as a "thunk") that calculates the > address of the parameter. Every time the callee needs to > refer to the parameter, it evaluates this function. > > This allows some neat tricks, but it's massive overkill for most > uses. It also is a very good source of surprising bugs. -- Grant Edwards grant.b.edwards Yow! I feel like I'm at in a Toilet Bowl with a gmail.com thumbtack in my forehead!! From invalid at invalid.invalid Thu May 5 10:25:58 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:25:58 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: On 2011-05-05, harrismh777 wrote: > Dennis Lee Bieber wrote: >>> > We do not consider passing a pointer as*by value* because its an >>> > address; by definition, that is pass-by-reference. We are not passing >> To most of the world, pass-by-reference means the COMPILER, not the >> PROGRAMMER is obtaining and passing the address, and the compiler also >> always dereferences the passed "value"... The programmer has no control >> over whether to operate on the address or the data referenced by the >> address. > > Who is "most of the world" ? Pretty much everybody except you. Please see: > http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr233.htm Yea, I read that. It doesn't support your argument. It agrees with the rest of the world. -- Grant Edwards grant.b.edwards Yow! I need to discuss at BUY-BACK PROVISIONS gmail.com with at least six studio SLEAZEBALLS!! From invalid at invalid.invalid Thu May 5 10:30:08 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:30:08 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <92f7nuFfhhU1@mid.individual.net> Message-ID: On 2011-05-05, Gregory Ewing wrote: > harrismh777 wrote: >> 'C' is still the best high-level language on that processor. > > Some would argue that C is actually better than assembler these > days, because modern architectures are so freaking complicated > that it takes a computer to figure out the best instruction > sequence. :-( Been there, done that. Many years ago, it took me more than a week (and required the help of an ARM instruction set guru) to come up with an assembly language IP checksum routine for the ARM that out-performed the somewhat naive NetBSD "C" version. When we switched to the FreeBSD stack (and a newer compiler) a few years later, my assembly code got tossed out because was no longer any faster than the C version. -- Grant Edwards grant.b.edwards Yow! Half a mind is a at terrible thing to waste! gmail.com From roy at panix.com Thu May 5 10:31:33 2011 From: roy at panix.com (Roy Smith) Date: Thu, 05 May 2011 10:31:33 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: In article , Grant Edwards wrote: > That's what I was trying to say, but probably not as clearly. The "&" > operatore returnas a _value_ that the OP passes _by_value_ to a > function. That function then uses the "*" operator to use that value > to access some data. Then, of course, there's references in C++. I think it's fair to call the following "call by reference" in the sense we're talking about it here. void f(int& i) { i = 5; } int i = 42; f(i); Of course, C++ lets you go off the deep end with abominations like references to pointers. Come to think of it, C++ let's you go off the deep end in so many ways... From invalid at invalid.invalid Thu May 5 10:31:58 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 14:31:58 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <4dc29cdd$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-05, Steven D'Aprano wrote: > On Wed, 04 May 2011 14:22:38 -0500, harrismh777 wrote: > >> Here is the thing that everyone forgets... all we have to work with >> is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). > > Actually, this is incorrect. Most processors these days are hybrids > between that and either the Harvard or Modified Harvard architecture: > > http://en.wikipedia.org/wiki/Modified_Harvard_architecture > http://en.wikipedia.org/wiki/Harvard_architecture > http://en.wikipedia.org/wiki/Von_Neumann_architecture And a lot of the are still full-up Harvard architecture (e.g. the entire Atmel AVR family and Intel 8051 family for example). -- Grant Edwards grant.b.edwards Yow! When this load is at DONE I think I'll wash it gmail.com AGAIN ... From pruebauno at latinmail.com Thu May 5 10:33:31 2011 From: pruebauno at latinmail.com (nn) Date: Thu, 5 May 2011 07:33:31 -0700 (PDT) Subject: Today's fun and educational Python recipe References: Message-ID: On May 4, 2:17?pm, Raymond Hettinger wrote: > Here's a 22-line beauty for a classic and amazing algorithm:http://bit.ly/bloom_filter > > The wiki article on the algorithm is brief and well-written:http://en.wikipedia.org/wiki/Bloom_filter > > It turns out that people in the 1970's were pretty smart :-) > > Raymond > > ------- > follow my other python tips and recipes on twitter: ?@raymondh Very cool! Thanks. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Thu May 5 10:37:59 2011 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Thu, 5 May 2011 14:37:59 +0000 (UTC) Subject: Need to solve the "Stateless HTTP" problem References: Message-ID: Gnarlodious wrote: > My scripting has grown to the point where the Apache server is a > problem. My Python websites run and quit, which means I need to save > data and recreate everything next page load. Bulky and slow. What is > the simplest solution? Karrigell? -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From harrismh777 at charter.net Thu May 5 10:40:49 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 09:40:49 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc29cdd$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <4dc29cdd$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > You should read Paul Graham on the Blub Paradox: > > http://www.paulgraham.com/avg.html > > Excellent-! ... thanks, fun article. ... where is that lisp manual anyway? ... oh, yeah, emacs! :) From rosuav at gmail.com Thu May 5 10:47:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 May 2011 00:47:30 +1000 Subject: Need to solve the "Stateless HTTP" problem In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 12:22 AM, Gnarlodious wrote: > My scripting has grown to the point where the Apache server is a > problem. My Python websites run and quit, which means I need to save > data and recreate everything next page load. Bulky and slow. What is > the simplest solution? > > I am running Py3 on OSX Server with Apache 2. Essentially I want > certain objects to be a "constantly running process" that may timeout > after some disuse. I suspect there are already systems for it. Please > advise in simple terms, I am not a professional. Depending on how much of Apache's featureset you're using, it may be easiest to set it aside altogether and just run a Python HTTP server. Then you can maintain as much state as you like. But if you're currently hosting multiple sites and distinguishing between them using Host: headers (using NameVirtualHost), then you'd have to change them all, which probably wouldn't be worthwhile. Chris Angelico From roy at panix.com Thu May 5 10:49:35 2011 From: roy at panix.com (Roy Smith) Date: Thu, 05 May 2011 10:49:35 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <4dc29cdd$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4dc29cdd$0$29991$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > C is better described as a high-level assembler, or a low-level language. > It is too close to the hardware to describe it as high-level, it has no > memory management, few data abstractions, and little protection. +1 I (and most people who really know C and the specific hardware architecture they're working on) should be able to look at a C program and (modulo optimization) pretty much be able to write down the generated assembler by hand. In fact, I used to do exactly that. I was once working on M-6800 hardware (8/16-bit microprocessor). I used to write out procedures in C, then hand-compile it into assembler code (and leave the C code as a comment). I wasn't a true masochist, however. I did let an assembler convert it to hex for me before I keyed it in :-) On the other hand, trying to do that for something like C++ is damn near impossible. There's too much stuff that happens by magic. Creation (and destruction) of temporary objects. Exception handling. RTTI. Not to mention truly black magic like template expansion. From steve+comp.lang.python at pearwood.info Thu May 5 10:50:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 14:50:36 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> Message-ID: <4dc2b93c$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 14:58:38 -0500, harrismh777 wrote: > Benjamin Kaplan wrote: >> CPython is implemented in C because that's the language chosen. Python >> is also implemented in Java, C#, Python, and several other languages. > > True enough. If I used Jython, I would want to take a look at those > sources... as well as the Java sources... which were wrtten in, um, C. No, Java sources are written in Java. That's why they're *Java* sources. Perhaps you mean that the Java compiler is written in C? Highly unlikely: Java compilers have been self-hosting for many years now. http://en.wikipedia.org/wiki/Self-hosting -- Steven From steve+comp.lang.python at pearwood.info Thu May 5 10:51:52 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 14:51:52 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4dc2b988$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 16:22:42 -0600, Ian Kelly wrote: > However, I hope we can all agree that pass-by-pointer shares certain > features with both pass-by-value and pass-by-reference, and there are > perfectly reasonable arguments for lumping it in either category, yes? *cries* Please don't invent another "pass by foo" term!!!! Seriously though, "pass by foo" refers to what the compiler or interpreter does when you, the coder, call a function with some variable, say, x: f(x) It is not referring to what you, the coder, does when you want to pass an indirect reference of some sort to a chunk of data to some function. In many languages, you would use a pointer, and write the function call something like this: f(^x) (using Pascal's up-arrow notation for "pointer to"). Such "pass by pointer" is a tactic used by the coder, as opposed to a language feature. I believe this distinction between what the compiler does, and what the coder does, is at the heart of much confusion. Pointers that are passed as arguments are themselves data, just as much as ints or floats, or (in languages that have first-class functions) functions. -- Steven From neilc at norwich.edu Thu May 5 11:10:43 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 5 May 2011 15:10:43 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: <92fsvjFkghU1@mid.individual.net> On 2011-05-05, Roy Smith wrote: > Of course, C++ lets you go off the deep end with abominations > like references to pointers. Come to think of it, C++ let's > you go off the deep end in so many ways... But you can do some really cool stuff in the deep end. -- Neil Cerutti From steve+comp.lang.python at pearwood.info Thu May 5 11:11:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 15:11:33 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 May 2011 14:14:22 +0000, Grant Edwards wrote: > On 2011-05-05, harrismh777 wrote: >> Grant Edwards wrote: >>> The "pass by value" and "pass by reference" parameter passing >>> mechanisms are pretty well defined, and C uses "pass by value". >> >> Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that >> helped define them.... > > I give up. You don't seem to understand the C language defintion or > what is commonly meant by "pass by reference". In fairness, he's not the only one. M Harris has twice now linked to an IBM site that describes pass-by-reference in C in terms of passing a pointer to the argument you want as the argument. Admittedly, doing so gives you almost the same behaviour, except that you have to dereference the pointers yourself. That's a pretty big difference though, and gets to the core of the argument: it's a bit like arguing that manual cars are fitted with exactly the same automatic transmission as auto cars, it's just that you have to engage the clutch and shift gears yourself. -- Steven From steve+comp.lang.python at pearwood.info Thu May 5 11:14:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 15:14:20 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> Message-ID: <4dc2becc$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 May 2011 09:18:56 -0700, Devin Jeanpierre wrote: > On May 4, 9:44 am, Hans Georg Schaathun wrote: >> : The only twist is that you never get to dereference : >> pointers in Python, but you can in C. Not much of a twist if you ask : >> me, but then again, I've been thinking in thismodelfor years. Maybe : >> I'm brainwashed. :) >> >> You are. You explain Python in terms of C. That's useful when you >> talk to other speakers of C. >> >> If you want to explain the language to a broader audience, you should >> use terminology from the language's own level of abstraction. > > No, I explained Python in terms of pointers/reference. Python has no pointers or references unless you simulate them yourself using other data types. They exist as implementation details of the Python virtual machine, which is at least two levels below that of Python code. The first is the byte code which runs in the virtual machine; the second is the code in the VM. -- Steven From roy at panix.com Thu May 5 11:29:48 2011 From: roy at panix.com (Roy Smith) Date: Thu, 05 May 2011 11:29:48 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> <92fsvjFkghU1@mid.individual.net> Message-ID: In article <92fsvjFkghU1 at mid.individual.net>, Neil Cerutti wrote: > On 2011-05-05, Roy Smith wrote: > > Of course, C++ lets you go off the deep end with abominations > > like references to pointers. Come to think of it, C++ let's > > you go off the deep end in so many ways... > > But you can do some really cool stuff in the deep end. "Hey, let's override operator,() and have some fun" From mwilson at the-wire.com Thu May 5 11:30:27 2011 From: mwilson at the-wire.com (Mel) Date: Thu, 05 May 2011 11:30:27 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Some day, we'll be using quantum computers without memory addresses, [ ... ] it will still be possible to > represent data indirectly via *some* mechanism. :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the 'nonlocal' keyword! Mel. From ian.g.kelly at gmail.com Thu May 5 11:36:39 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 May 2011 09:36:39 -0600 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 4:55 AM, Wojtek Mamrak wrote: > Thanks for the reply! > >> Can you import from zip files when running the Python.exe interpreter? > When I zip the folder "Lib" into Python27.zip and later rename it and > try to run the python.exe, I receive an error: > "Import error: no module named site" That means it's not finding it. After startup, try adding the zip file to your sys.path and then do "import site" at the command line, and it should work. >> Are you getting any sort of error message? > When I run my app, it crashes while calling Py_Initialize(). The > console closes suddenly. Hm, that definitely seems odd. What if you put the zip file in your PYTHONPATH environment variable? > Is it necessary to create zip archive using zipfile.PyZipFile? It shouldn't be. It works for me (at least with Python.exe) creating the zip archive using 7-Zip. From nagle at animats.com Thu May 5 11:41:27 2011 From: nagle at animats.com (John Nagle) Date: Thu, 05 May 2011 08:41:27 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <92fb5jFa2lU1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> <92fb5jFa2lU1@mid.individual.net> Message-ID: <4dc2c52e$0$10567$742ec2ed@news.sonic.net> On 5/5/2011 3:06 AM, Gregory Ewing wrote: > John Nagle wrote: > >> A reasonable compromise would be that "is" is treated as "==" on >> immutable objects. > > That wouldn't work for tuples, which can contain references > to other objects that are not immutable. Such tuples are still identical, even if they contain identical references to immutable objects. John Nagle From steve+comp.lang.python at pearwood.info Thu May 5 11:42:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 May 2011 15:42:58 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> Message-ID: <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> Given the following statement of Python code: >> >> >>> x = "spam" >> >> what is the value of the variable x? > > Mu (?). > > ?x? is a name. Names are bound to values. Talk of ?variable? only > confuses the issue because of the baggage carried with that term. Yes, good point. Consider me chastised, because I actually knew that. It's just that the term "variable" is so useful and so familiar that it's easy to use it even for languages that don't have variables in the C/ Pascal/Fortran/etc sense. > But the data model of Python doesn't fit well with the ideas that the > term ?variable? connotes for most programmers: a box, perhaps of a rigid > shape (data type) or not, which is labelled ?x? and nothing else. For > another variable to have an equal value, that value needs to be copied > and put in a separate box; or perhaps some special reference to the > original needs to be made and placed in a box. > > Saying ?variable? and ?has the value? just invites baggage needlessly, > and creates many assumptions about Python's data model which has to be > un-done, often after much false mental scaffolding has been built on > them by the newbie and needs to be dismantled carefully. I've quoted your two paragraphs because I think they're very important, not because I intend arguing. Possibly a first for me :) However.... > Python isn't pass by anything. Nothing gets copied, nothing gets passed; > when a function is called with an object as a parameter, the object > stays put, and simply gets a new temporary name bound to it for the > function's use. This, however, is incorrect. "Passing" in this sense refers to calling the function with an argument, hence "pass by..." and "call by..." are synonyms. The mechanics of how the compiler or interpreter makes arguments available to functions has real consequences at the language level: the calling strategy used by the compiler effects the language semantics. >> > Whatever, a rose by any other name...) >> >> Do you really think that roses would be the symbol of romantic love if >> they were called "disgusting stink-weeds of perversion and death"? > > Juliet's point stands, though: they would still smell as sweet, and the > term you describe would be unlikely to catch on since it doesn't > describe them well at all. Perhaps a counter-example is that of the tomato, which never took off as a food in Europe until people stopped calling them "love apples", and thinking that they were deadly poison. Or Chinese Gooseberries, better known by the name thought up by a marketing firm, "kiwi fruit". -- Steven From workitharder at gmail.com Thu May 5 11:51:10 2011 From: workitharder at gmail.com (buck) Date: Thu, 5 May 2011 08:51:10 -0700 (PDT) Subject: Development tools and practices for Pythonistas In-Reply-To: Message-ID: I use hg for even 50-line standalone python scripts. It's very well suited to these small environments, and scales up nicely. cd /my/working/dir hg init hg add myscript.py hg ci -m 'added myscript' It's that simple, and now hyou can go back if you make a terrible mistake, and you can post it to bitbucket and share with the world if you like, almost as easily. --Buck From workitharder at gmail.com Thu May 5 11:55:00 2011 From: workitharder at gmail.com (buck) Date: Thu, 5 May 2011 08:55:00 -0700 (PDT) Subject: [OT] From svn to something else? In-Reply-To: Message-ID: This is what made me choose Mercurial in my recent search. http://www.python.org/dev/peps/pep-0374/ There is a tremendous amount of detail there. In summary, hg and git are both very good, and essentially equal in features. The only salient difference is that hg is implemented in python, so they went with that. I did the same, and I'm quite happy. It's basically svn with the shiny new distributed features added. From workitharder at gmail.com Thu May 5 11:55:00 2011 From: workitharder at gmail.com (buck) Date: Thu, 5 May 2011 08:55:00 -0700 (PDT) Subject: [OT] From svn to something else? In-Reply-To: Message-ID: This is what made me choose Mercurial in my recent search. http://www.python.org/dev/peps/pep-0374/ There is a tremendous amount of detail there. In summary, hg and git are both very good, and essentially equal in features. The only salient difference is that hg is implemented in python, so they went with that. I did the same, and I'm quite happy. It's basically svn with the shiny new distributed features added. From harrismh777 at charter.net Thu May 5 11:56:11 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 10:56:11 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mel wrote: >> represent data indirectly via*some* mechanism. > :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the > 'nonlocal' keyword! I was thinking pass-by-osmosis.... :) From nagle at animats.com Thu May 5 11:58:33 2011 From: nagle at animats.com (John Nagle) Date: Thu, 05 May 2011 08:58:33 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2ad5e$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> <4dc2ad5e$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc2c92f$0$10586$742ec2ed@news.sonic.net> On 5/5/2011 6:59 AM, Steven D'Aprano wrote: > On Thu, 05 May 2011 21:48:20 +1000, Chris Angelico wrote: > >> On Thu, May 5, 2011 at 9:44 PM, Mel wrote: >>> John Nagle wrote: >>>> On 5/4/2011 5:46 PM, harrismh777 wrote: >>>>> Or, as stated earlier, Python should not allow 'is' on immutable >>>>> objects. >>>> >>>> A reasonable compromise would be that "is" is treated as "==" on >>>> immutable objects. >>> >>> I foresee trouble testing among float(5), int(5), Decimal(5) ... >> >> Define 'x is y' as 'type(x)==type(y) and >> isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then. That's close to the right answer. > > `is` is supposed to be a *fast* operator, not even slower than equality > testing. That's an implementation problem. Those are cheap tests at the machine code level. An efficient test looks like this: def istest(a, b) : if id(a) == id(b) : # the cheap address test return(True) if type(x) != type(y) : # cheap binary comparison return(False) if mutable(x) : # the interpreter knows this return(False) return(x == y) # equality test for mutables Probably about 12 machine instructions, and the full "==" test is only reached for cases in which "is" now produces wrong answers. It's encouraging that a Google code search finds no matches of if .* is \" or if .* is 1 in Python code. John Nagle From harrismh777 at charter.net Thu May 5 12:00:53 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 11:00:53 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > In fairness, he's not the only one. M Harris has twice now linked to an > IBM site that describes pass-by-reference in C in terms of passing a > pointer to the argument you want as the argument. Admittedly, doing so > gives you almost the same behaviour, except that you have to dereference > the pointers yourself. > > That's a pretty big difference though, and gets to the core of the > argument: it's a bit like arguing that manual cars are fitted with > exactly the same automatic transmission as auto cars, it's just that you > have to engage the clutch and shift gears yourself. ... and actually, if you feel it just right and you have just the right synchro-mesh setup, you can slide from 3rd into 4th without every touching the clutch peddle... and if that isn't automatic, I don't know what is.... man those were the days... now I just press a button that says, "Auto 4-wheel Lock", set the gps, and take a nap... :) From harrismh777 at charter.net Thu May 5 12:18:46 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 11:18:46 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Grant Edwards wrote: > I give up. You don't seem to understand the C language defintion or > what is commonly meant by "pass by reference". > ah, don't give up... here is a link that might help to clarify some of these semantics... me thinks: http://en.wikipedia.org/wiki/Pass_by_reference#Call_by_value kind regards, m harris From andreas.tawn at ubisoft.com Thu May 5 12:27:26 2011 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Thu, 5 May 2011 18:27:26 +0200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <654D9D97DA51AD479973BC2D5578603C0BEA7F4864@PDC-MAIL-CMS01.ubisoft.org> > Steven D'Aprano wrote: > > > Some day, we'll be using quantum computers without memory addresses, > [ ... > ] it will still be possible to > > represent data indirectly via *some* mechanism. > > :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the > 'nonlocal' keyword! > > Mel. > If True and False: waveFunction.collapse(cat) That's going to be fun ;o) Cheers, Drea From miki.tebeka at gmail.com Thu May 5 12:33:56 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 5 May 2011 09:33:56 -0700 (PDT) Subject: Need to solve the "Stateless HTTP" problem In-Reply-To: Message-ID: <1416652a-99ba-43c5-96f6-6f40b7442368@glegroupsg2000goo.googlegroups.com> > Essentially I want > certain objects to be a "constantly running process" that may timeout > after some disuse. memcached? From ian.g.kelly at gmail.com Thu May 5 12:44:39 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 May 2011 10:44:39 -0600 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2c52e$0$10567$742ec2ed@news.sonic.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> <92fb5jFa2lU1@mid.individual.net> <4dc2c52e$0$10567$742ec2ed@news.sonic.net> Message-ID: On Thu, May 5, 2011 at 9:41 AM, John Nagle wrote: > On 5/5/2011 3:06 AM, Gregory Ewing wrote: >> >> John Nagle wrote: >> >>> A reasonable compromise would be that "is" is treated as "==" on >>> immutable objects. >> >> That wouldn't work for tuples, which can contain references >> to other objects that are not immutable. > > ? ?Such tuples are still identical, even if they > contain identical references to immutable objects. >>> a = (1, 2, [3, 4, 5]) >>> b = (1, 2, [3, 4, 5]) >>> a == b True >>> a is b # Using the proposed definition True >>> a[0] is b[0] True >>> a[1] is b[1] True >>> a[2] is b[2] False >>> a[2].append(6) >>> a (1, 2, [3, 4, 5, 6]) >>> b (1, 2, [3, 4, 5]) >>> a == b False >>> a is b False Thus a and b cannot be used interchangeably even though "a is b" originally returned True. From invalid at invalid.invalid Thu May 5 12:48:58 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 16:48:58 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-05, Steven D'Aprano wrote: > On Thu, 05 May 2011 14:14:22 +0000, Grant Edwards wrote: > >> On 2011-05-05, harrismh777 wrote: >>> Grant Edwards wrote: >>>> The "pass by value" and "pass by reference" parameter passing >>>> mechanisms are pretty well defined, and C uses "pass by value". >>> >>> Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that >>> helped define them.... >> >> I give up. You don't seem to understand the C language defintion or >> what is commonly meant by "pass by reference". > > > In fairness, he's not the only one. M Harris has twice now linked to an > IBM site that describes pass-by-reference in C in terms of passing a > pointer to the argument you want as the argument. Admittedly, doing so > gives you almost the same behaviour, except that you have to dereference > the pointers yourself. > > That's a pretty big difference though, and gets to the core of the > argument: it's a bit like arguing that manual cars are fitted with > exactly the same automatic transmission as auto cars, it's just that > you have to engage the clutch and shift gears yourself. I like that analogy. "My car has an automatic transmission except you have to shift gears yourself with that lever and that it has a clutch operated by that pedal instead of a hydrostatic torque converter." -- Grant Edwards grant.b.edwards Yow! ... bleakness at ... desolation ... plastic gmail.com forks ... From invalid at invalid.invalid Thu May 5 12:52:52 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 16:52:52 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-05, harrismh777 wrote: > Steven D'Aprano wrote: >> In fairness, he's not the only one. M Harris has twice now linked to an >> IBM site that describes pass-by-reference in C in terms of passing a >> pointer to the argument you want as the argument. Admittedly, doing so >> gives you almost the same behaviour, except that you have to dereference >> the pointers yourself. >> >> That's a pretty big difference though, and gets to the core of the >> argument: it's a bit like arguing that manual cars are fitted with >> exactly the same automatic transmission as auto cars, it's just that you >> have to engage the clutch and shift gears yourself. > > > ... and actually, if you feel it just right and you have just the > right synchro-mesh setup, you can slide from 3rd into 4th without > every touching the clutch peddle... That's possible on pretty much any modern automotive or small-truck transmission, and it's not really that hard to do. I can go from 1st up to 5th and back down to 1st without touching the clutch. I don't as a habit do it, because it puts unnecessary wear on the syncros (and I've had cars with pretty weak syncros -- Alfa-Romeo Spyders were famous for the 2nd gear syncro wearing out). > and if that isn't automatic, I don't know what is.... No, that's _not_ automatic if you have to do it yourself. It's automatic when it happens without user-intervention. Now I think you're trolling... -- Grant Edwards grant.b.edwards Yow! I want to dress you at up as TALLULAH BANKHEAD and gmail.com cover you with VASELINE and WHEAT THINS ... From invalid at invalid.invalid Thu May 5 12:56:01 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 16:56:01 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: On 2011-05-05, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> That's what I was trying to say, but probably not as clearly. The "&" >> operatore returnas a _value_ that the OP passes _by_value_ to a >> function. That function then uses the "*" operator to use that value >> to access some data. > > Then, of course, there's references in C++. I think it's fair to call > the following "call by reference" in the sense we're talking about it > here. > > void f(int& i) { > i = 5; > } > int i = 42; > f(i); If after the call to f(i) the caller sees that i == 5, then that's call by reference. But, we were talking about C. > Of course, C++ lets you go off the deep end with abominations like > references to pointers. Come to think of it, C++ let's you go off > the deep end in so many ways... :) -- Grant Edwards grant.b.edwards Yow! Is this sexual at intercourse yet?? Is it, gmail.com huh, is it?? From invalid at invalid.invalid Thu May 5 12:57:34 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 May 2011 16:57:34 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> <92fsvjFkghU1@mid.individual.net> Message-ID: On 2011-05-05, Neil Cerutti wrote: > On 2011-05-05, Roy Smith wrote: >> Of course, C++ lets you go off the deep end with abominations >> like references to pointers. Come to think of it, C++ let's >> you go off the deep end in so many ways... > > But you can do some really cool stuff in the deep end. Until you get pulled under and drowned by some flailing goof who oughtn't be there. -- Grant Edwards grant.b.edwards Yow! Zippy's brain cells at are straining to bridge gmail.com synapses ... From harrismh777 at charter.net Thu May 5 12:58:46 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 11:58:46 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: Grant Edwards wrote: > That's what I was trying to say, but probably not as clearly. The "&" > operatore returnas a_value_ that the OP passes_by_value_ to a > function. That function then uses the "*" operator to use that value > to access some data. I'm gonna try a D'Aprano-style bogus argument for a moment... ... saying that 'C' does not support pass-by-reference because you have to direct the compiler with the '&' and '*' characters is a little like saying that Python does not support decorations ! ... ... because you have to direct the interpreter with some @ bogus-decorator-syntax I want Python to support decorations automatically ! ;-) From harrismh777 at charter.net Thu May 5 13:03:27 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 12:03:27 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Grant Edwards wrote: > No, that's_not_ automatic if you have to do it yourself. It's > automatic when it happens without user-intervention. > > Now I think you're trolling... ... no, I was only kidding... :) From ian.g.kelly at gmail.com Thu May 5 13:07:42 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 May 2011 11:07:42 -0600 Subject: Need to solve the "Stateless HTTP" problem In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 8:22 AM, Gnarlodious wrote: > My scripting has grown to the point where the Apache server is a > problem. My Python websites run and quit, which means I need to save > data and recreate everything next page load. Bulky and slow. What is > the simplest solution? > > I am running Py3 on OSX Server with Apache 2. Essentially I want > certain objects to be a "constantly running process" that may timeout > after some disuse. I suspect there are already systems for it. Please > advise in simple terms, I am not a professional. It sounds to me like you're currently running your Python scripts as CGIs? You should look into running your scripts via mod_wsgi in daemon mode, which will do exactly what you are asking. See here: http://code.google.com/p/modwsgi/ From harrismh777 at charter.net Thu May 5 13:19:31 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 12:19:31 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: Ethan Furman wrote: > PS > My thanks to those who kept explaining in various ways about the > difference between language supported features and programmer constructs > -- I hadn't realized before this thread that call-by-reference was not a > language feature of C, but rather a programmer-implemented feature using > the C operators. You are most welcome. :) From ethan at stoneleaf.us Thu May 5 13:28:08 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 05 May 2011 10:28:08 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> Message-ID: <4DC2DE28.9030501@stoneleaf.us> harrismh777 wrote: > Grant Edwards wrote: >> I give up. You don't seem to understand the C language defintion or >> what is commonly meant by "pass by reference". >> > > ah, don't give up... here is a link that might help to clarify some of > these semantics... me thinks: > > http://en.wikipedia.org/wiki/Pass_by_reference#Call_by_value Indeed it does (emphasis added): "In call-by-reference evaluation (also referred to as pass-by-reference), a function receives an *implicit* reference to a variable used as argument" In C the the reference is explicit, which the article states in the next paragraph: "Even among languages that don't exactly support call-by-reference, many, including C and ML, support explicit references (objects that refer to other objects), such as pointers" ~Ethan~ PS My thanks to those who kept explaining in various ways about the difference between language supported features and programmer constructs -- I hadn't realized before this thread that call-by-reference was not a language feature of C, but rather a programmer-implemented feature using the C operators. From neilc at norwich.edu Thu May 5 13:39:03 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 5 May 2011 17:39:03 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: <92g5lnFkolU1@mid.individual.net> On 2011-05-05, harrismh777 wrote: > ... saying that 'C' does not support pass-by-reference because > you have to direct the compiler with the '&' and '*' characters > is a little like saying that > > Python does not support decorations ! ... > > > ... because you have to direct the interpreter with some > > > @ bogus-decorator-syntax > > > I want Python to support decorations automatically ! You do have to declare decorators when defining them, but they are called automatically when you call the decorated function, with no special syntax required. C pointers don't automatically dereference themselves. -- Neil Cerutti From tjreedy at udel.edu Thu May 5 14:39:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 May 2011 14:39:28 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <92fmffFucoU9@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <92fmffFucoU9@mid.individual.net> Message-ID: On 5/5/2011 9:19 AM, Neil Cerutti wrote: > On 2011-05-04, John Nagle wrote: >> That's a quirk of CPython's boxed number implementation. All >> integers are boxed, but there's a set of canned objects for >> small integers. CPython's range for this is -5 to +256, >> incidentally. That's visible through the "is" operator. >> Arguably, it should not be. > > But that's the sole purpose of the is operator. You either expose > those details, or you don't have an is operator at all. Which is to say, the CPython testsuite has a CPython-specific implementation test that uses 'is' to test that implementation detail. -- Terry Jan Reedy From joaquin.barry at gmail.com Thu May 5 15:09:28 2011 From: joaquin.barry at gmail.com (Wok-Thee-Recruiter) Date: Thu, 5 May 2011 12:09:28 -0700 (PDT) Subject: Employment Opportunity in Chicago Message-ID: <73f67ec1-cac4-4bee-ad9f-958ac87e3cb7@s16g2000prf.googlegroups.com> Python Developer Looking for a candidate with hands on Python development experience to work for a fast growing company that provides in-flight broadband services. ? This person will be working on portal development and optimizing plane systems. ? Help integrate third party products such as video and other products pertaining to aviation. ? Candidate should have a minimum of 5-7 years of experience. ? Position reports directly into the CTO Requirements ? 5-7 years of full software development lifecycle experience ? 2-3 years of Python development ? 2-3 years of SQL experience ? MySQL ? Database configuration Send emails to jbarry at pt-corp.com or call Joaquin direct at 312-643-2010 From ian.g.kelly at gmail.com Thu May 5 15:13:11 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 May 2011 13:13:11 -0600 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: On Thu, May 5, 2011 at 10:58 AM, harrismh777 wrote: > Grant Edwards wrote: >> >> That's what I was trying to say, but probably not as clearly. ?The "&" >> operatore returnas a_value_ ?that the OP passes_by_value_ ?to a >> function. ?That function then uses the "*" operator to use that value >> to access some data. > > I'm gonna try a D'Aprano-style bogus argument for a moment... > > ... saying that 'C' does not support pass-by-reference because you have to > direct the compiler with the '&' and '*' characters is a little like saying > that > > ? ? Python does not support decorations ! ... > > > ... ?because you have to direct the interpreter with some > > > @ bogus-decorator-syntax > > > ? ? I want Python to support decorations automatically ! It seems to me that manually referencing and dereferencing in C is more akin to decorating functions like this: def foo(x): do_stuff() foo = decorate(foo) On the other hand, the @ syntax is analogous to declaring reference types in C++ (e.g. "int &" as opposed to "int *"). In both cases you have to tell the interpreter / compiler that you want to use the decoration / pass-by-reference feature, and the actual work is done for you automatically. From harrismh777 at charter.net Thu May 5 16:12:45 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 05 May 2011 15:12:45 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> Message-ID: <2xDwp.49594$sS4.40218@newsfe11.iad> Ian Kelly wrote: > On the other hand, the @ syntax is analogous to declaring reference > types in C++ (e.g. "int&" as opposed to "int *"). In both cases you > have to tell the interpreter / compiler that you want to use the > decoration / pass-by-reference feature, and the actual work is done > for you automatically. [ @Ian, Neil ] :) ... uh, it was worth a shot... No, I see your point... with the slight small push-back that dereferencing a pointer with '*' can't really be called 'work' can it? ( I know, you'll say yes, because the 'compiler' didn't do it ! ) :)) From tacyt1007 at gmail.com Thu May 5 16:34:02 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Thu, 5 May 2011 22:34:02 +0200 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: > That means it's not finding it. After startup, try adding the zip > file to your sys.path and then do "import site" at the command line, > and it should work. Maybe I am missing the point, but I think I am not able to do this. When I remove the "Lib" folder and try to run Python.exe, the python console window closes rapidly, so that it is hard to read any message displayed in it and obvioulsy I can't run any python command. Could you clarify this please? > What if you put the zip file in your > PYTHONPATH environment variable? I don't have it defined. Maybe it is because I have 2 different Python interpreters installed. After adding the PYTHONPATH, the Python.exe seems to run normally. Unfortunately I am not able to import Image module (I am using it), which is installed in site-packages/PIL. This happens, because for some reason the site-packages directory is not present in sys.path. After reading the site module description I checked the sys.prefix and sys.exec_prefix, which are both empty, when the Lib folder is loaded from the zip archive. Thats why site-packages is not added to sys.path. Of course I can add site-packages directory to the sys.path by myself (yet I don't know why sys.prefix and sys.exec_prefix are empty), however how to deal with the PYTHONPATH, which is required to load site.py and hence has to be defined at the very beginning? thanks for your help 2011/5/5 Ian Kelly : > On Thu, May 5, 2011 at 4:55 AM, Wojtek Mamrak wrote: >> Thanks for the reply! >> >>> Can you import from zip files when running the Python.exe interpreter? >> When I zip the folder "Lib" into Python27.zip and later rename it and >> try to run the python.exe, I receive an error: >> "Import error: no module named site" > > That means it's not finding it. ?After startup, try adding the zip > file to your sys.path and then do "import site" at the command line, > and it should work. > >>> Are you getting any sort of error message? >> When I run my app, it crashes while calling Py_Initialize(). The >> console closes suddenly. > > Hm, that definitely seems odd. ?What if you put the zip file in your > PYTHONPATH environment variable? > >> Is it necessary to create zip archive using zipfile.PyZipFile? > > It shouldn't be. ?It works for me (at least with Python.exe) creating > the zip archive using 7-Zip. > From miki.tebeka at gmail.com Thu May 5 17:12:51 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 5 May 2011 14:12:51 -0700 (PDT) Subject: avro slow? Message-ID: <98cd6085-bb77-417b-80e4-68ca990001cf@glegroupsg2000goo.googlegroups.com> Greetings, I'm reading some data from avro file using the avro library. It takes about a minute to load 33K objects from the file. This seem very slow to me, specially with the Java version reading the same file in about 1sec. Here is the code, am I doing something wrong? import avro.datafile import avro.io from time import time def load(filename): fo = open(filename, "rb") reader = avro.datafile.DataFileReader(fo, avro.io.DatumReader()) for i, record in enumerate(reader): pass return i + 1 def main(argv=None): import sys from argparse import ArgumentParser argv = argv or sys.argv parser = ArgumentParser(description="Read avro file") start = time() num_records = load("events.avro") end = time() print("{0} records in {1} seconds".format(num_records, end - start)) if __name__ == "__main__": main() From pazurrobert at gmail.com Thu May 5 17:26:08 2011 From: pazurrobert at gmail.com (Robert Pazur) Date: Thu, 5 May 2011 23:26:08 +0200 Subject: access to some text string in PDFs Message-ID: Dear all, i would like to access some text and count the occurrence as follows > I got a lots of pdf with some scientific articles and i want to preview which words are usually related with for example "determinants" as an example in the article is a sentence > ....elevation is the most important determinant.... how can i acquire the "elevation" string? of course i dont know where the sententence in article is located or which particular word could there be any suggestions? Maybe its easy to solve, but its just one day since I subscribe to this forum (although i got some Python experience) so i really appreciate any help! Kind regards, Robert. ------------------------------------------------------- Robert Pazur -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu May 5 17:41:25 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 May 2011 15:41:25 -0600 Subject: Embedding Python's library as zip file In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 2:34 PM, Wojtek Mamrak wrote: > Maybe I am missing the point, but I think I am not able to do this. > When I remove the "Lib" folder and try to run Python.exe, the python > console window closes rapidly, so that it is hard to read any message > displayed in it and obvioulsy I can't run any python command. Could > you clarify this please? Darn, it worked for me in Python 2.5: C:\Python25>python 'import site' failed; use -v for traceback Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append(r'C:\Python25\lib.zip') >>> import site Although I am also seeing the issue with sys.prefix not getting set and site-packages not getting added. But in Python 2.7 I just get: C:\Python27>python ImportError: No module named site C:\Python27> And in Python 3.2 it causes a full-on crash: C:\Python32>python Fatal Python error: Py_Initialize: unable to load the file system codec LookupError: no codec search functions registered: can't find encoding This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. >> What if you put the zip file in your >> PYTHONPATH environment variable? > > I don't have it defined. Maybe it is because I have 2 different Python > interpreters installed. > After adding the PYTHONPATH, the Python.exe seems to run normally. > Unfortunately I am not able to import Image module (I am using it), > which is installed in site-packages/PIL. > This happens, because for some reason the site-packages directory is > not present in sys.path. After reading the site module description I > checked the sys.prefix and sys.exec_prefix, which are both empty, when > the Lib folder is loaded from the zip archive. Thats why site-packages > is not added to sys.path. > Of course I can add site-packages directory to the sys.path by myself > (yet I don't know why sys.prefix and sys.exec_prefix are empty), > however how to deal with the PYTHONPATH, which is required to load > site.py and hence has to be defined at the very beginning? Are you calling Py_SetProgramName? That may help to set sys.prefix and sys.exec_prefix. However, looking at site.py, it appears that it's only looking for proper directories. I don't think it will be able to add a site-packages inside a zip archive at all; you will just have to add that yourself. From rosuav at gmail.com Thu May 5 17:56:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 May 2011 07:56:17 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <654D9D97DA51AD479973BC2D5578603C0BEA7F4864@PDC-MAIL-CMS01.ubisoft.org> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> <654D9D97DA51AD479973BC2D5578603C0BEA7F4864@PDC-MAIL-CMS01.ubisoft.org> Message-ID: On Fri, May 6, 2011 at 2:27 AM, Andreas Tawn wrote: > If True and False: > ? ?waveFunction.collapse(cat) > > > That's going to be fun ;o) If a process crashes and init isn't there to hear it, does it produce a core dump? Chris Angelico From rosuav at gmail.com Thu May 5 18:01:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 May 2011 08:01:27 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> <92fsvjFkghU1@mid.individual.net> Message-ID: On Fri, May 6, 2011 at 1:29 AM, Roy Smith wrote: > "Hey, let's override operator,() and have some fun" Destroying sanity, for fun and profit. Chris Angelico From clp2 at rebertia.com Thu May 5 18:29:09 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 May 2011 15:29:09 -0700 Subject: access to some text string in PDFs In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 2:26 PM, Robert Pazur wrote: > Dear all, > i would like to access some text and count the?occurrence?as follows > > I got a lots of pdf with some scientific articles and i want to preview > ?which words are usually related with for example "determinants" > as an example in the article is a sentence > ....elevation is the most > important determinant.... > how can i acquire the "elevation" string? > of course i dont know where the sententence in article is located or which > particular word could there be > any suggestions? Extract the text using PDFMiner[1], pyPdf[2], or PageCatcher[3]. Then use something similar to n-grams on the extracted text, filtering out those that don't contain "determinant(s)". Then just keep a word frequency table for the remaining n-grams. Not-quite-pseudo-code: from collections import defaultdict, deque N = 7 # length of n-grams to consider; tune as needed buf = deque(maxlen=N) targets = frozenset(("determinant", "determinants")) steps_until_gone = 0 word2freq = defaultdict(int) for word in words_from_pdf: if word in targets: steps_until_gone = N buf.append(word) if steps_until_gone: for related_word in buf: if related_word not in targets: word2freq[related_word] += 1 steps_until_gone -= 1 for count, word in sorted((v,k) for k,v in word2freq.iteritems()): print(word, ':', count) Making this more efficient and less naive is left as an exercise to the reader. There may very well already be something similar but more sophisticated in NLTK[4]; I've never used it, so I dunno. [1]: http://www.unixuser.org/~euske/python/pdfminer/index.html [2]: http://pybrary.net/pyPdf/ [3]: http://www.reportlab.com/software/#pagecatcher [4]: http://www.nltk.org/ Cheers, Chris -- http://rebertia.com From drsalists at gmail.com Thu May 5 18:36:52 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 5 May 2011 15:36:52 -0700 Subject: avro slow? In-Reply-To: <98cd6085-bb77-417b-80e4-68ca990001cf@glegroupsg2000goo.googlegroups.com> References: <98cd6085-bb77-417b-80e4-68ca990001cf@glegroupsg2000goo.googlegroups.com> Message-ID: On Thu, May 5, 2011 at 2:12 PM, Miki Tebeka wrote: > Greetings, > > I'm reading some data from avro file using the avro library. It takes about > a minute to load 33K objects from the file. This seem very slow to me, > specially with the Java version reading the same file in about 1sec. > You might want to try an apache mailing list, like at http://avro.apache.org/mailing_lists.html , as I suspect most Python people use Python's native pickle support instead. It looks like the Python version of Avro is doing single-byte-at-a-time I/O for some types, which is almost guaranteed to perform poorly. If you're decoding an 8 byte integer, its much faster to at least read 8 bytes and then chop that up, and better still is to read a buffer at a time and chop that up too. Even in C, the performance of byte-at-a-time I/O is not going to be stellar, especially if you use read() rather than fread(). A related note: Python is often more about programmer efficiency than machine efficiency. With cost per MIPS going down and the price of programmer time going up, it seems a good idea. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Thu May 5 19:18:03 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 06 May 2011 01:18:03 +0200 Subject: avro slow? In-Reply-To: References: <98cd6085-bb77-417b-80e4-68ca990001cf@glegroupsg2000goo.googlegroups.com> Message-ID: Dan Stromberg, 06.05.2011 00:36: > Python is often more about programmer efficiency than > machine efficiency. With cost per MIPS going down and the price of > programmer time going up, it seems a good idea. Especially when you also count the MIPS improvement during the time it takes to write the code. Stefan From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu May 5 19:45:09 2011 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Fri, 06 May 2011 01:45:09 +0200 Subject: PIL: The _imaging C module is not installed References: Message-ID: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> Hi! > you need to install the appropriate libraries, among which are: > libjpeg-devel > freetype-devel > libpng-devel OK, but where can I find it? I want use PIL with Python under Windows, and I can't compile C's sources. Should I replace PIL by ImageMagick? @-salutations -- Michel Claveau From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu May 5 19:48:33 2011 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Fri, 06 May 2011 01:48:33 +0200 Subject: PIL: The _imaging C module is not installed References: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> Message-ID: <4dc3375a$0$14665$ba4acef3@reader.news.orange.fr> Re! And why the problem no exist with PIL 1.1.6? (only 1.1.7) Is that the version 1.1.6 does not use these libraries? @+ -- Michel Claveau From rosuav at gmail.com Thu May 5 20:51:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 May 2011 10:51:33 +1000 Subject: Py_XDECREF/Py_DECREF evaluating its argument more than once Message-ID: Okay, this is mainly a tale of a stupid C++ programmer who forgot the rules of C... I simplified a whole lot of code recently, cut out some temporary variables, did some general tidying-up, and then found that my program was segfaulting occasionally. Sure that I hadn't made any substantive changes, I went tinkering, and pinned it down to this change: Old code: PyObject *v=PyRun_StringFlags(code,Py_file_input,py_globals,locals,0); if (v) Py_DECREF(v); New code: Py_XDECREF(PyRun_StringFlags(code,Py_file_input,py_globals,locals,0)); It's the same, right? Py_XDECREF is just Py_DECREF with a check against null? No and whoops. DEC and XDEC are both implemented as *macros* and they evaluate their arguments more than once. (I'm not entirely sure of the cause of the segfault, but I'm guessing that the two runs of the code produced different results, or something. Not significant.) Would it be possible at some point to have them implemented as inline functions instead? At the top of my code, I just forced it thus: #undef Py_XDECREF inline void Py_XDECREF(PyObject *ob) {if (ob) Py_DECREF(ob);} Failing that, a warning note on the docs would be nice, but I'm guessing that idiots like me wouldn't think to read it. (Or if "idiot" is too strong, try "guy who's been spoiled by C++'s luxury".) Fortunately for my career, solving this self-created problem didn't take long, and my boss didn't even know about it till I'd solved it. *whoops* Just figured it might be worth mentioning, in case someone else is tempted to take a shortcut! Chris Angelico From rosuav at gmail.com Thu May 5 20:59:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 May 2011 10:59:59 +1000 Subject: Py_XDECREF/Py_DECREF evaluating its argument more than once In-Reply-To: References: Message-ID: Clarification: This IS stated in the source - in object.h are the following sage words: --- *** WARNING*** The Py_DECREF macro must have a side-effect-free argument since it may evaluate its argument multiple times. (The alternative would be to mace it a proper function or assign it to a global temporary variable first, both of which are slower; and in a multi-threaded environment the global variable trick is not safe.) --- (I assume that should be "make" not "mace", unless the implication is that turning a macro into a function involves pounding it into submission...) Since inline functions are a part of C99 as well as C++, would it be possible to have configure.sh detect its availability and optionally use that instead of preprocessor macros, or would this run the risk of encouraging trickily unportable code? Chris Angelico From clp2 at rebertia.com Thu May 5 21:11:23 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 May 2011 18:11:23 -0700 Subject: Py_XDECREF/Py_DECREF evaluating its argument more than once In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 5:59 PM, Chris Angelico wrote: > Since inline functions are a part of C99 as well as C++, would it be > possible to have configure.sh detect its availability and optionally > use that instead of preprocessor macros, or would this run the risk of > encouraging trickily unportable code? PEP 7 explicitly says to use C89... Cheers, Chris From 1011_wxy at 163.com Thu May 5 21:37:38 2011 From: 1011_wxy at 163.com (1011_wxy) Date: Fri, 6 May 2011 09:37:38 +0800 Subject: BeautifulSoup import error Message-ID: <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com> Dear friends: I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 . Is there any differences between Python 3.2 and other version? This is my first time to use Python3.2 . And the error message will be as below. >>> from BeautifulSoup import BeautifulSoup Traceback (most recent call last): File "", line 1, in from BeautifulSoup import BeautifulSoup File "C:\Python32\BeautifulSoup.py", line 448 raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr) ^ SyntaxError: invalid syntax And the error place point to BeautifulSoup class NavigableString(unicode, PageElement): def __new__(cls, value): """Create a new NavigableString. When unpickling a NavigableString, this method is called with the string in DEFAULT_OUTPUT_ENCODING. That encoding needs to be passed in to the superclass's __new__ or the superclass won't know how to handle non-ASCII characters. """ if isinstance(value, unicode): return unicode.__new__(cls, value) return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING) def __getnewargs__(self): return (NavigableString.__str__(self),) def __getattr__(self, attr): """text.string gives you text. This is for backwards compatibility for Navigable*String, but for CData* it lets you get the string without the CData wrapper.""" if attr == 'string': return self else: raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr) def __unicode__(self): return str(self).decode(DEFAULT_OUTPUT_ENCODING) def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING): if encoding: return self.encode(encoding) else: return self Did I make any mistake? How can I do this correctly? 2011-05-06 Kerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Thu May 5 21:46:30 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 May 2011 11:46:30 +1000 Subject: BeautifulSoup import error In-Reply-To: <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com> References: <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com> Message-ID: On Fri, May 6, 2011 at 11:37 AM, 1011_wxy <1011_wxy at 163.com> wrote: > I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 . > Is there any differences between Python 3.2 and other version? This is my > first time to use Python3.2 . > And the error message will be as below. Judging from your tracebacks, it would appear that BeuituflSoup has not yet been ported to and/or fixed for Python 3 compatibility. Maybe there's a later version of BeauitifulSOup or a development version that does support Python 3? There are several Syntax differences between Python 2.x and Python 3.x - notably: except Exception, e: # Python 2.x except Exception as e: # Python 3.x I might suggest you take a look at using lxml instead which ships with the standard library. [ ... ] cheers James -- -- James Mills -- -- "Problems are solved by method" From marduk at letterboxes.org Thu May 5 21:52:13 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 05 May 2011 21:52:13 -0400 Subject: PIL: The _imaging C module is not installed In-Reply-To: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> References: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> Message-ID: <1304646734.3212.3.camel@localhost.localdomain> On Fri, 2011-05-06 at 01:45 +0200, Michel Claveau - MVP wrote: > Hi! > > > you need to install the appropriate libraries, among which are: > > libjpeg-devel > > freetype-devel > > libpng-devel > > OK, but where can I find it? I want use PIL with Python under Windows, > and I can't compile C's sources. > Should I replace PIL by ImageMagick? The OP was about CentOS. I have no idea about Windows. From 1011_wxy at 163.com Thu May 5 22:29:15 2011 From: 1011_wxy at 163.com (1011_wxy) Date: Fri, 6 May 2011 10:29:15 +0800 Subject: =?UTF-8?Q?=E5=9B=9E=E5=A4=8D:=20=20Re:=20BeautifulSoup=20import=20error?= Message-ID: <541cf585.23105.12fc3207ff9.Coremail.1011_wxy@163.com> Dear JM: Thank you very much. BeautifulSoup does not work well with Python3.2 . 2011-05-06 Kerry ???: James Mills ????: 2011-05-06 09:47 ? ?: Re: BeautifulSoup import error ???: python list On Fri, May 6, 2011 at 11:37 AM, 1011_wxy <1011_wxy at 163.com> wrote: > I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 . > Is there any differences between Python 3.2 and other version? This is my > first time to use Python3.2 . > And the error message will be as below. Judging from your tracebacks, it would appear that BeuituflSoup has not yet been ported to and/or fixed for Python 3 compatibility. Maybe there's a later version of BeauitifulSOup or a development version that does support Python 3? There are several Syntax differences between Python 2.x and Python 3.x - notably: except Exception, e: # Python 2.x except Exception as e: # Python 3.x I might suggest you take a look at using lxml instead which ships with the standard library. [ ... ] cheers James -- -- James Mills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From miki.tebeka at gmail.com Thu May 5 23:20:56 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 5 May 2011 20:20:56 -0700 (PDT) Subject: Embedding Python's library as zip file In-Reply-To: Message-ID: <4bccd7ab-4bff-4b7c-a289-5c25ff259257@glegroupsg2000goo.googlegroups.com> I used py2exe in the past for that, see http://www.py2exe.org/index.cgi/ShippingEmbedded From miki.tebeka at gmail.com Thu May 5 23:20:56 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 5 May 2011 20:20:56 -0700 (PDT) Subject: Embedding Python's library as zip file In-Reply-To: Message-ID: <4bccd7ab-4bff-4b7c-a289-5c25ff259257@glegroupsg2000goo.googlegroups.com> I used py2exe in the past for that, see http://www.py2exe.org/index.cgi/ShippingEmbedded From jussij at zeusedit.com Fri May 6 00:39:36 2011 From: jussij at zeusedit.com (JussiJ) Date: Thu, 5 May 2011 21:39:36 -0700 (PDT) Subject: Python IDE/text-editor References: Message-ID: On Apr 16, 1:20 pm, Alec Taylor wrote: > I'm looking for an IDE which offers syntax-highlighting, > code-completion, tabs, The Zeus editor does offers all these features: http://www.zeusedit.com/ Zeus is also scriptable and Zeus scripts can be written in Python. Zeus also does Python smart indenting and code folding. > an embedded interpreter and which is portable Zeus does not have an embedded Python interpreter, but by using something like tee.exe it should be possible to emulate this: http://www.zeusedit.com/zforum/viewtopic.php?t=3156 > (for running from USB on Windows). Zeus is a Windows editor but it is not a Protable application. NOTE: Zeus is shareware. Jussi Jumppanen Author: Zeus for Windows From eaglebalti at gmail.com Fri May 6 00:55:22 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Thu, 5 May 2011 21:55:22 -0700 (PDT) Subject: Hello Friends Message-ID: Do you need legal help.If so Please visit www.chicagopersonalinjurylawyerz.blogspot.com From stefan_ml at behnel.de Fri May 6 01:57:51 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 06 May 2011 07:57:51 +0200 Subject: =?UTF-8?B?5Zue5aSNOiAgUmU6IEJlYXV0aWZ1bFNvdXAgaW1wb3J0IGVycm8=?= =?UTF-8?B?cg==?= In-Reply-To: <541cf585.23105.12fc3207ff9.Coremail.1011_wxy@163.com> References: <541cf585.23105.12fc3207ff9.Coremail.1011_wxy@163.com> Message-ID: 1011_wxy, 06.05.2011 04:29: > ???: James Mills >> On Fri, May 6, 2011 at 11:37 AM, 1011_wxy wrote: >>> I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 . >>> Is there any differences between Python 3.2 and other version? This is my >>> first time to use Python3.2 . >>> And the error message will be as below. >> >> Judging from your tracebacks, it would appear >> that BeuituflSoup has not yet been ported to >> and/or fixed for Python 3 compatibility. > > BeautifulSoup does not work well with Python3.2 . You can try to convert it using 2to3, though. > I might suggest you take a look at using lxml instead ... which works with all Python versions from 2.3 through 3.2. > which ships with the standard library. No. While this has been suggested, it will not become part of the stdlib in the foreseeable future. It's readily available as a separate package on PyPI, though. Stefan From prologic at shortcircuit.net.au Fri May 6 02:11:49 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 May 2011 16:11:49 +1000 Subject: =?UTF-8?B?UmU6IOWbnuWkjTogUmU6IEJlYXV0aWZ1bFNvdXAgaW1wb3J0IGVycm9y?= In-Reply-To: References: <541cf585.23105.12fc3207ff9.Coremail.1011_wxy@163.com> Message-ID: On Fri, May 6, 2011 at 3:57 PM, Stefan Behnel wrote: > No. While this has been suggested, it will not become part of the stdlib in > the foreseeable future. It's readily available as a separate package on > PyPI, though. Opps I meant xml.etree :/ My bad! cheers James -- -- James Mills -- -- "Problems are solved by method" From jabba.laci at gmail.com Fri May 6 02:36:26 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 6 May 2011 02:36:26 -0400 Subject: checking if a list is empty Message-ID: Hi, If I want to check if a list is empty, which is the more pythonic way? li = [] (1) if len(li) == 0: ... or (2) if not li: ... Thanks, Laszlo From nicogrubert at yahoo.de Fri May 6 02:55:32 2011 From: nicogrubert at yahoo.de (Nico Grubert) Date: Fri, 06 May 2011 08:55:32 +0200 Subject: Python-list Digest, Vol 92, Issue 40 In-Reply-To: References: Message-ID: <4DC39B64.5000708@yahoo.de> > PIL will compile and install if you don't have some development > libraries and then simply not work or not work up to full steam when > used. > > To avoid this, you need to install the appropriate libraries, among > which are: > > libjpeg-devel > freetype-devel > libpng-devel Dear Albert Thank you for your reply. I did install all these libraries. Testing it with yum shows: $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version $ yum install libjpeg-devel Package libjpeg-devel-6b-37.x86_64 already installed and latest version Package libjpeg-devel-6b-37.i386 already installed and latest version $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version Re-Compiling PIL shows: $ python setup.py build_ext -i -------------------------------------------------------------------- *** TKINTER support not available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available -------------------------------------------------------------------- However, running the selftest still fails: $ python selftest.py *** The _imaging C module is not installed Regards Nico From clp2 at rebertia.com Fri May 6 03:08:24 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 00:08:24 -0700 Subject: checking if a list is empty In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 11:36 PM, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? Option (2), IMO. > li = [] > > (1) if len(li) == 0: > ... FYI, also equivalent: if not len(li): ... > or > (2) if not li: Cheers, Chris From jabba.laci at gmail.com Fri May 6 03:18:17 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 6 May 2011 03:18:17 -0400 Subject: string formatting Message-ID: Hi, Which is the preferred way of string formatting? (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky', 'blue') As I know (1) is old style. (2) and (3) are new but (3) is only supported from Python 2.7+. Which one should be used? Laszlo From steve+comp.lang.python at pearwood.info Fri May 6 04:46:04 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 May 2011 08:46:04 GMT Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> Message-ID: <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: > Jabba Laci a ?crit ce vendredi 6 mai 2011 09:18 dans > : > >> Hi, >> >> Which is the preferred way of string formatting? >> >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {}".format('sky', 'blue') >> >> As I know (1) is old style. (2) and (3) are new but (3) is only >> supported from Python 2.7+. >> >> Which one should be used? > > According to python's documentation, (3) and (2) are preferred and (1) > is deprecated. I think you are wrong, % formatting is not deprecated. Do you have a link showing otherwise? [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 warnings >>> warnings.simplefilter("always") >>> "%d" % 42 '42' I see no DeprecationWarning. -- Steven From clp2 at rebertia.com Fri May 6 05:23:19 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 02:23:19 -0700 Subject: string formatting In-Reply-To: <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 6, 2011 at 1:46 AM, Steven D'Aprano wrote: > On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: >> Jabba Laci a ?crit ce vendredi 6 mai 2011 09:18 dans >> : >>> Hi, >>> >>> Which is the preferred way of string formatting? >>> >>> (1) "the %s is %s" % ('sky', 'blue') >>> >>> (2) "the {0} is {1}".format('sky', 'blue') >>> >>> (3) "the {} is {}".format('sky', 'blue') >>> >>> As I know (1) is old style. (2) and (3) are new but (3) is only >>> supported from Python 2.7+. >>> >>> Which one should be used? >> >> According to python's documentation, (3) and (2) are preferred and (1) >> is deprecated. > > I think you are wrong, % formatting is not deprecated. Do you have a link > showing otherwise? I'm not them, but: "Note: The formatting operations described here [involving %] are obsolete and may go away in future versions of Python. Use the new String Formatting [i.e. format()] in new code." http://docs.python.org/dev/library/stdtypes.html#old-string-formatting-operations Technically, not formally deprecated, but such a characterization isn't too far off the mark either. Cheers, Chris -- http://rebertia.com From dmitrey15 at gmail.com Fri May 6 05:24:23 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 6 May 2011 02:24:23 -0700 (PDT) Subject: seems like a bug in isinstance() Message-ID: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> hi all, suppose I've created a class Point in file .../openopt/kernel/Point.py Consider the code in file .../somewhere/file1.py from openopt.kernel.Point import Point p = Point() now let's pass p into a func from .../openopt/kernel/file2.py and check from Point import Point isinstance(p, Point) So, it returns False! p is , while Point is I have Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) D. From tartley at tartley.com Fri May 6 05:51:09 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 6 May 2011 02:51:09 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: On Apr 26, 3:39?pm, snorble wrote: > I appreciate any advice or guidance anyone has to offer. The 'Python Project HOWTO' gives good advice in terms of setting up a new project, what files and directories to create, what to put in version control, etc: http://infinitemonkeycorps.net/docs/pph/ Also, where I work we have tried many IDEs, but happily and productively use GVim and very little else, so don't feel you *have* to use an IDE. Best regards, Jonathan Hartley From clp2 at rebertia.com Fri May 6 05:57:39 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 02:57:39 -0700 Subject: seems like a bug in isinstance() In-Reply-To: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> Message-ID: On Fri, May 6, 2011 at 2:24 AM, dmitrey wrote: > hi all, > > suppose I've created a class Point in file .../openopt/kernel/Point.py > > Consider the code in file .../somewhere/file1.py > from openopt.kernel.Point import Point > p = Point() > > now let's pass p into a func from .../openopt/kernel/file2.py and > check > from Point import Point > isinstance(p, Point) > > So, it returns False! > > p is , while Point is openopt.kernel.Point.Point at 0x2048e20> > > [Subject: seems like a bug in isinstance()] This is due to a peculiarity of how (C)Python's import machinery works; isinstance() is working just fine. (And if you ever think you've found a bug in Python's built-ins, odds are you haven't. Python has been around too long, someone ought to have encountered it earlier, statistically speaking.) Note how the class is referred to as both Point.Point and openopt.kernel.Point.Point. This is because you did `from Point import ...` in file2.py, whereas in file1.py you did `from openopt.kernel.Point import ...`. These 2 different ways of referring to the same module are sufficient to "trick"/"outsmart" (C)Python and cause it to import the same module twice as 2 separate instances (i.e. it gets re-executed). Why the import machinery isn't smarter in this situation, I don't recall. The output of this should be illuminating: print(Point, type(p), type(p) is Point, id(Point), id(type(p))) As this demonstrates, you're dealing with 2 separate definitions of the same Point class. Solution: Avoid the implicitly-relative `from Point import ...` style of import; always use the absolute `from openopt.kernel.Point import ...` style instead. Subsequent imports will thus reference the already-previously-imported instance of a module rather than importing a copy of it from scratch again. Cheers, Chris -- http://rebertia.com From mail at timgolden.me.uk Fri May 6 05:59:54 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 06 May 2011 10:59:54 +0100 Subject: Development tools and practices for Pythonistas In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <4DC3C69A.3010606@timgolden.me.uk> On 06/05/2011 10:51, Jonathan Hartley wrote: > On Apr 26, 3:39 pm, snorble wrote: >> I appreciate any advice or guidance anyone has to offer. > > The 'Python Project HOWTO' gives good advice in terms of setting up a > new project, what files and directories to create, what to put in > version control, etc: > > http://infinitemonkeycorps.net/docs/pph/ I'd forgotten about that. Great resource! Thanks for reminding me... TJG From tacyt1007 at gmail.com Fri May 6 06:10:33 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Fri, 6 May 2011 12:10:33 +0200 Subject: Embedding Python's library as zip file In-Reply-To: <4bccd7ab-4bff-4b7c-a289-5c25ff259257@glegroupsg2000goo.googlegroups.com> References: <4bccd7ab-4bff-4b7c-a289-5c25ff259257@glegroupsg2000goo.googlegroups.com> Message-ID: > Are you calling Py_SetProgramName? That may help to set sys.prefix > and sys.exec_prefix. However, looking at site.py, it appears that > it's only looking for proper directories. I don't think it will be > able to add a site-packages inside a zip archive at all; you will just > have to add that yourself. Yes, I have tried Py_SetProgramName, but I am even not sure what argument (name, path?) should be passed to it and how it will affect the application. Some good news. After simplifying my application I realized, that importing of modules from the zip archive works well, I only have to add site-packages to sys.path (it looks like "python27.zip/site-packages"). Unfortunately even though I can import Image package, something still causes applications' sudden death. I will try to figure out what is the reason of that. As I said, the only non-standard package I am using is PIL. From lists at cheimes.de Fri May 6 06:16:03 2011 From: lists at cheimes.de (Christian Heimes) Date: Fri, 06 May 2011 12:16:03 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: <4dc3375a$0$14665$ba4acef3@reader.news.orange.fr> References: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> <4dc3375a$0$14665$ba4acef3@reader.news.orange.fr> Message-ID: Am 06.05.2011 01:48, schrieb Michel Claveau - MVP: > Re! > > And why the problem no exist with PIL 1.1.6? (only 1.1.7) > Is that the version 1.1.6 does not use these libraries? PIL 1.1.6 also uses its internal C library to speed things up. For Windows you should use the precompiled packages. http://www.pythonware.com/products/pil/ offers X86 Windows binaries for 1.1.7. You might run into a problem with 1.1.7 Windows binaries. The freetype C library references a debug CRT that is not available on all machines. You can easily patch the _imagingft.pyd file with a hex editor. Christian From dmitrey15 at gmail.com Fri May 6 06:20:58 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 6 May 2011 03:20:58 -0700 (PDT) Subject: seems like a bug in isinstance() References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> Message-ID: <8a61409d-7b30-4644-96dd-9bc750906e31@cu4g2000vbb.googlegroups.com> On May 6, 12:57?pm, Chris Rebert wrote: > On Fri, May 6, 2011 at 2:24 AM, dmitrey wrote: > > hi all, > > > suppose I've created a class Point in file .../openopt/kernel/Point.py > > > Consider the code in file .../somewhere/file1.py > > from openopt.kernel.Point import Point > > p = Point() > > > now let's pass p into a func from .../openopt/kernel/file2.py and > > check > > from Point import Point > > isinstance(p, Point) > > > So, it returns False! > > > p is , while Point is > openopt.kernel.Point.Point at 0x2048e20> > > > [Subject: seems like a bug in isinstance()] > > This is due to a peculiarity of how (C)Python's import machinery > works; isinstance() is working just fine. > (And if you ever think you've found a bug in Python's built-ins, odds > are you haven't. Python has been around too long, someone ought to > have encountered it earlier, statistically speaking.) > > Note how the class is referred to as both Point.Point and > openopt.kernel.Point.Point. This is because you did `from Point import > ...` in file2.py, whereas in file1.py you did `from > openopt.kernel.Point import ...`. These 2 different ways of referring > to the same module are sufficient to "trick"/"outsmart" (C)Python and > cause it to import the same module twice as 2 separate instances (i.e. > it gets re-executed). Why the import machinery isn't smarter in this > situation, I don't recall. > > The output of this should be illuminating: > print(Point, type(p), type(p) is Point, id(Point), id(type(p))) > As this demonstrates, you're dealing with 2 separate definitions of > the same Point class. > > Solution: Avoid the implicitly-relative `from Point import ...` style > of import; always use the absolute `from openopt.kernel.Point import > ...` style instead. Subsequent imports will thus reference the > already-previously-imported instance of a module rather than importing > a copy of it from scratch again. > > Cheers, > Chris > --http://rebertia.com Thanks Cris, however, I had understood reason of the bug and mere informed Python developers of the bug to fix it. >>> print(Point, type(p), type(p) is Point, id(Point), id(type(p))) (, , False, 44211536, 8585344) The proposed solution of using `from openopt.kernel.Point import ... ' everywhere is already performed but is not nice for me. I have lots of places like that in my code; also, when I import something from openopt it performs recursive import of many files including that one where Point is defined, thus I have cycled imports (well, it somehow works, but is unstable and may lead to future bugs). Also, writing "from Point import Point" is much simpler than using each time the long string "from name1.name2.Point import Point". I think it's Python developers who have to fix the issue, not users. I have 5 years of intensive Python experience yet it took same time to me to locate the bug, because my algorithm got "False" from isinstance() and went absolutely different thread from "if isinstance(): ... else: ...". This bug could be encountered very seldom under rare circumstances and thus be quite difficult to be located, especially for Python newbies unawared of this one. Regards, D. From chardster at gmail.com Fri May 6 06:34:40 2011 From: chardster at gmail.com (Richard Thomas) Date: Fri, 6 May 2011 03:34:40 -0700 (PDT) Subject: checking if a list is empty References: Message-ID: <39d4afc7-633f-4a44-a2f7-d4e442fafb38@k25g2000yqf.googlegroups.com> On May 6, 7:36?am, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: > ... > > Thanks, > > Laszlo I prefer (1), it feels more explicit about what I'm testing. The fact that empty sequences evaluate as false feels like a bit of a quirk to me. Actually the fact that 0 evaluates as false feels like a bit of a quirk to me, I more of a "use booleans in boolean contexts" kind of programmer. From lutfioduncuoglu at gmail.com Fri May 6 06:47:12 2011 From: lutfioduncuoglu at gmail.com (Lutfi Oduncuoglu) Date: Fri, 6 May 2011 13:47:12 +0300 Subject: if statement multiple or Message-ID: Hi, I am trying to write a script and I realised that I need to use something like if ('a' or 'b' or 'c') not in line: print line But it does not work for. What may be the problem Thanks, Lutfi -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Fri May 6 07:00:24 2011 From: lists at cheimes.de (Christian Heimes) Date: Fri, 06 May 2011 13:00:24 +0200 Subject: if statement multiple or In-Reply-To: References: Message-ID: Am 06.05.2011 12:47, schrieb Lutfi Oduncuoglu: > Hi, > > I am trying to write a script and I realised that I need to use something > like > > if ('a' or 'b' or 'c') not in line: > print line > > But it does not work for. What may be the problem if any(s not in line for s in ('a', 'b', 'c')): # do something Christian From marduk at letterboxes.org Fri May 6 07:02:30 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 06 May 2011 07:02:30 -0400 Subject: if statement multiple or In-Reply-To: References: Message-ID: <1304679750.355863.0.camel@localhost.localdomain> On Fri, 2011-05-06 at 13:47 +0300, Lutfi Oduncuoglu wrote: > Hi, > > I am trying to write a script and I realised that I need to use > something like > > if ('a' or 'b' or 'c') not in line: > print line > The expression: ('a' or 'b' or 'c') evaluates to True True not in line Is probably not what you intended. From marduk at letterboxes.org Fri May 6 07:04:18 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 06 May 2011 07:04:18 -0400 Subject: if statement multiple or In-Reply-To: References: Message-ID: <1304679858.355863.1.camel@localhost.localdomain> Correction: ('a' or 'b' or 'c') evaluates to 'a' From clp2 at rebertia.com Fri May 6 07:08:33 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 04:08:33 -0700 Subject: if statement multiple or In-Reply-To: <1304679750.355863.0.camel@localhost.localdomain> References: <1304679750.355863.0.camel@localhost.localdomain> Message-ID: On Fri, May 6, 2011 at 4:02 AM, Albert Hopkins wrote: > On Fri, 2011-05-06 at 13:47 +0300, Lutfi Oduncuoglu wrote: >> Hi, >> >> I am trying to write a script and I realised that I need to use >> something like >> >> if ('a' or 'b' or 'c') ?not in line: >> ? ?print line >> > > The expression: > ? ?('a' or 'b' or 'c') > > evaluates to True Not quite: $ python Python 2.6.6 (r266:84292, Jan 12 2011, 13:35:00) >>> 'a' or 'b' or 'c' 'a' >>> Cheers, Chris From prologic at shortcircuit.net.au Fri May 6 07:34:27 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 May 2011 21:34:27 +1000 Subject: checking if a list is empty In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 4:36 PM, Jabba Laci wrote: > If I want to check if a list is empty, which is the more pythonic way? [...] > (2) if not li: This is fine. cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Fri May 6 07:36:22 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 May 2011 21:36:22 +1000 Subject: if statement multiple or In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 8:47 PM, Lutfi Oduncuoglu wrote: > I am trying to write a script and I realised that I need to use something > like > > if ('a' or 'b' or 'c')? not in line: > ?? print line > > But it does not work for. What may be the problem You will need to (naively) do this: if "a" not in line or "b" not in line or "c" not in line: print line cheers James -- -- James Mills -- -- "Problems are solved by method" From rustompmody at gmail.com Fri May 6 07:55:12 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 6 May 2011 04:55:12 -0700 (PDT) Subject: Python packaging (was Development tools and practices for Pythonistas) References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: On May 6, 2:59?pm, Tim Golden wrote: > On 06/05/2011 10:51, Jonathan Hartley wrote: > > > On Apr 26, 3:39 pm, snorble ?wrote: > >> I appreciate any advice or guidance anyone has to offer. > > > The 'Python Project HOWTO' gives good advice in terms of setting up a > > new project, what files and directories to create, what to put in > > version control, etc: > > >http://infinitemonkeycorps.net/docs/pph/ > > I'd forgotten about that. Great resource! Thanks for reminding me... > > TJG Thanks for that link. There is one question in this regard that is not covered: package-use Of course this http://infinitemonkeycorps.net/docs/pph/#id10 is there. But I am talking of setting up one's python environment. For example on a linux box how to best optimize using the native package manager (eg apt/rpm) along with packages from pypi. And when one needs to run with multiple pythons how to use virtualenv etc From tooscattered at gmail.com Fri May 6 08:09:49 2011 From: tooscattered at gmail.com (scattered) Date: Fri, 6 May 2011 05:09:49 -0700 (PDT) Subject: if statement multiple or References: Message-ID: <9e36f9bc-0009-4924-9b36-62438bd52399@k22g2000yqh.googlegroups.com> On May 6, 7:00?am, Christian Heimes wrote: > Am 06.05.2011 12:47, schrieb Lutfi Oduncuoglu: > > > Hi, > > > I am trying to write a script and I realised that I need to use something > > like > > > if ('a' or 'b' or 'c') ?not in line: > > ? ?print line > > > But it does not work for. What may be the problem > > if any(s not in line for s in ('a', 'b', 'c')): > ? ?# do something > > Christian sets could also work if set('abc') & set(line) == set(): print line From lists at cheimes.de Fri May 6 08:25:27 2011 From: lists at cheimes.de (Christian Heimes) Date: Fri, 06 May 2011 14:25:27 +0200 Subject: if statement multiple or In-Reply-To: <9e36f9bc-0009-4924-9b36-62438bd52399@k22g2000yqh.googlegroups.com> References: <9e36f9bc-0009-4924-9b36-62438bd52399@k22g2000yqh.googlegroups.com> Message-ID: Am 06.05.2011 14:09, schrieb scattered: > sets could also work > > if set('abc') & set(line) == set(): > print line Right! Sets work in this special case, because the OP just wants to search for a single char. It won't work for longer strings, though. Also I would write the test as: if set(line).isdisjoint("abc"): print line Christian From nirina.raseliarison at gmail.com Fri May 6 08:27:41 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Fri, 06 May 2011 15:27:41 +0300 Subject: BeautifulSoup import error In-Reply-To: <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com> References: <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com> Message-ID: [1011_wxy] > I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 the error i see is a SyntaxError. > Is there any differences between Python 3.2 and other version? yes. and there is a tool, 2to3, which converts Python 2.x scripts to work with 3.x. > And the error message will be as below. > > >>>> from BeautifulSoup import BeautifulSoup > Traceback (most recent call last): > File "", line 1, in > from BeautifulSoup import BeautifulSoup > File "C:\Python32\BeautifulSoup.py", line 448 > raise AttributeError, "'%s' object has no attribute '%s'" % > (self.__class__.__name__, attr) > ^ > SyntaxError: invalid syntax a quick fix here, change: raise AttributeError, "'%s' object has no attribute '%s'" %(self.__class__.__name__, attr) to: raise AttributeError("'%s' object has no attribute '%s'" %(self.__class__.__name__, attr)) enclose the string message with parentheses. at least, you will not get the SyntaxError. but a better solution is to use 2to3. i don't use BeautifulSoup, and i'm still stick with Python2.5.4 on windows, so can't help much. with Linux, it is just: 2to3 a_python_file_or_a_dir_package on windows, i don't know, maybe: import subprocess subprocess.Popen(('python.exe', 'Tools/Scripts/2to3.py', 'the_package')) -- nirinA From tacyt1007 at gmail.com Fri May 6 08:52:52 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Fri, 6 May 2011 14:52:52 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: References: <4dc3368d$0$30773$ba4acef3@reader.news.orange.fr> <4dc3375a$0$14665$ba4acef3@reader.news.orange.fr> Message-ID: @Michel use PIL downloaded from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/ regards 2011/5/6 Christian Heimes : > Am 06.05.2011 01:48, schrieb Michel Claveau - MVP: >> Re! >> >> And why the problem no exist with PIL 1.1.6? ?(only 1.1.7) >> Is that the version 1.1.6 does not use these libraries? > > PIL 1.1.6 also uses its internal C library to speed things up. > > For Windows you should use the precompiled packages. > http://www.pythonware.com/products/pil/ offers X86 Windows binaries for > 1.1.7. You might run into a problem with 1.1.7 Windows binaries. The > freetype C library references a debug CRT that is not available on all > machines. You can easily patch the _imagingft.pyd file with a hex editor. > > Christian > > -- > http://mail.python.org/mailman/listinfo/python-list > From pruebauno at latinmail.com Fri May 6 09:06:46 2011 From: pruebauno at latinmail.com (nn) Date: Fri, 6 May 2011 06:06:46 -0700 (PDT) Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc3e52a$0$24510$426a74cc@news.free.fr> Message-ID: On May 6, 8:10?am, Web Dreamer wrote: > Chris Rebert a ?crit ce vendredi 6 mai 2011 11:23 dans > : > > > > > I'm not them, but: > > "Note: The formatting operations described here [involving %] are > > obsolete and may go away in future versions of Python. Use the new > > String Formatting [i.e. format()] in new code." > >http://docs.python.org/dev/library/stdtypes.html#old-string-formatting- > operations > > > Technically, not formally deprecated, but such a characterization > > isn't too far off the mark either. > > Thanks Chris for the link. > > Indeed, They mention: > > "The formatting operations described here are obsolete and may go away in > future versions of Python. Use the new String Formatting in new code." > > So the proper word is "obsolete" and in my mind I remembered "deprecated" > since they say it could be removed from future versions of python. > > So I should have said "obsolete". > > What I would like to know is the difference between "deprecated" and > "obsolete"... > > -- > Web Dreamer In this context I think obsolete means: Will be removed in some undetermined version in the future; 3 versions or more from now. There is also pending deprecation: Will be (usually) removed in the version after the next. And deprecated: Will be removed in the next version. From neilc at norwich.edu Fri May 6 09:10:27 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 6 May 2011 13:10:27 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <92fbt9FfooU1@mid.individual.net> <92fsvjFkghU1@mid.individual.net> Message-ID: <92iaa2FdjoU4@mid.individual.net> On 2011-05-05, Chris Angelico wrote: > On Fri, May 6, 2011 at 1:29 AM, Roy Smith wrote: >> "Hey, let's override operator,() and have some fun" > > Destroying sanity, for fun and profit. I was thinking more along the lines of stuff like combining the envelope pattern (an interface class containing a pointer to an implementation) with template classes to create type-safe polymorphic types with specializable, decoupled implementations. A Python programmer just feels depressed that anyone could have a need for such innovations, though. ;) -- Neil Cerutti From pazurrobert at gmail.com Fri May 6 09:12:35 2011 From: pazurrobert at gmail.com (Robert Pazur) Date: Fri, 6 May 2011 15:12:35 +0200 Subject: access to some text string in PDFs In-Reply-To: References: Message-ID: Hi Chris, thanks for fast reply and all recommendations in helps me much! as you recommended me i used Pdfminer module to extract the text from pdf files and then with file.xreadlines() I allocated the lines where my keyword ("factors in this case") appears. Till now i extract just the lines but im wondering if its able to extract whole sentenses (only this) where my keawords ("factors in this case") are located. I used following script >> import os, subprocess path="C:\\PDF" # insert the path to the directory of interest here dirList=os.listdir(path) for fname in dirList: output =fname.rstrip(".pdf") + ".txt" subprocess.call(["C:\Python26\python.exe", "pdf2txt.py", "-o", output, fname]) print fname file = open(output) for line in file.xreadlines(): if "driving" in line: print(line) ------------------------------------------------------- Robert Pazur Mobile : +421 948 001 705 Skype : ruegdeg 2011/5/6 Chris Rebert > On Thu, May 5, 2011 at 2:26 PM, Robert Pazur > wrote: > > Dear all, > > i would like to access some text and count the occurrence as follows > > > I got a lots of pdf with some scientific articles and i want to preview > > which words are usually related with for example "determinants" > > as an example in the article is a sentence > ....elevation is the most > > important determinant.... > > how can i acquire the "elevation" string? > > of course i dont know where the sententence in article is located or > which > > particular word could there be > > any suggestions? > > Extract the text using PDFMiner[1], pyPdf[2], or PageCatcher[3]. Then > use something similar to n-grams on the extracted text, filtering out > those that don't contain "determinant(s)". Then just keep a word > frequency table for the remaining n-grams. > > Not-quite-pseudo-code: > from collections import defaultdict, deque > N = 7 # length of n-grams to consider; tune as needed > buf = deque(maxlen=N) > targets = frozenset(("determinant", "determinants")) > steps_until_gone = 0 > word2freq = defaultdict(int) > for word in words_from_pdf: > if word in targets: > steps_until_gone = N > buf.append(word) > if steps_until_gone: > for related_word in buf: > if related_word not in targets: > word2freq[related_word] += 1 > steps_until_gone -= 1 > for count, word in sorted((v,k) for k,v in word2freq.iteritems()): > print(word, ':', count) > > Making this more efficient and less naive is left as an exercise to the > reader. > There may very well already be something similar but more > sophisticated in NLTK[4]; I've never used it, so I dunno. > > [1]: http://www.unixuser.org/~euske/python/pdfminer/index.html > [2]: http://pybrary.net/pyPdf/ > [3]: http://www.reportlab.com/software/#pagecatcher > [4]: http://www.nltk.org/ > > Cheers, > Chris > -- > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tooscattered at gmail.com Fri May 6 09:17:26 2011 From: tooscattered at gmail.com (scattered) Date: Fri, 6 May 2011 06:17:26 -0700 (PDT) Subject: if statement multiple or References: <9e36f9bc-0009-4924-9b36-62438bd52399@k22g2000yqh.googlegroups.com> Message-ID: <67941d2c-ad97-4395-80b9-59e8c941df99@w21g2000yqm.googlegroups.com> On May 6, 8:25?am, Christian Heimes wrote: > Am 06.05.2011 14:09, schrieb scattered: > > > sets could also work > > > if set('abc') & set(line) == set(): > > ? ? ?print line > > Right! > Sets work in this special case, because the OP just wants to search for > a single char. It won't work for longer strings, though. > > Also I would write the test as: > > if set(line).isdisjoint("abc"): > ? ? print line > > Christian Thanks for the tip - I'm still learning Python and was unaware of the isdisjoint method. From tacyt1007 at gmail.com Fri May 6 09:23:48 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Fri, 6 May 2011 15:23:48 +0200 Subject: Embedding Python's library as zip file In-Reply-To: References: <4bccd7ab-4bff-4b7c-a289-5c25ff259257@glegroupsg2000goo.googlegroups.com> Message-ID: > I used py2exe in the past for that, see http://www.py2exe.org/index.cgi/ShippingEmbedded Thanks for the advice, py2exe seems to be a great tool. Unfortunately the application stops executing at the same place. It might be the case of PIL library, I found some entries about it on py2exe site. From mail at timgolden.me.uk Fri May 6 09:31:41 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 06 May 2011 14:31:41 +0100 Subject: if statement multiple or In-Reply-To: <67941d2c-ad97-4395-80b9-59e8c941df99@w21g2000yqm.googlegroups.com> References: <9e36f9bc-0009-4924-9b36-62438bd52399@k22g2000yqh.googlegroups.com> <67941d2c-ad97-4395-80b9-59e8c941df99@w21g2000yqm.googlegroups.com> Message-ID: <4DC3F83D.7040407@timgolden.me.uk> On 06/05/2011 14:17, scattered wrote: > On May 6, 8:25 am, Christian Heimes wrote: >> Am 06.05.2011 14:09, schrieb scattered: >> >>> sets could also work >> >>> if set('abc')& set(line) == set(): >>> print line >> >> Right! >> Sets work in this special case, because the OP just wants to search for >> a single char. It won't work for longer strings, though. >> >> Also I would write the test as: >> >> if set(line).isdisjoint("abc"): >> print line >> >> Christian > > Thanks for the tip - I'm still learning Python and was unaware of the > isdisjoint method. If it's any consolation, I've been using Python for 10 years and I was unaware of the isdisjoint method. :) TJG From nicogrubert at yahoo.de Fri May 6 09:56:32 2011 From: nicogrubert at yahoo.de (Nico Grubert) Date: Fri, 06 May 2011 15:56:32 +0200 Subject: PIL: The _imaging C module is not installed Message-ID: <4DC3FE10.2060001@yahoo.de> > PIL will compile and install if you don't have some development > libraries and then simply not work or not work up to full steam when > used. > > To avoid this, you need to install the appropriate libraries, among > which are: > > libjpeg-devel > freetype-devel > libpng-devel Dear Albert Thank you for your reply. I did install all these libraries. Testing it with yum shows: $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version $ yum install libjpeg-devel Package libjpeg-devel-6b-37.x86_64 already installed and latest version Package libjpeg-devel-6b-37.i386 already installed and latest version $ yum install libpng-devel Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and latest version Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and latest version Re-Compiling PIL shows: $ python setup.py build_ext -i -------------------------------------------------------------------- *** TKINTER support not available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available -------------------------------------------------------------------- However, running the selftest still fails: $ python selftest.py *** The _imaging C module is not installed Regards Nico From steve+comp.lang.python at pearwood.info Fri May 6 10:24:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 May 2011 14:24:56 GMT Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 02:23:19 -0700, Chris Rebert wrote: > On Fri, May 6, 2011 at 1:46 AM, Steven D'Aprano > wrote: >> On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: >>> Jabba Laci a ?crit ce vendredi 6 mai 2011 09:18 dans >>> : >>>> Hi, >>>> >>>> Which is the preferred way of string formatting? >>>> >>>> (1) "the %s is %s" % ('sky', 'blue') >>>> >>>> (2) "the {0} is {1}".format('sky', 'blue') >>>> >>>> (3) "the {} is {}".format('sky', 'blue') >>>> >>>> As I know (1) is old style. (2) and (3) are new but (3) is only >>>> supported from Python 2.7+. >>>> >>>> Which one should be used? >>> >>> According to python's documentation, (3) and (2) are preferred and (1) >>> is deprecated. >> >> I think you are wrong, % formatting is not deprecated. Do you have a >> link showing otherwise? > > I'm not them, but: > "Note: The formatting operations described here [involving %] are > obsolete and may go away in future versions of Python. Use the new > String Formatting [i.e. format()] in new code." > http://docs.python.org/dev/library/stdtypes.html#old-string-formatting- operations > > Technically, not formally deprecated, but such a characterization isn't > too far off the mark either. Not deprecated at all. In context, deprecation *is* a formal process. In any case, on occasions that the issue has been raised, there has been considerable community objection to removal of % formatting. Guido might want to remove it, but I wouldn't bet on it happening before Python 4000. It's perfectly safe to continue using % formatting, if you choose. -- Steven From za_yaniddd at abv.bg Fri May 6 10:29:55 2011 From: za_yaniddd at abv.bg (za_yaniddd at abv.bg) Date: Fri, 6 May 2011 07:29:55 -0700 (PDT) Subject: $$$ GET FREE 1000 DOLLARS $$$ Message-ID: $$$ GET FREE 1000 DOLLARS $$$ GET FREE $ 1000 for first poker deposit in BET 365 !!! GET FREE $ 200 for first sports deposit in BET365 !!! GET FREE $ 200 for first casino deposit in BET 365 !!! http://sportbet365casino.blogspot.com/ From steve+comp.lang.python at pearwood.info Fri May 6 10:33:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 May 2011 14:33:01 GMT Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc3e52a$0$24510$426a74cc@news.free.fr> Message-ID: <4dc4069d$0$29992$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 14:10:17 +0200, Web Dreamer wrote: > What I would like to know is the difference between "deprecated" and > "obsolete"... Writing x*x instead of x**2 is obsolete, but it will never go away. Writing apply(func, args) instead of func(*args) is deprecated. It has gone away. Obsolete is a value judgment you are welcome to ignore. Deprecation is a formal process that warns you that your code *will* break in the future. -- Steven From info at wingware.com Fri May 6 10:54:35 2011 From: info at wingware.com (Wingware) Date: Fri, 06 May 2011 10:54:35 -0400 Subject: Wing IDE 4.0.2 Released Message-ID: <4DC40BAB.2080206@wingware.com> Hi, Wingware has released version 4.0.2 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.2** * Added introduce variable refactoring operation * Support for using *.pi files to augment source analysis of *.py files * Support autocompletion for PySide Qt bindings * Recognize tags and attributes for HTML5 * Avoid problems with Ubuntu Unity * Fixed matplotlib support for GtkAgg backend and missing default backend * Syntax highlight comments in Django template files * Fixed syntax highlighting for Cython, VHDL, R, and several others * Fixed failure to replace all search matches near the end of a file * About 40 other bug fixes and minor improvements See the change log for details. **New Features in Version 4.0** Version 4.0 adds the following new major features: * Refactoring -- Rename/move, extract to function/method, and introduce variable * 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.2/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 alec.taylor6 at gmail.com Fri May 6 10:55:31 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 7 May 2011 00:55:31 +1000 Subject: Python IDE/text-editor In-Reply-To: References: Message-ID: No thanks, it's shareware, doesn't included embedded python interpreter out-of-the-box, and isn't portable. On Fri, May 6, 2011 at 2:39 PM, JussiJ wrote: > On Apr 16, 1:20 pm, Alec Taylor wrote: > >> I'm looking for an IDE which offers syntax-highlighting, >> code-completion, tabs, > > The Zeus editor does offers all these features: > > ? ?http://www.zeusedit.com/ > > Zeus is also scriptable and Zeus scripts can be written in Python. > > Zeus also does Python smart indenting and code folding. > >> an embedded interpreter and which is portable > > Zeus does not have an embedded Python interpreter, but by using > something like tee.exe it should be possible to emulate this: > > ? ?http://www.zeusedit.com/zforum/viewtopic.php?t=3156 > >> (for running from USB on Windows). > > Zeus is a Windows editor but it is not a Protable application. > > NOTE: Zeus is shareware. > > Jussi Jumppanen > Author: Zeus for Windows > -- > http://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Fri May 6 10:58:19 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 May 2011 15:58:19 +0100 Subject: string formatting In-Reply-To: References: Message-ID: <4DC40C8B.5090901@mrabarnett.plus.com> On 06/05/2011 08:18, Jabba Laci wrote: > Hi, > > Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old style. (2) and (3) are new but (3) is only > supported from Python 2.7+. > > Which one should be used? > I use Python 3, and I tend to use (3), unless I need to use the same value more than once. From awilliam at whitemice.org Fri May 6 11:06:13 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 06 May 2011 11:06:13 -0400 Subject: string formatting In-Reply-To: <4DC40C8B.5090901@mrabarnett.plus.com> References: <4DC40C8B.5090901@mrabarnett.plus.com> Message-ID: <1304694373.8740.13.camel@linux-yu4c.site> On Fri, 2011-05-06 at 15:58 +0100, MRAB wrote: > On 06/05/2011 08:18, Jabba Laci wrote: > > Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old style. (2) and (3) are new but (3) is only > > supported from Python 2.7+. > > Which one should be used? > I use Python 3, and I tend to use (3), unless I need to use the same > value more than once. I like: 'my name is {name}'.format(name='Adam') That makes things clearest, IMO. From python at mrabarnett.plus.com Fri May 6 11:29:01 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 May 2011 16:29:01 +0100 Subject: string formatting In-Reply-To: <1304694373.8740.13.camel@linux-yu4c.site> References: <4DC40C8B.5090901@mrabarnett.plus.com> <1304694373.8740.13.camel@linux-yu4c.site> Message-ID: <4DC413BD.7060701@mrabarnett.plus.com> On 06/05/2011 16:06, Adam Tauno Williams wrote: > On Fri, 2011-05-06 at 15:58 +0100, MRAB wrote: >> On 06/05/2011 08:18, Jabba Laci wrote: >>> Which is the preferred way of string formatting? >>> (1) "the %s is %s" % ('sky', 'blue') >>> (2) "the {0} is {1}".format('sky', 'blue') >>> (3) "the {} is {}".format('sky', 'blue') >>> As I know (1) is old style. (2) and (3) are new but (3) is only >>> supported from Python 2.7+. >>> Which one should be used? >> I use Python 3, and I tend to use (3), unless I need to use the same >> value more than once. > > I like: > > 'my name is {name}'.format(name='Adam') > > That makes things clearest, IMO. > I wouldn't do that for a short piece of text, but for a much longer piece of text with multiple values, it does make it a lot clearer. From gandalf at shopzeus.com Fri May 6 12:21:07 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 06 May 2011 18:21:07 +0200 Subject: dictionary size changed during iteration In-Reply-To: References: <4DAED72B.2030400@shopzeus.com> Message-ID: <4DC41FF3.3090601@shopzeus.com> >> ... > That works, but if d is large, it won't be very efficient because it has > to generate a large list. It is not large. But I'm using Python 2.6 , not Python 3. I did not get this error again in the last two days. I'll post a new reply if I encounter it again. (It happened just a few times out of many thousand program invocations) From steve+comp.lang.python at pearwood.info Fri May 6 12:59:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 May 2011 16:59:30 GMT Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 May 2011 10:33:31 -0700, Raymond Hettinger wrote: > I think it is time to give some visibility to some of the instructive > and very cool recipes in ActiveState's python cookbook. [...] > What are your favorites? I'm not sure if favourite is the right word, but I'm amazed by this one: McCarthy's "amb" (ambiguous) operator. http://code.activestate.com/recipes/577368 Here's how I might use it to solve the problem if making change. In Australian currency, I have 5, 10, 20, 50 cent and $1 and $2 coins. Ignoring the dollar coins, how can I make up change for any multiple of five cents up to a dollar? Suppose I have more 5 cent coins that I can deal with, and I want to make sure I hand out at least three of them. Here's how to make 45 cents worth of change: >>> amb = Amb() >>> a = amb(range(3, 21)) # number of 5 cent coins >>> b = amb(range(11)) # number of 10 cent coins >>> c = amb(range(6)) # number of 20 cent coins >>> d = amb(range(3)) # number of 50 cent coins >>> for _ in amb(lambda a,b,c,d: 5*a+10*b+20*c+50*d == 45): ... print a, b, c, d ... 3 1 1 0 3 3 0 0 5 0 1 0 5 2 0 0 7 1 0 0 9 0 0 0 Suppose I have some words, and want to put them together so that there are a certain number of vowels: >>> amb = Amb() >>> a = amb(['quick', 'slow', 'hungry', 'wise-old']) >>> b = amb(['fox', 'hare', 'turtle', 'kangaroo']) >>> c = amb(['lazy', 'stupid', 'sleepy', 'confused']) >>> d = amb(['dog', 'aardvark', 'sloth', 'wombat']) >>> >>> def test(a, b, c, d): ... s = "The %s brown %s jumped over the %s %s." % (a, b, c, d) ... num_vowels = sum(s.count(c) for c in 'aeiou') ... return num_vowels in (12, 18, 19) ... >>> for _ in amb(test): ... print a, b, c, d ... quick fox lazy sloth quick fox lazy dog quick kangaroo stupid aardvark [...more solutions cut for brevity] hungry kangaroo confused aardvark As written, amb is just a brute-force solver using more magic than is good for any code, but it's fun to play with. -- Steven From ian.g.kelly at gmail.com Fri May 6 13:27:18 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 11:27:18 -0600 Subject: seems like a bug in isinstance() In-Reply-To: <8a61409d-7b30-4644-96dd-9bc750906e31@cu4g2000vbb.googlegroups.com> References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> <8a61409d-7b30-4644-96dd-9bc750906e31@cu4g2000vbb.googlegroups.com> Message-ID: On Fri, May 6, 2011 at 4:20 AM, dmitrey wrote: > Thanks Cris, however, I had understood reason of the bug and mere > informed Python developers of the bug to fix it. No you haven't. Few if any Python developers make a habit of reading this newsgroup. To actually report the issue so that it might get fixed, you need to add it to the issue tracker at http://bugs.python.org Anyway, I played around with this a little and was unable to reproduce it, so I suspect the issue is actually a bit more complicated than what Chris is describing. From debatem1 at gmail.com Fri May 6 13:43:06 2011 From: debatem1 at gmail.com (geremy condra) Date: Fri, 6 May 2011 10:43:06 -0700 Subject: Coolest Python recipe of all time In-Reply-To: <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 6, 2011 at 9:59 AM, Steven D'Aprano wrote: > On Mon, 02 May 2011 10:33:31 -0700, Raymond Hettinger wrote: > >> I think it is time to give some visibility to some of the instructive >> and very cool recipes in ActiveState's python cookbook. > [...] >> What are your favorites? > > > I'm not sure if favourite is the right word, but I'm amazed by this one: > McCarthy's "amb" (ambiguous) operator. > > http://code.activestate.com/recipes/577368 > > Here's how I might use it to solve the problem if making change. In > Australian currency, I have 5, 10, 20, 50 cent and $1 and $2 coins. > Ignoring the dollar coins, how can I make up change for any multiple of > five cents up to a dollar? > > Suppose I have more 5 cent coins that I can deal with, and I want to make > sure I hand out at least three of them. Here's how to make 45 cents worth > of change: > >>>> amb = Amb() >>>> a = amb(range(3, 21)) ?# number of 5 cent coins >>>> b = amb(range(11)) ?# number of 10 cent coins >>>> c = amb(range(6)) ?# number of 20 cent coins >>>> d = amb(range(3)) ?# number of 50 cent coins >>>> for _ in amb(lambda a,b,c,d: 5*a+10*b+20*c+50*d == 45): > ... ? ? print a, b, c, d > ... > 3 1 1 0 > 3 3 0 0 > 5 0 1 0 > 5 2 0 0 > 7 1 0 0 > 9 0 0 0 > > > Suppose I have some words, and want to put them together so that there > are a certain number of vowels: > >>>> amb = Amb() >>>> a = amb(['quick', 'slow', 'hungry', 'wise-old']) >>>> b = amb(['fox', 'hare', 'turtle', 'kangaroo']) >>>> c = amb(['lazy', 'stupid', 'sleepy', 'confused']) >>>> d = amb(['dog', 'aardvark', 'sloth', 'wombat']) >>>> >>>> def test(a, b, c, d): > ... ? ? s = "The %s brown %s jumped over the %s %s." % (a, b, c, d) > ... ? ? num_vowels = sum(s.count(c) for c in 'aeiou') > ... ? ? return num_vowels in (12, 18, 19) > ... >>>> for _ in amb(test): > ... ? ? print a, b, c, d > ... > quick fox lazy sloth > quick fox lazy dog > quick kangaroo stupid aardvark > [...more solutions cut for brevity] > hungry kangaroo confused aardvark > > > > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. I use a similar technique *a lot* for various kinds of constraint solvers, but I have yet to come up with a really satisfying spelling for it. Have you looked at the way this is done in Sage? Geremy Condra From Dick.Bridges at wdc.com Fri May 6 13:43:08 2011 From: Dick.Bridges at wdc.com (Dick Bridges) Date: Fri, 6 May 2011 10:43:08 -0700 Subject: setuptools for 64-bit 2.7.1 on 64-bit Windows 7? Message-ID: Hi all, Can someone provide some search terms I can use to find guidelines for installing modules for my 'stock' 64-bit r 271:86832, Nov 27, 2010 [MSC v.1500 64 bit (AMD)] on Win32. Host is 64-bit Windows 7. My goal is to install suds. Period. That's all. So far I've spent the better part of two days trying to figure out how to make python setup.py install actually work. Current error involves "...no module named setuptools" and, of course all I can find is the 32-bit setuptools-0.6c11.win32-py2.7.exe which fails with "Python version 2.7 required, which was not found in the registry." There's nothing new here - all of this has appeared in various forums over the last few years - but none I have found contains an actual answer. Simple question: Is it true that no setuptools (or any other module installer) exists for 64-bit python 2.7.1? If there is an installer that works, what terms might I use to Google for information on how to acquire and install it? Regards, Dick Bridges (\(\ Western Digital ?". .. ( . .) The opinions and data in this missive are my own and do not necessarily | ? ? represent Western Digital positions, strategies, or opinions. ? ; c?".UJ" Glenda: http://glenda.cat-v.org/gallery/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen at -NOSPAM-xs4all.nl Fri May 6 13:47:58 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Fri, 06 May 2011 19:47:58 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: References: Message-ID: <4dc4344f$0$65870$e4fe514c@news.xs4all.nl> On 06-05-11 15:56, Nico Grubert wrote: > > However, running the selftest still fails: > $ python selftest.py > *** The _imaging C module is not installed > I had this happening to me as well someday. I recall that first installing it (python setup.py install), and then rerunning selftest, solved that error. Irmen From alister.ware at ntlworld.com Fri May 6 13:49:41 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Fri, 06 May 2011 17:49:41 GMT Subject: Hello Friends References: Message-ID: On Thu, 05 May 2011 21:55:22 -0700, Ashraf Ali wrote: > Do you need legal help.If so Please visit > www.chicagopersonalinjurylawyerz.blogspot.com sorry I would only use a reputable firm (spaming a news group makes you disreputable by default) -- My NOSE is NUMB! From nospam at torek.net Fri May 6 13:57:03 2011 From: nospam at torek.net (Chris Torek) Date: 6 May 2011 17:57:03 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <92fb5jFa2lU1@mid.individual.net> <4dc2c52e$0$10567$742ec2ed@news.sonic.net> Message-ID: >>> John Nagle wrote: >>>> A reasonable compromise would be that "is" is treated as "==" on >>>> immutable objects. (Note: I have no dog in this fight, I would be happy with a changed "is" or with the current one -- leaky abstractions are fine with me, provided I am told *when* they may -- or sometimes may not -- leak. :-) ) >> On 5/5/2011 3:06 AM, Gregory Ewing wrote: >>> That wouldn't work for tuples, which can contain references >>> to other objects that are not immutable. >On Thu, May 5, 2011 at 9:41 AM, John Nagle wrote: >> Such tuples are still identical, even if they >> contain identical references to immutable objects. In article Ian Kelly wrote: >>>> a = (1, 2, [3, 4, 5]) >>>> b = (1, 2, [3, 4, 5]) >>>> a == b >True >>>> a is b # Using the proposed definition >True I believe that John Nagle's proposal would make "a is b" false, because while a and b are both immutable, they contain *different* refernces to *mutable* objects (thus failing the "identical references to immutable objects" part of the claim). On the other hand, should one do: L = [3, 4, 5] a = (1, 2, L) b = (1, 2, L) then "a is b" should (I say) be True under the proposal -- even though they contain (identical) references to *mutable* objects. Loosely speaking, we would define the "is" relation as: (x is y) if and only if (id(x) == id(y) or (x is immutable and y is immutable and (for all components xi and yi of x, xi is yi))) In this case, even if the tuples "a" and "b" have different id()s, we would find that both have an immutable type, and both have components -- in this case, numbered, subscriptable tuple elements, but instances of immutable class types like decimal.Decimal would have dictionaries instead -- and thus we would recursively apply the modified "is" definition to each element. (For tuples, the "all components" implies that the lengths must be equal; for class instances, it implies that they need to have "is"-equal attributes, etc.) It's not entirely clear to me whether different immutable classes (i.e., different types) but with identical everything-else should compare equal under this modified "is". I.e., today: $ cp /usr/lib/python2.?/decimal.py /tmp/deccopy.py $ python ... >>> sys.path.append('/tmp') >>> import decimal >>> import deccopy >>> x = decimal.Decimal('1') >>> y = deccopy.Decimal('1') >>> print x, y 1 1 >>> x == y False and obviously "x is y" is currently False: >>> type(x) >>> type(y) However, even though the types differ, both x and y are immutable [%] and obviously (because I copied the code) they have all the same operations. Since they were both created with the same starting value, x and y will behave identically given identical treatment. As such, it might be reasonable to ask that "x is y" be True rather than False. [% This is not at all obvious -- I have written an immutable class, and it is pretty easy to accidentally mutate an instance inside the class implementation. There is nothing to prevent this in CPython, at least. If there were a minor bug in the decimal.Decimal code such that x.invoke_bug() modified x, then x would *not* be immutable, even though it is "intended to be". (As far as I know there are no such bugs in decimal.Decimal, it's just that I had them in my "Money" class.)] -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From nospam at torek.net Fri May 6 14:17:55 2011 From: nospam at torek.net (Chris Torek) Date: 6 May 2011 18:17:55 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article harrismh777 wrote: >There may be some language somewhere that does pass-by-reference which >is not implemented under the hood as pointers, but I can't think of >any... 'cause like I've been saying, way down under the hood, we only >have direct and indirect memory addressing in today's processors. EOS. There have been Fortran compilers that implemented modification of variables via "value-result" rather than "by-reference". This is perhaps best illustrated by some code fragments: SUBROUTINE FOO(X, Y) INTEGER X, Y ... X = 3 Y = 4 RETURN SUBROUTINE BAR(A) FOO(A, 0) RETURN might compile to the equivalent of the following C code: void foo(int *x0, int *y0) { int x = *x0, y = *y0; ... *x0 = x; *y0 = y; } void bar(int *a0) { int a = *a0; int temp = 0; foo(&a, &temp); *a0 = a; } In order to allow both by-reference and value-result, Fortran forbids the programmer to peek at the machinery. That is, the following complete program is invalid: SUBROUTINE PEEK(X) INTEGER X, GOTCHA COMMON /BLOCK/ GOTCHA PRINT *, 'INITIALLY GOTCHA = ', GOTCHA X = 4 PRINT *, 'AFTER X=4 GOTCHA = ', GOTCHA RETURN PROGRAM MAIN INTEGER GOTCHA COMMON /BLOCK/ GOTCHA GOTCHA = 3 PEEK(GOTCHA) PRINT *, 'FINALLY GOTCHA = ', GOTCHA STOP END (It has been so long since I used Fortran that the above may not be quite right in ways other than the one intended. Please forgive small errors. :-) ) The trick in "subroutine peek" is that it refers to both a "global variable" (in Fortran, simulated with a common block) and a "dummy variable" (as it is termed in Fortran) -- the parameter that aliases the global variable -- in such a way that we can see *when* the change happens. If "gotcha" starts out set to 3, remains 3 after assignment to x, and changes to 4 after peek() returns, then peek() effectively used value-result to change the parameter. If, on the other hand, "gotcha" became 4 immediately after the assignment to x, then peek() effectively used by-reference. The key take-away here is not so much the trick by which we "peeked inside" the implementation (although peeking *is* useful in solving the "murder mystery" we have after some program aborts with a core-dump or what-have-you), but rather the fact that the Fortran language proper forbids us from peeking at all. By forbidding it -- by making the program illegal -- the language provide implementors the freedom to use *either* by-reference or value-result. All valid Fortran programs behave identically under either kind of implementation. Like it or not, Python has similar "defined as undefined" grey areas: one is not promised, for instance, whether the "is" operator is always True for small integers that are equal (although it is in CPython), nor when __del__ is called (if ever), and so on. As with the Python-named-Monty, we have "rigidly defined areas of doubt and uncertainty". These exist for good reasons: to allow different implementations. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From ian.g.kelly at gmail.com Fri May 6 14:36:09 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 12:36:09 -0600 Subject: Coolest Python recipe of all time In-Reply-To: <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 6, 2011 at 10:59 AM, Steven D'Aprano wrote: > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. This isn't really amb; as you said it's just a brute-force solver with some weird syntax. The whole point of amb is to enable non-deterministic programming, such as this: def find_values(): a = amb(1, 3, 5) b = amb(2, 4, 8) if a + b <= 5: fail() if not is_prime(a * b + 1): fail() c = amb(a, b, None) if c is not None and c < 5: fail() return a, b, c The amb engine would conceptually execute this function for every possible combination of a, b, and c, pruning away the combinations that fail at some point, and arbitrarily returning one of the remaining combinations. So find_values() here might return (3, 4, None) after failing at one point or another on (1, 2); (1, 4); (1, 8); (3, 2); (3, 4, 3); and (3; 4; 4). Note in particular that the declaration of c is not easily expressible using the Python recipe. This is typically implemented using continuations, and I'm not sure whether a true amb could actually be achieved in Python without adding continuations or flow-control macros to the language. From john at castleamber.com Fri May 6 14:46:52 2011 From: john at castleamber.com (John Bokma) Date: Fri, 06 May 2011 13:46:52 -0500 Subject: Hello Friends References: Message-ID: <87k4e3hdk3.fsf@castleamber.com> Alister Ware writes: > On Thu, 05 May 2011 21:55:22 -0700, Ashraf Ali wrote: > >> Do you need legal help.If so Please visit >> > > sorry I would only use a reputable firm > (spaming a news group makes you disreputable by default) Does it make you disreputable? Since you just repeated the spamvertized URL... -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From nospam at torek.net Fri May 6 15:06:27 2011 From: nospam at torek.net (Chris Torek) Date: 6 May 2011 19:06:27 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article I wrote, in part: >Like it or not, Python has similar "defined as undefined" grey >areas: one is not promised, for instance, whether the "is" operator >is always True for small integers that are equal (although it is >in CPython), nor when __del__ is called (if ever), and so on. As >with the Python-named-Monty, we have "rigidly defined areas of >doubt and uncertainty". These exist for good reasons: to allow >different implementations. Oops, attribution error: this comes from Douglas Adams rather than Monty Python. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From harrismh777 at charter.net Fri May 6 15:22:25 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 06 May 2011 14:22:25 -0500 Subject: string formatting In-Reply-To: <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > It's perfectly safe to continue using % formatting, if you choose. > I would hope so, since its the way in most of the books, much of the doc and a majority of the code... I don't really like the old style, not because there is anything wrong with it, because its an obvious carry-over from the cryptic formatting style of 'C' printf(), and others. It seems to me that the purpose of formatting is to make output clear, and therefore the output formatting style itself should be clear and clean. On the other hand, among the three styles listed by the OP (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky', 'blue') ... they all *feel* good... I mean, they're all clear, clean, precise... On the other hand, while any 'C' programmer is able to see instantly that (1) is a some type of formatting construct, (2) & (3) are clear and obvious formatting constructs, even for newbies and esp. for non 'C' programmers. On the other hand, at this point, it seems that this is personal preference issue completely. So, if the book says you can do it, and there is no formal deprecation process in the works, feel free to express yourself with the style that best suits 'you'. On the other hand,..... :) kind regards, m harris From harrismh777 at charter.net Fri May 6 15:25:52 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 06 May 2011 14:25:52 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4XXwp.18782$Ot6.2313@newsfe15.iad> Chris Torek wrote: >> with the Python-named-Monty, we have "rigidly defined areas of >> >doubt and uncertainty". These exist for good reasons: to allow >> >different implementations. > Oops, attribution error: this comes from Douglas Adams rather > than Monty Python. Well, its certainly Monte-esq.... I like it, whoever said it. From tjreedy at udel.edu Fri May 6 15:31:57 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 May 2011 15:31:57 -0400 Subject: checking if a list is empty In-Reply-To: References: Message-ID: On 5/6/2011 7:34 AM, James Mills wrote: > On Fri, May 6, 2011 at 4:36 PM, Jabba Laci wrote: >> If I want to check if a list is empty, which is the more pythonic way? > > [...] > >> (2) if not li: > > This is fine. This is the intended way. Anything in addition is extra noise and wasted calculation. In other words, let Python do the boilerplate work for you. -- Terry Jan Reedy From ian.g.kelly at gmail.com Fri May 6 15:38:08 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 13:38:08 -0600 Subject: Coolest Python recipe of all time In-Reply-To: References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 6, 2011 at 12:36 PM, Ian Kelly wrote: > This is typically implemented using continuations, and I'm not sure > whether a true amb could actually be achieved in Python without adding > continuations or flow-control macros to the language. I stand corrected. After poking around a bit more I found this recipe that is designed for unit-testing but implements amb beautifully. http://lackingrhoticity.blogspot.com/2009/08/how-to-do-model-checking-of-python-code.html My code from the previous post using this recipe: def find_values(chooser): def amb(*choices): return chooser.choose(choices) def require(x): if not x: amb() a = amb(1, 3, 5) b = amb(2, 4, 8) require(a + b > 5) require(is_prime(a * b + 1)) c = amb(a, b, None) require(c is None or c >= 5) return a, b, c check(find_values) The one downside is that the check function (again, designed for unit-testing) does not provide any way to retrieve the returned values, but that is easily solved by rewriting as a generator. Cheers, Ian From harrismh777 at charter.net Fri May 6 15:39:15 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 06 May 2011 14:39:15 -0500 Subject: string formatting In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: harrismh777 wrote: OP wrote: > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') On the other hand, consider this 3.x code snip: print("the %s is %d" % ('sky', 'blue')) That formatting will throw an exception, because the format construct is restricting the format entry to be a number, which 'blue' clearly isn't.... The following print() is better, because *any* time or *most* types can be substituted and the 'polymorphism' of Python kicks in allowing for that, as so: print("the {} is {}".format('sky', 3.4)) print("the {} is {}".format('sky', 'blue')) l=['cloudy', 'today'] print("the {} is {}".format('sky', l)) On the other hand,.... :) kind regards, m harris From dmitrey15 at gmail.com Fri May 6 15:40:13 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 6 May 2011 12:40:13 -0700 (PDT) Subject: Python 3 dict question Message-ID: hi all, suppose I have Python dict myDict and I know it's not empty. I have to get any (key, value) pair from the dict (no matter which one) and perform some operation. In Python 2 I used mere key, val = myDict.items()[0] but in Python 3 myDict.items() return iterator. Of course, I could use for key, val in myDict.items(): do_something break but maybe there is any better way? Thank you in advance, D. From harrismh777 at charter.net Fri May 6 15:49:24 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 06 May 2011 14:49:24 -0500 Subject: checking if a list is empty In-Reply-To: References: Message-ID: <9hYwp.5805$xo2.3333@newsfe07.iad> Terry Reedy wrote: >>> (2) if not li: >> >> This is fine. > > This is the intended way. Anything in addition is extra noise and wasted > calculation. In other words, let Python do the boilerplate work for you. I agree, but I don't like it. ... if not li says nothing about what li is supposed to 'be' and implies in any case that li does not exist, or worse is some kind of boolean. li is in fact an empty list [] and will identify as such, and of course (as a list object) has all of the attributes and methods of a list... Why not have a list method that makes this more explicit: if not li.emptylist() if not li.empty([]) there might be others... kind regards, m harris From clp2 at rebertia.com Fri May 6 15:51:27 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 12:51:27 -0700 Subject: Python 3 dict question In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 12:40 PM, dmitrey wrote: > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterator. > Of course, I could use > for key, val in myDict.items(): > ? do_something > ? break > but maybe there is any better way? key, val = next(myDict.items()) Cheers, Chris From neilc at norwich.edu Fri May 6 15:54:14 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 6 May 2011 19:54:14 GMT Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92j1v6FthtU1@mid.individual.net> On 2011-05-06, harrismh777 wrote: > Steven D'Aprano wrote: >> It's perfectly safe to continue using % formatting, if you >> choose. > > I would hope so, since its the way in most of the books, much > of the doc and a majority of the code... > > I don't really like the old style, not because there is > anything wrong with it, because its an obvious carry-over from > the cryptic formatting style of 'C' printf(), and others. It > seems to me that the purpose of formatting is to make output > clear, and therefore the output formatting style itself should > be clear and clean. C's printf is a venerable example of the power of notation. Notation kicks ass. Another that's well known are regular expressions. Python uses this powerful idea again in the struct module. Any other places? Functions and classes are a general purpose, though verbose, form of notation and can be used in place of mini languages when you don't want to bother, e.g., C++'s iostreams, and pyparsing's grammar declarations. Lisp declared that you could implement mini-languages in Lisp, rather than just parsing them. Python 3's format notation is an improvement for Python, since Python doesn't need the type information that's crucial for C and particularly scanf, an application of C's mini-language that Python doesn't need. Delimiting the escape sequences also makes it easier to read and parse complex formating declarations. For simple constructs there's not much difference between them, but if you switch to .format you'll probably reap some benefit. -- Neil Cerutti From ian.g.kelly at gmail.com Fri May 6 15:54:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 13:54:52 -0600 Subject: string formatting In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 6, 2011 at 1:39 PM, harrismh777 wrote: > harrismh777 wrote: ? ?OP wrote: > >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {}".format('sky', 'blue') > > ? On the other hand, consider this 3.x code snip: > > ? print("the %s is %d" % ('sky', 'blue')) > > > ? That formatting will throw an exception, because the format construct is > restricting the format entry to be a number, which 'blue' clearly isn't.... If you used %d, then that exception is presumably what you wanted. If not, then you should just do: print("the %s is %s" % ('sky', 'blue')) > ? The following print() is better, because *any* time or *most* types can be > substituted and the 'polymorphism' of Python kicks in allowing for that, as > so: '%s' has exactly the same degree of polymorphism as '{}', because both simply call str() on their argument. There are good reasons to use format instead of % if possible, but polymorphism isn't one of them. From dmitrey15 at gmail.com Fri May 6 15:57:11 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 6 May 2011 12:57:11 -0700 (PDT) Subject: Python 3 dict question References: Message-ID: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> On May 6, 10:51?pm, Chris Rebert wrote: > On Fri, May 6, 2011 at 12:40 PM, dmitrey wrote: > > hi all, > > suppose I have Python dict myDict and I know it's not empty. > > I have to get any (key, value) pair from the dict (no matter which > > one) and perform some operation. > > In Python 2 I used mere > > key, val = myDict.items()[0] > > but in Python 3 myDict.items() return iterator. > > Of course, I could use > > for key, val in myDict.items(): > > ? do_something > > ? break > > but maybe there is any better way? > > key, val = next(myDict.items()) > > Cheers, > Chris Unfortunately, it doesn't work, it turn out to be dict_items: >>> next({1:2}.items()) Traceback (most recent call last): File "", line 1, in TypeError: dict_items object is not an iterator >>> dir({1:2}.items()) ['__and__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__or__', '__rand__', '__reduce__', '__reduce_ex__', '__repr__', '__ror__', '__rsub__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__xor__', 'isdisjoint'] From python at rcn.com Fri May 6 15:58:56 2011 From: python at rcn.com (Raymond Hettinger) Date: Fri, 6 May 2011 12:58:56 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <31819e29-a02f-4721-bb75-5decbd0056ae@i39g2000prd.googlegroups.com> [Steven D'Aprano]: > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. With a small change in API, much of the magic isn't needed. from itertools import product def amb(func, *argument_ranges): for args in product(*argument_ranges): if func(*args): print(args) amb(lambda a,b,c,d: 5*a+10*b+20*c+50*d == 45, range(3, 21), # number of 5 cent coins range(11), # number of 10 cent coins range(6), # number of 20 cent coins range(3), # number of 50 cent coins ) def test(a, b, c, d): s = "The %s brown %s jumped over the %s %s." % (a, b, c, d) num_vowels = sum(s.count(c) for c in 'aeiou') return num_vowels in (12, 18, 19) amb(test, ['quick', 'slow', 'hungry', 'wise-old'], ['fox', 'hare', 'turtle', 'kangaroo'], ['lazy', 'stupid', 'sleepy', 'confused'], ['dog', 'aardvark', 'sloth', 'wombat'], ) amb(lambda x, y, z: x*x + y*y == z*z, range(1, 11), range(1, 11), range(1, 11), ) Raymond ------------ follow my recipes and tips on twitter: @raymondh From ericsnowcurrently at gmail.com Fri May 6 16:00:02 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 6 May 2011 14:00:02 -0600 Subject: checking if a list is empty In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 1:31 PM, Terry Reedy wrote: > On 5/6/2011 7:34 AM, James Mills wrote: > >> On Fri, May 6, 2011 at 4:36 PM, Jabba Laci wrote: >> >>> If I want to check if a list is empty, which is the more pythonic way? >>> >> >> [...] >> >> (2) if not li: >>> >> >> This is fine. >> > > This is the intended way. Anything in addition is extra noise and wasted > calculation. In other words, let Python do the boilerplate work for you. > > That works for lists, but for a class that implements a list-like interface, subclassing list or not, it will not always work the way you want. The language reference indicates that, for the implicit cast to a bool, __bool__ is checked on the object, then __len__, and then it defaults to True [1]. So the above only works the way you expect if __len__ is the normal length for a list and __bool__ is not defined. I ran into this once when I had a class that defined __len__ but wanted the object to cast to True no matter what. For my case I chose to redefine __bool__. So it seems like this boils down to what you want to know. Is the list empty (length 0) or is the boolean version false? Again, for lists these are the same. For list-like classes they are not necessarily the same. Incidently, you can also check "if li == []:". This will let the __eq__ operator jump in. -eric [1] http://docs.python.org/dev/py3k/reference/datamodel.html#object.__bool__ -- > Terry Jan Reedy > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri May 6 16:02:23 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 14:02:23 -0600 Subject: Python 3 dict question In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 1:51 PM, Chris Rebert wrote: > On Fri, May 6, 2011 at 12:40 PM, dmitrey wrote: >> hi all, >> suppose I have Python dict myDict and I know it's not empty. >> I have to get any (key, value) pair from the dict (no matter which >> one) and perform some operation. >> In Python 2 I used mere >> key, val = myDict.items()[0] >> but in Python 3 myDict.items() return iterator. >> Of course, I could use >> for key, val in myDict.items(): >> ? do_something >> ? break >> but maybe there is any better way? > > key, val = next(myDict.items()) Recognizing that if myDict is empty then this will raise StopIteration instead of KeyError. From awilliam at whitemice.org Fri May 6 16:05:09 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 06 May 2011 16:05:09 -0400 Subject: checking if a list is empty In-Reply-To: <9hYwp.5805$xo2.3333@newsfe07.iad> References: <9hYwp.5805$xo2.3333@newsfe07.iad> Message-ID: <1304712309.9905.10.camel@linux-yu4c.site> On Fri, 2011-05-06 at 14:49 -0500, harrismh777 wrote: > Terry Reedy wrote: > >>> (2) if not li: > >> This is fine. > > This is the intended way. Anything in addition is extra noise and wasted > > calculation. In other words, let Python do the boilerplate work for you. > I agree, but I don't like it. +1 This is the Python reality-distortion-field at work. Motto#1: Python is all about readability! Motto#2: Crytic code is awesome if it is Pythoncally cryptic! I'd never accept code like "if not x" as an empty test. > ... if not li says nothing about what li is supposed to 'be' and > implies in any case that li does not exist, or worse is some kind of > boolean. > li is in fact an empty list [] and will identify as such, and of > course (as a list object) has all of the attributes and methods of a list... > Why not have a list method that makes this more explicit: > if not li.emptylist() > if not li.empty([]) > there might be others... Good luck. Just code - # You can immediately tell what this is meant to do! if len(x) == 0: - and ignore the Pythonistas [they're nuts; that x.count() doesn't work is amazingly stupid]. From clp2 at rebertia.com Fri May 6 16:46:14 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 May 2011 13:46:14 -0700 Subject: checking if a list is empty In-Reply-To: <1304712309.9905.10.camel@linux-yu4c.site> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <1304712309.9905.10.camel@linux-yu4c.site> Message-ID: On Fri, May 6, 2011 at 1:05 PM, Adam Tauno Williams wrote: > - and ignore the Pythonistas [they're nuts; ?that x.count() doesn't work > is amazingly stupid]. Eh? It works fine. [5, 2, 2, 1, 2].count(2) == 3. If you mean you want len(x) to be spelled x.count(), that's equally stupid; `count` would be a lousy name (people would confuse it with what the current .count() does). `length` or `size` would make much more sense. Cheers, Chris From rw at smsnet.pl Fri May 6 16:46:36 2011 From: rw at smsnet.pl (Rob Wolfe) Date: Fri, 06 May 2011 22:46:36 +0200 Subject: Python 3 dict question References: Message-ID: <87pqnvr1zn.fsf@smsnet.pl> dmitrey writes: > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterator. > Of course, I could use > for key, val in myDict.items(): > do_something > break > but maybe there is any better way? key, val = next(iter(myDict.items())) http://docs.python.org/py3k/library/stdtypes.html#dictionary-view-objects HTH, Rob From ian.g.kelly at gmail.com Fri May 6 16:48:45 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 14:48:45 -0600 Subject: Python 3 dict question In-Reply-To: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> Message-ID: On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: > Unfortunately, it doesn't work, it turn out to be dict_items: >>>> next({1:2}.items()) > Traceback (most recent call last): > ?File "", line 1, in > TypeError: dict_items object is not an iterator So call iter() on it first: next(iter(myDict.items())) From listas.programacao at gmail.com Fri May 6 16:49:47 2011 From: listas.programacao at gmail.com (Jayme Proni Filho) Date: Fri, 6 May 2011 17:49:47 -0300 Subject: How can I print one sqlite table with UTF-8 collumn Message-ID: I have one sqlite database called aripuanaonline.db. In this database I have one table with two collumns first with autoincrement not null and other with varchar(100) not null. I got this error: Traceback (most recent call last): File "C:\Documents and Settings\Marco\Desktop\aripuanaonline\aripuana.py", line 9, in rows = cursor.fetchall() sqlite3.OperationalError: Could not decode to UTF-8 column 'mensagem' with text 'Shampoo Pantene Restaura??o Profunda ? vista por R$4,99' How can I print my table? --------------------------------------------------------------------------------------- Jayme Proni Filho Skype: jaymeproni Twitter: @jaymeproni Phone: +55 - 17 - 3631 - 6576 Mobile: +55 - 17 - 9605 - 3560 e-Mail: jaymeproni at yahoo dot com dot br --------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri May 6 16:54:17 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 May 2011 16:54:17 -0400 Subject: string formatting In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/6/2011 3:22 PM, harrismh777 wrote: > I don't really like the old style, not because there is anything wrong > with it, There is in that it special cases tuples. For instance, a message function like def emsg(x): print("The following object caused a proplem: %s" % x) raises "TypeError: not all arguments converted during string formatting" if x is a tuple with other than 1 member and extracts x[0] if there is just one. Neither is the desired behavior. That has been a problem (and sometimes a debugging puzzle) in real code One has to remember to write something like def emsg(x): if isinstance(x,tuple): x = (x,) print(The following object caused a proplem: %s" % x) Guido sees that his original design is a bit of a bug trap, which is one reason he wanted to replace it. -- Terry Jan Reedy From nirina.raseliarison at gmail.com Fri May 6 17:18:59 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Fri, 06 May 2011 14:18:59 -0700 (PDT) Subject: Python 3 dict question References: Message-ID: <4dc465c3.454de50a.7493.7e68@mx.google.com> [dmitrey] > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterator. > Of course, I could use > for key, val in myDict.items(): > do_something > break > but maybe there is any better way? key, val = list(myDict.items())[0] -- nirinA From tooscattered at gmail.com Fri May 6 17:57:21 2011 From: tooscattered at gmail.com (scattered) Date: Fri, 6 May 2011 14:57:21 -0700 (PDT) Subject: checking if a list is empty References: Message-ID: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> On May 6, 2:36?am, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: > ... > > Thanks, > > Laszlo is there any problem with (3) if li == []: ? Seems to work when I test it and seems to clearly test what you are trying to test. The only problem might be if in some contexts == has the semantics of checking for object identity. From philip at semanchuk.com Fri May 6 18:21:09 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 6 May 2011 18:21:09 -0400 Subject: checking if a list is empty In-Reply-To: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> Message-ID: <8BD5792C-AFE3-4B86-82DB-B6C3F249FA5F@semanchuk.com> On May 6, 2011, at 5:57 PM, scattered wrote: > On May 6, 2:36 am, Jabba Laci wrote: >> Hi, >> >> If I want to check if a list is empty, which is the more pythonic way? >> >> li = [] >> >> (1) if len(li) == 0: >> ... >> or >> (2) if not li: >> ... >> >> Thanks, >> >> Laszlo > > is there any problem with > > (3) if li == []: > > ? What if it's not a list but a tuple or a numpy array? Often I just want to iterate through an element's items and I don't care if it's a list, set, etc. For instance, given this function definition -- def print_items(an_iterable): if not an_iterable: print "The iterable is empty" else: for item in an_iterable: print item I get the output I want with all of these calls: print_items( list() ) print_items( tuple() ) print_items( set() ) print_items( numpy.array([]) ) Given this slightly different definition, only the first call gives me the output I expect: def print_items(an_iterable): if an_iterable == []: print "The iterable is empty" else: for item in an_iterable: print item I find I use the the former style ("if not an_iterable") almost exclusively. bye Philip From drobinow at gmail.com Fri May 6 18:24:44 2011 From: drobinow at gmail.com (David Robinow) Date: Fri, 6 May 2011 18:24:44 -0400 Subject: setuptools for 64-bit 2.7.1 on 64-bit Windows 7? In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 1:43 PM, Dick Bridges wrote: > Simple question: Is it true that no setuptools (or any other module > installer) exists for 64-bit python 2.7.1? If there is an installer that > works, what terms might I use to Google for information on how to acquire > and install it? Doesn't the installer at http://www.lfd.uci.edu/~gohlke/pythonlibs/ work? From ethan at stoneleaf.us Fri May 6 18:49:40 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 06 May 2011 15:49:40 -0700 Subject: Dictionary Views -- good examples? [was Re: Python 3 dict question] In-Reply-To: References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> Message-ID: <4DC47B04.9070007@stoneleaf.us> Ian Kelly wrote: > On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: >> Unfortunately, it doesn't work, it turn out to be dict_items: >>>>> next({1:2}.items()) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: dict_items object is not an iterator > > So call iter() on it first: > > next(iter(myDict.items())) Which is becoming less elegant. Seems to me that View objects should be directly iterable, but then I don't really understand the motivation behind them or what greatness is facilitated by having them. Anybody care to chime in with their usage of this construct? ~Ethan~ From python at rcn.com Fri May 6 18:52:18 2011 From: python at rcn.com (Raymond Hettinger) Date: Fri, 6 May 2011 15:52:18 -0700 (PDT) Subject: checking if a list is empty References: Message-ID: On May 5, 11:36?pm, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: The Python core developers use the second form. See http://www.python.org/dev/peps/pep-0008/ for the official recommendation. Raymond From rosuav at gmail.com Fri May 6 19:43:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 May 2011 09:43:20 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <4XXwp.18782$Ot6.2313@newsfe15.iad> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <4XXwp.18782$Ot6.2313@newsfe15.iad> Message-ID: On Sat, May 7, 2011 at 5:25 AM, harrismh777 wrote: > Chris Torek wrote: >>> >>> with the Python-named-Monty, we have "rigidly defined areas of >>> >doubt and uncertainty". ?These exist for good reasons: to allow >>> >different implementations. >> >> Oops, attribution error: this comes from Douglas Adams rather >> than Monty Python. > > Well, its certainly Monte-esq.... I like it, whoever said it. Same style of humour, they both derived significantly from Spike Milligan and "The Goon Show". That particular quote relates to the famous computer that calculated the number 42, which - to drag this, kicking and screaming, back to some semblance of on-topicness - was clearly built with a view to conserving programmer time at the expense of execution time. I don't understand why they didn't just recode the heavy computation in C and cut it down to just a few thousand years... Chris Angelico From ian.g.kelly at gmail.com Fri May 6 19:51:44 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 17:51:44 -0600 Subject: checking if a list is empty In-Reply-To: <8BD5792C-AFE3-4B86-82DB-B6C3F249FA5F@semanchuk.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <8BD5792C-AFE3-4B86-82DB-B6C3F249FA5F@semanchuk.com> Message-ID: On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk wrote: > What if it's not a list but a tuple or a numpy array? Often I just want to iterate through an element's items and I don't care if it's a list, set, etc. For instance, given this function definition -- > > def print_items(an_iterable): > ? ?if not an_iterable: > ? ? ? ?print "The iterable is empty" > ? ?else: > ? ? ? ?for item in an_iterable: > ? ? ? ? ? ?print item > > I get the output I want with all of these calls: > print_items( list() ) > print_items( tuple() ) > print_items( set() ) > print_items( numpy.array([]) ) But sadly it fails on iterators: print_items(xrange(0)) print_items(-x for x in []) print_items({}.iteritems()) From rosuav at gmail.com Fri May 6 20:09:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 May 2011 10:09:49 +1000 Subject: string formatting In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 7, 2011 at 6:54 AM, Terry Reedy wrote: > def emsg(x): > ?if isinstance(x,tuple): > ? ?x = (x,) > ?print(The following object caused a proplem: %s" % x) > Couldn't you just do that unconditionally? print(The following object caused a proplem: %s" % (x,)) Chris Angelico From ian.g.kelly at gmail.com Fri May 6 20:23:22 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 May 2011 18:23:22 -0600 Subject: Dictionary Views -- good examples? [was Re: Python 3 dict question] In-Reply-To: <4DC47B04.9070007@stoneleaf.us> References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> <4DC47B04.9070007@stoneleaf.us> Message-ID: On Fri, May 6, 2011 at 4:49 PM, Ethan Furman wrote: > Ian Kelly wrote: >> >> On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: >>> >>> Unfortunately, it doesn't work, it turn out to be dict_items: >>>>>> >>>>>> next({1:2}.items()) >>> >>> Traceback (most recent call last): >>> ?File "", line 1, in >>> TypeError: dict_items object is not an iterator >> >> So call iter() on it first: >> >> next(iter(myDict.items())) > > Which is becoming less elegant. That's not even the worst of it. If the dict is empty, then the code above will raise a StopIteration, which must be caught locally since if it propagates it could be swallowed by a generator. So a full recipe should really look more like this: try: first_item = next(iter(my_dict.items())) except StopIteration: raise ValueError("empty dict") >?Seems to me that View objects should be directly iterable They are. They're just not directly nextable because they're treated as dependent collections, not iterators. > but then I don't really understand the motivation behind them or what greatness is facilitated by having them. > > Anybody care to chime in with their usage of this construct? You should start with PEP 3106. The main idea is that dict.keys() and dict.items() can be treated as frozensets, while still being more lightweight than lists. That lets you do nifty things like "a.keys() == b.keys()" which, if a and b are Python 3 dicts, will tell you whether they contain the same keys. Whether anybody actually uses this, I have no idea. From joncle at googlemail.com Fri May 6 20:43:51 2011 From: joncle at googlemail.com (Jon Clements) Date: Fri, 6 May 2011 17:43:51 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <8BD5792C-AFE3-4B86-82DB-B6C3F249FA5F@semanchuk.com> Message-ID: <61e9b51a-492f-410d-8ebc-e516165795df@y12g2000yqh.googlegroups.com> On May 7, 12:51?am, Ian Kelly wrote: > On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk wrote: > > What if it's not a list but a tuple or a numpy array? Often I just want to iterate through an element's items and I don't care if it's a list, set, etc. For instance, given this function definition -- > > > def print_items(an_iterable): > > ? ?if not an_iterable: > > ? ? ? ?print "The iterable is empty" > > ? ?else: > > ? ? ? ?for item in an_iterable: > > ? ? ? ? ? ?print item > > > I get the output I want with all of these calls: > > print_items( list() ) > > print_items( tuple() ) > > print_items( set() ) > > print_items( numpy.array([]) ) > > But sadly it fails on iterators: > print_items(xrange(0)) > print_items(-x for x in []) > print_items({}.iteritems()) My stab: from itertools import chain def print_it(iterable): it = iter(iterable) try: head = next(it) except StopIteration: print 'Empty' return for el in chain( (head,), it ): print el Not sure if I'm truly happy with that though. Jon Jon. From rosuav at gmail.com Fri May 6 20:51:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 May 2011 10:51:43 +1000 Subject: checking if a list is empty In-Reply-To: <1304712309.9905.10.camel@linux-yu4c.site> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <1304712309.9905.10.camel@linux-yu4c.site> Message-ID: On Sat, May 7, 2011 at 6:05 AM, Adam Tauno Williams wrote: > On Fri, 2011-05-06 at 14:49 -0500, harrismh777 wrote: >> Terry Reedy wrote: >> >>> (2) if not li: >> >> This is fine. >> > This is the intended way. Anything in addition is extra noise and wasted >> > calculation. In other words, let Python do the boilerplate work for you. >> ? ? I agree, but I don't like it. > > +1 ?This is the Python reality-distortion-field at work. > > Motto#1: Python is all about readability! > Motto#2: Crytic code is awesome if it is Pythoncally cryptic! As a C and C++ programmer, I probably shouldn't offer an opinion, but it is quite normal in C++ to compare objects for truth/falseness - for instance, stream objects return false on error/eof, so you can efficiently code a loop with "while (infile) {...}". Not to mention that the nullness of a C string (a PSZ) is quite happily and safely tested by seeing if the pointer is true (non-null) or false (null). That said, though, readability is a relative thing. A construct is transparently obvious if it does something in the exact same way that it's always been done, no matter how obscure it was the first time. Why is it, for instance, that putting two short strokes perpendicular to one another indicates addition? Yet if you see the construct "x + y", you know exactly what it means - it's readable, it's not cryptic at all. People assume and expect that this compact syntax will be available, and object heavily to such notation as "add(x,y)" which says exactly what it does. if not li: is perfectly readable; you just need a comprehension of what truth means for a list. Chris Angelico From daniil.re at gmail.com Fri May 6 22:02:26 2011 From: daniil.re at gmail.com (=?UTF-8?B?0JTQsNC90LjQuNC7INCg0YvQttC60L7Qsg==?=) Date: Sat, 7 May 2011 13:02:26 +1100 Subject: PyGTK, Glade/libglade. What am I doing wrong? Message-ID: Sorry for my English (I could not find help in the Russian community) I'm trying to learn PyGTK and Glade. I made test window in Glade and saved it as "test.glade" (attached). Then I wrote script "test.py"(attached, http://pastebin.com/waKytam3). I tried to run it. While the script was executed, console did not show anything and window wasn't displayed. When I pressed CTRL+? console displayed trackback: --- CTraceback (most recent call last): File "test.py", line 32, in gtk.main() KeyboardInterrupt --- So what am I doing wrong? -- Best wishes, Daniil -------------- next part -------------- A non-text attachment was scrubbed... Name: test.py Type: text/x-python Size: 547 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test.glade Type: application/x-glade Size: 385 bytes Desc: not available URL: From steve+comp.lang.python at pearwood.info Fri May 6 22:30:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2011 02:30:53 GMT Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc4aedc$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 14:39:15 -0500, harrismh777 wrote: > On the other hand, consider this 3.x code snip: > > print("the %s is %d" % ('sky', 'blue')) > > > That formatting will throw an exception, because the format > construct is restricting the format entry to be a number, which 'blue' > clearly isn't.... Er, yes. That's clearly deliberate, because the target uses %d rather than %s. If the author wanted to accept anything, she would used %r or %s. You might as well argue that: print("the {} is {}".format('sky', int(x))) is wrong, because if you leave the int out, any object can be used. > The following print() is better, because *any* time or *most* types > can be substituted and the 'polymorphism' of Python kicks in allowing > for that, as so: > > print("the {} is {}".format('sky', 3.4)) This is not comparing apples with apples. The format equivalent is: print("the {} is {:d}".format('sky', 'blue')) which will also raise an exception, ValueError instead of TypeError. -- Steven From benjamin.kaplan at case.edu Fri May 6 22:48:40 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 6 May 2011 22:48:40 -0400 Subject: PyGTK, Glade/libglade. What am I doing wrong? In-Reply-To: References: Message-ID: On May 6, 2011 7:05 PM, "?????? ??????" wrote: > > Sorry for my English (I could not find help in the Russian community) > I'm trying to learn PyGTK and Glade. I made test window in Glade and > saved it as "test.glade" (attached). Then I wrote script > "test.py"(attached, http://pastebin.com/waKytam3). I tried to run it. > While the script was executed, console did not show anything and > window wasn't displayed. When I pressed CTRL+? console displayed > trackback: > --- > CTraceback (most recent call last): > File "test.py", line 32, in > gtk.main() > KeyboardInterrupt > --- > So what am I doing wrong? > I haven't used gtk before, but is there a show method or something similar you need, to actually make the window appear? The KeyboardInterrupt is normal. That's how control-c works. > -- > Best wishes, > Daniil > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri May 6 22:49:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2011 02:49:53 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> Message-ID: <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 16:05:09 -0400, Adam Tauno Williams wrote: > I'd never accept code like "if not x" as an empty test. So much the worse for you then. The point of the "if x" idiom is that it is a polymorphic test which is independent of the type. It works with any non-broken object[1], no matter what x is, since it allows x to decide for itself whether it is empty or not. Of course, you can write your own polymorphic test: try: flag = len(x) == 0 except TypeError: # This *should* succeed, for anything not broken. If not, we can't # recover, so just let the exception propagate. flag = bool(x) # Hilariously, bool(x) may also try len(x) == 0... oh well. if flag: ... Congratulations! You've now found a way to write "if x:" in five lines, 53 characters (plus whitespace and comments) and an extraneous variable polluting the namespace. If you're being paid per line of code, this is a good win. Of course, sometimes you don't want polymorphism (or at least, not too much polymorphism). Sometimes I'll write "if x == 0" or similar if I want to emphasize that x is a special case unrelated to the truth/falseness of x. But that's quite rare. Normally I trust x to decide for itself whether it is empty or not. [1] Arguably with the exception of iterables. But then the len(x) test doesn't work for them either. -- Steven From steve+comp.lang.python at pearwood.info Fri May 6 22:51:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2011 02:51:50 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> Message-ID: <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 14:57:21 -0700, scattered wrote: > is there any problem with > > (3) if li == []: > > ? > > Seems to work when I test it and seems to clearly test what you are > trying to test. The only problem might be if in some contexts == has the > semantics of checking for object identity. Yes, if li == [] works too. But how do you know li is a list and not some other sequence type? The advantage of the "if x" test is that it is independent of the type of x. -- Steven From daniil.re at gmail.com Fri May 6 23:46:06 2011 From: daniil.re at gmail.com (=?UTF-8?B?0JTQsNC90LjQuNC7INCg0YvQttC60L7Qsg==?=) Date: Sat, 7 May 2011 14:46:06 +1100 Subject: PyGTK, Glade/libglade. What am I doing wrong? In-Reply-To: References: Message-ID: > I haven't used gtk before, but is there a show method or something similar > you need, to actually make the window appear? I don't know. I think "self.wTree = gtk.glade.XML(self.gladefile)" should do this. For example, author of this tutorial (http://www.learningpython.com/2006/05/07/creating-a-gui-using-pygtk-and-glade/) wrote script similar to my. P.S. I have glade3 3.8.0, gtk 2.24.4, GNOME 2.32.1 and Python 2.7.1 -- Best wishes, Daniil From pyclutter at gmail.com Fri May 6 23:47:42 2011 From: pyclutter at gmail.com (craf) Date: Sat, 07 May 2011 00:47:42 -0300 Subject: PyGTK, Glade/libglade. What am I doing wrong? In-Reply-To: References: Message-ID: <1304740062.2510.2.camel@cristian-desktop> On May 6, 2011 7:05 PM, "?????? ??????" wrote: > > Sorry for my English (I could not find help in the Russian community) > I'm trying to learn PyGTK and Glade. I made test window in Glade and > saved it as "test.glade" (attached). Then I wrote script > "test.py"(attached, http://pastebin.com/waKytam3). I tried to run it. > While the script was executed, console did not show anything and > window wasn't displayed. When I pressed CTRL+? console displayed > trackback: > --- > CTraceback (most recent call last): > File "test.py", line 32, in > gtk.main() > KeyboardInterrupt > --- > So what am I doing wrong? > >I haven't used gtk before, but is there a show method or something >similar you need, to actually make the window appear? The >KeyboardInterrupt is normal. That's how control-c works. > -- > Best wishes, > Daniil > > -- > http://mail.python.org/mailman/listinfo/python-list > Hi. Try this: #!/usr/bin/env python import gtk.glade class TestPyGtk: """This is an Hello World GTK application""" def __init__(self): #Set the Glade file self.gladefile = "test.glade" self.glade = gtk.glade.XML(self.gladefile) self.MainWindow = self.glade.get_widget('MainWindow') self.MainWindow.show() self.MainWindow.connect('destroy', lambda e:gtk.main_quit()) TestPyGtk() gtk.main() Regards. Cristian. List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk From daniil.re at gmail.com Sat May 7 00:14:07 2011 From: daniil.re at gmail.com (=?UTF-8?B?0JTQsNC90LjQuNC7INCg0YvQttC60L7Qsg==?=) Date: Sat, 7 May 2011 15:14:07 +1100 Subject: PyGTK, Glade/libglade. What am I doing wrong? In-Reply-To: References: <1304740062.2510.2.camel@cristian-desktop> Message-ID: Thanks, Cristian! It works. > List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk Thanks again. Subscribed :) 2011/5/7 craf : > Hi. > > Try this: > > #!/usr/bin/env python > > import gtk.glade > > class TestPyGtk: > ? ?"""This is an Hello World GTK application""" > > ? ?def __init__(self): > > ? ? ? ?#Set the Glade file > ? ? ? ?self.gladefile = "test.glade" > ? ? ? ?self.glade = gtk.glade.XML(self.gladefile) > > ? ? ? ?self.MainWindow = self.glade.get_widget('MainWindow') > ? ? ? ?self.MainWindow.show() > ? ? ? ?self.MainWindow.connect('destroy', lambda e:gtk.main_quit()) > > > > TestPyGtk() > gtk.main() > > Regards. > > Cristian. > > List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk -- Best wishes, Daniil From rustompmody at gmail.com Sat May 7 01:21:02 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 6 May 2011 22:21:02 -0700 (PDT) Subject: Testing tools classification Message-ID: <0a6beebc-35b7-4f81-b64b-55c0dbed1bae@h12g2000pro.googlegroups.com> There is this nice page of testing tools taxonomy: http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy But it does not list staf: http://staf.sourceforge.net/index.php. From tjreedy at udel.edu Sat May 7 03:55:01 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 May 2011 03:55:01 -0400 Subject: string formatting In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/6/2011 8:09 PM, Chris Angelico wrote: > On Sat, May 7, 2011 at 6:54 AM, Terry Reedy wrote: >> def emsg(x): >> if isinstance(x,tuple): >> x = (x,) >> print(The following object caused a proplem: %s" % x) >> > > Couldn't you just do that unconditionally? > print(The following object caused a proplem: %s" % (x,)) I guess so, as long as one remembers the ','. That does not obviate the fact that % x is an attractive nuisance which works until it does not. -- Terry Jan Reedy From alister.ware at ntlworld.com Sat May 7 04:11:40 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Sat, 07 May 2011 08:11:40 GMT Subject: PyGTK, Glade/libglade. What am I doing wrong? References: <1304740062.2510.2.camel@cristian-desktop> Message-ID: <097xp.16$_T5.11@newsfe02.ams2> On Sat, 07 May 2011 15:14:07 +1100, ?????? ?????? wrote: > Thanks, Cristian! It works. >> List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk > Thanks again. Subscribed :) > 2011/5/7 craf : >> Hi. >> >> Try this: >> >> #!/usr/bin/env python >> >> import gtk.glade >> >> class TestPyGtk: >> ? ?"""This is an Hello World GTK application""" >> >> ? ?def __init__(self): >> >> ? ? ? ?#Set the Glade file >> ? ? ? ?self.gladefile = "test.glade" >> ? ? ? ?self.glade = gtk.glade.XML(self.gladefile) >> >> ? ? ? ?self.MainWindow = self.glade.get_widget('MainWindow') >> ? ? ? ?self.MainWindow.show() >> ? ? ? ?self.MainWindow.connect('destroy', lambda e:gtk.main_quit()) >> >> >> >> TestPyGtk() >> gtk.main() >> >> Regards. >> >> Cristian. >> >> List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk you may also want to look at using gtk.builder instread as it is now the prefered option. -- The human mind ordinarily operates at only ten percent of its capacity -- the rest is overhead for the operating system. From steve+comp.lang.python at pearwood.info Sat May 7 04:28:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2011 08:28:56 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> Message-ID: <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 14:49:24 -0500, harrismh777 wrote: > Terry Reedy wrote: >>>> (2) if not li: >>> >>> This is fine. >> >> This is the intended way. Anything in addition is extra noise and >> wasted calculation. In other words, let Python do the boilerplate work >> for you. > > I agree, but I don't like it. > > ... if not li says nothing about what li is supposed to 'be' Yes, and? Neither does: isempty(li) # li could be anything that polymorphic isempty can deal with li.isempty() # li could be anything with a "isempty" method len(li) == 0 # li could be anything with a length (list, dict, set, ...) That's duck-typing for you, and it is generally a strength rather than a weakness. For those times when it is a weakness, that's where we have naming conventions, type-testing, and (in some languages) static types. > and implies in any case that li does not exist It does nothing of the sort. If li doesn't exist, you get a NameError. > or worse is some kind of boolean. Only if you're still thinking in some language that isn't Python. Boolean tests in Python are polymorphic. bool() exists mainly to provide a canonical representation of true and false values, not because you are limited to using booleans in truth-testing. Far from it: it is often very useful to do something like this: settings = local_settings or global_settings or builtin_settings where the first non-empty *_settings wins. > li is in fact an empty list [] and will identify as such, and of > course (as a list object) has all of the attributes and methods of a > list... > > Why not have a list method that makes this more explicit: For the same reason that we don't have an int method that makes zero testing more explicit: n = 0 n.iszero() # returns True Because sometimes you can have too much explicitness. -- Steven From steve+comp.lang.python at pearwood.info Sat May 7 04:29:28 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 May 2011 08:29:28 GMT Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc502e8$0$29991$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 May 2011 12:36:09 -0600, Ian Kelly wrote: > On Fri, May 6, 2011 at 10:59 AM, Steven D'Aprano > wrote: >> As written, amb is just a brute-force solver using more magic than is >> good for any code, but it's fun to play with. > > This isn't really amb; as you said it's just a brute-force solver with > some weird syntax. The whole point of amb is to enable > non-deterministic programming, such as this: [...] > The amb engine would conceptually execute this function for every > possible combination of a, b, and c, Which pretty much is the definition of "brute-force solver", no? -- Steven From greg.ewing at canterbury.ac.nz Sat May 7 04:53:40 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 20:53:40 +1200 Subject: seems like a bug in isinstance() In-Reply-To: References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> Message-ID: <92kfkmF4d5U1@mid.individual.net> Chris Rebert wrote: > This is because you did `from Point import > ...` in file2.py, whereas in file1.py you did `from > openopt.kernel.Point import ...`. These 2 different ways of referring > to the same module are sufficient to "trick"/"outsmart" (C)Python and > cause it to import the same module twice That can't be the whole story, because those two ways of referring to the module *should* have returned the same module object, even though one is absolute and the other relative. I suspect what's happened is that somehow sys.path contains both the directory containing .../openopt *and* the directory .../openopt/kernel, and the second import is picking up Point.py a second time as though it were a top-level module. This could have happened by starting an interactive session while cd'ed to .../openopt/kernel, or by launching a .py file from there as a main script. The solution is to make sure that sys.path only contains the top level directories of the package hierarchy, and doesn't also contain any of their subdirectories. Always using absolute imports may be a good idea stylistically, but in this case it will only mask the symptoms of whatever is really wrong, and further problems could result from the same cause. -- Greg From greg.ewing at canterbury.ac.nz Sat May 7 05:09:09 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 21:09:09 +1200 Subject: Dictionary Views -- good examples? [was Re: Python 3 dict question] In-Reply-To: References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> Message-ID: <92kghnFb37U1@mid.individual.net> Ethan Furman wrote: > Ian Kelly wrote: > >> next(iter(myDict.items())) > > Which is becoming less elegant. If you're doing this sort of thing a lot you can make a little helper function: def first(x): return next(iter(x)) then you get to say first(myDict.items()) -- Greg From greg.ewing at canterbury.ac.nz Sat May 7 05:21:45 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 21:21:45 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> Message-ID: <92kh9cFgdcU1@mid.individual.net> Hans Georg Schaathun wrote: > You cannot reference nor manipulate a > reference in python, and that IMHO makes them more abstract. You can manipulate them just fine by moving them from one place to another: a = b You can use them to get at stuff they refer to: a = b.c a[:] = b[:] You can compare them: if a is b: ... That's about all you can do with pointers in Pascal, and I've never heard anyone argue that Pascal pointers are any more or less abstract than any other piece of data in that language. As for "referencing" a reference, you can't really do that in Pascal either, at least not the way you can in C, because (plain) Pascal doesn't have an address-of operator. The only way to get a pointer to a pointer in Pascal is to heap-allocate a single pointer, which isn't normally a very useful thing to do. -- Greg From rosuav at gmail.com Sat May 7 05:28:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 May 2011 19:28:50 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <92kh9cFgdcU1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> Message-ID: On Sat, May 7, 2011 at 7:21 PM, Gregory Ewing wrote: > Hans Georg Schaathun wrote: > >> You cannot reference nor manipulate a reference in python, and that IMHO >> makes them more abstract. > > You can manipulate them just fine by moving them > from one place to another: I think "manipulate" here means things like pointer arithmetic, which are perfectly normal and common in C and assembly, but not in languages where they're references. Chris Angelico From greg.ewing at canterbury.ac.nz Sat May 7 05:39:47 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 21:39:47 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2c52e$0$10567$742ec2ed@news.sonic.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc1ca92$0$10552$742ec2ed@news.sonic.net> <5smwp.309$BG2.230@newsfe08.iad> <4dc22882$0$10557$742ec2ed@news.sonic.net> <92fb5jFa2lU1@mid.individual.net> <4dc2c52e$0$10567$742ec2ed@news.sonic.net> Message-ID: <92kib3FgdcU2@mid.individual.net> John Nagle wrote: > Such tuples are still identical, even if they > contain identical references to immutable objects. The point is you'd have to do the comparison only one level deep, so it wouldn't be exactly the same as == on tuples. -- Greg From dmitrey15 at gmail.com Sat May 7 06:02:29 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Sat, 7 May 2011 03:02:29 -0700 (PDT) Subject: Python3: imports don't see files from same directory? Message-ID: hi all, I try to port my code to Python 3 and somehow files don't see files from same directory, so I have to add those directories explicitly, e.g. import sys sys.path += [...] Also, it leads to bugs like this one: http://groups.google.com/group/comp.lang.python/browse_thread/thread/961a90219a61e19d# any ideas what's the reason and how to fix it? I have tried to search google but got nothing yet. Thank you in advance, D. From greg.ewing at canterbury.ac.nz Sat May 7 06:04:06 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 22:04:06 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92kjooF31mU1@mid.individual.net> > On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote: > >>?x? is a name. Names are bound to values. Talk of ?variable? only >>confuses the issue because of the baggage carried with that term. But to use 'name' as a complete replacement for 'variable', you have to stretch it to include things like a[i], b.c, e.f(x).g[i:j].k, etc. which goes rather a long way beyond the everyday meaning of the word. In Python I use 'variable' to mean more or less 'something that can be assigned to', which accords with the way it's used in relation to many other languages, and doesn't suggest any restriction to things named by a single identifier. >>But the data model of Python doesn't fit well with the ideas that the >>term ?variable? connotes for most programmers: Seems to me that anyone taking that connotation from it has not yet been sufficiently educated about the Python data model itself. Part of explaining that data model consists of instilling the very idea that the things in Python that are analogous to variables in other languages only refer to data rather than containing the actual data. >>Saying ?variable? and ?has the value? But I don't say "has a value", I say "refers to". -- Greg From dmitrey15 at gmail.com Sat May 7 06:04:09 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Sat, 7 May 2011 03:04:09 -0700 (PDT) Subject: seems like a bug in isinstance() References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> <92kfkmF4d5U1@mid.individual.net> Message-ID: <619d1edd-4aeb-4c2d-a5c1-757f63e52bd5@d27g2000vbz.googlegroups.com> On May 7, 11:53?am, Gregory Ewing wrote: > Chris Rebert wrote: > > This is because you did `from Point import > > ...` in file2.py, whereas in file1.py you did `from > > openopt.kernel.Point import ...`. These 2 different ways of referring > > to the same module are sufficient to "trick"/"outsmart" (C)Python and > > cause it to import the same module twice > > That can't be the whole story, because those two ways of > referring to the module *should* have returned the same > module object, even though one is absolute and the other > relative. > > I suspect what's happened is that somehow sys.path contains > both the directory containing .../openopt *and* the directory > .../openopt/kernel, and the second import is picking up > Point.py a second time as though it were a top-level module. > > This could have happened by starting an interactive session > while cd'ed to .../openopt/kernel, or by launching a .py > file from there as a main script. > > The solution is to make sure that sys.path only contains the > top level directories of the package hierarchy, and doesn't > also contain any of their subdirectories. > > Always using absolute imports may be a good idea stylistically, > but in this case it will only mask the symptoms of whatever > is really wrong, and further problems could result from the > same cause. > > -- > Greg > I suspect what's happened is that somehow sys.path contains both the directory containing .../openopt *and* the directory .../openopt/kernel Yes, you are right. But I have to do it due to another issue I haven't solved yet: Python3 imports don't see files from same directory http://groups.google.com/group/comp.lang.python/browse_thread/thread/9470dbdacc138709# Regards, D. From greg.ewing at canterbury.ac.nz Sat May 7 06:09:42 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 22:09:42 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2afd2$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92kk36F31mU2@mid.individual.net> Andreas Tawn wrote: > If True and False: > waveFunction.collapse(cat) Call-by-entanglement would be interesting. Anything that the callee does to the parameter would affect the caller, but you would only be able to tell by examining a trace of the output afterwards. -- Greg From greg.ewing at canterbury.ac.nz Sat May 7 06:12:27 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 May 2011 22:12:27 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92kk8bF31mU3@mid.individual.net> Grant Edwards wrote: > if you feel it just right and you have just the >>right synchro-mesh setup, you can slide from 3rd into 4th without >>every touching the clutch peddle... > >>and if that isn't automatic, I don't know what is.... > > No, that's _not_ automatic if you have to do it yourself. It's > automatic when it happens without user-intervention. Does it count if the transmission is activated by saying "Home, Jeeves"? -- Greg From nobody at nowhere.net.no Sat May 7 07:40:35 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 07 May 2011 19:40:35 +0800 Subject: A suggestion for an easy logger Message-ID: Hello, I've resumed my hold project and I like to convert it for py3k2. My knowledge has stagnated at version 2.4, then I found some improvements, but it will take me some time before I get used to. I was using this logger >> ========================================================================= class log: """ It outputs lists and strings on file or any possible device that allows write mode. Options are: output file writing mode and special end of line (EOL)""" def __init__(self, output= None, mode= 'w', lsp= EOL): """ Can instantiate even no output is given. Choose to build an open file object to append to, or new and give a different line separator""" self.lsp = lsp self.output= output self.mode= mode try: self.output= open(output, self.mode) except (IOError, TypeError): self.output = None def logger(self, strng, allowed=None): # without any output will simply send log to nowhere :-) if not allowed and not self.output: return # no allowed to write the output # keep silent even temporary skip writing # if allowed, it will go to stderr if isinstance(strng,list): a= EOL.join(strng)+ EOL strng = a strng= strng.replace(EOL,self.lsp) # when not allowed just return if allowed is None: return if strng == '?close?': try: # try to close the file self.output.close() return except IOError: return # silently ignore the failure if self.output and Exists(self.output): self.output.write(strng) else: sys.stderr.write(strng) sys.stderr.flush() return ========================================================================= It is somehow convulitive, isn't it? I do believe the builtin *print* would do more better than my logger. Basically I would like a class which shoudl do: 1) print to stdout either with or without carriage return 2) writing to a file 3) Skip some output Everything should do according to the caller. I didn't picked up the logging module, a way of confusion on my point of view. Some small example might easy my aberration :P -- goto /dev/null From invalid at invalid.invalid Sat May 7 08:03:47 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 7 May 2011 12:03:47 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc2be25$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kk8bF31mU3@mid.individual.net> Message-ID: On 2011-05-07, Gregory Ewing wrote: > Grant Edwards wrote: >> if you feel it just right and you have just the >>>right synchro-mesh setup, you can slide from 3rd into 4th without >>>every touching the clutch peddle... >> >>>and if that isn't automatic, I don't know what is.... >> >> No, that's _not_ automatic if you have to do it yourself. It's >> automatic when it happens without user-intervention. > > Does it count if the transmission is activated > by saying "Home, Jeeves"? Only if your name is Bertie Wooster. From nobody at nowhere.net.no Sat May 7 08:18:46 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 07 May 2011 20:18:46 +0800 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <3Ihwp.18043$Ot6.11759@newsfe15.iad> <92f7nuFfhhU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > because modern architectures are so freaking complicated > that it takes a computer to figure out the best instruction > sequence certainly is, I would not imagine one who writes on scraps of paper :D :D :D -- goto /dev/null From marian at sendung.de Sat May 7 08:24:33 2011 From: marian at sendung.de (Marian Steinbach) Date: Sat, 7 May 2011 14:24:33 +0200 Subject: Stuck with urllib.quote and Unicode/UTF-8 Message-ID: Hi! I am stuck with calling URLs with parameters containing non-ASCII characters. I'm creating a url like this. url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + urllib.quote(address) + '&sensor=false&language=DE' address can be a string like u"K?ln, Nordrhein-Westfalen". This results in http://maps.googleapis.com/maps/api/geocode/json?address=K%F6ln%2C%20Nordrhein-Westfalen&sensor=false&language=DE and this doesn't seem to meet Google's Encoding expectations. I get an "INVALID REQUEST" response. (The same things works if there are only ASCII characters in the address.) When I manually enter the "K?ln"... string in the Firefox address bar, Firefox makes the URL http://maps.googleapis.com/maps/api/geocode/xml?address=K%C3%B6ln,%20Nordrhein-Westfalen&sensor=false&language=DE out of this and it works fine. %C3%B6 seems to be the url-encoded representation of an UTF-8 representation of a "?" character. So the next thing I tried is to get address utf-8-encoded, like this: url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + urllib.quote(address.encode('utf-8')) + '&sensor=false&language=DE' This gives me an error like UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 1: ordinal not in range(128) Again, the input string for address is u"K?ln, Nordrhein-Westfalen". Can you see what I'm doing wrong or what I would have to to to get from u"?" to "%C3%B6"? Thanks! Marian From cpopa at bitdefender.com Sat May 7 08:31:33 2011 From: cpopa at bitdefender.com (Claudiu Popa) Date: Sat, 7 May 2011 15:31:33 +0300 Subject: Custom string joining Message-ID: <254518825.20110507153133@bitdefender.com> Hello Python-list, I have an object which defines some methods. I want to join a list or an iterable of those objects like this: new_string = "|".join(iterable_of_custom_objects) What is the __magic__ function that needs to be implemented for this case to work? I though that __str__ is sufficient but it doesn't seems to work. Thanks in advance. PC From marian at sendung.de Sat May 7 08:35:09 2011 From: marian at sendung.de (Marian Steinbach) Date: Sat, 7 May 2011 14:35:09 +0200 Subject: Stuck with urllib.quote and Unicode/UTF-8 In-Reply-To: References: Message-ID: An addition/correction: It seems as if my input variable address is not Unicode. This is what I get for print [address]: ['K\xf6ln, Nordrhein-Westfalen'] Isn't this utf-8 encoding? And I'm using Python 2.5.2. From clp2 at rebertia.com Sat May 7 10:14:55 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 7 May 2011 07:14:55 -0700 Subject: Stuck with urllib.quote and Unicode/UTF-8 In-Reply-To: References: Message-ID: On Sat, May 7, 2011 at 5:35 AM, Marian Steinbach wrote: > An addition/correction: > > It seems as if my input variable address is not Unicode. This is what > I get for print [address]: > > ['K\xf6ln, Nordrhein-Westfalen'] > > Isn't this utf-8 encoding? Nope, it's Latin-1 (or similar, e.g. Windows-1252): Python 2.7.1 (r271:86832, Dec 5 2010, 00:12:20) >>> x = u"K?ln" >>> x.encode('utf_8') 'K\xc3\xb6ln' >>> x.encode('latin_1') 'K\xf6ln' >>> Cheers, Chris -- http://rebertia.com From clp2 at rebertia.com Sat May 7 10:25:58 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 7 May 2011 07:25:58 -0700 Subject: Custom string joining In-Reply-To: <254518825.20110507153133@bitdefender.com> References: <254518825.20110507153133@bitdefender.com> Message-ID: On Sat, May 7, 2011 at 5:31 AM, Claudiu Popa wrote: > Hello Python-list, > > I ?have ?an object which defines some methods. I want to join a list or > an iterable of those objects like this: > > new_string = "|".join(iterable_of_custom_objects) > > What ? is ? the ? __magic__ ?function that needs to be implemented for > this case to work? ?I ?though ?that ?__str__ ?is sufficient but it doesn't seems to > work. Thanks in advance. You need to do the string conversion yourself; .join() doesn't do it for you, due to strong typing. It only accepts iterables of strings: new_string = "|".join(str(x) for x in iterable_of_custom_objects) Cheers, Chris -- http://rebertia.com From ian.g.kelly at gmail.com Sat May 7 10:54:23 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 7 May 2011 08:54:23 -0600 Subject: Coolest Python recipe of all time In-Reply-To: <4dc502e8$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc502e8$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 7, 2011 at 2:29 AM, Steven D'Aprano wrote: >> This isn't really amb; as you said it's just a brute-force solver with >> some weird syntax. ?The whole point of amb is to enable >> non-deterministic programming, such as this: > [...] >> The amb engine would conceptually execute this function for every >> possible combination of a, b, and c, > > Which pretty much is the definition of "brute-force solver", no? The "execute the function for every possible combination" part, yes. The "non-deterministic programming" part, no. From affdfsdfdsfsd at b.com Sat May 7 11:04:22 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 07 May 2011 15:04:22 GMT Subject: PyGTK notebook: get current page Message-ID: <4dc55f75$0$38638$4fafbaef@reader1.news.tin.it> Hi all! I've made a simple PyGTK program. It's a window with a notebook, the notebook have 2 pages When changing page, i'ld like to get the id of current page. I've coded it, but i can get only the previously open page, not the current one. This is not a big deal if i have only 2 pages, but it could be with 3 or more pages. Here's the code: #!/usr/bin/env python # -*- coding: utf-8 -*- # template di finestra in pyGTK import pygtk pygtk.require('2.0') import gtk class FinestraGTK: def pippo(self, widget, event, data=None): print "current page: " + str(self.nb.get_current_page() ) def delete_event(self, widget, event, data=None): print "delete event occurred" return False def destroy(self, widget, data=None): print "destroy signal occurred" gtk.main_quit() def __init__(self): self.w = gtk.Window(gtk.WINDOW_TOPLEVEL) self.w.connect("delete_event", self.delete_event) self.w.connect("destroy", self.destroy) self.w.set_border_width(10) self.w.set_default_size(455,460) # NOTEBOOK + LABELS self.nb = gtk.Notebook() self.nb_label1 = gtk.Label("page 0") self.nb_label2 = gtk.Label("page 1") # PAGE 1 self.b1 = gtk.Button("button tab 0") self.nb.insert_page(self.b1, self.nb_label1, 0) # PAGE 2 self.b2 = gtk.Button("button tab 1") self.nb.insert_page(self.b2, self.nb_label2, 1) self.w.add(self.nb) self.nb.connect("switch-page", self.pippo) self.b1.connect("clicked", self.pippo, "") self.b2.connect("clicked", self.pippo, "") self.w.show_all() def main(self): gtk.main() if __name__ == "__main__": hello = FinestraGTK() hello.main() any hint? i know it's all about correctly temporize signals, but i don't know how to accompliesh this many thanks regards sorry for my english Nico From ian.g.kelly at gmail.com Sat May 7 11:07:37 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 7 May 2011 09:07:37 -0600 Subject: Python3: imports don't see files from same directory? In-Reply-To: References: Message-ID: On Sat, May 7, 2011 at 4:02 AM, dmitrey wrote: > hi all, > I try to port my code to Python 3 and somehow files don't see files > from same directory, so I have to add those directories explicitly, > e.g. > import sys > sys.path += [...] > > Also, it leads to bugs like this one: > http://groups.google.com/group/comp.lang.python/browse_thread/thread/961a90219a61e19d# > > any ideas what's the reason and how to fix it? > I have tried to search google but got nothing yet. Implicit relative imports were removed in Python 3 to prevent ambiguity as the number of packages grows. See PEP 328. If you have two modules in the same package, pack1.mod1 and pack1.mod2, then in pack1.mod1 you can no longer just do "import mod2" or "from mod2 import foo". Either use an absolute import ("from pack1.mod2 import foo") or make the relative import explicit ("from .mod2 import foo" -- note the ".") If you're upgrading scripts from Python 2 to Python 3, you should really run them through the 2to3 tool. I believe this is one of the many things it will fix for you automatically. From jlsphar at gmail.com Sat May 7 11:20:32 2011 From: jlsphar at gmail.com (John) Date: Sat, 7 May 2011 08:20:32 -0700 (PDT) Subject: Django/AppEngine DevSoup Message-ID: Sooo I have a windows box... which I like to think is the reason I'm a django/appengine mess right now. There's eclipse, pydev, django non-rel, mediagenerator, etc.... Would it be stupid of me to just use the simple, clean notepad++ & django with aims to port into appengine after I finish in a week? I don't want to deal with all of the other stuff. Will this come back to haunt me in 7 days? Yours frazzled, John From emato at nothere.tampabay.com Sat May 7 14:29:41 2011 From: emato at nothere.tampabay.com (emato) Date: Sat, 7 May 2011 14:29:41 -0400 Subject: Python IDE/text-editor References: Message-ID: <4dc58fa3$0$8718$9a6e19ea@unlimited.newshosting.com> > On Apr 16, 1:20 pm, Alec Taylor wrote: > >> I'm looking for an IDE which offers syntax-highlighting, >> code-completion, tabs, gedit http://projects.gnome.org/gedit/index.html From andrew at acooke.org Sat May 7 15:03:28 2011 From: andrew at acooke.org (andrew cooke) Date: Sat, 7 May 2011 12:03:28 -0700 (PDT) Subject: ABC-registered Exceptions are not caught as subclasses Message-ID: <69a952d2-55c8-4328-85de-47f51ef53d32@glegroupsg2000goo.googlegroups.com> This isn't hugely surprising, but doesn't seem to be documented. Is it a bug, or worth raising as one, or have I misunderstood? Python 3.2 (r32:88445, Feb 27 2011, 13:00:05) [GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from abc import ABCMeta >>> class RootException(Exception,metaclass=ABCMeta): pass ... >>> class MyException(Exception): pass ... >>> RootException.register(MyException) >>> try: ... raise MyException ... except RootException: ... print('caught') ... Traceback (most recent call last): File "", line 2, in __main__.MyException If you assume that the ABC "register" class should work likeinheritance (as it does with issubclass and isinstance then you would, I think, have expected the exception above to have been caught. Andrew From ben+python at benfinney.id.au Sat May 7 16:09:19 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 May 2011 06:09:19 +1000 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> Message-ID: <87aaeymfww.fsf@benfinney.id.au> Gregory Ewing writes: > > On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote: > > > >>?x? is a name. Names are bound to values. Talk of ?variable? only > >>confuses the issue because of the baggage carried with that term. > > But to use 'name' as a complete replacement for 'variable', I don't propose doing that. > In Python I use 'variable' to mean more or less 'something that can be > assigned to', which accords with the way it's used in relation to many > other languages, and doesn't suggest any restriction to things named > by a single identifier. No, I think not. The term ?variable? usually comes with a strong expectation that every variable has exactly one name. Your more broad usage would need to be carefully explained to newbies anyway, so I don't see a good reason to use the term ?variable? for that either. > Seems to me that anyone taking that connotation from it has not yet > been sufficiently educated about the Python data model itself. Yes, of course. But why not meet such newcomers partway, by not confusing the issue with a term which needs such delicate treatment? > >>Saying ?variable? and ?has the value? > > But I don't say "has a value", I say "refers to". Good for you. Most don't. -- \ Q: ?I've heard that Linux causes cancer...? Torvalds: ?That's a | `\ filthy lie. Besides, it was only in rats and has not been | _o__) reproduced in humans.? ?Linus Torvalds | Ben Finney From roy at panix.com Sat May 7 16:24:26 2011 From: roy at panix.com (Roy Smith) Date: Sat, 07 May 2011 16:24:26 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> <87aaeymfww.fsf@benfinney.id.au> Message-ID: In article <87aaeymfww.fsf at benfinney.id.au>, Ben Finney wrote: > No, I think not. The term ???variable??? usually comes with a strong > expectation that every variable has exactly one name. Heh. You've never used common blocks in Fortran? Or, for that matter, references in C++? I would call either of those "two names for the same variable". From python at rcn.com Sat May 7 17:02:10 2011 From: python at rcn.com (Raymond Hettinger) Date: Sat, 7 May 2011 14:02:10 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> <4dc428f2$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc502e8$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 7, 1:29?am, Steven D'Aprano wrote: > On Fri, 06 May 2011 12:36:09 -0600, Ian Kelly wrote: > > The amb engine would conceptually execute this function for every > > possible combination of a, b, and c, > > Which pretty much is the definition of "brute-force solver", no? FWIW, here's one of my favorite brute-force solvers: http://code.activestate.com/recipes/576615-alphametics-solver/ Raymond ------- follow my recipes and tips on twitter: @raymondh From no.email at nospam.invalid Sat May 7 17:07:38 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 07 May 2011 14:07:38 -0700 Subject: dictionary size changed during iteration References: <4DAED72B.2030400@shopzeus.com> Message-ID: <7xd3jukyn9.fsf@ruckus.brouhaha.com> Roy Smith writes: > changes = [ ] > for key in d.iterkeys(): > if is_bad(key): > changes.append(key) changes = list(k for k in d if is_bad(k)) is a little bit more direct. From alex.kapps at web.de Sat May 7 18:05:16 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Sun, 08 May 2011 00:05:16 +0200 Subject: PyGTK notebook: get current page In-Reply-To: <4dc55f75$0$38638$4fafbaef@reader1.news.tin.it> References: <4dc55f75$0$38638$4fafbaef@reader1.news.tin.it> Message-ID: <4DC5C21C.6030107@web.de> On 07.05.2011 17:04, Tracubik wrote: > Hi all! > I've made a simple PyGTK program. > It's a window with a notebook, the notebook have 2 pages > When changing page, i'ld like to get the id of current page. > > I've coded it, but i can get only the previously open page, not the > current one. This is not a big deal if i have only 2 pages, but it could > be with 3 or more pages. > > Here's the code: > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > # template di finestra in pyGTK > > import pygtk > pygtk.require('2.0') > import gtk > > class FinestraGTK: > > def pippo(self, widget, event, data=None): > print "current page: " + str(self.nb.get_current_page() ) According to PyGTK docs, the event handler for the switch_page signal should look like this: def pippo(self, notebook, page, page_num, user_data=None): ... With this method you get the new page number in page_num (or in your original method with the misleadingly named "data" argument) HTH From roy at panix.com Sat May 7 18:12:21 2011 From: roy at panix.com (Roy Smith) Date: Sat, 07 May 2011 18:12:21 -0400 Subject: dictionary size changed during iteration References: <4DAED72B.2030400@shopzeus.com> <7xd3jukyn9.fsf@ruckus.brouhaha.com> Message-ID: In article <7xd3jukyn9.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Roy Smith writes: > > changes = [ ] > > for key in d.iterkeys(): > > if is_bad(key): > > changes.append(key) > > changes = list(k for k in d if is_bad(k)) > > is a little bit more direct. This is true. I still file list comprehensions under "new fangled toys". While I use them, and appreciate their value, I admit they're not always the first thing that comes to my mind. OBTW, > changes = [k for k in d if is_bad(k)] is even more direct :-) From greg.ewing at canterbury.ac.nz Sat May 7 18:39:39 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 08 May 2011 10:39:39 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> Message-ID: <92m01eFeilU1@mid.individual.net> Chris Angelico wrote: > I think "manipulate" here means things like pointer arithmetic, I don't believe that allowing arithmetic on pointers is a prerequisite to considering them first-class values. You can't do arithmetic on pointers in Pascal, for example, but nobody argues that Pascal pointers are not values. -- Greg From stef.mientki at gmail.com Sat May 7 18:40:20 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 08 May 2011 00:40:20 +0200 Subject: is there an autocompletion like Dasher ? Message-ID: <4DC5CA54.7010606@gmail.com> hello, I would like to have a autocompletion / help /snippet system like Dasher : http://www.inference.phy.cam.ac.uk/dasher/ anyone seen such a component ? thanks, Stef From greg.ewing at canterbury.ac.nz Sat May 7 18:54:57 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 08 May 2011 10:54:57 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <87aaeymfww.fsf@benfinney.id.au> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> <87aaeymfww.fsf@benfinney.id.au> Message-ID: <92m0u4Fkl5U1@mid.individual.net> Ben Finney wrote: > No, I think not. The term ?variable? usually comes with a strong > expectation that every variable has exactly one name. I would say that many variables don't have names *at all*, unless you consider an expression such as a[i] to be a "name". And if you *do* consider that to be a name, then clearly one variable can have a great many names. What would *you* call a[i]? -- Greg From greg.ewing at canterbury.ac.nz Sat May 7 18:58:39 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 08 May 2011 10:58:39 +1200 Subject: seems like a bug in isinstance() In-Reply-To: <619d1edd-4aeb-4c2d-a5c1-757f63e52bd5@d27g2000vbz.googlegroups.com> References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> <92kfkmF4d5U1@mid.individual.net> <619d1edd-4aeb-4c2d-a5c1-757f63e52bd5@d27g2000vbz.googlegroups.com> Message-ID: <92m151Fm76U1@mid.individual.net> dmitrey wrote: > Yes, you are right. But I have to do it due to another issue I haven't > solved yet: Python3 imports don't see files from same directory > http://groups.google.com/group/comp.lang.python/browse_thread/thread/9470dbdacc138709# That's because the syntax for relative imports has changed in Python 3. See the recent comment on your posting there for details. -- Greg From greg.ewing at canterbury.ac.nz Sat May 7 19:04:53 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 08 May 2011 11:04:53 +1200 Subject: Django/AppEngine DevSoup In-Reply-To: References: Message-ID: <92m1goFoinU1@mid.individual.net> John wrote: > There's eclipse, pydev, django non-rel, mediagenerator, etc.... > > Would it be stupid of me to just use the simple, clean notepad++ & > django with aims to port into appengine after I finish in a week? I > don't want to deal with all of the other stuff. Will this come back to > haunt me in 7 days? I'd say you definitely don't need Eclipse, and probably don't need the other stuff. I've being doing all my Python coding using relatively dumb text editors for many years, including maintaining a django-based site, and haven't suffered any hauntings so far. :-) -- Greg From drsalists at gmail.com Sat May 7 19:28:12 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 7 May 2011 16:28:12 -0700 Subject: is there an autocompletion like Dasher ? In-Reply-To: <4DC5CA54.7010606@gmail.com> References: <4DC5CA54.7010606@gmail.com> Message-ID: On Sat, May 7, 2011 at 3:40 PM, Stef Mientki wrote: > hello, > > I would like to have a autocompletion / help /snippet system like Dasher : > > http://www.inference.phy.cam.ac.uk/dasher/ > > anyone seen such a component ? > Ummm... For what OS and what hardware? Do you need something that was written in Python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat May 7 19:43:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 May 2011 09:43:28 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <92m0u4Fkl5U1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> <87aaeymfww.fsf@benfinney.id.au> <92m0u4Fkl5U1@mid.individual.net> Message-ID: On Sun, May 8, 2011 at 8:54 AM, Gregory Ewing wrote: > Ben Finney wrote: > >> No, I think not. The term ?variable? usually comes with a strong >> expectation that every variable has exactly one name. > > I would say that many variables don't have names *at all*, > unless you consider an expression such as a[i] to be > a "name". And if you *do* consider that to be a name, > then clearly one variable can have a great many names. > > What would *you* call a[i]? a is a variable; i is a variable; a[i] is an expression. It's not a single name, and if you had two variables i and j with the same value, nobody would disagree that a[i] and a[j] ought to be the same thing. That's the whole point of arrays/lists/etc/etc. But if you want to fry your noggin, wrap your head around REXX's compound variables: a=5 b=3 array.a.b="Hello" /* see, this is a two-dimensional array */ c=63/10 array.c="world!" /* see, we can have non-integers as array indices */ d=a+1 result = array.a.b", "array.d.b /* "Hello, world!" */ So what is a "name" in REXX? You have to evaluate the compound variable as a set of tokens, then evaluate the whole thing again, and is that the name? Because the resulting "name" might not be a valid identifier... Yep, it's good stuff. Chris Angelico From stef.mientki at gmail.com Sat May 7 19:56:52 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 08 May 2011 01:56:52 +0200 Subject: is there an autocompletion like Dasher ? In-Reply-To: References: <4DC5CA54.7010606@gmail.com> Message-ID: <4DC5DC44.3030208@gmail.com> On 08-05-2011 01:28, Dan Stromberg wrote: > > On Sat, May 7, 2011 at 3:40 PM, Stef Mientki > wrote: > > hello, > > I would like to have a autocompletion / help /snippet system like Dasher : > > http://www.inference.phy.cam.ac.uk/dasher/ > > anyone seen such a component ? > > > Ummm... For what OS and what hardware? Windows desktop (and webbrowser would be nice) > Do you need something that was written in Python? > > preferable thanks, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From noah.mcilraith at gmail.com Sat May 7 20:00:11 2011 From: noah.mcilraith at gmail.com (mcilrain) Date: Sat, 7 May 2011 17:00:11 -0700 (PDT) Subject: A suggestion for an easy logger In-Reply-To: Message-ID: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> Aside from the fact that it's very Javay, what's wrong with the logging module? From ben+python at benfinney.id.au Sat May 7 21:16:40 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 May 2011 11:16:40 +1000 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> <87aaeymfww.fsf@benfinney.id.au> <92m0u4Fkl5U1@mid.individual.net> Message-ID: <8762pmm1on.fsf@benfinney.id.au> Gregory Ewing writes: > Ben Finney wrote: > > > No, I think not. The term ?variable? usually comes with a strong > > expectation that every variable has exactly one name. > > I would say that many variables don't have names *at all*, unless you > consider an expression such as a[i] to be a "name". Again, our disagreement is not over the behaviour of Python, but over what an average newcomer to Python can be expected to understand by the term ?variable? from its usage elsewhere in programming. > What would *you* call a[i]? What *I* would call that isn't relevant to the point. I do think it's even more misleading to call that ?a variable?, though, since it's not what the Python docs call a variable and it's not what an average newcomer would call a variable. It's a reference. So is ?a?, so is ?i?; names are a special kind of reference. In Python, references are how we get at objects within our code, and names are one kind of reference. -- \ ?Not using Microsoft products is like being a non-smoker 40 or | `\ 50 years ago: You can choose not to smoke, yourself, but it's | _o__) hard to avoid second-hand smoke.? ?Michael Tiemann | Ben Finney From clp2 at rebertia.com Sat May 7 22:03:35 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 7 May 2011 19:03:35 -0700 Subject: ABC-registered Exceptions are not caught as subclasses In-Reply-To: <69a952d2-55c8-4328-85de-47f51ef53d32@glegroupsg2000goo.googlegroups.com> References: <69a952d2-55c8-4328-85de-47f51ef53d32@glegroupsg2000goo.googlegroups.com> Message-ID: On Sat, May 7, 2011 at 12:03 PM, andrew cooke wrote: > > This isn't hugely surprising, but doesn't seem to be documented. ?Is it a bug, or worth raising as one, or have I misunderstood? > > > Python 3.2 (r32:88445, Feb 27 2011, 13:00:05) > [GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from abc import ABCMeta >>>> class RootException(Exception,metaclass=ABCMeta): pass > ... >>>> class MyException(Exception): pass > ... >>>> RootException.register(MyException) >>>> try: > ... ? ? raise MyException > ... except RootException: > ... ? ? print('caught') > ... > Traceback (most recent call last): > ?File "", line 2, in > __main__.MyException > > If you assume that the ABC "register" class should work likeinheritance (as it does with issubclass and isinstance then you would, I think, have expected the exception above to have been caught. Seems worth filing a bug IMO; it probably deserves clarification in the docs if nothing else, though this behavior isn't inconsistent with them as they're currently written (due to the vagaries of natural language). Cheers, Chris From steve+comp.lang.python at pearwood.info Sat May 7 22:17:38 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2011 02:17:38 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> Message-ID: <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 May 2011 21:21:45 +1200, Gregory Ewing wrote: > Hans Georg Schaathun wrote: > >> You cannot reference nor manipulate a reference in python, and that >> IMHO makes them more abstract. > > You can manipulate them just fine by moving them from one place to > another: > > a = b I see no reference there, nor do I see any moving taking place. What I see is a name binding operation. What is happening is that the name "a" is being bound to the object "b" (or to be precise, to whatever object is currently bound to name "b"). Since you haven't explained what you think is happening, I can only guess. My guess is that you are thinking about some implementation of the Python VM which uses some sort of reference internally. Perhaps it's CPython, which uses pointers, or some C++ implementation which actually uses an indirect pointer-like data structure called "reference", or maybe even some old-time FORTRAN I implementation that simulates pointers with integer indexes into a fixed size array. It could be anything. But whatever you're thinking of, it's not the behaviour of *Python* code, it's behaviour of the Python virtual machine's implementation. It astonishes me how hard it is to distinguish between abstraction levels when discussing computer languages. We don't have this problem in other fields. Nobody talking about (say) Solitaire on a computer would say: "Blat the pixels in the rect A,B,C,D to the rect E,F,G,H. That will free up the Ace of Spades and allow you to memcopy the records in the far right column of the tableau into the foundation." but when it comes to high-level computer languages like Python, we do the equivalent *all the time*. (I include myself in this.) And people get into (often angry) arguments over definitions, when what they're really arguing about is what is happening at different abstraction levels. A simplified view: At the Python level: binding of objects to names. No data is copied except by use of a direct "copy" instruction, e.g. slicing. At the Python VM level: objects pushed and popped from a stack. At the VM implementation level: Name binding may be implemented by copying pointers, or some other reference, in some data structure representing name spaces. Or by any other mechanism you like, so long as the behaviour at the Python level is the same. At the assembly language level: memory is copied from one address to another. At the hardware level: we usually describe bit manipulation in terms of binary AND, XOR and OR, but even that may be an abstraction: it's possible that the only binary op physically used by the machine is NAND. -- Steven From vinay_sajip at yahoo.co.uk Sat May 7 22:27:17 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 7 May 2011 19:27:17 -0700 (PDT) Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> Message-ID: On May 8, 1:00?am, mcilrain wrote: > Aside from the fact that it's very Javay, what's wrong with theloggingmodule? It's not especially Java-like. Since you can log using just import logging logging.basicConfig(level=logging.DEBUG) logging.debug('This is %sic, not %s-like - that's FUD', 'Python', 'Java') it doesn't seem especially Java-like: no factories, Interfaces, builders, using plain functions etc. The second line is optional and needed only if you want to log DEBUG or INFO messages (as the default threshold is WARNING). Despite other logging libraries claiming to be more Pythonic, they have pretty much the same concepts as stdlib logging - because those concepts are tied to logging, not to Java. Call it correlation vs. causation, or convergent evolution, or what you will. Regards, Vinay Sajip From gnarlodious at gmail.com Sat May 7 22:55:21 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 7 May 2011 19:55:21 -0700 (PDT) Subject: Py 3.2: sqlite can't operate on a closed cursor Message-ID: <2ba90070-ee5e-4388-a713-c612a7419db0@s16g2000prf.googlegroups.com> I installed Python 3.2, suddenly getting an error on my sqlite pages (CGI): ProgrammingError: Cannot operate on a closed cursor Works normally in interactive mode. Seems to error when the sqlite statement is in a function. Are sqlite objects now required to be declared global? -- Gnarlie From gnarlodious at gmail.com Sat May 7 23:17:57 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 7 May 2011 20:17:57 -0700 (PDT) Subject: Py 3.2: sqlite can't operate on a closed cursor References: <2ba90070-ee5e-4388-a713-c612a7419db0@s16g2000prf.googlegroups.com> Message-ID: It turns out Python 3.2 now honors closing sqlite connections opened in another module. Previous versions allowed you to have identically named sqlite connections open in other modules. Python 3.2 apparently treats them all as the same connection. Hopefully some other victim will find this, because it wasn't written in the documentation http://docs.python.org/dev/whatsnew/3.2.html#sqlite3 -- Gnarlie From harrismh777 at charter.net Sat May 7 23:50:55 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 07 May 2011 22:50:55 -0500 Subject: checking if a list is empty In-Reply-To: <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> ... if not li says nothing about what li is supposed to 'be' > Yes, and? Neither does: > > isempty(li) # li could be anything that polymorphic isempty can deal with > li.isempty() # li could be anything with a "isempty" method > len(li) == 0 # li could be anything with a length (list, dict, set, ...) Sure. > That's duck-typing for you, and it is generally a strength rather than a > weakness. For those times when it is a weakness, that's where we have > naming conventions, type-testing, and (in some languages) static types. I can fix almost anything with duck-type... :) >> > and implies in any case that li does not exist > It does nothing of the sort. If li doesn't exist, you get a NameError. That was the point. 'not' implies something that is not logical; which is irony extreme since 'not' is typically considered a logical operator. What does it mean to say not ? Well, apparently it means the list is 'empty'... but why should it mean that? Why not have it mean the list has been reversed in place? Why not have it mean that the list isn't homogeneous? Why not have it mean that its not mutable? I could think of more... Why should 'not' mean 'empty'? >> > or worse is some kind of boolean. > Only if you're still thinking in some language that isn't Python. Which most of us are... hate to remind you... Python is the new kid on the block, and most of us are coming at this from multiple filters in comp sci experience. Its just the truth. >> > Why not have a list method that makes this more explicit: > For the same reason that we don't have an int method that makes zero > testing more explicit: > Because sometimes you can have too much explicitness. True. kind regards, m harris From harrismh777 at charter.net Sun May 8 00:10:54 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 07 May 2011 23:10:54 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Nobody talking about (say) Solitaire on a computer would say: > > "Blat the pixels in the rect A,B,C,D to the rect E,F,G,H. That will free > up the Ace of Spades and allow you to memcopy the records in the far > right column of the tableau into the foundation." > > but when it comes to high-level computer languages like Python, we do the > equivalent *all the time*. I find exception to that argument. That is an example of the bogus analogy fallacy. (I am offering this in friendship, actually). The two cases have nothing to do with one another, do not affect one another directly or indirectly, and are not helpful for comparison sake. Analogies are generally not helpful in discussion and ought to be avoided generally... except for entertainment sake... and frankly I have found many of your analogies most entertaining (and creative) ! Second point, we seldom do anything *all the time* / this is a fallacy that presupposes extreme references, as we think about the argument; extreme exageration is not helpful... may or may not be rightly extreme, and may or may not be relevant. What can be said (about the argument) is that we sometimes waste time arguing over abstraction layers with limited cross-dependent understanding. (I include myself in this.) (myself, as well) ... the humility is appreciated. > And people get > into (often angry) arguments over definitions, when what they're really > arguing about is what is happening at different abstraction levels. Sometimes. More often than not, folks are not really angry (I am seldom angry at my computer terminal... its one of the places where I relax, learn, communicate, and relate with other computer scientists who enjoy what they do because its enjoyable. I do agree with you that we all sometimes talk past each other because we're arguing from within a 'different' level of abstraction. kind regards, m harris From nobody at nowhere.net.no Sun May 8 00:49:21 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 08 May 2011 12:49:21 +0800 Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> Message-ID: Vinay Sajip wrote: WoW :O , the creator !! > import logging > > logging.basicConfig(level=logging.DEBUG) I'm getting there, but the result it's not what I would. As far as I got to know, it should take to write a configuration file, which I still not aware of. I'd like to just have the 4 conditions mentioned in the first post. Once I'll get into the dirt I'll try to bring up also the other features that logging module gives. -- goto /dev/null From ethan at stoneleaf.us Sun May 8 00:57:13 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 07 May 2011 21:57:13 -0700 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DC622A9.4010000@stoneleaf.us> harrismh777 wrote: > Steven D'Aprano wrote: >>> attribution lost wrote: >>> > and implies in any case that li does not exist >> It does nothing of the sort. If li doesn't exist, you get a NameError. > > That was the point. 'not' implies something that is not logical; > which is irony extreme since 'not' is typically considered a logical > operator. What does it mean to say not ? Well, apparently > it means the list is 'empty'... but why should it mean that? Why not > have it mean the list has been reversed in place? Why not have it mean > that the list isn't homogeneous? Why not have it mean that its not > mutable? I could think of more... Why should 'not' mean 'empty'? Because this is Python, and in Python that's what it means. > >>> > or worse is some kind of boolean. >> Only if you're still thinking in some language that isn't Python. > > Which most of us are... hate to remind you... Python is the new kid > on the block, and most of us are coming at this from multiple filters in > comp sci experience. Its just the truth. And your point would be? If you're going to use a language, and use it well, you have to learn how that language works. ~Ethan~ From robert.brown at gmail.com Sun May 8 01:44:13 2011 From: robert.brown at gmail.com (Robert Brown) Date: Sun, 08 May 2011 01:44:13 -0400 Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87hb9521ci.fsf@ugg.bibliotech.com> Steven D'Aprano writes: > If you value runtime efficiency over development time, sure. There are > plenty of languages which have made that decision: Pascal, C, Java, > Lisp, Forth, and many more. I don't understand why you place Lisp and Forth in the same category as Pascal, C, and Java. Lisp and Forth generally have highly interactive development environments, while the other languages generally require an edit, compile, run it again debugging cycle. Lisp in particular does a better job than Python in optimizing developer time. I can change class definitions interactively without restarting my program. I can add type declarations to a single function and recompile it without restarting my program. Python requires me to rewrite the slow bits of my program in C to get good performance. Why is that an efficient use of developer time? bob From rustompmody at gmail.com Sun May 8 01:48:20 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 7 May 2011 22:48:20 -0700 (PDT) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1cf03d24-5e64-4770-a03b-b82978b35a6b@y27g2000prb.googlegroups.com> On May 8, 7:17?am, Steven D'Aprano wrote: > On Sat, 07 May 2011 21:21:45 +1200, Gregory Ewing wrote: > > Hans Georg Schaathun wrote: > > >> You cannot reference nor manipulate a reference in python, and that > >> IMHO makes them more abstract. > > > You can manipulate them just fine by moving them from one place to > > another: > > > ? ? a = b > > I see no reference there, nor do I see any moving taking place. What I > see is a name binding operation. What is happening is that the name "a" > is being bound to the object "b" (or to be precise, to whatever object is > currently bound to name "b"). > > Since you haven't explained what you think is happening, I can only > guess. My guess is that you are thinking about some implementation of the > Python VM which uses some sort of reference internally. Perhaps it's > CPython, which uses pointers, or some C++ implementation which actually > uses an indirect pointer-like data structure called "reference", or maybe > even some old-time FORTRAN I implementation that simulates pointers with > integer indexes into a fixed size array. It could be anything. > > But whatever you're thinking of, it's not the behaviour of *Python* code, > it's behaviour of the Python virtual machine's implementation. > > It astonishes me how hard it is to distinguish between abstraction levels > when discussing computer languages. We don't have this problem in other > fields. Nobody talking about (say) Solitaire on a computer would say: > > "Blat the pixels in the rect A,B,C,D to the rect E,F,G,H. That will free > up the Ace of Spades and allow you to memcopy the records in the far > right column of the tableau into the foundation." > > but when it comes to high-level computer languages like Python, we do the > equivalent *all the time*. It has to be so -- because the Turing machine like the modern computer is an unbelievable abstraction squasher. Yes unbelievable in the sense that people simply cant come to terms with this. [Witness your "It astonishes me..." Harris: "I take exception.." etc] The modern computer (von Neumann) <- self-modifying code <- Data=Code <- Undecidability (Halting problem) <- Consistency XOR Completeness (Godels theorem(s)) <- Leaky Abstractions as inevitable If anyone thinks Godels theorems are easy trivial, he probably does not know what he is talking about, Yet we think that computers are easy to understand? [Ive personally witnessed PhDs in computer science not appreciate compilers' inability to do certain things, and yet they could go and take a bunch of lectures on the halting problem. What they understand is anybody's guess :-) ] Coming back to topic: The argument (about bindings, variables etc) arises because python (like lisp) is an imperative language masquerading as a functional one. Such arguments dont arise in Haskell or in assembly language. They arise and are tolerable in C. They are terrible in C++ because all the abstractions are built to leak. Where python sits in this (circular) spectrum is an interesting question (and I watch the arguments with much interest) From research at johnohagan.com Sun May 8 02:04:30 2011 From: research at johnohagan.com (John O'Hagan) Date: Sun, 8 May 2011 06:04:30 +0000 Subject: Python3: imports don't see files from same directory? In-Reply-To: References: Message-ID: <201105080604.31146.research@johnohagan.com> On Sat, 7 May 2011, Ian Kelly wrote: [...] > > Implicit relative imports were removed in Python 3 to prevent > ambiguity as the number of packages grows. See PEP 328. > > If you have two modules in the same package, pack1.mod1 and > pack1.mod2, then in pack1.mod1 you can no longer just do "import mod2" > or "from mod2 import foo". Either use an absolute import ("from > pack1.mod2 import foo") or make the relative import explicit ("from > .mod2 import foo" -- note the ".") > > If you're upgrading scripts from Python 2 to Python 3, you should > really run them through the 2to3 tool. I believe this is one of the > many things it will fix for you automatically. For some reason I haven't fathomed yet, I've found that while 2to3 does change the import syntax to the dot form as you say, this results in "ValueError: Attempted relative import in non-package", and I have to change it back to the old way, which works fine although the docs say it shouldn't. This is python 3.2 on Debian testing. For example, if I have a directory containing an __init__.py file, and two modules, one of which is called mod1 and contains #!/usr/bin/python3 a=1 in the other module I can have import mod1 or from mod1 import a but not from .mod1 import a or import .mod1 What gives? From nobody at nowhere.net.no Sun May 8 02:15:57 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 08 May 2011 14:15:57 +0800 Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> Message-ID: TheSaint wrote: > I'd like to just have the 4 conditions mentioned in the first post. > OK, my analysis led me to the print() function, which would suffice for initial my purposes. Meanwhile I reading the tutorials, but I couldn't get how to make a formatter to suppress or keep the LF(CR) at the end of the statement. -- goto /dev/null From benjamin.kaplan at case.edu Sun May 8 02:24:03 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 7 May 2011 23:24:03 -0700 Subject: Python3: imports don't see files from same directory? In-Reply-To: <201105080604.31146.research@johnohagan.com> References: <201105080604.31146.research@johnohagan.com> Message-ID: On Sat, May 7, 2011 at 11:04 PM, John O'Hagan wrote: > On Sat, 7 May 2011, Ian Kelly wrote: > [...] >> >> Implicit relative imports were removed in Python 3 to prevent >> ambiguity as the number of packages grows. ?See PEP 328. >> >> If you have two modules in the same package, pack1.mod1 and >> pack1.mod2, then in pack1.mod1 you can no longer just do "import > mod2" >> or "from mod2 import foo". ?Either use an absolute import ("from >> pack1.mod2 import foo") or make the relative import explicit ("from >> .mod2 import foo" -- note the ".") >> >> If you're upgrading scripts from Python 2 to Python 3, you should >> really run them through the 2to3 tool. ?I believe this is one of the >> many things it will fix for you automatically. > > For some reason I haven't fathomed yet, I've found that while 2to3 > does change the import syntax to the dot form as you say, this results > in "ValueError: Attempted relative import in non-package", and I have > to change it back to the old way, which works fine although the docs > say it shouldn't. This is python 3.2 on Debian testing. > > For example, if I have a directory containing an __init__.py file, and two > modules, one of which is called mod1 and contains > > #!/usr/bin/python3 > a=1 > > in the other module I can have > > import mod1 > > or > > from ?mod1 import a > > but not > > from .mod1 import a > > or > > import .mod1 > > > What gives? * Absolute imports are given as modules coming straight from something on sys.path. If you actually check sys.path, you'll probably notice that '' is on there, which in this case refers to the current directory. * In order to do relative imports, you need to be in a package. Having an __init__.py somewhere does not automatically make it a package. To be a package, it has to be in one of the folders on sys.path. Since python doesn't have a name for that folder that __init__.py is in, it's not actually a part of a package. From rosuav at gmail.com Sun May 8 02:32:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 May 2011 16:32:04 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92kjooF31mU1@mid.individual.net> <87aaeymfww.fsf@benfinney.id.au> <92m0u4Fkl5U1@mid.individual.net> Message-ID: On Sun, May 8, 2011 at 4:16 PM, Dennis Lee Bieber wrote: > On Sun, 08 May 2011 10:54:57 +1200, Gregory Ewing > declaimed the following in > gmane.comp.python.general: > >> >> What would *you* call a[i]? >> > ? ? ? ?Depending upon the nature of the beast, I'd be tempted to call it a > "fully qualified name" or a "partially qualified name" > > ? ? ? ?a = [1, 2, 4, ("c", "d", "e")] Why is an integer more or less important than a tuple? a[3] is no less qualified than a[2]; each of them points to an object. One of those objects happens to contain other objects. What if you had: stdio = [stdin, stdout, stderr] They might be 'file' objects, or they might be integers (unlikely in Python), or they could be pipes or other file-like objects, or they might be some kind of special tee object that contains two file objects. Let's say your standard I/O uses the notation stdout.write('message') and that you have a subclass of tuple that will apply the . operator to all its members (is that possible in Python? If not, pretend it is). You could then execute stdio[1]=(stdout,teeobject) to easily copy your screen output to another file. At this point, you can actually pretend that stdio[0] and stdio[1] are identical objects, but you can use stdio[1][1] and you can't use stdio[0][1] - which means that, per your definition, one of them is only partially qualified. As Inigo Montoya said, there is too much - let me sum up. Lists/tuples and integers are equally objects, so whether or not you have a 'name' is not affected by what type of object it points to. Chris Angelico From rustompmody at gmail.com Sun May 8 03:43:37 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 8 May 2011 00:43:37 -0700 (PDT) Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <7ab08d8c-3af0-4292-8f6b-68b912762474@d19g2000prh.googlegroups.com> On Apr 26, 7:39?pm, snorble wrote: > I'm not a Pythonista, but I aspire to be. > > My current tools: > > Python, gvim, OS file system > > My current practices: > > When I write a Python app, I have several unorganized scripts in a > directory (usually with several named test1.py, test2.py, etc., from > random ideas I have tested), and maybe a todo.txt file. Then I hack > away, adding features in a semi-random order. Then I get busy with > other things. Maybe one week I spend 20 hours on development. The next > week, no time on development. A few weeks later when I have some time, > I'm excited to get back to making progress, only to find that I have > to spend 30-60 minutes figuring out where I left off. The code is > usually out of sync with todo.txt. I see people who release new > versions and bug fixes, so I sometimes will create a new directory and > continue working from that copy, because it seems like the thing to > do. But if I ever made something worth releasing, and got a request > like, "I have problems with the 2.0 version. Can you send me the old > 1.1 version?" I'd be like, "uhhh... let me hunt through my files by > hand and get back to you in a month". I'm thinking I can do a lot > better than this. > > I am aware of tools like version control systems, bug trackers, and > things like these, but I'm not really sure if I need them, or how to > use them properly. I think having some organization to all of this > would help me to make more consistent progress, and spend less time > bringing myself up to speed after some time off. > > I really like the idea of having a list of features, and tackling > those features one at a time. I read about people who do this, and > each new features gets a new minor version number. It sounds very > organized and clean. But I'm not really sure of the best way to > achieve this. Mainly I think I just need some recommendations to help > create a good mental map of what needs to happen, and mapping jargon > to concepts. Like, "each feature gets its own directory". Or with a > version control tool, I don't know if a feature maps to a branch, or a > commit? > > I appreciate any advice or guidance anyone has to offer. Recently saw this: [Disclaimer: Not tried] http://labs.creativecommons.org/2010/11/10/bridging-public-bugtrackers-and-local-tasklists/ From andrew at acooke.org Sun May 8 04:55:08 2011 From: andrew at acooke.org (andrew cooke) Date: Sun, 8 May 2011 01:55:08 -0700 (PDT) Subject: ABC-registered Exceptions are not caught as subclasses In-Reply-To: Message-ID: <3638ce9d-a1c0-4f3f-9a76-84103244a6e5@glegroupsg2000goo.googlegroups.com> http://bugs.python.org/issue12029 From andrew at acooke.org Sun May 8 04:55:08 2011 From: andrew at acooke.org (andrew cooke) Date: Sun, 8 May 2011 01:55:08 -0700 (PDT) Subject: ABC-registered Exceptions are not caught as subclasses In-Reply-To: Message-ID: <3638ce9d-a1c0-4f3f-9a76-84103244a6e5@glegroupsg2000goo.googlegroups.com> http://bugs.python.org/issue12029 From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sun May 8 05:23:48 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sun, 08 May 2011 11:23:48 +0200 Subject: Dictionary Views -- good examples? [was Re: Python 3 dict question] In-Reply-To: <92kghnFb37U1@mid.individual.net> References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> <92kghnFb37U1@mid.individual.net> Message-ID: Am 07.05.2011 11:09, schrieb Gregory Ewing: > Ethan Furman wrote: >> Ian Kelly wrote: >> >>> next(iter(myDict.items())) >> >> Which is becoming less elegant. > > If you're doing this sort of thing a lot you can make > a little helper function: > > def first(x): > return next(iter(x)) > > then you get to say > > first(myDict.items()) ... and get a StopIteration if the dict is empty. If you do def first(x, default=None): for i in x: return i return default you might have an alternative approach to do so. Thomas From vinay_sajip at yahoo.co.uk Sun May 8 06:26:18 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 8 May 2011 03:26:18 -0700 (PDT) Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> Message-ID: <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> On May 8, 7:15?am, TheSaint wrote: > OK, my analysis led me to the print() function, which would suffice for > initial my purposes. The logging HOWTO tells you when to use logging, warnings and print(): http://docs.python.org/howto/logging.html > Meanwhile I reading the tutorials, but I couldn't get how to make a > formatter to suppress or keep the LF(CR) at the end of the statement. For Python 3.2 and later, it's the terminator attribute of the StreamHandler. See: http://plumberjack.blogspot.com/2010/10/streamhandlers-newline-terminator-now.html Unfortunately, for earlier Python versions, you'd need to subclass and override StreamHandler.emit() to get equivalent functionality :-( Regards, Vinay Sajip From peterthebag at yahoo.com Sun May 8 06:44:06 2011 From: peterthebag at yahoo.com (pb) Date: Sun, 8 May 2011 03:44:06 -0700 (PDT) Subject: scipy Message-ID: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> Hi, I', having trouble with scipy. I have followed the instructions at scipy website and have installed the following on my mac osx 10.6.6 NumPy version 1.5.1 NumPy is installed in /Library/Frameworks/Python.framework/Versions/ 2.6/lib/python2.6/site-packages/numpy SciPy version 0.8.0 SciPy is installed in /Library/Frameworks/Python.framework/Versions/ 2.6/lib/python2.6/site-packages/scipy Python version 2.6.6 (r266:84374, Aug 31 2010, 11:00:51) [GCC 4.0.1 (Apple Inc. build 5493)] nose version 1.0.0 When I run the test scipy.test('1','10') some items seem to pass: test_streams.test_make_stream(True,) ... ok Some tests seem to be skipped: nose.selector: INFO: /Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/scipy/io/matlab/mio5_utils.so is executable; skipped some seem to fail: /Users/user/.python26_compiled/m7/module_multi_function.cpp:13:19: error: complex: No such file or directory and ====================================================================== ERROR: test_string_and_int (test_ext_tools.TestExtModule) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/scipy/weave/tests/test_ext_tools.py", line 72, in test_string_and_int mod.compile(location = build_dir) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/scipy/weave/ext_tools.py", line 367, in compile verbose = verbose, **kw) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/scipy/weave/build_tools.py", line 273, in build_extension setup(name = module_name, ext_modules = [ext],verbose=verb) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/numpy/distutils/core.py", line 186, in setup return old_setup(**new_attr) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/distutils/core.py", line 169, in setup raise SystemExit, "error: " + str(msg) CompileError: error: Command "c++ -fno-strict-aliasing -fno-common - dynamic -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/ 2.6/lib/python2.6/site-packages/scipy/weave -I/Library/Frameworks/ Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/weave/ scxx -I/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/core/include -I/Library/Frameworks/ Python.framework/Versions/2.6/include/python2.6 -c /Library/Frameworks/ Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/weave/ scxx/weave_imp.cpp -o /var/folders/4b/4bhByeH9HSuDIezfnSZ6G++++TI/- Tmp-/user/python26_intermediate/ compiler_7ca1591dfd3261e140e707030a00840e/Library/Frameworks/ Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/weave/ scxx/weave_imp.o" failed with exit status 1 with the final result being: FAILED (KNOWNFAIL=15, SKIP=40, errors=242, failures=2) I'm assuming I have the wrong version of something, would that be right? Does anyone know how I can fix this? thanks, Peter From nobody at nowhere.net.no Sun May 8 07:21:18 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 08 May 2011 19:21:18 +0800 Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> Message-ID: Vinay Sajip wrote: 8< > For Python 3.2 and later, it's the terminator attribute of the > StreamHandler. See: 8< > Unfortunately, for earlier Python versions, you'd need to subclass and > override StreamHandler.emit() to get equivalent functionality :-( > I'm with 3.2 and willing to stay :) I was trying ==================================code================================== >>>logging.basicConfig(format='%(message)s',terminator='',level=logging.DEBUG) >>> logging.debug('here we are') DEBUG:root:here we are >>> ==================================code================================== First I didn't espect to see much more than my message. I agree that I'm very new to the module Second the will terminator appear only to real stdout, or am I doing something incorrect? Note: some word wrapping doesn't show the python shell correctly. -- goto /dev/null From msarro at gmail.com Sun May 8 07:52:55 2011 From: msarro at gmail.com (Matty Sarro) Date: Sun, 8 May 2011 07:52:55 -0400 Subject: Python IDE/text-editor In-Reply-To: <4dc58fa3$0$8718$9a6e19ea@unlimited.newshosting.com> References: <4dc58fa3$0$8718$9a6e19ea@unlimited.newshosting.com> Message-ID: Pydev for eclipse/aptana On Saturday, May 7, 2011, emato wrote: > >> On Apr 16, 1:20 pm, Alec Taylor wrote: >> >>> I'm looking for an IDE which offers syntax-highlighting, >>> code-completion, tabs, > > gedit > > http://projects.gnome.org/gedit/index.html > > > -- > http://mail.python.org/mailman/listinfo/python-list > From vinay_sajip at yahoo.co.uk Sun May 8 08:31:15 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 8 May 2011 05:31:15 -0700 (PDT) Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> Message-ID: On May 8, 12:21?pm, TheSaint wrote: > First I didn't espect to see much more than my message. I agree that I'm > very new to the module You could do logging.basicConfig(level=logging.DEBUG, format='%(message)s') to get just the message. > Second the will terminator appear only to real stdout, or am I doing > something incorrect? The terminator is an attribute on the StreamHandler instance, so works with whatever stream the handler is using. You can't use basicConfig() directly, if you want to configure the terminator - instead, use something like sh = logging.StreamHandler(sys.stdout) sh.terminator = '' logging.getLogger().addHandler(sh) but be sure to execute this code one time only, or you will get multiple identical messages for a single logging call. Regards, Vinay Sajip From steve+comp.lang.python at pearwood.info Sun May 8 08:59:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2011 12:59:02 GMT Subject: Fibonacci series recursion error References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> <87hb9521ci.fsf@ugg.bibliotech.com> Message-ID: <4dc69395$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 08 May 2011 01:44:13 -0400, Robert Brown wrote: > Steven D'Aprano writes: >> If you value runtime efficiency over development time, sure. There are >> plenty of languages which have made that decision: Pascal, C, Java, >> Lisp, Forth, and many more. > > I don't understand why you place Lisp and Forth in the same category as > Pascal, C, and Java. Lisp and Forth generally have highly interactive > development environments, while the other languages generally require an > edit, compile, run it again debugging cycle. Good point. Perhaps I need to rethink where Lisp and Forth sit in the development vs runtime trade-off continuum. > Python requires me to rewrite the slow bits of my program in C > to get good performance. Python doesn't require you to re-write anything in C. If you want to make a different trade-off (faster runtime, slower development time) then you use a language that has made the appropriate trade-off. This applies whether you are talking about the entire program, or just one subroutine. > Why is that an efficient use of developer time? Because for any non-trivial program, it is faster and more developer friendly to just write one or three performance-critical routines in C, and the rest in Python, than it is to write everything in C. -- Steven From rdsteph at mac.com Sun May 8 09:28:26 2011 From: rdsteph at mac.com (rdsteph at mac.com) Date: Sun, 8 May 2011 06:28:26 -0700 (PDT) Subject: Pushing for Pythoncard 1.0 References: <6d896b66-3933-4743-8eb5-b9754f1ec14f@t19g2000prd.googlegroups.com> <5348cf4b-ffd2-41f0-a7a5-afedc00ed703@b35g2000yqn.googlegroups.com> Message-ID: <8a52d854-a029-4a5a-a6ba-7a060444a026@22g2000prx.googlegroups.com> On May 3, 12:15?pm, rnd wrote: > On May 2, 10:48?pm, John Henry wrote: > > > Attempt to push Pythoncard to a 1.0 status is now underway. ?A > > temporary website has been created at: > > >http://code.google.com/p/pythoncard-1-0/ > > > The official website continues to behttp://pythoncard.sourceforge.net/ > > > Pythoncard is such a wonderful package that it would be a shame to > > allow development for the package to go stagnant. ? The Python > > community deserves to continue enjoying the simplicity of Pythoncard > > for creating a GUI Python application. > > I was very positively surprised to hear someone talking about > PythonCard these days. > Even though I've not needed to develop GUI apps for years, I believe > its still great idea > to revive PythonCard even though everybody is busy developing for > "iThings" right now. > > Regards, > Roman Suzi I love and use PythonCard! From roy at panix.com Sun May 8 09:31:10 2011 From: roy at panix.com (Roy Smith) Date: Sun, 08 May 2011 09:31:10 -0400 Subject: Development tools and practices for Pythonistas References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: In article <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21 at r35g2000prj.googlegroups.com>, snorble wrote: > [standard tale of chaotic software development elided] > > I am aware of tools like version control systems, bug trackers, and > things like these, but I'm not really sure if I need them, or how to > use them properly. None of this has anything to do with python. It's all standard software engineering stuff that's the same with any language or technology. Bug trackers are essential for large projects. For a one-man project, it's probably more effort than it's worth. For the project I'm on now (4 developers co-located with the customer), we're using a shared google docs spreadsheet for bug tracking. It's free, low-overhead, and works well enough. For a single person, even that may be more than you need. On the other hand version control is essential from day zero, even on a one-man project. There's plenty of perfectly good, free, systems out there. The obvious choices are hg, git, and bzr. Pick one and use it. The nice thing about them all is there's no lock-in. If you decide you don't like the one you're using, you can easily convert your entire code repository to any of the others without losing anything. > I really like the idea of having a list of features, and tackling > those features one at a time. Yup, that's the core concept of all the agile development processes that are all the rage these days. Sometimes called "release early and often". > I read about people who do this, and > each new features gets a new minor version number. For the project I'm on, we don't even bother with version numbers. We have a main branch which we (try to) keep stable and shippable at all times, and push that to production whenever we've completed a feature (or bug fix) that the customer needs. I see we're currently running: 9be3fc6a0e01cf128f63d1af2b19c180fb4eaacb (tip) Version numbers make more sense with a traditional ("waterfall") type process, where you design a bunch of stuff, write the code, go through a testing and bug-fixing cycle, and the finally push it out the door. > I think I just need some recommendations to help > create a good mental map of what needs to happen, and mapping jargon > to concepts. Like, "each feature gets its own directory". Or with a > version control tool, I don't know if a feature maps to a branch, or a > commit? Well, start from the premise that you have a main branch which is always shippable. That means the code runs and passes all the tests after every single commit to that branch. Now, when you need to make a change (add a feature or fix a bug), ask yourself if the change is small enough that you can do all the work required in one day. If so, then doing it in a single commit on your main branch may make sense. If not, then spin up a development branch, do the work there, and when you're satisfied it's shippable, merge it onto your main branch. From steve+comp.lang.python at pearwood.info Sun May 8 10:07:23 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2011 14:07:23 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 May 2011 22:50:55 -0500, harrismh777 wrote: > Steven D'Aprano wrote: >>> > and implies in any case that li does not exist >> It does nothing of the sort. If li doesn't exist, you get a NameError. > > That was the point. 'not' implies something that is not logical; I'm afraid that makes no sense to me. How does "does not exist" imply something not logical? In what way is "this is not my house" implying something not logical? > which is irony extreme since 'not' is typically considered a logical > operator. Because "not" is typically used as a logical operator. In English, it negates a word or statement: "the cat is not on the mat" --> "the cat is on the mat" is false. As an operator, "not" negates a true value to a false value. In mathematical Boolean algebra, there only is one true value and one false value, conventionally called True/False or 1/0. In non-Boolean algebras, you can define other values. In three-value logic, the negation of True/ False/Maybe is usually False/True/Maybe. In fuzzy logic, the logic values are the uncountable infinity (that's a technical term, not hyperbole) of real numbers between 0 and 1. Python uses a boolean algebra where there are many ways of spelling the true and false values. The "not" operator returns the canonical bool values: not returns False not returns True Take note of the distinction between lower-case true/false, which are adjectives, and True/False, which are objects of class bool. This is not unique to Python. I understand the practice of allowing any value to be used in boolean expressions comes from Lisp in 1958, which makes it practically antediluvian. Lisp uses the empty list and the special atom NIL as false values, any other s-expression is true. Scheme is different: it defines a special false atom, and empty lists are considered true. In Ruby, only the false object and the null object are considered false. In Forth, any non-zero word is true. In Javascript, the empty string, null, undefined, NaN, +0, -0, and false are all considered false. > What does it mean to say not ? Well, apparently > it means the list is 'empty'... but why should it mean that? Because that is the definition chosen by the language designers. It is based on the fact that distinguishing between "something" and "nothing" is useful, common, fundamental, and applies to nearly all data types. > Why not > have it mean the list has been reversed in place? Why not have it mean > that the list isn't homogeneous? Why not have it mean that its not > mutable? I could think of more... Because those tests are not fundamental tests that deserve to be elevated to a language design feature, any more than we need a built-in function to add 27 and three quarters to the argument. > Why should 'not' mean 'empty'? Because the test of "is this nothing, or something?" is a common, useful test: 0 (nothing) vs 1, 2, 3, ... (something) empty list versus non-empty list empty dict versus non-empty dict empty set versus non-empty set empty string versus non-empty string no search results returned versus some search results returned no network connection available versus some network connection available no food in the cupboard versus food in the cupboard This is a fundamental distinction which is very useful in practice. >>> > or worse is some kind of boolean. >> Only if you're still thinking in some language that isn't Python. > > Which most of us are... hate to remind you... Time to stop then. This is Python, not whatever language you're thinking in. Don't force language A into the conceptual pigeonholes of language B. To be effective in a programming language, you need to understand how that language works, and not see everything filtered through the conceptual framework of another language. Bringing the viewpoints of other languages is a good thing. Python borrows concepts from many languages (sometimes what it borrows is the idea of "that's not how to do it"). And many idioms do cross language boundaries. But in general, it pays to think, and code, in the appropriate style for whatever language you are writing in. And certainly, you should not argue that a language feature is invalid or wrong merely because that's not how another language does it. Or, to put it another way: http://dirtsimple.org/2004/12/python-is-not-java.html http://dirtsimple.org/2004/12/java-is-not-python-either.html > Python is the new kid on the block, Nonsense. Python is 20 years old (1991), which makes it older than: Java, PHP, Ruby (1995) Javascript (1996) C# (2000) Visual Basic .Net (2001) to say nothing of dozens of other languages. > and most of us are coming at this from multiple > filters in comp sci experience. Its just the truth. There's nothing wrong with having experience in many languages. That's a good thing. -- Steven From gslindstrom at gmail.com Sun May 8 11:20:44 2011 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Sun, 8 May 2011 10:20:44 -0500 Subject: Dictionary from String? Message-ID: Is it possible to create a dictionary from a string value? Something along these lines (but that works): >>> mystring = "{'name':'greg','hatsize':'7 5/8'}" >>> mystring "{'name':'greg','hatsize':'7 5/8'}" >>> dict(mystring) Traceback (most recent call last): File "", line 1, in ValueError: dictionary update sequence element #0 has length 1; 2 is required >>> I would like to return an undetermined (at call time) number of fields from a postgres database (only 1 record) for a given request. My thought is that I could build a dictionary in the form of a string, return the string and then convert the string value to a dictionary. I can do that now, but I have to parse the string and then build the dictionary. Any thoughts or help you could provide would be appreciated. --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Sun May 8 11:59:44 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 08 May 2011 18:59:44 +0300 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > Lisp uses the empty list and the special atom NIL as false values, > any other s-expression is true. Scheme is different: it defines a > special false atom, and empty lists are considered true. In Ruby, I'll inject a pedantic note: there is only one false value in both Lisp (which now is mostly Common Lisp) and Scheme. The empty list () and the symbol NIL in Lisp are one value, not two values. The first Google hit (for me, just now) explains it the way I understand it: . (Common Lisp The Language, 2nd edition. Odd place to find that book. It predates the formal standard, but then I think this particular feature of the language is, indeed, as old as you say, and unlikely to have changed.) Scheme was the same. Then for a time it was not specified whether the empty list was distinct from the false value or the symbol nil - people disagreed and implementations were allowed to differ - until the three were definitely separated. From rosuav at gmail.com Sun May 8 12:16:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 May 2011 02:16:50 +1000 Subject: Dictionary from String? In-Reply-To: References: Message-ID: On Mon, May 9, 2011 at 1:20 AM, Greg Lindstrom wrote: > Is it possible to create a dictionary from a string value?? Something along > these lines (but that works): > >>>> mystring = "{'name':'greg','hatsize':'7 5/8'}" >>>> mystring > "{'name':'greg','hatsize':'7 5/8'}" >>>> dict(mystring) > Traceback (most recent call last): > ? File "", line 1, in > ValueError: dictionary update sequence element #0 has length 1; 2 is > required >>>> > > I would like to return an undetermined (at call time) number of fields from > a postgres database (only 1 record) for a given request.? My thought is that > I could build a dictionary in the form of a string, return the string and > then convert the string value to a dictionary.? I can do that now, but I > have to parse the string and then build the dictionary.? Any thoughts or > help you could provide would be appreciated. The first one can be done with the eval() function, but you want to be REALLY sure that the string is safe. But if you're building the dictionary from a database, it would be far more efficient to build it directly in Python and return it; I'm assuming that you're currently building the string outside of Python, but the easiest solution (in my opinion, based solely on the information given and potentially hopelessly useless to your actual situation) would be to simply return multiple values from postgres and have Python do the parsing and building. Alternatively, if there is a character that you can guarantee does not exist in the content, you could do something like this: mystring = "name=greg#hatsize=7 5/8" dict((field.split('=',1) for field in mystring.split('#'))) I used the hash character as a separator here, but you could just as easily use a non-printing character like \n if you can be sure it never appears in any string value. (It's okay for an equals sign, as long as it's not in the field name.) Hope that's of value! Chris Angelico From tlikonen at iki.fi Sun May 8 12:34:13 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Sun, 08 May 2011 19:34:13 +0300 Subject: Development time vs. runtime performance (was: Fibonacci series recursion error) References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> <87hb9521ci.fsf@ugg.bibliotech.com> <4dc69395$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87fwoprw1m.fsf@mithlond.arda> * 2011-05-08T12:59:02Z * Steven D'Aprano wrote: > On Sun, 08 May 2011 01:44:13 -0400, Robert Brown wrote: >> I don't understand why you place Lisp and Forth in the same category >> as Pascal, C, and Java. Lisp and Forth generally have highly >> interactive development environments, while the other languages >> generally require an edit, compile, run it again debugging cycle. > > Good point. Perhaps I need to rethink where Lisp and Forth sit in the > development vs runtime trade-off continuum. > >> Python requires me to rewrite the slow bits of my program in C to get >> good performance. > > Python doesn't require you to re-write anything in C. If you want to > make a different trade-off (faster runtime, slower development time) > then you use a language that has made the appropriate trade-off. I believe that Robert Brown wanted to imply that Common Lisp is quite optimal on both sides. It supports dynamic interactive development and yet it has implementations with very efficient compilers. The trade-off is not necessarily between the two. But of course "development time" is a nicely vague concept. Depending on the argument it can include just the features of language and implementation. Other times it could include all the available resources such as documentation, library archives and community mailing lists. All these can reduce development time. From benjamin.kaplan at case.edu Sun May 8 12:43:59 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 May 2011 09:43:59 -0700 Subject: Dictionary from String? In-Reply-To: References: Message-ID: On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom wrote: > Is it possible to create a dictionary from a string value?? Something along > these lines (but that works): > >>>> mystring = "{'name':'greg','hatsize':'7 5/8'}" >>>> mystring > "{'name':'greg','hatsize':'7 5/8'}" >>>> dict(mystring) > Traceback (most recent call last): > ? File "", line 1, in > ValueError: dictionary update sequence element #0 has length 1; 2 is > required >>>> > > I would like to return an undetermined (at call time) number of fields from > a postgres database (only 1 record) for a given request.? My thought is that > I could build a dictionary in the form of a string, return the string and > then convert the string value to a dictionary.? I can do that now, but I > have to parse the string and then build the dictionary.? Any thoughts or > help you could provide would be appreciated. > > --greg building the dictionary as a string seems like a hacky thing to do and you might want to reevaluate your methods. But if everything in the dict is a literal, you can do ast.literal_eval. > > -- > http://mail.python.org/mailman/listinfo/python-list > > From drsalists at gmail.com Sun May 8 15:00:22 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 8 May 2011 12:00:22 -0700 Subject: Dictionary from String? In-Reply-To: References: Message-ID: On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom wrote: > Is it possible to create a dictionary from a string value? Something along > these lines (but that works): > > >>> mystring = "{'name':'greg','hatsize':'7 5/8'}" > >>> mystring > "{'name':'greg','hatsize':'7 5/8'}" > >>> dict(mystring) > Traceback (most recent call last): > File "", line 1, in > ValueError: dictionary update sequence element #0 has length 1; 2 is > required > >>> > > I would like to return an undetermined (at call time) number of fields from > a postgres database (only 1 record) for a given request. My thought is that > I could build a dictionary in the form of a string, return the string and > then convert the string value to a dictionary. I can do that now, but I > have to parse the string and then build the dictionary. Any thoughts or > help you could provide would be appreciated. > Does this help any? $ /usr/local/cpython-3.2/bin/python Python 3.2 (r32:88445, Mar 4 2011, 22:43:54) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> my_dict = {'name':'greg','hatsize':'7 5/8'} >>> import json >>> my_string = json.dumps(my_dict) >>> my_string '{"hatsize": "7 5/8", "name": "greg"}' >>> my_dict2 = json.loads(my_string) >>> my_dict2 {'hatsize': '7 5/8', 'name': 'greg'} >>> my_dict == my_dict2 True >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From hansmu at xs4all.nl Sun May 8 15:32:06 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 08 May 2011 21:32:06 +0200 Subject: dictionary size changed during iteration In-Reply-To: References: <4DAED72B.2030400@shopzeus.com> <7xd3jukyn9.fsf@ruckus.brouhaha.com> Message-ID: <4dc6f077$0$41117$e4fe514c@news.xs4all.nl> On 08/05/2011 00:12, Roy Smith wrote: > In article<7xd3jukyn9.fsf at ruckus.brouhaha.com>, > Paul Rubin wrote: > >> Roy Smith writes: >>> changes = [ ] >>> for key in d.iterkeys(): >>> if is_bad(key): >>> changes.append(key) >> >> changes = list(k for k in d if is_bad(k)) >> >> is a little bit more direct. > > This is true. I still file list comprehensions under "new fangled > toys". While I use them, and appreciate their value, I admit they're > not always the first thing that comes to my mind. > > OBTW, > >> changes = [k for k in d if is_bad(k)] > > is even more direct :-) How about: changes = filter(is_bad, d) Or would that be too compact? -- HansM From gslindstrom at gmail.com Sun May 8 15:39:53 2011 From: gslindstrom at gmail.com (gslindstrom at gmail.com) Date: Sun, 08 May 2011 19:39:53 +0000 Subject: Dictionary from String? In-Reply-To: Message-ID: <0016363b796e0a697004a2c8e313@google.com> On May 8, 2011 2:00pm, Dan Stromberg wrote: > On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom gslindstrom at gmail.com> > wrote: > Is it possible to create a dictionary from a string value? Something > along these lines (but that works): > >>> mystring = "{'name':'greg','hatsize':'7 5/8'}" > >>> mystring > "{'name':'greg','hatsize':'7 5/8'}" > >>> dict(mystring) > Traceback (most recent call last): > File "", line 1, in > ValueError: dictionary update sequence element #0 has length 1; 2 is > required Yes. It works like a champ. Thanks! --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Sun May 8 15:42:23 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 08 May 2011 12:42:23 -0700 Subject: dictionary size changed during iteration References: <4DAED72B.2030400@shopzeus.com> <7xd3jukyn9.fsf@ruckus.brouhaha.com> <4dc6f077$0$41117$e4fe514c@news.xs4all.nl> Message-ID: <7xhb952d40.fsf@ruckus.brouhaha.com> Hans Mulder writes: > How about: > changes = filter(is_bad, d) > Or would that be too compact? I thought of writing something like that but filter in python 3 creates an iterator that would have the same issue of walking the dictionary while the dictionary is mutating. changes = list(filter(is_bad, d)) should work. From tjreedy at udel.edu Sun May 8 18:41:20 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 08 May 2011 18:41:20 -0400 Subject: checking if a list is empty In-Reply-To: <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/8/2011 10:07 AM, Steven D'Aprano wrote: > Because the test of "is this nothing, or something?" is a common, useful > test: Because inductive algorithms commonly branch on 'input is something' (not done, change args toward 'nothing'and recurse or iterate) versus 'input is nothing (done, return base expression). > 0 (nothing) vs 1, 2, 3, ... (something) > empty list versus non-empty list > empty dict versus non-empty dict > empty set versus non-empty set > empty string versus non-empty string and non-inductive algorithms also branch on the same question. > no search results returned versus some search results returned > no network connection available versus some network connection available > no food in the cupboard versus food in the cupboard > > This is a fundamental distinction which is very useful in practice. Definitely. Python commonly hides the distinction inside of iterators called by for statememts, but StopIteration is understood as 'collection is empty'. An I suspect something vs. nothing is also the most common overt condition in if and while statements. -- Terry Jan Reedy From tjreedy at udel.edu Sun May 8 19:29:50 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 08 May 2011 19:29:50 -0400 Subject: scipy In-Reply-To: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> Message-ID: On 5/8/2011 6:44 AM, pb wrote: > Hi, > I', having trouble with scipy. If you do not get an answer here, try the scipy list where scipy experts hang out. You might also try searching the archives of that list or the scipy bug tracker. -- Terry Jan Reedy From drsalists at gmail.com Sun May 8 19:36:11 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 8 May 2011 16:36:11 -0700 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 8, 2011 at 3:41 PM, Terry Reedy wrote: > On 5/8/2011 10:07 AM, Steven D'Aprano wrote: > > Because the test of "is this nothing, or something?" is a common, useful >> test: >> > > Because inductive algorithms commonly branch on 'input is something' (not > done, change args toward 'nothing'and recurse or iterate) versus 'input is > nothing (done, return base expression). > Just what is an inductive algorithm? I'm familiar with inductive reasoning and inductive proofs, but there doesn't seem to be much on the 'net defining inductive algorithms. There are some papers that reference the topic, but few seem to spend much time on defining it. They seem to have to do with A.I. knowledge acquisition - perhaps it's an algorithm that reasons from a bunch of factlets to create a general rule? -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sun May 8 20:52:27 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 09 May 2011 12:52:27 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92os6dF5jbU1@mid.individual.net> Steven D'Aprano wrote: > Since you haven't explained what you think is happening, I can only > guess. Let me save you from guessing. I'm thinking of a piece of paper with a little box on it and the name 'a' written beside it. There is an arrow from that box to a bigger box. +-------------+ +---+ | | a | --+---------------->| | +---+ | | +-------------+ There is another little box labelled 'b'. After executing 'a = b', both little boxes have arrows pointing to the same big box. +-------------+ +---+ | | a | --+---------------->| | +---+ | | +-------------+ ^ +---+ | b | --+-----------------------| +---+ In this model, a "reference" is an arrow. Manipulating references consists of rubbing out the arrows and redrawing them differently. Also in this model, a "variable" is a little box. It's *not* the same thing as a name; a name is a label for a variable, not the variable itself. It seems that you would prefer to eliminate the little boxes and arrows and write the names directly beside the objects: +-------------+ a | | | | b | | +-------------+ +-------------+ c | | | | | | +-------------+ But what would you do about lists? With little boxes and arrows, you can draw a diagram like this: +---+ +---+ a | --+----->| | +-------------+ +---+ +---+ | | | --+----->| | +---+ | | | | +-------------+ +---+ (Here, the list is represented as a collection of variables. That's why variables and names are not the same thing -- the elements of the list don't have textual names.) But without any little boxes or arrows, you can't represent the list itself as a coherent object. You would have to go around and label various objects with 'a[0]', 'a[1]', etc. +-------------+ a[0] | | | | | | +-------------+ +-------------+ a[1] | | | | | | +-------------+ This is not very satisfactory. If the binding of 'a' changes, you have to hunt for all your a[i] labels, rub them out and rewrite them next to different objects. It's hardly conducive to imparting a clear understanding of what is going on, whereas the boxes-and-arrows model makes it instantly obvious. There is a half-way position, where we use boxes to represent list items, but for bare names we just draw the arrow coming directly out of the name: +---+ a --------->| | +-------------+ +---+ | | | --+----->| | +---+ | | | | +-------------+ +---+ But this is really just a minor variation. It can be a useful shorthand, but it has the drawback of making it seem as though the binding of a bare name is somehow different from the binding of a list element, when it isn't really. Finally, there's another benefit of considering a reference to be a distinct entity in the data model. If you think of the little boxes as being of a fixed size, just big enough to hold a reference, then it's obvious that you can only bind it to *one* object at a time. Otherwise it might appear that you could draw more than one arrow coming out of a name, or write the same name next to more than one object. It seems to me that the boxes-and-arrows model, or something isomorphic to it, is the most abstract model you can make of Python that captures everything necessary to reason about it both easily and correctly. -- Greg From qwsxza147 at 163.com Sun May 8 21:04:38 2011 From: qwsxza147 at 163.com (qw) Date: Sun, 8 May 2011 18:04:38 -0700 (PDT) Subject: payment wholesale SHOES(UGG BOOTS, Timberland boots ,Munich www dot 51-wholesale dot com Message-ID: <2e156db0-4306-4302-9f35-bf75f9860976@q12g2000prb.googlegroups.com> payment wholesale SHOES(UGG BOOTS, Timberland boots ,Munich shoes,NIKE,ADIDAS,LV,GUCCI,CHANEL,PRADA,POLO,D&G,DIOR AND SO ON) www dot 51-wholesale dot com From rosuav at gmail.com Sun May 8 22:49:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 May 2011 12:49:01 +1000 Subject: Development time vs. runtime performance (was: Fibonacci series recursion error) In-Reply-To: <87fwoprw1m.fsf@mithlond.arda> References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> <87hb9521ci.fsf@ugg.bibliotech.com> <4dc69395$0$29991$c3e8da3$5496439d@news.astraweb.com> <87fwoprw1m.fsf@mithlond.arda> Message-ID: On Mon, May 9, 2011 at 2:34 AM, Teemu Likonen wrote: > But of course "development time" is a nicely vague concept. Depending on > the argument it can include just the features of language and > implementation. Other times it could include all the available resources > such as documentation, library archives and community mailing lists. All > these can reduce development time. > And it also includes a developer's personal experience level. A good programmer will have a mental "algorithmic library" if you like; effectively, it's a gigantic hash table of "if I need to do this, I can do it this way". A mediocre programmer will both take longer and produce less efficient code than an awesome programmer. This is primarily not a language feature, but a language that usually has one obvious way to do things will likely be easier to grok than a language that has myriad "gotchas" to work around. Chris Angelico From robert.brown at gmail.com Sun May 8 23:01:18 2011 From: robert.brown at gmail.com (Robert Brown) Date: Sun, 08 May 2011 23:01:18 -0400 Subject: Development time vs. runtime performance (was: Fibonacci series recursion error) References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dbedec0$0$29991$c3e8da3$5496439d@news.astraweb.com> <38f398-14h.ln1@svn.schaathun.net> <4dbf4a99$0$29991$c3e8da3$5496439d@news.astraweb.com> <87hb9521ci.fsf@ugg.bibliotech.com> <4dc69395$0$29991$c3e8da3$5496439d@news.astraweb.com> <87fwoprw1m.fsf@mithlond.arda> Message-ID: <8739ko7f29.fsf@ugg.bibliotech.com> Teemu Likonen writes: > * 2011-05-08T12:59:02Z * Steven D'Aprano wrote: > >> On Sun, 08 May 2011 01:44:13 -0400, Robert Brown wrote: >>> Python requires me to rewrite the slow bits of my program in C to get >>> good performance. >> >> Python doesn't require you to re-write anything in C. If you want to >> make a different trade-off (faster runtime, slower development time) >> then you use a language that has made the appropriate trade-off. > > I believe that Robert Brown wanted to imply that Common Lisp is quite > optimal on both sides. It supports dynamic interactive development and > yet it has implementations with very efficient compilers. The trade-off > is not necessarily between the two. Yes, exactly. Sometimes I don't know in advance which parts of my Python program will run too slowly or take too much memory. I only find out after the code is written, when it fails to run fast enough or doesn't fit in my computer's 32-bit address space. Then the slow parts get recoded in C. Common Lisp supports a larger performance range. A developer can write slow code quickly or faster code by giving the compiler more information, which requires more developer time. > But of course "development time" is a nicely vague concept. Depending on > the argument it can include just the features of language and > implementation. Other times it could include all the available resources > such as documentation, library archives and community mailing lists. All > these can reduce development time. This is definitely true. The total time to complete any task always depends on tons of factors outside of the programming language. The ecosystem is important ... How much code can I avoid writing myself? bob From chris_roysmith.nothere at internode.on.net Sun May 8 23:15:51 2011 From: chris_roysmith.nothere at internode.on.net (Chris Roy-Smith) Date: 09 May 2011 03:15:51 GMT Subject: How to access elemenst in a list of lists? Message-ID: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Just learning python. I can see that I can address an individual element of a list of lists by doing something like: row = list[5] element = row[3] But is there a way to directly address an entry in a single statement? Thanks for any help. Regards Chris Roy-Smith From rosuav at gmail.com Sun May 8 23:23:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 May 2011 13:23:38 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 9, 2011 at 1:15 PM, Chris Roy-Smith wrote: > Just learning python. > I can see that I can address an individual element of a list of lists by > doing something like: > row = list[5] > element = row[3] > > But is there a way to directly address an entry in a single statement? Yep! element = list[5][3] Everything's an expression, there's nothing special about something that's stored in a variable. You can even use square brackets after a function call that returns a list (which is very useful at times). Chris Angelico From prologic at shortcircuit.net.au Sun May 8 23:31:30 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 9 May 2011 13:31:30 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 9, 2011 at 1:23 PM, Chris Angelico wrote: >> Just learning python. >> I can see that I can address an individual element of a list of lists by >> doing something like: >> row = list[5] >> element = row[3] This is the correct approach. Here's an interactive example (tested): $ python Python 2.7.1 (r271:86832, Feb 8 2011, 10:07:16) [GCC 4.5.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> grid = [[" " for x in range(5)] for y in range(5)] >>> from pprint import pprint >>> pprint(grid) [[' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ']] >>> grid[2][2] = "X" >>> pprint(grid) [[' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', 'X', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ']] >>> cheers James -- -- James Mills -- -- "Problems are solved by method" From torriem at gmail.com Sun May 8 23:31:35 2011 From: torriem at gmail.com (Michael Torrie) Date: Sun, 08 May 2011 21:31:35 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DC76017.7010705@gmail.com> On 05/08/2011 05:36 PM, Dan Stromberg wrote: > Just what is an inductive algorithm? >From what I can remember, it's just an implementation of a proof essentially. Any algorithm that can be inductively proven can be implemented with recursion and specific base cases. In other words you program just like you'd do the proof. First you deal with the base cases and then you can call yourself for F(n) and F(n-1). The inductive proof provides the pattern for the code. From harrismh777 at charter.net Sun May 8 23:33:11 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 08 May 2011 22:33:11 -0500 Subject: checking if a list is empty In-Reply-To: <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> which is irony extreme since 'not' is typically considered a logical >> > operator. > Because "not" is typically used as a logical operator. > > In English, it negates a word or statement: > > "the cat is not on the mat" --> "the cat is on the mat" is false. Your pedantic bogus cat analogy talks past my point entirely, as well as making you look silly... if you would stop being pedantic long enough to think about what I'm saying you might come to some understanding... ... yes, 'not' is a logical negation. Why would you waste time with a pedantic explanation of 'not' ? Wait--- its a rhetorical question... Why should the negation of a list imply that the list empty? ... nor any other abstract condition which is not well suited to 'not' ? (forget python for a moment... then move on to my argument...) What made the python development team (or individual) decide that the logical construct 'not list' would return True if the list is empty? To say that "This is the way we do it in Python because Python does it this way"--- goes beyond pedantic becoming circular and redundant. On the other hand, if you were to tell me *why* you think that the logical construct 'not list' should be logically True when the list is empty--- when clearly negating a list would not necessarily mean to make the list empty (including destroying it)... then you might be seeing my point. Here's the bottom line you missed... ... although syntactically correct, the following test is not a logical construct that makes sense (except for the syntactically initiated): if not list <===== this makes no logical sense... ... to test for an empty list . . . ... although, it is legal syntax. :-} I know that is the way Python does it... I've been coding it that way for a long time... but that doesn't answer my concern.... To say this another way, IMHO, if not list ... should return True only if 'list' is bound to NULL, or if the name 'list' would throw a name exception... ... and, Python should have an explicit way of testing for an empty list that is clear, concise, and easy to understand even for the relatively new Python programmer. This is not intended to generate counter argument, its just my feedback on a language construct that I find to be inconsistent logically. ... Please, no pedantic discourse explaining why I'm wrong... just put in into a PEP and move on. :) kind regards, m harris From harrismh777 at charter.net Sun May 8 23:56:02 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 08 May 2011 22:56:02 -0500 Subject: checking if a list is empty In-Reply-To: <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> Python is the new kid on the block, > Nonsense. Python is 20 years old (1991), which makes it older than: > > Java, PHP, Ruby (1995) > Javascript (1996) > C# (2000) > Visual Basic .Net (2001) Python is the new kid on the block. ... not chronologically perhaps, but measured in terms of acceptance and widespread use it is only really now coming into its own. It usually takes an advance in technology about 20 - 25 years to catch on... and Python has finally arrived IMHO. As an example of this... in many default setups in linux distros today Python is now the default 'Programming' environment. This was not true in 1991, nor was it true in 2001... in fact, this has not been true until the past couple of years. Python is catching on in the community at large... not just specialized development shops. As I've given my opinion before on this list, Python is finally becoming the New BASIC for 'people'. Python is also the new kid on the block in educational settings. Haskell and Erlang have dominated for some time now (in fact, many colleges and universities have focused beginning classes on pure functional programming)... and before that Pascal and Lisp... and in limited ways C or C++ ./ Python is moving into that arena lately. For me personally, the environment provided by TCL/Tk was the way for many years... TCL was the glue, Tk was the graphics, and 'C' was the engine (it all works together seamlessly with great performance and minimal lines of coding). Python takes it up a notch; big time. Because, as you've pointed out, less has to be written in 'C'. Almost all of the app can be written in Python, with only one (or three) mods written in 'C'... frankly, for most scripting, the whole thing can be written in Python. But *this* is a relatively *new* discovery for much of the community at large. (I'm not talking here about Google, nor YouTube). Linux is in this same boat... Linux is twenty years old; however, Linux has not enjoyed wide-spread use on the Desktop (until this year, and part of last) and has only enjoyed wide-spread use on servers over the past ten years. Linux is now coming into its own, and when everything is said and done and all the dust settles history is going to find Windows as a minor footnote in personal computing (I'm talking 100 years from now). Linux is the new kid on the block, twenty years old and kicking it... Python is the new kid on the block... twenty years old and kicking it.... many of us are catching up with the new trend; however, we will be evaluating the new trends through historic filters. This cannot be avoided--- for linux, nor for python. kind regards, m harris From i.m.laurent at gmail.com Mon May 9 00:31:44 2011 From: i.m.laurent at gmail.com (Mali Laurent) Date: Sun, 8 May 2011 21:31:44 -0700 (PDT) Subject: Python IDE/text-editor References: Message-ID: <0818ae3c-b55a-4a06-9472-0e5530c8654f@p6g2000vbn.googlegroups.com> On Apr 16, 5:20?am, Alec Taylor wrote: > Good Afternoon, > > I'm looking for an IDE which offers syntax-highlighting, > code-completion, tabs, an embedded interpreter and which is portable > (for running from USB on Windows). > > Here's a mockup of the app I'm looking for:http://i52.tinypic.com/2uojswz.png > > Which would you recommend? > > Thanks in advance for any suggestions, What about geany? I mostly use that. And sometimes eclipse with python support. From ian.g.kelly at gmail.com Mon May 9 00:34:04 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 8 May 2011 22:34:04 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 8, 2011 at 9:33 PM, harrismh777 wrote: > ? Why should the negation of a list imply that the list empty? ?... nor any > other abstract condition which is not well suited to 'not' ? (forget python > for a moment... then move on to my argument...) > > ? What made the python development team (or individual) decide that the > logical construct ? 'not list' ? would return True if the list is empty? > To say that "This is the way we do it in Python because Python does it this > way"--- ?goes beyond pedantic becoming circular and redundant. > > ? On the other hand, if you were to tell me *why* you think that the logical > construct 'not list' should be logically True when the list is empty--- when > clearly negating a list would not necessarily mean to make the list empty > (including destroying it)... then you might be seeing my point. "bool(list)" describes whether the list contains something. "Not" being a logical operator, it stands to reason that "not list" should mean the same thing as "not bool(list)". Anything else would be surprising and pointlessly convoluted. If "not list" bothers you, then I would suggest that your problem is actually with "bool(list)". > ? ? ? ?... ?should return True only if 'list' is bound to NULL, or if the > name 'list' would throw a name exception... Why? Should "not False" return True only if "False" is bound to NULL (whatever you mean by that), or if the name "False" would throw a name exception? > ? ? ? ?... ?and, Python should have an explicit way of testing for an empty > list that is clear, concise, and easy to understand even for the relatively > new Python programmer. ?This is not intended to generate counter argument, > its just my feedback on a language construct that I find to be inconsistent > logically. ... Please, no pedantic discourse explaining why I'm wrong... > just put in into a PEP and move on. ?:) It does. "if len(list) == 0" From chris_roysmith at internode.on.net Mon May 9 00:40:55 2011 From: chris_roysmith at internode.on.net (Chris Roy-Smith) Date: Mon, 09 May 2011 14:40:55 +1000 Subject: How to access elements in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc77057$0$29999$c3e8da3$5496439d@news.astraweb.com> On 09/05/11 13:31, James Mills wrote: > On Mon, May 9, 2011 at 1:23 PM, Chris Angelico wrote: >>> Just learning python. >>> I can see that I can address an individual element of a list of lists by >>> doing something like: >>> row = list[5] >>> element = row[3] > > This is the correct approach. > > Here's an interactive example (tested): > > $ python > Python 2.7.1 (r271:86832, Feb 8 2011, 10:07:16) > [GCC 4.5.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> grid = [[" " for x in range(5)] for y in range(5)] >>>> from pprint import pprint >>>> pprint(grid) > [[' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' ']] >>>> grid[2][2] = "X" >>>> pprint(grid) > [[' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' '], > [' ', ' ', 'X', ' ', ' '], > [' ', ' ', ' ', ' ', ' '], > [' ', ' ', ' ', ' ', ' ']] >>>> > > cheers > James > Thanks, that has my understanding problem fixed! And answers what would probably be my next question. Regards Chris Roy-Smith From prologic at shortcircuit.net.au Mon May 9 00:46:45 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 9 May 2011 14:46:45 +1000 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 9, 2011 at 2:34 PM, Ian Kelly wrote: > "bool(list)" describes whether the list contains something. ?"Not" > being a logical operator, it stands to reason that "not list" should > mean the same thing as "not bool(list)". ?Anything else would be > surprising and pointlessly convoluted. ?If "not list" bothers you, > then I would suggest that your problem is actually with "bool(list)". I concur! +1 >> ? ? ? ?... ?should return True only if 'list' is bound to NULL, or if the >> name 'list' would throw a name exception... [...] >> ? ? ? ?... ?and, Python should have an explicit way of testing for an empty >> list that is clear, concise, and easy to understand even for the relatively >> new Python programmer. ?This is not intended to generate counter argument, >> its just my feedback on a language construct that I find to be inconsistent >> logically. ... Please, no pedantic discourse explaining why I'm wrong... >> just put in into a PEP and move on. ?:) > > It does. ?"if len(list) == 0" Again +1 on the if len(list) == 0: Now... One thing that really concerns me about the Python community as a whole is the no. of varying opinions of "correct" ways of doing things and the distaste for a lot of things (which in Python are just obvious). If you are an opinionated individuals and disagree with the suggestion (even if it is "right"), perhaps keep that to yourself. if not my_list: is a perfectly valid and fine idiom to use in Python. If you prefer some other way, that's fine. Quite frankly I'm sick of seeing posts that argue for the sake of arguing. cheers James -- -- James Mills -- -- "Problems are solved by method" From wuwei23 at gmail.com Mon May 9 01:47:04 2011 From: wuwei23 at gmail.com (alex23) Date: Sun, 8 May 2011 22:47:04 -0700 (PDT) Subject: string formatting References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9ea3dc0e-06ba-4391-8e6a-1fdc3072ee10@35g2000prp.googlegroups.com> harrismh777 wrote: > [...] because *any* time or *most* types > can be substituted and the 'polymorphism' of Python kicks in allowing > for that [...] The same benefit one might get from using the idiomatic 'if not list:'? ;) From nicogrubert at yahoo.de Mon May 9 02:22:29 2011 From: nicogrubert at yahoo.de (Nico Grubert) Date: Mon, 09 May 2011 08:22:29 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: References: Message-ID: <4DC78825.4030905@yahoo.de> > I had this happening to me as well someday. > I recall that first installing it (python setup.py install), and then > rerunning selftest, solved that error. I tried that as well. Here is the summary of the install process: build/temp.linux-x86_64-2.4/libImaging/ZipEncode.o -L/usr/local/lib -L/usr/lib -ljpeg -lz -o build/lib.linux-x86_64-2.4/_imaging.so /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc building '_imagingft' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/freetype2 -IlibImaging -I/usr/local/include -I/usr/include -I/usr/local/include/python2.4 -c _imagingft.c -o build/temp.linux-x86_64-2.4/_imagingft.o gcc -pthread -shared build/temp.linux-x86_64-2.4/_imagingft.o -L/usr/local/lib -L/usr/lib -lfreetype -o build/lib.linux-x86_64-2.4/_imagingft.so /usr/bin/ld: skipping incompatible /usr/lib/libfreetype.so when searching for -lfreetype /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc building '_imagingmath' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/freetype2 -IlibImaging -I/usr/local/include -I/usr/include -I/usr/local/include/python2.4 -c _imagingmath.c -o build/temp.linux-x86_64-2.4/_imagingmath.o gcc -pthread -shared build/temp.linux-x86_64-2.4/_imagingmath.o -L/usr/local/lib -L/usr/lib -o build/lib.linux-x86_64-2.4/_imagingmath.so /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc -------------------------------------------------------------------- PIL 1.1.7 SETUP SUMMARY -------------------------------------------------------------------- version 1.1.7 platform linux2 2.4.6 (#1, Mar 16 2011, 11:33:33) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] -------------------------------------------------------------------- *** TKINTER support not available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available -------------------------------------------------------------------- To add a missing option, make sure you have the required library, and set the corresponding ROOT variable in the setup.py script. To check the build, run the selftest.py script. running build_scripts creating build/scripts-2.4 copying Scripts/pilfont.py -> build/scripts-2.4 copying and adjusting Scripts/pilconvert.py -> build/scripts-2.4 copying and adjusting Scripts/pilfile.py -> build/scripts-2.4 copying and adjusting Scripts/pilprint.py -> build/scripts-2.4 copying and adjusting Scripts/pildriver.py -> build/scripts-2.4 changing mode of build/scripts-2.4/pilfont.py from 644 to 755 changing mode of build/scripts-2.4/pilconvert.py from 644 to 755 changing mode of build/scripts-2.4/pilfile.py from 644 to 755 changing mode of build/scripts-2.4/pilprint.py from 644 to 755 changing mode of build/scripts-2.4/pildriver.py from 644 to 755 running install_lib copying build/lib.linux-x86_64-2.4/_imagingft.so -> /usr/local/lib/python2.4/site-packages/PIL copying build/lib.linux-x86_64-2.4/_imagingmath.so -> /usr/local/lib/python2.4/site-packages/PIL copying build/lib.linux-x86_64-2.4/_imaging.so -> /usr/local/lib/python2.4/site-packages/PIL running install_scripts copying build/scripts-2.4/pilconvert.py -> /usr/local/bin copying build/scripts-2.4/pilfile.py -> /usr/local/bin copying build/scripts-2.4/pilprint.py -> /usr/local/bin copying build/scripts-2.4/pildriver.py -> /usr/local/bin changing mode of /usr/local/bin/pilfont.py to 755 changing mode of /usr/local/bin/pilconvert.py to 755 changing mode of /usr/local/bin/pilfile.py to 755 changing mode of /usr/local/bin/pilprint.py to 755 changing mode of /usr/local/bin/pildriver.py to 755 creating /usr/local/lib/python2.4/site-packages/PIL.pth $ python selftest.py *** The _imaging C module is not installed Regards Nico From hg at schaathun.net Mon May 9 02:23:40 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 9 May 2011 07:23:40 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> Message-ID: On Sat, 07 May 2011 21:21:45 +1200, Gregory Ewing wrote: : You can manipulate them just fine by moving them : from one place to another: : : a = b : : You can use them to get at stuff they refer to: : : a = b.c : a[:] = b[:] Surely you can refer to the objects, but you cannot refer to the reference. : You can compare them: : : if a is b: : ... This could be implemented as pointer comparison, but it is not defined as such and there is no requirement that it be. : That's about all you can do with pointers in Pascal, : and I've never heard anyone argue that Pascal pointers : are any more or less abstract than any other piece of : data in that language. In Pascal a pointer is a distinct data type, and you can have variables of a given type or of type pointer to that given type. That makes the pointer a concrete concept defined by the languagedefined by the language. -- :-- Hans Georg From 4aedc00f81024 at poster.grepler.com Mon May 9 04:25:11 2011 From: 4aedc00f81024 at poster.grepler.com (Antonio CHESSA) Date: 09 May 2011 08:25:11 GMT Subject: How to access elemenst in a list of lists? In-Reply-To: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: >Just learning python. >I can see that I can address an individual element of a list of lists >by >doing something like: >row = list[5] >element = row[3] > >But is there a way to directly address an entry in a single statement? >Thanks for any help. >Regards >Chris Roy-Smith suppose you have a list like this: apple = [["a","b","c"],[1,2,3,4,5,6],["antony","max","sandra","sebastian"]] apple[0] = ["a","b","c"] apple[1] = [1,2,3,4,5,6] apple[2] = ["antony","max","sandra","sebastian"] apple[0][1] = "b" apple[2][3] = "sebastian" to view all videos in a loop so you can set: for i in range(len(apple)): print apple[i] for j in range (len(apple[i])): print apple[i][j] in your monitor when you do run this little program, you will see: ["a","b","c"] a b c [1,2,3,4,5,6] 1 2 3 4 5 6 ["antony","max","sandra","sebastian"] antony max sandra sebastian Bay vonkes ---------------------------- http://grepler.com groups From peterthebag at yahoo.com Mon May 9 04:35:11 2011 From: peterthebag at yahoo.com (pb) Date: Mon, 9 May 2011 01:35:11 -0700 (PDT) Subject: scipy References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> Message-ID: <7bee87fe-f157-4001-8901-e67586a999ba@q20g2000vbx.googlegroups.com> On May 9, 12:29?am, Terry Reedy wrote: > On 5/8/2011 6:44 AM, pb wrote: > > > Hi, > > I', having trouble with scipy. > > If you do not get an answer here, try the scipy list where scipy experts > hang out. You might also try searching the archives of that list or the > scipy bug tracker. > > -- > Terry Jan Reedy Hi, the scipy mailing list? Thanks, Peter From jean_paez at hotmail.es Mon May 9 04:56:40 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?RW55R21BIE3hcyBQcm8=?=) Date: Mon, 9 May 2011 03:56:40 -0500 Subject: HELP ME, PLEASE. SCRIP EXPORT TO .TM Message-ID: Good morning Python community, I need help to develop or create a script to export to. tmb but blender, there is to import. tmb in blender (look here: http://www.mediafire.com/?2g20yymmxam) this and I have, but need one to export in a blender. tmb. Windows platform (XP, Windows 7 and Windows Server). Thank you for your attention and your prompt response. Sincerely, Jean Carlos Paez R. I am of Colombia. ____________________________________ Versi?n espa?ol: Buenos d?as comunidad Python, necesito ayuda para desarrollar o crear un script para exportar a .tmb pero en blender, existe el de importar a .tmb en blender (miren aqu?: http://www.mediafire.com/?2g20yymmxam) este ya lo tengo, pero necesito uno que exporte en blender a .tmb. Plataforma windows (xp, windows 7 y windows server). Gracias por su atenci?n prestada y su pronta respuesta. Atentamente, Jean carlos P?ez R. Yo soy de Colombia. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jean_paez at hotmail.es Mon May 9 05:05:06 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?RW55R21BIE3hcyBQcm8=?=) Date: Mon, 9 May 2011 04:05:06 -0500 Subject: FW: AYUDA PORFAVOR. HELP ME, PLEASE. SCRIP EXPORT TO .TM In-Reply-To: References: Message-ID: aYudenme porfavor. Gracias. From: jean_paez at hotmail.es To: python-list at python.org; help at python.org; pycolombia at listas.el-directorio.org Subject: HELP ME, PLEASE. SCRIP EXPORT TO .TM Date: Mon, 9 May 2011 03:56:40 -0500 Good morning Python community, I need help to develop or create a script to export to. tmb but blender, there is to import. tmb in blender (look here: http://www.mediafire.com/?2g20yymmxam) this and I have, but need one to export in a blender. tmb. Windows platform (XP, Windows 7 and Windows Server). Thank you for your attention and your prompt response. Sincerely, Jean Carlos Paez R. I am of Colombia. ____________________________________ Versi?n espa?ol: Buenos d?as comunidad Python, necesito ayuda para desarrollar o crear un script para exportar a .tmb pero en blender, existe el de importar a .tmb en blender (miren aqu?: http://www.mediafire.com/?2g20yymmxam) este ya lo tengo, pero necesito uno que exporte en blender a .tmb. Plataforma windows (xp, windows 7 y windows server). Gracias por su atenci?n prestada y su pronta respuesta. Atentamente, Jean carlos P?ez R. Yo soy de Colombia. -------------- next part -------------- An HTML attachment was scrubbed... URL: From trent at snakebite.org Mon May 9 05:31:07 2011 From: trent at snakebite.org (Trent Nelson) Date: Mon, 9 May 2011 02:31:07 -0700 Subject: Coolest Python recipe of all time In-Reply-To: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: <5E3A89398864414E8EE2CB192E0C965C0A956F2746@EXMBX10.exchhosting.com> > What are your favorites? I think I've posted this before, but I love my 3-lines-if-you-ignore-the-scaffolding language translator. Not because it's clever code -- quite the opposite, the code is dead simple -- but because it encompasses one of the things I love about Python the most: it gets shit done. In [1]: from translate import * In [2]: translate('French', 'The quick brown fox jumped over the lazy dog.') Le renard brun rapide a saut? par-dessus le chien paresseux. In [3]: translate('German', 'The quick brown fox jumped over the lazy dog.') Der schnelle braune Fuchs sprang ?ber den faulen Hund. In [4]: translate('Spanish', 'The quick brown fox jumped over the lazy dog.') El zorro marr?n r?pido salt? sobre el perro perezoso. translate.py: import sys from urllib import urlopen, urlencode from BeautifulSoup import BeautifulSoup url = 'http://babelfish.altavista.com/tr' languages = { 'French' : 'en_fr', 'German' : 'en_de', 'Italian' : 'en_it', 'Spanish' : 'en_es', 'Russian' : 'en_ru', 'Portuguese': 'en_pt', 'Dutch' : 'en_nl', 'Japanese' : 'en_ja', } def translate(lang, text): kwds = { 'trtext' : text, 'lp' : languages[lang]} soup = BeautifulSoup(urlopen(url, urlencode(kwds))) print soup.find('div', style='padding:10px;').string if __name__ == '__main__': translate(sys.argv[1], sys.argv[2]) From lists at cheimes.de Mon May 9 06:28:06 2011 From: lists at cheimes.de (Christian Heimes) Date: Mon, 09 May 2011 12:28:06 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: <4DC78825.4030905@yahoo.de> References: <4DC78825.4030905@yahoo.de> Message-ID: Am 09.05.2011 08:22, schrieb Nico Grubert: > $ python selftest.py > *** The _imaging C module is not installed It works for me after an inplace installation of the C extensions with "python setup.py build_ext -i". With build_ext -i the C extension is installed inside the source tree so selftest can find it. Christian From hg at schaathun.net Mon May 9 06:38:30 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 9 May 2011 11:38:30 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> Message-ID: <6qsk98-em1.ln1@svn.schaathun.net> On Mon, 09 May 2011 12:52:27 +1200, Gregory Ewing wrote: : Let me save you from guessing. I'm thinking of a piece of paper with : a little box on it and the name 'a' written beside it. There is an : arrow from that box to a bigger box. : : +-------------+ : +---+ | | : a | --+---------------->| | : +---+ | | : +-------------+ The flaw of this model, and I am not discounting its merits, just pointing out that it isn't perfect, is that it creates the illusion that references are boxes (objects) just like data objects, leading the reader to think that we could have a reference to a reference. If they are all boxes, by can't we make reference thereto? -- :-- Hans Georg From felipe.vinturini at gmail.com Mon May 9 07:07:14 2011 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Mon, 9 May 2011 08:07:14 -0300 Subject: FW: AYUDA PORFAVOR. HELP ME, PLEASE. SCRIP EXPORT TO .TM In-Reply-To: References: Message-ID: On Mon, May 9, 2011 at 6:05 AM, EnyGmA M?s Pro wrote: > aYudenme porfavor. Gracias. > > ------------------------------ > From: jean_paez at hotmail.es > To: python-list at python.org; help at python.org; > pycolombia at listas.el-directorio.org > Subject: HELP ME, PLEASE. SCRIP EXPORT TO .TM > Date: Mon, 9 May 2011 03:56:40 -0500 > > Good morning Python community, I need help to develop or create a script > to export to. tmb but blender, there is to import. tmb in blender (look > here: http://www.mediafire.com/?2g20yymmxam) this and I have, but need one > to export in a blender. tmb. Windows platform (XP, Windows 7 and Windows > Server). > > Thank you for your attention and your prompt response. > > Sincerely, > > Jean Carlos Paez R. > > I am of Colombia. > > ____________________________________ > > Versi?n espa?ol: > > Buenos d?as comunidad Python, necesito ayuda para desarrollar o crear un > script para exportar a .tmb pero en blender, existe el de importar a .tmb en > blender (miren aqu?: http://www.mediafire.com/?2g20yymmxam) este ya lo > tengo, pero necesito uno que exporte en blender a .tmb. Plataforma windows > (xp, windows 7 y windows server). > > Gracias por su atenci?n prestada y su pronta respuesta. > > Atentamente, > > Jean carlos P?ez R. > > > Yo soy de Colombia. > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, What have you done so far? Please, post your code and traceback. It will be easier to help you... Regards, Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon May 9 07:18:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 May 2011 21:18:29 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <6qsk98-em1.ln1@svn.schaathun.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <6qsk98-em1.ln1@svn.schaathun.net> Message-ID: On Mon, May 9, 2011 at 8:38 PM, Hans Georg Schaathun wrote: > The flaw of this model, and I am not discounting its merits, just > pointing out that it isn't perfect, is that it creates the illusion > that references are boxes (objects) just like data objects, leading > the reader to think that we could have a reference to a reference. > If they are all boxes, by can't we make reference thereto? http://www.xkcd.com/895/ Analogies are like diagrams. Not all of them are perfect or useful. The boxes are different sizes. If you really want them to look different, do one as squares and one as circles, but don't try that in plain text. Chris Angelico From ander2_1434 at hotmail.com Mon May 9 08:13:00 2011 From: ander2_1434 at hotmail.com (ander2_1434 at hotmail.com) Date: Mon, 9 May 2011 05:13:00 -0700 (PDT) Subject: input() or raw_input() in Console module. Message-ID: I'm using Console module (doc: http://effbot.org/zone/console-handbook.htm, like nCurses) on Windows, but I don't know how to call a keyboard input like input() or raw_input(). What to do? From steve+comp.lang.python at pearwood.info Mon May 9 10:29:04 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 May 2011 14:29:04 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> Message-ID: <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 May 2011 12:52:27 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> Since you haven't explained what you think is happening, I can only >> guess. > > Let me save you from guessing. I'm thinking of a piece of paper with a > little box on it and the name 'a' written beside it. There is an arrow > from that box to a bigger box. > > +-------------+ > +---+ | | > a | --+---------------->| | > +---+ | | > +-------------+ > > There is another little box labelled 'b'. After executing 'a = b', both > little boxes have arrows pointing to the same big box. [...] > In this model, a "reference" is an arrow. Manipulating references > consists of rubbing out the arrows and redrawing them differently. All very good, but that's not what takes place at the level of Python code. It's all implementation. I think Hans Georg Schaathun made a good objection to the idea that "Python has references": In Pascal a pointer is a distinct data type, and you can have variables of a given type or of type pointer to that given type. That makes the pointer a concrete concept defined by the language. The same can't be said of "references" in Python. It's not part of Python the language, although it might be part of Python's implementation. > Also > in this model, a "variable" is a little box. It's *not* the same thing > as a name; a name is a label for a variable, not the variable itself. That's essentially the same model used when dealing with pointers. I've used it myself, programming in Pascal. The "little box" named a or b is the pointer variable, and the "big box" is the data that the pointer points to. It's not an awful model for Python: a name binding a = obj is equivalent to sticking a reference (a pointer?) in box a that points to obj. Certainly there are advantages to it. But one problem is, the model is ambiguous with b = a. You've drawn little boxes a and b both pointing to the big box (which I deleted for brevity). But surely, if a = 1234 creates a reference from a to the big box 1234, then b = a should create a reference from b to the box a? +-------------+ +---+ | | a | --+---------------->| | +---+ | | ^ +-------------+ | +-|-+ b | | | +---+ which is the reference (pointer) model as most people would recognise it. That's how it works in C and Pascal (well, at least with the appropriate type declarations). To get b pointing to the big box, you would need an explicit dereference: "b = whatever a points to" rather than "b = a". Of course, both of these concepts are models, which is another word for "lies" *wink*. Your model is closer to what the CPython implementation actually does, using actual C pointers, except of course you do need to dereference the pointers appropriately. One of my objections to it is not that it is wrong (all models are wrong) but that it will mislead some people to reason incorrectly about Python's behaviour, e.g. that b now points to the little box a, and therefore if you change what a points to, b will follow along. The whole "call by reference" thing. I suppose you might argue that you're not responsible for the misunderstandings of blinkered C coders *wink*, and there's something to that. But there's another objection... take, say, the line of Python code: n = len('hello world') I can identify the little box "n", which ends up pointing to the big box holding int 11; another little box "len", which points to a big box holding a function; and a third big box holding the string 'hello world'. But where is its little box? If len were written in pure Python, then *inside* len's namespace there would be a local little box for the argument. I expect that there is an analogous local little box for built-in functions too. But I don't care what happens inside len. What about outside len? Where's the little box pointing to 'hello world'? So it seems your model fails to deal with sufficiently anonymous objects. I say "sufficiently", because of course your model deals fine with objects without names inside, say, lists: the little box there is the list slot rather than a named entry in a namespace. It's not just literals that your model fails to deal with, it's any expression that isn't bound to a little box: n = len('hello world') + func(y) func(y) produces a new object, a big box. Where is the little box pointing to it? If we drop down an abstraction layer, we can see where objects live: >>> code = compile("n = len('hello world') + func(y)", '', 'single') >>> import dis >>> dis.dis(code) 1 0 LOAD_NAME 0 (len) 3 LOAD_CONST 0 ('hello world') 6 CALL_FUNCTION 1 9 LOAD_NAME 1 (func) 12 LOAD_NAME 2 (y) 15 CALL_FUNCTION 1 18 BINARY_ADD 19 STORE_NAME 3 (n) 22 LOAD_CONST 1 (None) 25 RETURN_VALUE Both the call to len and the call to func push their results onto the stack. There's no little box pointing to the result. There's no little box pointing to len, or y, or any of the others: there are just names and abstract operations LOAD_NAME and friends. Again, this is just an abstraction layer. Python objects can be huge, potentially hundreds of megabytes or gigabytes. No way are they being pushed and popped onto a stack, even if the virtual machine gives the illusion that they are. For practical reasons, there must be some sort of indirection. But that's implementation and not the VM's model. > It seems that you would prefer to eliminate the little boxes and arrows > and write the names directly beside the objects: > > +-------------+ > a | | > | | > b | | > +-------------+ > > +-------------+ > c | | > | | > | | > +-------------+ That's not a bad model. But again, it's incomplete, because it would suggest that the big box should be able to read its own name tags, which of course is impossible in Python. But I suppose one might say, if the tag is on the outside of the object, the object can't use introspection to see it, can it? But note that this is really your model in disguise: if you imagine the name tags are stuck on with a little piece of blutack, and you carefully pull on the name and stretch it away, you get a name sitting over here with a tiny thread of blutack attaching it to the big box over there, just like in your model. I actually prefer to keep the nature of the mapping between name and object abstract: names map to objects. Objects float around in space, wherever the interpreter happens to put them, and you can optionally give them names. Objects are dumb and don't know their own name, but the Python interpreter knows the names. Names are not the only way to ask the interpreter for an object: e.g. you can put them in a list, and ask for them by position. If people then ask, how does the interpreter know the names?, I can add more detail: names are actually strings in a namespace, which is usually nothing more than a dict. Oh, and inside functions, it's a bit more complicated still. And so on. There is a problem with my model of free-floating objects in space: it relies on objects being able to be in two places at once, even *inside* themselves (you can append a list to itself). If you hate that concept, you'll hate my model. But if you're a science fiction fan from way back, then you won't have any problem with the idea that objects can be inside themselves: http://www.youtube.com/watch?v=51JtuEa_OPc Remember: it's just a model, and all models are lies. Abstractions all leak. You can only chose where and how badly they break down. Now, that's a good challenge for your model. Little boxes only point to big boxes. So how do you model cycles, including lists that contain themselves? > But what would you do about lists? With little boxes and arrows, you can > draw a diagram like this: > > +---+ +---+ > a | --+----->| | +-------------+ > +---+ +---+ | | > | --+----->| | > +---+ | | > | | +-------------+ > +---+ > > (Here, the list is represented as a collection of variables. That's why > variables and names are not the same thing -- the elements of the list > don't have textual names.) But that's wrong! Names (little boxes) can't point to *slots in a list*, any more than they can point to other names! This doesn't work: >>> L = [None, 42, None] >>> a = L[0] >>> L[0] = 23 >>> print(a) # This doesn't work! 23 It's a pity that Python doesn't actually have references. Imagine how much time we'd save: all the unproductive time we spend arguing about whether Python has references, we could be fixing bugs caused by the use of references instead... > But without any little boxes or arrows, you can't represent the list > itself as a coherent object. You would have to go around and label > various objects with 'a[0]', 'a[1]', etc. > > +-------------+ > a[0] | | > | | > | | > +-------------+ > > +-------------+ > a[1] | | > | | > | | > +-------------+ > > This is not very satisfactory. If the binding of 'a' changes, you have > to hunt for all your a[i] labels, rub them out and rewrite them next to > different objects. It's hardly conducive to imparting a clear > understanding of what is going on, whereas the boxes-and-arrows model > makes it instantly obvious. But I wouldn't do it like that. I'd do it like this: 0 1 2 3 4 +--------+--------+--------+--------+--------+ a | | | | | | | | | | | | | | | | | | +--------+--------+--------+--------+--------+ which conveniently happens to be the way Python lists actually are set up. More or less. [...] > Finally, there's another benefit of considering a reference to be a > distinct entity in the data model. If you think of the little boxes as > being of a fixed size, just big enough to hold a reference, then it's > obvious that you can only bind it to *one* object at a time. Otherwise > it might appear that you could draw more than one arrow coming out of a > name, or write the same name next to more than one object. But that's pretty much an arbitrary restriction. Why are the boxes so small? Just because. Why can't you carefully tease the thread of blutack apart, into a bifurcated Y shaped thread? Just because. If objects can be in two places at once, why can't names? Just because. (Actually, because Guido decrees it so. Also because it would be kinda crazy to do otherwise. I can't think of any language that has a many:many mapping between names and values.) -- Steven From robert.kern at gmail.com Mon May 9 10:34:12 2011 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 09 May 2011 09:34:12 -0500 Subject: scipy In-Reply-To: <7bee87fe-f157-4001-8901-e67586a999ba@q20g2000vbx.googlegroups.com> References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> <7bee87fe-f157-4001-8901-e67586a999ba@q20g2000vbx.googlegroups.com> Message-ID: On 5/9/11 3:35 AM, pb wrote: > On May 9, 12:29 am, Terry Reedy wrote: >> On 5/8/2011 6:44 AM, pb wrote: >> >>> Hi, >>> I', having trouble with scipy. >> >> If you do not get an answer here, try the scipy list where scipy experts >> hang out. You might also try searching the archives of that list or the >> scipy bug tracker. >> >> -- >> Terry Jan Reedy > > Hi, > the scipy mailing list? http://www.scipy.org/Mailing_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 mail at timgolden.me.uk Mon May 9 10:41:11 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 09 May 2011 15:41:11 +0100 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DC7FD07.6060402@timgolden.me.uk> On 09/05/2011 15:29, Steven D'Aprano wrote: [... snippage galore ...] Slightly abstract comment: while I don't usually get much enjoyment out of the regular "Python is call-by-value; no it isn't; yes it is" debates, I always enjoy reading Steven D'Aprano's responses. Thanks, Mr D'A. :) TJG From nobody at nowhere.net.no Mon May 9 10:53:44 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 09 May 2011 22:53:44 +0800 Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> Message-ID: Vinay Sajip wrote: > logging.basicConfig(level=logging.DEBUG, format='%(message)s') logging.basicConfig(format='%(message)s', level=logging.DEBUG) I formulated in the reverse order of arguments, may that cause an unpredicted result? The other points became clearer.. Once again Thank You -- goto /dev/null From Dick.Bridges at wdc.com Mon May 9 11:22:42 2011 From: Dick.Bridges at wdc.com (Dick Bridges) Date: Mon, 9 May 2011 08:22:42 -0700 Subject: setuptools for 64-bit 2.7.1 on 64-bit Windows 7? In-Reply-To: References: Message-ID: David, Thanks for the link. I'd scanned but skipped it because it was "third-party". This time I started following some of the links and finally found the link for distutils: http://pypi.python.org/pypi/distribute#installation-instructions. Works like a charm. Thanks for pointing me back to that link - I was clearly too hasty dismissing it during my so-called "due diligence". 8-P Dick Bridges (\(\ Western Digital ?". .. ( . .) The opinions and data in this missive are my own and do not necessarily | ? ? represent Western Digital positions, strategies, or opinions. ? ; c?".UJ" Glenda: http://glenda.cat-v.org/gallery/ > -----Original Message----- > From: David Robinow [mailto:drobinow at gmail.com] > Sent: Friday, May 06, 2011 3:25 PM > To: Dick Bridges > Cc: python-list at python.org > Subject: Re: setuptools for 64-bit 2.7.1 on 64-bit Windows 7? > > On Fri, May 6, 2011 at 1:43 PM, Dick Bridges > wrote: > > Simple question: Is it true that no setuptools (or any other module > > installer) exists for 64-bit python 2.7.1? If there is an installer > that > > works, what terms might I use to Google for information on how to > acquire > > and install it? > Doesn't the installer at > http://www.lfd.uci.edu/~gohlke/pythonlibs/ > work? From chris at simplistix.co.uk Mon May 9 12:22:33 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 09 May 2011 17:22:33 +0100 Subject: Zope with mySQL In-Reply-To: <31499628.post@talk.nabble.com> References: <31499628.post@talk.nabble.com> Message-ID: <4DC814C9.5040301@simplistix.co.uk> Hi Harry, You'd be better off asking this on the zope at zope.org mailing list... cheers, Chris On 28/04/2011 20:19, harryjatt wrote: > > Hi, i am doing web development with Zope. My connected database is mySQL. I > am new to this combination.I have to upload the files to mySQL with > programming in zope and then downloading them via zope.Can you help me in > this regard? I will be very thankfull to you. > Regards, Harry -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From vinay_sajip at yahoo.co.uk Mon May 9 12:34:54 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 9 May 2011 09:34:54 -0700 (PDT) Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> Message-ID: <7508a36a-5d27-49a7-8572-c9bba3d2c61e@h12g2000pro.googlegroups.com> On May 9, 3:53?pm, TheSaint wrote: > Vinay Sajip wrote: > >logging.basicConfig(level=logging.DEBUG, format='%(message)s') > > logging.basicConfig(format='%(message)s', level=logging.DEBUG) > > I formulated in the reverse order of arguments, may that cause an > unpredicted result? No, you can pass keyword arguments in any order - that's what makes them keyword, as opposed to positional, arguments. Regards, Vinay Sajip From ethan at stoneleaf.us Mon May 9 13:15:05 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 09 May 2011 10:15:05 -0700 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DC82119.2020601@stoneleaf.us> Steven D'Aprano wrote: > But that's wrong! Names (little boxes) can't point to *slots in a list*, > any more than they can point to other names! This doesn't work: > > > --> L = [None, 42, None] > --> a = L[0] > --> L[0] = 23 > --> print(a) # This doesn't work! > 23 Minor nitpick -- having a comment saying "this doesn't work" then having output showing that it does is confusing. I had to load up the interpretor to make sure I was confused! ;) ~Ethan~ From mwilson at the-wire.com Mon May 9 13:38:44 2011 From: mwilson at the-wire.com (Mel) Date: Mon, 09 May 2011 13:38:44 -0400 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > It's not an awful model for Python: a name binding a = obj is equivalent > to sticking a reference (a pointer?) in box a that points to obj. > Certainly there are advantages to it. > > But one problem is, the model is ambiguous with b = a. You've drawn > little boxes a and b both pointing to the big box (which I deleted for > brevity). But surely, if a = 1234 creates a reference from a to the big > box 1234, then b = a should create a reference from b to the box a? :) There's a way around that too. Describe literals as "magic names" or "Platonic names" that are bound to objects in ideal space. I actually considered that for a while as a way of explaining to newbs why the characters in a string literal could be different from the characters in the string value. This would probably have troubles of its own; I never took it through the knock-down drag-out disarticulation that would show what the problems were. Mel. From jamfwright at gmail.com Mon May 9 14:10:21 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 14:10:21 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? Message-ID: Hello, I have been using a script on several boxes that have been around for a while, and everything works just fine. I am finding though, that on some new OS installs the script fails with: Traceback (most recent call last): File "render4.py", line 114, in create_report_index(each_item) File "render4.py", line 25, in create_report_index [clean_name, _] = each_value.split('_', 1) ValueError: need more than 1 value to unpack The OS's are various OpenSuse installs from 10.3 to 11.4. It works on all the existing ones, which leads me to believe that I have a package or configuration inconsistency. It should be noted though that I am quite new to python programming and very well could have coded in a non-portable manner and was just lucky to get it working in the first place :) Here is the code snippet that generates the failure ( when you look at this remember that I am a novice :-) ): for each_item in D4: #D4 is a dictionary create_report_index(each_item) def create_report_index(report): #Here we are creating a simple index.html file from data in a text file newfile = open(report + '.html', 'w') #Create the index file using report name for each_value in D4[report]: [clean_name, _] = each_value.split('_', 1) newfile.write('' + clean_name + '
\n') I've tried to match packages from a known working install and even compiled a newer python (one known to work, version 3.1.3 in this particular case). The only discernible difference is that the new OS installs are VM's hosted on VMWare ESX. Using the same ISO I can spin up a VirtualBox VM and the script works just fine. I've tried this with OpenSuse 11.3 and 11.4, once again, using the exact same ISO's to install. Do I have a Python, OS, or package issue? Many thanks, James From peterthebag at yahoo.com Mon May 9 14:13:55 2011 From: peterthebag at yahoo.com (pb) Date: Mon, 9 May 2011 11:13:55 -0700 (PDT) Subject: scipy References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> <7bee87fe-f157-4001-8901-e67586a999ba@q20g2000vbx.googlegroups.com> Message-ID: <6bfdb99c-c8db-4c5c-af2b-35ff88bd94d8@32g2000vbe.googlegroups.com> On May 9, 3:34?pm, Robert Kern wrote: > On 5/9/11 3:35 AM, pb wrote: > > > On May 9, 12:29 am, Terry Reedy ?wrote: > >> On 5/8/2011 6:44 AM, pb wrote: > > >>> Hi, > >>> I', having trouble with scipy. > > >> If you do not get an answer here, try the scipy list where scipy experts > >> hang out. You might also try searching the archives of that list or the > >> scipy bug tracker. > > >> -- > >> Terry Jan Reedy > > > Hi, > > the scipy mailing list? > > http://www.scipy.org/Mailing_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 Thanks, I have tried to register for the mailing lists there, but cannot loggin and have received no "registration comfirmation email" from them. I'd email the list maintainer/admin, but cannot find an email address for them. Peter From irmen.NOSPAM at xs4all.nl Mon May 9 14:16:42 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 09 May 2011 20:16:42 +0200 Subject: PIL: The _imaging C module is not installed In-Reply-To: References: Message-ID: <4dc82f8b$0$32470$e4fe514c@news.xs4all.nl> On 9-5-2011 8:22, Nico Grubert wrote: >> I had this happening to me as well someday. >> I recall that first installing it (python setup.py install), and then >> rerunning selftest, solved that error. > > I tried that as well. > Here is the summary of the install process: > > build/temp.linux-x86_64-2.4/libImaging/ZipEncode.o -L/usr/local/lib -L/usr/lib -ljpeg > -lz -o build/lib.linux-x86_64-2.4/_imaging.so [...] > > $ python selftest.py > *** The _imaging C module is not installed > Don't know why the build seems to fail. PIL installs and works fine on all computers I've installed it on recently... What happens when you just forget about selftest and run python and type import Image? Doesn't the package manager on CentOS offer a python-imaging, python-pil or whatever precompiled and configured package? If not (why not!?) try pip install PIL. Irmen From bob at example.com Mon May 9 14:20:01 2011 From: bob at example.com (Bob Fnord) Date: Mon, 09 May 2011 20:20:01 +0200 Subject: can't get urllib2 or httplib to work with tor & privoxy Message-ID: Here's my python code: import httplib, urllib2 proxy_handler = {'http' : 'localhost:8118', 'https' : 'localhost:8118'} def connect_u2(url = 'http://ipid.shat.net/iponly/'):, proxied = urllib2.ProxyHandler(proxy_handler) opnr = urllib2.build_opener(proxied) opnr.addheaders = [('User-agent', agent)] rsp = opnr.open(url) page = rsp.read() return page def connect_h(url = 'http://ipid.shat.net/iponly/'): cnn = httplib.HTTPConnection('127.0.0.1', 8118) cnn.connect() cnn.request('GET', url) rsp = cnn.getresponse() stderr.write('%u %s\n' % (rsp.status, rsp.reason)) page = rsp.read(500) cnn.close() return page Both methods give me a 503 error, even though this export http_proxy='http://localhost:8118/' lynx -dump 'http://ipid.shat.net/iponly/' works in bash and prints out the IP of a tor exit. What am I doing wrong in python? (I tried both 'localhost:8118' and 'http://localhost:8118/' in the proxy_handler dict.) From ian.g.kelly at gmail.com Mon May 9 14:41:58 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 May 2011 12:41:58 -0600 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: Message-ID: On Mon, May 9, 2011 at 12:10 PM, James Wright wrote: > Hello, > > I have been using a script on several boxes that have been around for > a while, and everything works just fine. ?I am finding though, that on > some new OS installs the script fails with: > > Traceback (most recent call last): > ?File "render4.py", line 114, in > ? ?create_report_index(each_item) > ?File "render4.py", line 25, in create_report_index > ? ?[clean_name, _] = each_value.split('_', 1) > ValueError: need more than 1 value to unpack You should check the value of each_value at the point when the script fails. It sounds like split() is getting passed a string that doesn't contain any '_' characters at all, resulting in a sequence with only one value. Passing 1 as the second argument ensures that there will be at most 1 split, but there may still be fewer. Cheers, Ian From steve+comp.lang.python at pearwood.info Mon May 9 14:43:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 May 2011 18:43:09 GMT Subject: Inconsistency with split() - Script, OS, or Package Problem? References: Message-ID: <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 May 2011 14:10:21 -0400, James Wright wrote: > Hello, > > I have been using a script on several boxes that have been around for a > while, and everything works just fine. I am finding though, that on > some new OS installs the script fails with: > > Traceback (most recent call last): > File "render4.py", line 114, in > create_report_index(each_item) > File "render4.py", line 25, in create_report_index > [clean_name, _] = each_value.split('_', 1) > ValueError: need more than 1 value to unpack It's a data issue, not an OS or package problem. Firstly, you don't have to wrap the left hand side in brackets, this works fine: >>> each_value = "aaa_bbb_ccc" >>> clean_name, _ = each_value.split('_', 1) >>> clean_name 'aaa' However, if your data has no underscore at all: >>> each_value = "aaa*bbb*ccc" >>> clean_name, _ = each_value.split('_', 1) Traceback (most recent call last): File "", line 1, in ValueError: need more than 1 value to unpack So you need to allow for the possibility that there is no underscore. -- Steven From ethan at stoneleaf.us Mon May 9 14:56:13 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 09 May 2011 11:56:13 -0700 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: Message-ID: <4DC838CD.7030404@stoneleaf.us> James Wright wrote: > Hello, Howdy! > def create_report_index(report): #Here we are creating a simple > index.html file from data in a text file > newfile = open(report + '.html', 'w') #Create the index file using > report name > for each_value in D4[report]: > [clean_name, _] = each_value.split('_', 1) > newfile.write('' + clean_name + '
\n') Add the line print("current each_value is: %s" % each_value) just before the line [clean_name, _] = each_value.split('_', 1) I'm guessing you'll see a value with no '_' in it -- at that point you can track down why. ~Ethan~ From jamfwright at gmail.com Mon May 9 15:02:17 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 15:02:17 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: <4DC838CD.7030404@stoneleaf.us> References: <4DC838CD.7030404@stoneleaf.us> Message-ID: Thank you Ethan, This is what I see now: # python render4.py current each_value is: vsr Traceback (most recent call last): File "render4.py", line 115, in create_report_index(each_item) File "render4.py", line 26, in create_report_index [clean_name, _] = each_value.split('_', 1) ValueError: need more than 1 value to unpack # grep -i vsr * # Using the informational line you suggested I see that 'vsr' showing as the current each_value. The string 'vsr' does not exist in my data though. Where could this be coming from? Thanks, James On Mon, May 9, 2011 at 2:56 PM, Ethan Furman wrote: > James Wright wrote: >> >> Hello, > > Howdy! > >> def create_report_index(report): ?#Here we are creating a simple >> index.html file from data in a text file >> ? ?newfile = open(report + '.html', 'w') #Create the index file using >> report name >> ? ?for each_value in D4[report]: >> ? ? ? ?[clean_name, _] = each_value.split('_', 1) >> ? ? ? ?newfile.write('' + clean_name + '
\n') > > Add the line > > ? ?print("current each_value is: %s" % each_value) > > just before the line > > ? ?[clean_name, _] = each_value.split('_', 1) > > > I'm guessing you'll see a value with no '_' in it -- at that point you can > track down why. > > ~Ethan~ > From jamfwright at gmail.com Mon May 9 15:09:32 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 15:09:32 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thank you Steven, I will take your advice :) In this particular case though, I do not think a lack of underscore is the issue, at least as far as I can understand the issue. Please see my reply to Ethan. Thanks, James On Mon, May 9, 2011 at 2:43 PM, Steven D'Aprano wrote: > On Mon, 09 May 2011 14:10:21 -0400, James Wright wrote: > >> Hello, >> >> I have been using a script on several boxes that have been around for a >> while, and everything works just fine. ?I am finding though, that on >> some new OS installs the script fails with: >> >> Traceback (most recent call last): >> ? File "render4.py", line 114, in >> ? ? create_report_index(each_item) >> ? File "render4.py", line 25, in create_report_index >> ? ? [clean_name, _] = each_value.split('_', 1) >> ValueError: need more than 1 value to unpack > > It's a data issue, not an OS or package problem. > > Firstly, you don't have to wrap the left hand side in brackets, this > works fine: > >>>> each_value = "aaa_bbb_ccc" >>>> clean_name, _ = each_value.split('_', 1) >>>> clean_name > 'aaa' > > > However, if your data has no underscore at all: > >>>> each_value = "aaa*bbb*ccc" >>>> clean_name, _ = each_value.split('_', 1) > Traceback (most recent call last): > ?File "", line 1, in > ValueError: need more than 1 value to unpack > > > > So you need to allow for the possibility that there is no underscore. > > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From jamfwright at gmail.com Mon May 9 15:10:39 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 15:10:39 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: Message-ID: Hello Ian, It does indeed to seem that way. However the script works just fine on other machines, with the same input file. Thanks, James On Mon, May 9, 2011 at 2:41 PM, Ian Kelly wrote: > On Mon, May 9, 2011 at 12:10 PM, James Wright wrote: >> Hello, >> >> I have been using a script on several boxes that have been around for >> a while, and everything works just fine. ?I am finding though, that on >> some new OS installs the script fails with: >> >> Traceback (most recent call last): >> ?File "render4.py", line 114, in >> ? ?create_report_index(each_item) >> ?File "render4.py", line 25, in create_report_index >> ? ?[clean_name, _] = each_value.split('_', 1) >> ValueError: need more than 1 value to unpack > > You should check the value of each_value at the point when the script > fails. ?It sounds like split() is getting passed a string that doesn't > contain any '_' characters at all, resulting in a sequence with only > one value. ?Passing 1 as the second argument ensures that there will > be at most 1 split, but there may still be fewer. > > Cheers, > Ian > From csamaras72 at gmail.com Mon May 9 15:13:31 2011 From: csamaras72 at gmail.com (CTS) Date: Mon, 9 May 2011 12:13:31 -0700 (PDT) Subject: Missing 'line' event when writing to frame.f_lineno in trace function Message-ID: <4a0fce60-2ecd-47fd-822d-9a9b90210b3d@17g2000prr.googlegroups.com> Hello all, I've been playing with sys.settrace() in an attempt to better understand how trace functions (and debugging) work. I'm running Python3.2 on Windows, which I installed by running the installer package (i.e. I did not compile from source code). Here's my code, some of which I borrowed from Pdb/Bdb. The trace function basically prints out the event type, the filename, and the line number, and asks the user what to do next. If "jump " is entered, is written to frame.f_lineno before moving on. Otherwise, we just move on to the next trace event. # ---------- BEGIN tracing code ------------------- import sys import __main__ import re class Tracer: def __init__( self, filename ): __main__.__dict__.clear() __main__.__dict__.update( { "__name__": "__main__", "__file__": filename, "__builtins__": __builtins__, } ) with open( filename, "rb" ) as file: code = compile( file.read(), filename, 'exec') sys.settrace( self.trace ) exec( code, __main__.__dict__ ) def trace( self, frame, event, arg ): filename = frame.f_code.co_filename line = frame.f_lineno prompt = event + " -> " + filename + "(" + str( line ) + "):" action = input( prompt ) tokens = re.split( " +", action ) if tokens[ 0 ] == "jump": frame.f_lineno = int( tokens[ 1 ] ) return self.trace def run( filename ): Tracer( filename ) # ---------- END end tracing code ------------- I start tracing a script's execution by typing the following at the interactive prompt: >>> import tracer >>> tracer.run( "insert file name here" ) Given the following code, # ----- BEGIN traced script ------ print( "Line 1" ) print( "Line 2" ) print( "Line 3" ) print( "Line 4" ) # ----- END traced script------- ... I get the following output if I just step though from beginning to end: # BEGIN output (no writes to frame.f_lineno) C:\python_tests>python Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1 32 Type "help", "copyright", "credits" or "license" for m >>> import tracer >>> tracer.run('just_prints.py') call -> just_prints.py(1): line -> just_prints.py(1): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 1call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(2): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 2call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(3): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 3call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(4): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 4call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): return -> just_prints.py(6): >>> # END output (no writes to frame.f_lineno) So, as expected, I get "line" events for each of my script's lines, and it appears that the print() built-in calls some helper functions in lib\encodings\cp437.py, which is fine and explainable. Now, if I try to jump to any line during the trace (in the following output, after I'm done with line 3, I try to jump back to line 1 by writing "1" to frame.f_lineno), I don't get the "line" event; instead I go directly to the first "call" event of file cp437.py: # BEGIN output (with a write to frame.f_lineno) C:\python_tests>python Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit ( 32 Type "help", "copyright", "credits" or "license" for more informat >>> import tracer >>> tracer.run( 'just_prints.py') call -> just_prints.py(1): line -> just_prints.py(1): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 1call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(2): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 2call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(3): call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 3call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(4):jump 1 <======= write to frame.f_lineno call -> c:\python32\lib\encodings\cp437.py(18): <======= No "line" event !!!! line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): Line 1call -> c:\python32\lib\encodings\cp437.py(18): line -> c:\python32\lib\encodings\cp437.py(19): return -> c:\python32\lib\encodings\cp437.py(19): line -> just_prints.py(2): # # END output (with a write to frame.f_lineno) The above behavior occurs both when I jump back, as well as forward in a script. My questions to the group: 1) I was expecting a "line" event for line 1 of my traced script right after I wrote "1" to frame.f_lineno, shouldn't that event have been passed to my trace function? 2) Is there a way to get the missing "line" event by any means other than by writing to frame.f_lineno? My apologies for the lengthy message. Thanks in advance for your insights, -CTS From tjreedy at udel.edu Mon May 9 15:24:16 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 15:24:16 -0400 Subject: How to access elemenst in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/9/2011 4:25 AM, Antonio CHESSA wrote: > apple = [["a","b","c"],[1,2,3,4,5,6],["antony","max","sandra","sebastian"]] > > apple[0] = ["a","b","c"] > apple[1] = [1,2,3,4,5,6] > apple[2] = ["antony","max","sandra","sebastian"] > > apple[0][1] = "b" > apple[2][3] = "sebastian" > > to view all videos in a loop so you can set: > > for i in range(len(apple)): > print apple[i] > for j in range (len(apple[i])): > print apple[i][j] While this illustrate double indexing, it can be simplified to for top in apple: print(top) for inner in top: print(inner) and give the same output. Indexing is only needed for random access and for changing a list in place. -- Terry Jan Reedy From python at mrabarnett.plus.com Mon May 9 15:25:40 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 09 May 2011 20:25:40 +0100 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: Message-ID: <4DC83FB4.4050503@mrabarnett.plus.com> On 09/05/2011 20:10, James Wright wrote: > On Mon, May 9, 2011 at 2:41 PM, Ian Kelly wrote: >> On Mon, May 9, 2011 at 12:10 PM, James Wright wrote: >>> Hello, >>> >>> I have been using a script on several boxes that have been around for >>> a while, and everything works just fine. I am finding though, that on >>> some new OS installs the script fails with: >>> >>> Traceback (most recent call last): >>> File "render4.py", line 114, in >>> create_report_index(each_item) >>> File "render4.py", line 25, in create_report_index >>> [clean_name, _] = each_value.split('_', 1) >>> ValueError: need more than 1 value to unpack >> >> You should check the value of each_value at the point when the script >> fails. It sounds like split() is getting passed a string that doesn't >> contain any '_' characters at all, resulting in a sequence with only >> one value. Passing 1 as the second argument ensures that there will >> be at most 1 split, but there may still be fewer. >> > It does indeed to seem that way. However the script works just fine > on other machines, with the same input file. > 'each_value' gets its value from D4[report], so check which value of 'report' that is, and look at where 'D4' is filled. From ggrp2.20.martineau at dfgh.net Mon May 9 15:26:28 2011 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Mon, 9 May 2011 12:26:28 -0700 (PDT) Subject: Custom string joining References: Message-ID: On May 7, 5:31?am, Claudiu Popa wrote: > Hello Python-list, > > I ?have ?an object which defines some methods. I want to join a list or > an iterable of those objects like this: > > new_string = "|".join(iterable_of_custom_objects) > > What ? is ? the ? __magic__ ?function that needs to be implemented for > this case to work? ?I ?though ?that ?__str__ ?is sufficient but it doesn't seems to > work. Thanks in advance. > > PC Instead of join() here's a function that does something similar to what the string join() method does. The first argument can be a list of any type of objects and the second separator argument can likewise be any type. The result is list of the various objects. (The example usage just uses a list of string objects and separator to illustrate what it does.) def tween(seq, sep): return reduce(lambda r,v: r+[sep,v], seq[1:], seq[:1]) lst = ['a','b','c','d','e'] print tween(lst, '|') print ''.join(tween(lst, '|')) Output: ['a', '|', 'b', '|', 'c', '|', 'd', '|', 'e'] a|b|c|d|e It could be made a little more memory efficient by applying the itertools module's islice() generator to the first 'seq' argument passed to reduce(): def tween(seq, sep): return reduce(lambda r,v: r+[sep,v], itertools.islice(seq,1,None), seq[:1]) -- Martin From jamfwright at gmail.com Mon May 9 15:29:34 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 15:29:34 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: <4DC84223.3000502@stoneleaf.us> References: <4DC838CD.7030404@stoneleaf.us> <4DC84223.3000502@stoneleaf.us> Message-ID: On Mon, May 9, 2011 at 3:36 PM, Ethan Furman wrote: > James Wright wrote: >> >> Thank you Ethan, >> >> This is what I see now: >> >> # python render4.py >> current each_value is: vsr >> Traceback (most recent call last): >> ?File "render4.py", line 115, in >> ? ?create_report_index(each_item) >> ?File "render4.py", line 26, in create_report_index >> ? ?[clean_name, _] = each_value.split('_', 1) >> ValueError: need more than 1 value to unpack >> >> # grep -i vsr * >> # >> >> Using the informational line you suggested I see that 'vsr' showing as >> the current each_value. ?The string 'vsr' does not exist in my data >> though. ?Where could this be coming from? > > So 'vsr' in the value -- what is the key? ?(Sorry, should have had you print > that at the same time...) > > Change your print line to: > > ? ?print("D4[%s] = %s" % (report, each_value)) > > After that, you'll have to track down how D4 is being created to see where > 'vsr' is coming from. > > ~Ethan~ > Hi Ethan, It does not appear to show a key: D4[] = vsr Traceback (most recent call last): File "render4.py", line 115, in create_report_index(each_item) File "render4.py", line 26, in create_report_index [clean_name, _] = each_value.split('_', 1) ValueError: need more than 1 value to unpack Thanks, James From ethan at stoneleaf.us Mon May 9 15:36:03 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 09 May 2011 12:36:03 -0700 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: <4DC838CD.7030404@stoneleaf.us> Message-ID: <4DC84223.3000502@stoneleaf.us> James Wright wrote: > Thank you Ethan, > > This is what I see now: > > # python render4.py > current each_value is: vsr > Traceback (most recent call last): > File "render4.py", line 115, in > create_report_index(each_item) > File "render4.py", line 26, in create_report_index > [clean_name, _] = each_value.split('_', 1) > ValueError: need more than 1 value to unpack > > # grep -i vsr * > # > > Using the informational line you suggested I see that 'vsr' showing as > the current each_value. The string 'vsr' does not exist in my data > though. Where could this be coming from? So 'vsr' in the value -- what is the key? (Sorry, should have had you print that at the same time...) Change your print line to: print("D4[%s] = %s" % (report, each_value)) After that, you'll have to track down how D4 is being created to see where 'vsr' is coming from. ~Ethan~ From ian.g.kelly at gmail.com Mon May 9 15:51:01 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 May 2011 13:51:01 -0600 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: <4DC838CD.7030404@stoneleaf.us> <4DC84223.3000502@stoneleaf.us> Message-ID: On Mon, May 9, 2011 at 1:29 PM, James Wright wrote: > It does not appear to show a key: > > D4[] = vsr > Traceback (most recent call last): > ?File "render4.py", line 115, in > ? ?create_report_index(each_item) > ?File "render4.py", line 26, in create_report_index > ? ?[clean_name, _] = each_value.split('_', 1) > ValueError: need more than 1 value to unpack The key appears to be the empty string. You can confirm that by changing the %s to %r in Ethan's diagnostic. That will print out the repr() of the value, which should make it more clear what the value actually is. From alex at moreati.org.uk Mon May 9 16:02:04 2011 From: alex at moreati.org.uk (Alex Willmer) Date: Mon, 9 May 2011 13:02:04 -0700 (PDT) Subject: Inconsistency with split() - Script, OS, or Package Problem? References: Message-ID: <3722b403-ac45-4360-a13b-4814f14de389@gu8g2000vbb.googlegroups.com> (Direct reply to me, reposted on Jame's behalf) Hi Alex, On Mon, May 9, 2011 at 3:21 PM, Alex Willmer wrote: > On May 9, 8:10 pm, James Wright wrote: >> Hello Ian, >> >> It does indeed to seem that way. However the script works just fine >> on other machines, with the same input file. > > How sure of that are you? Post md5sums of the script and the input > file on a working machine and a non-working (4 md5sums total). > > Does the script use an non-stdlib modules? Check the md5sum of those > too. > > Are the platforms/python versions the same? Post the uname and python - > v from each. > > Can you post the script and the file online for us? Do so. > > Regards, Alex > The md5sums match (great idea by the way, I hadn't thought of that). What do you mean by using a non-stdlib module? I am not using any import statements, if that is what you are referring to. As for kernel and Python versions, I have updated both in case this was a bug - they no longer match across the machines I am testing on. The script consistently works with the machines that it always has been working with. The script continues to not work on the new VMWare installs (but does in new VirtualBox installs - odd). I can post the script (attached), but am not so certain that is at fault - given that the script is running on other hosts just fine. Please read the script with a grain of salt, this is my first run at this, and I am well aware that I am not yet following the conventions of Python. I have much to learn. Thanks, James From ethan at stoneleaf.us Mon May 9 16:04:07 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 09 May 2011 13:04:07 -0700 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: <4DC838CD.7030404@stoneleaf.us> <4DC84223.3000502@stoneleaf.us> Message-ID: <4DC848B7.6010804@stoneleaf.us> James Wright wrote: > On Mon, May 9, 2011 at 3:36 PM, Ethan Furman wrote: >> Change your print line to: >> >> print("D4[%s] = %s" % (report, each_value)) >> >> After that, you'll have to track down how D4 is being created to see where >> 'vsr' is coming from. > > It does not appear to show a key: > > D4[] = vsr Huh -- probably the empty string ('') -- to verify that (and know for sure -- always good when debugging! ;) change the both %s to %r and run again; then you'll have to track down where D4 is being created to see why it's getting that weird key. ~Ethan~ From ian.g.kelly at gmail.com Mon May 9 16:07:40 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 May 2011 14:07:40 -0600 Subject: Custom string joining In-Reply-To: References: Message-ID: On Mon, May 9, 2011 at 1:26 PM, Martineau wrote: > Instead of join() here's a function that does something similar to > what the string join() method does. The first argument can be a list > of any type of objects and the second separator argument can likewise > be any type. The result is list of the various objects. (The example > usage just uses a list of string objects ?and separator to illustrate > what it does.) > > def tween(seq, sep): > ? ?return reduce(lambda r,v: r+[sep,v], seq[1:], seq[:1]) > > lst = ['a','b','c','d','e'] > > print tween(lst, '|') > print ''.join(tween(lst, '|')) > > Output: > > ['a', '|', 'b', '|', 'c', '|', 'd', '|', 'e'] > a|b|c|d|e > > > It could be made a little more memory efficient by applying the > itertools module's islice() generator to the first 'seq' argument > passed to reduce(): > > def tween(seq, sep): > ? ?return reduce(lambda r,v: r+[sep,v], itertools.islice(seq,1,None), > seq[:1]) This version accepts any iterable, not just a list: def tween(seq, sep): it = iter(seq) try: first = it.next() except StopIteration: return [] return reduce(lambda r, v: r + [sep, v], it, [first]) A further efficiency improvement would be to do the list concatenation in place to avoid generating O(n) intermediate copies: def tween(seq, sep): it = iter(seq) try: first = it.next() except StopIteration: return [] def add_sep(r, v): r += [sep, v] return r return reduce(add_sep, it, [first]) From jamfwright at gmail.com Mon May 9 16:08:20 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 16:08:20 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: <4DC848B7.6010804@stoneleaf.us> References: <4DC838CD.7030404@stoneleaf.us> <4DC84223.3000502@stoneleaf.us> <4DC848B7.6010804@stoneleaf.us> Message-ID: Hello Ethan, On Mon, May 9, 2011 at 4:04 PM, Ethan Furman wrote: > James Wright wrote: >> >> On Mon, May 9, 2011 at 3:36 PM, Ethan Furman wrote: >>> >>> Change your print line to: >>> >>> ? print("D4[%s] = %s" % (report, each_value)) >>> >>> After that, you'll have to track down how D4 is being created to see >>> where >>> 'vsr' is coming from. >> >> It does not appear to show a key: >> >> D4[] = vsr > > Huh -- probably the empty string ('') -- to verify that (and know for sure > -- always good when debugging! ;) ?change the both %s to %r and run again; > ?then you'll have to track down where D4 is being created to see why it's > getting that weird key. > > ~Ethan~ > A quick note: Renaming the file allowed it to run successfully one time. Then it failed per usual. Renaming it again did not help, so that is not a repeatable test. Changing %s to %r: D4[''] = vsr Traceback (most recent call last): File "render5.py", line 115, in create_report_index(each_item) File "render5.py", line 26, in create_report_index [clean_name, _] = each_value.split('_', 1) ValueError: need more than 1 value to unpack Thanks, James From jamfwright at gmail.com Mon May 9 16:08:45 2011 From: jamfwright at gmail.com (James Wright) Date: Mon, 9 May 2011 16:08:45 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: <3722b403-ac45-4360-a13b-4814f14de389@gu8g2000vbb.googlegroups.com> References: <3722b403-ac45-4360-a13b-4814f14de389@gu8g2000vbb.googlegroups.com> Message-ID: Sorry Alex, and thank you. On Mon, May 9, 2011 at 4:02 PM, Alex Willmer wrote: > (Direct reply to me, reposted on Jame's behalf) > > > > Hi Alex, > > On Mon, May 9, 2011 at 3:21 PM, Alex Willmer > wrote: >> On May 9, 8:10 pm, James Wright wrote: >>> Hello Ian, >>> >>> It does indeed to seem that way. ?However the script works just fine >>> on other machines, with the same input file. >> >> How sure of that are you? Post md5sums of the script and the input >> file on a working machine and a non-working (4 md5sums total). >> >> Does the script use an non-stdlib modules? Check the md5sum of those >> too. >> >> Are the platforms/python versions the same? Post the uname and python - >> v from each. >> >> Can you post the script and the file online for us? Do so. >> >> Regards, Alex >> > > The md5sums match (great idea by the way, I hadn't thought of that). > > What do you mean by using a non-stdlib module? ?I am not using any > import statements, if that is what you are referring to. > > As for kernel and Python versions, I have updated both in case this > was a bug - they no longer match across the machines I am testing on. > The script consistently works with the machines that it always has > been working with. ?The script continues to not work on the new VMWare > installs (but does in new VirtualBox installs - odd). > > I can post the script (attached), but am not so certain that is at > fault - given that the script is running on other hosts just fine. > > Please read the script with a grain of salt, this is my first run at > this, and I am well aware that I am not yet following the conventions > of Python. ?I have much to learn. > > > > Thanks, > James > -- > http://mail.python.org/mailman/listinfo/python-list > From karim.liateni at free.fr Mon May 9 16:14:38 2011 From: karim.liateni at free.fr (Karim) Date: Mon, 09 May 2011 22:14:38 +0200 Subject: Custom string joining In-Reply-To: References: <254518825.20110507153133@bitdefender.com> Message-ID: <4DC84B2E.9090209@free.fr> On 05/07/11 16:25, Chris Rebert wrote: > On Sat, May 7, 2011 at 5:31 AM, Claudiu Popa wrote: >> Hello Python-list, >> >> I have an object which defines some methods. I want to join a list or >> an iterable of those objects like this: >> >> new_string = "|".join(iterable_of_custom_objects) >> >> What is the __magic__ function that needs to be implemented for >> this case to work? I though that __str__ is sufficient but it doesn't seems to >> work. Thanks in advance. > You need to do the string conversion yourself; .join() doesn't do it > for you, due to strong typing. It only accepts iterables of strings: > new_string = "|".join(str(x) for x in iterable_of_custom_objects) You just have to implement __str__() python special method for your "custom_objects". Regards Karim > Cheers, > Chris > -- > http://rebertia.com From tjreedy at udel.edu Mon May 9 16:23:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 16:23:21 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/9/2011 10:29 AM, Steven D'Aprano wrote: > > If people then ask, how does the interpreter know the names?, I can add > more detail: names are actually strings in a namespace, which is usually > nothing more than a dict. Oh, and inside functions, it's a bit more > complicated still. And so on. Which is why I think it best to stick with 'A namespace is a many-to-one mapping (in other words, a function) of names to objects'. Any programmer should understand the abstractions 'mapping' and 'function'. Asking how the interpreter finds the object associated with a name amounts to asking how to do tabular lookup. Well, we basically know, though the details depends on the implementation of the table (mapping). An interpreter can *implement* namespaces various ways. One is to objectify names and namespaces as strings and dicts. If the set of names in a namespace is fixed, another way is to objectify names and namespaces as ints and arrays. Python prohibits 'from x import *' within functions precisely to keep the set of local namespace names fixed. Therefore, CPython can and does always use C ints and array for function local namespaces. -- Terry Jan Reedy From cpopa at bitdefender.com Mon May 9 16:25:27 2011 From: cpopa at bitdefender.com (Claudiu Popa) Date: Mon, 9 May 2011 23:25:27 +0300 Subject: Custom string joining In-Reply-To: <4DC84B2E.9090209@free.fr> References: <254518825.20110507153133@bitdefender.com> <4DC84B2E.9090209@free.fr> Message-ID: <354289288.20110509232527@bitdefender.com> Hello Karim, > You just have to implement __str__() python special method for your > "custom_objects". > Regards > Karim >> Cheers, >> Chris >> -- >> http://rebertia.com I already told in the first post that I've implemented __str__ function, but it doesn't seems to be automatically called. For instance, the following example won't work: >>> class a: def __init__(self, i): self.i = i def __str__(self): return "magic_function_{}".format(self.i) >>> t = a(0) >>> str(t) 'magic_function_0' >>> "".join([t]) Traceback (most recent call last): File "", line 1, in "".join([t]) TypeError: sequence item 0: expected str instance, a found -- Best regards, Claudiu From ethan at stoneleaf.us Mon May 9 16:44:43 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 09 May 2011 13:44:43 -0700 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: <4DC838CD.7030404@stoneleaf.us> <4DC84223.3000502@stoneleaf.us> <4DC848B7.6010804@stoneleaf.us> Message-ID: <4DC8523B.7010705@stoneleaf.us> James Wright wrote: > On Mon, May 9, 2011 at 4:04 PM, Ethan Furman wrote: >> James Wright wrote: >>> On Mon, May 9, 2011 at 3:36 PM, Ethan Furman wrote: >>>> >>>> Change your print line to: >>>> >>>> print("D4[%s] = %s" % (report, each_value)) >>>> >>>> After that, you'll have to track down how D4 is being created to see >>>> where 'vsr' is coming from. >>> >>> It does not appear to show a key: >>> >>> D4[] = vsr >> >> Huh -- probably the empty string ('') -- to verify that (and know for sure >> -- always good when debugging! ;) change the both %s to %r and run again; >> then you'll have to track down where D4 is being created to see why it's >> getting that weird key. > > A quick note: Renaming the file allowed it to run successfully one > time. Then it failed per usual. Renaming it again did not help, so > that is not a repeatable test. > > Changing %s to %r: > > D4[''] = vsr When you find the problem let us know -- might save somebody else some grief. :) ~Ethan~ From tjreedy at udel.edu Mon May 9 16:46:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 16:46:02 -0400 Subject: Inconsistency with split() - Script, OS, or Package Problem? In-Reply-To: References: Message-ID: On 5/9/2011 2:10 PM, James Wright wrote: > Hello, > > I have been using a script on several boxes that have been around for > a while, and everything works just fine. I am finding though, that on > some new OS installs the script fails with: > > Traceback (most recent call last): > File "render4.py", line 114, in > create_report_index(each_item) > File "render4.py", line 25, in create_report_index > [clean_name, _] = each_value.split('_', 1) > ValueError: need more than 1 value to unpack What this means is that at some point you tried to split a string that does not have an underscore to print on. >>> [s,_] = 'no underscore'.split('_',1) Traceback (most recent call last): File "", line 1, in [s,_] = 'no underscore'.split('_',1) ValueError: need more than 1 value to unpack > The OS's are various OpenSuse installs from 10.3 to 11.4. It works on > all the existing ones, which leads me to believe that I have a package > or configuration inconsistency. It should be noted though that I am > quite new to python programming and very well could have coded in a > non-portable manner and was just lucky to get it working in the first > place :) Your code is fine. The question is,"How could, or why, would new installs result in invalid inputs?" > Here is the code snippet that generates the failure ( when you look > at this remember that I am a novice :-) ): > > for each_item in D4: #D4 is a dictionary > create_report_index(each_item) I might write 'for key in D4:' which makes it obvious that D4 is a dict and that you are iterating through its keys. Or 'for report_name...' > def create_report_index(report): #Here we are creating a simple > index.html file from data in a text file > newfile = open(report + '.html', 'w') #Create the index file using > report name > for each_value in D4[report]: For debugging, add if '_' not in each_value: print(report, D4[report], each_value > [clean_name, _] = each_value.split('_', 1) > newfile.write('' + clean_name +'
\n') Once you find the offending input, then investigate its source in the code that creates D4. Your other questions are premature. If a no_underscore each_value is wrong, fix the source. If you decide that such are actually ok, then fix the code above: if '_' in each_value: clean_name = each_value.split('_', 1) else: clean_name = each_value -- Terry Jan Reedy From bahamutzero8825 at gmail.com Mon May 9 16:52:52 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 09 May 2011 15:52:52 -0500 Subject: Finding the bitness of an arbitrary executable with Python Message-ID: <4DC85424.2020609@gmail.com> I need to find whether a given file is 32-bit or 64-bit (and raise an exception if the file doesn't exist or isn't an executable file). I thought platform.architecture() would do this, but it returns ('64bit', '') no matter what value I assign to the executable parameter (looks like it uses the given executable to find info on the underlying system rather than info on the specific file, reverting to sys.executable if there are any errors). A quick look on Google doesn't give me anything useful. Something cross-platform would be nice, but it really only needs to work on Windows (on win32 binaries). From hg at schaathun.net Mon May 9 16:53:33 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Mon, 9 May 2011 21:53:33 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <6qsk98-em1.ln1@svn.schaathun.net> Message-ID: On Mon, 9 May 2011 21:18:29 +1000, Chris Angelico wrote: : Analogies are like diagrams. Not all of them are perfect or useful. : : The boxes are different sizes. If you really want them to look : different, do one as squares and one as circles, but don't try that in : plain text. Analogies, even imperfect ones, are good when we are clear about the fact that they are analogies. Using C pointers to illustrate how to use bound names in python may be useful, but only if we are clear about the fact that it is an analogy and do not pretend that it explains it in full. -- :-- Hans Georg From chardster at gmail.com Mon May 9 17:02:17 2011 From: chardster at gmail.com (Richard Thomas) Date: Mon, 9 May 2011 14:02:17 -0700 (PDT) Subject: Finding the bitness of an arbitrary executable with Python References: Message-ID: On May 9, 9:52?pm, Andrew Berg wrote: > I need to find whether a given file is 32-bit or 64-bit (and raise an > exception if the file doesn't exist or isn't an executable file). I > thought platform.architecture() would do this, but it returns ('64bit', > '') no matter what value I assign to the executable parameter (looks > like it uses the given executable to find info on the underlying system > rather than info on the specific file, reverting to sys.executable if > there are any errors). A quick look on Google doesn't give me anything > useful. Something cross-platform would be nice, but it really only needs > to work on Windows (on win32 binaries). I don't know of anything that does that. If you wanted to do it yourself the correct place to start is by reading up on the Protable Executable Format: http://en.wikipedia.org/wiki/PE_format. That page has references to the MSDN article which is probably most useful. Other platforms have other executable formats of course but there's no reason it couldn't exist... From irmen.NOSPAM at xs4all.nl Mon May 9 17:10:25 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 09 May 2011 23:10:25 +0200 Subject: Finding the bitness of an arbitrary executable with Python In-Reply-To: References: Message-ID: <4dc85842$0$81484$e4fe514c@news.xs4all.nl> On 9-5-2011 22:52, Andrew Berg wrote: > I need to find whether a given file is 32-bit or 64-bit (and raise an > exception if the file doesn't exist or isn't an executable file). I > thought platform.architecture() would do this, but it returns ('64bit', > '') no matter what value I assign to the executable parameter (looks > like it uses the given executable to find info on the underlying system > rather than info on the specific file, reverting to sys.executable if > there are any errors). A quick look on Google doesn't give me anything > useful. Something cross-platform would be nice, but it really only needs > to work on Windows (on win32 binaries). A few options are mentioned here: http://stackoverflow.com/questions/1345632/determine-if-an-executable-or-library-is-32-or-64-bits-on-windows -irmen From python at rcn.com Mon May 9 17:10:54 2011 From: python at rcn.com (Raymond Hettinger) Date: Mon, 9 May 2011 14:10:54 -0700 (PDT) Subject: Coolest Python recipe of all time References: <69c1813d-1a9a-4686-9768-8ec1910a45f8@d19g2000prh.googlegroups.com> Message-ID: <55c0b493-7d4e-42c2-a411-537c68a058b3@b7g2000prg.googlegroups.com> On May 9, 2:31?am, Trent Nelson wrote: > > What are your favorites? > > I think I've posted this before, but I love my 3-lines-if-you-ignore-the-scaffolding language translator. ?Not because it's clever code -- quite the opposite, the code is dead simple -- but because it encompasses one of the things I love about Python the most: it gets shit done. > > ? ? In [1]: from translate import * > > ? ? In [2]: translate('French', 'The quick brown fox jumped over the lazy dog.') > ? ? Le renard brun rapide a saut? par-dessus le chien paresseux. > > ? ? In [3]: translate('German', 'The quick brown fox jumped over the lazy dog.') > ? ? Der schnelle braune Fuchs sprang ?ber den faulen Hund. > > ? ? In [4]: translate('Spanish', 'The quick brown fox jumped over the lazy dog.') > ? ? El zorro marr?n r?pido salt? sobre el perro perezoso. > > translate.py: > > ? ? import sys > ? ? from urllib import urlopen, urlencode > ? ? from BeautifulSoup import BeautifulSoup > > ? ? url = 'http://babelfish.altavista.com/tr' > ? ? languages = { > ? ? ? ? 'French' ? ?: 'en_fr', > ? ? ? ? 'German' ? ?: 'en_de', > ? ? ? ? 'Italian' ? : 'en_it', > ? ? ? ? 'Spanish' ? : 'en_es', > ? ? ? ? 'Russian' ? : 'en_ru', > ? ? ? ? 'Portuguese': 'en_pt', > ? ? ? ? 'Dutch' ? ? : 'en_nl', > ? ? ? ? 'Japanese' ?: 'en_ja', > ? ? } > > ? ? def translate(lang, text): > ? ? ? ? kwds = { 'trtext' : text, 'lp' : languages[lang]} > ? ? ? ? soup = BeautifulSoup(urlopen(url, urlencode(kwds))) > ? ? ? ? print soup.find('div', style='padding:10px;').string > > ? ? if __name__ == '__main__': > ? ? ? ? translate(sys.argv[1], sys.argv[2]) That completely rocks! Thanks for the recipe. Raymond ---------- follow my recipes and tips on twitter: @raymondh From robert.kern at gmail.com Mon May 9 17:22:47 2011 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 09 May 2011 16:22:47 -0500 Subject: Finding the bitness of an arbitrary executable with Python In-Reply-To: <4DC85424.2020609@gmail.com> References: <4DC85424.2020609@gmail.com> Message-ID: On 5/9/11 3:52 PM, Andrew Berg wrote: > I need to find whether a given file is 32-bit or 64-bit (and raise an > exception if the file doesn't exist or isn't an executable file). I > thought platform.architecture() would do this, but it returns ('64bit', > '') no matter what value I assign to the executable parameter (looks > like it uses the given executable to find info on the underlying system > rather than info on the specific file, reverting to sys.executable if > there are any errors). Actually, that information is built into the Python interpreter when it gets built. It is not actually examining the file referenced by sys.executable. -- 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 harrismh777 at charter.net Mon May 9 17:28:43 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 09 May 2011 16:28:43 -0500 Subject: What other languages use the same data model as Python? In-Reply-To: <92os6dF5jbU1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > > +-------------+ > +---+ | | > a | --+---------------->| | > +---+ | | > +-------------+ > ^ > +---+ | > b | --+-----------------------| > +---+ > > In this model, a "reference" is an arrow. Manipulating references > consists of rubbing out the arrows and redrawing them differently. Greg, this is an excellent model, thank you for taking the time to put it together for the list... very helpful. Both Summerfield and Lutz use the same model (and almost the identical graphic symbolism) to explain dynamic typing in Python. Summerfield's Programming in Python 3 2nd ed. has a good explanation similar, see pages 17 and 32 (there are others). Lutz has an entire chapter devoted to the topic in Learning Python 4th ed., see chapter six. He calls it the Dynamic Typing Interlude. The model is in-the-field and very workable; and yet, it does have limitations, as most models do. For visual thinkers this model probably comes closest to being most helpful, esp in the beginning. kind regards, m harris From tjreedy at udel.edu Mon May 9 17:30:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 17:30:22 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/8/2011 7:36 PM, Dan Stromberg wrote: > > On Sun, May 8, 2011 at 3:41 PM, Terry Reedy > wrote: > Because inductive algorithms commonly branch on 'input is something' > (not done, change args toward 'nothing'and recurse or iterate) > versus 'input is nothing (done, return base expression). > > > Just what is an inductive algorithm? The parenthesized comments were meant to define common patterns such as: def f(x): if x: return g(f(reduce_arg(x)) else: return base(x) def f(x) ret = start(x) while x: ret = reduce_arg(x) return x More generally, an inductive algorithm computes by looping (with recursion or iteration). That is my definition. That includes most of the 'interesting' algorithms. You might ask, what is not an inductive algorithm? One that does no looping and just returns non-recursive expressions, perhaps in multiple branches. The functions in the expression are taken as primitives and their internal use of induction is ignored. Of course, a computer is nothing but an induction machine: while not halted: get next instruction get args compute result Michal Torrie's response is right. Inductive algorithms follow the pattern of inductive proofs. -- Terry Jan Reedy From ggrp2.20.martineau at dfgh.net Mon May 9 17:38:24 2011 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Mon, 9 May 2011 14:38:24 -0700 (PDT) Subject: Custom string joining References: <254518825.20110507153133@bitdefender.com> <4DC84B2E.9090209@free.fr> Message-ID: On May 9, 1:25?pm, Claudiu Popa wrote: > Hello Karim, > > > You just have to implement __str__() python special method for your > > "custom_objects". > > Regards > > Karim > >> Cheers, > >> Chris > >> -- > >>http://rebertia.com > > I ?already told in the first post that I've implemented __str__ function, but it doesn't > seems to be automatically called. > For instance, the following example won't work: > > >>> class a: > > ? ? ? ? def __init__(self, i): > ? ? ? ? ? ? ? ? self.i = i > ? ? ? ? def __str__(self): > ? ? ? ? ? ? ? ? return "magic_function_{}".format(self.i)>>> t = a(0) > >>> str(t) > 'magic_function_0' > >>> "".join([t]) > > Traceback (most recent call last): > ? File "", line 1, in > ? ? "".join([t]) > TypeError: sequence item 0: expected str instance, a found > > -- > Best regards, > ?Claudiu The built-in str join() method just doesn't do the conversion to string automatically -- instead it assume it has been given a sequence of string. You can achieve the effect you want by modifying the optimized version of my earlier post that @Ian Kelly submitted. def join(seq, sep): it = iter(seq) sep = str(sep) try: first = it.next() except StopIteration: return [] def add_sep(r, v): r += [sep, str(v)] return r return ''.join(reduce(add_sep, it, [str(first)])) class A: def __init__(self, i): self.i = i def __str__(self): return "magic_function_{}".format(self.i) lst = [A(0),A(1),A('b'),A(3)] print repr( join(lst, '|') ) Output: 'magic_function_0|magic_function_1|magic_function_b|magic_function_3' From bahamutzero8825 at gmail.com Mon May 9 17:44:41 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 09 May 2011 16:44:41 -0500 Subject: Finding the bitness of an arbitrary executable with Python In-Reply-To: <4dc85842$0$81484$e4fe514c@news.xs4all.nl> References: <4dc85842$0$81484$e4fe514c@news.xs4all.nl> Message-ID: <4DC86049.3070509@gmail.com> On 2011.05.09 04:10 PM, Irmen de Jong wrote: > http://stackoverflow.com/questions/1345632/determine-if-an-executable-or-library-is-32-or-64-bits-on-windows The code using struct doesn't look terribly complicated, so that could work. I might need to inspect other executable types, but I don't see it being any time soon. Thank you. From harrismh777 at charter.net Mon May 9 17:58:14 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 09 May 2011 16:58:14 -0500 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian Kelly wrote: > "bool(list)" describes whether the list contains something. "Not" > being a logical operator, it stands to reason that "not list" should > mean the same thing as "not bool(list)". Ian, James, Agreed, and thank you. This *is* the explanation I was trying to prompt D'Aprano for, rather than getting his 'not cat' analogy. James, the argument is not for argument sake. The argument is to better facilitate understanding for others who are also trying to make sense of new ideas, some of whom are lurking. :) This argument actually goes back to a previous discussion D'Aprano and I (and others) were having pertaining to whether software is mathematics. It is easy to see how that negating a binary value ( on or off ) works with 'not'... because there are only two possible states. not on, means off.... not off, means on. Same with '1' and '0' where we have only two states, or True and False where we have only two states... &etc. But when we have a list, what two states are we really discussing? Aren't we really talking about set theory? A list is an ordered collection of 'stuff' comprising a set. Negating the set 'not set' is saying 'not bool(set)' / The two states are either 1) the elements of the set, or 2) not the elements of the set--- the empty set, or that 'stuff' outside the set. The answer to the 'not list' question has to do with the conceived semantics of Python ordered collections, which are based more in mathematics proper (set theory) than in logic--- the 'not' operator. It is better to explain to students where the syntax is based (as Ian did) than to state uniformly, "This is just the way Python does it!". As a side point, the answer, "This is the way Python does it!"... would be o.k. if-and-only-if Python were a standardized language, which it isn't. Python's greatest strength is also its greatest weakness... that it is constantly evolving through the PEP process. James, one of the reasons we argue about language features is for that very purpose invited by PEP (and other feedback mechanisms, including this list). The community decides over time how Python does things (along with the final stamp, I suppose, of Guido the BDFL). So, we must needs be arguing, but its not for pedantic squabbling sake.... :-) kind regards, m harris From tjreedy at udel.edu Mon May 9 19:16:24 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 19:16:24 -0400 Subject: Custom string joining In-Reply-To: <354289288.20110509232527@bitdefender.com> References: <254518825.20110507153133@bitdefender.com> <4DC84B2E.9090209@free.fr> <354289288.20110509232527@bitdefender.com> Message-ID: On 5/9/2011 4:25 PM, Claudiu Popa wrote: > I already told in the first post that I've implemented __str__ function, > but it doesn't seems to be automatically called. No, Python does not auto-coerce to strings (only between numbers). You have to be explicit by calling str. Karim's statement "You just have to implement __str__() python special method for your "custom_objects". " means that str will then work. > For instance, the following example won't work: > >>>> class a: > def __init__(self, i): > self.i = i > def __str__(self): > return "magic_function_{}".format(self.i) >>>> t = a(0) >>>> str(t) > 'magic_function_0' >>>> "".join([t]) print('\n'.join(str(ob) for ob in [a(0), a(1), a(None)])) magic_function_0 magic_function_1 magic_function_None -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Mon May 9 19:34:59 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 May 2011 23:34:59 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 May 2011 16:58:14 -0500, harrismh777 wrote: > Ian Kelly wrote: >> "bool(list)" describes whether the list contains something. "Not" >> being a logical operator, it stands to reason that "not list" should >> mean the same thing as "not bool(list)". > > Ian, James, > > Agreed, and thank you. This *is* the explanation I was trying to > prompt D'Aprano for, rather than getting his 'not cat' analogy. Your dislike of analogies is leading you to see them where they aren't. The "cat on the mat" sentence I gave is a concrete example of the use of negation in English, not an analogy. It is virtually the opposite of an analogy. In that same post that annoyed you with the cat on the mat example, I wrote: Python uses a boolean algebra where there are many ways of spelling the true and false values. The "not" operator returns the canonical bool values: not returns False not returns True Take note of the distinction between lower-case true/false, which are adjectives, and True/False, which are objects of class bool. and later on, I contrasted: empty list versus non-empty list Ergo, "not (empty list)" returns True, and "not (non-empty list)" returns False, because the empty list is considered false and any non-empty list is considered true. I'm sorry that I failed to make that more explicit. If I were talking to a programming n00b, I would have been more careful, but you've made numerous references to your long, long programming experience and I thought you would be able to draw the obvious connection without me insulting you by stating the obvious. -- Steven From ben+python at benfinney.id.au Mon May 9 19:54:48 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 10 May 2011 09:54:48 +1000 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r587l99z.fsf@benfinney.id.au> Steven D'Aprano writes: > I'm sorry that I failed to make that more explicit. If I were talking > to a programming n00b, I would have been more careful, but you've made > numerous references to your long, long programming experience and I > thought you would be able to draw the obvious connection without me > insulting you by stating the obvious. +1 QOTW -- \ ?Never use a long word when there's a commensurate diminutive | `\ available.? ?Stan Kelly-Bootle | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Mon May 9 20:00:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2011 00:00:34 GMT Subject: Inconsistency with split() - Script, OS, or Package Problem? References: <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dc88022$0$29991$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 May 2011 15:09:32 -0400, James Wright wrote: > Thank you Steven, > > I will take your advice :) In this particular case though, I do not > think a lack of underscore is the issue, at least as far as I can > understand the issue. Please see my reply to Ethan. In your reply to Ethan, you inserted a print statement in the code and got this output: # python render4.py current each_value is: vsr Traceback (most recent call last): File "render4.py", line 115, in create_report_index(each_item) File "render4.py", line 26, in create_report_index [clean_name, _] = each_value.split('_', 1) ValueError: need more than 1 value to unpack The current value of each_value is the three letter string "vsr". There are no underscores in "vsr". Clearly the lack of underscore is the issue. Now that this has been solved, it has revealed a deeper problem, namely, how you get an empty key and "vsr" into your data on some machines but not others. If your script is behaving differently on different machines with the same data, it is *far* more likely that there is something non- deterministic in your code than that it is a bug in either the OS, Python, or the virtualization environment. Without seeing either your code or data, it is impossible to know what. No offense, but are you sure it's not a PEBCAK error? Are you absolutely sure you're running the same script the same way from the same data on each virtual machine? The fact that your script works correctly *once* when you rename it doesn't strike me with confidence. Renaming the script shouldn't change its behaviour. I suppose it is just barely plausible that one of the VMs is reading its data from faulty sectors on a disk, and hence gets inconsistent results, but that is stretching the bounds of possibility almost to breaking. You posted the data and script to Alex off list. Perhaps you could post it again on-list? As they say, many eyes make bugs shallow. -- Steven From harrismh777 at charter.net Mon May 9 20:10:18 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 09 May 2011 19:10:18 -0500 Subject: checking if a list is empty In-Reply-To: <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Python uses a boolean algebra where there are many ways of > spelling the true and false values. The "not" operator returns > the canonical bool values: > Take note of the distinction between lower-case true/false, > which are adjectives, and True/False, which are objects of > class bool. Yes, yes... to your previous comments, and to move the discussion forward a bit... ... the interesting thing about this part of the discussion is the class bool... because it looks like 'list' is being 'promoted' to type class bool in the following: if not list: <=== this is not logical on the surface... ... if the equivalent is: if not bool(list): <=== this is more explicit, and more readable although it still doesn't tell a casual reader how the bool(list) evaluates... is it empty? is it name exception? other? I'm just saying; no need to respond... just that its easier to understand the syntax of 'not list' in the knowledge that what is happening under the hood is that the 'not' operator does require a bool() and that list is being evaluated bool(list) as one of two logical states. Having played around a little bit with this today I am again impressed that bool() can take *any* object as a parm and derive the correct binary state, whatever that happens to be: bool({}) False bool([]) False bool(0) False bool('') False bool(()) False Therefore, if not str tests for the empty string... if not dict tests for the empty dictionary... &etc. ... is at least consistent ... kind regards, m harris From harrismh777 at charter.net Mon May 9 20:19:55 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 09 May 2011 19:19:55 -0500 Subject: checking if a list is empty In-Reply-To: <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc87a23$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > If I were talking to a programming n00b, I would have been more careful, > but you've made numerous references to your long, long programming > experience and I thought you would be able to draw the obvious connection > without me insulting you by stating the obvious. Pedantics is always potentially insulting, which was your intent, me thinks. Whether I choose to be insulted is my own prerogative, and I choose to 'not' be insulted. I would only suggest an argumentation style that is clear, 'not' pedantic, and 'not' potentially insulting when possible. (not necessarily for my sake) uh, not bool(insulting) kind regards, m harris From akabaila at pcug.org.au Mon May 9 20:31:15 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 10 May 2011 10:31:15 +1000 Subject: scipy In-Reply-To: <6bfdb99c-c8db-4c5c-af2b-35ff88bd94d8@32g2000vbe.googlegroups.com> References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> <6bfdb99c-c8db-4c5c-af2b-35ff88bd94d8@32g2000vbe.googlegroups.com> Message-ID: <201105101031.15778.akabaila@pcug.org.au> On Tuesday 10 May 2011 04:13:55 pb wrote: > On May 9, 3:34 pm, Robert Kern wrote: > > On 5/9/11 3:35 AM, pb wrote: > > > On May 9, 12:29 am, Terry Reedy wrote: > > >> On 5/8/2011 6:44 AM, pb wrote: > > >>> Hi, > > >>> I', having trouble with scipy. > > >> > > >> If you do not get an answer here, try the scipy list > > >> where scipy experts hang out. You might also try > > >> searching the archives of that list or the scipy bug > > >> tracker. > > >> > > >> -- > > >> Terry Jan Reedy > > > > > > Hi, > > > the scipy mailing list? > > > > http://www.scipy.org/Mailing_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 > > Thanks, > I have tried to register for the mailing lists there, but > cannot loggin and have received no "registration > comfirmation email" from them. I'd email the list > maintainer/admin, but cannot find an email address for them. > Peter Some lists require a "real email address", I think it is because it is so easy to create web mail addresses that it makes it too easy for the spammers to flood a mailing list with spam. Just a thought - I do not know what scipy list requirements are. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From onexpadREMOVE at EVOMERyahoodotyouknow.com Mon May 9 20:40:02 2011 From: onexpadREMOVE at EVOMERyahoodotyouknow.com (Kyle T. Jones) Date: Mon, 09 May 2011 19:40:02 -0500 Subject: Overuse of try/except/else? Message-ID: It has been hard for me to determine what would constitute overuse. Cheers. From akabaila at pcug.org.au Mon May 9 20:44:28 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 10 May 2011 10:44:28 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201105101044.28593.akabaila@pcug.org.au> On Tuesday 10 May 2011 05:24:16 Terry Reedy wrote: > On 5/9/2011 4:25 AM, Antonio CHESSA wrote: > > apple = > > [["a","b","c"],[1,2,3,4,5,6],["antony","max","sandra","seb > > astian"]] > > for j in range (len(apple[i])): > > print apple[i][j] > > While this illustrate double indexing, it can be simplified > to > > for top in apple: > print(top) > for inner in top: > print(inner) > > and give the same output. Indexing is only needed for random > access and for changing a list in place. The method of double indexing in the manner apple[i][j] or a[i][j] for the (i, j) -th element of multi-dimensional array is well known and widely used. But how to enable the "standard" matrix notation a[i, j] in Python 3.2 in the manner of numpy (and other matrix packages)? Is it subclassing of "special methods" __getitem__() and/or __setitem__() and if so how? OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Mon May 9 21:09:01 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 10 May 2011 11:09:01 +1000 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: On Tue, May 10, 2011 at 10:40 AM, Kyle T. Jones wrote: > It has been hard for me to determine what would constitute overuse. A rule of thumb I always follow and practice is: "Let the error lie where it occurred." or "Don't hide errors.". It's good practice to follow IHMO as it makes it easier to find the source of defects in your function(s). If you constantly do things like try/except/log then it makes finding the source harder and may make it harder to identify what caused it. I favor Test Driven Development (TDD) over Contracts in Python (as Python is a dynamic programming language) but errors should be handled and caught by the caller - not the callee. My 2c, others may have other points of view... cheers James -- -- James Mills -- -- "Problems are solved by method" From tjreedy at udel.edu Mon May 9 21:25:59 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 May 2011 21:25:59 -0400 Subject: How to access elemenst in a list of lists? In-Reply-To: <201105101044.28593.akabaila@pcug.org.au> References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> <201105101044.28593.akabaila@pcug.org.au> Message-ID: On 5/9/2011 8:44 PM, Algis Kabaila wrote: > The method of double indexing in the manner > a[i][j] > for the (i, j) -th element of multi-dimensional array is well known and > widely used. But how to enable the "standard" matrix notation > a[i, j] > in Python 3.2 in the manner of numpy (and other matrix packages)? Is it > subclassing of "special methods" > > __getitem__() # to get > __setitem__() # to set Yes. class listwrap: def __init__(self, lis): self._list = lis def __getitem__(self, dex): i,j = dex return self._list[i][j] # __setitem__: exercise for reader l = listwrap([[1,2,3],['a','b','c']]) print(l[0,2],l[1,0]) # 3 a IMO, Hardly worth it for two dimensions. -- Terry Jan Reedy From w.g.sneddon at gmail.com Mon May 9 21:33:31 2011 From: w.g.sneddon at gmail.com (python) Date: Mon, 9 May 2011 18:33:31 -0700 (PDT) Subject: Dictionary from String? References: Message-ID: <75c131bb-ac5f-4292-9ae2-b0e3e631cc2e@cu4g2000vbb.googlegroups.com> On May 8, 12:43?pm, Benjamin Kaplan wrote: > On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom wrote: > > Is it possible to create a dictionary from a string value?? Something along > > these lines (but that works): > > >>>> mystring = "{'name':'greg','hatsize':'7 5/8'}" > >>>> mystring > > "{'name':'greg','hatsize':'7 5/8'}" > >>>> dict(mystring) > > Traceback (most recent call last): > > ? File "", line 1, in > > ValueError: dictionary update sequence element #0 has length 1; 2 is > > required > > > I would like to return an undetermined (at call time) number of fields from > > a postgres database (only 1 record) for a given request.? My thought is that > > I could build a dictionary in the form of a string, return the string and > > then convert the string value to a dictionary.? I can do that now, but I > > have to parse the string and then build the dictionary.? Any thoughts or > > help you could provide would be appreciated. > > > --greg > > building the dictionary as a string seems like a hacky thing to do and > you might want to reevaluate your methods. But if everything in the > dict is a literal, you can do ast.literal_eval. > > > > > > > > > > > -- > >http://mail.python.org/mailman/listinfo/python-list There are lots of possibilites and the "best" solution will very based on your strings' structure. List of tuples convert to dict nicely for example. So if your string can be parse to a list of tuples. a = [ (chr(num),num) for num in range(48,58)] [('0', 48), ('1', 49), ('2', 50), ('3', 51), ('4', 52), ('5', 53), ('6', 54), ('7', 55), ('8', 56)] dict(a) {'1': 49, '0': 48, '3': 51, '2': 50, '5': 53, '4': 52, '7': 55, '6': 54, '9': 57, '8': 56} if your string looks something like your example above. The shlex module might be helpful. From w.g.sneddon at gmail.com Mon May 9 21:41:47 2011 From: w.g.sneddon at gmail.com (python) Date: Mon, 9 May 2011 18:41:47 -0700 (PDT) Subject: Dictionary from String? References: <75c131bb-ac5f-4292-9ae2-b0e3e631cc2e@cu4g2000vbb.googlegroups.com> Message-ID: <916ad167-2559-443f-9527-92f827c4603e@m10g2000yqd.googlegroups.com> On May 9, 9:33?pm, python wrote: > On May 8, 12:43?pm, Benjamin Kaplan wrote: > > > > > > > > > > > On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom wrote: > > > Is it possible to create a dictionary from a string value?? Something along > > > these lines (but that works): > > > >>>> mystring = "{'name':'greg','hatsize':'7 5/8'}" > > >>>> mystring > > > "{'name':'greg','hatsize':'7 5/8'}" > > >>>> dict(mystring) > > > Traceback (most recent call last): > > > ? File "", line 1, in > > > ValueError: dictionary update sequence element #0 has length 1; 2 is > > > required > > > > I would like to return an undetermined (at call time) number of fields from > > > a postgres database (only 1 record) for a given request.? My thought is that > > > I could build a dictionary in the form of a string, return the string and > > > then convert the string value to a dictionary.? I can do that now, but I > > > have to parse the string and then build the dictionary.? Any thoughts or > > > help you could provide would be appreciated. > > > > --greg > > > building the dictionary as a string seems like a hacky thing to do and > > you might want to reevaluate your methods. But if everything in the > > dict is a literal, you can do ast.literal_eval. > > > > -- > > >http://mail.python.org/mailman/listinfo/python-list > > There are lots of possibilites and the "best" solution will very based > on your strings' structure. ?List of tuples convert to dict nicely for > example. ?So if your string can be parse to a list of tuples. > > a = [ (chr(num),num) for num in range(48,58)] > [('0', 48), ('1', 49), ('2', 50), ('3', 51), ('4', 52), ('5', 53), > ('6', 54), ('7', 55), ('8', 56)] > dict(a) > {'1': 49, '0': 48, '3': 51, '2': 50, '5': 53, '4': 52, '7': 55, '6': > 54, '9': 57, '8': 56} > if your string looks something like your example above. The shlex > module might be helpful. After re-reading your post saw you were reading from a database. Have you looked at SQLAlchemy? It might have the functionality you are trying to create. From greg.ewing at canterbury.ac.nz Mon May 9 21:49:04 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 10 May 2011 13:49:04 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92rjsiFfsoU1@mid.individual.net> Steven D'Aprano wrote: > It's just that the term "variable" is so useful and so familiar that it's > easy to use it even for languages that don't have variables in the C/ > Pascal/Fortran/etc sense. Who says it has to have the Pascal/Fortran/etc sense? Why should static languages have a monopoly on the use of the term? That seems like a rather languagist attitude! And BTW, applying it to Python is not inconsistent with its usage in Pascal. In the technical vocabulary of Pascal, a "variable" is anything that can appear on the left hand side of an assignment. The analogous term in C is "lvalue". -- Greg From greg.ewing at canterbury.ac.nz Mon May 9 21:51:46 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 10 May 2011 13:51:46 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92rk1jFfsoU2@mid.individual.net> Steven D'Aprano wrote: > Or Chinese Gooseberries, better known by the name thought up by a > marketing firm, "kiwi fruit". And I'm told that there is a language (one of the Nordic ones, IIRC) where "kiwi" means "stone". So in that country they wonder why they should be getting so excited about something called a "stonefruit". :-) -- Greg From sjmachin at lexicon.net Mon May 9 22:27:26 2011 From: sjmachin at lexicon.net (John Machin) Date: Tue, 10 May 2011 12:27:26 +1000 Subject: codecs.open() doesn't handle platform-specific line terminator Message-ID: <3f197ae5a0fbd1da75e8088aa5ba2f52.squirrel@webmail.lexicon.net> According to the 3.2 docs (http://docs.python.org/py3k/library/codecs.html#codecs.open), """Files are always opened in binary mode, even if no binary mode was specified. This is done to avoid data loss due to encodings using 8-bit values. This means that no automatic conversion of b'\n' is done on reading and writing.""" The first point is that one would NOT expect "conversion of b'\n'" anyway. One expects '\n' -> os.sep.encode(the_encoding) on writing and vice versa on reading. The second point is that there is no such restriction with the built-in open(), which appears to work as expected, doing (e.g. Windows, UTF-16LE) '\n' -> b'\r\x00\n\x00' when writing and vice versa on reading, and not striking out when thrown curve balls like '\u0a0a'. Why is codecs.open() different? What does "encodings using 8-bit values" mean? What data loss? From python at mrabarnett.plus.com Mon May 9 22:47:40 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 May 2011 03:47:40 +0100 Subject: What other languages use the same data model as Python? In-Reply-To: <92rk1jFfsoU2@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rk1jFfsoU2@mid.individual.net> Message-ID: <4DC8A74C.7000705@mrabarnett.plus.com> On 10/05/2011 02:51, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> Or Chinese Gooseberries, better known by the name thought up by a >> marketing firm, "kiwi fruit". > > And I'm told that there is a language (one of the > Nordic ones, IIRC) where "kiwi" means "stone". So in > that country they wonder why they should be getting so > excited about something called a "stonefruit". :-) > I had heard something about the meaning of the word "gift", so I checked in Google Translate. For Swedish "gift" it says: noun 1. POISON 2. VENOM 3. TOXIN 4. VIRUS adjective 1. MARRIED 2. WEDDED From steve+comp.lang.python at pearwood.info Mon May 9 23:13:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2011 03:13:12 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: <4dc8ad47$0$29979$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 May 2011 13:49:04 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> It's just that the term "variable" is so useful and so familiar that >> it's easy to use it even for languages that don't have variables in the >> C/ Pascal/Fortran/etc sense. > > Who says it has to have the Pascal/Fortran/etc sense? Why should static > languages have a monopoly on the use of the term? That seems like a > rather languagist attitude! Established usage. They came first, and outnumber us :/ But I wouldn't quite say they have a monopoly of the term. Where there is no risk of misunderstanding, it's fine to use the term. Mathematicians' "variable" is different still, but there's very little risk of misunderstanding. I'm far less cautious about using "variable" when I'm talking to you, because I know you won't be confused, than I would be when talking to a newbie, who may be. When two people use the same words, but their understanding of them are slightly different, it's often easier to change the terminology than it is to break people's preconceptions and connotations. > And BTW, applying it to Python is not inconsistent with its usage in > Pascal. In the technical vocabulary of Pascal, a "variable" is anything > that can appear on the left hand side of an assignment. The analogous > term in C is "lvalue". Sure, but if you think Python "variables" behave like Pascal "variables", you'll may be surprised by Python and wonder why integer arguments are call by value and list arguments are call by reference... -- Steven From wuwei23 at gmail.com Mon May 9 23:30:53 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 9 May 2011 20:30:53 -0700 (PDT) Subject: input() or raw_input() in Console module. References: Message-ID: On May 9, 10:13?pm, ander2_1... at hotmail.com wrote: > I'm using Console module (doc:http://effbot.org/zone/console-handbook.htm, > like nCurses) on Windows, but I don't know how to call a keyboard > input like input() or raw_input(). > What to do? Maybe read the docs, specifically the section titled "Input": get() => event Get the first event from the input queue. The return value is an instance of the Event class. If the input queue is empty, this method blocks. getchar() => event Get the first character event from the input queue, ignoring any other kind of event. The return value is an instance of the KeyPress class. If the input queue is empty, this method blocks. If you've tried playing with these without success, at least post code showing what you've tried, it makes it easier in providing a suitable response. From gagsl-py2 at yahoo.com.ar Mon May 9 23:55:51 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 May 2011 00:55:51 -0300 Subject: Testing tools classification References: <0a6beebc-35b7-4f81-b64b-55c0dbed1bae@h12g2000pro.googlegroups.com> Message-ID: En Sat, 07 May 2011 02:21:02 -0300, rusi escribi?: > There is this nice page of testing tools taxonomy: > http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy > > But it does not list staf: http://staf.sourceforge.net/index.php. The good thing about wikis is, you can add it yourself. -- Gabriel Genellina From cpopa at bitdefender.com Tue May 10 01:51:55 2011 From: cpopa at bitdefender.com (Claudiu Popa) Date: Tue, 10 May 2011 08:51:55 +0300 Subject: Custom string joining In-Reply-To: References: <254518825.20110507153133@bitdefender.com> <4DC84B2E.9090209@free.fr> <354289288.20110509232527@bitdefender.com> Message-ID: <931720564.20110510085155@bitdefender.com> Hello Terry, Thanks, I understand now. Tuesday, May 10, 2011, 2:16:24 AM, you wrote: > On 5/9/2011 4:25 PM, Claudiu Popa wrote: >> I already told in the first post that I've implemented __str__ function, >> but it doesn't seems to be automatically called. > No, Python does not auto-coerce to strings (only between numbers). > You have to be explicit by calling str. Karim's statement "You just have > to implement __str__() python special method for your "custom_objects". > " means that str will then work. >> For instance, the following example won't work: >> >>>>> class a: >> def __init__(self, i): >> self.i = i >> def __str__(self): >> return "magic_function_{}".format(self.i) >>>>> t = a(0) >>>>> str(t) >> 'magic_function_0' >>>>> "".join([t]) > print('\n'.join(str(ob) for ob in [a(0), a(1), a(None)])) > magic_function_0 > magic_function_1 > magic_function_None -- Best regards, Claudiu From akabaila at pcug.org.au Tue May 10 03:22:42 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 10 May 2011 17:22:42 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> <201105101044.28593.akabaila@pcug.org.au> Message-ID: <201105101722.42524.akabaila@pcug.org.au> On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote: > On 5/9/2011 8:44 PM, Algis Kabaila wrote: > > The method of double indexing in the manner > > a[i][j] > > for the (i, j) -th element of multi-dimensional array is > > well known and widely used. But how to enable the > > "standard" matrix notation a[i, j] > > in Python 3.2 in the manner of numpy (and other matrix > > packages)? Is it subclassing of "special methods" > > > > __getitem__() # to get > > > > __setitem__() # to set > > Yes. > > class listwrap: > def __init__(self, lis): > self._list = lis > def __getitem__(self, dex): > i,j = dex > return self._list[i][j] > # __setitem__: exercise for reader > > l = listwrap([[1,2,3],['a','b','c']]) > print(l[0,2],l[1,0]) > # 3 a > > IMO, Hardly worth it for two dimensions. Terry, Thank you for your response. I have to confess that I do have the cludge of an answer to my own quesion, but it is a cludge; Your method looks much better, though I don't think it is complete - this subclassing of __getitem__ appears to stop simple list access, i.e. if li = [1, 2 ,3], it seems to me that print(li[2]) would raise an exception, no? However, the method that you have indicated is a neat way to solve the problem -- thank you for it! OldAl PS: just to confirm your method and the limitation of it "as is": It is NOT a criticism, just a mere observation, Good method, nice examle, great contribution! >>> 3 a Showing limitation of "as is" in this great method for access of list of lists Traceback (most recent call last): File "/dat/work/linalg/dim2.py", line 15, in print(ll[1]) File "/dat/work/linalg/dim2.py", line 6, in __getitem__ i,j = dex TypeError: 'int' object is not iterable >>> -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From akabaila at pcug.org.au Tue May 10 03:32:38 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 10 May 2011 17:32:38 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: <201105101722.42524.akabaila@pcug.org.au> References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> <201105101722.42524.akabaila@pcug.org.au> Message-ID: <201105101732.38838.akabaila@pcug.org.au> On Tuesday 10 May 2011 17:22:42 Algis Kabaila wrote: > On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote: > > On 5/9/2011 8:44 PM, Algis Kabaila wrote: > > > The method of double indexing in the manner > > > a[i][j] > > > for the (i, j) -th element of multi-dimensional array is > > > well known and widely used. But how to enable the > > > "standard" matrix notation a[i, j] > > > in Python 3.2 in the manner of numpy (and other matrix > > > packages)? Is it subclassing of "special methods" > > > > > > __getitem__() # to get > > > > > > __setitem__() # to set > > > > Yes. > > > > class listwrap: > > def __init__(self, lis): > > self._list = lis > > > > def __getitem__(self, dex): > > i,j = dex > > return self._list[i][j] > > > > # __setitem__: exercise for reader > > > > l = listwrap([[1,2,3],['a','b','c']]) > > print(l[0,2],l[1,0]) > > # 3 a > > > > IMO, Hardly worth it for two dimensions. > > Terry, > > Thank you for your response. I have to confess that I do > have the cludge of an answer to my own question, but it is a > cludge; Your method looks much better, though I don't think > it is complete - this subclassing of __getitem__ appears to > stop simple list access, i.e. if li = [1, 2 ,3], it seems to > me that print(li[2]) > would raise an exception, no? > However, the method that you have indicated is a neat way to > solve the problem -- thank you for it! > > OldAl > > PS: just to confirm your method and the limitation of it "as > is": It is NOT a criticism, just a mere observation, Good > method, nice example, great contribution! > > > 3 a > Showing limitation of "as is" in this > great method for access of list of lists > Traceback (most recent call last): > File "/dat/work/linalg/dim2.py", line 15, in > print(ll[1]) > File "/dat/work/linalg/dim2.py", line 6, in __getitem__ > i,j = dex > TypeError: 'int' object is not iterable Apologies for accidental mail sending before it was completed: The original code and additional data is as follows l = listwrap([[1,2,3],['a','b','c']]) print(l[0,2],l[1,0]) print('''Showing limitation of "as is" in this great method for access of list of lists''') ll = listwrap([1,2,3]) print(ll[1]) Above is the output. Thank you again, Al. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Tue May 10 03:41:38 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 10 May 2011 19:41:38 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92s8hlFqn5U1@mid.individual.net> Steven D'Aprano wrote: > All very good, but that's not what takes place at the level of Python > code. It's all implementation. Actually, you're right. What I've presented is a paper-and-pencil implementation of the Python data model. Together with a set of rules for manipulating the diagram under the direction of Python code, you have a complete implementation of Python that you can execute in your head. And you NEED such an implementation in order to reason correctly about Python programs under all circumstances. I find it very difficult to imagine *any* implementation of Python, computer-based or otherwise, that doesn't have something equivalent to references. Whether you call them that, or pointers, or arrows, or object bindings, or something else, the concept needs to be there in some form. > But surely, if a = 1234 creates a reference from a to the big > box 1234, then b = a should create a reference from b to the box a? > > +-------------+ > +---+ | | > a | --+---------------->| | > +---+ | | > ^ +-------------+ > | > +-|-+ > b | | | > +---+ You can't expect anyone to draw correct conclusions from the diagram alone; you also need to explain the rules for manipulating the diagram under control of Python code. Here, the explanation goes something like this: 1. The right hand side of an assignment denotes a big box. The literal 1234 in a program denotes a big box containing the integer value 1234. 2. The left hand side of an assignment denotes a little box. The effect of an assignment is to make the arrow from the left hand side's little box point to the big box denoted by the right hand side. So the assignment a = 1234 results in +-------------+ +---+ | | a | --+---------------->| 1234 | +---+ | | +-------------+ 3. When a name is used on the right hand side, it denotes whichever big box is pointed to by the arrow from its little box. So given the above diagram, the assignment b = a results in +-------------+ +---+ | | a | --+---------------->| 1234 | +---+ | | +-------------+ ^ +---+ | b | --+--------------------- +---+ Furthermore, from rule 2 alone it's evident that no assignment can ever make an arrow lead from one little box to another little box. Arrows can only lead from a little box to a big box. > That's how it works in C and Pascal (well, at least with the appropriate > type declarations). Um, no, it doesn't, really. There's no way 'b = a' can give you that in C; you would have to write 'b = &a'. And you couldn't do it at all in standard Pascal, because there is no equivalent to the & operator there. > Your model is closer to what the CPython implementation > actually does, I think it's close -- actually, I would say isomorphic -- to what *any conceivable* Python implementation would do in some form. > n = len('hello world') > > What about outside len? Where's the little box > pointing to 'hello world'? > So it seems your model fails to deal with sufficiently anonymous objects. Anonymous objects are fine. You just draw a little box and don't write any label beside it. Or you don't bother drawing a little box at all and just draw a big box until such time as some little box that you care about needs to point to it. If that's a problem, then you have the same problem talking about names bound to objects. An anonymous object obviously doesn't have any name bound to it. So you have to admit that objects can exist, at least temporarily, without being bound to anything, or bound to some anonymous thing. > Both the call to len and the call to func push their results onto the > stack. There's no little box pointing to the result. If you want to model things at that level of detail, then the stack itself is an array of little boxes inside a frame object. And the frame object is pointed to by a little box in its calling frame object, etc. until you get to some global little box, that doesn't have a name in Python, but exists somewhere and keeps the chain of active stack frames alive. But you don't have to draw any of that if you don't want to. > For practical reasons, there must be some sort of > indirection. But that's implementation and not the VM's model. No, it's not just implementation. Indirection is needed for *correct semantics*, not just practicality. > There is a problem with my model of free-floating objects in space: it > relies on objects being able to be in two places at once, Yes, that's the point I'm trying to make. While it might be possible to make such a model work, it would require bizarre contortions that actually obscure what is going on instead of clarifying it. Trying to teach someone about Python using a model like that would be actively harmful, and probably vilolate several human rights conventions. > But if you're a science fiction fan from way back, > then you won't have any problem with the idea that objects can be inside > themselves: > > http://www.youtube.com/watch?v=51JtuEa_OPc Yeah, it's fun to play around with ideas like that precisely because they twist our brains into knots. But it's not a good way to explain Python semantics clearly! > Now, that's a good challenge for your model. Little boxes only point to > big boxes. So how do you model cycles, including lists that contain > themselves? I'll answer your next question first, and come back to that. >> +---+ +---+ >> a | --+----->| | +-------------+ >> +---+ +---+ | | >> | --+----->| | >> +---+ | | >> | | +-------------+ >> +---+ > > But that's wrong! Names (little boxes) can't point to *slots in a list*, The arrow from a is to be understood as pointing to the whole list, not any particular little box within the list. If you want to clarify that, you can embellish the big boxes with some kind of header area and point to that instead. +---+ a | --+----->/---\ +---+ +---+ | | +---+ | --+----->/-------------\ +---+ +-------------+ | | | | +---+ | | | | +-------------+ Now, a list that "contains" itself: -------- | | +---+ V | a | --+----->/---\ | +---+ +---+ | | | | +---+ | | --+----- +---+ | | +---+ > But I wouldn't do it like that. I'd do it like this: > > 0 1 2 3 4 > +--------+--------+--------+--------+--------+ > a | | | | | | > | | | | | | > | | | | | | > +--------+--------+--------+--------+--------+ But then you can't model two list items bound to the same object, unless you invoke the two-places-at-once idea. Even then, you would have trouble unambiguously indicating that boxes draw in two places are mean to actually represent the *same* object as against two different objects with equal values. > Why are the boxes so > small? Just because. Why can't you carefully tease the thread of blutack > apart, into a bifurcated Y shaped thread? Just because. Yes, it's probably just as good to leave it as an arbitrary rule that a little box can only point to one big box at a time. -- Greg From tjreedy at udel.edu Tue May 10 03:44:44 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 May 2011 03:44:44 -0400 Subject: How to access elemenst in a list of lists? In-Reply-To: <201105101722.42524.akabaila@pcug.org.au> References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> <201105101044.28593.akabaila@pcug.org.au> <201105101722.42524.akabaila@pcug.org.au> Message-ID: On 5/10/2011 3:22 AM, Algis Kabaila wrote: > On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote: > > class listwrap: > > def __init__(self, lis): > > self._list = lis > > def __getitem__(self, dex): > > i,j = dex > > return self._list[i][j] > > > # __setitem__: exercise for reader > > l = listwrap([[1,2,3],['a','b','c']]) > > print(l[0,2],l[1,0]) > > # 3 a > Thank you for your response. I have to confess that I do have the cludge > of an answer to my own quesion, but it is a cludge; Your method looks > much better, though I don't think it is complete - this subclassing of > __getitem__ appears to stop simple list access, i.e. if li = [1, 2 ,3], > it seems to me that print(li[2]) would raise an exception, no? Yes, there really should be a guard condition: if isinstance(x tuple) or try: len(x) == 2. A __getattr__ method could be added to forwar other list methods to the wrapped list. One could try subclassing instead of wrapping, but some special methods have a fast path access for builtins that bypasses subclass methods. I think __getitem__ may be one such. Wrapping is safe in that respect. -- Terry Jan Reedy From jeanmichel at sequans.com Tue May 10 05:34:10 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 10 May 2011 11:34:10 +0200 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: <4DC90692.50903@sequans.com> James Mills wrote: > On Tue, May 10, 2011 at 10:40 AM, Kyle T. Jones > wrote: > >> It has been hard for me to determine what would constitute overuse. >> > > A rule of thumb I always follow and practice is: > > "Let the error lie where it occurred." > > or > > "Don't hide errors.". > > It's good practice to follow IHMO as it makes it easier to find > the source of defects in your function(s). If you constantly > do things like try/except/log then it makes finding the source > harder and may make it harder to identify what caused it. > You can reraise the exception without loosing the stack trace. try: ... except SomeException, exc: log(exc) print 'Hello world' raise # "raise exc" would loose the original stack trace JM PS : "code that crashes could use improvement, but incorrect code that doesn?t crash is a horrible nightmare." (I don't know the author) From rosuav at gmail.com Tue May 10 05:35:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 May 2011 19:35:22 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: <92s8hlFqn5U1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> <92s8hlFqn5U1@mid.individual.net> Message-ID: On Tue, May 10, 2011 at 12:29 AM, Steven D'Aprano wrote: > If objects can be in two places at once, why can't names? Just because. Because then you'd need some way to identify which object you wanted to refer to - something like name[0] and name[1]. A tuple is one effective way to do this (sort of - actually, the name points at the tuple and the tuple points at each of the objects). On Tue, May 10, 2011 at 12:47 PM, MRAB wrote: > I had heard something about the meaning of the word "gift", so I > checked in Google Translate. For Swedish "gift" it says: > > noun > 1. POISON > 2. VENOM > 3. TOXIN > 4. VIRUS Beware of Swedes bearing gifts! On Tue, May 10, 2011 at 5:41 PM, Gregory Ewing wrote: > Anonymous objects are fine. You just draw a little box and > don't write any label beside it. Or you don't bother drawing > a little box at all and just draw a big box until such time > as some little box that you care about needs to point to it. > > If that's a problem, then you have the same problem talking > about names bound to objects. An anonymous object obviously > doesn't have any name bound to it. So you have to admit that > objects can exist, at least temporarily, without being bound > to anything, or bound to some anonymous thing. There has to be a way to get from some mythical "home" location (which we know in Python as locals()+globals()+current expression - the "current namespace") to your object. That might involve several names, or none at all, but if there's no such path, the object is unreferenced and must be disposed of. IIRC that's not just an implementation detail (the garbage collector), but a language guarantee (that the __del__ method will be called). Names are immaterial to that. Chris Angelico From nobody at nowhere.net.no Tue May 10 06:06:02 2011 From: nobody at nowhere.net.no (TheSaint) Date: Tue, 10 May 2011 18:06:02 +0800 Subject: A suggestion for an easy logger References: <863052b3-3b6f-482e-820a-ec1278b81b19@glegroupsg2000goo.googlegroups.com> <06491221-3c68-48ca-ad9c-9cb8c171b1ed@w24g2000yqb.googlegroups.com> <7508a36a-5d27-49a7-8572-c9bba3d2c61e@h12g2000pro.googlegroups.com> Message-ID: Vinay Sajip wrote: > No, you can pass keyword arguments in any order - that's what makes > them keyword, as opposed to positional, arguments. I getting puzzled :) ==================================code================================== myself at laptop-~> python Python 3.2 (r32:88445, Apr 15 2011, 11:09:05) [GCC 4.5.2 20110127 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import logging, sys >>> logging.basicConfig(level=logging.DEBUG, format='%(message)s') >>> sh = logging.StreamHandler(sys.stdout) >>> sh.terminator = '' >>> logging.getLogger().addHandler(sh) >>> logging.debug('here we are') here we are here we are>>> print(logging.__version__) 0.5.1.2 ==================================code================================== Terminator is removed, but as you stated it's doing double print-out One more point is, if you'd have the time to look back to one of the first posts, that the leading *"DEBUG:root:"* doesn't show :-/ It's reported herein the version of Python and logging module's version. For my thinking I'd go to look into the code and docs as well, to understand what I should do to have my 4 way of logging. I repeat, I'm very new on using logging module, but I should go in that way, it isn't necessary to re-invent the wheel :). Also I'd like to say that's only for my own learning, which I do as hobby. -- goto /dev/null From rosuav at gmail.com Tue May 10 06:33:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 May 2011 20:33:12 +1000 Subject: can't get urllib2 or httplib to work with tor & privoxy In-Reply-To: References: Message-ID: On Tue, May 10, 2011 at 4:20 AM, Bob Fnord wrote: > Both methods give me a 503 error... As a networking geek, my first thought would be to fire up a tiny little "snoop server" and see what, exactly, the two methods are doing. (Ignore the HTTPS options as they're more complicated to snoop on; you're almost certainly going to see exactly the same on the HTTP.) A snoop server is simply an HTTP server that dumps its requests to stdout or a file, utterly raw. You can write one in Python fairly easily, or use another program; if I'm working on Windows, I'll generally use my own RosMud MUD client, but you'll be able to whip up a cross-platform one in half a page of code in any decent high level language. I recommend you work at the sockets level, rather than using an HTTP library, unless you have one that can emit the entire request, exactly as it came from the client. Once you've found the difference(s) between Lynx and your script, you can see what's causing the 503 (Service Unavailable) error; it may be that you need to authenticate with the proxy. Chris Angelico From akabaila at pcug.org.au Tue May 10 07:11:09 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 10 May 2011 21:11:09 +1000 Subject: How to access elemenst in a list of lists? In-Reply-To: References: <4dc75c67$0$29896$c3e8da3$5496439d@news.astraweb.com> <201105101722.42524.akabaila@pcug.org.au> Message-ID: <201105102111.09577.akabaila@pcug.org.au> On Tuesday 10 May 2011 17:44:44 Terry Reedy wrote: > On 5/10/2011 3:22 AM, Algis Kabaila wrote: > > On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote: > > > class listwrap: > > > def __init__(self, lis): > > > self._list = lis > > > > > > def __getitem__(self, dex): > > > i,j = dex > > > return self._list[i][j] > > > > > > # __setitem__: exercise for reader > > > > > > l = listwrap([[1,2,3],['a','b','c']]) > > > print(l[0,2],l[1,0]) > > > # 3 a > > > > Thank you for your response. I have to confess that I do > > have the cludge of an answer to my own quesion, but it is > > a cludge; Your method looks much better, though I don't > > think it is complete - this subclassing of __getitem__ > > appears to stop simple list access, i.e. if li = [1, 2 > > ,3], it seems to me that print(li[2]) would raise an > > exception, no? > > Yes, there really should be a guard condition: if > isinstance(x tuple) or try: len(x) == 2. A __getattr__ > method could be added to forwar other list methods to the > wrapped list. One could try subclassing instead of wrapping, > but some special methods have a fast path access for > builtins that bypasses subclass methods. I think __getitem__ > may be one such. Wrapping is safe in that respect. Actually, I am working on an array class that subclasses list. My interest is to have a module that deals with matrices with pure Python 3.2 or higher. The class would need to deal with many different arrays and matrix operations between them. In since Array subclasses list, any modifications of __getitem__ ir __setitem__ would naturally be in the array class and would in fact subclass the list special methods if implemented in the Array class. And, to my chagrin, I do manage to mess it up... Thanks for your bright suggestion, OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Tue May 10 07:36:42 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 10 May 2011 07:36:42 -0400 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: <1305027402.3751.11.camel@linux-yu4c.site> On Mon, 2011-05-09 at 19:40 -0500, Kyle T. Jones wrote: > It has been hard for me to determine what would constitute overuse. The chronic problem is under use; so I wouldn't worry much about it. try/except should occur as often as is required for the application to either deal gracefully with the condition or report *meaningful* error messages to the user/administrator. From hg at schaathun.net Tue May 10 08:10:11 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 10 May 2011 13:10:11 +0100 Subject: Overuse of try/except/else? References: Message-ID: <3imn98-6r3.ln1@svn.schaathun.net> On Tue, 10 May 2011 07:36:42 -0400, Adam Tauno Williams wrote: : On Mon, 2011-05-09 at 19:40 -0500, Kyle T. Jones wrote: : > It has been hard for me to determine what would constitute overuse. : : The chronic problem is under use; so I wouldn't worry much about it. : : try/except should occur as often as is required for the application to : either deal gracefully with the condition or report *meaningful* error : messages to the user/administrator. So overuse is really when you cannot do anything meaningful about the exception. The two interesting questions are really 1. where and when to catch a given exception 2. at what stage of the development cycle catching a particular (class of) exception should become a priority There is a potential overuse of exceptions, where they are used for quite ordinary and frequent (i.e. not exceptional) conditions, and the information could be passed through the return value instead. Exceptions is a very flexible, but also rather expensive means of communications. You can, actually, write any program using raise instead of return. That would be overuse. -- :-- Hans Georg From rustompmody at gmail.com Tue May 10 08:32:31 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 10 May 2011 05:32:31 -0700 (PDT) Subject: Testing tools classification References: <0a6beebc-35b7-4f81-b64b-55c0dbed1bae@h12g2000pro.googlegroups.com> Message-ID: <8073828a-e871-4b06-b4f2-0abf247c5e34@q12g2000prb.googlegroups.com> On May 10, 8:55?am, "Gabriel Genellina" wrote: > En Sat, 07 May 2011 02:21:02 -0300, rusi escribi?: > > > There is this nice page of testing tools taxonomy: > >http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy > > > But it does not list staf:http://staf.sourceforge.net/index.php. > > The good thing about wikis is, you can add it yourself. > > -- > Gabriel Genellina Could not figure out how to get edit rights. [Which is all for the good considering what a testing-ignoramus I am :-) ] From invalid at invalid.invalid Tue May 10 10:05:34 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 May 2011 14:05:34 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On 2011-05-10, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> It's just that the term "variable" is so useful and so familiar that it's >> easy to use it even for languages that don't have variables in the C/ >> Pascal/Fortran/etc sense. > > Who says it has to have the Pascal/Fortran/etc sense? Because it's easier to communicate if everybody agrees on what a word means. -- Grant Edwards grant.b.edwards Yow! The SAME WAVE keeps at coming in and COLLAPSING gmail.com like a rayon MUU-MUU ... From rosuav at gmail.com Tue May 10 10:43:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 00:43:33 +1000 Subject: string formatting In-Reply-To: <4dc94897$0$18589$426a74cc@news.free.fr> References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc3e52a$0$24510$426a74cc@news.free.fr> <4dc94897$0$18589$426a74cc@news.free.fr> Message-ID: On Wed, May 11, 2011 at 12:15 AM, Web Dreamer wrote: > I was unsure of the difference between deprecated and obsolete. > > So now, if I understand well, obsolete comes before deprecated, such that if > a feature is obsolete it will be deprecated in an unknown future, after > which it will be removed once it has been deprecated (a certain time after > it was rendered obsolete)? > (might need an aspirin to read that one :-) ) > > So If I'm right, old string formatting "could" one day be deprecated but it > is not yet? I wouldn't say that obsolete features "will be" deprecated. That expression makes little sense (I know, for I have seen it in eBay's API documentation, and it did not fill me with joy). Deprecation is (usually) a formal procedure that clearly states that a feature should not be used. It may be accompanied by a strict cutoff ("will be removed in version X"), or just left vague, but linting tools can identify all use of deprecated features. Obsolete, however, is simply a description. Sopwith Camels were obsolete in the second world war, and VHS has been obsoleted by optical disc media. However, if you wish to fly a Camel or play a VHS, nothing's stopping you. The sky will still accept your Camel, and your VHS player will still talk to your television. (The analogy breaks down a bit in that your obsolete VHS player may be using a deprecated cabling style, but it's coax that's deprecated, not VHS.) There's no "projected end date" for them. Generally, a feature is obsolete before it's deprecated, but technically that's not a requirement, and API designers can sometimes be quite arbitrary. On the other hand, obsolescence is quite informal, and people can disagree about whether or not something is. (Hi Ken, your continued use of inches is noted. Thank you.) Chris Angelico From hg at schaathun.net Tue May 10 11:09:14 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 10 May 2011 16:09:14 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On Tue, 10 May 2011 14:05:34 +0000 (UTC), Grant Edwards wrote: : Because it's easier to communicate if everybody agrees on what a word : means. Why should we agree on that particular word? Are there any other words we agree about? Other key words, such as class, object, or function don't have universal meanings. :-) -- :-- Hans Georg From invalid at invalid.invalid Tue May 10 11:16:10 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 May 2011 15:16:10 +0000 (UTC) Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On 2011-05-10, Hans Georg Schaathun wrote: > On Tue, 10 May 2011 14:05:34 +0000 (UTC), Grant Edwards > wrote: >: Because it's easier to communicate if everybody agrees on what a word >: means. > > Why should we agree on that particular word? Are there any other words > we agree about? Other key words, such as class, object, or function don't > have universal meanings. And what do we mean by "agree"? What do we mean by "mean"? It's turtles all they down... -- Grant Edwards grant.b.edwards Yow! at gmail.com From rosuav at gmail.com Tue May 10 11:27:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 01:27:36 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On Wed, May 11, 2011 at 1:16 AM, Grant Edwards wrote: > And what do we mean by "agree"? > > What do we mean by "mean"? > > It's turtles all they down... When I use a word, it means just what I choose it to mean - neither more nor less. -- Humpty Dumpty. Language is for communication. If we're not using the same meanings for words, we will have problems. Chris Angelico PS. By "mean", I mean average. Except when I mean mean. But now I'm just being mean. From hg at schaathun.net Tue May 10 11:40:05 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 10 May 2011 16:40:05 +0100 Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On Wed, 11 May 2011 01:27:36 +1000, Chris Angelico wrote: : Language is for communication. If we're not using the same meanings : for words, we will have problems. So if you adopt the word class to mean a type (or composite type), as in python, what word would you use for a class of types (as in haskell or ada)? I think there are too many meanings and too few words ... That's why some languages support overloading. I am afraid we just need to cope with it, overloading I mean. -- :-- Hans Georg From rosuav at gmail.com Tue May 10 11:44:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 01:44:03 +1000 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <87mxj2f8f4.fsf@benfinney.id.au> <4dc2c582$0$29991$c3e8da3$5496439d@news.astraweb.com> <92rjsiFfsoU1@mid.individual.net> Message-ID: On Wed, May 11, 2011 at 1:40 AM, Hans Georg Schaathun wrote: > On Wed, 11 May 2011 01:27:36 +1000, Chris Angelico > ? wrote: > : ?Language is for communication. If we're not using the same meanings > : ?for words, we will have problems. > > So if you adopt the word class to mean a type (or composite type), > as in python, what word would you use for a class of types (as in > haskell or ada)? > > I think there are too many meanings and too few words ... > > That's why some languages support overloading. Of course. Nobody ever said that one name had to point to one value... oh wait. Yes, Virginia, there is overloading. Chris Angelico From hg at schaathun.net Tue May 10 11:49:52 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 10 May 2011 16:49:52 +0100 Subject: scipy References: <0ea8c722-1af7-4a96-b1d7-5213c63b5a54@u15g2000vby.googlegroups.com> Message-ID: <0e3o98-t84.ln1@svn.schaathun.net> On Sun, 8 May 2011 03:44:06 -0700 (PDT), pb wrote: : I', having trouble with scipy. I have followed the instructions at : scipy website and have installed the following on my mac osx 10.6.6 : (...) : I'm assuming I have the wrong version of something, would that be : right? : Does anyone know how I can fix this? I had the same problem, but assumed that it was more likely to be a bug in the unit tests than a bug anywhere else. But then I mainly use linux boxen to run the stuff, so a bug on the mac installation does not bother me much. Installing software on a mac is just painful. -- :-- Hans Georg From rustompmody at gmail.com Tue May 10 12:41:19 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 10 May 2011 09:41:19 -0700 (PDT) Subject: Non Programming in python References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: Sorry for a silly subject change: A better one will be welcome -- cant think of a name myself. There is this whole area of python that may be called the non- programming side of programming: Is there some central site where all such is put up? What if any should such a bundle of things be called? ------------------------------------------------- | Area | Tool(s) | |------------------+------------------------| | packaging | distutils, setuptools, | | | distutils2, distribute | | | Native tools (eg apt) | | versioning | hg, git, bzr | | multiple pythons | virtualenv | | ?? | tox | | testing | unittest, nose, pytest | | build | scons, make... | | deployment | fabric | ------------------------------ * Primary Development tools/aids 1. Help 2. Completion ('intellisense') 3. Tags (Jumping) 4. Refactoring 5. Integration with 'non-programming' above (eg VCSes, packagers etc) * Other Development Tools - Debugger - Profiler - Heap Profiler - Coverage From claird271 at gmail.com Tue May 10 12:45:43 2011 From: claird271 at gmail.com (Cameron Laird) Date: Tue, 10 May 2011 09:45:43 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (May 10) Message-ID: [This content provided by Gabriel Genellina, despite what the "From:" line says.] QOTW: "Often, the cleverness of people is inversely proportional to the amount of CPU power and RAM that they have in their computer. Unfortunately, the difficulty in debugging and maintaining code is often directly proportional to the cleverness exhibited by the original programmer." - Irmen de Jong and Grant Edwards http://groups.google.com/group/comp.lang.python/t/58559ead6dc82448 Looking for "The Coolest Python Recipe of All Times": http://groups.google.com/group/comp.lang.python/t/141fdde77caab932 A nice and clever probabilistic data structure: http://groups.google.com/group/comp.lang.python/t/58559ead6dc82448 Development tools and best practices (continued from previous week): http://groups.google.com/group/comp.lang.python/t/836537e6c25cf027 Things to be aware of when using dictionary views: http://groups.google.com/group/comp.lang.python/t/b9c6ded7522e7425 Python3 and absolute/relative imports: http://groups.google.com/group/comp.lang.python/t/9470dbdacc138709 Another gotcha when using import with packages: http://groups.google.com/group/comp.lang.python/t/961a90219a61e19d Fibonacci, recursion, and the 'P' conspiracy theory: http://groups.google.com/group/comp.lang.python/t/b713b14e3e0d9872 The preferred way for string formatting: http://groups.google.com/group/comp.lang.python/t/f0cd2717ffe13560 Checking if a list is empty - and how to think "the Python way": http://groups.google.com/group/comp.lang.python/t/d36dcd2e2e175d1e Classics never die: What other languages use the same data model as Python? http://groups.google.com/group/comp.lang.python/t/4b8b0e06a2d5cfcc ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- From ethan at stoneleaf.us Tue May 10 13:18:53 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 10 May 2011 10:18:53 -0700 Subject: Dictionary Views -- good examples? [was Re: Python 3 dict question] In-Reply-To: References: <777641c8-4928-4e49-832a-6a4a076628d1@o26g2000vby.googlegroups.com> <4DC47B04.9070007@stoneleaf.us> Message-ID: <4DC9737D.1040608@stoneleaf.us> Ian Kelly wrote: > On Fri, May 6, 2011 at 4:49 PM, Ethan Furman wrote: >> Anybody care to chime in with their usage of this construct? > > You should start with PEP 3106. The main idea is that dict.keys() and > dict.items() can be treated as frozensets, while still being more > lightweight than lists. That lets you do nifty things like "a.keys() > == b.keys()" which, if a and b are Python 3 dicts, will tell you > whether they contain the same keys. Cool, thanks. ~Ethan~ From python at rcn.com Tue May 10 13:20:27 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 10 May 2011 10:20:27 -0700 (PDT) Subject: string formatting References: Message-ID: > Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old style. (2) and (3) are new but (3) is only > supported from Python 2.7+. > > Which one should be used? Sometimes, I use both ;-) That can save you from ugly escapes such as %%s or {{0}}. Here's an example from the standard library: http://hg.python.org/cpython/file/7254c03b7180/Lib/collections.py#l235 Note the template has both {typename} formatting for the first pass and %r style formatting in the generated code. Raymond ------------ follow my tips and recipes on twitter: @raymondh From python at rcn.com Tue May 10 13:25:54 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 10 May 2011 10:25:54 -0700 (PDT) Subject: Python 3 dict question References: Message-ID: <36fba210-18e8-4e9f-8de3-7386ecaf6a21@s16g2000prf.googlegroups.com> On May 6, 12:40?pm, dmitrey wrote: > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterator. > Of course, I could use > for key, val in myDict.items(): > ? ?do_something > ? ?break > but maybe there is any better way? If your use case allows the item to be removed, then use: key, val = myDict.popitem() Otherwise, use: key, val = next(iter(MyDict.items())) The latter is nice because next() allows you to supply a default argument in case the dictionary is emtpy: key, val = next(iter(MyDict.items()), (None, None)) Raymond --------- follow my tips and recipes on twitter: @raymondh From hg at schaathun.net Tue May 10 14:31:54 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Tue, 10 May 2011 19:31:54 +0100 Subject: vertical ordering of functions References: Message-ID: On Tue, 3 May 2011 18:08:27 -0400, Jabba Laci wrote: : I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch. : 5 he says that a function that is called should be below a function : that does the calling. This creates a nice flow down from top to : bottom. My advice would be to order it in the same way as you would if you were presenting the algorithm in a paper. >From such a viewpoint, it depends on whether you consider the called names to be terms which need definitions, or operations with an intutive purpose, merely requiring an explanation (implentation) of how it is done. In a paper that means that definitions must come before the theorems and lemmata very often between the theorem and its proof. If you don't write papers, that may not be particularly useful :-) In programming, it means that names which have self-explanatory name may very well be called first and defined later. The caller will give a high-level view of what is going on. The callees are building blocks whose purpose can be understood immediately, and whose inner workings can be sought further down the file. Fundamental definitions which may be as easy to implement as explain may often come first. The question here, is didactics and not programming per se. A simple rule does not make complex code significantly easier to read, but a thought structure of the code (with comments and choice of names) over-all does. And let's not forget that calls may be circular or otherwise convolved in a way that does not allow consistent sorting of caller before/after callee. -- :-- Hans Georg From jean_paez at hotmail.es Tue May 10 14:51:03 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?SmVhbiBDYXJsb3MgUOFleiBSYW3tcmV6?=) Date: Tue, 10 May 2011 13:51:03 -0500 Subject: This it is the code of tmb_import.py (to matter of .tmb to blender) I need tmb_exporter.py (to export of blender to .tmb) Thanks. In-Reply-To: References: , , Message-ID: I need help. Hello. The attached file is script of blender fact in python that .tmb serves to concern archives (secondly attached file), unloadings to blender and uses script and concerns the second file that you shipment you see so that it. Everything can be published and, but it is not possible to be exported again to .tmb To unload in this Link: http://www.blender.org/ script: http://www.mediafire.com/?clmdgkymsfooddd secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 PD: I need script to export in extension .tmb Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue May 10 15:18:52 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 May 2011 15:18:52 -0400 Subject: What other languages use the same data model as Python? In-Reply-To: <92s8hlFqn5U1@mid.individual.net> References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> <92s8hlFqn5U1@mid.individual.net> Message-ID: On 5/10/2011 3:41 AM, Gregory Ewing wrote: > Actually, you're right. What I've presented is a paper-and-pencil > implementation of the Python data model. Together with a set of > rules for manipulating the diagram under the direction of Python > code, you have a complete implementation of Python that you can > execute in your head. I think that it would be both fun and useful to have an animated graphical tutorial that used and box and arrow model. Names should be in ovals (instead of the little boxes used here due to text limitations) to differentiate them from objects. Immutable objects could have solid boundaries and mutables a broken line boundary. Collection objects would have dotted lines to separate slots. Ovals could also use different lines for builtins, globals, and locals. > And you NEED such an implementation in order to reason correctly > about Python programs under all circumstances. > > I find it very difficult to imagine *any* implementation of > Python, computer-based or otherwise, that doesn't have something > equivalent to references. Whether you call them that, or pointers, > or arrows, or object bindings, or something else, the concept > needs to be there in some form. Since namespaces link names in a namespace with objects not in the namespace, any practical implementation needs a third entity to link or associated each name with an object. This is pretty much needed to explain multiple links without objects being in multiple locations. It is also needed to explain how an object can link to itself. -- Terry Jan Reedy From tjreedy at udel.edu Tue May 10 15:28:27 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 May 2011 15:28:27 -0400 Subject: Non Programming in python In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: On 5/10/2011 12:41 PM, rusi wrote: > Sorry for a silly subject change: A better one will be welcome -- cant > think of a name myself. Associated tools. I might separate them into development tools (up to the production of python.exe) and usage tools (everything thereafter). On Windows, this is a pretty clean separation. On Linux, less so since users sometimes build their own binaries and therefore use some of the development tools. Assuming that there is not one already, this could be the beginning of a useful overview wiki page with links to existing pages on the specific topics ('areas') listed below. > There is this whole area of python that may be called the non- > programming side of programming: > > Is there some central site where all such is put up? > What if any should such a bundle of things be called? > > ------------------------------------------------- > > | Area | Tool(s) | > |------------------+------------------------| > | packaging | distutils, setuptools, | > | | distutils2, distribute | > | | Native tools (eg apt) | > | versioning | hg, git, bzr | > | multiple pythons | virtualenv | > | ?? | tox | > | testing | unittest, nose, pytest | > | build | scons, make... | > | deployment | fabric | > > ------------------------------ I would reorder this list in the typical order used, starting with editors. > * Primary Development tools/aids > > 1. Help > 2. Completion ('intellisense') > 3. Tags (Jumping) > 4. Refactoring > 5. Integration with 'non-programming' above (eg VCSes, packagers > etc) > > * Other Development Tools > - Debugger > - Profiler > - Heap Profiler > - Coverage -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Tue May 10 18:47:46 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 11 May 2011 10:47:46 +1200 Subject: What other languages use the same data model as Python? In-Reply-To: References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <77f64071-b288-404c-8280-b2c61ba77f06@n10g2000yqf.googlegroups.com> <4dc12fb4$0$29991$c3e8da3$5496439d@news.astraweb.com> <7q1898-f3l.ln1@svn.schaathun.net> <9fd898-0el.ln1@svn.schaathun.net> <92f70aF9pqU1@mid.individual.net> <92kh9cFgdcU1@mid.individual.net> <4dc5fd42$0$29991$c3e8da3$5496439d@news.astraweb.com> <92os6dF5jbU1@mid.individual.net> <4dc7fa2f$0$29991$c3e8da3$5496439d@news.astraweb.com> <92s8hlFqn5U1@mid.individual.net> Message-ID: <92ttklFqs3U1@mid.individual.net> Chris Angelico wrote: > There has to be a way to get from some mythical "home" location (which > we know in Python as locals()+globals()+current expression - the > "current namespace") to your object. That might involve several names, > or none at all, but if there's no such path, the object is > unreferenced and must be disposed of. Yes, that's what I mean by "bound to some anonymous thing". Somewhere in the implementation there must be one or more "root" references, but they don't necessarily have any names that you can refer to from Python. When I say "not bound to any name", I just mean that it's okay to leave some bindings out of your diagram if they're not pertinent to what you're trying to illustrate. For example, you can draw a box representing a string object and trust that something will keep it alive long enough for you to draw an arrow to it from the name you're assigning it to. -- Greg From steve+comp.lang.python at pearwood.info Tue May 10 18:53:54 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2011 22:53:54 GMT Subject: Non Programming in python References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <4dc9c202$0$29991$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 May 2011 09:41:19 -0700, rusi wrote: > Sorry for a silly subject change: A better one will be welcome -- cant > think of a name myself. > > There is this whole area of python that may be called the non- > programming side of programming: > > Is there some central site where all such is put up? What if any should > such a bundle of things be called? Documentation. Check the Python wiki. -- Steven From drsalists at gmail.com Tue May 10 19:00:40 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 10 May 2011 16:00:40 -0700 Subject: Python backup programs? Message-ID: What are your favorite backup programs written, in whole or in part, in Python? What do you like about them? Dislike about them? Are there any features you wish your backup program had, whether in Python or not? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Tue May 10 19:57:48 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 11 May 2011 09:57:48 +1000 Subject: Python backup programs? In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 9:00 AM, Dan Stromberg wrote: > > What are your favorite backup programs written, in whole or in part, in > Python? > > What do you like about them?? Dislike about them? > > Are there any features you wish your backup program had, whether in Python > or not? Recently I wrote a simple backup system for a client using a mixture of Python and Bash using rsync, ssh and pptp. (Not packaged well enough to show source though) It works very well and does the job. cheers James -- -- James Mills -- -- "Problems are solved by method" From gagsl-py2 at yahoo.com.ar Tue May 10 21:30:03 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 May 2011 22:30:03 -0300 Subject: This it is the code of tmb_import.py (to matter of .tmb to blender) I need tmb_exporter.py (to export of blender to .tmb) Thanks. References: Message-ID: En Tue, 10 May 2011 15:51:03 -0300, Jean Carlos P?ez Ram?rez escribi?: > The attached file is script of blender fact in python that .tmb serves to > concern archives (secondly attached file), unloadings to blender and uses Por lo que pude entender, tu problema es bastante espec?fico de Blender, as? que tal vez te convenga preguntar en un foro como: http://www.g-blender.org/ (espec?ficamente dedicado a Blender 3D en espa?ol) Tambi?n est? la comunidad de Python Argentina: http://python.org.ar/pyar/ (busca la lista de correo) Suerte! -- Gabriel Genellina From paulprobert at sbcglobal.net Tue May 10 23:26:18 2011 From: paulprobert at sbcglobal.net (Paul Probert) Date: Tue, 10 May 2011 22:26:18 -0500 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: On 05/09/2011 07:40 PM, Kyle T. Jones wrote: > > It has been hard for me to determine what would constitute overuse. > > Cheers. Well, for me the power of exceptions is that it lets me write much more concise code. For example, suppose I call a routine I wrote over and over, and I have to check for errors on each call. Then you have a long block of code like: if err == 0: x1,err=somefunction(1) if err == o: x2,err=somefunction(2) ... ... but if somefunction just raises an exception on error, then you do try: x1=somefunction(1) x2=somefunction(2) ... ... except: blah blah So for my uses, its handy to let things raise exceptions willy nilly in the lower level functions, and do the catching in the higher level function. Paul Probert From rustompmody at gmail.com Tue May 10 23:36:43 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 10 May 2011 20:36:43 -0700 (PDT) Subject: Non Programming in python References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: <56535cf9-1b78-4150-9013-24c891753bc8@h12g2000pro.googlegroups.com> On May 11, 12:28?am, Terry Reedy wrote: > On 5/10/2011 12:41 PM, rusi wrote: > > > Sorry for a silly subject change: A better one will be welcome -- cant > > think of a name myself. > > Associated tools. I might separate them into development tools (up to > the production of python.exe) and usage tools (everything thereafter). > On Windows, this is a pretty clean separation. On Linux, less so since > users sometimes build their own binaries and therefore use some of the > development tools. Can you elaborate? I dont understand > > Assuming that there is not one already, this could be the beginning of a > useful overview wiki page with links to existing pages on the specific > topics ('areas') listed below. > > > > > There is this whole area of python that may be called the non- > > programming side of programming: > > > Is there some central site where all such is put up? > > What if any should such a bundle of things be called? > > > ------------------------------------------------- > > > ? ?| Area ? ? ? ? ? ? | Tool(s) ? ? ? ? ? ? ? ?| > > ? ?|------------------+------------------------| > > ? ?| packaging ? ? ? ?| distutils, setuptools, | > > ? ?| ? ? ? ? ? ? ? ? ?| distutils2, distribute | > > ? ?| ? ? ? ? ? ? ? ? ?| Native tools (eg apt) ?| > > ? ?| versioning ? ? ? | hg, git, bzr ? ? ? ? ? | > > ? ?| multiple pythons | virtualenv ? ? ? ? ? ? | > > ? ?| ?? ? ? ? ? ? ? ? | tox ? ? ? ? ? ? ? ? ? ?| > > ? ?| testing ? ? ? ? ?| unittest, nose, pytest | > > ? ?| build ? ? ? ? ? ?| scons, make... ? ? ? ? | > > ? ?| deployment ? ? ? | fabric ? ? ? ? ? ? ? ? | > > > ------------------------------ > > I would reorder this list in the typical order used, starting with editors. > > > * Primary Development tools/aids > > > ? ?1. Help > > ? ?2. Completion ('intellisense') > > ? ?3. Tags (Jumping) > > ? ?4. Refactoring > > ? ?5. Integration with 'non-programming' above (eg VCSes, packagers > > etc) > > > * Other Development Tools > > ? ?- Debugger > > ? ?- Profiler > > ? ?- Heap Profiler > > ? ?- Coverage Some more 'areas': 1. Which python 'form' does one use? At the least python vs pythonw on windows. But more generally scripting vs REPL. In REPL python vs ipython Note 1. I am often unnerved by how even experienced python programmers think that the only way to 'do' python is like C -- write a main, not appreciating the luxury of an unstructured, exploratory mode that an REPL makes possible. Note 2. ruby makes this distinction more obvious by distinguishing the scripting engine -- ruby -- form the interactive interpreter (REPL) -- irb. 2. Literate Programming: When the primary purpose of the program is not the program but (some form of) discussion around it 3. Program namespace lookup and structuring: sys.path is the interior program view but there is also the 'exterior' view -- PYTHONPATH, .pth files etc. Finally some thoughts on how to name this list of areas: a. Software Engineering? : Inasmuch as real program development is programming + 'something-else' and SE is that 'something else' b. Python Development Environment? Similar to above [Cannot say I like these names too much but at least its more specific than Steven's vanilla 'documentation' :-) ] From prologic at shortcircuit.net.au Tue May 10 23:37:57 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 11 May 2011 13:37:57 +1000 Subject: Overuse of try/except/else? In-Reply-To: <4DC90692.50903@sequans.com> References: <4DC90692.50903@sequans.com> Message-ID: On Tue, May 10, 2011 at 7:34 PM, Jean-Michel Pichavant wrote: > You can reraise the exception without loosing the stack trace. > > try: > ... > except SomeException, exc: > log(exc) > print 'Hello world' > raise # "raise exc" would loose the original stack trace Valid point :) However I was referring to real experience where I've seen code that "catches all any any exception" and simply logs it. cheers James -- -- James Mills -- -- "Problems are solved by method" From greg.ewing at canterbury.ac.nz Wed May 11 01:35:08 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 11 May 2011 17:35:08 +1200 Subject: Merge multiple source directories into one package with distutils? Message-ID: <92ulgfFmukU1@mid.individual.net> Is there a straightforward way to tell distutils to merge .py files from more than one source directory into a single package when installing? PyGUI consists of some generic modules and some platform specific ones, that conceptually all live at the same level within a single package. In the source, there is a subdirectory for each platform containing the platform-dependent files. When run from the source, __path__ manipulation is done to make the appropriate platform subdirectory appear to be part of the main package. However, when installing, I would like to just copy the generic files plus the relevant platform ones directly into the destination package directory, so that __path__ fiddling is not needed. This is so that bundling tools such as py2app and py2exe can find all the relevant modules without requiring any hacking. But distutils doesn't appear to support this. Unless I'm missing something, you only get to specify one source directory for each package. Anyone have any ideas for getting around this? -- Greg From moky.math at gmail.com Wed May 11 02:45:51 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Wed, 11 May 2011 08:45:51 +0200 Subject: Python backup programs? In-Reply-To: References: Message-ID: Le 11/05/2011 01:57, James Mills a ?crit : > On Wed, May 11, 2011 at 9:00 AM, Dan Stromberg wrote: >> >> What are your favorite backup programs written, in whole or in part, in >> Python? My favorite one is the one I wrote myself for myself ;) The point I like : 1. the backup is a simple copy. I can retrieve it without any specific programs. 2. if a file changed, before to be copied, the backup file is moved to a specific repertory whose name is the date and hour. So if I destroy a file and backup the destroyed one, the old non-destroyed one is still available. 3. Since the program is anyway performing a long os.walk operation, in the same time, it performs `git commit` in the directories that need it. 4. My program is command-line only. Works fine in tty Points that are of no importance (very personal and adapted to my specific case !) : 1. time. One backup takes between 10 minutes and one hour. I don't really care. 2. space. Since my backup is a copy (and copy of copies), my backup directory takes ~150Go while my home is about 25 Go. Hope it answer your question. Have a nice day Laurent From swavijay at gmail.com Wed May 11 02:57:13 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Wed, 11 May 2011 12:27:13 +0530 Subject: NewBie Doubt in Python Thread Programming Message-ID: Hi All, I'm new bie to thread programming and I need some assistance in understanding few concepts ... I have a very simple program which runs a thread and prints a string. import threading class MyThread(threading.Thread): def __init__(self, parent = None): threading.Thread.__init__(self) def run(self): print 'Hello World' def main(): for i in range(10): MyThread_Object = MyThread() print 'Object id is : ' , id(MyThread_Object) print 'Staring thread ----------> ' , MyThread_Object.getName() MyThread_Object.start() count = threading.activeCount() print 'The active thread count is: ' , count if __name__ == '__main__': main() When I run this, I could see 10 thread being called. But when I print the active thread count it is only 2. Need some understanding on the following. 1. How the total active thread is 2? 2. how do I stop a thread? does it get automatically stopped after execution ? 3. Am I totally wrong in understanding the concepts. 4. what is the difference between active_count() and activeCount() since both seem to give the same result. 5. is there a way to find out if the thread is still active or dead? Please help me in understanding .. -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed May 11 03:15:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 17:15:25 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 4:57 PM, vijay swaminathan wrote: > ??? for i in range(10): > ??????? MyThread_Object.start() > ??? count = threading.activeCount() > > When I run this, I could see 10 thread being called. But when I print the > active thread count it is only 2. > > Need some understanding on the following. > > 1. How the total active thread is 2? My guess is that all (or all but one) of the threads have finished already by the time you check activeCount. If you add a call to time.sleep(1) in the run() method, you'll see 11 or 12 threads (your main threads and 10 others). If you print out threading.activeCount() at the top of the program, you'll see that it starts at 2 in IDLE, or 1 in stand-alone Python. > 2. how do I stop a thread? does it get automatically stopped after execution Once the run() method returns, the thread is terminated. You shouldn't normally need to stop a thread from another thread. > 3. Am I totally wrong in understanding the concepts. > 4. what is the difference between active_count() and activeCount() since > both seem to give the same result. The camelCase function names were inspired by Java's API, the ones with underscores are more Python's style. They are absolutely the same though. See the notes at the top of http://docs.python.org/library/threading.html for that and other information. > 5. is there a way to find out if the thread is still active or dead? Yep! Call is_alive() on your thread object. It'll return True if it's still going. Again, the docs for the threading module (http://docs.python.org/library/threading.html) have all that sort of thing. Threading is a bit of a tricky concept, and takes some getting used to. There are many places where threads are awesome, and many where they're pretty useless. The place I most often use threads is in socket programming; when I run a server, I usually spin off a thread to handle each incoming socket, as it's the easiest way to handle sequential actions (especially if the socket protocol is command-response, like a MUD or a mail server). Once you get your head around the threading module, you'll find the multiprocessing module very similar. For Python, the difference is sometimes quite important, so it's as well to understand both. Hope that helps! Chris Angelico From gagsl-py2 at yahoo.com.ar Wed May 11 03:31:50 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 11 May 2011 04:31:50 -0300 Subject: NewBie Doubt in Python Thread Programming References: Message-ID: En Wed, 11 May 2011 03:57:13 -0300, vijay swaminathan escribi?: > Hi All, > > I'm new bie to thread programming and I need some assistance in > understanding few concepts ... > > I have a very simple program which runs a thread and prints a string. > > import threading > > class MyThread(threading.Thread): > def __init__(self, parent = None): > threading.Thread.__init__(self) > > def run(self): > print 'Hello World' > > def main(): > for i in range(10): > MyThread_Object = MyThread() > print 'Object id is : ' , id(MyThread_Object) > print 'Staring thread ----------> ' , MyThread_Object.getName() > MyThread_Object.start() > count = threading.activeCount() > print 'The active thread count is: ' , count > > if __name__ == '__main__': > main() > > When I run this, I could see 10 thread being called. But when I print the > active thread count it is only 2. > > Need some understanding on the following. > > 1. How the total active thread is 2? Because most of them have already finished by then. Your run() method executes quite fast. Make it take more time (maybe by adding time.sleep(1)) and you'll see 10 active threads. > 2. how do I stop a thread? does it get automatically stopped after > execution > ? You don't; a trhread runs until the run() method exits. After that, the OS thread finishes. The Python object (a threading.Thread instance) is still alive (until the last reference to it disappears, as any other object). > 3. Am I totally wrong in understanding the concepts. I don't know... > 4. what is the difference between active_count() and activeCount() since > both seem to give the same result. Nothing. active_count is the preferred Python spelling per PEP8; activeCount is the original Java spelling. > 5. is there a way to find out if the thread is still active or dead? Yes, use is_alive() -- Gabriel Genellina From prologic at shortcircuit.net.au Wed May 11 03:34:10 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 11 May 2011 17:34:10 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 4:57 PM, vijay swaminathan wrote: [...] > 1. How the total active thread is 2? Your threads are terminating as normal. Without some kind of loop in your run() method they will execute the instructions and terminate. > 2. how do I stop a thread? does it get automatically stopped after execution Usually by a flag or condition that terminates your run() function/method. > 3. Am I totally wrong in understanding the concepts. > 4. what is the difference between active_count() and activeCount() since > both seem to give the same result. They are synonyms. > 5. is there a way to find out if the thread is still active or dead? See: pydoc threading.Thread or help(threading.Thread) cheers James -- -- James Mills -- -- "Problems are solved by method" From nobody at nowhere.net.no Wed May 11 04:04:13 2011 From: nobody at nowhere.net.no (TheSaint) Date: Wed, 11 May 2011 16:04:13 +0800 Subject: Py3k,email header handling Message-ID: Hello, some time ago, I wrote a program to eliminate undesided emails from the server(s) and leave those which comply to certain filter criteria. I started it when I got to know whit Python 2.3. Now a days I'd like to spend some time to improve it, just for my interest, however it didn't gather anybody's interest before. Now python 3.2 (and some version before) started to use byte, rather than text strings, almost for all data handling in compliance to unicode. My problem arise that my program handle text strings, so I'd like to rewrite the code My program reads from IMAP4 or POP3 server, I'd prefer that a function/class will return either a list or a dictionary which contains the following fields: 'from', 'to', 'cc', 'bcc', 'date', 'subject', 'reply-to', 'message-id' The list may be organized as tuple (from, its_content,), etc,etc for each field, but I think dictionary would be more efficient to use. 1) is there a way to call the IMAPlib or POPlib and pass the data directly to email.parser.HeaderParser to achieve my intention? 2) If the above will do, do re.compile compile unicode results? I guess yes. 3) any related documentation... -- goto /dev/null From rosuav at gmail.com Wed May 11 04:46:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 18:46:36 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: I'm responding to this on-list on the assumption that this wasn't meant to be private; apologies if you didn't intend for this to be the case! On Wed, May 11, 2011 at 6:38 PM, vijay swaminathan wrote: > so If i understand correctly, once the run method of the thread is executed, > the thread is no more alive. Once run() finishes executing, the thread dies. > Actually, I'm trying to invoke a command prompt to run some script and as > long as the script runs on the command prompt, I would like to have the > thread alive. But according to your statement, the thread would die off > after invoking the command prompt. is there a way to keep the thread active > till I manually close the command prompt? That depends on how the "invoke command prompt" function works. > A snippet of the code written is: > # Thread definition > class RunMonitor(QThread): > ??? def __init__(self, parent=None): > ??????? QThread.__init__(self) > ??? def run(self): > ??????? print 'Invoking Command Prompt..........' > ??????? subprocess.call(["start", "/DC:\\Scripts", > "scripts_to_execute.bat"], shell=True) > > ?def sendData(self): > > ??????? if self.run_timer: > ??????????? run_monitor_object = RunMonitor() > ??????????? print 'Starting the thread...........' > ??????????? run_monitor_object.start() > ??????????? self.run_timer = False > > ??????? if run_monitor_object.isAlive(): > ??????????? print 'Thread Alive...' > ??????? else: > ??????????? print 'Thread is Dead....' > subprocess.call() will return immediately, so this won't work. But if you use os.system() instead, then it should do as you intend. > to check the status of the thread repeatedly I have the QTimer which would > call the self.sendData() for every minute. > > ??????? self.timer = QTimer() > ??????? self.timer.connect(self.timer, SIGNAL("timeout()"),self.sendData) > ??????? self.timer.start(1000) I'm not really sure what your overall goal is. Can you explain more of your high-level intentions for this program? There may be a much easier way to accomplish it. Chris Angelico From hg at schaathun.net Wed May 11 05:02:42 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 10:02:42 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07 May 2011 02:51:50 GMT, Steven D'Aprano wrote: : On Fri, 06 May 2011 14:57:21 -0700, scattered wrote: : : > is there any problem with : > : > (3) if li == []: : > : > ? : > : > Seems to work when I test it and seems to clearly test what you are : > trying to test. The only problem might be if in some contexts == has the : > semantics of checking for object identity. : : Yes, if li == [] works too. But how do you know li is a list and not some : other sequence type? It says so in the Subject header :-) : The advantage of the "if x" test is that it is independent of the type of : x. Sure, but the question wasn't ... The problem with 'if x' is that it requires a much more detailed understanding of python. li == [] is as explicit as it gets, and leaves no room for doubt. len(li) == 0 is almost as explicit and much more flexible. Just x is as generic as it gets, but depends on python's convolved rules for duck processing and if you aim at legibility it is better avoided. -- :-- Hans Georg From swavijay at gmail.com Wed May 11 05:08:55 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Wed, 11 May 2011 14:38:55 +0530 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: Sorry. My intention was not to send out a private message. when I chose reply to all, I was confused if this would start as a new thread. so just did a reply.. coming back, I have developed a GUI based on pyQT4 which has a run button. when I click on run, it invokes a command prompt and runs a .bat file. Till the execution of .bat file is over, I want the run button on the GUI to be disabled. so i thought of invoking the command prompt and running the .bat file on a thread so that I could monitor the status of the thread (assuming that the thread would be active till command prompt is active - correct me if I'm wrong). for this, the code that I had written is; # to invoke a command prompt and execute the .bat file. class RunMonitor(threading.Thread): def __init__(self, parent=None): threading.Thread.__init__(self) def run(self): print 'Invoking Command Prompt..........' subprocess.call(["start", "/DC:\\Script", "scripts_to_execute.bat"], shell=True) A timer function to call this thread and monitor this thread.. def runscript(self): self.timer = QTimer() self.timer.connect(self.timer, SIGNAL("timeout()"),self.sendData) self.timer.start(1000) def sendData(self): if self.run_timer: run_monitor_object = RunMonitor() print 'Starting the thread...........' run_monitor_object.start() self.run_timer = False if run_monitor_object.isAlive(): print 'Thread Alive...' else: print 'Thread is Dead....' Any flaw in the logic? any other better ways of achieving this? On Wed, May 11, 2011 at 2:16 PM, Chris Angelico wrote: > I'm responding to this on-list on the assumption that this wasn't > meant to be private; apologies if you didn't intend for this to be the > case! > > On Wed, May 11, 2011 at 6:38 PM, vijay swaminathan > wrote: > > so If i understand correctly, once the run method of the thread is > executed, > > the thread is no more alive. > > Once run() finishes executing, the thread dies. > > > Actually, I'm trying to invoke a command prompt to run some script and as > > long as the script runs on the command prompt, I would like to have the > > thread alive. But according to your statement, the thread would die off > > after invoking the command prompt. is there a way to keep the thread > active > > till I manually close the command prompt? > > That depends on how the "invoke command prompt" function works. > > > A snippet of the code written is: > > # Thread definition > > class RunMonitor(QThread): > > def __init__(self, parent=None): > > QThread.__init__(self) > > def run(self): > > print 'Invoking Command Prompt..........' > > subprocess.call(["start", "/DC:\\Scripts", > > "scripts_to_execute.bat"], shell=True) > > > > def sendData(self): > > > > if self.run_timer: > > run_monitor_object = RunMonitor() > > print 'Starting the thread...........' > > run_monitor_object.start() > > self.run_timer = False > > > > if run_monitor_object.isAlive(): > > print 'Thread Alive...' > > else: > > print 'Thread is Dead....' > > > > subprocess.call() will return immediately, so this won't work. But if > you use os.system() instead, then it should do as you intend. > > > to check the status of the thread repeatedly I have the QTimer which > would > > call the self.sendData() for every minute. > > > > self.timer = QTimer() > > self.timer.connect(self.timer, SIGNAL("timeout()"),self.sendData) > > self.timer.start(1000) > > I'm not really sure what your overall goal is. Can you explain more of > your high-level intentions for this program? There may be a much > easier way to accomplish it. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From hg at schaathun.net Wed May 11 05:14:38 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 10:14:38 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07 May 2011 02:49:53 GMT, Steven D'Aprano wrote: : On Fri, 06 May 2011 16:05:09 -0400, Adam Tauno Williams wrote: : : > I'd never accept code like "if not x" as an empty test. : : So much the worse for you then. : : The point of the "if x" idiom is that it is a polymorphic test which is : independent of the type. Normally, polymorphisms implies multiple forms only, where the different forms has some form of common interpretation. That's what makes polymorphism useful and helpful, increasing legibility. In this case, the interpretation of an arbitrary object as a boolean is peculiar for python. An empty list is a real, existing object, and the supposition that [] be false is counter-intuitive. It can be learnt, and the shorthand may be powerful when it is, but it will confuse many readers. -- :-- Hans Georg From moky.math at gmail.com Wed May 11 05:48:16 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Wed, 11 May 2011 11:48:16 +0200 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: > In this case, the interpretation of an arbitrary object as a boolean > is peculiar for python. An empty list is a real, existing object, and > the supposition that [] be false is counter-intuitive. It can be > learnt, and the shorthand may be powerful when it is, but it will > confuse many readers. Once I wrote something like: def f(x=None): if x: print x else: print "I have no value" The caller of that function was something like f(cos(2*theta)) where theta come from some computations. Well. When it turned out that theta was equal to pi/4, I got "I have no value". I spent a while to figure out the problem :) Conclusion: the boolean value of an object is to be used with care in order to tests if an optional parameter is given or not (when default value is None). Have a good noon Laurent From hg at schaathun.net Wed May 11 06:47:42 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 11:47:42 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 07 May 2011 21:57:13 -0700, Ethan Furman wrote: : If you're going to use a language, and use it well, you have to learn : how that language works. And if the world evolves around the compiler and you, that advice suffices. However, programming is often as much about developing ideas in a large and complex community, where perfect universal mastery of one language is not an option, because half the community do not normally use that language or aren't really programmers at all. The less you assume about the skill of the reader, the better it is. -- :-- Hans Georg From rosuav at gmail.com Wed May 11 07:13:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 May 2011 21:13:33 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 7:08 PM, vijay swaminathan wrote: > Sorry. My intention was not to send out a private message. when I chose > reply to all, I was confused if this would start as a new thread. so just > did a reply.. No probs. If you just send your response to the list python-list at python.org. it'll get to everyone. > I have developed a GUI based on pyQT4 which has a run button. when I click > on run, it invokes a command prompt and runs a .bat file. > > Till the execution of .bat file is over, I want the run button on the GUI to > be disabled. so i thought of invoking the command prompt and running the > .bat file on a thread so that I could monitor the status of the thread > (assuming that the thread would be active till command prompt is active - > correct me if I'm wrong). Yes, but only if you use os.system(). > Any flaw? in the logic? any other better ways of achieving this? > You'll find it easier to get an event at the end of it; simply have another line of code after the os.system() which will reenable the button. Chris Angelico From steve+comp.lang.python at pearwood.info Wed May 11 07:14:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 11:14:25 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dca6f91$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 11:48:16 +0200, Laurent Claessens wrote: > Once I wrote something like: > > def f(x=None): > if x: > print x > else: > print "I have no value" > > > The caller of that function was something like f(cos(2*theta)) where > theta come from some computations. > > Well. When it turned out that theta was equal to pi/4, I got "I have no > value". I spent a while to figure out the problem :) I believe you are grossly oversimplifying whatever code you had. Using the definition of f from above: >>> theta = math.pi/4 >>> f(math.cos(2*theta)) 6.12303176911e-17 But even if you rounded the result of cos(2*theta) to zero, you will get the same result regardless of whether you test for "if x" or "if x != 0". > Conclusion: the boolean value of an object is to be used with care in > order to tests if an optional parameter is given or not (when default > value is None). Or, to put it another way: if you want to test for an object being None, test for the object being None. -- Steven From jean_paez at hotmail.es Wed May 11 07:30:04 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?SmVhbiBDYXJsb3MgUOFleiBSYW3tcmV6?=) Date: Wed, 11 May 2011 06:30:04 -0500 Subject: HELP. This it is the code of tmb_import.py (to matter of .tmb to blender) I need tmb_exporter.py (to export of blender to .tmb) Thanks. In-Reply-To: References: , , , , , Message-ID: Buen d?a comunidad Hola. El archivo adjunto es un script de blender hecho en python que sirve para importar archivos .tmb (http://www.mediafire.com/?clmdgkymsfooddd), descargas blender y usa el script e importa el segundo archivo que te envio para que lo veas (http://www.mediafire.com/?lbmj594ru6r4b67). El se puede editar y todo, pero no se puede exportar de nuevo a .tmb link del script: http://www.mediafire.com/?clmdgkymsfooddd Segundo archivo adjunto: http://www.mediafire.com/?lbmj594ru6r4b67 PD: Necesito el script para exportar en extension .tmb En si necesito ayuda en ese dise?o de un script que exporte de .blend a .tmb Gracias. _________________________________________ Hello. The attached file is script of blender fact in python that .tmb serves to concern archives (secondly attached file), unloadings to blender and uses script and concerns the second file that you shipment you see so that it. Everything can be published and, but it is not possible to be exported again to .tmb To unload in this Link: http://www.blender.org/ script: http://www.mediafire.com/?clmdgkymsfooddd secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 PD: I need script to export in extension .tmb Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jean_paez at hotmail.es Wed May 11 07:31:27 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?SmVhbiBDYXJsb3MgUOFleiBSYW3tcmV6?=) Date: Wed, 11 May 2011 06:31:27 -0500 Subject: HELP. This it is the code of tmb_import.py (to matter of .tmb to blender) I need tmb_exporter.py (to export of blender to .tmb) Thanks. In-Reply-To: References: , , , , , Message-ID: Buen d?a comunidad Hola. El archivo adjunto es un script de blender hecho en python que sirve para importar archivos .tmb (http://www.mediafire.com/?clmdgkymsfooddd), descargas blender y usa el script e importa el segundo archivo que te envio para que lo veas (http://www.mediafire.com/?lbmj594ru6r4b67). El se puede editar y todo, pero no se puede exportar de nuevo a .tmb link del script: http://www.mediafire.com/?clmdgkymsfooddd Segundo archivo adjunto: http://www.mediafire.com/?lbmj594ru6r4b67 PD: Necesito el script para exportar en extension .tmb En si necesito ayuda en ese dise?o de un script que exporte de .blend a .tmb Gracias. _________________________________________ Hello. The attached file is script of blender fact in python that .tmb serves to concern archives (secondly attached file), unloadings to blender and uses script and concerns the second file that you shipment you see so that it. Everything can be published and, but it is not possible to be exported again to .tmb To unload in this Link: http://www.blender.org/ script: http://www.mediafire.com/?clmdgkymsfooddd secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 PD: I need script to export in extension .tmb Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From moky.math at gmail.com Wed May 11 07:45:05 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Wed, 11 May 2011 13:45:05 +0200 Subject: checking if a list is empty In-Reply-To: <4dca6f91$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca6f91$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCA76C1.4040205@gmail.com> > I believe you are grossly oversimplifying whatever code you had. Using > the definition of f from above: > >>>> theta = math.pi/4 >>>> f(math.cos(2*theta)) > 6.12303176911e-17 Yes: its oversimplifued. The angle come from a normal vector of a curve and so on.... In particular, I was using Sage; the computations are exact: pi is pi and cos(pi) is zero. >> Conclusion: the boolean value of an object is to be used with care in >> order to tests if an optional parameter is given or not (when default >> value is None). > > Or, to put it another way: if you want to test for an object being None, > test for the object being None. It was my conclusion too ;) Laurent From moky.math at gmail.com Wed May 11 07:45:23 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Wed, 11 May 2011 13:45:23 +0200 Subject: checking if a list is empty In-Reply-To: <4dca6f91$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca6f91$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: > I believe you are grossly oversimplifying whatever code you had. Using > the definition of f from above: > >>>> theta = math.pi/4 >>>> f(math.cos(2*theta)) > 6.12303176911e-17 Yes: its oversimplifued. The angle come from a normal vector of a curve and so on.... In particular, I was using Sage; the computations are exact: pi is pi and cos(pi) is zero. >> Conclusion: the boolean value of an object is to be used with care in >> order to tests if an optional parameter is given or not (when default >> value is None). > > Or, to put it another way: if you want to test for an object being None, > test for the object being None. It was my conclusion too ;) Laurent From steve+comp.lang.python at pearwood.info Wed May 11 08:14:46 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 12:14:46 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 10:02:42 +0100, Hans Georg Schaathun wrote: > The problem with 'if x' is that it requires a much more detailed > understanding of python. "Much" more detailed? Hardly. Understanding that Python accepts any and all objects in truth-testing concepts, and the rules thereof, is Python 101 territory. It's beginner- level knowledge. It is far less advanced than the knowledge that ** is used for exponentiation. After all, many programmers have never needed to raise a number to a power, and might not learn about it for years, but every programmer writes if or while statements at some point. Not knowing that you can write "if x" instead of "if x == []" is like not knowing that you can write elif condition instead of else: if condition If somebody were to argue that it is "better to write else if explicitly, instead of the confusing elif", we'd all laugh at them. Every time the question of conditional testing comes up here, it never ceases to astonish me how many developers argue against learning the idioms of the language, and prefer to re-use the idioms of other languages in Python. Python is an object-oriented language where objects get to decide for themselves whether they should be treated as true or false. Writing: if x == []: instead of if x: merely[1] because you worry that it isn't explicit enough, or could confuse other developers, or out of some nagging concern that maybe Python will do the wrong thing[2] unless you hold its hand through the process, is as silly as writing this: count = 0 for item in x: count += 1 instead of: count = len(x) (As silly, but not as verbose.) I don't mean to insult anyone, but I've heard and read all the arguments against Python's truth-testing, and they don't impress me in the slightest. Most of them strike me as silly. The only argument that carries any weight to me is one which I haven't seen anyone raise: "if x:" turns something which arguably could have been a mistake ("oops, I forgot to write the condition!") into valid code. [1] It may be that there are good, solid reasons for writing explicit len(x)==0 tests, although I'm hard-pressed to think of any. The closest I come to is when you wish to emphasize "equal to some number that just happens to be zero" rather than "it's a false/empty value". If so, you get a free pass to write the test the long way. E.g. you might write "x % 2 == 1" rather than just "x % 2" because you want to highlight that the remainder equals one, rather than the remainder merely being a true value. [2] Of course, a custom object x might misbehave when you test it for truth value. That would be a bug, just like it would be a bug if it misbehaved when you call len(x) == 0. If you can't trust "if x" to work, what makes you think you can trust "len(x) == 0" either? -- Steven From roy at panix.com Wed May 11 08:26:53 2011 From: roy at panix.com (Roy Smith) Date: Wed, 11 May 2011 08:26:53 -0400 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hans Georg Schaathun wrote: > li == [] is as explicit as it gets, and > leaves no room for doubt. I was about to write, "this fails if li is an instance of a subclass of list", but then I tried it. I was astounded to discover that: class MyList(list): "I'm a subclass" li = MyList() print li == [] print [] == li prints True, twice! I expected them both to be false. In fact, the docs (http://tinyurl.com/3qga3lb) explicitly say: > If both are numbers, they are converted to a common type. Otherwise, > objects of different types always compare unequal Since these are different types, i.e. print type(li) print type([]) print type(li) == type([]) prints False I conclude that li == [] should have returned False. Either I'm not understanding things correctly, or this is a bug. From ironfroggy at gmail.com Wed May 11 08:27:13 2011 From: ironfroggy at gmail.com (Calvin Spealman) Date: Wed, 11 May 2011 08:27:13 -0400 Subject: Non Programming in python In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: If this is the "non-programming side of python" then maybe some of us have a lacking definition of what "programming" is. My mechanic stilll has to check the tire pressure and I need to update the version number in PyPI. On May 10, 2011 12:46 PM, "rusi" wrote: Sorry for a silly subject change: A better one will be welcome -- cant think of a name myself. There is this whole area of python that may be called the non- programming side of programming: Is there some central site where all such is put up? What if any should such a bundle of things be called? ------------------------------------------------- | Area | Tool(s) | |------------------+------------------------| | packaging | distutils, setuptools, | | | distutils2, distribute | | | Native tools (eg apt) | | versioning | hg, git, bzr | | multiple pythons | virtualenv | | ?? | tox | | testing | unittest, nose, pytest | | build | scons, make... | | deployment | fabric | ------------------------------ * Primary Development tools/aids 1. Help 2. Completion ('intellisense') 3. Tags (Jumping) 4. Refactoring 5. Integration with 'non-programming' above (eg VCSes, packagers etc) * Other Development Tools - Debugger - Profiler - Heap Profiler - Coverage -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From vithyamaha6 at gmail.com Wed May 11 08:28:59 2011 From: vithyamaha6 at gmail.com (maha) Date: Wed, 11 May 2011 05:28:59 -0700 (PDT) Subject: EARN 1000 DOLLARS PER DAY - FOREX TRADING CLICK HERE Message-ID: <77cbe98f-e740-4fb5-895b-27b04913af54@z7g2000prh.googlegroups.com> http://earnforexnow.blogspot.com/ http://earnforexnow.blogspot.com/ http://earnforexnow.blogspot.com/ http://earnforexnow.blogspot.com/ http://earnforexnow.blogspot.com/ From miki.tebeka at gmail.com Wed May 11 09:15:34 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 11 May 2011 06:15:34 -0700 (PDT) Subject: Merge multiple source directories into one package with distutils? In-Reply-To: <92ulgfFmukU1@mid.individual.net> Message-ID: <4228410e-4631-47be-936c-041122f27ffb@glegroupsg2000goo.googlegroups.com> Greg, > Is there a straightforward way to tell distutils to merge .py files from more than one source directory into a single package when installing? The Selenium Python bindings does something like that, have a look at http://selenium.googlecode.com/svn/trunk/setup.py The other option is to write some code in setup.py before calling "setup" to do the merge. HTH -- Miki Tebeka http://pythonwise.blogspot.com From steve+comp.lang.python at pearwood.info Wed May 11 09:29:38 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 13:29:38 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dca8f41$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 08:26:53 -0400, Roy Smith wrote: > Hans Georg Schaathun wrote: > >> li == [] is as explicit as it gets, and leaves no room for doubt. > > I was about to write, "this fails if li is an instance of a subclass of > list", but then I tried it. I was astounded to discover that: > > class MyList(list): > "I'm a subclass" > > li = MyList() > print li == [] > print [] == li > > prints True, twice! I expected them both to be false. In fact, the > docs (http://tinyurl.com/3qga3lb) explicitly say: > >> If both are numbers, they are converted to a common type. Otherwise, >> objects of different types always compare unequal That should be understood as only applying for built-in types, not arbitrary types. For arbitrary types, you can decide what counts as equal by writing an __eq__ method, and you can do *anything*: def __eq__(self, other): if today() == "Tuesday": return True else: ... To understand the behaviour you are seeing, it helps to understand that while li is a MyList, it is also a list: >>> isinstance(li, list) True It therefore inherits the same behaviour as list, unless you override or overload it. Since you did neither, MyLists work just like lists, right down to their __eq__ method. It is normally considered The Right Thing To Do for subclasses to be usable anywhere where a superclass was. That is, subclasses like MyList should only *add* behaviour, never *subtract* it. Since: >>> li = list() >>> li == [] True applies, you should be able to replace list() with any subclass of list and it should still work. (This is known as the Liskov Substitution Principle, if you wish to google on it.) This being Python, it's more of a guideline than a law, and you can violate it if you choose, but you probably shouldn't unless you have good reason. But if you want, just add a method: def __eq__(self, other): # untested if type(self) is not type(other): return False return super(self, MyList).__eq__(other) to get the behaviour you are after. So, not a bug, but a subtle point that isn't explained terribly well in the docs. -- Steven From emile at fenx.com Wed May 11 09:34:28 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 11 May 2011 06:34:28 -0700 Subject: Python backup programs? In-Reply-To: References: Message-ID: On 5/10/2011 4:00 PM Dan Stromberg said... > What are your favorite backup programs written, in whole or in part, in > Python? bup > What do you like about them? resilient and written in python > Dislike about them? lack of a user accessible front-end to monitor and restore > Are there any features you wish your backup program had, whether in > Python or not? I like backuppc because of it's front-end. Emile From steve+comp.lang.python at pearwood.info Wed May 11 09:36:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 13:36:02 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 10:14:38 +0100, Hans Georg Schaathun wrote: > In this case, the interpretation of an arbitrary object as a boolean is > peculiar for python. Incorrect. It is widespread among many languages. Programmers have been writing conditional tests using arbitrary values since 1958 when Lisp introduced the concept. C, Forth and Visual Basic treat any non-zero number as true, and zero as false; that's not quite arbitrary objects, but it's arbitrary integer values. Similarly, Objective C has two different boolean types, "BOOL" which is a C char where 0 is false and everything else is true, and "bool" which is more like the Java boolean type. Perl treats the empty string, "0", 0 and undefined variables as false, and everything else as true. Ruby treats null and false as false, and everything else as true. JavaScript treats "", null, undefined, NaN, 0 and false as false values, and everything else as true. PHP treats FALSE, 0, "", "0", empty arrays, objects with no member variables, NULL, unset variables, and SimpleXML objects created from empty tags as false, everything else as true. Clojure treats nil and false as false, everything else as true. SQL's boolean type has three or four values: true, false, null and unknown, where implementations are free to treat null and unknown as either the same or different values. (So a 3 or 4 value logic, not actually Boolean at all.) So Python is hardly unique, nor is this some new-fangled innovation. > An empty list is a real, existing object, and the > supposition that [] be false is counter-intuitive. Not to me, nor to anyone who has an intuition about "something" versus "nothing". I believe this distinction is fundamental to the universe, and that nearly every person understands this intuitively. The distinction between something and nothing is so strong that it took centuries of argument for the finest minds in Europe[1] to finally decide that, yes, zero is a number -- and they only did it because the Arabs and Indians had proven how useful it was, and Roman numerals really do suck for doing calculations. > It can be learnt, > and the shorthand may be powerful when it is, but it will confuse many > readers. In my experience, it does not confuse newbies or beginners. The only people it confuses are those who are over-educated into thinking that the One Correct Way of doing truth testing is with a dedicated boolean type, and anything else is heresy. [1] At least is you asked them. -- Steven From steve+comp.lang.python at pearwood.info Wed May 11 09:44:17 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 13:44:17 GMT Subject: Py3k,email header handling References: Message-ID: <4dca92b1$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 16:04:13 +0800, TheSaint wrote: > Now python 3.2 (and some version before) started to use byte, rather > than text strings, almost for all data handling in compliance to > unicode. My problem arise that my program handle text strings, so I'd > like to rewrite the code Before you re-write it, you should run 2to3 over it and see how much it can do automatically: http://docs.python.org/library/2to3.html > My program reads from IMAP4 or POP3 server, I'd prefer that a > function/class will return either a list or a dictionary which contains > the following fields: > > 'from', 'to', 'cc', 'bcc', 'date', 'subject', 'reply-to', 'message-id' > > The list may be organized as tuple (from, its_content,), etc,etc for > each field, but I think dictionary would be more efficient to use. > > 1) is there a way to call the IMAPlib or POPlib and pass the data > directly to email.parser.HeaderParser to achieve my intention? I'm afraid I don't understand the question. > 2) If the above will do, do re.compile compile unicode results? I guess > yes. Yes. In Python 3, re.compile("some string") is automatically unicode, because "some string" is unicode. > 3) any related documentation... http://docs.python.org/py3k/library/email.html http://docs.python.org/py3k/library/re.html http://docs.python.org/py3k/library/imaplib.html http://docs.python.org/py3k/library/poplib.html If you have any more concrete questions, please ask. -- Steven From steve+comp.lang.python at pearwood.info Wed May 11 09:45:52 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 13:45:52 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 11:47:42 +0100, Hans Georg Schaathun wrote: > On Sat, 07 May 2011 21:57:13 -0700, Ethan Furman > wrote: > : If you're going to use a language, and use it well, you have to learn > : how that language works. > > And if the world evolves around the compiler and you, that advice > suffices. > > However, programming is often as much about developing ideas in a large > and complex community, where perfect universal mastery of one language > is not an option, because half the community do not normally use that > language or aren't really programmers at all. The less you assume about > the skill of the reader, the better it is. Do you think that we should avoid chained comparisons, class methods, closures, co-routines, decorators, default values to functions, delegation, doc tests, exceptions, factory functions, generator expressions, inheritance, iterators, list comprehensions, operator overloading, properties, regular expressions, tuple unpacking, or unit tests, to say nothing of *advanced* techniques like descriptors or metaclasses, just in case the person reading your code is a clueless n00b? We routinely and uncontroversially use all of these techniques (well, sometimes metaclasses get a few raised eyebrows). Truth testing is MUCH simpler than any of those. It is extremely patronizing to say that we should avoid truth-testing arbitrary objects because it is too complicated for other people. It's not hard, and they can learn. -- Steven From hg at schaathun.net Wed May 11 10:00:17 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 15:00:17 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 13:36:02 GMT, Steven D'Aprano wrote: : > In this case, the interpretation of an arbitrary object as a boolean is : > peculiar for python. : : Incorrect. It is widespread among many languages. Programmers have been : writing conditional tests using arbitrary values since 1958 when Lisp : introduced the concept. The fact that you need to list language by language which objects evaluate as false or equivalent to false illustrates that this has to be learnt language by language. Allowing arbitrary objects is one thing, the particular interpretation is peculiar. The fact that if and while accepts any object for the condition may be chapter 1 stuff, but the memorisation of exactly how the interpretation does not come early (unless you learn it by rote of course). : C, Forth and Visual Basic treat any non-zero number as true, and zero as : false; that's not quite arbitrary objects, but it's arbitrary integer : values. Similarly, Objective C has two different boolean types, "BOOL" : which is a C char where 0 is false and everything else is true, and : "bool" which is more like the Java boolean type. Mentioning C, with no Boolean type at all, in this context is a bit absurd. Understanding boolean evaluation in C is very little help when you want to understand it in python. : > An empty list is a real, existing object, and the : > supposition that [] be false is counter-intuitive. : : Not to me, nor to anyone who has an intuition about "something" versus : "nothing". I believe this distinction is fundamental to the universe, and : that nearly every person understands this intuitively. The distinction : between something and nothing is so strong that it took centuries of : argument for the finest minds in Europe[1] to finally decide that, yes, : zero is a number -- and they only did it because the Arabs and Indians : had proven how useful it was, and Roman numerals really do suck for doing : calculations. Exactly. By now we have gotten past that old-fashioned idea that 0 is not a number. Computer scientists even tend to count 0 as a natural number. When 0 is a number as real and existent as any other, one would think that the empty list is also as real and existent as any other list. : In my experience, it does not confuse newbies or beginners. The only : people it confuses are those who are over-educated into thinking that the : One Correct Way of doing truth testing is with a dedicated boolean type, : and anything else is heresy. What kind of beginners are you talking about? Beginners to python or beginners to programming. The audience I am concerned about is the ones who are over-educated into using and having used a score of different meanings of the same symbols. They will be used to their intuition being wrong when they move into a new context. Being explicit will help them. -- :-- Hans Georg From hg at schaathun.net Wed May 11 10:05:45 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 15:05:45 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 12:14:46 GMT, Steven D'Aprano wrote: : Not knowing that you can write "if x" instead of "if x == []" is like not : knowing that you can write : : elif condition : : instead of : : else: : if condition My concern was with the reader and not the writer. What could elif mean other than else: if? if x could, for instance, mean "if x is defined". -- :-- Hans Georg From darcy at druid.net Wed May 11 10:27:49 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 11 May 2011 10:27:49 -0400 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110511102749.5ff8ef57.darcy@druid.net> On Wed, 11 May 2011 15:05:45 +0100 Hans Georg Schaathun wrote: > What could elif mean other than else: if? If run by an elf? Who knows. You do, of course, if you have learned the basics of the language you are using. > if x could, for instance, mean "if x is defined". It could also mean "if x was created on a Tuesday." A short introduction to the language explains what it actually means. When did we come to the idea that people should be able to program in a language without actually learning it? The fact that Python comes so close to that possibility is nothing short of revolutionary. I suppose one day a reasoning android will be able to sit down at the terminal of a star ship computer and ask simple questions while making random hand movements across a screen but for now I am afraid that programmers still have to learn programming. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Wed May 11 10:33:51 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 11 May 2011 10:33:51 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110511103351.2dd25113.darcy@druid.net> On Wed, 11 May 2011 11:47:42 +0100 Hans Georg Schaathun wrote: > However, programming is often as much about developing ideas in a large > and complex community, where perfect universal mastery of one language > is not an option, because half the community do not normally use that > language or aren't really programmers at all. The less you assume about > the skill of the reader, the better it is. Non-programmers should be able to program? Should non-doctors be able to doctor? Should cars be built so that anyone can intuitively fix them without a mechanic? Should trucks be built so that drivers don't have to learn how to split shift? Why is programming so different that we can't expect people to actually learn their discipline? This discussion is giving me some insight into some of the crap programming I see these days. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From hg at schaathun.net Wed May 11 10:34:28 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 15:34:28 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 13:45:52 GMT, Steven D'Aprano wrote: : Do you think that we should avoid chained comparisons, class methods, : closures, co-routines, decorators, default values to functions, : delegation, doc tests, exceptions, factory functions, generator : expressions, inheritance, iterators, list comprehensions, operator : overloading, properties, regular expressions, tuple unpacking, or unit : tests, to say nothing of *advanced* techniques like descriptors or : metaclasses, just in case the person reading your code is a clueless n00b? Not at all. On both accounts. 1. My concern was not about clueless newbies. They need to learn. My concern is about experienced scientists and engineers who are simply new to python. They will be dealing with a dozen different languages (programming and otherwise), with a need to read more languages than they can possibly learn to master. 2. You should avoid constructs which can /reasonably/ be avoided to /increase/ legibility. Writing if x for if len(x) > 0 when you know that x is of some sort of collection type with len defined does nothing to help legibility. Many of the socalled advanced constructs you mention are used to increase legibility one way or another. Others will simply allow functionality which would otherwise be impossible. I don't object to using if x in a case where x may or may not have len() defined. : We routinely and uncontroversially use all of these techniques (well, : sometimes metaclasses get a few raised eyebrows). Truth testing is MUCH : simpler than any of those. Simpler, yes, but it surely depends on more detailed knowledge. One has to remember how the boolean conversion works, for each possible data type. This requires looking up the rules for each data type. E.g. Anyone who has used list/set comprehension in Z, haskell, set theory, or whereever will understand python list comprehension immediately. : It is extremely patronizing to say that we should avoid truth-testing : arbitrary objects because it is too complicated for other people. It's : not hard, and they can learn. Again you miss the point. It is not /too/ complicated. It is /unnecessarily/ complicated. You don't noticeably gain anything by using if x instead of if len(x) > 0, if you know that the latter is defined. If everyone who ever needs to see your program is a python programmer, then your approach works as well as mine. -- :-- Hans Georg From rosuav at gmail.com Wed May 11 10:46:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 00:46:47 +1000 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 at 12:00 AM, Hans Georg Schaathun wrote: > The fact that you need to list language by language which objects > evaluate as false or equivalent to false illustrates that this has > to be learnt language by language. Allowing arbitrary objects is > one thing, the particular interpretation is peculiar. Languages have to be learned language by language. Yes, you want to be similar to others if you can (and in 'most every language where it's legal syntax, "1+2" will mean "3"), but whenever I'm working in a language with which I'm not _really_ fluent, I like to keep an operator table handy (precedence, plus oddments like what the exponentiation operator is, or whether & is bitwise or boolean). They do differ, and if I'm writing in PHP or Python or Pike or C++ or Java or whatever else it be, I have to use the operators the way the interpreter/compiler will understand them, not in some other way that I "deem better". > Mentioning C, with no Boolean type at all, in this context is a bit > absurd. Understanding boolean evaluation in C is very little help > when you want to understand it in python. Actually, it's not. # Python code: if x: statements /* C code: */ if (x) { statements; } What's the difference? Both of them let you test the truth of some arbitrary object or expression, and neither of those statements implies a Boolean type. In C++, this is exploited extensively with, for instance, the stream I/O objects evaluating as false when in an error or EOF state: while (infile) infile >> *ptr++; // Compact and convenient way to read into an array Actually that one can be combined down even further, but for clarity I leave it like that. Chris Angelico From tacyt1007 at gmail.com Wed May 11 11:16:28 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Wed, 11 May 2011 17:16:28 +0200 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: Is there any special reason you don't want to use QThread? http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details regards 2011/5/11 Chris Angelico : > On Wed, May 11, 2011 at 7:08 PM, vijay swaminathan wrote: >> Sorry. My intention was not to send out a private message. when I chose >> reply to all, I was confused if this would start as a new thread. so just >> did a reply.. > > No probs. If you just send your response to the list > python-list at python.org. it'll get to everyone. > >> I have developed a GUI based on pyQT4 which has a run button. when I click >> on run, it invokes a command prompt and runs a .bat file. >> >> Till the execution of .bat file is over, I want the run button on the GUI to >> be disabled. so i thought of invoking the command prompt and running the >> .bat file on a thread so that I could monitor the status of the thread >> (assuming that the thread would be active till command prompt is active - >> correct me if I'm wrong). > > Yes, but only if you use os.system(). > >> Any flaw? in the logic? any other better ways of achieving this? >> > > You'll find it easier to get an event at the end of it; simply have > another line of code after the os.system() which will reenable the > button. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Wed May 11 11:22:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 01:22:03 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 1:16 AM, Wojtek Mamrak wrote: > Is there any special reason you don't want to use QThread? > http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details Other than that QThread is part of QT and threading isn't, what are the advantages of QThread? Is it possible (safe) to manipulate QT objects - in this case, the button - from a thread other than the one that created them? (If not, that would be a good reason for using QThread, which will fire an event upon termination.) Chris Angelico From redcat at catfolks.net Wed May 11 11:31:01 2011 From: redcat at catfolks.net (Redcat) Date: 11 May 2011 15:31:01 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92vodkFrniU3@mid.individual.net> On Wed, 11 May 2011 10:33:51 -0400, D'Arcy J.M. Cain wrote: > Non-programmers should be able to program? Wasn't that sort of the premise behind Visual Basic? I don't know if that was the intention, but it sure was the result in a lot of cases. From steve+comp.lang.python at pearwood.info Wed May 11 11:50:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 15:50:45 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dcab055$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 15:05:45 +0100, Hans Georg Schaathun wrote: > My concern was with the reader and not the writer. > > What could elif mean other than else: if? It could mean "Oh, the author has made a stupid typo, I better fix it." It could mean "What does the elif command do?" The first time I read Python code, I had literally no idea what to make of elif. It seemed so obvious to me that any language would let you write "else if ..." (on a single line) that I just assumed that elif must be some other construct, and I had no idea what it was. It never even crossed my mind that it could be "else if" rammed together into one word. I soon learned better though. Once you start dumbing down your code for readers who don't know your language, it's a race to the bottom. There's very little you can write that *somebody* won't misunderstand. > if x could, for instance, mean "if x is defined". Yes it could, if you're programming in Perl. But we're not. When I write a sentence in English, and I use the word "gift" to mean a thing which is given, I don't worry that German or Swedish readers will think I'm talking about poison. If I use "preservative", I mean something which preserves, and if Italian and Spanish readers mistake it for a condom, that's their problem, not mine. Writing code is no different. When I'm coding in Python, I use Python rules and meanings, not some other language. Why should I code according to what some hypothetical Python dummy *might* think the code will do, instead of what the code *actually* does? -- Steven From ethan at stoneleaf.us Wed May 11 11:53:24 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 May 2011 08:53:24 -0700 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCAB0F4.7040106@stoneleaf.us> Hans Georg Schaathun wrote: > On 11 May 2011 13:36:02 GMT, Steven D'Aprano > wrote: > : > In this case, the interpretation of an arbitrary object as a boolean is > : > peculiar for python. > : > : Incorrect. It is widespread among many languages. Programmers have been > : writing conditional tests using arbitrary values since 1958 when Lisp > : introduced the concept. > > The fact that you need to list language by language which objects > evaluate as false or equivalent to false illustrates that this has > to be learnt language by language. Allowing arbitrary objects is > one thing, the particular interpretation is peculiar. Like so many other things Python got right, I think it got this right as well. "something" vs "nothing" is simple, useful, and easy to remember. > By now we have gotten past that old-fashioned idea that 0 > is not a number. Computer scientists even tend to count 0 as a > natural number. When 0 is a number as real and existent as any other, > one would think that the empty list is also as real and existent as > any other list. Python is not concerned with whether it exists -- that's a name binding; Python is concerned with whether anything is there. 0 apples is nothing and a an empty list is nothing as well. ~Ethan~ From tacyt1007 at gmail.com Wed May 11 11:55:19 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Wed, 11 May 2011 17:55:19 +0200 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: 2011/5/11 Chris Angelico : > On Thu, May 12, 2011 at 1:16 AM, Wojtek Mamrak wrote: >> Is there any special reason you don't want to use QThread? >> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details > > Other than that QThread is part of QT and threading isn't, what are > the advantages of QThread? Is it possible (safe) to manipulate QT > objects - in this case, the button - from a thread other than the one > that created them? (If not, that would be a good reason for using > QThread, which will fire an event upon termination.) > QThread provides mechanism of signals and slots ("from" and "to" the thread), which are used across all pyQt. Unfortunately it is not possible to use any widget classes in the thread (direct quote from the docs). On the other hand signals can fire methods from the main thread (running the app'a main loop), so this is not a big deal. The signals are: - finished - started - terminated It is possible to block the thread, make it sleep, check whether the thread is running, and few others. From rosuav at gmail.com Wed May 11 12:05:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 02:05:21 +1000 Subject: checking if a list is empty In-Reply-To: <4dcab055$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab055$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 at 1:50 AM, Steven D'Aprano wrote: > On Wed, 11 May 2011 15:05:45 +0100, Hans Georg Schaathun wrote: > >> My concern was with the reader and not the writer. >> >> What could elif mean other than else: if? > > The first time I read Python code, I had literally no idea what to make > of elif. It seemed so obvious to me that any language would let you write > "else if ..." (on a single line) that I just assumed that elif must be > some other construct, and I had no idea what it was. It never even > crossed my mind that it could be "else if" rammed together into one word. In a Bourne shell script, if ends with fi... case ends with esac... so file would end with... hmm. Yeah, I think it's best to know the language you're trying to comprehend, and/or actually look at context instead of shoving a piece of code under someone's nose and saying "I bet you can't figure out what THIS does!". Chris Angelico From steve+comp.lang.python at pearwood.info Wed May 11 12:26:40 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 16:26:40 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 15:34:28 +0100, Hans Georg Schaathun wrote: > On 11 May 2011 13:45:52 GMT, Steven D'Aprano > wrote: > : Do you think that we should avoid chained comparisons, class methods, > : closures, co-routines, decorators, default values to functions, : > delegation, doc tests, exceptions, factory functions, generator : > expressions, inheritance, iterators, list comprehensions, operator : > overloading, properties, regular expressions, tuple unpacking, or unit : > tests, to say nothing of *advanced* techniques like descriptors or : > metaclasses, just in case the person reading your code is a clueless > n00b? > > Not at all. On both accounts. > 1. My concern was not about clueless newbies. They need to > learn. My concern is about experienced scientists and engineers who > are simply new to python. Which makes them clueless newbies *about Python*. I don't care how experienced they are in astrophysics or biology or calculating the average airspeed of an unladen swallow. > They will be dealing with a dozen different > languages (programming and otherwise), with a need to read more > languages than they can possibly learn to master. Yeah, life is hard and then you die, and scientists don't even get paid that much. So what? Do physicists write their scientific papers about string theory with the thought "What if some Python programmer who knows nothing about string theory is reading this? I better dumb it down." Of course not. A ridiculous idea. They use their tools the way they are designed to be used, and outsiders have to learn the language and the jargon to make sense of it. This is not a problem that needs solving. It's one thing to simplify code that you are explicitly using as a teaching aid. That's a good thing, I approve of that. But it's a completely different thing to dumb down production code because you think some non-programmer might have to read it. > 2. You should avoid constructs which can /reasonably/ be avoided to > /increase/ legibility. Writing if x for if len(x) > 0 when you know > that x is of some sort of collection type with len defined does > nothing to help legibility. Of course it does. It means you don't have to care about implementation details of what emptiness means for a list. It means you don't force the reader to read, parse and understand three extraneous terms. It means you don't force the reader to wonder why you bothered to use a long-winded test when a short test would do, or be concerned that maybe > 0 is a typo and you actually meant > 10. [...] > Simpler, yes, but it surely depends on more detailed knowledge. One has > to remember how the boolean conversion works, for each possible data > type. This requires looking up the rules for each data type. No. You have that exactly backwards. The point of "if x" is that you DON'T have to care about how the boolean conversion works, because the object itself encapsulates that behaviour. This is basic object-oriented principles. When you call len(x) you don't care about the details of how to calculate the length of x. The object itself knows so that you don't have to. The same applies to truth testing. I have a data type that is an array of lists. When you call "if len(x) > 0" on it, it will blow up in your face, because len(x) returns a list of lengths like [12, 0, 2, 5]. But if you say "if x", it will do the right thing. You don't need to care how to truth-test my data type, because it does it for you. By ignoring my type's interface, and insisting on doing the truth-test by hand, you shoot yourself in the foot. > E.g. Anyone who has used list/set comprehension in Z, haskell, set > theory, or whereever will understand python list comprehension > immediately. Yes. And anyone who hasn't, probably won't. But they will learn. -- Steven From nobody at nowhere.net.no Wed May 11 12:27:22 2011 From: nobody at nowhere.net.no (TheSaint) Date: Thu, 12 May 2011 00:27:22 +0800 Subject: Py3k,email header handling References: <4dca92b1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Before you re-write it, you should run 2to3 over it and see how much it > can do automatically: Widely done, only the results from some query has radically changed on favour of unicode. Errors raising about results which are not strings anymore. > I'm afraid I don't understand the question. Making an example : from poplib import POP3 as pop3 pop3.user('userid') pop3.pass_('password') numMsg, total = pop3.stat() for cnt in numMsgs: header = pop3.top(cnt) # here I'd like to pass the header to some function that will return # a dictionary filling # from', 'to', 'cc', 'bcc', 'date', 'subject', 'reply-to', 'message-id' # keys, if nothing the leave empty string or None dict = email.header,decode_header(header) # but might not my result # Should I subclass this? The same would be from the IMAP4 message parsing. Some different process would take, would it ? > If you have any more concrete questions, please ask. If these aren't concrete questions, forgive me, I perhaps got into wrong news group. In the other and I hugely apreciated your clues. I'll see the docs some more long to achieve a clear learning. -- goto /dev/null From genstein at invalid.invalid Wed May 11 12:27:32 2011 From: genstein at invalid.invalid (Genstein) Date: Wed, 11 May 2011 17:27:32 +0100 Subject: py3k buffered IO - flush() required between read/write? Message-ID: Hey all, Apologies if this is a dumb question (self = Python noob), but under py3k is it necessary to flush() a file between read/write calls in order to see consistent results? I ask because I have a case under Python 3.2 (r32:88445) where it does appear to be, on both Gentoo Linux and Windows Vista. I've naturally read http://docs.python.org/py3k/library/io.html and http://docs.python.org/py3k/tutorial/inputoutput.html#reading-and-writing-files but could find no reference to such a requirement. PEP 3116 suggested this might not be required in py3k and the implementation notes in bufferedio.c state "BufferedReader, BufferedWriter and BufferedRandom...share a single buffer...this enables interleaved reads and writes without flushing." Which seemed conclusive but I'm seeing otherwise. I have a test case, which is sadly rather long: http://pastebin.com/xqrzKr5D It's lengthy because it's autogenerated from some rather more complex code I'm working on, in order to reproduce the issue in isolation. Any advice and/or flames appreciated. All the best, -eg. From ian.g.kelly at gmail.com Wed May 11 12:31:59 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 11 May 2011 10:31:59 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 11, 2011 at 8:34 AM, Hans Georg Schaathun wrote: > E.g. Anyone who has used list/set comprehension in Z, haskell, set theory, > or whereever will understand python list comprehension immediately. They would understand the underlying concept. But would somebody who is not a Python programmer intuitively understand the difference between this: [x + 3 for x in xs if x % 2 == 1] and this: {x + 3 for x in xs if x % 2 == 1} and this: (x + 3 for x in xs if x % 2 == 1) Somebody with rudimentary Python knowledge might even reason that since the first two create a list and a set respectively, the third must therefore create a tuple, which is wrong. None of this should be taken as an argument against using generator expressions. From ericsnowcurrently at gmail.com Wed May 11 13:22:06 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 11 May 2011 11:22:06 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: All of this just boils down to Python providing an implicit bool cast in syntactic situations that expect conditional expressions, including if [1]. So "if x:" is equivalent to "if bool(x)". Perhaps that is the part that is not immediately obvious, being implicit to Python conditional syntax. Python also provides a mechanism for customization of a wide variety of behavior that is not obvious without reading the [excellent] documentation [2]. So the following three forms will implicitly call the special method names: if x: => if bool(x): => if x.__bool__(): [3] if x == []: => if x.__eq__([]): if len(x) == 0: => if x.__len__() == 0: Other than the implicit cast to bool for conditional syntax and the implicit calls to special method names as appropriate I am not clear that there is any remaining mystery for this question. And the language reference makes all of the above very clear, so I highly recommend it. The only caveat is that builtin types don't always act the same way as user defined types (classes). Not sure if the few differences are well documented, but to be honest that hasn't bit me hard enough that I needed to look it up. I do know that the builtin list has a __eq__ method and a __len__ method, but not a __bool__ method (which it doesn't need [3]). -eric [1] http://docs.python.org/dev/py3k/reference/compound_stmts.html#the-if-statement [2] http://docs.python.org/dev/py3k/reference/datamodel.html#special-method-names [3] http://docs.python.org/dev/py3k/reference/datamodel.html#object.__bool__ so if __bool__ doesn't exist it tries __len__ and so forth. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Wed May 11 13:29:50 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 11 May 2011 12:29:50 -0500 Subject: Proper way to handle errors in a module Message-ID: <4DCAC78E.1000901@gmail.com> I'm a bit new to programming outside of shell scripts (and I'm no expert there), so I was wondering what is considered the best way to handle errors when writing a module. Do I just let exceptions go and raise custom exceptions for errors that don't trigger a standard one? Have the function/method return nothing or a default value and show an error message? I'm sure there's not a clear-cut answer, but I was just wondering what most developers would expect a module to do in certain situations. From ramit.prasad at jpmchase.com Wed May 11 13:39:44 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Wed, 11 May 2011 13:39:44 -0400 Subject: checking if a list is empty In-Reply-To: <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA3B33534@EMARC112VS01.exchad.jpmchase.net> > I don't mean to insult anyone, but I've heard and read all the arguments against Python's truth-testing, and they >don't impress me in the slightest. Most of them strike me as silly. The only argument that carries any weight to me is >one which I haven't seen anyone raise: >"if x:" turns something which arguably could have been a mistake ("oops, I forgot to write the condition!") into valid >code. The only problem I have had with the "if x:" notation is when I have values that might be empty lists, empty strings, None, or a boolean value being returned from the same source. But this is probably an instance when a good programmer would explicitly check the type instead of the naive "if x:" notation. On the other hand, as a fairly n00b Python (and n00b Perl) developer, I find the notation "if not x:" to be far more English readable than "if x==None or len(x)== 0 or x==0 or bool(x):" (or some derivative/combination of those). Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From hg at schaathun.net Wed May 11 13:44:34 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 18:44:34 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2huq98-2v6.ln1@svn.schaathun.net> On Wed, 11 May 2011 10:33:51 -0400, D'Arcy J.M. Cain wrote: : Non-programmers should be able to program? That was not really what I suggested; I was primarily talking about reading programs and commenting on formul? and algorithms. : Should non-doctors be able to doctor? If I were God, I might consider simplifying the anatomy to allow that, yes. : Should cars be built so that : anyone can intuitively fix them without a mechanic? Should trucks be : built so that drivers don't have to learn how to split shift? That's out of my area so I don't know. However, contrary to software, I have never seen any use of rebuilding the car to do something other than transport ... And, besides, as mechanics do not design cars or even engines, they are not analogous to programmers, but rather to computer technicians (maintenance, deployment, installation, etc). : Why is : programming so different that we can't expect people to actually learn : their discipline? It is not different from other engineering disciplines, where you would have to interact with experts from other disciplines, and understand and comment on their designs. That's the way to build a /system/. Say, you want to create the software to make weather forcasts. At the end of the day, that's programming, but no way that's going to be a task for programmers alone. You need mathematicians, algorithm theorists, physicists, programmers, and multiple specialisations within each discipline. If you can make your programs clear enough to be used as a language of communications, you will simplify the development, and allow the code to be validated by those who knows how the computation has to be done without specialising in talking to the computer. : This discussion is giving me some insight into some of the crap : programming I see these days. I wonder if you would do a better job at programming the software to crack equations from quantum physics than the physicist :-) -- :-- Hans Georg From hg at schaathun.net Wed May 11 13:46:01 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 18:46:01 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 May 2011 10:31:59 -0600, Ian Kelly wrote: : (x + 3 for x in xs if x % 2 == 1) Interesting. Thanks. That might come in handy some time. -- :-- Hans Georg From ramit.prasad at jpmchase.com Wed May 11 13:50:54 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Wed, 11 May 2011 13:50:54 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA3B33589@EMARC112VS01.exchad.jpmchase.net> >The audience I am concerned about is the ones who are over-educated >into using and having used a score of different meanings of the same >symbols. They will be used to their intuition being wrong when they >move into a new context. Being explicit will help them. I find this argument to be flawed. Should I stop using built-in generators instead of range/xrange for looping through lists? Certainly for loops with loop counting are understood more widely than generators. Should I stop using any advanced feature Python because it is difficult to understand without knowing Python? I do not code for absolute beginner in Python to read my code. That way lies madness! I code with the assumption that someone with intermediate knowledge can read my code (unless I am forced into optimizing and then I rely on comments to explain). Actually, that is how I attempt to code in any language. I may not have made the point well, but I cannot see any advantage for trying to program for the lowest common denominator. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From hg at schaathun.net Wed May 11 13:56:00 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 18:56:00 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab055$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 12 May 2011 02:05:21 +1000, Chris Angelico wrote: : In a Bourne shell script, if ends with fi... case ends with esac... so : file would end with... hmm. Yeah, I think it's best to know the : language you're trying to comprehend, and/or actually look at context : instead of shoving a piece of code under someone's nose and saying "I : bet you can't figure out what THIS does!". Code is quite often published to document algorithms, methods and formul? for the purpose of scientific research. Since there is no universal language which suits everything and everyone, this is exactly what happens. One has to have the rudimentary knowledge to read half a dozen different languages to be able to read the code and extract the algorithms. If one tried to maintain the necessary programming skills to exploit all of those languages to their full potential, one would simply not be able to keep up with the application discipline. If all you do is to write software for computer illiterate users, YMWV. -- :-- Hans Georg From tjreedy at udel.edu Wed May 11 13:56:16 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 May 2011 13:56:16 -0400 Subject: Py3k,email header handling In-Reply-To: References: <4dca92b1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/11/2011 12:27 PM, TheSaint wrote: > Steven D'Aprano wrote: > >> Before you re-write it, you should run 2to3 over it and see how much it >> can do automatically: > > Widely done, only the results from some query has radically changed on > favour of unicode. Errors raising about results which are not strings > anymore. Make sure you use 3.2 and not 3.1 (or 3.0) as there were improvements to the email module. -- Terry Jan Reedy From patty at cruzio.com Wed May 11 13:57:49 2011 From: patty at cruzio.com (Patty) Date: Wed, 11 May 2011 10:57:49 -0700 Subject: Proper way to handle errors in a module References: <4DCAC78E.1000901@gmail.com> Message-ID: <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> ----- Original Message ----- From: "Andrew Berg" To: Sent: Wednesday, May 11, 2011 10:29 AM Subject: Proper way to handle errors in a module > I'm a bit new to programming outside of shell scripts (and I'm no expert > there), so I was wondering what is considered the best way to handle > errors when writing a module. Do I just let exceptions go and raise > custom exceptions for errors that don't trigger a standard one? Have the > function/method return nothing or a default value and show an error > message? I'm sure there's not a clear-cut answer, but I was just > wondering what most developers would expect a module to do in certain > situations. > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi Andrew - Sometimes you want an exception come up and then use that information to take your program in some direction. For example, you might want your program to 'see' the exception that comes up when you go one beyond the end of an array. This means that something you wanted to happen within the array you set up finished successfully (the program just reached one beyond it and you didn't get an error!). The enduser doesn't need to see this displayed on the screen or in a window, you can just use an exception as-is to your advantage within the program. Regards, Patty From hg at schaathun.net Wed May 11 13:59:58 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 18:59:58 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 May 2011 10:27:49 -0400, D'Arcy J.M. Cain wrote: : When did we come to the idea that people should be able to program in a : language without actually learning it? The fact that Python comes so : close to that possibility is nothing short of revolutionary. Revolutionary indeed, so why don't we exploit the revolution and write the programs to be as accessible as possible? (Although, python is not the most revolutionary in this respect.) -- :-- Hans Georg From roy at panix.com Wed May 11 14:05:09 2011 From: roy at panix.com (Roy Smith) Date: Wed, 11 May 2011 14:05:09 -0400 Subject: Proper way to handle errors in a module References: Message-ID: In article , Andrew Berg wrote: > I'm a bit new to programming outside of shell scripts (and I'm no expert > there), so I was wondering what is considered the best way to handle > errors when writing a module. Do I just let exceptions go and raise > custom exceptions for errors that don't trigger a standard one? Have the > function/method return nothing or a default value and show an error > message? I'm sure there's not a clear-cut answer, but I was just > wondering what most developers would expect a module to do in certain > situations. In general, raise an exception when there is no valid value that can be returned from a function. Sometimes it makes more sense to return 0, None, an empty list, etc. So: count_vowels("banana") ==> 3 count_vowels("xyzzy") ==> 0 # counting "y" as not a vowel count_vowels("") ==> 0 count_vowels(None) ==> raises TypeError You want to raise specific errors. Let's say you've got a function like this: def airspeed(swallow): speeds = {"european": 42, "african", 196} return speeds[swallow] If somebody passes an invalid string, it will raise KeyError as written. Better to do something like: def airspeed(swallow): speeds = {"european": 42, "african", 196} try: return speeds[swallow] except KeyError: raise UnknownBirdError(swallow) This lets somebody catch UnknownBirdError at some higher level and do something useful. If you let KeyError escape, that's a lot harder to deal with because it could come from almost anywhere. From hg at schaathun.net Wed May 11 14:05:31 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 19:05:31 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 16:26:40 GMT, Steven D'Aprano wrote: : > 1. My concern was not about clueless newbies. They need to : > learn. My concern is about experienced scientists and engineers who : > are simply new to python. : : Which makes them clueless newbies *about Python*. I don't care how : experienced they are in astrophysics or biology or calculating the : average airspeed of an unladen swallow. Someone who knows how to program is never clueless starting a new language. Newbie, may be, but he knows most of the constructions and semantic principles to look for; most of it is learning the syntax. : Yeah, life is hard and then you die, and scientists don't even get paid : that much. So what? Do physicists write their scientific papers about : string theory with the thought "What if some Python programmer who knows : nothing about string theory is reading this? I better dumb it down." That depends on the purpose of that particular paper, but the real question is, who writes the software to test that string theory empirically? Please tell. -- :-- Hans Georg From python at mrabarnett.plus.com Wed May 11 14:08:57 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 11 May 2011 19:08:57 +0100 Subject: Proper way to handle errors in a module In-Reply-To: <4DCAC78E.1000901@gmail.com> References: <4DCAC78E.1000901@gmail.com> Message-ID: <4DCAD0B9.7030406@mrabarnett.plus.com> On 11/05/2011 18:29, Andrew Berg wrote: > I'm a bit new to programming outside of shell scripts (and I'm no expert > there), so I was wondering what is considered the best way to handle > errors when writing a module. Do I just let exceptions go and raise > custom exceptions for errors that don't trigger a standard one? Have the > function/method return nothing or a default value and show an error > message? I'm sure there's not a clear-cut answer, but I was just > wondering what most developers would expect a module to do in certain > situations. Generally speaking, a function or method should either do what it's expected to do, returning the expected result, or raise an exception if it can't. Also, it's often clearer to distinguish between a function, which returns a result, and a procedure, which doesn't (in Python it would return None). For example, if you have a list, the functional form is: sorted(my_list) which returns a new sorted list, and the procedural form is: my_list.sort() which sorts in-place (modifying the list) and returns None. From bahamutzero8825 at gmail.com Wed May 11 14:14:39 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 11 May 2011 13:14:39 -0500 Subject: Proper way to handle errors in a module In-Reply-To: <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> References: <4DCAC78E.1000901@gmail.com> <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> Message-ID: <4DCAD20F.4010206@gmail.com> On 2011.05.11 12:57 PM, Patty wrote: > Hi Andrew - > > Sometimes you want an exception come up and then use that information to > take your > program in some direction. Right, but I'm wondering how I should handle errors in a module, where different people will want their programs to do different things when an error occurs in a function or method from my module (which is not necessarily because of a bug in my module - the calling script could send a bad parameter or some system configuration could prevent the function from doing something). On one hand, I could let almost all exceptions go unhandled and have the calling script handle them. This would force the developer of the calling script to learn all the exceptions that my module could raise (which could be really annoying if I have custom exceptions for problems that don't otherwise raise an exception). OTOH, I could handle all the exceptions and return None or some default value, but that would make it harder for the developer to make the script react appropriately. From hg at schaathun.net Wed May 11 14:15:59 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 19:15:59 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 May 2011 13:50:54 -0400, Prasad, Ramit wrote: : I find this argument to be flawed. Should I stop using built-in : generators instead of range/xrange for looping through lists? : Certainly for loops with loop counting are understood more widely : than generators. Should I stop using any advanced feature Python : because it is difficult to understand without knowing Python? No; I'd suggest the most legible and intuitive construct that /does/ the job. Never something which requires one extra (illegible) page to do the job, or something which does not do the job at all. : I may not have made the point well, but I cannot see any advantage : for trying to program for the lowest common denominator. Common to what? I'd try the lowest common denominator of legibility and effictiveness. It is just KISS. -- :-- Hans Georg From tjreedy at udel.edu Wed May 11 14:24:57 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 May 2011 14:24:57 -0400 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 5/11/2011 12:27 PM, Genstein wrote: > In py3k is it necessary to flush() a file between read/write calls in order > to see consistent results? > > I ask because I have a case under Python 3.2 (r32:88445) where it does > appear to be, on both Gentoo Linux and Windows Vista. > > I've naturally read http://docs.python.org/py3k/library/io.html and > http://docs.python.org/py3k/tutorial/inputoutput.html#reading-and-writing-files > but could find no reference to such a requirement. > > PEP 3116 suggested this might not be required in py3k and the > implementation notes in bufferedio.c state "BufferedReader, > BufferedWriter and BufferedRandom...share a single buffer...this enables > interleaved reads and writes without flushing." Which seemed conclusive > but I'm seeing otherwise. > > I have a test case, which is sadly rather long: > http://pastebin.com/xqrzKr5D It's lengthy because it's autogenerated > from some rather more complex code I'm working on, in order to reproduce > the issue in isolation. I notice that you have required seek calls when switching between writing and reading. If you want others to look at this more, you should 1) produce a minimal* example that demonstrates the questionable behavior, and 2) show the comparative outputs that raise your question. The code is way too long to cut and paste into an editor and see what is does on my windows machine. *minimal = local minimum rather than global minimum. That means that removal or condensation of a line or lines removes the problem. In this case, remove extra seeks, unless doing so removes behavior discrepancy. Condense 1 byte writes to multibyte writes, unless ... . Are repeated interleavings required or is write, seek, read, seek, write enough? -- Terry Jan Reedy From tartley at tartley.com Wed May 11 14:34:32 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 11 May 2011 19:34:32 +0100 Subject: lightweight way to create new projects from templates Message-ID: <4DCAD6B8.3070003@tartley.com> Hi. I'm looking for a quick way to create new Python projects from a template. I understand that 'Paste' (http://pythonpaste.org/) is one way to do this, but I find Paste very intimidating because of all the functionality it includes. I'm not even sure whether 'creating new projects from templates' is the central goal of Paste, or just an incidental benefit that it provides while performing some other task. As a lightweight alternative, I'm creating a project called 'Genesis'. Functionally, it will be little more than a 'cp -r' followed by a few search and replace operations. I realise this idea is modest, but I think it could be helpful for: a) people who are just getting started with Python, and want to see how best to structure their projects, and b) people who are already up-to-speed, and who want to create their own templates and spawn projects from them with a minimum of effort. c) for the community, to exemplify and publicise best practices for new projects. My goals include: * Create a new project using the default template: $ genesis myproj * or using a particular project template: $ genesis --template=mytemplate myproj * Allow people to create their own templates, simply stored as directories under '~/.genesis' * Files in a template contain 'tags' of the form 'G{author}'. When a new project is created, these tags are replaced. For example, G{author} will be replaced with the value for 'author' supplied either on the command-line: $ genesis myproj author=Jonathan Or in your ~/.genesis/config file (a python file read using 'exec'): author = 'Jonathan' * The default template should embody good practices like those demonstrated in the Python Project howto: http://infinitemonkeycorps.net/docs/pph/ * The default template should include a setup.py, supporting sdist, register and upload commands. * I'd also like the default template to include things like creating Windows binaries, so that it is easier for projects to include this out of the box. It would be nice to extend this to binaries for other platforms too. * The default template for command-line applications should include an acceptance test, which invokes the script in a new process and makes assertions about stdout, stderr and exit value. * One of my inspirations is to create a good template for events like pyweek, where many people set out to write opengl or pyglet applications from scratch, and yet every time, many entrants fail to properly create binaries, etc. Genesis is only partially written, so is not yet on PyPI, but is on bitbucket: https://bitbucket.org/tartley/genesis/overview If you have any feedback, it would be very welcome. In particular: What do you think about the approach in general? What do you think about the contents of my default template: https://bitbucket.org/tartley/genesis/src/tip/genesis/config/default/ Do you think a single default template containing all the above ideas is viable? Or is it likely to be so idiosyncratic that I might be better shipping with several built-in templates, including a 'minimal' one? Do I need different templates for applications than for libraries? For console apps vs GUI apps? What do you think of my choice of 'G{name}' for replaceable tags in the template? I wanted something that would not be valid Python, and would be unlikely to occur naturally in a project. Best regards, Jonathan -- Jonathan Hartley tartley at tartley.com http://tartley.com Made of meat. +44 7737 062 225 twitter/skype: tartley From ramit.prasad at jpmchase.com Wed May 11 14:44:37 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Wed, 11 May 2011 14:44:37 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA3B33714@EMARC112VS01.exchad.jpmchase.net> > Someone who knows how to program is never clueless starting a new >language. Newbie, may be, but he knows most of the constructions >and semantic principles to look for; most of it is learning the syntax. I claim to be able to program (Java/Python), but would be absolutely lost programming in Lisp. It is more than just "learning the syntax", it includes a thought paradigm as well. Just like I claim to be able to do math, but severely suck at RPN math. (Okay, that analogy is bad but it is all I can come up with at the moment.) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -----Original Message----- From: python-list-bounces+ramit.prasad=jpmchase.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com at python.org] On Behalf Of Hans Georg Schaathun Sent: Wednesday, May 11, 2011 1:06 PM To: python-list at python.org Subject: Re: checking if a list is empty On 11 May 2011 16:26:40 GMT, Steven D'Aprano wrote: : > 1. My concern was not about clueless newbies. They need to : > learn. My concern is about experienced scientists and engineers who : > are simply new to python. : : Which makes them clueless newbies *about Python*. I don't care how : experienced they are in astrophysics or biology or calculating the : average airspeed of an unladen swallow. : Yeah, life is hard and then you die, and scientists don't even get paid : that much. So what? Do physicists write their scientific papers about : string theory with the thought "What if some Python programmer who knows : nothing about string theory is reading this? I better dumb it down." That depends on the purpose of that particular paper, but the real question is, who writes the software to test that string theory empirically? Please tell. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From ramit.prasad at jpmchase.com Wed May 11 14:50:00 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Wed, 11 May 2011 14:50:00 -0400 Subject: Proper way to handle errors in a module In-Reply-To: <4DCAD20F.4010206@gmail.com> References: <4DCAC78E.1000901@gmail.com> <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> <4DCAD20F.4010206@gmail.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA3B3373E@EMARC112VS01.exchad.jpmchase.net> The simple but code heavy system is to create two functions. One that raises an error and one that returns None or something that is mutually agreed to be invalid. You can even get away with one of them doing the actual work and the other one just as a wrapper. I feel too lazy to fix the mistakes below, but you get the idea. Def a(): Blahblah Raise SomeError Def b(): Try: A() Except SomeError: Return blah Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -----Original Message----- From: python-list-bounces+ramit.prasad=jpmchase.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com at python.org] On Behalf Of Andrew Berg Sent: Wednesday, May 11, 2011 1:15 PM To: python-list at python.org Subject: Re: Proper way to handle errors in a module On 2011.05.11 12:57 PM, Patty wrote: > Hi Andrew - > > Sometimes you want an exception come up and then use that information to > take your > program in some direction. Right, but I'm wondering how I should handle errors in a module, where different people will want their programs to do different things when an error occurs in a function or method from my module (which is not necessarily because of a bug in my module - the calling script could send a bad parameter or some system configuration could prevent the function from doing something). On one hand, I could let almost all exceptions go unhandled and have the calling script handle them. This would force the developer of the calling script to learn all the exceptions that my module could raise (which could be really annoying if I have custom exceptions for problems that don't otherwise raise an exception). OTOH, I could handle all the exceptions and return None or some default value, but that would make it harder for the developer to make the script react appropriately. -- http://mail.python.org/mailman/listinfo/python-list This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From ramit.prasad at jpmchase.com Wed May 11 14:59:34 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Wed, 11 May 2011 14:59:34 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA3B33787@EMARC112VS01.exchad.jpmchase.net> >Common to what? I'd try the lowest common denominator of >legibility and effictiveness. >It is just KISS. Fair enough. I am a sheep, so I do what other (more knowledgeable) people do. It is a fair assumption (for my specific code writing environments) that everyone who is going to read my code understands "if x:" notation or is expected to learn enough Python to understand it. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -----Original Message----- From: python-list-bounces+ramit.prasad=jpmchase.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com at python.org] On Behalf Of Hans Georg Schaathun Sent: Wednesday, May 11, 2011 1:16 PM To: python-list at python.org Subject: Re: checking if a list is empty On Wed, 11 May 2011 13:50:54 -0400, Prasad, Ramit wrote: : I find this argument to be flawed. Should I stop using built-in : generators instead of range/xrange for looping through lists? : Certainly for loops with loop counting are understood more widely : than generators. Should I stop using any advanced feature Python : because it is difficult to understand without knowing Python? No; I'd suggest the most legible and intuitive construct that /does/ the job. Never something which requires one extra (illegible) page to do the job, or something which does not do the job at all. : I may not have made the point well, but I cannot see any advantage : for trying to program for the lowest common denominator. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From nospam at torek.net Wed May 11 15:05:03 2011 From: nospam at torek.net (Chris Torek) Date: 11 May 2011 19:05:03 GMT Subject: checking if a list is empty References: <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4dcab8bf$0$29980$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: >When you call len(x) you don't care about the details of how to calculate >the length of x. The object itself knows so that you don't have to. The >same applies to truth testing. > >I have a data type that is an array of lists. When you call "if len(x) > >0" on it, it will blow up in your face, because len(x) returns a list of >lengths like [12, 0, 2, 5]. But if you say "if x", it will do the right >thing. You don't need to care how to truth-test my data type, because it >does it for you. By ignoring my type's interface, and insisting on doing >the truth-test by hand, you shoot yourself in the foot. What this really points out is that "if x" and "if len(x) > 0" are *different tests*. Consider xml.etree.ElementTree "Element" objects. The documentation says, in part: In ElementTree 1.2 and earlier, the sequence behavior means that an element without any subelements tests as false (since it's an empty sequence), even if it contains text and attributions. ... Note: This behavior is likely to change somewhat in ElementTree 1.3. To write code that is compatible in both directions, use ... "len(element)" to test for non-empty elements. In this case, when x is an Element, the result of bool(x) *could* mean just "x has sub-elements", but it could also/instead mean "x has sub-elements, text, or attributions". The issue raised at the beginning of this thread was: which test is "better" when x is a list, the test that invokes bool(x), or the test that invokes len(x)? There is no answer to that, any more than there is to which ice cream flavor is "best". [%] A more interesting question to ask, in any given bit of code, is whether bool(x) or len(x) is more appropriate for *all* the types x might take at that point, rather than whether one or the other is better for lists, where the result is defined as equivalent. (The biggest problem with answering that tends to be deciding what types x might take.) [% Chocolate with raspberry, or mint, or similar.] -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From genstein at invalid.invalid Wed May 11 15:08:08 2011 From: genstein at invalid.invalid (Genstein) Date: Wed, 11 May 2011 20:08:08 +0100 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 11/05/2011 19:24, Terry Reedy wrote: > writing and reading. If you want others to look at this more, you should > 1) produce a minimal* example that demonstrates the questionable > behavior, and 2) show the comparative outputs that raise your question. Thanks for a quick response. Perhaps I was being unclear - in py3k, given the following code and assuming no errors arise: > f = open("foo", "w+b") > f.write(b'test') > f.seek(0) > print(f.read(4)) What is the printed result supposed to be? i) b'test' ii) never b'test' iii) platform dependent/undefined/other All the best, -eg. From hg at schaathun.net Wed May 11 15:08:19 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 20:08:19 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3e3r98-k67.ln1@svn.schaathun.net> On Wed, 11 May 2011 14:59:34 -0400, Prasad, Ramit wrote: : Fair enough. I am a sheep, so I do what other (more knowledgeable) : people do. It is a fair assumption (for my specific code writing : environments) that everyone who is going to read my code understands : "if x:" notation or is expected to learn enough Python to understand it. That's fair enough. You know your code, so it is probably true. It would not be true for the code I am writing. -- :-- Hans Georg From hg at schaathun.net Wed May 11 15:13:35 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 20:13:35 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 May 2011 12:17:33 -0700, Ethan Furman wrote: : 'if li' *is* KISS. It /might/ be in some contexts, but a priori it is not, as it superimposes a truth value on a data type which is otherwise a pretty accurate model of real objects (outside python). One principle of object oriented programming is to bestow the objects with properties reflecting known properties from the domain being modelled. Lists do not have truth values in the application domain, and therefore truth values in the implementation domain is complicated. -- :-- Hans Georg From ethan at stoneleaf.us Wed May 11 15:17:33 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 May 2011 12:17:33 -0700 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCAE0CD.1040406@stoneleaf.us> Hans Georg Schaathun wrote: > On Wed, 11 May 2011 13:50:54 -0400, Prasad, Ramit > wrote: > : I find this argument to be flawed. Should I stop using built-in > : generators instead of range/xrange for looping through lists? > : Certainly for loops with loop counting are understood more widely > : than generators. Should I stop using any advanced feature Python > : because it is difficult to understand without knowing Python? > > No; I'd suggest the most legible and intuitive construct that /does/ the > job. Never something which requires one extra (illegible) page to do > the job, or something which does not do the job at all. > > : I may not have made the point well, but I cannot see any advantage > : for trying to program for the lowest common denominator. > > Common to what? I'd try the lowest common denominator of > legibility and effictiveness. > > It is just KISS. 'if li' *is* KISS. ~Ethan~ From hg at schaathun.net Wed May 11 15:26:48 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 11 May 2011 20:26:48 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 May 2011 14:44:37 -0400, Prasad, Ramit wrote: : > Someone who knows how to program is never clueless starting a new : >language. Newbie, may be, but he knows most of the constructions : >and semantic principles to look for; most of it is learning the syntax. : : I claim to be able to program (Java/Python), but would be absolutely : lost programming in Lisp. It is more than just "learning the syntax", : it includes a thought paradigm as well. OK. I should written 'how to program imperatively' ... 'new imperative language'. Or substitute functional/logical/whatever for imperative. You would not be completely clueless moving to ada/fortran/C/pascal/simula. There may be new concepts, and some concepts which must be adapted to another level of abstraction, but you do have a clue about the core concepts. -- :-- Hans Georg From rodrick.brown at gmail.com Wed May 11 16:54:16 2011 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 11 May 2011 16:54:16 -0400 Subject: How to deal with optional argument evaluation Message-ID: I'm having a hard time dealing with the following scenario My class takes a hash like the following: rdargs = {'env:'prod','feed':'opra','hostname':'host13dkp1','process':'delta','side':'a','zone','ny'} All the keys in this hash can be optional. I'm having a hard time dealing with all 36 possible combinations and I dont want to use a monstorous if not and else or etc... to evaluate all possible combinations before I call my search routine. How do others deal with situations like this? And have it look readable? if someone supplies just a host and side my search can return 400 responses, if they supply all 6 elements it can return just 1-5 matches. class RD(object): def __init__(self,**kwargs): self.value = 0 #for field in ('env', 'side', 'zone', 'feed', 'hostname', 'process', 'status'): #val = kwargs[field] if kwargs.has_key(field) else False #setattr(self, field, val) self.env = kwargs.get('env',False) self.side = kwargs.get('side',False) self.zone = kwargs.get('zone',False) self.feed = kwargs.get('feed',False) self.hostname = kwargs.get('hostname',False) self.process = kwargs.get('process',False) self.status = kwargs.get('status',False) -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown -------------- next part -------------- An HTML attachment was scrubbed... URL: From hobson42 at gmail.com Wed May 11 17:02:19 2011 From: hobson42 at gmail.com (Ian) Date: Wed, 11 May 2011 22:02:19 +0100 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCAF95B.60307@gmail.com> On 11/05/2011 20:13, Hans Georg Schaathun wrote: > On Wed, 11 May 2011 12:17:33 -0700, Ethan Furman > wrote: > : 'if li' *is* KISS. > > It /might/ be in some contexts, but a priori it is not, as it > superimposes a truth value on a data type which is otherwise > a pretty accurate model of real objects (outside python). > > One principle of object oriented programming is to bestow the > objects with properties reflecting known properties from the > domain being modelled. Lists do not have truth values in the > application domain, and therefore truth values in the > implementation domain is complicated. > Exactly. Its just a convention. If it exists, its true, if if doesn't its false. In the "real world" lists of zero items do not exist. You don't go shopping with a shopping list of zero items. You don't take a journey going nowhere. You wouldn't have a party and invite nobody. What kind of building is one with zero floors? Would you have an Aircraft Carrier with no aircraft? Oh Wait - the UK has one of those coming into service soon. Regards Ian From harrismh777 at charter.net Wed May 11 17:13:03 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 16:13:03 -0500 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab055$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hans Georg Schaathun wrote: > Code is quite often published to document algorithms, methods and > formul? for the purpose of scientific research. Since there is no > universal language which suits everything and everyone, this > is exactly what happens. One has to have the rudimentary knowledge > to read half a dozen different languages to be able to read the > code and extract the algorithms. +1 QOTW From harrismh777 at charter.net Wed May 11 17:24:47 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 16:24:47 -0500 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: D'Arcy J.M. Cain wrote: > Non-programmers should be able to program? > > Should non-doctors be able to doctor? Should cars be built so that > anyone can intuitively fix them without a mechanic? Non-programmers should not be expected to program in 'C' nor in lisp... ... but non-programmers were able to program in BASIC jes fine... I contend that non-programmers are able to learn rudimentary python and work with it to solve real problems 'without' formal training in 'programming'. Python is the New BASIC for 'people'. At least, it has the potential to be that... people should be able to talk to their computers (whatever we mean by that) and have the computer respond with real-world solutions. We need to move away from 'canned apps' to a new day where the masses can sit down to their computer and solve new problems with it through intuitive language skills. Why not? From ethan at stoneleaf.us Wed May 11 17:26:02 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 May 2011 14:26:02 -0700 Subject: How to deal with optional argument evaluation In-Reply-To: References: Message-ID: <4DCAFEEA.8040102@stoneleaf.us> Rodrick Brown wrote: > I'm having a hard time dealing with the following scenario > > My class takes a hash like the following: > rdargs = > {'env:'prod','feed':'opra','hostname':'host13dkp1','process':'delta','side':'a','zone','ny'} > > All the keys in this hash can be optional. > > I'm having a hard time dealing with all 36 possible combinations and I > dont want to use a monstorous if not and else or etc... to evaluate all > possible combinations before I call my search routine. > > How do others deal with situations like this? And have it look readable? > > if someone supplies just a host and side my search can return 400 > responses, if they supply all 6 elements it can return just 1-5 matches. > > class RD(object): > def __init__(self,**kwargs): > self.value = 0 > #for field in ('env', 'side', 'zone', 'feed', 'hostname', > 'process', 'status'): > #val = kwargs[field] if kwargs.has_key(field) else False > #setattr(self, field, val) > self.env = kwargs.get('env',False) > self.side = kwargs.get('side',False) > self.zone = kwargs.get('zone',False) > self.feed = kwargs.get('feed',False) > self.hostname = kwargs.get('hostname',False) > self.process = kwargs.get('process',False) > self.status = kwargs.get('status',False) class RD(object): def __init__( self, env=False, side=False, zone=False, feed=False, hostname=False, process=False, status=False ): self.env = env self.side = side self.zone = zone self.feed = feed self.hostname = hostname self.process = process self.status = status What does the code look like that actually uses this information? ~Ethan~ From harrismh777 at charter.net Wed May 11 17:37:49 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 16:37:49 -0500 Subject: unicode by default Message-ID: hi folks, I am puzzled by unicode generally, and within the context of python specifically. For one thing, what do we mean that unicode is used in python 3.x by default. (I know what default means, I mean, what changed?) I think part of my problem is that I'm spoiled (American, ascii heritage) and have been either stuck in ascii knowingly, or UTF-8 without knowing (just because the code points lined up). I am confused by the implications for using 3.x, because I am reading that there are significant things to be aware of... what? On my installation 2.6 sys.maxunicode comes up with 1114111, and my 2.7 and 3.2 installs come up with 65535 each. So, I am assuming that 2.6 was compiled with UCS-4 (UTF-32) option for 4 byte unicode(?) and that the default compile option for 2.7 & 3.2 (I didn't change anything) is set for UCS-2 (UTF-16) or 2 byte unicode(?). Do I understand this much correctly? The books say that the .py sources are UTF-8 by default... and that 3.x is either UCS-2 or UCS-4. If I use the file handling capabilities of Python in 3.x (by default) what encoding will be used, and how will that affect the output? If I do not specify any code points above ascii 0xFF does any of this matter anyway? Thanks. kind regards, m harris From tjreedy at udel.edu Wed May 11 17:38:26 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 May 2011 17:38:26 -0400 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 5/11/2011 3:08 PM, Genstein wrote: > On 11/05/2011 19:24, Terry Reedy wrote: >> writing and reading. If you want others to look at this more, you should >> 1) produce a minimal* example that demonstrates the questionable >> behavior, and 2) show the comparative outputs that raise your question. > > Thanks for a quick response. Perhaps I was being unclear - in py3k, > given the following code and assuming no errors arise: > > > f = open("foo", "w+b") > > f.write(b'test') > > f.seek(0) > > print(f.read(4)) > > What is the printed result supposed to be? > > i) b'test' > ii) never b'test' > iii) platform dependent/undefined/other Good clear question. I expect i). With 3.2 on winxp, that is what I get with StringIO, text file, and bytes file (the first two with b's removed). I would expect the same on any system. If you get anything different, I would consider it a bug -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed May 11 17:42:10 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 21:42:10 GMT Subject: checking if a list is empty References: <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dcb02b1$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 19:05:03 +0000, Chris Torek wrote: > In article <4dcab8bf$0$29980$c3e8da3$5496439d at news.astraweb.com> Steven > D'Aprano wrote: >>When you call len(x) you don't care about the details of how to >>calculate the length of x. The object itself knows so that you don't >>have to. The same applies to truth testing. >> >>I have a data type that is an array of lists. When you call "if len(x) > >>0" on it, it will blow up in your face, because len(x) returns a list of >>lengths like [12, 0, 2, 5]. But if you say "if x", it will do the right >>thing. You don't need to care how to truth-test my data type, because it >>does it for you. By ignoring my type's interface, and insisting on doing >>the truth-test by hand, you shoot yourself in the foot. > > What this really points out is that "if x" and "if len(x) > 0" are > *different tests*. *Potentially* different tests. Which is exactly the point. Given an arbitrary object, the developer doesn't know what test is appropriate. Should I write len(x) == 0 or list(x) == [] or x.next is None or something else? How can I tell which is appropriate without knowing everything about the internals of every object I ever see? But if x is a non-broken object, then you don't have to. Just test on x itself, because it knows what to do to be considered a truth value. Of course there may be objects where this doesn't work. There are no guarantees in Python. You can't even guarantee that printing an object won't blow up: >>> class Broken: ... def __str__(self): ... return "... %s ..." % 1/2 ... __repr__ = __str__ ... >>> b = Broken() >>> b Traceback (most recent call last): File "", line 1, in File "", line 3, in __str__ TypeError: unsupported operand type(s) for /: 'str' and 'int' > Consider xml.etree.ElementTree "Element" objects. > The documentation says, in part: > > In ElementTree 1.2 and earlier, the sequence behavior means that an > element without any subelements tests as false (since it's an empty > sequence), even if it contains text and attributions. ... > > Note: This behavior is likely to change somewhat in ElementTree 1.3. > To write code that is compatible in both directions, use ... > "len(element)" to test for non-empty elements. > > In this case, when x is an Element, the result of bool(x) *could* mean > just "x has sub-elements", but it could also/instead mean "x has > sub-elements, text, or attributions". Either behaviour is correct, but a semantic change to the class means that you have to do more work if you care about supporting both versions in the same code base. That is a neat example of where you might choose *not* to let an object decide for itself whether it is true or false, but instead impose your own definition on it. -- Steven From steve+comp.lang.python at pearwood.info Wed May 11 17:47:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 May 2011 21:47:27 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: > One principle of object oriented programming is to bestow the objects > with properties reflecting known properties from the domain being > modelled. Lists do not have truth values in the application domain Yes they do. Empty lists are nothing, ergo false, and non-empty lists are something, ergo true. -- Steven From hansmu at xs4all.nl Wed May 11 18:06:57 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 12 May 2011 00:06:57 +0200 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> Message-ID: <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> On 03/05/2011 09:52, rusi wrote: > [If you believe it is, then try writing a log(n) fib iteratively :D ] It took me a while, but this one seems to work: from collections import namedtuple Triple = namedtuple('Triple', 'hi mid lo') Triple.__mul__ = lambda self, other: Triple( self.hi * other.hi + self.mid * other.mid, self.hi * other.mid + self.mid * other.lo, self.mid * other.mid + self.lo * other.lo, ) def fib(n): f = Triple(1, 1, 0) a = Triple(1, 0, 1) while n: if n & 1: a *= f f *= f n >>= 1 return a.mid -- HansM From ian.g.kelly at gmail.com Wed May 11 18:09:29 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 11 May 2011 16:09:29 -0600 Subject: unicode by default In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 3:37 PM, harrismh777 wrote: > hi folks, > ? I am puzzled by unicode generally, and within the context of python > specifically. For one thing, what do we mean that unicode is used in python > 3.x by default. (I know what default means, I mean, what changed?) The `unicode' class was renamed to `str', and a stripped-down version of the 2.X `str' class was renamed to `bytes'. > ? I think part of my problem is that I'm spoiled (American, ascii heritage) > and have been either stuck in ascii knowingly, or UTF-8 without knowing > (just because the code points lined up). I am confused by the implications > for using 3.x, because I am reading that there are significant things to be > aware of... what? Mainly Python 3 no longer does explicit conversion between bytes and unicode, requiring the programmer to be explicit about such conversions. If you have Python 2 code that is sloppy about this, you may get some Unicode encode/decode errors when trying to run the same code in Python 3. The 2to3 tool can help somewhat with this, but it can't prevent all problems. > ? On my installation 2.6 ?sys.maxunicode comes up with 1114111, and my 2.7 > and 3.2 installs come up with 65535 each. So, I am assuming that 2.6 was > compiled with UCS-4 (UTF-32) option for 4 byte unicode(?) and that the > default compile option for 2.7 & 3.2 (I didn't change anything) is set for > UCS-2 (UTF-16) or 2 byte unicode(?). ? Do I understand this much correctly? I think that UCS-2 has always been the default unicode width for CPython, although the exact representation used internally is an implementation detail. > ? The books say that the .py sources are UTF-8 by default... and that 3.x is > either UCS-2 or UCS-4. ?If I use the file handling capabilities of Python in > 3.x (by default) what encoding will be used, and how will that affect the > output? If you open a file in binary mode, the result is a non-decoded byte stream. If you open a file in text mode and do not specify an encoding, then the result of locale.getpreferredencoding() is used for decoding, and the result is a unicode stream. > ? If I do not specify any code points above ascii 0xFF does any of this > matter anyway? You mean 0x7F, and probably, due to the need to explicitly encode and decode. From howe.steven at gmail.com Wed May 11 18:09:51 2011 From: howe.steven at gmail.com (Steven Howe) Date: Wed, 11 May 2011 15:09:51 -0700 Subject: checking if a list is empty In-Reply-To: <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCB092F.5020202@gmail.com> On 05/11/2011 02:47 PM, Steven D'Aprano wrote: > On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: > >> One principle of object oriented programming is to bestow the objects >> with properties reflecting known properties from the domain being >> modelled. Lists do not have truth values in the application domain > Yes they do. Empty lists are nothing, ergo false, and non-empty lists are > something, ergo true. > > > >>> a=[] > >>> if a: > ... print 'Yes' > ... > >>> a=[1] > >>> if a: > ... print 'Yes' > ... > Yes Cool; I'd never of thought to try that method to determine if a list was empty. I usually test it's length. This looks faster. From benjamin.kaplan at case.edu Wed May 11 18:34:02 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 May 2011 15:34:02 -0700 Subject: unicode by default In-Reply-To: References: Message-ID: On Wed, May 11, 2011 at 2:37 PM, harrismh777 wrote: > hi folks, > ? I am puzzled by unicode generally, and within the context of python > specifically. For one thing, what do we mean that unicode is used in python > 3.x by default. (I know what default means, I mean, what changed?) > > ? I think part of my problem is that I'm spoiled (American, ascii heritage) > and have been either stuck in ascii knowingly, or UTF-8 without knowing > (just because the code points lined up). I am confused by the implications > for using 3.x, because I am reading that there are significant things to be > aware of... what? > > ? On my installation 2.6 ?sys.maxunicode comes up with 1114111, and my 2.7 > and 3.2 installs come up with 65535 each. So, I am assuming that 2.6 was > compiled with UCS-4 (UTF-32) option for 4 byte unicode(?) and that the > default compile option for 2.7 & 3.2 (I didn't change anything) is set for > UCS-2 (UTF-16) or 2 byte unicode(?). ? Do I understand this much correctly? > Not really sure about that, but it doesn't matter anyway. Because even though internally the string is stored as either a UCS-2 or a UCS-4 string, you never see that. You just see this string as a sequence of characters. If you want to turn it into a sequence of bytes, you have to use an encoding. > ? The books say that the .py sources are UTF-8 by default... and that 3.x is > either UCS-2 or UCS-4. ?If I use the file handling capabilities of Python in > 3.x (by default) what encoding will be used, and how will that affect the > output? > > ? If I do not specify any code points above ascii 0xFF does any of this > matter anyway? ASCII only goes up to 0x7F. If you were using UTF-8 bytestrings, then there is a difference for anything over that range. A byte string is a sequence of bytes. A unicode string is a sequence of these mythical abstractions called characters. So a unicode string u'\u00a0' will have a length of 1. Encode that to UTF-8 and you'll find it has a length of 2 (because UTF-8 uses 2 bytes to encode everything over 128- the top bit is used to signal that you need the next byte for this character) If you want the history behind the whole encoding mess, Joel Spolsky wrote a rather amusing article explaining how this all came about: http://www.joelonsoftware.com/articles/Unicode.html And the biggest reason to use Unicode is so that you don't have to worry about your program messing up because someone hands you input in a different encoding than you used. From harrismh777 at charter.net Wed May 11 18:38:58 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 17:38:58 -0500 Subject: checking if a list is empty In-Reply-To: <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6eEyp.199$BS4.197@newsfe01.iad> Steven D'Aprano wrote: >> modelled. Lists do not have truth values in the application domain > Yes they do. Empty lists are nothing, ergo false, and non-empty lists are > something, ergo true. > No they don't. Empty lists are empty lists... which just happen to become False when type cast bool(list[])--> False. lists cannot have a truth... binary False or True... however, when cast with bool(list) they can be used in a test (even with 'not') to make some decision. Lists by themselves, empty or not, cannot have a 'truth' in an of themselves. kind regards, m harris From greg.ewing at canterbury.ac.nz Wed May 11 18:50:23 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 12 May 2011 10:50:23 +1200 Subject: Merge multiple source directories into one package with distutils? In-Reply-To: <4228410e-4631-47be-936c-041122f27ffb@glegroupsg2000goo.googlegroups.com> References: <4228410e-4631-47be-936c-041122f27ffb@glegroupsg2000goo.googlegroups.com> Message-ID: <930i5iFas9U1@mid.individual.net> Miki Tebeka wrote: > .py files from more than one source directory into a single > package when installing? > The Selenium Python bindings does something like that, have a look at http://selenium.googlecode.com/svn/trunk/setup.py Unless I'm missing something, nothing out of the ordinary is happening there. Each destination directory is getting .py files from just one source directory. I'm not talking about a package with multiple submodules, I know how to do that. I'm talking about putting .py files from more than one source directory into the same intallation directory. E.g. Source: stuff/__init__.py stuff/dir1/foo.py stuff/dir2/blarg.py Installation: stuff/__init__.py stuff/foo.py stuff/blarg.py -- Greg From harrismh777 at charter.net Wed May 11 18:51:07 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 17:51:07 -0500 Subject: unicode by default In-Reply-To: References: Message-ID: Ian Kelly wrote: Ian, Benjamin, thanks much. > The `unicode' class was renamed to `str', and a stripped-down version > of the 2.X `str' class was renamed to `bytes'. ... thank you, this is very helpful. >> > If I do not specify any code points above ascii 0xFF does any of this >> > matter anyway? > You mean 0x7F, and probably, due to the need to explicitly encode and decode. Yes, actually, I did... and from Benjamin's reply it seems that this matters only if I am working with bytes. Is it true that if I am working without using bytes sequences that I will not need to care about the encoding anyway, unless of course I need to specify a unicode code point? Thanks again. kind regards, m harris From greg.ewing at canterbury.ac.nz Wed May 11 19:08:04 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 12 May 2011 11:08:04 +1200 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <930j6nFi2lU1@mid.individual.net> Hans Georg Schaathun wrote: > 0 is a number as real and existent as any other, > one would think that the empty list is also as real and existent as > any other list. 0 does have some special properties, though, such as being the additive identity and not having a multiplicative inverse. Adding falseness as another special property isn't too much of a stretch and turns out to be useful. Likewise, it's useful to treat empty containers as having a similar special property, since they're often a base or terminating case in algorithms. It's especially useful in a dynamic language where any additional operations such as finding the length or comparing with zero has a run-time cost. Yes, you have to learn it, but it's a small thing to learn with a considerable payoff. -- Greg From harrismh777 at charter.net Wed May 11 19:12:13 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 18:12:13 -0500 Subject: checking if a list is empty In-Reply-To: <6eEyp.199$BS4.197@newsfe01.iad> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> <6eEyp.199$BS4.197@newsfe01.iad> Message-ID: harrismh777 wrote: > Lists by themselves, empty or not, cannot have a 'truth' in an of > themselves. ... forgot., Based on Ian's comment a couple of days ago... if alist: ... is actually : if bool(alist): I think this is more than just semantics or silly argumentation. Its important to understand where the boolean truth is coming from... my understanding 'now' is that the list[] has no such boolean attribute, but is cast for the 'if' construct.... so... if alist: is --> if bool(alist): and... if not alist: is also --> if not bool(alist): The 'alist[]' has no boolean attribute, right?? kind regards, m harris From martin.hellwig at gmail.com Wed May 11 19:24:46 2011 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Wed, 11 May 2011 23:24:46 +0000 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 11/05/2011 19:08, Genstein wrote: > On 11/05/2011 19:24, Terry Reedy wrote: >> writing and reading. If you want others to look at this more, you should >> 1) produce a minimal* example that demonstrates the questionable >> behavior, and 2) show the comparative outputs that raise your question. > > Thanks for a quick response. Perhaps I was being unclear - in py3k, > given the following code and assuming no errors arise: > > > f = open("foo", "w+b") > > f.write(b'test') > > f.seek(0) > > print(f.read(4)) > > What is the printed result supposed to be? > > i) b'test' > ii) never b'test' > iii) platform dependent/undefined/other > > All the best, > > -eg. from: http://docs.python.org/py3k/library/functions.html#open """ open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True)? buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows: * Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device?s ?block size? and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long. * ?Interactive? text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files. """ So given that explanation, and assuming I understand it, I go for option 'iii'. -- mph From sjmachin at lexicon.net Wed May 11 19:32:06 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 09:32:06 +1000 Subject: unicode by default In-Reply-To: References: Message-ID: On Thu, May 12, 2011 8:51 am, harrismh777 wrote: > Is it true that if I am > working without using bytes sequences that I will not need to care about > the encoding anyway, unless of course I need to specify a unicode code > point? Quite the contrary. (1) You cannot work without using bytes sequences. Files are byte sequences. Web communication is in bytes. You need to (know / assume / be able to extract / guess) the input encoding. You need to encode your output using an encoding that is expected by the consumer (or use an output method that will do it for you). (2) You don't need to use bytes to specify a Unicode code point. Just use an escape sequence e.g. "\u0404" is a Cyrillic character. From michiel at thingmajig.org Wed May 11 20:20:13 2011 From: michiel at thingmajig.org (Michiel Sikma) Date: Thu, 12 May 2011 02:20:13 +0200 Subject: urllib2 request with binary file as payload Message-ID: Hi there, I made a small script implementing a part of Youtube's API that allows you to upload videos. It's pretty straightforward and uses urllib2. The script was written for Python 2.6, but the server I'm going to use it on only has 2.5 (and I can't update it right now, unfortunately). It seems that one vital thing doesn't work in 2.5's urllib2: -- data = open(video['filename'], 'rb') opener = urllib2.build_opener(urllib2.HTTPHandler) req = urllib2.Request(settings['upload_location'], data, { 'Host': 'uploads.gdata.youtube.com', 'Content-Type': video['type'], 'Content-Length': '%d' % os.path.getsize(video['filename']) }) req.get_method = lambda: 'PUT' url = opener.open(req) -- This works just fine on 2.6: send: sendIng a read()able However, on 2.5 it refuses: Traceback (most recent call last): File "./pyup", line 119, in main() File "./pyup", line 116, in main url = opener.open(req) File "/usr/lib/python2.5/urllib2.py", line 381, in open response = self._open(req, data) File "/usr/lib/python2.5/urllib2.py", line 399, in _open '_open', req) File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 1107, in http_open return self.do_open(httplib.HTTPConnection, req) File "/usr/lib/python2.5/urllib2.py", line 1079, in do_open h.request(req.get_method(), req.get_selector(), req.data, headers) File "/usr/lib/python2.5/httplib.py", line 866, in request self._send_request(method, url, body, headers) File "/usr/lib/python2.5/httplib.py", line 892, in _send_request self.send(body) File "/usr/lib/python2.5/httplib.py", line 711, in send self.sock.sendall(str) File "", line 1, in sendall TypeError: sendall() argument 1 must be string or read-only buffer, not file Is there any other way I can do this? I'm pretty new to Python so I'm not sure how to proceed at this point. Thanks! Michiel Sikma We Demand HTML http://wedemandhtml.com/ michiel at wedemandhtml.com From jpiee at aim.com Wed May 11 20:52:26 2011 From: jpiee at aim.com (jpiee at aim.com) Date: Wed, 11 May 2011 20:52:26 -0400 (EDT) Subject: pymultimouse access violation error Message-ID: <8CDDE55FF32795F-A04-FD35@angweb-usd005.sysops.aol.com> A couple of years back Oscar Lindberg wrote a program called pymultimouse, which has a homepage at http://code.google.com/p/pymultimouse/. I've been using the file rawinputreader.py, which is avaliable in the zipped folder in the downloads section of the above link. I'm trying to get raw mouse input in a program I'm working on, and I've been trying to use pymultimouse . I'm trying to run the code he's got, but it uses ctypes, and when I try to run I'm getting this error: Traceback (most recent call last): File "C:\Users\jmite\rawinputreader.py", line 324, in pprint.pprint(rir.pollEvents()) File "C:\Users\jmite\rawinputreader.py", line 210, in pollEvents windll.user32.DispatchMessageA(pMsg) WindowsError: exception: access violation writing 0x00000001 Does anybody have ideas as to how the code could be patched to possibly fix this? There's only been one release of it, and other people seem to be able to run it just fine, so is it possibly something machine specific? I'm new to python, let alone ctypes and win32 modules, so any help would be tremendously wonderful at this point. Thanks! Jmite -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Wed May 11 20:57:31 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 10:57:31 +1000 Subject: urllib2 request with binary file as payload In-Reply-To: References: Message-ID: <2fa89ca32d0796866e0fe4121371b882.squirrel@webmail.lexicon.net> On Thu, May 12, 2011 10:20 am, Michiel Sikma wrote: > Hi there, > I made a small script implementing a part of Youtube's API that allows > you to upload videos. It's pretty straightforward and uses urllib2. > The script was written for Python 2.6, but the server I'm going to use > it on only has 2.5 (and I can't update it right now, unfortunately). > It seems that one vital thing doesn't work in 2.5's urllib2: > > -- > > data = open(video['filename'], 'rb') > > opener = urllib2.build_opener(urllib2.HTTPHandler) > req = urllib2.Request(settings['upload_location'], data, { > 'Host': 'uploads.gdata.youtube.com', > 'Content-Type': video['type'], > 'Content-Length': '%d' % os.path.getsize(video['filename']) > }) > req.get_method = lambda: 'PUT' > url = opener.open(req) > > -- > > This works just fine on 2.6: > send: > sendIng a read()able > > However, on 2.5 it refuses: > Traceback (most recent call last): [snip] > TypeError: sendall() argument 1 must be string or read-only buffer, not > file I don't use this stuff, just curious. But I can read docs. Quoting from the 2.6.6 docs: """ class urllib2.Request(url[, data][, headers][, origin_req_host][, unverifiable]) This class is an abstraction of a URL request. url should be a string containing a valid URL. data may be a string specifying additional data to send to the server, or None if no such data is needed. Currently HTTP requests are the only ones that use data; the HTTP request will be a POST instead of a GET when the data parameter is provided. data should be a buffer in the standard application/x-www-form-urlencoded format. The urllib.urlencode() function takes a mapping or sequence of 2-tuples and returns a string in this format. """ 2.6 is expecting a string, according to the above. No mention of file. Moreover it expects the data to be urlencoded. 2.7.1 docs say the same thing. Are you sure you have shown the code that worked with 2.6? From steve+comp.lang.python at pearwood.info Wed May 11 21:07:05 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 May 2011 01:07:05 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> <6eEyp.199$BS4.197@newsfe01.iad> Message-ID: <4dcb32b9$0$29973$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 17:38:58 -0500, harrismh777 wrote: > Steven D'Aprano wrote: >>> modelled. Lists do not have truth values in the application domain >> Yes they do. Empty lists are nothing, ergo false, and non-empty lists >> are something, ergo true. >> >> > No they don't. Empty lists are empty lists... which just happen to > become False when type cast bool(list[])--> False. > > lists cannot have a truth... binary False or True... however, when cast > with bool(list) they can be used in a test (even with 'not') to make > some decision. Have you been not paying any attention at all? >>> alist = [] >>> if alist: pass ... else: print "alist is a false value" ... alist is a false value >>> >>> if type(alist) is bool: pass ... else: print "but not a bool" ... but not a bool > Lists by themselves, empty or not, cannot have a 'truth' in an of > themselves. Despite your confident tone, they really do. Just like EVERY OTHER OBJECT IN PYTHON. And Perl, and Ruby, and Javascript, and PHP, and many other languages. You might not like that fact, but it is a fact. -- Steven From harrismh777 at charter.net Wed May 11 21:22:50 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 20:22:50 -0500 Subject: unicode by default In-Reply-To: References: Message-ID: John Machin wrote: > (1) You cannot work without using bytes sequences. Files are byte > sequences. Web communication is in bytes. You need to (know / assume / be > able to extract / guess) the input encoding. You need to encode your > output using an encoding that is expected by the consumer (or use an > output method that will do it for you). > > (2) You don't need to use bytes to specify a Unicode code point. Just use > an escape sequence e.g. "\u0404" is a Cyrillic character. > Thanks John. In reverse order, I understand point (2). I'm less clear on point (1). If I generate a string of characters that I presume to be ascii/utf-8 (no \u0404 type characters) and write them to a file (stdout) how does default encoding affect that file.by default..? I'm not seeing that there is anything unusual going on... If I open the file with vi? If I open the file with gedit? emacs? .... Another question... in mail I'm receiving many small blocks that look like sprites with four small hex codes, scattered about the mail... mostly punctuation, maybe? ... guessing, are these unicode code points, and if so what is the best way to 'guess' the encoding? ... is it coded in the stream somewhere...protocol? thanks From python at mrabarnett.plus.com Wed May 11 22:31:18 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 May 2011 03:31:18 +0100 Subject: unicode by default In-Reply-To: References: Message-ID: <4DCB4676.9070904@mrabarnett.plus.com> On 12/05/2011 02:22, harrismh777 wrote: > John Machin wrote: >> (1) You cannot work without using bytes sequences. Files are byte >> sequences. Web communication is in bytes. You need to (know / assume / be >> able to extract / guess) the input encoding. You need to encode your >> output using an encoding that is expected by the consumer (or use an >> output method that will do it for you). >> >> (2) You don't need to use bytes to specify a Unicode code point. Just use >> an escape sequence e.g. "\u0404" is a Cyrillic character. >> > > Thanks John. In reverse order, I understand point (2). I'm less clear on > point (1). > > If I generate a string of characters that I presume to be ascii/utf-8 > (no \u0404 type characters) and write them to a file (stdout) how does > default encoding affect that file.by default..? I'm not seeing that > there is anything unusual going on... If I open the file with vi? If I > open the file with gedit? emacs? > > .... > > Another question... in mail I'm receiving many small blocks that look > like sprites with four small hex codes, scattered about the mail... > mostly punctuation, maybe? ... guessing, are these unicode code points, > and if so what is the best way to 'guess' the encoding? ... is it coded > in the stream somewhere...protocol? > You need to understand the difference between characters and bytes. A string contains characters, a file contains bytes. The encoding specifies how a character is represented as bytes. For example: In the Latin-1 encoding, the character "?" is represented by the byte 0xA3. In the UTF-8 encoding, the character "?" is represented by the byte sequence 0xC2 0xA3. In the ASCII encoding, the character "?" can't be represented at all. The advantage of UTF-8 is that it can represent _all_ Unicode characters (codepoints, actually) as byte sequences, and all those in the ASCII range are represented by the same single bytes which the original ASCII system used. Use the UTF-8 encoding unless you have to use a different one. A file contains only bytes, a socket handles only bytes. Which encoding you should use for characters is down to protocol. A system such as email, which can handle different encodings, should have a way of specifying the encoding, and perhaps also a default encoding. From wuwei23 at gmail.com Wed May 11 23:16:01 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 11 May 2011 20:16:01 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hans Georg Schaathun wrote: > Revolutionary indeed, so why don't we exploit the revolution > and write the programs to be as accessible as possible? Where do you draw the line, though? No decorators, as they're not intuitively obvious? No custom descriptors, as that requires a deeper knowledge of Python internals that utter ignorance allows? Both of those aspects alone seem far more complex and advanced than treating empty collections as False. From steve+comp.lang.python at pearwood.info Wed May 11 23:16:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 May 2011 03:16:09 GMT Subject: unicode by default References: Message-ID: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 May 2011 03:31:18 +0100, MRAB wrote: >> Another question... in mail I'm receiving many small blocks that look >> like sprites with four small hex codes, scattered about the mail... >> mostly punctuation, maybe? ... guessing, are these unicode code points, >> and if so what is the best way to 'guess' the encoding? ... is it coded >> in the stream somewhere...protocol? >> > You need to understand the difference between characters and bytes. http://www.joelonsoftware.com/articles/Unicode.html is also a good resource. -- Steven From wuwei23 at gmail.com Wed May 11 23:31:45 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 11 May 2011 20:31:45 -0700 (PDT) Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> On May 12, 7:24?am, harrismh777 wrote: >?We need to move away from 'canned apps' to a new day where > the masses can sit down to their computer and solve new problems with it > through intuitive language skills. ?Why not? Because the vast majority of them don't seem to want to be bothered? From tlikonen at iki.fi Wed May 11 23:37:50 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Thu, 12 May 2011 06:37:50 +0300 Subject: Learning new languages (was: checking if a list is empty) References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vcxgoagh.fsf_-_@mithlond.arda> * 2011-05-11T20:26:48+01:00 * Hans Georg Schaathun wrote: > On Wed, 11 May 2011 14:44:37 -0400, Prasad, Ramit > wrote: >> I claim to be able to program (Java/Python), but would be absolutely >> lost programming in Lisp. It is more than just "learning the syntax", >> it includes a thought paradigm as well. > > OK. I should written 'how to program imperatively' ... 'new imperative > language'. Or substitute functional/logical/whatever for imperative. Common Lisp is an imperative language. It is also functional and object-oriented language. It does not force any paradigm but supports many. Thus, it is called a multi-paradigm language. I understand that Lisp can be scary, though. Lisp code looks weird and it seems that the myth that it's a functional language can't be busted. Anyway, I agree with this: * 2011-05-11T19:05:31+01:00 * Hans Georg Schaathun wrote: > Someone who knows how to program is never clueless starting a new > language. Newbie, may be, but he knows most of the constructions > and semantic principles to look for; most of it is learning the > syntax. From harrismh777 at charter.net Wed May 11 23:44:23 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 22:44:23 -0500 Subject: unicode by default In-Reply-To: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> You need to understand the difference between characters and bytes. > > http://www.joelonsoftware.com/articles/Unicode.html > > is also a good resource. Thanks for being patient guys, here's what I've done: >>>> astr="pound sign" >>>> asym=" \u00A3" >>>> afile=open("myfile", mode='w') >>>> afile.write(astr + asym) > 12 >>>> afile.close() When I edit "myfile" with vi I see the 'characters' : pound sign ? ... same with emacs, same with gedit ... When I hexdump myfile I see this: 0000000 6f70 6375 2064 6973 6e67 c220 00a3 This is *not* what I expected... well it is (little-endian) right up to the 'c2' and that is what is confusing me.... I did not open the file with an encoding of UTF-8... so I'm assuming UTF-16 by default (python3) so I was expecting a '00A3' little-endian as 'A300' but what I got instead was UTF-8 little-endian 'c2a3' .... See my problem?... when I open the file with emacs I see the character pound sign... same with gedit... they're all using UTF-8 by default. By default it looks like Python3 is writing output with UTF-8 as default... and I thought that by default Python3 was using either UTF-16 or UTF-32. So, I'm confused here... also, I used the character sequence \u00A3 which I thought was UTF-16... but Python3 changed my intent to 'c2a3' which is the normal UTF-8... Thanks again for your patience... I really do hate to be dense about this... but this is another area where I'm just beginning to dabble and I'd like to know soon what I'm doing... Thanks for the link Steve... I'm headed there now... kind regards, m harris From nospam at torek.net Wed May 11 23:49:05 2011 From: nospam at torek.net (Chris Torek) Date: 12 May 2011 03:49:05 GMT Subject: checking if a list is empty References: <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc6a39a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4dc6a39a$0$29991$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: >In English, [the word "not"] negates a word or statement: > >"the cat is not on the mat" --> "the cat is on the mat" is false. As a mostly off topic aside, English is considerably more complicated than that. There are people who use the word "not" as a purely boolean operator (a la computer languages), so that "the cat is not not on the mat" means "the cat IS on the mat", but others use double negation as a form of intensifier, so that the phrase with multiple "not"s is simply a more emphatic claim: the cat is really, truly, *definitely*, not on that particular mat. :-) In various other "natural languages" -- i.e., languages meant for human-to-human communications, rather than for computers -- multiple negatives are more often (or always?) intensifiers. Some languages have the idea of "negative matching" in much the same sense that English has number [%] matching: "the cat is on the mat" and "the cats are on the mat" are OK because the noun and verb numbers match, but neither "the cats is on the mat" nor "the cat are on the mat" are correct. [% "Number" here is really 1 vs not-1: no cats, one cat, two cats.] Of course, there are descriptivists and prescriptivists, and many of the latter claim that using multi-valued boolean logic in English is "nonstandard" or "invalid". Many of those in turn will tell you that "ain't good English" ain't good English. Still, one should be aware of these forms and their uses, in much the same way as one should be able to boldly split infinitives. :-) Moving back towards on-topic-ness: >As an operator, "not" negates a true value to a false value. In >mathematical Boolean algebra, there only is one true value and one false >value, conventionally called True/False or 1/0. In non-Boolean algebras, >you can define other values. In three-value logic, the negation of True/ >False/Maybe is usually False/True/Maybe. In fuzzy logic, the logic values >are the uncountable infinity (that's a technical term, not hyperbole) of >real numbers between 0 and 1. Or, to put it another way, before we can communicate clearly, we have to pick out a set of rules. Most computer languages do this pretty well, and Python does a good (and reasonably conventional) job: >Python uses a boolean algebra where there are many ways of spelling the >true and false values. The "not" operator returns the canonical bool >values: > >not returns False >not returns True > >Take note of the distinction between lower-case true/false, which are >adjectives, and True/False, which are objects of class bool. (At least as of current versions of Python -- in much older versions there was no real distinction between booleans and type "int", presumably a a holdover from C.) [remainder snipped as I have nothing else to add] -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From rosuav at gmail.com Wed May 11 23:51:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 13:51:12 +1000 Subject: checking if a list is empty In-Reply-To: <4DCAF95B.60307@gmail.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4DCAF95B.60307@gmail.com> Message-ID: On Thu, May 12, 2011 at 7:02 AM, Ian wrote: > In the "real world" ?lists of zero items do not exist. > You don't go shopping with a shopping list of zero items. Actually, yes you do. You maintain your shopping list between trips; whenever you need something, you put it on the list immediately. Then when you go shopping, you just take the list with you (if you're lucky, you don't need to move or copy it at all, you just get another reference to it). Once you're done, you empty the list - you now have a shopping list with zero items (until you get home and realize you forgot something). Chris Angelico From harrismh777 at charter.net Wed May 11 23:53:45 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 11 May 2011 22:53:45 -0500 Subject: checking if a list is empty In-Reply-To: <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> Message-ID: alex23 wrote: >> through intuitive language skills. Why not? > Because the vast majority of them don't seem to want to be bothered? > That could very well be... but I have a hope for them. I honestly think its not because they don't want to be bothered, rather they just think its too far past them... and not do-able. This is where I think it would be helpful at the undergraduate level to insist that *all* students learn some programming (and yes, using Python). Actually, I am thinking that it would be great to begin this in grade school. But then, I'm also one of those Americans who believe that every student should learn at least (1) non-English language beginning in 1st grade--- mandatory. (of course others are just hoping they learn English...) kind regards, m harris From sjmachin at lexicon.net Wed May 11 23:54:20 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 13:54:20 +1000 Subject: unicode by default In-Reply-To: References: Message-ID: On Thu, May 12, 2011 11:22 am, harrismh777 wrote: > John Machin wrote: >> (1) You cannot work without using bytes sequences. Files are byte >> sequences. Web communication is in bytes. You need to (know / assume / >> be >> able to extract / guess) the input encoding. You need to encode your >> output using an encoding that is expected by the consumer (or use an >> output method that will do it for you). >> >> (2) You don't need to use bytes to specify a Unicode code point. Just >> use >> an escape sequence e.g. "\u0404" is a Cyrillic character. >> > > Thanks John. In reverse order, I understand point (2). I'm less clear > on point (1). > > If I generate a string of characters that I presume to be ascii/utf-8 > (no \u0404 type characters) > and write them to a file (stdout) how does > default encoding affect that file.by default..? I'm not seeing that > there is anything unusual going on... About """characters that I presume to be ascii/utf-8 (no \u0404 type characters)""": All Unicode characters (including U+0404) are encodable in bytes using UTF-8. The result of sys.stdout.write(unicode_characters) to a TERMINAL depends mostly on sys.stdout.encoding. This is likely to be UTF-8 on a linux/OSX/platform. On a typical American / Western European /[former] colonies Windows box, this is likely to be cp850 on a Command Prompt window, and cp1252 in IDLE. UTF-8: All Unicode characters are encodable in UTF-8. Only problem arises if the terminal can't render the character -- you'll get spaces or blobs or boxes with hex digits in them or nothing. Windows (Command Prompt window): only a small subset of characters can be encoded in e.g. cp850; anything else causes an exception. Windows (IDLE): ignores sys.stdout.encoding and renders the characters itself. Same outcome as *x/UTF-8 above. If you write directly (or sys.stdout is redirected) to a FILE, the default encoding is obtained by sys.getdefaultencoding() and is AFAIK ascii unless the machine's site.py has been fiddled with to make it UTF-8 or something else. > If I open the file with vi? If > I open the file with gedit? emacs? Any editor will have a default encoding; if that doesn't match the file encoding, you have a (hopefully obvious) problem if the editor doesn't detect the mismatch. Consult your editor's docs or HTFF1K. > Another question... in mail I'm receiving many small blocks that look > like sprites with four small hex codes, scattered about the mail... > mostly punctuation, maybe? ... guessing, are these unicode code > points, yes > and if so what is the best way to 'guess' the encoding? google("chardet") or rummage through the mail headers (but 4 hex digits in a box are a symptom of inability to render, not necessarily caused by an incorrect decoding) ... is > it coded in the stream somewhere...protocol? Should be. From rosuav at gmail.com Thu May 12 00:00:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 14:00:08 +1000 Subject: lightweight way to create new projects from templates In-Reply-To: <4DCAD6B8.3070003@tartley.com> References: <4DCAD6B8.3070003@tartley.com> Message-ID: On Thu, May 12, 2011 at 4:34 AM, Jonathan Hartley wrote: > Hi. > > I'm looking for a quick way to create new Python projects from a template. > > I understand that 'Paste' (http://pythonpaste.org/) is one way to do this, > but I find Paste very intimidating because of all the functionality it > includes. I'm not even sure whether 'creating new projects from templates' > is the central goal of Paste, or just an incidental benefit that it provides > while performing some other task. > > As a lightweight alternative, I'm creating a project called 'Genesis'. > Functionally, it will be little more than a 'cp -r' followed by a few search > and replace operations. Depending on how simple your goals are, it might be possible to do it with a simple shell or Python script that creates multiple files and/or directories. That way, your template is all contained in a single file, which is convenient for distribution and such; and the scripting facilities can handle the search and replace operations. Chris Angelico From ben+python at benfinney.id.au Thu May 12 00:07:08 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 May 2011 14:07:08 +1000 Subject: unicode by default References: Message-ID: <874o50k1eb.fsf@benfinney.id.au> MRAB writes: > You need to understand the difference between characters and bytes. Yep. Those who don't need to join us in the third millennium, and the resources pointed out in this thread are good to help that. > A string contains characters, a file contains bytes. That's not true for Python 2. I'd phrase that as: * Text is a sequence of characters. Most inputs to the program, including files, sockets, etc., contain a sequence of bytes. * Always know whether you're dealing with text or with bytes. No object can be both. * In Python 2, ?str? is the type for a sequence of bytes. ?unicode? is the type for text. * In Python 3, ?str? is the type for text. ?bytes? is the type for a sequence of bytes. -- \ ?I went to a garage sale. ?How much for the garage?? ?It's not | `\ for sale.?? ?Steven Wright | _o__) | Ben Finney From tjreedy at udel.edu Thu May 12 00:12:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 00:12:02 -0400 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/11/2011 11:44 PM, harrismh777 wrote: > Steven D'Aprano wrote: >>> You need to understand the difference between characters and bytes. >> >> http://www.joelonsoftware.com/articles/Unicode.html >> >> is also a good resource. > > Thanks for being patient guys, here's what I've done: > >>>>> astr="pound sign" >>>>> asym=" \u00A3" >>>>> afile=open("myfile", mode='w') >>>>> afile.write(astr + asym) >> 12 >>>>> afile.close() > > > When I edit "myfile" with vi I see the 'characters' : > > pound sign ? > > ... same with emacs, same with gedit ... > > > When I hexdump myfile I see this: > > 0000000 6f70 6375 2064 6973 6e67 c220 00a3 > This is *not* what I expected... well it is (little-endian) right up to > the 'c2' and that is what is confusing me.... > I did not open the file with an encoding of UTF-8... so I'm assuming > UTF-16 by default (python3) so I was expecting a '00A3' little-endian as > 'A300' but what I got instead was UTF-8 little-endian 'c2a3' .... > > See my problem?... when I open the file with emacs I see the character > pound sign... same with gedit... they're all using UTF-8 by default. By > default it looks like Python3 is writing output with UTF-8 as default... > and I thought that by default Python3 was using either UTF-16 or UTF-32. > So, I'm confused here... also, I used the character sequence \u00A3 > which I thought was UTF-16... but Python3 changed my intent to 'c2a3' > which is the normal UTF-8... If you open a file as binary (bytes), you must write bytes, and they are stored without transformation. If you open in text mode, you must write text (string as unicode in 3.2) and Python will encode to bytes using either some default or the encoding you specified in the open statement. It does not matter how Python stored the unicode internally. Does this help? Your intent is signalled by how you open the file. -- Terry Jan Reedy From sjmachin at lexicon.net Thu May 12 00:14:35 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 14:14:35 +1000 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 1:44 pm, harrismh777 wrote: > By > default it looks like Python3 is writing output with UTF-8 as default... > and I thought that by default Python3 was using either UTF-16 or UTF-32. > So, I'm confused here... also, I used the character sequence \u00A3 > which I thought was UTF-16... but Python3 changed my intent to 'c2a3' > which is the normal UTF-8... Python uses either a 16-bit or a 32-bit INTERNAL representation of Unicode code points. Those NN bits have nothing to do with the UTF-NN encodings, which can be used to encode the codepoints as byte sequences for EXTERNAL purposes. In your case, UTF-8 has been used as it is the default encoding on your platform. From benjamin.kaplan at case.edu Thu May 12 00:14:49 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 May 2011 21:14:49 -0700 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 11, 2011 at 8:44 PM, harrismh777 wrote: > Steven D'Aprano wrote: >>> >>> You need to understand the difference between characters and bytes. >> >> http://www.joelonsoftware.com/articles/Unicode.html >> >> is also a good resource. > > Thanks for being patient guys, here's what I've done: > >>>>> astr="pound sign" >>>>> asym=" \u00A3" >>>>> afile=open("myfile", mode='w') >>>>> afile.write(astr + asym) >> >> 12 >>>>> >>>>> afile.close() > > > When I edit "myfile" with vi I see the 'characters' : > > pound sign ? > > ? ... same with emacs, same with gedit ?... > > > When I hexdump myfile I see this: > > 0000000 6f70 6375 2064 6973 6e67 c220 00a3 > > > This is *not* what I expected... well it is (little-endian) right up to the > 'c2' and that is what is confusing me.... > > I did not open the file with an encoding of UTF-8... so I'm assuming UTF-16 > by default (python3) so I was expecting a '00A3' little-endian as 'A300' but > what I got instead was UTF-8 little-endian ?'c2a3' .... > quick note here: UTF-8 doesn't have an endian-ness. It's always read from left to right, with the high bit telling you whether you need to continue or not. So it's always "little endian". > See my problem?... when I open the file with emacs I see the character pound > sign... same with gedit... they're all using UTF-8 by default. By default it > looks like Python3 is writing output with UTF-8 as default... and I thought > that by default Python3 was using either UTF-16 or UTF-32. So, I'm confused > here... ?also, I used the character sequence \u00A3 which I thought was > UTF-16... but Python3 changed my intent to ?'c2a3' which is the normal > UTF-8... > The fact that CPython uses UCS-2 or UCS-4 internally is an implementation detail and isn't actually part of the Python specification. As far as a Python program is concerned, a Unicode string is a list of character objects, not bytes. Much like any other object, a unicode character needs to be serialized before it can be written to a file. An encoding is a serialization function for characters. If the file you're writing to doesn't specify an encoding, Python will default to locale.getdefaultencoding(), which tries to get your system's preferred encoding from environment variables (in other words, the same source that emacs and gedit will use to get the default encoding). From sjmachin at lexicon.net Thu May 12 00:41:47 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 14:41:47 +1000 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 2:14 pm, Benjamin Kaplan wrote: > > If the file you're writing to doesn't specify an encoding, Python will > default to locale.getdefaultencoding(), No such attribute. Perhaps you mean locale.getpreferredencoding() From hg at schaathun.net Thu May 12 01:20:37 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 06:20:37 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca7db5$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5a7s98-m68.ln1@svn.schaathun.net> On Wed, 11 May 2011 20:16:01 -0700 (PDT), alex23 wrote: : Hans Georg Schaathun wrote: : > Revolutionary indeed, so why don't we exploit the revolution : > and write the programs to be as accessible as possible? : : Where do you draw the line, though? I said that, "as possible". You draw it at the limit of possibility. : No decorators, as they're not intuitively obvious? No custom : descriptors, as that requires a deeper knowledge of Python internals : that utter ignorance allows? When they help clarify or simplify the code, they are good. When they do nothing of the sort, they aren't. : Both of those aspects alone seem far more complex and advanced than : treating empty collections as False. Probably, but they also seem far more useful. -- :-- Hans Georg From hg at schaathun.net Thu May 12 01:21:28 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 06:21:28 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb03ef$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 21:47:27 GMT, Steven D'Aprano wrote: : On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: : > One principle of object oriented programming is to bestow the objects : > with properties reflecting known properties from the domain being : > modelled. Lists do not have truth values in the application domain : : Yes they do. Empty lists are nothing, ergo false, and non-empty lists are : something, ergo true. What application domain has established that terminology? -- :-- Hans Georg From swavijay at gmail.com Thu May 12 01:35:14 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Thu, 12 May 2011 11:05:14 +0530 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: I tried using QThread as well.. But the problem is, on the run method when i invoke the command prompt, it sends out the finished signal... I want it to send out the finished signal only on closing the command prompt that is invoked earlier in my process. guess some logic to be implement inside run() which monitors the command prompt / reports the status once the command prompt is closed. I tried running loop inside the run() to keep the thread active but no help.. class RunMonitor(QThread): def __init__(self, parent = None): QThread.__init__(self) def run(self): print 'Invoking command prompt...............' subprocess.call(["start", "/DC:\\PerfLocal_PAL", "scripts_to_execute.bat"], shell=True) while True: pass def runscript(self): print 'Complete_file_Path inside Run script is : ' , self.complete_file_path file_operation.Generate_Bat_File(self.complete_file_path) self.run_monitor_object = RunMonitor() self.run_monitor_object.start() self.connect(self.run_monitor_object, SIGNAL("finished()"),self.threadstatus) On Wed, May 11, 2011 at 9:25 PM, Wojtek Mamrak wrote: > 2011/5/11 Chris Angelico : > > On Thu, May 12, 2011 at 1:16 AM, Wojtek Mamrak > wrote: > >> Is there any special reason you don't want to use QThread? > >> > http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details > > > > Other than that QThread is part of QT and threading isn't, what are > > the advantages of QThread? Is it possible (safe) to manipulate QT > > objects - in this case, the button - from a thread other than the one > > that created them? (If not, that would be a good reason for using > > QThread, which will fire an event upon termination.) > > > > > QThread provides mechanism of signals and slots ("from" and "to" the > thread), which are used across all pyQt. Unfortunately it is not > possible to use any widget classes in the thread (direct quote from > the docs). On the other hand signals can fire methods from the main > thread (running the app'a main loop), so this is not a big deal. > The signals are: > - finished > - started > - terminated > It is possible to block the thread, make it sleep, check whether the > thread is running, and few others. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Thu May 12 01:44:07 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 12 May 2011 17:44:07 +1200 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <931adaF9g1U1@mid.individual.net> Roy Smith wrote: > Hans Georg Schaathun wrote: >>If both are numbers, they are converted to a common type. Otherwise, >>objects of different types always compare unequal That's just the default treatment for unrelated types that don't know anything about each other. I would guess that the list's == method is asking "Is the other object a list?", and since a subclass of list is also a list, it's happy and goes on to compare the elements. -- Greg From darcy at druid.net Thu May 12 01:49:05 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 12 May 2011 01:49:05 -0400 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110512014905.96c592f6.darcy@druid.net> On Wed, 11 May 2011 16:24:47 -0500 harrismh777 wrote: > D'Arcy J.M. Cain wrote: > Non-programmers should not be expected to program in 'C' nor in lisp... > > ... but non-programmers were able to program in BASIC jes fine... They still had to learn the language. > I contend that non-programmers are able to learn rudimentary python and > work with it to solve real problems 'without' formal training in > 'programming'. When did the discussion shift from "learn the language" to "formal training?" How you learn the language is totally irrelevant. > Python is the New BASIC for 'people'. At least, it has the potential to > be that... people should be able to talk to their computers (whatever > we mean by that) and have the computer respond with real-world > solutions. We need to move away from 'canned apps' to a new day where > the masses can sit down to their computer and solve new problems with it > through intuitive language skills. Why not? That's not programming. That's using a canned app that a programmer wrote that takes your unstructured input and does something useful with it. Spreadsheets are a primitive example of that. Google is a more advanced example. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From hg at schaathun.net Thu May 12 02:06:42 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 07:06:42 +0100 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> Message-ID: On Thu, 12 May 2011 17:44:07 +1200, Gregory Ewing wrote: : Roy Smith wrote: : > Hans Georg Schaathun wrote: : >>If both are numbers, they are converted to a common type. Otherwise, : >>objects of different types always compare unequal Actually, I did not. :-- hg From hg at schaathun.net Thu May 12 02:13:28 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 07:13:28 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> Message-ID: <8das98-nd8.ln1@svn.schaathun.net> On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 wrote: : On May 12, 7:24?am, harrismh777 wrote: : >?We need to move away from 'canned apps' to a new day where : > the masses can sit down to their computer and solve new problems with it : > through intuitive language skills. ?Why not? : : Because the vast majority of them don't seem to want to be bothered? Why does that matter? There is a sizeable group who need computers for purposes not (sufficiently) supported by the `canned apps'. The fact that they are outnumbered by users who really only need typewriters and entertainment theatres does in no way reduce the need of those who actually need /computers/. -- :-- Hans Georg From steve+comp.lang.python at pearwood.info Thu May 12 02:13:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 May 2011 06:13:34 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> Message-ID: <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 May 2011 22:53:45 -0500, harrismh777 wrote: > alex23 wrote: >>> through intuitive language skills. Why not? >> Because the vast majority of them don't seem to want to be bothered? >> >> > That could very well be... but I have a hope for them. I honestly think > its not because they don't want to be bothered, rather they just think > its too far past them... and not do-able. An admirable hope, but there is a significant amount of research into teaching computer programming that suggests that learning to program is simply beyond a large portion of the population, no matter what you do or what language you teach. Some 30-60% of people barely get past "Hello World". (That's not to imply that they're dumb, just that whatever mental skills are needed for programming is beyond them, just as whatever mental skills are needed for writing poetry are beyond me.) http://www.codinghorror.com/blog/2006/07/separating-programming-sheep-from-non-programming-goats.html Shorter version: it seems that programming aptitude is a bimodal distribution, with very little migration from the "can't program" hump into the "can program" hump. There does seem to be a simple predictor for which hump you fall into: those who intuitively develop a consistent model of assignment (right or wrong, it doesn't matter, so long as it is consistent) can learn to program. Those who don't, can't. -- Steven From harrismh777 at charter.net Thu May 12 02:14:37 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 12 May 2011 01:14:37 -0500 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: John Machin wrote: > On Thu, May 12, 2011 2:14 pm, Benjamin Kaplan wrote: >> >> If the file you're writing to doesn't specify an encoding, Python will >> default to locale.getdefaultencoding(), > > No such attribute. Perhaps you mean locale.getpreferredencoding() >>> import locale >>> locale.getpreferredencoding() 'UTF-8' >>> Yessssssss! :) From hg at schaathun.net Thu May 12 02:21:09 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 07:21:09 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 12 May 2011 01:49:05 -0400, D'Arcy J.M. Cain wrote: : That's not programming. That's using a canned app that a programmer : wrote that takes your unstructured input and does something useful with : it. Spreadsheets are a primitive example of that. Google is a more : advanced example. You are really trying to defend the programmers' status as a modern day priesthood, mastering a mystic art completely inaccessible to those not initiated. For ages, the literate elite deliberately made the language cryptic to protect their art and their status. Some programmers seem to do the same. The fact is that it is not black and white. There are programmers with domain expertise, programmers without domain expertise, domain experts with decent programming skills, domain experts with rudimentary programming skills, monolingual programmers, domain experts without programming skills, polyglot programmers etc. Only very narrow-purpose applications can be created by one of these groups on their own, and to collaborate their abilities must be overlapping. -- :-- Hans Georg From hg at schaathun.net Thu May 12 02:23:20 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 07:23:20 +0100 Subject: checking if a list is empty References: <4dca9310$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcab8bf$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dcb02b1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 May 2011 21:42:10 GMT, Steven D'Aprano wrote: : *Potentially* different tests. Which is exactly the point. Given an : arbitrary object, the developer doesn't know what test is appropriate. : Should I write len(x) == 0 or list(x) == [] or x.next is None or : something else? How can I tell which is appropriate without knowing : everything about the internals of every object I ever see? Sure, but the question asked was how to check if a /list/ is empty. You defend your answer assuming a different question. You could at least have the decency to change the subject header when you go down that route. -- :-- Hans Georg From harrismh777 at charter.net Thu May 12 02:31:16 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 12 May 2011 01:31:16 -0500 Subject: unicode by default In-Reply-To: <874o50k1eb.fsf@benfinney.id.au> References: <874o50k1eb.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > I'd phrase that as: > * Text is a sequence of characters. Most inputs to the program, > including files, sockets, etc., contain a sequence of bytes. > * Always know whether you're dealing with text or with bytes. No object > can be both. > * In Python 2, ?str? is the type for a sequence of bytes. ?unicode? is > the type for text. > * In Python 3, ?str? is the type for text. ?bytes? is the type for a > sequence of bytes. That is very helpful... thanks MRAB, Steve, John, Terry, Ben F, Ben K, Ian... ...thank you guys so much, I think I've got a better picture now of what is going on... this is also one place where I don't think the books are as clear as they need to be at least for me...(Lutz, Summerfield). So, the UTF-16 UTF-32 is INTERNAL only, for Python... and text in/out is based on locale... in my case UTF-8 ...that is enormously helpful for me... understanding locale on this system is as mystifying as unicode is in the first place. Well, after reading about unicode tonight (about four hours) I realize that its not really that hard... there's just a lot of details that have to come together. Straightening out that whole tower-of-babel thing is sure a pain in the butt. I also was not aware that UTF-8 chars could be up to six(6) byes long from left to right. I see now that the little-endianness I was ascribing to python is just a function of hexdump... and I was a little disappointed to find that hexdump does not support UTF-8, just ascii...doh. Anyway, thanks again... I've got enough now to play around a bit... PS thanks Steve for that link, informative and entertaining too... Joe says, "If you are a programmer . . . and you don't know the basics of characters, character sets, encodings, and Unicode, and I catch you, I'm going to punish you by making you peel onions for 6 months in a submarine. I swear I will". :) kind regards, m harris From swavijay at gmail.com Thu May 12 02:31:30 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Thu, 12 May 2011 12:01:30 +0530 Subject: Need Assistance on this program. Message-ID: Hi All, I'm new bie to python thread programming and would like to assistance on the attached code. In this, I'm calling a thread to invoke a command prompt and would like to print the "Thread as alive" as long as the command prompt is opened and would like to print "Thread is Dead" only when the command prompt is closed by the user. based on my understand I have written this peace of code which does not seem to work. There is some flaw in the logic which I could not understand since I'm not that familiar with the thread concepts. Can somebody help me in getting this piece of code working. Also can somebody point me to a good tutorial on understanding python thread programming since I want to get my understanding on the concept of thread better. I googled a few but quite confusing. -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Thread_Example1.py Type: application/octet-stream Size: 830 bytes Desc: not available URL: From harrismh777 at charter.net Thu May 12 02:43:23 2011 From: harrismh777 at charter.net (harrismh777) Date: Thu, 12 May 2011 01:43:23 -0500 Subject: unicode by default In-Reply-To: References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Terry Reedy wrote: > It does not matter how Python stored the unicode internally. Does this > help? Your intent is signalled by how you open the file. Very much, actually, thanks. I was missing the 'internal' piece, and did not realize that if I didn't specify the encoding on the open that python would pull the default encoding from locale... kind regards, m harris From ben+python at benfinney.id.au Thu May 12 02:46:38 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 May 2011 16:46:38 +1000 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <8das98-nd8.ln1@svn.schaathun.net> Message-ID: <87zkmsifg1.fsf@benfinney.id.au> Hans Georg Schaathun writes: > On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 > wrote: > : On May 12, 7:24?am, harrismh777 wrote: > : >?We need to move away from 'canned apps' to a new day where > : > the masses can sit down to their computer and solve new problems with it > : > through intuitive language skills. ?Why not? > : > : Because the vast majority of them don't seem to want to be bothered? > > Why does that matter? There is a sizeable group who need computers > for purposes not (sufficiently) supported by the `canned apps'. Those people, outnumbered by the masses as you say, are thereby not themselves ?the masses?. -- \ ?Hey Homer! You're late for English!? ?Pff! English, who needs | `\ that? I'm never going to England!? ?Barney & Homer, _The | _o__) Simpsons_ | Ben Finney From hg at schaathun.net Thu May 12 03:28:03 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 08:28:03 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <8das98-nd8.ln1@svn.schaathun.net> <87zkmsifg1.fsf@benfinney.id.au> Message-ID: <3pes98-eh8.ln1@svn.schaathun.net> On Thu, 12 May 2011 16:46:38 +1000, Ben Finney wrote: : Hans Georg Schaathun writes: : : > On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 : > wrote: : > : On May 12, 7:24?am, harrismh777 wrote: : > : >?We need to move away from 'canned apps' to a new day where : > : > the masses can sit down to their computer and solve new problems with it : > : > through intuitive language skills. ?Why not? : > : : > : Because the vast majority of them don't seem to want to be bothered? : > : > Why does that matter? There is a sizeable group who need computers : > for purposes not (sufficiently) supported by the `canned apps'. : : Those people, outnumbered by the masses as you say, are thereby not : themselves ?the masses?. So what? Do we only need solutions and systems for the masses? What about systems for those who develop systems for the masses? Or the theory necessary to develop the systems to develop more advanced systems for the masses in the future? Get real, software development and programming is more than just overpriced web systems that just almost manage to replicate the functionality of IBM page based terminals and mainframes of 1973, just slower and with more eye candy. -- :-- Hans Georg From ben+python at benfinney.id.au Thu May 12 03:37:58 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 May 2011 17:37:58 +1000 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <8das98-nd8.ln1@svn.schaathun.net> <87zkmsifg1.fsf@benfinney.id.au> <3pes98-eh8.ln1@svn.schaathun.net> Message-ID: <87vcxgid2h.fsf@benfinney.id.au> Hans Georg Schaathun writes: > On Thu, 12 May 2011 16:46:38 +1000, Ben Finney > wrote: > : Hans Georg Schaathun writes: > : > : > On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 > : > wrote: > : > : On May 12, 7:24?am, harrismh777 wrote: > : > : >?We need to move away from 'canned apps' to a new day where > : > : > the masses can sit down to their computer and solve new problems with it > : > : > through intuitive language skills. ?Why not? > : > : > : > : Because the vast majority of them don't seem to want to be bothered? > : > > : > Why does that matter? There is a sizeable group who need computers > : > for purposes not (sufficiently) supported by the `canned apps'. > : > : Those people, outnumbered by the masses as you say, are thereby not > : themselves ?the masses?. > > So what? Do we only need solutions and systems for the masses? Your ?why does that matter?? was addressed to an answer specifically in the context of ?a new day where the masses can sit down to their computer and ??. The question is asked and answered. If you want to raise a *new* topic ? that of the non-masses who have different needs ? it's best not to start with ?Why does that matter?? but to lay out your separate case. -- \ ?Visitors are expected to complain at the office between the | `\ hours of 9 and 11 a.m. daily.? ?hotel, Athens | _o__) | Ben Finney From nagle at animats.com Thu May 12 03:40:08 2011 From: nagle at animats.com (John Nagle) Date: Thu, 12 May 2011 00:40:08 -0700 Subject: Python Developers with 5 years of experience In-Reply-To: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> References: <5f0086e5-96e3-4589-999a-dd43569a0b13@glegroupsg2000goo.googlegroups.com> Message-ID: <4dcb8ef9$0$60254$742ec2ed@news.sonic.net> On 5/4/2011 10:32 AM, Jerome jjcpl.rpo wrote: > send resumes to jerome at jjcpl.net > > > One of our client in New Jersey is looking for Python Developers with > 5 years of experience. If you have any resumes please send it > across. Very strange recruiting organization. Strong Christian religious orientation, but run from India. "He who trusts in the LORD will be prospered ! Proverb 28:25" "JEHOVAH JIREH COMMUNICATIONS is promoted by a group of professionals with extensive IT experience, especially in the Staffing Industry, across the globe." Headoffice Plot No 158, CGE Colony First Street Tuticorin - 628003 Tamilnadu Phone no: 91 461 4005333 / 3290473 Fax No: 91 461 4001473 Email : contact at jjcpl.net John Nagle From sjmachin at lexicon.net Thu May 12 03:58:24 2011 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2011 17:58:24 +1000 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> Message-ID: <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> On Thu, May 12, 2011 4:31 pm, harrismh777 wrote: > > So, the UTF-16 UTF-32 is INTERNAL only, for Python NO. See one of my previous messages. UTF-16 and UTF-32, like UTF-8 are encodings for the EXTERNAL representation of Unicode characters in byte streams. > I also was not aware that UTF-8 chars could be up to six(6) byes long > from left to right. It could be, once upon a time in ISO faerieland, when it was thought that Unicode could grow to 2**32 codepoints. However ISO and the Unicode consortium have agreed that 17 planes is the utter max, and accordingly a valid UTF-8 byte sequence can be no longer than 4 bytes ... see below >>> chr(17 * 65536) Traceback (most recent call last): File "", line 1, in ValueError: chr() arg not in range(0x110000) >>> chr(17 * 65536 - 1) '\U0010ffff' >>> _.encode('utf8') b'\xf4\x8f\xbf\xbf' >>> b'\xf5\x8f\xbf\xbf'.decode('utf8') Traceback (most recent call last): File "", line 1, in File "C:\python32\lib\encodings\utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xf5 in position 0: invalid start byte From tartley at tartley.com Thu May 12 04:04:58 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 12 May 2011 01:04:58 -0700 (PDT) Subject: lightweight way to create new projects from templates In-Reply-To: Message-ID: <8c898c2b-d858-41f0-950f-14570c0931c9@glegroupsg2000goo.googlegroups.com> Hey Chris, Thanks for the thoughts. I must confess I had already given up on a 'single file' approach, because I want to make it easy for people to create their own templates, so I have to handle copying a template defined by creating a new directory full of diles. If I'm already handling this case, I thought, I might as well bundle the built-in default templates as a bunch of files. I'd hope to provide platform binaries to make download and install easy for end-users, regardless of what Python version they already have installed. Which reminds me, I should make sure the default template works on Python2.x as well as 3.x. Thanks! From tartley at tartley.com Thu May 12 04:04:58 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 12 May 2011 01:04:58 -0700 (PDT) Subject: lightweight way to create new projects from templates In-Reply-To: Message-ID: <8c898c2b-d858-41f0-950f-14570c0931c9@glegroupsg2000goo.googlegroups.com> Hey Chris, Thanks for the thoughts. I must confess I had already given up on a 'single file' approach, because I want to make it easy for people to create their own templates, so I have to handle copying a template defined by creating a new directory full of diles. If I'm already handling this case, I thought, I might as well bundle the built-in default templates as a bunch of files. I'd hope to provide platform binaries to make download and install easy for end-users, regardless of what Python version they already have installed. Which reminds me, I should make sure the default template works on Python2.x as well as 3.x. Thanks! From michiel at wedemandhtml.com Thu May 12 04:05:52 2011 From: michiel at wedemandhtml.com (Michiel Sikma) Date: Thu, 12 May 2011 10:05:52 +0200 Subject: urllib2 request with binary file as payload In-Reply-To: <2fa89ca32d0796866e0fe4121371b882.squirrel@webmail.lexicon.net> References: <2fa89ca32d0796866e0fe4121371b882.squirrel@webmail.lexicon.net> Message-ID: > > 2.6 is expecting a string, according to the above. No mention of file. > Moreover it expects the data to be urlencoded. 2.7.1 docs say the same > thing. Are you sure you have shown the code that worked with 2.6? > > > -- > http://mail.python.org/mailman/listinfo/python-list > Yes, in fact I simply tried passing the file to the Request class without having checked the docs to see if I could even do that, but it worked. I also send an unencoded XML string a little bit earlier on. Maybe it no longer needs to be a urlencoded string as soon as you add a Content-Type header. Here's what happens when I put the HTTPHandler in debug mode and pass a file in 2.6: send: 'PUT /resumable/feeds/api/users/default/uploads?upload_id=[id]HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 898801\r\nHost: uploads.gdata.youtube.com\r\nContent-Type: application/octet-stream\r\nConnection: close\r\nUser-Agent: Python-urllib/2.6\r\n\r\n' send: sendIng a read()able A little while later: reply: 'HTTP/1.1 201 Created\r\n' [...etc] So it seems to work just fine, but 2.5 does indeed complain about this being an incorrect use of Request. Moreover, though I can't upgrade my Python from 2.5 I was able to compile another alongside it (latest stable 2.7) and use that with my code, and it worked just fine. Uploaded a 6GB file to Youtube this way. :) Michiel Sikma We Demand HTML http://wedemandhtml.com/ michiel at wedemandhtml.com From rosuav at gmail.com Thu May 12 04:08:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 18:08:05 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 3:35 PM, vijay swaminathan wrote: > I tried using QThread as well.. But the problem is, on the run method when i > invoke the command prompt, it sends out the finished signal...? I want it to > send out the finished signal only on closing the command prompt that is > invoked earlier in my process. > ??????? subprocess.call(["start", "/DC:\\PerfLocal_PAL", > "scripts_to_execute.bat"], shell=True) This is your problem, still. You need to change to a call that waits. In my testing on Windows (Python 2.6.5), this can be done with os.system() quite happily. Change that, and it should all work. Chris Angelico From andrea.crotti.0 at gmail.com Thu May 12 05:16:36 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 12 May 2011 11:16:36 +0200 Subject: Need Assistance on this program. In-Reply-To: References: Message-ID: vijay swaminathan writes: > Hi All, > > I'm new bie to python thread programming and would like to assistance > on the attached code. > > In this, I'm calling a thread to invoke a command prompt and would > like to print the "Thread as alive" as long as the command prompt is > opened and would like to print "Thread is Dead" only when the command > prompt is closed by the user. > > based on my understand I have written this peace of code which does > not seem to work. There is some flaw in the logic which I could not > understand since I'm not that familiar with the thread concepts. > > Can somebody help me in getting this piece of code working. > > Also can somebody point me to a good tutorial on understanding python > thread programming since I want to get my understanding on the concept > of thread better. I googled a few but quite confusing. > > -- > Vijay Swaminathan Easy mistake, this: if mythread_object.is_alive: is wrong, since is_alive is a method, not a bool so it should be is_alive(). Pay attention to these things, and actually something called "is_adjective" is almost never a variable. From swavijay at gmail.com Thu May 12 05:42:39 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Thu, 12 May 2011 15:12:39 +0530 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: Hi Chris, I tried using os.system as well but it did not even open up the command prompt. Can you please share the code that worked for you.. just wondering if I'm missing something very basic. Regards, -Vijay Swaminathan., On Thu, May 12, 2011 at 1:38 PM, Chris Angelico wrote: > On Thu, May 12, 2011 at 3:35 PM, vijay swaminathan > wrote: > > I tried using QThread as well.. But the problem is, on the run method > when i > > invoke the command prompt, it sends out the finished signal... I want it > to > > send out the finished signal only on closing the command prompt that is > > invoked earlier in my process. > > > subprocess.call(["start", "/DC:\\PerfLocal_PAL", > > "scripts_to_execute.bat"], shell=True) > > This is your problem, still. You need to change to a call that waits. > In my testing on Windows (Python 2.6.5), this can be done with > os.system() quite happily. Change that, and it should all work. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From swavijay at gmail.com Thu May 12 05:45:07 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Thu, 12 May 2011 15:15:07 +0530 Subject: Need Assistance on this program. In-Reply-To: References: Message-ID: I tried using that as well. The problem is, the thread becomes dead as soon as it executes the invocation of command prompt. I want the thread to be alive till I go and manually close the command prompt. -Vijay Swaminathan. On Thu, May 12, 2011 at 2:46 PM, Andrea Crotti wrote: > vijay swaminathan writes: > > > Hi All, > > > > I'm new bie to python thread programming and would like to assistance > > on the attached code. > > > > In this, I'm calling a thread to invoke a command prompt and would > > like to print the "Thread as alive" as long as the command prompt is > > opened and would like to print "Thread is Dead" only when the command > > prompt is closed by the user. > > > > based on my understand I have written this peace of code which does > > not seem to work. There is some flaw in the logic which I could not > > understand since I'm not that familiar with the thread concepts. > > > > Can somebody help me in getting this piece of code working. > > > > Also can somebody point me to a good tutorial on understanding python > > thread programming since I want to get my understanding on the concept > > of thread better. I googled a few but quite confusing. > > > > -- > > Vijay Swaminathan > > Easy mistake, this: > if mythread_object.is_alive: > > is wrong, since is_alive is a method, not a bool so it should be > is_alive(). > > Pay attention to these things, and actually something called > "is_adjective" is almost never a variable. > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Thu May 12 06:08:11 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 12 May 2011 11:08:11 +0100 Subject: Need Assistance on this program. In-Reply-To: References: Message-ID: <4DCBB18B.5050309@timgolden.me.uk> On 12/05/2011 10:45, vijay swaminathan wrote: > > I tried using that as well. > The problem is, the thread becomes dead as soon as it executes the > invocation of command prompt. Can you post the code you're using, please? This should be simple so maybe you've misunderstood something in the threading / subprocess mix. TJG From swavijay at gmail.com Thu May 12 06:29:51 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Thu, 12 May 2011 15:59:51 +0530 Subject: Need Assistance on this program. In-Reply-To: <4DCBB18B.5050309@timgolden.me.uk> References: <4DCBB18B.5050309@timgolden.me.uk> Message-ID: Hi Tim, I have already done that. But for some reason my response went as a new thread. Attaching the code again. On Thu, May 12, 2011 at 3:38 PM, Tim Golden wrote: > On 12/05/2011 10:45, vijay swaminathan wrote: > >> >> I tried using that as well. >> The problem is, the thread becomes dead as soon as it executes the >> invocation of command prompt. >> > > Can you post the code you're using, please? > > This should be simple so maybe you've misunderstood > something in the threading / subprocess mix. > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Thread_Example1.py Type: application/octet-stream Size: 814 bytes Desc: not available URL: From mail at timgolden.me.uk Thu May 12 06:38:02 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 12 May 2011 11:38:02 +0100 Subject: Need Assistance on this program. In-Reply-To: References: <4DCBB18B.5050309@timgolden.me.uk> Message-ID: <4DCBB88A.8020702@timgolden.me.uk> On 12/05/2011 11:29, vijay swaminathan wrote: <... snippet from code ...> print 'Invoking Command Promptt..............' #subprocess.call(["start", "/DC:\\PerfLocal_PAL", "scripts_to_execute.bat"], shell=True) subprocess.call(["start", "C:\\windows\\system32\\cmd.exe"], shell = True) self.status() If you want to use start, use start /wait. But you don't have to: import threading import time import subprocess def run_command (command): # # .call is shorthand for: start process and wait # CREATE_NEW_CONSOLE prevents it from getting messed # up with the Python console # subprocess.call ( [command], creationflags=subprocess.CREATE_NEW_CONSOLE ) t = threading.Thread (target=run_command, args=("cmd.exe",)) t.start () while t.is_alive (): print "alive" time.sleep (0.5) print "Thread is dead" TJG From rosuav at gmail.com Thu May 12 06:46:15 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 20:46:15 +1000 Subject: NewBie Doubt in Python Thread Programming In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 7:42 PM, vijay swaminathan wrote: > Hi Chris, > > I tried using os.system as well but it did not even open up the command > prompt. > > Can you please share the code that worked for you.. just wondering if I'm > missing something very basic. Caveat: I'm not using Qt, I just tried this in IDLE (which is graphical). C:\>copy con test.bat echo Hello, world! pause ^Z 1 file(s) copied. IDLE 2.6.5 >>> import os >>> os.system("c:\\test.bat") 0 The 0 and subsequent prompt don't appear until the batch file finishes. Meanwhile, the batch file is executing in a separate window. When you try it inside Qt, do you get a background window that needs to be brought to the front? Does execution pause while the batch file runs? Chris Angelico From qtvali at gmail.com Thu May 12 07:06:52 2011 From: qtvali at gmail.com (Tambet) Date: Thu, 12 May 2011 14:06:52 +0300 Subject: Slice implementation bug Message-ID: Hello! Let's say slice is multidimensional now - how to interpret it? I excpect these to work: - m[0, 3] - get one element from matrix - m[0:2, 0:2] - get four elements from matrix, iterate over them (I have actually an rtree if it doesn't make sense to you) But it won't, because if m[0, 3] returns something, then m[0:2, 0:2] cannot yield anymore. Ofcourse I could return an iterator, but this would not be so simple. So, maybe we need these: - __isslice__(key) - return true, false - __getitem__(key) - return a value - __getslice__(key) - yield a lots of values So that if isslice returns true, getslice will be called. Would be much more beauty! Right now it's ugly. I love Python, but I also love n-dimensional spaces and those are ugly in Python - last time I did Matrix multiplication I could not implement m[0, 3] (stupid errors), could not m[0j + 3], could not use tuple. Now I was happy that it's implemented and just ran into another problem that I have to choose, if getter returns one or many :) Ofcourse I could return list or other iterable, but I want to be able to do it with three-liner, because the rest of my code mostly consists of those. Except the few masterfunctions, which do some complex manipulations with data. I also need to implement things like that, which also return true for __isslice__: m[Circle(0, 0, 10)] - for RTree, any shape object implementing getExtent and doesOverlap can be used as slice index. Because I do complex map transformations and all this trivial stuff must be *hidden*! Tambet -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Thu May 12 07:36:27 2011 From: roy at panix.com (Roy Smith) Date: Thu, 12 May 2011 07:36:27 -0400 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> Message-ID: In article <931adaF9g1U1 at mid.individual.net>, Gregory Ewing wrote: > Roy Smith wrote: > >>If both are numbers, they are converted to a common type. Otherwise, > >>objects of different types always compare unequal > > That's just the default treatment for unrelated types that don't > know anything about each other. > > I would guess that the list's == method is asking "Is the > other object a list?", and since a subclass of list is also > a list, it's happy and goes on to compare the elements. Well, that explains what's happening, but the behavior still doesn't match the docs. Is this a bug or are the docs wrong? From andrea.crotti.0 at gmail.com Thu May 12 08:12:37 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 12 May 2011 14:12:37 +0200 Subject: Slice implementation bug In-Reply-To: References: Message-ID: Tambet writes: > Hello! > > Let's say slice is multidimensional now - how to interpret it? > But who said that slice is multidimensional in the first place? Since python is not matlab I don't think it will ever be done, so what's the purpose of talking about a bug in something that doesn't exist? PS. probably in numpy you can find what you look for From rosuav at gmail.com Thu May 12 08:16:10 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 22:16:10 +1000 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 at 4:21 PM, Hans Georg Schaathun wrote: > On Thu, 12 May 2011 01:49:05 -0400, D'Arcy J.M. Cain > ? wrote: > : ?That's not programming. ?That's using a canned app that a programmer > : ?wrote that takes your unstructured input and does something useful with > : ?it. ?Spreadsheets are a primitive example of that. ?Google is a more > : ?advanced example. > > You are really trying to defend the programmers' status as a modern > day priesthood, mastering a mystic art completely inaccessible to > those not initiated. Anyone can join. Not everyone wants to join. Me, I'm happy here as a priest of the software industry, and I have no desire to become a priest of, say, automotive engineering or concrete pouring. Would an expert concreter be expected to explain to me exactly how to make different sorts of concrete, or would he be expected simply to fulfill his contract and provide me with my structure? Chris Angelico From roy at panix.com Thu May 12 08:23:04 2011 From: roy at panix.com (Roy Smith) Date: Thu, 12 May 2011 08:23:04 -0400 Subject: list equal to subclass of list? Message-ID: I have a vague feeling this may have been discussed a long time ago, but I can't find the thread, so I'll bring it up again. I recently observed in the "checking if a list is empty" thread that a list and a subclass of list can compare equal: ---------------------------- class MyList(list): "I'm a subclass" l1 = [] l2 = MyList() print type(l1), type(l2) print type(l1) == type(l2) print l1 == l2 ---------------------------- when run, prints: False True The docs say: [http://docs.python.org/library/stdtypes.html] Objects of different types, except different numeric types and different string types, never compare equal [http://docs.python.org/release/2.7/reference/expressions.html#notin] objects of different types (emphasis)always compare unequal In the test code above, l1 an l2 are different types, at least in the sense that type() returns something different for each of them. What's the intended behavior here? Either the code is wrong or the docs are wrong. From nobody at nowhere.net.no Thu May 12 08:40:08 2011 From: nobody at nowhere.net.no (TheSaint) Date: Thu, 12 May 2011 20:40:08 +0800 Subject: unicode by default References: <4dcb50f8$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: John Machin wrote: > On Thu, May 12, 2011 2:14 pm, Benjamin Kaplan wrote: >> >> If the file you're writing to doesn't specify an encoding, Python will >> default to locale.getdefaultencoding(), > > No such attribute. Perhaps you mean locale.getpreferredencoding() what about sys.getfilesystemencoding() In the event to distribuite a program how to guess which encoding will the user has? -- goto /dev/null From hg at schaathun.net Thu May 12 08:43:51 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 12 May 2011 13:43:51 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <791t98-659.ln1@svn.schaathun.net> On Thu, 12 May 2011 22:16:10 +1000, Chris Angelico wrote: : Anyone can join. Not everyone wants to join. Me, I'm happy here as a : priest of the software industry, and I have no desire to become a : priest of, say, automotive engineering or concrete pouring. Would an : expert concreter be expected to explain to me exactly how to make : different sorts of concrete, or would he be expected simply to fulfill : his contract and provide me with my structure? Of course he would. When a piece of software to calculate the properties or recipes for different kinds of concrete is needed. -- :-- Hans Georg From james.housden at deutsche-boerse.com Thu May 12 09:11:42 2011 From: james.housden at deutsche-boerse.com (JamesEM) Date: Thu, 12 May 2011 06:11:42 -0700 (PDT) Subject: generate properties code in class dynamically Message-ID: Hello, I have a python class that contains a dictionary. I would like to use python properties to access the elements of the dictionary. This could be achieved as follows: class MyClass(object): def __init__(self): self.d = {} d['field1'] = 1.0 d['field2'] = 'A' d['field3'] = [10.0,20.0,30.0] @property def field1(self): return self.d['field1'] @field1.setter def field1(self, value): self.d['field1'] = value @field1.deleter def field1(self): del self.d['field1'] @property def field2(self): return self.d['field2'] @field1.setter def field2(self, value): self.d['field2'] = value @field1.deleter def field2(self): del self.d['field2'] @property def field3(self): return self.d['field3'] @field3.setter def field3(self, value): self.d['field3'] = value @field3.deleter def field3(self): del self.d['field3'] However, I am effectively writing the same properties code three times. I would prefer to generate the properties code dynamically from the keys of the dictionaries. What I am looking for is something like: class MyClass(object): def __init__(self): self.d = {} d['field1'] = 1.0 d['field2'] = 'A' d['field3'] = [10.0,20.0,30.0] for f in d: create_property(f) where create_property(f) dynamically creates the property code for field f in MyClass. Is this possible? If so, how could I do it? Thanks, James From rosuav at gmail.com Thu May 12 09:20:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 May 2011 23:20:20 +1000 Subject: checking if a list is empty In-Reply-To: <791t98-659.ln1@svn.schaathun.net> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <791t98-659.ln1@svn.schaathun.net> Message-ID: On Thu, May 12, 2011 at 10:43 PM, Hans Georg Schaathun wrote: > On Thu, 12 May 2011 22:16:10 +1000, Chris Angelico > ? wrote: > : ?Anyone can join. Not everyone wants to join. Me, I'm happy here as a > : ?priest of the software industry, and I have no desire to become a > : ?priest of, say, automotive engineering or concrete pouring. Would an > : ?expert concreter be expected to explain to me exactly how to make > : ?different sorts of concrete, or would he be expected simply to fulfill > : ?his contract and provide me with my structure? > > Of course he would. ?When a piece of software to calculate the > properties or recipes for different kinds of concrete is needed. Writing a program requires expertise both in programming and in the purpose for which it's being written. Ultimately, a programmer is a translator; without proper comprehension of the material he's translating, he can't make a clear translation. But that's completely different from hiring someone to do a job, and then looking at the job afterwards; if I order a concreting job, I'll look at whether it's properly suited to the task, but I won't expect an explanation of exactly what went into it, and I do not expect to understand the exact chemistry of it. Only another expert in concrete would truly comprehend it all. Chris Angelico From genstein at invalid.invalid Thu May 12 09:30:18 2011 From: genstein at invalid.invalid (Genstein) Date: Thu, 12 May 2011 14:30:18 +0100 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: > With 3.2 on winxp, that is what I get with StringIO, text file, and > bytes file (the first two with b's removed). I would expect the same on > any system. If you get anything different, I would consider it a bug Thanks Terry, you're entirely right there; I trimmed down my test case, asked for confirmation and have reported it as http://bugs.python.org/issue12062. Noted here in case anyone else trips over it. From thorsten at thorstenkampe.de Thu May 12 09:38:31 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 12 May 2011 15:38:31 +0200 Subject: Customize help output from optparse (or argparse) Message-ID: Hi, I'm using optparse for a little Python script. 1. The output from "--help" is: """ Usage: script.py script.py does something Options: -h, --help show this help message and exit """ I would prefer to have the description before the usage, like... """ script.py does something Usage: script.py Options: -h, --help show this help message and exit """ 2. The output from "--doesnotexit" is: """ Usage: script.py script.py: error: no such option: --doesnotexist """ I would prefer to have the error first, then the usage and additionally the options, like... """ script.py: error: no such option: --doesnotexist Usage: script.py Options: -h, --help show this help message and exit """ Is that possible with either optparse or the "new kid on the block" argparse. If so how? Thorsten From akabaila at pcug.org.au Thu May 12 09:41:54 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Thu, 12 May 2011 23:41:54 +1000 Subject: list equal to subclass of list? In-Reply-To: References: Message-ID: <201105122341.54998.akabaila@pcug.org.au> On Thursday 12 May 2011 22:23:04 Roy Smith wrote: > I have a vague feeling this may have been discussed a long > time ago, but I can't find the thread, so I'll bring it up > again. > > I recently observed in the "checking if a list is empty" > thread that a list and a subclass of list can compare equal: > > ---------------------------- > class MyList(list): > "I'm a subclass" > > l1 = [] > l2 = MyList() > > print type(l1), type(l2) > print type(l1) == type(l2) > print l1 == l2 > ---------------------------- > > when run, prints: > > > False > True > > The docs say: > > [http://docs.python.org/library/stdtypes.html] > Objects of different types, except different numeric types > and different string types, never compare equal > > [http://docs.python.org/release/2.7/reference/expressions.htm > l#notin] objects of different types (emphasis)always compare > unequal > > In the test code above, l1 an l2 are different types, at > least in the sense that type() returns something different > for each of them. What's the intended behavior here? > Either the code is wrong or the docs are wrong. Subclassing of lists can be tricky, as you have indicated. Here is another simple example: Using Python 3.2, >>> class Array(list): def __init__(self): print(type(self)) temp = [[0,0], [0,0]] print('temp =', temp) self = temp[:] print(type(self), type(temp)) print('self =', self) >>> a = Array() temp = [[0, 0], [0, 0]] self = [[0, 0], [0, 0]] So copying *values* of a list to a subclass of list ( tem[:]) makes converts the subclass back to its parent... The equality of list is rather an ambiguous concept. For instance, a euclidian vector is usually represented by a list of 3 vector components. So if two vectors are of equal length and point in opposite directions, are they equal to each other? The answer is clearly no. The other difficulty is that a list is creted by [], viz. lst = []. So an array has to use the square brackets with great care not to be converted back to a list. Thanks for your nice example and pointers to docs. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Thu May 12 10:02:37 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 07:02:37 -0700 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4DCAF95B.60307@gmail.com> Message-ID: <4DCBE87D.6000300@stoneleaf.us> Chris Angelico wrote: > On Thu, May 12, 2011 at 7:02 AM, Ian wrote: >> In the "real world" lists of zero items do not exist. >> You don't go shopping with a shopping list of zero items. > > Actually, yes you do. You maintain your shopping list between trips; > whenever you need something, you put it on the list immediately. Then > when you go shopping, you just take the list with you (if you're > lucky, you don't need to move or copy it at all, you just get another > reference to it). Once you're done, you empty the list - you now have > a shopping list with zero items (until you get home and realize you > forgot something). Um -- you contradicted Ian, then contradicted yourself -- according to your scenario your shopping list is *not* empty when you go to the store (otherwise known as "going shopping" ;). ~Ethan~ From ayaskanta.swain at altair.com Thu May 12 10:11:00 2011 From: ayaskanta.swain at altair.com (Ayaskanta Swain) Date: Thu, 12 May 2011 19:41:00 +0530 Subject: os.popen command working differently on Windows Message-ID: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> Hi All, Please help me in solving the following issue I am facing while executing my python script. Basically I am executing the OS specific move command to move a file/dir from one location to another. I am executing the 'mv' command on linux & the 'move' DOS command on windows machine from my python script. Everything works fine on linux & windows , but the script fails to detect a particular error situation on Windows, which is very important for my application. Normally the move operation fails if we try to move a directory to a location where the same directory already exists. That means overwriting of directories is not allowed by the OS for move operation. For example on Windows command prompt - "move /Y C:\temp\my_dir C:\stage\profiles\" will fail with Access is Denied message if C:\stage\profiles\ already contains my_dir inside it. It is an expected OS behavior. But the problem is that, this error message is not thrown if the command is executed from a python script. --- filemove.py script has the following code - .................................................. import os src = sys.argv[1] dst = sys.argv[2] # Using the DOS command 'move'. Adding quotes("") to avoid issues with spaces in the path. command = 'move' + ' ' + '/Y' + ' ' + '"' + src + '"' + ' ' + '"' + dst + '"' try: os.popen(command) except IOError: print 'fatal: failed to execute move command' except OSError, err: print >> sys.stderr, "System Error while making a copy from " + src + " to " + dst ........................................................................ .................... The script executes without giving any error msg and returns 0 exit code, but in the back ground the directory is not moved to the destination. I am providing the source & destination values as command line arguments to the script. On Linux this type of use case gives me the OS error message "cannot overwrite directory" which makes it easy for me to catch the error message & return it the end user. But I wonder why is this not the case on Windows. Any help to solve this will be great. Thanks Ayaskant- -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 12 10:13:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 May 2011 00:13:06 +1000 Subject: checking if a list is empty In-Reply-To: <4DCBE87D.6000300@stoneleaf.us> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4DCAF95B.60307@gmail.com> <4DCBE87D.6000300@stoneleaf.us> Message-ID: On Fri, May 13, 2011 at 12:02 AM, Ethan Furman wrote: > Chris Angelico wrote: >> >> On Thu, May 12, 2011 at 7:02 AM, Ian wrote: >>> >>> In the "real world" ?lists of zero items do not exist. >>> You don't go shopping with a shopping list of zero items. >> >> Actually, yes you do. You maintain your shopping list between trips; >> whenever you need something, you put it on the list immediately. Then >> when you go shopping, you just take the list with you (if you're >> lucky, you don't need to move or copy it at all, you just get another >> reference to it). Once you're done, you empty the list - you now have >> a shopping list with zero items (until you get home and realize you >> forgot something). > > Um -- you contradicted Ian, then contradicted yourself -- according to your > scenario your shopping list is *not* empty when you go to the store > (otherwise known as "going shopping" ;). Ehh, mea culpa (I shouldn't post in haste). Replace "Actually, yes you do" with "Actually, yes they do". Indeed you do not *go shopping* with a list of zero items; but a shopping list with no items on it DOES exist (when you come back). def do_shopping(): if shopping_list: goto shop; # Muahahahahaha. for item in shopping_list: inventory.append(item) return; # Muahahahaha again! Chris Angelico From pruebauno at latinmail.com Thu May 12 10:14:36 2011 From: pruebauno at latinmail.com (nn) Date: Thu, 12 May 2011 07:14:36 -0700 (PDT) Subject: generate properties code in class dynamically References: Message-ID: <922112f8-956f-49da-9a95-fd2eccd4911f@l30g2000vbn.googlegroups.com> On May 12, 9:11?am, JamesEM wrote: > Hello, > I have a python class that contains a dictionary. > I would like to use python properties to access the elements of the > dictionary. > This could be achieved as follows: > > class MyClass(object): > > ? ? def __init__(self): > ? ? ? ? self.d = {} > ? ? ? ? d['field1'] = 1.0 > ? ? ? ? d['field2'] = 'A' > ? ? ? ? d['field3'] = [10.0,20.0,30.0] > > ? ? @property > ? ? def field1(self): > ? ? ? ? return self.d['field1'] > > ? ? @field1.setter > ? ? def field1(self, value): > ? ? ? ? self.d['field1'] = value > > ? ? @field1.deleter > ? ? def field1(self): > ? ? ? ? del self.d['field1'] > > ? ? @property > ? ? def field2(self): > ? ? ? ? return self.d['field2'] > > ? ? @field1.setter > ? ? def field2(self, value): > ? ? ? ? self.d['field2'] = value > > ? ? @field1.deleter > ? ? def field2(self): > ? ? ? ? del self.d['field2'] > > ? ? @property > ? ? def field3(self): > ? ? ? ? return self.d['field3'] > > ? ? @field3.setter > ? ? def field3(self, value): > ? ? ? ? self.d['field3'] = value > > ? ? @field3.deleter > ? ? def field3(self): > ? ? ? ? del self.d['field3'] > > However, I am effectively writing the same properties code three > times. > I would prefer to generate the properties code dynamically from the > keys of the dictionaries. > What I am looking for is something like: > > class MyClass(object): > > ? ? def __init__(self): > ? ? ? ? self.d = {} > ? ? ? ? d['field1'] = 1.0 > ? ? ? ? d['field2'] = 'A' > ? ? ? ? d['field3'] = [10.0,20.0,30.0] > ? ? ? ? for f in d: > ? ? ? ? ? ?create_property(f) > > where create_property(f) dynamically creates the property code for > field f in MyClass. > > Is this possible? > If so, how could I do it? > > Thanks, > James Some searching in the cookbook should help. I found this: http://code.activestate.com/recipes/577590-dictionary-whos-keys-act-like-attributes-as-well/ From mail at timgolden.me.uk Thu May 12 10:21:41 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 12 May 2011 15:21:41 +0100 Subject: os.popen command working differently on Windows In-Reply-To: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> References: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> Message-ID: <4DCBECF5.2050908@timgolden.me.uk> On 12/05/2011 15:11, Ayaskanta Swain wrote: > Please help me in solving the following issue I am facing while > executing my python script. Basically I am executing the OS specific > move command to move a file/dir from one location to another. Why? Why not use os.rename or shutil.move which already do whatever is needed under the covers for different Operating Systems? os.popen returns a file-like object from which you can read any error messages generated. You're not doing that, and os.popen won't raise an error itself unless you, say, pass it a number rather than a string. import os output = os.popen ("dir") print output.read () # # But note: # os.popen ("Nonsen*se") # raises no exception TJG From python at mrabarnett.plus.com Thu May 12 10:45:51 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 May 2011 15:45:51 +0100 Subject: os.popen command working differently on Windows In-Reply-To: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> References: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> Message-ID: <4DCBF29F.20801@mrabarnett.plus.com> On 12/05/2011 15:11, Ayaskanta Swain wrote: > Hi All, > > Please help me in solving the following issue I am facing while > executing my python script. Basically I am executing the OS specific > move command to move a file/dir from one location to another. I am > executing the ?mv? command on linux & the ?move? DOS command on windows > machine from my python script. Everything works fine on linux & windows > , but the script fails to detect a particular error situation on > Windows, which is very important for my application. > > Normally the move operation fails if we try to move a directory to a > location where the same directory already exists. That means overwriting > of directories is not allowed by the OS for move operation. > > For example on Windows command prompt ? *?move /Y C:\temp\my_dir > C:\stage\profiles\?* will fail with *Access is Denied* message if > C:\stage\profiles\ already contains my_dir inside it. It is an expected > OS behavior. But the problem is that, this error message is not thrown > if the command is executed from a python script. > > --- > > filemove.py script has the following code ? > > ????????????????.. > > import os > > src = sys.argv[1] > dst = sys.argv[2] > > # Using the DOS command 'move'. Adding quotes("") to avoid issues with spaces in the path. > > command = 'move' + ' ' + '/Y' + ' ' + '"' + src + '"' + ' ' + '"' + dst + '"' > > try: > os.popen(command) > except IOError: > print 'fatal: failed to execute move command' > except OSError, err: > print >> sys.stderr, "System Error while making a copy from " + src + " to " + dst > > ??????????????????????????????.. > > The script executes without giving any error msg and returns 0 exit > code, but in the back ground the directory is not moved to the > destination. I am providing the source & destination values as command > line arguments to the script. > > On Linux this type of use case gives me the OS error message ?cannot > overwrite directory? which makes it easy for me to catch the error > message & return it the end user. But I wonder why is this not the case > on Windows. Any help to solve this will be great. > os.popen(command) will just call the command. If the command fails, its exit code will be non-zero, but that won't make Python raise an exception. os.popen(...) will return an object and you can get the exit code of the command on closing it: p = os.popen(command) exit_code = p.close() On my PC (Windows XP) I get None (not 0) if the command succeeded and 1 if it failed. From up2date.cyborg at gmail.com Thu May 12 11:06:05 2011 From: up2date.cyborg at gmail.com (up2date.cyborg) Date: Thu, 12 May 2011 17:06:05 +0200 Subject: urllib2.urlopen+BadStatusLine+https Message-ID: <4DCBF75D.4020603@gmail.com> Hi, I am new to this list, I don't really know if I should post here my request. Anyway. The following code is raising httplib.BadStatusLine on urllib2.urlopen(url) url = 'https://stat.netaffiliation.com/requete.php?login=xxx&mdp=yyy&debut=2011-05-01&fin=2011-05-12' response = urllib2.urlopen(url) content = response.read() response.close() if the url is http, it doesn't fail, if it's https://www.gmail.com, it doesn't fail neither! someone could help me to make it work. When going to the url using a browser, there is no error. The only thing is that the certificate is signed for another domain. of course, on my real test I replace xxx and yyy, but anyway the error is the same with or without the parameters, even https://stat.netaffiliation.com raises the exception... Thanks! From jorgeromero178 at gmail.com Thu May 12 11:27:46 2011 From: jorgeromero178 at gmail.com (Jorge Romero) Date: Thu, 12 May 2011 11:27:46 -0400 Subject: Python 2.7 Debian 6.0. Squeeze Message-ID: Hi all, My machine is running Debian Squeeze so my default Python runtime is 2.6.6. According to Python docs *optparse* library is deprecated and the development will be moved to *argparse*, which is new in Python 2.7.1. So now that I'm about to write a script that parse command line arguments thought would be a good idea to do the transition right now, besides the good comments about this version. I tried Googling about Python 2.7 on Debian Squeeze, but did not find anything but discussions -.-. Anyone out there that can point me some helpful material or anyone who had luck running 2.7 on Debian? Thanks in advanced. -- Jorge Romero -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericsnowcurrently at gmail.com Thu May 12 11:30:19 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Thu, 12 May 2011 09:30:19 -0600 Subject: list equal to subclass of list? In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 6:23 AM, Roy Smith wrote: > I have a vague feeling this may have been discussed a long time ago, but > I can't find the thread, so I'll bring it up again. > > I recently observed in the "checking if a list is empty" thread that a > list and a subclass of list can compare equal: > > ---------------------------- > class MyList(list): > "I'm a subclass" > > l1 = [] > l2 = MyList() > > print type(l1), type(l2) > print type(l1) == type(l2) > print l1 == l2 > ---------------------------- > > when run, prints: > > > False > True > > The docs say: > > [http://docs.python.org/library/stdtypes.html] > Objects of different types, except different numeric types and different > string types, never compare equal > > [http://docs.python.org/release/2.7/reference/expressions.html#notin] > objects of different types (emphasis)always compare unequal > > That definitely makes it unclear. A little further down it says that you can customize comparison with the __cmp__ special method. You can also override implement other specific comparison special methods, like __eq__ in your classes. So I can definitely see what you mean. In the case of list, a list object has a __eq__ method that it uses for determining equality, rather than using the __eq__ method of the base object type (which behaves as described in your citation). Many of the builtin types have custom special methods for a variety of operators, including comparison. Looking over the documentation, it seems like it could be touched up to alleviate any confusion. Perhaps rewording to make it clear that the described behavior is the default for objects, rather than always the case. -eric > In the test code above, l1 an l2 are different types, at least in the > sense that type() returns something different for each of them. What's > the intended behavior here? Either the code is wrong or the docs are > wrong. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at example.com Thu May 12 11:51:09 2011 From: bob at example.com (Bob Fnord) Date: Thu, 12 May 2011 17:51:09 +0200 Subject: can't get urllib2 or httplib to work with tor & privoxy References: Message-ID: <44ec92ef1af181bd3839228f88c1b78d@msgid.frell.theremailer.net> Chris Angelico wrote: > On Tue, May 10, 2011 at 4:20 AM, Bob Fnord wrote: > > Both methods give me a 503 error... > > As a networking geek, my first thought would be to fire up a tiny > little "snoop server" and see what, exactly, the two methods are > doing. (Ignore the HTTPS options as they're more complicated to snoop > on; you're almost certainly going to see exactly the same on the > HTTP.) > > A snoop server is simply an HTTP server that dumps its requests to > stdout or a file, utterly raw. You can write one in Python fairly > easily, or use another program; if I'm working on Windows, I'll > generally use my own RosMud MUD client, but you'll be able to whip up > a cross-platform one in half a page of code in any decent high level > language. I recommend you work at the sockets level, rather than using > an HTTP library, unless you have one that can emit the entire request, > exactly as it came from the client. > > Once you've found the difference(s) between Lynx and your script, you > can see what's causing the 503 (Service Unavailable) error; it may be > that you need to authenticate with the proxy. Duh, I was doing something else stupid. Thanks but never mind! From roy at panix.com Thu May 12 12:02:09 2011 From: roy at panix.com (Roy Smith) Date: Thu, 12 May 2011 12:02:09 -0400 Subject: list equal to subclass of list? In-Reply-To: References: Message-ID: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> On May 12, 2011, at 11:30 AM, Eric Snow wrote: > On Thu, May 12, 2011 at 6:23 AM, Roy Smith wrote: > The docs say: > > [http://docs.python.org/library/stdtypes.html] > Objects of different types, except different numeric types and different > string types, never compare equal > > [http://docs.python.org/release/2.7/reference/expressions.html#notin] > objects of different types (emphasis)always compare unequal > > > That definitely makes it unclear. I don't think it's unclear at all. It's very clear. Clearly wrong :-) > A little further down it says that you can customize comparison with the __cmp__ special method. Yes, and that says: The operators <, >, ==, >=, <=, and != compare the values of two objects. The objects need not have the same type. If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal, and are ordered consistently but arbitrarily. You can control comparison behavior of objects of non-built-in types by defining a __cmp__ method or rich comparison methods like __gt__, described in section Special method names. I read that as saying that if you implement __eq__(), you must make sure that it returns False if self and other have different types (and likewise, __ne__() should return True for that case). The same way that it says that obj1.__lt__(obj2) must return a consistent result for all types of obj1 and obj2. > Looking over the documentation, it seems like it could be touched up to alleviate any confusion. Perhaps rewording to make it clear that the described behavior is the default for objects, rather than always the case. That would be a start, but doesn't address this specific problem. If the docs are changed to say that "type(obj1) != type(obj2) implies obj1 != obj2" in only the default, people will assume that list follows this default rule since it's a built-in type. Built-in types which don't follow the default rule need to have their behavior documented. --- Roy Smith roy at panix.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jorgeromero178 at gmail.com Thu May 12 12:03:26 2011 From: jorgeromero178 at gmail.com (Jorge Romero) Date: Thu, 12 May 2011 12:03:26 -0400 Subject: Python 2.7 Debian 6.0. Squeeze In-Reply-To: References: Message-ID: Actually came back with some feedback to my own question. The following repositories do the job: # /etc/apt/sources.list deb http://ftp.uk.debian.org/debian/ unstable main contrib non-free deb http://ftp.uk.debian.org/debian/ experimental main contrib non-free deb http://security.debian.org/ testing/updates main contrib $ apt-get update $ apt-get install python2.7 $ python --version Python 2.6.6 $ python2.7 --version Python 2.7.1+ If you need 2.7 as default runtime: $ update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10 This is the first time I need two Python instances, so might helpful for someone in the same position. Any further help feel free to reply. Cheers. On Thu, May 12, 2011 at 11:27 AM, Jorge Romero wrote: > Hi all, > > My machine is running Debian Squeeze so my default Python runtime is 2.6.6. > > According to Python docs *optparse* library is deprecated and the > development will be moved to *argparse*, which is new in Python 2.7.1. So > now that I'm about to write a script that parse command line arguments > thought would be a good idea to do the transition right now, besides the > good comments about this version. > > I tried Googling about Python 2.7 on Debian Squeeze, but did not find > anything but discussions -.-. Anyone out there that can point me some > helpful material or anyone who had luck running 2.7 on Debian? > > Thanks in advanced. > > -- > Jorge Romero > > -- Jorge Romero -------------- next part -------------- An HTML attachment was scrubbed... URL: From vanboxem.ruben at gmail.com Thu May 12 12:14:18 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Thu, 12 May 2011 18:14:18 +0200 Subject: Python enabled gdb on Windows and relocation Message-ID: Hi, I am currently trying to integrate Python support into my toolchain build (including GDB of course). It is a sysrooted binutils+GCC+GDB+mingw-w64 toolchain. I currently have the basic setup working: I can link gdb with my manually generated import lib to the python dll from the official Windows install. If there is anything I am missing or a very easy solution to the problems decsribed below, please just say so. I am only suggesting what I would like to happen. Now on to the problems I'd like to discuss: 1. gdb.exe won't start without me having set PYTHONPATH manually. I understand the need for this, but as gdb requires Python 2, and users of my toolchain may have installed Python 3 or a 32-bit version python they want to use from the same environment (without changing their own PYTHONPATH), there is no way to run python-enabled gdb. What I suggest is perhaps a Windows only change: a kind of "sysroot"ed gdb+python, so that the python used by gdb is truly built in. I cannot require everyone using my toolchain to install the correct python version for obvious reasons (Windows != Linux in this regard). However way this is tackled, the gdb I want should look relative to it's current (relocatable) directory for Python modules/*;py files in a well-defined directory at build time. That would allow me to distribute gdb in a very clear way: /bin /bin/python27.dll /bin/gdb.exe /lib /lib/python27 /lib/python27/ Currently, this scheme only works if I manually set the PYTHONPATH environment variable to /lib/python27. This global environment variable could conflict with existing Python installations, that may have another bitness (I have 64- and 32-bit toolchains). I think you can see there are problems enough with the current set up. I also read this old discussion: http://comments.gmane.org/gmane.comp.gdb.patches/62811 that might imply that the PYTHONPATH check is something built-in to the python dll. Can anyone shed some light on this? 2. With PYTHONPATH set as a temporary workaround, gdb starts, but spits out a traceback: Traceback (most recent call last): File "", line 35, in File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line 18, in gdb.command.pretty_printers.register_pretty_printer_commands() File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", line 368, in register_pretty_printer_commands InfoPrettyPrinter() File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", line 100, in __init__ gdb.COMMAND_DATA) RuntimeError: Could not find command prefix info. This is a minor problem I think, as "python import time" "python print time.clock()" works as expected. What is wrong? Thanks very much! Ruben PS: I've sent this to both the gdb and python mailing lists, as these issues have a large overlap to both projects. PS2: Please reply-to-all as I do not want daily mails from both mailing lists on every issue brought up there. My apologies. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu May 12 12:17:33 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 12 May 2011 10:17:33 -0600 Subject: unicode by default In-Reply-To: <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> Message-ID: On Thu, May 12, 2011 at 1:58 AM, John Machin wrote: > On Thu, May 12, 2011 4:31 pm, harrismh777 wrote: > >> >> So, the UTF-16 UTF-32 is INTERNAL only, for Python > > NO. See one of my previous messages. UTF-16 and UTF-32, like UTF-8 are > encodings for the EXTERNAL representation of Unicode characters in byte > streams. Right. *Under the hood* Python uses UCS-2 (which is not exactly the same thing as UTF-16, by the way) to represent Unicode strings. However, this is entirely transparent. To the Python programmer, a unicode string is just an abstraction of a sequence of code-points. You don't need to think about UCS-2 at all. The only times you need to worry about encodings are when you're encoding unicode characters to byte strings, or decoding bytes to unicode characters, or opening a stream in text mode; and in those cases the only encoding that matters is the external one. From vanboxem.ruben at gmail.com Thu May 12 12:19:55 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Thu, 12 May 2011 18:19:55 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: (now in plain-text as required by gdb mailing list) Hi, I am currently trying to integrate Python support into my toolchain build (including GDB of course). It is a sysrooted binutils+GCC+GDB+mingw-w64 toolchain. I currently have the basic setup working: I can link gdb with my manually generated import lib to the python dll from the official Windows install. If there is anything I am missing or a very easy solution to the problems decsribed below, please just say so. I am only suggesting what I would like to happen. Now on to the problems I'd like to discuss: 1. gdb.exe won't start without me having set PYTHONPATH manually. I understand the need for this, but as gdb requires Python 2, and users of my toolchain may have installed Python 3 or a 32-bit version python they want to use from the same environment (without changing their own PYTHONPATH), there is no way to run python-enabled gdb. What I suggest is perhaps a Windows only change: a kind of "sysroot"ed gdb+python, so that the python used by gdb is truly built in. I cannot require everyone using my toolchain to install the correct python version for obvious reasons (Windows != Linux in this regard). However way this is tackled, the gdb I want should look relative to it's current (relocatable) directory for Python modules/*;py files in a well-defined directory at build time. That would allow me to distribute gdb in a very clear way: /bin /bin/python27.dll /bin/gdb.exe /lib /lib/python27 /lib/python27/ Currently, this scheme only works if I manually set the PYTHONPATH environment variable to /lib/python27. This global environment variable could conflict with existing Python installations, that may have another bitness (I have 64- and 32-bit toolchains). I think you can see there are problems enough with the current set up. I also read this old discussion: http://comments.gmane.org/gmane.comp.gdb.patches/62811 that might imply that the PYTHONPATH check is something built-in to the python dll. Can anyone shed some light on this? 2. With PYTHONPATH set as a temporary workaround, gdb starts, but spits out a traceback: Traceback (most recent call last): ? File "", line 35, in ? File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line 18, in ??? gdb.command.pretty_printers.register_pretty_printer_commands() ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", line 368, in register_pretty_printer_commands ??? InfoPrettyPrinter() ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", line 100, in __init__ ??? gdb.COMMAND_DATA) RuntimeError: Could not find command prefix info. This is a minor problem I think, as "python import time" "python print time.clock()" works as expected. What is wrong? Thanks very much! Ruben PS: I've sent this to both the gdb and python mailing lists, as these issues have a large overlap to both projects. PS2: Please reply-to-all as I do not want daily mails from both mailing lists on every issue brought up there. My apologies. From ethan at stoneleaf.us Thu May 12 12:43:23 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 09:43:23 -0700 Subject: list equal to subclass of list? In-Reply-To: References: Message-ID: <4DCC0E2B.4010803@stoneleaf.us> Roy Smith wrote: > I recently observed in the "checking if a list is empty" thread that a > list and a subclass of list can compare equal: > > ---------------------------- > class MyList(list): > "I'm a subclass" > > l1 = [] > l2 = MyList() > > print type(l1), type(l2) > print type(l1) == type(l2) > print l1 == l2 > ---------------------------- > > when run, prints: > > > False > True > > The docs say: > > [http://docs.python.org/library/stdtypes.html] > Objects of different types, except different numeric types and different > string types, never compare equal This part of the documentation is talking about built-in types, which your MyList is not. > [http://docs.python.org/release/2.7/reference/expressions.html#notin] > objects of different types *always* compare unequal Should probably have the word 'built-in' precede 'types' here, since constructed objects can do whatever they have been told to do. > In the test code above, l1 an l2 are different types, at least in the > sense that type() returns something different for each of them. --> MyList.__mro__ (, , ) MyList is a list -- just a more specific kind of list -- as can be seen from its mro; this is analogous to a square (2 sets of parallel lines joined at 90 degree angles, both sets being the same length) also being a rectangle (2 sets of parallel lines joined at 90 degree angles). > What's the intended behavior here? Either the code is wrong or the docs > are wrong. The code is correct. ~Ethan~ PS Yes, I know my square/rectangle definitions are incomplete, thanks. ;) From robert.kern at gmail.com Thu May 12 13:24:11 2011 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 12 May 2011 12:24:11 -0500 Subject: Slice implementation bug In-Reply-To: References: Message-ID: On 5/12/11 6:06 AM, Tambet wrote: > Hello! > > Let's say slice is multidimensional now - how to interpret it? > > I excpect these to work: > > * m[0, 3] - get one element from matrix > * m[0:2, 0:2] - get four elements from matrix, iterate over them (I have > actually an rtree if it doesn't make sense to you) > > But it won't, because if m[0, 3] returns something, then m[0:2, 0:2] cannot > yield anymore. Let me try to rephrase, since you seem to be leaving out a lot of assumptions. You are trying to say that you want m[0:2,0:2] to return an iterator and that if you define __getitem__() such that m[0,3] returns a value, then you cannot implement __getitem__() to be a generator using a yield statement. Okay. Fine. But there is no reason that __getitem__() needs to be a generator function for you to return an iterator. You can simply return another generator. For example: def __getitem__(self, key): if isinstance(key, tuple): if any(isinstance(x, slice) for x in key): return self._generate_from_slice(key) # The default, boring case. return self._get_value(key) def _generate_from_slice(self, key): yield foo yield bar yield etc > Ofcourse I could return an iterator, but this would not be so simple. Really, it is. -- 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 rurpy at yahoo.com Thu May 12 13:42:44 2011 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 12 May 2011 10:42:44 -0700 (PDT) Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> On 05/12/2011 12:13 AM, Steven D'Aprano wrote: >[snip] > http://www.codinghorror.com/blog/2006/07/separating-programming-sheep-from-non-programming-goats.html > > Shorter version: it seems that programming aptitude is a bimodal > distribution, with very little migration from the "can't program" hump > into the "can program" hump. There does seem to be a simple predictor for > which hump you fall into: those who intuitively develop a consistent > model of assignment (right or wrong, it doesn't matter, so long as it is > consistent) can learn to program. Those who don't, can't. A later paper by the same authors... (http://www.eis.mdx.ac.uk/research/PhDArea/saeed/paper3.pdf) Abstract: [...] Despite a great deal of research into teaching methods and student responses, there have been to date no strong predictors of success in learning to program. Two years ago we appeared to have discovered an exciting and enigmatic new predictor of success in a first programming course. We now report that after six experiments, involving more than 500 students at six institutions in three countries, the predictive effect of our test has failed to live up to that early promise. We discuss the strength of the effects that have been observed and the reasons for some apparent failures of prediction. From ethan at stoneleaf.us Thu May 12 14:29:54 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 11:29:54 -0700 Subject: list equal to subclass of list? In-Reply-To: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> References: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> Message-ID: <4DCC2722.9090003@stoneleaf.us> Roy Smith wrote: > On May 12, 2011, at 11:30 AM, Eric Snow wrote: >> >> That definitely makes it unclear. > > I don't think it's unclear at all. It's very clear. Clearly wrong :-) While it is wrong (it should have 'built-in' precede the word 'types'), it is not wrong in the way you think -- a subclass *is* a type of its superclass. >> A little further down it says that you can customize comparison with >> the __cmp__ special method. > > I read that as saying that if you implement __eq__(), you must make sure > that it returns False if self and other have different types (and > likewise, __ne__() should return True for that case). Your understanding is flawed. If your object does not know how to compare itself to some other object, it should return NotImplemented -- at that point Python will follow the rules outlined in the docs. By returning NotImplemented you are allowing the other object a chance to perform the comparison -- after all, it might know how! :) If the other object also returns NotImplemented then (drum-roll please) they won't compare equal. > The same way that it says that obj1.__lt__(obj2) must return a consistent > result for all types of obj1 and obj2. Where do you see that? I couldn't find it. The point of being able to write your own rich comparison methods is so you can control what happens -- there is no "must" about it. This is Python -- do what you want! :) ~Ethan~ PS I have a broken sense of humor -- sometimes it works, sometimes it doesn't. My apologies in advance if my attempt at humor was not funny. From jean_paez at hotmail.es Thu May 12 15:13:28 2011 From: jean_paez at hotmail.es (=?iso-8859-1?B?SmVhbiBDYXJsb3MgUOFleiBSYW3tcmV6?=) Date: Thu, 12 May 2011 14:13:28 -0500 Subject: Hi all. I need aid in creating script to blender. In-Reply-To: References: , , , , Message-ID: Hello. The attached file is script of blender fact in python that .tmb serves to concern archives (secondly attached file), unloadings to blender and uses script and concerns the second file that you shipment you see so that it. Everything can be published and, but it is not possible to be exported again to .tmb To unload in this Link: http://www.blender.org/ script: http://www.mediafire.com/?clmdgkymsfooddd secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 PD: I need script to export in extension .tmb Thanks. Buen d?a comunidad Hola. El archivo adjunto es un script de blender hecho en python que sirve para importar archivos .tmb (http://www.mediafire.com/?clmdgkymsfooddd), descargas blender y usa el script e importa el segundo archivo que te envio para que lo veas (http://www.mediafire.com/?lbmj594ru6r4b67). El se puede editar y todo, pero no se puede exportar de nuevo a .tmb link del script: http://www.mediafire.com/?clmdgkymsfooddd Segundo archivo adjunto: http://www.mediafire.com/?lbmj594ru6r4b67 PD: Necesito el script para exportar en extension .tmb En si necesito ayuda en ese dise?o de un script que exporte de .blend a .tmb Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Thu May 12 15:14:22 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 12 May 2011 14:14:22 -0500 Subject: Proper way to handle errors in a module In-Reply-To: References: Message-ID: <4DCC318E.7020809@gmail.com> On 2011.05.11 01:05 PM, Roy Smith wrote: > You want to raise specific errors. Let's say you've got a function like > this: > > def airspeed(swallow): > speeds = {"european": 42, > "african", 196} > return speeds[swallow] > > If somebody passes an invalid string, it will raise KeyError as written. > Better to do something like: > > def airspeed(swallow): > speeds = {"european": 42, > "african", 196} > try: > return speeds[swallow] > except KeyError: > raise UnknownBirdError(swallow) Is there any way to do this without purposely setting up the code to trigger an arbitrary exception if the function can't do its job? That is, can I raise an UnknownBirdError outside of an except clause, and if so, how? I can't find much help for doing this in Python 3, even in the official docs. From felipe.vinturini at gmail.com Thu May 12 15:23:12 2011 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Thu, 12 May 2011 16:23:12 -0300 Subject: Me ayudas? Hi . I need aid in creating script to blender. In-Reply-To: References: Message-ID: 2011/5/12 Jean Carlos P?ez Ram?rez > Hello. > > The attached file is script of blender fact in python that .tmb serves to > concern archives (secondly attached file), unloadings to blender and uses > script and concerns the second file that you shipment you see so that it. > Everything can be published and, but it is not possible to be exported again > to .tmb > > To unload in this Link: http://www.blender.org/ > script: http://www.mediafire.com/?clmdgkymsfooddd > secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 > > PD: I need script to export in extension .tmb in BLENDER. > > Thanks. > > ------------------------------ > Buen d?a comunidad > > Hola. > > El archivo adjunto es un script de blender hecho en python que sirve para > importar archivos .tmb (http://www.mediafire.com/?clmdgkymsfooddd), > descargas blender y usa el script e importa el segundo archivo que te envio > para que lo veas (http://www.mediafire.com/?lbmj594ru6r4b67). El se puede > editar y todo, pero no se puede exportar de nuevo a .tmb > > > link del script: http://www.mediafire.com/?clmdgkymsfooddd > Segundo archivo adjunto: http://www.mediafire.com/?lbmj594ru6r4b67 > > PD: Necesito el script para exportar en extension .tmb En si necesito ayuda > en ese dise?o de un script que exporte de .blend a .tmb > > > > Gracias. > Hei! If you don't try to do anything, nobody will help you... That's why you didn't have any answer for all your posts! I think you got the point... Sorry. Regads, Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu May 12 15:25:21 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 May 2011 20:25:21 +0100 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC318E.7020809@gmail.com> References: <4DCC318E.7020809@gmail.com> Message-ID: <4DCC3421.9070007@mrabarnett.plus.com> On 12/05/2011 20:14, Andrew Berg wrote: > On 2011.05.11 01:05 PM, Roy Smith wrote: >> You want to raise specific errors. Let's say you've got a function like >> this: >> >> def airspeed(swallow): >> speeds = {"european": 42, >> "african", 196} >> return speeds[swallow] >> >> If somebody passes an invalid string, it will raise KeyError as written. >> Better to do something like: >> >> def airspeed(swallow): >> speeds = {"european": 42, >> "african", 196} >> try: >> return speeds[swallow] >> except KeyError: >> raise UnknownBirdError(swallow) > Is there any way to do this without purposely setting up the code to > trigger an arbitrary exception if the function can't do its job? That > is, can I raise an UnknownBirdError outside of an except clause, and if > so, how? I can't find much help for doing this in Python 3, even in the > official docs. > You can raise an exception wherever you like! :-) From felipe.vinturini at gmail.com Thu May 12 15:34:25 2011 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Thu, 12 May 2011 16:34:25 -0300 Subject: Me ayudas? Hi . I need aid in creating script to blender. In-Reply-To: References: Message-ID: 2011/5/12 Jean Carlos P?ez Ram?rez > To ok there is no problem friend, of all ways thanks, I will see that I > can do, nor in the pages Web of blender they answer to me. > > Thanks friend. > > Regads, > > Jean P. > > ------------------------------ > From: felipe.vinturini at gmail.com > Date: Thu, 12 May 2011 16:23:12 -0300 > Subject: Re: Me ayudas? Hi . I need aid in creating script to blender. > To: jean_paez at hotmail.es > CC: python-list at python.org > > > > 2011/5/12 Jean Carlos P?ez Ram?rez > > Hello. > > The attached file is script of blender fact in python that .tmb serves to > concern archives (secondly attached file), unloadings to blender and uses > script and concerns the second file that you shipment you see so that it. > Everything can be published and, but it is not possible to be exported again > to .tmb > > To unload in this Link: http://www.blender.org/ > script: http://www.mediafire.com/?clmdgkymsfooddd > secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67 > > PD: I need script to export in extension .tmb in BLENDER. > > Thanks. > > ------------------------------ > Buen d?a comunidad > > Hola. > > El archivo adjunto es un script de blender hecho en python que sirve para > importar archivos .tmb (http://www.mediafire.com/?clmdgkymsfooddd), > descargas blender y usa el script e importa el segundo archivo que te envio > para que lo veas (http://www.mediafire.com/?lbmj594ru6r4b67). El se puede > editar y todo, pero no se puede exportar de nuevo a .tmb > > > link del script: http://www.mediafire.com/?clmdgkymsfooddd > Segundo archivo adjunto: http://www.mediafire.com/?lbmj594ru6r4b67 > > PD: Necesito el script para exportar en extension .tmb En si necesito ayuda > en ese dise?o de un script que exporte de .blend a .tmb > > > Gracias. > > > Hei! > > If you don't try to do anything, nobody will help you... > > That's why you didn't have any answer for all your posts! > > I think you got the point... > > Sorry. > > Regads, > Felipe. > Ok, no problem! When you have something come back... Also, don't forget to always copy the list on your posts and try no to top post... Regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu May 12 15:37:48 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 15:37:48 -0400 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/11/2011 8:26 AM, Roy Smith wrote: > I conclude that li == [] should have returned False. Either I'm not > understanding things correctly, or this is a bug. The doc is wrong (and not only on this). I am working on a report with suggested fixes. Will post number when finish. -- Terry Jan Reedy From tjreedy at udel.edu Thu May 12 15:44:31 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 15:44:31 -0400 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 5/12/2011 9:30 AM, Genstein wrote: >> With 3.2 on winxp, that is what I get with StringIO, text file, and >> bytes file (the first two with b's removed). I would expect the same on >> any system. If you get anything different, I would consider it a bug > > Thanks Terry, you're entirely right there; I trimmed down my test case, > asked for confirmation and have reported it as > http://bugs.python.org/issue12062. Noted here in case anyone else trips > over it. I want people to know that with a simple, minimal, easy to run and reproduce and think about test case posted, more info, more test cases, and probable fixes were posted within an hour. (Fixes are not always that quick, but stripping away irrelevancies really helps speed the process.) -- Terry Jan Reedy From tjreedy at udel.edu Thu May 12 16:04:07 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 16:04:07 -0400 Subject: generate properties code in class dynamically In-Reply-To: References: Message-ID: On 5/12/2011 9:11 AM, JamesEM wrote: > I would prefer to generate the properties code dynamically from the > keys of the dictionaries. > What I am looking for is something like: > > class MyClass(object): > > def __init__(self): > self.d = {} > d['field1'] = 1.0 > d['field2'] = 'A' > d['field3'] = [10.0,20.0,30.0] > for f in d: > create_property(f) > > where create_property(f) dynamically creates the property code for > field f in MyClass. > > Is this possible? Without actually trying, I am not sure, but I believe maybe (possibly version dependent). The init method is the wrong place. Create the properties exactly once, just after the class is created. It is possible to add functions to classes as attributes (instance methods) after they are created. The property decorators *might* require that they be invoked with the class body, I do not know. I would first try with property(). Assuming dict name 'd' is fixed: def gsd(key): def get(self): return self.d[key] def set(self, value): self.d[key] = value def del(self): del self.d[key] return get,set,del for key in fieldnames: setattr(MyClass, key, property(*gsd(key))) For recent versions, this could be done within a class decorator, but that is only convenient syntactic sugar. -- Terry Jan Reedy From bahamutzero8825 at gmail.com Thu May 12 16:12:39 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 12 May 2011 15:12:39 -0500 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC3421.9070007@mrabarnett.plus.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> Message-ID: <4DCC3F37.3010904@gmail.com> On 2011.05.12 02:25 PM, MRAB wrote: > You can raise an exception wherever you like! :-) If I raise an exception that isn't a built-in exception, I get something like "NameError: name 'HelloError' is not defined". I don't know how to define the exception. From kb1pkl at aim.com Thu May 12 16:20:13 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Thu, 12 May 2011 16:20:13 -0400 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC3F37.3010904@gmail.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> Message-ID: <4DCC40FD.2030907@aim.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/12/2011 04:12 PM, Andrew Berg wrote: > On 2011.05.12 02:25 PM, MRAB wrote: >> You can raise an exception wherever you like! :-) > If I raise an exception that isn't a built-in exception, I get something > like "NameError: name 'HelloError' is not defined". I don't know how to > define the exception. class HelloError(Exception): pass Of course, there are all sorts of other things you could do with your exception. http://docs.python.org/tutorial/errors.html#user-defined-exceptions - -- Corey Richardson -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJNzED9AAoJEAFAbo/KNFvp1uQIAKFaKyD1Q3RL7LGFSmnyRFTK 9XWRH3CSM9mOALccfQ8bUkrquol1fAqhrm4jyOW0scWmsJpRlcb6Rj4HtrmMQOuG DpsUzEZCTnT9Xk80OeTFbpWWBIVBkxdhCxCl75XAP22o5EjhHpgLyqoqMD+81BKH 5/JWAGRJx/9E4BvNWsxIUhb1jlz+XT4H1XykTE1UUOP0uZneWRJMs7P12WNiL2Ii HT0hEUhQc1eP1fJ5BqPB/6/B9q/KxTbN55hCq1VwwfRhgbaM4kR7Bekri7QUHGAK 1MKxRa1v+Co59y+ywAIH92L3wky3xNyFrUlFzK4AwYOnwRkVvUWw7vPG1iShE+k= =2+y6 -----END PGP SIGNATURE----- From PointedEars at web.de Thu May 12 16:22:20 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 12 May 2011 22:22:20 +0200 Subject: Customize help output from optparse (or argparse) References: Message-ID: <2635961.LZWGnKmheA@PointedEars.de> Thorsten Kampe wrote: > I'm using optparse for a little Python script. > > 1. The output from "--help" is: > """ > Usage: script.py > > script.py does something > > Options: > -h, --help show this help message and exit > """ > > I would prefer to have the description before the usage, like... > """ > script.py does something > > Usage: script.py > > Options: > -h, --help show this help message and exit > """ > > 2. The output from "--doesnotexit" is: > """ > Usage: script.py > > script.py: error: no such option: --doesnotexist > """ > > I would prefer to have the error first, then the usage and additionally > the options, like... > """ > script.py: error: no such option: --doesnotexist > > Usage: script.py > > Options: > -h, --help show this help message and exit > """ > > Is that possible with either optparse or the "new kid on the block" > argparse. If so how? You can easily have #1 with optparse.OptionParser(usage="?")?, but optparse is deprecated in favor of argparse.ArgumentParser. I do not think you can have #2 with either optparse or argparse: OptionParser() would print the error message last, and ArgumentParser() would not print the description on error. Subclassing ArgumentParser might be feasible, though. ______ ? -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From tycho at tycho.ws Thu May 12 16:26:27 2011 From: tycho at tycho.ws (Tycho Andersen) Date: Thu, 12 May 2011 15:26:27 -0500 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC3F37.3010904@gmail.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> Message-ID: <20110512202627.GW18269@point.cs.wisc.edu> On Thu, May 12, 2011 at 03:12:39PM -0500, Andrew Berg wrote: > On 2011.05.12 02:25 PM, MRAB wrote: > > You can raise an exception wherever you like! :-) > If I raise an exception that isn't a built-in exception, I get something > like "NameError: name 'HelloError' is not defined". I don't know how to > define the exception. You'll have to define it, as you would anything else (exceptions are just regular "things"; in fact you can raise anything that's a class or instance). I typically don't put a whole lot in my exception classes, though. point:~/working$ python Python 2.6.2 (r262:71600, Jun 8 2009, 11:11:42) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class HelloError(Exception): pass ... >>> raise HelloError("hello!") Traceback (most recent call last): File "", line 1, in __main__.HelloError: hello! \t From python at mrabarnett.plus.com Thu May 12 16:26:55 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 May 2011 21:26:55 +0100 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC3F37.3010904@gmail.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> Message-ID: <4DCC428F.6070002@mrabarnett.plus.com> On 12/05/2011 21:12, Andrew Berg wrote: > On 2011.05.12 02:25 PM, MRAB wrote: >> You can raise an exception wherever you like! :-) > If I raise an exception that isn't a built-in exception, I get something > like "NameError: name 'HelloError' is not defined". I don't know how to > define the exception. Define it as a subclass of Exception: class UnknownBirdError(Exception): pass From bahamutzero8825 at gmail.com Thu May 12 16:35:16 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 12 May 2011 15:35:16 -0500 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC40FD.2030907@aim.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> <4DCC40FD.2030907@aim.com> Message-ID: <4DCC4484.7050509@gmail.com> On 2011.05.12 03:20 PM, Corey Richardson wrote: > class HelloError(Exception): > pass > > Of course, there are all sorts of other things you could do with your > exception. > > http://docs.python.org/tutorial/errors.html#user-defined-exceptions So that's where that info is. I wasn't looking in the tutorial section. Thanks! From PointedEars at web.de Thu May 12 16:36:23 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 12 May 2011 22:36:23 +0200 Subject: Need Assistance on this program. References: <4DCBB18B.5050309@timgolden.me.uk> Message-ID: <5331926.9J7NaK4W3v@PointedEars.de> vijay swaminathan wrote: > I have already done that. But for some reason my response went > as a new thread. Attaching the code again. JFYI: Please DO NOT post attachments in a non-binary newsgroup or to a mailing list (are there binary ones at all?) again. TIA. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From genstein at invalid.invalid Thu May 12 16:38:53 2011 From: genstein at invalid.invalid (Genstein) Date: Thu, 12 May 2011 21:38:53 +0100 Subject: py3k buffered IO - flush() required between read/write? In-Reply-To: References: Message-ID: On 12/05/2011 20:44, Terry Reedy wrote: > I want people to know that with a simple, minimal, easy to run and > reproduce and think about test case posted, more info, more test cases, > and probable fixes were posted within an hour. (Fixes are not always > that quick, but stripping away irrelevancies really helps speed the > process.) A very good point. I'm extremely impressed with the speed and deftness which the bug was handled once raised. Hats off to the people involved. I should have posted a short test case initially, but I knew it would take some time for me to produce and didn't want to go that far if it was clear to everyone but me that flushes were required by design :) Thanks again, -eg. From karim.liateni at free.fr Thu May 12 16:40:01 2011 From: karim.liateni at free.fr (Karim) Date: Thu, 12 May 2011 22:40:01 +0200 Subject: Customize help output from optparse (or argparse) In-Reply-To: <2635961.LZWGnKmheA@PointedEars.de> References: <2635961.LZWGnKmheA@PointedEars.de> Message-ID: <4DCC45A1.4020305@free.fr> On 05/12/2011 10:22 PM, Thomas 'PointedEars' Lahn wrote: > Thorsten Kampe wrote: > >> I'm using optparse for a little Python script. >> >> 1. The output from "--help" is: >> """ >> Usage: script.py >> >> script.py does something >> >> Options: >> -h, --help show this help message and exit >> """ >> >> I would prefer to have the description before the usage, like... >> """ >> script.py does something >> >> Usage: script.py >> >> Options: >> -h, --help show this help message and exit >> """ >> >> 2. The output from "--doesnotexit" is: >> """ >> Usage: script.py >> >> script.py: error: no such option: --doesnotexist >> """ >> >> I would prefer to have the error first, then the usage and additionally >> the options, like... >> """ >> script.py: error: no such option: --doesnotexist >> >> Usage: script.py >> >> Options: >> -h, --help show this help message and exit >> """ >> >> Is that possible with either optparse or the "new kid on the block" >> argparse. If so how? > You can easily have #1 with optparse.OptionParser(usage="?")?, but optparse > is deprecated in favor of argparse.ArgumentParser. I do not think you can > have #2 with either optparse or argparse: OptionParser() would print the > error message last, and ArgumentParser() would not print the description > on error. Subclassing ArgumentParser might be feasible, though. > > ______ > ? Please find documentation to configure help in ArgumentParser BUT for argparse module: - HelpFormatter, RawDescriptionHelpFormatter, RawTextHelpFormatter, 50 ArgumentDefaultsHelpFormatter -- Formatter classes which 51 may be passed as the formatter_class= argument to the 52 ArgumentParser constructor. HelpFormatter is the default, 53 RawDescriptionHelpFormatter and RawTextHelpFormatter tell the parser 54 not to change the formatting for help text, and 55 ArgumentDefaultsHelpFormatter adds information about argument defaults 56 to the help. So It seems easy to a different pass formatter_class to ArgumentParser. You can inherite from HelpFormater class but you have to know the implementation details: File is located at /lib/python2.7/argparse.py Cheers Karim From ethan at stoneleaf.us Thu May 12 16:40:44 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 13:40:44 -0700 Subject: Proper way to handle errors in a module In-Reply-To: <4DCC3F37.3010904@gmail.com> References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> Message-ID: <4DCC45CC.8040808@stoneleaf.us> Andrew Berg wrote: > On 2011.05.12 02:25 PM, MRAB wrote: >> You can raise an exception wherever you like! :-) > If I raise an exception that isn't a built-in exception, I get something > like "NameError: name 'HelloError' is not defined". I don't know how to > define the exception. class HelloError(Exception): "custom exception" and that's all you need. You can override __init__ to add your own attributes, etc, if you need to. ~Ethan~ From PointedEars at web.de Thu May 12 16:40:55 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 12 May 2011 22:40:55 +0200 Subject: list equal to subclass of list? References: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> Message-ID: <7378643.eNJFYEL58v@PointedEars.de> Ethan Furman wrote: > PS > I have a broken sense of humor -- sometimes it works, sometimes it > doesn't. My apologies in advance if my attempt at humor was not funny. Now that was very unpythonic. Know where your roots are! :) -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From tjreedy at udel.edu Thu May 12 16:42:45 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 16:42:45 -0400 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> Message-ID: On 5/12/2011 12:17 PM, Ian Kelly wrote: > On Thu, May 12, 2011 at 1:58 AM, John Machin wrote: >> On Thu, May 12, 2011 4:31 pm, harrismh777 wrote: >> >>> >>> So, the UTF-16 UTF-32 is INTERNAL only, for Python >> >> NO. See one of my previous messages. UTF-16 and UTF-32, like UTF-8 are >> encodings for the EXTERNAL representation of Unicode characters in byte >> streams. > > Right. *Under the hood* Python uses UCS-2 (which is not exactly the > same thing as UTF-16, by the way) to represent Unicode strings. I know some people say that, but according to the definitions of the unicode consortium, that is wrong! The earlier UCS-2 *cannot* represent chars in the Supplementary Planes. The later (1996) UTF-16, which Python uses, can. The standard considers 'UCS-2' obsolete long ago. See https://secure.wikimedia.org/wikipedia/en/wiki/UTF-16/UCS-2 or http://www.unicode.org/faq/basic_q.html#14 The latter says: "Q: What is the difference between UCS-2 and UTF-16? A: UCS-2 is obsolete terminology which refers to a Unicode implementation up to Unicode 1.1, before surrogate code points and UTF-16 were added to Version 2.0 of the standard. This term should now be avoided." It goes on: "Sometimes in the past an implementation has been labeled "UCS-2" to indicate that it does not support supplementary characters and doesn't interpret pairs of surrogate code points as characters. Such an implementation would not handle processing of character properties, code point boundaries, collation, etc. for supplementary characters." I know that 16-bit Python *does* use surrogate pairs for supplementary chars and at least some properties work for them. I am not sure exactly what the rest means. > However, this is entirely transparent. To the Python programmer, a > unicode string is just an abstraction of a sequence of code-points. > You don't need to think about UCS-2 at all. The only times you need > to worry about encodings are when you're encoding unicode characters > to byte strings, or decoding bytes to unicode characters, or opening a > stream in text mode; and in those cases the only encoding that matters > is the external one. If one uses unicode chars in the Supplementary Planes above the BMP (the first 2**16), which require surrogate pairs for 16 bit unicode (UTF-16), then the abstraction leaks. -- Terry Jan Reedy From roy at panix.com Thu May 12 16:49:00 2011 From: roy at panix.com (Roy Smith) Date: Thu, 12 May 2011 13:49:00 -0700 (PDT) Subject: list equal to subclass of list? References: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> Message-ID: <925edfdd-51c7-400b-af2b-4171779779c8@r35g2000prj.googlegroups.com> On May 12, 2:29?pm, Ethan Furman wrote: > While it is wrong (it should have 'built-in' precede the word 'types'), > it is not wrong in the way you think -- a subclass *is* a type of its > superclass. Well, consider this: class List_A(list): "A list subclass" class List_B(list): "Another list subclass" a = List_A() b = List_B() print a == b It prints "True". Neither a nor b are a type of the other: print isinstance(List_A, List_B) print isinstance(List_B, List_A) False False From ethan at stoneleaf.us Thu May 12 17:48:20 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 14:48:20 -0700 Subject: list equal to subclass of list? In-Reply-To: <925edfdd-51c7-400b-af2b-4171779779c8@r35g2000prj.googlegroups.com> References: <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com> <925edfdd-51c7-400b-af2b-4171779779c8@r35g2000prj.googlegroups.com> Message-ID: <4DCC55A4.1020303@stoneleaf.us> Roy Smith wrote: > On May 12, 2:29 pm, Ethan Furman wrote: > >> While it is wrong (it should have 'built-in' precede the word 'types'), >> it is not wrong in the way you think -- a subclass *is* a type of its >> superclass. > > Well, consider this: > > class List_A(list): > "A list subclass" > > class List_B(list): > "Another list subclass" > > a = List_A() > b = List_B() > print a == b > > It prints "True". Neither a nor b are a type of the other: > > print isinstance(List_A, List_B) > print isinstance(List_B, List_A) > > False > False Okay, considering: List_A is a user-defined type. List_B is a user-defined type. Both are sub-classes of list. Corrected documentation (which says 'built-in types' etc, etc) says nothing about user-defined types not being able to be equal to each other neither List_A nor List_B have overridden the __eq__ method, so list.__eq__ will be used... conclusion: if they have equal elements in the same order, they will compare equal since they are, in fact, list's Do you not get the same conclusion? ~Ethan~ From tjreedy at udel.edu Thu May 12 18:00:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 May 2011 18:00:11 -0400 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/12/2011 3:37 PM, Terry Reedy wrote: > On 5/11/2011 8:26 AM, Roy Smith wrote: > >> I conclude that li == [] should have returned False. Either I'm not >> understanding things correctly, or this is a bug. > > The doc is wrong (and not only on this). I am working on a report with > suggested fixes. Will post number when finish. > http://bugs.python.org/issue12067 -- Terry Jan Reedy From ian.g.kelly at gmail.com Thu May 12 18:25:24 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 12 May 2011 16:25:24 -0600 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> Message-ID: On Thu, May 12, 2011 at 2:42 PM, Terry Reedy wrote: > On 5/12/2011 12:17 PM, Ian Kelly wrote: >> Right. ?*Under the hood* Python uses UCS-2 (which is not exactly the >> same thing as UTF-16, by the way) to represent Unicode strings. > > I know some people say that, but according to the definitions of the unicode > consortium, that is wrong! The earlier UCS-2 *cannot* represent chars in the > Supplementary Planes. The later (1996) UTF-16, which Python uses, can. The > standard considers 'UCS-2' obsolete long ago. See > > https://secure.wikimedia.org/wikipedia/en/wiki/UTF-16/UCS-2 > or http://www.unicode.org/faq/basic_q.html#14 At the first link, in the section _Use in major operating systems and environments_ it states, "The Python language environment officially only uses UCS-2 internally since version 2.1, but the UTF-8 decoder to "Unicode" produces correct UTF-16. Python can be compiled to use UCS-4 (UTF-32) but this is commonly only done on Unix systems." PEP 100 says: The internal format for Unicode objects should use a Python specific fixed format implemented as 'unsigned short' (or another unsigned numeric type having 16 bits). Byte order is platform dependent. This format will hold UTF-16 encodings of the corresponding Unicode ordinals. The Python Unicode implementation will address these values as if they were UCS-2 values. UCS-2 and UTF-16 are the same for all currently defined Unicode character points. UTF-16 without surrogates provides access to about 64k characters and covers all characters in the Basic Multilingual Plane (BMP) of Unicode. It is the Codec's responsibility to ensure that the data they pass to the Unicode object constructor respects this assumption. The constructor does not check the data for Unicode compliance or use of surrogates. I'm getting out of my depth here, but that implies to me that while Python stores UTF-16 and can correctly encode/decode it to UTF-8, other codecs might only work correctly with UCS-2, and the unicode class itself ignores surrogate pairs. Although I'm not sure how much this might have changed since the original implementation, especially for Python 3. From weichen302 at aol.com Thu May 12 19:18:23 2011 From: weichen302 at aol.com (Chen Wei) Date: Fri, 13 May 2011 07:18:23 +0800 Subject: Python 2.7 Debian 6.0. Squeeze In-Reply-To: References: Message-ID: <20110512231823.GA6528@Tungsten.DarkStar> On Thu, May 12, 2011 at 12:03:26PM -0400, Jorge Romero wrote: > Actually came back with some feedback to my own question. > > The following repositories do the job: > # /etc/apt/sources.list > deb http://ftp.uk.debian.org/debian/ unstable main contrib non-free > deb http://ftp.uk.debian.org/debian/ experimental main contrib non-free > deb http://security.debian.org/ testing/updates main contrib python2.7 is included in debian testing, so point the sources.list to testing instead of unstable or experimental should also works. deb http://ftp.uk.debian.org/debian/ testing main contrib non-free > $ apt-get update > $ apt-get install python2.7 > $ python --version > Python 2.6.6 > $ python2.7 --version > Python 2.7.1+ > -- Chen Wei From amannijhawan at gmail.com Thu May 12 19:29:57 2011 From: amannijhawan at gmail.com (Aman Nijhawan) Date: Thu, 12 May 2011 16:29:57 -0700 Subject: Peculiar Behaviour of __builtins__ Message-ID: I was trying to call the builtin function min by using getattr(__builtins__,'min') This works at the interpretter prompt However when I called it inside a module that was imported by another module it fails and gives an attribute error print getattr(__builtins__,'min')(range(20)) AttributeError: 'dict' object has no attribute 'min' Also in the interpreter >>>type(__builtins__) but in my module print type(__builtins__) Can anyone help me understand whats going on here? Thanks -- Aman Nijhawan -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu May 12 20:16:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2011 00:16:30 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> Message-ID: <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 May 2011 07:36:27 -0400, Roy Smith wrote: > In article <931adaF9g1U1 at mid.individual.net>, > Gregory Ewing wrote: > >> Roy Smith wrote: >> >>If both are numbers, they are converted to a common type. Otherwise, >> >>objects of different types always compare unequal >> >> That's just the default treatment for unrelated types that don't know >> anything about each other. >> >> I would guess that the list's == method is asking "Is the other object >> a list?", and since a subclass of list is also a list, it's happy and >> goes on to compare the elements. > > Well, that explains what's happening, but the behavior still doesn't > match the docs. Is this a bug or are the docs wrong? The docs are incomplete. You are missing two facts: * The docs you are quoting refer only to built-in types. That it doesn't make so clear is a documentation bug. * Talking about "different" and "same" types is ambiguous. It depends on how you compare types: type(a) is type(b) isinstance(a, type(b)) You are reading the docs as if the first comparison is the way to do it, but the second is usually preferred. Any time you read something about "the same type", you should mentally add "(or an instance of a sub-class)" to it, unless explicitly told different. Whether it is better to add that parenthetical comment every time it is needed, or to assume that the read knows enough about object- oriented programming to assume it, is an open question. Me personally, I think it's part of the mental landscape that can be assumed, like C docs might state "dereference the pointer" without adding "(unless it is a nul pointer)" *every single time*. -- Steven From steve+comp.lang.python at pearwood.info Thu May 12 20:18:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2011 00:18:01 GMT Subject: list equal to subclass of list? References: Message-ID: <4dcc78b8$0$29980$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 May 2011 09:43:23 -0700, Ethan Furman wrote: > MyList is a list -- just a more specific kind of list -- as can be seen > from its mro; this is analogous to a square (2 sets of parallel lines > joined at 90 degree angles, both sets being the same length) also being > a rectangle (2 sets of parallel lines joined at 90 degree angles). Possibly the worst analogy ever! *wink* http://en.wikipedia.org/wiki/Circle-ellipse_problem Also known as the square-rectangle problem. A better analogy might be, Lassie is a dog, and Flipper is a dolphin, so they are different types of animal. But both dogs and dolphins are mammals, so in that sense, Lassie and Flipper are both mammals and therefore the same type of animal. It depends on what you mean by "type". -- Steven From steve+comp.lang.python at pearwood.info Thu May 12 20:43:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 May 2011 00:43:06 GMT Subject: Proper way to handle errors in a module References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> Message-ID: <4dcc7e9a$0$29980$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 May 2011 15:26:27 -0500, Tycho Andersen wrote: > On Thu, May 12, 2011 at 03:12:39PM -0500, Andrew Berg wrote: >> On 2011.05.12 02:25 PM, MRAB wrote: >> > You can raise an exception wherever you like! :-) >> If I raise an exception that isn't a built-in exception, I get >> something like "NameError: name 'HelloError' is not defined". I don't >> know how to define the exception. > > You'll have to define it, as you would anything else (exceptions are > just regular "things"; in fact you can raise anything that's a class or > instance). Not quite. >>> raise 42 Traceback (most recent call last): File "", line 1, in TypeError: exceptions must be classes or instances, not int Not a very good error message, because 42 is an instance! >>> isinstance(42, int) True In Python 3, you get a better error message, and further restrictions on what you can raise: >>> raise 42 Traceback (most recent call last): File "", line 1, in TypeError: exceptions must derive from BaseException In general, you should always subclass Exception rather than BaseException. There are, er, exceptions, but for error-handling you normally should inherit from Exception directly, or some sub-class like ValueError, KeyError, etc. -- Steven From ben+python at benfinney.id.au Thu May 12 20:56:14 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 13 May 2011 10:56:14 +1000 Subject: Proper way to handle errors in a module References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> <4DCC40FD.2030907@aim.com> Message-ID: <87r583ifkh.fsf@benfinney.id.au> Andrew Berg writes: > So that's where that info is. I wasn't looking in the tutorial > section. Does this mean you haven't worked through the tutorial? Time to remedy that. -- \ ?You are welcome to visit the cemetery where famous Russian and | `\ Soviet composers, artists, and writers are buried daily except | _o__) Thursday.? ?Russian orthodox monastery, Moscow | Ben Finney From ethan at stoneleaf.us Thu May 12 21:04:20 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 May 2011 18:04:20 -0700 Subject: list equal to subclass of list? In-Reply-To: <4dcc78b8$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4dcc78b8$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DCC8394.60307@stoneleaf.us> Steven D'Aprano wrote: > On Thu, 12 May 2011 09:43:23 -0700, Ethan Furman wrote: > >> MyList is a list -- just a more specific kind of list -- as can be seen >> from its mro; this is analogous to a square (2 sets of parallel lines >> joined at 90 degree angles, both sets being the same length) also being >> a rectangle (2 sets of parallel lines joined at 90 degree angles). > > Possibly the worst analogy ever! *wink* > > http://en.wikipedia.org/wiki/Circle-ellipse_problem > > Also known as the square-rectangle problem. > > A better analogy might be, Lassie is a dog, and Flipper is a dolphin, so > they are different types of animal. But both dogs and dolphins are > mammals, so in that sense, Lassie and Flipper are both mammals and > therefore the same type of animal. It depends on what you mean by "type". I thought about using the mammal analogy instead, but geometry seemed simpler. *sigh* Oh, well, can't win 'em all! ~Ethan~ From roy at panix.com Thu May 12 21:53:05 2011 From: roy at panix.com (Roy Smith) Date: Thu, 12 May 2011 21:53:05 -0400 Subject: list equal to subclass of list? References: Message-ID: In article , Ethan Furman wrote: > > [http://docs.python.org/library/stdtypes.html] > > Objects of different types, except different numeric types and different > > string types, never compare equal > > This part of the documentation is talking about built-in types, which > your MyList is not. > > > > [http://docs.python.org/release/2.7/reference/expressions.html#notin] > > objects of different types *always* compare unequal > > Should probably have the word 'built-in' precede 'types' here, since > constructed objects can do whatever they have been told to do. Changing the docs (in numerous places) to make it clear that this is only true of built-in types would indeed resolve the problem. As it reads now, it's a general statement about ALL types, built-in or user-defined. From gagsl-py2 at yahoo.com.ar Thu May 12 21:59:24 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 12 May 2011 22:59:24 -0300 Subject: Peculiar Behaviour of __builtins__ References: Message-ID: En Thu, 12 May 2011 20:29:57 -0300, Aman Nijhawan escribi?: > I was trying to call the builtin function min by using > getattr(__builtins__,'min') > > This works at the interpretter prompt > > However when I called it inside a module that was imported by another > module > it fails and gives an attribute error __builtins__ (note the final 's') is an implementation detail. You want the __builtin__ (no 's') module, renamed 'builtin' in Python 3.x py> import __builtin__ py> builtin_min = __builtin__.min py> builtin_min([8,2,5]) 2 See http://docs.python.org/library/__builtin__.html Note: using getattr with a literal name is not so useful. Better to use dot notation. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu May 12 22:02:02 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 12 May 2011 23:02:02 -0300 Subject: Peculiar Behaviour of __builtins__ References: Message-ID: En Thu, 12 May 2011 22:59:24 -0300, Gabriel Genellina escribi?: > En Thu, 12 May 2011 20:29:57 -0300, Aman Nijhawan > escribi?: > >> I was trying to call the builtin function min by using >> getattr(__builtins__,'min') >> >> This works at the interpretter prompt >> >> However when I called it inside a module that was imported by another >> module >> it fails and gives an attribute error > > __builtins__ (note the final 's') is an implementation detail. You want > the __builtin__ (no 's') module, renamed 'builtin' in Python 3.x Should read "...renamed 'builtins' in Python 3.x, just to add to the confusion." :) -- Gabriel Genellina From rustompmody at gmail.com Thu May 12 23:53:19 2011 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 13 May 2011 09:23:19 +0530 Subject: Non Programming in python In-Reply-To: References: <58a6bb1b-a98e-4c4a-86ea-09e040cb2d21@r35g2000prj.googlegroups.com> Message-ID: On Wed, May 11, 2011 at 5:57 PM, Calvin Spealman wrote: > If this is the "non-programming side of python" then maybe some of us have > a lacking definition of what "programming" is. My mechanic stilll has to > check the tire pressure and I need to update the version number in PyPI. > O well you dont like the term 'non-programming'? As I said neither do I... On May 10, 2011 12:46 PM, "rusi" wrote: > > Sorry for a silly subject change: A better one will be welcome -- cant > think of a name myself. > > Maybe another way of describing this list may be 1. Programming from 'inside' or 'under' python and 2. The rest of it which is outside/surrounding the python interpreter Because 1 is mostly called 'programming' and 2 has no name, 2 gets neglected more than it should. Or take any python book and browse the contents. What will you find? Python data structures, Python control structures, OOP in python, advanced function topics, scopes, modules, exceptions etc -- almost all the 'inside' stuff well organized, with the outside stuff strewn around in hard-to-find corners of the index (if at all). Does that reflect the reality of python's actual learning curve? -------------- next part -------------- An HTML attachment was scrubbed... URL: From swavijay at gmail.com Fri May 13 01:22:54 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Fri, 13 May 2011 10:52:54 +0530 Subject: Need Assistance on this program. In-Reply-To: <4DCBB88A.8020702@timgolden.me.uk> References: <4DCBB18B.5050309@timgolden.me.uk> <4DCBB88A.8020702@timgolden.me.uk> Message-ID: Hi Tim., Thanks.. This works as I had expected. are there any documentation for the subprocess.call method? I tried going through the python doc but could not narrow down. I just wanted to know how do I pass an arguement after invoking the command prompt? Any thoughts on this pls? On Thu, May 12, 2011 at 4:08 PM, Tim Golden wrote: > On 12/05/2011 11:29, vijay swaminathan wrote: > > <... snippet from code ...> > print 'Invoking Command Promptt..............' > #subprocess.call(["start", "/DC:\\PerfLocal_PAL", > "scripts_to_execute.bat"], shell=True) > subprocess.call(["start", "C:\\windows\\system32\\cmd.exe"], shell = > True) > self.status() > > > If you want to use start, use start /wait. > > But you don't have to: > > > import threading > import time > import subprocess > > def run_command (command): > # > # .call is shorthand for: start process and wait > # CREATE_NEW_CONSOLE prevents it from getting messed > # up with the Python console > # > subprocess.call ( > [command], > creationflags=subprocess.CREATE_NEW_CONSOLE > ) > > t = threading.Thread (target=run_command, args=("cmd.exe",)) > t.start () > > while t.is_alive (): > print "alive" > time.sleep (0.5) > > print "Thread is dead" > > > > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From james.housden at deutsche-boerse.com Fri May 13 01:45:10 2011 From: james.housden at deutsche-boerse.com (JamesEM) Date: Thu, 12 May 2011 22:45:10 -0700 (PDT) Subject: generate properties code in class dynamically References: Message-ID: <9d949617-f4f0-4421-8de7-f283861995ac@t19g2000yql.googlegroups.com> On May 12, 10:04?pm, Terry Reedy wrote: > On 5/12/2011 9:11 AM, JamesEM wrote: > > > > > I would prefer to generate the properties code dynamically from the > > keys of the dictionaries. > > What I am looking for is something like: > > > class MyClass(object): > > > ? ? ?def __init__(self): > > ? ? ? ? ?self.d = {} > > ? ? ? ? ?d['field1'] = 1.0 > > ? ? ? ? ?d['field2'] = 'A' > > ? ? ? ? ?d['field3'] = [10.0,20.0,30.0] > > ? ? ? ? ?for f in d: > > ? ? ? ? ? ? create_property(f) > > > where create_property(f) dynamically creates the property code for > > field f in MyClass. > > > Is this possible? > > Without actually trying, I am not sure, but I believe maybe (possibly > version dependent). The init method is the wrong place. Create the > properties exactly once, just after the class is created. It is possible > to add functions to classes as attributes (instance methods) after they > are created. The property decorators *might* require that they be > invoked with the class body, I do not know. I would first try with > property(). > > Assuming dict name 'd' is fixed: > > def gsd(key): > ? ?def get(self): > ? ? ?return self.d[key] > ? ?def set(self, value): > ? ? ?self.d[key] = value > ? ?def del(self): > ? ? ?del self.d[key] > ? ?return get,set,del > > for key in fieldnames: > ? ?setattr(MyClass, key, property(*gsd(key))) > > For recent versions, this could be done within a class decorator, but > that is only convenient syntactic sugar. > > -- > Terry Jan Reedy Thanks for your help. I tried the above for get and set which worked as desired. However, the del did not seem to work for me (using python 2.6.5). I hope I did not mistype anything, but it objects to def del with a syntax error. I guess because del is a reserved word. James From wxjmfauth at gmail.com Fri May 13 02:28:09 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 12 May 2011 23:28:09 -0700 (PDT) Subject: unicode by default References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> Message-ID: <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> On 12 mai, 18:17, Ian Kelly wrote: > ... > to worry about encodings are when you're encoding unicode characters > to byte strings, or decoding bytes to unicode characters A small but important correction/clarification: In Unicode, "unicode" does not encode a *character*. It encodes a *code point*, a number, the integer associated to the character. jmf From rustompmody at gmail.com Fri May 13 02:46:12 2011 From: rustompmody at gmail.com (rusi) Date: Thu, 12 May 2011 23:46:12 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mathematics has existed for millenia. Hindu-arabic numerals (base-10 numbers) have been known for about one millennium The boolean domain is only a 100 years old. Unsurprisingly it is not quite 'first-class' yet: See http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html [Lifted from http://c2.com/cgi/wiki?EqualVsTrueFalse ] ---------------------------- "In retrospect, one might be tempted to regard the introduction of something as simple as the boolean domain as a minor invention, but I think that that would be a grave mistake: it is a great invention because, being so simple, it is such a powerful simplifier. It is of the same level as the introduction of natural numbers, which enabled us to add 3 to 5, regardless of whether we are adding apples or pears." "George Boole made a radical invention, so radical, in fact, that now, more than a century later, the scientific community has not absorbed it yet. (To stay with the metaphor: officially, boolean expressions may have reached the status of first-class citizens, in practice ? because old habits and prejudices die hard? they are still the victims of discrimination.) Let me give you a few examples." "In the programming language FORTRAN, as conceived a century after Boole published his invention, boolean expressions are allowed, but there are no boolean variables! Their introduction into programming had to wait until the design of ALGOL 60." ------------------------ So, M Harris problem is that python could almost be a language for the 'masses' (whatever that might mean) were it not for warts like "l not is empty" is shorten-able to just "l" Dijkstra's problem (paraphrased) is that python, by choosing the FORTRAN alternative of having a non-first-class boolean type, hinders scientific/mathematical thinking/progress. I tend to agree with Dijkstra's view that the boolean type should be given more respect except for the small fact that the computer's ALU is based on the logic-arithmetic pun: half-adder = xor (half)-carry = and From mail at timgolden.me.uk Fri May 13 03:40:10 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 May 2011 08:40:10 +0100 Subject: Need Assistance on this program. In-Reply-To: References: <4DCBB18B.5050309@timgolden.me.uk> <4DCBB88A.8020702@timgolden.me.uk> Message-ID: <4DCCE05A.2070600@timgolden.me.uk> On 13/05/2011 06:22, vijay swaminathan wrote: > Hi Tim., > > Thanks.. This works as I had expected. > > are there any documentation for the subprocess.call method? I tried > going through the python doc but could not narrow down. http://docs.python.org/library/subprocess.html?highlight=subprocess%20call#subprocess.call > I just wanted to > know how do I pass an arguement after invoking the command prompt? Well, now, that's a whole 'nother can of worms :) The more so since you're relying on a command prompt. Can I suggest you read around the Popen.communicate method: http://docs.python.org/library/subprocess.html?highlight=subprocess%20call#subprocess.Popen.communicate and some of the examples below and try something out for yourself. It can be a little bit fiddly, but you'll do better if you get something up-and-running (or up-and-failing) and then ask for advice on where you're going wrong. TJG From clp2 at rebertia.com Fri May 13 04:02:07 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 13 May 2011 01:02:07 -0700 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 12, 2011 at 11:46 PM, rusi wrote: > The boolean domain is only a 100 years old. > Unsurprisingly it is not quite 'first-class' yet: See It is nowadays. Every halfway-mainstream language I can think of has an explicit boolean datatype. Heck, as of C99, even C has one now. I conjecture the only languages still lacking one are exotic niche/fringe languages. I would be interested to see a counterexample. > http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > [Lifted from http://c2.com/cgi/wiki?EqualVsTrueFalse ] > > ---------------------------- > "In retrospect, one might be tempted to regard the introduction of > something as simple as the boolean domain as a minor invention, but I > think that that would be a grave mistake: it is a great invention > because, being so simple, it is such a powerful simplifier. It is of > the same level as the introduction of natural numbers, which enabled > us to add 3 to 5, regardless of whether we are adding apples or > pears." > > "George Boole made a radical invention, so radical, in fact, that now, > more than a century later, the scientific community has not absorbed > it yet. (To stay with the metaphor: officially, boolean expressions > may have reached the status of first-class citizens, in practice ? > because old habits and prejudices die hard? they are still the victims > of discrimination.) Let me give you a few examples." > > "In the programming language FORTRAN, as conceived a century after > Boole published his invention, boolean expressions are allowed, but > there are no boolean variables! Their introduction into programming > had to wait until the design of ALGOL 60." > > ------------------------ > So, M Harris problem is that python could almost be a language for the > 'masses' (whatever that might mean) were it not for warts like "l not > is empty" is shorten-able to just "l" One language's wart is another language's idiom. And I think the irrational hate towards syntactically-significant indentation is by far a much larger barrier to "mass" adoption of Python; C++ has some features that are at least (if not more) subtle/unobvious than Python's __bool__(), yet it still enjoys "mass" use. > Dijkstra's problem (paraphrased) is that python, by choosing the > FORTRAN alternative of having a non-first-class boolean type, hinders > scientific/mathematical thinking/progress. Python has *not* chosen the Fortran alternative; *it has a first-class Boolean type*, namely bool. This line of argument thus fails. The fact that other types are implicitly coercible to bools doesn't make `bool` itself any less first-class. It is also ironic that one of the projects that exploits Python's flexible typing regarding normally-Boolean operators is a scientific one (NumPy). Cheers, Chris -- http://rebertia.com From hg at schaathun.net Fri May 13 04:47:50 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Fri, 13 May 2011 09:47:50 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <791t98-659.ln1@svn.schaathun.net> Message-ID: On Thu, 12 May 2011 23:20:20 +1000, Chris Angelico wrote: : Writing a program requires expertise both in programming and in the : purpose for which it's being written. Ultimately, a programmer is a : translator; without proper comprehension of the material he's : translating, he can't make a clear translation. But that's completely : different from hiring someone to do a job, and then looking at the job : afterwards; True. When you are able completely to specify the job and commission it, then it is possible to isolate the disciplines, and reduce the programmer to translator. The challenge is that that very often is not the case. The double challenge in computing is that software its development is still not as well understood as hardware or construction. We still do not have sufficient tools, experience and frameworks to project and precisely plan a software development projects. They go over time, over budget, and under specifications far more often and more seriously than projects in other disciplines. Civil and electronic engineers spend much of their time learning to project and cost solutions. Computer engineers very rarely do; they just hack it. In other trades, there tend to be clear role divisions with different roles and specialisations, complementing eachothers. We have not yet quite managed to work out what a programmer, architect, designer, engineer, et cetera are in software. We have the idea that we need them, but we have not formalised them to the point where we know what to expect from each role, and we struggle communicating between them. Therefore, a programmer is not just a translator. The language to specify precisely what is required is not good enough, and therefor the programmer also needs to be a system designer, to some extent. What extent depends much on the situation. >From my point of view, it is just harder to instruct a programmer to write a code than it is to instruct a python interpreter. : if I order a concreting job, I'll look at whether it's : properly suited to the task, but I won't expect an explanation of : exactly what went into it, and I do not expect to understand the exact : chemistry of it. Only another expert in concrete would truly : comprehend it all. Now you are thinking black and white, while reality is a gray blur. You may not care about your concrete, but someone commissioning concrete to build a skyscraper would surely want to check the spec's to quite some level of detail. The construction engineers will surely need to know a lot more about the exact composition and science behind the recipe than the manager renting the top floor, and still much less than the concrete engineer. And the main difference here, is that the civil engineers have a much better language to share information. The best programmers have is the programmming language, and we ought to make that as good as possible. -- :-- Hans Georg From nobody at nowhere.com Fri May 13 04:48:52 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 13 May 2011 09:48:52 +0100 Subject: os.popen command working differently on Windows References: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> Message-ID: On Thu, 12 May 2011 15:21:41 +0100, Tim Golden wrote: > os.popen returns a file-like object from which you can read any error > messages generated. The documentation doesn't say, but if it's anything like the Unix popen() function, with mode='r' the returned file-like object will correspond to the child's stdout, but error messages will normally be written to stderr. In any case, os.popen() and similar are deprecated in favour of subprocess.Popen(). From saeedullah at gmail.com Fri May 13 05:33:29 2011 From: saeedullah at gmail.com (saeed) Date: Fri, 13 May 2011 02:33:29 -0700 (PDT) Subject: Call for Papers (CFP) Message-ID: <3afe5ec5-5ff9-436f-92c4-70ce85daff31@r27g2000prr.googlegroups.com> ========================================================= Journal of Emerging Trends in Computing and Information Sciences Call for Research Papers (Vol. 2 No. 6) June 2011 http://cisjournal.org/ ========================================================= Dear Sir/ Madam, Journal of Emerging Trends in Computing and Information Sciences (E- ISSN 2218-6301/ ISSN 2079-8407) is an international refereed research publishing journal, focused on promoting and publishing original high quality research work in both theoretical and scientific aspects of all disciplines of Computing and Information Sciences. The objectives of the journal are to promote and publish original high quality research and to provide a forum to the researchers and industry practitioners for exchanging ideas, knowledge, and experience. We welcome original research and industry experience papers. Contributions should be written for one of the following categories: Original research Literature Review / Systematic Literature Review Short Articles on ongoing research Preliminary Findings Technical Reports / Notes Results previously published in conferences and/or journals may be submitted as extended versions. For more information about Journal and Publication Charges, please visit http://www.cisjournal.org/. You are requested to circulate this message among your colleagues and college/university fellows. Sincerely Yours, Editor Journal of Emerging Trends in Computing and Information Sciences URL: http://www.cisjournal.org E-mail:editor at cisjournal.org From balle at chaostal.de Fri May 13 06:19:01 2011 From: balle at chaostal.de (Bastian Ballmann) Date: Fri, 13 May 2011 12:19:01 +0200 Subject: Parsing a graph image Message-ID: <20110513121901.7ff67dd1@chaostal.de> Hi python lovers out there, I am searching for a library to parse data from a graph in an image file something like http://pytseries.sourceforge.net/_images/yahoo.png Any suggestions, hints, links? TIA && have a nice day! :) Basti -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From rustompmody at gmail.com Fri May 13 06:58:44 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 13 May 2011 03:58:44 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ebe45e2-9f6c-4f2c-b641-647490a75888@y27g2000prb.googlegroups.com> On May 13, 1:02?pm, Chris Rebert wrote: > On Thu, May 12, 2011 at 11:46 PM, rusi wrote: > > > The boolean domain is only a 100 years old. > > Unsurprisingly it is not quite 'first-class' yet: See > > It is nowadays. Every halfway-mainstream language I can think of has > an explicit boolean datatype. I guess you did not quite see my 'quite' -- which itself is a summarization of Dijkstra's "officially" vs "in practice" ? [Heres the quote] > >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > > [Lifted fromhttp://c2.com/cgi/wiki?EqualVsTrueFalse] > > > ---------------------------- > > "In retrospect, one might be tempted to regard the introduction of > > something as simple as the boolean domain as a minor invention, but I > > think that that would be a grave mistake: it is a great invention > > because, being so simple, it is such a powerful simplifier. It is of > > the same level as the introduction of natural numbers, which enabled > > us to add 3 to 5, regardless of whether we are adding apples or > > pears." > > > "George Boole made a radical invention, so radical, in fact, that now, > > more than a century later, the scientific community has not absorbed > > it yet. (To stay with the metaphor: officially, boolean expressions > > may have reached the status of first-class citizens, in practice ? > > because old habits and prejudices die hard? they are still the victims > > of discrimination.) Let me give you a few examples." > > > "In the programming language FORTRAN, as conceived a century after > > Boole published his invention, boolean expressions are allowed, but > > there are no boolean variables! Their introduction into programming > > had to wait until the design of ALGOL 60." As an analogy, in Perl, a list can get coerced to its length "... when in scalar context.." or something like that. Most programmers from the static-typechecked-languages camp would balk at that laissez faire attitude. Likewise Harris is pointing out that noob python programmers may feel a bit unnerved by non-boolean types unexpectedly showing 'boolean-ness.' Maybe we are just more in noob category and we've not got the zen of python?? Dunno... From swavijay at gmail.com Fri May 13 07:03:07 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Fri, 13 May 2011 16:33:07 +0530 Subject: Assistance in understanding the sub-Process module Message-ID: Hi Gurus, I'm new to Python programming and in the process of learning the sub process module. I went through the python documentation http://docs.python.org/library/subprocess.html and I have the following queries 1. The class definition as per the documentation is: *class *subprocess.Popen(*args*, *bufsize=0*, *executable=None*, *stdin=None *, *stdout=None*, *stderr=None*, *preexec_fn=None*, *close_fds=False*, * shell=False*, *cwd=None*, *env=None*, *universal_newlines=False*, * startupinfo=None*, *creationflags=0*) *args* should be a string, or a sequence of program arguments. so I assume that args can be a string or a list with first item of the list being the program to execute. so on the python IDLE, I executed this command, >>> subprocess.Popen('cmd.exe') which opened up a command prompt. when I give this as a list, as below it throwed this error. >>> subprocess.Popen(['cmd.exe', 'dir']) Traceback (most recent call last): File "", line 1, in subprocess.Popen(['cmd.exe' 'dir']) File "C:\Python26\lib\subprocess.py", line 623, in __init__ errread, errwrite) File "C:\Python26\lib\subprocess.py", line 833, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified >>> I would assume that a list is accepted as part of the args and first being the program (cmd.exe) and the rest being the arguments... please correct me If i misunderstood. Thanks, -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri May 13 07:11:33 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 13 May 2011 04:11:33 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> Message-ID: On May 12, 3:06?am, Hans Mulder wrote: > On 03/05/2011 09:52, rusi wrote: > > > [If you believe it is, then try writing a log(n) fib iteratively :D ] > > It took me a while, but this one seems to work: > > from collections import namedtuple > > Triple = namedtuple('Triple', 'hi mid lo') > Triple.__mul__ = lambda self, other: Triple( > ? ? ?self.hi * other.hi + self.mid * other.mid, > ? ? ?self.hi * other.mid + self.mid * other.lo, > ? ? ?self.mid * other.mid + self.lo * other.lo, > ) > > def fib(n): > ? ? ?f = Triple(1, 1, 0) > ? ? ?a = Triple(1, 0, 1) > ? ? ?while n: > ? ? ? ? ?if n & 1: > ? ? ? ? ? ? ?a *= f > ? ? ? ? ?f *= f > ? ? ? ? ?n >>= 1 > ? ? ?return a.mid > > -- HansM Bravo! Can you explain this? The tightest way I knew so far was this: The 2x2 matrix 0 1 1 1 raised to the nth power gives the nth fibonacci number. [And then use a logarithmic matrix mult] Your version is probably tighter than this. Yet one could argue that this is 'cheating' because you (and I) are still solving the power problem. What I had in mind was to use fib results like: f_(2n) = f_n^2 + f_(n+1)^2 and use these in the same way (from first principles) like we use the equation x^2n = (x*x)^n to arrive at a logarithmic power algo. From ulrich.eckhardt at dominolaser.com Fri May 13 08:01:48 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 13 May 2011 14:01:48 +0200 Subject: Parsing a graph image References: Message-ID: <90jv98-322.ln1@satorlaser.homedns.org> Bastian Ballmann wrote: > I am searching for a library to parse data from a graph in an image file > something like http://pytseries.sourceforge.net/_images/yahoo.png > Any suggestions, hints, links? I'm not sure I understand 100% what you want. If you want to extract ("parse") the data that is contained in an image file, I have no clue how to do that. However, if you want to create such images and you already have the data, that should be as easy as picking the right library for that. I did a short search of Packages available for Debian and it gave me these: python-magics++ - python support for Magics++ python-matplotlib - Python based plotting system in a style similar to Matlab python-mpmath - library for arbitrary-precision floating-point arithmetic python-plplot - Python support for PLplot, a plotting library python-qwt3d-qt3 - Python bindings of the QwtPlot3D library python-qwt3d-qt4 - Python bindings of the QwtPlot3D library python-qwt5-qt3 - Python version of the Qwt5 technical widget library python-qwt5-qt4 - Python version of the Qwt5 technical widget library python-pybiggles - Scientific plotting package for Python python-chaco - interactive plotting application toolkit python-gnuplot - A Python interface to the gnuplot plotting program python-pychart - Python library for creating high quality charts python-simpy - python-based simulation package python-scitools - Python library for scientific computing python-sympy - Computer Algebra System (CAS) in Python python-viper - minimalistic scientific plotter and run-time visualization module Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From balle at chaostal.de Fri May 13 08:24:45 2011 From: balle at chaostal.de (Bastian Ballmann) Date: Fri, 13 May 2011 14:24:45 +0200 Subject: Parsing a graph image In-Reply-To: <90jv98-322.ln1@satorlaser.homedns.org> References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <20110513142445.0792eb4e@chaostal.de> Hi, Am Fri, 13 May 2011 14:01:48 +0200 schrieb Ulrich Eckhardt : > I'm not sure I understand 100% what you want. If you want to extract > ("parse") the data that is contained in an image file, I have no clue > how to do that. Yes, I want to extract the data that is contained in an image file. Greets Basti -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From moky.math at gmail.com Fri May 13 08:30:01 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:30:01 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <4DCD2449.8010203@gmail.com> > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent From moky.math at gmail.com Fri May 13 08:30:12 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:30:12 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <4DCD2454.3080208@gmail.com> > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent From moky.math at gmail.com Fri May 13 08:30:19 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:30:19 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <4DCD245B.4000301@gmail.com> > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent From moky.math at gmail.com Fri May 13 08:30:37 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:30:37 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <4DCD246D.9030001@gmail.com> > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent From moky.math at gmail.com Fri May 13 08:30:56 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:30:56 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> Message-ID: <4DCD2480.9030009@gmail.com> > Yes, I want to extract the data that is contained in an image file. > Greets > > Basti > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent From nitw.saurabh at gmail.com Fri May 13 08:42:40 2011 From: nitw.saurabh at gmail.com (saurabh verma) Date: Fri, 13 May 2011 18:12:40 +0530 Subject: Parsing a graph image In-Reply-To: <20110513142445.0792eb4e@chaostal.de> References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> Message-ID: On 13-May-2011, at 5:54 PM, Bastian Ballmann wrote: > Hi, > > Am Fri, 13 May 2011 14:01:48 +0200 > schrieb Ulrich Eckhardt : > >> I'm not sure I understand 100% what you want. If you want to extract >> ("parse") the data that is contained in an image file, I have no clue >> how to do that. > > Yes, I want to extract the data that is contained in an image file. > Greets > I guess it requires some kind of image processing , where you can move around image pixel by pixel and somehow figure out what color is present in that pixel . If there isn?t much noise in the image you should sharp contrast and would be able to differentiate between two colors ? if yes ( I don?t know matlab might provide some tools .. just guessing ) then its easy i think to pick (X,Y) as time and value ? ~saurabh verma From moky.math at gmail.com Fri May 13 08:43:46 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Fri, 13 May 2011 14:43:46 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> Message-ID: <4DCD2782.2010803@gmail.com> > I guess it requires some kind of image processing , where you can move around image pixel >by pixel and somehow figure out what color is present in that pixel . > If there isn?t much noise in the image you should sharp contrast and would >be able to differentiate between two colors ? if yes ( I don?t know matlab >might provide some tools .. just guessing ) then its easy i think to pick (X,Y) as time and value ? You made me think that in addition to ask to imagemagick's and matplotlib, one can also as to Sage[1] In order of pythonicity : - matplotlib - sage - imagemagick's Laurent [1] www.sagemath.org PS : Sorry for having send my previous answer 5 times. I don't understand :( From mail at timgolden.me.uk Fri May 13 08:44:03 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 May 2011 13:44:03 +0100 Subject: Assistance in understanding the sub-Process module In-Reply-To: References: Message-ID: <4DCD2793.5060806@timgolden.me.uk> On 13/05/2011 12:03, vijay swaminathan wrote: > 1. The class definition as per the documentation is: > /class /subprocess.Popen(/args/, /bufsize=0/, /executable=None/, > /stdin=None/, /stdout=None/, /stderr=None/, /preexec_fn=None/, > /close_fds=False/, /shell=False/, /cwd=None/, /env=None/, > /universal_newlines=False/, /startupinfo=None/, /creationflags=0/) > /args/ should be a string, or a sequence of program arguments. > so I assume that args can be a string or a list with first item of the > list being the program to execute. That's more or less correct. A list is usually preferable as it leaves the heavy-lifting of getting the quotes right to the underlying library. > so on the python IDLE, I executed this command, > >>> subprocess.Popen('cmd.exe') > which opened up a command prompt. > when I give this as a list, as below it throwed this error. > >>> subprocess.Popen(['cmd.exe', 'dir']) > Traceback (most recent call last): > File "", line 1, in > subprocess.Popen(['cmd.exe' 'dir']) > File "C:\Python26\lib\subprocess.py", line 623, in __init__ > errread, errwrite) > File "C:\Python26\lib\subprocess.py", line 833, in _execute_child > startupinfo) > WindowsError: [Error 2] The system cannot find the file specified Well I would actually have expected it to open a command prompt and do nothing else. If you do this in a (Windows) command prompt: cmd /? you can see that the way to run a command from with a command shell is to use: cmd /c (or /k which leaves the console running afterwards). Note that you only even need to launch cmd for internal commands which aren't executables in their own right. ie you don't need to do cmd /c notepad since notepad can run on its own. So doing cmd will just run cmd and, I think, ignore the rest of the line. You actually want: import subprocess subprocess.Popen (["cmd", "/c", "dir"]) However, that is exactly what passing shell=True to Popen does for you so... import subprocess subprocess.Popen ("dir", shell=True) # or subprocess.Popen (["dir"], shell=True) TJG From alister.ware at ntlworld.com Fri May 13 09:13:00 2011 From: alister.ware at ntlworld.com (alister ware) Date: Fri, 13 May 2011 13:13:00 GMT Subject: problem with GKT module? Message-ID: I am using gtk.builder with a glade generated GUI I have a simple call back defined for a radio button widget when I use widget.name in linux I get a value of None, windows returns the widget name as I would expect. is this a bug? if not how should i find the name of the widget that has triggered a call back? (I would like all my radio buttons to go to the same callback routine if possible to make code maintenance easier) -- 101-ism: The tendency to pick apart, often in minute detail, all aspects of life using half-understood pop psychology as a tool. -- Douglas Coupland, "Generation X: Tales for an Accelerated Culture" -- You may my glories and my state dispose, But not my griefs; still am I king of those. -- William Shakespeare, "Richard II" From neilc at norwich.edu Fri May 13 09:31:25 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 13 May 2011 13:31:25 GMT Subject: Parsing a graph image References: Message-ID: <934q5dFrhdU6@mid.individual.net> On 2011-05-13, Bastian Ballmann wrote: > Hi python lovers out there, > > I am searching for a library to parse data from a graph in an > image file something like > http://pytseries.sourceforge.net/_images/yahoo.png Any > suggestions, hints, links? You can do this with PIL . The technique is necessary in The Python Challenge, for example. -- Neil Cerutti From ian.g.kelly at gmail.com Fri May 13 09:55:51 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 May 2011 07:55:51 -0600 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> Message-ID: On Fri, May 13, 2011 at 5:11 AM, rusi wrote: > The tightest way I knew so far was this: > The 2x2 matrix > 0 1 > 1 1 > raised to the nth power gives the nth fibonacci number. [And then use > a logarithmic matrix mult] > Your version is probably tighter than this. Oh, nice! I did it this way once: V = [0 1] M = [0 1] [1 1] fib(n) = (V * M ** n)[0] Since I viewed M as operating on V, it never occurred to me that multiplying by V is actually unnecessary, but it is obvious in retrospect. I think it's just a fortuitous coincidence that it works, since V sets up the base case and M describes the recursive case. For a FIbonacci sequence starting with any other pair of numbers, V would change, but M would not, and so V would no longer happen to be identical to the top row of M. Ian From yagnesh.cyberthink at gmail.com Fri May 13 11:21:18 2011 From: yagnesh.cyberthink at gmail.com (Yagnesh from CyberThink) Date: Fri, 13 May 2011 08:21:18 -0700 (PDT) Subject: My direct client Hiring and interviewing going on Live today. Message-ID: <63b52b88-b7ce-42b1-a971-df9b628e8655@h36g2000pro.googlegroups.com> Hi, My direct client Hiring and interviewing going on Live today. I am having some very good direct client openings currently. I can get the consultant interviewed within 24 business hours. Please drop me an email to get all my direct client openings. I will reply to only those emails which are delivered to yagnesh at cyberthink.com. Thanks and Regards, Yagnesh From yagnesh.cyberthink at gmail.com Fri May 13 11:22:24 2011 From: yagnesh.cyberthink at gmail.com (Yagnesh from CyberThink) Date: Fri, 13 May 2011 08:22:24 -0700 (PDT) Subject: My direct client Hiring and interviewing going on Live today. Message-ID: Hi, My direct client Hiring and interviewing going on Live today. I am having some very good direct client openings currently. I can get the consultant interviewed within 24 business hours. Please drop me an email to get all my direct client openings. I will reply to only those emails which are delivered to yagnesh at cyberthink.com. Thanks and Regards, Yagnesh From lechten at helios.uni-muenster.de Fri May 13 12:01:30 2011 From: lechten at helios.uni-muenster.de (Jens Lechtenboerger) Date: Fri, 13 May 2011 18:01:30 +0200 Subject: Regular Expression for words (with umlauts, without numbers) Message-ID: <878vua4mjp.fsf@pcwi7557.uni-muenster.de> Dear experts, I'm looking for a regular expression to recognize natural language words with umlauts but without numbers. While \w with re.U does recognize words with umlauts, it also matches numbers, which I do not want. Is there a better way than an exhaustive enumeration such as [-a-z???????...]? I guess there should be a better way as \w appears to know about alphabetical characters... Thanks in advance Jens From devchon at gmail.com Fri May 13 12:14:47 2011 From: devchon at gmail.com (Tim Chon) Date: Fri, 13 May 2011 09:14:47 -0700 Subject: Regular Expression for words (with umlauts, without numbers) In-Reply-To: <878vua4mjp.fsf@pcwi7557.uni-muenster.de> References: <878vua4mjp.fsf@pcwi7557.uni-muenster.de> Message-ID: Hallo Jens, In current python re module, you have to do something like: ((?!\d|_\w)+ which uses the negative look ahead to grab all words except integers and underscore. Of course, if you turn on the unicode flag re.U or use it inline like, (?u) then this will grab your desired umlauts. I'd actually recommend, however, that if you have an extra 20 minutes, to use Regexp 2.7: http://bugs.python.org/issue2636 Its a much needed improvement over F.Lundh's re implementation (from 1999!) and its 40% faster. Moreover, you can do exactly what you are requesting like so, (?u)[[:alpha:]]+ cheers, --tim On Fri, May 13, 2011 at 9:01 AM, Jens Lechtenboerger < lechten at helios.uni-muenster.de> wrote: > Dear experts, > > I'm looking for a regular expression to recognize natural language > words with umlauts but without numbers. While \w with re.U does > recognize words with umlauts, it also matches numbers, which I do > not want. > > Is there a better way than an exhaustive enumeration such as > [-a-z???????...]? > > I guess there should be a better way as \w appears to know about > alphabetical characters... > > Thanks in advance > Jens > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri May 13 12:18:43 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 May 2011 18:18:43 +0200 Subject: Regular Expression for words (with umlauts, without numbers) References: Message-ID: Jens Lechtenboerger wrote: > I'm looking for a regular expression to recognize natural language > words with umlauts but without numbers. While \w with re.U does > recognize words with umlauts, it also matches numbers, which I do > not want. > > Is there a better way than an exhaustive enumeration such as > [-a-z???????...]? > > I guess there should be a better way as \w appears to know about > alphabetical characters... How about [^\W\d] ? From lechten at helios.uni-muenster.de Fri May 13 12:49:21 2011 From: lechten at helios.uni-muenster.de (Jens Lechtenboerger) Date: Fri, 13 May 2011 18:49:21 +0200 Subject: Regular Expression for words (with umlauts, without numbers) In-Reply-To: (Peter Otten's message of "Fri, 13 May 2011 18:18:43 +0200") References: Message-ID: <87tycy35ri.fsf@pcwi7557.uni-muenster.de> On 2011-05-13, Peter Otten wrote: > Jens Lechtenboerger wrote: > >> I'm looking for a regular expression to recognize natural language >> words with umlauts but without numbers. While \w with re.U does >> recognize words with umlauts, it also matches numbers, which I do >> not want. >> >> Is there a better way than an exhaustive enumeration such as >> [-a-z???????...]? >> >> I guess there should be a better way as \w appears to know about >> alphabetical characters... > > How about [^\W\d] ? Brilliant. Thanks Jens From hansmu at xs4all.nl Fri May 13 13:10:44 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 13 May 2011 19:10:44 +0200 Subject: os.popen command working differently on Windows In-Reply-To: References: <21581D39FA3BDF40904D75AF9653CE26064FC6D1@blrex.prog.altair.com> Message-ID: <4dcd66d6$0$81483$e4fe514c@news.xs4all.nl> On 12/05/2011 16:21, Tim Golden wrote: > On 12/05/2011 15:11, Ayaskanta Swain wrote: >> Please help me in solving the following issue I am facing while >> executing my python script. Basically I am executing the OS specific >> move command to move a file/dir from one location to another. > > Why? Why not use os.rename or shutil.move which already do > whatever is needed under the covers for different Operating Systems? > > os.popen returns a file-like object from which you can read any > error messages generated. You're not doing that, and os.popen > won't raise an error itself unless you, say, pass it a number > rather than a string. > > > import os > > output = os.popen ("dir") > print output.read () > > # > # But note: > # > os.popen ("Nonsen*se") > > # raises no exception > > If you want exceptions, try the subprocess module: >>> import subprocess >>> subprocess.Popen("Nonsen*se") Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__ errread, errwrite) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1201, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory >>> In fact, os.popen is deprecated in favour of subprocess.Popen(). HTH, -- HansM From jenn.duerr at gmail.com Fri May 13 13:15:29 2011 From: jenn.duerr at gmail.com (noydb) Date: Fri, 13 May 2011 10:15:29 -0700 (PDT) Subject: How best to convert a string "list" to a python list Message-ID: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> I want some code to take the items in a semi-colon-delimted string "list" and places each in a python list. I came up with below. In the name of learning how to do things properly, do you experts have a better way of doing it? Thanks for any inputs! *** x = "red;blue;green;yellow" ## string of semi-colon delimited colors color_list = [] ## sc = semi-colon while x.find(";") <> -1: sc_pos = x.find(";") current_color = x[0:sc_pos] ## color w/o sc current_color_sc = x[0:sc_pos+1] ## color with sc color_list.append(current_color) ## append color to list x = x.replace(current_color_sc, "") ## remove color and sc from string print current_color print color_list print x + "\n" color_list.append(x) # append last color left in x (no sc at end of string) print color_list print "done" From prahamark at gmail.com Fri May 13 13:25:54 2011 From: prahamark at gmail.com (Mark Niemczyk) Date: Fri, 13 May 2011 10:25:54 -0700 (PDT) Subject: How best to convert a string "list" to a python list In-Reply-To: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: There are a series of built-in methods for string objects; including the split method which will accomplish exactly the result you are looking for. >>> x = "red;blue;green;yellow" >>> color_list = x.split(';') >>> color_list ['red', 'blue', 'green', 'yellow'] >>> Here is the link to a discussion of the build-in str methods (3.2), but this documentation exists for prior versions of Python as well. http://docs.python.org/py3k/library/stdtypes.html#str.split Good luck, Mark Niemczyk From malaclypse2 at gmail.com Fri May 13 13:30:39 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 13 May 2011 13:30:39 -0400 Subject: How best to convert a string "list" to a python list In-Reply-To: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 1:15 PM, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. ?I came up with below. ?In > the name of learning how to do things properly, do you experts have a > better way of doing it? Strings have a split method, which splits the string into a list based on a delimiter, like this: >>> x = "red;blue;green;yellow" >>> color_list = x.split(";") >>> print color_list ['red', 'blue', 'green', 'yellow'] That's how I'd do it. -- Jerry From jenn.duerr at gmail.com Fri May 13 13:31:26 2011 From: jenn.duerr at gmail.com (noydb) Date: Fri, 13 May 2011 10:31:26 -0700 (PDT) Subject: How best to convert a string "list" to a python list References: Message-ID: On May 13, 1:25?pm, Mark Niemczyk wrote: > There are a series of built-in methods for string objects; including the split method which will accomplish exactly the result you are looking for. > > >>> x = "red;blue;green;yellow" > >>> color_list = x.split(';') > >>> color_list > > ['red', 'blue', 'green', 'yellow'] > > > > Here is the link to a discussion of the build-in str methods (3.2), but this documentation exists for prior versions of Python as well. > > ? ? ?http://docs.python.org/py3k/library/stdtypes.html#str.split > > Good luck, > > Mark Niemczyk Haha! This is why I ask, because my code is pretty laughable and elementary! I'm learning... Thanks Mark! From python at mrabarnett.plus.com Fri May 13 13:34:55 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 May 2011 18:34:55 +0100 Subject: Regular Expression for words (with umlauts, without numbers) In-Reply-To: References: <878vua4mjp.fsf@pcwi7557.uni-muenster.de> Message-ID: <4DCD6BBF.70308@mrabarnett.plus.com> On 13/05/2011 17:14, Tim Chon wrote: > Hallo Jens, > > In current python re module, you have to do something like: > > ((?!\d|_\w)+ which uses the negative look ahead to grab all words except > integers and underscore. Of course, if you turn on the unicode flag re.U > or use it inline like, (?u) then this will grab your desired umlauts. > > I'd actually recommend, however, that if you have an extra 20 minutes, > to use Regexp 2.7: > http://bugs.python.org/issue2636 > > Its a much needed improvement over F.Lundh's re implementation (from > 1999!) and its 40% faster. Moreover, you can do exactly what you are > requesting like so, > > (?u)[[:alpha:]]+ > The latest release is here: http://pypi.python.org/pypi/regex From python at mrabarnett.plus.com Fri May 13 13:36:53 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 May 2011 18:36:53 +0100 Subject: How best to convert a string "list" to a python list In-Reply-To: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: <4DCD6C35.9060607@mrabarnett.plus.com> On 13/05/2011 18:15, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In > the name of learning how to do things properly, do you experts have a > better way of doing it? > > Thanks for any inputs! > > *** > x = "red;blue;green;yellow" ## string of semi-colon delimited colors > > color_list = [] > ## sc = semi-colon > > while x.find(";")<> -1: > sc_pos = x.find(";") > current_color = x[0:sc_pos] ## color w/o sc > current_color_sc = x[0:sc_pos+1] ## color with sc > color_list.append(current_color) ## append color to list > x = x.replace(current_color_sc, "") ## remove color and sc from > string > print current_color > print color_list > print x + "\n" > > color_list.append(x) # append last color left in x (no sc at end of > string) > print color_list > > print "done" >>> x = "red;blue;green;yellow" >>> x.split(";") ['red', 'blue', 'green', 'yellow'] From ericsnowcurrently at gmail.com Fri May 13 13:37:55 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 13 May 2011 11:37:55 -0600 Subject: How best to convert a string "list" to a python list In-Reply-To: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 11:15 AM, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In > the name of learning how to do things properly, do you experts have a > better way of doing it? > > Thanks for any inputs! > > *** > x = "red;blue;green;yellow" ## string of semi-colon delimited colors > > color_list = [] > ## sc = semi-colon > > while x.find(";") <> -1: > sc_pos = x.find(";") > current_color = x[0:sc_pos] ## color w/o sc > current_color_sc = x[0:sc_pos+1] ## color with sc > color_list.append(current_color) ## append color to list > x = x.replace(current_color_sc, "") ## remove color and sc from > string > print current_color > print color_list > print x + "\n" > > color_list.append(x) # append last color left in x (no sc at end of > string) > print color_list > > print "done" > -- > http://mail.python.org/mailman/listinfo/python-list > Try the following: color_list = x.split(";") Python string objects have a variety of helpful methods. Take a look at http://docs.python.org/library/stdtypes.html#string-methods. Hope that helps. -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri May 13 13:40:44 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 13 May 2011 10:40:44 -0700 (PDT) Subject: how to install easy_install Message-ID: <9f994806-bb7e-4219-9d64-eb50890b4b68@18g2000prd.googlegroups.com> I tried to install easy_install (This is on windows) I downloaded the executable and ran it. It claimed to have done its job. But now when I type easy_install at a cmd prompt I get easy_install is not a command... [I guess I am a perennial noob to windows, never being able to comprehend the PATH lookup logic (or lack of it)] Another related question: I gather that easy_install is being superseded by pypi or some such but I cant find the link... From ian.g.kelly at gmail.com Fri May 13 14:29:17 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 May 2011 12:29:17 -0600 Subject: how to install easy_install In-Reply-To: <9f994806-bb7e-4219-9d64-eb50890b4b68@18g2000prd.googlegroups.com> References: <9f994806-bb7e-4219-9d64-eb50890b4b68@18g2000prd.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 11:40 AM, rusi wrote: > I tried to install easy_install (This is on windows) > I downloaded the executable and ran it. It claimed to have done its > job. > > But now when I type easy_install at a cmd prompt I get > easy_install is not a command... > > [I guess I am a perennial noob to windows, never being able to > comprehend the PATH lookup logic (or lack of it)] > > Another related question: I gather that easy_install is being > superseded by pypi or some such but I cant find the link... easy_install is part of the setuptools or distribute package. I assume that one of these is what you installed. On Windows, the easy_install command is installed into your Python Scripts directory, which should be something like "C:\Python27\Tools\Scripts" or "C:\Python25\Scripts" depending on your Python version. You just need to find that directory and add it to your PATH. PyPI is the Python package index. It's a website at http://pypi.python.org/ -- not a replacement for setuptools or easy_install, which uses it to look up package metadata. Setuptools is supposed to be superseded by distribute, which may be what you heard. HTH, Ian From mitchell.hashimoto at gmail.com Fri May 13 14:43:23 2011 From: mitchell.hashimoto at gmail.com (Mitchell Hashimoto) Date: Fri, 13 May 2011 11:43:23 -0700 Subject: Import on case insensitive filesystem Message-ID: Hello, I'm developing an app which runs Python on a filesystem which is not case sensitive (Mac OS X), but is mounted as an NFS drive on a remote machine. This causes errors because of the import being case sensitive but accessing an FS which is case insensitive. Short of copying the entire directory tree over to another filesystem, is there anything I can do to flag Python to act as though it were on a case sensitive FS? The exact issue I'm seeing is this file, named crypto.py, and relying on pycrypto: from Crypto.Cipher import AES print("Made it!") That attempts to import the same file (itself) instead of finding the Crypto module since the filesystem casing is incorrect. Any tips would be greatly appreciated. Best, Mitchell -------------- next part -------------- An HTML attachment was scrubbed... URL: From redcat at catfolks.net Fri May 13 15:26:40 2011 From: redcat at catfolks.net (Redcat) Date: 13 May 2011 19:26:40 GMT Subject: How best to convert a string "list" to a python list References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: <935evgF8cmU1@mid.individual.net> On Fri, 13 May 2011 10:15:29 -0700, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In the > name of learning how to do things properly, do you experts have a better > way of doing it? How about the below? dan at dan:~/development$ python Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = "cyan;magenta;yellow;black" >>> xList = x.split(';') >>> xList ['cyan', 'magenta', 'yellow', 'black'] >>> From robert.kern at gmail.com Fri May 13 15:38:45 2011 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 13 May 2011 14:38:45 -0500 Subject: Parsing a graph image In-Reply-To: <20110513142445.0792eb4e@chaostal.de> References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> Message-ID: On 5/13/11 7:24 AM, Bastian Ballmann wrote: > Hi, > > Am Fri, 13 May 2011 14:01:48 +0200 > schrieb Ulrich Eckhardt: > >> I'm not sure I understand 100% what you want. If you want to extract >> ("parse") the data that is contained in an image file, I have no clue >> how to do that. > > Yes, I want to extract the data that is contained in an image file. There is nothing in Python that solves this problem, per se, but there are free and open source tools for this out there. E.g. http://digitizer.sourceforge.net/ -- 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 harrismh777 at charter.net Fri May 13 15:41:02 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 13 May 2011 14:41:02 -0500 Subject: checking if a list is empty In-Reply-To: <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: >> http://www.codinghorror.com/blog/2006/07/separating-programming-sheep-from-non-programming-goats.html > A later paper by the same authors... > (http://www.eis.mdx.ac.uk/research/PhDArea/saeed/paper3.pdf) > These papers are fascinating reading, not only for philosophy sake in a great study in epistemology, but for a good clean study in good science and an appropriate measure of the scientific method in an interesting case study that 'failed'. In that regard it was a huge success! The authors recognize (in paper [2]) that while their findings disproved their hypothesis the advances they made through good science have left the door open for further study. This is good news for the field of philosophy generally, and for epistemology in particular. ------- I too have noticed the general 'case' put forward in paper(1): namely, some people just don't seem to get it on the surface, and we can't figure out why. On the other hand, I have 'always' been able to teach computer science (programming in particular) to 'anyone' given enough time, attention, creativity, and caring. In fact, when I find someone who is exhibiting low aptitude potential (let's say zero '0') then I must allow even more time, more attention, much more creativity, and a lot more caring. I remember a line from "Mr. Holland's Opus," (a great movie, by the way) where Mr Holland is explaining to the coach why a certain young man has not any musical acumen --- and the coach says, "..you telling me you can't teach a willing kid to beat a drum...?... then you're a lousy teacher!" Holland ended up teaching us all a lot more than how to beat a drum, before the end of the movie.... The point here is that aptitude says what a person has been conditioned for at this 'point in time' to be able to do... but says nothing about what re-conditioning might do for a transformed life! If I can't teach a kid how to program a computer, I'm a lousy teacher! ------- I grew up with computers. But kids today have 'magical' thinking about these machines, because they didn't grow up with them. If you started out (like I did) on the Altair 8800, or the Wang 700, programming in machine code, it became very clear rapidly why a high level language of some type might be beneficial ( and you could relate how the language constructs made the translation to machine code possible ). It was easier for me to learn programming, because I evolved with it. On the other hand, kids today are dumped into a first comp sci course in programming and plopped in-front of a Hugs interactive shell and then are expected to learn programming and be successful by trying to grasp pure functional programming in Haskell(!) in a ten to 12 week term and we wonder why so many students are failing their 'first' programming class!! Give me a break. No, give them a break. Guido van Rossum has said in one of his interviews (can't remember now which one) that BASIC is a terrible first computer language... and I agree... but, it was a lot better than Hugs! But that's not my point, my point is that Python is better still. Why? Because Python can be taught at a *very* rudimentary level ( input, control, arithmetic, logic and output ) in almost a BASIC or REXX procedural style -- top down -- so that students 'get it'. Then, in subsequent classes down the road (much later) Python can grow and expand with the student's re-conditioning for more in-depth expansion of concepts and knowledge. At the graduate level Python will still be there... challenging students to extend and expand in ways that were not even possible to discuss in the first introductory course. It seems to me that if the goal of comp sci courses at universities and colleges is 'education' that comp sci professors and instructors would get a handle on this. If you can't teach a willing kid to write a functioning computer program then you're a lousy teacher. kind regards, m harris From hansmu at xs4all.nl Fri May 13 15:46:04 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 13 May 2011 21:46:04 +0200 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> Message-ID: <4dcd8b47$0$81473$e4fe514c@news.xs4all.nl> On 13/05/2011 13:11, rusi wrote: > On May 12, 3:06 am, Hans Mulder wrote: >> On 03/05/2011 09:52, rusi wrote: >> >>> [If you believe it is, then try writing a log(n) fib iteratively :D ] >> >> It took me a while, but this one seems to work: >> >> from collections import namedtuple >> >> Triple = namedtuple('Triple', 'hi mid lo') >> Triple.__mul__ = lambda self, other: Triple( >> self.hi * other.hi + self.mid * other.mid, >> self.hi * other.mid + self.mid * other.lo, >> self.mid * other.mid + self.lo * other.lo, >> ) >> >> def fib(n): >> f = Triple(1, 1, 0) >> a = Triple(1, 0, 1) >> while n: >> if n& 1: >> a *= f >> f *= f >> n>>= 1 >> return a.mid >> >> -- HansM > > Bravo! Can you explain this? > > The tightest way I knew so far was this: > The 2x2 matrix > 0 1 > 1 1 > raised to the nth power gives the nth fibonacci number. [And then use > a logarithmic matrix mult] > Your version is probably tighter than this. My method is just a thinly disguised version of your method: your 2x2 matrices are symmetrical, i.e. the number in the upper right is equal to the number in the lower left. So I can save some memory and some CPU time by working with only three numbers. > Yet one could argue that this is 'cheating' because you (and I) are > still solving the power problem. That's true. > What I had in mind was to use fib results like: > f_(2n) = f_n^2 + f_(n+1)^2 > and use these in the same way (from first principles) like we use the > equation > x^2n = (x*x)^n > to arrive at a logarithmic power algo. To compute f(4n) this way, you need to compute both f(2n) and f(2n+1) first, and to compute those, you need f(n) and f(n+1) and f(n+2).... I think I can construct an O(log(n)**2) algorithm this way. And it would still be 'cheating', because we'd still use some special property of the Fibonacci sequence to reduce our problem to the power problem. I think this sort of cheating can't be avoided: there is no general method to compute recurrent sequences faster than O(n); Fibonacci is just a special case. -- HansM From harrismh777 at charter.net Fri May 13 15:53:50 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 13 May 2011 14:53:50 -0500 Subject: unicode by default In-Reply-To: <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: jmfauth wrote: >> to worry about encodings are when you're encoding unicode characters >> > to byte strings, or decoding bytes to unicode characters > > A small but important correction/clarification: > > In Unicode, "unicode" does not encode a*character*. It > encodes a*code point*, a number, the integer associated > to the character. > That is a huge code-point... pun intended. ... and there is another point that I continue to be somewhat puzzled about, and that is the issue of fonts. On of my hobbies at the moment is ancient Greek (biblical studies, Septuaginta LXX, and Greek New Testament). I have these texts on my computer in a folder in several formats... pdf, unicode 'plaintext', osis.xml, and XML. These texts may be found at http://sblgnt.com I am interested for the moment only in the 'plaintext' stream, because it is unicode. ( first, in unicode, according to all the doc there is no such thing as 'plaintext,' so keep that in mind). When I open the text stream in one of my unicode editors I can see 'most' of the characters in a rudimentary Greek font with accents; however, I also see many tiny square blocks indicating (I think) that the code points do *not* have a corresponding character in my unicode font for that Greek symbol (whatever it is supposed to be). The point, or question is, how does one go about making sure that there is a corresponding font glyph to match a specific unicode code point for display in a particular terminal (editor, browser, whatever) ? The unicode consortium is very careful to make sure that thousands of symbols have a unique code point (that's great !) but how do these thousands of symbols actually get displayed if there is no font consortium? Are there collections of 'standard' fonts for unicode that I am not aware? Is there a unix linux package that can be installed that drops at least 'one' default standard font that will be able to render all or 'most' (whatever I mean by that) code points in unicode? Is this a Python issue at all? kind regards, m harris From robert.kern at gmail.com Fri May 13 16:18:33 2011 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 13 May 2011 15:18:33 -0500 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: On 5/13/11 2:53 PM, harrismh777 wrote: > The unicode consortium is very careful to make sure that thousands of symbols > have a unique code point (that's great !) but how do these thousands of symbols > actually get displayed if there is no font consortium? Are there collections of > 'standard' fonts for unicode that I am not aware? There are some well-known fonts that try to cover a large section of the Unicode standard. http://en.wikipedia.org/wiki/Unicode_typeface > Is there a unix linux package > that can be installed that drops at least 'one' default standard font that will > be able to render all or 'most' (whatever I mean by that) code points in > unicode? Is this a Python issue at all? Not really. -- 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 Fri May 13 16:21:49 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 May 2011 14:21:49 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 1:41 PM, harrismh777 wrote: > On the other hand, kids today are dumped into a first comp sci course in > programming and plopped in-front of a Hugs interactive shell and then are > expected to learn programming and be successful by trying to grasp pure > functional programming in Haskell(!) in a ten to 12 week term and we wonder > why so many students are failing their 'first' programming class!! ?Give me > a break. ?No, give them a break. Well, at least Haskell is probably better as an introductory language than Lisp or Scheme. But what schools actually do this? My perception is that the vast majority of schools use C++ or C# or Java, typically relegating functional programming to a single second- or third-year course. Of course it's well known that MIT used to use Scheme, but they switched to Python a couple years ago. > Guido van Rossum has said in one of his interviews (can't remember now which > one) that BASIC is a terrible first computer language... and I agree... but, > it was a lot better than Hugs! ?But that's not my point, my point is that > Python is better still. ?Why? ?Because Python can be taught at a *very* > rudimentary level ( input, control, arithmetic, logic and output ) in almost > a BASIC or REXX procedural style -- top down -- so that students 'get it'. > Then, in subsequent classes down the road (much later) Python can grow and > expand with the student's re-conditioning for more in-depth expansion of > concepts and knowledge. I don't think a single language is necessarily going to be best for all students. If a math major comes to you wanting to learn some programming for theorem-proving, bearing in mind that they probably aren't interested in learning more than a single language, would you try to start them out with Python, or would you just give them the functional language that they're ultimately going to want? From dickinsm at gmail.com Fri May 13 17:48:32 2011 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 13 May 2011 14:48:32 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> Message-ID: On May 11, 11:06?pm, Hans Mulder wrote: > On 03/05/2011 09:52, rusi wrote: > > > [If you believe it is, then try writing a log(n) fib iteratively :D ] > > It took me a while, but this one seems to work: > > from collections import namedtuple > > Triple = namedtuple('Triple', 'hi mid lo') > Triple.__mul__ = lambda self, other: Triple( > ? ? ?self.hi * other.hi + self.mid * other.mid, > ? ? ?self.hi * other.mid + self.mid * other.lo, > ? ? ?self.mid * other.mid + self.lo * other.lo, > ) > [...] You can even get away with pairs rather than triples: ---- from collections import namedtuple Pair = namedtuple('Pair', 'z o') Pair.__mul__ = lambda self, other: Pair( self.z * other.z + self.o * other.o, self.z * other.o + self.o * other.z + self.o * other.o, ) def fib(n): f = Pair(0, 1) a = Pair(1, 0) while n: if n & 1: a *= f f *= f n >>= 1 return a.o ---- I don't see this (or Hans' version) as cheating at all. This really *is* the power algorithm, just in a different number system from the usual one. For those with a bit of abstract algebra, the above algorithm is just computing x^n in the ring Z[x] / (x^2 - x - 1). A pair 'Pair(a, b)' represents the element 'a + bx' (more precisely, the image of 'a + bx' under the natural quotient map Z[x] -> Z[x] / (x^2 - x - 1)) of that ring. And this *can* be generalised to other sequences given by a linear recurrence. Mark From drsalists at gmail.com Fri May 13 19:23:08 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 13 May 2011 16:23:08 -0700 Subject: Parsing a graph image In-Reply-To: <20110513121901.7ff67dd1@chaostal.de> References: <20110513121901.7ff67dd1@chaostal.de> Message-ID: You could convert the image to a netpbm format, like ppm, pgm or pbm. If the image has few colors, that should be quite viable. Each of these formats are easy to work with in Python. ppm is for color, pgm is for grayscale, pbm is for strictly black and white, pnm pertains to any of the 3. There are all sorts of filters for converting between these formats and many others in netpbm, and image processing. You might be able to use pnmcut (to select just the part of the image you need - I'm guessing your math will be simpler if you crop off the axes and everything outside them), ppmdist (to convert color (with a low number of colors) to grayscale) or ppmtopgm (for high color images), and pgmedge (for edge detection), etc. Then you might pnmnoraw to get an ASCII pbm instead of a binary one - ASCII netpbm files are even simpler than binary onesto work with. Here's an example of generating a ppm file in Python 2. It looks like this after conversion to png format: http://stromberg.dnsalias.org/~dstromberg/software/circle.png If you set a bunch of them next to each other (say, by tiling it as a wallpaper), it gives a slightly eerie 3D effect. It's an application of the inverse square law. I know, it's kind of the opposite of what you need, but it may still illustrate the approach: #!/usr/bin/python # writes a ppm file for a sort of sphere on stdout. import math import sys def pad(n): s = str(n) while len(s) < 4: s = s + ' ' return s size=200 colors=256 print 'P3' print size,size print colors-1 half=float(size/2) sqrt2 = math.sqrt(2) for i in range(0,size): for j in range(0,size): x = float(i - half) / half y = float(j - half) / half z = math.sqrt(x*x + y*y)/sqrt2 col = int(z * (colors-1)) #sys.stderr.write(str(x)+' '+str(y)+' '+str(col)+'\n') ch = chr(col) sys.stdout.write(pad(col)+pad(col)+pad(col)+' ') print BTW, I don't do string concatenation this much anymore, and xrange is good in 2.x. :) On Fri, May 13, 2011 at 3:19 AM, Bastian Ballmann wrote: > Hi python lovers out there, > > I am searching for a library to parse data from a graph in an image file > something like http://pytseries.sourceforge.net/_images/yahoo.png > Any suggestions, hints, links? > > TIA && have a nice day! :) > > Basti > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Fri May 13 19:30:03 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 14 May 2011 01:30:03 +0200 Subject: Regular Expression for words (with umlauts, without numbers) In-Reply-To: <4DCD6BBF.70308@mrabarnett.plus.com> References: <878vua4mjp.fsf@pcwi7557.uni-muenster.de> <4DCD6BBF.70308@mrabarnett.plus.com> Message-ID: 2011/5/13 MRAB : > The latest release is here: > > ? ?http://pypi.python.org/pypi/regex > -- Wow, set operators were added recently ... https://code.google.com/p/mrab-regex-hg/wiki/GeneralDetails ok, it might be not necassary to sove this exact problem with respect to the solutions already mentioned, but I quite like this extra possibilities, anyway, the double negation [^\W] is not needed here: (?u)[\w--\d] Thank you very much for this excellent library! vbr From harrismh777 at charter.net Fri May 13 20:48:15 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 13 May 2011 19:48:15 -0500 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: Ian Kelly wrote: > Well, at least Haskell is probably better as an introductory language > than Lisp or Scheme. But what schools actually do this? http://www.cs.kent.ac.uk/teaching/resources/haskell/HugsResources.html http://research.cs.queensu.ca/home/cisc260/2010w/haskell.html These are just two schools that teach functional programming early on using Haskell... but there are many. (google around) caveat: thingks are changing all the time, for instance I notice that Margaret Lamb at Queen's University in Ontario hasn't updated her page in about a year... so things may be different there for her classes than when we were first corresponding... ... and I'm also lumping two other languages into this 'category'... namely, Scheme, and Erlang. > perception is that the vast majority of schools use C++ or C# or Java, ... that may be the trend now... > typically relegating functional programming to a single second- or > third-year course. Of course it's well known that MIT used to use > Scheme, but they switched to Python a couple years ago. Scheme seems to be very popular in education, based on the discussions, as a functional language; but, alas, I've not seen it nor played with it ( so can't comment too much, yet ). I'm glad to hear that MIT is using Python now..! > I don't think a single language is necessarily going to be best for > all students. no doubt... I can dream can't I ? > If a math major comes to you wanting to learn some > programming for theorem-proving, bearing in mind that they probably > aren't interested in learning more than a single language, would you > try to start them out with Python, or would you just give them the > functional language that they're ultimately going to want? Well, that's just it... learning how to program is essential for all disciplines IMHO and learning just one language is not an option. Everyone needs a GPL and that's going to be Python... me hopes. And then some majors are going to require special purpose languages that meet certain requirements... and functional languages (haskell, erlang, scheme) are going to suit that need very well) by the by, don't get me wrong... I think Haskell is elegant, one of the best... but, not for students with no programming background, nor for those who just don't seem to be getting it on the first pass. kind regards, m harris From tjreedy at udel.edu Fri May 13 21:41:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 May 2011 21:41:30 -0400 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: On 5/13/2011 3:53 PM, harrismh777 wrote: > The unicode consortium is very careful to make sure that thousands of > symbols have a unique code point (that's great !) but how do these > thousands of symbols actually get displayed if there is no font > consortium? Are there collections of 'standard' fonts for unicode that I > am not aware? Is there a unix linux package that can be installed that > drops at least 'one' default standard font that will be able to render > all or 'most' (whatever I mean by that) code points in unicode? Is this > a Python issue at all? Easy, practical use of unicode is still a work in progress. -- Terry Jan Reedy From ian.g.kelly at gmail.com Fri May 13 21:52:39 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 May 2011 19:52:39 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 6:48 PM, harrismh777 wrote: > Ian Kelly wrote: >> >> Well, at least Haskell is probably better as an introductory language >> than Lisp or Scheme. ?But what schools actually do this? > > http://www.cs.kent.ac.uk/teaching/resources/haskell/HugsResources.html > http://research.cs.queensu.ca/home/cisc260/2010w/haskell.html > > ? These are just two schools that teach functional programming early on > using Haskell... but there are many. ?(google around) The first link is just a collection of Haskell resources, which indicates that they use it, but not when. They also have a collection of Java resources on the department website. Perusing the handbook, I see the following modules: CO320 Introduction to Object-Oriented Programming This appears to be their introductory module. It doesn't say what language they use, but since they have Java resources on the website that's what I'm going to guess. CO530 Functional Programming This is listed as an intermediate-level course and is in the 2nd/3rd year handbook. The synopsis includes: "Introduction to a Haskell system (sessions and scripts)." So no, Kent does not appear to be teaching Haskell as an introductory course, or even in the first year. The Queen's course also appears to be a 2nd year class, based on the number. Its description includes this: "You will learn two new languages: Haskell and Prolog. These languages are a bit different from languages such as *Python* and *Java* that you have learned so far in Queen's courses" (emphasis added). Notably, this class isn't even focused on functional programming; it's an introduction to programming paradigms other than the imperative one. So far, neither of these universities support your claim that "kids today are dumped into a first comp sci course in programming and plopped in-front of a Hugs interactive shell and then are expected to learn programming and be successful by trying to grasp pure functional programming in Haskell(!) in a ten to 12 week term". From greg.ewing at canterbury.ac.nz Fri May 13 22:26:08 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 14 May 2011 14:26:08 +1200 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: <9367i3Fnq3U1@mid.individual.net> Ian Kelly wrote: > If a math major comes to you wanting to learn some > programming for theorem-proving, bearing in mind that they probably > aren't interested in learning more than a single language, I would question whether theorem-proving is the *only* thing they will ever want to do with a programming language. If they really only want to learn one language, it would be better to learn the one with the widest field of applicability. I'd hazard to guess that writing a theorem prover in Python would be a more practical proposition than writing a script to automate processing his LaTeX papers in Haskell. -- Greg From greg.ewing at canterbury.ac.nz Fri May 13 22:32:06 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 14 May 2011 14:32:06 +1200 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: <9367t9Fq0fU1@mid.individual.net> harrismh777 wrote: > ... and I'm also lumping two other languages into this 'category'... > namely, Scheme, and Erlang. Scheme isn't really a functional language, though. You can use a subset of it in a functional way, but it doesn't have the sort of built-in support for pattern matching and case analysis that true functional languages tend to have. As families of languages go, Scheme has more in common with Python than Haskell. -- Greg From greg.ewing at canterbury.ac.nz Fri May 13 22:34:51 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 14 May 2011 14:34:51 +1200 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <93682bFq0fU2@mid.individual.net> rusi wrote: > Dijkstra's problem (paraphrased) is that python, by choosing the > FORTRAN alternative of having a non-first-class boolean type, hinders > scientific/mathematical thinking/progress. Python doesn't have the flaw that Dijkstra was talking about. Fortran's flaw wasn't so much the lack of a boolean type, but that you couldn't assign the result of a logical expression to a variable. Python has always been able to do that, even before it had a distinct boolean type. -- Greg From jjposner at optimum.net Fri May 13 23:47:49 2011 From: jjposner at optimum.net (John Posner) Date: Fri, 13 May 2011 23:47:49 -0400 Subject: How best to convert a string "list" to a python list In-Reply-To: References: Message-ID: <4DCDFB65.5000603@optimum.net> On 5/13/2011 3:38 PM, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In > the name of learning how to do things properly, No big deal that you weren't aware of the split() method for strings. Since you asked for pointers, here are some notes on your code -- which is just fine, overall! > x = "red;blue;green;yellow" ## string of semi-colon delimited colors > > color_list = [] > ## sc = semi-colon > > while x.find(";") <> -1: > sc_pos = x.find(";") > current_color = x[0:sc_pos] ## color w/o sc > current_color_sc = x[0:sc_pos+1] ## color with sc You don't really need the variable "current_color_sc", since you use it only once. For example, your invocation of replace() could look like this: x = x.replace(current_color + ";", "") But if you really want the extra variable, the following definition is clearer (and also avoids a slice operation): current_color_sc = current_color + ";" > color_list.append(current_color) ## append color to list > x = x.replace(current_color_sc, "") ## remove color and sc from string Here's another reason why you don't need the variable "current_color_sc": instead of using replace(), why not just chop off the first N characters of the string: x = x[len(current_color)+1:] (The "+1" takes care of the semicolon.) > print current_color > print color_list > print x + "\n" > > color_list.append(x) # append last color left in x (no sc at end of > string) Does that last append(), outside the loop, offend you? You can get rid of it by modifying the original string: x = "red;blue;green;yellow" x += ";" Now, the final component of the string is no longer a special case, but is terminated by ";" -- just like all the other components. HTH, John From far.runner at gmail.com Sat May 14 00:46:12 2011 From: far.runner at gmail.com (Far.Runner) Date: Fri, 13 May 2011 21:46:12 -0700 Subject: Get IP address of WIFI interface Message-ID: Hi Python Experts: There are two network interfaces on my laptop, one is 100M Ethernet interface, the other is wifi interface, both are connected and has an IP address. then the question is: how to get the ip address of the wifi interface in a python script? OS: Windows or Linux -------------- next part -------------- An HTML attachment was scrubbed... URL: From harrismh777 at charter.net Sat May 14 00:47:06 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 13 May 2011 23:47:06 -0500 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: Ian Kelly wrote: >> >> Well, at least Haskell is probably better as an introductory language >> >> than Lisp or Scheme. But what schools actually do this? >> http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/ http://www.cs.ou.edu/~rlpage/fpclassSpring97/ There are lots of these... the two above afaik are still doing this at the entry level... ... supposedly, these kids are 'mostly' successful and exit interviews are great... but that doesn't fit with the observed idea that students are not doing well in comp sci classes generally... but, read below... this at the entry level?? ====== block quote ========= The first 10 to 11 weeks of the course use Haskell. Students are required to write nine programs in Haskell, three of which are team projects that combine software developed in individual projects. Different members of a team are assigned different individual projects, and the team efforts combine their solutions into a working piece of software. In the early part of the course, students use operators like map, foldr, zip, and iterate to express computations. Explicit recursion is introduced after some experience with these common patterns of computation. Examples and problems address non-numeric applications, for the most part. Both interactive and file I/O are covered, but general purpose monads are not. The last 5 to 6 weeks of the course use C, and most of the projects in that part of the course duplicate the function of earlier pieces of software that the students have written in Haskell. ====== /block quote ========= From far.runner at gmail.com Sat May 14 01:09:24 2011 From: far.runner at gmail.com (Far.Runner) Date: Fri, 13 May 2011 22:09:24 -0700 Subject: Get the IP address of WIFI interface Message-ID: Hi python experts: There are two network interfaces on my laptop: one is 100M Ethernet interface, the other is wifi interface, both are connected and has an ip address. The question is: How to get the ip address of the wifi interface in a python script without parsing the output of a shell command like "ipconfig" or "ifconfig"? OS: Windows or Linux F.R -------------- next part -------------- An HTML attachment was scrubbed... URL: From hujun.work at gmail.com Sat May 14 01:40:01 2011 From: hujun.work at gmail.com (Jun Hu) Date: Fri, 13 May 2011 22:40:01 -0700 Subject: How to get the IP address of the wifi interface? Message-ID: Hi python experts: There are two network interfaces on my laptop, one is 100M Ethernet, the other is wifi, both are connected and have IP addresses. The question is: how to get the ip address of WIFI interface without parsing the output of a shell command like "ipconfig" or "ifconfig"? OS: Windows or Linux H.J -------------- next part -------------- An HTML attachment was scrubbed... URL: From ishwor.gurung at gmail.com Sat May 14 01:41:05 2011 From: ishwor.gurung at gmail.com (Ishwor Gurung) Date: Sat, 14 May 2011 15:41:05 +1000 Subject: Get IP address of WIFI interface In-Reply-To: References: Message-ID: Hi. On 14 May 2011 14:46, Far.Runner wrote: > Hi Python Experts: > There are two network interfaces on my laptop, one is > 100M?Ethernet?interface, the other is wifi interface, both are connected and > has an IP address. then the question is: how to get the ip address of the > wifi interface in a python script? > OS: Windows or Linux Detect the OS with os.name and branch out to specific use case. The specific functionality can be implemented 2 ways: 1/ Regular expression pattern match 2/ Substring match and splits The subprocess module will then let you run those commands. 1/ posix - (Linux in your case) will use ifconfig 2/ nt - (windows in your ase) will use ipconfig. HTH. -- Regards Ishwor Gurung Key id:0xa98db35e Key fingerprint:FBEF 0D69 6DE1 C72B A5A8? 35FE 5A9B F3BB 4E5E 17B5 From astan.chee at gmail.com Sat May 14 02:08:44 2011 From: astan.chee at gmail.com (Astan Chee) Date: Sat, 14 May 2011 16:08:44 +1000 Subject: turn monitor off and on Message-ID: Hi, I'm trying to turn off my monitor, pause and then turn it on again. I'm doing this in python 2.6 and windows xp. Here is my script so far (that doesn't work): import time import win32gui import win32con import win32api def turnOffMonitor(): SC_MONITORPOWER = 0xF170 win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) def turnOnMonitor(): SC_MONITORPOWER = 0xF170 win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) if __name__ == "__main__": turnOffMonitor() time.sleep(5) turnOnMonitor() For some reason, the script doesn't turn the monitor back on. What am I doing wrong here or are there any other alternative? From ian.g.kelly at gmail.com Sat May 14 02:14:59 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 May 2011 00:14:59 -0600 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc502c7$0$29991$c3e8da3$5496439d@news.astraweb.com> <8354770a-d69d-4132-b0ba-2d610eab2fe7@d26g2000prn.googlegroups.com> <4dcb7a8d$0$29973$c3e8da3$5496439d@news.astraweb.com> <25a7c6d9-5d60-4528-8eaf-e6d0e73dfd1d@17g2000prr.googlegroups.com> Message-ID: On Fri, May 13, 2011 at 10:47 PM, harrismh777 wrote: > http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/ > > http://www.cs.ou.edu/~rlpage/fpclassSpring97/ > > > There are lots of these... ? the two above afaik are still doing this at the > entry level... ? ?... supposedly, these kids are 'mostly' successful and > exit interviews are great... ?but that doesn't fit with the observed idea > that students are not doing well in comp sci classes generally... but, read > below... ?this at the entry level?? I'll grant you Edinburgh. That Oklahoma syllabus is from 1997. The 2010 syllabus for the entry-level course indicates that it is taught in Java. From dje at google.com Sat May 14 02:38:59 2011 From: dje at google.com (Doug Evans) Date: Fri, 13 May 2011 23:38:59 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem wrote: > (now in plain-text as required by gdb mailing list) > > Hi, > > I am currently trying to integrate Python support into my toolchain > build (including GDB of course). It is a sysrooted > binutils+GCC+GDB+mingw-w64 toolchain. > > I currently have the basic setup working: I can link gdb with my > manually generated import lib to the python dll from the official > Windows install. If there is anything I am missing or a very easy > solution to the problems decsribed below, please just say so. I am > only suggesting what I would like to happen. > > Now on to the problems I'd like to discuss: > > 1. gdb.exe won't start without me having set PYTHONPATH manually. In a properly configured/built gdb on linux this isn't necessary, even if python is installed in some random place. I'm not sure about windows though. Did you specify --with-python when you configured gdb, and if so did you specify a value? e.g., --with-python=SOME_VALUE > I understand the need for this, but as gdb requires Python 2, and users > of my toolchain may have installed Python 3 or a 32-bit version python > they want to use from the same environment (without changing their own > PYTHONPATH), there is no way to run python-enabled gdb. > [...] Yeah. There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have gdb use that instead of PYTHONPATH if it exists, but there's been resistance to it. I think(!) what would happen is that gdb would set $PYTHONPATH to the value of $GDB_PYTHONPATH. [Inferiors started by gdb should still get the original value of PYTHONPATH though.] > 2. With PYTHONPATH set as a temporary workaround, gdb starts, but > spits out a traceback: > Traceback (most recent call last): > ? File "", line 35, in > ? File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line > 18, in > ??? gdb.command.pretty_printers.register_pretty_printer_commands() > ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", > line 368, in register_pretty_printer_commands > ??? InfoPrettyPrinter() > ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", > line 100, in __init__ > ??? gdb.COMMAND_DATA) > RuntimeError: Could not find command prefix info. > > This is a minor problem I think, as "python import time" "python print > time.clock()" works as expected. What is wrong? I'm not sure. The error message is complaining that the "info" command prefix doesn't exist. I don't see how that can happen as python is initialized long after the info command is created. From harrismh777 at charter.net Sat May 14 03:13:57 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 02:13:57 -0500 Subject: turn monitor off and on In-Reply-To: References: Message-ID: Astan Chee wrote: > import time > import win32gui > import win32con > import win32api > > def turnOffMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) > > def turnOnMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > if __name__ == "__main__": > turnOffMonitor() > time.sleep(5) > turnOnMonitor() What we need here is a matching script that turns off WinXP and leaves it off too... ... ouch, :) lol m harris From harrismh777 at charter.net Sat May 14 03:20:55 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 02:20:55 -0500 Subject: turn monitor off and on In-Reply-To: References: Message-ID: harrismh777 wrote: > > def turnOnMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) I've never tried turning my monitor on/off without using my finger... gonna have to play with this... wouldn't that be a great script kiddie tool... just turn off all the windows monitors around the world... no problem(s) after that... ... what happens if you try to turn it back on with your finger... ? ... I have another idea... while its off, try pushing the alt key on your keyboard... or moving your mouse... (come back on ? ) kind regards, m harris From rustompmody at gmail.com Sat May 14 03:23:51 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 00:23:51 -0700 (PDT) Subject: how to install easy_install References: mailman.1522.1305311391.9059.python-list@python.org Message-ID: On May 13, 11:29?pm, Ian Kelly wrote: > On Fri, May 13, 2011 at 11:40 AM, rusi wrote: > > I tried to install easy_install (This is on windows) > > I downloaded the executable and ran it. It claimed to have done its > > job. > > > But now when I type easy_install at a cmd prompt I get > > easy_install is not a command... > > > [I guess I am a perennial noob to windows, never being able to > > comprehend the PATH lookup logic (or lack of it)] > > > Another related question: I gather that easy_install is being > > superseded by pypi or some such but I cant find the link... > > easy_install is part of the setuptools or distribute package. ?I > assume that one of these is what you installed. > > On Windows, the easy_install command is installed into your Python > Scripts directory, which should be something like > "C:\Python27\Tools\Scripts" or "C:\Python25\Scripts" depending on your > Python version. ?You just need to find that directory and add it to > your PATH. > > PyPI is the Python package index. ?It's a website athttp://pypi.python.org/-- not a replacement for setuptools or > easy_install, which uses it to look up package metadata. ?Setuptools > is supposed to be superseded by distribute, which may be what you > heard. It seems to be something called pip -- Easy_install and plain setup.py install cant uninstall whereas pip can. But to install pip you have to do easy_install pip. O well :-) From harrismh777 at charter.net Sat May 14 03:29:02 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 02:29:02 -0500 Subject: turn monitor off and on In-Reply-To: References: Message-ID: <2bqzp.1932$7N5.281@newsfe04.iad> harrismh777 wrote: >> >> def turnOnMonitor(): >> SC_MONITORPOWER = 0xF170 >> win32gui.SendMessage(win32con.HWND_BROADCAST, >> win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) Wonder what the equivalent of this is in Linux... ? From steve+comp.lang.python at pearwood.info Sat May 14 03:39:31 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 May 2011 07:39:31 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 May 2011 23:46:12 -0700, rusi wrote: > Mathematics has existed for millenia. Hindu-arabic numerals (base-10 > numbers) have been known for about one millennium > The boolean domain is only a 100 years old. Unsurprisingly it is not > quite 'first-class' yet: See > http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > [Lifted from http://c2.com/cgi/wiki?EqualVsTrueFalse ] Th money-quote as regards using arbitrary objects in truth tests: [quote] All this changed with the introduction of the two-element boolean domain {true, false} which provides the vocabulary needed to assign values to boolean expressions: 3<4 is a way for writing true, 3>4 is a way for writing false, whereas the value of x>0 depends on the value of x ... [end quote] In Python, [1, 2, 3] is another way of writing true, and [] is another way of writing false. Similarly with any other arbitrary objects. The only things that bools True and False are good for are: * giving functions a canonical way of spelling true/false when they want to emit a Boolean value; * giving documentation writers a canonical way of spelling true/false when they want to discuss passing a Boolean value. Other than those conveniences, there's nothing you can do with True and False in Python that you can't do with any other set of objects. -- Steven From harrismh777 at charter.net Sat May 14 03:41:10 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 02:41:10 -0500 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: Terry Reedy wrote: >> Is there a unix linux package that can be installed that >> drops at least 'one' default standard font that will be able to render >> all or 'most' (whatever I mean by that) code points in unicode? Is this >> a Python issue at all? > > Easy, practical use of unicode is still a work in progress. Apparently... the good news for me is that SBL provides their unicode font here: http://www.sbl-site.org/educational/biblicalfonts.aspx I'm getting much closer here, but now the problem is typing. The pain with unicode fonts is that the glyph is tied to the code point for the represented character, and not tied to any code point that matches any keyboard scan code for typing. :-} So, I can now see the ancient text with accents and aparatus in all of my editors, but I still cannot type any ancient Greek with my keyboard... because I have to make up a keymap first. I don't find that SBL (nor Logos Software) has provided keymaps as yet... rats. I can read the test with Python though... yessss. m harris From steve+comp.lang.python at pearwood.info Sat May 14 03:43:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 May 2011 07:43:12 GMT Subject: turn monitor off and on References: Message-ID: <4dce3290$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 May 2011 02:20:55 -0500, harrismh777 wrote: > harrismh777 wrote: >> >> def turnOnMonitor(): >> SC_MONITORPOWER = 0xF170 >> win32gui.SendMessage(win32con.HWND_BROADCAST, >> win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > > I've never tried turning my monitor on/off without using my finger... You've never had your PC turn your monitor off after X minutes of inactivity? > gonna have to play with this... wouldn't that be a great script kiddie > tool... just turn off all the windows monitors around the world... no > problem(s) after that... > > ... what happens if you try to turn it back on with your finger... ? Then you actually turn it off, at the power switch, instead of merely off in software. > ... I have another idea... while its off, try pushing the alt key on > your keyboard... or moving your mouse... (come back on ? ) Presumably you would need to program something to watch for activity and turn it back on. It would be somewhat embarrassing if you neglected to so this... -- Steven From rustompmody at gmail.com Sat May 14 03:45:29 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 00:45:29 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 14, 12:39?pm, Steven D'Aprano wrote: > On Thu, 12 May 2011 23:46:12 -0700, rusi wrote: > > Mathematics has existed for millenia. Hindu-arabic numerals (base-10 > > numbers) have been known for about one millennium > > The boolean domain is only a 100 years old. Unsurprisingly it is not > > quite 'first-class' yet: See > >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > > [Lifted fromhttp://c2.com/cgi/wiki?EqualVsTrueFalse] > > Th money-quote as regards using arbitrary objects in truth tests: > > ? ? [quote] > ? ? All this changed with the introduction of the two-element > ? ? boolean domain {true, false} which provides the vocabulary > ? ? needed to assign values to boolean expressions: 3<4 is a > ? ? way for writing true, 3>4 is a way for writing false, > ? ? whereas the value of x>0 depends on the value of x ... > ? ? [end quote] > > In Python, [1, 2, 3] is another way of writing true, and [] is another > way of writing false. Similarly with any other arbitrary objects. Well so is [1,2] another way of writing True And then we get the interesting result that (True = True) is False From alex.kapps at web.de Sat May 14 03:59:07 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 14 May 2011 09:59:07 +0200 Subject: turn monitor off and on In-Reply-To: <2bqzp.1932$7N5.281@newsfe04.iad> References: <2bqzp.1932$7N5.281@newsfe04.iad> Message-ID: <4DCE364B.3090603@web.de> On 14.05.2011 09:29, harrismh777 wrote: > harrismh777 wrote: >>> >>> def turnOnMonitor(): >>> SC_MONITORPOWER = 0xF170 >>> win32gui.SendMessage(win32con.HWND_BROADCAST, >>> win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > > Wonder what the equivalent of this is in Linux... ? Probably xset dpms force {on,off,...} From harrismh777 at charter.net Sat May 14 04:05:11 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 03:05:11 -0500 Subject: turn monitor off and on In-Reply-To: <4dce3290$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4dce3290$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> I've never tried turning my monitor on/off without using my finger... > You've never had your PC turn your monitor off after X minutes of > inactivity? I know you're being funny, but actually, no-- I don't. That's a back-in-the-day thing... all of my monitors (and I only have a couple now because I use VNC to get to the rest of my machines) are flat panel LED, very low power, cool, and virtually indestructible. I just leave them on... with beautiful screen savers running... which aren't screen savers these days either... because nothing really burns... more like perpetual light-candy eye-pleasers... Sure, back in the day I configured my system to shutoff the CRT... but honestly, I haven't had a CRT for almost a decade... you can still shutdown the flat panel several different ways on the linux platform based on timing if you want to... in BIOS, in the OS, in gnome, using the xscreensaver, etc... but, no, I have never written a code routine to shutoff the monitor (my finger always worked just fine). :) I wrote a code routine one time just to open the drive bay door, timer(), and then close the door... from across the network... until my wife got wise to it, I would open her drive bay door over the network... it was fun for a while, even after she got wise to it... ... till the morning I tried it and she had a cup of cocoa sitting on the desk in front of the drive bay... ... there have been better days in my house. :) From nobody at nowhere.com Sat May 14 04:34:54 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 14 May 2011 09:34:54 +0100 Subject: unicode by default References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: On Fri, 13 May 2011 14:53:50 -0500, harrismh777 wrote: > The unicode consortium is very careful to make sure that thousands > of symbols have a unique code point (that's great !) but how do these > thousands of symbols actually get displayed if there is no font > consortium? Are there collections of 'standard' fonts for unicode that I > am not aware? Is there a unix linux package that can be installed that > drops at least 'one' default standard font that will be able to render all > or 'most' (whatever I mean by that) code points in unicode? Using the original meaning of "font" (US) or "fount" (commonwealth), you can't have a single font cover the whole of Unicode. A font isn't a random set of glyphs, but a set of glyphs in a common style, which can only practically be achieved for a specific alphabet. You can bundle multiple fonts covering multiple repertoires into a single TTF (etc) file, but there's not much point. In software, the term "font" is commonly used to refer to some ad-hoc mapping between codepoints and glyphs. This typically works by either associating each specific font with a specific repertoire (set of codepoints), or by simply trying each font in order until one is found with the correct glyph. This is a sufficiently common problem that the FontConfig library exists to simplify a large part of it. > Is this a Python issue at all? No. From nobody at nowhere.com Sat May 14 04:41:20 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 14 May 2011 09:41:20 +0100 Subject: How best to convert a string "list" to a python list References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: On Fri, 13 May 2011 10:15:29 -0700, noydb wrote: > I want some code to take the items in a semi-colon-delimted string "list" > and places each in a python list. I came up with below. In the name of > learning how to do things properly, do you experts have a better way of > doing it? > x = "red;blue;green;yellow" ## string of semi-colon delimited colors Provided that a semicolon is *always* a delimiter, just use the .split() method: color_list = x.split(";") For more complex formats, where there are quote and/or escape characters which allow the delimiter to occur as part of an item, you typically need to use a regular expression to match everything up to the next delimiter, and do this in a loop to extract the individual items. From pmartinsen at gmail.com Sat May 14 04:44:39 2011 From: pmartinsen at gmail.com (Paul) Date: Sat, 14 May 2011 01:44:39 -0700 (PDT) Subject: Parsing a graph image References: mailman.1510.1305281943.9059.python-list@python.org Message-ID: <759e1b75-cbf7-4caf-9658-9fbef3731dc2@34g2000pru.googlegroups.com> On May 13, 11:19?pm, Bastian Ballmann wrote: > Hi python lovers out there, > > I am searching for a library to parse data from a graph in an image file > something likehttp://pytseries.sourceforge.net/_images/yahoo.png > Any suggestions, hints, links? > > TIA && have a nice day! :) > > Basti > > ?signature.asc > < 1KViewDownload Hi, If you are trying to digitize data from the graph, you could try Dagra: http://www.BlueLeafSoftware.com/Products/Dagra/ There is a Python library for reading the files it produces. hth paul From hansmu at xs4all.nl Sat May 14 04:52:50 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 14 May 2011 10:52:50 +0200 Subject: checking if a list is empty In-Reply-To: <61e9b51a-492f-410d-8ebc-e516165795df@y12g2000yqh.googlegroups.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <8BD5792C-AFE3-4B86-82DB-B6C3F249FA5F@semanchuk.com> <61e9b51a-492f-410d-8ebc-e516165795df@y12g2000yqh.googlegroups.com> Message-ID: <4dce43a7$0$81476$e4fe514c@news.xs4all.nl> On 07/05/2011 02:43, Jon Clements wrote: > On May 7, 12:51 am, Ian Kelly wrote: >> On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk wrote: >>> What if it's not a list but a tuple or a numpy array? Often I just want to iterate through an element's items and I don't care if it's a list, set, etc. For instance, given this function definition -- >> >>> def print_items(an_iterable): >>> if not an_iterable: >>> print "The iterable is empty" >>> else: >>> for item in an_iterable: >>> print item >> >>> I get the output I want with all of these calls: >>> print_items( list() ) >>> print_items( tuple() ) >>> print_items( set() ) >>> print_items( numpy.array([]) ) >> >> But sadly it fails on iterators: >> print_items(xrange(0)) >> print_items(-x for x in []) >> print_items({}.iteritems()) > > My stab: > > from itertools import chain > > def print_it(iterable): > it = iter(iterable) > try: > head = next(it) > except StopIteration: > print 'Empty' > return > for el in chain( (head,), it ): > print el > > Not sure if I'm truly happy with that though. How about: def print_items(an_iterable): found_item = False for item in an_iterable: print item found_item = True if not found_item: print "The iterable was empty" -- HansM From nobody at nowhere.net.no Sat May 14 04:52:54 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 14 May 2011 16:52:54 +0800 Subject: how to install easy_install References: <9f994806-bb7e-4219-9d64-eb50890b4b68@18g2000prd.googlegroups.com> Message-ID: rusi wrote: > tried to install easy_install (This is on windows) > I downloaded the executable and ran it. It claimed to have done its > job. Perhaps, the abit to just click is disordering some easy steps like copy the script files into the normal place. Only when there's a particular copy then it's the time to pay attention, like some executable and/or framework. In the README.txt should mention these few easy steps -- goto /dev/null From nobody at nowhere.net.no Sat May 14 05:02:48 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 14 May 2011 17:02:48 +0800 Subject: Converting a set into list Message-ID: Hello I've stumble to find a solution to get a list from a set >>> aa= ['a','b','c','f'] >>> aa ['a', 'b', 'c', 'f'] >>> set(aa) {'a', 'c', 'b', 'f'} >>> [k for k in aa] ['a', 'b', 'c', 'f'] I repute the comprehension list too expensive, is there another method? -- goto /dev/null From vanboxem.ruben at gmail.com Sat May 14 05:09:13 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Sat, 14 May 2011 11:09:13 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: 2011/5/14 Doug Evans : > On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem > wrote: >> (now in plain-text as required by gdb mailing list) >> >> Hi, >> >> I am currently trying to integrate Python support into my toolchain >> build (including GDB of course). It is a sysrooted >> binutils+GCC+GDB+mingw-w64 toolchain. >> >> I currently have the basic setup working: I can link gdb with my >> manually generated import lib to the python dll from the official >> Windows install. If there is anything I am missing or a very easy >> solution to the problems decsribed below, please just say so. I am >> only suggesting what I would like to happen. >> >> Now on to the problems I'd like to discuss: >> >> 1. gdb.exe won't start without me having set PYTHONPATH manually. > > In a properly configured/built gdb on linux this isn't necessary, even > if python is installed in some random place. > I'm not sure about windows though. > Did you specify --with-python when you configured gdb, and if so did > you specify a value? > e.g., --with-python=SOME_VALUE I was cross-compiling a mingw toolchain+gdb from Linux, so I used --with-python without a value (because gdb configure tries to find the Python executabe), and I added -I"/path/to/python/includes" to CFLAGS and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it should. This is hacky though, and gdb configure should provide --with-python-libs and --with-python-include to make it more streamlined with any other build prerequisite (like gmp/mpfr/mpc/cloog/ppl in GCC for example). > >> I understand the need for this, but as gdb requires Python 2, and users >> of my toolchain may have installed Python 3 or a 32-bit version python >> they want to use from the same environment (without changing their own >> PYTHONPATH), there is no way to run python-enabled gdb. >> [...] > > Yeah. > There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have > gdb use that instead of PYTHONPATH if it exists, but there's been > resistance to it. > I think(!) what would happen is that gdb would set $PYTHONPATH to the > value of $GDB_PYTHONPATH. > [Inferiors started by gdb should still get the original value of > PYTHONPATH though.] That way would be almost ideal, but a hardcoded *relative* path to the python scripts (that is standardized within gdb) wouldn't hurt. An extra environment variable would require a lot of explaining for Windows, and is not "plug-and-play", like the rest of a sysrooted toolchain is supposed to be like. I think this should work on all setups: 1. Check hardcoded path; my suggestion would be "/../lib/python27" 2. If this fails to find the necessary files/scripts, find it like you described above in Linux, without PYTHONPATH set. 3. Check PYTHONPATH. I would think only number one would change, and perhaps be only enabled with a special configure option. Nothing else would have to change, and Windows users would rejoice :) Again, this is only my suggestion, if there are problems with it in way I haven't thought of, please say so, and we can come up with another solution. > >> 2. With PYTHONPATH set as a temporary workaround, gdb starts, but >> spits out a traceback: >> Traceback (most recent call last): >> ? File "", line 35, in >> ? File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line >> 18, in >> ??? gdb.command.pretty_printers.register_pretty_printer_commands() >> ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", >> line 368, in register_pretty_printer_commands >> ??? InfoPrettyPrinter() >> ? File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", >> line 100, in __init__ >> ??? gdb.COMMAND_DATA) >> RuntimeError: Could not find command prefix info. >> >> This is a minor problem I think, as "python import time" "python print >> time.clock()" works as expected. What is wrong? > > I'm not sure. > The error message is complaining that the "info" command prefix doesn't exist. > I don't see how that can happen as python is initialized long after > the info command is created. > Thanks for the prompt response. From eliz at gnu.org Sat May 14 05:29:57 2011 From: eliz at gnu.org (Eli Zaretskii) Date: Sat, 14 May 2011 12:29:57 +0300 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: <83ei41fx4a.fsf@gnu.org> > Date: Sat, 14 May 2011 11:09:13 +0200 > From: Ruben Van Boxem > Cc: gdb at sourceware.org, python-list at python.org > > 1. Check hardcoded path; my suggestion would be "/../lib/python27" > 2. If this fails to find the necessary files/scripts, find it like you > described above in Linux, without PYTHONPATH set. > 3. Check PYTHONPATH. > > I would think only number one would change, and perhaps be only > enabled with a special configure option. Nothing else would have to > change, and Windows users would rejoice :) The problem, I think, is that it's not so easy on Unix to get the place where the GDB executable leaves. There isn't a system call to do that (similar to what Windows gives you). So I think on Posix platforms, number 2 would be used most of the time. From __peter__ at web.de Sat May 14 05:33:15 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 14 May 2011 11:33:15 +0200 Subject: Converting a set into list References: Message-ID: TheSaint wrote: > I've stumble to find a solution to get a list from a set > > > >>>> aa= ['a','b','c','f'] >>>> aa > ['a', 'b', 'c', 'f'] >>>> set(aa) To clarify: this creates a new object, so aa is still a list. > {'a', 'c', 'b', 'f'} >>>> [k for k in aa] > ['a', 'b', 'c', 'f'] So you are actually converting a list to a (new) list here. Of course it would have worked with a set or an arbitrary iterable, too. > > I repute the comprehension list too expensive, is there another method? mylist = list(myset) Do you notice the similarity to converting a list to a set? From vanboxem.ruben at gmail.com Sat May 14 06:10:03 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Sat, 14 May 2011 12:10:03 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: <83ei41fx4a.fsf@gnu.org> References: <83ei41fx4a.fsf@gnu.org> Message-ID: 2011/5/14 Eli Zaretskii : >> Date: Sat, 14 May 2011 11:09:13 +0200 >> From: Ruben Van Boxem >> Cc: gdb at sourceware.org, python-list at python.org >> >> 1. Check hardcoded path; my suggestion would be "/../lib/python27" >> 2. If this fails to find the necessary files/scripts, find it like you >> described above in Linux, without PYTHONPATH set. >> 3. Check PYTHONPATH. >> >> I would think only number one would change, and perhaps be only >> enabled with a special configure option. Nothing else would have to >> change, and Windows users would rejoice :) > > The problem, I think, is that it's not so easy on Unix to get the > place where the GDB executable leaves. ?There isn't a system call to > do that (similar to what Windows gives you). > > So I think on Posix platforms, number 2 would be used most of the > time. > I understand. So better/feasible would be: Windows: Check /../lib/python27 or any configure-time specified relative path to gdb executable? If that fails, revert to current behavoir. POSIX (so pretty much everythin else): Keep current behavior. Which would come down to a configure option+ a small block of #if _WIN32 code in the Python part of the code. Thanks, Ruben From dan.kluev at gmail.com Sat May 14 06:16:02 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sat, 14 May 2011 21:16:02 +1100 Subject: How best to convert a string "list" to a python list In-Reply-To: References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: On Sat, May 14, 2011 at 7:41 PM, Nobody wrote: > to use a regular expression to match everything up to the next delimiter, > and do this in a loop to extract the individual items. re.findall() should let you match all items at once, without loop. -- With best regards, Daniel Kluev From wxjmfauth at gmail.com Sat May 14 06:26:26 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Sat, 14 May 2011 03:26:26 -0700 (PDT) Subject: unicode by default References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: On 14 mai, 09:41, harrismh777 wrote: > ... > I'm getting much closer here, > ... You should really understand, that Unicode is a domain per se. It is independent from any os's, programming languages or applications. It is up to these tools to be "unicode" compliant. Working in a full unicode mode (at least for texts) is today practically a solved problem. But you have to ensure the whole toolchain is unicode compliant (editors, fonts (OpenType technology), rendering devices, ...). Tip. This list is certainly not the best place to grab informations. I suggest you start by getting informations about XeTeX. XeTeX is the "new" TeX engine working only in a unicode mode. From this starting point, you will fall on plenty web sites speaking about the "unicode world", tools, fonts, ... A variant is to visit sites speaking about *typography*. jmf From chrispaton2005 at gmail.com Sat May 14 07:48:31 2011 From: chrispaton2005 at gmail.com (Chris Paton) Date: Sat, 14 May 2011 12:48:31 +0100 Subject: Having a problem getting python working... Message-ID: <6E09A0F4-B9A6-4C9F-874B-CB6E21EF7A45@gmail.com> Hey all, Not sure if this is the right place to put this (forgive me for my ignorance, I'm looking everywhere!). I'm having a problem getting IDLE working. I'm working off Mac OSX 10.6.7 with Python 3.2 installed and I installed Activetcl 8.5.9 as recommended. IDLE is still crashing at random moments - loading, saving, typing, compiling... I tried to do a simple 'hello world' but it kept crashing. There's no official report; I just get the spinning beach ball then have to force quit. I'm quite new to all of this so any help would be extremely appreciated. Need to get into this ASAP as I need to do some stuff for my thesis project! Thanks! Chris From highfellow at gmail.com Sat May 14 09:12:44 2011 From: highfellow at gmail.com (Andy Baxter) Date: Sat, 14 May 2011 14:12:44 +0100 Subject: threads with gtk gui problem Message-ID: <4DCE7FCC.8020907@gmail.com> Hi, I'm working on adding a Gtk GUI to a python program. Its main function is to read raw data from an arduino board over USB, and convert it to MIDI note/controller events to be sent to another program. I've had it working fine with just a command line interface, but when I replaced the command line with a Gtk interface, I started having problems getting the thread that reads the USB port to run. I'm not sure what the custom is on this list for pasting code - It's a long program so I don't want to paste the whole thing. The sequence of events I've coded is: - the program starts. - the port reader thread (which is a threading.Thread subclass) is initialised. - the object which controls the interface is initialised (i.e. the glade file is loaded.) - the port reader is started (i.e. the 'start' method is called, which calls the 'run' method in a thread). - then the gtk main loop is run. The behaviour I'm getting is that the port reader either fails to start, or stops running at the point where it tries to initialise the serial port. It then does nothing until I close the main window, at which point it starts running again. The port reader's run method begins like this: # the method called by the thread superclass to run the main loop of the thread. def run(self): # main loop of thread. print "Starting port reader." fhan=serial.Serial(port=keeper.config['usbPort'], baudrate=keeper.config['usbBaud'], timeout=0.1) print "1" fhan.open() print "2" seq=PySeq() # the sequencer library object port=seq.createOutPort(keeper.config['midiPortName']) # make a midi out port. midich=keeper.config['midich'] print "3" while True: inbuf=[] print ".", char=fhan.read(1) if self.quit: fhan.close() return if len(char)==0: continue ... (code to process the character read in) ('keeper' is a global object which stores the config data and references to a few key objects). When you start the program, the thread stops either before the first print statement, or on the line which initialises the serial port ( fhan=serial.Serial(...) ). '1', '2', and '3' only get printed /after/ you close the gtk main window. Can anyone help with this? cheers, andy baxter -- http://highfellow.org From rosuav at gmail.com Sat May 14 09:42:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 May 2011 23:42:45 +1000 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 14, 2011 at 5:45 PM, rusi wrote: > And then we get the interesting result that > (True = True) is False How does this work? In Python, the = sign is illegal there, and if you mean True == True, then it's True (obviously), which is not False. Chris Angelico From ben+python at benfinney.id.au Sat May 14 10:12:31 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 May 2011 00:12:31 +1000 Subject: Converting a set into list References: Message-ID: <87iptdid68.fsf@benfinney.id.au> TheSaint writes: > Hello > > I've stumble to find a solution to get a list from a set > > > > >>> aa= ['a','b','c','f'] Creates a new list object. Binds the name ?aa? to that object. > >>> aa > ['a', 'b', 'c', 'f'] Evaluates the object referenced by the name ?aa?. > >>> set(aa) > {'a', 'c', 'b', 'f'} Creates a new set object, populating it with the contents from the list object referenced by ?aa?. Doesn't do anything with the new set object, which will soon be garbage-collected. > >>> [k for k in aa] > ['a', 'b', 'c', 'f'] Creates a new list object by iterating each of the items from the list referenced by ?aa?. Does nothing with the new list object, which will soon be garbage-collected. > > I repute the comprehension list too expensive, is there another method? Another method to do what? If you want to bind ?aa? to a new object, do so with an assignment statement. (Your example has exactly one assignment statement; all the other statements create objects which are never bound to anything.) But what is it you actually want to do? -- \ ?The fact that I have no remedy for all the sorrows of the | `\ world is no reason for my accepting yours. It simply supports | _o__) the strong probability that yours is a fake.? ?Henry L. Mencken | Ben Finney From nobody at nowhere.net.no Sat May 14 10:14:40 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 14 May 2011 22:14:40 +0800 Subject: Converting a set into list References: Message-ID: Peter Otten wrote: > mylist = list(myset) > Do you notice the similarity to converting a list to a set? > There was something confusing me yesterday in doing that, but (for me strangely) I got cleared out. The point was that after a result from: newset= set(myset1) & set(myset2) list= [newset] << [{'bla', 'alb', 'lab'}] Probably list(set) is not like [set]. -- goto /dev/null From drobinow at gmail.com Sat May 14 10:28:07 2011 From: drobinow at gmail.com (David Robinow) Date: Sat, 14 May 2011 10:28:07 -0400 Subject: checking if a list is empty In-Reply-To: <93682bFq0fU2@mid.individual.net> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <93682bFq0fU2@mid.individual.net> Message-ID: On Fri, May 13, 2011 at 10:34 PM, Gregory Ewing wrote: > rusi wrote: > >> Dijkstra's problem (paraphrased) is that python, by choosing the >> FORTRAN alternative of having a non-first-class boolean type, hinders >> scientific/mathematical thinking/progress. > > Python doesn't have the flaw that Dijkstra was talking about. > Fortran's flaw wasn't so much the lack of a boolean type, but > that you couldn't assign the result of a logical expression to > a variable. Python has always been able to do that, even before > it had a distinct boolean type. And Fortran could do it at least 25 years before Python was invented. From nobody at nowhere.net.no Sat May 14 10:51:30 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 14 May 2011 22:51:30 +0800 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Another method to do what? > Sorry, some time we expect to have said it as we thought it. The example was to show that after having made a set set(aa) the need to get that set converted into a list. My knowledge drove me to use a comprehension list as a converter. In another post I got to know the simplest way to state list(aa) Where aa is a set. -- goto /dev/null From roy at panix.com Sat May 14 11:04:15 2011 From: roy at panix.com (Roy Smith) Date: Sat, 14 May 2011 11:04:15 -0400 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <93682bFq0fU2@mid.individual.net> Message-ID: In article , David Robinow wrote: > On Fri, May 13, 2011 at 10:34 PM, Gregory Ewing > wrote: > > rusi wrote: > > > >> Dijkstra's problem (paraphrased) is that python, by choosing the > >> FORTRAN alternative of having a non-first-class boolean type, hinders > >> scientific/mathematical thinking/progress. > > > > Python doesn't have the flaw that Dijkstra was talking about. > > Fortran's flaw wasn't so much the lack of a boolean type, but > > that you couldn't assign the result of a logical expression to > > a variable. Python has always been able to do that, even before > > it had a distinct boolean type. > And Fortran could do it at least 25 years before Python was invented. I vaguely remember that Fortran called the data type LOGICAL, but yes, it was exactly what most modern languages call a bool or boolean. And the operators were spelled .NOT., .AND., .OR., etc but that's because Fortran was designed for punch cards, which didn't have much in the way of special characters. From cesium5500 at yahoo.ca Sat May 14 11:11:36 2011 From: cesium5500 at yahoo.ca (cesium5500 at yahoo.ca) Date: Sat, 14 May 2011 11:11:36 -0400 Subject: Question about available python lib for a task Message-ID: <4DCE9BA8.6030509@yahoo.ca> Hello, I would like to build a database of all the MS-Excel file on a LAN. I would like to get the files metadata : filename, summary, location, size, etc. Is there a dedicated python lib for the task? Is pywin32 one of the possible lib available? I would prefer to not building everything from scratch testing, etc. ETL software could also is a solution maybe... Thanks From rustompmody at gmail.com Sat May 14 11:47:41 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 08:47:41 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 14, 6:42?pm, Chris Angelico wrote: > On Sat, May 14, 2011 at 5:45 PM, rusi wrote: > > And then we get the interesting result that > > (True = True) is False > > How does this work? In Python, the = sign is illegal there, and if you > mean True == True, then it's True (obviously), which is not False. > > Chris Angelico 1. = vs == Ok to be true to python syntax I should have said (True == True) is False. But then the question arises, is the is a python is or an English is? If its python then that's fine but its just bland code with no discussion about it. To say something about it (in English) one would have to say (True == True) is False is True (where the first is is a python is and the second an English one). 2. True == True is (obviously) True Here is the quote (with internal quote from Dijkstra) from Steven that I was answering: ------------------------------ [Dijkstra quote] All this changed with the introduction of the two-element boolean domain {true, false} which provides the vocabulary needed to assign values to boolean expressions: 3<4 is a way for writing true, 3>4 is a way for writing false, whereas the value of x>0 depends on the value of x ... [end quote] [Steven quote] In Python, [1, 2, 3] is another way of writing true, and [] is another way of writing false. Similarly with any other arbitrary objects. The only things that bools True and False are good for are: [end Steven quote] ------------------------ So since [1,2,3] is one way of writing True (lets call it True3) and [1,2] is another (call it True2) then we have True3 == True2 is False But since according to Steven (according to Python?) True3 *is the same* as True2 we get False = [1,2,3] == [1,2] = True3 == True2 = True == True = True From rosuav at gmail.com Sat May 14 11:55:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 May 2011 01:55:34 +1000 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 15, 2011 at 1:47 AM, rusi wrote: > So since > [1,2,3] is one way of writing True (lets call it True3) > and [1,2] is another (call it True2) > then we have True3 == True2 is False > > But since according to Steven (according to Python?) True3 *is the > same* as True2 > we get > ?False > = [1,2,3] == [1,2] > = True3 ?== True2 > = True == True > = True Okay, I see what you're doing here. http://www.rinkworks.com/ithink/search.cgi?words=compress When you condense a whole lot of information down to just two states, True and False, *obviously* there'll be a huge amount that fits into one or the other without being identical. It's not an argument for whether [1,2,3] ought to be True or ought to be False. You could make the exact same argument if they evaluated to False. You have proven nothing and just wasted your time proving it. Chris Angelico From nobody at nowhere.net.no Sat May 14 11:55:45 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 14 May 2011 23:55:45 +0800 Subject: Trace in a class Message-ID: Hello, first of all, I'm a dummy in programming. My methods are just do-it-and-try- it. For more convinience I commonly using and go with step-into and breakpoints. Lately I was setting a class, but it's incomplete and just calling it at the pdb prompt line I can't use breakpoints or stop it to check what values are coming into the play. BTW, would it be much difference to use the class functions outside the class. I mean I don't declare the class statement just leave funtions alone in the module. -- goto /dev/null From hujun.work at gmail.com Sat May 14 12:02:59 2011 From: hujun.work at gmail.com (Jun Hu) Date: Sat, 14 May 2011 09:02:59 -0700 Subject: Get IP address of WIFI interface In-Reply-To: References: Message-ID: Thanks, is there any other way without using external command? On Fri, May 13, 2011 at 10:41 PM, Ishwor Gurung wrote: > Hi. > > On 14 May 2011 14:46, Far.Runner wrote: > > Hi Python Experts: > > There are two network interfaces on my laptop, one is > > 100M Ethernet interface, the other is wifi interface, both are connected > and > > has an IP address. then the question is: how to get the ip address of the > > wifi interface in a python script? > > OS: Windows or Linux > > Detect the OS with os.name and branch out to specific use case. > > The specific functionality can be implemented 2 ways: > 1/ Regular expression pattern match > 2/ Substring match and splits > > The subprocess module will then let you run those commands. > 1/ posix - (Linux in your case) will use ifconfig > 2/ nt - (windows in your ase) will use ipconfig. > > HTH. > > > > -- > > Regards > Ishwor Gurung > Key id:0xa98db35e > Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Sat May 14 13:24:13 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 10:24:13 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> Message-ID: <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> On May 14, 2:48?am, Mark Dickinson wrote: > I don't see this (or Hans' version) as cheating at all. Yeah sure -- cheating is a strong word :-) > This really *is* the power algorithm, just in a different number system from the > usual one. Yes that was my point. If we take the standard logarithmic power algo as trivial (in the sense that it is well known) then all these solutions do heavy-lifting to transform fib to power and then use the 'trivial' algo. A more direct approach would be to use the identities: f_2n = f_n ^ 2 + 2*f_n * f_(n-1) f_(2n-1) = f_n ^ 2 + f_(n-1) ^ 2 The naive python implementation of which is: def even(n): return n % 2 == 0 def sq(x): return x * x def fib(n): if n==1 or n==2: return 1 elif even(n): return sq(fib (n//2)) + 2 * fib(n//2) * fib(n//2 - 1) else: return sq(fib (n//2 + 1)) + sq(fib(n // 2)) This is a strange algo -- logarithmic because it halves the n, exponential because of the double (triple) calls. [I cannot say I know how to work out its exact complexity but I would guess its about linear] -------------- BTW How do I parse "the ring Z[x] / (x^2 - x - 1)"? Is this a division ring? From rustompmody at gmail.com Sat May 14 13:43:31 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 10:43:31 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <311327ac-2593-44d7-b19d-32533af87d4b@x38g2000pri.googlegroups.com> On May 14, 8:55?pm, Chris Angelico wrote: > On Sun, May 15, 2011 at 1:47 AM, rusi wrote: > > So since > > [1,2,3] is one way of writing True (lets call it True3) > > and [1,2] is another (call it True2) > > then we have True3 == True2 is False > > > But since according to Steven (according to Python?) True3 *is the > > same* as True2 > > we get > > ?False > > = [1,2,3] == [1,2] > > = True3 ?== True2 > > = True == True > > = True > > Okay, I see what you're doing here. > > http://www.rinkworks.com/ithink/search.cgi?words=compress LOL -- Thanks for that. But it seems you did not get the moral? Spelt out: "Beware of lossy compression!" [Which is also the moral of my 'proof'] > > When you condense a whole lot of information down to just two states, > True and False, *obviously* there'll be a huge amount that fits into > one or the other without being identical. It's not an argument for > whether [1,2,3] ought to be True or ought to be False. You could make > the exact same argument if they evaluated to False. You have proven > nothing and just wasted your time proving it. > > Chris Angelico From rosuav at gmail.com Sat May 14 14:22:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 May 2011 04:22:33 +1000 Subject: Converting a set into list In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 12:14 AM, TheSaint wrote: > newset= set(myset1) & set(myset2) > list= [newset] > > << [{'bla', 'alb', 'lab'}] > > Probably list(set) is not like [set]. list(set) creates a list out of the set. [set] creates a list with one element, the set itself. It's not a copy of the set, it's another reference to the same set; change one and you'll see the change in the other. Chris Angelico From dje at google.com Sat May 14 14:30:55 2011 From: dje at google.com (Doug Evans) Date: Sat, 14 May 2011 11:30:55 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem wrote: > 2011/5/14 Doug Evans : >> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem >> wrote: >>> (now in plain-text as required by gdb mailing list) >>> >>> Hi, >>> >>> I am currently trying to integrate Python support into my toolchain >>> build (including GDB of course). It is a sysrooted >>> binutils+GCC+GDB+mingw-w64 toolchain. >>> >>> I currently have the basic setup working: I can link gdb with my >>> manually generated import lib to the python dll from the official >>> Windows install. If there is anything I am missing or a very easy >>> solution to the problems decsribed below, please just say so. I am >>> only suggesting what I would like to happen. >>> >>> Now on to the problems I'd like to discuss: >>> >>> 1. gdb.exe won't start without me having set PYTHONPATH manually. >> >> In a properly configured/built gdb on linux this isn't necessary, even >> if python is installed in some random place. >> I'm not sure about windows though. >> Did you specify --with-python when you configured gdb, and if so did >> you specify a value? >> e.g., --with-python=SOME_VALUE > > I was cross-compiling a mingw toolchain+gdb from Linux, so I used > --with-python without a value (because gdb configure tries to find the > Python executabe), and I added -I"/path/to/python/includes" to CFLAGS > and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it > should. This is hacky though, and gdb configure should provide > --with-python-libs and --with-python-include to make it more > streamlined with any other build prerequisite (like > gmp/mpfr/mpc/cloog/ppl in GCC for example). Ah. Cross-compiling gdb with python is in need of improvement. Alas python hasn't been designed with cross-compilation in mind (e.g. build on linux, run on windows). AIUI, the way to get the parameters required for compiling with libpython is to get them from python's "distutils": kinda hard to do in a cross-compile. Done correctly there's no need to run python. I haven't done anything more to support python in gdb's configure.ac because it's not clear to me what the right thing to do is: distutils provides more than just --libs and --includes (btw, we don't use --libs though, we use --ldflags which includes all of: the directory in which to find libpython, the -l for libpython, and the -l's for all the other libraries python needs). [Which isn't to say that someone else isn't free to tackle this.] In the meantime, what I've been doing is a hack: write a script that responds to: --includes --ldflags --exec-prefix and pass that as --with-python. E.g. bash$ cat $HOME/my-python-for-config #! /bin/sh if [ $# -ne 2 ] then echo "Bad # args. Blech!" >&2 exit 1 fi # The first argument is the path to python-config.py, ignore it. case "$2" in --includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;; --ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm -lpython2.6" ;; --exec-prefix) echo "/usr" ;; *) echo "Bad arg $2. Blech!" >&2 ; exit 1 ;; esac exit 0 bash$ ./configure --with-python=$HOME/my-python-for-config [...] [...] Note that --exec-prefix is the runtime location of python. GCC uses this to tell libpython where to find its support files. [grep for Py_SetProgramName in gdb/python/python.c] >>> I understand the need for this, but as gdb requires Python 2, and users >>> of my toolchain may have installed Python 3 or a 32-bit version python >>> they want to use from the same environment (without changing their own >>> PYTHONPATH), there is no way to run python-enabled gdb. >>> [...] >> >> Yeah. >> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have >> gdb use that instead of PYTHONPATH if it exists, but there's been >> resistance to it. >> I think(!) what would happen is that gdb would set $PYTHONPATH to the >> value of $GDB_PYTHONPATH. >> [Inferiors started by gdb should still get the original value of >> PYTHONPATH though.] > > That way would be almost ideal, but a hardcoded *relative* path to the > python scripts (that is standardized within gdb) wouldn't hurt. See above re: --exec-prefix. > An > extra environment variable would require a lot of explaining for > Windows, and is not "plug-and-play", like the rest of a sysrooted > toolchain is supposed to be like. I think this should work on all > setups: > > 1. Check hardcoded path; my suggestion would be " executable>/../lib/python27" > 2. If this fails to find the necessary files/scripts, find it like you > described above in Linux, without PYTHONPATH set. > 3. Check PYTHONPATH. The problem being solved by the proposed GDB_PYTHONPATH is "What if the user has PYTHONPATH set and it points to an incompatible version of python?". Leaving such a value for PYTHONPATH set while gdb's python is running feels wrong (and IIRC has caused some problems). The problem of telling python where to find itself is already solved (or at least is intended to be solved) with gdb's calling Py_SetProgramName with a value derived from the python-provided --exec-prefix. > I would think only number one would change, and perhaps be only > enabled with a special configure option. Nothing else would have to > change, and Windows users would rejoice :) > Again, this is only my suggestion, if there are problems with it in > way I haven't thought of, please say so, and we can come up with > another solution. From dje at google.com Sat May 14 14:38:16 2011 From: dje at google.com (Doug Evans) Date: Sat, 14 May 2011 11:38:16 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: <83ei41fx4a.fsf@gnu.org> References: <83ei41fx4a.fsf@gnu.org> Message-ID: On Sat, May 14, 2011 at 2:29 AM, Eli Zaretskii wrote: >> Date: Sat, 14 May 2011 11:09:13 +0200 >> From: Ruben Van Boxem >> Cc: gdb at sourceware.org, python-list at python.org >> >> 1. Check hardcoded path; my suggestion would be "/../lib/python27" >> 2. If this fails to find the necessary files/scripts, find it like you >> described above in Linux, without PYTHONPATH set. >> 3. Check PYTHONPATH. >> >> I would think only number one would change, and perhaps be only >> enabled with a special configure option. Nothing else would have to >> change, and Windows users would rejoice :) > > The problem, I think, is that it's not so easy on Unix to get the > place where the GDB executable leaves. ?There isn't a system call to > do that (similar to what Windows gives you). > > So I think on Posix platforms, number 2 would be used most of the > time. For reference sake, gdb is "relocatable". [meaning, if you take a gdb installation and move it, it should continue to work fine] And if gdb's python lives inside the gdb tree, that too should continue to work fine if moved with gdb (the value to pass to Py_SetProgramName is appropriately (re-)computed when gdb is run). [For completeness sake, IIRC the calculation of a path being "relocatable" isn't bulletproof, but it works in practice.] It's not impossible for gdb to find where it lives, but you're right it can be moderately difficult (basically, if argv[0] isn't an absolute path then scan $PATH for it). From andy at earthsong.free-online.co.uk Sat May 14 14:39:44 2011 From: andy at earthsong.free-online.co.uk (andy baxter) Date: Sat, 14 May 2011 19:39:44 +0100 Subject: threads with gtk gui problem In-Reply-To: <4DCE7FCC.8020907@gmail.com> References: <4DCE7FCC.8020907@gmail.com> Message-ID: <4DCECC70.5020703@earthsong.free-online.co.uk> On 14/05/11 14:12, Andy Baxter wrote: > Hi, > > I'm working on adding a Gtk GUI to a python program. Its main function > is to read raw data from an arduino board over USB, and convert it to > MIDI note/controller events to be sent to another program. I've had it > working fine with just a command line interface, but when I replaced > the command line with a Gtk interface, I started having problems > getting the thread that reads the USB port to run. > > I'm not sure what the custom is on this list for pasting code - It's a > long program so I don't want to paste the whole thing. > > The sequence of events I've coded is: > > - the program starts. > - the port reader thread (which is a threading.Thread subclass) is > initialised. > - the object which controls the interface is initialised (i.e. the > glade file is loaded.) > - the port reader is started (i.e. the 'start' method is called, which > calls the 'run' method in a thread). > - then the gtk main loop is run. > > The behaviour I'm getting is that the port reader either fails to > start, or stops running at the point where it tries to initialise the > serial port. It then does nothing until I close the main window, at > which point it starts running again. > > The port reader's run method begins like this: > > # the method called by the thread superclass to run the main loop > of the thread. > def run(self): > # main loop of thread. > print "Starting port reader." > fhan=serial.Serial(port=keeper.config['usbPort'], > baudrate=keeper.config['usbBaud'], timeout=0.1) > print "1" > fhan.open() > print "2" > seq=PySeq() # the sequencer library object > port=seq.createOutPort(keeper.config['midiPortName']) # make a > midi out port. > midich=keeper.config['midich'] > print "3" > while True: > inbuf=[] > print ".", > char=fhan.read(1) > if self.quit: > fhan.close() > return > if len(char)==0: continue > ... (code to process the character read in) > > ('keeper' is a global object which stores the config data and > references to a few key objects). > > When you start the program, the thread stops either before the first > print statement, or on the line which initialises the serial port ( > fhan=serial.Serial(...) ). '1', '2', and '3' only get printed /after/ > you close the gtk main window. > I've verified that the problem is due to the gtk main loop interfering with the thread I've started. If I use this code: if __name__ == "__main__": print "Starting mapper" keeper=Keeper() # initialise the keeper. (A global object which holds references to key objects) keeper.start() # tell the keeper to start the port reader. for n in xrange(10): # wait for 10 seconds. time.sleep(1) print "x" #gtk.main() # start the gtk main loop. keeper.stop() # tell the keeper to shut things down. the program runs correctly. I.e. values are read from the usb port when they come in. if I use this code: if __name__ == "__main__": print "Starting mapper" keeper=Keeper() # initialise the keeper. (A global object which holds references to key objects) keeper.start() # tell the keeper to start the port reader. #for n in xrange(10): # time.sleep(1) # print "x" gtk.main() # start the gtk main loop. keeper.stop() # tell the keeper to shut things down. The port reader thread blocks at the point it tries to open the serial port. I.e. 'Starting port reader' is printed straight away, but '1', '2', and '3' are only printed after you close the gtk main window. From dje at google.com Sat May 14 14:40:15 2011 From: dje at google.com (Doug Evans) Date: Sat, 14 May 2011 11:40:15 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: On Sat, May 14, 2011 at 11:30 AM, Doug Evans wrote: > Note that --exec-prefix is the runtime location of python. > GCC uses this to tell libpython where to find its support files. > [grep for Py_SetProgramName in gdb/python/python.c] Oops. s/GCC/GDB/ From andy at earthsong.free-online.co.uk Sat May 14 14:51:37 2011 From: andy at earthsong.free-online.co.uk (andy baxter) Date: Sat, 14 May 2011 19:51:37 +0100 Subject: threads with gtk gui problem In-Reply-To: <4DCE7FCC.8020907@gmail.com> References: <4DCE7FCC.8020907@gmail.com> Message-ID: <4DCECF39.5020701@earthsong.free-online.co.uk> On 14/05/11 14:12, Andy Baxter wrote: > Hi, > > I'm working on adding a Gtk GUI to a python program. Its main function > is to read raw data from an arduino board over USB, and convert it to > MIDI note/controller events to be sent to another program. I've had it > working fine with just a command line interface, but when I replaced > the command line with a Gtk interface, I started having problems > getting the thread that reads the USB port to run. I've solved this by adding 'import gobject' and 'gobject.threads_init()' to the start of the program. Looks like if you don't do this then the gtk main loop never releases the python threading lock to other threads. andy From tjreedy at udel.edu Sat May 14 15:58:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 15:58:28 -0400 Subject: turn monitor off and on In-Reply-To: References: Message-ID: On 5/14/2011 3:20 AM, harrismh777 wrote: > harrismh777 wrote: >> >> def turnOnMonitor(): >> SC_MONITORPOWER = 0xF170 >> win32gui.SendMessage(win32con.HWND_BROADCAST, >> win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > > I've never tried turning my monitor on/off without using my finger... The computer cannot turn off the monitor. It can only tell the graphics card to turnoff the signal to the monitor. My monitor then displays 'No signal detected' in a box and puts itself into a low-power state awaiting a signal. Even if the monitor does not do that, a black screen should use less power. Why the turnon does not work, if indeed it does not (and the monitor is not failing to respond to its resumption) is not a Python question. 2 and -1 as off and on parameters is a bit strange. The OP might try a different api reference source or ask on a windows innards list. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 14 15:59:33 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 15:59:33 -0400 Subject: How best to convert a string "list" to a python list In-Reply-To: References: <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com> Message-ID: On 5/14/2011 4:41 AM, Nobody wrote: > On Fri, 13 May 2011 10:15:29 -0700, noydb wrote: > >> I want some code to take the items in a semi-colon-delimted string "list" >> and places each in a python list. I came up with below. In the name of >> learning how to do things properly, do you experts have a better way of >> doing it? > >> x = "red;blue;green;yellow" ## string of semi-colon delimited colors > > Provided that a semicolon is *always* a delimiter, just use the .split() > method: > > color_list = x.split(";") > > For more complex formats, where there are quote and/or escape characters > which allow the delimiter to occur as part of an item, you typically need > to use a regular expression to match everything up to the next delimiter, > and do this in a loop to extract the individual items. Or, for some formats, use the cvs module. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 14 16:26:53 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 16:26:53 -0400 Subject: unicode by default In-Reply-To: References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: On 5/14/2011 3:41 AM, harrismh777 wrote: > Terry Reedy wrote: >> Easy, practical use of unicode is still a work in progress. > > Apparently... the good news for me is that SBL provides their unicode > font here: > > http://www.sbl-site.org/educational/biblicalfonts.aspx > > I'm getting much closer here, but now the problem is typing. The pain > with unicode fonts is that the glyph is tied to the code point for the > represented character, and not tied to any code point that matches any > keyboard scan code for typing. :-} > > So, I can now see the ancient text with accents and aparatus in all of > my editors, but I still cannot type any ancient Greek with my > keyboard... because I have to make up a keymap first. > > I don't find that SBL (nor Logos Software) has provided keymaps as > yet... rats. You need what is called, at least with Windows, an IME -- Input Method Editor. These are part of (or associated with) the OS, so they can be used with *any* application that will accept unicode chars (in whatever encoding) rather than just ascii chars. Windows has about a hundred or so, including Greek. I do not know if that includes classical Greek with the extra marks. > I can read the test with Python though... yessss. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 14 16:31:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 16:31:30 -0400 Subject: Question about available python lib for a task In-Reply-To: <4DCE9BA8.6030509@yahoo.ca> References: <4DCE9BA8.6030509@yahoo.ca> Message-ID: On 5/14/2011 11:11 AM, cesium5500 at yahoo.ca wrote: > I would like to build a database of all the MS-Excel file on a LAN. I > would like to get the files metadata : filename, summary, location, > size, etc. You subject line is about a non-specific as can be, which means that the person who can answer would not know and would likely skip over it. Something like "Wanted: a module to catalog Excel files on a LAN" would grab attention better. > Is there a dedicated python lib for the task? Is pywin32 one of the > possible lib available? Sorry, I have no idea. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 14 16:53:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 16:53:39 -0400 Subject: checking if a list is empty In-Reply-To: <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/14/2011 3:39 AM, Steven D'Aprano wrote: > Th money-quote as regards using arbitrary objects in truth tests: > > [quote] > All this changed with the introduction of the two-element > boolean domain {true, false} which provides the vocabulary > needed to assign values to boolean expressions: 3<4 is a > way for writing true, 3>4 is a way for writing false, > whereas the value of x>0 depends on the value of x ... > [end quote] > > > In Python, [1, 2, 3] is another way of writing true, and [] is another > way of writing false. Similarly with any other arbitrary objects. Another way to look at it is that Python automatically calls bool() on every expression in its two boolean or conditional contexts: 'if e:' and 'while e'. This is a boilerplate-removing, labor-saving convenience. Python has many such conveniences. -- Terry Jan Reedy From tjreedy at udel.edu Sat May 14 16:59:40 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 16:59:40 -0400 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/14/2011 3:45 AM, rusi wrote: > (True = True) is False is a syntax error ;-) and 'True = True' is a (useless) statement, and statements do not have boolean values, and 'True == True' *is* True, which is to say, ((True == True) is False) is False. -- Terry Jan Reedy From ian.g.kelly at gmail.com Sat May 14 17:19:55 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 May 2011 15:19:55 -0600 Subject: Recursion or iteration (was Fibonacci series recursion error) In-Reply-To: <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> Message-ID: On Sat, May 14, 2011 at 11:24 AM, rusi wrote: > def fib(n): > ? ?if n==1 or n==2: > ? ? ? ?return 1 > ? ?elif even(n): > ? ? ? ?return sq(fib (n//2)) + 2 * fib(n//2) * fib(n//2 - 1) > ? ?else: > ? ? ? ?return sq(fib (n//2 + 1)) + sq(fib(n // 2)) > > This is a strange algo ?-- logarithmic because it halves the n, > exponential because of the double (triple) calls. ?[I cannot say I > know how to work out its exact complexity but I would guess its about > linear] Yup, linear. Assuming you optimize the even case so that it doesn't actually call fib(n//2) twice, the call tree can be approximated as a balanced binary tree with height log(n). The total number of nodes in the tree is thus O(2 ** log(n)) = O(n). From tjreedy at udel.edu Sat May 14 17:29:53 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2011 17:29:53 -0400 Subject: checking if a list is empty In-Reply-To: <311327ac-2593-44d7-b19d-32533af87d4b@x38g2000pri.googlegroups.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <311327ac-2593-44d7-b19d-32533af87d4b@x38g2000pri.googlegroups.com> Message-ID: On 5/14/2011 1:43 PM, rusi wrote: > But it seems you did not get the moral? Spelt out: "Beware of lossy > compression!" > [Which is also the moral of my 'proof'] I get it now. As I suggested in response to Stephen, [] and [1] spell False and True only in boolean contexts (if/while headers) where they are implicitly wrapped with a bool() call, which is to say, where their boolean value is extracted from them. As you point out, there is information loss as all other context-irrelevant details are ignored. -- Terry Jan Reedy From brenNOSPAMbarn at NObrenSPAMbarn.net Sat May 14 19:01:15 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 14 May 2011 23:01:15 +0000 (UTC) Subject: Python drawing library? Message-ID: Is there any Python library for interactive drawing? I've done some googling but most searches for "drawing" lead me to libraries for programmatic creation of shapes on some GUI canvas. I'm looking for GUI widgets that allow the user to draw with the mouse, like a paint program, and let me get info about the drawing as its made (get color at mouse location, etc.). I'd prefer a wxPython solution, although any Python solution would be better than none. Thanks, -- --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 ben+python at benfinney.id.au Sat May 14 19:21:38 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 May 2011 09:21:38 +1000 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> Message-ID: <871v00j2bh.fsf@benfinney.id.au> TheSaint writes: > The example was to show that after having made a set > > set(aa) > > the need to get that set converted into a list. As pointed out: you already know how to create a set from an object; creating a list from an object is very similar: list(set(aa)) But why are you doing that? What are you trying to achieve? -- \ ?We are all agreed that your theory is crazy. The question that | `\ divides us is whether it is crazy enough to have a chance of | _o__) being correct.? ?Niels Bohr (to Wolfgang Pauli), 1958 | Ben Finney From ben+python at benfinney.id.au Sat May 14 19:26:59 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 May 2011 09:26:59 +1000 Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wrhshni4.fsf@benfinney.id.au> rusi writes: > [Steven quote] > In Python, [1, 2, 3] is another way of writing true, and [] is another > way of writing false. Similarly with any other arbitrary objects. The > only things that bools True and False are good for are: > > [end Steven quote] > ------------------------ > > So since > [1,2,3] is one way of writing True (lets call it True3) No. Steven knew exactly why he was using ?true? versus ?True?. He's explained why elsewhere in this thread. The former does not refer to the Python boolean singleton, the latter does. The only object that is True is the True singleton. But there are many objects that are true. -- \ ?I got up the other day, and everything in my apartment has | `\ been stolen and replaced with an exact replica.? ?Steven Wright | _o__) | Ben Finney From ben+python at benfinney.id.au Sat May 14 19:47:05 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 May 2011 09:47:05 +1000 Subject: unicode by default References: <874o50k1eb.fsf@benfinney.id.au> <3ae7c960dc8cf622fcf95aa48ed9df40.squirrel@webmail.lexicon.net> <492f8500-fd53-4b52-bd7b-cd90a3118d38@k16g2000yqm.googlegroups.com> Message-ID: <87r580hmkm.fsf@benfinney.id.au> Terry Reedy writes: > You need what is called, at least with Windows, an IME -- Input Method > Editor. For a GNOME or KDE environment you want an input method framework; I recommend IBus which comes with the major GNU+Linux operating systems . Then you have a wide range of input methods available. Many of them are specific to local writing systems. For writing special characters in English text, I use either ?rfc1345? or ?latex? within IBus. That allows special characters to be typed into any program which communicates with the desktop environment's input routines. Yay, unified input of special characters! Except Emacs :-( which fortunately has ?ibus-el? available to work with IBus :-). -- \ ??????????| `\ (What is undesirable to you, do not do to others.) | _o__) ???? Confucius, 551 BCE ? 479 BCE | Ben Finney From see at sig.for.address Sat May 14 20:08:24 2011 From: see at sig.for.address (Victor Eijkhout) Date: Sat, 14 May 2011 19:08:24 -0500 Subject: I don't understand generator.send() Message-ID: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> #! /usr/bin/env python def ints(): i=0 while True: yield i i += 1 gen = ints() while True: i = gen.next() print i if i==5: r = gen.send(2) print "return:",r if i>10: break I thought the send call would push the value "2" at the front of the queue. Instead it coughs up the 2, which seems senseless to me. 1/ How should I view the send call? I'm reading the manual and dont' get it 2/ Is there a way to push something in the generator object? So that it becomes the next yield expression? In my code I was hoping to get 0,1,2,3,4,5,2,6,7 as yield expressions. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From harrismh777 at charter.net Sat May 14 20:25:39 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 14 May 2011 19:25:39 -0500 Subject: turn monitor off and on In-Reply-To: References: Message-ID: <74Fzp.572$ar1.165@newsfe08.iad> Terry Reedy wrote: > The computer cannot turn off the monitor. ... this was my point ;-) From brenNOSPAMbarn at NObrenSPAMbarn.net Sat May 14 20:38:47 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sun, 15 May 2011 00:38:47 +0000 (UTC) Subject: I don't understand generator.send() References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: Victor Eijkhout wrote: > #! /usr/bin/env python > > def ints(): > i=0 > while True: > yield i > i += 1 > > gen = ints() > while True: > i = gen.next() > print i > if i==5: > r = gen.send(2) > print "return:",r > if i>10: > break > > I thought the send call would push the value "2" at the front of > the queue. Instead it coughs up the 2, which seems senseless to me. > > 1/ How should I view the send call? I'm reading the manual and > dont' get it > 2/ Is there a way to push something in the generator object? So > that it becomes the next yield expression? In my code I was hoping > to get 0,1,2,3,4,5,2,6,7 as yield expressions. You can't usefully use send() unless the generator is set up to make use of the sent values. You can't just push values into any old generator. For it to do anything, you need to use assign the result of the yield to something within your generator and make use of it. See http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features for an example. -- --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 crebert at ucsd.edu Sat May 14 20:47:00 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Sat, 14 May 2011 17:47:00 -0700 Subject: I don't understand generator.send() In-Reply-To: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sat, May 14, 2011 at 5:08 PM, Victor Eijkhout wrote: > #! /usr/bin/env python > > def ints(): > ? ?i=0 > ? ?while True: > ? ? ? ?yield i > ? ? ? ?i += 1 > > gen = ints() > while True: > ? ?i = gen.next() > ? ?print i > ? ?if i==5: > ? ? ? ?r = gen.send(2) > ? ? ? ?print "return:",r > ? ?if i>10: > ? ? ? ?break > > I thought the send call would push the value "2" at the front of the > queue. Instead it coughs up the 2, which seems senseless to me. > > 1/ How should I view the send call? I'm reading the manual and dont' get > it `yield` is an expression. Within the generator, the result of that expression is [, ignoring the complications of .throw() etc.,] the argument to .send(). You're currently using `yield` only as a statement, so it's no wonder you're not quite understanding .send(). I think this example should clarify things somewhat: >>> def example(start): ... i = ord(start) ... while True: ... sent = (yield chr(i)) # Note use of yield as expression ... print('was sent', sent) ... i += 1 ... >>> g = example('a') >>> g.send(3) Traceback (most recent call last): File "", line 1, in TypeError: can't send non-None value to a just-started generator >>> # Ok, so we can't send something back to `yield` >>> # until we hit the first `yield`. >>> g.send(None) # Follow the error message's advice 'a' >>> g.send(3) # Let's try again now. was sent 3 'b' >>> g.send(5) was sent 5 'c' >>> g.send(9) was sent 9 'd' >>> Cheers, Chris -- http://rebertia.com From rosuav at gmail.com Sat May 14 20:47:09 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 May 2011 10:47:09 +1000 Subject: I don't understand generator.send() In-Reply-To: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sun, May 15, 2011 at 10:08 AM, Victor Eijkhout wrote: > ? ? ? ?yield i > ? ? ? ?r = gen.send(2) When you send() something to a generator, it becomes the return value of the yield expression. See the example here: http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features For what you're doing, there's a little complexity. If I understand, you want send() to be like an ungetc call... you could do that like this: def ints(): i=0 while True: sent=(yield i) if sent is not None: yield None # This becomes the return value from gen.send() yield sent # This is the next value yielded i += 1 This lets you insert at most one value per iteration. Supporting more than one insertion is more complicated, but changing the loop structure entirely may help: def ints(): i=0 queue=[] while True: if queue: # see other thread, this IS legal and pythonic and quite sensible sent=(yield queue.pop(0)) else: sent=(yield i) i+=1 if sent is not None: yield None # This is the return value from gen.send() queue.append(sent) With this generator, you maintain a queue of sent values (if you want it to be a LIFO stack rather than a FIFO queue, just change the pop(0) to just pop()), and if the queue's empty, it produces sequential integers. (Incidentally, the sent values don't have to be integers. I leave it to you to decide whether that's any use or not.) Hope that helps! Chris Angelico From ian.g.kelly at gmail.com Sat May 14 20:57:56 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 May 2011 18:57:56 -0600 Subject: I don't understand generator.send() In-Reply-To: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sat, May 14, 2011 at 6:08 PM, Victor Eijkhout wrote: > I thought the send call would push the value "2" at the front of the > queue. Instead it coughs up the 2, which seems senseless to me. > > 1/ How should I view the send call? I'm reading the manual and dont' get > it There is no queue unless you create one inside the generator. The generator by itself behaves more like a coroutine. > 2/ Is there a way to push something in the generator object? So that it > becomes the next yield expression? In my code I was hoping to get > 0,1,2,3,4,5,2,6,7 as yield expressions. This will do what you're asking for: def ints(): i=0 while True: next_yield = (yield i) while next_yield is not None: next_yield = (yield next_yield) i += 1 However, I don't think this is what you want. The send call returns a yield expression, which will then be the value that you just passed in, which seems a bit silly. Probably you want something more like this: def ints(): i=0 while True: next_yield = (yield i) while next_yield is not None: yield None next_yield = (yield next_yield) i += 1 Then the send() call will return None, and the next next() call will return the value you passed in. Note though that this is too simple to work correctly if you call send() more than once before calling next() again. In general, I think it is a bad idea to mix calling next() and send() on the same generator. It makes the generator logic too complicated, and I think it's better just to create a stateful iterator class instead, where send() and next() are two entirely separate methods. Cheers, Ian From ian.g.kelly at gmail.com Sat May 14 21:05:27 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 May 2011 19:05:27 -0600 Subject: I don't understand generator.send() In-Reply-To: References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sat, May 14, 2011 at 6:47 PM, Chris Angelico wrote: > def ints(): > ? ?i=0 > ? ?queue=[] > ? ?while True: > ? ? ? ?if queue: ?# see other thread, this IS legal and pythonic and > quite sensible > ? ? ? ? ? ?sent=(yield queue.pop(0)) > ? ? ? ?else: > ? ? ? ? ? ?sent=(yield i) > ? ? ? ? ? ?i+=1 > ? ? ? ?if sent is not None: > ? ? ? ? ? ?yield None ?# This is the return value from gen.send() > ? ? ? ? ? ?queue.append(sent) > > With this generator, you maintain a queue of sent values (if you want > it to be a LIFO stack rather than a FIFO queue, just change the pop(0) > to just pop()), and if the queue's empty, it produces sequential > integers. (Incidentally, the sent values don't have to be integers. I > leave it to you to decide whether that's any use or not.) Actually, this won't work, because the value of the "yield None" gets ignored. Thus if you try to call send() twice in a row, the generator the treats second send() as if it were a next(), and it is not possible to have more than one item in the queue. From rosuav at gmail.com Sat May 14 21:17:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 May 2011 11:17:31 +1000 Subject: I don't understand generator.send() In-Reply-To: References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sun, May 15, 2011 at 11:05 AM, Ian Kelly wrote: > Actually, this won't work, because the value of the "yield None" gets > ignored. ?Thus if you try to call send() twice in a row, the generator > the treats second send() as if it were a next(), and it is not > possible to have more than one item in the queue. You're right. It needs a while loop instead of the if (and some slight reordering): def ints(): i=0 queue=[] while True: if queue: # see other thread, this IS legal and pythonic and quite sensible sent=(yield queue.pop(0)) else: sent=(yield i) i+=1 while sent is not None: queue.append(sent) sent=(yield None) # This is the return value from gen.send() That should work. Chris Angelico From see at sig.for.address Sat May 14 21:40:22 2011 From: see at sig.for.address (Victor Eijkhout) Date: Sat, 14 May 2011 20:40:22 -0500 Subject: I don't understand generator.send() References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: <1k19yop.1np9xao1gbclj4N%see@sig.for.address> Chris Angelico wrote: > For what you're doing, there's a little complexity. If I understand, > you want send() to be like an ungetc call... you could do that like > this: > > > def ints(): > i=0 > while True: > sent=(yield i) > if sent is not None: > yield None # This becomes the return value from gen.send() > yield sent # This is the next value yielded > i += 1 I think this will serve my purposes. Thanks everyone for broadening my understanding of generators. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From nospam at torek.net Sat May 14 22:11:11 2011 From: nospam at torek.net (Chris Torek) Date: 15 May 2011 02:11:11 GMT Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Message-ID: In article <871v00j2bh.fsf at benfinney.id.au> Ben Finney wrote: >As pointed out: you already know how to create a set from an object; >creating a list from an object is very similar: > > list(set(aa)) > >But why are you doing that? What are you trying to achieve? I have no idea why someone *else* is doing that, but I have used this very expression to unique-ize a list: >>> x = [3, 1, 4, 1, 5, 9, 2, 6] >>> x [3, 1, 4, 1, 5, 9, 2, 6] >>> list(set(x)) [1, 2, 3, 4, 5, 6, 9] >>> Of course, this trick only works if all the list elements are hashable. This might not be the best example since the result is sorted "by accident", while other list(set(...)) results are not. Add sorted() or .sort() if needed: >>> x = ['three', 'one', 'four', 'one', 'five'] >>> x ['three', 'one', 'four', 'one', 'five'] >>> list(set(x)) ['four', 'five', 'three', 'one'] >>> sorted(list(set(x))) ['five', 'four', 'one', 'three'] >>> -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From rustompmody at gmail.com Sat May 14 22:41:32 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 19:41:32 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> Message-ID: <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> On May 15, 4:26?am, Ben Finney wrote: > rusi writes: > > [Steven quote] > > In Python, [1, 2, 3] is another way of writing true, and [] is another > > way of writing false. Similarly with any other arbitrary objects. The > > only things that bools True and False are good for are: > > > > [end Steven quote] > > ------------------------ > > > So since > > [1,2,3] is one way of writing True (lets call it True3) > > No. Steven knew exactly why he was using ?true? versus ?True?. He's > explained why elsewhere in this thread. The former does not refer to the > Python boolean singleton, the latter does. > > The only object that is True is the True singleton. But there are many > objects that are true. Yes. The python entities: {True, False} are not an exact (isomorphic) model for the semantic boolean domain {true, false} (which is needed for example to explicate the semantics of if while etc) Which is to say the boolean type in python is not first class. From wallenpb at gmail.com Sat May 14 22:45:31 2011 From: wallenpb at gmail.com (Bill Allen) Date: Sat, 14 May 2011 21:45:31 -0500 Subject: PyPad 2.7.1 (Update 2) In-Reply-To: <950dfcf2-0ebf-4d7a-ab57-c862f2fedfd8@y27g2000prb.googlegroups.com> References: <950dfcf2-0ebf-4d7a-ab57-c862f2fedfd8@y27g2000prb.googlegroups.com> Message-ID: Jon, Looks very promising. Seems to be an issue with interactive mode. The following code behaves as thus: testvar=raw_input("enter value: ") print testvar When run, the prompt from raw_input does print to the output screen as: enter value: But when you tap in the lower window to enter the value for the input, the app closes unexpected. When I reopen it, what I was working on is still present. However, if I tap into the lower window and do this one line at a time from the interactive prompt >>>, the above code works ok. A problem? Or am I missing something? Anyway, I love this little Python app. Been wanting something like this for a long time. I installed this on my iPhone running iOS 4.3.3 (8J2). Congrats on a great app! Bill Allen On Thu, May 12, 2011 at 02:06, Jon D wrote: > Hi All, > > PyPad 2.7.1 Update 2 is now available on the AppStore. This is mainly > a bug fix release addressing a number of issues with the interactive > mode, but does also add some colour highlighting of output. > > PyPad is a port of the standard python code base to the iPad. It > includes most of the standard python modules and can be used for > testing small scripts or interactively for simple computation. > > Regards, > > Jon > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sat May 14 23:03:41 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 May 2011 21:03:41 -0600 Subject: I don't understand generator.send() In-Reply-To: References: <1k19ubi.dwyvio12tkc4kN%see@sig.for.address> Message-ID: On Sat, May 14, 2011 at 7:17 PM, Chris Angelico wrote: > You're right. It needs a while loop instead of the if (and some slight > reordering): > > def ints(): > ? i=0 > ? queue=[] > ? while True: > ? ? ? if queue: ?# see other thread, this IS legal and pythonic and > quite sensible > ? ? ? ? ? sent=(yield queue.pop(0)) > ? ? ? else: > ? ? ? ? ? sent=(yield i) > ? ? ? ? ? i+=1 > ? ? ? while sent is not None: > ? ? ? ? ? queue.append(sent) > ? ? ? ? ? sent=(yield None) ?# This is the return value from gen.send() > > That should work. Yeah, that should do it. But this is so much easier to get right and to understand: import itertools class Ints(object): def __init__(self): self.ints = itertools.count() self.queue = [] def __iter__(self): return self def next(self): if self.queue: return self.queue.pop(0) else: return self.ints.next() def insert(self, x): self.queue.append(x) From rustompmody at gmail.com Sat May 14 23:32:47 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 14 May 2011 20:32:47 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> Message-ID: On May 15, 2:19?am, Ian Kelly wrote: > On Sat, May 14, 2011 at 11:24 AM, rusi wrote: > > def fib(n): > > ? ?if n==1 or n==2: > > ? ? ? ?return 1 > > ? ?elif even(n): > > ? ? ? ?return sq(fib (n//2)) + 2 * fib(n//2) * fib(n//2 - 1) > > ? ?else: > > ? ? ? ?return sq(fib (n//2 + 1)) + sq(fib(n // 2)) > > > This is a strange algo ?-- logarithmic because it halves the n, > > exponential because of the double (triple) calls. ?[I cannot say I > > know how to work out its exact complexity but I would guess its about > > linear] > > Yup, linear. ?Assuming you optimize the even case so that it doesn't > actually call fib(n//2) twice, the call tree can be approximated as a > balanced binary tree with height log(n). ?The total number of nodes in > the tree is thus O(2 ** log(n)) = O(n). It would be linear if the base of the log were 2. I am not sure it is. You see the naive fib has a complexity which is fib itself. [Earlier discussion with Steven] fib is exponential but with radix < 2 [phi = (1 + sqrt(5))/2 ] This would suggest that this algo is slightly better than linear. But I have no idea of the exact complexity. From steve+comp.lang.python at pearwood.info Sun May 15 01:00:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2011 05:00:36 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dcf5df4$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 May 2011 00:45:29 -0700, rusi wrote: > On May 14, 12:39?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Thu, 12 May 2011 23:46:12 -0700, rusi wrote: >> > Mathematics has existed for millenia. Hindu-arabic numerals (base-10 >> > numbers) have been known for about one millennium The boolean domain >> > is only a 100 years old. Unsurprisingly it is not quite 'first-class' >> > yet: See >> >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html >> > [Lifted fromhttp://c2.com/cgi/wiki?EqualVsTrueFalse] >> >> Th money-quote as regards using arbitrary objects in truth tests: >> >> ? ? [quote] >> ? ? All this changed with the introduction of the two-element boolean >> ? ? domain {true, false} which provides the vocabulary needed to >> ? ? assign values to boolean expressions: 3<4 is a way for writing >> ? ? true, 3>4 is a way for writing false, whereas the value of x>0 >> ? ? depends on the value of x ... [end quote] >> >> In Python, [1, 2, 3] is another way of writing true, and [] is another >> way of writing false. Similarly with any other arbitrary objects. > > Well so is [1,2] another way of writing True > > And then we get the interesting result that (True = True) is False I presume you mean to say: ([1, 2] == True) is False that is, that one true value is not equal to another true value. That is correct. However, Python's == operator is not a Boolean Algebra operator. If it were, it would probably be called "material biconditional", or XNOR, and written ? or <-> and would be smart enough to recognise that both [1, 2] and True are true. Or possibly dumb enough... the difficulty is that the equality operator knows more about the objects than just their truth value. And furthermore: ([1, 2] and True) == (True and [1, 2]) is also False, again because == is too smart to recognise that the left hand side (True) and the right hand side ([1, 2]) are both true values. It's not that Python bools aren't first class objects, but that Python doesn't have a full set of all 16 possible boolean algebra operators. -- Steven From steve+comp.lang.python at pearwood.info Sun May 15 01:07:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2011 05:07:37 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> Message-ID: <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 May 2011 19:41:32 -0700, rusi wrote: > The python entities: {True, False} are not an exact (isomorphic) model > for the semantic boolean domain {true, false} (which is needed for > example to explicate the semantics of if while etc) Which is to say the > boolean type in python is not first class. I'm afraid I don't understand what you mean. Can you explain please, what properties of "first class booleans" do you think are missing from Python? -- Steven From cwg at falma.de Sun May 15 04:28:53 2011 From: cwg at falma.de (Christoph Groth) Date: Sun, 15 May 2011 10:28:53 +0200 Subject: dict: retrieve the original key by key Message-ID: <874o4wwenu.fsf@falma.de> Dear python experts, I use a huge python dictionary where the values are lists of that dictionary's keys (yes, a graph). Each key is thus referenced several times. As the keys are rather large objects, I would like to save memory by re-using key objects wherever possible, instead of having several equal objects in memory. There does not seem to be a way to retrieve the original key from a python dictionary. Is there a technical reason for this? (Other than that such functionality was not considered to be useful enough.) What I will probably do now is store (key, real_value) as values in my dictionary. Is there a better solution? thanks, Christoph From rafadurancastaneda at gmail.com Sun May 15 04:37:46 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sun, 15 May 2011 10:37:46 +0200 Subject: Python drawing library? In-Reply-To: References: Message-ID: <4DCF90DA.6090609@gmail.com> On 15/05/11 01:01, OKB (not okblacke) wrote: > Is there any Python library for interactive drawing? I've done > some googling but most searches for "drawing" lead me to libraries for > programmatic creation of shapes on some GUI canvas. I'm looking for GUI > widgets that allow the user to draw with the mouse, like a paint > program, and let me get info about the drawing as its made (get color at > mouse location, etc.). I'd prefer a wxPython solution, although any > Python solution would be better than none. > > Thanks, I'm not suere, but I think you should be able to do that using PyQt QPaintDevice. From clp2 at rebertia.com Sun May 15 04:44:19 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 May 2011 01:44:19 -0700 Subject: dict: retrieve the original key by key In-Reply-To: <874o4wwenu.fsf@falma.de> References: <874o4wwenu.fsf@falma.de> Message-ID: On Sun, May 15, 2011 at 1:28 AM, Christoph Groth wrote: > Dear python experts, > > I use a huge python dictionary where the values are lists of that > dictionary's keys (yes, a graph). ?Each key is thus referenced several > times. > > As the keys are rather large objects, I would like to save memory by > re-using key objects wherever possible, instead of having several equal > objects in memory. > > There does not seem to be a way to retrieve the original key from a > python dictionary. ?Is there a technical reason for this? ?(Other than > that such functionality was not considered to be useful enough.) Define "original key". Cheers, Chris From tacyt1007 at gmail.com Sun May 15 04:47:14 2011 From: tacyt1007 at gmail.com (Wojtek Mamrak) Date: Sun, 15 May 2011 10:47:14 +0200 Subject: Python drawing library? In-Reply-To: <4DCF90DA.6090609@gmail.com> References: <4DCF90DA.6090609@gmail.com> Message-ID: Yes, it is possible with use of PyQt. 2011/5/15 Rafael Dur?n Casta?eda : > On 15/05/11 01:01, OKB (not okblacke) wrote: >> >> ? ? ? ?Is there any Python library for interactive drawing? ?I've done >> some googling but most searches for "drawing" lead me to libraries for >> programmatic creation of shapes on some GUI canvas. ?I'm looking for GUI >> widgets that allow the user to draw with the mouse, like a paint >> program, and let me get info about the drawing as its made (get color at >> mouse location, etc.). ?I'd prefer a wxPython solution, although any >> Python solution would be better than none. >> >> Thanks, > > I'm not suere, but I think you should be able to do that using PyQt > QPaintDevice. > -- > http://mail.python.org/mailman/listinfo/python-list > From n4vpython at gmail.com Sun May 15 05:00:14 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Sun, 15 May 2011 14:30:14 +0530 Subject: recvall() Message-ID: Hi All, I am trying to program an HTTP webserver, I am a little confused about the best way to program a recvall function. There are a couple of ways to do this? But performance wise which one is better? a) recvall using a timeout? b) recvall using a condition that nothing was received? c) recvall using a condition for it to wait for a CRLF or a timeout whichever occurs first? Any help would be appreciated. Regards, Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From cwg at falma.de Sun May 15 05:11:41 2011 From: cwg at falma.de (Christoph Groth) Date: Sun, 15 May 2011 11:11:41 +0200 Subject: dict: retrieve the original key by key References: <874o4wwenu.fsf@falma.de> Message-ID: <87wrhsuy42.fsf@falma.de> Chris Rebert writes: > On Sun, May 15, 2011 at 1:28 AM, Christoph Groth wrote: >> I use a huge python dictionary where the values are lists of that >> dictionary's keys (yes, a graph). ?Each key is thus referenced >> several times. >> >> As the keys are rather large objects, I would like to save memory by >> re-using key objects wherever possible, instead of having several >> equal objects in memory. >> >> There does not seem to be a way to retrieve the original key from a >> python dictionary. ?Is there a technical reason for this? ?(Other >> than that such functionality was not considered to be useful enough.) > > Define "original key". def original_key(dictionary, key): for k in dictionary: if k == key: return k raise KeyError(key) But this is not efficient. I would like to avoid having _multiple_ objects which are equal (a == b) but not the same (a is not b). This would save a lot of memory. From akabaila at pcug.org.au Sun May 15 05:15:48 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Sun, 15 May 2011 19:15:48 +1000 Subject: Python 3.2 Vectors.py module Message-ID: <201105151915.48203.akabaila@pcug.org.au> Hi All, I would really appreciate any comments and suggestions for the Vectors.py module, which can be downloaded from http://akabaila.pcug.org.au/linalg/vectors.tar.gz The tar ball is only about 4 KiB, but I gather that this mailing list does not tolerate attachments. The module is designed with PYTHON 3.2 and it is required for some structural analysis programs to port them to Python 3.x world. A quick start introduction to the module follows ********************************* #!/usr/bin/env python3.2 ''' quickVector.py - quick introduction to Vectors module. More information in "the manual". The quick introduction starts right here! With Vectors.py in the current directory, fire up the Python 3.2 Idle and try Vector algebra in the Python Shell. (Alternatively, just fire up Python 3.2 and try the commands from the terminal - CLI. >>> from Vectors import Vector >>> v1 = Vector(3, 4) >>> print('v1 = ', v1) v1 = Vector(3.0, 4.0, 0.0) >>> print('v1.size =', v1.size) v1.size = 5.0 >>> v2 = Vector(0, -5) >>> print('v2 =', v2) v2 = Vector(0.0, -5.0, 0.0) >>> print('scalar product =', v1 * v2) scalar product = -20.0 >>> print('vector product =', v1 ** v2) vector product = Vector(0.0, 0.0, -15.0) >>> v3 = v1 + v2 >>> print('v1 + v2 =', v3) v1 + v2 = Vector(3.0, -1.0, 0.0) >>> print('v3 - v1 verify = v2 =', v3 -v1) v3 - v1 verify = v2 = Vector(0.0, -5.0, 0.0) >>> # All vectors are three dimensional. But >>> # by specifying z = 0 we had vectors in (x y) >>> # plane. However, when we form a vector product >>> # (aka cross product), the resulting vector has >>> # to be at right angles to the (x y) plane, so >>> # we return to the 3 Dimensional media... >>> # Vector (cross) product is signalled by ** >>> w1 = v1 ** v2 >>> print('w1 = v1 ** v2 =', w1) w1 = v1 ** v2 = Vector(0.0, 0.0, -15.0) >>> w2 = w1 + v1 >>> print('w2 a vector in 3 dim. =', w2) w2 a vector in 3 dim. = Vector(3.0, 4.0, -15.0) >>> # Time to look at the "user manual" and other examples. >>> # Temp. home: http://akabaila/pcug.org.au/linalg/vectors.py ''' import doctest doctest.testmod() ********************************* Thank you in anticipation for suggestions and comments. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From gruszczy at gmail.com Sun May 15 05:33:40 2011 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Sun, 15 May 2011 11:33:40 +0200 Subject: ANN: Fathom 0.3.0 Message-ID: Hi, I have released version 0.2.0 of fathom, python3 package for database inspection. Fathom supports retrieving database schema from Sqlite3, PostgreSQL, MySQL and Oracle. This is still very early version and I am experimenting with different approaches. As always I would be very thankful for any input and suggestions about what would be useful in the library or tools. Here you can download the package: http://code.google.com/p/fathom/downloads/list **Changes in 0.3.0:** -> Oracle support :-) -> Triggers provide information about event upon which they are fired -> utility function for finding procedures that access a table -> fathom2graphviz draws lines between columns for foreign key -> fathom2graphviz and fathom2django can now print output to a file, rather than to std -- Filip Gruszczy?ski From chris at spam.org Sun May 15 05:44:04 2011 From: chris at spam.org (Christoph Scheingraber) Date: Sun, 15 May 2011 09:44:04 +0000 (UTC) Subject: connect SIGINT to custom interrupt handler Message-ID: Hi, I am trying to connect SIGINT (^c) to a custom interrupt handler like this (no threading, just straightforward): if __name__ == "__main__": quit = False def interrupt_handler(signal, frame): global quit if not quit: print "blabla, i'll finish my task and quit kind of message" print "Press ^C again to interrupt immediately." else: sys.exit(2) quit = True signal.signal(signal.SIGINT, interrupt_handler) # main will use the quit flag to determine if it should quit before next # task status = main() This worked fine in some rare lucky cases, but most of the times, the module I am using (my university's seismology project) catches the SIGINT and quits: select.error: (4, 'Interrupted system call') How can I prevent the imported module's function from catching the interrupt signal? Thanks to anyone that takes the time to help me... Chris -- Chris Scheingraber - www.scheingraber.net From dan.kluev at gmail.com Sun May 15 05:44:29 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 15 May 2011 20:44:29 +1100 Subject: Python 3.2 Vectors.py module In-Reply-To: <201105151915.48203.akabaila@pcug.org.au> References: <201105151915.48203.akabaila@pcug.org.au> Message-ID: On Sun, May 15, 2011 at 8:15 PM, Algis Kabaila wrote: > Hi All, > > I would really appreciate any comments and suggestions for the Vectors.py > module, which can be downloaded from - If you intend to provide it as general-purpose vector module for other people to use, it would be better if you pack it in separate package and upload to PyPI. You can find good tutorial on packaging here: http://diveintopython3.org/packaging.html - NumPy/SciPy has pretty fair support for vectors. Would be good if you pointed out the differences to begin with. -- With best regards, Daniel Kluev From dan.kluev at gmail.com Sun May 15 05:49:46 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 15 May 2011 20:49:46 +1100 Subject: threads with gtk gui problem In-Reply-To: <4DCECC70.5020703@earthsong.free-online.co.uk> References: <4DCE7FCC.8020907@gmail.com> <4DCECC70.5020703@earthsong.free-online.co.uk> Message-ID: You can also use multiprocessing module instead of threads. Use pipe and gobject.idle_add(somefunc) to process data from other thread. -- With best regards, Daniel Kluev From steve+comp.lang.python at pearwood.info Sun May 15 06:18:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2011 10:18:45 GMT Subject: dict: retrieve the original key by key References: <874o4wwenu.fsf@falma.de> Message-ID: <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: > I would like to avoid having _multiple_ objects which are equal (a == b) > but not the same (a is not b). This would save a lot of memory. Based on the idea of interning, which is used for Python strings: cache = {} def my_intern(obj): return cache.setdefault(obj, obj) x = make_some_object() x = my_intern(x) This ensures that equal objects in the graph are not just equal, but the same cached object. -- Steven From cwg at falma.de Sun May 15 06:46:15 2011 From: cwg at falma.de (Christoph Groth) Date: Sun, 15 May 2011 12:46:15 +0200 Subject: dict: retrieve the original key by key References: <874o4wwenu.fsf@falma.de> <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjsgutqg.fsf@falma.de> Steven D'Aprano writes: > On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: > >> I would like to avoid having _multiple_ objects which are equal (a == >> b) but not the same (a is not b). This would save a lot of memory. > > Based on the idea of interning, which is used for Python strings: > > cache = {} def my_intern(obj): > return cache.setdefault(obj, obj) > > > x = make_some_object() x = my_intern(x) > > This ensures that equal objects in the graph are not just equal, but > the same cached object. This requires another dictionary, though. But hey, they keys of my dictionary are actually strings, so I can use the built-in intern. Somehow, I have never stumbled accross this built-in function so far. Thanks a lot for the hint! Christoph From akabaila at pcug.org.au Sun May 15 06:55:32 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Sun, 15 May 2011 20:55:32 +1000 Subject: Python 3.2 Vectors.py module In-Reply-To: References: <201105151915.48203.akabaila@pcug.org.au> Message-ID: <201105152055.32225.akabaila@pcug.org.au> On Sunday 15 May 2011 19:44:29 Daniel Kluev wrote: > On Sun, May 15, 2011 at 8:15 PM, Algis Kabaila wrote: > > Hi All, > > > > I would really appreciate any comments and suggestions for > > the Vectors.py module, which can be downloaded from > > - If you intend to provide it as general-purpose vector > module for other people to use, it would be better if you > pack it in separate package and upload to PyPI. > You can find good tutorial on packaging here: > http://diveintopython3.org/packaging.html > > - NumPy/SciPy has pretty fair support for vectors. Would be > good if you pointed out the differences to begin with. Daniel, Thank you for the packaging suggestion. I had a glance at Chapter 16 of Dive into Python, do the packaging for my own use and only then will go to PyPi. Pointing out the differences is a tall order, but I do understand its importance. Actually, airing early the development in a mailing list may be a good way to get some suggestions as to where similarities may be. For one, "euclid " was an inspiration. I started by trying to update it for Python 3.x and that lead to developing an alternative package. The size of it (in terms of code lines) is differs by a factor of 10, partly because the Vectors.py does not deal with matrices as for my interests I would need a much wider reaching package. My moves are slow for a variety of reasons, but ignoring advice is not one of the reasons. Your suggestions are greatly appreciated. OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Sun May 15 07:04:27 2011 From: ndbecker2 at gmail.com (Neal Becker) Date: Sun, 15 May 2011 07:04:27 -0400 Subject: Get the IP address of WIFI interface References: Message-ID: Far.Runner wrote: > Hi python experts: > There are two network interfaces on my laptop: one is 100M Ethernet > interface, the other is wifi interface, both are connected and has an ip > address. > The question is: How to get the ip address of the wifi interface in a python > script without parsing the output of a shell command like "ipconfig" or > "ifconfig"? > > OS: Windows or Linux > > F.R Here's some useful snippits for linux: def get_default_if(): f = open('/proc/net/route') for i in csv.DictReader(f, delimiter="\t"): if long(i['Destination'], 16) == 0: return i['Iface'] return None def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) From mail at timgolden.me.uk Sun May 15 07:12:07 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 15 May 2011 12:12:07 +0100 Subject: Get the IP address of WIFI interface In-Reply-To: References: Message-ID: <4DCFB507.2040007@timgolden.me.uk> On 15/05/2011 12:04 PM, Neal Becker wrote: > Far.Runner wrote: > >> Hi python experts: >> There are two network interfaces on my laptop: one is 100M Ethernet >> interface, the other is wifi interface, both are connected and has an ip >> address. >> The question is: How to get the ip address of the wifi interface in a python >> script without parsing the output of a shell command like "ipconfig" or >> "ifconfig"? >> >> OS: Windows or Linux >> >> F.R > > Here's some useful snippits for linux: ... and for Windows: import wmi for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): print nic.Caption, nic.IPAddress TJG From alister.ware at ntlworld.com Sun May 15 07:13:17 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Sun, 15 May 2011 11:13:17 GMT Subject: problem with GKT module? References: Message-ID: On Fri, 13 May 2011 13:13:00 +0000, alister ware wrote: > I am using gtk.builder with a glade generated GUI > > I have a simple call back defined for a radio button widget when I use > widget.name in linux I get a value of None, windows returns the widget > name as I would expect. > > is this a bug? > if not how should i find the name of the widget that has triggered a > call back? > > (I would like all my radio buttons to go to the same callback routine if > possible to make code maintenance easier) > So nobody has any Ideas on this at all? -- I never failed to convince an audience that the best thing they could do was to go away. From sigmundv at gmail.com Sun May 15 07:18:46 2011 From: sigmundv at gmail.com (SigmundV) Date: Sun, 15 May 2011 04:18:46 -0700 (PDT) Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Message-ID: <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> I think the OP wants to find the intersection of two lists. list(set(list1) & set(list2)) is indeed one way to achieve this. [i for i in list1 if i in list2] is another one. Sigmund On May 15, 4:11?am, Chris Torek wrote: > In article <871v00j2bh.... at benfinney.id.au> > Ben Finney ? wrote: > > >As pointed out: you already know how to create a set from an object; > >creating a list from an object is very similar: > > > ? ?list(set(aa)) > > >But why are you doing that? What are you trying to achieve? > > I have no idea why someone *else* is doing that, but I have used > this very expression to unique-ize a list: > > ? ? >>> x = [3, 1, 4, 1, 5, 9, 2, 6] > ? ? >>> x > ? ? [3, 1, 4, 1, 5, 9, 2, 6] > ? ? >>> list(set(x)) > ? ? [1, 2, 3, 4, 5, 6, 9] > ? ? >>> > > Of course, this trick only works if all the list elements are > hashable. > > This might not be the best example since the result is sorted > "by accident", while other list(set(...)) results are not. ?Add > sorted() or .sort() if needed: > > ? ? >>> x = ['three', 'one', 'four', 'one', 'five'] > ? ? >>> x > ? ? ['three', 'one', 'four', 'one', 'five'] > ? ? >>> list(set(x)) > ? ? ['four', 'five', 'three', 'one'] > ? ? >>> sorted(list(set(x))) > ? ? ['five', 'four', 'one', 'three'] > ? ? >>> > -- > In-Real-Life: Chris Torek, Wind River Systems > Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) ?+1 801 277 2603 > email: gmail (figure it out) ? ? ?http://web.torek.net/torek/index.html From sigmundv at gmail.com Sun May 15 07:23:40 2011 From: sigmundv at gmail.com (SigmundV) Date: Sun, 15 May 2011 04:23:40 -0700 (PDT) Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: <7b1ee48b-cd41-4baa-bfa2-473e7d898150@gu8g2000vbb.googlegroups.com> I'm sorry I top posted. I'll remember not to top post next time. Sigmund From vanboxem.ruben at gmail.com Sun May 15 08:29:57 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Sun, 15 May 2011 14:29:57 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: 2011/5/14 Doug Evans : > On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem > wrote: >> 2011/5/14 Doug Evans : >>> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem >>> wrote: >>>> (now in plain-text as required by gdb mailing list) >>>> >>>> Hi, >>>> >>>> I am currently trying to integrate Python support into my toolchain >>>> build (including GDB of course). It is a sysrooted >>>> binutils+GCC+GDB+mingw-w64 toolchain. >>>> >>>> I currently have the basic setup working: I can link gdb with my >>>> manually generated import lib to the python dll from the official >>>> Windows install. If there is anything I am missing or a very easy >>>> solution to the problems decsribed below, please just say so. I am >>>> only suggesting what I would like to happen. >>>> >>>> Now on to the problems I'd like to discuss: >>>> >>>> 1. gdb.exe won't start without me having set PYTHONPATH manually. >>> >>> In a properly configured/built gdb on linux this isn't necessary, even >>> if python is installed in some random place. >>> I'm not sure about windows though. >>> Did you specify --with-python when you configured gdb, and if so did >>> you specify a value? >>> e.g., --with-python=SOME_VALUE >> >> I was cross-compiling a mingw toolchain+gdb from Linux, so I used >> --with-python without a value (because gdb configure tries to find the >> Python executabe), and I added -I"/path/to/python/includes" to CFLAGS >> and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it >> should. This is hacky though, and gdb configure should provide >> --with-python-libs and --with-python-include to make it more >> streamlined with any other build prerequisite (like >> gmp/mpfr/mpc/cloog/ppl in GCC for example). > > Ah. > Cross-compiling gdb with python is in need of improvement. > Alas python hasn't been designed with cross-compilation in mind (e.g. > build on linux, run on windows). > AIUI, the way to get the parameters required for compiling with > libpython is to get them from python's "distutils": kinda hard to do > in a cross-compile. ?Done correctly there's no need to run python. > > I haven't done anything more to support python in gdb's configure.ac > because it's not clear to me what the right thing to do is: distutils > provides more than just --libs and --includes (btw, we don't use > --libs though, we use --ldflags which includes all of: the directory > in which to find libpython, the -l for libpython, and the -l's for all > the other libraries python needs). [Which isn't to say that someone > else isn't free to tackle this.] > > In the meantime, what I've been doing is a hack: write a script that > responds to: > --includes > --ldflags > --exec-prefix > and pass that as --with-python. > > E.g. > bash$ cat $HOME/my-python-for-config > #! /bin/sh > > if [ $# -ne 2 ] > then > ? ? ? ?echo "Bad # args. ?Blech!" >&2 > ? ? ? ?exit 1 > fi > > # The first argument is the path to python-config.py, ignore it. > > case "$2" in > --includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;; > --ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm > -lpython2.6" ;; > --exec-prefix) echo "/usr" ;; > *) echo "Bad arg $2. ?Blech!" >&2 ; exit 1 ;; > esac > > exit 0 > bash$ ./configure --with-python=$HOME/my-python-for-config [...] > [...] > > > Note that --exec-prefix is the runtime location of python. > GCC uses this to tell libpython where to find its support files. > [grep for Py_SetProgramName in gdb/python/python.c] OK, I tried your script in a couple of variations. It gets rid of the traceback I had before, but still doesn't help the PYTHONPATH problem. My directory structure is as follows (this is not in root, "/" is just my main build directory, there are several levels below it): /gdb <-- gdb build dir /gdb/gdb <-- where the python configuration is done /python <-- temporary install dir for python files for build, extracted from the official Windows installer, also location of libpython2.7.a import library /python/include/python27 <-- python headers, found by gdb in both cases /mingw64 <-- toolchain sysroot prefix /mingw64/bin <-- install location of gdb and python27.dll /mingw64/lib/python27 <-- install location of all python scripts First variant: --includes) echo "-I../../python/include" ;; --ldflags) echo "-L../../python -lpython2.7" ;; --exec-prefix) echo "../../mingw64/lib/python27" ;; Here exec-prefix would be the relative path from where "configure" does its magic to the final location of the scripts on the build system. Second variant: --includes) echo "-I../../python/include" ;; --ldflags) echo "-L../../python -lpython2.7" ;; --exec-prefix) echo "../lib/python27" ;; I thought the second points gdb to the installed location of the python scripts, but it still needed PYTHONPATH for that. I used relative paths in an attempt to "do the right thing", hackwise... Remember that the whole "/mingw64" directory gets zipped and moved, then it gets extracted to a random location in the Windows filesystem. Thanks for the help so far, I think we might just get this worked out together. Ruben > >>>> I understand the need for this, but as gdb requires Python 2, and users >>>> of my toolchain may have installed Python 3 or a 32-bit version python >>>> they want to use from the same environment (without changing their own >>>> PYTHONPATH), there is no way to run python-enabled gdb. >>>> [...] >>> >>> Yeah. >>> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have >>> gdb use that instead of PYTHONPATH if it exists, but there's been >>> resistance to it. >>> I think(!) what would happen is that gdb would set $PYTHONPATH to the >>> value of $GDB_PYTHONPATH. >>> [Inferiors started by gdb should still get the original value of >>> PYTHONPATH though.] >> >> That way would be almost ideal, but a hardcoded *relative* path to the >> python scripts (that is standardized within gdb) wouldn't hurt. > > See above re: --exec-prefix. > >> An >> extra environment variable would require a lot of explaining for >> Windows, and is not "plug-and-play", like the rest of a sysrooted >> toolchain is supposed to be like. I think this should work on all >> setups: >> >> 1. Check hardcoded path; my suggestion would be "> executable>/../lib/python27" >> 2. If this fails to find the necessary files/scripts, find it like you >> described above in Linux, without PYTHONPATH set. >> 3. Check PYTHONPATH. > > The problem being solved by the proposed GDB_PYTHONPATH is "What if > the user has PYTHONPATH set and it points to an incompatible version > of python?". > Leaving such a value for PYTHONPATH set while gdb's python is running > feels wrong (and IIRC has caused some problems). > > The problem of telling python where to find itself is already solved > (or at least is intended to be solved) with gdb's calling > Py_SetProgramName with a value derived from the python-provided > --exec-prefix. > >> I would think only number one would change, and perhaps be only >> enabled with a special configure option. Nothing else would have to >> change, and Windows users would rejoice :) >> Again, this is only my suggestion, if there are problems with it in >> way I haven't thought of, please say so, and we can come up with >> another solution. > From devivithyamaha at gmail.com Sun May 15 09:08:55 2011 From: devivithyamaha at gmail.com (devi vithya) Date: Sun, 15 May 2011 06:08:55 -0700 (PDT) Subject: DATING FOR BEAUTY GIRLS - DATING TIPS FOR GUYS - DATING ROMANCE - CLICK HERE Message-ID: http://dating4maha.blogspot.com/ http://dating4maha.blogspot.com/ http://dating4maha.blogspot.com/ http://dating4maha.blogspot.com/ http://dating4maha.blogspot.com/ From nobody at nowhere.com Sun May 15 09:08:59 2011 From: nobody at nowhere.com (Nobody) Date: Sun, 15 May 2011 14:08:59 +0100 Subject: connect SIGINT to custom interrupt handler References: Message-ID: On Sun, 15 May 2011 09:44:04 +0000, Christoph Scheingraber wrote: > signal.signal(signal.SIGINT, interrupt_handler) > This worked fine in some rare lucky cases, but most of the times, the > module I am using (my university's seismology project) catches the SIGINT > and quits: > > select.error: (4, 'Interrupted system call') After installing the signal handler, call: signal.siginterrupt(signal.SIGINT, False) This will cause (most) interrupted system calls to be restarted after the signal has been handled. > How can I prevent the imported module's function from catching the > interrupt signal? It isn't catching the signal. Unless you enable restarting of system calls, an interrupted system call will typically fail with EINTR. Python typically reports failures via exceptions; failures due to EINTR aren't handled differently. From vanboxem.ruben at gmail.com Sun May 15 09:26:45 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Sun, 15 May 2011 15:26:45 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: 2011/5/15 Ruben Van Boxem : > 2011/5/14 Doug Evans : >> On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem >> wrote: >>> 2011/5/14 Doug Evans : >>>> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem >>>> wrote: >>>>> (now in plain-text as required by gdb mailing list) >>>>> >>>>> Hi, >>>>> >>>>> I am currently trying to integrate Python support into my toolchain >>>>> build (including GDB of course). It is a sysrooted >>>>> binutils+GCC+GDB+mingw-w64 toolchain. >>>>> >>>>> I currently have the basic setup working: I can link gdb with my >>>>> manually generated import lib to the python dll from the official >>>>> Windows install. If there is anything I am missing or a very easy >>>>> solution to the problems decsribed below, please just say so. I am >>>>> only suggesting what I would like to happen. >>>>> >>>>> Now on to the problems I'd like to discuss: >>>>> >>>>> 1. gdb.exe won't start without me having set PYTHONPATH manually. >>>> >>>> In a properly configured/built gdb on linux this isn't necessary, even >>>> if python is installed in some random place. >>>> I'm not sure about windows though. >>>> Did you specify --with-python when you configured gdb, and if so did >>>> you specify a value? >>>> e.g., --with-python=SOME_VALUE >>> >>> I was cross-compiling a mingw toolchain+gdb from Linux, so I used >>> --with-python without a value (because gdb configure tries to find the >>> Python executabe), and I added -I"/path/to/python/includes" to CFLAGS >>> and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it >>> should. This is hacky though, and gdb configure should provide >>> --with-python-libs and --with-python-include to make it more >>> streamlined with any other build prerequisite (like >>> gmp/mpfr/mpc/cloog/ppl in GCC for example). >> >> Ah. >> Cross-compiling gdb with python is in need of improvement. >> Alas python hasn't been designed with cross-compilation in mind (e.g. >> build on linux, run on windows). >> AIUI, the way to get the parameters required for compiling with >> libpython is to get them from python's "distutils": kinda hard to do >> in a cross-compile. ?Done correctly there's no need to run python. >> >> I haven't done anything more to support python in gdb's configure.ac >> because it's not clear to me what the right thing to do is: distutils >> provides more than just --libs and --includes (btw, we don't use >> --libs though, we use --ldflags which includes all of: the directory >> in which to find libpython, the -l for libpython, and the -l's for all >> the other libraries python needs). [Which isn't to say that someone >> else isn't free to tackle this.] >> >> In the meantime, what I've been doing is a hack: write a script that >> responds to: >> --includes >> --ldflags >> --exec-prefix >> and pass that as --with-python. >> >> E.g. >> bash$ cat $HOME/my-python-for-config >> #! /bin/sh >> >> if [ $# -ne 2 ] >> then >> ? ? ? ?echo "Bad # args. ?Blech!" >&2 >> ? ? ? ?exit 1 >> fi >> >> # The first argument is the path to python-config.py, ignore it. >> >> case "$2" in >> --includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;; >> --ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm >> -lpython2.6" ;; >> --exec-prefix) echo "/usr" ;; >> *) echo "Bad arg $2. ?Blech!" >&2 ; exit 1 ;; >> esac >> >> exit 0 >> bash$ ./configure --with-python=$HOME/my-python-for-config [...] >> [...] >> >> >> Note that --exec-prefix is the runtime location of python. >> GCC uses this to tell libpython where to find its support files. >> [grep for Py_SetProgramName in gdb/python/python.c] > > OK, I tried your script in a couple of variations. It gets rid of the > traceback I had before, but still doesn't help the PYTHONPATH problem. > My directory structure is as follows (this is not in root, "/" is just > my main build directory, there are several levels below it): > > /gdb <-- gdb build dir > /gdb/gdb <-- where the python configuration is done > /python <-- temporary install dir for python files for build, > extracted from the official Windows installer, also location of > libpython2.7.a import library > /python/include/python27 <-- python headers, found by gdb in both cases > /mingw64 <-- toolchain sysroot prefix > /mingw64/bin <-- install location of gdb and python27.dll > /mingw64/lib/python27 <-- install location of all python scripts > > First variant: > --includes) echo "-I../../python/include" ;; > --ldflags) echo "-L../../python -lpython2.7" ;; > --exec-prefix) echo "../../mingw64/lib/python27" ;; > > Here exec-prefix would be the relative path from where "configure" > does its magic to the final location of the scripts on the build > system. > > Second variant: > --includes) echo "-I../../python/include" ;; > --ldflags) echo "-L../../python -lpython2.7" ;; > --exec-prefix) echo "../lib/python27" ;; > > I thought the second points gdb to the installed location of the > python scripts, but it still needed PYTHONPATH for that. I used > relative paths in an attempt to "do the right thing", hackwise... > Remember that the whole "/mingw64" directory gets zipped and moved, > then it gets extracted to a random location in the Windows filesystem. > > Thanks for the help so far, I think we might just get this worked out together. > > Ruben Wow, I think I have a partial solution. Delving into the Python docs, for example here: http://docs.python.org/using/windows.html#finding-modules, you can see that PYTHONPATH is used first, then the Windows registry, then PYTHONHOME, then some default relative paths. I placed the python scripts all in the directory structure like so: /bin/gdb /bin/Lib/ /bin/python27.dll This works, even without any manual PYTHONPATH intervention. Problem is though, that as soon as someone has a PYTHONPATH environment variable from a (incompatible) Python installation (think different bitness or version 3.x instead of 2.7.1), I cannot predict what will go wrong. This problem originates in Python's way of filling in the search path (sys.path). A true solution in the GDB case to prevent this collision of an incompatible PYTHONPATH would be that GDB sets an internal PYTHONPATH as directed by configure, uses that to load its Python internals, and allows the GDB child processes (apps being debugged) to use the environment PYTHONPATH. For now, I have a functional installation, but it will break as soon as someone installs Python on their system. The part your script plays in this (if I haven't misunderstood the intention/effects of the "--exec-prefix" part) is allowing a uniform way of directing the configure script to the right directories for includes/libs. Ruben > >> >>>>> I understand the need for this, but as gdb requires Python 2, and users >>>>> of my toolchain may have installed Python 3 or a 32-bit version python >>>>> they want to use from the same environment (without changing their own >>>>> PYTHONPATH), there is no way to run python-enabled gdb. >>>>> [...] >>>> >>>> Yeah. >>>> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have >>>> gdb use that instead of PYTHONPATH if it exists, but there's been >>>> resistance to it. >>>> I think(!) what would happen is that gdb would set $PYTHONPATH to the >>>> value of $GDB_PYTHONPATH. >>>> [Inferiors started by gdb should still get the original value of >>>> PYTHONPATH though.] >>> >>> That way would be almost ideal, but a hardcoded *relative* path to the >>> python scripts (that is standardized within gdb) wouldn't hurt. >> >> See above re: --exec-prefix. >> >>> An >>> extra environment variable would require a lot of explaining for >>> Windows, and is not "plug-and-play", like the rest of a sysrooted >>> toolchain is supposed to be like. I think this should work on all >>> setups: >>> >>> 1. Check hardcoded path; my suggestion would be ">> executable>/../lib/python27" >>> 2. If this fails to find the necessary files/scripts, find it like you >>> described above in Linux, without PYTHONPATH set. >>> 3. Check PYTHONPATH. >> >> The problem being solved by the proposed GDB_PYTHONPATH is "What if >> the user has PYTHONPATH set and it points to an incompatible version >> of python?". >> Leaving such a value for PYTHONPATH set while gdb's python is running >> feels wrong (and IIRC has caused some problems). >> >> The problem of telling python where to find itself is already solved >> (or at least is intended to be solved) with gdb's calling >> Py_SetProgramName with a value derived from the python-provided >> --exec-prefix. >> >>> I would think only number one would change, and perhaps be only >>> enabled with a special configure option. Nothing else would have to >>> change, and Windows users would rejoice :) >>> Again, this is only my suggestion, if there are problems with it in >>> way I haven't thought of, please say so, and we can come up with >>> another solution. >> > From usgallery01 at gmail.com Sun May 15 10:21:48 2011 From: usgallery01 at gmail.com (charmi s) Date: Sun, 15 May 2011 07:21:48 -0700 (PDT) Subject: SEE KAREENA KAPOOR BOLLYWOOD HOT ACTRESS BOOBS PRESSED IN SHOPPING MALL Message-ID: SEE KAREENA KAPOOR BOLLYWOOD HOT ACTRESS BOOBS PRESSED IN SHOPPING MALL At http://hollypops.Co.CC Due to GOOGLE security risks, i have hidden the videos in an image. in that website on Right side below search box click on image and watch videos in all angles. From chris at spam.org Sun May 15 10:32:13 2011 From: chris at spam.org (Christoph Scheingraber) Date: Sun, 15 May 2011 14:32:13 +0000 (UTC) Subject: connect SIGINT to custom interrupt handler References: Message-ID: I now have signal.siginterrupt(signal.SIGINT, False) in the line below signal.signal(signal.SIGINT, interrupt_handler) Unfortunately, pressing ^c still results in the same interrupt error. I also tried putting signal.siginterrupt into the interrupt_handler function, which gave an interesting result: File "/usr/local/bin/obspysod", line 586, in interrupt_handler signal.siginterrupt(signal.SIGINT, False) AttributeError: 'int' object has no attribute 'siginterrupt' Could there be a namespace problem? On 2011-05-15, Nobody wrote: > On Sun, 15 May 2011 09:44:04 +0000, Christoph Scheingraber wrote: > >> signal.signal(signal.SIGINT, interrupt_handler) > >> This worked fine in some rare lucky cases, but most of the times, the >> module I am using (my university's seismology project) catches the SIGINT >> and quits: >> >> select.error: (4, 'Interrupted system call') > > After installing the signal handler, call: > > signal.siginterrupt(signal.SIGINT, False) > > This will cause (most) interrupted system calls to be restarted after the > signal has been handled. > >> How can I prevent the imported module's function from catching the >> interrupt signal? > > It isn't catching the signal. Unless you enable restarting of system > calls, an interrupted system call will typically fail with EINTR. Python > typically reports failures via exceptions; failures due to EINTR aren't > handled differently. > -- Chris Scheingraber - www.scheingraber.net From miki.tebeka at gmail.com Sun May 15 11:25:42 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 15 May 2011 08:25:42 -0700 (PDT) Subject: connect SIGINT to custom interrupt handler In-Reply-To: Message-ID: <04cee22d-fc07-4c54-b91b-3f9e4730f095@glegroupsg2000goo.googlegroups.com> Greetings, > I am trying to connect SIGINT (^c) to a custom interrupt handler like > this (no threading, just straightforward): Why not just catch KeyboardInterrupt? All the best, -- Miki From rosuav at gmail.com Sun May 15 11:30:10 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 01:30:10 +1000 Subject: connect SIGINT to custom interrupt handler In-Reply-To: References: Message-ID: On Mon, May 16, 2011 at 12:32 AM, Christoph Scheingraber wrote: > I now have signal.siginterrupt(signal.SIGINT, False) in the line > below signal.signal(signal.SIGINT, interrupt_handler) > > Unfortunately, pressing ^c still results in the same interrupt error. I > also tried putting signal.siginterrupt into the interrupt_handler > function, which gave an interesting result: > ? ?File "/usr/local/bin/obspysod", line 586, in interrupt_handler > ? ?signal.siginterrupt(signal.SIGINT, False) > ? ?AttributeError: 'int' object has no attribute 'siginterrupt' > > Could there be a namespace problem? def interrupt_handler(signal, frame): You're using 'signal' as a parameter here. The local int is masking the global module. Chris Angelico From PointedEars at web.de Sun May 15 11:43:40 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 15 May 2011 17:43:40 +0200 Subject: connect SIGINT to custom interrupt handler References: Message-ID: <1691845.hkbZ0PkbqX@PointedEars.de> Christoph Scheingraber wrote: > I now have signal.siginterrupt(signal.SIGINT, False) in the line > below signal.signal(signal.SIGINT, interrupt_handler) > > Unfortunately, pressing ^c still results in the same interrupt error. I > also tried putting signal.siginterrupt into the interrupt_handler > function, which gave an interesting result: > File "/usr/local/bin/obspysod", line 586, in interrupt_handler > signal.siginterrupt(signal.SIGINT, False) > AttributeError: 'int' object has no attribute 'siginterrupt' > > Could there be a namespace problem? Obviously. `signal' refers to an `int' object, probably by something like signal = 42 before. E.g. `print' or a debugger will tell you, as you have not showed the relevant parts of the code. Please trim your quotes to the relevant minimum; DO NOT top-post. Also, it is not acceptable behavior to use domain namespaces without authorization (chris at spam.org is not a mailbox, yet spam.org is registered to someone else). -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From nobody at nowhere.net.no Sun May 15 11:56:58 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 15 May 2011 23:56:58 +0800 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: SigmundV wrote: > I think the OP wants to find the intersection of two lists. > list(set(list1) & set(list2)) is indeed one way to achieve this. [i > for i in list1 if i in list2] is another one Exactly. I was confused on that I wasn't able to have a list in return. The set intersection is the smartest result better than a "for" loop or a comprehension list. Infact the operatin loops are compiled into python, therfore they are the fastest. -- goto /dev/null From nobody at nowhere.net.no Sun May 15 12:05:44 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 16 May 2011 00:05:44 +0800 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Message-ID: Chris Torek wrote: > >>> x = ['three', 'one', 'four', 'one', 'five'] > >>> x > ['three', 'one', 'four', 'one', 'five'] > >>> list(set(x)) > ['four', 'five', 'three', 'one'] Why one *"one"* has purged out? Removing double occurences in a list? -- goto /dev/null From vanboxem.ruben at gmail.com Sun May 15 12:11:43 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Sun, 15 May 2011 18:11:43 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: 2011/5/15 Ruben Van Boxem : > 2011/5/15 Ruben Van Boxem : >> 2011/5/14 Doug Evans : >>> On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem >>> wrote: >>>> 2011/5/14 Doug Evans : >>>>> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem >>>>> wrote: >>>>>> (now in plain-text as required by gdb mailing list) >>>>>> >>>>>> Hi, >>>>>> >>>>>> I am currently trying to integrate Python support into my toolchain >>>>>> build (including GDB of course). It is a sysrooted >>>>>> binutils+GCC+GDB+mingw-w64 toolchain. >>>>>> >>>>>> I currently have the basic setup working: I can link gdb with my >>>>>> manually generated import lib to the python dll from the official >>>>>> Windows install. If there is anything I am missing or a very easy >>>>>> solution to the problems decsribed below, please just say so. I am >>>>>> only suggesting what I would like to happen. >>>>>> >>>>>> Now on to the problems I'd like to discuss: >>>>>> >>>>>> 1. gdb.exe won't start without me having set PYTHONPATH manually. >>>>> >>>>> In a properly configured/built gdb on linux this isn't necessary, even >>>>> if python is installed in some random place. >>>>> I'm not sure about windows though. >>>>> Did you specify --with-python when you configured gdb, and if so did >>>>> you specify a value? >>>>> e.g., --with-python=SOME_VALUE >>>> >>>> I was cross-compiling a mingw toolchain+gdb from Linux, so I used >>>> --with-python without a value (because gdb configure tries to find the >>>> Python executabe), and I added -I"/path/to/python/includes" to CFLAGS >>>> and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it >>>> should. This is hacky though, and gdb configure should provide >>>> --with-python-libs and --with-python-include to make it more >>>> streamlined with any other build prerequisite (like >>>> gmp/mpfr/mpc/cloog/ppl in GCC for example). >>> >>> Ah. >>> Cross-compiling gdb with python is in need of improvement. >>> Alas python hasn't been designed with cross-compilation in mind (e.g. >>> build on linux, run on windows). >>> AIUI, the way to get the parameters required for compiling with >>> libpython is to get them from python's "distutils": kinda hard to do >>> in a cross-compile. ?Done correctly there's no need to run python. >>> >>> I haven't done anything more to support python in gdb's configure.ac >>> because it's not clear to me what the right thing to do is: distutils >>> provides more than just --libs and --includes (btw, we don't use >>> --libs though, we use --ldflags which includes all of: the directory >>> in which to find libpython, the -l for libpython, and the -l's for all >>> the other libraries python needs). [Which isn't to say that someone >>> else isn't free to tackle this.] >>> >>> In the meantime, what I've been doing is a hack: write a script that >>> responds to: >>> --includes >>> --ldflags >>> --exec-prefix >>> and pass that as --with-python. >>> >>> E.g. >>> bash$ cat $HOME/my-python-for-config >>> #! /bin/sh >>> >>> if [ $# -ne 2 ] >>> then >>> ? ? ? ?echo "Bad # args. ?Blech!" >&2 >>> ? ? ? ?exit 1 >>> fi >>> >>> # The first argument is the path to python-config.py, ignore it. >>> >>> case "$2" in >>> --includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;; >>> --ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm >>> -lpython2.6" ;; >>> --exec-prefix) echo "/usr" ;; >>> *) echo "Bad arg $2. ?Blech!" >&2 ; exit 1 ;; >>> esac >>> >>> exit 0 >>> bash$ ./configure --with-python=$HOME/my-python-for-config [...] >>> [...] >>> >>> >>> Note that --exec-prefix is the runtime location of python. >>> GCC uses this to tell libpython where to find its support files. >>> [grep for Py_SetProgramName in gdb/python/python.c] >> >> OK, I tried your script in a couple of variations. It gets rid of the >> traceback I had before, but still doesn't help the PYTHONPATH problem. >> My directory structure is as follows (this is not in root, "/" is just >> my main build directory, there are several levels below it): >> >> /gdb <-- gdb build dir >> /gdb/gdb <-- where the python configuration is done >> /python <-- temporary install dir for python files for build, >> extracted from the official Windows installer, also location of >> libpython2.7.a import library >> /python/include/python27 <-- python headers, found by gdb in both cases >> /mingw64 <-- toolchain sysroot prefix >> /mingw64/bin <-- install location of gdb and python27.dll >> /mingw64/lib/python27 <-- install location of all python scripts >> >> First variant: >> --includes) echo "-I../../python/include" ;; >> --ldflags) echo "-L../../python -lpython2.7" ;; >> --exec-prefix) echo "../../mingw64/lib/python27" ;; >> >> Here exec-prefix would be the relative path from where "configure" >> does its magic to the final location of the scripts on the build >> system. >> >> Second variant: >> --includes) echo "-I../../python/include" ;; >> --ldflags) echo "-L../../python -lpython2.7" ;; >> --exec-prefix) echo "../lib/python27" ;; >> >> I thought the second points gdb to the installed location of the >> python scripts, but it still needed PYTHONPATH for that. I used >> relative paths in an attempt to "do the right thing", hackwise... >> Remember that the whole "/mingw64" directory gets zipped and moved, >> then it gets extracted to a random location in the Windows filesystem. >> >> Thanks for the help so far, I think we might just get this worked out together. >> >> Ruben > > Wow, I think I have a partial solution. Delving into the Python docs, > for example here: > http://docs.python.org/using/windows.html#finding-modules, you can see > that PYTHONPATH is used first, then the Windows registry, then > PYTHONHOME, then some default relative paths. I placed the python > scripts all in the directory structure like so: > > /bin/gdb > /bin/Lib/ > /bin/python27.dll > > This works, even without any manual PYTHONPATH intervention. Problem > is though, that as soon as someone has a PYTHONPATH environment > variable from a (incompatible) Python installation (think different > bitness or version 3.x instead of 2.7.1), I cannot predict what will > go wrong. This problem originates in Python's way of filling in the > search path (sys.path). A true solution in the GDB case to prevent > this collision of an incompatible PYTHONPATH would be that GDB sets an > internal PYTHONPATH as directed by configure, uses that to load its > Python internals, and allows the GDB child processes (apps being > debugged) to use the environment PYTHONPATH. For now, I have a > functional installation, but it will break as soon as someone installs > Python on their system. > > The part your script plays in this (if I haven't misunderstood the > intention/effects of the "--exec-prefix" part) is allowing a uniform > way of directing the configure script to the right directories for > includes/libs. > > Ruben I am sorry for the repeated messages that no one cares about, but I may have discovered GDB in its current form already allows what I want: I tried to figure out what exact paths the snake in gdb was using to search for its modules, and came up with this: (gdb) python import sys (gdb) python print sys.path ['m:\\development\\mingw64\\share\\gdb/python', 'M:\\Development\\mingw64\\bin\\python27.zip', 'M:\\Development\\mingw64\\bin\\DLLs', 'M:\\Development\\mingw64\\bin\\lib', 'M:\\Development\\mingw64\\bin\\lib\\plat-win', 'M:\\Development\\mingw64\\bin\\lib\\lib-tk', 'M:\\Development\\mingw64\\bin', 'M:\\Development\\mingw64\\bin\\lib\\site-packages'] This means that every python command within gdb searches /share/gdb/python FIRST (even before an environment's PYTHONPATH), alleviating any concerns or problems I or anyone would have with another python installation, as this apparently built-in path comes up first. All I, or anyone interested in doing this kind of thing, have to do is copy all the python scripts from the Windows installation's Lib directory to the /share/gdb/python directory. I don't know where this path comes from, but it is quite handy, and makes this whole discussion moot for Python people. Only "issue" that I'll have to work around is the --with-python-includes and --with-python-libs that are missing, using either manual CFLAGS/LDFLAGS or a variant of your script. Thanks for all the help and motivation to keep trying :) Ruben > >> >>> >>>>>> I understand the need for this, but as gdb requires Python 2, and users >>>>>> of my toolchain may have installed Python 3 or a 32-bit version python >>>>>> they want to use from the same environment (without changing their own >>>>>> PYTHONPATH), there is no way to run python-enabled gdb. >>>>>> [...] >>>>> >>>>> Yeah. >>>>> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have >>>>> gdb use that instead of PYTHONPATH if it exists, but there's been >>>>> resistance to it. >>>>> I think(!) what would happen is that gdb would set $PYTHONPATH to the >>>>> value of $GDB_PYTHONPATH. >>>>> [Inferiors started by gdb should still get the original value of >>>>> PYTHONPATH though.] >>>> >>>> That way would be almost ideal, but a hardcoded *relative* path to the >>>> python scripts (that is standardized within gdb) wouldn't hurt. >>> >>> See above re: --exec-prefix. >>> >>>> An >>>> extra environment variable would require a lot of explaining for >>>> Windows, and is not "plug-and-play", like the rest of a sysrooted >>>> toolchain is supposed to be like. I think this should work on all >>>> setups: >>>> >>>> 1. Check hardcoded path; my suggestion would be ">>> executable>/../lib/python27" >>>> 2. If this fails to find the necessary files/scripts, find it like you >>>> described above in Linux, without PYTHONPATH set. >>>> 3. Check PYTHONPATH. >>> >>> The problem being solved by the proposed GDB_PYTHONPATH is "What if >>> the user has PYTHONPATH set and it points to an incompatible version >>> of python?". >>> Leaving such a value for PYTHONPATH set while gdb's python is running >>> feels wrong (and IIRC has caused some problems). >>> >>> The problem of telling python where to find itself is already solved >>> (or at least is intended to be solved) with gdb's calling >>> Py_SetProgramName with a value derived from the python-provided >>> --exec-prefix. >>> >>>> I would think only number one would change, and perhaps be only >>>> enabled with a special configure option. Nothing else would have to >>>> change, and Windows users would rejoice :) >>>> Again, this is only my suggestion, if there are problems with it in >>>> way I haven't thought of, please say so, and we can come up with >>>> another solution. >>> >> > From steve+comp.lang.python at pearwood.info Sun May 15 12:28:05 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2011 16:28:05 GMT Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Message-ID: <4dcfff15$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 May 2011 00:05:44 +0800, TheSaint wrote: > Chris Torek wrote: > >> >>> x = ['three', 'one', 'four', 'one', 'five'] x >> ['three', 'one', 'four', 'one', 'five'] >> >>> list(set(x)) >> ['four', 'five', 'three', 'one'] > > Why one *"one"* has purged out? > Removing double occurences in a list? Break the operation up into two steps instead of one: >>> x = ['three', 'one', 'four', 'one', 'five'] >>> s = set(x) >>> print s set(['four', 'five', 'three', 'one']) >>> list(s) ['four', 'five', 'three', 'one'] Once an element is already in a set, adding it again is a null-op: >>> s = set() >>> s.add(42) >>> s.add(42) >>> s.add(42) >>> print s set([42]) -- Steven From nobody at nowhere.net.no Sun May 15 12:35:55 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 16 May 2011 00:35:55 +0800 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <4dcfff15$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >>>> s = set() >>>> s.add(42) >>>> s.add(42) >>>> s.add(42) >>>> print s > set([42]) Good to know. I'll remember it -- goto /dev/null From spam at scheingraber.net Sun May 15 13:05:57 2011 From: spam at scheingraber.net (Christoph Scheingraber) Date: Sun, 15 May 2011 17:05:57 +0000 (UTC) Subject: connect SIGINT to custom interrupt handler References: <1691845.hkbZ0PkbqX@PointedEars.de> Message-ID: On 2011-05-15, Thomas 'PointedEars' Lahn wrote: > > Obviously. `signal' refers to an `int' object, probably by something like > > signal = 42 > > before. E.g. `print' or a debugger will tell you, as you have not showed > the relevant parts of the code. The problem is that I am running someone else's module which seems to use signal, I guess that means I have to create a child method? Is it correct anyway to have signal.siginterrupt(signal.SIGINT, False) in my custom interrupt_handler function or should it be outside but after signal.signal(signal.SIGINT, interrupt_handler)? > > Please trim your quotes to the relevant minimum; DO NOT top-post. > Also, it is not acceptable behavior to use domain namespaces without > authorization (chris at spam.org is not a mailbox, yet spam.org is > registered to someone else). > I am sorry, I changed it to my own domain. -- Chris Scheingraber - www.scheingraber.net From roy at panix.com Sun May 15 13:07:25 2011 From: roy at panix.com (Roy Smith) Date: Sun, 15 May 2011 13:07:25 -0400 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: In article <34fc571c-f382-405d-94b1-0a673da5f46b at t16g2000vbi.googlegroups.com>, SigmundV wrote: > I think the OP wants to find the intersection of two lists. > list(set(list1) & set(list2)) is indeed one way to achieve this. [i > for i in list1 if i in list2] is another one. Both ways work, but the first is O(n) and the second is O(n^2). import time n = 10000 list1 = range(n) list2 = range(n) t0 = time.time() list(set(list1) & set(list2)) t1 = time.time() print "list(set) method took %f seconds" % (t1 - t0) t0 = time.time() [i for i in list1 if i in list2] t1 = time.time() print "loop method took %f seconds" % (t1 - t0) ./intersect.py 100000 list(set) method took 0.004791 seconds loop method took 1.437322 seconds From rustompmody at gmail.com Sun May 15 13:33:38 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 15 May 2011 10:33:38 -0700 (PDT) Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> On May 15, 10:07?am, Steven D'Aprano wrote: > > I'm afraid I don't understand what you mean. Can you explain please, what > properties of "first class booleans" do you think are missing from Python? Dijkstra's writings I alluded to, take a logic/math line to this. Let me try to rephrase Dijkstra (who is now sadly not able to defend our (mis)understandings of his writings) in a more linguistic way: In English when we say something like "x is y" the y (predicate) can be an adjective phrase -- the apple is red -- or a noun phrase -- the apple is a fruit. They seem similar; they are very different -- you agree?? >From times immemorial 'true' and 'false' have been used in the adjective sense: eg Such-and-such statement is true. Boole's contribution -- actually Dijkstra's recognition of Boole's contribution -- is that dignifying {true, false} from adjectives to nouns -- the boolean domain -- fundamentally alter and improve the rules and possibilities for our thinking. [See his puzzles in the same paper: http://www.google.com/url?sa=D&q=http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html As an analogy for this consider arithmetic. Even primitive people can count: My 3 children, my 5 sheep. They do this with the ordinals -- first child, second child, third child... But arithmetic cannot really take off until we allow these numbers (ordinals) to be dignified into entities in their own right -- cardinals. ie the mathematician needs to believe in the existence of the numbers 1,2 etc for him to do his job well. [As an aside I may mention that philosophers of mathematicians will call this platonism: "In which heaven do these numbers exist?" And platonism is mysticism. And mysticism is bullshit. But the vast majority of practicing mathematicians refuse to be dislodged from their 'platonic heaven.' For them mathematics can only be done if it is done in 'discovery' mode and not in 'invention' mode.] And so just as good math happens by believing that the numbers exist and discovering their properties, good logic happens when we believe that {True, False} exist (in some platonic heaven). Which is to say they should be nouns in our language. Well that in summary is the Boole's ideology (Dijkstra's evangelism) understood linguistically and independent of python/programming. Reapplied back to the math/programming field, we find that if a value- domain (data-type) has to be first-class, it at the least has to be a denotable entity in the language which should be conformable with its abstract/expected properties. For example if my language seems to have entities like '2' '3' '+' but 2+3 does not work out equal to 5 we would (I hope!) not say the language has first-class numbers. But in order for any of this discussion to be possible, equality should be well-defined. Which means that in addition to being an equivalence relation it must have substitutivity http://en.wikipedia.org/wiki/Equality_%28mathematics%29#Some_basic_logical_properties_of_equality which is another form of a very fundamental principle attributed to Leibniz, the principle of identity of indiscernibles: http://en.wikipedia.org/wiki/Leibniz%27s_law Seemingly you and Dijkstra are saying something similar when you say [1,2,3] is a way of writing true and he says 2<3 is a way of writing true. But on further examination (with Leibniz law above) Dijkstra's 2<3 = True will work consistently in all contexts but [1,2,3] = True will work sometimes and fail sometimes. In mathSpeak we say, the definition of bool is not well defined In CSSpeak we say the definition is not first class. In the language of algebraic specifications, the slogan is "No confusion, No junk" eg http://www.informatik.uni-bremen.de/agbkb/lehre/ws06-07/casl/slides/Datatypes-II.pdf This is usually applied to specific models in a given language But it could as well be applied to the models that a language supplies by default. And when we apply it to python's bool as a model of the abstract/math concept bool it has confusion and junk. From dickinsm at gmail.com Sun May 15 15:20:03 2011 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 15 May 2011 12:20:03 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> Message-ID: On May 15, 4:32?am, rusi wrote: > On May 15, 2:19?am, Ian Kelly wrote: > > Yup, linear. ?Assuming you optimize the even case so that it doesn't > > actually call fib(n//2) twice, the call tree can be approximated as a > > balanced binary tree with height log(n). ?The total number of nodes in > > the tree is thus O(2 ** log(n)) = O(n). > > It would be linear if the base of the log were 2. > I am not sure it is. > You see the naive fib has a complexity which is fib itself. [Earlier > discussion with Steven] > fib is exponential but with radix < 2 [phi = (1 + sqrt(5))/2 ] > This would suggest that this algo is slightly better than linear. Nope. It's linear, just as Ian Kelly said. If g(n) is the total number of fib calls made for fib(n), then it's easy to show (e.g., by induction) that: (a) g(n) is an increasing function of n, and (b) g(2^k) = 2^k - 1 for all k >= 1. Hence g(n) is O(n). Mark From hujun.work at gmail.com Sun May 15 15:23:14 2011 From: hujun.work at gmail.com (Jun Hu) Date: Sun, 15 May 2011 12:23:14 -0700 Subject: Get the IP address of WIFI interface In-Reply-To: <4DCFB507.2040007@timgolden.me.uk> References: <4DCFB507.2040007@timgolden.me.uk> Message-ID: Thanks for the tip, it is really helpful! however the class of Win32_NetworkAdapterConfiguration doesn't include the interface type (you can NOT tell if it is a wifi interface), so I change the code a bit like following: import wmi wlan_int_id=None for nic in wmi.WMI().Win32_NetworkAdapter(): if nic.NetConnectionID == "Wireless Network Connection": wlan_int_id=nic.Index break if wlan_int_id<>None: for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): if nic.Index==wlan_int_id: print nic.IPAddress[0] else: print "WLAN interface NOT Found" On Sun, May 15, 2011 at 4:12 AM, Tim Golden wrote: > On 15/05/2011 12:04 PM, Neal Becker wrote: > >> Far.Runner wrote: >> >> Hi python experts: >>> There are two network interfaces on my laptop: one is 100M Ethernet >>> interface, the other is wifi interface, both are connected and has an ip >>> address. >>> The question is: How to get the ip address of the wifi interface in a >>> python >>> script without parsing the output of a shell command like "ipconfig" or >>> "ifconfig"? >>> >>> OS: Windows or Linux >>> >>> F.R >>> >> >> Here's some useful snippits for linux: >> > > ... and for Windows: > > > import wmi > > for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): > print nic.Caption, nic.IPAddress > > > > TJG > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Sun May 15 15:29:38 2011 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 15 May 2011 12:29:38 -0700 (PDT) Subject: Recursion or iteration (was Fibonacci series recursion error) References: <0HFvp.18698$vT3.2042@newsfe06.iad> <6828b506-1e18-4bfa-85c0-caa830daf98a@j13g2000pro.googlegroups.com> <4dcb0943$0$81482$e4fe514c@news.xs4all.nl> <71093cb7-3eb4-47f7-8936-2591cdaf4688@l2g2000prg.googlegroups.com> Message-ID: On May 15, 8:20?pm, Mark Dickinson wrote: > On May 15, 4:32?am, rusi wrote: > > > On May 15, 2:19?am, Ian Kelly wrote: > > > Yup, linear. ?Assuming you optimize the even case so that it doesn't > > > actually call fib(n//2) twice, the call tree can be approximated as a > > > balanced binary tree with height log(n). ?The total number of nodes in > > > the tree is thus O(2 ** log(n)) = O(n). > > > It would be linear if the base of the log were 2. > > I am not sure it is. > > You see the naive fib has a complexity which is fib itself. [Earlier > > discussion with Steven] > > fib is exponential but with radix < 2 [phi = (1 + sqrt(5))/2 ] > > This would suggest that this algo is slightly better than linear. > > Nope. ?It's linear, just as Ian Kelly said. ?If g(n) is the total > number of fib calls made for fib(n), then it's easy to show (e.g., by > induction) that: > > (a) g(n) is an increasing function of n, and > (b) g(2^k) = 2^k - 1 for all k >= 1. > > Hence g(n) is O(n). Hmm. It's even easier: g(n) is: * 1 if n == 1 * n if n > 1, n odd * n-1 if n > 1, n even So definitely linear. :-) -- Mark From mail at timgolden.me.uk Sun May 15 15:38:40 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 15 May 2011 20:38:40 +0100 Subject: Get the IP address of WIFI interface In-Reply-To: References: <4DCFB507.2040007@timgolden.me.uk> Message-ID: <4DD02BC0.60005@timgolden.me.uk> On 15/05/2011 20:23, Jun Hu wrote: > Thanks for the tip, it is really helpful! > however the class of Win32_NetworkAdapterConfiguration doesn't include > the interface type (you can NOT tell if it is a wifi interface), so I > change the code a bit like following: > > import wmi > > wlan_int_id=None > for nic in wmi.WMI().Win32_NetworkAdapter(): > if nic.NetConnectionID == "Wireless Network Connection": > wlan_int_id=nic.Index > break > > if wlan_int_id<>None: > for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): > if nic.Index==wlan_int_id: > print nic.IPAddress[0] > else: > print "WLAN interface NOT Found" Glad it was useful; you can get a little bit prettier: import wmi c = wmi.WMI () for nic in c.Win32_NetworkAdapter ( NetConnectionID="Wireless Network Connection" ): for config in nic.associators ( wmi_result_class="Win32_NetworkAdapterConfiguration" ): print config.Caption, "=>", " / ".join (config.IPAddress) break else: print "No Wireless NIC found" TJG From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sun May 15 16:27:34 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sun, 15 May 2011 22:27:34 +0200 Subject: Converting a set into list In-Reply-To: References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: Am 15.05.2011 17:56 schrieb TheSaint: > SigmundV wrote: > >> I think the OP wants to find the intersection of two lists. >> list(set(list1)& set(list2)) is indeed one way to achieve this. [i >> for i in list1 if i in list2] is another one > > Exactly. I was confused on that I wasn't able to have a list in return. > The set intersection is the smartest result better than a "for" loop or a > comprehension list. I'm not sure about if it is really the smartest way. s=set(list2); [i for i in list1 if i in s] is in the same order of magnitude as the set operation. Both solutions seem to be equivalent in that concerns the number of needed loop runs, but this two-step operation might require one less loop over list1. The set&set solution, in contrary, might require one loop while transforming to a set and another one for the & operation. > Infact the operatin loops are compiled into python, therfore they are the > fastest. Which loops do you mean here? Thomas From bahamutzero8825 at gmail.com Sun May 15 16:45:29 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 15 May 2011 15:45:29 -0500 Subject: Trying to understand html.parser.HTMLParser Message-ID: <4DD03B69.6050301@gmail.com> I'm trying to understand why HMTLParser.feed() isn't returning the whole page. My test script is this: import urllib.request import html.parser class MyHTMLParser(html.parser.HTMLParser): def handle_starttag(self, tag, attrs): if tag == 'a' and attrs: print(tag,'-',attrs) url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth' page = urllib.request.urlopen(url).read() parser = MyHTMLParser() parser.feed(str(page)) I can do print(page) and get the entire HTML source, but parser.feed(str(page)) only spits out the information for the top links and none of the "revisionxxxx" links. Ultimately, I just want to find the name of the first "revisionxxxx" link (right now it's "revision1995", when a new build is uploaded it will be "revision2000" or whatever). I figure this is a relatively simple page; once I understand all of this, I can move on to more complicated pages. I've searched Google, but everything I find is either outdated, a recommendation for some external module (I don't need to do anything too fancy and most modules don't completely support Python 3 anyway) or is just a code snippet with no real explanation. I had a book that explained this, but I had to return it to the library (and I'll have to get back in line to check it out again). From tjreedy at udel.edu Sun May 15 16:53:07 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 May 2011 16:53:07 -0400 Subject: dict: retrieve the original key by key In-Reply-To: <87sjsgutqg.fsf@falma.de> References: <874o4wwenu.fsf@falma.de> <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> <87sjsgutqg.fsf@falma.de> Message-ID: On 5/15/2011 6:46 AM, Christoph Groth wrote: > Steven D'Aprano writes: > >> On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: >> >>> I would like to avoid having _multiple_ objects which are equal (a == >>> b) but not the same (a is not b). This would save a lot of memory. Python hashed collections have methods used to test if the collection has an item/key that is equal to some object. They do not currently have a method to return the equal item/key already there. This has been proposed and, I believe, rejected due to lack of sufficient presented use cases or because, conceptually, one wants to map key values to an object with the key value and Stephen's identity dict does precisely that. In any case, if you put an object into a collection and you want to use the object for other purposes without accessing the collection, you must keep a reference to it outside of the collection. >> Based on the idea of interning, which is used for Python strings: >> >> cache = {} def my_intern(obj): >> return cache.setdefault(obj, obj) >> >> >> x = make_some_object() x = my_intern(x) >> >> This ensures that equal objects in the graph are not just equal, but >> the same cached object. > > This requires another dictionary, though. It does, however, twice reuse the key already in your graph dict, so each entry is minimal extra memory. It is typical in graph algorithms to have both a graph map (nodes to set of nodes) and a properties map (nodes to property structure). Some properties are fixed, others are changed during particular algoritms. It is also typical to use counts as node identifiers, so that both maps are implemented as sequences, but string indentifiers and dict for maps work too. > But hey, they keys of my dictionary are actually strings, so I can use > the built-in intern. Somehow, I have never stumbled accross this > built-in function so far. It was, however, removed in 3.x as a seldom-externally-used internal implementation detail. -- Terry Jan Reedy From bahamutzero8825 at gmail.com Sun May 15 17:14:18 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 15 May 2011 16:14:18 -0500 Subject: Get the IP address of WIFI interface In-Reply-To: <4DCFB507.2040007@timgolden.me.uk> References: <4DCFB507.2040007@timgolden.me.uk> Message-ID: <4DD0422A.8030008@gmail.com> On 2011.05.15 06:12 AM, Tim Golden wrote: > ... and for Windows: > > > import wmi > > for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): > print nic.Caption, nic.IPAddress > > One thing I found out about Win32_NetworkAdapterConfiguration is that it only contains /current/ information and not the stored info that it uses when making an initial connection (you can see and edit this info in the Network and Sharing Center applet). The difference is that if you're offline, that WMI object will have no useful info at all. You can find the info in the registry if you know what the UUID (or whatever it is) of (or assigned to) the interface (it's in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces). The OP said the card would be connected, so it might not be an issue, but I think it's important to know that. Wouldn't want you to suddenly get blank strings or exceptions and not know why. ;-) From clp2 at rebertia.com Sun May 15 17:19:42 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 May 2011 14:19:42 -0700 Subject: dict: retrieve the original key by key In-Reply-To: References: <874o4wwenu.fsf@falma.de> <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> <87sjsgutqg.fsf@falma.de> Message-ID: On Sun, May 15, 2011 at 1:53 PM, Terry Reedy wrote: > On 5/15/2011 6:46 AM, Christoph Groth wrote: >> But hey, they keys of my dictionary are actually strings, so I can use >> the built-in intern. ?Somehow, I have never stumbled accross this >> built-in function so far. > > It was, however, removed in 3.x as a seldom-externally-used internal > implementation detail. Still exists in sys module though: http://docs.python.org/dev/library/sys.html#sys.intern Cheers, Chris From tjreedy at udel.edu Sun May 15 17:36:01 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 May 2011 17:36:01 -0400 Subject: checking if a list is empty In-Reply-To: <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> Message-ID: On 5/15/2011 1:33 PM, rusi wrote: > On May 15, 10:07 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> >> I'm afraid I don't understand what you mean. Can you explain please, what >> properties of "first class booleans" do you think are missing from Python? Given the usual CS definition of 'first class object', all Python objects are first class. But that does not preclude other definitions. > Dijkstra's writings I alluded to, take a logic/math line to this. Let > me try to rephrase Dijkstra (who is now sadly not able to defend our > (mis)understandings of his writings) in a more linguistic way: > > In English when we say something like "x is y" the y (predicate) can > be an adjective phrase -- the apple is red -- or a noun phrase -- the > apple is a fruit. > > They seem similar; they are very different -- you agree?? Sometimes. Sometimes it could mean 'the apple is fruity' or 'the apple has the characters that define the wider grouping of fruits'. "John is brilliant", "John is a brilliant man", and "John is a genius" (there is no 'a brilliant') pretty much have the same effective meaning. But I get the point about reification. >> From times immemorial 'true' and 'false' have been used in the > adjective sense: eg Such-and-such statement is true. > Boole's contribution -- actually Dijkstra's recognition of Boole's > contribution -- is that dignifying {true, false} from adjectives to > nouns -- the boolean domain -- fundamentally alter and improve the > rules and possibilities for our thinking. [See his puzzles in the same > paper: > http://www.google.com/url?sa=D&q=http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > > As an analogy for this consider arithmetic. > > Even primitive people can count: My 3 children, my 5 sheep. They do > this with the ordinals -- first child, second child, third child... > But arithmetic cannot really take off until we allow these numbers > (ordinals) to be dignified into entities in their own right -- > cardinals. > ie the mathematician needs to believe in the existence of the numbers > 1,2 etc for him to do his job well. > > [As an aside I may mention that philosophers of mathematicians will > call this platonism: "In which heaven do these numbers exist?" > And platonism is mysticism. And mysticism is bullshit. But the vast > majority of practicing mathematicians refuse to be dislodged from > their 'platonic heaven.' For them mathematics can only be done if it > is done in 'discovery' mode and not in 'invention' mode.] > > And so just as good math happens by believing that the numbers exist > and discovering their properties, good logic happens when we believe > that {True, False} exist (in some platonic heaven). Which is to say > they should be nouns in our language. > > Well that in summary is the Boole's ideology (Dijkstra's evangelism) > understood linguistically and independent of python/programming. > > Reapplied back to the math/programming field, we find that if a value- > domain (data-type) has to be first-class, it at the least has to be a > denotable entity in the language which should be conformable with its > abstract/expected properties. > For example if my language seems to have entities like '2' '3' '+' but > 2+3 does not work out equal to 5 we would (I hope!) not say the > language has first-class numbers. You seem to equate 'number' with 'natural number' in the classical sense. If '2' and '3' are residue classes (remainers) mod 5, then 2 + 3 is 0. Even kids understand clock arithmetics. Of course, the 24 hour (0 to 23 hourse) is saner than the older 1-12,am/pm system, but kids even manage with that. > But in order for any of this discussion to be possible, equality > should be well-defined. > Which means that in addition to being an equivalence relation it must > have substitutivity > http://en.wikipedia.org/wiki/Equality_%28mathematics%29#Some_basic_logical_properties_of_equality > which is another form of a very fundamental principle attributed to > Leibniz, the principle of identity of indiscernibles: > http://en.wikipedia.org/wiki/Leibniz%27s_law > > Seemingly you and Dijkstra are saying something similar when you say > [1,2,3] is a way of writing true > and he says 2<3 is a way of writing true. > But on further examination (with Leibniz law above) Dijkstra's 2<3 = > True will work consistently in all contexts In general, a < b will work consistently as generally expected of total orders if, but only if, a and b are members of a totally ordered set and < indicates that total order. If '<' represents a partial order, 'a but [1,2,3] = True will work sometimes and fail sometimes. 'Bool() is a much a spelling of true or false as 'a < b'. It works just as consistently in all contexts. *nornal expression: evaluates to an object with a well-defined boolean value, which is to say, causes bool() to return True or False. > In mathSpeak we say, the definition of bool is not well defined The math definition of bool or the Python definition? And what definition of 'well-defined'? On builtins, bool(ob) always returns the same value. And the values are pretty consistent. > In CSSpeak we say the definition is not first class. What CS definition? -- Terry Jan Reedy From hujun.work at gmail.com Sun May 15 19:07:20 2011 From: hujun.work at gmail.com (Jun Hu) Date: Sun, 15 May 2011 16:07:20 -0700 Subject: Get the IP address of WIFI interface In-Reply-To: <4DD0422A.8030008@gmail.com> References: <4DCFB507.2040007@timgolden.me.uk> <4DD0422A.8030008@gmail.com> Message-ID: On Sun, May 15, 2011 at 2:14 PM, Andrew Berg wrote: > > One thing I found out about Win32_NetworkAdapterConfiguration is that it > only contains /current/ information and not the stored info that it uses > when making an initial connection (you can see and edit this info in the > Network and Sharing Center applet). The difference is that if you're > offline, that WMI object will have no useful info at all. You can find > the info in the registry if you know what the UUID (or whatever it is) > of (or assigned to) the interface (it's in > > HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces). > The OP said the card would be connected, so it might not be an issue, > but I think it's important to know that. Wouldn't want you to suddenly > get blank strings or exceptions and not know why. ;-) > > Thanks for the reminder, however, it seems the IPAddress of Win32_NetworkAdapterConfiguration will be 0.0.0.0 if the interface is NOT connected (at least that is the result on my winxp), so I think we are safe here. ^_^ -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sun May 15 20:00:01 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 16 May 2011 12:00:01 +1200 Subject: turn monitor off and on In-Reply-To: References: Message-ID: <93b7o1Fb92U1@mid.individual.net> Terry Reedy wrote: > My monitor then displays 'No > signal detected' in a box and puts itself into a low-power state > awaiting a signal. Even if the monitor does not do that, a black screen > should use less power. I'm not so sure about that. If the monitor is an LCD and isn't doing anything to reduce its own power usage, then the backlight is still running and using just as much power, whether the screen is black or not. -- Greg From steve+comp.lang.python at pearwood.info Sun May 15 20:36:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2011 00:36:19 GMT Subject: checking if a list is empty References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> Message-ID: <4dd07182$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 May 2011 10:33:38 -0700, rusi wrote: > On May 15, 10:07?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> >> I'm afraid I don't understand what you mean. Can you explain please, >> what properties of "first class booleans" do you think are missing from >> Python? [snip] I'm afraid I didn't find your discussion about reification, Platonism and linguistics very helpful. Some of it I disagree with, some I agree with, but in neither case do I see any relevance to the question of whether bools are first class objects in Python, and if not, why not. > Reapplied back to the math/programming field, we find that if a value- > domain (data-type) has to be first-class, it at the least has to be a > denotable entity in the language which should be conformable with its > abstract/expected properties. Now you're getting somewhere! > For example if my language seems to have entities like '2' '3' '+' but > 2+3 does not work out equal to 5 we would (I hope!) not say the language > has first-class numbers. Well, that's a problem. By that definition, floats are not first class numbers. While 2+3 does work out to be equal to 5, other standard properties of the real number system do not apply: >>> 0.3 + 0.4 - 0.3 == 0.4 False Similarly, in many languages (including older versions of Python), neither are integers: >>> 2147483647 + 1 Traceback (innermost last): File "", line 1, in ? OverflowError: integer addition Other languages may wrap around, giving -1 or -2147483648. So it seems that either we're forced to accept that neither floats nor integers are "first class", or instead back-track and ask: "Hang on, who decides what the expected properties are?" > But in order for any of this discussion to be possible, equality should > be well-defined. > Which means that in addition to being an equivalence relation it must > have substitutivity Can you show us a problem that is hard to solve in Python because ([1,2] and True) evaluates as True, but ([1,2] == True) evaluates as False? > http://en.wikipedia.org/wiki/Equality_%28mathematics% 29#Some_basic_logical_properties_of_equality > which is another form of a very fundamental principle attributed to > Leibniz, the principle of identity of indiscernibles: > http://en.wikipedia.org/wiki/Leibniz%27s_law But Python truth values are not indiscernible. Do you think they must be? If they are indiscernible, there can only be two unique values (possibly spelled "Veritas" and "Falsus" to avoid confusion with Python's True and False). But why must they be indiscernible? > Seemingly you and Dijkstra are saying something similar when you say > [1,2,3] is a way of writing true > and he says 2<3 is a way of writing true. But on further examination > (with Leibniz law above) Dijkstra's 2<3 = True will work consistently in > all contexts but [1,2,3] = True will work sometimes and fail sometimes. Please do not arbitrarily mix Python and mathematics syntax. What you have stated gives a SyntaxError. [1,2,3] == True will work always, or you have a very buggy version of Python. It will always return False, as expected. I suspect that in a boolean context, the operator you want is material biconditional, or XNOR, also known as "p if and only if q". Python does not have this as a built-in, but it's easy enough to write it: def xnor(p, q): if p: return q else: return p if q else True (I have deliberately written it to return one of the two arguments when possible. If you don't care for this behaviour, the else clause is even simpler: return not q) If you don't like the name XNOR, rename it "equals" and be done. Nobody says that equality *must* be spelled with = or == as an infix operator. That would be a foolish insistence. Another way would be to compare the canonical truth values for equality: bool(p) == bool(q) but of course there's nothing special about the canonical truth values except ease of use. One could choose any other values: def canonical(flag): if flag: return "Nobody expects the Spanish Inquisition!!!" else: return None canonical(p) == canonical(q) The important thing is that Python's sense of equality doesn't just apply in the boolean domain, it applies to the broader any-arbitrary-Python- object domain. Python's equals is too powerful to be limited to Python's truth values: it needs to distinguish between 42 and 23, while in the boolean domain one need not. Consequently, if you want equality in the boolean domain, you need to use something other than the built-in == operator. Python doesn't allow you to override == for built-in objects, so the simplest, most straight- forward way is with a function. Using such a function: >>> equals = xnor >>> equals( equals([1, 2], 42), equals("spam", 23) ) 23 which is, naturally, just another way of spelling True. > In mathSpeak we say, the definition of bool is not well defined In > CSSpeak we say the definition is not first class. That is not the normal definition of "first class" in computer science. The normal definition relates to whether a data type can be assigned to variables, passed to functions, and otherwise treated like ints or floats or other "first class" types. That certainly applies to truth values in Python, and bools. > In the language of algebraic specifications, the slogan is "No > confusion, No junk" > eg > http://www.informatik.uni-bremen.de/agbkb/lehre/ws06-07/casl/slides/ Datatypes-II.pdf > > This is usually applied to specific models in a given language > > But it could as well be applied to the models that a language supplies > by default. > And when we apply it to python's bool as a model of the abstract/math > concept bool it has confusion and junk. Well there is certainly confusion, but it's not in Python's model. The confusion seems to entirely rest in your mistake in thinking that the only valid way to do an equality test is with the built-in == syntax. -- Steven From jorgeromero178 at gmail.com Sun May 15 20:42:07 2011 From: jorgeromero178 at gmail.com (Jorge Romero) Date: Sun, 15 May 2011 20:42:07 -0400 Subject: MySQLdb SEC_TO_TIME function returns datetime.timedelta class Message-ID: Hi Pythonists, I'm retrieving some time data from a MySQL database using Python's MySQLdb library. Here's the situation, I got a time field on MySQL given in seconds, I need it on HH:MM:SS format, so I'm SELECTING that field with SEC_TO_TIME function, something like this: query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table" fetched = cursor.execute(query) return fetched[0] The result of the query is given to me as *datetime.timedelta *type, which has an undesired print behavior for my purposes: >>> query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table" >>> fetched = cursor.execute(query) >>> print fetched[0] 3 days, 7:30:09 >>> print type(fetched[0]) Instead of *datetime.timedelta *I need *datetime.time *type. Does anybody knows how to change this behavior or is it something I must deal with my code? Thanks in advanced. -- Jorge Romero -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sun May 15 20:47:45 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 15 May 2011 18:47:45 -0600 Subject: dict: retrieve the original key by key In-Reply-To: <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <874o4wwenu.fsf@falma.de> <4dcfa885$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 15, 2011 at 4:18 AM, Steven D'Aprano wrote: > On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: > >> I would like to avoid having _multiple_ objects which are equal (a == b) >> but not the same (a is not b). ?This would save a lot of memory. > > Based on the idea of interning, which is used for Python strings: > > cache = {} > def my_intern(obj): > ? ?return cache.setdefault(obj, obj) And if the idea of a dictionary with identical keys and values offends, you can also use a set: cache = set() def my_intern(obj): cache.add(obj) return cache.intersection([obj]).pop() Cheers, Ian From timr at probo.com Sun May 15 20:50:59 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 15 May 2011 17:50:59 -0700 Subject: Question about available python lib for a task References: Message-ID: <9os0t6pa69gl9e1uhvts087s8d2re4jr4v@4ax.com> cesium5500 at yahoo.ca wrote: > >I would like to build a database of all the MS-Excel file on a LAN. I >would like to get the files metadata : filename, summary, location, >size, etc. > >Is there a dedicated python lib for the task? No. The file name, location, and size are all completely generic. You can do that with standard Python and the os.walk command. The document properties (like the summary) can be accessed in a couple of ways. You can do it in Excel by opening the application, opening the document, and using the BuiltinDocumentProperties collection. Or, you can do it without Excel, using the COM interfaces for "structured storage", like IPropertySetStorage and IPropertyStorage. >Is pywin32 one of the possible lib available? You will need PyWin32 in order to use COM to launch Excel, or use the structured storage interfaces. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From drobinow at gmail.com Sun May 15 21:06:49 2011 From: drobinow at gmail.com (David Robinow) Date: Sun, 15 May 2011 21:06:49 -0400 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD03B69.6050301@gmail.com> References: <4DD03B69.6050301@gmail.com> Message-ID: On Sun, May 15, 2011 at 4:45 PM, Andrew Berg wrote: > I'm trying to understand why HMTLParser.feed() isn't returning the whole > page. My test script is this: > > import urllib.request > import html.parser > class MyHTMLParser(html.parser.HTMLParser): > ? ?def handle_starttag(self, tag, attrs): > ? ? ? ?if tag == 'a' and attrs: > ? ? ? ? ? ?print(tag,'-',attrs) > > url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth' > page = urllib.request.urlopen(url).read() > parser = MyHTMLParser() > parser.feed(str(page)) > > I can do print(page) and get the entire HTML source, but > parser.feed(str(page)) only spits out the information for the top links > and none of the "revisionxxxx" links. Ultimately, I just want to find > the name of the first "revisionxxxx" link (right now it's > "revision1995", when a new build is uploaded it will be "revision2000" > or whatever). I figure this is a relatively simple page; once I > understand all of this, I can move on to more complicated pages. You've got bad HTML. Look closely and you'll see the there's no space between the "revisionxxxx" strings and the style tag following. The parser doesn't like this. I don't know a solution other than fixing the html. (I created a local copy, edited it and it worked.) From harrismh777 at charter.net Sun May 15 21:25:44 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 20:25:44 -0500 Subject: checking if a list is empty In-Reply-To: <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> Message-ID: rusi wrote: > But on further examination (with Leibniz law above) Dijkstra's 2<3 = > True will work consistently in all contexts but [1,2,3] = True will > work sometimes and fail sometimes. It would have to be written 2<3 == True; [1,2,3] == True; otherwise, ... +1 QOTW From mrjean1 at gmail.com Sun May 15 21:42:32 2011 From: mrjean1 at gmail.com (MrJean1) Date: Sun, 15 May 2011 18:42:32 -0700 (PDT) Subject: Get the IP address of WIFI interface References: <4DCFB507.2040007@timgolden.me.uk> Message-ID: <537d5138-2dc1-422a-8ebc-24a76270f2ce@k27g2000pri.googlegroups.com> Perhaps, this recipe works for your case: It does parse ifconfig and ipconfig, if found. /Jean On May 15, 2:14?pm, Andrew Berg wrote: > On 2011.05.15 06:12 AM, Tim Golden wrote:> ... and for Windows: > > > > > import wmi > > > for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): > > ? ?print nic.Caption, nic.IPAddress > > > > > One thing I found out about Win32_NetworkAdapterConfiguration is that it > only contains /current/ information and not the stored info that it uses > when making an initial connection (you can see and edit this info in the > Network and Sharing Center applet). The difference is that if you're > offline, that WMI object will have no useful info at all. You can find > the info in the registry if you know what the UUID (or whatever it is) > of (or assigned to) the interface (it's in > HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Inter faces). > The OP said the card would be connected, so it might not be an issue, > but I think it's important to know that. Wouldn't want you to suddenly > get blank strings or exceptions and not know why. ;-) From harrismh777 at charter.net Sun May 15 21:42:46 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 20:42:46 -0500 Subject: problem with GKT module? In-Reply-To: References: Message-ID: Alister Ware wrote: > I have a simple call back defined for a radio button widget when I use >> widget.name in linux I get a value of None, windows returns the widget >> name as I would expect. >> First, not familiar with your issue... ... but might be able to help you think through it... I am assuming that you are building a Python script using a glade interface that provides the widgets drag-an-drop style and then allowing you to take the default code, add to it, or otherwise modify it. I am also assuming that the /call back/ is returning a Python None, on the linux platform... otherwise you're getting the widget name from the same script on the windows platform?? right? It might be helpful to examine both scripts to see where (if any) they differ. More likely than not, this little snag is a difference in the way that the windows version of gtk+ libraries are working, than the original ones on the linux platform. On the other hand, the Python wrappers for the gtk+ library on the linux platform may be hiding the return values. Python functions return 'None' if the 'return' is not explicitly coded. The gtk+ libraries may be returning a value but the 'builder' is not generating the right Python wrapper. I'm making this up, but you get the idea, and you can probably check from here. On the other hand, folks here can enter into a discussion with you regarding the generated Python code (output from the builder) if you provide relevant code snippets. Kind regards, m harris From harrismh777 at charter.net Sun May 15 21:48:37 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 20:48:37 -0500 Subject: turn monitor off and on In-Reply-To: <93b7o1Fb92U1@mid.individual.net> References: <93b7o1Fb92U1@mid.individual.net> Message-ID: Gregory Ewing wrote: > I'm not so sure about that. If the monitor is an LCD and isn't > doing anything to reduce its own power usage, then the backlight > is still running and using just as much power, whether the screen > is black or not. Depends on dpmi. Some monitors turn off the backlight, and some don't. My monitor(s) that are LCD turn off the backlight... and the downside of that (very annoying) is that they have to 'warm up' again... making them dim for the first few seconds of use... An LED flat panel is a completely different animal, because there is no backlight (no ccfl). They monitors don't use much power in the first place, but they use less when they're blank, obviously, not producing light. kind regards, m harris From tjreedy at udel.edu Sun May 15 21:57:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 May 2011 21:57:39 -0400 Subject: checking if a list is empty In-Reply-To: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroup s.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> Message-ID: On 5/15/2011 5:36 PM, Terry Reedy wrote: > On 5/15/2011 1:33 PM, rusi wrote: >> Dijkstra's writings I alluded to, at http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html "Acquiring that familiarity requires what in these financial times is known as "intellectual investment"; you can take my word for it that this investment quickly pays off." I recommend understanding the following as three more "intellectual investments": We create a Boolean domain by drawing a distinction in some domain and treating everything on each side of the distinction as equal in some value. A Boolean value or variable represents such a dichotomy, a choice between two all-inclusive but mutually exclusive possibilities. Boole derived his domain from truth/falsity of propositions. But that is an interpretation of his abstract model and only one of endless possibilities. This realization that switching networks are another interpretation is the basis of digital computation. Boolean algebra theorems are theorems about switching networks and can be used to design such networks. Such networks can be used to do boolean arithmetic. The trick is to coerce physical components into one of two states. Part of the trick is to not look when they are transiting between them. For its built-in information objects, Python choose 'representation of something' versus 'representation of nothing' as the dichotomy. It matches 'something' to True and 'nothing' to False as this is generally more useful than the opposite matching. In boolean contexts, it automatically fetches the boolean value of an object. -- Terry Jan Reedy From harrismh777 at charter.net Sun May 15 21:59:28 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 20:59:28 -0500 Subject: checking if a list is empty In-Reply-To: <4dd07182$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> <4dd07182$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4y%zp.4255$iv4.1254@newsfe09.iad> Steven D'Aprano wrote: > I'm afraid I don't understand what you mean. Can you explain please, >>> http://www.informatik.uni-bremen.de/agbkb/lehre/ws06-07/casl/slides/Datatypes-II.pdf Geeze, I wonder if software is mathematics.... kind regards, m harris From tyler at tysdomain.com Sun May 15 22:04:16 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 15 May 2011 20:04:16 -0600 Subject: obviscating python code for distribution Message-ID: <4DD08620.4030507@tysdomain.com> Hello all: I have been considering writing a couple of programs in Python, but I don't want to distribute the code along with them. So I'm curious of a couple things. First, does there exist a cross-platform library for playing audio files, whose license I would not be violating if I do this? Second, would I be violating the twisted, wxpython licenses by doing this? Finally, is there a good way to accomplish this? I know that I can make .pyc files, but those can be disassembled very very easily with the disassembler and shipping these still means that the person needs the modules that are used. Is there another way to go about this? -- Take care, Ty my website: http://tds-solutions.net my blog: http://tds-solutions.net/blog skype: st8amnd127 ?Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.? ?If Java had true garbage collection, most programs would delete themselves upon execution.? From akabaila at pcug.org.au Sun May 15 22:17:00 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Mon, 16 May 2011 12:17:00 +1000 Subject: checking if a list is empty In-Reply-To: References: Message-ID: <201105161217.00473.akabaila@pcug.org.au> On Friday 13 May 2011 18:47:50 Hans Georg Schaathun wrote: > On Thu, 12 May 2011 23:20:20 +1000, Chris Angelico > > wrote: > : Writing a program requires expertise both in programming snip... > > And the main difference here, is that the civil engineers > have a much better language to share information. The best > programmers have is the programming language, and we ought > to make that as good as possible. As an old Civil Engineer and a retired educator of Civil and Aeronautical Engineers, I want to get at the end of the long thread. Early in the thread I (wrongly) thought that the discussion just did not make sense. Much as has been said, makes a good sense, though some of it is hardly relevant. So what is the purpose of this discussion - is it to proffer advice to the "Benevolent Dictator for life" and to his cohort or is it to better understand the programming language Python? In relation to the first part of the question is that the aim is far too ambitious - the success of Python language is enough to suggest that Guido and his team do not need advice and they will ask for it if they really do want to hear the opinions about it. The job they have done in developing the language is admirable and the users better concentrate on trying to understand it better. The second part of the (rhetorical) question is that the answer depends what the designers of Python have chosen as criterion for "True" or "False". In my little effort to present Vector algebra in an easy to use manner (refer to thread of yesterday: "Python 3.2 Vectors.py module") it was necessary to answer the question of what could and what should be used to determine what the instruction '==' or '>=' should mean and what should be used for comparison. The only one that I could find useful was the equality - two vectors are equal if and only if all three of their components are equal. As the components (for purposes of engineering analysis) are real numbers, even the postulation of (v1.x == v2.x) is problematic, as has been pointed out in the thread (as the "floats" are subject to unavoidable round off errors). So the answers are not necessarily unique and one must consider what the program is supposed to achieve. BTW, the "Vector" class inherits from the list, which avoids "reinventing the wheel". The other operators are assigned specific purposes, viz. v1 * v2 is a scalar product of two vectors (the result is a scalar, float), while v1 * r (where v1 is a vector and r is a float) is scaling the size of vector by factor r, (the result is a vector) i.e. each component of v1 is multiplied by r. Vector product (cross product) is shown as v1 ** v2 (the result is a vector). The purpose of choosing this scheme is neither linguistic, nor philosophical - it is practical, just as the vector algebra is practical. It helps to visualise solutions of physical problems (or, if you prefer, engineering problems). OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan.kluev at gmail.com Sun May 15 22:21:00 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 16 May 2011 13:21:00 +1100 Subject: obviscating python code for distribution In-Reply-To: <4DD08620.4030507@tysdomain.com> References: <4DD08620.4030507@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 1:04 PM, Littlefield, Tyler wrote: > Hello all: > Finally, is there a good way to accomplish this? I know that I can make .pyc > files, but those can be disassembled very very easily with the disassembler > and shipping these still means that the person needs the modules that are > used. Is there another way to go about this? No, there is no way to prevent users from getting access to raw python sources. By its nature and design, python is not meant to be used this way, and even obfuscation would not harm readability much. However, you can write all parts you want to hide in C/C++/Cython and distribute them as .so/.dll -- With best regards, Daniel Kluev From nobody at nowhere.com Sun May 15 22:28:31 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 16 May 2011 03:28:31 +0100 Subject: connect SIGINT to custom interrupt handler References: <1691845.hkbZ0PkbqX@PointedEars.de> Message-ID: On Sun, 15 May 2011 17:05:57 +0000, Christoph Scheingraber wrote: > Is it correct anyway to have > > signal.siginterrupt(signal.SIGINT, False) > > in my custom interrupt_handler function No. > or should it be outside but after > signal.signal(signal.SIGINT, interrupt_handler)? Yes. From prologic at shortcircuit.net.au Sun May 15 22:36:56 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 16 May 2011 12:36:56 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 12:21 PM, Daniel Kluev wrote: > No, there is no way to prevent users from getting access to raw python > sources. By its nature and design, python is not meant to be used this > way, and even obfuscation would not harm readability much. > However, you can write all parts you want to hide in C/C++/Cython and > distribute them as .so/.dll Or you could do what everyone else is doing and provide your "application" as a service in some manner. cheers James -- -- James Mills -- -- "Problems are solved by method" From dan.kluev at gmail.com Sun May 15 22:37:17 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 16 May 2011 13:37:17 +1100 Subject: Converting a set into list In-Reply-To: References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: > Both solutions seem to be equivalent in that concerns the number of needed loop runs, but this two-step operation might require one less loop over list1. > The set&set solution, in contrary, might require one loop while transforming to a set and another one for the & operation. python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" "l3 = list(set(l1) & set(l2))" 100 loops, best of 3: 2.19 msec per loop python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" "s=set(l2); l3 = [i for i in l1 if i in s]" 100 loops, best of 3: 2.45 msec per loop python -m timeit -s "l1 = range(1, 100000); l2 = range(50000, 150000)" "l3 = list(set(l1) & set(l2))" 10 loops, best of 3: 28 msec per loop python -m timeit -s "l1 = range(1, 100000); l2 = range(50000, 150000)" "s=set(l2); l3 = [i for i in l1 if i in s]" 10 loops, best of 3: 28.1 msec per loop So even with conversion back into list set&set is still marginally faster. -- With best regards, Daniel Kluev From nobody at nowhere.com Sun May 15 22:53:22 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 16 May 2011 03:53:22 +0100 Subject: connect SIGINT to custom interrupt handler References: Message-ID: On Sun, 15 May 2011 14:32:13 +0000, Christoph Scheingraber wrote: > I now have signal.siginterrupt(signal.SIGINT, False) in the line > below signal.signal(signal.SIGINT, interrupt_handler) > > Unfortunately, pressing ^c still results in the same interrupt error. Sorry; I wasn't paying sufficient attention to the details: >>> select.error: (4, 'Interrupted system call') According to Linux' signal(7) manpage, select() is never restarted, regardless of the siginterrupt() setting. In general, wait-for-something functions aren't restarted; the caller is expected to check that the waited-for condition actually happened, so returning prematurely isn't considered problematic. EINTR is one of those "special" errors (like EAGAIN) which don't actually indicate an error. In the context of select(), a return value of -1 with errno set to EINTR should normally be handled in the same way as a return value of zero, i.e. "nothing has happened yet, try again". While the EINTR case isn't identical to the zero-return case, it's much closer to it than it is to a genuine error. If it's being treated like genuine errors (i.e. raising an exception), that's a defect in the Python bindings. In which case, I'd suggest catching the exception and checking the error code, e.g.: def myselect(rlist, wlist, xlist, timeout = None): try: return select.select(rlist, wlist, xlist, timeout) except select.error, e: if e[0] == errno.EINTR: return 0 raise From ben+python at benfinney.id.au Sun May 15 23:29:49 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 16 May 2011 13:29:49 +1000 Subject: obviscating python code for distribution References: Message-ID: <87boz3gw5u.fsf@benfinney.id.au> "Littlefield, Tyler" writes: > I have been considering writing a couple of programs in Python, but I > don't want to distribute the code along with them. This topic has been raised many times before, and there is a response which is now common but may sound harsh: What is it you think you would gain by obfuscating the code, and why is that worthwhile? What evidence do you have that code obfuscation would achieve that? > Finally, is there a good way to accomplish this? I know that I can > make .pyc files, but those can be disassembled very very easily with > the disassembler and shipping these still means that the person needs > the modules that are used. Is there another way to go about this? Not really, no. You would be best served by critically examining the requirement to obfuscate the code at all. -- \ ?Leave nothing to chance. Overlook nothing. Combine | `\ contradictory observations. Allow yourself enough time.? | _o__) ?Hippocrates | Ben Finney From tyler at tysdomain.com Sun May 15 23:36:53 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 15 May 2011 21:36:53 -0600 Subject: obviscating python code for distribution In-Reply-To: <87boz3gw5u.fsf@benfinney.id.au> References: <87boz3gw5u.fsf@benfinney.id.au> Message-ID: <4DD09BD5.9070405@tysdomain.com> I'm putting lots of work into this. I would rather not have some script kiddy dig through it, yank out chunks and do whatever he wants. I just want to distribute the program as-is, not distribute it and leave it open to being hacked. On 5/15/2011 9:29 PM, Ben Finney wrote: > "Littlefield, Tyler" writes: > >> I have been considering writing a couple of programs in Python, but I >> don't want to distribute the code along with them. > This topic has been raised many times before, and there is a response > which is now common but may sound harsh: > > What is it you think you would gain by obfuscating the code, and why is > that worthwhile? What evidence do you have that code obfuscation would > achieve that? > >> Finally, is there a good way to accomplish this? I know that I can >> make .pyc files, but those can be disassembled very very easily with >> the disassembler and shipping these still means that the person needs >> the modules that are used. Is there another way to go about this? > Not really, no. You would be best served by critically examining the > requirement to obfuscate the code at all. > -- Take care, Ty my website: http://tds-solutions.net my blog: http://tds-solutions.net/blog skype: st8amnd127 ?Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.? ?If Java had true garbage collection, most programs would delete themselves upon execution.? From harrismh777 at charter.net Sun May 15 23:48:03 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 22:48:03 -0500 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> Message-ID: Littlefield, Tyler wrote: > I'm putting lots of work into this. I would rather not have some script > kiddy dig through it, yank out chunks and do whatever he wants. I just > want to distribute the program as-is, not distribute it and leave it > open to being hacked. Protection via obfuscation is invalid practically as well as philosophically. Those of us who work in the free software movement (or the open software movement too) specifically believe that obfuscation is an incorrect approach. Obfuscation is the paramount Microsoft strategy for protection and for security. It doesn't work. In fact, making the code open permits what many of us who consider open source to be 'good science' more secure by allowing peer review and community improvement. Some of us believe that code is not useful unless its open. If I can't see what you're doing, comment on it, improve it if I like, and share it with others I don't need it (its really that simple). Nobody can make this decision for you, of course, but please consider making your coding free software (GPL license), or at least open and GPL compatible licensed. kind regards, m harris From rosuav at gmail.com Sun May 15 23:50:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 13:50:05 +1000 Subject: MySQLdb SEC_TO_TIME function returns datetime.timedelta class In-Reply-To: References: Message-ID: On Mon, May 16, 2011 at 10:42 AM, Jorge Romero wrote: > Hi Pythonists, > I'm retrieving some time data from a MySQL database using Python's MySQLdb > library. Here's the situation, I got a time field on MySQL given in seconds, > I need it on HH:MM:SS format, so I'm SELECTING that field with SEC_TO_TIME > function, something like this: > query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table" You're summing a column, so presumably the values are actually deltas (it doesn't make sense, for instance, to add Tues March 16th to Sat Nov 2nd). The result exceeds a day; in what format do you actually want it? For maximum flexibility, you could ditch the SEC_TO_TIME call and simply work with the integer seconds in Python. You can then format that into HHHHH:MM:SS or whatever suits you. Chris Angelico From gnarlodious at gmail.com Sun May 15 23:53:31 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 15 May 2011 20:53:31 -0700 (PDT) Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) Message-ID: Can someone please explain what I am doing wrong? Calling script: from Gnomon import GnomonBase Gnomon=GnomonBase(3) Called script: class GnomonBase(object): def __init__(self, bench): # do stuff But all I get is: TypeError: __init__() takes exactly 1 positional argument (2 given) I don't understand, I am only sending one variable. What does it think I am sending two? This is Python 3.1.3. -- Gnarlie From harrismh777 at charter.net Sun May 15 23:59:57 2011 From: harrismh777 at charter.net (harrismh777) Date: Sun, 15 May 2011 22:59:57 -0500 Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) In-Reply-To: References: Message-ID: <1j1Ap.30146$Vp.4643@newsfe14.iad> Gnarlodious wrote: > class GnomonBase(object): > def __init__(self, bench): <======= (1) (2) > # do stuff This only answers the surface question.... I have not taken any time to see or understand what (if anything) you are doing which might make any sense... only that the message is complaining about giving __init__() two parms, because you gave it two parms.... ... I know you're joking, but I don't know why...? kind regards, m harris From steve+comp.lang.python at pearwood.info Mon May 16 00:03:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2011 04:03:09 GMT Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> Message-ID: <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 May 2011 21:36:53 -0600, Littlefield, Tyler wrote: > I'm putting lots of work into this. I would rather not have some script > kiddy dig through it, yank out chunks and do whatever he wants. The best way to do that is to labour in obscurity, where nobody either knows or cares about your application. There are hundreds of thousands, possibly millions, of such applications, with a user base of one: the creator. One other alternative is to ask yourself, what's the marginal value of yanking out chunks from my code? What harm does it do me if Joe Haxor spends hours pulling out one subroutine, or a dozen, from my app, and using them in his app? Why should I care? It never ceases to amaze me how often people write some trivial application, like a thousand others, or even some trivial function or class, and then treat it like the copyright to Mickey Mouse. I don't know what your application is, or how it works. It's conceivable that it's the next Microsoft Office. But my advice to you is to take a pragmatic, realistic view of the cost of copyright infringement. If it's going to cost you $1000 in extra effort to prevent $100 of harm, it's simply not worth it. > I just > want to distribute the program as-is, not distribute it and leave it > open to being hacked. Right... because of course we all know how Windows being distributed without source code makes it soooooo secure. You are conflating two different issues: * Can people "steal" or copy my ideas and code? * Can people hack my code (in the bad sense)? I hope this does not offend, because I mean it in the nicest possible way, but if you think that not distributing source code will prevent your code from being broken, then you are delusional. Look at Facebook and its periodic security holes and accounts being hacked. Not only don't Facebook distribute source code, but they don't distribute *anything* -- their application is on their servers, behind a firewall. Does it stop hackers? Not a chance. -- Steven From jorgeromero178 at gmail.com Mon May 16 00:06:21 2011 From: jorgeromero178 at gmail.com (Jorge Romero) Date: Mon, 16 May 2011 00:06:21 -0400 Subject: MySQLdb SEC_TO_TIME function returns datetime.timedelta class In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 11:50 PM, Chris Angelico wrote: > On Mon, May 16, 2011 at 10:42 AM, Jorge Romero > wrote: > > Hi Pythonists, > > I'm retrieving some time data from a MySQL database using Python's > MySQLdb > > library. Here's the situation, I got a time field on MySQL given in > seconds, > > I need it on HH:MM:SS format, so I'm SELECTING that field with > SEC_TO_TIME > > function, something like this: > > query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table" > > You're summing a column, so presumably the values are actually deltas > (it doesn't make sense, for instance, to add Tues March 16th to Sat > Nov 2nd). The result exceeds a day; in what format do you actually > want it? > > For maximum flexibility, you could ditch the SEC_TO_TIME call and > simply work with the integer seconds in Python. You can then format > that into HHHHH:MM:SS or whatever suits you. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > Yeah, I believe that's the way to go, retrieve seconds and deal with them with Python, for flexibility as you pointed. I need the seconds to become HH:MM:SS format. What seems weird to me is why MySQLdb treats the result of the query as deltas. Here's what I get if a query directly the database, output from PHP MyAdmin: SEC_TO_TIME(SUM(billsec)) *79:30:09* * * *This value suits better the datetime.time type, instead of datetime.deltatime. * Thanks Chris for your feedback. -- Jorge Romero -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon May 16 00:10:06 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 May 2011 21:10:06 -0700 Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 8:53 PM, Gnarlodious wrote: > Can someone please explain what I am doing wrong? > > Calling script: > > from Gnomon import GnomonBase > Gnomon=GnomonBase(3) > > > Called script: > > class GnomonBase(object): > ? ?def __init__(self, bench): > ? ? ? ?# do stuff > > But all I get is: > TypeError: __init__() takes exactly 1 positional argument (2 given) > > I don't understand, I am only sending one variable. What does it think > I am sending two? Please post the *full* exception Traceback. Cheers, Chris From ben+python at benfinney.id.au Mon May 16 00:10:11 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 16 May 2011 14:10:11 +1000 Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> Message-ID: <877h9rguak.fsf@benfinney.id.au> "Littlefield, Tyler" writes: > I'm putting lots of work into this. I would rather not have some > script kiddy dig through it, yank out chunks and do whatever he wants. > I just want to distribute the program as-is, not distribute it and > leave it open to being hacked. How do these arguments apply to your code base when they don't apply to, say, LibreOffice or Linux or Python or Apache or Firefox? How is your code base going to be harmed by having the source code available to recipients, when that demonstrably doesn't harm countless other code bases out there? -- \ ?Let others praise ancient times; I am glad I was born in | `\ these.? ?Ovid (43 BCE?18 CE) | _o__) | Ben Finney From ian.g.kelly at gmail.com Mon May 16 00:12:47 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 15 May 2011 22:12:47 -0600 Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 9:53 PM, Gnarlodious wrote: > class GnomonBase(object): > ? ?def __init__(self, bench): > ? ? ? ?# do stuff > > But all I get is: > TypeError: __init__() takes exactly 1 positional argument (2 given) > > I don't understand, I am only sending one variable. What does it think > I am sending two? Usually this error means that you forgot to include "self" in the method signature. As a result it receives two arguments (self and bench) but only has one defined (bench). The snippet you posted looks correct, though. It might be easier to help if you posted the actual code. Also the full stack trace might be helpful. From gnarlodious at gmail.com Mon May 16 00:30:06 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 15 May 2011 21:30:06 -0700 (PDT) Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) References: Message-ID: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> I don't have a trace because I am using mod_wsgi under Apache. Maybe there is a way to debug using mod_wsgi but I haven't been able to figure out how. My problem is that in order to run mod_wsgi I had to downgrade to Python 3.1.3 which may be causing the problem. This website was running fine in Py3.2. I did find an explanation that sounds like this is an intentional deprecation in Python: It looks like we are now expected to initialize instance variables with a setter statement? -- Gnarlie From steve+comp.lang.python at pearwood.info Mon May 16 00:31:00 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2011 04:31:00 GMT Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) References: Message-ID: <4dd0a883$0$29983$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 May 2011 20:53:31 -0700, Gnarlodious wrote: > Can someone please explain what I am doing wrong? > > Calling script: > > from Gnomon import GnomonBase > Gnomon=GnomonBase(3) > > > Called script: > > class GnomonBase(object): > def __init__(self, bench): > # do stuff > > But all I get is: > TypeError: __init__() takes exactly 1 positional argument (2 given) > > I don't understand, I am only sending one variable. What does it think I > am sending two? Whenever you call a method, the instance is automatically provided by Python as an argument (conventionally called "self") to the function. So, for any arbitrary method, the call: instance.method(arg) is converted to: type(instance).method(instance, arg) hence two arguments. My guess is that your GnomonBase __init__ method is *not* what you show above, but (probablY) one of the following: def __init__(bench): # oops, forgot self # do stuff def __init__(selfbench): # oops, forgot the comma # do stuff -- Steven From rosuav at gmail.com Mon May 16 00:40:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 14:40:17 +1000 Subject: obviscating python code for distribution In-Reply-To: <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 16, 2011 at 2:03 PM, Steven D'Aprano wrote: > The best way to do that is to labour in obscurity, where nobody either > knows or cares about your application. There are hundreds of thousands, > possibly millions, of such applications, with a user base of one: the > creator. And I'm sure Steven will agree with me that this is not in any way a bad thing. I've written hundreds of such programs myself (possibly thousands), and they have all served their purposes. On a slightly larger scale, there are even more programs that have never left the walls of my house, having been written for my own family - not because I'm afraid someone else will steal them, but because they simply are of no value to anyone else. But hey, if anyone wants a copy of my code that's basically glue between [obscure application #1] and [obscure application #2] that does [obscure translation] as well to save a human from having to do it afterwards, sure! You're welcome to it! :) However, I do not GPL my code; I prefer some of the other licenses (such as CC-BY-SA), unless I'm working on a huge project that's not meant to have separate authors. For something that by and large is one person's work, I think it's appropriate to give attribution. But discussion of exactly _which_ open source license to use is a can of worms that's unlikely to be worth opening at this stage. Chris Angelico From clp2 at rebertia.com Mon May 16 00:44:23 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 May 2011 21:44:23 -0700 Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) In-Reply-To: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> References: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> Message-ID: On Sun, May 15, 2011 at 9:30 PM, Gnarlodious wrote: > I don't have a trace because I am using mod_wsgi under Apache. Maybe > there is a way to debug using mod_wsgi but I haven't been able to > figure out how. > > My problem is that in order to run mod_wsgi I had to downgrade to > Python 3.1.3 which may be causing the problem. This website was > running fine in Py3.2. > > I did find an explanation that sounds like this is an intentional > deprecation in Python: > do-they-do> > > > It looks like we are now expected to initialize instance variables > with a setter statement? Er, what are you talking about? That's always been the case; it's nothing new at all. Perhaps your "# do stuff" from earlier isn't doing the right stuff? Posting the actual code would help. Cheers, Chris -- http://rebertia.com From n4vpython at gmail.com Mon May 16 00:52:24 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Mon, 16 May 2011 10:22:24 +0530 Subject: Memcached in python 3 Message-ID: Hi Guys, How can I used memcached with python 3? Are there any other good alternatives to memcached? What about python dictionary manager, would it compare to memcached if I were to use it for storing in-memory information? Any light on this matter will be appreciated. Regards, Navkirat -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnarlodious at gmail.com Mon May 16 00:53:45 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 15 May 2011 21:53:45 -0700 (PDT) Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) References: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> Message-ID: <09233fe8-b1ef-4c1c-a7f6-9aa65de48368@z7g2000prh.googlegroups.com> Well, I have a whole lot of scripts where I could say something like this: def __init__(self, var1, var2, var3...): Now suddenly I have to change them all to run in Python 3.1.3? This is apparently not a bug. And I rebooted still getting the same behavior. Can someone explain it? -- Gnarlie From ian.g.kelly at gmail.com Mon May 16 00:54:03 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 15 May 2011 22:54:03 -0600 Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) In-Reply-To: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> References: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> Message-ID: On Sun, May 15, 2011 at 10:30 PM, Gnarlodious wrote: > I don't have a trace because I am using mod_wsgi under Apache. Maybe > there is a way to debug using mod_wsgi but I haven't been able to > figure out how. http://code.google.com/p/modwsgi/wiki/DebuggingTechniques > My problem is that in order to run mod_wsgi I had to downgrade to > Python 3.1.3 which may be causing the problem. This website was > running fine in Py3.2. > > I did find an explanation that sounds like this is an intentional > deprecation in Python: > do-they-do> > I don't think those are related. If it were an intentional change in Python from 2007, then you would be seeing the error in both versions. I don't see how the stackoverflow link has any bearing on the error at all. > It looks like we are now expected to initialize instance variables > with a setter statement? You mean like this? x = Foo() x.y = z No, there is no such expectation. From gnarlodious at gmail.com Mon May 16 01:08:10 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 15 May 2011 22:08:10 -0700 (PDT) Subject: TypeError: __init__() takes exactly 1 positional argument (2 given) References: <70608e59-3316-44ce-9d98-2b170d497839@z15g2000prn.googlegroups.com> Message-ID: <42766145-b076-40c1-bc2b-b85c9c2e1edc@35g2000prp.googlegroups.com> Thanks for all the help, this looks like a bug in mod_wsgi. I tried it interactively under Py3.1.3 and it behaves normally. I'll take this over to the mod_wsgi group. -- Gnarlie http://Gnarlodious.com From rustompmody at gmail.com Mon May 16 01:40:37 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 15 May 2011 22:40:37 -0700 (PDT) Subject: checking if a list is empty References: <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> <4dd07182$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0266541d-3039-42ef-a979-23722b78f9cd@f15g2000pro.googlegroups.com> I have been scolded off-list for pursuing a discussion that has nothing to do with python. So I continue a bit gingerly :-) and will stop when others feel this is useless/irrelevant/whatever. Steven wrote: > I'm afraid I didn't find your discussion about reification, Platonism and > linguistics very helpful. Some of it I disagree with, some I agree with, > but in neither case do I see any relevance to the question of whether > bools are first class objects in Python, and if not, why not. Thank you (Steven and Terry) for using the word 'reification'. I used the more common 'firstclass' because I assumed that will be more generally known. I however prefer reification since one can discuss (more cooly :-) ) what and how much one should reify; the word reification has less of a strong value judgment in philosophy than firstclass has in computer science. The lead-writeup on reification http://en.wikipedia.org/wiki/Reification_%28computer_science%29 has the following line: > Informally, reification is often referred to as "making something a first-class citizen" within the scope of a particular system. So from the CS side reification == movement-towards-firstclassness >From the philosophical side we could try to define platonism (non- mystically) as "The strong reification of abstract concepts" So much for my defense of bringing in platonism into the discussion. Steven wrote: > > > Seemingly you and Dijkstra are saying something similar when you say > > [1,2,3] is a way of writing true > > and he says 2<3 is a way of writing true. But on further examination > > (with Leibniz law above) Dijkstra's 2<3 = True will work consistently in > > all contexts but [1,2,3] = True will work sometimes and fail sometimes. > Please do not arbitrarily mix Python and mathematics syntax. What you have stated gives a SyntaxError. Is this non-mixing-up possible? Like 'reification,' I do not know if using the funny brackets of denotational semantics would be intelligible on this list ( and I dont know how to write them in ASCII) but using |[ ]| as an approximation, I would have to say something like: Dijkstra's |[ 2<3 ]| = True will work consistently... Python's | [ [1,2,3] ]| = |[True ]| will be be true in boolean contexts and not elsewhere. Note that the first |[]| is for the object language called mathematics and the other two for the object language called python. And the = is in a pidgin English-math meta language that is need to discuss these object languages. I am not clear that this form of discourse actually enhances clarity, however it does bring up the point that this discussion is as much about object/meta-language distinctions and confusions as it is about reification. You see when Terry talks of boolean algebra for switching networks, he is referring to logic as an object language. But when we use logic to discuss and understand (and argue :-) ) we are using it in the meta-language. Dijkstra's signal contribution -- which he attributes to Boole, Leibniz and Recorde (for the = sign) -- lies in this: >From the time of Aristotle, all usage of logic in the meta-language (logic as the substrate for arguments rather than logic as a model for things like switching networks) has been a string of assertions linked up with 'implies' 'therefore' 'follows from' etc. All these when modelled (in a suitable object logic) would traditionally look like => (implies) or at best <= (follows from) It is possible to do all this -- traditional logic -- using = (aka iff, <=>, etc) The benefit is that logic becomes much more like traditional algebra: Proofs become of the form: desideradum = : : = true The cost is that bool has to be properly reified. Steven wrote: > Rusi wrote: > > For example if my language seems to have entities like '2' '3' '+' but > > 2+3 does not work out equal to 5 we would (I hope!) not say the language > > has first-class numbers. > Well, that's a problem. By that definition, floats are not first class > numbers. While 2+3 does work out to be equal to 5, other standard > properties of the real number system do not apply: > >>> 0.3 + 0.4 - 0.3 == 0.4 >From C onwards (and in Fortran), its been called float, not real. Note that C like python uses a math-suggesting name int for integers but a hardware implementation name for float. This suggests that (aside from overflow) int in C corresponds to the math Z whereas float does not quite correspond to real. [The whole field of numerical analysis comes about because of this non-correspondence] In the language Pascal, what we call float today was called real and this would be an argument. But in this context I dont get the argument... From tyler at tysdomain.com Mon May 16 01:41:23 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 15 May 2011 23:41:23 -0600 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DD0B903.4090109@tysdomain.com> Hello: Thanks all for your information and ideas. I like the idea of open source; I have a fairly large (or large, by my standards anyway) project that I am working on that is open source. Here's kind of what I want to prevent. I want to write a multi-player online game; everyone will essentually end up connecting to my server to play the game. I don't really like the idea of security through obscurity, but I wanted to prevent a couple of problems. 1) First I want to prevent people from hacking at the code, then using my server as a test for their new setups. I do not want someone to gain some extra advantage just by editing the code. Is there some other solution to this, short of closed-source? Thanks, From rustompmody at gmail.com Mon May 16 01:56:03 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 15 May 2011 22:56:03 -0700 (PDT) Subject: checking if a list is empty References: <931adaF9g1U1@mid.individual.net> <4dcc785e$0$29980$c3e8da3$5496439d@news.astraweb.com> <4dce31b3$0$29980$c3e8da3$5496439d@news.astraweb.com> <87wrhshni4.fsf@benfinney.id.au> <61ccd16d-02c1-4adb-adc3-26a876a8762f@z15g2000prn.googlegroups.com> <4dcf5f99$0$29996$c3e8da3$5496439d@news.astraweb.com> <48487954-dea9-483f-aaf2-de71e21b0f98@18g2000prd.googlegroups.com> Message-ID: <56619d3d-f1e4-4f45-9dc6-88ff4668f40f@18g2000prd.googlegroups.com> On May 16, 2:36?am, Terry Reedy wrote: > On 5/15/2011 1:33 PM, rusi wrote: > > > On May 15, 10:07 am, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> ?wrote: > > >> I'm afraid I don't understand what you mean. Can you explain please, what > >> properties of "first class booleans" do you think are missing from Python? > > Given the usual CS definition of 'first class object', all Python > objects are first class. But that does not preclude other definitions. > > > > What CS definition? Perhaps your definition matches the wikipedia article: http://en.wikipedia.org/wiki/First-class_object And I am using the extended definition on the talk page: http://en.wikipedia.org/wiki/Talk:First-class_object#Is_it_is.2C_or_is_it_aint.3F [Evidently the arguments of this thread are repeatedly played out elsewhere :-; ] From prologic at shortcircuit.net.au Mon May 16 02:00:12 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 16 May 2011 16:00:12 +1000 Subject: obviscating python code for distribution In-Reply-To: <4DD0B903.4090109@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 3:41 PM, Littlefield, Tyler wrote: > Here's kind of what I want to prevent. I want to write a multi-player online > game; everyone will essentually end up connecting to my server to play the > game. I don't really like the idea of security through obscurity, but I > wanted to prevent a couple of problems. > 1) First I want to prevent people from hacking at the code, then using my > server as a test for their new setups. I do not want someone to gain some > extra advantage just by editing the code. > Is there some other solution to this, short of closed-source? As I mentioned before (which I don't think you quite got)... Write your "game" for the "web". Write is as a SaaS (Software as a Service) - even if it's free and open source. cheers James -- -- James Mills -- -- "Problems are solved by method" From rosuav at gmail.com Mon May 16 02:12:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 16:12:36 +1000 Subject: obviscating python code for distribution In-Reply-To: <4DD0B903.4090109@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 3:41 PM, Littlefield, Tyler wrote: > Here's kind of what I want to prevent. I want to write a multi-player online > game; everyone will essentually end up connecting to my server to play the > game. I don't really like the idea of security through obscurity, but I > wanted to prevent a couple of problems. > 1) First I want to prevent people from hacking at the code, then using my > server as a test for their new setups. I do not want someone to gain some > extra advantage just by editing the code. > Is there some other solution to this, short of closed-source? 1) If you're worried about people getting hold of the code that's running on your server, that's a server security issue and not a Python obscurity issue (if they get the code, they can run it no matter how obscured it is). 2) Was there a problem 2? :) As James Mills said, just leave it on the server and then you don't have to give out the source (and by "don't have to", I mean ethically, legally, and technically). You may want to give some thought to scaleability of your code; Google told their staff to avoid Python for things that are going to get hammered a lot (although it's possible that Google's idea of "a lot" is five orders of magnitude more than you'll ever get!!). But if your game world puts a hard limit on its own load (eg if players are on a 50x50 board and you know you can handle 2500 simultaneous players), you won't have a problem. Also, Python doesn't really cater to servers that want to have their code updated on the fly; I'm sure you could work something out using a dictionary of function objects, but otherwise you're stuck with bringing the server down to do updates. That's considered normal in today's world, but I really don't know why... downtime is SO last century! Chris Angelico happily running servers on fully open source stacks From tyler at tysdomain.com Mon May 16 02:17:15 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 16 May 2011 00:17:15 -0600 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: <4DD0C16B.4010500@tysdomain.com> >Write your "game" for the "web". >Write is as a SaaS (Software as a Service) - even if it's free and open source. I understood you loud and clear. And that makes a lot of assumptions on my game and the design. I don't really care to host this over the web. I want a centralized server that would perform the logic, where I can offload the playing of sounds (through a soundpack that's already installed) to the client-side. Not only that, but a lot of web technologies that would be used for this wouldn't really work, as I am doing this for the blind; Flash as well as a lot of the popular setups are not very accessible. From tyler at tysdomain.com Mon May 16 02:20:07 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 16 May 2011 00:20:07 -0600 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: <4DD0C217.9050304@tysdomain.com> Hello: I wanted to make the client in python, and the server possibly, though I'm not really sure on that. I was not worried about the code for the server being stolen, as much as I was worried about people tinkering with the client code for added advantages. Most of the logic can be handled by the server to prevent a lot of this, but there are still ways people could give themselves advantages by altering the client. From prologic at shortcircuit.net.au Mon May 16 02:24:12 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 16 May 2011 16:24:12 +1000 Subject: obviscating python code for distribution In-Reply-To: <4DD0C127.80300@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> <4DD0C127.80300@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 4:16 PM, Littlefield, Tyler wrote: > I understood you loud and clear. And that makes a lot of assumptions on my > game and the design. I don't really care to host this over the web. I want a > centralized server that would perform the logic, where I can offload the > playing of sounds (through a soundpack that's already installed) to the > client-side. Not only that, but a lot of web technologies that would be used > for this wouldn't really work, as I am doing this for the blind; Flash as > well as a lot of the popular setups are not very accessible. Funny you should mention this "now" :) I happen to be blind myself. Yes I agree Flash is not very accessible (never has been). Web Standards web apps and such however are quite accessible! cheers James -- -- James Mills -- -- "Problems are solved by method" From __peter__ at web.de Mon May 16 02:34:44 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 May 2011 08:34:44 +0200 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: Daniel Kluev wrote: >> Both solutions seem to be equivalent in that concerns the number of >> needed loop runs, but this two-step operation might require one less loop >> over list1. The set&set solution, in contrary, might require one loop >> while transforming to a set and another one for the & operation. > > python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" > "l3 = list(set(l1) & set(l2))" > 100 loops, best of 3: 2.19 msec per loop > > python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" > "s=set(l2); l3 = [i for i in l1 if i in s]" > 100 loops, best of 3: 2.45 msec per loop > > python -m timeit -s "l1 = range(1, 100000); l2 = range(50000, 150000)" > "l3 = list(set(l1) & set(l2))" > 10 loops, best of 3: 28 msec per loop > > python -m timeit -s "l1 = range(1, 100000); l2 = range(50000, 150000)" > "s=set(l2); l3 = [i for i in l1 if i in s]" > 10 loops, best of 3: 28.1 msec per loop > > So even with conversion back into list set&set is still marginally faster. If you are looking for speed, consider s = set(l1) s.intersection_update(l2) l3 = list(s) $ python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" "list(set(l1) & set(l2))" 100 loops, best of 3: 4 msec per loop $ python -m timeit -s "l1 = range(1, 10000); l2 = range(5000, 15000)" "s = set(l1); s.intersection_update(l2); list(s)" 100 loops, best of 3: 1.99 msec per loop From karim.liateni at free.fr Mon May 16 03:26:26 2011 From: karim.liateni at free.fr (Karim) Date: Mon, 16 May 2011 09:26:26 +0200 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: References: <4DD03B69.6050301@gmail.com> Message-ID: <4DD0D1A2.6060109@free.fr> On 05/16/2011 03:06 AM, David Robinow wrote: > On Sun, May 15, 2011 at 4:45 PM, Andrew Berg wrote: >> I'm trying to understand why HMTLParser.feed() isn't returning the whole >> page. My test script is this: >> >> import urllib.request >> import html.parser >> class MyHTMLParser(html.parser.HTMLParser): >> def handle_starttag(self, tag, attrs): >> if tag == 'a' and attrs: >> print(tag,'-',attrs) >> >> url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth' >> page = urllib.request.urlopen(url).read() >> parser = MyHTMLParser() >> parser.feed(str(page)) >> >> I can do print(page) and get the entire HTML source, but >> parser.feed(str(page)) only spits out the information for the top links >> and none of the "revisionxxxx" links. Ultimately, I just want to find >> the name of the first "revisionxxxx" link (right now it's >> "revision1995", when a new build is uploaded it will be "revision2000" >> or whatever). I figure this is a relatively simple page; once I >> understand all of this, I can move on to more complicated pages. > You've got bad HTML. Look closely and you'll see the there's no space > between the "revisionxxxx" strings and the style tag following. > The parser doesn't like this. I don't know a solution other than > fixing the html. > (I created a local copy, edited it and it worked.) Hello, Use regular expression for bad HTLM or beautifulSoup (google it), below a exemple to extract all html links: linksList = re.findall('.*?',htmlSource) for link in linksList: print link Cheers Karim From debatem1 at gmail.com Mon May 16 03:27:44 2011 From: debatem1 at gmail.com (geremy condra) Date: Mon, 16 May 2011 00:27:44 -0700 Subject: obviscating python code for distribution In-Reply-To: <4DD0B903.4090109@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: On Sun, May 15, 2011 at 10:41 PM, Littlefield, Tyler wrote: > Hello: > Thanks all for your information and ideas. I like the idea of open source; I > have a fairly large (or large, by my standards anyway) project that I am > working on that is open source. > > Here's kind of what I want to prevent. I want to write a multi-player online > game; everyone will essentually end up connecting to my server to play the > game. I don't really like the idea of security through obscurity, but I > wanted to prevent a couple of problems. > 1) First I want to prevent people from hacking at the code, then using my > server as a test for their new setups. I do not want someone to gain some > extra advantage just by editing the code. > Is there some other solution to this, short of closed-source? > Thanks, I don't know that closing the source does you much more good than obfuscating it. The obvious attack surface here is pretty much totally exposed via network traffic, which any legitimate client can gain access to. A better approach would be to simply write more secure code in the first place. Geremy Condra From gagsl-py2 at yahoo.com.ar Mon May 16 03:50:11 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 May 2011 04:50:11 -0300 Subject: Import on case insensitive filesystem References: Message-ID: En Fri, 13 May 2011 15:43:23 -0300, Mitchell Hashimoto escribi?: > I'm developing an app which runs Python on a filesystem which is not case > sensitive (Mac OS X), but is mounted as an NFS drive on a remote machine. > This causes errors because of the import being case sensitive but > accessing > an FS which is case insensitive. Short of copying the entire directory > tree > over to another filesystem, is there anything I can do to flag Python to > act > as though it were on a case sensitive FS? Try creating an environment variable PYTHONCASEOK with any value. See http://www.python.org/dev/peps/pep-0235/ for details. -- Gabriel Genellina From jnr.gonzalez at googlemail.com Mon May 16 04:19:31 2011 From: jnr.gonzalez at googlemail.com (J) Date: Mon, 16 May 2011 01:19:31 -0700 (PDT) Subject: Convert AWK regex to Python Message-ID: Good morning all, Wondering if you could please help me with the following query:- I have just started learning Python last weekend after a colleague of mine showed me how to dramatically cut the time a Bash script takes to execute by re-writing it in Python. I was amazed at how fast it ran. I would now like to do the same thing with another script I have. This other script reads a log file and using AWK it filters certain fields from the log and writes them to a new file. See below the regex the script is executing. I would like to re-write this regex in Python as my script is currently taking about 1 hour to execute on a log file with about 100,000 lines. I would like to cut this time down as much as possible. cat logs/pdu_log_fe.log | awk -F\- '{print $1,$NF}' | awk -F\. '{print $1,$NF}' | awk '{print $1,$4,$5}' | sort | uniq | while read service command status; do echo "Service: $service, Command: $command, Status: $status, Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | grep $status | wc -l | awk '{ print $1 }'`" >> logs/pdu_log_fe_clean.log; done This AWK command gets lines which look like this:- 2011-05-16 09:46:22,361 [Thread-4847133] PDU D And outputs lines like this:- CC_SMS_SERVICE_51408 submit_resp: 0 I have tried writing the Python script myself but I am getting stuck writing the regex. So far I have the following:- #!/usr/bin/python # Import RegEx module import re as regex # Log file to work on filetoread = open('/tmp/ pdu_log.log', "r") # File to write output to filetowrite = file('/tmp/ pdu_log_clean.log', "w") # Perform filtering in the log file linetoread = filetoread.readlines() for line in linetoread: filter0 = regex.sub(r" References: Message-ID: On Mon, May 16, 2011 at 6:19 PM, J wrote: > cat logs/pdu_log_fe.log | awk -F\- '{print $1,$NF}' | awk -F\. '{print $1,$NF}' | awk '{print $1,$4,$5}' | sort | uniq | while read service command status; do echo "Service: $service, Command: $command, Status: $status, Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | grep $status | wc -l | awk '{ print $1 }'`" >> logs/pdu_log_fe_clean.log; done Small side point: Instead of "| sort | uniq |", you could use a Python dictionary. That'll likely speed things up somewhat! Chris Angelico From jnr.gonzalez at googlemail.com Mon May 16 04:43:20 2011 From: jnr.gonzalez at googlemail.com (J) Date: Mon, 16 May 2011 01:43:20 -0700 (PDT) Subject: Convert AWK regex to Python In-Reply-To: Message-ID: <0426dbb3-178c-42ac-aebc-29603b3b3bce@glegroupsg2000goo.googlegroups.com> Good morning Angelico, Do I understand correctly? Do you mean incorporating a Python dict inside the AWK command? How can I do this? From jnr.gonzalez at googlemail.com Mon May 16 04:43:20 2011 From: jnr.gonzalez at googlemail.com (J) Date: Mon, 16 May 2011 01:43:20 -0700 (PDT) Subject: Convert AWK regex to Python In-Reply-To: Message-ID: <0426dbb3-178c-42ac-aebc-29603b3b3bce@glegroupsg2000goo.googlegroups.com> Good morning Angelico, Do I understand correctly? Do you mean incorporating a Python dict inside the AWK command? How can I do this? From rosuav at gmail.com Mon May 16 04:46:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 18:46:51 +1000 Subject: Convert AWK regex to Python In-Reply-To: <0426dbb3-178c-42ac-aebc-29603b3b3bce@glegroupsg2000goo.googlegroups.com> References: <0426dbb3-178c-42ac-aebc-29603b3b3bce@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 16, 2011 at 6:43 PM, J wrote: > Good morning Angelico, > Do I understand correctly? Do you mean incorporating a Python dict inside the AWK command? How can I do this? No, inside Python. What I mean is that you can achieve the same uniqueness requirement by simply storing the intermediate data in a dictionary and then retrieving it at the end. Chris Angelico From steve+comp.lang.python at pearwood.info Mon May 16 04:49:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 May 2011 08:49:12 GMT Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dd0e507$0$29983$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 May 2011 23:41:23 -0600, Littlefield, Tyler wrote: > Here's kind of what I want to prevent. I want to write a multi-player > online game; everyone will essentually end up connecting to my server to > play the game. I don't really like the idea of security through > obscurity, but I wanted to prevent a couple of problems. 1) First I want > to prevent people from hacking at the code, then using my server as a > test for their new setups. I do not want someone to gain some extra > advantage just by editing the code. Is there some other solution to > this, short of closed-source? Thanks, Closed source is not a solution. Please wipe that out of your mind. People successfully hack closed source applications. The lack of source is hardly a barrier at all: it's like painting over the door to your house in camouflage colours so from a distance people won't see it. To a guy with a network sniffer and debugger, the lack of source is no barrier at all. You're trying to solve a hard problem, and by hard, I mean "impossible". It simply isn't possible to trust software on a machine you don't control, and pretty damn hard on a machine you do control. To put it in a nutshell, you can't trust *anything*. See the classic paper by Ken Thompson, "Reflections on Trusting Trust": http://cm.bell-labs.com/who/ken/trust.html Now, in a more practical sense, you might not fear that the operating system will turn on you, or the Python compiler. Some threats you don't care about. The threat model you do care about is a much more straight- forward one: how to trust the desktop client of your game? Alas, the answer is, you can't. You can't trust anything that comes from the client until you've verified it is unmodified, and you can't verify it is unmodified until you can trust the information it sends you. A vicious circle. You're fighting physics here. Don't think that obscuring the source code will help. On-line game servers are engaged in a never-ending arms race against "punks" who hack the clients. The servers find a way to detect one hack and block it, and the punks find another hack that goes unnoticed for a while. It's like anti-virus and virus, or immune systems and germs. The question you should be asking is not "how do I make this secure against cheats?", but "how much cheating can I afford to ignore?". If your answer is "No cheating is acceptable", then you have to do all the computation on the server, nothing on the client, and to hell with performance. All your client does is the user interface part. If the answer is, "Its a MUD, who's going to cheat???" then you don't have to do anything. Trust your users. If the benefit from "cheating" is small enough, and the number of cheaters low, who cares? You're not running an on-line casino for real money. See also here: http://web.archiveorange.com/archive/v/bqumydkHsi2ytdsX7ewa Another approach might be to use psychology on your users. Run one server for vanilla clients to connect to, and another server where anything goes. Let the punks get it out of their system by competing with other punks. Run competitions to see who can beat the most souped up, dirty, cheating turbo-powered clients, for honour and glory. Name and shame the punks who cheat on the vanilla server, praise the best cheaters on the anything-goes machine, and you'll (hopefully!) find that the level of cheating on the vanilla server is quite low. Who wants to be the low-life loser who wins by cheating when you can challenge your hacker peers instead? (Note: I don't know if this approach ever works, but I know it does *not* work when real money or glory is involved. Not even close.) If Blizzard can't stop private servers, rogue clients and hacked accounts, what makes you think you can? -- Steven From rosuav at gmail.com Mon May 16 05:10:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 May 2011 19:10:20 +1000 Subject: obviscating python code for distribution In-Reply-To: <4dd0e507$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4dd0e507$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 16, 2011 at 6:49 PM, Steven D'Aprano wrote: > If your answer is "No cheating is acceptable", then you have to do all > the computation on the server, nothing on the client, and to hell with > performance. All your client does is the user interface part. > > If the answer is, "Its a MUD, who's going to cheat???" then you don't > have to do anything. Trust your users. If the benefit from "cheating" is > small enough, and the number of cheaters low, who cares? You're not > running an on-line casino for real money. The nearest I've seen to the latter is Dungeons and Dragons. People can cheat in a variety of ways, but since they're not playing *against* each other, cheating is rare. As to the former, though... the amount of computation that you can reliably offload to even a trusted client is low, so you don't lose much by doing it all on the server. The most computationally-intensive client-side work would be display graphics and such, and that's offloadable if and ONLY if there's no game-sensitive information hidden behind things. Otherwise someone could snoop the traffic-stream and find out what's behind that big nasty obstacle, or turn the obstacle transparent, or whatever... not safe. There's an old OS/2 game called Stellar Frontier that moves sprites around on the screen using clientside code, but if there's a bit of lag talking to the server, you see a ship suddenly yoinked to its new position when the client gets the latest location data. That's a fair compromise, I think; the client predicts where the ship "ought to be", and the server corrects it when it can. Chris Angelico From gagsl-py2 at yahoo.com.ar Mon May 16 05:29:00 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 May 2011 06:29:00 -0300 Subject: turn monitor off and on References: Message-ID: En Sat, 14 May 2011 03:08:44 -0300, Astan Chee escribi?: > I'm trying to turn off my monitor, pause and then turn it on again. > I'm doing this in python 2.6 and windows xp. Here is my script so far > (that doesn't work): > > def turnOnMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > For some reason, the script doesn't turn the monitor back on. What am > I doing wrong here or are there any other alternative? Your script worked fine for me, 2.6 and XP also. Perhaps your monitor device driver is buggy or does not implement the required functionality. Mine is from Philips. -- Gabriel Genellina From jeanmichel at sequans.com Mon May 16 05:36:02 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 16 May 2011 11:36:02 +0200 Subject: obviscating python code for distribution In-Reply-To: <4DD0B903.4090109@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: <4DD0F002.10005@sequans.com> Littlefield, Tyler wrote: > Hello: > Thanks all for your information and ideas. I like the idea of open > source; I have a fairly large (or large, by my standards anyway) > project that I am working on that is open source. > > Here's kind of what I want to prevent. I want to write a multi-player > online game; everyone will essentually end up connecting to my server > to play the game. I don't really like the idea of security through > obscurity, but I wanted to prevent a couple of problems. > 1) First I want to prevent people from hacking at the code, then using > my server as a test for their new setups. I do not want someone to > gain some extra advantage just by editing the code. > Is there some other solution to this, short of closed-source? > Thanks, > If your App meet some success, you'll need some help. You'll be able to get some only if the community grows and has access to your code. If you want to battle versus hackers, you have already lost (if your app hos no success, there will be no hacker anyway :o) ) Otherwise I guess that most online games execute all decisions and state machine transitions at server side, which is the only code you can trust. The client only forwards user inputs to the server, and display the resulting effect . JM From __peter__ at web.de Mon May 16 06:07:27 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 May 2011 12:07:27 +0200 Subject: Convert AWK regex to Python References: Message-ID: J wrote: > Good morning all, > Wondering if you could please help me with the following query:- > I have just started learning Python last weekend after a colleague of mine > showed me how to dramatically cut the time a Bash script takes to execute > by re-writing it in Python. I was amazed at how fast it ran. I would now > like to do the same thing with another script I have. > > This other script reads a log file and using AWK it filters certain fields > from the log and writes them to a new file. See below the regex the > script is executing. I would like to re-write this regex in Python as my > script is currently taking about 1 hour to execute on a log file with > about 100,000 lines. I would like to cut this time down as much as > possible. > > cat logs/pdu_log_fe.log | awk -F\- '{print $1,$NF}' | awk -F\. '{print > $1,$NF}' | awk '{print $1,$4,$5}' | sort | uniq | while read service > command status; do echo "Service: $service, Command: $command, Status: > $status, Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | > grep $status | wc -l | awk '{ print $1 }'`" >> logs/pdu_log_fe_clean.log; > done > > This AWK command gets lines which look like this:- > > 2011-05-16 09:46:22,361 [Thread-4847133] PDU D > CC_SMS_SERVICE_51408_656-ServerThread- VASPSessionThread-7ee35fb0-7e87-11e0-a2da-00238bce423b-TRX > - 2011-05-16 09:46:22 - OUT - (submit_resp: (pdu: L: 53 ID: 80000004 > Status: 0 SN: 25866) 98053090-7f90-11e0-a2da-00238bce423b (opt: ) ) > > > And outputs lines like this:- > > CC_SMS_SERVICE_51408 submit_resp: 0 > > I have tried writing the Python script myself but I am getting stuck > writing the regex. So far I have the following:- For the moment forget about the implementation. The first thing you should do is to describe the problem as clearly as possible, in plain English. From duncan.booth at invalid.invalid Mon May 16 06:24:28 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 16 May 2011 10:24:28 GMT Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Message-ID: Chris Torek wrote: > >>> x = [3, 1, 4, 1, 5, 9, 2, 6] > >>> x > [3, 1, 4, 1, 5, 9, 2, 6] > >>> list(set(x)) > [1, 2, 3, 4, 5, 6, 9] > >>> > > Of course, this trick only works if all the list elements are > hashable. > > This might not be the best example since the result is sorted > "by accident", while other list(set(...)) results are not. A minor change to your example makes it out of order even for integers: >>> x = [7, 8, 9, 1, 4, 1] >>> list(set(x)) [8, 9, 1, 4, 7] or for that mattter: >>> list(set([3, 32, 4, 32, 5, 9, 2, 6])) [32, 2, 3, 4, 5, 6, 9] -- Duncan Booth http://kupuguy.blogspot.com From jnr.gonzalez at googlemail.com Mon May 16 06:57:49 2011 From: jnr.gonzalez at googlemail.com (J) Date: Mon, 16 May 2011 03:57:49 -0700 (PDT) Subject: Convert AWK regex to Python In-Reply-To: Message-ID: Hello Peter, Angelico, Ok lets see, My aim is to filter out several fields from a log file and write them to a new log file. The current log file, as I mentioned previously, has thousands of lines like this:- 2011-05-16 09:46:22,361 [Thread-4847133] PDU D All the lines in the log file are similar and they all have the same length (same amount of fields). Most of the fields are separated by spaces except for couple of them which I am processing with AWK (removing " Message-ID: Hello Peter, Angelico, Ok lets see, My aim is to filter out several fields from a log file and write them to a new log file. The current log file, as I mentioned previously, has thousands of lines like this:- 2011-05-16 09:46:22,361 [Thread-4847133] PDU D All the lines in the log file are similar and they all have the same length (same amount of fields). Most of the fields are separated by spaces except for couple of them which I am processing with AWK (removing " Message-ID: <4dd10a8a$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 May 2011 03:57:49 -0700, J wrote: > Most of the fields are separated by > spaces except for couple of them which I am processing with AWK > (removing " to do is evaluate each line in the log file and break them down into > fields which I can call individually and write them to a new log file > (for example selecting only fields 1, 2 and 3). fields = line.split(' ') output.write(fields[1] + ' ') output.write(fields[2] + ' ') output.write(fields[3] + '\n') -- Steven From __peter__ at web.de Mon May 16 07:36:01 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 May 2011 13:36:01 +0200 Subject: Convert AWK regex to Python References: Message-ID: J wrote: > Hello Peter, Angelico, > > Ok lets see, My aim is to filter out several fields from a log file and > write them to a new log file. The current log file, as I mentioned > previously, has thousands of lines like this:- 2011-05-16 09:46:22,361 > [Thread-4847133] PDU D CC_SMS_SERVICE_51408_656-ServerThread- VASPSessionThread-7ee35fb0-7e87-11e0-a2da-00238bce423b-TRX > - 2011-05-16 09:46:22 - OUT - (submit_resp: (pdu: L: 53 ID: 80000004 > Status: 0 SN: 25866) 98053090-7f90-11e0-a2da-00238bce423b (opt: ) ) > > > All the lines in the log file are similar and they all have the same > length (same amount of fields). Most of the fields are separated by > spaces except for couple of them which I am processing with AWK (removing > " evaluate each line in the log file and break them down into fields which I > can call individually and write them to a new log file (for example > selecting only fields 1, 2 and 3). > > I hope this is clearer now Not much :( It doesn't really matter whether there are 100, 1000, or a million lines in the file; the important information is the structure of the file. You may be able to get away with a quick and dirty script consisting of just a few regular expressions, e. g. import re filename = ... def get_service(line): return re.compile(r"[(](\w+)").search(line).group(1) def get_command(line): return re.compile(r" <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 15 May 2011 23:41:23 -0600, Littlefield, Tyler wrote: > Here's kind of what I want to prevent. I want to write a multi-player > online game; everyone will essentually end up connecting to my server to > play the game. I don't really like the idea of security through > obscurity, but I wanted to prevent a couple of problems. > 1) First I want to prevent people from hacking at the code, then using > my server as a test for their new setups. I do not want someone to gain > some extra advantage just by editing the code. > Is there some other solution to this, short of closed-source? Closed source will not help in the slightest. What will help is to remember the fundamental rule of client-server security: Don't Trust The Client. If you don't remember this rule, you have no security whatsoever, whether the source is open or closed. Obfuscating the source won't prevent someone from running it under a modified Python interpreter, or running an unmodified Python interpreter under a debugger, or with modified DLLs (or even device drivers). To give just one example, Blizzard has a whole team of people working on anti-cheating measures, most of which involve installing various pieces of privacy-invading, security-endangering malware on their customers' systems. And it still doesn't work. From alister.ware at ntlworld.com Mon May 16 08:29:43 2011 From: alister.ware at ntlworld.com (alister ware) Date: Mon, 16 May 2011 12:29:43 GMT Subject: problem with GKT module? References: Message-ID: On Sun, 15 May 2011 20:42:46 -0500, harrismh777 wrote: > Alister Ware wrote: >> I have a simple call back defined for a radio button widget when I use >>> widget.name in linux I get a value of None, windows returns the >>> widget name as I would expect. >>> >>> > First, not familiar with your issue... > > ... but might be able to help you think through it... > > I am assuming that you are building a Python script using a glade > interface that provides the widgets drag-an-drop style and then allowing > you to take the default code, add to it, or otherwise modify it. > > I am also assuming that the /call back/ is returning a Python None, on > the linux platform... otherwise you're getting the widget name from the > same script on the windows platform?? right? > > It might be helpful to examine both scripts to see where (if any) they > differ. More likely than not, this little snag is a difference in the > way that the windows version of gtk+ libraries are working, than the > original ones on the linux platform. > > On the other hand, the Python wrappers for the gtk+ library on the linux > platform may be hiding the return values. Python functions return 'None' > if the 'return' is not explicitly coded. The gtk+ libraries may be > returning a value but the 'builder' is not generating the right Python > wrapper. I'm making this up, but you get the idea, and you can probably > check from here. > > On the other hand, folks here can enter into a discussion with you > regarding the generated Python code (output from the builder) if you > provide relevant code snippets. > > > Kind regards, > m harris glade generates an xml file that is processed by the python script it is the same ml file & the same python script running on both platforms the basic structure of my call back for testing is:- import gtk class GUI: def __init__(self): builder=gtk.Builder() builder.add_from_file('glade.test') # xml file from glade builder.get_object('window1').show() builder.connect_signals(self) def callback(self,widget,data=None): print widget #gives reference to radio button ok print widget.name #widget name on windoze, None on linux def main (self): gtk.main() def main(): gui=GUI() gui.main() if __name__ =='__main__':main() I can provide more detailed sample code if required (including the xml from glade) -- Has everyone noticed that all the letters of the word "database" are typed with the left hand? Now the layout of the QWERTYUIOP typewriter keyboard was designed, among other things, to facilitate the even use of both hands. It follows, therefore, that writing about databases is not only unnatural, but a lot harder than it appears. From balle at chaostal.de Mon May 16 09:38:54 2011 From: balle at chaostal.de (Bastian Ballmann) Date: Mon, 16 May 2011 15:38:54 +0200 Subject: Parsing a graph image In-Reply-To: References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> Message-ID: <20110516153854.28b7fe4f@chaostal.de> Hi, the project sounds like the exact tool that i need but regarding the user manual one has to mark the points on the graph manually. Therefore it's more work to get the data out than doing it without a tool. Or may I miss something here? Greets Basti Am Fri, 13 May 2011 14:38:45 -0500 schrieb Robert Kern : > On 5/13/11 7:24 AM, Bastian Ballmann wrote: > > Hi, > > > > Am Fri, 13 May 2011 14:01:48 +0200 > > schrieb Ulrich Eckhardt: > > > >> I'm not sure I understand 100% what you want. If you want to > >> extract ("parse") the data that is contained in an image file, I > >> have no clue how to do that. > > > > Yes, I want to extract the data that is contained in an image file. > > There is nothing in Python that solves this problem, per se, but > there are free and open source tools for this out there. E.g. > > http://digitizer.sourceforge.net/ > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From invalid at invalid.invalid Mon May 16 09:52:46 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 16 May 2011 13:52:46 +0000 (UTC) Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <877h9rguak.fsf@benfinney.id.au> Message-ID: On 2011-05-16, Ben Finney wrote: > "Littlefield, Tyler" writes: > >> I'm putting lots of work into this. I would rather not have some >> script kiddy dig through it, yank out chunks and do whatever he wants. >> I just want to distribute the program as-is, not distribute it and >> leave it open to being hacked. > > How do these arguments apply to your code base when they don't apply to, > say, LibreOffice or Linux or Python or Apache or Firefox? One obvious way that those arguments don't apply is that the OP didn't put lots of work into LibreOffice, Linux, Python, Apache or Firefox and therefore doesn't have any right to control their distribution. > How is your code base going to be harmed by having the source code > available to recipients, when that demonstrably doesn't harm > countless other code bases out there? The owner of something is free to determine how it is distributed -- he doesn't have any obligation to prove to you that some particular method of distribution is harmful to him or anybody else. -- Grant Edwards grant.b.edwards Yow! at BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI- gmail.com From jnr.gonzalez at googlemail.com Mon May 16 10:01:22 2011 From: jnr.gonzalez at googlemail.com (J) Date: Mon, 16 May 2011 07:01:22 -0700 (PDT) Subject: Convert AWK regex to Python References: Message-ID: Thanks for the sugestions Peter, I will give them a try Peter Otten wrote: > J wrote: > > > Hello Peter, Angelico, > > > > Ok lets see, My aim is to filter out several fields from a log file and > > write them to a new log file. The current log file, as I mentioned > > previously, has thousands of lines like this:- 2011-05-16 09:46:22,361 > > [Thread-4847133] PDU D > CC_SMS_SERVICE_51408_656-ServerThread- > VASPSessionThread-7ee35fb0-7e87-11e0-a2da-00238bce423b-TRX > > - 2011-05-16 09:46:22 - OUT - (submit_resp: (pdu: L: 53 ID: 80000004 > > Status: 0 SN: 25866) 98053090-7f90-11e0-a2da-00238bce423b (opt: ) ) > > > > > All the lines in the log file are similar and they all have the same > > length (same amount of fields). Most of the fields are separated by > > spaces except for couple of them which I am processing with AWK (removing > > " > evaluate each line in the log file and break them down into fields which I > > can call individually and write them to a new log file (for example > > selecting only fields 1, 2 and 3). > > > > I hope this is clearer now > > Not much :( > > It doesn't really matter whether there are 100, 1000, or a million lines in > the file; the important information is the structure of the file. You may be > able to get away with a quick and dirty script consisting of just a few > regular expressions, e. g. > > import re > > filename = ... > > def get_service(line): > return re.compile(r"[(](\w+)").search(line).group(1) > > def get_command(line): > return re.compile(r" > def get_status(line): > return re.compile(r"Status:\s+(\d+)").search(line).group(1) > > with open(filename) as infile: > for line in infile: > print get_service(line), get_command(line), get_status(line) > > but there is no guarantee that there isn't data in your file that breaks the > implied assumptions. Also, from the shell hackery it looks like your > ultimate goal seems to be a kind of frequency table which could be built > along these lines: > > freq = {} > with open(filename) as infile: > for line in infile: > service = get_service(line) > command = get_command(line) > status = get_status(line) > key = command, service, status > freq[key] = freq.get(key, 0) + 1 > > for key, occurences in sorted(freq.iteritems()): > print "Service: {}, Command: {}, Status: {}, Occurences: {}".format(*key > + (occurences,)) From giacomo.boffi at polimi.it Mon May 16 10:19:49 2011 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Mon, 16 May 2011 16:19:49 +0200 Subject: Convert AWK regex to Python References: Message-ID: <86iptabud6.fsf@aiuole.stru.polimi.it> J writes: > cat logs/pdu_log_fe.log | awk -F\- '{print $1,$NF}' | awk -F\. '{print $1,$NF}' | awk '{print $1,$4,$5}' | sort | uniq | while read service command status; do echo "Service: $service, Command: $command, Status: $status, Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | grep $status | wc -l | awk '{ print $1 }'`" >> logs/pdu_log_fe_clean.log; done > > This AWK command gets lines which look like this:- > > 2011-05-16 09:46:22,361 [Thread-4847133] PDU D > > And outputs lines like this:- > > CC_SMS_SERVICE_51408 submit_resp: 0 > i see some discrepancies in the description of your problem 1. if i echo a properly quoted line "like this" above in the pipeline formed by the first three awk commands i get $ echo $likethis | awk -F\- '{print $1,$NF}' \ | awk -F\. '{print$1,$NF}' \ | awk '{print $1,$4,$5}' 2011 ) ) $ not a triple 'service command status' 2. with regard to the final product, you script outputs lines like in echo "Service: $service, [...]" and you say that it produces lines like CC_SMS_SERVICE_51408 submit_resp: WHATEVER, the abnormous run time is due to the fact that for every output line you rescan again and again the whole log file IF i had understood what you want, imho you should run your data through sort and uniq -c $ awk -F\- '{print $1,$NF}' < $file \ | awk -F\. '{print$1,$NF}' \ | awk '{print $1,$4,$5}' | sort | uniq -c | format_program uniq -c drops repeated lines from a sorted input AND prepends to each line the count of equal lines in the original stream hth g From nobody at nowhere.net.no Mon May 16 10:23:07 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 16 May 2011 22:23:07 +0800 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: Thomas Rachel wrote: > Which loops do you mean here? list(set) has been proved to largely win against list = [] for item in set: list.append(item) or [list.append(item) for item in set] -- goto /dev/null From tyler at tysdomain.com Mon May 16 10:44:33 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 16 May 2011 08:44:33 -0600 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> <4DD0C127.80300@tysdomain.com> Message-ID: <4DD13851.7040406@tysdomain.com> >Funny you should mention this "now" I don't go around parading the info, until I have to. >Yes I agree Flash is not very accessible (never has been). >Web Standards web apps and such however are quite >accessible! If I was making a browser-based game, yes. As I'm not though... Anyway, thanks to everyone else who answered this thread. I've not done much like this besides muds, and all the logic is on the server there, I think I will build the client in python, open source it for people to fix/add to if they want and make sure to keep the server as secure as it can be. From python.list at tim.thechases.com Mon May 16 10:54:21 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 May 2011 09:54:21 -0500 Subject: obviscating python code for distribution In-Reply-To: <87boz3gw5u.fsf@benfinney.id.au> References: <87boz3gw5u.fsf@benfinney.id.au> Message-ID: <4DD13A9D.1080906@tim.thechases.com> On 05/15/2011 10:29 PM, Ben Finney wrote: > What is it you think you would gain by obfuscating the code, > and why is that worthwhile? What evidence do you have that > code obfuscation would achieve that? Based on past experience at several employers', the preeminent reason for obfuscating is to make it hard for people to see the absolutely atrocious coding that takes place behind closed doors. Having seen behind the curtain, every time I hear the buzzword(s) "enterprise software", I now equate that with "shovelware pushed out the door driven by a marketing agenda rather than customer needs; held together by baling wire and string; lacking test-suites, UI testing, or attention to failure conditions; random hit-or-miss deployment processes; usually a lack of decent revision control; etc". -tkc From matthewberends at gmail.com Mon May 16 11:02:42 2011 From: matthewberends at gmail.com (Matt Berends) Date: Mon, 16 May 2011 08:02:42 -0700 (PDT) Subject: Convert AWK regex to Python References: <86iptabud6.fsf@aiuole.stru.polimi.it> Message-ID: <69be0110-1992-46b2-bafb-ec3204663bbc@x10g2000yqj.googlegroups.com> This doesn't directly bear upon the posted example, but I found the following tutorial extremely helpful for learning how to parse log files with idiomatic python. Maybe you'll might find it useful, too. http://www.dabeaz.com/generators/ http://www.dabeaz.com/generators/Generators.pdf From ian.g.kelly at gmail.com Mon May 16 11:37:44 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 16 May 2011 09:37:44 -0600 Subject: obviscating python code for distribution In-Reply-To: <4DD0C16B.4010500@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> <4DD0C16B.4010500@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 12:17 AM, Littlefield, Tyler wrote: >>Write your "game" for the "web". >>Write is as a SaaS (Software as a Service) - even if it's free and open >> source. > I understood you loud and clear. And that makes a lot of assumptions on my > game and the design. I don't really care to host this over the web. I want a > centralized server that would perform the logic, where I can offload the > playing of sounds (through a soundpack that's already installed) to the > client-side. > Not only that, but a lot of web technologies that would be used for this > wouldn't really work, as I am doing this for the blind; Flash as well as a > lot > of the popular setups are not very accessible. Probably the best thing you can do is just to treat your client as untrusted. That means: 1) Avoid sending it any data that you would not want the user to have. If they want it, they'll find a way to get it. 2) Don't rely on the client to restrict the user. If they're not supposed to be able to send a command 10 times a second, that should be enforced by the server. If the client has no useful data beyond what is normally presented to the user, and if every input that the server will accept can be done with the vanilla client, then there is no way to cheat, and the only reason remaining to hack up the client that could be detrimental to gameplay is for botting. For that, I'm afraid you'll just have to employ detection algorithms and enforce a strict no-botting policy. Cheers, Ian From trisha4u4u at gmail.com Mon May 16 11:41:01 2011 From: trisha4u4u at gmail.com (Elisha trisha4uuu.blogspot.com) Date: Mon, 16 May 2011 08:41:01 -0700 (PDT) Subject: KAJAL old pictures Message-ID: <93150c74-69bf-4836-b659-10c256145487@x38g2000pri.googlegroups.com> she is good and most poplar actress she is looking very cute and milky white and big eyes and good looking she always smiley face she act wit top and young hero's Ramcharan teja, JR.Ntr, Ram,Prabas,Kalyanram,Allu Arjun, and also top tamil hero's her more pictures wallpapers photos for you watch and enjoy http://trisha4uuu.blogspot.com/2011/05/kajal-hot-old-wallpapers.html From robert.kern at gmail.com Mon May 16 11:44:57 2011 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 16 May 2011 10:44:57 -0500 Subject: Parsing a graph image In-Reply-To: <20110516153854.28b7fe4f@chaostal.de> References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> <20110516153854.28b7fe4f@chaostal.de> Message-ID: On 5/16/11 8:38 AM, Bastian Ballmann wrote: > Hi, > > the project sounds like the exact tool that i need but regarding the > user manual one has to mark the points on the graph manually. Therefore > it's more work to get the data out than doing it without a tool. Or may > I miss something here? You are probably looking at the tutorials for manually digitizing graphs. Check out this one: http://digitizer.sourceforge.net/usermanual/tutorautolinegraph.html -- 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 affdfsdfdsfsd at b.com Mon May 16 12:25:00 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 16 May 2011 16:25:00 GMT Subject: regular expression i'm going crazy Message-ID: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> pls help me fixing this: import re s = "linka la baba" re_s = re.compile(r'(link|l)a' , re.IGNORECASE) print re_s.findall(s) output: ['link', 'l'] why? i want my re_s to find linka and la, he just find link and l and forget about the ending a. can anyone help me? trying the regular expression in redemo.py (program provided with python to explore the use of regular expression) i get what i want, so i guess re_s is ok, but it still fail... why? help! Nico From python at mrabarnett.plus.com Mon May 16 12:39:11 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 May 2011 17:39:11 +0100 Subject: Convert AWK regex to Python In-Reply-To: References: Message-ID: <4DD1532F.1090204@mrabarnett.plus.com> On 16/05/2011 09:19, J wrote: [snip] > #!/usr/bin/python > > # Import RegEx module > import re as regex > # Log file to work on > filetoread = open('/tmp/ pdu_log.log', "r") > # File to write output to > filetowrite = file('/tmp/ pdu_log_clean.log', "w") > # Perform filtering in the log file > linetoread = filetoread.readlines() > for line in linetoread: > filter0 = regex.sub(r" filter1 = regex.sub(r"\."," ",filter0) > # Write new log file > filetowrite.write(filter1) > filetowrite.close() > # Read new log and get required fields from it > filtered_log = open('/tmp/ pdu_log_clean.log', "r") > filtered_line = filtered_log.readlines() > for line in filtered_line: > token = line.split(" ") > print token[0], token[1], token[5], token[13], token[20] > print "Done" > [snip] If you don't need the power of regex, it's faster to use string methods: filter0 = line.replace(" References: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> Message-ID: On 5/16/11 11:25 AM, Tracubik wrote: > pls help me fixing this: > > import re > s = "linka la baba" > re_s = re.compile(r'(link|l)a' , re.IGNORECASE) > > print re_s.findall(s) > > output: > ['link', 'l'] > > why? > i want my re_s to find linka and la, he just find link and l and forget > about the ending a. > > can anyone help me? trying the regular expression in redemo.py (program > provided with python to explore the use of regular expression) i get what > i want, so i guess re_s is ok, but it still fail... > why? The parentheses () create a capturing group, which specifies that the contents of the group should be extracted. See the "(...)" entry here: http://docs.python.org/library/re#regular-expression-syntax You can use the non-capturing version of parentheses if you want to just isolate the | from affecting the rest of the regex: """ (?:...) A non-capturing version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern. """ [~] |1> import re [~] |2> s = "linka la baba" [~] |3> re_s = re.compile(r'(?:link|l)a' , re.IGNORECASE) [~] |4> print re_s.findall(s) ['linka', 'la'] -- 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 alex.kapps at web.de Mon May 16 13:01:35 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Mon, 16 May 2011 19:01:35 +0200 Subject: regular expression i'm going crazy In-Reply-To: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> References: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> Message-ID: <4DD1586F.4070308@web.de> On 16.05.2011 18:25, Tracubik wrote: > pls help me fixing this: > > import re > s = "linka la baba" > re_s = re.compile(r'(link|l)a' , re.IGNORECASE) > > print re_s.findall(s) > > output: > ['link', 'l'] > > why? As the docs say: "If one or more groups are present in the pattern, return a list of groups;" http://docs.python.org/library/re.html?highlight=findall#re.findall > i want my re_s to find linka and la, he just find link and l and forget > about the ending a. Try with non-grouping parentheses: re_s = re.compile(r'(?:link|l)a' , re.IGNORECASE) From andy at earthsong.free-online.co.uk Mon May 16 13:11:01 2011 From: andy at earthsong.free-online.co.uk (andy baxter) Date: Mon, 16 May 2011 18:11:01 +0100 Subject: regular expression i'm going crazy In-Reply-To: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> References: <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it> Message-ID: <4DD15AA5.3090509@earthsong.free-online.co.uk> On 16/05/11 17:25, Tracubik wrote: > pls help me fixing this: > > import re > s = "linka la baba" > re_s = re.compile(r'(link|l)a' , re.IGNORECASE) > > print re_s.findall(s) > > output: > ['link', 'l'] > > why? > i want my re_s to find linka and la, he just find link and l and forget > about the ending a. The round brackets define a 'capturing group'. I.e. when you do findall it returns those elements in the string that match what's inside the brackets. If you want to get linka and la, you need something like this: >>> re_s = re.compile(r'((link|l)a)' , re.IGNORECASE) >>> print re_s.findall(s) [('linka', 'link'), ('la', 'l')] Then just look at the first element in each of the tuples in the array (which matches the outside set of brackets). see: http://www.regular-expressions.info/python.html From goldtech at worldpost.com Mon May 16 13:11:43 2011 From: goldtech at worldpost.com (goldtech) Date: Mon, 16 May 2011 10:11:43 -0700 (PDT) Subject: Image processing to auto adjust colors in python ? Message-ID: <4bb21cd6-6ece-4341-8231-18818e942ab3@y19g2000yqk.googlegroups.com> Hi, I'm processing thumbnails with python but one thing I need to do is to auto-adjust an image for the "best" colors. I am using ffmpeg to get thumbs three seconds into a video, sometimes the image is too dark. Normally I'd go into something like the windows program Irfan View and do "Auto Adjust Colors", but I need a comand-line solution to processes hundreds of images in a loop. I'm using Ubuntu and Python. Is there an image precessing package i could use to do this? thanks, Lee G. From nobody at nowhere.com Mon May 16 14:02:08 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 16 May 2011 19:02:08 +0100 Subject: Image processing to auto adjust colors in python ? References: <4bb21cd6-6ece-4341-8231-18818e942ab3@y19g2000yqk.googlegroups.com> Message-ID: On Mon, 16 May 2011 10:11:43 -0700, goldtech wrote: > I'm processing thumbnails with python but one thing I need to do is to > auto-adjust an image for the "best" colors. I am using ffmpeg to get > thumbs three seconds into a video, sometimes the image is too dark. > Normally I'd go into something like the windows program Irfan View and > do "Auto Adjust Colors", but I need a comand-line solution to > processes hundreds of images in a loop. I'm using Ubuntu and Python. > Is there an image precessing package i could use to do this? PIL (Python Imaging Library) is the most widely-used general-purpose image library. For more advanced tasks, the usual solution is to use PIL to load/save images and do the processing with NumPy/SciPy (array-processing library). But you might want to check whether either ImageMagick (e.g. "convert -equalize ...") or NetPBM (e.g. pnmhisteq) do what you want. If they do, it will probably be the simplest solution. From saeedullah at gmail.com Mon May 16 14:59:44 2011 From: saeedullah at gmail.com (saeed) Date: Mon, 16 May 2011 11:59:44 -0700 (PDT) Subject: Call for Papers (CFP) Message-ID: ========================================================= Journal of Emerging Trends in Computing and Information Sciences Call for Research Papers (Vol. 2 No. 6) June 2011 http://cisjournal.org/ ========================================================= Dear Sir/ Madam, Journal of Emerging Trends in Computing and Information Sciences (E- ISSN 2218-6301/ ISSN 2079-8407) is an international refereed research publishing journal, focused on promoting and publishing original high quality research work in both theoretical and scientific aspects of all disciplines of Computing and Information Sciences. The objectives of the journal are to promote and publish original high quality research and to provide a forum to the researchers and industry practitioners for exchanging ideas, knowledge, and experience. We welcome original research and industry experience papers. Contributions should be written for one of the following categories: Original research Literature Review / Systematic Literature Review Short Articles on ongoing research Preliminary Findings Technical Reports / Notes Results previously published in conferences and/or journals may be submitted as extended versions. For more information about Journal and Publication Charges, please visit http://www.cisjournal.org/. You are requested to circulate this message among your colleagues and college/university fellows. Sincerely Yours, Editor Journal of Emerging Trends in Computing and Information Sciences URL: http://www.cisjournal.org E-mail:editor at cisjournal.org From harrismh777 at charter.net Mon May 16 15:40:39 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 16 May 2011 14:40:39 -0500 Subject: obviscating python code for distribution In-Reply-To: <4dd0e507$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4dd0e507$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > To put it in a > nutshell, you can't trust*anything*. See the classic paper by Ken > Thompson, "Reflections on Trusting Trust": > This is true, but there's another way to put it pro-active--- ... expect the client to be untrustworthy. In other words, write the server code with a protocol that 'expects' the client to be hacked. Yes, it takes three times the code and at least five times the work, but its worth it. What do you do with syn floods? What do you do with attempted overruns? What if someone builds a client emulator, just to hammer your protocol and slow the server down, just for fun...? You must build your server side 'assuming' that *all* of these things are going to happen (and more), and then be able to handle them when they do. That is what makes server-side coding so difficult. In other words, you build the server in such a way that you can confidently hand Mr junior cracker your client source code and be confident that your gaming server is going to be a.o.k. Many, many, coders don't want to go to all this trouble (and don't)... mainly because they're just glad if they can get simple sockets to work. So, they don't handle attempted overruns, or syn flood open attempts, or other. One thing to remember (think about this) is whether your server/client is in a push or pull mode. *Never* allow the client to be in control (pushing) while your server is passively (pulling). The server must control everything so that the untrusted client will be *controlled* regardless of client side hacks. I realize that this probably means redesign of your server. Do it. Happy gaming! m harris From harrismh777 at charter.net Mon May 16 15:56:38 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 16 May 2011 14:56:38 -0500 Subject: problem with GKT module? In-Reply-To: References: Message-ID: alister ware wrote: > def callback(self,widget,data=None): > print widget #gives reference to radio button ok > print widget.name #widget name on windoze, None on linux Well, you're obviously using Python 2.x ... ... have you tried this in Python 3.x ? Neither here nor there... you need to know who/what is generating 'widget'. Is widget buried in gtk where you can't see how it works, or is widget a Python class (or wrapper) where you can see what its doing? The fact that widget.name returns None on the linux platform tells me that widget is a Python class (or wrapper) ... so you probably have a widget.py file somewhere... or some other module that widget is a class definition in... who knows... (at this point). It seems to me that the 'builder' is behaving differently on the two platforms (rather than Python is behaving differently on the two platforms). What happens if you change the data=None pair? What happens if you omit data=None pair? Do you see this difference with *all* widgets, or just radio buttons? kind regards, m harris From as at sci.fi Mon May 16 15:57:29 2011 From: as at sci.fi (Anssi Saari) Date: Mon, 16 May 2011 22:57:29 +0300 Subject: Get the IP address of WIFI interface References: Message-ID: Neal Becker writes: > Here's some useful snippits for linux: > > def get_default_if(): > f = open('/proc/net/route') > for i in csv.DictReader(f, delimiter="\t"): > if long(i['Destination'], 16) == 0: > return i['Iface'] > return None > > def get_ip_address(ifname): > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > return socket.inet_ntoa(fcntl.ioctl( > s.fileno(), > 0x8915, # SIOCGIFADDR > struct.pack('256s', ifname[:15]) > )[20:24]) One possible solution in Linux is asking NetworkManager, if it's in use. It knows which interfaces are active and what kind they are (LAN, WLAN, WWAN etc.) NetworkManager communicates via dbus and even includes python example scripts. So here's my scriptlet based on NetworkManager example nm-state.py. This one prints out all active devices and their type and IP address. Easily modified to print only WLAN types. import dbus, socket, struct bus = dbus.SystemBus() proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager") manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager") # Get device-specific state devices = manager.GetDevices() for d in devices: dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d) prop_iface = dbus.Interface(dev_proxy, "org.freedesktop.DBus.Properties") # Get the device's current state and interface name state = prop_iface.Get("org.freedesktop.NetworkManager.Device", "State") name = prop_iface.Get("org.freedesktop.NetworkManager.Device", "Interface") ifa = "org.freedesktop.NetworkManager.Device" type = prop_iface.Get(ifa, "DeviceType") addr = prop_iface.Get(ifa, "Ip4Address") # and print them out if state == 8: # activated addr_dotted = socket.inet_ntoa(struct.pack(' Message-ID: Alister Ware writes: > On Fri, 13 May 2011 13:13:00 +0000, alister ware wrote: > >> I am using gtk.builder with a glade generated GUI >> >> I have a simple call back defined for a radio button widget when I use >> widget.name in linux I get a value of None, windows returns the widget >> name as I would expect. >> >> is this a bug? >> if not how should i find the name of the widget that has triggered a >> call back? >> >> (I would like all my radio buttons to go to the same callback routine if >> possible to make code maintenance easier) >> > So nobody has any Ideas on this at all? You may want to post runnable code demonstrating your problem. From garyr at fidalgo.net Mon May 16 17:23:33 2011 From: garyr at fidalgo.net (garyr) Date: Mon, 16 May 2011 14:23:33 -0700 Subject: Deleting a file? Message-ID: A file can be deleted by opening it with mode os.O_TEMPORARY and then closing it. How can a file be moved to the Recycle Bin, a la Windows? From drsalists at gmail.com Mon May 16 18:37:20 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 16 May 2011 15:37:20 -0700 Subject: Memcached in python 3 In-Reply-To: References: Message-ID: Do you need something shared across multiple hosts? Across multiple CPU's of the same host? Or single process? By "Python Dictionary Manager", do you mean the manager stuff in the multiprocessing module? On Sun, May 15, 2011 at 9:52 PM, Navkirat Singh wrote: > Hi Guys, > > How can I used memcached with python 3? Are there any other good > alternatives to memcached? What about python dictionary manager, would it > compare to memcached if I were to use it for storing in-memory information? > > Any light on this matter will be appreciated. > > Regards, > Navkirat > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Mon May 16 18:42:40 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 16 May 2011 23:42:40 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> Message-ID: On Mon, 16 May 2011 03:21:00 +0100, Daniel Kluev wrote: > On Mon, May 16, 2011 at 1:04 PM, Littlefield, Tyler > wrote: >> Hello all: >> Finally, is there a good way to accomplish this? I know that I can make >> .pyc >> files, but those can be disassembled very very easily with the >> disassembler >> and shipping these still means that the person needs the modules that >> are >> used. Is there another way to go about this? > > No, there is no way to prevent users from getting access to raw python > sources. By its nature and design, python is not meant to be used this > way, and even obfuscation would not harm readability much. > However, you can write all parts you want to hide in C/C++/Cython and > distribute them as .so/.dll ...which is, of course, not exactly secure either. A sufficiently determined hacker won't have much trouble disassembling a shared library even if you do strip out all the debug information. By chance I'm having to do something closely related to this at work just at the moment; it's hard, but far from impossible. -- Rhodri James *-* Wildebeest Herder to the Masses From luke.leighton at gmail.com Mon May 16 19:32:12 2011 From: luke.leighton at gmail.com (Luke Kenneth Casson Leighton) Date: Tue, 17 May 2011 00:32:12 +0100 Subject: pythonwebkit-gtk, pythonwebkit-dfb Message-ID: in preparation for a 0.8 release of pyjamas, a bit of work has been done on pythonwebkit (http://www.gnu.org/software/pythonwebkit) that makes it easier to compile and install. pythonwebkit provides full and complete (see caveats below!) bindings to web browser functionality... in python. what you would normally expect to be able to do in javascript "in-browser", you can do EXACTLY the same thing, in a "declarative" programming style, in python: import gtk import pywebkitgtk url = "http://www.gnu.org/software/pythonwebkit" wv = pywebkitgtk.WebView(1024,768, url=url) def _doc_loaded(*args): doc = wv.GetDomDocument() txt = doc.createTextNode("hello") doc.body.appendChild(txt) wv.SetDocumentLoadedCallback(_doc_loaded) gtk.main() yes, that's really python, doing a createTextNode and an appendChild, *not* javascript. not interpreted javascript, not interpreted python, *real* python, byte-coded and everything. throw in some AJAX, some browser event callbacks (onclick etc.) and some web browser timer callbacks and it all starts to get a bit weird, as two or maybe three disparate programming worlds that should never really have been brought together suddenly.. um... well, are brought together. the bit that's easier about installing pythonwebkit is that it is no longer necessary to download and patch up the http://code.google.com/p/pywebkitgtk project in order to use pythonwebkit. you can simply do "./autogen.sh" followed by the usual "make" and "make install". a new and absolute minimalist python module is created and installed which will get you a blank window - just like if you were firing up a python-GTK application or a python-QT4 application. anyway - just a bit of an informal not-really-announcement because, well, it's a side-dependency to the pyjamas project, even if it is a whopping 20mb one. those caveats btw are that a) you can't set CSS properties as if they were python object properties: you have to use the method "setProperty", duh, and b) there are *no* 2D or 3D SVG Canvas objects or functions available, yet, because it would take a good full-time 7 to 10 days to smack the codegenerator into shape and i'm waiting for someone to step forward and fund that work. am still servicing ?20,000 in debt and still have to find a way to pay back a complete stranger who incredibly kindly paid ?4,000 in owed rent so that we did not end up with a County Court Judgement against us. myself, my partner and our 25 month old daughter still got evicted, but that's another story. against this kind of background, perhaps i might be forgiven for not doing "freebie" free software development, i trust. l. From hujun.work at gmail.com Mon May 16 19:44:27 2011 From: hujun.work at gmail.com (Jun Hu) Date: Mon, 16 May 2011 16:44:27 -0700 Subject: Get the IP address of WIFI interface In-Reply-To: References: Message-ID: Thanks, this code works perfectly in ubuntu 10.04. one question though, is dbus usually implemented in other distribution of linux? On Mon, May 16, 2011 at 12:57 PM, Anssi Saari wrote: > Neal Becker writes: > > One possible solution in Linux is asking NetworkManager, if it's in > use. It knows which interfaces are active and what kind they are (LAN, > WLAN, WWAN etc.) NetworkManager communicates via dbus and even > includes python example scripts. So here's my scriptlet based on > NetworkManager example nm-state.py. This one prints out all active > devices and their type and IP address. Easily modified to print only > WLAN types. > > import dbus, socket, struct > > bus = dbus.SystemBus() > > proxy = bus.get_object("org.freedesktop.NetworkManager", > "/org/freedesktop/NetworkManager") > manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager") > > # Get device-specific state > devices = manager.GetDevices() > for d in devices: > dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d) > prop_iface = dbus.Interface(dev_proxy, > "org.freedesktop.DBus.Properties") > > # Get the device's current state and interface name > state = prop_iface.Get("org.freedesktop.NetworkManager.Device", "State") > name = prop_iface.Get("org.freedesktop.NetworkManager.Device", > "Interface") > ifa = "org.freedesktop.NetworkManager.Device" > type = prop_iface.Get(ifa, "DeviceType") > addr = prop_iface.Get(ifa, "Ip4Address") > > # and print them out > if state == 8: # activated > addr_dotted = socket.inet_ntoa(struct.pack(' > s = "Device %s is activated and has type %s and address %s" > print s % (name, type, addr_dotted) > else: > print "Device %s is not activated" % name > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon May 16 20:22:48 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 10:22:48 +1000 Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> Message-ID: <8739kegopz.fsf@benfinney.id.au> "Littlefield, Tyler" writes: > I wanted to make the client in python, and the server possibly, though > I'm not really sure on that. I was not worried about the code for the > server being stolen, as much as I was worried about people tinkering > with the client code for added advantages. Thank you for making your constraints explicit; that's more than most people do when asked. As Steven said, you're trying to solve a problem which is very difficult, and obfuscating the code won't be of much help. If people have the program running on their own computers, they can hack it. You can't stop that, so you have to consider other ways of making it ineffective. -- \ ?The fact that a believer is happier than a skeptic is no more | `\ to the point than the fact that a drunken man is happier than a | _o__) sober one.? ?George Bernard Shaw | Ben Finney From ben+python at benfinney.id.au Mon May 16 20:27:48 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 10:27:48 +1000 Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <877h9rguak.fsf@benfinney.id.au> Message-ID: <87y626f9x7.fsf@benfinney.id.au> Grant Edwards writes: > On 2011-05-16, Ben Finney wrote: > > "Littlefield, Tyler" writes: > > > >> I'm putting lots of work into this. I would rather not have some > >> script kiddy dig through it, yank out chunks and do whatever he > >> wants. I just want to distribute the program as-is, not distribute > >> it and leave it open to being hacked. > > > > How do these arguments apply to your code base when they don't apply > > to, say, LibreOffice or Linux or Python or Apache or Firefox? > > One obvious way that those arguments don't apply is that the OP didn't > put lots of work into LibreOffice, Linux, Python, Apache or Firefox Yet the copyright holders *did* put lots of effort into those works respectively. So the arguments would apply equally well; which is to say, they don't. > > How is your code base going to be harmed by having the source code > > available to recipients, when that demonstrably doesn't harm > > countless other code bases out there? > > The owner of something is free to determine how it is distributed -- > he doesn't have any obligation to prove to you that some particular > method of distribution is harmful to him or anybody else. Note that I didn't say anything about obligation or harm to persons. I asked only about the code base and the distribution thereof. In the meantime, Tyler has come back to us with arguments that *do* differentiate between the above cases and his own. So thanks, Tyler, for answering the questions. -- \ ?Of course, everybody says they're for peace. Hitler was for | `\ peace. Everybody is for peace. The question is: what kind of | _o__) peace?? ?Noam Chomsky, 1984-05-14 | Ben Finney From ben+python at benfinney.id.au Mon May 16 20:30:22 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 10:30:22 +1000 Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> <4DD0C127.80300@tysdomain.com> Message-ID: <87r57yf9sx.fsf@benfinney.id.au> "Littlefield, Tyler" writes: > Anyway, thanks to everyone else who answered this thread. I've not > done much like this besides muds, and all the logic is on the server > there, I think I will build the client in python, open source it for > people to fix/add to if they want and make sure to keep the server as > secure as it can be. Sounds like a good approach to me that doesn't treat users as necessarily hostile. I wish you good fortune in building a strong community around the game so that it can defend itself from cheaters, and a free-software client will IMO promote exactly that. -- \ ?I do not believe in immortality of the individual, and I | `\ consider ethics to be an exclusively human concern with no | _o__) superhuman authority behind it.? ?Albert Einstein, letter, 1953 | Ben Finney From ben+python at benfinney.id.au Mon May 16 20:33:16 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 10:33:16 +1000 Subject: Converting a set into list References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> Message-ID: <87mximf9o3.fsf@benfinney.id.au> TheSaint writes: > Thomas Rachel wrote: > > > Which loops do you mean here? > > list(set) has been proved to largely win against > list = [] > for item in set: > list.append(item) > or [list.append(item) for item in set] Remember that the criterion of speed is a matter of the implementation, and what's fast on one won't necessarily be fast on others. Which implementations did you try? Where I do agree is that ?list(foo)? wins over the other examples you show on the important criteria of concision and readability. -- \ ?A thing moderately good is not so good as it ought to be. | `\ Moderation in temper is always a virtue; but moderation in | _o__) principle is always a vice.? ?Thomas Paine | Ben Finney From bahamutzero8825 at gmail.com Mon May 16 21:05:25 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 16 May 2011 20:05:25 -0500 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD0D1A2.6060109@free.fr> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> Message-ID: <4DD1C9D5.4070206@gmail.com> On 2011.05.16 02:26 AM, Karim wrote: > Use regular expression for bad HTLM or beautifulSoup (google it), below > a exemple to extract all html links: > > linksList = re.findall('.*?',htmlSource) > for link in linksList: > print link I was afraid I might have to use regexes (mostly because I could never understand them). Even the BeautifulSoup website itself admits it's awful with Python 3 - only the admittedly broken 3.1.0 will work with Python 3 at all. ElementTree doesn't seem to have been updated in a long time, so I'll assume it won't work with Python 3. lxml looks promising, but it doesn't say anywhere whether it'll work on Python 3 or not, which is puzzling since the latest release was only a couple months ago. Actually, if I'm going to use regex, I might as well try to implement Versions* in Python. Thanks for the answers! *http://en.totalcmd.pl/download/wfx/net/Versions (original, made for Total Commander) and https://addons.mozilla.org/en-US/firefox/addon/versions-wfx_versions/ (clone implemented as a Firefox add-on; it's so wonderful, I even wrote the docs for it!) From nospam at torek.net Mon May 16 21:07:41 2011 From: nospam at torek.net (Chris Torek) Date: 17 May 2011 01:07:41 GMT Subject: Converting a set into list References: <871v00j2bh.fsf@benfinney.id.au> Message-ID: >Chris Torek wrote: >> >>> x = [3, 1, 4, 1, 5, 9, 2, 6] >> >>> list(set(x)) >> This might not be the best example since the result is sorted >> "by accident", while other list(set(...)) results are not. In article , Duncan Booth wrote: >A minor change to your example makes it out of order even for integers: > >>>> x = [7, 8, 9, 1, 4, 1] >>>> list(set(x)) >[8, 9, 1, 4, 7] > >or for that mattter: > >>>> list(set([3, 32, 4, 32, 5, 9, 2, 6])) >[32, 2, 3, 4, 5, 6, 9] Yes, but then it is no longer "as easy as pi". :-) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From ben+python at benfinney.id.au Mon May 16 21:39:37 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 11:39:37 +1000 Subject: Deleting a file? References: Message-ID: <878vu6f6li.fsf@benfinney.id.au> "garyr" writes: > A file can be deleted by opening it with mode os.O_TEMPORARY and then > closing it. Much simpler: ?os.remove(path)?. > How can a file be moved to the Recycle Bin, a la Windows? That's not deleting it (as you probably know), so you might better change the subject field for the thread. -- \ ?Unix is an operating system, OS/2 is half an operating system, | `\ Windows is a shell, and DOS is a boot partition virus.? ?Peter | _o__) H. Coffin | Ben Finney From malaclypse2 at gmail.com Mon May 16 23:06:44 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 16 May 2011 23:06:44 -0400 Subject: Deleting a file? In-Reply-To: References: Message-ID: On Mon, May 16, 2011 at 5:23 PM, garyr wrote: > A file can be deleted by opening it with mode os.O_TEMPORARY and then > closing it. How can a file be moved to the Recycle Bin, a la Windows? I see a send2trash module (http://hg.hardcoded.net/send2trash and http://www.hardcoded.net/articles/send-files-to-trash-on-all-platforms.htm) The source code looks pretty straightforward, but I don't think there's anything in the standard library that does that. -- Jerry From wuwei23 at gmail.com Mon May 16 23:45:55 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 16 May 2011 20:45:55 -0700 (PDT) Subject: obviscating python code for distribution References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> <4DD0B903.4090109@tysdomain.com> <4DD0C127.80300@tysdomain.com> Message-ID: <15eb7b39-fea0-4f9c-8673-2b13c17705c5@34g2000pru.googlegroups.com> "Littlefield, Tyler" wrote: > Anyway, thanks to everyone else who answered this thread. I've not done > much like this besides muds, and all the logic is on the server there, I > think I will build the client in python, open source it for people to > fix/add to if they want and make sure to keep the server as secure as it > can be. The browser-based game Lacuna Expanse actually open sources the Perl client for their game, it might be a good place for ideas on how to approach this: https://github.com/plainblack/Lacuna-Web-Client The MMO EVE uses Stackless Python for both the client & server. Here's a slightly older doc detailing their architecture: http://www.slideshare.net/Arbow/stackless-python-in-eve Hope this helps. From n4vpython at gmail.com Tue May 17 00:36:34 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Tue, 17 May 2011 10:06:34 +0530 Subject: Memcached in python 3 In-Reply-To: References: Message-ID: On Tue, May 17, 2011 at 4:07 AM, Dan Stromberg wrote: > > Do you need something shared across multiple hosts? Across multiple CPU's > of the same host? Or single process? > > By "Python Dictionary Manager", do you mean the manager stuff in the > multiprocessing module? > > On Sun, May 15, 2011 at 9:52 PM, Navkirat Singh wrote: > >> Hi Guys, >> >> How can I used memcached with python 3? Are there any other good >> alternatives to memcached? What about python dictionary manager, would it >> compare to memcached if I were to use it for storing in-memory information? >> >> Any light on this matter will be appreciated. >> >> Regards, >> Navkirat >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > Hi, I need something that can be scalable. Something that if needed, can scale to multiple hosts. Yes, I mean the manager stuff in the multiprocessing module. Regards, Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From n4vpython at gmail.com Tue May 17 00:48:52 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Tue, 17 May 2011 10:18:52 +0530 Subject: Python 3 vs Python 2.7 dilemma Message-ID: Hi Guys, I have been trying to fight this issue for sometime now. I know that a large part of the python 3rd party software base has not been ported to python 3 yet. I am trying to build a web-based enterprise solution for my client. Most of reputed frameworks like Django and Turbo gears are yet in the 2.x stage. I know that these frameworks are extremely good. But I wanted to build my base with python 3 as that is what is going to prevail in the future. I have built my own little architecture using python3. Here is what I have accomplished till now: a) A multiprocessing webserver built directly using low level sockets for maximum control, conforming to RFC 2616 (not completely right now). b) A HTTP message parser for parsing HTTP/1.1 requests and generating response messages c) A session control base using python multiprocessing dictionary manager d) A partially build MVC model, without a templating engine at the moment. I am planning to put Jinja 3 there. I have spent months of free time doing this. I have learnt a lot, but well I am not sure if the path I am on is the right one. My question to everyone is whether I should go ahead with this approach, or should I just use 2.x technology? I am not sure if I will be able to port all the code to python3 later. I will really appreciate any input. Thanks and regards, Navkirat -------------- next part -------------- An HTML attachment was scrubbed... URL: From highfellow at gmail.com Tue May 17 01:13:21 2011 From: highfellow at gmail.com (Andy Baxter) Date: Tue, 17 May 2011 06:13:21 +0100 Subject: indirect assignment question Message-ID: <4DD203F1.1000202@gmail.com> Hi, I have some lines of code which currently look like this: self.window = self.wTree.get_widget("mainWindow") self.outputToggleMenu = self.wTree.get_widget("menuitem_output_on") self.outputToggleButton = self.wTree.get_widget("button_toggle_output") self.logView = self.wTree.get_widget("textview_log") self.logScrollWindow = self.wTree.get_widget("scrolledwindow_log") and I would like (for tidiness / compactness's sake) to replace them with something like this: widgetDic = { "mainWindow": self.window, "menuitem_output_on": self.outputToggleMenu, "button_toggle_output": self.outputToggleButton, "textview_log": self.logView, "scrolledwindow_log": self.logScrollWindow } for key in widgetDic: ... set the variable in dic[key] to point to self.wTree.get_widget(key) somehow what I need is some kind of indirect assignment where I can assign to a variable whose name is referenced in a dictionary value. Is there a way of doing this in python? thanks, andy baxter -- http://highfellow.org From clp2 at rebertia.com Tue May 17 01:24:34 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 May 2011 22:24:34 -0700 Subject: indirect assignment question In-Reply-To: <4DD203F1.1000202@gmail.com> References: <4DD203F1.1000202@gmail.com> Message-ID: On Mon, May 16, 2011 at 10:13 PM, Andy Baxter wrote: > Hi, > > I have some lines of code which currently look like this: > > ? ? ?self.window = self.wTree.get_widget("mainWindow") > ? ? ?self.outputToggleMenu = self.wTree.get_widget("menuitem_output_on") > ? ? ?self.outputToggleButton = self.wTree.get_widget("button_toggle_output") > ? ? ?self.logView = self.wTree.get_widget("textview_log") > ? ? ?self.logScrollWindow = self.wTree.get_widget("scrolledwindow_log") > > and I would like (for tidiness / compactness's sake) to replace them with > something like this: > ? ? ? ?widgetDic = { > ? ? ? ? ? "mainWindow": self.window, > ? ? ? ? ? "menuitem_output_on": self.outputToggleMenu, > ? ? ? ? ? "button_toggle_output": self.outputToggleButton, > ? ? ? ? ? "textview_log": self.logView, > ? ? ? ? ? "scrolledwindow_log": self.logScrollWindow > ? ? ? ?} > ? ? ? ?for key in widgetDic: > ? ? ? ? ? ... set the variable in dic[key] to point to > self.wTree.get_widget(key) somehow > > what I need is some kind of indirect assignment where I can assign to a > variable whose name is referenced in a dictionary value. > > Is there a way of doing this in python? You can achieve almost the same level of brevity, with less use of magic, by simply using a local variable to refer to self.wTree.get_widget: w = self.wTree.get_widget # or choose some other similarly short variable name self.window = w("mainWindow") self.outputToggleMenu = w("menuitem_output_on") self.outputToggleButton = w("button_toggle_output") self.logView = w("textview_log") self.logScrollWindow = w("scrolledwindow_log") Python functions/methods are first-class; exploit this feature! Cheers, Chris -- http://rebertia.com From ben+python at benfinney.id.au Tue May 17 02:01:25 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 May 2011 16:01:25 +1000 Subject: indirect assignment question References: Message-ID: <87y625euh6.fsf@benfinney.id.au> Andy Baxter writes: > with something like this: > widgetDic = { > "mainWindow": self.window, > "menuitem_output_on": self.outputToggleMenu, > "button_toggle_output": self.outputToggleButton, > "textview_log": self.logView, > "scrolledwindow_log": self.logScrollWindow > } > for key in widgetDic: > ... set the variable in dic[key] to point to > self.wTree.get_widget(key) somehow > > what I need is some kind of indirect assignment where I can assign to > a variable whose name is referenced in a dictionary value. for (name, value) in widgetDic.iteritems(): setattr(self, name, value) -- \ ?The double standard that exempts religious activities from | `\ almost all standards of accountability should be dismantled | _o__) once and for all.? ?Daniel Dennett, 2010-01-12 | Ben Finney From dotancohen at gmail.com Tue May 17 02:16:35 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 17 May 2011 09:16:35 +0300 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 16, 2011 at 07:40, Chris Angelico wrote: > And I'm sure Steven will agree with me that this is not in any way a > bad thing. I've written hundreds of such programs myself (possibly > thousands), and they have all served their purposes. On a slightly > larger scale, there are even more programs that have never left the > walls of my house, having been written for my own family - not because > I'm afraid someone else will steal them, but because they simply are > of no value to anyone else. But hey, if anyone wants a copy of my code > that's basically glue between [obscure application #1] and [obscure > application #2] that does [obscure translation] as well to save a > human from having to do it afterwards, sure! You're welcome to it! :) > > However, I do not GPL my code; I prefer some of the other licenses > (such as CC-BY-SA), unless I'm working on a huge project that's not > meant to have separate authors. For something that by and large is one > person's work, I think it's appropriate to give attribution. But > discussion of exactly _which_ open source license to use is a can of > worms that's unlikely to be worth opening at this stage. > Actually, Chris, those applications are probably no less valuable to be open source than Linux or Firefox. The reason is that when one goes to learn a new language it is valuable to look at existing real world code. However, the code available online generally falls into one of two categories: 1) Simple sample code, which demonstrates a principle or technique 2) Full-blown FOSS application with hundreds of source files and a build It sounds to me like your home-brew code might be one of the missing links between the two. It won't be so tiny as to be trivial, but it won't be so huge as to be beyond the grasp of novices. I for one would love to look over such code. I'll learn something, without a doubt. Maybe someone might even spot a bug or make a suggestion to improve it. And almost invariably, any problem that I've ever had someone has had first. So while you might have been one of the first have a need to interface FooWidget with PlasmoidBar, someone after you will in fact need just the code to do that. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From rosuav at gmail.com Tue May 17 02:39:48 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 May 2011 16:39:48 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 17, 2011 at 4:16 PM, Dotan Cohen wrote: > Actually, Chris, those applications are probably no less valuable to > be open source than Linux or Firefox. The reason is that when one goes > to learn a new language it is valuable to look at existing real world > code. However, the code available online generally falls into one of > two categories: > 1) Simple sample code, which demonstrates a principle or technique > 2) Full-blown FOSS application with hundreds of source files and a build > > It sounds to me like your home-brew code might be one of the missing > links between the two. It won't be so tiny as to be trivial, but it > won't be so huge as to be beyond the grasp of novices. You have a point there. Although I can't guarantee that all my code is particularly *good*, certainly not what I'd want to hold up for a novice to learn from - partly because it dates back anywhere up to two decades, and partly because quite a few of the things I was working with are completely undocumented! But if you have Pastel Accounting Version 5, running in a Windows 3.1 virtual session, and you want to export some of its data to a DB2 database, I can help you quite a bit. Assuming you have an OS/2 system to run it on, of course. (You see what I mean about obscure?) I should probably dust off some of the slightly-more-useful pieces and put them up on either The Esstu Pack (my old web site) or rosuav.com (my new web site, doesn't have any better name than that), but that kinda requires time, a resource that I don't have an awful lot of. I'm sure there'll be a few oddments in there where at least one half of the glue is more useful. Back then, though, I didn't know Python, nor Pike, nor any of quite a few other awesome languages, but REXX and C++ are at least available open source. Chris Angelico From rustompmody at gmail.com Tue May 17 03:00:39 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 17 May 2011 00:00:39 -0700 (PDT) Subject: ipython prompt does not appear in windows Message-ID: If I use ipython under emacs on linux it works (at least basic REPL) ie I can type an expression and I get a result followed by a prompt On windows ipython works at the shell. Plain python works in emacs as well. But inside emacs I dont see a prompt in ipython although I see it in python. I have to type an expression and then the prompt appears. Any clues? From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue May 17 03:15:57 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 17 May 2011 09:15:57 +0200 Subject: indirect assignment question In-Reply-To: References: Message-ID: Am 17.05.2011 07:13 schrieb Andy Baxter: > self.window = self.wTree.get_widget("mainWindow") > self.outputToggleMenu = self.wTree.get_widget("menuitem_output_on") > self.outputToggleButton = self.wTree.get_widget("button_toggle_output") > self.logView = self.wTree.get_widget("textview_log") > self.logScrollWindow = self.wTree.get_widget("scrolledwindow_log") > > and I would like (for tidiness / compactness's sake) to replace them > with something like this: > widgetDic = { > "mainWindow": self.window, > "menuitem_output_on": self.outputToggleMenu, > "button_toggle_output": self.outputToggleButton, > "textview_log": self.logView, > "scrolledwindow_log": self.logScrollWindow > } > for key in widgetDic: > ... set the variable in dic[key] to point to self.wTree.get_widget(key) > somehow assignmap = ( ('mainWindow', 'window'), ('menuitem_output_on', 'outputToggleMenu'), ('button_toggle_output', 'outputToggleButton'), ('textview_log', 'logView'), ('scrolledwindow_log', 'logScrollWindow'), ) for name, selfname in assignmap: val = widgetDic[name] = self.wTree.get_widget(name) setattr(self, selfname, val) HTH, Thomas From akabaila at pcug.org.au Tue May 17 03:44:22 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Tue, 17 May 2011 17:44:22 +1000 Subject: Deleting a file? In-Reply-To: References: Message-ID: <201105171744.22500.akabaila@pcug.org.au> On Tuesday 17 May 2011 07:23:33 garyr wrote: > A file can be deleted by opening it with mode os.O_TEMPORARY > and then closing it. How can a file be moved to the Recycle > Bin, a la Windows? Just highlight it, pess the "Del" key and select "move to Trash". (With minor variation between different desktops, viz. KDE, gnome etc. If you ask a genuine answer, the above are genuine answers. HTH, OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From vgnulinux at gmail.com Tue May 17 03:50:07 2011 From: vgnulinux at gmail.com (VGNU Linux) Date: Tue, 17 May 2011 13:20:07 +0530 Subject: How to select Python web frameworks and which one is the best framework ? Message-ID: Hi all, I am confused on which web framework to select for developing a small data driven web application. Application will have features generally found in now-a-days web application like security, database connectivity, authentication etc. I found few web frameworks over the net like django, zope 2/3, pylons, turbogears, web2py, grok etc. etc. I just want to know that how developers/managers/organizations select a framework which best suits their needs ? what are the parameters for selection ? also which is the best and widely used web framework for python ? I apologize if this is a repeated question. Regards, VGNU -------------- next part -------------- An HTML attachment was scrubbed... URL: From hamed3099 at hotmail.com Tue May 17 05:43:51 2011 From: hamed3099 at hotmail.com (hamed azarkeshb) Date: Tue, 17 May 2011 14:13:51 +0430 Subject: FW: help please In-Reply-To: References: Message-ID: From: hamed3099 at hotmail.com To: webmaster at python.org Subject: help please Date: Tue, 17 May 2011 13:20:22 +0430 hi dearinwant to useautomation with catiaby python,but i dont know,how do we can creat catsafearrayvariant in python?please help me.i need urhelp by one example.thank u forany thing -------------- next part -------------- An HTML attachment was scrubbed... URL: From jnr.gonzalez at googlemail.com Tue May 17 06:07:34 2011 From: jnr.gonzalez at googlemail.com (J) Date: Tue, 17 May 2011 03:07:34 -0700 (PDT) Subject: Convert AWK regex to Python In-Reply-To: Message-ID: Hello, I have managed to get my script finished in the end by taking bits from everyone who answered. Thank you so much. the finished query string looks like this (still not the best but it gets the job done. Once I learn to code more with Python I will probably go back to it and re-write it):- # Log file to work on filetoread = open("/tmp/pdu.log", "r") # Perform filtering in the log file text = filetoread.read() text = text.replace(" Message-ID: Hello, I have managed to get my script finished in the end by taking bits from everyone who answered. Thank you so much. the finished query string looks like this (still not the best but it gets the job done. Once I learn to code more with Python I will probably go back to it and re-write it):- # Log file to work on filetoread = open("/tmp/pdu.log", "r") # Perform filtering in the log file text = filetoread.read() text = text.replace(" Hi list I'm using datetime.timedelta and i have a problem delta = 1 day, 2:30:00 hours = delta.days * 8 how to add 8 + 2:30:00 Regards Tsolmon. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Tue May 17 07:41:41 2011 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 17 May 2011 07:41:41 -0400 Subject: cPickle -> invalid signature Message-ID: What does it mean when cPickle.load says: RuntimeError: invalid signature Is binary format not portable? From gagsl-py2 at yahoo.com.ar Tue May 17 07:44:48 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 08:44:48 -0300 Subject: Datetime.timedelta References: Message-ID: En Tue, 17 May 2011 07:44:08 -0300, Tsolmon Narantsogt escribi?: > I'm using datetime.timedelta and i have a problem > > delta = 1 day, 2:30:00 > hours = delta.days * 8 > > how to add 8 + 2:30:00 Just operate with it as it were a number. The timedelta class implements all "sane" mathematical operations. py> from datetime import * py> def timedelta_from_dhms(days=0, hours=0, mins=0, secs=0): ... return timedelta(days, hours*3600 + mins*60 + secs) ... py> delta = timedelta_from_dhms(1, 2, 30) py> delta datetime.timedelta(1, 9000) py> hours = delta.days * 8 py> delta + hours Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'datetime.timedelta' and 'int' py> hours = timedelta_from_dhms(0, delta.days * 8) py> hours datetime.timedelta(0, 28800) py> delta + hours datetime.timedelta(1, 37800) py> def dhms_from_timedelta(td): ... return td.days, td.seconds // 3600, (td.seconds % 3600) // 60, td.seconds % 60 ... py> dhms_from_timedelta(delta + hours) (1, 10, 30, 0) -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue May 17 08:17:10 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 09:17:10 -0300 Subject: FW: help please References: Message-ID: En Tue, 17 May 2011 06:43:51 -0300, hamed azarkeshb escribi?: > hi dearinwant to useautomation with catiaby python,but i dont know,how > do we can creat catsafearrayvariant in python?please help me.i need > urhelp by one example.thank u forany thing There are two sides when you want to use automation with Python: * learn how to do automation by itself, how COM works, how to invoke a COM server from Python. This is mostly application-independent. A good resource is "Python Programming in Win32" book by Mark Hammond. Chapter 5 "Introduction to COM" is exactly what you need, and is available for preview in Google Books: http://books.google.com.ar/books?id=fzUCGtyg0MMC&lpg=PA65&pg=PA65#v=onepage&f=false * learn how to use the actual objects exposed by the desired application. Usually, documentation is available for VBA or other languages, but can be easily translated into Python terms. So I'd say you first read the book, then search the documentation about CATSafeArrayVariant and see how to create it, and then translate that into Python. Feel free to post any problem you encounter, a better place would be the python-win32 list: http://mail.python.org/mailman/listinfo/python-win32 Good luck! -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue May 17 08:29:01 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 09:29:01 -0300 Subject: cPickle -> invalid signature References: Message-ID: En Tue, 17 May 2011 08:41:41 -0300, Neal Becker escribi?: > What does it mean when cPickle.load says: > RuntimeError: invalid signature > > Is binary format not portable? Are you sure that's the actual error message? I cannot find such message anywhere in the sources. The pickle format is quite portable, even cross-version. As a generic answer, make sure you open the file in binary mode, both when writing and reading. -- Gabriel Genellina From chaoyuejoy at gmail.com Tue May 17 08:53:20 2011 From: chaoyuejoy at gmail.com (Yue Chao) Date: Tue, 17 May 2011 14:53:20 +0200 Subject: where to find shared python script? Message-ID: Dear all, I am new to python and thank you for your help! the first question is, is there any resource online where we can find shared python script (like reading a csv file for ready plot making, I know to use csv module while I find it's not good enough) . The second one is, is there a search function in the our mailing list archive http://mail.python.org/pipermail/python-list/. ? Best, Chao -- *********************************************************************************** Chao YUE Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL) UMR 1572 CEA-CNRS-UVSQ Batiment 712 - Pe 119 91191 GIF Sur YVETTE Cedex Tel: (33) 01 69 08 77 30 Portable Phone (Mobil phone) : (33) 07 60 54 23 71 ************************************************************************************ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue May 17 09:10:07 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 17 May 2011 14:10:07 +0100 Subject: where to find shared python script? In-Reply-To: References: Message-ID: <4DD273AF.7090000@timgolden.me.uk> On 17/05/2011 13:53, Yue Chao wrote: > I am new to python and thank you for your help! > the first question is, is there any resource online where we can find > shared python script (like reading a csv file for ready plot making, I > know to use csv module while I find it's not good enough) . I don't know if that specific example is there, but the ActiveState Python Cookbook is usually a good resource: http://code.activestate.com/recipes/langs/python/ > The second one is, is there a search function in the our mailing list > archive http://mail.python.org/pipermail/python-list/. ? http://www.google.com/search?q=site%3Amail.python.org+csv%20module&safe=active There's also the corresponding Google Group: http://groups.google.com/group/comp.lang.python/topics?lnk and MarkMail: http://python.markmail.org/ and GMane: http://news.gmane.org/gmane.comp.python.general and quite a few others which republish the list as Web pages TJG From matt.j.warren at gmail.com Tue May 17 09:33:25 2011 From: matt.j.warren at gmail.com (AlienBaby) Date: Tue, 17 May 2011 06:33:25 -0700 (PDT) Subject: Convert AWK regex to Python References: Message-ID: <12e7b8b8-20ac-40b1-bb66-3a9e22172b3f@d28g2000yqf.googlegroups.com> On May 17, 11:07?am, J wrote: > Hello, > > I have managed to get my script finished in the end by taking bits from everyone who answered. ?Thank you so much. ?the finished query string looks like this (still not the best but it gets the job done. ?Once I learn to code more with Python I will probably go back to it and re-write it):- > > # Log file to work on > filetoread = open("/tmp/pdu.log", "r") > # Perform filtering in the log file > text = filetoread.read() > text = text.replace(" text = text.replace(".", " ") > text = text.replace(r"(", " ") > filetoread.close() > # File to write output to > filetowrite = file("/tmp/pdu_filtered.log", "w") > # Write new log file > filetowrite.write(text) > filetowrite.close() > # Read new log and get required fields from it > filtered_log = ?open("/tmp/pdu_filtered.log", "r") > filtered_line = filtered_log.readlines() > for line in filtered_line: > ? ? ? ? field = line.split(" ") > ? ? ? ? field5 = field[5].rsplit("_", 1) > ? ? ? ? print field5[0], field[14], field[22] > print "Done" You can also process the lines and write them out to the new logfile as you read them in first time around, rather than: read them in, process them, write them out, read them in, process them, write them out; log_file=open("old_log_file","r") output_file=open("new_log_file","w") for line in log_file: line=line.replace(" References: <87boz3gw5u.fsf@benfinney.id.au> <4dd0a1fc$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110517093623.c420c9b3.darcy@druid.net> On Tue, 17 May 2011 16:39:48 +1000 Chris Angelico wrote: > You have a point there. Although I can't guarantee that all my code is > particularly *good*, certainly not what I'd want to hold up for a > novice to learn from - partly because it dates back anywhere up to two > decades, and partly because quite a few of the things I was working > with are completely undocumented! Sounds like a perfect reason to open source it. If what you say is true it could benefit you more than others, at least at the beginning. Remember, open source is a two way street. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From harrismh777 at charter.net Tue May 17 09:58:03 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 17 May 2011 08:58:03 -0500 Subject: Convert AWK regex to Python In-Reply-To: References: Message-ID: J wrote: > Hello, Hello, J, This is totally off-topic, but I was wondering why you are posting with double messages (triple) all over the place? Your reply-to is set to comp.lang.python at googlegroups.com, and you cc to python-list at python.org... and you're stuff is showing up in newsgroup comp.lang.python... ... did you know that all you need to do is use the newsgroup (use a client like sea monkey, or other... ) and your posts will show up in googlegroups, and will also be archived forever.... authomatically? Your messages are duplicating which is not only annoying on the surface, but also breaks the threads apart in a news client. What should appear (and does in googlegroups) as a single thread appears as many threads in the mail client; partly because of the RE: in the subject, and partly because of the reduplication. Just a heads up.... kind regards, m harris From jorgeromero178 at gmail.com Tue May 17 10:10:30 2011 From: jorgeromero178 at gmail.com (Jorge Romero) Date: Tue, 17 May 2011 10:10:30 -0400 Subject: Python 3 vs Python 2.7 dilemma In-Reply-To: References: Message-ID: I would recommend you going on the Python 2.x path. Python 2.x is far from being deprecated. According to Wesley Chun (active member of Python community and author of Core Python Programming) on a Google I/O talk, everybody will be using Python 3 by 2018, so there's still plenty of time. Besides, you can start with Python 2.7, which still is 2.x but introduces 3.x features, and in some benchmarks seems to be more efficient than latest 3.x. 3.x is said to be backwards incompatible, but that incompatibility is not something that would bring you a limitation on porting your code later. So, for the sake of web frameworks and runtime infrastructures, I'd stick to 2.x. This is my IMHO, I'm sure you can get a more accurate answer from someone in this list more experienced in the matter ;) Have a good one. On Tue, May 17, 2011 at 12:48 AM, Navkirat Singh wrote: > Hi Guys, > > I have been trying to fight this issue for sometime now. I know that a > large part of the python 3rd party software base has not been ported to > python 3 yet. I am trying to build a web-based enterprise solution for my > client. Most of reputed frameworks like Django and Turbo gears are yet in > the 2.x stage. I know that these frameworks are extremely good. But I wanted > to build my base with python 3 as that is what is going to prevail in the > future. > > I have built my own little architecture using python3. Here is what I have > accomplished till now: > > a) A multiprocessing webserver built directly using low level sockets for > maximum control, conforming to RFC 2616 (not completely right now). > b) A HTTP message parser for parsing HTTP/1.1 requests and generating > response messages > c) A session control base using python multiprocessing dictionary manager > d) A partially build MVC model, without a templating engine at the moment. > I am planning to put Jinja 3 there. > > I have spent months of free time doing this. I have learnt a lot, but well > I am not sure if the path I am on is the right one. > > My question to everyone is whether I should go ahead with this approach, or > should I just use 2.x technology? I am not sure if I will be able to port > all the code to python3 later. > > I will really appreciate any input. > > Thanks and regards, > Navkirat > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Jorge Romero -------------- next part -------------- An HTML attachment was scrubbed... URL: From mosmann at expires-31-05-2011.news-group.org Tue May 17 10:40:54 2011 From: mosmann at expires-31-05-2011.news-group.org (Andreas Mosmann) Date: Tue, 17 May 2011 16:40:54 +0200 Subject: Newbie: Python 3.2, search for module dBase + Excel Message-ID: <1305643254.64@user.newsoffice.de> Hi, I am new to python and so I decided to use python 3.2 But, if I found out correctly, the are no working modules concerning Excel and dBase for this python version. Did I only misunderstand anything or is this right? I tried to download and use pydbf and pyexcelerator but both gave me an syntax error inside the modules and I somewhere read, that both modules only exist for version 2.X Is there a way for me to use them anyway or do I have to change to any 2.X- Version? If last, which should I install? Thanks in advance Andreas remark: My task is to compare 2 directories incl. subdirs containing dBase- Files and find out differencers in FileNames and FileStructures. Up t now I devided it into 3 lists: OnlyInDir1, OnlyInDir2 and InBothDirs. Next step is to put it into an Excel- File with 3 worksheets. If this would be impossible, so I could save this in any other way. But I really need a module that handles dBase- files to compare Structures of files with equal names. My Code up to now is something like import os dirV1 = "C:\Path1" dirV2 = "C:\Path2" anzL1=0 listV1 = [] for root, dirs, files in os.walk(dirV1): for file in files: myFile=os.path.join(root[len(dirV1):], file) listV1.append(myFile) anzL1=anzL1+1 print(anzL1) anzL2=0 anzLG=0 listV2 = [] listGem = [] for root, dirs, files in os.walk(dirV2): for file in files: myFile=os.path.join(root[len(dirV2):], file) try: listV1.index(myFile) listV1.remove(myFile) listGem.append(myFile) anzL1=anzL1-1 anzLG=anzLG+1 except ValueError: listV2.append(myFile) anzL2=anzL2+1 print(anzL1) print(anzLG) print(anzL2) -- wenn email, dann AndreasMosmann web de From garyr at fidalgo.net Tue May 17 10:43:41 2011 From: garyr at fidalgo.net (garyr) Date: Tue, 17 May 2011 07:43:41 -0700 Subject: Deleting a file? References: Message-ID: Jerry, There was an error during the install but only required a minor change to an __init__.py file to correct. Works great. Just what I was looking for. Many thanks! Gary "Jerry Hill" wrote in message news:mailman.1654.1305601607.9059.python-list at python.org... > On Mon, May 16, 2011 at 5:23 PM, garyr wrote: >> A file can be deleted by opening it with mode os.O_TEMPORARY and then >> closing it. How can a file be moved to the Recycle Bin, a la Windows? > > I see a send2trash module (http://hg.hardcoded.net/send2trash and > http://www.hardcoded.net/articles/send-files-to-trash-on-all-platforms.htm) > > The source code looks pretty straightforward, but I don't think > there's anything in the standard library that does that. > > -- > Jerry From eric.frederich at gmail.com Tue May 17 11:14:21 2011 From: eric.frederich at gmail.com (Eric Frederich) Date: Tue, 17 May 2011 11:14:21 -0400 Subject: portable multiprocessing code Message-ID: I have written some code using Python 2.7 but I'd like these scripts to be able to run on Red Hat 5's 2.4.3 version of Python which doesn't have multiprocessing. I can try to import multiprocessing and set a flag as to whether it is available. Then I can create a Queue.Queue instead of a multiprocessing.Queue for the arg_queue and result_queue. Without actually trying this yet it seems like things would work okay except for the Worker class. It seems I can conditionally replace multiprocessing.Queue with Queue.Queue, but is there anything to replace multiprocessing.Process with? Are there any best practices for doing something like this? Below is a dumb example that just counts lines in files. What would be the best way to make this runnable in older (2.4.3) versions of Python? #!/usr/bin/env python import sys import os import multiprocessing import Queue fnames = sys.argv[1:] def SimpleWorker(func): class SimpleWorker_wrapped(multiprocessing.Process): def __init__(self, arg_queue, result_queue): super(SimpleWorker_wrapped, self).__init__() self.arg_queue = arg_queue self.result_queue = result_queue def run(self): while True: try: args = self.arg_queue.get_nowait() except Queue.Empty: break self.result_queue.put(func(*args)) return SimpleWorker_wrapped @SimpleWorker def line_counter(fname): lc = len(open(fname).read().splitlines()) return fname, lc arg_queue = multiprocessing.Queue() result_queue = multiprocessing.Queue() for fname in fnames: arg_queue.put((fname,)) for i in range(multiprocessing.cpu_count()): w = line_counter(arg_queue, result_queue) w.start() results = {} for fname in sorted(fnames): while fname not in results: n, i = result_queue.get() results[n] = i print "%-40s %d" % (fname, results[fname]) From benjamin.kaplan at case.edu Tue May 17 11:49:02 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 17 May 2011 08:49:02 -0700 Subject: portable multiprocessing code In-Reply-To: References: Message-ID: On Tue, May 17, 2011 at 8:14 AM, Eric Frederich wrote: > I have written some code using Python 2.7 but I'd like these scripts > to be able to run on Red Hat 5's 2.4.3 version of Python which doesn't > have multiprocessing. > I can try to import multiprocessing and set a flag as to whether it is > available. ?Then I can create a Queue.Queue instead of a > multiprocessing.Queue for the arg_queue and result_queue. > Without actually trying this yet it seems like things would work okay > except for the Worker class. ?It seems I can conditionally replace > multiprocessing.Queue with Queue.Queue, but is there anything to > replace multiprocessing.Process with? > > Are there any best practices for doing something like this? > Below is a dumb example that just counts lines in files. > What would be the best way to make this runnable in older (2.4.3) > versions of Python? > http://pypi.python.org/pypi/multiprocessing Also, you may be able to find the processing package (what multiprocessing was called back when it was 3rd party) in your package manager. From rbotting at csusb.edu Tue May 17 11:50:59 2011 From: rbotting at csusb.edu (RJB) Date: Tue, 17 May 2011 08:50:59 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers Message-ID: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> I noticed some discussion of recursion..... the trick is to find a formula where the arguments are divided, not decremented. I've had a "divide-and-conquer" recursion for the Fibonacci numbers for a couple of years in C++ but just for fun rewrote it in Python. It was easy. Enjoy. And tell me how I can improve it! def fibo(n): """A Faster recursive Fibonaci function Use a formula from Knuth Vol 1 page 80, section 1.2.8: If F[n] is the n'th Fibonaci number then F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. First set m = n+1 F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. Then put m = n in Knuth's formula, F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], and replace F[n+1] by F[n]+F[n-1], F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). """ if n<=0: return 0 elif n<=2: return 1 elif n%2==0: half=n//2 f1=fibo(half) f2=fibo(half-1) return f1*(f1+2*f2) else: nearhalf=(n-1)//2 f1=fibo(nearhalf+1) f2=fibo(nearhalf) return f1*f1 + f2*f2 RJB the Lurker http://www.csci.csusb.edu/dick/cs320/lab/10.html From luke.leighton at gmail.com Tue May 17 12:07:14 2011 From: luke.leighton at gmail.com (lkcl) Date: Tue, 17 May 2011 09:07:14 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: Message-ID: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> On May 4, 7:37?pm, Terry Reedy wrote: > On 5/4/2011 10:06 AM, Luke Kenneth Casson Leighton wrote: > > > after a long delay thepyjamasproject -http://pyjs.org- has begun the > > 0.8 series of releases, beginning with alpha1: > > >https://sourceforge.net/projects/pyjamas/files/pyjamas/0.8/ > > >pyjamasis a suite of projects, including a python-to-javascript > > compiler > > As you well know, there is no such thing as 'python' when it comes to > compiling actual code. So please specify both in announcements here and > on the project homepagehttp://sourceforge.net/projects/pyjamas/ > which versions are supported. I do not really want to have to download > and experiment to determine whether to bother downloading. > > If you do not yet support 3.x, I request and recommend that you do so, with the situation as it is, there is not a snowball in hell's chance that's going to happen. allow me to explain. the python translator in pyjamas is heavily dependent on the "compiler" module (which is written in c) and is in turn, as you are no doubt aware, specifically dependent on the grammar file. the python translator for pyjamas 0.3 was 1,200 lines of code. thanks to some brilliant and dedicated work by kees bos, over something like a 6 month virtually full-time period, it's now somewhere around 5,000 lines of heavily-dense code in which very specific javascript optimisations have been encoded. then, on top of that, it is necessary to implement the data types that are supported in python 3.x, along with several built-ins (exceptions etc.). the basic implementation - pyjslib.py - is 6,700 lines of python code with in-built hand-optimised javascript, and it would be necessary to reimplement / re-work... and then support... that reimplementation. then, on top of that, there are a number of python-based reimplementations of various python modules, such as md5.py, re.py, string.py and so on, each of which would have to be double-checked for compatibility with their python 3.x counterparts. do they exist, have they been rewritten, modified etc.` then, on top of that, it is necessary to run the pyjamas UI code, which is some 15,000 lines of code, along with the other libraries such as GChart, through lib2to3, and then to double-check them. then, on top of that, it is necessary to run the examples - of which there are 70 - again through lib2to3. i've just done a "wc" on the examples source code: it comes to a whopping total of 60,000 lines of code. so you have to do all this work, and really it's impossible to begin realistically checking that it works until you get to the LibTest example (which is the main test suite, comprising some 3,000 or so regression tests), and once you've done all that work you now need a userbase and also some maintainers. and, when it comes to doing a release, you need to test all 70 examples in a matrix of 14 browsers plus 4 desktop runtime engines, and the browsers you need to recompile three times - with -O (optimised), --strict (python-compliant) and there's one more, i forget its name, it's designed to minimise the amount of javascript generated. to support 3.x therefore requires a complete and utter rewrite, and then a hell of a lot of work on top of that. it's basically supporting a totally separate language, and so is basically a completely new project. i know you mean well, but... you've drastically underestimated quite how much effort has gone into the pyjamas project - just look at the ohloh statistics for goodness sake! it's listed as having had 31 man-years gone into it! http://www.ohloh.net/p/pyjamas so if you can find the money to get people paid to create a python 3.x to javascript compiler, which will require approximately twelve to fifteen man-months of full-time dedicated programming effort, please do speak up! otherwise please - really: just saying "give me support for python 3.x or else" is ... honestly - it's a free software project, _not_ a paid-up corporate google/nokia/ibm/redhat/etc. funded project: you know the score, and you know the drill. now. leaving _that_ aside, there happens to be absolutely no really good compelling reason to support python 3.x in the first place. "python 3 is the future of python" gimme a break!! [so why is archlinux the only linux distribution that's converted over to run everything off of python 3.x?] the thing is: there aren't really any major dependencies to "get in the way" in pyjs. as in: it's entirely self-sufficient [it has to be]. even the installation has its own sandbox system. the only dependency *is* python 2.N, and when daniel kluev completes his GSoC2011 project, that'll be a "bootstrap" into javascript, including the translator itself being compiled into javascript, and then not even python 2.N will be a dependency! the bottom line is this: somewhere in the next 8 to 10 years, python 2.N will be deprecated in all but the most die-hard places. at *that* time, it will have been worthwhile to convert pyjamas over to python 3.N - and probably not even then would it be strictly necessary. the only really compelling reason would be if it became difficult for the pyjamas-desktop engines to be compiled for python 2. that's MSHTML (python-comtypes for python 2 disappearing or being hard to get) - i'm the maintainer of the pyjd/mshtml.py engine so that'll be around for a long time; pythonwebkit (again, i'm the maintainer, so that'll be around for a long time) and xulrunner / python-xpcom and python-hulahop (python-xpcom is maintained by activestate.com). so - if it becomes "difficult" to get hold of all the pyjd engines, *then* and *only* then does it make sense to look at converting to python 3. i seriously, seriously doubt that pythonwebkit, python- comtypes or python-xpcom for python 2 are going to disappear within the next 5 years, don't you? l. p.s. if you _really_ want to use python 3 with pyjs, then run the pyjs translator code through lib2to3, and then make damn sure that you use the "--internal-ast" option when compiling [this is what is recommended for people who use python 2.4, or 2.7 and above. one minor change and we might even be able to support python 2.3 or below]. you will then use the (duh) internal AST code in pyjs, and will *still* need to write pyjamas applications that are in python 2.N syntax, because that's what the pyjs translator supports. but you will at least not require an http://python.org version 2.N interpreter. p.p.s for anyone who might be interested, the --internal-ast code sort- of came from the lib2to3 project, and was used to create a module which is entirely compatible with the standard http://python.org version 2.0 "compile" module and the ast module. except that it supports the features of lib2to3 which include line and character numbers. From ericsnowcurrently at gmail.com Tue May 17 12:07:20 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 17 May 2011 10:07:20 -0600 Subject: Python 3 vs Python 2.7 dilemma In-Reply-To: References: Message-ID: On Mon, May 16, 2011 at 10:48 PM, Navkirat Singh wrote: > Hi Guys, > > I have been trying to fight this issue for sometime now. I know that a > large part of the python 3rd party software base has not been ported to > python 3 yet. I am trying to build a web-based enterprise solution for my > client. Most of reputed frameworks like Django and Turbo gears are yet in > the 2.x stage. I know that these frameworks are extremely good. But I wanted > to build my base with python 3 as that is what is going to prevail in the > future. > > I have built my own little architecture using python3. Here is what I have > accomplished till now: > > a) A multiprocessing webserver built directly using low level sockets for > maximum control, conforming to RFC 2616 (not completely right now). > b) A HTTP message parser for parsing HTTP/1.1 requests and generating > response messages > c) A session control base using python multiprocessing dictionary manager > d) A partially build MVC model, without a templating engine at the moment. > I am planning to put Jinja 3 there. > > I have spent months of free time doing this. I have learnt a lot, but well > I am not sure if the path I am on is the right one. > > My question to everyone is whether I should go ahead with this approach, or > should I just use 2.x technology? I am not sure if I will be able to port > all the code to python3 later. > > I will really appreciate any input. > > Thanks and regards, > Navkirat > > -- > http://mail.python.org/mailman/listinfo/python-list > > I would say go Python 3, unless you have a dependency that prevents it. There was a lot of talk at pycon this year about how the rate of Python 3 transition is drastically increasing. Many of the large projects (as well as pypy, ironpython, and jython) talked about their transition plans for Python 3 in the next year or two. The expectation is that this year will see a switch across many projects. It is a snowball effect, as more dependencies transition the remaining ones have less reason to stay on Python 2. The anticipation was to see everyone on Python 3 by 5 years after its release. It was released just over 2.5 years ago. Here are some references that you might find helpful: http://wiki.python.org/moin/Python2orPython3 http://py3ksupport.appspot.com/ http://dev.pocoo.org/~gbrandl/py3pkgs.png Cheers, -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyler at tysdomain.com Tue May 17 12:18:57 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Tue, 17 May 2011 10:18:57 -0600 Subject: FW: help please In-Reply-To: References: Message-ID: <4DD29FF1.9090506@tysdomain.com> Not to be pedantic or anything, and I may not be able to help regardless, but it looks like your space key is fixed, and I don't really care to pick through and try to play hangman with your message. On 5/17/2011 3:43 AM, hamed azarkeshb wrote: > > > From: hamed3099 at hotmail.com > To: webmaster at python.org > Subject: help please > Date: Tue, 17 May 2011 13:20:22 +0430 > > hi dear > inwant to useautomation with catiaby python,but i dont know,h*ow do we > can creat catsafearrayvariant in python?* > please help me.i need urhelp by one example. > thank u forany thing -- Take care, Ty my website: http://tds-solutions.net my blog: http://tds-solutions.net/blog skype: st8amnd127 ?Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.? ?If Java had true garbage collection, most programs would delete themselves upon execution.? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 17 12:23:48 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 10:23:48 -0600 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> Message-ID: On Tue, May 17, 2011 at 9:50 AM, RJB wrote: > I noticed some discussion of recursion..... the trick is to find a > formula where the arguments are divided, not decremented. > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > for a couple of years in C++ but just for fun rewrote it > in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! > > def fibo(n): > ? ? ? ?"""A Faster recursive Fibonaci function > Use a formula from Knuth Vol 1 page 80, section 1.2.8: > ? ? ? ? ? If F[n] is the n'th Fibonaci number then > ? ? ? ? ? ? ? ? ? F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. > ?First set m = n+1 > ? F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. > > ?Then put m = n in Knuth's formula, > ? ? ? ? ? F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], > ? and replace F[n+1] by F[n]+F[n-1], > ? ? ? ? ? F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). > """ > ? ? ? ?if n<=0: > ? ? ? ? ? ? ? ?return 0 > ? ? ? ?elif n<=2: > ? ? ? ? ? ? ? ?return 1 > ? ? ? ?elif n%2==0: > ? ? ? ? ? ? ? ?half=n//2 > ? ? ? ? ? ? ? ?f1=fibo(half) > ? ? ? ? ? ? ? ?f2=fibo(half-1) > ? ? ? ? ? ? ? ?return f1*(f1+2*f2) > ? ? ? ?else: > ? ? ? ? ? ? ? ?nearhalf=(n-1)//2 > ? ? ? ? ? ? ? ?f1=fibo(nearhalf+1) > ? ? ? ? ? ? ? ?f2=fibo(nearhalf) > ? ? ? ? ? ? ? ?return f1*f1 + f2*f2 Thanks for posting! Actually, it looks like this is the same O(n) algorithm that rusi posted. There was also a O(log n) algorithm discussed that is based on vector math. You might want to take a look. Cheers, Ian From rustompmody at gmail.com Tue May 17 12:25:40 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 17 May 2011 09:25:40 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> Message-ID: On May 17, 8:50?pm, RJB wrote: > I noticed some discussion of recursion..... the trick is to find a > formula where the arguments are divided, not decremented. > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > for a couple of years in C++ but just for fun rewrote it > in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! > > def fibo(n): > ? ? ? ? """A Faster recursive Fibonaci function > Use a formula from Knuth Vol 1 page 80, section 1.2.8: > ? ? ? ? ? ?If F[n] is the n'th Fibonaci number then > ? ? ? ? ? ? ? ? ? ?F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. > ? First set m = n+1 > ? ?F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. > > ? Then put m = n in Knuth's formula, > ? ? ? ? ? ?F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], > ? ?and replace F[n+1] by F[n]+F[n-1], > ? ? ? ? ? ?F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). > """ > ? ? ? ? if n<=0: > ? ? ? ? ? ? ? ? return 0 > ? ? ? ? elif n<=2: > ? ? ? ? ? ? ? ? return 1 > ? ? ? ? elif n%2==0: > ? ? ? ? ? ? ? ? half=n//2 > ? ? ? ? ? ? ? ? f1=fibo(half) > ? ? ? ? ? ? ? ? f2=fibo(half-1) > ? ? ? ? ? ? ? ? return f1*(f1+2*f2) > ? ? ? ? else: > ? ? ? ? ? ? ? ? nearhalf=(n-1)//2 > ? ? ? ? ? ? ? ? f1=fibo(nearhalf+1) > ? ? ? ? ? ? ? ? f2=fibo(nearhalf) > ? ? ? ? ? ? ? ? return f1*f1 + f2*f2 > > RJB the Lurkerhttp://www.csci.csusb.edu/dick/cs320/lab/10.html From vanboxem.ruben at gmail.com Tue May 17 12:32:37 2011 From: vanboxem.ruben at gmail.com (Ruben Van Boxem) Date: Tue, 17 May 2011 18:32:37 +0200 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: 2011/5/15 Ruben Van Boxem : > 2011/5/15 Ruben Van Boxem : >> 2011/5/15 Ruben Van Boxem : >>> 2011/5/14 Doug Evans : >>>> On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem >>>> wrote: >>>>> 2011/5/14 Doug Evans : >>>>>> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem >>>>>> wrote: >>>>>>> (now in plain-text as required by gdb mailing list) >>>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> I am currently trying to integrate Python support into my toolchain >>>>>>> build (including GDB of course). It is a sysrooted >>>>>>> binutils+GCC+GDB+mingw-w64 toolchain. >>>>>>> >>>>>>> I currently have the basic setup working: I can link gdb with my >>>>>>> manually generated import lib to the python dll from the official >>>>>>> Windows install. If there is anything I am missing or a very easy >>>>>>> solution to the problems decsribed below, please just say so. I am >>>>>>> only suggesting what I would like to happen. >>>>>>> >>>>>>> Now on to the problems I'd like to discuss: >>>>>>> >>>>>>> 1. gdb.exe won't start without me having set PYTHONPATH manually. >>>>>> >>>>>> In a properly configured/built gdb on linux this isn't necessary, even >>>>>> if python is installed in some random place. >>>>>> I'm not sure about windows though. >>>>>> Did you specify --with-python when you configured gdb, and if so did >>>>>> you specify a value? >>>>>> e.g., --with-python=SOME_VALUE >>>>> >>>>> I was cross-compiling a mingw toolchain+gdb from Linux, so I used >>>>> --with-python without a value (because gdb configure tries to find the >>>>> Python executabe), and I added -I"/path/to/python/includes" to CFLAGS >>>>> and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it >>>>> should. This is hacky though, and gdb configure should provide >>>>> --with-python-libs and --with-python-include to make it more >>>>> streamlined with any other build prerequisite (like >>>>> gmp/mpfr/mpc/cloog/ppl in GCC for example). >>>> >>>> Ah. >>>> Cross-compiling gdb with python is in need of improvement. >>>> Alas python hasn't been designed with cross-compilation in mind (e.g. >>>> build on linux, run on windows). >>>> AIUI, the way to get the parameters required for compiling with >>>> libpython is to get them from python's "distutils": kinda hard to do >>>> in a cross-compile. ?Done correctly there's no need to run python. >>>> >>>> I haven't done anything more to support python in gdb's configure.ac >>>> because it's not clear to me what the right thing to do is: distutils >>>> provides more than just --libs and --includes (btw, we don't use >>>> --libs though, we use --ldflags which includes all of: the directory >>>> in which to find libpython, the -l for libpython, and the -l's for all >>>> the other libraries python needs). [Which isn't to say that someone >>>> else isn't free to tackle this.] >>>> >>>> In the meantime, what I've been doing is a hack: write a script that >>>> responds to: >>>> --includes >>>> --ldflags >>>> --exec-prefix >>>> and pass that as --with-python. >>>> >>>> E.g. >>>> bash$ cat $HOME/my-python-for-config >>>> #! /bin/sh >>>> >>>> if [ $# -ne 2 ] >>>> then >>>> ? ? ? ?echo "Bad # args. ?Blech!" >&2 >>>> ? ? ? ?exit 1 >>>> fi >>>> >>>> # The first argument is the path to python-config.py, ignore it. >>>> >>>> case "$2" in >>>> --includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;; >>>> --ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm >>>> -lpython2.6" ;; >>>> --exec-prefix) echo "/usr" ;; >>>> *) echo "Bad arg $2. ?Blech!" >&2 ; exit 1 ;; >>>> esac >>>> >>>> exit 0 >>>> bash$ ./configure --with-python=$HOME/my-python-for-config [...] >>>> [...] >>>> >>>> >>>> Note that --exec-prefix is the runtime location of python. >>>> GCC uses this to tell libpython where to find its support files. >>>> [grep for Py_SetProgramName in gdb/python/python.c] >>> >>> OK, I tried your script in a couple of variations. It gets rid of the >>> traceback I had before, but still doesn't help the PYTHONPATH problem. >>> My directory structure is as follows (this is not in root, "/" is just >>> my main build directory, there are several levels below it): >>> >>> /gdb <-- gdb build dir >>> /gdb/gdb <-- where the python configuration is done >>> /python <-- temporary install dir for python files for build, >>> extracted from the official Windows installer, also location of >>> libpython2.7.a import library >>> /python/include/python27 <-- python headers, found by gdb in both cases >>> /mingw64 <-- toolchain sysroot prefix >>> /mingw64/bin <-- install location of gdb and python27.dll >>> /mingw64/lib/python27 <-- install location of all python scripts >>> >>> First variant: >>> --includes) echo "-I../../python/include" ;; >>> --ldflags) echo "-L../../python -lpython2.7" ;; >>> --exec-prefix) echo "../../mingw64/lib/python27" ;; >>> >>> Here exec-prefix would be the relative path from where "configure" >>> does its magic to the final location of the scripts on the build >>> system. >>> >>> Second variant: >>> --includes) echo "-I../../python/include" ;; >>> --ldflags) echo "-L../../python -lpython2.7" ;; >>> --exec-prefix) echo "../lib/python27" ;; >>> >>> I thought the second points gdb to the installed location of the >>> python scripts, but it still needed PYTHONPATH for that. I used >>> relative paths in an attempt to "do the right thing", hackwise... >>> Remember that the whole "/mingw64" directory gets zipped and moved, >>> then it gets extracted to a random location in the Windows filesystem. >>> >>> Thanks for the help so far, I think we might just get this worked out together. >>> >>> Ruben >> >> Wow, I think I have a partial solution. Delving into the Python docs, >> for example here: >> http://docs.python.org/using/windows.html#finding-modules, you can see >> that PYTHONPATH is used first, then the Windows registry, then >> PYTHONHOME, then some default relative paths. I placed the python >> scripts all in the directory structure like so: >> >> /bin/gdb >> /bin/Lib/ >> /bin/python27.dll >> >> This works, even without any manual PYTHONPATH intervention. Problem >> is though, that as soon as someone has a PYTHONPATH environment >> variable from a (incompatible) Python installation (think different >> bitness or version 3.x instead of 2.7.1), I cannot predict what will >> go wrong. This problem originates in Python's way of filling in the >> search path (sys.path). A true solution in the GDB case to prevent >> this collision of an incompatible PYTHONPATH would be that GDB sets an >> internal PYTHONPATH as directed by configure, uses that to load its >> Python internals, and allows the GDB child processes (apps being >> debugged) to use the environment PYTHONPATH. For now, I have a >> functional installation, but it will break as soon as someone installs >> Python on their system. >> >> The part your script plays in this (if I haven't misunderstood the >> intention/effects of the "--exec-prefix" part) is allowing a uniform >> way of directing the configure script to the right directories for >> includes/libs. >> >> Ruben > > I am sorry for the repeated messages that no one cares about, but I > may have discovered GDB in its current form already allows what I > want: I tried to figure out what exact paths the snake in gdb was > using to search for its modules, and came up with this: > (gdb) python import sys > (gdb) python print sys.path > ['m:\\development\\mingw64\\share\\gdb/python', > 'M:\\Development\\mingw64\\bin\\python27.zip', > 'M:\\Development\\mingw64\\bin\\DLLs', > 'M:\\Development\\mingw64\\bin\\lib', > 'M:\\Development\\mingw64\\bin\\lib\\plat-win', > 'M:\\Development\\mingw64\\bin\\lib\\lib-tk', > 'M:\\Development\\mingw64\\bin', > 'M:\\Development\\mingw64\\bin\\lib\\site-packages'] > > This means that every python command within gdb searches > /share/gdb/python FIRST (even before an environment's > PYTHONPATH), alleviating any concerns or problems I or anyone would > have with another python installation, as this apparently built-in > path comes up first. All I, or anyone interested in doing this kind of > thing, have to do is copy all the python scripts from the Windows > installation's Lib directory to the /share/gdb/python > directory. > > I don't know where this path comes from, but it is quite handy, and > makes this whole discussion ?moot for Python people. Only "issue" that > I'll have to work around is the --with-python-includes and > --with-python-libs that are missing, using either manual > CFLAGS/LDFLAGS or a variant of your script. > > Thanks for all the help and motivation to keep trying :) > > Ruben Scratch that, I had lingering install of Python laying around. Without PYTHONPATH, no gdb (module site not found). Why not make gdb search the ../share/gdb/python path first, and then complain? Ruben > >> >>> >>>> >>>>>>> I understand the need for this, but as gdb requires Python 2, and users >>>>>>> of my toolchain may have installed Python 3 or a 32-bit version python >>>>>>> they want to use from the same environment (without changing their own >>>>>>> PYTHONPATH), there is no way to run python-enabled gdb. >>>>>>> [...] >>>>>> >>>>>> Yeah. >>>>>> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have >>>>>> gdb use that instead of PYTHONPATH if it exists, but there's been >>>>>> resistance to it. >>>>>> I think(!) what would happen is that gdb would set $PYTHONPATH to the >>>>>> value of $GDB_PYTHONPATH. >>>>>> [Inferiors started by gdb should still get the original value of >>>>>> PYTHONPATH though.] >>>>> >>>>> That way would be almost ideal, but a hardcoded *relative* path to the >>>>> python scripts (that is standardized within gdb) wouldn't hurt. >>>> >>>> See above re: --exec-prefix. >>>> >>>>> An >>>>> extra environment variable would require a lot of explaining for >>>>> Windows, and is not "plug-and-play", like the rest of a sysrooted >>>>> toolchain is supposed to be like. I think this should work on all >>>>> setups: >>>>> >>>>> 1. Check hardcoded path; my suggestion would be ">>>> executable>/../lib/python27" >>>>> 2. If this fails to find the necessary files/scripts, find it like you >>>>> described above in Linux, without PYTHONPATH set. >>>>> 3. Check PYTHONPATH. >>>> >>>> The problem being solved by the proposed GDB_PYTHONPATH is "What if >>>> the user has PYTHONPATH set and it points to an incompatible version >>>> of python?". >>>> Leaving such a value for PYTHONPATH set while gdb's python is running >>>> feels wrong (and IIRC has caused some problems). >>>> >>>> The problem of telling python where to find itself is already solved >>>> (or at least is intended to be solved) with gdb's calling >>>> Py_SetProgramName with a value derived from the python-provided >>>> --exec-prefix. >>>> >>>>> I would think only number one would change, and perhaps be only >>>>> enabled with a special configure option. Nothing else would have to >>>>> change, and Windows users would rejoice :) >>>>> Again, this is only my suggestion, if there are problems with it in >>>>> way I haven't thought of, please say so, and we can come up with >>>>> another solution. >>>> >>> >> > From rustompmody at gmail.com Tue May 17 12:36:49 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 17 May 2011 09:36:49 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> Message-ID: <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> On May 17, 8:50?pm, RJB wrote: > I noticed some discussion of recursion..... the trick is to find a > formula where the arguments are divided, not decremented. > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > for a couple of years in C++ but just for fun rewrote it > in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! > > def fibo(n): > ? ? ? ? """A Faster recursive Fibonaci function > Use a formula from Knuth Vol 1 page 80, section 1.2.8: > ? ? ? ? ? ?If F[n] is the n'th Fibonaci number then > ? ? ? ? ? ? ? ? ? ?F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. > ? First set m = n+1 > ? ?F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. > > ? Then put m = n in Knuth's formula, > ? ? ? ? ? ?F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], > ? ?and replace F[n+1] by F[n]+F[n-1], > ? ? ? ? ? ?F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). > """ > ? ? ? ? if n<=0: > ? ? ? ? ? ? ? ? return 0 > ? ? ? ? elif n<=2: > ? ? ? ? ? ? ? ? return 1 > ? ? ? ? elif n%2==0: > ? ? ? ? ? ? ? ? half=n//2 > ? ? ? ? ? ? ? ? f1=fibo(half) > ? ? ? ? ? ? ? ? f2=fibo(half-1) > ? ? ? ? ? ? ? ? return f1*(f1+2*f2) > ? ? ? ? else: > ? ? ? ? ? ? ? ? nearhalf=(n-1)//2 > ? ? ? ? ? ? ? ? f1=fibo(nearhalf+1) > ? ? ? ? ? ? ? ? f2=fibo(nearhalf) > ? ? ? ? ? ? ? ? return f1*f1 + f2*f2 > > RJB the Lurkerhttp://www.csci.csusb.edu/dick/cs320/lab/10.html ------------------------------------------------------------- Its an interesting problem and you are 75% there. You see the halving gives you logarithmic behavior and the double calls give exponential behavior. So how to get rid of double calls? Its quite simple: Just define your function in terms of return pairs of adjacent pairs ie (fib(n), fib(n +1)) for some n rather then a single number fib(n) Here's a straightforward linear function: def fp(n): #fibpair if n==1: return (1,1) else: a,b = fp(n-1) return (b, a+b) def fib(n): a,b = fp(n) return a --------------- Now use this (pairing) idea with your (halving) identities and you should get a logarithmic algo. [If you cant do it ask again but yes its fun to work out so do try :-) ] From harrismh777 at charter.net Tue May 17 12:38:36 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 17 May 2011 11:38:36 -0500 Subject: [ann] pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: Terry Reedy wrote: > Like it or not, Python 3 is the future of Python. It is the Python that > many Python newcomers learn first, and perhaps ever will. Yes, no doubt, and I'm genuine about that... ... but there is something else to consider, as I'm sure you are aware. At some point Python is going to have to standardize in order to survive. And by survive I'm not talking about the Python 'community,' as much as I'm talking about the acceptance and wide-spread use of Python by people who just want to get work done and solve problems. If there is another major jump like 2.x --> 3.x in the future, Python will die. I hope you guys are aware of this. The user base might accept this thing once, but they're not going do it again... Like it or not, Python 2.x has millions of lines of code running out there, and they're not going to get morphed into 3.x coding. So, 2x is going to be around for many years to come. On the other hand, I'm teaching 3x, coding 3x, and porting to 3x... and also encouraging others to do the same... but there is a limit to that also. My system has 2.4, 2.5, 2.6, 2.7 and 3.2... and that's the trouble with an interpreter. Different versions of the source code (.py files) require a matching 'interpreter,' where-as in other languages a new compiler version does not require recompiling source, but if source is recompiled everything still works... not so in Python. The fact that Python is free to morph gleely from PEP to PEP without responsibility or accountability with the user base is what may kill Python, unless the Python community gets a grip on this concept. kind regards, m harris From jackcwoodhead at googlemail.com Tue May 17 13:01:23 2011 From: jackcwoodhead at googlemail.com (Jackson) Date: Tue, 17 May 2011 10:01:23 -0700 (PDT) Subject: groupby - summing multiple columns in a list of lists Message-ID: <2f60e6c7-1ce2-4094-a777-e544293e8843@hg8g2000vbb.googlegroups.com> I'm currently using a function pasted in below. This allows me to sum a column (index) in a list of lists. So if mylist = [[1, 2, 3], [1, 3, 4], [2, 3, 4], [2, 4, 5]] group_results(mylist,[0],1) Returns: [(1, 5), (2, 7)] What I would like to do is allow a tuple/list of index values, rather than a single index value to be summed up, so you could say group_results(mylist,[0],[1,2]) would return [(1, 5,7), (2, 7,9)] but I'm struggling to do so, any thoughts? Cheers from itertools import groupby as gb from operator import itemgetter as ig def group_results(table,keys,value): res = [] nkey = ig(*keys) value = ig(value) for k, group in gb(sorted(table,key=ig(*keys)),nkey): res.append((k,sum(value(row) for row in group))) return res From debatem1 at gmail.com Tue May 17 13:02:21 2011 From: debatem1 at gmail.com (geremy condra) Date: Tue, 17 May 2011 10:02:21 -0700 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> Message-ID: On Tue, May 17, 2011 at 9:36 AM, rusi wrote: > On May 17, 8:50?pm, RJB wrote: >> I noticed some discussion of recursion..... the trick is to find a >> formula where the arguments are divided, not decremented. >> I've had a "divide-and-conquer" recursion for the Fibonacci numbers >> for a couple of years in C++ but just for fun rewrote it >> in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! >> >> def fibo(n): >> ? ? ? ? """A Faster recursive Fibonaci function >> Use a formula from Knuth Vol 1 page 80, section 1.2.8: >> ? ? ? ? ? ?If F[n] is the n'th Fibonaci number then >> ? ? ? ? ? ? ? ? ? ?F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. >> ? First set m = n+1 >> ? ?F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. >> >> ? Then put m = n in Knuth's formula, >> ? ? ? ? ? ?F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], >> ? ?and replace F[n+1] by F[n]+F[n-1], >> ? ? ? ? ? ?F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). >> """ >> ? ? ? ? if n<=0: >> ? ? ? ? ? ? ? ? return 0 >> ? ? ? ? elif n<=2: >> ? ? ? ? ? ? ? ? return 1 >> ? ? ? ? elif n%2==0: >> ? ? ? ? ? ? ? ? half=n//2 >> ? ? ? ? ? ? ? ? f1=fibo(half) >> ? ? ? ? ? ? ? ? f2=fibo(half-1) >> ? ? ? ? ? ? ? ? return f1*(f1+2*f2) >> ? ? ? ? else: >> ? ? ? ? ? ? ? ? nearhalf=(n-1)//2 >> ? ? ? ? ? ? ? ? f1=fibo(nearhalf+1) >> ? ? ? ? ? ? ? ? f2=fibo(nearhalf) >> ? ? ? ? ? ? ? ? return f1*f1 + f2*f2 >> >> RJB the Lurkerhttp://www.csci.csusb.edu/dick/cs320/lab/10.html > > ------------------------------------------------------------- > Its an interesting problem and you are 75% there. > You see the halving gives you logarithmic behavior and the double > calls give exponential behavior. > > So how to get rid of double calls? ?Its quite simple: Just define your > function in terms of return pairs of adjacent pairs ie (fib(n), fib(n > +1)) for some n rather then a single number fib(n) > > Here's a straightforward linear function: > > def fp(n): ?#fibpair > ? ?if n==1: > ? ? ? ?return (1,1) > ? ?else: > ? ? ? ?a,b = fp(n-1) > ? ? ? ?return (b, a+b) > > def fib(n): > ? ?a,b = fp(n) > ? ?return a > > --------------- > Now use this (pairing) idea with your (halving) identities and you > should get a logarithmic algo. > > [If you cant do it ask again but yes its fun to work out so do > try :-) ] > -- > http://mail.python.org/mailman/listinfo/python-list > or O(1): ? = (1 + sqrt(5)) / 2 def fib(n): numerator = (?**n) - (1 - ?)**n denominator = sqrt(5) return round(numerator/denominator) Testing indicates that it's faster somewhere around 7 or so. Geremy Condra From chris at simplistix.co.uk Tue May 17 13:04:25 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 17 May 2011 18:04:25 +0100 Subject: in search of graceful co-routines Message-ID: <4DD2AA99.3010508@simplistix.co.uk> Hi All, I'm looking for a graceful pattern for the situation where I have a provider of a sequence, the consumer of a sequence and code to moderate the two, and where I'd like to consumer to be able to signal to the provider that it hasn't succeeded in processing one element in the queue. So, I'd want the controlling code to look a lot like: for item in provider: try: consumer.handleItem(self) except: provider.failed(item) Now, since the sequence is long, and comes from a file, I wanted the provider to be an iterator, so it occurred to me I could try and use the new 2-way generator communication to solve the "communicate back with the provider", with something like: for item in provider: try: consumer.handleItem(self) except: provider.send('fail') else: provider.send('succeed') ..but of course, this won't work, as 'send' causes the provider iteration to continue and then returns a value itself. That feels weird and wrong to me, but I guess my use case might not be what was intended for the send method. Anyway, I wonder how other people would write this? (I'm particularly interested in a sane way to use the two way communication that PEP 342 introduced) cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From jpiitula at ling.helsinki.fi Tue May 17 13:19:05 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 17 May 2011 20:19:05 +0300 Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> Message-ID: geremy condra writes: > or O(1): > > ? = (1 + sqrt(5)) / 2 > def fib(n): > numerator = (?**n) - (1 - ?)**n > denominator = sqrt(5) > return round(numerator/denominator) > > Testing indicates that it's faster somewhere around 7 or so. And increasingly inaccurate from 71 on. From ian.g.kelly at gmail.com Tue May 17 13:26:54 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 11:26:54 -0600 Subject: in search of graceful co-routines In-Reply-To: <4DD2AA99.3010508@simplistix.co.uk> References: <4DD2AA99.3010508@simplistix.co.uk> Message-ID: On Tue, May 17, 2011 at 11:04 AM, Chris Withers wrote: > Now, since the sequence is long, and comes from a file, I wanted the > provider to be an iterator, so it occurred to me I could try and use the new > 2-way generator communication to solve the "communicate back with the > provider", with something like: > > for item in provider: > ?try: > ? ?consumer.handleItem(self) > ?except: > ? ? provider.send('fail') > ?else: > ? ? provider.send('succeed') > > ..but of course, this won't work, as 'send' causes the provider iteration to > continue and then returns a value itself. That feels weird and wrong to me, > but I guess my use case might not be what was intended for the send method. > > Anyway, I wonder how other people would write this? > (I'm particularly interested in a sane way to use the two way communication > that PEP 342 introduced) You can use send the way you're wanting to. It will look something like this: def provider(): result = None while True: if result is None: if has_more_items(): next_item = get_next_item() else: break elif result == 'fail': process_fail() next_item = None elif result == 'succeed': process_succeed() next_item = None else: raise ValueError('unknown result %s' % result) result = (yield next_item) Whenever you call provider().next() or provider().send(None), you simply get the next item. If you call provider().send('succeed') or provider().send('fail'), then the corresponding code is run and the yielded value is None, without consuming anything from the sequence. Cheers, Ian From pavlovevidence at gmail.com Tue May 17 13:30:25 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 17 May 2011 10:30:25 -0700 (PDT) Subject: in search of graceful co-routines In-Reply-To: Message-ID: On Tuesday, May 17, 2011 10:04:25 AM UTC-7, Chris Withers wrote: > Now, since the sequence is long, and comes from a file, I wanted the > provider to be an iterator, so it occurred to me I could try and use the > new 2-way generator communication to solve the "communicate back with > the provider", with something like: > > for item in provider: > try: > consumer.handleItem(self) > except: > provider.send('fail') > else: > provider.send('succeed') > > ..but of course, this won't work, as 'send' causes the provider > iteration to continue and then returns a value itself. That feels weird > and wrong to me, but I guess my use case might not be what was intended > for the send method. You just have to call send() in a loop yourself. Note that you should usually catch StopIteration whenever calling send() or next() by hand. Untested: result = None while True: try: item = provider.send(result) except StopIteration: break try: consumer.handleItem(item) except: result = 'failure' else: result = 'success' Carl Banks From pavlovevidence at gmail.com Tue May 17 13:30:25 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 17 May 2011 10:30:25 -0700 (PDT) Subject: in search of graceful co-routines In-Reply-To: Message-ID: On Tuesday, May 17, 2011 10:04:25 AM UTC-7, Chris Withers wrote: > Now, since the sequence is long, and comes from a file, I wanted the > provider to be an iterator, so it occurred to me I could try and use the > new 2-way generator communication to solve the "communicate back with > the provider", with something like: > > for item in provider: > try: > consumer.handleItem(self) > except: > provider.send('fail') > else: > provider.send('succeed') > > ..but of course, this won't work, as 'send' causes the provider > iteration to continue and then returns a value itself. That feels weird > and wrong to me, but I guess my use case might not be what was intended > for the send method. You just have to call send() in a loop yourself. Note that you should usually catch StopIteration whenever calling send() or next() by hand. Untested: result = None while True: try: item = provider.send(result) except StopIteration: break try: consumer.handleItem(item) except: result = 'failure' else: result = 'success' Carl Banks From joe.leonardo at datalogix.com Tue May 17 14:02:03 2011 From: joe.leonardo at datalogix.com (Joe Leonardo) Date: Tue, 17 May 2011 11:02:03 -0700 Subject: if statement on lenght of a list Message-ID: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Hey all, Totally baffled by this...maybe I need a nap. Writing a small function to reject input that is not a list of 19 fields. def breakLine(value): if value.__class__() != [] and value.__len__() != 19: print 'You must pass a list that contains 19 fields.' else: print 'YAY!' If I pass: breakLine([]) I get: YAY! I expect: You must pass a list that contains 19 fields. If I print len(value) I get: 0 What is going on here? Thanks! [cid:image001.png at 01CC148A.3C0C1950] Joe Leonardo | Business Intelligence Analyst | DataLogix 303.327.1730 d | 415.812.5244 c | joe.leonardo at datalogix.com Better Marketing through Data(tm) -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.png Type: image/png Size: 3465 bytes Desc: image001.png URL: From pazurrobert at gmail.com Tue May 17 14:22:33 2011 From: pazurrobert at gmail.com (Robert Pazur) Date: Tue, 17 May 2011 20:22:33 +0200 Subject: best way to extract sentence from txt file In-Reply-To: References: Message-ID: Hi all, my question is maybe quite simple: What is the best (and shortest) way to extract sentence from .txt file? Thanks in advance, Robert Pazur -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue May 17 14:24:14 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 May 2011 20:24:14 +0200 Subject: groupby - summing multiple columns in a list of lists References: <2f60e6c7-1ce2-4094-a777-e544293e8843@hg8g2000vbb.googlegroups.com> Message-ID: Jackson wrote: > I'm currently using a function pasted in below. This allows me to sum > a column (index) in a list of lists. > > So if mylist = [[1, 2, 3], [1, 3, 4], [2, 3, 4], [2, 4, 5]] > group_results(mylist,[0],1) > > Returns: > [(1, 5), (2, 7)] > > What I would like to do is allow a tuple/list of index values, rather > than a single index value to be summed up, so you could say > group_results(mylist,[0],[1,2]) would return [(1, 5,7), (2, 7,9)] but > I'm struggling to do so, any thoughts? Cheers > > from itertools import groupby as gb > from operator import itemgetter as ig > > def group_results(table,keys,value): > res = [] > nkey = ig(*keys) > value = ig(value) > for k, group in gb(sorted(table,key=ig(*keys)),nkey): > res.append((k,sum(value(row) for row in group))) > return res You could write a version of sum() that can cope with tuples: from itertools import groupby, imap def itemgetter(keys, rowtype=tuple): def getitem(value): return rowtype(value[key] for key in keys) return getitem def sum_all(rows): rows = iter(rows) sigma = next(rows) rowtype = type(sigma) sigma = list(sigma) for row in rows: for i, x in enumerate(row): sigma[i] += x return rowtype(sigma) def group_results(table, key, value): get_key = itemgetter(key) get_value = itemgetter(value) table = sorted(table, key=get_key) for keyvalue, group in groupby(table, get_key): yield keyvalue + sum_all(imap(get_value, group)) but I'd probably use a dict-based approach: def group_results(table, key, value): get_key = itemgetter(key) get_value = itemgetter(value) grouped = {} for row in table: key = get_key(row) value = get_value(row) if key in grouped: grouped[key] = tuple(a + b for a, b in zip(grouped[key], value)) else: grouped[key] = value return [k + v for k, v in sorted(grouped.iteritems())] if __name__ == "__main__": items = [(1, 2, 3), (1, 3, 4), (2, 3, 4), (2, 4, 5)] print list(group_results(items, [0], [1, 2])) Note that the function built with my version of itemgetter() will always return a tuple. From ndbecker2 at gmail.com Tue May 17 14:26:53 2011 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 17 May 2011 14:26:53 -0400 Subject: cPickle -> invalid signature References: Message-ID: Gabriel Genellina wrote: > En Tue, 17 May 2011 08:41:41 -0300, Neal Becker > escribi?: > >> What does it mean when cPickle.load says: >> RuntimeError: invalid signature >> >> Is binary format not portable? > > Are you sure that's the actual error message? > I cannot find such message anywhere in the sources. > The pickle format is quite portable, even cross-version. As a generic > answer, make sure you open the file in binary mode, both when writing and > reading. > Yes, that's the message. Part of what is pickled is a numpy array. I am writing on a 32-bit linux system and reading on a 64-bit system. Reading on the 64-bit system is no problem. Maybe the message comes from numpy's unpickling? From malaclypse2 at gmail.com Tue May 17 14:28:02 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 17 May 2011 14:28:02 -0400 Subject: if statement on lenght of a list In-Reply-To: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> References: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Message-ID: On Tue, May 17, 2011 at 2:02 PM, Joe Leonardo wrote: > Hey all, > > > > Totally baffled by this?maybe I need a nap. Writing a small function to > reject input that is not a list of 19 fields. > > > > def breakLine(value): > > if value.__class__() != [] and value.__len__() != 19: > > This should use an "or" test, not "and". And is probably better written as: if not isinstance(value, list) or len(value) != 19: That would allow for subclasses of list, assuming that would be okay. -- Jerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue May 17 14:31:19 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 May 2011 11:31:19 -0700 Subject: if statement on lenght of a list In-Reply-To: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> References: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Message-ID: On Tue, May 17, 2011 at 11:02 AM, Joe Leonardo wrote: > > Hey all, > > Totally baffled by this?maybe I need a nap. Writing a small function to reject input that is not a list of 19 fields. > > def breakLine(value): > ??? if value.__class__() != [] and value.__len__() != 19: > ??????? print 'You must pass a list that contains 19 fields.' > ??? else: > ??????? print 'YAY!' > > If I pass: > breakLine([]) > > I get: > YAY! > > I expect: > You must pass a list that contains 19 fields. Your test should use `or` as opposed to `and`. Since you're indeed passing in a list, the first part of your condition is False; since you used `and`, this makes the entire condition False. Therefore, the else clause ("YAY!") gets executed. Also, your test is written quite strangely. One would more normally and straightforwardly write it as: if not isinstance(value, list) or len(value) != 19: Cheers, Chris -- http://rebertia.com From python at mrabarnett.plus.com Tue May 17 14:32:14 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 May 2011 19:32:14 +0100 Subject: if statement on lenght of a list In-Reply-To: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> References: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Message-ID: <4DD2BF2E.4050001@mrabarnett.plus.com> On 17/05/2011 19:02, Joe Leonardo wrote: > Hey all, > > Totally baffled by this?maybe I need a nap. Writing a small function to > reject input that is not a list of 19 fields. > > def breakLine(value): > if value.__class__() != [] and value.__len__() != 19: > print 'You must pass a list that contains 19 fields.' > else: > print 'YAY!' > > If I pass: > > breakLine([]) > > I get: > > YAY! > > I expect: > > You must pass a list that contains 19 fields. > > If I print len(value) I get: 0 > > What is going on here? > If value is [], then value.__class__() is [], so value.__class__() != [] is False. What you meant was: if value.__class__() != [] or value.__len__() != 19: print 'You must pass a list that contains 19 fields.' else: print 'YAY!' although the Pythonic way to write it would be: if not isinstance(value, list) or len(value) != 19: print 'You must pass a list that contains 19 fields.' else: print 'YAY!' or, even better: if isinstance(value, list) and len(value) == 19: print 'YAY!' else: print 'You must pass a list that contains 19 fields.' From ian.g.kelly at gmail.com Tue May 17 14:33:51 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 12:33:51 -0600 Subject: if statement on lenght of a list In-Reply-To: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> References: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Message-ID: On Tue, May 17, 2011 at 12:02 PM, Joe Leonardo wrote: > Hey all, > > > > Totally baffled by this?maybe I need a nap. Writing a small function to > reject input that is not a list of 19 fields. > > > > def breakLine(value): > > if value.__class__() != [] and value.__len__() != 19: > > print 'You must pass a list that contains 19 fields.' > > else: > > print 'YAY!' > > > > If I pass: > > breakLine([]) > > > > I get: > > YAY! > > > > I expect: > > You must pass a list that contains 19 fields. > > > > If I print len(value) I get: 0 > > > > What is going on here? > > Evaluating the conditions, the first line reduces to "if False and True" which further reduces to "if False". You probably meant to write "or" instead of "and". A few other comments: "value.__len__()" is better written as "len(value)". "value.__class__() != []" would be better written as "type(value) is list". Better yet would be to not worry so much about the particular type of sequence passed in by the caller. To allow any sequence you could just do this: def break_line(value): if len(value) != 19: raise ValueError('value must contain 19 items') If value is not a sequence, then it will just raise a TypeError, which is typically what you would want in that situation anyway. Or if value absolutely must be a list due to the way your function works, you can do this: def break_line(value): value = list(value) if len(value) != 19: raise ValueError('value must contain 19 items') Again that will just raise a TypeError if the value can't be converted to a list. One of the niceties about this version is that value can be any iterable, not just a sequence. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From motoom at xs4all.nl Tue May 17 14:40:40 2011 From: motoom at xs4all.nl (Michiel Overtoom) Date: Tue, 17 May 2011 20:40:40 +0200 Subject: best way to extract sentence from txt file In-Reply-To: References: Message-ID: On May 17, 2011, at 20:22, Robert Pazur wrote: > my question is maybe quite simple: > What is the best (and shortest) way to extract sentence from .txt file? Well, open("filename.txt").readlines() gives you a list of all the lines in a txt file, which might not be sentences, depending on the text file is structured. If you really want to interpret the text file as a collection of sentences, some parsing might be involved. What is a sentence? A sequence of words ending with a dot? With a question mark? How do quotes play a role in this? Did you have a specific sentence (or line) in thought? The first line? The last line? A random line somewhere in between? Until then we have to guess, and my E.S.P. is notoriously bad. Greetings, -- "Learn to value yourself, which means: fight for your happiness." - Ayn Rand From ethan at stoneleaf.us Tue May 17 14:47:01 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 May 2011 11:47:01 -0700 Subject: Python 3.x and bytes Message-ID: <4DD2C2A5.3080403@stoneleaf.us> In Python 3 one can say --> huh = bytes(5) Since the bytes type is actually a list of integers, I would have expected this to have huh being a bytestring with one element -- the integer 5. Actually, what you get is: --> huh b'\x00\x00\x00\x00\x00' or five null bytes. Note that this is an immutable type, so you cannot go in later and say --> huh[3] = 9 Traceback (most recent call last): File "", line 1, in TypeError: 'bytes' object does not support item assignment So, out of curiosity, does anyone actually use this, um, feature? ~Ethan~ From georg at python.org Tue May 17 14:50:37 2011 From: georg at python.org (Georg Brandl) Date: Tue, 17 May 2011 20:50:37 +0200 Subject: [RELEASED] Python 3.2.1 rc 1 Message-ID: <4DD2C37D.7000008@python.org> On behalf of the Python development team, I am pleased to announce the first release candidate of Python 3.2.1. Python 3.2.1 will the first bugfix release for Python 3.2, fixing over 120 bugs and regressions in Python 3.2. For an extensive list of changes and features in the 3.2 line, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2.1 visit: http://www.python.org/download/releases/3.2.1/ This is a testing release: Please consider trying Python 3.2.1 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 debatem1 at gmail.com Tue May 17 14:56:33 2011 From: debatem1 at gmail.com (geremy condra) Date: Tue, 17 May 2011 11:56:33 -0700 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> Message-ID: On Tue, May 17, 2011 at 10:19 AM, Jussi Piitulainen wrote: > geremy condra writes: > >> or O(1): >> >> ? = (1 + sqrt(5)) / 2 >> def fib(n): >> ? ? numerator = (?**n) - (1 - ?)**n >> ? ? denominator = sqrt(5) >> ? ? return round(numerator/denominator) >> >> Testing indicates that it's faster somewhere around 7 or so. > > And increasingly inaccurate from 71 on. Yup. That's floating point for you. For larger values you could just add a linear search at the bottom using the 5f**2 +/- 4 rule, which would still be quite fast out to about 10 times that. The decimal module gets you a tiny bit further, and after that it's time to just use Dijkstra's, like rusi suggested. In any event, I still think this formulation is the most fun ;). Geremy Condra From ethan at stoneleaf.us Tue May 17 15:07:44 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 May 2011 12:07:44 -0700 Subject: if statement on lenght of a list In-Reply-To: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> References: <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> Message-ID: <4DD2C780.9010909@stoneleaf.us> Joe Leonardo wrote: > > Totally baffled by this?maybe I need a nap. Writing a small function to > reject input that is not a list of 19 fields. > > def breakLine(value): > if value.__class__() != [] and value.__len__() != 19: > print 'You must pass a list that contains 19 fields.' > else: > print 'YAY!' > > If I pass: > > breakLine([]) > > I get: > > YAY! Change your 'and' to an 'or'. Also, change your 'value.__len__()' to 'len(value)'. Finally, if you absolutely don't want any iterable that might work (such as a tuple), change 'value.__class__() != []' to either 'type(value) != list' or, if subclasses are okay (and they probably should be) 'not isinstance(value, list)'. Incorporating these suggestions looks like this: def breakLine(value): if not isinstance(value, list) or len(value) != 19: print 'You must pass a list that contains 19 fields.' else: print 'YAY!' From miki.tebeka at gmail.com Tue May 17 15:15:30 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 17 May 2011 12:15:30 -0700 (PDT) Subject: best way to extract sentence from txt file In-Reply-To: Message-ID: http://nltk.googlecode.com/svn/trunk/doc/api/nltk.tokenize-module.html ? From miki.tebeka at gmail.com Tue May 17 15:15:30 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 17 May 2011 12:15:30 -0700 (PDT) Subject: best way to extract sentence from txt file In-Reply-To: Message-ID: http://nltk.googlecode.com/svn/trunk/doc/api/nltk.tokenize-module.html ? From ian.g.kelly at gmail.com Tue May 17 15:20:32 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 13:20:32 -0600 Subject: Python 3.x and bytes In-Reply-To: <4DD2C2A5.3080403@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: On Tue, May 17, 2011 at 12:47 PM, Ethan Furman wrote: > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have expected > this to have huh being a bytestring with one element -- the integer 5. > ?Actually, what you get is: > > --> huh > b'\x00\x00\x00\x00\x00' > > or five null bytes. ?Note that this is an immutable type, so you cannot go > in later and say > > --> huh[3] = 9 > Traceback (most recent call last): > ?File "", line 1, in > TypeError: 'bytes' object does not support item assignment > > > So, out of curiosity, does anyone actually use this, um, feature? I suppose it's for interoperability with the mutable bytearray type, which takes the same parameters in the constructor. From felipe.bastosn at gmail.com Tue May 17 15:22:30 2011 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Tue, 17 May 2011 16:22:30 -0300 Subject: Python 3.x and bytes In-Reply-To: <4DD2C2A5.3080403@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: They accept .replace(b"00", b"12") for example. Documentation about it. 2011/5/17 Ethan Furman > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have expected > this to have huh being a bytestring with one element -- the integer 5. > Actually, what you get is: > > --> huh > b'\x00\x00\x00\x00\x00' > > or five null bytes. Note that this is an immutable type, so you cannot go > in later and say > > --> huh[3] = 9 > Traceback (most recent call last): > File "", line 1, in > TypeError: 'bytes' object does not support item assignment > > > So, out of curiosity, does anyone actually use this, um, feature? > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 17 15:25:35 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 13:25:35 -0600 Subject: Python 3.x and bytes In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: On Tue, May 17, 2011 at 1:20 PM, Ian Kelly wrote: > I suppose it's for interoperability with the mutable bytearray type, > which takes the same parameters in the constructor. http://www.python.org/dev/peps/pep-3137/#constructors From topher.bartos at gmail.com Tue May 17 15:26:52 2011 From: topher.bartos at gmail.com (Chris M. Bartos) Date: Tue, 17 May 2011 15:26:52 -0400 Subject: Cartoonify Myself Message-ID: <4DD2CBFC.4070109@gmail.com> Hi, Is there a Python module that can "cartoonify" a picture of myself? There's got to be an algorithm out there somewhere, right? If there is a way to cartoon a single picture, could you cartoonify a video, too? Thanks for your help. Chris -- Christopher M. Bartos bartos.25 at osu.edu 330-324-0018 From alister.ware at ntlworld.com Tue May 17 15:26:58 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Tue, 17 May 2011 19:26:58 GMT Subject: problem with GKT module? References: Message-ID: <6_zAp.5859$6K4.49@newsfe14.ams2> On Mon, 16 May 2011 14:56:38 -0500, harrismh777 wrote: > alister ware wrote: >> def callback(self,widget,data=None): >> print widget #gives reference to radio button ok print >> widget.name #widget name on windoze, None on linux > > Well, you're obviously using Python 2.x ... > > ... have you tried this in Python 3.x ? > > > Neither here nor there... you need to know who/what is generating > 'widget'. Is widget buried in gtk where you can't see how it works, or > is widget a Python class (or wrapper) where you can see what its doing? > > The fact that widget.name returns None on the linux platform tells me > that widget is a Python class (or wrapper) ... so you probably have a > widget.py file somewhere... or some other module that widget is a class > definition in... who knows... (at this point). > > It seems to me that the 'builder' is behaving differently on the two > platforms (rather than Python is behaving differently on the two > platforms). > > What happens if you change the data=None pair? > > What happens if you omit data=None pair? > > Do you see this difference with *all* widgets, or just radio buttons? > > > > kind regards, > m harris It seems it was introduced in pygtk 2.1.7 as a side effect of correcting something to do with widget id's and the fact that widget names do not have to be unique (although glade insists that they are). looks like i have to modify my code & use gtk.buildable.get_name(widget) instead, not really a big change but may break someone else's code -- If you're not careful, you're going to catch something. From python at mrabarnett.plus.com Tue May 17 15:39:12 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 May 2011 20:39:12 +0100 Subject: Python 3.x and bytes In-Reply-To: <4DD2C2A5.3080403@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: <4DD2CEE0.4080403@mrabarnett.plus.com> On 17/05/2011 19:47, Ethan Furman wrote: > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have > expected this to have huh being a bytestring with one element -- the > integer 5. Actually, what you get is: > > --> huh > b'\x00\x00\x00\x00\x00' > > or five null bytes. Note that this is an immutable type, so you cannot > go in later and say > > --> huh[3] = 9 > Traceback (most recent call last): > File "", line 1, in > TypeError: 'bytes' object does not support item assignment > > > So, out of curiosity, does anyone actually use this, um, feature? > I suppose it follows the example of 'list' and 'tuple' in accepting an iterable. Producing a bytestring of zero bytes might have its uses, but because Python lets me do coding at a high level (lists, dicts, etc), I've never used that feature. BTW, help(bytes) doesn't seem to mention it! From marduk at letterboxes.org Tue May 17 15:48:29 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 17 May 2011 15:48:29 -0400 Subject: FW: help please In-Reply-To: <4DD29FF1.9090506@tysdomain.com> References: <4DD29FF1.9090506@tysdomain.com> Message-ID: <1305661713.3831.1.camel@localhost.localdomain> On Tue, 2011-05-17 at 10:18 -0600, Littlefield, Tyler wrote: > Not to be pedantic or anything, and I may not be able to help > regardless, but it looks like your space key is fixed, and I don't > really care to pick through and try to play hangman with your message. I actually, at first glance, thought it was spam, ignored it, and was wondering why people were replying to it :| -a From kb1pkl at aim.com Tue May 17 15:50:13 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Tue, 17 May 2011 15:50:13 -0400 Subject: Python 3.x and bytes In-Reply-To: <4DD2C2A5.3080403@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: <4DD2D175.30506@aim.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/17/2011 02:47 PM, Ethan Furman wrote: > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have > expected this to have huh being a bytestring with one element -- the > integer 5. Actually, what you get is: > > --> huh > b'\x00\x00\x00\x00\x00' > > or five null bytes. Note that this is an immutable type, so you cannot > go in later and say For the bytes to actually be a 'list of integers', you need to pass it an iterable, ex: >>> bytes([5, 6, 1, 3]) b'\x05\x06\x01\x03' - From help(bytes): | bytes(iterable_of_ints) -> bytes | bytes(string, encoding[, errors]) -> bytes | bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer | bytes(memory_view) -> bytes Looks like you're using the fourth when you want the first, possibly? - -- Corey Richardson -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJN0tF1AAoJEAFAbo/KNFvp41AH/1l2zR6XVOJ0xM7s2P+PDYZX OAhmi19hFEP0zQoWiW3TiMEVPlaqgtipPCp1t+jTeNNN3F+H4NG2DHJJZ3dPDr2J CpABQKyS4MJQTUxhCIlXqAaA2I1pejzAv6fwsF66/zPFmyaTAJLDP+3WMQvCUUoZ 5A3qHgHNp6vBHXd13RNdQStLeprfQptA+z6XdiJPos348ecRj/u9id7v28dwxxsm d9WA6oYwJ+Y/NcG2OP0Flyp3Zc3hymVsv5vhmhG2+EiIrxMn95k8ImsKLEhvUW3a 72CxlE6EaOMD4MuWyeGMS33c0vHwtAvEIE7M56R2FAl8EsUFwP2swaij0tEiemg= =8MRV -----END PGP SIGNATURE----- From drsalists at gmail.com Tue May 17 15:53:11 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 17 May 2011 12:53:11 -0700 Subject: ipython prompt does not appear in windows In-Reply-To: References: Message-ID: Try running ipython in a cmd.exe. If that works, it almost certainly means that the I/O is going directly to video RAM instead of through a disciplined API. On Tue, May 17, 2011 at 12:00 AM, rusi wrote: > If I use ipython under emacs on linux it works (at least basic REPL) > ie I can type an expression and I get a result followed by a prompt > > On windows ipython works at the shell. > Plain python works in emacs as well. > > But inside emacs I dont see a prompt in ipython although I see it in > python. > I have to type an expression and then the prompt appears. > > Any clues? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrmakent at gmail.com Tue May 17 16:10:11 2011 From: mrmakent at gmail.com (Michael Kent) Date: Tue, 17 May 2011 13:10:11 -0700 (PDT) Subject: portable multiprocessing code In-Reply-To: Message-ID: <216bc8df-560c-4417-935f-5421c2a495fe@glegroupsg2000goo.googlegroups.com> You could also install Python 2.7 on that RedHat machine. It can be done without interfering with the 2.5 that RedHat depends on. From mrmakent at gmail.com Tue May 17 16:10:11 2011 From: mrmakent at gmail.com (Michael Kent) Date: Tue, 17 May 2011 13:10:11 -0700 (PDT) Subject: portable multiprocessing code In-Reply-To: Message-ID: <216bc8df-560c-4417-935f-5421c2a495fe@glegroupsg2000goo.googlegroups.com> You could also install Python 2.7 on that RedHat machine. It can be done without interfering with the 2.5 that RedHat depends on. From felipe.bastosn at gmail.com Tue May 17 16:19:10 2011 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Tue, 17 May 2011 17:19:10 -0300 Subject: Python 3.x and bytes In-Reply-To: <4DD2D89D.4000303@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> Message-ID: This piece of code works fine for me: > >>> somevar = bytes() > >>> somevar > '' > >>> somevar.replace(b'', b'10') > '10' > >>> somevar > '' > >>> somevar = somevar.replace(b'', b'10') > >>> somevar > '10' > >>> somevar2 = bytes(b'10'*2) > >>> somevar2 > '1010' > >>> somevar2 = somevar2.replace(b'01', b'57'*3) > >>> somevar2 > '15757570' > > They're unmutable, but replace deals with it. 2011/5/17 Ethan Furman > Felipe Bastos Nunes wrote: > > 2011/5/17 Ethan Furman wrote: >> >>> >>> In Python 3 one can say >>> >>> --> huh = bytes(5) >>> >>> Since the bytes type is actually a list of integers, I would have >>> expected this to have huh being a bytestring with one element -- the >>> integer 5. Actually, what you get is: >>> >>> --> huh >>> b'\x00\x00\x00\x00\x00' >>> >>> or five null bytes. Note that this is an immutable type, so you >>> cannot go in later and say >>> >>> --> huh[3] = 9 >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: 'bytes' object does not support item assignment >>> >>> >>> So, out of curiosity, does anyone actually use this, um, feature? >>> >> > > >> They accept .replace(b"00", b"12") for example. >> > > So they do. Although that particular example doesn't work since b'0' is > the integer 48... > > --> huh.replace(b'00',b'12') > > b'\x00\x00\x00\x00\x00' > > > The big question, though, is would you do it this way: > > some_var = bytes(23).replace(b'\x00', b'a') > > or this way? > > some_var = bytes(b'a' * 23) > > ~Ethan~ > -- Felipe Bastos Nunes -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue May 17 16:20:45 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 May 2011 13:20:45 -0700 Subject: Python 3.x and bytes In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> Message-ID: <4DD2D89D.4000303@stoneleaf.us> Felipe Bastos Nunes wrote: > 2011/5/17 Ethan Furman wrote: >> >> In Python 3 one can say >> >> --> huh = bytes(5) >> >> Since the bytes type is actually a list of integers, I would have >> expected this to have huh being a bytestring with one element -- the >> integer 5. Actually, what you get is: >> >> --> huh >> b'\x00\x00\x00\x00\x00' >> >> or five null bytes. Note that this is an immutable type, so you >> cannot go in later and say >> >> --> huh[3] = 9 >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: 'bytes' object does not support item assignment >> >> >> So, out of curiosity, does anyone actually use this, um, feature? > > They accept .replace(b"00", b"12") for example. So they do. Although that particular example doesn't work since b'0' is the integer 48... --> huh.replace(b'00',b'12') b'\x00\x00\x00\x00\x00' The big question, though, is would you do it this way: some_var = bytes(23).replace(b'\x00', b'a') or this way? some_var = bytes(b'a' * 23) ~Ethan~ From andy at earthsong.free-online.co.uk Tue May 17 16:25:31 2011 From: andy at earthsong.free-online.co.uk (andy baxter) Date: Tue, 17 May 2011 21:25:31 +0100 Subject: Cartoonify Myself In-Reply-To: <4DD2CBFC.4070109@gmail.com> References: <4DD2CBFC.4070109@gmail.com> Message-ID: <4DD2D9BB.5080405@earthsong.free-online.co.uk> On 17/05/11 20:26, Chris M. Bartos wrote: > Hi, > > Is there a Python module that can "cartoonify" a picture of myself? > There's got to be an algorithm out there somewhere, right? If there is > a way to cartoon a single picture, could you cartoonify a video, too? > > Thanks for your help. > > > Chris > You could have a look at the python automation module for the gimp (a free software image editor). See e.g.: http://starryalley.homelinux.net/blog/index.php?/archives/1248-Star-Trail-Automation-script-using-python-gimp.html From karim.liateni at free.fr Tue May 17 16:26:13 2011 From: karim.liateni at free.fr (Karim) Date: Tue, 17 May 2011 22:26:13 +0200 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD1C9D5.4070206@gmail.com> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD1C9D5.4070206@gmail.com> Message-ID: <4DD2D9E5.1040308@free.fr> On 05/17/2011 03:05 AM, Andrew Berg wrote: > On 2011.05.16 02:26 AM, Karim wrote: >> Use regular expression for bad HTLM or beautifulSoup (google it), below >> a exemple to extract all html links: >> >> linksList = re.findall('.*?',htmlSource) >> for link in linksList: >> print link > I was afraid I might have to use regexes (mostly because I could never > understand them). > Even the BeautifulSoup website itself admits it's awful with Python 3 - > only the admittedly broken 3.1.0 will work with Python 3 at all. > ElementTree doesn't seem to have been updated in a long time, so I'll > assume it won't work with Python 3. > lxml looks promising, but it doesn't say anywhere whether it'll work on > Python 3 or not, which is puzzling since the latest release was only a > couple months ago. > > Actually, if I'm going to use regex, I might as well try to implement > Versions* in Python. > > Thanks for the answers! > > *http://en.totalcmd.pl/download/wfx/net/Versions (original, made for > Total Commander) and > https://addons.mozilla.org/en-US/firefox/addon/versions-wfx_versions/ > (clone implemented as a Firefox add-on; it's so wonderful, I even wrote > the docs for it!) Andrew, I wrote a class with HMLTParser to get only one link for a given project, cf below: 73 class ResultsLinkParser(HTMLParser.HTMLParser): 74 """Class ResultsLinkParser inherits form HTMLParser to extract 75 the original 'Submission date' of the a bug. 76 This customized parser will deals with the 'View Defect' HTML 77 page from Clear DDTS. 78 """ 79 def __init__(self): 80 HTMLParser.HTMLParser.__init__(self) 81 self._link = None 82 83 def handle_starttag(self, tag, attrs): 84 """Implement standard class HTMLParser customizing method.""" 85 if tag == 'frame': 86 try: 87 attributes = dict(attrs) 88 if attributes['name'] == 'indexframe': 89 self._link = attributes['src'] 90 except KeyError, e: 91 print("""WARNING: Attribute '{keyname}' from frame tag 92 in QueryResult page does not exist!""".format(keyname=e)) 93 94 def link(self): 95 """Return the html link of the query results page.""" 96 return self._link You can use it and just modified it to get the latest just add some code (and change the tag 'name' of my example) to compare revision number with max and keep the max to compare it to the next value. I let you add this little code just create self._revision = None in the __init__(self) which hold the current max revision. After parser.feed() you can get the value by parser._revision or a public parser.revision() method to get the value. Cheers Karim From dje at google.com Tue May 17 16:35:27 2011 From: dje at google.com (Doug Evans) Date: Tue, 17 May 2011 13:35:27 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 6:26 AM, Ruben Van Boxem wrote: > Wow, I think I have a partial solution. Delving into the Python docs, > for example here: > http://docs.python.org/using/windows.html#finding-modules, you can see > that PYTHONPATH is used first, then the Windows registry, then > PYTHONHOME, then some default relative paths. I placed the python > scripts all in the directory structure like so: > > /bin/gdb > /bin/Lib/ > /bin/python27.dll > > This works, even without any manual PYTHONPATH intervention. Problem > is though, that as soon as someone has a PYTHONPATH environment > variable from a (incompatible) Python installation (think different > bitness or version 3.x instead of 2.7.1), I cannot predict what will > go wrong. This problem originates in Python's way of filling in the > search path (sys.path). A true solution in the GDB case to prevent > this collision of an incompatible PYTHONPATH would be that GDB sets an > internal PYTHONPATH as directed by configure, uses that to load its > Python internals, and allows the GDB child processes (apps being > debugged) to use the environment PYTHONPATH. For now, I have a > functional installation, but it will break as soon as someone installs > Python on their system. What if the user *wants* gdb's python to use $PYTHONPATH from his/her environment? To handle *this* case, *and* the case of an incompatible python installation using $PYTHONPATH, there is the $GDB_PYTHONPATH proposal (see earlier email for details). It feels problematic to decide at configure time whether there will or will not be an incompatible python at runtime. [I realize you have subsequent messages. Just replying in sequence.] From felipe.bastosn at gmail.com Tue May 17 16:50:00 2011 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Tue, 17 May 2011 17:50:00 -0300 Subject: Python 3.x and bytes In-Reply-To: <4DD2D175.30506@aim.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com> Message-ID: Mine bytes constructor when useing Corey's advice give's me a string instead of a b''... 2011/5/17 Corey Richardson > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 05/17/2011 02:47 PM, Ethan Furman wrote: > > In Python 3 one can say > > > > --> huh = bytes(5) > > > > Since the bytes type is actually a list of integers, I would have > > expected this to have huh being a bytestring with one element -- the > > integer 5. Actually, what you get is: > > > > --> huh > > b'\x00\x00\x00\x00\x00' > > > > or five null bytes. Note that this is an immutable type, so you cannot > > go in later and say > > For the bytes to actually be a 'list of integers', you need to pass it > an iterable, ex: > >>> bytes([5, 6, 1, 3]) > b'\x05\x06\x01\x03' > > - From help(bytes): > | bytes(iterable_of_ints) -> bytes > | bytes(string, encoding[, errors]) -> bytes > | bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer > | bytes(memory_view) -> bytes > > Looks like you're using the fourth when you want the first, possibly? > > - -- > Corey Richardson > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.17 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iQEcBAEBAgAGBQJN0tF1AAoJEAFAbo/KNFvp41AH/1l2zR6XVOJ0xM7s2P+PDYZX > OAhmi19hFEP0zQoWiW3TiMEVPlaqgtipPCp1t+jTeNNN3F+H4NG2DHJJZ3dPDr2J > CpABQKyS4MJQTUxhCIlXqAaA2I1pejzAv6fwsF66/zPFmyaTAJLDP+3WMQvCUUoZ > 5A3qHgHNp6vBHXd13RNdQStLeprfQptA+z6XdiJPos348ecRj/u9id7v28dwxxsm > d9WA6oYwJ+Y/NcG2OP0Flyp3Zc3hymVsv5vhmhG2+EiIrxMn95k8ImsKLEhvUW3a > 72CxlE6EaOMD4MuWyeGMS33c0vHwtAvEIE7M56R2FAl8EsUFwP2swaij0tEiemg= > =8MRV > -----END PGP SIGNATURE----- > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 17 16:51:31 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 14:51:31 -0600 Subject: Python 3.x and bytes In-Reply-To: <4DD2D175.30506@aim.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com> Message-ID: On Tue, May 17, 2011 at 1:50 PM, Corey Richardson wrote: > - From help(bytes): > ?| ?bytes(iterable_of_ints) -> bytes > ?| ?bytes(string, encoding[, errors]) -> bytes > ?| ?bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer > ?| ?bytes(memory_view) -> bytes > > Looks like you're using the fourth when you want the first, possibly? Nope, he's using the fifth form, bytes(int), which is listed in the PEP but not in the help. From dje at google.com Tue May 17 16:52:13 2011 From: dje at google.com (Doug Evans) Date: Tue, 17 May 2011 13:52:13 -0700 Subject: Python enabled gdb on Windows and relocation In-Reply-To: References: Message-ID: On Sun, May 15, 2011 at 9:11 AM, Ruben Van Boxem wrote: > I am sorry for the repeated messages that no one cares about, but I > may have discovered GDB in its current form already allows what I > want: I tried to figure out what exact paths the snake in gdb was > using to search for its modules, and came up with this: > (gdb) python import sys > (gdb) python print sys.path > ['m:\\development\\mingw64\\share\\gdb/python', > 'M:\\Development\\mingw64\\bin\\python27.zip', > 'M:\\Development\\mingw64\\bin\\DLLs', > 'M:\\Development\\mingw64\\bin\\lib', > 'M:\\Development\\mingw64\\bin\\lib\\plat-win', > 'M:\\Development\\mingw64\\bin\\lib\\lib-tk', > 'M:\\Development\\mingw64\\bin', > 'M:\\Development\\mingw64\\bin\\lib\\site-packages'] > > This means that every python command within gdb searches > /share/gdb/python FIRST (even before an environment's > PYTHONPATH), alleviating any concerns or problems I or anyone would > have with another python installation, as this apparently built-in > path comes up first. All I, or anyone interested in doing this kind of > thing, have to do is copy all the python scripts from the Windows > installation's Lib directory to the /share/gdb/python > directory. > > I don't know where this path comes from, but it is quite handy, and > makes this whole discussion ?moot for Python people. Only "issue" that > I'll have to work around is the --with-python-includes and > --with-python-libs that are missing, using either manual > CFLAGS/LDFLAGS or a variant of your script. IMO *if* gdb wanted to support people adding files to *its* /share/gdb directory, more thought is needed - e.g. maybe document a "site" directory for such files. Dunno. IMO we certainly don't want to formally allow folks to willy-nilly put anything there - no guarantees a future release might add something that collides with something the user put there. If and until then, you're probably pretty safe if you put everything in a subdirectory with a unique enough name, if you really wanted to go this route. Btw, there is the system.gdbinit file which sites *are* free to customize. E.g., configure --with-system-gdbinit=/share/gdb/system.gdbinit. You can put whatever you want in that file. E.g., you could add a directory to python's sys.path. [Technically speaking, the path /share/gdb/system.gdbinit goes against what I just said, but IMO this name is safe.] From ian.g.kelly at gmail.com Tue May 17 16:52:43 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 14:52:43 -0600 Subject: Python 3.x and bytes In-Reply-To: <4DD2D89D.4000303@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> Message-ID: On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: > The big question, though, is would you do it this way: > > some_var = bytes(23).replace(b'\x00', b'a') > > or this way? > > some_var = bytes(b'a' * 23) Actually, I would just do it this way: some_var = b'a' * 23 That's already a bytes object. Passing it into the constructor is redundant. From mail2fei at gmail.com Tue May 17 16:55:34 2011 From: mail2fei at gmail.com (Fei) Date: Tue, 17 May 2011 13:55:34 -0700 (PDT) Subject: python logging Message-ID: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> where is default logging file on Mac? I saw lots of app just import logging, and begins to logging.info(...) etc. I'm not sure where to look at the logging configuration to figure out the log location. I just get in touch of python about 1month ago, and I appreciate your help. From ethan at stoneleaf.us Tue May 17 16:55:36 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 May 2011 13:55:36 -0700 Subject: Python 3.x and bytes In-Reply-To: <4DD2D175.30506@aim.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com> Message-ID: <4DD2E0C8.2090101@stoneleaf.us> Corey Richardson wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 05/17/2011 02:47 PM, Ethan Furman wrote: >> In Python 3 one can say >> >> --> huh = bytes(5) >> >> Since the bytes type is actually a list of integers, I would have >> expected this to have huh being a bytestring with one element -- the >> integer 5. Actually, what you get is: >> >> --> huh >> b'\x00\x00\x00\x00\x00' >> >> or five null bytes. Note that this is an immutable type, so you cannot >> go in later and say > > For the bytes to actually be a 'list of integers', you need to pass it > an iterable, ex: >>>> bytes([5, 6, 1, 3]) > b'\x05\x06\x01\x03' Not so. --> huh = b'abcedfg' --> huh[3] 101 It's a list of int's. > - From help(bytes): > | bytes(iterable_of_ints) -> bytes > | bytes(string, encoding[, errors]) -> bytes > | bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer > | bytes(memory_view) -> bytes > > Looks like you're using the fourth when you want the first, possibly? Nope. Apparently, it's not well documented. If you check PEP 358 you'll find it. ~Ethan~ From wolfram.hinderer at googlemail.com Tue May 17 17:04:50 2011 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Tue, 17 May 2011 14:04:50 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> Message-ID: <80ba3b5e-34c1-420a-aade-9c1996d0239e@u26g2000vby.googlegroups.com> On 17 Mai, 20:56, geremy condra wrote: > On Tue, May 17, 2011 at 10:19 AM, Jussi Piitulainen > > wrote: > > geremy condra writes: > > >> or O(1): > > >> ? = (1 + sqrt(5)) / 2 > >> def fib(n): > >> ? ? numerator = (?**n) - (1 - ?)**n > >> ? ? denominator = sqrt(5) > >> ? ? return round(numerator/denominator) > > >> Testing indicates that it's faster somewhere around 7 or so. > > > And increasingly inaccurate from 71 on. > > Yup. That's floating point for you. For larger values you could just > add a linear search at the bottom using the 5f**2 +/- 4 rule, which > would still be quite fast out to about 10 times that. The decimal > module gets you a tiny bit further, and after that it's time to just > use Dijkstra's, like rusi suggested. In any event, I still think this > formulation is the most fun ;). I think you can write it even more funny def fib(n): return round(((.5 + .5 * 5 ** .5) ** n - (.5 - .5 * 5 ** .5) ** n) * 5 ** -.5) ;-) From ian.g.kelly at gmail.com Tue May 17 17:18:14 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 15:18:14 -0600 Subject: portable multiprocessing code In-Reply-To: References: Message-ID: On Tue, May 17, 2011 at 9:14 AM, Eric Frederich wrote: > I have written some code using Python 2.7 but I'd like these scripts > to be able to run on Red Hat 5's 2.4.3 version of Python which doesn't > have multiprocessing. > I can try to import multiprocessing and set a flag as to whether it is > available. ?Then I can create a Queue.Queue instead of a > multiprocessing.Queue for the arg_queue and result_queue. > Without actually trying this yet it seems like things would work okay > except for the Worker class. ?It seems I can conditionally replace > multiprocessing.Queue with Queue.Queue, but is there anything to > replace multiprocessing.Process with? Yes, threading.Thread. Pro: Since the multiprocessing module is designed to be a drop-in replacement for the threading module, it should also be pretty straight-forward to go in the reverse direction. Con: You won't have true concurrency because of the GIL. Cheers, Ian From kb1pkl at aim.com Tue May 17 17:27:04 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Tue, 17 May 2011 17:27:04 -0400 Subject: Python 3.x and bytes In-Reply-To: <4DD2E0C8.2090101@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com> <4DD2E0C8.2090101@stoneleaf.us> Message-ID: <4DD2E828.9000502@aim.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/17/2011 04:55 PM, Ethan Furman wrote: > Apparently, it's not well documented. If you check PEP 358 > you'll find it. > > ~Ethan~ Agreed, it looks like it should be mentioned in bytes.__doc__ about the single-integer argument. - -- Corey Richardson -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJN0ugoAAoJEAFAbo/KNFvphIsH/3LOzN8+D98D0+nm6m8sfCUC f+KfgTLITAmecYOuOBym1snl6qj2JnZkGYRW6M2O5NV8arNJ1dHty3dPbwMeKdfH 67m2a0UgHcwqv5M5VGNQQYTQ03Mzqy+A84MMvBKWUQ0nxZRCkPMtdxm2T4/UEVLx uelDPOdOWB1PDmc3sNUDPovXeOFlTKmcQ5yfolyrdLFU/KmbamgRSltpBFEbyInO 4KI3hoGka4PVaaBLf9QPjFC6tBu4QdQ4UTnWD3sy78LA3KPsa5MEpXFXctwJkJ+O q2Y7SWOPJDz19V+MT87Aeu69YpzxWwkp4fBflNxYaQUoJqNlzIfRkavUzZ0zfMQ= =E2qm -----END PGP SIGNATURE----- From nirina.raseliarison at gmail.com Tue May 17 17:31:52 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Wed, 18 May 2011 00:31:52 +0300 Subject: test_argparse.py FAILED (failures=6) Message-ID: ====================================================================== FAIL: test_failures_many_groups_listargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ====================================================================== FAIL: test_failures_many_groups_sysargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ====================================================================== FAIL: test_failures_no_groups_listargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ====================================================================== FAIL: test_failures_no_groups_sysargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ====================================================================== FAIL: test_failures_one_group_listargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ====================================================================== FAIL: test_failures_one_group_sysargs (__main__.TestFileTypeW) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/test/test_argparse.py", line 216, in wrapper test_func(self) File "Lib/test/test_argparse.py", line 235, in test_failures raises(ArgumentParserError, parser.parse_args, args) AssertionError: ArgumentParserError not raised by parse_args ---------------------------------------------------------------------- Ran 1599 tests in 6.298s FAILED (failures=6) Traceback (most recent call last): File "Lib/test/test_argparse.py", line 4681, in test_main() File "Lib/test/test_argparse.py", line 4673, in test_main support.run_unittest(__name__) File "/mnt/sda14/pack_build/Python-3.2.1rc1/Lib/test/support.py", line 1184, in run_unittest _run_suite(suite) File "/mnt/sda14/pack_build/Python-3.2.1rc1/Lib/test/support.py", line 1167, in _run_suite raise TestFailed(err) test.support.TestFailed: multiple errors occurred -- nirinA From nirina.raseliarison at gmail.com Tue May 17 17:32:16 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Wed, 18 May 2011 00:32:16 +0300 Subject: test_ftplib.py failed with segmentation fault,gcc4.6.0,glibc-2.13 Message-ID: hi all, i can't get connected to bugs.python.org so here my make test results. make test aborted when running test_ftplib. and running # ./python Lib/test/test_ftplib.py Segmentation fault with this kernel message: [ 2166.927138] python[12142]: segfault at 1d81 ip 00007f7e733a09c2 sp 00007f7e701038a0 error 4 in libc-2.13.so[7f7e73328000+19b000] however, i just tested using ftplib without tls and it worked fine. below the error log == CPython 3.2.1rc1 (default, May 17 2011, 22:01:34) [GCC 4.6.0] == Linux-2.6.38.wmodem-x86_64-Intel-R-_Pentium-R-_Dual__CPU__E2180__ at _2.00GHz-with-slackware-12.2.0 little-endian == /mnt/sda14/pack_build/Python-3.2.1rc1/build/test_python_12247 Testing with flags: sys.flags(debug=0, division_warning=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0) test_abort (__main__.TestFTPClass) ... ok test_acct (__main__.TestFTPClass) ... ok test_all_errors (__main__.TestFTPClass) ... ok test_delete (__main__.TestFTPClass) ... ok test_dir (__main__.TestFTPClass) ... ok test_exceptions (__main__.TestFTPClass) ... ok test_getwelcome (__main__.TestFTPClass) ... ok test_login (__main__.TestFTPClass) ... ok test_makepasv (__main__.TestFTPClass) ... ok test_makeport (__main__.TestFTPClass) ... ok test_mkd (__main__.TestFTPClass) ... ok test_nlst (__main__.TestFTPClass) ... ok test_parse257 (__main__.TestFTPClass) ... ok test_pwd (__main__.TestFTPClass) ... ok test_quit (__main__.TestFTPClass) ... ok test_rename (__main__.TestFTPClass) ... ok test_retrbinary (__main__.TestFTPClass) ... ok test_retrbinary_rest (__main__.TestFTPClass) ... ok test_retrlines (__main__.TestFTPClass) ... ok test_rmd (__main__.TestFTPClass) ... ok test_sanitize (__main__.TestFTPClass) ... ok test_set_pasv (__main__.TestFTPClass) ... ok test_size (__main__.TestFTPClass) ... ok test_storbinary (__main__.TestFTPClass) ... ok test_storbinary_rest (__main__.TestFTPClass) ... ok test_storlines (__main__.TestFTPClass) ... ok test_voidcmd (__main__.TestFTPClass) ... ok test_with_statement (__main__.TestFTPClass) ... ok testTimeoutConnect (__main__.TestTimeouts) ... ok testTimeoutDefault (__main__.TestTimeouts) ... ok testTimeoutDifferentOrder (__main__.TestTimeouts) ... ok testTimeoutDirectAccess (__main__.TestTimeouts) ... ok testTimeoutNone (__main__.TestTimeouts) ... ok testTimeoutValue (__main__.TestTimeouts) ... ok test_abort (__main__.TestTLS_FTPClassMixin) ... *** glibc detected *** ./python: free(): invalid next size (normal): 0x00007f38f0018cf0 *** ======= Backtrace: ========= /lib64/libc.so.6(+0x78f85)[0x7f38fa1e7f85] /lib64/libc.so.6(cfree+0x73)[0x7f38fa1ebd93] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(CRYPTO_free+0x3d)[0x7f38f940b3aa] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(+0x12f407)[0x7f38f9492407] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(RSA_private_decrypt+0x45)[0x7f38f9429979] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(ssl3_get_client_key_exchange+0x2a4)[0x7f38f93e7060] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(ssl3_accept+0xa0b)[0x7f38f93e40d2] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(SSL_do_handshake+0x98)[0x7f38f9400021] /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_ssl.cpython-32m.so(+0x77f69)[0x7f38f93daf69] ./python(PyEval_EvalFrameEx+0x709c)[0x45d4ec] ./python(PyEval_EvalCodeEx+0x696)[0x456186] ./python(PyEval_EvalFrameEx+0x6d83)[0x45d1d3] ./python(PyEval_EvalFrameEx+0x6e9e)[0x45d2ee] ./python(PyEval_EvalCodeEx+0x696)[0x456186] ./python(PyEval_EvalFrameEx+0x6d83)[0x45d1d3] ./python(PyEval_EvalFrameEx+0x6e9e)[0x45d2ee] ./python(PyEval_EvalCodeEx+0x696)[0x456186] ./python(PyEval_EvalFrameEx+0x6d83)[0x45d1d3] ./python(PyEval_EvalCodeEx+0x696)[0x456186] ./python(PyEval_EvalFrameEx+0x6d83)[0x45d1d3] ./python(PyEval_EvalFrameEx+0x6e9e)[0x45d2ee] ======= Memory map: ======== 00400000-00586000 r-xp 00000000 08:0e 54225 /mnt/sda14/pack_build/Python-3.2.1rc1/python 00786000-007cf000 rw-p 00186000 08:0e 54225 /mnt/sda14/pack_build/Python-3.2.1rc1/python 007cf000-007ed000 rw-p 00000000 00:00 0 00b9c000-0111a000 rw-p 00000000 00:00 0 [heap] 7f38f0000000-7f38f0022000 rw-p 00000000 00:00 0 7f38f0022000-7f38f4000000 ---p 00000000 00:00 0 7f38f6537000-7f38f654c000 r-xp 00000000 08:0b 224 /usr/lib64/libgcc_s.so.1 7f38f654c000-7f38f674b000 ---p 00015000 08:0b 224 /usr/lib64/libgcc_s.so.1 7f38f674b000-7f38f674c000 rw-p 00014000 08:0b 224 /usr/lib64/libgcc_s.so.1 7f38f674c000-7f38f674d000 ---p 00000000 00:00 0 7f38f674d000-7f38f6f4d000 rw-p 00000000 00:00 0 7f38f6f4d000-7f38f6f64000 r-xp 00000000 08:0b 117661 /lib64/libresolv-2.13.so 7f38f6f64000-7f38f7164000 ---p 00017000 08:0b 117661 /lib64/libresolv-2.13.so 7f38f7164000-7f38f7165000 r--p 00017000 08:0b 117661 /lib64/libresolv-2.13.so 7f38f7165000-7f38f7166000 rw-p 00018000 08:0b 117661 /lib64/libresolv-2.13.so 7f38f7166000-7f38f7168000 rw-p 00000000 00:00 0 7f38f7168000-7f38f716f000 r-xp 00000000 08:0b 117654 /lib64/libnss_dns-2.13.so 7f38f716f000-7f38f736e000 ---p 00007000 08:0b 117654 /lib64/libnss_dns-2.13.so 7f38f736e000-7f38f736f000 r--p 00006000 08:0b 117654 /lib64/libnss_dns-2.13.so 7f38f736f000-7f38f7370000 rw-p 00007000 08:0b 117654 /lib64/libnss_dns-2.13.so 7f38f7370000-7f38f737c000 r-xp 00000000 08:0b 117655 /lib64/libnss_files-2.13.so 7f38f737c000-7f38f757b000 ---p 0000c000 08:0b 117655 /lib64/libnss_files-2.13.so 7f38f757b000-7f38f757c000 r--p 0000b000 08:0b 117655 /lib64/libnss_files-2.13.so 7f38f757c000-7f38f757d000 rw-p 0000c000 08:0b 117655 /lib64/libnss_files-2.13.so 7f38f757d000-7f38f7587000 r-xp 00000000 08:0e 54307 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/array.cpython-32m.so 7f38f7587000-7f38f7786000 ---p 0000a000 08:0e 54307 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/array.cpython-32m.so 7f38f7786000-7f38f7789000 rw-p 00009000 08:0e 54307 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/array.cpython-32m.so 7f38f7789000-7f38f7826000 r-xp 00000000 08:0e 54337 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/unicodedata.cpython-32m.so 7f38f7826000-7f38f7a26000 ---p 0009d000 08:0e 54337 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/unicodedata.cpython-32m.so 7f38f7a26000-7f38f7a3b000 rw-p 0009d000 08:0e 54337 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/unicodedata.cpython-32m.so 7f38f7a3b000-7f38f7a3d000 r-xp 00000000 08:0e 54328 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/atexit.cpython-32m.so 7f38f7a3d000-7f38f7c3c000 ---p 00002000 08:0e 54328 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/atexit.cpython-32m.so 7f38f7c3c000-7f38f7c3d000 rw-p 00001000 08:0e 54328 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/atexit.cpython-32m.so 7f38f7c3d000-7f38f7c40000 r-xp 00000000 08:0e 54361 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_posixsubprocess.cpython-32m.so 7f38f7c40000-7f38f7e3f000 ---p 00003000 08:0e 54361 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_posixsubprocess.cpython-32m.so 7f38f7e3f000-7f38f7e40000 rw-p 00002000 08:0e 54361 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_posixsubprocess.cpython-32m.so 7f38f7e40000-7f38f7e51000 r-xp 00000000 08:0e 54325 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_pickle.cpython-32m.so 7f38f7e51000-7f38f8050000 ---p 00011000 08:0e 54325 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_pickle.cpython-32m.so 7f38f8050000-7f38f8054000 rw-p 00010000 08:0e 54325 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/_pickle.cpython-32m.so 7f38f8054000-7f38f8063000 r-xp 00000000 08:0b 256 /lib64/libbz2.so.1.0.4 7f38f8063000-7f38f8262000 ---p 0000f000 08:0b 256 /lib64/libbz2.so.1.0.4 7f38f8262000-7f38f8264000 rw-p 0000e000 08:0b 256 /lib64/libbz2.so.1.0.4 7f38f8264000-7f38f826a000 r-xp 00000000 08:0e 54397 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/bz2.cpython-32m.so 7f38f826a000-7f38f846a000 ---p 00006000 08:0e 54397 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/bz2.cpython-32m.so 7f38f846a000-7f38f846c000 rw-p 00006000 08:0e 54397 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/bz2.cpython-32m.so 7f38f846c000-7f38f846e000 r-xp 00000000 08:0e 54341 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/grp.cpython-32m.so 7f38f846e000-7f38f866e000 ---p 00002000 08:0e 54341 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/grp.cpython-32m.so 7f38f866e000-7f38f866f000 rw-p 00002000 08:0e 54341 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/grp.cpython-32m.so 7f38f866f000-7f38f8730000 rw-p 00000000 00:00 0 7f38f8730000-7f38f8733000 r-xp 00000000 08:0e 54339 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/fcntl.cpython-32m.so 7f38f8733000-7f38f8933000 ---p 00003000 08:0e 54339 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/fcntl.cpython-32m.so 7f38f8933000-7f38f8935000 rw-p 00003000 08:0e 54339 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/fcntl.cpython-32m.so 7f38f8935000-7f38f8939000 r-xp 00000000 08:0e 54315 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/time.cpython-32m.so 7f38f8939000-7f38f8b39000 ---p 00004000 08:0e 54315 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/time.cpython-32m.so 7f38f8b39000-7f38f8b3b000 rw-p 00004000 08:0e 54315 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/time.cpython-32m.so 7f38f8b3b000-7f38f8b3f000 r-xp 00000000 08:0e 54345 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/select.cpython-32m.so 7f38f8b3f000-7f38f8d3f000 ---p 00004000 08:0e 54345 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/select.cpython-32m.so 7f38f8d3f000-7f38f8d41000 rw-p 00004000 08:0e 54345 /mnt/sda14/pack_build/Python-3.2.1rc1/build/lib.linux-x86_64-3.2/select.cpython-32m.so 7f38f8d41000-7f38f8d55000 r-xp 00000000 08:0b 219 /usr/lib64/libz.so.1.2.3 7f38f8d55000-7f38f8f54000 ---p 00014000 08:0b 219 /usr/lib64/libz.so.1.2.3Aborted -- nirinA From nirina.raseliarison at gmail.com Tue May 17 17:32:19 2011 From: nirina.raseliarison at gmail.com (nirinA raseliarison) Date: Wed, 18 May 2011 00:32:19 +0300 Subject: smtplib is broken when using TLS Message-ID: i think this has the same origin as the ftplib test failure. Python 3.2.1rc1 (default, May 17 2011, 22:01:34) [GCC 4.6.0] on linux2 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART >>> ================================ >>> send: 'ehlo [127.0.0.1]\r\n' reply: b'250-mx.google.com at your service, [41.188.13.184]\r\n' reply: b'250-SIZE 35882577\r\n' reply: b'250-8BITMIME\r\n' reply: b'250-STARTTLS\r\n' reply: b'250 ENHANCEDSTATUSCODES\r\n' reply: retcode (250); Msg: b'mx.google.com at your service, [41.188.13.184]\nSIZE 35882577\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES' send: 'STARTTLS\r\n' reply: b'220 2.0.0 Ready to start TLS\r\n' reply: retcode (220); Msg: b'2.0.0 Ready to start TLS' Traceback (most recent call last): File "/root/template_mail_text.py", line 49, in server.starttls() File "/usr/local/lib/python3.2/smtplib.py", line 649, in starttls self.sock = ssl.wrap_socket(self.sock, keyfile, certfile) File "/usr/local/lib/python3.2/ssl.py", line 509, in wrap_socket ciphers=ciphers) File "/usr/local/lib/python3.2/ssl.py", line 266, in __init__ raise x File "/usr/local/lib/python3.2/ssl.py", line 262, in __init__ self.do_handshake() File "/usr/local/lib/python3.2/ssl.py", line 441, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [Errno 1] _ssl.c:392: error:140943FC:SSL routines:SSL3_READ_BYTES:sslv3 alert bad record mac -- nirinA From nad at acm.org Tue May 17 17:46:32 2011 From: nad at acm.org (Ned Deily) Date: Tue, 17 May 2011 14:46:32 -0700 Subject: Having a problem getting python working... References: <6E09A0F4-B9A6-4C9F-874B-CB6E21EF7A45@gmail.com> Message-ID: In article <6E09A0F4-B9A6-4C9F-874B-CB6E21EF7A45 at gmail.com>, Chris Paton wrote: > Not sure if this is the right place to put this (forgive me for my ignorance, > I'm looking everywhere!). I'm having a problem getting IDLE working. I'm > working off Mac OSX 10.6.7 with Python 3.2 installed and I installed > Activetcl 8.5.9 as recommended. IDLE is still crashing at random moments - > loading, saving, typing, compiling... I tried to do a simple 'hello world' > but it kept crashing. There's no official report; I just get the spinning > beach ball then have to force quit. I'm quite new to all of this so any help > would be extremely appreciated. Need to get into this ASAP as I need to do > some stuff for my thesis project! Sorry for the late response but if you can document how to reproduce the crashes or have a crash report that would be great. But, first, are you sure you were using IDLE 3.2 and not the Apple-supplied IDLE 2.6 in OS X 10.6? The latter will definitely exhibit that behavior. If you are installed Python 3.2 from one of the python.org installers, IDLE 3.2 will be available in /Applications/Python 3.2/ or as /usr/local/bin/idle3.2. -- Ned Deily, nad at acm.org From debatem1 at gmail.com Tue May 17 17:59:06 2011 From: debatem1 at gmail.com (geremy condra) Date: Tue, 17 May 2011 14:59:06 -0700 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <80ba3b5e-34c1-420a-aade-9c1996d0239e@u26g2000vby.googlegroups.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <80ba3b5e-34c1-420a-aade-9c1996d0239e@u26g2000vby.googlegroups.com> Message-ID: On Tue, May 17, 2011 at 2:04 PM, Wolfram Hinderer wrote: > On 17 Mai, 20:56, geremy condra wrote: >> On Tue, May 17, 2011 at 10:19 AM, Jussi Piitulainen >> >> wrote: >> > geremy condra writes: >> >> >> or O(1): >> >> >> ? = (1 + sqrt(5)) / 2 >> >> def fib(n): >> >> ? ? numerator = (?**n) - (1 - ?)**n >> >> ? ? denominator = sqrt(5) >> >> ? ? return round(numerator/denominator) >> >> >> Testing indicates that it's faster somewhere around 7 or so. >> >> > And increasingly inaccurate from 71 on. >> >> Yup. That's floating point for you. For larger values you could just >> add a linear search at the bottom using the 5f**2 +/- 4 rule, which >> would still be quite fast out to about 10 times that. The decimal >> module gets you a tiny bit further, and after that it's time to just >> use Dijkstra's, like rusi suggested. In any event, I still think this >> formulation is the most fun ;). > > I think you can write it even more funny > > def fib(n): > ? ?return round(((.5 + .5 * 5 ** .5) ** n - ?(.5 - .5 * 5 ** .5) ** > n) * 5 ** -.5) > > ;-) Ok, that's amusing. It does hide the interaction with the golden ratio though, which is what I find so fascinating about the earlier one. Geremy Condra From rafadurancastaneda at gmail.com Tue May 17 18:00:58 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Wed, 18 May 2011 00:00:58 +0200 Subject: python logging In-Reply-To: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> Message-ID: <4DD2F01A.1000704@gmail.com> On 17/05/11 22:55, Fei wrote: > where is default logging file on Mac? I saw lots of app just import > logging, and begins to logging.info(...) etc. I'm not sure where to > look at the logging configuration to figure out the log location. > > I just get in touch of python about 1month ago, and I appreciate your > help. Looking at python docs you will find: http://docs.python.org/howto/logging.html#logging-basic-tutorial First example explains what you are asking. P.S.: Next time you may try to look for the info you need before asking From xahlee at gmail.com Tue May 17 18:26:42 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 17 May 2011 15:26:42 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively Message-ID: might be of interest. ?English Idiom in Unix: Directory Recursively? http://xahlee.org/comp/idiom_directory_recursively.html ------------------------------------------ English Idiom in Unix: Directory Recursively Xah Lee, 2011-05-17 Today, let's discuss something in the category of lingustics. You know how in unix tools, when you want to delete the whole directory and all sub-directories and files in it, it's referred as ?recursive?? For example, when you want to delete the whole dir in emacs, it prompts this message: ?Recursive delete of xx? (y or n) ?. (Note: to be able to delete whole dir in emacs in dired, you'll first need to turn it on. See: emacs dired tutorial.) Here's another example. A quote from ?rsync? man page: ? This would recursively transfer all files from the directory ? -r, --recursive recurse into directories This tells rsync to copy directories recursively. See also -- dirs (-d). ? Here's a quote from ?cp?'s man page: -R, -r, --recursive copy directories recursively and lots of other tools has a ?-r? option, and they all refer to it as ?recursive?. Though, if you think about it, it's not exactly a correct description. ?Recursive?, or ?recursion?, refers to a particular type of algorithm, or a implementation using that algorithm. Obviously, to process all directory's content does not necessarily mean it must be done by a recursive algorithm. A iteration can do it as well and it's easy to have the full behavior and properties in the result as a recursive approach, such as specifying depth order, level to dive into, etc. (because, dir is a tree, and recursive algorithm is useful for walking the tree data structure but is not necessary, because a tree can be laid out flat. Any path order taken by a recursive approach can be done by just enumerating the nodes in sequence. In fact, iteration approach can be faster and simpler in many aspects. (i wrote a article about this some 10 years ago, see: Trees and Indexes.) Note: this thought about tree and its nodes as a set of node addresses can be applied to any tree data structure, such as lisp's nested syntax, XML. See: Programing Language: Fundamental Problems of Lisp.) If you look at Windows or Mac OS X world, i don't think they ever refer to dealing with whole dir as ?recursive? in user interface. For example, in Windows Vista, while changing properties of a folder, it has this message: Apply changes to this folder only. Apply changes to this folder, subfolders and files. Note the second choice. In unix, it would say ?Apply changes to this folder recursively.? So, the word ?recursive? used in unixes may be technically incorrect, but more so, it's just not the right phrase. Because, we want to communicate whether the whole content of a directory are processed, not about certain algorithm or how it is implemented. A simple ?all the dir's branches/contents? or similar would be more apt. Recently i was chatting in Second Life with someone (Sleeves). She's typing, while i'm on voice. In part of our conversation, i said ?you sounded fine?. Note that it's technically incorrect, because she's typing, not on voice. So she didn't actually make any ?sound?. But to say ?you typed fine?, or ?you chatted fine?, won't get the message across. That's idiom. When you interpret a idiom logically, it doesn't make much sense, but people understand the particular phrase better anyway. I suspect the ?directory recursively? is also a idiom. It seems so natural and really gets the point across, without any ill effects. Even if the implementation actually used a iteration, it doesn't seems to matter. So the interesting question is, why this idiom works? Or, how it developed? I think, among programers (which all unix users are in the 1970s), every one knows the concept of recursion, and many unix tools on dir probably are implemented with a recursive algorithm. When you say ?? recursively?, the point gets across, because we all understand it, even when we are not actually talking about implementation. The phrase ?? directory recursively? is short and memorable, while ?? directory and all its contents? or ?? directory and all its branches? or ?? directory and all its sub-directories and files? are wordy and unwieldy. ? Idiocy Of Unix Copy Command Emacs Lisp Suggestion: Function to Copy/Delete a Directory Recursively How to rsync, unison, wget, curl Hunspell Tutorial Mac OS X Resource Fork and Command Line Tips ImageMagick Tutorial Making System Calls in Perl and Python Unix And Literary Correlation The Unix Pestilence To An Or Not To An On ?I? versus ?i? (capitalization of first person pronoun) On the Postposition of Conjunction in Penultimate Position of a Sequence What's Passive Voice? What's Aggressive Voice? Why You Should Avoid The Jargon ?Tail Recursion? Why You should Not Use The Jargon Lisp1 and Lisp2 Jargons of Info Tech Industry Xah From ethan at stoneleaf.us Tue May 17 18:28:23 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 May 2011 15:28:23 -0700 Subject: Python 3.x and bytes In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> Message-ID: <4DD2F687.9050809@stoneleaf.us> Ian Kelly wrote: > On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: >> The big question, though, is would you do it this way: >> >> some_var = bytes(23).replace(b'\x00', b'a') >> >> or this way? >> >> some_var = bytes(b'a' * 23) > > Actually, I would just do it this way: > > some_var = b'a' * 23 > > That's already a bytes object. Passing it into the constructor is redundant. Heh, good point. ~Ethan~ From ori.livneh at gmail.com Tue May 17 18:31:21 2011 From: ori.livneh at gmail.com (Ori L.) Date: Tue, 17 May 2011 15:31:21 -0700 (PDT) Subject: ipython prompt does not appear in windows References: Message-ID: See here for a workaround: https://bugs.launchpad.net/ipython/+bug/290228 First result on Google for the query "ipython emacs windows", BTW. On May 17, 3:00?am, rusi wrote: > If I use ipython under emacs on linux it works (at least basic REPL) > ie I can type an expression and I get a result followed by a prompt > > On windows ipython works at the shell. > Plain python works in emacs as well. > > But inside emacs I dont see a prompt in ipython although I see it in > python. > I have to type an expression and then the prompt appears. > > Any clues? From ian.g.kelly at gmail.com Tue May 17 18:55:55 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 16:55:55 -0600 Subject: python logging In-Reply-To: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> Message-ID: On Tue, May 17, 2011 at 2:55 PM, Fei wrote: > where is default logging file on Mac? I saw lots of app just import > logging, and begins to logging.info(...) etc. ?I'm not sure where to > look at the logging configuration to figure out the log location. There is no default log file. You're seeing that because logging only needs to be configured by the program once, not on a per-module basis. Thus most modules will just do import logging on the assumption that the configuration has already been performed somewhere else. If no logging configuration is done at all, then the logging statements will have no effect. From ian.g.kelly at gmail.com Tue May 17 19:20:12 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 17:20:12 -0600 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: On Tue, May 17, 2011 at 4:26 PM, Xah Lee wrote: > Though, if you think about it, it's not exactly a correct description. > ?Recursive?, or ?recursion?, refers to a particular type of algorithm, > or a implementation using that algorithm. Only when used as programming jargon. In mathematics, "recursive function" does *not* mean "a function implemented using a recursive algorithm". It's just a formal definition of a specific class of mathematical functions. As it turns out, "recursive" also has a non-technical definition, which again has nothing to do with algorithms except in the broadest sense: recursive adj. 1. pertaining to or using a rule or procedure that can be applied repeatedly (from dictionary.com) This definition fits the Unix usage perfectly. From rosuav at gmail.com Tue May 17 19:23:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 May 2011 09:23:40 +1000 Subject: best way to extract sentence from txt file In-Reply-To: References: Message-ID: On Wed, May 18, 2011 at 4:40 AM, Michiel Overtoom wrote: > Until then we have to guess, and my E.S.P. is notoriously bad. Roll d20 and add your ESP skill and your Wisdom modifier. The DC for this test is 20 if you're familiar with D&D, or 25 if you are not. Chris Angelico Dungeon Master From rosuav at gmail.com Tue May 17 19:42:54 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 May 2011 09:42:54 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: On Wed, May 18, 2011 at 8:26 AM, Xah Lee wrote: > ? ? ?Apply changes to this folder only. > ? ? ? ?Apply changes to this folder, subfolders and files. > > Note the second choice. In unix, it would say ?Apply changes to this > folder recursively.? I think this is more about the Windows and Mac philosophy to dumb things down at the expense of verbosity, than about Unix jargon. Archiving and compressing files using Phil Katz's PKZip utility uses the -r option to include all subdirectories; it's documented as "recurse subudirectories", which makes plenty of sense. (There's an equivalent utility from Info-ZIP in a lot of Linux distros, and it has the same option, listed as "recurse into directories".) Can you think of any other single word that clearly describes the action of tracing into all subdirectories? Even if it's not algorithmically accurate, it carries the meaning. The "mind-space" requirement is quite compact; you can ignore the "into subdirectories" part and just think "-r means recurse", whereas the alternative is "-r means files in this directory and all its subdirectories". Chris Angelico From gagsl-py2 at yahoo.com.ar Tue May 17 20:46:45 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 21:46:45 -0300 Subject: FW: help please References: <4DD29FF1.9090506@tysdomain.com> <1305661713.3831.1.camel@localhost.localdomain> Message-ID: En Tue, 17 May 2011 16:48:29 -0300, Albert Hopkins escribi?: > On Tue, 2011-05-17 at 10:18 -0600, Littlefield, Tyler wrote: >> Not to be pedantic or anything, and I may not be able to help >> regardless, but it looks like your space key is fixed, and I don't >> really care to pick through and try to play hangman with your message. > > I actually, at first glance, thought it was spam, ignored it, and was > wondering why people were replying to it :| I can't remember exactly in which release 'perfect English skills' were added to Python runtime requirements, could you please refresh my memory? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue May 17 20:47:06 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 21:47:06 -0300 Subject: cPickle -> invalid signature References: Message-ID: En Tue, 17 May 2011 15:26:53 -0300, Neal Becker escribi?: > Gabriel Genellina wrote: > >> En Tue, 17 May 2011 08:41:41 -0300, Neal Becker >> escribi?: >> >>> What does it mean when cPickle.load says: >>> RuntimeError: invalid signature >>> >>> Is binary format not portable? >> >> Are you sure that's the actual error message? >> I cannot find such message anywhere in the sources. >> The pickle format is quite portable, even cross-version. As a generic >> answer, make sure you open the file in binary mode, both when writing >> and >> reading. >> > > Yes, that's the message. > > Part of what is pickled is a numpy array. I am writing on a 32-bit > linux system > and reading on a 64-bit system. Reading on the 64-bit system is no > problem. > > Maybe the message comes from numpy's unpickling? Maybe, at least 'invalid signature' makes sense in Numpy. In that case, a better place to ask would be a numpy specific list, see http://www.scipy.org/Mailing_Lists -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue May 17 20:47:06 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 21:47:06 -0300 Subject: cPickle -> invalid signature References: Message-ID: En Tue, 17 May 2011 15:26:53 -0300, Neal Becker escribi?: > Gabriel Genellina wrote: > >> En Tue, 17 May 2011 08:41:41 -0300, Neal Becker >> escribi?: >> >>> What does it mean when cPickle.load says: >>> RuntimeError: invalid signature >>> >>> Is binary format not portable? >> >> Are you sure that's the actual error message? >> I cannot find such message anywhere in the sources. >> The pickle format is quite portable, even cross-version. As a generic >> answer, make sure you open the file in binary mode, both when writing >> and >> reading. >> > > Yes, that's the message. > > Part of what is pickled is a numpy array. I am writing on a 32-bit > linux system > and reading on a 64-bit system. Reading on the 64-bit system is no > problem. > > Maybe the message comes from numpy's unpickling? Maybe, at least 'invalid signature' makes sense in Numpy. In that case, a better place to ask would be a numpy specific list, see http://www.scipy.org/Mailing_Lists -- Gabriel Genellina From dmuchap001 at gmail.com Tue May 17 20:50:30 2011 From: dmuchap001 at gmail.com (john kode) Date: Tue, 17 May 2011 17:50:30 -0700 (PDT) Subject: Ed hardy, (tshirt$13, swim strunk$25, jean$30, handbag$34, cap$13, sunglass$12, shoes$25), Nike shoes:$32, Handbag:$35, NFL:$20, jean:$30, air force one shoes, lv, gucci, D&G, bbc, coachUGG boot:$50 Message-ID: Get Nike Shoes at Super Cheap Prices Discount Ed hardy tshirt (www.dmuch.com) Discount Ed hardy swimming suit (www.dmuch.com) Discount Ed hardy jean (www.dmuch.com) Discount Ed hardy shoes (www.dmuch.com) Discount Ed hardy handbag (www.dmuch.com) Discount Ed hardy other porduct (www.dmuch.com) Discount Nike air jordans (www.dmuch.com) Discount Nike Air Max 90 Sneakers (www.dmuch.com) Discount Nike Air Max 91 Supplier (www.dmuch.com) Discount Nike Air Max 95 Shoes Supplier (www.dmuch.com) Discount Nike Air Max 97 Trainers (www.dmuch.com) Discount Nike Air Max 2003 Wholesale (www.dmuch.com) Discount Nike Air Max 2004 Shoes Wholesale (www.dmuch.com) Discount Nike Air Max 2005 Shop (www.dmuch.com) Discount Nike Air Max 2006 Shoes Shop (www.dmuch.com) Discount Nike Air Max 360 Catalogs (www.dmuch.com) Discount Nike Air Max Ltd Shoes Catalogs (www.dmuch.com) Discount Nike Air Max Tn Men's Shoes (www.dmuch.com) Discount Nike Air Max Tn 2 Women's Shoes (www.dmuch.com) Discount Nike Air Max Tn 3 Customize (www.dmuch.com) Discount Nike Air Max Tn 4 Shoes Customize ( www.dmuch.com) Discount Nike Air Max Tn 6 Supply (www.dmuch.com) Discount Nike Shox NZ Shoes Supply (www.dmuch.com) Discount Nike Shox OZ Sale (www.dmuch.com) Discount Nike Shox TL Store (www.dmuch.com) Discount Nike Shox TL 2 Shoes Store (www.dmuch.com) Discount Nike Shox TL 3 Distributor (www.dmuch.com) Discount Nike Shox Bmw Shoes Distributor (www.dmuch.com) Discount Nike Shox Elite Shoes Manufacturer (www.dmuch.com) Discount Nike Shox Monster Manufacturer (www.dmuch.com) Discount Nike Shox R4 Running Shoes (www.dmuch.com) Discount Nike Shox R5 Mens Shoes (www.dmuch.com) Discount Nike Shox Ride Womens Shoes (www.dmuch.com) Discount Nike Shox Rival Shoes Wholesaler (www.dmuch.com) Discount Nike Shox Energia Wholesaler (www.dmuch.com) Discount Nike Shox LV Sneaker (www.dmuch.com) Discount Nike Shox Turbo Suppliers (www.dmuch.com) Discount Nike Shox Classic Shoes Suppliers (www.dmuch.com) Discount Nike Shox Dendara Trainer (www.dmuch.com) Discount Nike Air Jordan 1 Seller (www.dmuch.com) Discount Nike Air Jordan 2 Shoes Seller (www.dmuch.com) Discount Nike Air Jordan 3 Collection (www.dmuch.com) Discount Nike Air Jordan 4 Shoes Collection (www.dmuch.com) Discount Nike Air Jordan 5 Chaussure Shoes (www.dmuch.com) Discount Nike Air Jordan 6 Catalog (www.dmuch.com) Discount Nike Air Jordan 7 Shoes Catalog (www.dmuch.com) Discount Nike Air Jordan 8 Customized (www.dmuch.com) Discount Nike Air Jordan 9 Shoes Customized From tyler at tysdomain.com Tue May 17 20:50:53 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Tue, 17 May 2011 18:50:53 -0600 Subject: FW: help please In-Reply-To: References: <4DD29FF1.9090506@tysdomain.com> <1305661713.3831.1.camel@localhost.localdomain> Message-ID: <4DD317ED.1060906@tysdomain.com> >I can't remember exactly in which release 'perfect English skills' were >added to Python runtime requirements, could you please refresh my memory? the one that requires people use the space key and check over their messages before they hit the enter key. Not so bad a request, I don't think. I am using a screen reader--it takes the text and puts it in speech. It uses the space as it's separation between words, as we all do, so wheniseetextlikethis it just jumbles it altogether. The point was to request that the OP try to formulate a good request, or get the space key fixed, both of which would've helped. From rouslank at msn.com Tue May 17 21:03:50 2011 From: rouslank at msn.com (Rouslan Korneychuk) Date: Tue, 17 May 2011 21:03:50 -0400 Subject: basic bytecode to machine code compiler (part 2) Message-ID: I mentioned before that I had a proof of concept to convert Python bytecode to native machine code. It's available at https://github.com/Rouslan/nativecompile Now that I have a substantial number of the bytecode instructions implemented, I thought I would share some benchmark results. The first test performs a quicksort on a list of 100 numbers, 5000 times. The second calculates all the prime numbers up to 10000000. Each test is run three times in a row, first with the interpreter, then with the compiled code. #### SCRIPT ONE #### import time import random import nativecompile bcode = compile(''' def quicksort(array): if len(array) <= 1: return array pindex = len(array)//2 pivot = array[pindex] less = [] greater = [] for i,x in enumerate(array): if i != pindex: (less if x <= pivot else greater).append(x) return quicksort(less) + [pivot] + quicksort(greater) in_ = list(range(100)) random.seed(346097) random.shuffle(in_) t = time.clock() for x in range(5000): out = quicksort(in_) t = time.clock()-t assert out == sorted(in_) print('execution time: {}'.format(round(t,10))) ''','','exec') mcode = nativecompile.compile(bcode) print('byte code') for x in range(3): eval(bcode) print() print('machine code') for x in range(3): mcode() print() #### OUTPUT #### byte code execution time: 1.77 execution time: 1.76 execution time: 1.77 machine code execution time: 1.42 execution time: 1.42 execution time: 1.42 #### SCRIPT TWO #### import time import math import nativecompile bcode = compile(''' def primes_list(upto): nums = [True] * (upto//2-1) for i in range(3,math.floor(math.sqrt(upto))+1,2): if nums[i//2-1]: for j in range(i*3,upto,i*2): nums[j//2-1] = False primes = [] for i,n in enumerate(nums): if n: primes.append((i+1)*2+1) return primes t = time.clock() primes = primes_list(10000000) t = time.clock()-t print(primes[-1]) print('execution time: {}'.format(round(t,10))) ''','','exec') mcode = nativecompile.compile(bcode) print('byte code') for x in range(3): eval(bcode) print() print('machine code') for x in range(3): mcode() print() #### OUTPUT #### byte code 9999991 execution time: 3.47 9999991 execution time: 3.38 9999991 execution time: 3.36 machine code 9999991 execution time: 2.95 9999991 execution time: 2.96 9999991 execution time: 2.95 The results are not terribly impressive, but it's something. Also, although I wasn't intending on doing anything more complicated than getting rid of the interpreter loop, I'm starting to notice little ways the code can be optimized without needing run-time analysis. The most obvious is looping over a range object. I could do away with the iterator and just use a native integer (and have the program fall back to the iterator interface if 'range' didn't refer to the built-in range object after all). From mail2fei at gmail.com Tue May 17 21:09:28 2011 From: mail2fei at gmail.com (Fei) Date: Tue, 17 May 2011 18:09:28 -0700 (PDT) Subject: python logging References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> Message-ID: <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> On May 17, 6:55?pm, Ian Kelly wrote: > On Tue, May 17, 2011 at 2:55 PM, Fei wrote: > > where is default logging file on Mac? I saw lots of app just import > > logging, and begins to logging.info(...) etc. ?I'm not sure where to > > look at the logging configuration to figure out the log location. > > There is no default log file. ?You're seeing that because logging only > needs to be configured by the program once, not on a per-module basis. > ?Thus most modules will just do import logging on the assumption that > the configuration has already been performed somewhere else. > > If no logging configuration is done at all, then the logging > statements will have no effect. Thanks Ian. From steveo at syslang.net Tue May 17 21:16:46 2011 From: steveo at syslang.net (Steven W. Orr) Date: Tue, 17 May 2011 21:16:46 -0400 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: <4DD31DFE.9030707@syslang.net> On 5/17/2011 6:26 PM, Xah Lee wrote: > might be of interest. > > ?English Idiom in Unix: Directory Recursively? > http://xahlee.org/comp/idiom_directory_recursively.html The answer is from compute science 101. From any standard data structures course, you learn the algorithm for how to walk a tree. To make it simple, the example is to use a binary tree which means that any non-leaf node of a tree may only have two child nodes, which are designated as Left and Right. There are only three things that are possible: Visit, Go Left, or Go Right. This means that a tree traversal program can only be written three ways: A PreOrder Traversal will Visit, Go Left, Go Right. An InOrder Traversal will Go Left, Visit, Go Right. A PostOrder Traversal will Go Left, Go Right, Visit. So, the Visit function is the function that does whatever you want to have happen at that node. Selection of whether you want to do things like copy, print or delete are designated by what kind of traversal you perform. And, since the Traversal function calls itself, it is, by definition, recursive. QED. -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From tjreedy at udel.edu Tue May 17 21:33:55 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 May 2011 21:33:55 -0400 Subject: pyjamas 0.8alpha1 release In-Reply-To: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> References: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> Message-ID: On 5/17/2011 12:07 PM, lkcl wrote: > On May 4, 7:37 pm, Terry Reedy wrote: >> On 5/4/2011 10:06 AM, Luke Kenneth Casson Leighton wrote: >>> pyjamasis a suite of projects, including a python-to-javascript >>> compiler >> As you well know, there is no such thing as 'python' when it comes to >> compiling actual code. So please specify both in announcements here and >> on the project homepagehttp://sourceforge.net/projects/pyjamas/ >> which versions are supported. > [no response] I would still like to know. Do you fully support 2.7? It has many of the same changes that are in 3.1 and even 3.2 so I can imagine it would be difficult. >> If you do not yet support 3.x, I request and recommend that you do so, > > with the situation as it is, there is not a snowball in hell's chance > that's going to happen. allow me to explain. Thank you for the explanation. You are right that I probably underestimated the work, though you have or will do some of what is needed to fully support 2.7. ... > otherwise please - really: just saying "give me support for python > 3.x or else" is ... And I did not say that. I first learned Python with 1.3 and could again write 2.x code if motivated. ... > leaving _that_ aside, there happens to be absolutely no really good > compelling reason to support python 3.x in the first place. Depend on who *you* want to target as users. *Your* choice, of course. > "python 3 is the future of python" gimme a break!! Let's discuss that in a couple of years. > [so why is archlinux the only linux distribution that's converted > over to run everything off of python 3.x?] Because being first is their thing. -- Terry Jan Reedy From are.dogue at gmail.com Tue May 17 21:44:41 2011 From: are.dogue at gmail.com (are Dogue) Date: Tue, 17 May 2011 18:44:41 -0700 (PDT) Subject: Finding the local directory of a file in the python path Message-ID: <208b4720-ee3d-4dd1-b4cd-c455af2cde9a@p13g2000yqh.googlegroups.com> Hi there, I have a problem that I can't seem to solve after quite a bit of searching, probably because I can't find the right terms to search for. Basically, here's the situation. Let's say I have a file at ~/foo/bin/ foo.py that imports a script that at ~/bar/bin/bar.py. The imported file needs to load something from '~/bar/bin/data/', but I cannot hard code the full path. Instead, what I need is to have something in bar.py like dir = .... # Not sure what this line should be datadir = dir + '/data/' If I use sys.path[0] or os.getcwd(), then when I import the file from ~/foo/bin/, I get that dir is '~/foo/bin' rather than '~/bar/bin' I hope this explanation makes sense. If you have any insights, I would be most appreciative. Thanks Are From tjreedy at udel.edu Tue May 17 21:52:44 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 May 2011 21:52:44 -0400 Subject: [ann] pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: On 5/17/2011 12:38 PM, harrismh777 wrote: > Terry Reedy wrote: >> Like it or not, Python 3 is the future of Python. It is the Python that >> many Python newcomers learn first, and perhaps ever will. > > Yes, no doubt, and I'm genuine about that... > > ... but there is something else to consider, as I'm sure you are aware. > At some point Python is going to have to standardize in order to > survive. And by survive I'm not talking about the Python 'community,' as > much as I'm talking about the acceptance and wide-spread use of Python > by people who just want to get work done and solve problems. > > If there is another major jump like 2.x --> 3.x in the future, There can't be, in that the essence of the jump was elimination of original flaws in 1.0 or 1.1 by elimination of old ways in favor of new ways that are already present in 2.7 or before. > Python will die. I hope you guys are aware of this. No, because I think you are exaggerating. That said, I think core Python is pretty close to 'complete' and I would not mind further syntax freezes like the one for 3.2. > Like it or not, Python 2.x has millions of lines of code running out > there, and they're not going to get morphed into 3.x coding. Except for public libraries, I do not think it should be. > So, 2x is going to be around for many years to come. For as long the existing binaries can run or a long as the code can be compiled. > with an interpreter. Different versions of the source code (.py files) > require a matching 'interpreter,' Most 2.x code is forward compatible with newer 2.x versions. > where-as in other languages a new > compiler version does not require recompiling source, but if source is > recompiled everything still works... Unless the new compiler is for a newer version of the language. I believe C89 compilers had problems with some K&R + extensions C. I do not know if C89 code is completely C99 compatible. I know the reverse is not true, CPython is still C89 code since that apparently still makes it available on more machines. -- Terry Jan Reedy From are.dogue at gmail.com Tue May 17 21:53:11 2011 From: are.dogue at gmail.com (are Dogue) Date: Tue, 17 May 2011 18:53:11 -0700 (PDT) Subject: Finding the local directory of a file in the python path References: <208b4720-ee3d-4dd1-b4cd-c455af2cde9a@p13g2000yqh.googlegroups.com> Message-ID: Nevermind... os.path.dirname (__file__) On May 17, 9:44?pm, are Dogue wrote: > Hi there, > > I have a problem that I can't seem to solve after quite a bit of > searching, probably because I can't find the right terms to search > for. > > Basically, here's the situation. Let's say I have a file at ~/foo/bin/ > foo.py that imports a script that at ~/bar/bin/bar.py. The imported > file needs to load something from '~/bar/bin/data/', but I cannot hard > code the full path. Instead, what I need is to have something in > bar.py like > > dir = .... # Not sure what this line should be > datadir = dir + '/data/' > > If I use sys.path[0] or os.getcwd(), then when I import the file from > ~/foo/bin/, I get that dir is '~/foo/bin' rather than '~/bar/bin' > > I hope this explanation makes sense. If you have any insights, I would > be most appreciative. > > Thanks > Are From tjreedy at udel.edu Tue May 17 22:10:08 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 May 2011 22:10:08 -0400 Subject: in search of graceful co-routines In-Reply-To: <4DD2AA99.3010508@simplistix.co.uk> References: <4DD2AA99.3010508@simplistix.co.uk> Message-ID: On 5/17/2011 1:04 PM, Chris Withers wrote: > Hi All, > > I'm looking for a graceful pattern for the situation where I have a > provider of a sequence, the consumer of a sequence and code to moderate > the two, and where I'd like to consumer to be able to signal to the > provider that it hasn't succeeded in processing one element in the queue. > > So, I'd want the controlling code to look a lot like: > > for item in provider: > try: > consumer.handleItem(self) > except: > provider.failed(item) > > Now, since the sequence is long, and comes from a file, I wanted the > provider to be an iterator, so it occurred to me I could try and use the > new 2-way generator communication to solve the "communicate back with > the provider", with something like: > > for item in provider: > try: > consumer.handleItem(self) > except: > provider.send('fail') > else: > provider.send('succeed') > > ..but of course, this won't work, as 'send' causes the provider > iteration to continue and then returns a value itself. That feels weird > and wrong to me, but I guess my use case might not be what was intended > for the send method. > > Anyway, I wonder how other people would write this? > (I'm particularly interested in a sane way to use the two way > communication that PEP 342 introduced) By default, Python iterators operate in pull mode -- consumers request a new item when they want one. I believe .send was mostly intended to reverse that, to operate in push mode where producers .send() a item to a consumer when they are ready to. That is certainly true of examples I have seen. Using .send for feedback to a provider is trickier, as the two other posts have shown. Another option is to write an iterator class instead of generator function. You can then give the provider a message receive method (.send or whatever) that is decoupled from the send-next method. Your example above then *would* work, as 'send' would not cause anything in the provider except what you want it to cause. Standard generator functions abbreviate standard iterator classes. When one moves beyond standard iterator behavior, the equivalence tends to break down. -- Terry Jan Reedy From tjreedy at udel.edu Tue May 17 22:28:08 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 May 2011 22:28:08 -0400 Subject: Python 3.x and bytes In-Reply-To: <4DD2CEE0.4080403@mrabarnett.plus.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2CEE0.4080403@mrabarnett.plus.com> Message-ID: On 5/17/2011 3:39 PM, MRAB wrote: > On 17/05/2011 19:47, Ethan Furman wrote: >> In Python 3 one can say >> >> --> huh = bytes(5) > BTW, help(bytes) doesn't seem to mention it! I believe I mentioned that on some tracker issue. -- Terry Jan Reedy From tjreedy at udel.edu Tue May 17 22:30:45 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 May 2011 22:30:45 -0400 Subject: Python 3.x and bytes In-Reply-To: <4DD2E828.9000502@aim.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D175.30506@aim.com> <4DD2E0C8.2090101@stoneleaf.us> <4DD2E828.9000502@aim.com> Message-ID: On 5/17/2011 5:27 PM, Corey Richardson wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 05/17/2011 04:55 PM, Ethan Furman wrote: >> Apparently, it's not well documented. If you check PEP 358 >> you'll find it. >> >> ~Ethan~ > > Agreed, it looks like it should be mentioned in bytes.__doc__ about the > single-integer argument. It will be when some volunteer writes a patch. http://bugs.python.org/issue11231 -- Terry Jan Reedy From rosuav at gmail.com Tue May 17 22:50:09 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 May 2011 12:50:09 +1000 Subject: in search of graceful co-routines In-Reply-To: <4DD2AA99.3010508@simplistix.co.uk> References: <4DD2AA99.3010508@simplistix.co.uk> Message-ID: On Wed, May 18, 2011 at 3:04 AM, Chris Withers wrote: > Hi All, > > I'm looking for a graceful pattern for the situation where I have a provider > of a sequence, the consumer of a sequence and code to moderate the two, and > where I'd like to consumer to be able to signal to the provider that it > hasn't succeeded in processing one element in the queue. I wonder would this work nicely if concepted as a couple of threads with a Queue between them? Whether or not you actually use threads per se, or if you just have two separate processing loops and message passing between them, it might be easier to code that way than as generators. Chris Angelico From gwrkarthik at gmail.com Wed May 18 00:22:56 2011 From: gwrkarthik at gmail.com (gowri karthik) Date: Tue, 17 May 2011 21:22:56 -0700 (PDT) Subject: EARN EASY PPC FORM FILLING JOB Message-ID: <1b015bb0-764d-4007-a85b-058822d18d4d@d26g2000prn.googlegroups.com> http://internetjob4u.yolasite.com From rustompmody at gmail.com Wed May 18 00:43:07 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 17 May 2011 21:43:07 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <80ba3b5e-34c1-420a-aade-9c1996d0239e@u26g2000vby.googlegroups.com> Message-ID: <444f4191-b530-4049-b041-09a8ec1a796e@s16g2000prf.googlegroups.com> On May 18, 2:04?am, Wolfram Hinderer wrote: > On 17 Mai, 20:56, geremy condra wrote: > > > > > On Tue, May 17, 2011 at 10:19 AM, Jussi Piitulainen > > > wrote: > > > geremy condra writes: > > > >> or O(1): > > > >> ? = (1 + sqrt(5)) / 2 > > >> def fib(n): > > >> ? ? numerator = (?**n) - (1 - ?)**n > > >> ? ? denominator = sqrt(5) > > >> ? ? return round(numerator/denominator) > > > >> Testing indicates that it's faster somewhere around 7 or so. > > > > And increasingly inaccurate from 71 on. > > > Yup. That's floating point for you. For larger values you could just > > add a linear search at the bottom using the 5f**2 +/- 4 rule, which > > would still be quite fast out to about 10 times that. The decimal > > module gets you a tiny bit further, and after that it's time to just > > use Dijkstra's, like rusi suggested. In any event, I still think this > > formulation is the most fun ;). > > I think you can write it even more funny > > def fib(n): > ? ? return round(((.5 + .5 * 5 ** .5) ** n - ?(.5 - .5 * 5 ** .5) ** > n) * 5 ** -.5) > > ;-) VOW! Tour de Force - Thanks [I am going to trouble some class of students with that :-) ] From my.spamtrap at verizon.net Wed May 18 00:51:59 2011 From: my.spamtrap at verizon.net (Roland Hutchinson) Date: Wed, 18 May 2011 04:51:59 +0000 (UTC) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On Tue, 17 May 2011 15:26:42 -0700, Xah Lee wrote: > might be of interest. > > ?English Idiom in Unix: Directory Recursively? > http://xahlee.org/comp/idiom_directory_recursively.html > > ------------------------------------------ English Idiom in Unix: > Directory Recursively > > Xah Lee, 2011-05-17 > > Today, let's discuss something in the category of lingustics. > > You know how in unix tools, when you want to delete the whole directory > and all sub-directories and files in it, it's referred as ?recursive?? > > For example, when you want to delete the whole dir in emacs, it prompts > this message: ?Recursive delete of xx? (y or n) ?. (Note: to be able to > delete whole dir in emacs in dired, you'll first need to turn it on. > See: emacs dired tutorial.) > > Here's another example. A quote from ?rsync? man page: > > ? > This would recursively transfer all files from the directory ? -r, > --recursive recurse into directories This tells rsync > to copy directories recursively. See also -- > dirs (-d). > ? > > Here's a quote from ?cp?'s man page: > > -R, -r, --recursive > copy directories recursively > > and lots of other tools has a ?-r? option, and they all refer to it as > ?recursive?. > > Though, if you think about it, it's not exactly a correct description. > ?Recursive?, or ?recursion?, refers to a particular type of algorithm, > or a implementation using that algorithm. Obviously, to process all > directory's content does not necessarily mean it must be done by a > recursive algorithm. A iteration can do it as well and it's easy to have > the full behavior and properties in the result as a recursive approach, > such as specifying depth order, level to dive into, etc. (because, dir > is a tree, and recursive algorithm is useful for walking the tree data > structure but is not necessary, because a tree can be laid out flat. Any > path order taken by a recursive approach can be done by just enumerating > the nodes in sequence. In fact, iteration approach can be faster and > simpler in many aspects. (i wrote a article about this some 10 years > ago, see: Trees and Indexes.) Note: this thought about tree and its > nodes as a set of node addresses can be applied to any tree data > structure, such as lisp's nested syntax, XML. See: Programing Language: > Fundamental Problems of Lisp.) > > If you look at Windows or Mac OS X world, i don't think they ever refer > to dealing with whole dir as ?recursive? in user interface. For example, > in Windows Vista, while changing properties of a folder, it has this > message: > > Apply changes to this folder only. > Apply changes to this folder, subfolders and files. > > Note the second choice. In unix, it would say ?Apply changes to this > folder recursively.? > > So, the word ?recursive? used in unixes may be technically incorrect, > but more so, it's just not the right phrase. Because, we want to > communicate whether the whole content of a directory are processed, not > about certain algorithm or how it is implemented. A simple ?all the > dir's branches/contents? or similar would be more apt. > Sorry to have to contradict you, but it really is a textbook example of recursion. Try this psuedo-code on for size: FUNCTION DIR-DELETE (directory) FOR EACH entry IN directory IF entry IS-A-DIRECTORY THEN DIR-DELETE (entry). Well, now that's not just recursion; it's tail recursion. Tail recursion can always be turned into an iteration when it is executed. Reasonably designed compilers are required to do so, in fact--have been for decades now. That doesn't mean that recursion isn't the best way of describing the algorithm. > Recently i was chatting in Second Life with someone (Sleeves). She's > typing, while i'm on voice. In part of our conversation, i said ?you > sounded fine?. Note that it's technically incorrect, because she's > typing, not on voice. So she didn't actually make any ?sound?. But to > say ?you typed fine?, or ?you chatted fine?, won't get the message > across. > > That's idiom. When you interpret a idiom logically, it doesn't make much > sense, but people understand the particular phrase better anyway. I > suspect the ?directory recursively? is also a idiom. The collocation in question is not "directory recursively"; it's "delete ... recursively". Or "Change ... recursively" (etc). Does that help? > It seems so natural > and really gets the point across, without any ill effects. Even if the > implementation actually used a iteration, it doesn't seems to matter. > > So the interesting question is, why this idiom works? Or, how it > developed? It's also not an idiom. It's meaning is completely determined by the meaning of "delete" and the meaning of "recurse", as in "recurse down a tree structure"--which is precisely what the various *nix commands do when their recursive option is invoked. "Recurse _down_ a tree" is an interesting phrase, though, as it implies that, in computing, trees are thought of as growing with their root topmost and their branches underneath -- i.e., upside-down! > I think, among programers (which all unix users are in the 1970s), every > one knows the concept of recursion, and many unix tools on dir probably > are implemented with a recursive algorithm. When you say ?? > recursively?, the point gets across, because we all understand it, even > when we are not actually talking about implementation. The phrase ?? > directory recursively? is short and memorable, while ?? directory and > all its contents? or ?? directory and all its branches? or ?? directory > and all its sub-directories and files? are wordy and unwieldy. > ? > > Idiocy Of Unix Copy Command > Emacs Lisp Suggestion: Function to Copy/Delete a Directory > Recursively > How to rsync, unison, wget, curl > Hunspell Tutorial > Mac OS X Resource Fork and Command Line Tips ImageMagick Tutorial > Making System Calls in Perl and Python Unix And Literary Correlation > The Unix Pestilence > To An Or Not To An > On ?I? versus ?i? (capitalization of first person pronoun) On the > Postposition of Conjunction in Penultimate Position of a > Sequence > What's Passive Voice? What's Aggressive Voice? Why You Should Avoid > The Jargon ?Tail Recursion? Why You should Not Use The Jargon Lisp1 > and Lisp2 Jargons of Info Tech Industry > > Xah I'm writing from alt.usage.english. The non-natural language mavens may have more to add. -- Roland Hutchinson He calls himself "the Garden State's leading violist da gamba," ... comparable to being ruler of an exceptionally small duchy. --Newark (NJ) Star Ledger ( http://tinyurl.com/RolandIsNJ ) From pjb at informatimago.com Wed May 18 01:19:08 2011 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Wed, 18 May 2011 07:19:08 +0200 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Roland Hutchinson writes: > Sorry to have to contradict you, Don't be sorry. > but it really is a textbook example of > recursion. Try this psuedo-code on for size: > > FUNCTION DIR-DELETE (directory) > FOR EACH entry IN directory > IF entry IS-A-DIRECTORY THEN DIR-DELETE (entry). > > Well, now that's not just recursion; it's tail recursion. It's not tail recursion. If you had indented your code properly, you'd see why it's not: (defun dir-delete (directory) (loop for entry in directory do (if (is-a-directory entry) (dir-delete entry)))) (I put parentheses, so my editor knows what I mean and can do the indentation for me). That's why walking a directory is done with a recursive procedure, instead of an iterative one: it's much simplier. To implement an iterative procedure, you would have to manage a stack yourself, instead of using the implicit stack of the recursive procedure. > Tail recursion can always be turned into an iteration when it is > executed. All recursions can be turned into iterations, before execution. > Reasonably designed compilers are required to do so, in fact--have > been for decades now. That doesn't mean that recursion isn't the > best way of describing the algorithm. -- p__Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From chris at simplistix.co.uk Wed May 18 01:27:15 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 18 May 2011 06:27:15 +0100 Subject: in search of graceful co-routines In-Reply-To: References: <4DD2AA99.3010508@simplistix.co.uk> Message-ID: <4DD358B3.2060308@simplistix.co.uk> On 17/05/2011 18:26, Ian Kelly wrote: > You can use send the way you're wanting to. It will look something like this: > > def provider(): > result = None > while True: > if result is None: > if has_more_items(): > next_item = get_next_item() > else: > break > elif result == 'fail': > process_fail() > next_item = None > elif result == 'succeed': > process_succeed() > next_item = None > else: > raise ValueError('unknown result %s' % result) > result = (yield next_item) Yes, but it's this kind of birds nest I'm trying to avoid... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From harrismh777 at charter.net Wed May 18 01:29:04 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 18 May 2011 00:29:04 -0500 Subject: [ann] pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: Terry Reedy wrote: > > No, because I think you are exaggerating. That said, I think core > Python is pretty close to 'complete' and I would not mind further syntax > freezes like the one for 3.2. I am exaggerating only to the extent that someone can imagine folks becoming just annoyed with PEP progress to drop the whole thing... I am exaggerating only to the extent that we define 'it' as language death... if the user base narrows, python's future is held tentative... on the other hand, if the user base grows and campers are happy, then python's future is more stable... I don't think this is an exaggeration... That said, I am encouraged to here your other words, including a favored tendency towards syntax freeze... thanks... kind regards, m harris From ian.g.kelly at gmail.com Wed May 18 01:46:27 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 May 2011 23:46:27 -0600 Subject: in search of graceful co-routines In-Reply-To: <4DD358B3.2060308@simplistix.co.uk> References: <4DD2AA99.3010508@simplistix.co.uk> <4DD358B3.2060308@simplistix.co.uk> Message-ID: On Tue, May 17, 2011 at 11:27 PM, Chris Withers wrote: > Yes, but it's this kind of birds nest I'm trying to avoid... I was actually kind of hoping you might see it that way. That's about as simple as you're going to get using a generator for this, though. I'll second Terry's suggestion on this: forget using a generator for the provider, and instead create an iterator class with regular methods to decouple the push logic from the pull logic. I think you'll be glad that you did. Cheers, Ian From wuwei23 at gmail.com Wed May 18 01:54:43 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 May 2011 22:54:43 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: Message-ID: harrismh777 wrote: > If there is another major jump like ?2.x --> 3.x ?in the future, Python > will die. I hope you guys are aware of this. The user base might accept > this thing once, but they're not going do it again... The differences between major version releases of Python are far, far less than those of PHP's _minor_ releases. Hasn't seemed to have harmed its uptake at all. From chris at simplistix.co.uk Wed May 18 02:00:20 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 18 May 2011 07:00:20 +0100 Subject: in search of graceful co-routines In-Reply-To: References: <4DD2AA99.3010508@simplistix.co.uk> Message-ID: <4DD36074.3000505@simplistix.co.uk> On 18/05/2011 03:10, Terry Reedy wrote: > By default, Python iterators operate in pull mode -- consumers request a > new item when they want one. I believe .send was mostly intended to > reverse that, to operate in push mode where producers .send() a item to > a consumer when they are ready to. That is certainly true of examples I > have seen. My first exposure was with the @inlineCallbacks decorator in twisted, which does use it both ways... > Using .send for feedback to a provider is trickier, as the two other > posts have shown. The closest I've found to something graceful is: def mygenerator(*args): for arg in args: print "yielding:",arg result = yield arg print "returned:",result if result is not None: yield None provider = mygenerator(1,2,3) for arg in provider: print "got:",arg if arg%2: provider.send('hello') However, if you do g.send(None), you still get a result back, which feels a bit weird... It's pretty disappointing that neither the send nor throw methods added as part of PEP342 were provided with a parameter or variant that did "send an item but don't advance the generator". > Another option is to write an iterator class instead > of generator function. You can then give the provider a message receive > method (.send or whatever) that is decoupled from the send-next method. Yes, that's an option I'd considered, however, with a provider class as follows: class Provider: def __init__(self,*args): self.args = args self.current = 0 def next(self): try: val = self.args[self.current] except: raise StopIteration() self.current += 1 print "yielding:",val return val def send(self,value): print "returned:",value def __iter__(self): return self provider = Provider(1,2,3) for arg in provider: print "got:",arg if arg%2: provider.send('hello') ...but that's a lot more code, and allows one of my anti-use cases to happen: provider = Provider(1,2,3) provider.send("don't want this to be possible") The generator implementation deals with the above specific case: File "test.py", line 12, in provider.send('hello') TypeError: can't send non-None value to a just-started generator ...which is, in itself, a little weird, given that it doesn't protect against: provider = Provider(1,2,3) val = provider.next() provider.send("don't want this to be possible") provider.send("don't want this to be possible") cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rustompmody at gmail.com Wed May 18 02:06:44 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 17 May 2011 23:06:44 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> On May 18, 9:51?am, Roland Hutchinson wrote: > Sorry to have to contradict you, but it really is a textbook example of > recursion. ?Try this psuedo-code on for size: ? Well and so far this thread is a textbook example of myths and misconceptions regarding recursion :D 1. 'Recursive' is a meaningful adjective for algorithms only and not data structures 2. Recursion is inefficient which is a corollary to 3. Recursion is different from (more general, less efficient) iteration 4. Recursion in 'recursion theory' aka 'computability theory' is somehow different from recursion in programming. Let me start with 1. The Haskell (pseudocode) defn for lists is: data List(t) = [] | (:) t List(t) In words, a list over type t is either empty or is made byt taking a (smaller) list and consing (:) and element onto it It is only given this defn that al the list functions which are (in the sense that most programmers understand) recursive. For example: len [] = 0 len (x:xs) = 1 + len xs Note that the definition of List is primary and the recursive functions on this definition are secondary to this definition. What happens in languages more and more far from the 'functional purity' of Haskell? Much the same except that implementation details muddy the waters. eg in C the defn for list (of an elsewhere specified type t) runs thus struct node { t elem; struct node *next; } To make the recursion more explicit, introduce the typedef: typedef struct node *nodeptr; struct node { t elem; nodeptr next; }; And we see clearly a mutual recursion in this data type: node contains nodeptr nodeptr points to node So one could say that the C defn is more recursive than the Haskell one in the sense that double recursion is 'more recursion' than single. I could continue down 2,3,4 but really it may be worthwhile if the arguers first read the wikipedia disambiguation pages on recursion... From techtonik at gmail.com Wed May 18 02:07:19 2011 From: techtonik at gmail.com (anatoly techtonik) Date: Wed, 18 May 2011 09:07:19 +0300 Subject: [Python-Dev] [RELEASED] Python 3.2.1 rc 1 In-Reply-To: <4DD2C37D.7000008@python.org> References: <4DD2C37D.7000008@python.org> Message-ID: That's great, but where is the list if changes? -- anatoly t. On Tue, May 17, 2011 at 9:50 PM, Georg Brandl wrote: > On behalf of the Python development team, I am pleased to announce the > first release candidate of Python 3.2.1. > > Python 3.2.1 will the first bugfix release for Python 3.2, fixing over 120 > bugs and regressions in Python 3.2. > > For an extensive list of changes and features in the 3.2 line, see > > ? ?http://docs.python.org/3.2/whatsnew/3.2.html > > To download Python 3.2.1 visit: > > ? ?http://www.python.org/download/releases/3.2.1/ > > This is a testing release: Please consider trying Python 3.2.1 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) > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: http://mail.python.org/mailman/options/python-dev/techtonik%40gmail.com > From tyler at tysdomain.com Wed May 18 02:19:33 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Wed, 18 May 2011 00:19:33 -0600 Subject: [Python-Dev] [RELEASED] Python 3.2.1 rc 1 In-Reply-To: References: <4DD2C37D.7000008@python.org> Message-ID: <4DD364F5.4020708@tysdomain.com> >For an extensive list of changes and features in the 3.2 line, see >http://docs.python.org/3.2/whatsnew/3.2.html Might I presume that clicking the link would show the required changes? From tar at sevak.isi.edu Wed May 18 02:42:20 2011 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 17 May 2011 23:42:20 -0700 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: "Pascal J. Bourguignon" writes: > Roland Hutchinson writes: > > Tail recursion can always be turned into an iteration when it is > > executed. > > All recursions can be turned into iterations, before execution. True, but only by simulating the call stack in the iterative code. To my mind that isn't really an iterative algorithm anymore if it ends up simulating the call stack. Tree walks are the canonical example of what can't be done in an iterative fashion without the addition of an explicitly managed stack -- Thomas A. Russ, USC/Information Sciences Institute From harrishill at gmx.com Wed May 18 02:50:09 2011 From: harrishill at gmx.com (Harrison Hill) Date: Tue, 17 May 2011 23:50:09 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> Message-ID: <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> On May 18, 7:06?am, rusi wrote: > On May 18, 9:51?am, Roland Hutchinson wrote: > > > Sorry to have to contradict you, but it really is a textbook example of > > recursion. ?Try this psuedo-code on for size: ? > > Well and so far this thread is a textbook example of myths and > misconceptions regarding recursion :D > > 1. 'Recursive' is a meaningful adjective for algorithms only and not > data structures > > 2. Recursion is inefficient > > which is a corollary to > > 3. Recursion is different from (more general, less efficient) > iteration > > 4. Recursion in 'recursion theory' aka 'computability theory' is > somehow different from recursion in programming. > > Let me start with 1. > > The Haskell (pseudocode) defn for lists is: > ? ?data List(t) = [] ? ?| ? ?(:) t List(t) > > In words, a list over type t is either empty or is made byt taking a > (smaller) list and consing (:) and element onto it > > It is only given this defn that al the list functions which are (in > the sense that > most programmers understand) recursive. For example: > > len [] = 0 > len (x:xs) = 1 + len xs > > Note that the definition of List is primary and the recursive > functions on this definition are secondary to this definition. > > What happens in languages more and more far from the 'functional > purity' of Haskell? > Much the same except that implementation details muddy the waters. > > eg in C the defn for list (of an elsewhere specified type t) runs thus > > struct node { > ? t elem; > ? struct node *next; > > } > > To make the recursion more explicit, introduce the typedef: > > typedef struct node *nodeptr; > > struct node { > ? t elem; > ? nodeptr next; > > }; > > And we see clearly a mutual recursion in this data type: > node contains nodeptr > nodeptr points to node > > So one could say that the C defn is more recursive than the Haskell > one in the sense that double recursion is 'more recursion' than > single. > > I could continue down 2,3,4 but really it may be worthwhile if the > arguers first read the wikipedia disambiguation pages on recursion... No need - I have the Dictionary definition of recursion here: Recursion: (N). See recursion. From trisha4u4u at gmail.com Wed May 18 02:52:34 2011 From: trisha4u4u at gmail.com (Elisha trisha4uuu.blogspot.com) Date: Tue, 17 May 2011 23:52:34 -0700 (PDT) Subject: Actresses mumaith khan old movies updated wallpapers Message-ID: <62a94dbe-8c73-4b03-9b14-926fac913160@x38g2000pri.googlegroups.com> http://trisha4uuu.blogspot.com/2011/01/mumaith-khan-wall-papers.html mumaith khan wallpapers and photos and pictures watch and enjoy Mumaith Khan Includes mumaith khan photos, mumaith khan gossip, mumaith khan biography, mumaith khan wallpapers, mumaith khan filmography, mumaith khan videos, mumaith khan pictures. Mumaith khan facebook mumaith khan - telugupedia collaboratively authored wiki about telugu, telugu people, ugadi telugu greetings 2011, telugu films news, telugu newspapers, eenaud newspaper. Mumaith khan mumait khan hot sexy actress profile biography mumaith khan - description: mumaith khan is an indian film actress known for her item numbers she has acted in movies in hindi, telugu, tamil and kannada languages. Mumaith khan facebook mumaith khan is on facebook join facebook to connect with mumaith khan and others you may know facebook gives people the power to share and makes the world more open. Mumaith khan - telugupedia download telugu calendar 2011, ugadi hot and news mumaith khan mumaith khan wallpapers mumaith khan pictures mumaith khan photos mumaith khan hot pics.Mumaith khan mumaith khan wallpapers mumaith khan pictures mumaith khan mumait khan hot sexy actress profile biography movies psyphil celebrity. Mumaith khan mumaith khan an indian film actress who is very popular by her glamour songs she has acted in nearly 15 movies in hindi, telugu, tamil and kannada languages. Mumaith khan - ask jeeves encyclopedia why mumaith khan should be called as cameo girl as she has done almost all her movies for just item dances her dance in pokkiri got attention and no longer far she grew. Mumaith khan sexy photo tamil actress photos tamil movies mumaith khan is an indian film actress known for her item numbers she has acted in movies in hindi, telugu, tamil and kannada languages mumaith khan is 39 years old. http://trisha4uuu.blogspot.com/2011/01/mumaith-khan-wall-papers.html From ian.g.kelly at gmail.com Wed May 18 02:58:00 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 00:58:00 -0600 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> Message-ID: On Wed, May 18, 2011 at 12:06 AM, rusi wrote: > 4. Recursion in 'recursion theory' aka 'computability theory' is > somehow different from recursion in programming. Um, it is. Consider the simple function (lambda x, y: x + y). Mathematically, this function is recursive. Algorithmically, it is not. Do you disagree? From sdouche at gmail.com Wed May 18 03:05:25 2011 From: sdouche at gmail.com (Sebastien Douche) Date: Wed, 18 May 2011 09:05:25 +0200 Subject: Python 2.7 Debian 6.0. Squeeze In-Reply-To: References: Message-ID: On Thu, May 12, 2011 at 17:27, Jorge Romero wrote: > I tried Googling about Python 2.7 on Debian Squeeze, but did not find > anything but discussions -.-. Anyone out there that can point me some > helpful material or anyone who had luck running 2.7 on Debian? I use pythonbrew : http://pypi.python.org/pypi/pythonbrew -- Sebastien Douche Twitter: @sdouche (agile, lean, python, git, open source) From rustompmody at gmail.com Wed May 18 03:10:51 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 00:10:51 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> Message-ID: <436ff55b-f61d-46a8-b5ea-f29d73190aba@s41g2000prb.googlegroups.com> On May 18, 11:58?am, Ian Kelly wrote: > On Wed, May 18, 2011 at 12:06 AM, rusi wrote: > > 4. Recursion in 'recursion theory' aka 'computability theory' is > > somehow different from recursion in programming. > > Um, it is. ?Consider the simple function (lambda x, y: x + y). > Mathematically, this function is recursive. ?Algorithmically, it is > not. ?Do you disagree? See the definition of primitive recursion eg. http://en.wikipedia.org/wiki/Primitive_recursive_function#Definition (2 of the second set of "more complex" definitions) from where the name 'primitive recursion' is presumably derived) And for the more general (wider) class of 'recursive' functions (in the math sense aka computable functions) see a little below: http://en.wikipedia.org/wiki/Primitive_recursive_function#Relationship_to_recursive_functions Of course I grant that the adjective 'recursive' is used differently in computability and in programming but the roots are not all that different. If I remember right (I may be misremembering) Hofstader, referring to the invention of 'recursive function' by Godel, says something to the effect that Godel was inventing lisp 30 years before lisp... From rustompmody at gmail.com Wed May 18 03:16:06 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 00:16:06 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: <814f4883-ae12-4444-bb32-e239d3837585@35g2000prp.googlegroups.com> On May 18, 11:50?am, Harrison Hill wrote: > Rusi wrote > > I could continue down 2,3,4 but really it may be worthwhile if the > > arguers first read the wikipedia disambiguation pages on recursion... > > No need - I have the Dictionary definition of recursion here: > > Recursion: (N). See recursion. Ha! Ha! Worth also looking at the talk page of the recursive disambiguation page: http://en.wikipedia.org/wiki/Talk:Recursive From hg at schaathun.net Wed May 18 03:36:37 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 08:36:37 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> Message-ID: <5h9ca8-ekq.ln1@svn.schaathun.net> On Mon, 16 May 2011 23:42:40 +0100, Rhodri James wrote: : ...which is, of course, not exactly secure either. A sufficiently : determined hacker won't have much trouble disassembling a shared library : even if you do strip out all the debug information. By chance I'm having : to do something closely related to this at work just at the moment; it's : hard, but far from impossible. But then, nothing is secure in any absolute sense. The best you can do with all your security efforts is to manage risk. Since obfuscation increases the cost of mounting an attack, it also reduces risk, and thereby provides some level of security. Obviously, if your threat sources are dedicated hackers or maybe MI5, there is no point bothering with obfuscation, but if your threat source is script kiddies, then it might be quite effective. -- :-- Hans Georg From rustompmody at gmail.com Wed May 18 03:41:12 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 00:41:12 -0700 (PDT) Subject: Multiple python environments (was Python 2.7 Debian 6.0. Squeeze) References: Message-ID: On May 18, 12:05?pm, Sebastien Douche wrote: > On Thu, May 12, 2011 at 17:27, Jorge Romero wrote: > > I tried Googling about Python 2.7 on Debian Squeeze, but did not find > > anything but discussions -.-. Anyone out there that can point me some > > helpful material or anyone who had luck running 2.7 on Debian? > > I use pythonbrew :http://pypi.python.org/pypi/pythonbrew Interesting. Is this an alternative to virtualenv? My overall impression of this area is that there are a zillion alternatives (Well ok exaggeration -- more alternatives than needed) And all of them fail on some essential aspects. Yesterday I was trying to setup python on a client site and easy_install kept giving errors. Not easy_install printing errors but python printing backtraces. After repeatedly trying it a few times the errors disappeared. God alone knows... (or maybe Heisenberg...) From rustompmody at gmail.com Wed May 18 04:00:26 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 01:00:26 -0700 (PDT) Subject: ipython prompt does not appear in windows References: Message-ID: On May 18, 3:31?am, "Ori L." wrote: > See here for a workaround:https://bugs.launchpad.net/ipython/+bug/290228 > > First result on Google for the query "ipython emacs windows", BTW. Thanks -- I did find that before asking. That link starts by recommending a small change (add -i flag) to ipython.bat I only find an ipython.exe (in C:\Python27|Scripts ) From hg at schaathun.net Wed May 18 04:12:05 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 09:12:05 +0100 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On Tue, 17 May 2011 15:26:42 -0700 (PDT), Xah Lee wrote: : If you look at Windows or Mac OS X world, i don't think they ever : refer to dealing with whole dir as ?recursive? in user interface. That's purely due to a difference in the level of abstraction. Mac OS introduced its own vocabulary, of folders, where Unix and DOS talked about directories. A folder is a visual element on the screen; exactly modelling a paper folder. It goes without saying that if you bin a folder, the contents goes with it. Anything else would break the model and abstraction. On Unix, the directory is just a file, listing other files by name and disk location. Then it is perfectly natural (although very rarely smart) to delete a directory without any concequences to the contents. The data structure is clearly recursive; a file is either an ordinary file or a directory, and a directory is a list of files. An operation traversing the recursive data structure is recursive regardless of how the algorithm is specified or implemented. A large, although diminishing, fraction of Unix (excluding Mac OS) users are likely to be familiar with the recursive structure of the file system. Now Mac OS X has maintained the folder concept of older mac generations, and Windows has cloned it. They do not want the user to understand recursive data structures, and therefore, naturally, avoid the word. -- :-- Hans Georg From espen at vestre.net Wed May 18 04:20:15 2011 From: espen at vestre.net (Espen Vestre) Date: Wed, 18 May 2011 10:20:15 +0200 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: Hans Georg Schaathun writes: > On Unix, the directory is just a file, listing other files by name > and disk location. Then it is perfectly natural (although very > rarely smart) to delete a directory without any concequences to the > contents. Ironically, the only unix I know of where this makes a lot of sense is Mac OS X (where multiple hard links to a single directory is utilised by TimeMachine to minimise the size of incremental backup trees) :-) -- (espen) From hg at schaathun.net Wed May 18 04:26:27 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 09:26:27 +0100 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: ["Followup-To:" header set to comp.lang.python.] On 17 May 2011 23:42:20 -0700, Thomas A. Russ wrote: : Tree walks are the canonical example of what can't be done in an : iterative fashion without the addition of an explicitly managed stack Of course you can do it. It isn't nice, but it is possible. I assume that you refer to depth first walks, as breadth first is more easily described by iteration on a queue in the first place. Depth first can be achieved by looping over the nodes, with a state keeping references to the current and the previous node considered. By comparing the previous node (pointer or ID) to the current node's parent and children one will know wherefrom the current node was entered, and can choose the next child in the list as the next node, or the parent if all children have been visited. A visit action may be added in any or all times the node is visited. This node requires no stack. The only state space is constant, regardless of the size of the tree, requiring just the two pointers to previous and current. -- :-- Hans Georg From stefan_ml at behnel.de Wed May 18 04:30:26 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 18 May 2011 10:30:26 +0200 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD1C9D5.4070206@gmail.com> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD1C9D5.4070206@gmail.com> Message-ID: Andrew Berg, 17.05.2011 03:05: > lxml looks promising, but it doesn't say anywhere whether it'll work on > Python 3 or not Well, it pretty clearly states that on the PyPI page, but I also added it to the project home page now. lxml 2.3 works with any CPython version from 2.3 to 3.2. Stefan From luke.leighton at gmail.com Wed May 18 05:24:45 2011 From: luke.leighton at gmail.com (lkcl) Date: Wed, 18 May 2011 02:24:45 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> Message-ID: On May 18, 2:33?am, Terry Reedy wrote: > On 5/17/2011 12:07 PM, lkcl wrote: > > > On May 4, 7:37 pm, Terry Reedy ?wrote: > >> On 5/4/2011 10:06 AM, Luke Kenneth Casson Leighton wrote: > >>> pyjamasis a suite of projects, including a python-to-javascript > >>> compiler > >> As you well know, there is no such thing as 'python' when it comes to > >> compiling actual code. So please specify both in announcements here and > >> on the project homepagehttp://sourceforge.net/projects/pyjamas/ > >> which versions are supported. > > ?> [no response] > > I would still like to know. Do you fully support 2.7? It has many of the > same changes that are in 3.1 and even 3.2 so I can imagine it would be > difficult. sorry, terry, missed this out. there are two answers: a) at the moment a http://python.org 2.N interpreter is required to actually run the translator. if you use http://python.org 2.5 or 2.6 you do not need to use the "--internal-ast" option. if you use 2.4, 2.7 or above, you will need to use --internal-ast because we're heavily reliant on the internal c-based "compile" module [without the --internal-ast option enabled]. b) the actual pyjs interpreter grammar (AST) was 2.5 but has mostly been updated to 2.6. actual python syntax / features are therefore mostly 2.5, with someone having pointed out that "slice" has different return results it's hard to say exactly which is best to be picked, 2.5 or 2.6. nobody's needed slice until recently, so it's not an issue that's ever come up before. the thing is - it's worth reiterating: you just... really don't need as much python interoperability for user-interfaces when they're split along MVC lines. bear in mind that it's necessary to do that split: it's web browser technology, you can't *actually* execute things like psycopg or mysql in a web browser as javascript! so once you've divided that application into "python that runs the actual user interface" and "python on the other side of the AJAX barrier e.g. a django app" you're left with a far smaller task for the pyjs interpreter to have to tackle. this is why it's been so unnecessary to keep absolutely up-to-date with the full python development that's been going on, yet we still have people developing 10,000+ LOC 2 man-year pyjamas projects. that having been said, there _is_ the requirement to be "python strict" as well as "fast" - mutually exclusive of course. and there is someone working on getting the pyjs compiler and supporting libraries into shape in order to run the entire http://python.org regression test suite. there really are quite a lot of little sub- projects within the pyjamas project. > >> If you do not yet support 3.x, I request and recommend that you do so, > > > with the situation as it is, there is not a snowball in hell's chance > > that's going to happen. allow me to explain. > > Thank you for the explanation. not a problem. > You are right that I probably underestimated the work, yeah... i apologise for the somewhat-evident flabbergasted tone that may have been apparent in what could otherwise be considered to be a project outline / roadmap :) > though you have or will do some of what is > needed to fully support 2.7. weell... see above: it's kiinda unnecessary - it just depends on people's needs. if there are intelligent and willing people (like kees) who just come along and go "yep, that's nice, but it's not good enough for me: i'm going to make it so" then it'll happen. everyone else _not_ willing to put in the effort to make pyjs do what they want will just have to put up with the foibles. so if someone wants to do it, hell i'm not going to stand in the way - anyone who asks i give them commit rights, point them at the DEVELOPER.RULES and let them get on with it. > ... > > > ? otherwise please - really: just saying "give me support for python > > 3.x or else" is ... > > And I did not say that. yeah i know - i'm sorry: it just, with a little bit of "twisting", could be construed as implying that. > > "python 3 is the future of python" gimme a break!! > > Let's discuss that in a couple of years. :) i think... people forget that there are now two mutually- exclusively-incompatible programming languages out there, where the first six letters of the name of the programming language happen to be the same... l. From mikebarnes at bluebottle.com Wed May 18 05:25:38 2011 From: mikebarnes at bluebottle.com (Mike Barnes) Date: Wed, 18 May 2011 10:25:38 +0100 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: Xah Lee : >For example, when you want to delete the whole dir in emacs, it >prompts this message: ?Recursive delete of xx? (y or n) ?. AFAICS what emacs calls "recursive delete" is what the ordinary person would simply call "delete". Presumably the non-recursive delete is called simply "delete" but is actually something more complicated than delete, and you're supposed to know what that is. Also (I'm speculating) a recursive delete means carrying out the (ordinary, non-recursive) delete process on sub-directories, recursively. The result of which is, put simply, to delete the directory. I find all this somewhat arcane. Questioning the precise suitability of the word "recursive" seems like a quibble. -- Mike Barnes Cheshire, England From luke.leighton at gmail.com Wed May 18 05:39:24 2011 From: luke.leighton at gmail.com (lkcl) Date: Wed, 18 May 2011 02:39:24 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: Message-ID: On May 18, 6:29?am, harrismh777 wrote: > Terry Reedy wrote: > > > No, because I think you are exaggerating. ?That said, I think core > > Python is pretty close to 'complete' and I would not mind further syntax > > freezes like the one for 3.2. > > I am exaggerating only to the extent that someone can imagine folks > becoming just annoyed with PEP progress to drop the whole thing... I am > exaggerating only to the extent that we define 'it' as language death... > if the user base narrows, python's future is held tentative... on the > other hand, if the user base grows and campers are happy, then python's > future is more stable... I don't think this is an exaggeration... one thing that people are not aware of - because it normally simply does not make its way out into the public world: you're forgetting those people who "just use" python. they don't get onto public mailing lists, they don't develop free software projects. i've mentioned this story before, but it's worth repeating in this context. i worked in a military environment (NC3A) back in 2006-2007. the version of python that they were using was http://python two... point... ONE. six years after its release. why??? well, it went something like this. someone got the idea that doing a portal would be good. so they looked around, and found Zope. so, they evaluated the latest version somewhere around ooo april to june of 2001. ok they _started_ evaluating it. so, some four months later, after doing some coding examples, we're now up to august 2001, a decision has to be made by the internal client. they say "yep, go for it", but that took another four months (dec 2002). now we do 18 months of software development (july 2003) to produce a base package. now the code now has to be handed over to a team who perform security evaluations. this has to be paid for. another six months go by, and the security accreditation is received (dec 2004). but this was just for the "base" code: now we have deployment and actual product / portal development, and a maintenance cycle of 2 years (2006). now i'm called in to help with that maintenance and development cycle (2007). and throughout this time there is *no way* that they can upgrade from python 2.1, because it would cost another $EUR 10,000 to get the accreditation certificate. it's now 2011. for all i know, some TEN YEARS after python 2.1 was released, they're still using it. you ... _just_ don't normally hear about these kinds of deployments of free software, but it illustrates that a particular version can hang around for a hell of a long time. l. From rustompmody at gmail.com Wed May 18 05:42:42 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 02:42:42 -0700 (PDT) Subject: Multiple python environments (was Python 2.7 Debian 6.0. Squeeze) References: Message-ID: On May 18, 12:41?pm, rusi wrote: > On May 18, 12:05?pm, Sebastien Douche wrote: > > > On Thu, May 12, 2011 at 17:27, Jorge Romero wrote: > > > I tried Googling about Python 2.7 on Debian Squeeze, but did not find > > > anything but discussions -.-. Anyone out there that can point me some > > > helpful material or anyone who had luck running 2.7 on Debian? > > > I use pythonbrew :http://pypi.python.org/pypi/pythonbrew > > Interesting. Is this an alternative to virtualenv? > > My overall impression of this area is that there are a zillion > alternatives > (Well ok exaggeration -- more alternatives than needed) > And all of them fail on some essential aspects. > > Yesterday I was trying to setup python on a client site and > easy_install kept giving errors. Not easy_install printing errors but > python printing backtraces. > > After repeatedly trying it a few times the errors disappeared. > > God alone knows... (or maybe Heisenberg...) pythonbrew does not run on windows [Just recording it here to save others time if/when they reach here] From marduk at letterboxes.org Wed May 18 07:47:28 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 18 May 2011 07:47:28 -0400 Subject: FW: help please In-Reply-To: References: <4DD29FF1.9090506@tysdomain.com> <1305661713.3831.1.camel@localhost.localdomain> Message-ID: <1305719249.29114.6.camel@localhost.localdomain> On Tue, 2011-05-17 at 21:46 -0300, Gabriel Genellina wrote: > En Tue, 17 May 2011 16:48:29 -0300, Albert Hopkins > escribi?: > > On Tue, 2011-05-17 at 10:18 -0600, Littlefield, Tyler wrote: > > >> Not to be pedantic or anything, and I may not be able to help > >> regardless, but it looks like your space key is fixed, and I don't > >> really care to pick through and try to play hangman with your message. > > > > I actually, at first glance, thought it was spam, ignored it, and was > > wondering why people were replying to it :| > > I can't remember exactly in which release 'perfect English skills' were > added to Python runtime requirements, could you please refresh my memory? I can't speak for Tyler (I assume your message was meant for him) but as for myself: I saw a glob of practically unreadable text and simply passed it off as spam, concluding that any well-intentioned, moderately intelligent human being wouldn't have intentionally posted such a monstrosity and actually expected an intelligent response. I'm guessing Tyler's message was to help you so that your messages don't continue to be ignored by people who may otherwise be of assistance. From invalid at peter.pmoylan.org.invalid Wed May 18 08:09:46 2011 From: invalid at peter.pmoylan.org.invalid (Peter Moylan) Date: Wed, 18 May 2011 22:09:46 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: Thomas A. Russ wrote: > "Pascal J. Bourguignon" writes: > >> Roland Hutchinson writes: > >>> Tail recursion can always be turned into an iteration when it is >>> executed. >> All recursions can be turned into iterations, before execution. > > True, but only by simulating the call stack in the iterative code. To > my mind that isn't really an iterative algorithm anymore if it ends up > simulating the call stack. When does a data structure stop being a simulation of a stack? I've often had to turn recursive algorithms into iterative ones, where the solution turned out to be "simulating the call stack" only in a very broad sense; a big stretch of the imagination is needed to see the equivalent of push or pop operations. > Tree walks are the canonical example of what can't be done in an > iterative fashion without the addition of an explicitly managed stack Let me throw in an example where the desired tree walk is neither depth-first or breadth-first. It's to do with the way I display my family tree on my web site; an example may be found at http://www.pmoylan.org/cgi-bin/wft.cmd?D=moylan;P=I004 Most people familiar with algorithm design will, I believe, end up deciding that the appropriate data structure in this case is a queue rather than a stack. ObAUE: In common parlance, the English word "recursion" means pretty much the same as what computing people call "iteration". This might be the first time I have ever found a point of agreement with Xah Lee. -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. From invalid at peter.pmoylan.org.invalid Wed May 18 08:19:16 2011 From: invalid at peter.pmoylan.org.invalid (Peter Moylan) Date: Wed, 18 May 2011 22:19:16 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: Harrison Hill wrote: > On May 18, 7:06 am, rusi wrote: >> I could continue down 2,3,4 but really it may be worthwhile if the >> arguers first read the wikipedia disambiguation pages on recursion... > > No need - I have the Dictionary definition of recursion here: > > Recursion: (N). See recursion. It's interesting to note that the definitions of 'recursive' to be found in Wikipedia and Wiktionary have very little in common with the definitions to be found in the dictionaries covered by Onelook. No wonder experts in different areas have trouble communicating with one another. -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. From smackay at flagstonesoftware.com Wed May 18 08:39:31 2011 From: smackay at flagstonesoftware.com (Stuart MacKay) Date: Wed, 18 May 2011 13:39:31 +0100 Subject: FW: help please In-Reply-To: <1305719249.29114.6.camel@localhost.localdomain> References: <4DD29FF1.9090506@tysdomain.com> <1305661713.3831.1.camel@localhost.localdomain> <1305719249.29114.6.camel@localhost.localdomain> Message-ID: <4DD3BE03.9060204@flagstonesoftware.com> On 18/05/2011 12:47, Albert Hopkins wrote: > On Tue, 2011-05-17 at 21:46 -0300, Gabriel Genellina wrote: >> En Tue, 17 May 2011 16:48:29 -0300, Albert Hopkins >> escribi?: >>> On Tue, 2011-05-17 at 10:18 -0600, Littlefield, Tyler wrote >>>> Not to be pedantic or anything, and I may not be able to help >>>> regardless, but it looks like your space key is fixed, and I don't >>>> really care to pick through and try to play hangman with your message. >>> I actually, at first glance, thought it was spam, ignored it, and was >>> wondering why people were replying to it :| >> I can't remember exactly in which release 'perfect English skills' were >> added to Python runtime requirements, could you please refresh my memory? > I can't speak for Tyler (I assume your message was meant for him) but as > for myself: I saw a glob of practically unreadable text and simply > passed it off as spam, concluding that any well-intentioned, moderately > intelligent human being wouldn't have intentionally posted such a > monstrosity and actually expected an intelligent response. > > I'm guessing Tyler's message was to help you so that your messages don't > continue to be ignored by people who may otherwise be of assistance. > Sure the English wasn't the best but there was enough information in the post to identify the likely source of the problem - with a little help from my favourite search engine - and give the guy/gal some ideas of where to look for a solution. If you were required to answer the question then asking the poster to phrase it better is going to help solve the issue faster but for a mailing list like this simply ignore it. Stuart From rustompmody at gmail.com Wed May 18 09:14:16 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 06:14:16 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> On May 18, 5:09?pm, Peter Moylan wrote: > > ObAUE: In common parlance, the English word "recursion" means pretty > much the same as what computing people call "iteration". ?This might be > the first time I have ever found a point of agreement with Xah Lee. Maybe the common usage mirrors the facts better than the lore that half-baked programmers remain devoted to. Consider first implementations: The implementation of recursion by a typical language (eg gcc for C) maximizes generality at the cost of efficiency The implementation of a very special case -- tail recursion -- in some special languages (most notably scheme) is required to be competitive with the iterative solution. [If I remember right in Chez scheme tail recursion was more efficient than a do (iteration) because a do typically needed assignment and assignment was more expensive than parameter passing] But there is a wide spectrum of cases between the most general case of recursion and tail recursion. Some examples 1 A non-tail recursive function, with a single recursive call, when implemented naively would push the return address. This is unnecessary as only a flag needs to be pushed -- return to internal call point or return to external call point. This itself can be efficiently simulated by storing the recursion depth -- zero => jump out; > 0 => jump to internal call 2. A single function with double recursion -- quicksort is the classic -- can be implemented without recursion or stack. It just needs a set of pending begin-end pairs yet to be sorted. This may look like the stack in another guise but unlike the stack it does not need to store any function call return paraphernalia. 3. Tree recursion (though not the case of the OP) can be solved non- recursively with threading http://en.wikipedia.org/wiki/Threaded_binary_tree and Schorr Waite Deutsch http://www.cs.cornell.edu/courses/cs312/2007fa/lectures/lec21-schorr-waite.pdf In fact the only example I can think of where the full blown generality of recursion cannot be tightened is perhaps recursive descent parsing. So much for implementations. Semantically the while loop while B: statement is equivalent to the recursion: def stateiter(): if B: statement stateiter() From spam at scheingraber.net Wed May 18 09:28:41 2011 From: spam at scheingraber.net (Christoph Scheingraber) Date: Wed, 18 May 2011 13:28:41 +0000 (UTC) Subject: connect SIGINT to custom interrupt handler References: <04cee22d-fc07-4c54-b91b-3f9e4730f095@glegroupsg2000goo.googlegroups.com> Message-ID: On 2011-05-15, Miki Tebeka wrote: > Why not just catch KeyboardInterrupt? Would it be possible to continue my program as nothing had happened in that case (like I did before, setting a flag to tell main() to finish the running data download and quit instead of starting the next data download {it's a for-loop})? I have tried it, but after catching the KeyboardInterrupt I could only continue to the next iteration. From luke.leighton at gmail.com Wed May 18 09:35:14 2011 From: luke.leighton at gmail.com (lkcl) Date: Wed, 18 May 2011 06:35:14 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> Message-ID: On May 18, 10:24?am, lkcl wrote: > > > ? otherwise please - really: just saying "give me support for python > > > 3.x or else" is ... > > > And I did not say that. > > ?yeah i know - i'm sorry: it just, with a little bit of "twisting", > could be construed as implying that. in case it wasn't clear, i apologise for doing that :) From luke.leighton at gmail.com Wed May 18 09:42:24 2011 From: luke.leighton at gmail.com (lkcl) Date: Wed, 18 May 2011 06:42:24 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: Message-ID: On May 17, 5:38?pm, harrismh777 wrote: > is recompiled everything still works... not so in Python. The fact that > Python is free to morph gleely from PEP to PEP without responsibility or > accountability with the user base is what may kill Python, unless the > Python community gets a grip on this concept. he's got a good point, terry. breaking backwards-compatibility was a completely mad and incomprehensible decision. i don't believe version N of python is going to "die" due to changes - the sheer inertia of hundreds of millions of lines of code and hundreds of thousands of projects will make sure that's not going to happen, but it doesn't help. it doesn't matter what the leading-edge developers behind python _want_ to happen: it took 10+ years for python 1 and 2 to gain traction, and i believe that's the sort of order of magnitude lag-time to expect people world-wide to make decisions [to replace code]. you only have to look at how long it's taking IE6 to die.... :) l. From marduk at letterboxes.org Wed May 18 09:48:13 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 18 May 2011 09:48:13 -0400 Subject: FW: help please In-Reply-To: <4DD3BE03.9060204@flagstonesoftware.com> References: <4DD29FF1.9090506@tysdomain.com> <1305661713.3831.1.camel@localhost.localdomain> <1305719249.29114.6.camel@localhost.localdomain> <4DD3BE03.9060204@flagstonesoftware.com> Message-ID: <1305726494.3259.0.camel@localhost.localdomain> On Wed, 2011-05-18 at 13:39 +0100, Stuart MacKay wrote: > If you were required to answer the question then asking the poster to > phrase it better is going to help solve the issue faster but for a > mailing list like this simply ignore it. Which is what I've done. From calderone.jeanpaul at gmail.com Wed May 18 10:16:40 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Wed, 18 May 2011 07:16:40 -0700 (PDT) Subject: connect SIGINT to custom interrupt handler References: <04cee22d-fc07-4c54-b91b-3f9e4730f095@glegroupsg2000goo.googlegroups.com> Message-ID: <18857efb-05be-42f0-8c62-40be5ec9dd26@gu8g2000vbb.googlegroups.com> On May 18, 9:28?am, Christoph Scheingraber wrote: > On 2011-05-15, Miki Tebeka wrote: > > > Why not just catch KeyboardInterrupt? > > Would it be possible to continue my program as nothing had happened in > that case (like I did before, setting a flag to tell main() to finish the > running data download and quit instead of starting the next data download > {it's a for-loop})? > > I have tried it, but after catching the KeyboardInterrupt I could only > continue to the next iteration. No, since the exception being raised represents a different flow of control through the program, one that is mutually exclusive with the flow of control which would be involved with continuing the processing in the "current" iteration of your loop. Setting SA_RESTART on SIGINT is probably the right thing to do. It's not totally clear to me from the messages in this thread if you managed to get that approach working. The most commonly encountered problem with this approach is that it means that any blocking (eg I/O) operation in progress won't be interrupted and you'll have to wait for it to complete normally. In this case, it sounds like this is the behavior you actually want, though. Jean-Paul From rbotting at csusb.edu Wed May 18 10:27:30 2011 From: rbotting at csusb.edu (RJB) Date: Wed, 18 May 2011 07:27:30 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: 9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com Message-ID: On May 17, 9:36?am, rusi wrote: > On May 17, 8:50?pm, RJB wrote: > > > > > > > I noticed some discussion of recursion..... the trick is to find a > > formula where the arguments are divided, not decremented. > > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > > for a couple of years in C++ but just for fun rewrote it > > in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! > > > def fibo(n): > > ? ? ? ? """A Faster recursive Fibonaci function > > Use a formula from Knuth Vol 1 page 80, section 1.2.8: > > ? ? ? ? ? ?If F[n] is the n'th Fibonaci number then > > ? ? ? ? ? ? ? ? ? ?F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. > > ? First set m = n+1 > > ? ?F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. > > > ? Then put m = n in Knuth's formula, > > ? ? ? ? ? ?F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], > > ? ?and replace F[n+1] by F[n]+F[n-1], > > ? ? ? ? ? ?F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). > > """ > > ? ? ? ? if n<=0: > > ? ? ? ? ? ? ? ? return 0 > > ? ? ? ? elif n<=2: > > ? ? ? ? ? ? ? ? return 1 > > ? ? ? ? elif n%2==0: > > ? ? ? ? ? ? ? ? half=n//2 > > ? ? ? ? ? ? ? ? f1=fibo(half) > > ? ? ? ? ? ? ? ? f2=fibo(half-1) > > ? ? ? ? ? ? ? ? return f1*(f1+2*f2) > > ? ? ? ? else: > > ? ? ? ? ? ? ? ? nearhalf=(n-1)//2 > > ? ? ? ? ? ? ? ? f1=fibo(nearhalf+1) > > ? ? ? ? ? ? ? ? f2=fibo(nearhalf) > > ? ? ? ? ? ? ? ? return f1*f1 + f2*f2 > > > RJB the Lurkerhttp://www.csci.csusb.edu/dick/cs320/lab/10.html > > ------------------------------------------------------------- > Its an interesting problem and you are 75% there. > You see the halving gives you logarithmic behavior and the double > calls give exponential behavior. > > So how to get rid of double calls? ?Its quite simple: Just define your > function in terms of return pairs of adjacent pairs ie (fib(n), fib(n > +1)) for some n rather then a single number fib(n) > > Here's a straightforward linear function: > > def fp(n): ?#fibpair > ? ? if n==1: > ? ? ? ? return (1,1) > ? ? else: > ? ? ? ? a,b = fp(n-1) > ? ? ? ? return (b, a+b) > > def fib(n): > ? ? a,b = fp(n) > ? ? return a > > --------------- > Now use this (pairing) idea with your (halving) identities and you > should get a logarithmic algo. > > [If you cant do it ask again but yes its fun to work out so do > try :-) ] Thank you! Very cool and clear. I hoped that there was something that Python made natural I couldn't see after 50 years in other languages. I'd like to work on combining both approaches. It may take a while... From ian.g.kelly at gmail.com Wed May 18 10:32:29 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 08:32:29 -0600 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <436ff55b-f61d-46a8-b5ea-f29d73190aba@s41g2000prb.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <436ff55b-f61d-46a8-b5ea-f29d73190aba@s41g2000prb.googlegroups.com> Message-ID: On Wed, May 18, 2011 at 1:10 AM, rusi wrote: >> Um, it is. ?Consider the simple function (lambda x, y: x + y). >> Mathematically, this function is recursive. ?Algorithmically, it is >> not. ?Do you disagree? > > See the definition of primitive recursion eg. > > http://en.wikipedia.org/wiki/Primitive_recursive_function#Definition > > (2 of the second set of "more complex" definitions) from where the > name 'primitive recursion' is presumably derived) > > And for the more general (wider) class of 'recursive' functions (in > the math sense aka computable functions) see a little below: > > http://en.wikipedia.org/wiki/Primitive_recursive_function#Relationship_to_recursive_functions I know what primitive recursive and computable functions are, thanks. What you're failing to explain is why you would consider that function to be recursive from a programming standpoint. In programming, when we say a function is recursive, we mean that it is implemented using the technique of recursion, not that it is computable. Since we're throwing around Wikipedia links, see the definition in the first sentence at: http://en.wikipedia.org/wiki/Recursion_%28computer_science%29 In fact, the mathematical definition would not be useful for programming since to us a function is an implementation of an algorithm (I expect Lispers may quibble over this, but it is true even there). Thus, in programming, all functions are computable. > Of course I grant that the adjective 'recursive' is used differently > in computability and in programming but the roots are not all that > different. Not just the adjective 'recursive', but also the noun 'function'. I'm not sure of the exact etymology of 'recursive', although I would bet that the mathematical usage came first and the programming usage is a derivative of it. From dotancohen at gmail.com Wed May 18 10:42:36 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 May 2011 17:42:36 +0300 Subject: obviscating python code for distribution In-Reply-To: <5h9ca8-ekq.ln1@svn.schaathun.net> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 10:36, Hans Georg Schaathun wrote: > But then, nothing is secure in any absolute sense. ?The best you can > do with all your security efforts is to manage risk. ?Since obfuscation > increases the cost of mounting an attack, it also reduces risk, > and thereby provides some level of security. > > Obviously, if your threat sources are dedicated hackers or maybe MI5, > there is no point bothering with obfuscation, but if your threat source > is script kiddies, then it might be quite effective. > The flip side is that the developer will not know about weaknesses until much later in the development, when making changes to the underlying code organization may be difficult or impossible. In this early phase of development, he should actually encourage the script kiddies to "report the bugs". -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From rustompmody at gmail.com Wed May 18 11:15:08 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 08:15:08 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <436ff55b-f61d-46a8-b5ea-f29d73190aba@s41g2000prb.googlegroups.com> Message-ID: <488559dd-b1a4-4b81-8d53-40f0af9773c0@d26g2000prn.googlegroups.com> On May 18, 7:32?pm, Ian Kelly wrote: > On Wed, May 18, 2011 at 1:10 AM, rusi wrote: > >> Um, it is. ?Consider the simple function (lambda x, y: x + y). > >> Mathematically, this function is recursive. ?Algorithmically, it is > >> not. ?Do you disagree? > > > See the definition of primitive recursion eg. > > >http://en.wikipedia.org/wiki/Primitive_recursive_function#Definition > > > (2 of the second set of "more complex" definitions) from where the > > name 'primitive recursion' is presumably derived) > > > And for the more general (wider) class of 'recursive' functions (in > > the math sense aka computable functions) see a little below: > > >http://en.wikipedia.org/wiki/Primitive_recursive_function#Relationshi... > > I know what primitive recursive and computable functions are, thanks. Myself, my memory of things studied badly decades ago may be fuzzy :D ) Anyhow taking those links to be authoritative, what I am saying is: Coming from the computability side, there are 3 related but distinct definitions of recursive: 1. Anything computable is recursive -- general recursive or partial recursive (evidently there is some dispute re these definitions http://mathworld.wolfram.com/RecursiveFunction.html 2. Primitive recursive -- ie any function that is defined using - constant - successor - projection - composition - primitive recursion [This definition is recursive in a bad sense but let that be... The first use of the term is for the set of functions such that... The second is for a specific operation. Comes to the third use: 3. The *operation* of primitive recursion is exactly what programmers call recursion. In other words one specific and characteristic operation is used to give the name to the set being defined. > What you're failing to explain is why you would consider that function > to be recursive from a programming standpoint. ? As for putting + under the format of primitive recursion, it would go something like this (I guess) Matching up that definition Put h is what is being defined ie + (or plus) k = 1 f = id g(y, ic, x) = S(ic) #ignore y and x, ic is internal (recursive) call Gives plus(0, x) = x plus((S y), x) = S(plus(y, x)) From rustompmody at gmail.com Wed May 18 11:23:17 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 18 May 2011 08:23:17 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: 9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com Message-ID: <3ea62d61-cc9f-46ff-84a1-5c2cdfb1af13@18g2000prd.googlegroups.com> On May 18, 7:27?pm, RJB wrote: > Thank you! ?Very cool and clear. ?I > hoped that there was something that Python made natural I couldn't see > after 50 years in other languages. > > I'd like to work on combining both approaches. ?It may take a while... >From the Knuth identity F[n+m] = .. you pulled out two special cases F[2n+1] = .. and F[2n] = .. If you get one more: F[2n -1] = .. you are done From ian.g.kelly at gmail.com Wed May 18 11:43:24 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 09:43:24 -0600 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <488559dd-b1a4-4b81-8d53-40f0af9773c0@d26g2000prn.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <436ff55b-f61d-46a8-b5ea-f29d73190aba@s41g2000prb.googlegroups.com> <488559dd-b1a4-4b81-8d53-40f0af9773c0@d26g2000prn.googlegroups.com> Message-ID: On Wed, May 18, 2011 at 9:15 AM, rusi wrote: >> What you're failing to explain is why you would consider that function >> to be recursive from a programming standpoint. > > As for putting + under the format of primitive recursion, it would go > something like this (I guess) > > Matching up that definition > Put > h is what is being defined ie + (or plus) > k = 1 > f = id > g(y, ic, x) = S(ic) #ignore y and x, ic is internal (recursive) call > > Gives > > plus(0, x) = x > plus((S y), x) = S(plus(y, x)) You're still arguing mathematics. I am not disputing that the addition function is primitive recursive (in fact, I asserted that in my original reply). What I am saying is that this *implementation* of the addition function: def add(x, y): return y if x == 0 else add(x-1, y) + 1 is recursive in the programming sense (i.e. it uses the programming technique of recursion), while this implementation is not: def add(x, y): return x + y From claird271 at gmail.com Wed May 18 11:55:37 2011 From: claird271 at gmail.com (Cameron Laird) Date: Wed, 18 May 2011 08:55:37 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (May 18) Message-ID: QOTW: "When did we come to the idea that people should be able to program in a language without actually learning it? The fact that Python comes so close to that possibility is nothing short of revolutionary. I suppose one day a reasoning android will be able to sit down at the terminal of a star ship computer and ask simple questions while making random hand movements across a screen, but for now I am afraid that programmers still have to learn programming." - D'Arcy J.M. Cain - 2011-05-11 http://permalink.gmane.org/gmane.comp.python.general/690140 Fast way to convert a set into a list: http://groups.google.com/group/comp.lang.python/t/a3c72619c1e867e3/ 'Still time to submit a proposal to PyCon India 2011: http://pycon.blogspot.com/2011/05/pycon-india-2011-call-for-proposals.html How to make sure equal objects are unique: http://groups.google.com/group/comp.lang.python/t/a8889b7a327756dd/ generator.send() explained: http://groups.google.com/group/comp.lang.python/t/953c8f1f8a5f73ed/ "object of different types never compare equal", a documentation bug: http://groups.google.com/group/comp.lang.python/t/6ceb3a40dc263f25/ Ofuscating code: not a good idea http://groups.google.com/group/comp.lang.python/t/f887168ca476618f/ Summer pyGames Registration opens: http://pyfound.blogspot.com/2011/05/summer-pygames-registration-open.html The proper way to handle errors: http://groups.google.com/group/comp.lang.python/t/9c6a47de6bf8b352/ http://groups.google.com/group/comp.lang.python/t/79c38e653587d4a/ A long thread, now discussing an O(log n) algorithm for computing the Fibonacci sequence: http://groups.google.com/group/comp.lang.python/t/b713b14e3e0d9872/e9e64fa9a0348ad8?lnk=gst#e9e64fa9a0348ad8 Implementing a multi-dimensional array: a short but insightful response from Robert Kern: http://groups.google.com/group/comp.lang.python/t/f20a6522369d2bbe/ SciPy 2011, Austin, Texas, 11-16 July 2011: http://conference.scipy.org/scipy2011/index.php Unicode for dummies :-) : http://groups.google.com/group/comp.lang.python/t/23d8592a9170e26e/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From tar at sevak.isi.edu Wed May 18 12:16:26 2011 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 18 May 2011 09:16:26 -0700 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On 17 May 2011 23:42:20 -0700, Thomas A. Russ > wrote: > : Tree walks are the canonical example of what can't be done in an > : iterative fashion without the addition of an explicitly managed stack > > Of course you can do it. It isn't nice, but it is possible. > I assume that you refer to depth first walks, as breadth first > is more easily described by iteration on a queue in the first place. > > Depth first can be achieved by looping over the nodes, with a > state keeping references to the current and the previous node > considered. Well, unless you have a tree with backpointers, you have to keep the entire parent chain of nodes visited. Otherwise, you won't be able to find the parent node when you need to backtrack. A standard tree representation has only directional links. Consider: A--+---B----+---D | | | +---E | | | +---F | +---C If all you keep is the current and previous node, then the only thing you have reference do when doing the depth-first traverse is: 1. Current = A, Previous = null 2. Current = B. Previous = A 3. Current = D Previous = B 4. Current = E Previous = D 5. now what? You can't get from E or D back to B. > By comparing the previous node (pointer or ID) to the > current node's parent and children one will know wherefrom the > current node was entered, and can choose the next child in the > list as the next node, or the parent if all children have been > visited. A visit action may be added in any or all times the > node is visited. > > This node requires no stack. The only state space is constant, > regardless of the size of the tree, requiring just the two pointers > to previous and current. This will only work if there is a backpointer to the parent. So you have to add one extra pointer for each node back to its parent. This extra pointer will be the size of the graph, rather than (on average) log of the size of the graph stack frames. -- Thomas A. Russ, USC/Information Sciences Institute From ethan at stoneleaf.us Wed May 18 12:40:40 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 18 May 2011 09:40:40 -0700 Subject: Python 3.x and bytes In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> Message-ID: <4DD3F688.6030605@stoneleaf.us> Ian Kelly wrote: > On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: >> The big question, though, is would you do it this way: >> >> some_var = bytes(23).replace(b'\x00', b'a') >> >> or this way? >> >> some_var = bytes(b'a' * 23) > > Actually, I would just do it this way: > > some_var = b'a' * 23 > > That's already a bytes object. Passing it into the constructor is redundant. However, as I just discovered, it works well when dealing with a bytearray object: some_var = bytearray(b' ' * size) # want space initialized, not null ~Ethan~ From debatem1 at gmail.com Wed May 18 12:54:30 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 18 May 2011 09:54:30 -0700 Subject: obviscating python code for distribution In-Reply-To: <5h9ca8-ekq.ln1@svn.schaathun.net> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: > On Mon, 16 May 2011 23:42:40 +0100, Rhodri James > ? wrote: > : ?...which is, of course, not exactly secure either. ?A sufficiently > : ?determined hacker won't have much trouble disassembling a shared library > : ?even if you do strip out all the debug information. ?By chance I'm having > : ?to do something closely related to this at work just at the moment; it's > : ?hard, but far from impossible. > > But then, nothing is secure in any absolute sense. If you're talking security and not philosophy, there is such a thing as a secure system. As a developer you should aim for it. > The best you can > do with all your security efforts is to manage risk. ?Since obfuscation > increases the cost of mounting an attack, it also reduces risk, > and thereby provides some level of security. The on-the-ground reality is that it doesn't. Lack of access to the source code has not kept windows or adobe acrobat or flash player secure, and they have large full-time security teams, and as you might imagine from the amount of malware floating around targeting those systems there are a lot of people who have these skills in spades. > Obviously, if your threat sources are dedicated hackers or maybe MI5, > there is no point bothering with obfuscation, but if your threat source > is script kiddies, then it might be quite effective. On the theory that any attack model without an adversary is automatically secure? Geremy Condra From rosuav at gmail.com Wed May 18 13:24:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 03:24:12 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Thu, May 19, 2011 at 2:54 AM, geremy condra wrote: > On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: >> But then, nothing is secure in any absolute sense. > > If you're talking security and not philosophy, there is such a thing > as a secure system. As a developer you should aim for it. Agreed. Things can be secure if you accept caveats. A good server might be secure as long as attackers cannot, say: * Get physical access to the server, remove the hard disk, and tamper with it * Hold a gun to the developer and say "Log me in as root or you die" * Trigger a burst of cosmic rays that toggle some bits in memory If someone can do that, there's really not much you can do to stop them. But you CAN make a system 100% secure against network-based attacks. Denial of service attacks are the hardest to truly defend against, and if your level of business is low enough, you can probably ignore them in your code, and deal with them by human ("Hmm, we seem to be getting ridiculous amounts of traffic from XX.YY.ZZ.*, I think I'll put a temporary ban on that /24"). Although some really nasty DOSes can be blocked fairly easily, so it's worth thinking about them. But mainly: Don't panic about the really really obscure attack possibilities, the ones that would only happen if someone with a lot of resources is trying to bring you down. Just deal with the obvious stuff - make sure your server cannot be compromised via a standard network connection. Test your server by connecting with a basic TELNET client (or a hacked-up client, if it uses a binary protocol). Test your client by connecting it to a hacked-up server. Make sure you can't muck up either of them. Assume that any attacker will know every detail about your comms protocol, because chances are he will know most of it. Chris Angelico From john at castleamber.com Wed May 18 13:31:58 2011 From: john at castleamber.com (John Bokma) Date: Wed, 18 May 2011 12:31:58 -0500 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: <87mxijzzht.fsf@castleamber.com> Chris Angelico writes: > On Thu, May 19, 2011 at 2:54 AM, geremy condra wrote: >> On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: >>> But then, nothing is secure in any absolute sense. >> >> If you're talking security and not philosophy, there is such a thing >> as a secure system. As a developer you should aim for it. > > Agreed. Things can be secure if you accept caveats. A good server > might be secure as long as attackers cannot, say: > * Get physical access to the server, remove the hard disk, and tamper with it > * Hold a gun to the developer and say "Log me in as root or you die" > * Trigger a burst of cosmic rays that toggle some bits in memory You forgot the most important one: * if none of the software running on it has exploitable issues Personally, I think it's best to understand that no server is ever secure and hence one must always be prepared that a breach can happen. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From hg at schaathun.net Wed May 18 13:33:47 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 18:33:47 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, 18 May 2011 09:54:30 -0700, geremy condra wrote: : On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: : > But then, nothing is secure in any absolute sense. : : If you're talking security and not philosophy, there is such a thing : as a secure system. As a developer you should aim for it. You think so? Please name one, and let us know how you know that it is secure. : > and thereby provides some level of security. : : The on-the-ground reality is that it doesn't. Lack of access to the : source code has not kept windows or adobe acrobat or flash player : secure, and they have large full-time security teams, and as you might : imagine from the amount of malware floating around targeting those : systems there are a lot of people who have these skills in spades. You are just demonstrating that it does not provide complete security, something which I never argued against. : > Obviously, if your threat sources are dedicated hackers or maybe MI5, : > there is no point bothering with obfuscation, but if your threat source : > is script kiddies, then it might be quite effective. : : On the theory that any attack model without an adversary is : automatically secure? No, on the assumption that we were discussing real systems, real threats, and practical solutions, rather than models and theory. There will always be adversaries, but they have limited means, and limited interest in your system. And the limits vary. Any marginal control will stave off a few potential attackers who just could not be bothered. In theory, you can of course talk about absolute security. For instance, one can design something like AES?, which is secure in a very limited, theoretical model. However, to be of any practical use, AES must be built into a system, interacting with other systems, and the theory and skills to prove that such a system be secure simply has not been developed. Why do you think Common Criteria have not yet specified frameworks for the top levels of assurance? ? Advanced Encryption Standard -- :-- Hans Georg From debatem1 at gmail.com Wed May 18 13:40:51 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 18 May 2011 10:40:51 -0700 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 10:24 AM, Chris Angelico wrote: > On Thu, May 19, 2011 at 2:54 AM, geremy condra wrote: >> On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: >>> But then, nothing is secure in any absolute sense. >> >> If you're talking security and not philosophy, there is such a thing >> as a secure system. As a developer you should aim for it. > > Agreed. Things can be secure if you accept caveats. A good server > might be secure as long as attackers cannot, say: > * Get physical access to the server, remove the hard disk, and tamper with it > * Hold a gun to the developer and say "Log me in as root or you die" > * Trigger a burst of cosmic rays that toggle some bits in memory Just a note: you can do many cool things to prevent the last from working, assuming you're talking about RSA fault injection attacks. > If someone can do that, there's really not much you can do to stop > them. But you CAN make a system 100% secure against network-based > attacks. > > Denial of service attacks are the hardest to truly defend against, and > if your level of business is low enough, you can probably ignore them > in your code, and deal with them by human ("Hmm, we seem to be getting > ridiculous amounts of traffic from XX.YY.ZZ.*, I think I'll put a > temporary ban on that /24"). Although some really nasty DOSes can be > blocked fairly easily, so it's worth thinking about them. > > But mainly: Don't panic about the really really obscure attack > possibilities, the ones that would only happen if someone with a lot > of resources is trying to bring you down. Just deal with the obvious > stuff - make sure your server cannot be compromised via a standard > network connection. Just one caveat I would add to this: make sure you're drawing this line at the correct place. If your attack model is wrong things have a tendency to drop from 'impossible' to 'laughably easy' in a hurry. > Test your server by connecting with a basic TELNET client (or a > hacked-up client, if it uses a binary protocol). Test your client by > connecting it to a hacked-up server. Make sure you can't muck up > either of them. Assume that any attacker will know every detail about > your comms protocol, because chances are he will know most of it. I actually like to use scapy a lot. It's a little slow, but you can really get down deep and still feel sort of sane afterwards, and it makes it easier on you if you don't need to go all the way to the metal. Geremy Condra From rosuav at gmail.com Wed May 18 13:52:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 03:52:16 +1000 Subject: obviscating python code for distribution In-Reply-To: <87mxijzzht.fsf@castleamber.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <87mxijzzht.fsf@castleamber.com> Message-ID: On Thu, May 19, 2011 at 3:31 AM, John Bokma wrote: >> Agreed. Things can be secure if you accept caveats. A good server >> might be secure as long as attackers cannot, say: >> * Get physical access to the server, remove the hard disk, and tamper with it >> * Hold a gun to the developer and say "Log me in as root or you die" >> * Trigger a burst of cosmic rays that toggle some bits in memory > > You forgot the most important one: > > * if none of the software running on it has exploitable issues That's not a caveat. That's a purposeful and deliberate goal. And far from impossible. > Personally, I think it's best to understand that no server is ever > secure and hence one must always be prepared that a breach can happen. You need to balance the risk of a breach against the effort it'd take to prevent. See my comments re DOS attacks; it's not generally worth being preemptive with those, unless you're at a way higher transaction level than this discussion is about (for those who came in late, it's a basic network game, and not Google Docs or the DNS root servers or something). If it's going to impose 500ms latency on all packets just to prevent the one chance in 1E50 that you get some particular attack, then it's really not worthwhile. However, it IS possible to ensure that the server doesn't, for instance, trust the client; those extremely basic protections are well worth the effort (even if it seems like a lot of effort). Chris Angelico From see at sig.for.address Wed May 18 13:59:45 2011 From: see at sig.for.address (Victor Eijkhout) Date: Wed, 18 May 2011 12:59:45 -0500 Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> Harrison Hill wrote: > No need - I have the Dictionary definition of recursion here: > > Recursion: (N). See recursion. If you tell a joke, you have to tell it right. Recursion: (N). See recursion. See also tail recursion. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From rosuav at gmail.com Wed May 18 14:07:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 04:07:25 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Thu, May 19, 2011 at 3:40 AM, geremy condra wrote: > Just a note: you can do many cool things to prevent the last from > working, assuming you're talking about RSA fault injection attacks. Sure. Each of those caveats can be modified in various ways; keeping checksums of everything in memory, encrypting stored data with something that isn't stored on that computer, etc, etc, etc. But in terms of effort for gain, it's not usually worth it. However, it is a good idea to be aware of your caveats; for instance, are you aware that most Linux systems will allow a root login from another file system (eg a live-boot CD) to access the hard drive read-write, regardless of file ownership and passwords? (My boss wasn't, and was rather surprised at how easily it could be done.) >> But mainly: Don't panic about the really really obscure attack >> possibilities... > > Just one caveat I would add to this: make sure you're drawing this > line at the correct place. If your attack model is wrong things have a > tendency to drop from 'impossible' to 'laughably easy' in a hurry. Absolutely. Sometimes it's worth scribbling comments in your code like: /* TODO: If someone tries X, it might cause Y. Could rate-limit here if that's an issue. */ Then, you keep an administrative eye on the production code. If you start having problems, you can deal with them fast, rather than having the ridiculous situation of security issues lingering for months or years before finally getting a band-aid solution. >> Test your server by connecting with a basic TELNET client... > > I actually like to use scapy a lot. It's a little slow, but you can > really get down deep and still feel sort of sane afterwards, and it > makes it easier on you if you don't need to go all the way to the > metal. Sort of sane? I lost that feeling years ago. :) When I'm working on Windows, I'll sometimes use SMSniff for packet sniffing, but generally, I just stick with high level socket services and depend on the underlying libraries to deal with malformed packets and such. On Linux, I generally whip up a quick script to do whatever job on the spot (Python and Pike are both extremely well suited to this), but on Windows, I use my MUD client, RosMud, which has a "passive mode" option for playing the part of the server. Chris Angelico From hg at schaathun.net Wed May 18 14:11:29 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 19:11:29 +0100 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: ["Followup-To:" header set to comp.lang.python.] On 18 May 2011 09:16:26 -0700, Thomas A. Russ wrote: : Well, unless you have a tree with backpointers, you have to keep the : entire parent chain of nodes visited. Otherwise, you won't be able to : find the parent node when you need to backtrack. A standard tree : representation has only directional links. The array representation of a binary tree is standard, and the ?back? (parent) pointers are mathematically given. /Some/ standard tree representation do not have parent pointers. You are right that I assumed parent pointers of some description; but it does demonstrate that tree walks can be done iteratively, without keeping a stack of any sort. -- :-- Hans Georg From rosuav at gmail.com Wed May 18 14:12:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 04:12:49 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: On Thu, May 19, 2011 at 2:16 AM, Thomas A. Russ wrote: > Well, unless you have a tree with backpointers, you have to keep the > entire parent chain of nodes visited. ?Otherwise, you won't be able to > find the parent node when you need to backtrack. ?A standard tree > representation has only directional links. Sure, but there are plenty of trees that do have parent pointers. Widgets on every system I've tinkered with always have, and in a directory structure that doesn't allow files to be in multiple places, it's not hard (look at the . and .. entries in a directory). Of course, file systems are not idealized tree structures, so things will be a bit more complicated. ChrisA From raw at RAWMBP-2.local Wed May 18 14:20:01 2011 From: raw at RAWMBP-2.local (Raymond Wiker) Date: Wed, 18 May 2011 20:20:01 +0200 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On 18 May 2011 09:16:26 -0700, Thomas A. Russ > wrote: > : Well, unless you have a tree with backpointers, you have to keep the > : entire parent chain of nodes visited. Otherwise, you won't be able to > : find the parent node when you need to backtrack. A standard tree > : representation has only directional links. > > The array representation of a binary tree is standard, and the > ?back? (parent) pointers are mathematically given. /Some/ > standard tree representation do not have parent pointers. I don't think anybody mentioned *binary* trees. The context was directory traversal, in which case you would have nodes with an arbitrary (almost) number of children. > You are right that I assumed parent pointers of some description; > but it does demonstrate that tree walks can be done iteratively, > without keeping a stack of any sort. Except that the chain of parent pointers *would* constitue a stack. From tyler at tysdomain.com Wed May 18 14:26:45 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Wed, 18 May 2011 12:26:45 -0600 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: <4DD40F65.7090807@tysdomain.com> >might be secure as long as attackers cannot, say: You forgot UFOs. Anyway, again, thanks to everyone for the advice, this is good reading. Incidentally, I don't know to much about security. I know about rate limiting and dos attacks, as well as some others, but I think there's a lot more that I don't know--can someone kind of aim me in the right direction for some of this? I want to be able to take techniques, break my server and then fix it so that can't be done before I head to public with this. From dotancohen at gmail.com Wed May 18 14:30:00 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 May 2011 21:30:00 +0300 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 20:24, Chris Angelico wrote: > But you CAN make a system 100% secure against network-based > attacks. > Only by unplugging the network cable. This is called an air gap, and is common in military installations. Anything with a cable plugged in is hackable. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From dotancohen at gmail.com Wed May 18 14:31:48 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 May 2011 21:31:48 +0300 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 20:24, Chris Angelico wrote: > Denial of service attacks are the hardest to truly defend against, and > if your level of business is low enough, you can probably ignore them > in your code, and deal with them by human ("Hmm, we seem to be getting > ridiculous amounts of traffic from XX.YY.ZZ.*, I think I'll put a > temporary ban on that /24"). Although some really nasty DOSes can be > blocked fairly easily, so it's worth thinking about them. > The python code should not be concerned with DDoS, that is what iptables is for. Remember, never do in code what Linux will do for you. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From rosuav at gmail.com Wed May 18 14:37:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 04:37:30 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Thu, May 19, 2011 at 4:31 AM, Dotan Cohen wrote: > The python code should not be concerned with DDoS, that is what > iptables is for. Remember, never do in code what Linux will do for > you. In general, yes. Denial of service is a fairly broad term, though, and if there's a computationally-expensive request that a client can send, then it may be worth rate-limiting it. Or if there's a request that causes your server to send out inordinate amounts of data, and you're running it on a typical home internet connection, then that's a DOS vector too. So it's not only an iptables issue. But yes. The "system" is the entire system, not just the Python code you're writing. ChrisA From hg at schaathun.net Wed May 18 14:39:53 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 19:39:53 +0100 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: ["Followup-To:" header set to comp.lang.python.] On Wed, 18 May 2011 20:20:01 +0200, Raymond Wiker wrote: : I don't think anybody mentioned *binary* trees. The context was : directory traversal, in which case you would have nodes with an : arbitrary (almost) number of children. If we are being specific, then directory trees do have parent pointers. My point was really that ?standard tree representations? is not a well-defined concept, and having parent pointers is as standard as not having them. : Except that the chain of parent pointers *would* constitue a : stack. In the sense that the tree itself is a stack, yes. But if we consider the tree (or one of its branches) to be a stack, then the original claim becomes a tautology. But you do have a point. Keeping a stack of nodes on the path back to root is a great deal simpler and cheaper than a call stack, and not really a significant expense in context. -- :-- Hans Georg From rosuav at gmail.com Wed May 18 14:41:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 04:41:21 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: On Thu, May 19, 2011 at 4:20 AM, Raymond Wiker wrote: >> You are right that I assumed parent pointers of some description; >> but it does demonstrate that tree walks can be done iteratively, >> without keeping a stack of any sort. > > ? ? ? ?Except that the chain of parent pointers *would* constitue a > stack. Howso? It's part of your data structure, not part of your algorithm; and it's not something that grows and shrinks as you traverse. These considerations may be crucial if, for instance, you want to walk your tree in a signal handler, and you don't know how much memory is available to you... Chris Angelico From rosuav at gmail.com Wed May 18 14:49:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 May 2011 04:49:30 +1000 Subject: obviscating python code for distribution In-Reply-To: <4DD40F65.7090807@tysdomain.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <4DD40F65.7090807@tysdomain.com> Message-ID: On Thu, May 19, 2011 at 4:26 AM, Littlefield, Tyler wrote: >>might be secure as long as attackers cannot, say: > You forgot UFOs. > Anyway, again, thanks to everyone for the advice, this is good reading. > Incidentally, I don't know to much about security. I know about rate > limiting and dos attacks, as well as some others, but I think there's a lot > more that I don't know--can someone kind of aim me in the right direction > for some of this? I want to be able to take techniques, break my server and > then fix it so that can't be done before I head to public with this. Your last sentence IS the right direction. The two easiest ways to find out if your system is secure are (1) try to break it, and (2) pore over the code and see what can be broken. When you start testing things, try doing things in the wrong order. Your server should either cope with it fine, or throw back an error to that client, but should never allow any action that that client hasn't already proven he's allowed to do. There's plenty of people here who know what they're talking about when it comes to security (just skim over this thread for a few good names!), so if you have specific questions regarding your Python code, do ask. Alternatively, if it's not particularly Python-related, I would be happy for you to email me privately; I'm a gamer, and run an online game, so I'd be quite willing to have a bit of a poke at your code. Chris Angelico From pjb at informatimago.com Wed May 18 14:57:25 2011 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Wed, 18 May 2011 20:57:25 +0200 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: <8762p7omzu.fsf@kuiper.lan.informatimago.com> tar at sevak.isi.edu (Thomas A. Russ) writes: > Well, unless you have a tree with backpointers, you have to keep the > entire parent chain of nodes visited. Otherwise, you won't be able to > find the parent node when you need to backtrack. A standard tree > representation has only directional links. > > Consider: > > A--+---B----+---D > | | > | +---E > | | > | +---F > | > +---C > > If all you keep is the current and previous node, then the only thing > you have reference do when doing the depth-first traverse is: > 1. Current = A, Previous = null > 2. Current = B. Previous = A > 3. Current = D Previous = B > 4. Current = E Previous = D > 5. now what? You can't get from E or D back to B. > >> By comparing the previous node (pointer or ID) to the >> current node's parent and children one will know wherefrom the >> current node was entered, and can choose the next child in the >> list as the next node, or the parent if all children have been >> visited. A visit action may be added in any or all times the >> node is visited. >> >> This node requires no stack. The only state space is constant, >> regardless of the size of the tree, requiring just the two pointers >> to previous and current. > > This will only work if there is a backpointer to the parent. No, you don't need backpointers; some cases have been mentionned in the other answer, but in general: (defun parent (tree node) (if (member node (children tree)) tree (some (lambda (child) (parent child node)) (children tree)))) Yes, the question wasn't about time complexity. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From tmac641382 at yahoo.com Wed May 18 15:06:07 2011 From: tmac641382 at yahoo.com (tmac641382 at yahoo.com) Date: Wed, 18 May 2011 12:06:07 -0700 (PDT) Subject: How To Make Fast Money Legally Message-ID: <99c99019-754c-4b43-8a84-22ab7f2fc498@bl1g2000vbb.googlegroups.com> HOW TO MAKE EASY MONEY FAST AND LEGALLY!!!!!!!! This seems to really have potential. This is the way the original post appeared when I first found it. Read it all then decide for yourself. It works for me! I found this on a bulletin board and decided to try it. A little while back, I was browsing through newsgroups, just like you are now, and came across an article similar to this that said you could make thousands of dollars within weeks with only an initial investment of $6.00! So I thought, "Yeah right, this must be a scam", but like most of us, I was curious, so I kept reading. Even though the investment was a measly $6, I had three questions that needed to be answered before I could get involved in this sort of thing. IS THIS REALLY LEGAL? I called a lawyer first. The lawyer was a little skeptical that I would actually make any CASH but he said it WAS LEGAL if I wanted to try it. I told him it sounded a lot like a chain letter but the details of the system (SEE BELOW) actually made it a legitimate legal business. 2. IS OK WITH THE POST OFFICE OR IS IT MAIL FRAUD? I called them: 1-800-725-2161 and they confirmed THIS IS ABSOLUTELY LEGAL! (See 18, h sections1302 NS 1341 of Postal Lottery Laws). This clarifies the program of collecting names and addresses for a mailing list. 3. IS IT RIGHT? Well, everyone who sends me a buck has a good chance of getting A LOT of CASH ... a much better chance than buying a lottery ticket!!! 4. WHAT IS THE BUSINESS? You are in the business of collecting mailing lists and recruiting new list developers. These questions answered, I decided to proceed. The instructions said that you have to send $1.00 to each of the 6 names and address stated in the article. You then place your own name and address in the bottom of the list at #6, and post the article in at least 300 newsgroups. (There are thousands) No catch, that was it. So, I invested the measly $6.00. Well GUESS WHAT!! Within 7 days, I started getting money in the mail! I was shocked! I figured it would end soon, but the money just kept coming in. In my first week, I made about $25.00. By the end of the second week I had made a total of over $1,000! In the third week I had over $10,000.00 and it's still growing. This is now my fourth week and I have made a total of just over $42,000.00 and it's still coming in rapidly. It's certainly worth $6.00, and 6 stamps, I have spent more than that on the lottery!! Let me tell you how this works and most importantly, why it works. Also, make sure you print a copy of this article NOW, so you can get the information off of it as you need it. I seems likely to me that if you follow the directions exactly, that you will start making more money than you thought possible by doing something so easy! Suggestion: Read this entire message carefully! (print it out or download it.) Follow the simple directions and watch the money come in! It's easy. It's legal. And, your investment is only $6.00 (Plus postage) IMPORTANT: This is not a rip-off; it is not indecent; it is not illegal; and it is virtually no risk - it really works!!!! If all of the following instructions are adhered to, you will receive extraordinary dividends. PLEASE NOTE: Please follow these directions EXACTLY, and $50,000 or more can be yours in 20 to 60 days. This program remains successful because of the honesty and integrity of the participants. Please continue its success by carefully adhering to the instructions. You will now become part of the Mail Order business. In this business your product is not solid and tangible, it's a service. You are in the business of developing Mailing Lists. Many large corporations are happy to pay big bucks for quality lists. However, the money made from the mailing lists is secondary to the income which is made from people like you and me asking to be included in that list. Here are the 4 easy steps to success: STEP 1: Get 6 separate pieces of paper and write the following on each piece of paper "PLEASE PUT ME ON YOUR MAILING LIST include your mailing address, the date and your signature." Now get 6 US $1.00 bills and place ONE inside EACH of the 6 pieces of paper so the bill will not be seen through the envelope (to prevent thievery). Next, place one paper in each of the 6 envelopes and seal them. You should now have 6 sealed envelopes, each with a piece of paper stating the above phrase, your name and address, and a $1.00 bill. What you are doing is creating a service. THIS IS ABSOLUTELY LEGAL! You are requesting a legitimate service and you are paying for it! Like most of us I was a little skeptical and a little worried about the legal aspects of it all. So I checked it out with the U.S. Post Office (1-800-725-2161) and they confirmed that it is indeed legal! Mail the 6 envelopes to the following addresses: 1.)T. Dunn 722 Hopital Rd. Dawson Springs, Ky 42408,USA 2.) K. Carpenter P.O. Box 5174 Rantoul Illinois 61866-5174 3) D. Stephens P.O. Box 512 Staunton, MI 24321 4) J. Zuk 13709 Flank March Ln Spotsylvania, VA 22553 5.) Cornelius Stewart 2821 Avenue b Fort Pierce, Fl 34947 6) M. Wright Jr 9930 Richmond Kansas City MO 64134 STEP 2: Now take the #1 name off the list that you see above, move the other names up (6 becomes 5, 5 becomes 4, etc...) and add YOUR Name as number 6 on the list. STEP 3: Change anything you need to, but try to keep this article as close to original as possible. Now, post your amended article to at least 300 newsgroups. (I think there are close to 32,000 groups) All you need is 300, but remember, the more you post, the more money you make! This is perfectly legal! If you have any doubts, refer to Title 18 Sec. 1302 & 1341 of the Postal lottery laws. PLEASE REMEMBER that this program remains successful because of the honesty and integrity of the participants and by their carefully adhering to the directions. Look at it this way. If you are of integrity, the program will continue and the money that so many others have received will come your way. NOTE: You want to retain every name and address sent to you, either on a computer or hard copy and keep the notes people send you. This VERIFIES that you are truly providing a service. (Also, it might be a good idea to wrap the $1 bill in dark paper to reduce the risk of mail theft.) So, as each post is downloaded and the directions carefully followed, six members will be reimbursed for their participation as a List Developer with one dollar each. Your name will move up the list geometrically so that when your name reaches the #1 position you will be receiving thousands of dollars in CASH!!! What an opportunity for only $6.00 ($1.00 for each of the first six people listed above) Send it now, add your own name to the list and you're in business! DIRECTIONS FOR HOW TO POST TO NEWSGROUPS STEP 1) You do not need to re-type this entire letter to do your own posting. Simply put your cursor at the beginning of this letter and drag your cursor to the bottom of this document, and select 'copy' from the edit menu. This will copy the entire letter into the computer's memory STEP 2) Open a blank 'notepad' file and place your cursor at the top of the blank page. From the 'edit' menu select 'paste'. This will paste a copy of the letter into notepad so that you can add your name to the list STEP 3) Save your new notepad file as a text file. If you want to do your postings in different settings, you'll always have this file to go back to. STEP 4) Use Netscape or Internet explorer and try searching for various newsgroups (on-line forums, message boards, chat sites, discussions.) STEP 5) Visit these message boards and post this article as a new message by highlighting the text of this letter and selecting paste from the edit menu. Fill in the Subject, this will be the header that everyone sees as they scroll through the list of postings in a particular group, click the post message button. You're done with your first one! Congratulations...THAT'S IT! All you have to do is jump to different newsgroups and post away, after you get the hang of it, it will take about 30 seconds for each newsgroup! REMEMBER, THE MORE NEWSGROUPS YOU POST IN, THE MORE MONEY YOU WILL MAKE!! BUT YOU HAVE TO POST A MINIMUM OF 300 That's it! You will begin receiving money from around the world within days! You may eventually want to rent a P.O. Box due to the large amount From debatem1 at gmail.com Wed May 18 15:07:49 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 18 May 2011 12:07:49 -0700 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 10:33 AM, Hans Georg Schaathun wrote: > On Wed, 18 May 2011 09:54:30 -0700, geremy condra > ? wrote: > : ?On Wed, May 18, 2011 at 12:36 AM, Hans Georg Schaathun wrote: > : > But then, nothing is secure in any absolute sense. > : > : ?If you're talking security and not philosophy, there is such a thing > : ?as a secure system. As a developer you should aim for it. > > You think so? ?Please name one, and let us know how you know that it > is secure. I was playing around with an HSM the other day that had originally targeted FIPS 140-3 level 5, complete with formal verification models and active side-channel countermeasures. I'm quite confident that it was secure in nearly any practical sense. > : > and thereby provides some level of security. > : > : ?The on-the-ground reality is that it doesn't. Lack of access to the > : ?source code has not kept windows or adobe acrobat or flash player > : ?secure, and they have large full-time security teams, and as you might > : ?imagine from the amount of malware floating around targeting those > : ?systems there are a lot of people who have these skills in spades. > > You are just demonstrating that it does not provide complete security, > something which I never argued against. Ah, my mistake- when you said 'some level of security' I read that as 'some meaningful level of security'. If you were arguing that it provided roughly as much protection to your code as the curtain of air surrounding you does to your body, then yes- you're correct. > : > Obviously, if your threat sources are dedicated hackers or maybe MI5, > : > there is no point bothering with obfuscation, but if your threat source > : > is script kiddies, then it might be quite effective. > : > : ?On the theory that any attack model without an adversary is > : ?automatically secure? > > No, on the assumption that we were discussing real systems, real > threats, and practical solutions, rather than models and theory. > There will always be adversaries, but they have limited means, and > limited interest in your system. ?And the limits vary. ?Any marginal > control will stave off a few potential attackers who just could not > be bothered. Empirically this doesn't appear to be a successful gambit, and from an attacker's point of view it's pretty easy to see why. When a system I'm trying to break turns out to have done something stupid like this, it really just ticks me off, and I know a lot of actual attackers who think the same way. > In theory, you can of course talk about absolute security. ?For > instance, one can design something like AES?, which is secure in > a very limited, theoretical model. ?However, to be of any practical > use, AES must be built into a system, interacting with other systems, > and the theory and skills to prove that such a system be secure simply > has not been developed. This is flatly incorrect. > Why do you think Common Criteria have not yet specified frameworks > for the top levels of assurance? Perhaps because the lower levels of 'assurance' don't seem to provide very much. Geremy Condra From raw at RAWMBP-2.local Wed May 18 15:09:15 2011 From: raw at RAWMBP-2.local (Raymond Wiker) Date: Wed, 18 May 2011 21:09:15 +0200 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On Wed, 18 May 2011 20:20:01 +0200, Raymond Wiker > wrote: > : I don't think anybody mentioned *binary* trees. The context was > : directory traversal, in which case you would have nodes with an > : arbitrary (almost) number of children. > > If we are being specific, then directory trees do have parent pointers. > My point was really that ?standard tree representations? is not a > well-defined concept, and having parent pointers is as standard as > not having them. I cannot see that going back to the original case (directory traversal) is any more specific than talking about a completely unrelated case (binary trees). Further, even though most(?) hierarchical file systems have parent pointers, this is not necessary. > : Except that the chain of parent pointers *would* constitue a > : stack. > > In the sense that the tree itself is a stack, yes. But if we > consider the tree (or one of its branches) to be a stack, then > the original claim becomes a tautology. No, the tree is not a stack, but the chain of parent pointers from a particular node may be considered as a stack that records the path taken to reach the current node. > But you do have a point. Keeping a stack of nodes on the path > back to root is a great deal simpler and cheaper than a call > stack, and not really a significant expense in context. For this particular operation, possibly. For other tree operations, a single parent pointer may not be sufficient. From rafadurancastaneda at gmail.com Wed May 18 15:42:33 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Wed, 18 May 2011 21:42:33 +0200 Subject: python logging In-Reply-To: <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> Message-ID: <4DD42129.7030705@gmail.com> On 18/05/11 03:09, Fei wrote: > On May 17, 6:55 pm, Ian Kelly wrote: >> On Tue, May 17, 2011 at 2:55 PM, Fei wrote: >>> where is default logging file on Mac? I saw lots of app just import >>> logging, and begins to logging.info(...) etc. I'm not sure where to >>> look at the logging configuration to figure out the log location. >> There is no default log file. You're seeing that because logging only >> needs to be configured by the program once, not on a per-module basis. >> Thus most modules will just do import logging on the assumption that >> the configuration has already been performed somewhere else. >> >> If no logging configuration is done at all, then the logging >> statements will have no effect. > Thanks Ian. That's not exactly how it works. You can use logging without any configuration and the default output will be console. In addition default logging level is warning, so: logging.info("Some text") won't show anything and logging.warning("Other text") will show: WARNING:root:Other text Please check the link I gave before. Bye From darcy at druid.net Wed May 18 15:48:13 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 18 May 2011 15:48:13 -0400 Subject: How To Make Fast Money Legally In-Reply-To: <99c99019-754c-4b43-8a84-22ab7f2fc498@bl1g2000vbb.googlegroups.com> References: <99c99019-754c-4b43-8a84-22ab7f2fc498@bl1g2000vbb.googlegroups.com> Message-ID: <20110518154813.7a06436f.darcy@druid.net> On Wed, 18 May 2011 12:06:07 -0700 (PDT) "tmac641382 at yahoo.com" wrote: > HOW TO MAKE EASY MONEY FAST AND LEGALLY!!!!!!!! Wow! Was this stuck in someone's mail queue since 1992? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From hg at schaathun.net Wed May 18 15:56:17 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 20:56:17 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: <1skda8-3as.ln1@svn.schaathun.net> On Wed, 18 May 2011 12:07:49 -0700, geremy condra wrote: : I was playing around with an HSM the other day that had originally : targeted FIPS 140-3 level 5, complete with formal verification models : and active side-channel countermeasures. I'm quite confident that it : was secure in nearly any practical sense. And you ostensibly use the word /nearly/ rather than ?absolutely?. It seems that we agree. BTW, according to the sources I can find quickly, FIPS 140-3 targets /modules/ and not systems. : Ah, my mistake- when you said 'some level of security' I read that as : 'some meaningful level of security'. If you were arguing that it : provided roughly as much protection to your code as the curtain of air : surrounding you does to your body, then yes- you're correct. Well, I didn't. Whether it is meaningful is relative and dependent on the context, but it sure isn't meaningful if any values at stake are. : Empirically this doesn't appear to be a successful gambit, and from an : attacker's point of view it's pretty easy to see why. When a system : I'm trying to break turns out to have done something stupid like this, : it really just ticks me off, and I know a lot of actual attackers who : think the same way. That is very true. It is a very crude measure with a marginal effect on risk. Going out of one's way to try to obfuscate the code as machine code, as was the starting point of the discussion, is surely not a good strategy, as one is then spending significant time to achieve a rather insignificant. My main concern is that the use of absolutes, ?you need this?, and ?that is silly?, is drawing attention from the main point. Rather, get to know your risks and focus on the greater ones. Consider possible controls, and choose cheap and effective ones. Even a marginally effective control may be worth-while if the cost is even less. We all seem to agree on the main point; many have argued the same way. As an aside, OTOH, don't you think MAYFARE would have been broken earlier if the source code were open? It was around for ages before it was. : > In theory, you can of course talk about absolute security. ?For : > instance, one can design something like AES?, which is secure in : > a very limited, theoretical model. ?However, to be of any practical : > use, AES must be built into a system, interacting with other systems, : > and the theory and skills to prove that such a system be secure simply : > has not been developed. : : This is flatly incorrect. Which part of it? If you claim that the theory and skills to prove it exist, could you give a reference please? Of course, if you are only thinking of ?nearly any practical sense? again, then we agree and always did. : > Why do you think Common Criteria have not yet specified frameworks : > for the top levels of assurance? : : Perhaps because the lower levels of 'assurance' don't seem to provide very much. If the lower levels do not, would that not be an argument to implement more levels? Too many governments have put too much resources into this to just throw it away if the methodology to achieve higher assurance could be codified. Or maybe it is right to say that the theory and skills do exist, but the money to gather it all in one project to demonstrate the security of a single system does not :-) -- :-- Hans Georg From xahlee at gmail.com Wed May 18 16:00:01 2011 From: xahlee at gmail.com (Xah Lee) Date: Wed, 18 May 2011 13:00:01 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: Xah wrote: ?English Idiom in Unix: Directory Recursively? http://xahlee.org/comp/idiom_directory_recursively.html Mike Barnes wrote: > Xah Lee : > > >For example, when you want to delete the whole dir in emacs, it > >prompts this message: ?Recursive delete of xx? (y or n) ?. > > AFAICS what emacs calls "recursive delete" is what the ordinary person > would simply call "delete". Presumably the non-recursive delete is > called simply "delete" but is actually something more complicated than > delete, and you're supposed to know what that is. > > Also (I'm speculating) a recursive delete means carrying out the > (ordinary, non-recursive) delete process on sub-directories, > recursively. The result of which is, put simply, to delete the > directory. > > I find all this somewhat arcane. Questioning the precise suitability of > the word "recursive" seems like a quibble. that's good point. I think what happens is that the ?recursive? has become a idiom associated with directory to such a degree that the unix people don't know what the fuck they are talking about. They just simply use the word to go with directory whever they mean the whole directory. In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it possibly mean by the word ?recursive? there? Like, it might delete the directory but not delete all files in it? also, in the rsync case: ?This would recursively transfer all files from the directory ? ?, what does the word ?recursively? mean there? Xah From hg at schaathun.net Wed May 18 16:02:43 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 21:02:43 +0100 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: <38lda8-8as.ln1@svn.schaathun.net> ["Followup-To:" header set to comp.lang.python.] On Wed, 18 May 2011 21:09:15 +0200, Raymond Wiker wrote: : > In the sense that the tree itself is a stack, yes. But if we : > consider the tree (or one of its branches) to be a stack, then : > the original claim becomes a tautology. : : No, the tree is not a stack, but the chain of parent pointers : from a particular node may be considered as a stack that records the : path taken to reach the current node. That is one of its branches, yes, path from root towards leaf. It is part of the data structure, and you don't travers a data structure without using the datastructure. : > But you do have a point. Keeping a stack of nodes on the path : > back to root is a great deal simpler and cheaper than a call : > stack, and not really a significant expense in context. : : For this particular operation, possibly. For other tree : operations, a single parent pointer may not be sufficient. Que? What tree operations do you have in mind? We have covered all the standard textbook tree walks by now. -- :-- Hans Georg From nagle at animats.com Wed May 18 16:07:59 2011 From: nagle at animats.com (John Nagle) Date: Wed, 18 May 2011 13:07:59 -0700 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: <4dd4274a$0$1843$742ec2ed@news.sonic.net> On 5/17/2011 3:26 PM, Xah Lee wrote: > might be of interest. > > ?English Idiom in Unix: Directory Recursively? > http://xahlee.org/comp/idiom_directory_recursively.html > > ------------------------------------------ > English Idiom in Unix: Directory Recursively > > Xah Lee, 2011-05-17 > > Today, let's discuss something in the category of lingustics. > > You know how in unix tools, when you want to delete the whole > directory and all sub-directories and files in it, it's referred as > ?recursive?? The proper terminology is "subtree", "subfolder", or "subdirectory". John Nagle From hg at schaathun.net Wed May 18 16:19:22 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Wed, 18 May 2011 21:19:22 +0100 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: ["Followup-To:" header set to comp.lang.python.] On Wed, 18 May 2011 13:00:01 -0700 (PDT), Xah Lee wrote: : Mike Barnes wrote: : > I find all this somewhat arcane. Questioning the precise suitability of : > the word "recursive" seems like a quibble. : : that's good point. I think what happens is that the ?recursive? has : become a idiom associated with directory to such a degree that the : unix people don't know what the fuck they are talking about. They just : simply use the word to go with directory whever they mean the whole : directory. I totally agree that the motivation for the use of the word is arcane. We are many who understand and /need/ to understand arcane aspects of the system. However, the word ?recursive? is not automatically associated with discussion of directories. Listing a directory, and listing a directory recursively, are two different operations. Both are useful and important, and the distinction is necessary. : In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it : possibly mean by the word ?recursive? there? Like, it might delete the : directory but not delete all files in it? Yes you /might/ do exactly that. You just probably don't want to. I agree that the question could be rephrased in a more userfriendly manner, but OTOH, if you find the usage arcane, you probably don't have any benefit from using emacs over less arcane editors either. : also, in the rsync case: ?This would recursively transfer all files : from the directory ? ?, what does the word ?recursively? mean there? Exactly the same as it does in ?listing the directory recursively? or ?deleting the directory recursively?. Again the distinction could be useful. A non-recursive ?rsync dir1 dir2? probably isn't useful, but ?rsync * dir2? might be. -- :-- Hans Georg From lanarcam1 at yahoo.fr Wed May 18 16:33:00 2011 From: lanarcam1 at yahoo.fr (Lanarcam) Date: Wed, 18 May 2011 22:33:00 +0200 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: <4dd42cf8$0$26337$426a74cc@news.free.fr> Hans Georg Schaathun ?crivit: > > : also, in the rsync case: ?This would recursively transfer all files > : from the directory ? ?, what does the word ?recursively? mean there? > > Exactly the same as it does in ?listing the directory recursively? > or ?deleting the directory recursively?. Traversing recursively a directory is more readily understandable when there are sub-directories, the operation involves going down those sub-directories and applying the same function ad infinitum. Excuse my Latin. > Again the distinction could be useful. A non-recursive ?rsync dir1 > dir2? probably isn't useful, but ?rsync * dir2? might be. > From raw at RAWMBP-2.local Wed May 18 16:40:28 2011 From: raw at RAWMBP-2.local (Raymond Wiker) Date: Wed, 18 May 2011 22:40:28 +0200 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <38lda8-8as.ln1@svn.schaathun.net> Message-ID: Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On Wed, 18 May 2011 21:09:15 +0200, Raymond Wiker > wrote: > : > In the sense that the tree itself is a stack, yes. But if we > : > consider the tree (or one of its branches) to be a stack, then > : > the original claim becomes a tautology. > : > : No, the tree is not a stack, but the chain of parent pointers > : from a particular node may be considered as a stack that records the > : path taken to reach the current node. > > That is one of its branches, yes, path from root towards leaf. > It is part of the data structure, and you don't travers a data > structure without using the datastructure. > > : > But you do have a point. Keeping a stack of nodes on the path > : > back to root is a great deal simpler and cheaper than a call > : > stack, and not really a significant expense in context. > : > : For this particular operation, possibly. For other tree > : operations, a single parent pointer may not be sufficient. > > Que? What tree operations do you have in mind? We have covered > all the standard textbook tree walks by now. I said tree operations, not tree walks. A tree operation might involve several tree walks. Further, there has been an implicit assumption (I think) in this discussion that the order of children is given, or does not matter - if this is not the case, then you also need to maintain a stack of data structures representing lists (or sets) of children. From NotR at bestweb.net Wed May 18 16:54:49 2011 From: NotR at bestweb.net (Glenn Knickerbocker) Date: Wed, 18 May 2011 16:54:49 -0400 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: On 05/18/2011 02:50 AM, Harrison Hill wrote: > Recursion: (N). See recursion. The index of IBM's Document Composition Facility SCRIPT/VS Text Programmer's Guide, Release 3.0 (form SH35-0069-2), put it thus: > Circular definition > See definition, circular > definition > circular 211 > See also circular definition Sadly, only the Release 4 manuals are available online anymore. ?R From mikebarnes at bluebottle.com Wed May 18 17:00:22 2011 From: mikebarnes at bluebottle.com (Mike Barnes) Date: Wed, 18 May 2011 22:00:22 +0100 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: Xah Lee : >In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it >possibly mean by the word ?recursive? there? Like, it might delete the >directory but not delete all files in it? My understanding is that non-recursive means, I think there are no (non- empty?) subdirectories, or I haven't given the matter any thought, so if there are any such subdirectories, tell me and don't do anything. Recursive means I want everything deleted regardless. BICBW. -- Mike Barnes Cheshire, England From ian.g.kelly at gmail.com Wed May 18 17:29:47 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 15:29:47 -0600 Subject: python logging In-Reply-To: <4DD42129.7030705@gmail.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> Message-ID: 2011/5/18 Rafael Dur?n Casta?eda : > That's not exactly how it works. You can use logging without any > configuration and the default output will be console. In addition default > logging level is warning, so: > > logging.info("Some text") > > won't ?show anything and > > logging.warning("Other text") > > will show: > > WARNING:root:Other text > > Please check the link I gave before. > > Bye Odd. That seems to work, but it contradicts the documentation at: http://docs.python.org/howto/logging.html#what-happens-if-no-configuration-is-provided From debatem1 at gmail.com Wed May 18 17:34:46 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 18 May 2011 14:34:46 -0700 Subject: obviscating python code for distribution In-Reply-To: <1skda8-3as.ln1@svn.schaathun.net> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 12:56 PM, Hans Georg Schaathun wrote: > On Wed, 18 May 2011 12:07:49 -0700, geremy condra > ? wrote: > : ?I was playing around with an HSM the other day that had originally > : ?targeted FIPS 140-3 level 5, complete with formal verification models > : ?and active side-channel countermeasures. I'm quite confident that it > : ?was secure in nearly any practical sense. > > And you ostensibly use the word /nearly/ rather than ?absolutely?. > It seems that we agree. Systems can be designed that are absolutely secure under reasonable assumptions. The fact that it has assumptions does not make your statement true. > BTW, according to the sources I can find quickly, FIPS 140-3 > targets /modules/ and not systems. I can't tell if you're trying to play word games with the distinction between "system" and "module" or if you're just saying that you aren't sure what FIPS actually certifies. Could you please clarify? > : ?Ah, my mistake- when you said 'some level of security' I read that as > : ?'some meaningful level of security'. If you were arguing that it > : ?provided roughly as much protection to your code as the curtain of air > : ?surrounding you does to your body, then yes- you're correct. > > Well, I didn't. ?Whether it is meaningful is relative and dependent > on the context, but it sure isn't meaningful if any values at stake are. Again, I'm unsure what you're going for here. It sounds like you're saying that obfuscation doesn't provide meaningful security, which is my point. > : ?Empirically this doesn't appear to be a successful gambit, and from an > : ?attacker's point of view it's pretty easy to see why. When a system > : ?I'm trying to break turns out to have done something stupid like this, > : ?it really just ticks me off, and I know a lot of actual attackers who > : ?think the same way. > > That is very true. ?It is a very crude measure with a marginal > effect on risk. ?Going out of one's way to try to obfuscate the > code as machine code, as was the starting point of the discussion, > is surely not a good strategy, as one is then spending significant > time to achieve a rather insignificant. > > My main concern is that the use of absolutes, ?you need this?, and > ?that is silly?, is drawing attention from the main point. ?Rather, > get to know your risks and focus on the greater ones. ?Consider > possible controls, and choose cheap and effective ones. ?Even a > marginally effective control may be worth-while if the cost is even > less. ?We all seem to agree on the main point; many have argued the > same way. > > As an aside, OTOH, don't you think MAYFARE would have been broken > earlier if the source code were open? ?It was around for ages before > it was. Are you talking about the Mayfair classical cipher here? > : > In theory, you can of course talk about absolute security. ?For > : > instance, one can design something like AES?, which is secure in > : > a very limited, theoretical model. ?However, to be of any practical > : > use, AES must be built into a system, interacting with other systems, > : > and the theory and skills to prove that such a system be secure simply > : > has not been developed. > : > : ?This is flatly incorrect. > > Which part of it? ?If you claim that the theory and skills to prove it > exist, could you give a reference please? The entire field of formal modeling and verification has grown around solving this problem. My new favorite in the field is "formal models and techniques for analyzing security protocols", but there are other works discussing OS kernel verification (which has gotten a lot of attention lately) and tons of academic literature. Google (scholar) is the place to go. > Of course, if you are only thinking of ?nearly any practical sense? > again, then we agree and always did. Nope, talking about formal methods. > : > Why do you think Common Criteria have not yet specified frameworks > : > for the top levels of assurance? > : > : ?Perhaps because the lower levels of 'assurance' don't seem to provide very much. > > If the lower levels do not, would that not be an argument to implement > more levels? ?Too many governments have put too much resources into > this to just throw it away if the methodology to achieve higher assurance > could be codified. If you can't say with confidence that something meets minimum security standards, the answer is not to try to say it meets high security standards. > Or maybe it is right to say that the theory and skills do exist, but the > money to gather it all in one project to demonstrate the security of > a single system does not :-) Sorry, but again this is not correct. Geremy Condra From debatem1 at gmail.com Wed May 18 17:47:52 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 18 May 2011 14:47:52 -0700 Subject: obviscating python code for distribution In-Reply-To: <4DD40F65.7090807@tysdomain.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <4DD40F65.7090807@tysdomain.com> Message-ID: On Wed, May 18, 2011 at 11:26 AM, Littlefield, Tyler wrote: >>might be secure as long as attackers cannot, say: > You forgot UFOs. > Anyway, again, thanks to everyone for the advice, this is good reading. > Incidentally, I don't know to much about security. I know about rate > limiting and dos attacks, as well as some others, but I think there's a lot > more that I don't know--can someone kind of aim me in the right direction > for some of this? I want to be able to take techniques, break my server and > then fix it so that can't be done before I head to public with this. One good thing to do is to just read some of the black hat papers. They're pretty accessible and even if you don't know everything they're saying you should be able to get a general feel for things that way. You might also try working through things like Damn Vulnerable Web App, if you have the time. Geremy Condra From rafadurancastaneda at gmail.com Wed May 18 18:01:03 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Thu, 19 May 2011 00:01:03 +0200 Subject: python logging In-Reply-To: References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> Message-ID: <4DD4419F.5080400@gmail.com> On 18/05/11 23:29, Ian Kelly wrote: > 2011/5/18 Rafael Dur?n Casta?eda: >> That's not exactly how it works. You can use logging without any >> configuration and the default output will be console. In addition default >> logging level is warning, so: >> >> logging.info("Some text") >> >> won't show anything and >> >> logging.warning("Other text") >> >> will show: >> >> WARNING:root:Other text >> >> Please check the link I gave before. >> >> Bye > Odd. That seems to work, but it contradicts the documentation at: > > http://docs.python.org/howto/logging.html#what-happens-if-no-configuration-is-provided I think you are confuse because of you are looking at advanced logging, where getLogger is being used. Simple logging works without any configuration, getLogger doesn't. From tjreedy at udel.edu Wed May 18 18:02:53 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 May 2011 18:02:53 -0400 Subject: pyjamas 0.8alpha1 release In-Reply-To: References: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> Message-ID: On 5/18/2011 5:24 AM, lkcl wrote: There seem to be two somewhat separate requirement issues: the interpreter binary and the language version. > a) at the moment a http://python.org 2.N interpreter is required to > actually run the translator. if you use http://python.org 2.5 or 2.6 > you do not need to use the "--internal-ast" option. if you use 2.4, > 2.7 or above, you will need to use --internal-ast because we're > heavily reliant on the internal c-based "compile" module [without the > --internal-ast option enabled]. I presume '--internal-ast' is a 'compile the interpreter' option. Since I have never compilied Python (or anything else for perhaps 15 years), I do not understand completely. Am I correct to guess that the PSF Windows binaries for 2.7 were not compiled with the flag, and will not work? If so, Windows users should, I would think, use the latest 2.6.6 binaries. > b) the actual pyjs interpreter grammar (AST) was 2.5 but has mostly > been updated to 2.6. actual python syntax / features are therefore > mostly 2.5, with someone having pointed out that "slice" has different > return results it's hard to say exactly which is best to be picked, > 2.5 or 2.6. nobody's needed slice until recently, so it's not an > issue that's ever come up before. If I understand this, the safe thing to do is to stick with 2.5 syntax and omit exotic 3.x features put into 2.6 for eventual porting to 3.x. > the thing is - it's worth reiterating: you just... really don't need > as much python interoperability for user-interfaces when they're split > along MVC lines. bear in mind that it's necessary to do that split: > it's web browser technology, you can't *actually* execute things like > psycopg or mysql in a web browser as javascript! so once you've > divided that application into "python that runs the actual user > interface" and "python on the other side of the AJAX barrier e.g. a > django app" you're left with a far smaller task for the pyjs > interpreter to have to tackle. I do not get all this but it seems to say that I do not really need all the features of the later Pythons to write user-interface code. But I am not sure how this applies to business code behind the front end. Of course, it might work to run the UI in a separate process if on the same machine. >>> otherwise please - really: just saying "give me support for python >>> 3.x or else" is ... >> >> And I did not say that. > > yeah i know - i'm sorry: it just, with a little bit of "twisting", > could be construed as implying that. Let me be clear: some people think that free (as in beer) software developers have some sort of one-sided responsibility or obligation to users who pay nothing. I don't. If I say "Give me a Python 3 version of pyjamas or I will not use it", I consider you free to respond "Fine, don't use it." End of story until I compromise or contribute. I feel free to say the same to anyone who says "Stop developing new versions of Python or I will quit using the current version". > :) i think... people forget that there are now two mutually- > exclusively-incompatible programming languages out there, where the > first six letters of the name of the programming language happen to be > the same... Something of an exaggeration. It might well be possible to use a 3to2 frontend and run a mildly restricted subset of 3.x. -- Terry Jan Reedy From ian.g.kelly at gmail.com Wed May 18 18:10:20 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 16:10:20 -0600 Subject: python logging In-Reply-To: <4DD4419F.5080400@gmail.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> Message-ID: 2011/5/18 Rafael Dur?n Casta?eda : > I think you are confuse because of you are looking at advanced logging, > where getLogger is being used. Simple logging works without any > configuration, getLogger doesn't. It seems to work without any configuration just as well as the root logger: >>> import logging >>> logging.getLogger('foo').warning('test') WARNING:foo:test Or am I misunderstanding you? From rafadurancastaneda at gmail.com Wed May 18 18:21:56 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Thu, 19 May 2011 00:21:56 +0200 Subject: python logging In-Reply-To: References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> Message-ID: <4DD44684.1080504@gmail.com> On 19/05/11 00:10, Ian Kelly wrote: > 2011/5/18 Rafael Dur?n Casta?eda: >> I think you are confuse because of you are looking at advanced logging, >> where getLogger is being used. Simple logging works without any >> configuration, getLogger doesn't. > It seems to work without any configuration just as well as the root logger: > >>>> import logging >>>> logging.getLogger('foo').warning('test') > WARNING:foo:test > > Or am I misunderstanding you? Are you using python 2.x or 3.x? At python 2.7 using: import logging logging.getLogger('log').warning('test') I got: No handlers could be found for logger "log" From martin.hellwig at gmail.com Wed May 18 18:22:05 2011 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Wed, 18 May 2011 22:22:05 +0000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: On 17/05/2011 23:20, Ian Kelly wrote: > On Tue, May 17, 2011 at 4:26 PM, Xah Lee wrote: >> Though, if you think about it, it's not exactly a correct description. >> ?Recursive?, or ?recursion?, refers to a particular type of algorithm, >> or a implementation using that algorithm. > > Only when used as programming jargon. In mathematics, "recursive > function" does *not* mean "a function implemented using a recursive > algorithm". It's just a formal definition of a specific class of > mathematical functions. > > As it turns out, "recursive" also has a non-technical definition, > which again has nothing to do with algorithms except in the broadest > sense: > > recursive adj. > 1. pertaining to or using a rule or procedure that can be applied repeatedly > (from dictionary.com) > > This definition fits the Unix usage perfectly. I concur, although my dictionary defines the base of the word: "to happen many times or to happen again" http://dictionary.cambridge.org/dictionary/british/recur#recur__3 Perhaps the gp of the post might profit from a more holistic approach when adopting an opinion or at least consult a dictionary before going into a rant. -- mph From vinay_sajip at yahoo.co.uk Wed May 18 18:27:30 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 18 May 2011 15:27:30 -0700 (PDT) Subject: python logging References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> Message-ID: On May 18, 11:10?pm, Ian Kelly wrote: > It seems to work without any configuration just as well as the root logger: > > >>> importlogging > >>>logging.getLogger('foo').warning('test') > > WARNING:foo:test > > Or am I misunderstanding you? In general for Python 2.x, the code import logging logging.getLogger('foo').warning('test') will produce No handlers could be found for logger "foo" unless loggers have been configured, e.g. by calling logging.warning() - that call implicitly adds a console handler to the root logger, if no other handlers have been configured for the root logger. In Python 3.2 and later, if no handlers have been configured, messages at level WARNING and greater will be printed to sys.stderr using a "handler of last resort" - see http://docs.python.org/py3k/howto/logging.html#what-happens-if-no-configuration-is-provided Regards, Vinay Sajip From ian.g.kelly at gmail.com Wed May 18 18:30:18 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 16:30:18 -0600 Subject: Indexable properties recipe Message-ID: http://code.activestate.com/recipes/577703-item-properties/ From ian.g.kelly at gmail.com Wed May 18 18:37:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 16:37:52 -0600 Subject: python logging In-Reply-To: <4DD44684.1080504@gmail.com> References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> <4DD44684.1080504@gmail.com> Message-ID: 2011/5/18 Rafael Dur?n Casta?eda : > Are you using python 2.x or 3.x? At python 2.7 using: > > import logging > logging.getLogger('log').warning('test') > > I got: > > No handlers could be found for logger "log" Ah, that's it. I was using Python 2.5. Using 2.7 I get the same result that you do. Still, it's a surprising change that doesn't seem to be documented as such. I'm not sure whether it's a regression or an intentional change. From ian.g.kelly at gmail.com Wed May 18 18:42:07 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 May 2011 16:42:07 -0600 Subject: python logging In-Reply-To: References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> <4DD44684.1080504@gmail.com> Message-ID: 2011/5/18 Ian Kelly : > Ah, that's it. ?I was using Python 2.5. ?Using 2.7 I get the same > result that you do. > > Still, it's a surprising change that doesn't seem to be documented as > such. ?I'm not sure whether it's a regression or an intentional > change. I was wrong, it's more complicated than that. Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import logging >>> logging.getLogger('log').warning('test') No handlers could be found for logger "log" >>> logging.warning('test') WARNING:root:test >>> logging.getLogger('log').warning('test') WARNING:log:test Apparently, getLogger() is unconfigured by default, but if you just use the root logger once, then they magically get configured. From marduk at letterboxes.org Wed May 18 19:29:30 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 18 May 2011 19:29:30 -0400 Subject: How To Make Fast Money Legally In-Reply-To: <20110518154813.7a06436f.darcy@druid.net> References: <99c99019-754c-4b43-8a84-22ab7f2fc498@bl1g2000vbb.googlegroups.com> <20110518154813.7a06436f.darcy@druid.net> Message-ID: <1305761371.3259.3.camel@localhost.localdomain> On Wed, 2011-05-18 at 15:48 -0400, D'Arcy J.M. Cain wrote: > On Wed, 18 May 2011 12:06:07 -0700 (PDT) > "tmac641382 at yahoo.com" wrote: > > HOW TO MAKE EASY MONEY FAST AND LEGALLY!!!!!!!! > > Wow! Was this stuck in someone's mail queue since 1992? Me too! From bahamutzero8825 at gmail.com Wed May 18 20:39:42 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 18 May 2011 19:39:42 -0500 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD1C9D5.4070206@gmail.com> Message-ID: <4DD466CE.7050104@gmail.com> On 2011.05.18 03:30 AM, Stefan Behnel wrote: > Well, it pretty clearly states that on the PyPI page, but I also added it > to the project home page now. lxml 2.3 works with any CPython version from > 2.3 to 3.2. Thank you. I never would've looked at PyPI for info on a project that has its own site. I'll take a look at it. From invalid at peter.pmoylan.org.invalid Wed May 18 21:06:06 2011 From: invalid at peter.pmoylan.org.invalid (Peter Moylan) Date: Thu, 19 May 2011 11:06:06 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> Message-ID: rusi wrote: > On May 18, 5:09 pm, Peter Moylan > wrote: >> ObAUE: In common parlance, the English word "recursion" means pretty >> much the same as what computing people call "iteration". This might be >> the first time I have ever found a point of agreement with Xah Lee. > > Maybe the common usage mirrors the facts better than the lore that > half-baked programmers remain devoted to. Consider first > implementations: > > The implementation of recursion by a typical language (eg gcc for C) > maximizes generality at the cost of efficiency > > The implementation of a very special case -- tail recursion -- in some > special languages (most notably scheme) is required to be competitive > with the iterative solution. > > [If I remember right in Chez scheme tail recursion was more efficient > than a do (iteration) because a do typically needed assignment and > assignment was more expensive than parameter passing] I believe the word "legend", or something equivalent, was used elsewhere in this thread in this connection. The supposed inefficiency of recursive implementations is based largely on the properties of hardware that is now obsolete. With modern processors there's no great efficiency hit. In some of the smaller microcontrollers, it's true, you do have to worry about stack overflow; but the ARM processors, for example, provide plenty of stack space. In the microcontroller world, the big performance hits come from the fact that the only available compilers are for C and sometimes C++. (And nobody uses assembly language except for the very little jobs.) The nature of the C language prevents compilers from doing optimisations that are standard in compilers for high-level languages. Most C compilers will, for example, always pass parameters on the stack, despite the generous supply of registers available in newer hardware. -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. From tjreedy at udel.edu Wed May 18 21:13:51 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 May 2011 21:13:51 -0400 Subject: pyjamas 0.8alpha1 release In-Reply-To: References: Message-ID: On 5/18/2011 9:42 AM, lkcl wrote: > he's got a good point, terry. breaking backwards-compatibility was a > completely mad and incomprehensible decision. I see that I should take everything you (or Harris) say with a big grain of salt;-). You just gave me a lecture about the impossibility of doing everything one might like with limited all or mostly volunteer resources. So surely you can comprehend that the same applies to CPython also. Given that Python 1.0/1 had some design defects that became evident with experience and simply lacked some things thought of later, I can think of several options: 1. Never fix them. 2. Add fixes, but keep the old stuff. If the old and new ways are somewhat compatible, keep both available at the same time*. If they conflict, keep old as default and make new available on demand (future import)#. This was 2.x strategy. 2A. Make new ways default and have past imports. 3. Gradually delete old. This was and is policy mostly for library. 4. Delete lots of old ways all at once. This was 3.x. What would you have had us do instead? * Example: old and new style classes. Problems: the differences are hard to learn and hard to remember; they are sometimes irrelevant, but sometimes not; if you import and instantiate a class, you may not know which you have. # Example: int division. Problems: having the deprecated meaning be default is a damn nuisance; learning it is a stupid burden; if you see 'a/b' in a snippet extracted from a file, you do not know what it means. 2.7 is really the end of the road for strategy 2. Keeping obsolete features around is a learning burden for most newbies and a maintenance burden for developers. -- Terry Jan Reedy From harrismh777 at charter.net Wed May 18 22:54:48 2011 From: harrismh777 at charter.net (harrismh777) Date: Wed, 18 May 2011 21:54:48 -0500 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: Littlefield, Tyler wrote: > I know about rate limiting and dos attacks, as well as some others, but > I think there's a lot more that I don't know--can someone kind of aim me > in the right direction for some of this? I want to be able to take > techniques, break my server and then fix it so that can't be done before > I head to public with this. Black-hat and gray-hat papers are some of the best resources; and entertaining ta-boot... Four resources that you will what to look into, in no particular order: Erickson, Jon, "Hacking: The Art of Exploitation," 2nd ed, San Francisco: No Starch Press, 2008. Anonymous, "Maximum Linux Security: A Hacker's Guide to Protecting Your Linux Server and Workstation," Indianapolis: Sams Publishing, 2000. (check for other editions) (this volume is a good read, even for other platforms, but is geared specifically to Linux) Graves, Kimberly, "CEH Certified Ethical Hacker: Study Guide," Indianapolis: Wiley Publishing, 2010. Seitz, Justin, "Gray Hat Python: Python Programming for Hackers and Reverse Engineers," San Francisco: No Starch Press, 2009. The best way to protect your system is first to be able to understand how someone else will attempt to compromise it. I personally am an *ethical* hacker; by definition, I exploit possibilities, for problem solving, and I cause *NO* harm. Having said that, I have studied *all* of the techniques employed in the field for causing harm; why? Because that is the *only* way to know how to defend against them. Its like missile anti missile... virus anti virus, and the like. Because *all* of software is mathematical by nature it is not possible to lock software with software... this is partially the decidability problem at work. But mostly its a matter of their skills getting better... yours better be better yet, and when they get even better than you--- well you better be ready to improve ... and on and on it goes... But, first you need to understand what you're up against. There is absolutely *no* way to prevent reverse engineering. Its all just code, and that code can be unraveled with the right math and enough time. (time and talent is all it takes; that and the will to be tenacious and uncompromising. If someone wants your system badly enough, they will own it... its just a matter of time... so be ready for it... like the Bible says, "If the master of the house knew what hour the thief would break in and steal, he would have kept better watch on his house!" kind regards, m harris From vgnulinux at gmail.com Wed May 18 23:53:06 2011 From: vgnulinux at gmail.com (VGNU Linux) Date: Thu, 19 May 2011 09:23:06 +0530 Subject: How to select Python web frameworks and which one is the best framework ? In-Reply-To: References: Message-ID: On Tue, May 17, 2011 at 1:20 PM, VGNU Linux wrote: > Hi all, > > I am confused on which web framework to select for developing a small data > driven web application. Application will have features generally found in > now-a-days web application like security, database connectivity, > authentication etc. I found few web frameworks over the net like django, > zope 2/3, pylons, turbogears, web2py, grok etc. etc. > I just want to know that how developers/managers/organizations select a > framework which best suits their needs ? what are the parameters for > selection ? > also which is the best and widely used web framework for python ? > > I apologize if this is a repeated question. > > Regards, > VGNU > Please guys help as I am novice to web development. Regards, VGNU -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Thu May 19 00:24:12 2011 From: nagle at animats.com (John Nagle) Date: Wed, 18 May 2011 21:24:12 -0700 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <4dd49b97$0$1909$742ec2ed@news.sonic.net> On 5/4/2011 11:36 AM, Ethan Furman wrote: > Raymond Hettinger wrote: >> I'm writing-up more guidance on how to use super() and would like to >> point at some real-world Python examples of cooperative multiple >> inheritance. Multiple inheritance in Python is so badly designed that it probably should not be used in production code. Generalizing multiple inheritance from a tree to a directed acyclic graph is usually a mistake. John Nagle From hg at schaathun.net Thu May 19 00:56:19 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 19 May 2011 05:56:19 +0100 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <38lda8-8as.ln1@svn.schaathun.net> Message-ID: ["Followup-To:" header set to comp.lang.python.] On Wed, 18 May 2011 22:40:28 +0200, Raymond Wiker wrote: : I said tree operations, not tree walks. A tree operation might : involve several tree walks. OK. The original claim under dispute regarded tree walks. : Further, there has been an implicit : assumption (I think) in this discussion that the order of children is : given, or does not matter - if this is not the case, then you also need : to maintain a stack of data structures representing lists (or sets) of : children. It assumes that there is some canonical ordering on the children. If the tree nodes store their children as sets, where the implementation does not guarantee that they can be retrieved in the same order every time, then it breaks. However, that would be an unusual implementation. The tree has to store the children for each node, one way or another. The only thing I am assuming is that the children can be inspected in the same order every time the node is visited. -- :-- Hans Georg From hg at schaathun.net Thu May 19 01:21:08 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 19 May 2011 06:21:08 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> Message-ID: <4vlea8-55t.ln1@svn.schaathun.net> On Wed, 18 May 2011 14:34:46 -0700, geremy condra wrote: : Systems can be designed that are absolutely secure under reasonable : assumptions. The fact that it has assumptions does not make your : statement true. : (...) : I can't tell if you're trying to play word games with the distinction : between "system" and "module" or if you're just saying that you aren't : sure what FIPS actually certifies. Could you please clarify? The distinction between system and module is rather significant. If you only consider modules, you have bounded your problem and drastically limited the complexity. : Again, I'm unsure what you're going for here. It sounds like you're : saying that obfuscation doesn't provide meaningful security, which is : my point. Meaningful is a relative term, and it is hard to rule out the possibility that meaning can be found in some case. Overall, we agree though. : Are you talking about the Mayfair classical cipher here? I am talking about the system used in public transport cards like Oyster and Octopus. I am not sure how classical it is, or whether mayfair/mayfare referred to the system or just a cipher. Any way, it was broken, and it took years. : The entire field of formal modeling and verification has grown around : solving this problem. My new favorite in the field is "formal models : and techniques for analyzing security protocols", but there are other : works discussing OS kernel verification (which has gotten a lot of : attention lately) and tons of academic literature. Google (scholar) is : the place to go. Sure, but now you are considering modules, rather than systems again. It is when these reliable components are put together to form systems that people fail (empirically). : If you can't say with confidence that something meets minimum security : standards, the answer is not to try to say it meets high security : standards. So what? The levels of assurance have nothing to do with standards. The levels of assurance refer to the /confidence/ you can have that the standards are met. : > Or maybe it is right to say that the theory and skills do exist, but the : > money to gather it all in one project to demonstrate the security of : > a single system does not :-) : : Sorry, but again this is not correct. You keep saying that, but whenever you try to back the claim, you keep referring to limited components and not systems at all. -- :-- Hans Georg From stefan_ml at behnel.de Thu May 19 02:18:23 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 19 May 2011 08:18:23 +0200 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD466CE.7050104@gmail.com> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD1C9D5.4070206@gmail.com> <4DD466CE.7050104@gmail.com> Message-ID: Andrew Berg, 19.05.2011 02:39: > On 2011.05.18 03:30 AM, Stefan Behnel wrote: >> Well, it pretty clearly states that on the PyPI page, but I also added it >> to the project home page now. lxml 2.3 works with any CPython version from >> 2.3 to 3.2. > Thank you. I never would've looked at PyPI for info on a project that > has its own site. You should, especially for standardised information like this. Stefan From rafadurancastaneda at gmail.com Thu May 19 03:18:11 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Thu, 19 May 2011 09:18:11 +0200 Subject: python logging In-Reply-To: References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> <4DD44684.1080504@gmail.com> Message-ID: You are right that behavior isn't documented and might be a bug. You could report it. Bye El 19 de mayo de 2011 00:42, Ian Kelly escribi?: > 2011/5/18 Ian Kelly : > > Ah, that's it. I was using Python 2.5. Using 2.7 I get the same > > result that you do. > > > > Still, it's a surprising change that doesn't seem to be documented as > > such. I'm not sure whether it's a regression or an intentional > > change. > > I was wrong, it's more complicated than that. > > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import logging > >>> logging.getLogger('log').warning('test') > No handlers could be found for logger "log" > >>> logging.warning('test') > WARNING:root:test > >>> logging.getLogger('log').warning('test') > WARNING:log:test > > Apparently, getLogger() is unconfigured by default, but if you just > use the root logger once, then they magically get configured. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kushal.kumaran+python at gmail.com Thu May 19 03:51:00 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 19 May 2011 13:21:00 +0530 Subject: How to select Python web frameworks and which one is the best framework ? In-Reply-To: References: Message-ID: On Thu, May 19, 2011 at 9:23 AM, VGNU Linux wrote: > > > On Tue, May 17, 2011 at 1:20 PM, VGNU Linux wrote: >> >> Hi all, >> I am confused on which web framework to select for developing a small data >> driven web application. Application will have features generally found in >> now-a-days web application like security, database connectivity, >> authentication etc. I found few web frameworks over the net like django, >> zope 2/3, pylons, turbogears, web2py, grok etc. etc. >> I just want to know that how developers/managers/organizations select a >> framework which best suits their needs ? what are the parameters for >> selection ? >> also which is the best and widely used web framework for python ? >> I?apologize if this is a repeated question. > > Please guys help as I am novice to web development. Search the list archives. This topic has been discussed many many times. -- regards, kushal From steve+comp.lang.python at pearwood.info Thu May 19 04:47:28 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 May 2011 08:47:28 GMT Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> Message-ID: <4dd4d920$0$29968$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 May 2011 06:21:08 +0100, Hans Georg Schaathun wrote: > : Are you talking about the Mayfair classical cipher here? > > I am talking about the system used in public transport cards like Oyster > and Octopus. I am not sure how classical it is, or whether > mayfair/mayfare referred to the system or just a cipher. I think Geremy is talking about the Playfair cipher: http://en.wikipedia.org/wiki/Playfair_cipher > Any way, it was broken, and it took years. You don't know that. All you know is that it took years for people to realise that it had been broken, when a security researcher publicly announced the MIFARE cipher had been broken. If criminals had broken the cipher, they would have had no incentive to publicize the fact, and the companies running Oyster and similar ticketing schemes would have no incentive to admit they were broken. Far from it: all the incentives are against disclosure. So it's possible that Oyster cards have been counterfeited for years without anyone but the counterfitters, and possibly the Oyster card people themselves, knowing. The real barrier to cracking Oyster cards is not that the source code is unavailable, but that the intersection of the set of those who know how to break encryption, and the set of those who want to break Oyster cards, is relatively small. I don't know how long it took to break the encryption, but I'd guess that it was probably a few days of effort by somebody skilled in the art. http://www.usenix.org/events/sec08/tech/full_papers/nohl/nohl_html/index.html -- Steven From slafs.e at gmail.com Thu May 19 05:12:45 2011 From: slafs.e at gmail.com (Slafs) Date: Thu, 19 May 2011 02:12:45 -0700 (PDT) Subject: pypi mirror Message-ID: <09b8851c-00ec-49ae-af85-93e55df91375@s9g2000yqm.googlegroups.com> Hi there. I would like to make a "local" mirror of some packages that are on pypi. What options do You recommend ? I am leaning towards z3c.pypimirror because it was kind of first on my google search results. Regards S?awek From hg at schaathun.net Thu May 19 05:16:54 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 19 May 2011 10:16:54 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <4dd4d920$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6p3fa8-bnt.ln1@svn.schaathun.net> On 19 May 2011 08:47:28 GMT, Steven D'Aprano wrote: : The real barrier to cracking Oyster cards is not that the source code is : unavailable, but that the intersection of the set of those who know how : to break encryption, and the set of those who want to break Oyster cards, : is relatively small. I don't know how long it took to break the encryption, : but I'd guess that it was probably a few days of effort by somebody : skilled in the art. : : http://www.usenix.org/events/sec08/tech/full_papers/nohl/nohl_html/index.html In that paper, more than one art seem to have been applied. An open design would have eliminated the need for image analysis and reduced the requirement on hardware/electronics skills. Hence, the obfuscation has made that intersection you talk about smaller, and increased the cost of mounting the attack. As the system was broken anyway, it is hardly a victory for obfuscation, but that's beside the point. The work of that paper is almost certainly more than just ?a few days of effort?. There are simply to many technical issues to tackle, and they must be tackled one by one. The cost of mounting the attack is to figure out what it takes to do it, before spend the resources barking up the wrong tree. For each successful attack, there probably is a number of failed ones. Thanks for the reference. BTW. That's not the only attack on MIFARE. I cannot remember the details of the other. -- :-- Hans Georg From vinay_sajip at yahoo.co.uk Thu May 19 05:27:52 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 19 May 2011 02:27:52 -0700 (PDT) Subject: python logging References: <049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com> <4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com> <4DD42129.7030705@gmail.com> <4DD4419F.5080400@gmail.com> <4DD44684.1080504@gmail.com> Message-ID: <073b63fa-51bc-4c21-bdb2-676adc405093@r20g2000yqd.googlegroups.com> On May 18, 11:42?pm, Ian Kelly wrote: > I was wrong, it's more complicated than that. > > >>>logging.getLogger('log').warning('test') > > No handlers could be found for logger "log">>>logging.warning('test') > WARNING:root:test > >>>logging.getLogger('log').warning('test') > > WARNING:log:test > > Apparently, getLogger() is unconfigured by default, but if you just > use the root logger once, then they magically get configured. The difference is that you called the module-level convenience function - logging.warning('test') The module-level convenience functions call basicConfig(), which configures a console handler on the root logger if no handlers are present there. This is documented at http://docs.python.org/library/logging.html#logging.log (see para starting "PLEASE NOTE:") and http://docs.python.org/howto/logging.html#advanced-logging-tutorial (search for "If you call the functions") This is not a behaviour change - it's been like this since logging appeared in Python, see http://hg.python.org/cpython/annotate/f72b1f8684a2/Lib/logging/__init__.py#l1145 Regards, Vinay Sajip From g.rodola at gmail.com Thu May 19 05:28:48 2011 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 19 May 2011 11:28:48 +0200 Subject: smtplib is broken when using TLS In-Reply-To: References: Message-ID: Please file a ticket on: http://bugs.python.org/ Regards, --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ 2011/5/17 nirinA raseliarison : > i think this has the same origin as the ftplib test failure. > > Python 3.2.1rc1 (default, May 17 2011, 22:01:34) > [GCC 4.6.0] on linux2 > Type "copyright", "credits" or "license()" for more information. >>>> >>>> ================================ RESTART >>>> ================================ >>>> > > send: 'ehlo [127.0.0.1]\r\n' > reply: b'250-mx.google.com at your service, [41.188.13.184]\r\n' > reply: b'250-SIZE 35882577\r\n' > reply: b'250-8BITMIME\r\n' > reply: b'250-STARTTLS\r\n' > reply: b'250 ENHANCEDSTATUSCODES\r\n' > reply: retcode (250); Msg: b'mx.google.com at your service, > [41.188.13.184]\nSIZE 35882577\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES' > send: 'STARTTLS\r\n' > reply: b'220 2.0.0 Ready to start TLS\r\n' > reply: retcode (220); Msg: b'2.0.0 Ready to start TLS' > Traceback (most recent call last): > ? ?File "/root/template_mail_text.py", line 49, in > ? ? ?server.starttls() > ? ?File "/usr/local/lib/python3.2/smtplib.py", line 649, in starttls > ? ? ?self.sock = ssl.wrap_socket(self.sock, keyfile, certfile) > ? ?File "/usr/local/lib/python3.2/ssl.py", line 509, in wrap_socket > ? ? ?ciphers=ciphers) > ? ?File "/usr/local/lib/python3.2/ssl.py", line 266, in __init__ > ? ? ?raise x > ? ?File "/usr/local/lib/python3.2/ssl.py", line 262, in __init__ > ? ? ?self.do_handshake() > ? ?File "/usr/local/lib/python3.2/ssl.py", line 441, in do_handshake > ? ? ?self._sslobj.do_handshake() > ssl.SSLError: [Errno 1] _ssl.c:392: error:140943FC:SSL > routines:SSL3_READ_BYTES:sslv3 alert bad record mac > > > -- > nirinA > -- > http://mail.python.org/mailman/listinfo/python-list > From g.rodola at gmail.com Thu May 19 05:30:18 2011 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 19 May 2011 11:30:18 +0200 Subject: test_argparse.py FAILED (failures=6) In-Reply-To: References: Message-ID: There's no point in posting this here. Use the bug tracker: http://bugs.python.org/ --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ 2011/5/17 nirinA raseliarison : > > ====================================================================== > FAIL: test_failures_many_groups_listargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ====================================================================== > FAIL: test_failures_many_groups_sysargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ====================================================================== > FAIL: test_failures_no_groups_listargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ====================================================================== > FAIL: test_failures_no_groups_sysargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ====================================================================== > FAIL: test_failures_one_group_listargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ====================================================================== > FAIL: test_failures_one_group_sysargs (__main__.TestFileTypeW) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 216, in wrapper > ? ?test_func(self) > ?File "Lib/test/test_argparse.py", line 235, in test_failures > ? ?raises(ArgumentParserError, parser.parse_args, args) > AssertionError: ArgumentParserError not raised by parse_args > > ---------------------------------------------------------------------- > Ran 1599 tests in 6.298s > > FAILED (failures=6) > > Traceback (most recent call last): > ?File "Lib/test/test_argparse.py", line 4681, in > ? ?test_main() > ?File "Lib/test/test_argparse.py", line 4673, in test_main > ? ?support.run_unittest(__name__) > ?File "/mnt/sda14/pack_build/Python-3.2.1rc1/Lib/test/support.py", line > 1184, in run_unittest > ? ?_run_suite(suite) > ?File "/mnt/sda14/pack_build/Python-3.2.1rc1/Lib/test/support.py", line > 1167, in _run_suite > ? ?raise TestFailed(err) > test.support.TestFailed: multiple errors occurred > > > -- > nirinA > -- > http://mail.python.org/mailman/listinfo/python-list > From nobody at nowhere.com Thu May 19 06:34:28 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 19 May 2011 11:34:28 +0100 Subject: connect SIGINT to custom interrupt handler References: <04cee22d-fc07-4c54-b91b-3f9e4730f095@glegroupsg2000goo.googlegroups.com> <18857efb-05be-42f0-8c62-40be5ec9dd26@gu8g2000vbb.googlegroups.com> Message-ID: On Wed, 18 May 2011 07:16:40 -0700, Jean-Paul Calderone wrote: > Setting SA_RESTART on SIGINT is probably the right thing to do. It's not > totally clear to me from the messages in this thread if you managed to get > that approach working. He didn't; select() isn't SA_RESTART-able. Unfortunately, the author of select.select() decided to treat EINTR as an error. It isn't; it's a "third way", neither success nor failure, similar to EAGAIN. Normally, you would treat EINTR from select() in the same way as a timeout. While it's possible to work around this, the interface encourages getting it wrong. From mail at agcasey.com Thu May 19 07:29:21 2011 From: mail at agcasey.com (Adrian Casey) Date: Thu, 19 May 2011 20:59:21 +0930 Subject: pexpect: TIMEOUT no longer clears child.before Message-ID: The behaviour of pexpect has changed between version 2.1 and 2.3. In version 2.1, the following code would result in child.before being cleared -: >>>child.expect(pexpect.TIMEOUT,1) In version 2.3, this is no longer the case. No matter how many times the above code is run, child.before continues to hold the output from previous commands. It is important to be able to clear the contents of child.before between each command. What is the correct way to do this in version 2.3? Adrian. From oisin.mulvihill at gmail.com Thu May 19 07:49:28 2011 From: oisin.mulvihill at gmail.com (Oisin Mulvihill) Date: Thu, 19 May 2011 12:49:28 +0100 Subject: pypi mirror In-Reply-To: <09b8851c-00ec-49ae-af85-93e55df91375@s9g2000yqm.googlegroups.com> References: <09b8851c-00ec-49ae-af85-93e55df91375@s9g2000yqm.googlegroups.com> Message-ID: Hi S?awek, You could also do a local or private egg repository. I documented how I did this for my internal projects here: http://www.sourceweaver.com/posts/private-python-egg-repository I hadn't come across z3c.pymirror before. All the best, Oisin On 19 May 2011 10:12, Slafs wrote: > Hi there. > > I would like to make a "local" mirror of some packages that are on > pypi. What options do You recommend ? > > I am leaning towards z3c.pypimirror because it was kind of first on my > google search results. > > Regards > > S?awek > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From luke.leighton at gmail.com Thu May 19 08:42:29 2011 From: luke.leighton at gmail.com (lkcl) Date: Thu, 19 May 2011 05:42:29 -0700 (PDT) Subject: python2+3 References: Message-ID: <42394efe-439f-4431-9b87-b70547f58c80@k17g2000vbn.googlegroups.com> [changing subject, seems a good idea...] On May 19, 2:13?am, Terry Reedy wrote: > On 5/18/2011 9:42 AM, lkcl wrote: > > > ? he's got a good point, terry. ?breaking backwards-compatibility was a > > completely mad and incomprehensible decision. > > I see that I should take everything you (or Harris) say with a big grain > of salt;-). *lol* - i realise it's a hell of a lot of work to get a python interpreter to support two different grammars and syntaxes: you can appreciate that i'm in a better position than most to understand that [i've also done a port of python to gnu-win32 so am familiar with the codebase] now that the code for both has been written, tested and proven, the task of adding one t't'othr is a leetle less of a challenging task. there is one teeny tiny annoying challenge: namespace clashes in c, of functions and data structures between the two codebases. however, this isn't as bad as it first seems. it's only the "public" face (Python.h) which has to remain the same, and that can be taken care of by having data structures that are identical internally and externally (macros to the rescue) where the internal name is Python2_xxxx and the external name Python_xxx. where it becomes less of a maintenance burden is when you say "ok, that's it: definitely end-of-the-road for all 2.N development, period". has anyone considered the idea of literally creating a Python2/ subdirectory in the python3 codebase, literally just dropping the entire python2.N code directly into it, renaming all functions and data structures, adding a "--2-compatible" switch to the python3 argc/ v and seeing what happens? no interoperability, no maintenance, no "compatibility" - just "support for python 2 directly in the python3 binary". l. From feeley at iro.umontreal.ca Thu May 19 08:54:13 2011 From: feeley at iro.umontreal.ca (Marc Feeley) Date: Thu, 19 May 2011 05:54:13 -0700 (PDT) Subject: Gambit REPL app for iPhone/iPod touch/iPad Message-ID: A version of the Gambit Scheme system for iPhone/iPod touch/iPad is now available on the Apple App Store: http://itunes.apple.com/us/app/gambit-repl/id434534076?mt=8&ls=1 "Gambit REPL" is a complete version of Gambit (http:// dynamo.iro.umontreal.ca/~gambit) including the interpreter, debugger and built-in library (but not the compiler). The standard REPL is provided and also a script editor. Scripts can be saved, attached to function keys, and the "main" function of the application can be redefined to customize the application to your needs. Applications can be debugged remotely by telneting to the device from a desktop machine. The application is sold for $0.99 as a demonstration that you can distribute on the App Store paid applications written in Scheme and containing an interpreter, something that wasn't clear with previous versions of the App Store developer agreement. A version of Gambit REPL for Android is not planned (by me). The Gambit Scheme system compiles fine on Android (for example see https://github.com/seoushi/gambit-android-example), but the user interface layer would have to be changed and tested, and I don't own an Android device. If someone wants to try porting Gambit REPL to Android let me know and I can help. The sources of Gambit REPL for iOS are in the examples/iOS subdirectory of the Gambit source distribution. Marc From Pietro.Abate at pps.jussieu.fr Thu May 19 09:10:57 2011 From: Pietro.Abate at pps.jussieu.fr (Pietro Abate) Date: Thu, 19 May 2011 15:10:57 +0200 Subject: Problem with multiprocessing Message-ID: <20110519131057.GA9082@pps.jussieu.fr> Hi all, I'm a bit struggling to understand a KeyError raised by the multiprocessing library. My idea is pretty simple. I want to create a server that will spawn a number of workers that will share the same socket and handle requests independently. The goal is to build a 3-tier structure where all requests are handled via an http server and then dispatched to nodes sitting in a cluster and from nodes to workers via the multiprocessing managers... There is one public server, one node per machine and x number of workers on each machine depending on the number of cores... I know I can use a more sophisticated library, but for such a simple task (I'm just prototyping here) I would just use the multiprocessing library... Is this possible or I should explore directly other solutions ? I feel I'm very close to have something working here ... The problem with the code below is that if I run the server as `python server.py 1` , that is, using only one process, it works as expected. However if I spawn two processes (`python server.py 2`) listening for connections, I get a nasty error : $python client.py ping Traceback (most recent call last): File "client.py", line 24, in sys.exit(main(sys.argv)) File "client.py", line 21, in main print m.solver(args[1])._getvalue() File "/usr/lib/python2.6/multiprocessing/managers.py", line 637, in temp authkey=self._authkey, exposed=exp File "/usr/lib/python2.6/multiprocessing/managers.py", line 894, in AutoProxy incref=incref) File "/usr/lib/python2.6/multiprocessing/managers.py", line 700, in __init__ self._incref() File "/usr/lib/python2.6/multiprocessing/managers.py", line 750, in _incref dispatch(conn, None, 'incref', (self._id,)) File "/usr/lib/python2.6/multiprocessing/managers.py", line 79, in dispatch raise convert_to_error(kind, result) multiprocessing.managers.RemoteError: --------------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.6/multiprocessing/managers.py", line 181, in handle_request result = func(c, *args, **kwds) File "/usr/lib/python2.6/multiprocessing/managers.py", line 402, in incref self.id_to_refcount[ident] += 1 KeyError: '7fb51084c518' --------------------------------------------------------------------------- My understanding is that all processes share the same socket (from the Manager). When a client wants to connect, a new connection is created and server independently by that process. If you look at the server trace (using logging), it actually receives the connection, handles it, but fails to communicate back to the client. Can anybody shed some light for me and maybe propose a solution ? thanks pietro ---------------------------------------- Server : import sys from multiprocessing.managers import BaseManager, BaseProxy, Process def baz(aa) : l = [] for i in range(3) : l.append(aa) return l class SolverManager(BaseManager): pass class MyProxy(BaseProxy): pass manager = SolverManager(address=('127.0.0.1', 50000), authkey='mpm') manager.register('solver', callable=baz, proxytype=MyProxy) def serve_forever(server): try : server.serve_forever() except KeyboardInterrupt: pass def runpool(n): server = manager.get_server() workers = [] for i in range(int(n)): Process(target=serve_forever, args=(server,)).start() if __name__ == '__main__': runpool(sys.argv[1]) Client : import sys from multiprocessing.managers import BaseManager, BaseProxy import multiprocessing, logging class SolverManager(BaseManager): pass class MyProxy(BaseProxy): pass def main(args) : SolverManager.register('solver') m = SolverManager(address=('127.0.0.1', 50000), authkey='mpm') m.connect() print m.solver(args[1])._getvalue() if __name__ == '__main__': sys.exit(main(sys.argv)) also tried on stack overflow and the python list, but I didn't manage to come up with a working solution yet... -- ---- http://en.wikipedia.org/wiki/Posting_style From luke.leighton at gmail.com Thu May 19 09:17:58 2011 From: luke.leighton at gmail.com (lkcl) Date: Thu, 19 May 2011 06:17:58 -0700 (PDT) Subject: pyjamas 0.8alpha1 release References: <1fa81c6a-7b00-4bbb-b7e1-dc5b7a4aaa12@u26g2000vby.googlegroups.com> Message-ID: On May 18, 11:02?pm, Terry Reedy wrote: > On 5/18/2011 5:24 AM, lkcl wrote: > > There seem to be two somewhat separate requirement issues: the > interpreter binary and the language version. yes. [with the startling possibility of compiling the entire pyjs compiler into javascript and executing under e.g. spidermonkey's /usr/ bin/js turning that into just the one requirement - but that's another story] > > ? a) at the moment ahttp://python.org2.N interpreter is required to > > actually run the translator. ?if you usehttp://python.org2.5 or 2.6 > > you do not need to use the "--internal-ast" option. ?if you use 2.4, > > 2.7 or above, you will need to use --internal-ast because we're > > heavily reliant on the internal c-based "compile" module [without the > > --internal-ast option enabled]. > > I presume '--internal-ast' is a 'compile the interpreter' option. mmm... sort of. what it does is, in translator.py (the pyjs python- to-javascript compiler) is this: if options.internal_ast: import pyjamas.pgen.compile as compile # python version of compile module else: import compile # standard python compile module that "internal" compile module contains a complete independent grammar.txt file, and is basically lib2to3 re-ported *back* to being interoperable with, and a complete replacement for, the standard python "compile" module. including the ast module. we haven't *quite* got round to doing a "compile the interpreter" yet - it's half way there. the work that daniel kluev is doing, for his gsoc2011 project, will be a complete "compile the interpreter". by the time he's done, we'll even have "eval()" and "exec()" builtins... inside a web browser. > Since > I have never compilied Python (or anything else for perhaps 15 years), I > do not understand completely. Am I correct to guess that the PSF Windows > binaries for 2.7 were not compiled with the flag, and will not work? If > so, Windows users should, I would think, use the latest 2.6.6 binaries. ahh... i'm reading this as "requiring http://python.org c code to be compiled with different compilation flags". this isn't anything to do with compiling c-code: "pyjs the translator" is and always will be a pure vanilla python application, requiring absolutely no modifications to the python interpreter whatsoever. the --internal-ast option is an option which is passed to the pyjs application (which is a pure and vanilla python application). here's an example, shows the inter-relationships: /usr/bin/python pyjsbuild.py --internal-ast Hello.py python.exe pyjsbuild.py --internal-ast Hello.py * /usr/bin/python or python.exe - python2.N. * pyjsbuild.py - the pyjs python-to-javascript translator * --internal-ast - an option to pyjsbuild to tell it to use a version of compiler.ast which is written in pure python [and supports the 2.6 grammar] * Hello.py - the pyjamas application, written in python, being translated to javascript, for execution in a web browser. > > ? b) the actual pyjs interpreter grammar (AST) was 2.5 but has mostly > > been updated to 2.6. ?actual python syntax / features are therefore > > mostly 2.5, with someone having pointed out that "slice" has different > > return results it's hard to say exactly which is best to be picked, > > 2.5 or 2.6. ?nobody's needed slice until recently, so it's not an > > issue that's ever come up before. > > If I understand this, the safe thing to do is to stick with 2.5 syntax > and omit exotic 3.x features put into 2.6 for eventual porting to 3.x. yes. that would be the easiest path. however, we have a teeny problem: pyjamas desktop (pyjd). that's where you get to *really* execute the python code, exactly the same code that you munged through the pyjs compiler. in the pyjd case, what is going on is that it is *python* that has access to the features of the web browser engine (DOM functions, HTML5 etc.) and that is... ho hum, each engine is itself a massive project, and has to be a python c module (except for the MSHTML engine, which is COM). so for pyjd, we *have* to support whatever the latest easiest python 2.N is. that in turn dictates that we have to keep up-to-date with the python 2.N syntax/grammar, and, consequently, it dictates logically that the pyjs compiler, which *must* be interoperable with pyjd, must also support the latest python 2.N syntax/grammar. bummer, huh? :) fortunately, nobody on the pyjamas mailing list has really noticed that there _are_ any differences (!) between 2.5, 6 and 7 - except for daniel kluev, the gsoc2011 student, who is using pyjs with python-pyv8 to actually create a version of a python interpreter... by translating everything to javascript! the reason why they haven't really noticed is because the use-case for pyjamas UI code is much much smaller (due to web browsers being a restricted execution environment - see ongoing discussion below). > > ? the thing is - it's worth reiterating: you just... really don't need > > as much python interoperability for user-interfaces when they're split > > along MVC lines. ?bear in mind that it's necessary to do that split: > > it's web browser technology, you can't *actually* execute things like > > psycopg or mysql in a web browser as javascript! ?so once you've > > divided that application into "python that runs the actual user > > interface" and "python on the other side of the AJAX barrier e.g. a > > django app" you're left with a far smaller task for the pyjs > > interpreter to have to tackle. > > I do not get all this but it seems to say that I do not really need all > the features of the later Pythons to write user-interface code. by a roundabout route... yes. it's due to web browsers being a massively restricted environment. > But I am > not sure how this applies to business code behind the front end. Of > course, it might work to run the UI in a separate process if on the same > machine. ok, that's basically what happens: it's not like there is any choice in the matter. the python UI code has been translated to javascript: it's now an AJAX application, not a python application. the UI code therefore runs in that browser's "separate process". it's a highly restricted execution environment that's very very well-defined, and you cannot, *cannot* in any way go outside of the boundaries, as defined by W3C (sort-of). the only access to the outside world is either AJAX, HTML5 Sockets (if supported), or for the user to agree to the installation of a plugin (such as silverlight, java, adobe flash, or god forbid the xulrunner / firefox "language=python" extension which was sponsored by the mozilla foundation back in 2000 - it quite literally embeds the entire libpython library into a firefox plugin!) so, you REALLY have to subdivide the application, just as you have to subdivide *any* AJAX application, into "front-end", "back-end". at the front-end, you can do anything... as long as it's restricted javascript; at the back-end (server-side) you can do ANYTHING. django, whatever - even php or .net if you're feeling sick... this does take quite a long time to sink in :) even i had difficulty appreciating that yes, you can write UI web applications *in python*, but nooo, you can't *actually* execute that python code in the web browser, and consequently nooo, you cannot have "standard" python modules in the web browser. it's kinda like pypy - you can have anything you like, as long as it's in pure python [so it can be translated to javascript]. l. From drsalists at gmail.com Thu May 19 11:05:10 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 19 May 2011 08:05:10 -0700 Subject: Problem with multiprocessing In-Reply-To: <20110519131057.GA9082@pps.jussieu.fr> References: <20110519131057.GA9082@pps.jussieu.fr> Message-ID: Share as little as possible between your various processes - shared, mutable state is a parallelism tragedy. If you can avoid sharing an entire dictionary, do so. It'd probably be better to dedicate one process to updating your dictionary, and then using a multiprocessing.Queue to pass delta records from your workers to your dictionary management process. Also, I'm inclined to doubt it's going to work well to have multiple processes doing I/O on the same socket - you'd probably best have a process that does all the I/O on the socket, and then, again, have one or more multprocessing.Queue's that pass I/O results/requests around. On Thu, May 19, 2011 at 6:10 AM, Pietro Abate wrote: > Hi all, > > I'm a bit struggling to understand a KeyError raised by the multiprocessing > library. > > My idea is pretty simple. I want to create a server that will spawn a > number of > workers that will share the same socket and handle requests independently. > The > goal is to build a 3-tier structure where all requests are handled via an > http > server and then dispatched to nodes sitting in a cluster and from nodes to > workers via the multiprocessing managers... > > There is one public server, one node per machine and x number of workers on > each machine depending on the number of cores... I know I can use a more > sophisticated library, but for such a simple task (I'm just prototyping > here) I > would just use the multiprocessing library... Is this possible or I should > explore directly other solutions ? I feel I'm very close to have something > working here ... > > The problem with the code below is that if I run the server as > `python server.py 1` , that is, using only one process, it works as > expected. > > However if I spawn two processes (`python server.py 2`) listening for > connections, I get a nasty error : > > $python client.py ping > Traceback (most recent call last): > File "client.py", line 24, in > sys.exit(main(sys.argv)) > File "client.py", line 21, in main > print m.solver(args[1])._getvalue() > File "/usr/lib/python2.6/multiprocessing/managers.py", line 637, in > temp > authkey=self._authkey, exposed=exp > File "/usr/lib/python2.6/multiprocessing/managers.py", line 894, in > AutoProxy > incref=incref) > File "/usr/lib/python2.6/multiprocessing/managers.py", line 700, in > __init__ > self._incref() > File "/usr/lib/python2.6/multiprocessing/managers.py", line 750, in > _incref > dispatch(conn, None, 'incref', (self._id,)) > File "/usr/lib/python2.6/multiprocessing/managers.py", line 79, in > dispatch > raise convert_to_error(kind, result) > multiprocessing.managers.RemoteError: > > --------------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python2.6/multiprocessing/managers.py", line 181, in > handle_request > result = func(c, *args, **kwds) > File "/usr/lib/python2.6/multiprocessing/managers.py", line 402, in > incref > self.id_to_refcount[ident] += 1 > KeyError: '7fb51084c518' > > --------------------------------------------------------------------------- > > My understanding is that all processes share the same socket (from the > Manager). When a client wants to connect, a new connection is created and > server independently by that process. If you look at the server trace > (using > logging), it actually receives the connection, handles it, but fails to > communicate back to the client. > > Can anybody shed some light for me and maybe propose a solution ? > > thanks > pietro > > ---------------------------------------- > > Server : > > import sys > from multiprocessing.managers import BaseManager, BaseProxy, Process > > def baz(aa) : > l = [] > for i in range(3) : > l.append(aa) > return l > > class SolverManager(BaseManager): pass > > class MyProxy(BaseProxy): pass > > manager = SolverManager(address=('127.0.0.1', 50000), authkey='mpm') > manager.register('solver', callable=baz, proxytype=MyProxy) > > def serve_forever(server): > try : > server.serve_forever() > except KeyboardInterrupt: > pass > > def runpool(n): > server = manager.get_server() > workers = [] > > for i in range(int(n)): > Process(target=serve_forever, args=(server,)).start() > > if __name__ == '__main__': > runpool(sys.argv[1]) > > > Client : > > import sys > from multiprocessing.managers import BaseManager, BaseProxy > > import multiprocessing, logging > > class SolverManager(BaseManager): pass > > class MyProxy(BaseProxy): pass > > def main(args) : > SolverManager.register('solver') > m = SolverManager(address=('127.0.0.1', 50000), authkey='mpm') > m.connect() > > print m.solver(args[1])._getvalue() > > if __name__ == '__main__': > sys.exit(main(sys.argv)) > > > also tried on stack overflow and the python list, but I didn't manage to > come up > with a working solution yet... > > -- > ---- > http://en.wikipedia.org/wiki/Posting_style > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.net.no Thu May 19 12:02:08 2011 From: nobody at nowhere.net.no (TheSaint) Date: Fri, 20 May 2011 00:02:08 +0800 Subject: how to get PID from subprocess library Message-ID: hello, I'm using to launch a program by subprocess.getstatusoutput. I'd like to know whether I can get the program ID, in order to avoid another launch. For clarity sake, I'm calling aria2 (the download manager for linux) and I wouldn't like to call one more instance of it. So what will I use to find the PID of the launched program? -- goto /dev/null From miki.tebeka at gmail.com Thu May 19 12:05:38 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 19 May 2011 09:05:38 -0700 (PDT) Subject: how to get PID from subprocess library In-Reply-To: Message-ID: The best module for doing such things is subprocess. And the Popen object has a pid attribute (http://docs.python.org/library/subprocess.html#subprocess.Popen.pid) From debatem1 at gmail.com Thu May 19 13:23:47 2011 From: debatem1 at gmail.com (geremy condra) Date: Thu, 19 May 2011 10:23:47 -0700 Subject: obviscating python code for distribution In-Reply-To: <4vlea8-55t.ln1@svn.schaathun.net> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 10:21 PM, Hans Georg Schaathun wrote: > On Wed, 18 May 2011 14:34:46 -0700, geremy condra > ? wrote: > : ?Systems can be designed that are absolutely secure under reasonable > : ?assumptions. The fact that it has assumptions does not make your > : ?statement true. > : (...) > : ?I can't tell if you're trying to play word games with the distinction > : ?between "system" and "module" or if you're just saying that you aren't > : ?sure what FIPS actually certifies. Could you please clarify? > > The distinction between system and module is rather significant. > If you only consider modules, you have bounded your problem and > drastically limited the complexity. Ah, the 'word games' option. I'm not going to spend a lot of time arguing this one: HSMs are clearly the domain of systems research, are referred to in both technical and nontechnical documents as 'keystone systems', and the FIPS standard under which they are certified specifically calls them systems more times than I care to count. They are, to the people who make and use them, systems, and your attempt at redefinition won't change that. > : ?Are you talking about the Mayfair classical cipher here? > > I am talking about the system used in public transport cards like > Oyster and Octopus. ?I am not sure how classical it is, or whether > mayfair/mayfare referred to the system or just a cipher. ?Any way, > it was broken, and it took years. Ah, MIFARE. That's a different story, and no, I don't believe they would have been broken sooner if the specs were released. The importance (and difficulty) of securing devices like smartcards wasn't really recognized until much later, and certainly people with a foot in both worlds were very rare for a long time. Also remember that DES (with its 56-bit keys) was recertified just a few months before MIFARE (with its 48-bit keys) was first released- it was a different world. > : ?The entire field of formal modeling and verification has grown around > : ?solving this problem. My new favorite in the field is "formal models > : ?and techniques for analyzing security protocols", but there are other > : ?works discussing OS kernel verification (which has gotten a lot of > : ?attention lately) and tons of academic literature. Google (scholar) is > : ?the place to go. > > Sure, but now you are considering modules, rather than systems again. > It is when these reliable components are put together to form systems > that people fail (empirically). Let me get this straight: your argument is that operating *systems* aren't systems? > : ?If you can't say with confidence that something meets minimum security > : ?standards, the answer is not to try to say it meets high security > : ?standards. > > So what? ?The levels of assurance have nothing to do with standards. > The levels of assurance refer to the /confidence/ you can have that > the standards are met. The increasing levels of assurance don't just signify that you've checked for problems- it certifies that you don't have them, at least insofar as that level of testing is able to find. Insisting that this doesn't, or shouldn't, translate into tighter security doesn't make much sense. Geremy Condra From debatem1 at gmail.com Thu May 19 13:50:55 2011 From: debatem1 at gmail.com (geremy condra) Date: Thu, 19 May 2011 10:50:55 -0700 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: On Wed, May 18, 2011 at 7:54 PM, harrismh777 wrote: > Littlefield, Tyler wrote: > Four resources that you will what to look into, in no particular order: > > Erickson, Jon, "Hacking: The Art of Exploitation," 2nd ed, > ? ? ? ?San Francisco: No Starch Press, 2008. This would be a very good choice. It's a bit light on details, but makes up for it by being exceptionally well-written and very accessible. > Anonymous, "Maximum Linux Security: A Hacker's Guide to Protecting > ? ? ? ?Your Linux Server and Workstation," Indianapolis: > ? ? ? ?Sams Publishing, 2000. > > ? ? ? ?(check for other editions) > ? ? ? ?(this volume is a good read, even for other platforms, > ? ? ? ? ? ? ? ?but is geared specifically to Linux) This is a good volume, but very dated. I'd probably pass on it. > Graves, Kimberly, "CEH Certified Ethical Hacker: Study Guide," > ? ? ? ?Indianapolis: Wiley Publishing, 2010. Briefly glancing over the TOC, this actually looks surprisingly good. CEH itself is a joke among black hats, but if this gets down to the nitty-gritty of actually performing the attacks it covers it sounds like a buy. > Seitz, Justin, "Gray Hat Python: Python Programming for Hackers > ? ? ? ?and Reverse Engineers," San Francisco: No Starch Press, 2009. I'd skip this one, as it isn't really focused on what you want. The web application hacker's handbook is probably more along the lines of what you need, if you're going for a book. There's also an older volume called 'counter hack' that gives a good overview of some of the ways that attacks proceed. Another recommend I'm surprised hasn't popped up already: 'security power tools' is a good way to get your foot in the door. It has a practical, no-nonsense approach and is split into self-contained chapters so you don't waste too much of your time on tools that aren't relevant to you. Geremy Condra From myeates at jpl.nasa.gov Thu May 19 14:03:34 2011 From: myeates at jpl.nasa.gov (Mathew) Date: Thu, 19 May 2011 11:03:34 -0700 Subject: Windows Registry Keys Message-ID: Hi I have installed a new version of Python27 in a new directory. I want to get this info into the registry so, when I install Numpy, it will use my new Python TIA -Mathew From hg at schaathun.net Thu May 19 14:23:28 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Thu, 19 May 2011 19:23:28 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> Message-ID: <0q3ga8-s2v.ln1@svn.schaathun.net> On Thu, 19 May 2011 10:23:47 -0700, geremy condra wrote: : Let me get this straight: your argument is that operating *systems* : aren't systems? You referred to the kernel and not the system. The complexities of the two are hardly comparable. There probably are different uses of system; in computer security literature? it often refers, not only to a product (hardware/software) an actual installation and configuration of that product in a specific context. /I/ did not redefine it. Speaking of reasonable assumptions, one necessary assumption which is particularly dodgy is that whoever deploys and configures it understands all the assumptions and do not break them through ignorance. Is your concern with security purely from a developer's viewpoint, so that you don't have to worry about the context in which it will be deployed? : > So what? ?The levels of assurance have nothing to do with standards. : > The levels of assurance refer to the /confidence/ you can have that : > the standards are met. : : The increasing levels of assurance don't just signify that you've : checked for problems- it certifies that you don't have them, at least : insofar as that level of testing is able to find. Insisting that this : doesn't, or shouldn't, translate into tighter security doesn't make : much sense. Tighter sure, but the security requirements and the requirement on testing and/or validation are orthogonal scales. The higher levels of assurance are based on formal methods while the lower ones are based primarily on testing. I read your initial comment to imply that if you cannot get satisfactory assurance using the lower levels, you won't get any at the higher levels. That does not make any sense. Obviously, if you were implying that no system passes the lower levels, then of course they won't pass the higher levels, but then, if that's the case, we would all know that we cannot even design /seemingly/ secure systems. And nobody has suggested that so far. ? e.g. Dieter Gollmann for just one ref off the top of my head. -- :-- Hans Georg From ayaskanta.swain at altair.com Thu May 19 15:37:22 2011 From: ayaskanta.swain at altair.com (Ayaskanta Swain) Date: Fri, 20 May 2011 01:07:22 +0530 Subject: os.access giving incorrect results on Windows Message-ID: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> Hi All, Please help me in solving this issue. I want to check the write permissions on a directory on windows from my python script. I tried to use os.access(dirpath, os.W_OK) to check whether the user has write access or not, but it gives me incorrect result. It always gives me False even if the user has write permission. Interestingly this function works just fine on Linux platforms. There is another way to check the write permissions by creating a temporary file inside the directory & then removing it. Catch the exception if create file is not allowed to decide the iswritable value. But this is changing the last modification time (timestamp) of the directory which is a critical issue for our application. Please suggest a solution. Thanks Ayaskant- -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Thu May 19 15:43:55 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 19 May 2011 20:43:55 +0100 Subject: os.access giving incorrect results on Windows In-Reply-To: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> Message-ID: <4DD572FB.2010809@timgolden.me.uk> On 19/05/2011 20:37, Ayaskanta Swain wrote: > Please help me in solving this issue. I want to check the write > permissions on a directory on windows from my python script. > > I tried to use *os.access(dirpath, os.W_OK)*to check whether the user > has write access or not, but it gives me incorrect result. It always > gives me False even if the user has write permission. Interestingly this > function works just fine on Linux platforms. This is basically issue2528 [1]. The problem is that, although Windows (and Python) expose a version of os.access to match the Posix function, the meaning is so far removed on Windows as to be useless. Really what you need to do is use the AccessCheck API, which is a little bit tortuous, but is intended for this purpose. You can look at the code in my patch for that issue to get an idea of how to do it. Does that help? TJG [1] http://bugs.python.org/issue2528 From bahamutzero8825 at gmail.com Thu May 19 15:56:17 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 19 May 2011 14:56:17 -0500 Subject: os.access giving incorrect results on Windows In-Reply-To: <4DD572FB.2010809@timgolden.me.uk> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> <4DD572FB.2010809@timgolden.me.uk> Message-ID: <4DD575E1.9060801@gmail.com> On 2011.05.19 02:43 PM, Tim Golden wrote: > This is basically issue2528 [1]. > The problem is that, although Windows (and Python) > expose a version of os.access to match the Posix function, > the meaning is so far removed on Windows as to be useless. Does this affect just os.W_OK and directories or all of os.access()? In any case, this information should really be reflected in the docs. From efotinis at yahoo.com Thu May 19 16:05:18 2011 From: efotinis at yahoo.com (Elias Fotinis) Date: Thu, 19 May 2011 23:05:18 +0300 Subject: Windows Registry Keys References: Message-ID: On Thu, 19 May 2011 21:03:34 +0300, Mathew wrote: > I have installed a new version of Python27 in a new directory. I want to get > this info into the registry so, when I install Numpy, it will use my new > Python If I understand correctly (you have multiple Python 2.7 installations and what to make this new one the current), you should change this key: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath (ignore "Wow6432Node" if you are not on 64-bit Windows) That'd would probably be enough for the Numpy installer. I assume you are aware about the changes that may be required to the PATH and file associations. From mail at timgolden.me.uk Thu May 19 16:08:15 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 19 May 2011 21:08:15 +0100 Subject: os.access giving incorrect results on Windows In-Reply-To: <4DD575E1.9060801@gmail.com> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> <4DD572FB.2010809@timgolden.me.uk> <4DD575E1.9060801@gmail.com> Message-ID: <4DD578AF.3000001@timgolden.me.uk> On 19/05/2011 20:56, Andrew Berg wrote: > On 2011.05.19 02:43 PM, Tim Golden wrote: >> This is basically issue2528 [1]. >> The problem is that, although Windows (and Python) >> expose a version of os.access to match the Posix function, >> the meaning is so far removed on Windows as to be useless. > Does this affect just os.W_OK and directories or all of os.access()? > > In any case, this information should really be reflected in the docs. The current code is very naive: * A R_OK check always succeeds if the file's attributes can be read at all * A W_OK check fails if the file has its DOS read-only attribute set * A W_OK check always succeeds for a directory (because read-only means something else for directories). Would you care to propose some wording for the docs? I'm quite happy to commit if we can come to an agreement. TJG From weidezhang2007 at gmail.com Thu May 19 16:18:20 2011 From: weidezhang2007 at gmail.com (Walter Chang) Date: Thu, 19 May 2011 13:18:20 -0700 (PDT) Subject: application level monitoring for python Message-ID: <7281a33b-a32c-4eba-8646-82d9cef459b1@m10g2000yqd.googlegroups.com> Hi is there any open source library for python that can allow application level monitoring ? For example,application can send per request level/ aggregated monitoring events and some remote server dump it and show in the monitoring graph in real time ? What's best way of doing that ? From bahamutzero8825 at gmail.com Thu May 19 16:40:26 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 19 May 2011 15:40:26 -0500 Subject: os.access giving incorrect results on Windows In-Reply-To: <4DD578AF.3000001@timgolden.me.uk> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> <4DD572FB.2010809@timgolden.me.uk> <4DD575E1.9060801@gmail.com> <4DD578AF.3000001@timgolden.me.uk> Message-ID: <4DD5803A.4080208@gmail.com> On 2011.05.19 03:08 PM, Tim Golden wrote: > * A R_OK check always succeeds if the file's attributes can be read > at all So is this the same as F_OK then, or does it return false if the user isn't allowed to read permissions? > * A W_OK check fails if the file has its DOS read-only attribute set DOS attribute? > * A W_OK check always succeeds for a directory (because read-only means > something else for directories). > > Would you care to propose some wording for the docs? I'm quite happy > to commit if we can come to an agreement. I'm a beginner when it comes to Python, but I could give it a shot. A big red warning box explaining how the code under Windows doesn't use ACLs under the os.access() entry (above the notes) seems appropriate. A warning box under os.W_OK saying something like "Under Windows, access() will always indicate that a directory is writable." would also fit. You know more about this than I do. I'm running Windows 7 right now and I have a Python 3.2 interpreter window open if you want me to test/confirm something. :-) From skunkworks at rikishi42.net Thu May 19 17:21:30 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Thu, 19 May 2011 23:21:30 +0200 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On 2011-05-18, Hans Georg Schaathun wrote: > Now Mac OS X has maintained the folder concept of older mac generations, > and Windows has cloned it. They do not want the user to understand > recursive data structures, and therefore, naturally, avoid the word. You imply they want to keep their users ignorant of these structures, as if to keep something valuable from them. Wouldn't it be more honest, more to the point and much simpler to state they don't NEED the user to understand recursive - or indeed any other - data structures? And that the user doesn't NEED to understand or know about them, just to use them? After all they are users. They use their system for fun, learning or work. Even a very competent or advanced use of a tool (computer, car, mobile phone, fridge, TV, radio, toilet) in no way implies an understanding of it's inner workings. Nor the need, nor the desire. PS: Isn't this thread much ado about nothing? :-) It starts with the misconception (or should I say confusion?) between performing a recursive job and using a recursive tool to do it. And then it blazes off in these huge discusions about semantics to define a definition of an abstraction of a alleady theoretical problem. Glorious, just frelling glorious. :-) We have an expression for that. But I'll avoid using it, since it has the word 'masturbation' in it... And PPS: the P(P)S's don't specifically refer to your posting. -- When in doubt, use brute force. -- Ken Thompson From bahamutzero8825 at gmail.com Thu May 19 17:35:09 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 19 May 2011 16:35:09 -0500 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD0D1A2.6060109@free.fr> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> Message-ID: <4DD58D0D.4050508@gmail.com> On 2011.05.16 02:26 AM, Karim wrote: > Use regular expression for bad HTLM or beautifulSoup (google it), below > a exemple to extract all html links: Actually, using regex wasn't so bad: > import re > import urllib.request > > url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth' > page = str(urllib.request.urlopen(url).read(), encoding='utf-8') # > urlopen() returns a bytes object, need to get a normal string > rev_re = re.compile('revision[0-9][0-9][0-9][0-9]') > num_re = re.compile('[0-9][0-9][0-9][0-9]') > rev = rev_re.findall(str(page))[0] # only need the first item since > the first listing is the latest revision > num = num_re.findall(rev)[0] # findall() always returns a list > print(num) prints out the revision number - 1995. 'revision1995' might be useful, so I saved that to rev. This actually works pretty well for consistently formatted lists. I suppose I went about this the wrong way - I thought I needed to parse the HTML to get the links and do simple regexes on those, but I can just do simple regexes on the entire HTML document. From karim.liateni at free.fr Thu May 19 17:52:20 2011 From: karim.liateni at free.fr (Karim) Date: Thu, 19 May 2011 23:52:20 +0200 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD58D0D.4050508@gmail.com> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD58D0D.4050508@gmail.com> Message-ID: <4DD59114.1080405@free.fr> On 05/19/2011 11:35 PM, Andrew Berg wrote: > On 2011.05.16 02:26 AM, Karim wrote: >> Use regular expression for bad HTLM or beautifulSoup (google it), below >> a exemple to extract all html links: > Actually, using regex wasn't so bad: >> import re >> import urllib.request >> >> url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth' >> page = str(urllib.request.urlopen(url).read(), encoding='utf-8') # >> urlopen() returns a bytes object, need to get a normal string >> rev_re = re.compile('revision[0-9][0-9][0-9][0-9]') >> num_re = re.compile('[0-9][0-9][0-9][0-9]') >> rev = rev_re.findall(str(page))[0] # only need the first item since >> the first listing is the latest revision >> num = num_re.findall(rev)[0] # findall() always returns a list >> print(num) > prints out the revision number - 1995. 'revision1995' might be useful, > so I saved that to rev. > > This actually works pretty well for consistently formatted lists. I > suppose I went about this the wrong way - I thought I needed to parse > the HTML to get the links and do simple regexes on those, but I can just > do simple regexes on the entire HTML document. Great for you! Use what works well and easy to code, always the simpler is the better. For complicate search link to avoid using too complex and bugs prone regex you can derived the code I gave on HTMLParser with max comparison. Anyway you get the choice which is cool, not be stuck on only one solution. Cheers Karim From ethan at stoneleaf.us Thu May 19 18:18:22 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 19 May 2011 15:18:22 -0700 Subject: Trying to understand html.parser.HTMLParser In-Reply-To: <4DD1C9D5.4070206@gmail.com> References: <4DD03B69.6050301@gmail.com> <4DD0D1A2.6060109@free.fr> <4DD1C9D5.4070206@gmail.com> Message-ID: <4DD5972E.1080205@stoneleaf.us> Andrew Berg wrote: > ElementTree doesn't seem to have been updated in a long time, so I'll > assume it won't work with Python 3. I don't know how to use it, but you'll find ElementTree as xml.etree in Python 3. ~Ethan~ From steve+comp.lang.python at pearwood.info Thu May 19 18:40:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 May 2011 22:40:16 GMT Subject: python2+3 References: <42394efe-439f-4431-9b87-b70547f58c80@k17g2000vbn.googlegroups.com> Message-ID: <4dd59c50$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 May 2011 05:42:29 -0700, lkcl wrote: > has anyone considered the idea of literally creating a Python2/ > subdirectory in the python3 codebase, literally just dropping the entire > python2.N code directly into it, renaming all functions and data > structures, adding a "--2-compatible" switch to the python3 argc/ v and > seeing what happens? > > no interoperability, no maintenance, no "compatibility" - just > "support for python 2 directly in the python3 binary". No maintenance? The code won't maintain itself, people using it won't stop reporting bugs. Are you suggesting that the CPython developers should just grit their teeth and refuse to maintain or support code that is part of the official release? Who is your suggested user-base? Those who want support for 2.7 to continue won't be happy with an unmaintained, unsupported compatibility layer. Those who are happy to keep on using obsolete software won't need this compatibility layer, they can just keep using the Python 2.7 they already have. Or 2.5, or 1.5 if they prefer. (I have 1.5 on my machine, installed from source, and it works perfectly well.) And what of the others? Jython, IronPython, PyPy, Stackless ... once they make the move to Python 3 compatibility, are they expected to implement this compatibility layer as well? I dare say that once the original developers stop supporting Python 2.7 in three or seven(?) years, there will be a good niche for some commercial distribution like ActiveState to continue support. Or one of the many critics who insist that Python 3 is a mistake can put their money where their mouth is and continue support themselves. After all, Python is open source. Somebody (you?) could even fork the code base and implement your suggested compatibility layer, or backport Python 3 features, be really daring and create a 2/3 hybrid. -- Steven From steve+comp.lang.python at pearwood.info Thu May 19 18:47:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 May 2011 22:47:58 GMT Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> Message-ID: <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> On Tue, 17 May 2011 10:02:21 -0700, geremy condra wrote: > or O(1): > > ? = (1 + sqrt(5)) / 2 > def fib(n): > numerator = (?**n) - (1 - ?)**n > denominator = sqrt(5) > return round(numerator/denominator) I'd just like to point out that, strictly speaking, it's only O(1) if you assume that exponentiation is O(1). Computer scientists often like to make this simplifying assumption, and it might even be true for floats, but for long ints and any numeric data types with unlimited precision, it won't be. -- Steven From tar at sevak.isi.edu Thu May 19 19:14:14 2011 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 19 May 2011 16:14:14 -0700 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] Ignored, since I don't follow that group. > On Wed, 18 May 2011 20:20:01 +0200, Raymond Wiker > wrote: > : I don't think anybody mentioned *binary* trees. The context was > : directory traversal, in which case you would have nodes with an > : arbitrary (almost) number of children. > > If we are being specific, then directory trees do have parent pointers. > My point was really that ?standard tree representations? is not a > well-defined concept, and having parent pointers is as standard as > not having them. I suppose that I just assumed the standard mathematical definition of a tree as a directed, acyclic graph. It seems that in the context of computability that one would tend toward using the mathematical definitions. Certainly in a complex graph with labeled links or trees with backpointers, you would have an alternate data structure that you could follow. So, to be more precise, then: For directed, acyclic graphs without backpointers, you cannot write an iterative tree walker without simulating a stack. The larger point is that there are algorithms that are inherently recursive and for which there is no natural iterative algorithm. -- Thomas A. Russ, USC/Information Sciences Institute From tar at sevak.isi.edu Thu May 19 19:17:53 2011 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 19 May 2011 16:17:53 -0700 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <8762p7omzu.fsf@kuiper.lan.informatimago.com> Message-ID: "Pascal J. Bourguignon" writes: > tar at sevak.isi.edu (Thomas A. Russ) writes: > > > > This will only work if there is a backpointer to the parent. > > No, you don't need backpointers; some cases have been mentionned in the > other answer, but in general: > > (defun parent (tree node) > (if (member node (children tree)) > tree > (some (lambda (child) (parent child node)) (children tree)))) > > Yes, the question wasn't about time complexity. :-p Um, this is a recursive function. Inside PARENT, there is another call to PARENT. -- Thomas A. Russ, USC/Information Sciences Institute From rosuav at gmail.com Thu May 19 19:37:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 09:37:59 +1000 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 8:47 AM, Steven D'Aprano wrote: > On Tue, 17 May 2011 10:02:21 -0700, geremy condra wrote: > >> or O(1): >> >> ? = (1 + sqrt(5)) / 2 >> ? ? numerator = (?**n) - (1 - ?)**n > > I'd just like to point out that, strictly speaking, it's only O(1) if you > assume that exponentiation is O(1). Computer scientists often like to > make this simplifying assumption, and it might even be true for floats, > but for long ints and any numeric data types with unlimited precision, it > won't be. > Python doesn't have arbitrary precision non-integers, does it? So this is going to be done with floats. Chris Angelico From debatem1 at gmail.com Thu May 19 20:03:45 2011 From: debatem1 at gmail.com (geremy condra) Date: Thu, 19 May 2011 17:03:45 -0700 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 19, 2011 at 3:47 PM, Steven D'Aprano wrote: > On Tue, 17 May 2011 10:02:21 -0700, geremy condra wrote: > >> or O(1): >> >> ? = (1 + sqrt(5)) / 2 >> def fib(n): >> ? ? numerator = (?**n) - (1 - ?)**n >> ? ? denominator = sqrt(5) >> ? ? return round(numerator/denominator) > > I'd just like to point out that, strictly speaking, it's only O(1) if you > assume that exponentiation is O(1). Computer scientists often like to > make this simplifying assumption, and it might even be true for floats, > but for long ints and any numeric data types with unlimited precision, it > won't be. Great point, and something I should have paid attention to. Thanks. Geremy Condra From pjb at informatimago.com Thu May 19 20:38:39 2011 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 20 May 2011 02:38:39 +0200 Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <8762p7omzu.fsf@kuiper.lan.informatimago.com> Message-ID: <87pqnemcj4.fsf@kuiper.lan.informatimago.com> tar at sevak.isi.edu (Thomas A. Russ) writes: > "Pascal J. Bourguignon" writes: > >> tar at sevak.isi.edu (Thomas A. Russ) writes: >> > >> > This will only work if there is a backpointer to the parent. >> >> No, you don't need backpointers; some cases have been mentionned in the >> other answer, but in general: >> >> (defun parent (tree node) >> (if (member node (children tree)) >> tree >> (some (lambda (child) (parent child node)) (children tree)))) >> >> Yes, the question wasn't about time complexity. > > :-p > > Um, this is a recursive function. Inside PARENT, there is another call > to PARENT. Feel free to derecursive it. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From debatem1 at gmail.com Thu May 19 20:56:12 2011 From: debatem1 at gmail.com (geremy condra) Date: Thu, 19 May 2011 17:56:12 -0700 Subject: obviscating python code for distribution In-Reply-To: <0q3ga8-s2v.ln1@svn.schaathun.net> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: On Thu, May 19, 2011 at 11:23 AM, Hans Georg Schaathun wrote: > On Thu, 19 May 2011 10:23:47 -0700, geremy condra > ? wrote: > : ?Let me get this straight: your argument is that operating *systems* > : ?aren't systems? > > You referred to the kernel and not the system. ?The complexities of > the two are hardly comparable. I don't know about that. Among the many verified microkernels, at least two projects have formally verified both their kernel and their toolchain, and one of them claims they've verified everything in their TCB and are headed towards verified POSIX compliance in 2012. That would seem to be a fairly large system (and definitely a complete OS) to me. Another (seL4) says they've formally verified security of a complete system that includes a userspace and the ability to run other OSes in fully isolated containers, which also seems to be quite complete. Finally, there's one from Microsoft research that claims similar properties but which apparently isn't interested in compatibility, which I'm not sure how to interpret in terms of usefulness and size. In any event, higher level systems- like electronic voting mechanisms and automotive sensor networks- have also been verified, which seems to run counter to your original point. Also, not sure if it's open to the general public but if you're interested in this kind of thing and live near seattle, I think there's actually going to be a talk on verifying a POSIX userspace implementation here tomorrow. TL;DR version: large systems have indeed been verified for their security properties. > There probably are different uses of system; in computer security > literature? it often refers, not only to a product (hardware/software) > an actual installation and configuration of that product in a specific > context. ?/I/ did not redefine it. You chose a word with a many meanings, used it to make a very broad statement which is only a little bit true, and then pretended that you had the One True Definition in your pocket. I don't think that's legitimate, but whatever; let's just say that we meant different things by the word and drop it. > Speaking of reasonable assumptions, one necessary assumption which is > particularly dodgy is that whoever deploys and configures it > understands all the assumptions and do not break them through ignorance. Yup. Nothing is safe from idiots. > Is your concern with security purely from a developer's viewpoint, > so that you don't have to worry about the context in which it will > be deployed? My viewpoint is that of an attacker, since that's more or less my job. > I read your initial comment to imply that if you cannot get satisfactory > assurance using the lower levels, you won't get any at the higher > levels. ?That does not make any sense. Well, this is kind of like my point. My point was that you really don't get anything at the lower levels, and that they should fix that (which is far more useful to a normal consumer) rather than trying to talk about formal verification and similar tools, which are only going to be used on a tiny fraction of products. Geremy Condra From rosuav at gmail.com Thu May 19 21:33:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 11:33:25 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: On Fri, May 20, 2011 at 10:56 AM, geremy condra wrote: >> Speaking of reasonable assumptions, one necessary assumption which is >> particularly dodgy is that whoever deploys and configures it >> understands all the assumptions and do not break them through ignorance. > > Yup. Nothing is safe from idiots. > Which means that the assumption really is that you are evaluating a system, not a bald piece of code. I don't consider that an assumption. When you're writing code that you will yourself deploy, you take full responsibility; when you let other people deploy it, they have to take ultimate responsibility (although they will legitimately expect you to provide an install script and/or instructions). There are idiots in this world. Have you met them? Met them? I listen to you every week! -- The Goon Show, and so absolutely true Chris Angelico From n4vpython at gmail.com Thu May 19 22:13:51 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Fri, 20 May 2011 07:43:51 +0530 Subject: Inheriting Object Message-ID: Hi Guys, I have been wondering for a while now as to why some classes inherit Object? And what does it really do for the class? Can anyone shed some light on this? Regards, Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Thu May 19 22:30:52 2011 From: debatem1 at gmail.com (geremy condra) Date: Thu, 19 May 2011 19:30:52 -0700 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: On Thu, May 19, 2011 at 6:33 PM, Chris Angelico wrote: > On Fri, May 20, 2011 at 10:56 AM, geremy condra wrote: >>> Speaking of reasonable assumptions, one necessary assumption which is >>> particularly dodgy is that whoever deploys and configures it >>> understands all the assumptions and do not break them through ignorance. >> >> Yup. Nothing is safe from idiots. I actually think I need to take this statement back. The more I think about it, the less convinced I am that it's correct- I can at least conceive of violable systems which cannot be misconfigured. So, sorry about that. > Which means that the assumption really is that you are evaluating a > system, not a bald piece of code. I don't consider that an assumption. > When you're writing code that you will yourself deploy, you take full > responsibility; when you let other people deploy it, they have to take > ultimate responsibility (although they will legitimately expect you to > provide an install script and/or instructions). Sure, although I would personally still call it an assumption. Geremy Condra From rosuav at gmail.com Thu May 19 22:35:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 12:35:17 +1000 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: On Fri, May 20, 2011 at 12:30 PM, geremy condra wrote: >> On Fri, May 20, 2011 at 10:56 AM, geremy condra wrote: >>> Yup. Nothing is safe from idiots. > > I actually think I need to take this statement back. The more I think > about it, the less convinced I am that it's correct- I can at least > conceive of violable systems which cannot be misconfigured. So, sorry > about that. If it is, then you're not deploying it, you're just pushing buttons and acting like a user. I still stand by the view that the one with the root password is the one responsible for the computer's security; and if you have the root filesystem password, there's no way that something can be made unmisconfigurable. (You CAN, however, make something that's out-of-the-box secure, so someone just does a 'sudo apt-get install yoursystem' and it's specced up nicely. This is a Good Thing.) Chris Angelico From wbai at camiant.com Thu May 19 22:54:57 2011 From: wbai at camiant.com (William) Date: Fri, 20 May 2011 10:54:57 +0800 Subject: Inheriting Object In-Reply-To: References: Message-ID: <4DD5D801.80408@camiant.com> Hi Nav: Here is the long why. http://www.python.org/download/releases/2.2.3/descrintro/ I guess for most programs, there is no big difference, but if you use some special features that might be different. Say, could use super when using type() instead of class(), also, when using multiple inheritance, you can't multiply inherit from different built-in types. Some new features such as property() is not supported in type either. BRs William On 01/-9/-28163 03:59 AM, Navkirat Singh wrote: > Hi Guys, > > I have been wondering for a while now as to why some classes inherit > Object? And what does it really do for the class? Can anyone shed some > light on this? > > Regards, > Nav From python at mrabarnett.plus.com Thu May 19 22:55:45 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 20 May 2011 03:55:45 +0100 Subject: Inheriting Object In-Reply-To: References: Message-ID: <4DD5D831.4020308@mrabarnett.plus.com> On 20/05/2011 03:13, Navkirat Singh wrote: > Hi Guys, > > I have been wondering for a while now as to why some classes inherit > Object? And what does it really do for the class? Can anyone shed some > light on this? > Read section 3.3 "New-style and classic classes" in the Python docs. From wbai at camiant.com Thu May 19 23:00:36 2011 From: wbai at camiant.com (William) Date: Fri, 20 May 2011 11:00:36 +0800 Subject: Inheriting Object In-Reply-To: References: Message-ID: <4DD5D954.8080101@camiant.com> Hi Nav: Here is the long why. http://www.python.org/download/releases/2.2.3/descrintro/ I guess for most programs, there is no big difference. But in term of some new added features in python, you might not be able to work. Say, you could not use super in type, also you can't multiply inherit from different built-in types, what's more you could not use some builtin feature such as property. BRs William On 01/-9/-28163 03:59 AM, Navkirat Singh wrote: > Hi Guys, > > I have been wondering for a while now as to why some classes inherit > Object? And what does it really do for the class? Can anyone shed some > light on this? > > Regards, > Nav From William.Bai at tekelec.com Thu May 19 23:01:13 2011 From: William.Bai at tekelec.com (William.Bai) Date: Fri, 20 May 2011 11:01:13 +0800 Subject: Inheriting Object In-Reply-To: References: Message-ID: <4DD5D979.8050804@tekelec.com> Hi Nav: Here is the long why. http://www.python.org/download/releases/2.2.3/descrintro/ I guess for most programs, there is no big difference. But in term of some new added features in python, you might not be able to work. Say, you could not use super in type, also you can't multiply inherit from different built-in types, what's more you could not use some builtin feature such as property. BRs William On 01/-9/-28163 03:59 AM, Navkirat Singh wrote: > Hi Guys, > > I have been wondering for a while now as to why some classes inherit > Object? And what does it really do for the class? Can anyone shed some > light on this? > > Regards, > Nav From n4vpython at gmail.com Fri May 20 00:11:49 2011 From: n4vpython at gmail.com (Navkirat Singh) Date: Fri, 20 May 2011 09:41:49 +0530 Subject: Inheriting Object In-Reply-To: <4DD5D831.4020308@mrabarnett.plus.com> References: <4DD5D831.4020308@mrabarnett.plus.com> Message-ID: On Fri, May 20, 2011 at 8:25 AM, MRAB wrote: > On 20/05/2011 03:13, Navkirat Singh wrote: > >> Hi Guys, >> >> I have been wondering for a while now as to why some classes inherit >> Object? And what does it really do for the class? Can anyone shed some >> light on this? >> >> Read section 3.3 "New-style and classic classes" in the Python docs. > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks Guys...I will look deeper into this. I thought I read somewhere that it was required in older python releases, but in newer releases it is not. I might be wrong though. Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at gmail.com Fri May 20 00:15:48 2011 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 20 May 2011 14:15:48 +1000 Subject: turn monitor off and on In-Reply-To: References: Message-ID: On Mon, May 16, 2011 at 7:29 PM, Gabriel Genellina wrote: > > Your script worked fine for me, 2.6 and XP also. Perhaps your monitor > device driver is buggy or does not implement the required functionality. > Mine is from Philips. > > I'm actually using windows 7. Maybe its the difference in OS? Anyway, yes, the monitor turns back on if the keys are pressed. I've gone with a pygame/autoit hack which doesn't turn the monitor off (just black) and then removes the black screen (no offence). Thanks again for the helps -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at gmail.com Fri May 20 00:21:17 2011 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 20 May 2011 14:21:17 +1000 Subject: starting a separate thread in maya Message-ID: Hi, I'm using python2.5 in maya 2009 x64 (in linux). I have a script running and somewhere in the script, I want to start another python script that might not return and i don't want the main maya python script to wait for it to finish, even more, after the second script started, I'd like the main script to continue processing. I've tried using threading and maya.utils.executeInMainThread and os.popen and os.spawn, none seem to work this way. Is it not possible to do this in python2.5? Thanks again for any help. Cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: From hg at schaathun.net Fri May 20 00:28:05 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Fri, 20 May 2011 05:28:05 +0100 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On Thu, 19 May 2011 23:21:30 +0200, Rikishi42 wrote: : On 2011-05-18, Hans Georg Schaathun wrote: : > Now Mac OS X has maintained the folder concept of older mac generations, : > and Windows has cloned it. They do not want the user to understand : > recursive data structures, and therefore, naturally, avoid the word. : : You imply they want to keep their users ignorant of these structures, as if : to keep something valuable from them. Wouldn't it be more honest, more to : the point and much simpler to state they don't NEED the user to understand : recursive - or indeed any other - data structures? And that the user doesn't : NEED to understand or know about them, just to use them? Admittedly, my wording had unintended implictions. Mac OS X /targets/ users who do not need to understand the underlying structure. However, the system also has users who do. : After all they are users. They use their system for fun, learning or work. : Even a very competent or advanced use of a tool (computer, car, mobile phone, : fridge, TV, radio, toilet) in no way implies an understanding of it's inner : workings. Nor the need, nor the desire. For a general purpose computer, that is simply not true in general. : PS: Isn't this thread much ado about nothing? :-) Most threads are. : It starts with the misconception (or should I say confusion?) between : performing a recursive job and using a recursive tool to do it. And then it : blazes off in these huge discusions about semantics to define a definition : of an abstraction of a alleady theoretical problem. And explaining the source of the misconception and the varying use would be irrelevant? : And PPS: the P(P)S's don't specifically refer to your posting. Thanks :-) -- :-- Hans Georg From hg at schaathun.net Fri May 20 00:48:50 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Fri, 20 May 2011 05:48:50 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: On Thu, 19 May 2011 17:56:12 -0700, geremy condra wrote: : TL;DR version: large systems have indeed been verified for their : security properties. : (...) : Yup. Nothing is safe from idiots. The difficult part is mapping those properties to actual requirements and threat models. Formal methods do not help on that step. It takes more than a non-idiot to avoid misunderstandings on the interface betweeen professions. Either way, the assumption that your system will not be handled by idiots is only reasonable if you yourself is the only user. -- :-- Hans Georg From rustompmody at gmail.com Fri May 20 01:05:23 2011 From: rustompmody at gmail.com (rusi) Date: Thu, 19 May 2011 22:05:23 -0700 (PDT) Subject: Recursion in Computer Science Message-ID: <725020f8-3a73-4a8a-a587-e4c4996bcb04@z15g2000prn.googlegroups.com> There have been a number of unrelated discussions regarding recursion on this list. I believe that recursion occurs in a wider spread of areas than is usually recognised. Heres a list of some such areas. Please note I am using recursion in a broad and somewhat fuzzy sense. Narrow specific definitions would lead to conclusions like: -- Prolog has no functions or procedures so it has no recursion -- Since recursion is equivalent to stack + iteration therefore Fortran supports recursion. Heres (an initial approx to) such a list: ------------------------------------------------------- recursive functions recursive data -- eg linked lists, trees nesting self reference -- Y combinator well founded induction structural induction bootstrapping language to describe language -- syntax - yacc in yacc language to describe language -- semantics - lisp in lisp -- metacircularity Goedel's theorem <- meta-mathematics <- ordinary math undecidability <- universal TM <- Turing machine as ordinary computer reentrancy [An OS-like program fails to be reentrant for the same reason that Fortan-like language fails to support recursion -- Non use of stack] virtualization in OS Introspection in modern languages Models to metamodels corecursion - laziness, infinite datastructures - semantics of generators/iterators in python Von Neuman machine - code is data -- therefore quondam hardware becomes software - data can be code -- viruses From rustompmody at gmail.com Fri May 20 01:13:14 2011 From: rustompmody at gmail.com (rusi) Date: Thu, 19 May 2011 22:13:14 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On May 20, 2:21?am, Rikishi42 wrote: > On 2011-05-18, Hans Georg Schaathun wrote: > > > Now Mac OS X has maintained the folder concept of older mac generations, > > and Windows has cloned it. ?They do not want the user to understand > > recursive data structures, and therefore, naturally, avoid the word. > > You imply they want to keep their users ignorant of these structures, as if > to keep something valuable from them. Wouldn't it be more honest, more to > the point and much simpler to state they don't NEED the user to understand > recursive - or indeed any other - data structures? And that the user doesn't > NEED to understand or know about them, just to use them? > > After all they are users. They use their system for fun, learning or work. > Even a very competent or advanced use of a tool (computer, car, mobile phone, > fridge, TV, radio, toilet) in no way implies an understanding of it's inner > workings. Nor the need, nor the desire. > > PS: Isn't this thread much ado about nothing? ?:-) > It starts with the misconception (or should I say confusion?) between > performing a recursive job and using a recursive tool to do it. And then it > blazes off in these huge discusions about semantics to define a definition > of an abstraction of a alleady theoretical problem. > > Glorious, just frelling glorious. ? ?:-) > We have an expression for that. But I'll avoid using it, since it has the > word 'masturbation' in it... > > And PPS: the P(P)S's don't specifically refer to your posting. > > -- > When in doubt, use brute force. > ? ? ? ? ? ? ? ? -- Ken Thompson Well... I was rethinking my earlier argument with Ian Kelly about the similarity/differences between recursion in theory and in CS. On rethinking my position I come to the conclusion that I am arguing like an chimp -- and therefore not making my real point which is that that recursion is more widespread in computer science than is recognised. This is discussed separately here http://groups.google.com/group/comp.lang.python/browse_thread/thread/212e6477262125e9# [I agree with you Xah that recursion is a technical word that should not be foisted onto lay users.] From rosuav at gmail.com Fri May 20 01:18:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 15:18:50 +1000 Subject: Recursion in Computer Science In-Reply-To: <725020f8-3a73-4a8a-a587-e4c4996bcb04@z15g2000prn.googlegroups.com> References: <725020f8-3a73-4a8a-a587-e4c4996bcb04@z15g2000prn.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 3:05 PM, rusi wrote: > ?- data can be code -- viruses It's not JUST viruses. There's plenty of legitimate reasons for your data to actually be code... that's how compilers work! :) Chris Angelico From rustompmody at gmail.com Fri May 20 01:22:49 2011 From: rustompmody at gmail.com (rusi) Date: Thu, 19 May 2011 22:22:49 -0700 (PDT) Subject: Recursion in Computer Science References: <725020f8-3a73-4a8a-a587-e4c4996bcb04@z15g2000prn.googlegroups.com> Message-ID: On May 20, 10:18?am, Chris Angelico wrote: > On Fri, May 20, 2011 at 3:05 PM, rusi wrote: > > ?- data can be code -- viruses > > It's not JUST viruses. There's plenty of legitimate reasons for your > data to actually be code... that's how compilers work! :) > > Chris Angelico Yes sure Thanks. An exhaustive list would be much longer (and I got tired of typing) From ericsnowcurrently at gmail.com Fri May 20 01:33:12 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Thu, 19 May 2011 23:33:12 -0600 Subject: validating a class against an ABC at definition time Message-ID: Thinking about class APIs and validating a class against an API. The abc module provides the tools to do some of this. One thing I realized, that I hadn't noticed before, is that the abstractness of a class is measured when instances of the class are created. This happens in object.__new__ (pyobject.c). Validating thus when a class is defined would not be as helpful, since there is no guarantee that the class is not meant to be abstract as well. However, I have found that it is sometimes nice to validate a class at definition time. This is particularly true for a class that does not inherit from the abstract base class (but registers instead). Taking cues from abc.py and pyobject.c, here is a stab at a class decorator that validates a class against another. def validate(abc): if not isinstance(abc, type): raise TypeError("Can only validate against classes") def decorator(cls): if not __debug__: return cls if not isinstance(cls, type): raise TypeError("Can only validate classes") abstracts = set() for name in getattr(abc, "__abstractmethods__", set()): value = getattr(cls, name, None) if not value: abstracts.add(name) elif getattr(value, "__isabstractmethod__", False): abstracts.add(name) if abstracts: sorted_methods = sorted(abstracts) joined = ", ".join(sorted_methods) msg = "Class {} does not implement abstract methods {} of class {}" raise TypeError(msg.format(cls.__name__, joined, abc.__name__)) return cls return decorator Stack this with the ABCMeta.register method and you can ensure that your class is compliant with the ABC at the time you register it on that ABC. Does anyone find this irrelevant or superfluous? I know that it would be a good idea to stay on top of your class's implementation of an ABC's abstract methods. However, this seems like a good way of doing that programmatically. Does anyone know a better way to do ABC validation at definition time? Thanks. -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri May 20 01:43:43 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 19 May 2011 22:43:43 -0700 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> Message-ID: <4DD5FF8F.604@stoneleaf.us> Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me what horrible thing will happen if this isn't the case? Here's a toy example of a class I'm thinking of writing that will compare equal with int's, but hash differently: --> class Wierd(): ... def __init__(self, value): ... self.value = value ... def __eq__(self, other): ... return self.value == other ... def __hash__(self): ... return hash((self.value + 13) ** 3) ... --> one = Wierd(1) --> two = Wierd(2) --> three = Wierd(3) --> one --> one == 1 True --> one == 2 False --> two == 2 True --> three == 3 True --> d = dict() --> d[one] = '1' --> d[two] = '2' --> d[three] = '3' --> d {: '1', : '3', : '2'} --> d[1] = '1.0' --> d[2] = '2.0' --> d[3] = '3.0' --> d {: '3', 1: '1.0', 2: '2.0', 3: '3.0', : '2', : '1'} --> d[2] '2.0' --> d[two] '2' All information greatly appreciated! ~Ethan~ From steve+comp.lang.python at pearwood.info Fri May 20 01:58:04 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2011 05:58:04 GMT Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 May 2011 09:37:59 +1000, Chris Angelico wrote: > On Fri, May 20, 2011 at 8:47 AM, Steven D'Aprano > wrote: >> On Tue, 17 May 2011 10:02:21 -0700, geremy condra wrote: >> >>> or O(1): >>> >>> ? = (1 + sqrt(5)) / 2 >>> ? ? numerator = (?**n) - (1 - ?)**n >> >> I'd just like to point out that, strictly speaking, it's only O(1) if >> you assume that exponentiation is O(1). Computer scientists often like >> to make this simplifying assumption, and it might even be true for >> floats, but for long ints and any numeric data types with unlimited >> precision, it won't be. >> >> > Python doesn't have arbitrary precision non-integers, does it? So this > is going to be done with floats. Sure, which is why the above fib() function will become increasing inaccurate beyond some given n, by memory about n=71 or so. Er, at least the fib() function that *was* above until you deleted most of it :) If you want an *accurate* fib() function using exponentiation of ?, you need arbitrary precision non-integers. Nevertheless, at some point you will hit the limit of floats, which thanks to the exponential growth of the Fibonacci sequence won't take that long: it takes roughly 1475 iterations to exceed the range of Python floats. -- Steven From rosuav at gmail.com Fri May 20 02:06:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 16:06:40 +1000 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 3:58 PM, Steven D'Aprano wrote: > ... until you deleted most of it :) Minimalist quoting practice! :) > If you want an *accurate* fib() function using exponentiation of ?, you > need arbitrary precision non-integers. I believe the 'bc' command-line calculator can do a-p non-i, and I know REXX can, but it seems to be quite an unusual thing. Is it that much harder than a-p integer that it's just not worthwhile? It seems strange to smoothly slide from native integer to long integer and just keep on going, and yet to be unable to do the same if there's a fractional part on it. Chris Angelico From harrismh777 at charter.net Fri May 20 02:17:44 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 20 May 2011 01:17:44 -0500 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> Message-ID: geremy condra wrote: >> Anonymous, "Maximum Linux Security: A Hacker's Guide to Protecting >> > Your Linux Server and Workstation," Indianapolis: >> > Sams Publishing, 2000. > This is a good volume, but very dated. I'd probably pass on it. Actually, although dated, its still a very good manual for concepts, and much of it... believe it or not... is still just as valid as the day it was written. Some things of course have changed, like web security and protocols. Some of the linux admin stuff has now been automated with reasonable defaults, *but not all*... Appendix D is good-- additional resources bibliography ! Maybe try to buy or borrow a used copy [ or just skip it... ] PS I really have hoped that Anonymous would be putting out a second edition, but I can't find it... so not yet... kind regards, m harris From harrismh777 at charter.net Fri May 20 02:26:47 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 20 May 2011 01:26:47 -0500 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > I believe the 'bc' command-line calculator can do a-p non-i, and I > know REXX can Yes, bc is wonderful in this regard. Actually, bc does this sort of thing in 'circles' around Python. This is one of Python's weaknesses for some problem solving... no arbitrary precision. And its not just that bc does arbitrary precision--- its that it does it fast! Actually, it should be relatively easy to incorporate parts of bc into Python as C extensions. On the other hand, when needing specialized math work from bc, its probably just better to use bc and leave Python alone. On the other hand, most of the time (and I mean 99.999% of the time) floats are going to work just fine... usually folks don't even need doubles.... :) With fifteen or twenty digits of PI we can calculate the circumference of the visible universe to within the width of a proton... er, I mean hadron... and you know what... how many folks need to do that anyway?? Don't get me wrong... I absolutely love playing around with bignums, but then, I'm a math geek... ;-) kind regards, m harris From ssonaldd at gmail.com Fri May 20 02:31:31 2011 From: ssonaldd at gmail.com (SONAL ...) Date: Fri, 20 May 2011 12:01:31 +0530 Subject: Problem running pylons webtests. ImportError and TestController is not defined error. Message-ID: I have directory structure as gnukhata/tests/functional. In functional folder I have web tests files. Following is the sample tests: *from gnukhata.tests import * class TestVendorController(TestController): def test_index(self): response = self.app.get(url(controller='vendor', action='index'**))* After running tests, it gives me following error: *Traceback (most recent call last): File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 651, in loadByNames things.append(self.findByName(name)) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 460, in findByName return filenameToModule(name) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 98, in filenameToModule return _importFromFile(fn) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 117, in _importFromFile module = imp.load_source(moduleName, fn, fd) File "test_vendor.py", line 1, in from gnukhata.tests import * exceptions.ImportError: No module named tests* Instead of gnukhata.tests if I write gnukhata then it shows the following error: *Traceback (most recent call last): File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 651, in loadByNames things.append(self.findByName(name)) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 460, in findByName return filenameToModule(name) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 98, in filenameToModule return _importFromFile(fn) File "/usr/lib/python2.6/dist-packages/twisted/trial/runner.py", line 117, in _importFromFile module = imp.load_source(moduleName, fn, fd) File "test_vendor.py", line 3, in class TestVendorController(TestController): exceptions.NameError: name 'TestController' is not defined * How to remove these errors??? Suggest me solution... Thanks in advance... -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Fri May 20 02:33:46 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 20 May 2011 08:33:46 +0200 Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> Message-ID: <0deha8-6u9.ln1@satorlaser.homedns.org> Ethan Furman wrote: > Several folk have said that objects that compare equal must hash equal, > and the docs also state this > http://docs.python.org/dev/reference/datamodel.html#object.__hash__ > > I'm hoping somebody can tell me what horrible thing will happen if this > isn't the case? If you were familiar with what a hash map is, you wouldn't ask. The thing is that the hash is used to look up the place in the map where the thing is stored. If two equal objects have different hashes, they will be stored in different places in the hash map. Looking for object1 will then not turn up with object2, even though they are equal. If this is something you don't care about, and all you care about is identity, then I'd derive the hash from each object's ID. This ID has another property which is something that is assumed for hashes, and your code seems a bit to get that wrong, too, and that is that the hash must not change. Again, the reason is that if the hash changes, the position in the hash map changes, too. If you then try to look up the changed object, it will look for it in the new place, but it won't be found because it is in the old place. For that reason, it is generally useful to use immutable types like integers, floats, strings and tuples thereof as keys. Since you can't change them, you basically have the guarantee that they hash the same. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From __peter__ at web.de Fri May 20 02:38:30 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 May 2011 08:38:30 +0200 Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> Message-ID: Ethan Furman wrote: > Several folk have said that objects that compare equal must hash equal, > and the docs also state this > http://docs.python.org/dev/reference/datamodel.html#object.__hash__ > > I'm hoping somebody can tell me what horrible thing will happen if this > isn't the case? Here's a toy example of a class I'm thinking of writing > that will compare equal with int's, but hash differently: > > --> class Wierd(): > ... def __init__(self, value): > ... self.value = value > ... def __eq__(self, other): > ... return self.value == other > ... def __hash__(self): > ... return hash((self.value + 13) ** 3) > ... Try this: >>> d = {Wierd(1): 0} >>> 1 in d False >>> 1 in d.keys() True From clp2 at rebertia.com Fri May 20 02:44:59 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 19 May 2011 23:44:59 -0700 Subject: hash values and equality In-Reply-To: <4DD5FF8F.604@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD5FF8F.604@stoneleaf.us> Message-ID: On Thu, May 19, 2011 at 10:43 PM, Ethan Furman wrote: > Several folk have said that objects that compare equal must hash equal, and > the docs also state this > http://docs.python.org/dev/reference/datamodel.html#object.__hash__ > > I'm hoping somebody can tell me what horrible thing will happen if this > isn't the case? ?Here's a toy example of a class I'm thinking of writing > that will compare equal with int's, but hash differently: > > --> class Wierd(): > ... ? ? def __init__(self, value): > ... ? ? ? ? self.value = value > ... ? ? def __eq__(self, other): > ... ? ? ? ? return self.value == other > ... ? ? def __hash__(self): > ... ? ? ? ? return hash((self.value + 13) ** 3) > ... > --> one = Wierd(1) > --> two = Wierd(2) > --> three = Wierd(3) > --> one > > --> one == 1 > True > --> one == 2 > False > --> two == 2 > True > --> three == 3 > True > --> d = dict() > --> d[one] = '1' > --> d[two] = '2' > --> d[three] = '3' > --> d > {: '1', > ?: '3', > ?: '2'} > --> d[1] = '1.0' > --> d[2] = '2.0' > --> d[3] = '3.0' This is the part considered "horrible": > --> d > {: '3', > ?1: '1.0', > ?2: '2.0', > ?3: '3.0', > ?: '2', > ?: '1'} Compare: >>> x = {5.0 : 'foo'} >>> x[5] 'foo' Here's a more common/plausible "horrible" case closer to what the docs writers had in mind: >>> class Naughty(object): ... def __init__(self, n): ... self.n = n ... def __eq__(self, other): ... return self.n == other.n ... >>> Naughty(5) == Naughty(5) True >>> Naughty(5) is Naughty(5) False >>> bad = Naughty(3) >>> y = {bad : 'foo'} >>> y[bad] # just happens to work 'foo' >>> del bad >>> # ok, how do we get to 'foo' now? >>> y[Naughty(3)] # try the obvious way Traceback (most recent call last): File "", line 1, in KeyError: <__main__.Naughty object at 0x2a1cb0> >>> # We're screwed. Naughty instances (and similar) can't be used sensibly as hash keys (unless you /only/ care about object identity; this is often not the case). Cheers, Chris -- http://rebertia.com From my.spamtrap at verizon.net Fri May 20 02:50:23 2011 From: my.spamtrap at verizon.net (Roland Hutchinson) Date: Fri, 20 May 2011 06:50:23 +0000 (UTC) Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> Message-ID: On Wed, 18 May 2011 07:19:08 +0200, Pascal J. Bourguignon wrote: > Roland Hutchinson writes: > >> Sorry to have to contradict you, > > Don't be sorry. > > >> but it really is a textbook example of recursion. Try this psuedo-code >> on for size: >> >> FUNCTION DIR-DELETE (directory) >> FOR EACH entry IN directory >> IF entry IS-A-DIRECTORY THEN DIR-DELETE (entry). >> >> Well, now that's not just recursion; it's tail recursion. > > It's not tail recursion. If you had indented your code properly, you'd > see why it's not: > > (defun dir-delete (directory) > (loop for entry in directory > do (if (is-a-directory entry) > (dir-delete entry)))) > You are right, of course. Thanks for the correction. > (I put parentheses, so my editor knows what I mean and can do the > indentation for me). My editor would have done that, too--if I had bothered to be thinking clearly. > That's why walking a directory is done with a recursive procedure, > instead of an iterative one: it's much simplier. To implement an > iterative procedure, you would have to manage a stack yourself, instead > of using the implicit stack of the recursive procedure. Got it! Thanks again. -- Roland Hutchinson He calls himself "the Garden State's leading violist da gamba," ... comparable to being ruler of an exceptionally small duchy. --Newark (NJ) Star Ledger ( http://tinyurl.com/RolandIsNJ ) From ian.g.kelly at gmail.com Fri May 20 02:53:57 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 00:53:57 -0600 Subject: Inheriting Object In-Reply-To: References: <4DD5D831.4020308@mrabarnett.plus.com> Message-ID: On Thu, May 19, 2011 at 10:11 PM, Navkirat Singh wrote: > Thanks Guys...I will look deeper into this. I thought I read somewhere that > it was required in older python releases, but in newer releases it is not. I > might be wrong though. In Python 3.x all classes inherit from object by default, so "class Foo(object):" and "class Foo:" are equivalent. In Python 2.x they are not equivalent, and you should use "class Foo(object):" unless you have a specific reason not to. Cheers, Ian From rosuav at gmail.com Fri May 20 02:54:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 16:54:06 +1000 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 4:26 PM, harrismh777 wrote: > Actually, it should be relatively easy to incorporate parts of bc into > Python as C extensions. On the other hand, when needing specialized math > work from bc, its probably just better to use bc and leave Python alone. If someone has time to kill (as if!), it'd be awesome to get a new numeric type that uses bc's code; any other numeric type (int, long, float) could autopromote to it, removing the dilemma of which to promote out of long and float. Hmm... Python 4.0, 'bc' is the new default integer and everything else is a performance optimization? Heh. > On the other hand, most of the time (and I mean 99.999% of the time) floats > are going to work just fine... usually folks don't even need doubles.... > :) 99.9% of the time int will work fine, too. Most people don't need arbitrary precision OR floating point. > Don't get me wrong... I absolutely love playing around with bignums, but > then, I'm a math geek... ? ?;-) Absolutely. Bring on the geekiness. I've used bignums for things other than straight arithmetic, actually. In REXX, where everything is a string, I've done some fascinating (and completely useless) analyses that involve taking internal digits from a number, performing arithmetic on them, getting huge numbers back, and then searching for substrings (ie digit strings) in the result. What's the lowest power of 2 that has 5 consecutive digits in it? All 10 digits? (That is, it has '0123456789' somewhere in its decimal representation.) Like I said, completely useless... but how many of you immediately pondered which language to implement the search in? Chris Angelico From my.spamtrap at verizon.net Fri May 20 02:54:09 2011 From: my.spamtrap at verizon.net (Roland Hutchinson) Date: Fri, 20 May 2011 06:54:09 +0000 (UTC) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> Message-ID: On Wed, 18 May 2011 12:59:45 -0500, Victor Eijkhout wrote: > Harrison Hill wrote: > >> No need - I have the Dictionary definition of recursion here: >> >> Recursion: (N). See recursion. > > If you tell a joke, you have to tell it right. > > Recursion: (N). See recursion. See also tail recursion. Very good! -- Roland Hutchinson He calls himself "the Garden State's leading violist da gamba," ... comparable to being ruler of an exceptionally small duchy. --Newark (NJ) Star Ledger ( http://tinyurl.com/RolandIsNJ ) From steve+comp.lang.python at pearwood.info Fri May 20 02:55:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2011 06:55:35 GMT Subject: English Idiom in Unix: Directory Recursively References: Message-ID: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: > [I agree with you Xah that recursion is a technical word that should not > be foisted onto lay users.] I think that is a patronizing remark that under-estimates the intelligence of lay people and over-estimates the difficulty of understanding recursion. Any person who has ever been to a barber or hairdresser with mirrors on two parallel walls will be familiar with recursion: a reflection of the reflection of the reflection of the reflection, forever. In 1970, an extremely low-brow comedy "Carry On Up The Jungle" was about the search for an imaginary bird that flies in smaller and small circles until it disappears up it's own rear end, a type of recursion: http://en.wikipedia.org/wiki/Carry_On_Up_the_Jungle The bird in question goes back in folklore since at least 1854: http://en.wikipedia.org/wiki/Oozlum_bird Trust me on this, if the audience of Carry On films could understand recursion, anyone can! -- Steven From J.deBoynePollard-newsgroups at NTLWorld.COM Fri May 20 03:00:58 2011 From: J.deBoynePollard-newsgroups at NTLWorld.COM (Jonathan de Boyne Pollard) Date: Fri, 20 May 2011 08:00:58 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: > ?English Idiom in Unix: Directory Recursively? > http://xahlee.org/comp/idiom_directory_recursively.html > > ------------------------------------------ > English Idiom in Unix: Directory Recursively > > Xah Lee, 2011-05-17 > > Today, let's discuss something in the category of lingustics. > > You know how in unix tools, when you want to delete the whole > directory and all sub-directories and files in it, it's referred as > ?recursive?? > > [...] > > Though, if you think about it, it's not exactly a correct description. > ?Recursive?, or ?recursion?, refers to a particular type of algorithm, > [...] Indeed. And the algorithms that are employed to perform the operations so described are recursive. From steve+comp.lang.python at pearwood.info Fri May 20 03:04:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2011 07:04:27 GMT Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 May 2011 05:48:50 +0100, Hans Georg Schaathun wrote: > Either way, the assumption that your system will not be handled by > idiots is only reasonable if you yourself is the only user. Nonsense. How do you (generic "you", not any specific person) know that you are not an idiot? If you are an idiot, you obviously shouldn't trust your own judgment -- although of course idiots do trust their own judgment when they shouldn't, and the less they know, the less they realise how little they know: http://en.wikipedia.org/wiki/Dunning?Kruger_effect So if you think that you're not an idiot, you might be an idiot who is unaware of being an idiot. Your own opinion is the last opinion you should pay attention to. The world is full of people with delusions of superiority -- only an idiot would trust their own opinion of themselves. You can listen to others, but only so long as you don't surround yourself with idiots. But how do you know if the people around you are idiots? You certainly can't trust your judgment, nor can you trust theirs. If you're an idiot, you (still talking about generic "you") and your idiot friends are probably all congratulating yourselves for not being idiots. In contrast, if you're not an idiot, then you probably are aware (and if not, you should be) of all the cognitive biases human beings are prone to, of all the mental and emotional weaknesses that we all suffer from, which cause us to act in idiotic ways. If you're not an idiot, then you know your limitations, that like everyone, you can be fooled or foolish, that you can make mistakes, that you sometimes operate equipment when you are not at the optimum level of alertness, when your attention to detail is below normal or you are a little more careless than you should be. In short, that everyone, including yourself, can be an idiot, and the more intelligent you are, the more astonishingly stupid your mistakes may be. Any moron can accidentally burn themselves with a match, but it takes a first-class genius to give chronic lead poisoning to tens of millions *and* nearly destroy the ozone layer of the entire world: http://en.wikipedia.org/wiki/Thomas_Midgley,_Jr. So... if you think you are not an idiot, you are, and if you think you are an idiot, you are. Either way, even if your software is only being used by yourself, you should still attempt to make it as idiot-proof as an idiot like yourself can make it. -- Steven From J.deBoynePollard-newsgroups at NTLWorld.COM Fri May 20 03:07:08 2011 From: J.deBoynePollard-newsgroups at NTLWorld.COM (Jonathan de Boyne Pollard) Date: Fri, 20 May 2011 08:07:08 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: > AFAICS what emacs calls "recursive delete" is what the ordinary person > would simply call "delete". Presumably the non-recursive delete is > called simply "delete" but is actually something more complicated than > delete, and you're supposed to know what that is. > The "non-recursive delete" would be simply calling the rmdir() system call, which of course fails if the directory is non-empty. One has to empty the directory of its contents, if any, first. That, of course, involves potentially recursively removing any subdirectories, in exactly the same way. From rustompmody at gmail.com Fri May 20 03:08:36 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 20 May 2011 00:08:36 -0700 (PDT) Subject: embedding and extending on windows Message-ID: <990aa453-4471-4af9-8dd0-cdf5f54e6f43@l14g2000pro.googlegroups.com> A client wants to 'be lectured' on extending and embedding python on windows. I am familiar with this (or was until python2.3 or thereabouts) on linux -- never done it on windows. Can some kind soul point me to some link on the issues/pitfalls re this? I see three choices: 1. Us MS C for the C extensions 2. Use cygwin Recompile python from sources Use gcc for the extensions 3. Mix gcc extension + precompiled python (and pray!) -- If we use ctypes do we need to rely less on prayer? -- What goes wrong with python compiled with gcc? [Ok let me guess I have to compile everything else thereafter? Any other warnings?] From steve+comp.lang.python at pearwood.info Fri May 20 03:10:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2011 07:10:45 GMT Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> Message-ID: <4dd613f5$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 May 2011 17:56:12 -0700, geremy condra wrote: > TL;DR version: large systems have indeed been verified for their > security properties. How confident are we that the verification software is sufficiently bug- free that we should trust their results? How confident are we that the verification software tests every possible vulnerability, as opposed to merely every imaginable one? -- Steven From J.deBoynePollard-newsgroups at NTLWorld.COM Fri May 20 03:10:45 2011 From: J.deBoynePollard-newsgroups at NTLWorld.COM (Jonathan de Boyne Pollard) Date: Fri, 20 May 2011 08:10:45 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: > I think what happens is that the ?recursive? has become a idiom associated with directory to such a degree that the unix people don't know what the fuck they are talking about. They just simply use the word to go with directory whever they mean the whole directory. > > In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it possibly mean by the word ?recursive? there? Like, it might delete the > directory but not delete all files in it? It might *try* to delete the directory but not any of its contents, yes. If such functionality is not offered, then putting the word in the user interface is redundant, and possibly not the best way to warn the user of potentially a massive loss of files and directories. But the algorithm employed is indeed recursive. From rosuav at gmail.com Fri May 20 03:10:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 17:10:49 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> Message-ID: On Wed, 18 May 2011 12:59:45 -0500, Victor Eijkhout wrote: > Recursion: (N). See recursion. See also tail recursion. caching proxy (n): If you already know what recursion is, this is the same. Otherwise, see recursion. ChrisA From ian.g.kelly at gmail.com Fri May 20 03:26:49 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 01:26:49 -0600 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 19, 2011 at 11:58 PM, Steven D'Aprano wrote: > Sure, which is why the above fib() function will become increasing > inaccurate beyond some given n, by memory about n=71 or so. Er, at least > the fib() function that *was* above until you deleted most of it :) > > If you want an *accurate* fib() function using exponentiation of ?, you > need arbitrary precision non-integers. This seems to work for arbitrary n, although I only tested it out to about n=2000. from decimal import Decimal, localcontext from math import sqrt def fib(n): if n <= 70: return fib_float(n) else: return fib_decimal(n) phi_float = (1 + sqrt(5)) / 2 def fib_float(n): numerator = (phi_float ** n) - (1 - phi_float) ** n denominator = sqrt(5) return int(round(numerator / denominator)) def fib_decimal(n): with localcontext() as ctx: ctx.prec = n // 4 + 1 sqrt_5 = Decimal('5').sqrt() phi = (1 + sqrt_5) / 2 numerator = (phi ** n) - (1 - phi) ** n return int((numerator / sqrt_5).to_integral_value()) Cheers, Ian From ian.g.kelly at gmail.com Fri May 20 03:32:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 01:32:52 -0600 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2011/5/20 Ian Kelly : > def fib_decimal(n): > ? ?with localcontext() as ctx: > ? ? ? ?ctx.prec = n // 4 + 1 > ? ? ? ?sqrt_5 = Decimal('5').sqrt() > ? ? ? ?phi = (1 + sqrt_5) / 2 > ? ? ? ?numerator = (phi ** n) - (1 - phi) ** n > ? ? ? ?return int((numerator / sqrt_5).to_integral_value()) Note that I believe this is O(n) since the necessary precision grows linearly with n. From PointedEars at web.de Fri May 20 03:38:48 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 20 May 2011 09:38:48 +0200 Subject: connect SIGINT to custom interrupt handler References: <1691845.hkbZ0PkbqX@PointedEars.de> Message-ID: <1905065.XAFRqVoOGU@PointedEars.de> Christoph Scheingraber wrote: > On 2011-05-15, Thomas 'PointedEars' Lahn wrote: >> Obviously. `signal' refers to an `int' object, probably by something >> like >> >> signal = 42 >> >> before. E.g. `print' or a debugger will tell you, as you have not showed >> the relevant parts of the code. > > The problem is that I am running someone else's module which seems to > use signal, I guess that means I have to create a child method? > Is it correct anyway to have > > signal.siginterrupt(signal.SIGINT, False) > > in my custom interrupt_handler function Only if `signal' is not the name of an int argument. > or should it be outside but > after signal.signal(signal.SIGINT, interrupt_handler)? In the meantime, Chris Angelico has pointed out the cause of the problem. Please follow his advice, i.e. rename your argument. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From mail at timgolden.me.uk Fri May 20 04:21:54 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 20 May 2011 09:21:54 +0100 Subject: os.access giving incorrect results on Windows In-Reply-To: <4DD5803A.4080208@gmail.com> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> <4DD572FB.2010809@timgolden.me.uk> <4DD575E1.9060801@gmail.com> <4DD578AF.3000001@timgolden.me.uk> <4DD5803A.4080208@gmail.com> Message-ID: <4DD624A2.2030503@timgolden.me.uk> On 19/05/2011 21:40, Andrew Berg wrote: > On 2011.05.19 03:08 PM, Tim Golden wrote: >> * A R_OK check always succeeds if the file's attributes can be read >> at all > So is this the same as F_OK then, or does it return false if the user > isn't allowed to read permissions? >> * A W_OK check fails if the file has its DOS read-only attribute set > DOS attribute? >> * A W_OK check always succeeds for a directory (because read-only means >> something else for directories). >> >> Would you care to propose some wording for the docs? I'm quite happy >> to commit if we can come to an agreement. > I'm a beginner when it comes to Python, but I could give it a shot. A > big red warning box explaining how the code under Windows doesn't use > ACLs under the os.access() entry (above the notes) seems appropriate. A > warning box under os.W_OK saying something like "Under Windows, access() > will always indicate that a directory is writable." would also fit. You > know more about this than I do. I'm running Windows 7 right now and I > have a Python 3.2 interpreter window open if you want me to test/confirm > something. :-) (Sorry; just got back to this this morning). I might raise this on python-dev. It seems to me that the docs for os.access: http://docs.python.org/library/os.html#os.access are already fairly involved. And we try not to make the official docs too confusing. That said, there's clearly an issue here, albeit one which doesn't raise its head too often. There's a case for re-assessing the patch I proposed in issue2528 to see whether to apply it appropriately (reworked). TJG From hg at schaathun.net Fri May 20 04:48:47 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Fri, 20 May 2011 09:48:47 +0100 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 20 May 2011 06:55:35 GMT, Steven D'Aprano wrote: : On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: : : > [I agree with you Xah that recursion is a technical word that should not : > be foisted onto lay users.] : : I think that is a patronizing remark that under-estimates the : intelligence of lay people and over-estimates the difficulty of : understanding recursion. Could we then say that ?recursion is a technical word that should not /unnecessarily/ be foisted onto lay users?? -- :-- Hans Georg From mail at timgolden.me.uk Fri May 20 04:53:53 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 20 May 2011 09:53:53 +0100 Subject: os.access giving incorrect results on Windows In-Reply-To: <4DD624A2.2030503@timgolden.me.uk> References: <21581D39FA3BDF40904D75AF9653CE2606567E4A@blrex.prog.altair.com> <4DD572FB.2010809@timgolden.me.uk> <4DD575E1.9060801@gmail.com> <4DD578AF.3000001@timgolden.me.uk> <4DD5803A.4080208@gmail.com> <4DD624A2.2030503@timgolden.me.uk> Message-ID: <4DD62C21.5090304@timgolden.me.uk> On 20/05/2011 09:21, Tim Golden wrote: [... re os.access on Windows ...] > (Sorry; just got back to this this morning). I might raise this on > python-dev. If you want to follow, my post is here: http://mail.python.org/pipermail/python-dev/2011-May/111530.html TJG From hg at schaathun.net Fri May 20 04:54:46 2011 From: hg at schaathun.net (Hans Georg Schaathun) Date: Fri, 20 May 2011 09:54:46 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 20 May 2011 07:04:27 GMT, Steven D'Aprano wrote: : On Fri, 20 May 2011 05:48:50 +0100, Hans Georg Schaathun wrote: : : > Either way, the assumption that your system will not be handled by : > idiots is only reasonable if you yourself is the only user. : : Nonsense. How do you (generic "you", not any specific person) know that : you are not an idiot? You don't, but if you are, you cannot trust any of the other assumptions either, and making this assumption is reasonable by being less of a leap than anything else you have done. -- :-- Hans Georg From antti.ylikoski at tkk.fi Fri May 20 05:00:33 2011 From: antti.ylikoski at tkk.fi (Antti J Ylikoski) Date: Fri, 20 May 2011 12:00:33 +0300 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <87pqnemcj4.fsf@kuiper.lan.informatimago.com> References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <8762p7omzu.fsf@kuiper.lan.informatimago.com> <87pqnemcj4.fsf@kuiper.lan.informatimago.com> Message-ID: On 20.5.2011 3:38, Pascal J. Bourguignon wrote: > tar at sevak.isi.edu (Thomas A. Russ) writes: > >> "Pascal J. Bourguignon" writes: >> >>> tar at sevak.isi.edu (Thomas A. Russ) writes: >>>> >>>> This will only work if there is a backpointer to the parent. >>> >>> No, you don't need backpointers; some cases have been mentionned in the >>> other answer, but in general: >>> >>> (defun parent (tree node) >>> (if (member node (children tree)) >>> tree >>> (some (lambda (child) (parent child node)) (children tree)))) >>> >>> Yes, the question wasn't about time complexity. >> >> :-p >> >> Um, this is a recursive function. Inside PARENT, there is another call >> to PARENT. > > Feel free to derecursive it. > In the general case, to derecursive a function necessitates programming a stack, among other things............. Antti "Andy" Ylikoski From discmagnet at gmail.com Fri May 20 05:19:04 2011 From: discmagnet at gmail.com (Disc Magnet) Date: Fri, 20 May 2011 14:49:04 +0530 Subject: obviscating python code for distribution In-Reply-To: <4DD09BD5.9070405@tysdomain.com> References: <87boz3gw5u.fsf@benfinney.id.au> <4DD09BD5.9070405@tysdomain.com> Message-ID: On Mon, May 16, 2011 at 9:06 AM, Littlefield, Tyler wrote: > I'm putting lots of work into this. I would rather not have some script > kiddy dig through it, yank out chunks and do whatever he wants. I just want > to distribute the program as-is, not distribute it and leave it open to > being hacked. Obfuscating the code won't help here. Remember, "the enemy knows the system." From andreas.tawn at ubisoft.com Fri May 20 05:21:20 2011 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 20 May 2011 11:21:20 +0200 Subject: starting a separate thread in maya In-Reply-To: References: Message-ID: <654D9D97DA51AD479973BC2D5578603C0BEAB0FFEF@PDC-MAIL-CMS01.ubisoft.org> > Hi, > I'm using python2.5 in maya 2009 x64 (in linux). For Maya/Python stuff you'll probably have more success at http://www.tech-artists.org/ Cheers, Drea From jack.krieger at gmail.com Fri May 20 05:54:43 2011 From: jack.krieger at gmail.com (Jack Krieger) Date: Fri, 20 May 2011 02:54:43 -0700 (PDT) Subject: turn monitor off and on In-Reply-To: Message-ID: <0e005ec6-bf18-457b-9f39-fdbc56f37dfa@glegroupsg2000goo.googlegroups.com> > def turnOffMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) This code does not return control to you, so programm still locked. In my opinion it due broadcasting message. But I do not know how to send message to monitor directly. From jack.krieger at gmail.com Fri May 20 05:54:43 2011 From: jack.krieger at gmail.com (Jack Krieger) Date: Fri, 20 May 2011 02:54:43 -0700 (PDT) Subject: turn monitor off and on In-Reply-To: Message-ID: <0e005ec6-bf18-457b-9f39-fdbc56f37dfa@glegroupsg2000goo.googlegroups.com> > def turnOffMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) This code does not return control to you, so programm still locked. In my opinion it due broadcasting message. But I do not know how to send message to monitor directly. From LeotisBuchanan at exterbox.com Fri May 20 06:37:31 2011 From: LeotisBuchanan at exterbox.com (Leotis buchanan) Date: Fri, 20 May 2011 05:37:31 -0500 Subject: turn monitor off and on In-Reply-To: References: Message-ID: @Astan If you really want to turn your monitor on and off, you should probably try pyserial are pyparrallel(http://pyserial.sourceforge.net/pyparallel.html), along with a solid state relay. That worked for me on linux not sure about windowXP,but it should work. On Sat, May 14, 2011 at 1:08 AM, Astan Chee wrote: > Hi, > I'm trying to turn off my monitor, pause and then turn it on again. > I'm doing this in python 2.6 and windows xp. Here is my script so far > (that doesn't work): > > import time > import win32gui > import win32con > import win32api > > def turnOffMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) > > def turnOnMonitor(): > SC_MONITORPOWER = 0xF170 > win32gui.SendMessage(win32con.HWND_BROADCAST, > win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) > > if __name__ == "__main__": > turnOffMonitor() > time.sleep(5) > turnOnMonitor() > > For some reason, the script doesn't turn the monitor back on. What am > I doing wrong here or are there any other alternative? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards Leotis Buchanan -------------- next part -------------- An HTML attachment was scrubbed... URL: From sigmundv at gmail.com Fri May 20 06:53:34 2011 From: sigmundv at gmail.com (SigmundV) Date: Fri, 20 May 2011 03:53:34 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6826bb7e-67e1-4b22-ba4c-a20216a271a7@h9g2000yqk.googlegroups.com> There is a nice matrix representation of consecutive Fibonacci numbers: [[1, 1], [1, 0]] ** n = [[F_n+1, F_n], [F_n, F_n-1]]. Using the third party mpmath module, which uses arbitrary precision floating point arithmetic, we can calculate the n'th Fibonacci number for an arbitrary n as follows: import mpmath A = mpmath.matrix([[1, 1], [1, 0]]) F = A ** n The n'th Fibonacci number is then found as the elements [0, 1] and [1, 0] in the matrix F. This is more expensive than the formula involving the golden ratio, but I like the compact representation. From ayaskanta.swain at altair.com Fri May 20 07:26:19 2011 From: ayaskanta.swain at altair.com (Ayaskanta Swain) Date: Fri, 20 May 2011 16:56:19 +0530 Subject: os.access giving incorrect results on Windows Message-ID: <21581D39FA3BDF40904D75AF9653CE26065680B9@blrex.prog.altair.com> Hi Tim, Thanks for the reply and suggestions. I followed the patch provided by you in issue 2528, but the code looks very tricky to me. Anyways I wrote my Test.py script & tried only the def test_access_w(self): test case which is defined under class FileTests(unittest.TestCase) by providing my own directory path to check the write permissions on it. I executed my But it failed with the following errors - > python Test.py C:\temp\my_dir test_access_w (__main__.FileTests) ... ERROR ====================================================================== ERROR: test_access_w (__main__.FileTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "Test.py", line 14, in test_access_w f = os.open(dirpath, os.O_CREAT) OSError: [Errno 13] Permission denied: 'C:\\temp\\my_dir' ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (errors=1) Basically the os.open() function is failing to open a directory (In this case my_dir). The directory has write permissions for the user. Attached herewith is my Test script. Can you please suggest some simple python code which checks the write permissions of a directory in a straight forward way (Not by using unit tests) Thanks Ayaskant- Bangalore -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Test.py Type: application/octet-stream Size: 1577 bytes Desc: Test.py URL: From erichcart at gmail.com Fri May 20 07:37:21 2011 From: erichcart at gmail.com (ErichCart ErichCart) Date: Fri, 20 May 2011 04:37:21 -0700 (PDT) Subject: Python sets which support multiple same elements Message-ID: Many times when I am writing some program in python, I notice that I could transform my list into set, then use the set methods like union, intersection, set equality etc. , and it will solve my problem easily. But then I realize that if I transform my list into set, it will remove duplicates of elements in the list and so I will lose information from my original list. For example, I was writing a program to detect whether two strings are anagrams of each other. I had to write it like this: def isAnagram(w1, w2): w2=list(w2) for c in w1: if c not in w2: return False else: w2.remove(c) return True But if there was a data structure in python which supported duplicate elements(lets call it dset), then I could just write: def inAnagram(w1,w2): return dset(w1)==dset(w2) Example of some dset methods: {1,2,3,3} intersection {4,1,2,3,3,3} == {1,2,3,3} {1,2,3,3} union {4,1,2,3,3,3} == {1,2,3,3,3,4} {4,1,2,3,3,3} difference {1,2,3,3} == {4,3} Do you think that it would be a good idea to add this kind of data structure to python? Or did I overlook some other easy way to solve this kind of problems? From shunichi_wakabayashi at yahoo.co.jp Fri May 20 07:49:31 2011 From: shunichi_wakabayashi at yahoo.co.jp (Shunichi Wakabayashi) Date: Fri, 20 May 2011 04:49:31 -0700 (PDT) Subject: Python sets which support multiple same elements In-Reply-To: Message-ID: > Many times when I am writing some program in python, I notice that I > could transform my list into set, then use the set methods like union, > intersection, set equality etc. , and it will solve my problem easily. > But then I realize that if I transform my list into set, it will > remove duplicates of elements in the list and so I will lose > information from my original list. > > For example, I was writing a program to detect whether two strings are > anagrams of each other. I had to write it like this: > > def isAnagram(w1, w2): > w2=list(w2) > for c in w1: > if c not in w2: > return False > else: > w2.remove(c) > return True > > But if there was a data structure in python which supported duplicate > elements(lets call it dset), then I could just write: > > def inAnagram(w1,w2): > return dset(w1)==dset(w2) > > Example of some dset methods: > {1,2,3,3} intersection {4,1,2,3,3,3} == {1,2,3,3} > {1,2,3,3} union {4,1,2,3,3,3} == {1,2,3,3,3,4} > {4,1,2,3,3,3} difference {1,2,3,3} == {4,3} > > Do you think that it would be a good idea to add this kind of data > structure to python? Or did I overlook some other easy way to solve > this kind of problems? I think collections.Counter object may be useful for your purpose. http://docs.python.org/py3k/library/collections.html#collections.Counter From andreas.tawn at ubisoft.com Fri May 20 07:53:55 2011 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 20 May 2011 13:53:55 +0200 Subject: Python sets which support multiple same elements In-Reply-To: References: Message-ID: <654D9D97DA51AD479973BC2D5578603C0BEAB10101@PDC-MAIL-CMS01.ubisoft.org> > For example, I was writing a program to detect whether two strings are > anagrams of each other. I had to write it like this: > > def isAnagram(w1, w2): > w2=list(w2) > for c in w1: > if c not in w2: > return False > else: > w2.remove(c) > return True > > But if there was a data structure in python which supported duplicate > elements(lets call it dset), then I could just write: > > def inAnagram(w1,w2): > return dset(w1)==dset(w2) > > Example of some dset methods: > {1,2,3,3} intersection {4,1,2,3,3,3} == {1,2,3,3} > {1,2,3,3} union {4,1,2,3,3,3} == {1,2,3,3,3,4} > {4,1,2,3,3,3} difference {1,2,3,3} == {4,3} > > Do you think that it would be a good idea to add this kind of data > structure to python? Or did I overlook some other easy way to solve > this kind of problems? Just to do the anagram problem you could do... def isAnagram(w1, w2): return sorted(w1) == sorted(w2) To do the set-like operations, I guess that unless there's some itertools witchcraft available, you'd have to make your own dset type that inherits from list. Then you can define your own intersection/union etc. methods. Cheers, Drea From rosuav at gmail.com Fri May 20 07:57:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 May 2011 21:57:44 +1000 Subject: Python sets which support multiple same elements In-Reply-To: References: Message-ID: On Fri, May 20, 2011 at 9:37 PM, ErichCart ErichCart wrote: > For example, I was writing a program to detect whether two strings are > anagrams of each other. I had to write it like this: > > def isAnagram(w1, w2): > ?w2=list(w2) > ?for c in w1: > ? ?if c not in w2: > ? ? ?return False > ? ?else: > ? ? ?w2.remove(c) > ?return True You may find it helpful to simply sort the lists, keeping them as lists. If they're anagrams of each other, their sorted versions will be equal. Chris Angelico From erichcart at gmail.com Fri May 20 08:10:29 2011 From: erichcart at gmail.com (ErichCart ErichCart) Date: Fri, 20 May 2011 05:10:29 -0700 (PDT) Subject: Python sets which support multiple same elements References: Message-ID: <174adc6b-64b3-4b50-94fd-142570caba01@q12g2000prb.googlegroups.com> I see! How could I overlook sorting )) It seems that collections.Counter is what I was talking about. It seems to support all the set operations. Also I realized that the data structure which i was describing is called miltiset, and collections.Counter is python implementation of multiset. From nobody at nowhere.net.no Fri May 20 11:19:38 2011 From: nobody at nowhere.net.no (TheSaint) Date: Fri, 20 May 2011 23:19:38 +0800 Subject: how to get PID from subprocess library References: Message-ID: Miki Tebeka wrote: > The best module for doing such things is subprocess. And the Popen object > has a pid attribute I knew that, it's my fault that I'm not good to manage with popen. I found simplier to use subprocess.getstatusoutput. Maybe this function doesn't return the child pid, so I should adopt to work with Popen :( -- goto /dev/null From python at mrabarnett.plus.com Fri May 20 11:50:02 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 20 May 2011 16:50:02 +0100 Subject: hash values and equality In-Reply-To: <0deha8-6u9.ln1@satorlaser.homedns.org> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> Message-ID: <4DD68DAA.9050209@mrabarnett.plus.com> On 20/05/2011 07:33, Ulrich Eckhardt wrote: > Ethan Furman wrote: >> Several folk have said that objects that compare equal must hash equal, >> and the docs also state this >> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >> >> I'm hoping somebody can tell me what horrible thing will happen if this >> isn't the case? > > If you were familiar with what a hash map is, you wouldn't ask. The thing is > that the hash is used to look up the place in the map where the thing is > stored. If two equal objects have different hashes, they will be stored in > different places in the hash map. [snip] Is this strictly true? I thought that the hash value, an integer, is moduloed (Is that how you spell it? Looks weird!) with the number of array elements to give an index into the array, so different hashes could give the same index, and objects with different hashes could be stored in the same 'bucket'. From rosuav at gmail.com Fri May 20 12:20:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 May 2011 02:20:04 +1000 Subject: hash values and equality In-Reply-To: <4DD68DAA.9050209@mrabarnett.plus.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: On Sat, May 21, 2011 at 1:50 AM, MRAB wrote: > [snip] > Is this strictly true? I thought that the hash value, an integer, is > moduloed (Is that how you spell it? Looks weird!) with the number of > array elements to give an index into the array, so different hashes > could give the same index, and objects with different hashes could be > stored in the same 'bucket'. There can always be hash collisions between different objects, but the assumption is that two identical objects will _always_ "collide". Chris Angelico From debatem1 at gmail.com Fri May 20 12:26:28 2011 From: debatem1 at gmail.com (geremy condra) Date: Fri, 20 May 2011 09:26:28 -0700 Subject: obviscating python code for distribution In-Reply-To: <4dd613f5$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd613f5$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 12:10 AM, Steven D'Aprano wrote: > On Thu, 19 May 2011 17:56:12 -0700, geremy condra wrote: > >> TL;DR version: large systems have indeed been verified for their >> security properties. > > How confident are we that the verification software is sufficiently bug- > free that we should trust their results? Pretty confident. Most formal verification systems are developed in terms of a provably correct kernel bootstrapping the larger system. The important thing is that since that kernel doesn't need to be complete (only correct) it can typically be easily verified, and in some cases exhaustively tested. There are also techniques which generate certificates of correctness for verifiers that aren't provably correct, but that isn't an area I know much about, and I don't know if that gets used in practice. The bigger risk is really that the model you're feeding it is wrong. > How confident are we that the verification software tests every possible > vulnerability, as opposed to merely every imaginable one? Formal provers typically don't work by just throwing a bunch of input at a piece of software and then certifying it. They take a set of specifications (the model), a set of assumptions, and the program in question, and provide a proof (in the mathematical sense) that the program is exactly equivalent to the model given the assumptions. Testing the assumptions and model are typically part of the development process, though, and that's definitely a possible source of errors. Geremy Condra From ckaynor at zindagigames.com Fri May 20 12:36:00 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 20 May 2011 09:36:00 -0700 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: On Fri, May 20, 2011 at 9:20 AM, Chris Angelico wrote: > On Sat, May 21, 2011 at 1:50 AM, MRAB wrote: > > [snip] > > Is this strictly true? I thought that the hash value, an integer, is > > moduloed (Is that how you spell it? Looks weird!) with the number of > > array elements to give an index into the array, so different hashes > > could give the same index, and objects with different hashes could be > > stored in the same 'bucket'. > > There can always be hash collisions between different objects, but the > assumption is that two identical objects will _always_ "collide". I think the question was: can this dummy code ever produce a set containing less then itemCount items (for 0 < itemCount < 2**32)? itemCount = 100 import itertools counter = itertools.count().next class Test(object): def __init__(self): self.hash = counter() def __hash__(self): return self.hash def __eq__(self, other): return True set((Test() for i in xrange(itemCount))) > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From beliavsky at aol.com Fri May 20 12:39:51 2011 From: beliavsky at aol.com (Beliavsky) Date: Fri, 20 May 2011 09:39:51 -0700 (PDT) Subject: Why did Quora choose Python for its development? Message-ID: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> I thought this essay on why one startup chose Python was interesting. http://www.quora.com/Why-did-Quora-choose-Python-for-its-development PHP was out of the question. Facebook is stuck on that for legacy reasons, not because it's the best choice right now.[1] Our main takeaway from that experience is that programming language choice is very important and is extremely costly to change. Python was a language that Charlie and I both knew reasonably well (though I know it a lot better now than I did when we started). We also briefly considered C#, Java, and Scala. The biggest issues with Python are speed and the lack of typechecking. C# seemed pretty promising. As a programming language, it's great, but: ?We didn't want to be on the Microsoft stack. We were up for learning something new, and MS SQL Server actually seemed pretty good, but we knew we'd need to integrate with lots of open source code that has only second-class support for .NET, if it supports it at all. Also, most of the best engineers these days are used to open source stuff. ?We didn't want to take the risk of being on Mono (an open source implementation of C#/.NET). It's not clear how long funding will be around for that project, and I'd heard of various performance problems. Plus, it seemed like everything else in the C# ecosystem would assume we were on the Microsoft stack. For a lot of little reasons, Java programs end up being longer and more painful to write than the equivalent Python programs. It's also harder to interoperate with non-Java stuff. Scala had a lot of the downsides of Java and the JVM, although it wasn't quite as bad. The language seemed a little too new and like it would bring some unnecessary risk (for example, who knows how good will support be in 10 years). Two other languages we very briefly thought about were OCaml and Haskell (neither had big enough ecosystems or good enough standard libraries, and both were potentially too hard for some designers/data analysts/non-engineers who might need to write code). We decided that Python was fast enough for most of what we need to do (since we push our performance-critical code to backend servers written in C++ whenever possible). As far as typechecking, we ended up writing very thorough unit tests which are worth writing anyway, and achieve most of the same goals. We also had a lot of confidence that Python would continue to evolve in a direction that would be good for the life of our codebase, having watched it evolve over the last 5 years. So far, we've been pretty happy with the choice. There's a small selection bias, but all of the employees who'd been working with other languages in the past have been happy to transition to Python, especially those coming from PHP. Since starting the following things have happened: ?Python 2.6 got to the point where enough of the libraries we used were compatible with it, and we made a very easy transition to it. ?Tornado (web framework) was released as open source, and we moved our live updating web service to that. ?PyPy got to the point where it looks like it will eventually be usable and will give us a significant speedup. All together, these give us confidence that the language and ecosystem is moving in a good direction. [1] What are the horrors of PHP? and Do Facebook engineers enjoy programming in PHP? and Why hasn't Facebook migrated away from PHP? and What are some of the advantages of PHP over other programming languages? for more on that. Via Nizameddin Ha?im Ordulu and JR Ignacio. From steve+comp.lang.python at pearwood.info Fri May 20 13:07:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2011 17:07:25 GMT Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dd69fcd$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 May 2011 16:54:06 +1000, Chris Angelico wrote: > If someone has time to kill (as if!), it'd be awesome to get a new > numeric type that uses bc's code; any other numeric type (int, long, > float) could autopromote to it, removing the dilemma of which to promote > out of long and float. Hmm... Python 4.0, 'bc' is the new default > integer and everything else is a performance optimization? Heh. The problem is, it isn't *just* a performance optimization, there is a semantic difference too. Consider: >>> x = 1e-300 >>> x*x == 0 True But using something with more precision: >>> from fractions import Fraction >>> x = Fraction(10)**-300 >>> x*x == 0 False So you get different behaviour between floats and arbitrary precision numbers. -- Steven From rustompmody at gmail.com Fri May 20 13:21:11 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 20 May 2011 10:21:11 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6c3af321-599c-4ee0-8da6-cf47af0728ed@z13g2000prk.googlegroups.com> On May 20, 1:48?pm, Hans Georg Schaathun wrote: > On 20 May 2011 06:55:35 GMT, Steven D'Aprano? wrote: > > : ?On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: > : > : > [I agree with you Xah that recursion is a technical word that should not > : > be foisted onto lay users.] > : > : ?I think that is a patronizing remark that under-estimates the > : ?intelligence of lay people and over-estimates the difficulty of > : ?understanding recursion. > > Could we then say that ?recursion is a technical word that should > not /unnecessarily/ be foisted onto lay users?? Yes. Steven is talking about the fact that the intelligent lay user may be intelligent. I was referring to the fact that the intelligent lay user is a lay user. [Not my main point except to say that dragging in alt.usage.english into a discussion of recursion seemed a tad unnecessary and unfair] So the ILU may understand recursion He may not know "recursion" From nobody at nowhere.com Fri May 20 13:48:10 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 20 May 2011 18:48:10 +0100 Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd613f5$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 20 May 2011 07:10:45 +0000, Steven D'Aprano wrote: > How confident are we that the verification software tests every possible > vulnerability, Formal verification is based upon mathematical proof, not empirical results. As Dijkstra said: "Program testing can be used to show the presence of bugs, but never to show their absence". For complex algorithms, it may be infeasible to cover even all of the "interesting" cases, let alone a representative sample of all possible cases. For concurrent (multi-threaded) code, it's often impractical to methodically test various interleavings. From ethan at stoneleaf.us Fri May 20 13:56:02 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 May 2011 10:56:02 -0700 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD5FF8F.604@stoneleaf.us> Message-ID: <4DD6AB32.7030306@stoneleaf.us> Chris Rebert wrote: > On Thu, May 19, 2011 at 10:43 PM, Ethan Furman wrote: >> Several folk have said that objects that compare equal must hash equal, and >> the docs also state this >> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >> >> I'm hoping somebody can tell me what horrible thing will happen if this >> isn't the case? Here's a toy example of a class I'm thinking of writing >> that will compare equal with int's, but hash differently: > > This is the part considered "horrible": >> --> d >> {: '3', >> 1: '1.0', >> 2: '2.0', >> 3: '3.0', >> : '2', >> : '1'} > > Compare: >>>> x = {5.0 : 'foo'} >>>> x[5] > 'foo' > > Here's a more common/plausible "horrible" case closer to what the docs > writers had in mind: >--> class Naughty(object): > ... def __init__(self, n): > ... self.n = n > ... def __eq__(self, other): > ... return self.n == other.n > ... >--> Naughty(5) == Naughty(5) > True >--> Naughty(5) is Naughty(5) > False >--> bad = Naughty(3) >--> y = {bad : 'foo'} >--> y[bad] # just happens to work > 'foo' >--> del bad >--> # ok, how do we get to 'foo' now? >--> y[Naughty(3)] # try the obvious way > Traceback (most recent call last): > File "", line 1, in > KeyError: <__main__.Naughty object at 0x2a1cb0> >--> # We're screwed. > > Naughty instances (and similar) can't be used sensibly as hash keys > (unless you /only/ care about object identity; this is often not the > case). I tried this sequence (using Python 3, BTW -- forgot to mention that little tidbit -- sorry!): --> del two --> two Traceback (most recent call last): File "", line 1, in NameError: name 'two' is not defined --> d {<__main__.Wierd object at 0x00C0C950>: '3', 1: '1.0', 2: '2.0', 3: '3.0', <__main__.Wierd object at 0x00B3AC10>: '2', <__main__.Wierd object at 0x00B32E90>: '1'} --> new_two = Wierd(2) --> d[new_two] '2' ~Ethan~ From bahamutzero8825 at gmail.com Fri May 20 13:56:45 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 20 May 2011 12:56:45 -0500 Subject: List of WindowsError error codes and meanings Message-ID: <4DD6AB5D.1040707@gmail.com> This is probably somewhat off-topic, but where would I find a list of what each error code in WindowsError means? WindowsError is so broad that it could be difficult to decide what to do in an except clause. Fortunately, sys.exc_info()[1][0] holds the specific error code, so I could put in an if...elif...else clause inside the except clause if I needed to, but I don't know what all the different errors are. From ethan at stoneleaf.us Fri May 20 13:57:42 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 May 2011 10:57:42 -0700 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> Message-ID: <4DD6AB96.2040307@stoneleaf.us> Peter Otten wrote: > Ethan Furman wrote: > >> Several folk have said that objects that compare equal must hash equal, >> and the docs also state this >> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >> >> I'm hoping somebody can tell me what horrible thing will happen if this >> isn't the case? Here's a toy example of a class I'm thinking of writing >> that will compare equal with int's, but hash differently: >> >> --> class Wierd(): >> ... def __init__(self, value): >> ... self.value = value >> ... def __eq__(self, other): >> ... return self.value == other >> ... def __hash__(self): >> ... return hash((self.value + 13) ** 3) >> ... > > Try this: > >>>> d = {Wierd(1): 0} >>>> 1 in d > False >>>> 1 in d.keys() > True > My apologies -- I'm trying this in Python3: --> two in d True --> two in d.keys() True --> --> 2 in d True --> 2 in d.keys() True ~Ethan~ From ian.g.kelly at gmail.com Fri May 20 13:59:44 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 11:59:44 -0600 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: On Fri, May 20, 2011 at 10:36 AM, Chris Kaynor wrote: > I think the question was: can this dummy code ever produce a set containing > less then itemCount items (for 0 < itemCount < 2**32)? In CPython, no. Even when you get a hash collision, the code checks to see whether the hashes are actually equal before it calls the rich comparison, the former check being a much faster operation since the hash values are cached. I'm not sure whether this can be counted on for all Python implementations, though. From gsowww at yahoo.co.uk Fri May 20 14:03:09 2011 From: gsowww at yahoo.co.uk (GSO) Date: Fri, 20 May 2011 19:03:09 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <6c3af321-599c-4ee0-8da6-cf47af0728ed@z13g2000prk.googlegroups.com> References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <6c3af321-599c-4ee0-8da6-cf47af0728ed@z13g2000prk.googlegroups.com> Message-ID: On 20 May 2011 18:21, rusi wrote: > On May 20, 1:48 pm, Hans Georg Schaathun wrote: > > On 20 May 2011 06:55:35 GMT, Steven D'Aprano < > steve+comp.lang.pyt... at pearwood.info> wrote: > > > > : On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: > > : > > : > [I agree with you Xah that recursion is a technical word that should > not > > : > be foisted onto lay users.] > > : > > : I think that is a patronizing remark that under-estimates the > > : intelligence of lay people and over-estimates the difficulty of > > : understanding recursion. > > > > Could we then say that ?recursion is a technical word that should > > not /unnecessarily/ be foisted onto lay users?? > > Yes. > Steven is talking about the fact that the intelligent lay user may be > intelligent. > I was referring to the fact that the intelligent lay user is a lay > user. [Not my main point except to say that dragging in > alt.usage.english into a discussion of recursion seemed a tad > unnecessary and unfair] > > So the ILU may understand recursion > He may not know "recursion" > -- > > As a trainer there is an issue as to whether or not you should use words that your trainees will not understand, the argument being that if you don't use new words your trainees will not learn any new words. It is also very much a Unix philosophy that if you want idiots, feed them idiot food, so think very carefully about what you put on the menu. I think recursion was very much a list processing concept for list processing languages. I like the purity of LISP, but COBOL for business applications any day. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at mellowood.ca Fri May 20 14:03:16 2011 From: bob at mellowood.ca (bvdp) Date: Fri, 20 May 2011 11:03:16 -0700 (PDT) Subject: TK program problem Message-ID: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> I've just done an update to my system here to Ubuntu 11.04. Mostly no problems ... but I have an important (to me) python/TK program that's stopped working. Well, it works ... mostly. The python version is 2.7.1+ (no idea what the + means!). I _think_ I have traced the problem to certain menus which call a class. The calls appear to be ignored. Basically, what I have is a line like: bf = makeButtonBar(root, row=0, column=0, buttons=( ("Quit", self.quitall ), ("Stop", self.stopPmidi ), ("New Dir", self.chd), ("Load Playlist", self.playList), ("Favorites", selectFav), ("Options", setOptions) ) ) To create a menu bar. The function makeButtonBar() creates the buttons with: for txt, cmd in buttons: Button(bf, text=txt, height=1, command=cmd).grid(column=c, row=0, pady=5) All this is fine (and worked perfectly before my upgrade). The menu items which are ordinary functions continue to work. BUT the callbacks which are classes are just ignored when they are clicked. A cut from one of the ignored classes: class selectFav: def __init__(self): ... And I've inserted some prints in the __init__() and nothing is printed. Also, converted the class to new-style () but no change there either. Either python/tk has changed or my system is totally $*(#*#. Suggestions welcome! From stef.mientki at gmail.com Fri May 20 14:27:56 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 20 May 2011 20:27:56 +0200 Subject: maybe useful : datetime conversion Message-ID: <4DD6B2AC.10704@gmail.com> hello, using datetimes from a lot of different sources, in many languages, I had about 30 python helper routines, which I now packed in one class, much simpler. Although I used the Delphi date-format as the base, it shouldn't be difficult to rewrite the class for another type. The input can be one of the following types : - None : the current date-time is used - 30000.9 : a Delphi datetime - 30000 : a Delphi datetime - "30000.9" : a Delphi datetime as a string - "30000,9" : a Delphi datetime as a (Dutch) string - "20-5-11" : short year notation - "20-05-2011" : long year notation - "2009-09-24 10:12:24" : Access string - datetime.datetime ( 2011, 1, 15 ) - time.struct_time - wx.DateTime - time.time() (through method from_time) Maybe someone can use it. cheers, Stef -------------- next part -------------- A non-text attachment was scrubbed... Name: module1.py Type: text/x-python Size: 4880 bytes Desc: not available URL: From ethan at stoneleaf.us Fri May 20 14:38:41 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 May 2011 11:38:41 -0700 Subject: hash values and equality In-Reply-To: <0deha8-6u9.ln1@satorlaser.homedns.org> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> Message-ID: <4DD6B531.3080300@stoneleaf.us> Ulrich Eckhardt wrote: > Ethan Furman wrote: >> Several folk have said that objects that compare equal must hash equal, >> and the docs also state this >> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >> >> I'm hoping somebody can tell me what horrible thing will happen if this >> isn't the case? > > If you were familiar with what a hash map is, you wouldn't ask. The thing is > that the hash is used to look up the place in the map where the thing is > stored. If two equal objects have different hashes, they will be stored in > different places in the hash map. Looking for object1 will then not turn up > with object2, even though they are equal. In this case this is the behavior I want. > If this is something you don't > care about, and all you care about is identity, then I'd derive the hash > from each object's ID. This won't work, as objects of the same type that compare equal should (and do, in my code) hash equal. > This ID has another property which is something that is assumed for hashes, > and your code seems a bit to get that wrong, too, and that is that the hash > must not change. The hash does not change on the instances, and is the same for all instances of my type that compare equal. ~Ethan~ From debatem1 at gmail.com Fri May 20 14:43:43 2011 From: debatem1 at gmail.com (geremy condra) Date: Fri, 20 May 2011 11:43:43 -0700 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd69fcd$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd69fcd$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 10:07 AM, Steven D'Aprano wrote: > On Fri, 20 May 2011 16:54:06 +1000, Chris Angelico wrote: > >> If someone has time to kill (as if!), it'd be awesome to get a new >> numeric type that uses bc's code; any other numeric type (int, long, >> float) could autopromote to it, removing the dilemma of which to promote >> out of long and float. Hmm... Python 4.0, 'bc' is the new default >> integer and everything else is a performance optimization? Heh. > > The problem is, it isn't *just* a performance optimization, there is a > semantic difference too. Consider: > >>>> x = 1e-300 >>>> x*x == 0 > True > > But using something with more precision: > >>>> from fractions import Fraction >>>> x = Fraction(10)**-300 >>>> x*x == 0 > False > > > So you get different behaviour between floats and arbitrary precision > numbers. And this shows up in the above implementation; reimplementing it using Fractions and a truncated continuing fraction approximation of phi and the square root of 5 gets us up to about 500, at the cost of a very long computation time. Geremy Condra From ethan at stoneleaf.us Fri May 20 14:46:08 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 May 2011 11:46:08 -0700 Subject: hash values and equality In-Reply-To: <4DD5FF8F.604@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD5FF8F.604@stoneleaf.us> Message-ID: <4DD6B6F0.8050700@stoneleaf.us> Ethan Furman wrote: > Several folk have said that objects that compare equal must hash equal, > and the docs also state this > http://docs.python.org/dev/reference/datamodel.html#object.__hash__ Two things I didn't make clear originally: I'm using Python3. My objects (of type Wierd) obey the premise of comparing equal also meaning hashing equal (with other objects of type Wierd). Perhaps my question could be narrowed down to: Should the docs actually say that "objects of the same *type* that compare equal must hash equal", or is there an underlying reason that objects of *different types* that happen to compare equal *must not* have different hashes? In other words, is the fact that everything tried so far in Python3 to break my toy code has failed to do so just an implementation detail of Python3? ~Ethan~ From clp2 at rebertia.com Fri May 20 15:00:43 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 20 May 2011 12:00:43 -0700 Subject: hash values and equality In-Reply-To: <4DD6AB32.7030306@stoneleaf.us> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD5FF8F.604@stoneleaf.us> <4DD6AB32.7030306@stoneleaf.us> Message-ID: On Fri, May 20, 2011 at 10:56 AM, Ethan Furman wrote: > Chris Rebert wrote: >> On Thu, May 19, 2011 at 10:43 PM, Ethan Furman wrote: >>> Several folk have said that objects that compare equal must hash equal, >>> and >>> the docs also state this >>> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >>> >>> I'm hoping somebody can tell me what horrible thing will happen if this >>> isn't the case? >> Here's a more common/plausible "horrible" case closer to what the docs >> writers had in mind: >> --> class Naughty(object): >> ... ? ? def __init__(self, n): >> ... ? ? ? ? self.n = n >> ... ? ? def __eq__(self, other): >> ... ? ? ? ? return self.n == other.n >> ... >> --> Naughty(5) == Naughty(5) >> True >> --> Naughty(5) is Naughty(5) >> False >> --> bad = Naughty(3) >> --> y = {bad : 'foo'} >> --> y[bad] # just happens to work >> 'foo' >> --> del bad >> --> # ok, how do we get to 'foo' now? >> --> y[Naughty(3)] # try the obvious way >> Traceback (most recent call last): >> ?File "", line 1, in >> KeyError: <__main__.Naughty object at 0x2a1cb0> >> --> # We're screwed. >> >> Naughty instances (and similar) can't be used sensibly as hash keys >> (unless you /only/ care about object identity; this is often not the >> case). > > I tried this sequence (using Python 3, BTW -- forgot to mention that little > tidbit -- sorry!): Doesn't matter anyway. > --> del two > --> two > Traceback (most recent call last): > ?File "", line 1, in > NameError: name 'two' is not defined > --> d > {<__main__.Wierd object at 0x00C0C950>: '3', > ?1: '1.0', > ?2: '2.0', > ?3: '3.0', > ?<__main__.Wierd object at 0x00B3AC10>: '2', > ?<__main__.Wierd object at 0x00B32E90>: '1'} > --> new_two = Wierd(2) > --> d[new_two] > '2' Right, this is why I went to the trouble of writing Naughty instead of using Wierd. Wierd's exact problem is less common and less severe. The "equality implies identical hash" rule is not a universal one; some other languages instead impose the lesser requirement of "equality and same (or related) types implies identical hash". In Ruby for instance: irb(main):001:0> 1 == 1.0 => true irb(main):002:0> a = {1.0 => 'hi'} # float key => {1.0=>"hi"} irb(main):003:0> a[1] = 'bye' # int key => "bye" irb(main):004:0> a # notice how they don't collide: => {1=>"bye", 1.0=>"hi"} (Contrast this with my earlier analogous Python example.) Basically, Naughty is fundamentally broken [hash(Naughty(2)) != hash(Naughty(2))], whereas Wierd merely defies convention [hash(2) != hash(Wierd(2)) but hash(Wierd(2)) == hash(Wierd(2))]. Cheers, Chris -- http://rebertia.com From lists at cheimes.de Fri May 20 15:01:22 2011 From: lists at cheimes.de (Christian Heimes) Date: Fri, 20 May 2011 21:01:22 +0200 Subject: hash values and equality In-Reply-To: <4DD68DAA.9050209@mrabarnett.plus.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: Am 20.05.2011 17:50, schrieb MRAB: > Is this strictly true? I thought that the hash value, an integer, is > moduloed (Is that how you spell it? Looks weird!) with the number of > array elements to give an index into the array, so different hashes > could give the same index, and objects with different hashes could be > stored in the same 'bucket'. I don't think 'moduloed' is an existing word but your description is mostly correct. The hash of the object and length of the hash table are used to calculate the position in the hash table. However Python's implementation doesn't use buckets to reduce memory usage and pointer dereferencing. If a slot in the hash table is already filled with an object that is not equal to the new object (a collision), the hash is shifted and the new slot is checked. The implementation detail is well described in Modules/dictobject.c. Christian From ericsnowcurrently at gmail.com Fri May 20 15:13:45 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 20 May 2011 13:13:45 -0600 Subject: ABC validation strictly on an instance Message-ID: The current ABC implementation in Python implies that the class of a conformant instance complies with the ABC. The implication does not carry down to the compliance of the instance itself. This means that if you inherit from an ABC that has an abstract property, your subclass must have a matching name to that property, or you will get a TypeError. (Same goes for abstract methods--a matching name must be bound, even if not to a function). For example: class X(metaclass=ABCMeta): @abstractproperty def id(self): pass class Y(X): id = 1 class Z(X): def __init__(self, id): self._id = id @property def id(self): return self._id class Fail(X): def __init__(self, id): self.id = id So classes Y and Z will work fine, but class Fail will raise a TypeError when you instantiate [1] Fail, even though it "implemented" id in the instance __init__ [2]. I looked at this all yesterday and did not see a great way to approach this. The best I could come up with was the following: class X(metaclass=ABCMeta): @abstractproperty def id(self): pass @X.register class Y: def __init__(self, id): self.id = id So this is a promise that Y comforms to X without any of the automatic validation. However, you don't get _any_ validation. You also lose any otherwise inherited features, so it is more like an interface than an abstract class. I am not so sure about that above solution because it seems like such a loose constraint. I discussed the validation problem in another email [1]. I am not sure if there is a way to bake into Python an effective check that an instance (not the class of the instance) is compliant with an ABC. However, it would be cool if there was. The current checking mechanism for ABCs happens in object.__new__ at instantiation time. At that point it has no knowledge of what names your instance will have, other than those that come from the class. I spent a while looking at this whole problem yesterday and came up with a bunch of approaches for that Fail situation above. However, they mostly seem like overkill to me. I have included them below. If anyone has ideas on how to approach the problem of using an ABC but satisfying it with instance names, I would love to hear it. Thanks! -eric [1] In this case it would be nice to know at definition time that the class is missing the abstract "method". You don't want an exception at definition time for every subclass, though, since some you may want to keep abstract. I wrote up a decorator that allows you to validate at definition time in an email yesterday ( http://mail.python.org/pipermail/python-list/2011-May/1272541.html). [2] A related issue opened just yesterday: http://bugs.python.org/issue12128 ################################################################ 1 - properties, with a getter and setter. At definition time. This seems like overkill: class X(object): __metaclass__ = ABCMeta @abstractproperty def name(self): pass class Y(X): def __init__(self, name): self._name = name super(Y, self).__init__() @property def name(self): return self._name @name.setter def name(self, val): self._name = val 2 - getter/setter functions. At definition time. This does not guarantee the name, only access around it: class X(object): __metaclass__ = ABCMeta @abstractmethod def get_name(self): pass @abstractmethod def set_name(self): pass class Y(X): def __init__(self, name): self.name = name super(Y, self).__init__() def get_name(self): return self.name def set_name(self, val): self.name = val 3 - descriptors directly. At definition time. Like the properties example: class Name(object): def __get__(self, obj, cls): if obj is None: return self return obj._name def __set__(self, obj, val): obj._name = val class X(object) __metaclass__ = ABCMeta @abstractproperty def name(self): pass class Y(X): name = Name() def __init__(self, name): self.name = name super(Y, self).__init__() 4 - getattribute. At run time. More overkill: class Enforcer(object): API = () def __getattribute__(self, attr): if attr in API and attr not in dir(self): raise TypeError("Expected attribute: %s" % attr) return object.__getattribute__(self, attr) def __setattr(self, attr, val): if attr in API and attr not in dir(self): raise TypeError("Expected attribute: %s" % attr) object.__setattribute__(self, attr, val) class X(Enforcer): API = ("name",) class Y(X): def __init__(self, name): self.name = name super(Y, self).__init__() 5 - metaclass. At instantiation time. Overkill again: class Enforcer(object): class SomeMeta(type): def enforces_API(f): def __init__(self, *args, **kwargs): f(self, *args, **kwargs) for name in self.API: if name not in dir(self): raise TypeError("Expected attribute: %s" % attr) __init__.__doc__ = f.__doc__ return __init__ def __new__(self, name, bases, namespace): cls = super(SomeMeta, self).__new__(self, name, bases, namespace) __init__ = namespace.get("__init__") if not __init__: def __init__(self, *args, **kwargs): super(cls, self).__init__(*args, **kwargs) namespace["__init__"] = self.enforces_API(__init__) return cls API = () class X(Enforcer): API = ("name",) class Y(X): def __init__(self, name): self.name = name super(Y, self).__init__() 6 - decorator. At instantiation time. Apply to the __init__ of each class that must enforce the API or to the base __init__ and call super after the assignments... class Enforcer(object): API = () def enforces_API(f): def __init__(self, *args, **kwargs): f(self, *args, **kwargs) for name in self.API: if name not in dir(self): raise TypeError("Expected attribute: %s" % attr) __init__.__doc__ = f.__doc__ return __init__ class X(Enforcer): API = ("name",) class Y(X): @X.enforces_API def __init__(self, name): self.name = name super(Y, self).__init__() 7 - class decorator. At definition time. Apply to each class that must enforce the API... class Enforcer(object): API = () def enforces_API(cls): def __init__decorator(f): def __init__(self, *args, **kwargs): f(self, *args, **kwargs) for name in self.API: if name not in dir(self): raise TypeError("Expected attribute: %s" % attr) __init__.__doc__ = f.__doc__ return __init__ __init__ = cls__dict__.get("__init__") if not __init__: def __init__(self, *args, **kwargs): super(cls, self).__init__(*args, **kwargs) cls.__init__ = self.enforces_API(__init__) @Enforcer.enforces_API class X(Enforcer): API = ("name",) @Enforcer.enforces_API class Y(X): def __init__(self, name): self.name = name super(Y, self).__init__() -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri May 20 15:20:17 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 13:20:17 -0600 Subject: TK program problem In-Reply-To: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 12:03 PM, bvdp wrote: > All this is fine (and worked perfectly before my upgrade). The menu > items which are ordinary functions continue to work. BUT the callbacks > which are classes are just ignored when they are clicked. I'm not a tk user, but it sounds like it has regressed from accepting arbitrary callables as callbacks to accepting functions specifically. What happens if you replace: ("Favorites", selectFav), with: ("Favorites", lambda: selectFav()), From genstein at invalid.invalid Fri May 20 15:47:29 2011 From: genstein at invalid.invalid (Genstein) Date: Fri, 20 May 2011 20:47:29 +0100 Subject: List of WindowsError error codes and meanings In-Reply-To: References: Message-ID: On 20/05/2011 18:56, Andrew Berg wrote: > This is probably somewhat off-topic, but where would I find a list of > what each error code in WindowsError means? Assuming it's a Win32 error code, winerror.h from the Platform SDK holds the answer. One version is linked below, it's in theory out of date (2003) but all the best known codes are present. http://msdn.microsoft.com/en-us/library/ms819773.aspx http://msdn.microsoft.com/en-us/library/ms819775.aspx For example, "WindowsError [error 5] Access is denied" matches ERROR_ACCESS_DENIED (5L). HRESULTS may also crop up (e.g. E_FAIL, 0x80040005) which are harder to list exhaustively since subsystems and COM components may roll their own codes of various sorts; but common ones are present in winerror.h. All the best, -eg. From python at mrabarnett.plus.com Fri May 20 16:17:29 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 20 May 2011 21:17:29 +0100 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: <4DD6CC59.6070908@mrabarnett.plus.com> On 20/05/2011 20:01, Christian Heimes wrote: > Am 20.05.2011 17:50, schrieb MRAB: >> Is this strictly true? I thought that the hash value, an integer, is >> moduloed (Is that how you spell it? Looks weird!) with the number of >> array elements to give an index into the array, so different hashes >> could give the same index, and objects with different hashes could be >> stored in the same 'bucket'. > > I don't think 'moduloed' is an existing word but your description is > mostly correct. The hash of the object and length of the hash table are > used to calculate the position in the hash table. However Python's > implementation doesn't use buckets to reduce memory usage and pointer > dereferencing. If a slot in the hash table is already filled with an > object that is not equal to the new object (a collision), the hash is > shifted and the new slot is checked. The implementation detail is well > described in Modules/dictobject.c. > A brief search on the web found a use of the word in 1982. From mail at timgolden.me.uk Fri May 20 16:18:14 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 20 May 2011 21:18:14 +0100 Subject: List of WindowsError error codes and meanings In-Reply-To: <4DD6AB5D.1040707@gmail.com> References: <4DD6AB5D.1040707@gmail.com> Message-ID: <4DD6CC86.3090101@timgolden.me.uk> On 20/05/2011 18:56, Andrew Berg wrote: > This is probably somewhat off-topic, but where would I find a list of > what each error code in WindowsError means? WindowsError is so broad > that it could be difficult to decide what to do in an except clause. > Fortunately, sys.exc_info()[1][0] holds the specific error code, so I > could put in an if...elif...else clause inside the except clause if I > needed to, but I don't know what all the different errors are. Ultimately, only MSDN can tell you :) But to be going on with, a combination of Python's built-in errno module: http://docs.python.org/library/errno.html and the pywin32 package's winerror module: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/236b256c13bf/win32/Lib/winerror.py should help TJG From harrismh777 at charter.net Fri May 20 16:24:45 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 20 May 2011 15:24:45 -0500 Subject: obviscating python code for distribution In-Reply-To: <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Nonsense. How do you (generic "you", not any specific person) know that > you are not an idiot? lol Sum, ergo Idiot cogitat. Reminds me of a philosophical story I heard one time from my religion professor... ... as it goes, De Carte leads his horse into town ;-) and having hitched it to the rail outside the local saloon and sauntering up to the bar, the tender asks, "Would you be hav'in an ale sir?" ... De Carte replies, "I think not..." ... and then disappeared. :) From __peter__ at web.de Fri May 20 16:25:27 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 May 2011 22:25:27 +0200 Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD6AB96.2040307@stoneleaf.us> Message-ID: Ethan Furman wrote: > Peter Otten wrote: >> Ethan Furman wrote: >> >>> Several folk have said that objects that compare equal must hash equal, >>> and the docs also state this >>> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >>> >>> I'm hoping somebody can tell me what horrible thing will happen if this >>> isn't the case? Here's a toy example of a class I'm thinking of writing >>> that will compare equal with int's, but hash differently: >>> >>> --> class Wierd(): >>> ... def __init__(self, value): >>> ... self.value = value >>> ... def __eq__(self, other): >>> ... return self.value == other >>> ... def __hash__(self): >>> ... return hash((self.value + 13) ** 3) >>> ... >> >> Try this: >> >>>>> d = {Wierd(1): 0} >>>>> 1 in d >> False >>>>> 1 in d.keys() >> True >> > > My apologies -- I'm trying this in Python3: Then you have to convert the keys to a list explicitly: >>> class Weird: ... def __init__(self, value): ... self.value = value ... def __eq__(self, other): ... return self.value == other ... def __hash__(self): ... return hash((self.value + 13) **3) ... >>> d = {Weird(1): 0} >>> 1 in d False >>> 1 in d.keys() False >>> 1 in list(d.keys()) True From dotancohen at gmail.com Fri May 20 16:47:15 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 20 May 2011 23:47:15 +0300 Subject: Why did Quora choose Python for its development? In-Reply-To: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 19:39, Beliavsky wrote: > I thought this essay on why one startup chose Python was interesting. > > http://www.quora.com/Why-did-Quora-choose-Python-for-its-development > > PHP was out of the question. Facebook is stuck on that for legacy > reasons, not because it's the best choice right now.[1] Our main > takeaway from that experience is that programming language choice is > very important and is extremely costly to change. > > Python was a language that Charlie and I both knew reasonably well > (though I know it a lot better now than I did when we started). We > also briefly considered C#, Java, and Scala. The biggest issues with > Python are speed and the lack of typechecking. > > C# seemed pretty promising. As a programming language, it's great, > but: > > ?We didn't want to be on the Microsoft stack. We were up for learning > something new, and MS SQL Server actually seemed pretty good, but we > knew we'd need to integrate with lots of open source code that has > only second-class support for .NET, if it supports it at all. Also, > most of the best engineers these days are used to open source stuff. > ?We didn't want to take the risk of being on Mono (an open source > implementation of C#/.NET). It's not clear how long funding will be > around for that project, and I'd heard of various performance > problems. Plus, it seemed like everything else in the C# ecosystem > would assume we were on the Microsoft stack. > > For a lot of little reasons, Java programs end up being longer and > more painful to write than the equivalent Python programs. It's also > harder to interoperate with non-Java stuff. Scala had a lot of the > downsides of Java and the JVM, although it wasn't quite as bad. The > language seemed a little too new and like it would bring some > unnecessary risk (for example, who knows how good will support be in > 10 years). > > Two other languages we very briefly thought about were OCaml and > Haskell (neither had big enough ecosystems or good enough standard > libraries, and both were potentially too hard for some designers/data > analysts/non-engineers who might need to write code). > > We decided that Python was fast enough for most of what we need to do > (since we push our performance-critical code to backend servers > written in C++ whenever possible). As far as typechecking, we ended up > writing very thorough unit tests which are worth writing anyway, and > achieve most of the same goals. We also had a lot of confidence that > Python would continue to evolve in a direction that would be good for > the life of our codebase, having watched it evolve over the last 5 > years. > > So far, we've been pretty happy with the choice. There's a small > selection bias, but all of the employees who'd been working with other > languages in the past have been happy to transition to Python, > especially those coming from PHP. Since starting the following things > have happened: > > > ?Python 2.6 got to the point where enough of the libraries we used > were compatible with it, and we made a very easy transition to it. > ?Tornado (web framework) was released as open source, and we moved our > live updating web service to that. > ?PyPy got to the point where it looks like it will eventually be > usable and will give us a significant speedup. > > All together, these give us confidence that the language and ecosystem > is moving in a good direction. > > [1] What are the horrors of PHP? and Do Facebook engineers enjoy > programming in PHP? and Why hasn't Facebook migrated away from PHP? > and What are some of the advantages of PHP over other programming > languages? for more on that. > Via Nizameddin Ha?im Ordulu and JR Ignacio. > -- > http://mail.python.org/mailman/listinfo/python-list > They considered Haskell and OCaml and not a single mention of Perl? -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From albert at spenarnc.xs4all.nl Fri May 20 16:56:40 2011 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 20 May 2011 20:56:40 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <92f70aF9pqU1@mid.individual.net> Message-ID: In article , Chris Angelico wrote: >On Sat, May 7, 2011 at 7:21 PM, Gregory Ewing > wrote: >> Hans Georg Schaathun wrote: >> >>> You cannot reference nor manipulate a reference in python, and that IMHO >>> makes them more abstract. >> >> You can manipulate them just fine by moving them >> from one place to another: > >I think "manipulate" here means things like pointer arithmetic, which >are perfectly normal and common in C and assembly, but not in >languages where they're references. Adding an integer to a reference to an array element could have been perfectly well-defined in Algol: ref real operator+(ref real, int) That is called overloading of the plus operator not "pointer arithmetic". It is a misconception that these manipulation are dirty or ill-defined or unsafe. A similar extension would be possible in Python. Allusion to assembler where one adds a number to a register and can't tell whether the register contains an address or data are misleading. [This is not to say that I think it is advisable]. > >Chris Angelico Groetjes Albert. -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From albert at spenarnc.xs4all.nl Fri May 20 17:17:50 2011 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 20 May 2011 21:17:50 GMT Subject: What other languages use the same data model as Python? References: <4dbd1dbf$0$29991$c3e8da3$5496439d@news.astraweb.com> <92f70aF9pqU1@mid.individual.net> Message-ID: In article <4dc7fa2f$0$29991$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: >On Mon, 09 May 2011 12:52:27 +1200, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >> >>> Since you haven't explained what you think is happening, I can only >>> guess. >> >> Let me save you from guessing. I'm thinking of a piece of paper with a >> little box on it and the name 'a' written beside it. There is an arrow >> from that box to a bigger box. >> >> +-------------+ >> +---+ | | >> a | --+---------------->| | >> +---+ | | >> +-------------+ >> >> There is another little box labelled 'b'. After executing 'a = b', both >> little boxes have arrows pointing to the same big box. >[...] >> In this model, a "reference" is an arrow. Manipulating references >> consists of rubbing out the arrows and redrawing them differently. > >All very good, but that's not what takes place at the level of Python >code. It's all implementation. I think Hans Georg Schaathun made a good >objection to the idea that "Python has references": > > In Pascal a pointer is a distinct data type, and you can > have variables of a given type or of type pointer to that > given type. That makes the pointer a concrete concept > defined by the language. > >The same can't be said of "references" in Python. It's not part of Python >the language, although it might be part of Python's implementation. > > > >> Also >> in this model, a "variable" is a little box. It's *not* the same thing >> as a name; a name is a label for a variable, not the variable itself. > >That's essentially the same model used when dealing with pointers. I've >used it myself, programming in Pascal. The "little box" named a or b is >the pointer variable, and the "big box" is the data that the pointer >points to. > >It's not an awful model for Python: a name binding a = obj is equivalent >to sticking a reference (a pointer?) in box a that points to obj. >Certainly there are advantages to it. > >But one problem is, the model is ambiguous with b = a. You've drawn >little boxes a and b both pointing to the big box (which I deleted for >brevity). But surely, if a = 1234 creates a reference from a to the big >box 1234, then b = a should create a reference from b to the box a? There are cleaner languages. Algol 68 , Forth. This is Forth. VARIABLE A VARIABLE B 1234 ( anonymous "object" created by the language ) A ! A @ B ! ( Copy the content, equivalent of B=A). Algol 68 B:=A compiler : THINK ! THINK ! A is a "ref int" so it can't be stored into b which is a "ref int" which is the name of a place where an int can be stored (not where a ref int could be stored.) Solution: Algol dereferences A into an int, by getting its content. But it is a rule, very explicitly explained in the language definition. (If you are that clean you can handle "ref ref int q" where q is the name of a place where a "ref int" can be stored.) "real a" is in fact an abbreviation of "ref real a=loc real" meaning "a" is a reference to a local real, that is anonymous. The = means that the connection between a and that real is an identity, i.e. the connection can't be broken. (Forget about C++, "casting away const", yuck! ) In Forth and in Algol 68 storing a constant into a variable is very different from copying the content of a variable to some other variable. > >-- >Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From ethan at stoneleaf.us Fri May 20 17:48:27 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 May 2011 14:48:27 -0700 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <4DD6AB96.2040307@stoneleaf.us> Message-ID: <4DD6E1AB.4050603@stoneleaf.us> Peter Otten wrote: > Ethan Furman wrote: > >> Peter Otten wrote: >>> Ethan Furman wrote: >>> >>>> Several folk have said that objects that compare equal must hash equal, >>>> and the docs also state this >>>> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >>>> >>>> --> class Wierd(): >>>> ... def __init__(self, value): >>>> ... self.value = value >>>> ... def __eq__(self, other): >>>> ... return self.value == other >>>> ... def __hash__(self): >>>> ... return hash((self.value + 13) ** 3) >>>> ... >>> Try this: >>> >>>>>> d = {Wierd(1): 0} >>>>>> 1 in d >>> False >>>>>> 1 in d.keys() >>> True >>> >> My apologies -- I'm trying this in Python3: > > Then you have to convert the keys to a list explicitly: > >>>> class Weird: > ... def __init__(self, value): > ... self.value = value > ... def __eq__(self, other): > ... return self.value == other > ... def __hash__(self): > ... return hash((self.value + 13) **3) > ... >>>> d = {Weird(1): 0} >>>> 1 in d > False >>>> 1 in d.keys() > False >>>> 1 in list(d.keys()) > True Ah!! The light finally dawned! Many thanks for everyone's input. So if Wierd has a need to compare equal to some other type, it should implement a .equals() method. Gotcha. Likewise, if two different type's instances can compare equal, then for the most part they should be interchangeable. ~Ethan~ From bahamutzero8825 at gmail.com Fri May 20 17:55:01 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 20 May 2011 16:55:01 -0500 Subject: List of WindowsError error codes and meanings In-Reply-To: References: Message-ID: <4DD6E335.9090100@gmail.com> On 2011.05.20 02:47 PM, Genstein wrote: > On 20/05/2011 18:56, Andrew Berg wrote: > > This is probably somewhat off-topic, but where would I find a list of > > what each error code in WindowsError means? > > Assuming it's a Win32 error code, winerror.h from the Platform SDK holds > the answer. One version is linked below, it's in theory out of date > (2003) but all the best known codes are present. > > http://msdn.microsoft.com/en-us/library/ms819773.aspx > http://msdn.microsoft.com/en-us/library/ms819775.aspx > > For example, "WindowsError [error 5] Access is denied" matches > ERROR_ACCESS_DENIED (5L). I wasn't really sure if/how the codes in a WindowsError message mapped to something I would find on MSDN. That's really helpful, and I actually was able to find something more up-to-date: http://msdn.microsoft.com/en-us/library/ms681381%28v=VS.85%29.aspx > HRESULTS may also crop up (e.g. E_FAIL, 0x80040005) which are harder to > list exhaustively since subsystems and COM components may roll their own > codes of various sorts; but common ones are present in winerror.h. That's good to know. Thanks! From bob at mellowood.ca Fri May 20 18:12:31 2011 From: bob at mellowood.ca (bvdp) Date: Fri, 20 May 2011 15:12:31 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> > I'm not a tk user, but it sounds like it has regressed from accepting > arbitrary callables as callbacks to accepting functions specifically. > > What happens if you replace: > > ("Favorites", selectFav), > > with: > > ("Favorites", lambda: selectFav()), Okay, this works. Great and thanks! Seems to me that the way I was doing it should be alright ... and I've got some other programs exhibiting the same problem. Before I go "fixing" the issue ... is this known or even a bug? From ian.g.kelly at gmail.com Fri May 20 18:33:40 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 16:33:40 -0600 Subject: TK program problem In-Reply-To: <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 4:12 PM, bvdp wrote: > Okay, this works. Great and thanks! Seems to me that the way I was > doing it should be alright ... and I've got some other programs > exhibiting the same problem. > > Before I go "fixing" the issue ... is this known or even a bug? The docs [1] say that a callback is a function, so I guess that if it worked before it was just luck. You should bring it up on the tkinter list and see what they have to say about it, though. I'm a bit confused about why you would want to use a class as a callback anyway. It looks like when the button is clicked it instantiates the class and then throws it away? [1] http://docs.python.org/library/tkinter.html#tk-option-data-types From debatem1 at gmail.com Fri May 20 18:45:03 2011 From: debatem1 at gmail.com (geremy condra) Date: Fri, 20 May 2011 15:45:03 -0700 Subject: obviscating python code for distribution In-Reply-To: References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 20, 2011 at 1:24 PM, harrismh777 wrote: > Steven D'Aprano wrote: >> >> Nonsense. How do you (generic "you", not any specific person) know that >> you are not an idiot? > > lol ? ? Sum, ergo Idiot cogitat. > > > Reminds me of a philosophical story I heard one time from my religion > professor... > > ... as it goes, De Carte leads his horse into town ? ;-) ?and having hitched > it to the rail outside the local saloon and sauntering up to the bar, ?the > tender asks, "Would you be hav'in an ale sir?" > > ... De Carte replies, "I think not..." ? ? ... and then disappeared. At risk of being pedantic, I think you mean Descartes rather than De Carte. Geremy Condra From ericsnowcurrently at gmail.com Fri May 20 18:55:49 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 20 May 2011 16:55:49 -0600 Subject: validating a class against an ABC at definition time In-Reply-To: References: Message-ID: On Thu, May 19, 2011 at 11:33 PM, Eric Snow wrote: > Thinking about class APIs and validating a class against an API. The abc > module provides the tools to do some of this. One thing I realized, that I > hadn't noticed before, is that the abstractness of a class is measured when > instances of the class are created. This happens in object.__new__ > (pyobject.c). Validating thus when a class is defined would not be as > helpful, since there is no guarantee that the class is not meant to be > abstract as well. > > However, I have found that it is sometimes nice to validate a class at > definition time. This is particularly true for a class that does not > inherit from the abstract base class (but registers instead). > > Taking cues from abc.py and pyobject.c, here is a stab at a class decorator > that validates a class against another. > > def validate(abc): > if not isinstance(abc, type): > raise TypeError("Can only validate against classes") > def decorator(cls): > if not __debug__: > return cls > if not isinstance(cls, type): > raise TypeError("Can only validate classes") > abstracts = set() > for name in getattr(abc, "__abstractmethods__", set()): > value = getattr(cls, name, None) > if not value: > abstracts.add(name) > elif getattr(value, "__isabstractmethod__", False): > abstracts.add(name) > if abstracts: > sorted_methods = sorted(abstracts) > joined = ", ".join(sorted_methods) > msg = "Class {} does not implement abstract methods {} of class > {}" > raise TypeError(msg.format(cls.__name__, joined, abc.__name__)) > return cls > return decorator > > Stack this with the ABCMeta.register method and you can ensure that your > class is compliant with the ABC at the time you register it on that ABC. > > Does anyone find this irrelevant or superfluous? I know that it would be a > good idea to stay on top of your class's implementation of an ABC's abstract > methods. However, this seems like a good way of doing that > programmatically. > > Does anyone know a better way to do ABC validation at definition time? > > Thanks. > > -eric > > > > > I have revised this and made a recipe for it: http://code.activestate.com/recipes/577711-validating-classes-and-objects-against-an-abstract/ The question remains of what alternatives exist to this solution. Thanks! -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at mellowood.ca Fri May 20 19:07:39 2011 From: bob at mellowood.ca (bvdp) Date: Fri, 20 May 2011 16:07:39 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> Message-ID: Probably the fix is to use a function :) > The docs [1] say that a callback is a function, so I guess that if it > worked before it was just luck. ?You should bring it up on the tkinter > list and see what they have to say about it, though. > > I'm a bit confused about why you would want to use a class as a > callback anyway. ?It looks like when the button is clicked it > instantiates the class and then throws it away? I have no idea why I used a class like this, expect that it seemed to work at the time. Yes, the class is instantiated when the button is clicked. Then, the user stays in the class and uses its methods until he hits in the class. So, I guess what's happening is that I'm treating the button click much like a call to a new program/window which sets some options, etc. in the main program. You mention the tkinter group. Ummm, what group is that??? Best, From ian.g.kelly at gmail.com Fri May 20 19:29:05 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 May 2011 17:29:05 -0600 Subject: TK program problem In-Reply-To: References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 5:07 PM, bvdp wrote: > You mention the tkinter group. Ummm, what group is that??? http://tkinter.unpythonic.net/wiki/TkinterDiscuss From bob at mellowood.ca Fri May 20 19:34:27 2011 From: bob at mellowood.ca (bvdp) Date: Fri, 20 May 2011 16:34:27 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> Message-ID: On May 20, 4:29?pm, Ian Kelly wrote: > On Fri, May 20, 2011 at 5:07 PM, bvdp wrote: > > You mention the tkinter group. Ummm, what group is that??? > > http://tkinter.unpythonic.net/wiki/TkinterDiscuss Thanks. New one for me. I'll subscribe and see if they know about this. Best, From rantingrick at gmail.com Fri May 20 19:37:08 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 20 May 2011 16:37:08 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> Message-ID: <136b3435-a6bd-45fa-9c8c-5602ea23c861@s2g2000yql.googlegroups.com> On May 20, 6:07?pm, bvdp wrote: > Probably the fix is to use a function :) > > > The docs [1] say that a callback is a function, so I guess that if it > > worked before it was just luck. ?You should bring it up on the tkinter > > list and see what they have to say about it, though. > > > I'm a bit confused about why you would want to use a class as a > > callback anyway. ?It looks like when the button is clicked it > > instantiates the class and then throws it away? > > I have no idea why I used a class like this, expect that it seemed to > work at the time. Yes, the class is instantiated when the button is > clicked. Then, the user stays in the class and uses its methods until > he hits in the class. Thats sounds to me a lot like hammering square pegs though round holes... Perhaps you should explain first in "plain english" what problem your application is intended to solve, then how it is expected to interact with the user, and finally, what exactly is NOT working correctly. I would suffix such a documentary with the current source code, verbatim. From ericsnowcurrently at gmail.com Fri May 20 20:05:58 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 20 May 2011 18:05:58 -0600 Subject: validating a class against an ABC at definition time In-Reply-To: References: Message-ID: On Fri, May 20, 2011 at 4:55 PM, Eric Snow wrote: > > I have revised this and made a recipe for it: > > > http://code.activestate.com/recipes/577711-validating-classes-and-objects-against-an-abstract/ > > I also added this: http://code.activestate.com/recipes/577712-adding-__implements__-to-subclasses-during-abcmeta/ > The question remains of what alternatives exist to this solution. Thanks! > > -eric > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri May 20 20:44:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 May 2011 10:44:35 +1000 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: <4dd69fcd$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd69fcd$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 21, 2011 at 3:07 AM, Steven D'Aprano wrote: > On Fri, 20 May 2011 16:54:06 +1000, Chris Angelico wrote: > >> If someone has time to kill (as if!), it'd be awesome to get a new >> numeric type that uses bc's code; any other numeric type (int, long, >> float) could autopromote to it, removing the dilemma of which to promote >> out of long and float. Hmm... Python 4.0, 'bc' is the new default >> integer and everything else is a performance optimization? Heh. > > The problem is, it isn't *just* a performance optimization, there is a > semantic difference too. Consider: Sure, but I'm thinking here that the "gold standard" is accuracy, with other types allowing a programmer to forfeit some accuracy in favour of performance. (Oh, and I should have said "new default numeric type".) And, of course, I was thinking in a stupid hypothetical way that's extremely unlikely ever to happen. Chris Angelico From steve+comp.lang.python at pearwood.info Fri May 20 20:47:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 May 2011 00:47:56 GMT Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> Message-ID: <4dd70bbc$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 May 2011 21:17:29 +0100, MRAB wrote: > On 20/05/2011 20:01, Christian Heimes wrote: >> Am 20.05.2011 17:50, schrieb MRAB: >>> Is this strictly true? I thought that the hash value, an integer, is >>> moduloed (Is that how you spell it? Looks weird!) ... >> >> I don't think 'moduloed' is an existing word but your description is >> mostly correct. ... >> > A brief search on the web found a use of the word in 1982. All that means is that two people, three decades apart, used the same non- word :) I think you are treating "modulo" as a verb, equivalent to division, hence: a/b => a is divided by b a%b => a is "moduloed" by b But modulo is not a verb. It is a preposition, a modifier word. Just as you might say "the cat sat on the mat" (cat on mat) or "the Princess found a pea underneath her mattress" (pea underneath mattress) so mathematicians will say "a is taken modulo b" (a modulo b). English verbs nouns at the drop of a hat, but I've never heard of it verbing propositions: "The princess underneathed the pea." No, I don't think so. English does use "remainder" as a verb, although not in the mathematical sense; I think that: a%b => a is remaindered by b is at least grammatical, although still ugly and awkward. I'm afraid that in English, the best way to say what you are trying to say is moderately verbose: "the hash value, an integer, is taken modulo ..." -- Steven From barry at python.org Fri May 20 20:53:14 2011 From: barry at python.org (Barry Warsaw) Date: Fri, 20 May 2011 20:53:14 -0400 Subject: Python 2.6.7 release candidate 2 now available Message-ID: <20110520205314.1be39eec@neurotica.wooz.org> Hello to all you Pythoneers and Pythonistas, I'm happy to announce the availability of Python 2.6.7 release candidate 2. Release candidate 1 was not widely announced due to a mismatch between the Mercurial and Subversion branches. Barring any unforeseen issues, this will be the last release candidate before 2.6.7 final, which is currently scheduled for June 3, 2011. As previously announced, Python 2.6 is in security-fix only mode. This means that general bug fix maintenance has ended, and only critical security fixes are supported. We will support Python 2.6 in security-fix only mode until October 2013. Also, this is a source-only release; no installers for Windows or Mac OS X will be provided. Please download and test this release candidate. http://www.python.org/download/releases/2.6.7/ The NEWS file contains a list of changes since 2.6.6. http://www.python.org/download/releases/2.6.7/NEWS.txt Many thanks go out to the entire Python community for their contributions great and small. Enjoy, -Barry (on behalf of the Python development community) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: From steve+comp.lang.python at pearwood.info Fri May 20 20:54:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 May 2011 00:54:01 GMT Subject: obviscating python code for distribution References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dd70d29$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 May 2011 15:45:03 -0700, geremy condra wrote: > On Fri, May 20, 2011 at 1:24 PM, harrismh777 > wrote: >> ... as it goes, De Carte leads his horse into town ? ;-) ?and having >> hitched it to the rail outside the local saloon and sauntering up to >> the bar, ?the tender asks, "Would you be hav'in an ale sir?" >> >> ... De Carte replies, "I think not..." ? ? ... and then disappeared. > > At risk of being pedantic, I think you mean Descartes rather than De > Carte. Being a drunken old fart, I can't imagine Descartes turning down an ale... http://www.bbc.co.uk/dna/h2g2/A3651545 -- Steven From python at mrabarnett.plus.com Fri May 20 21:02:48 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 21 May 2011 02:02:48 +0100 Subject: hash values and equality In-Reply-To: <4dd70bbc$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> <4dd70bbc$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DD70F38.2080700@mrabarnett.plus.com> On 21/05/2011 01:47, Steven D'Aprano wrote: > On Fri, 20 May 2011 21:17:29 +0100, MRAB wrote: > >> On 20/05/2011 20:01, Christian Heimes wrote: >>> Am 20.05.2011 17:50, schrieb MRAB: >>>> Is this strictly true? I thought that the hash value, an integer, is >>>> moduloed (Is that how you spell it? Looks weird!) ... >>> >>> I don't think 'moduloed' is an existing word but your description is >>> mostly correct. ... >>> >> A brief search on the web found a use of the word in 1982. > > All that means is that two people, three decades apart, used the same non- > word :) > [snip] There were other uses. That's just the earliest one I found. From steve+comp.lang.python at pearwood.info Fri May 20 21:55:18 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 May 2011 01:55:18 GMT Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4DD68DAA.9050209@mrabarnett.plus.com> <4dd70bbc$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dd71b85$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 May 2011 02:02:48 +0100, MRAB wrote: > On 21/05/2011 01:47, Steven D'Aprano wrote: >> On Fri, 20 May 2011 21:17:29 +0100, MRAB wrote: >> >>> On 20/05/2011 20:01, Christian Heimes wrote: >>>> Am 20.05.2011 17:50, schrieb MRAB: >>>>> Is this strictly true? I thought that the hash value, an integer, is >>>>> moduloed (Is that how you spell it? Looks weird!) ... >>>> >>>> I don't think 'moduloed' is an existing word but your description is >>>> mostly correct. ... >>>> >>> A brief search on the web found a use of the word in 1982. >> >> All that means is that two people, three decades apart, used the same >> non- word :) >> > [snip] > There were other uses. That's just the earliest one I found. Nevertheless, it is still ungrammatical and incorrect usage. I'm not a prescriptivist, but not everything people write down is a word, otherwise we'd be forcefied to say evert typlo and mystake wsa an actul wrd. -- Steven From harrismh777 at charter.net Sat May 21 00:26:17 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 20 May 2011 23:26:17 -0500 Subject: Python 2.6.7 release candidate 2 now available In-Reply-To: References: Message-ID: Barry Warsaw wrote: > We will support Python 2.6 in security-fix only mode until > October 2013. Where can I read about the criteria for security-fix only? Who decides whether the security fix is critical? thanks, kind regards, m harris From harrismh777 at charter.net Sat May 21 00:26:24 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 20 May 2011 23:26:24 -0500 Subject: obviscating python code for distribution In-Reply-To: <4dd70d29$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DD08620.4030507@tysdomain.com> <5h9ca8-ekq.ln1@svn.schaathun.net> <1skda8-3as.ln1@svn.schaathun.net> <4vlea8-55t.ln1@svn.schaathun.net> <0q3ga8-s2v.ln1@svn.schaathun.net> <4dd6127b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd70d29$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >>> ... as it goes, De Carte leads his horse into town;-) and having >>> >> hitched it to the rail outside the local saloon and sauntering up to >>> >> the bar, the tender asks, "Would you be hav'in an ale sir?" >>> >> >>> >> ... De Carte replies, "I think not..." ... and then disappeared. >> > >> > At risk of being pedantic, I think you mean Descartes rather than De >> > Carte. > Being a drunken old fart, I can't imagine Descartes turning down an ale... > > http://www.bbc.co.uk/dna/h2g2/A3651545 > > .. .uh, yes... playing on 'de carte before de horse...' ... as for Steven's link: And Rene Descartes was a drunken old fart: "I drink, therefore I am", Ren? Descartes (1596-1650) I am not sure about Descartes drinking habits, but he was one true philosopher and mathematician... so we honor him... with jokes ! :) (how many of you guys are they going to be joking about 450 years from now ?) From kushal.kumaran+python at gmail.com Sat May 21 01:16:41 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sat, 21 May 2011 10:46:41 +0530 Subject: how to get PID from subprocess library In-Reply-To: References: Message-ID: On Thu, May 19, 2011 at 9:32 PM, TheSaint wrote: > hello, > > I'm using to launch a program by subprocess.getstatusoutput. I'd like to > know whether I can get the program ID, in order to avoid another launch. > > For clarity sake, I'm calling aria2 (the download manager for linux) and I > wouldn't like to call one more instance of it. So what will I use to find > the PID of the launched program? > The getstatusoutput function will only return when the command has finished. That's how it is able to give you the status. So, if you are using getstatusoutput, you will have only one instance of your command running. -- regards, kushal From cs at zip.com.au Sat May 21 01:40:20 2011 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 21 May 2011 15:40:20 +1000 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: <20110521054020.GA32313@cskk.homeip.net> On 11May2011 13:37, James Mills wrote: | On Tue, May 10, 2011 at 7:34 PM, Jean-Michel Pichavant | wrote: | > You can reraise the exception without loosing the stack trace. | > | > try: | > ... | > except SomeException, exc: | > log(exc) | > print 'Hello world' | > raise # "raise exc" would loose the original stack trace | | Valid point :) However I was referring to real experience | where I've seen code that "catches all any any exception" | and simply logs it. I've put code like that in a worker thread occasionally, because there's nobody "outside" to catch it; the submitter's attention is elsewhere. These days I think I'd use a LateFunction (a facility of my own which is a lot like the futures module) which returns a callable when you submit a function; the worker thread runs the submitted function and catches the return value or raised exception. Anyone who calls the returned callable later gets the return value or the exception reraised as appropriate, so one can avoid the dangerous "catch everything and log" scenario. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Observing the first balloon ascent in Paris, [Ben] Franklin heard a scoffer ask, "What good is it?" He spoke for a generation of scientists in his retort, "What good is a newly born infant?" - John F. Kasson From nad at acm.org Sat May 21 01:54:35 2011 From: nad at acm.org (Ned Deily) Date: Fri, 20 May 2011 22:54:35 -0700 Subject: Python 2.6.7 release candidate 2 now available References: Message-ID: In article , harrismh777 wrote: > Barry Warsaw wrote: > > We will support Python 2.6 in security-fix only mode until > > October 2013. > Where can I read about the criteria for security-fix only? You can read about the Python development cycle and security branches in the Python Developer's Guide: http://docs.python.org/devguide/devcycle.html#security-branches > Who decides whether the security fix is critical? Anyone can propose a security fix but the final decision is up to the release manager in charge of the branch. For 2.6.x, that is Barry. -- Ned Deily, nad at acm.org From prologic at shortcircuit.net.au Sat May 21 03:08:18 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Sat, 21 May 2011 17:08:18 +1000 Subject: Overuse of try/except/else? In-Reply-To: <20110521054020.GA32313@cskk.homeip.net> References: <20110521054020.GA32313@cskk.homeip.net> Message-ID: On Sat, May 21, 2011 at 3:40 PM, Cameron Simpson wrote: > These days I think I'd use a LateFunction (a facility of my own which is > a lot like the futures module) which returns a callable when you submit > a function; the worker thread runs the submitted function and catches the > return value or raised exception. Anyone who calls the returned callable > later gets the return value or the exception reraised as appropriate, > so one can avoid the dangerous "catch everything and log" scenario. I like this :) I guess you call this a Proxy Object although your calling it a LateFunction seems more "fitting" :) cheers James -- -- James Mills -- -- "Problems are solved by method" From __peter__ at web.de Sat May 21 04:18:59 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 21 May 2011 10:18:59 +0200 Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: bvdp wrote: > I've just done an update to my system here to Ubuntu 11.04. Mostly no > problems ... but I have an important (to me) python/TK program that's > stopped working. Well, it works ... mostly. > > The python version is 2.7.1+ (no idea what the + means!). > > I _think_ I have traced the problem to certain menus which call a > class. The calls appear to be ignored. > > Basically, what I have is a line like: > > bf = makeButtonBar(root, row=0, column=0, buttons=( > ("Quit", self.quitall ), > ("Stop", self.stopPmidi ), > ("New Dir", self.chd), > ("Load Playlist", self.playList), > ("Favorites", selectFav), > ("Options", setOptions) ) ) > > To create a menu bar. The function makeButtonBar() creates the buttons > with: > > for txt, cmd in buttons: > Button(bf, text=txt, height=1, command=cmd).grid(column=c, > row=0, pady=5) > > > All this is fine (and worked perfectly before my upgrade). The menu > items which are ordinary functions continue to work. BUT the callbacks > which are classes are just ignored when they are clicked. > > A cut from one of the ignored classes: > > > class selectFav: > > def __init__(self): > ... > > And I've inserted some prints in the __init__() and nothing is > printed. Also, converted the class to new-style () but no change there > either. > > Either python/tk has changed or my system is totally $*(#*#. > Suggestions welcome! Here's a minimal script to reproduces the problem: $ cat tkcallclass.py import Tkinter as tk root = tk.Tk() root.withdraw() class Classic: def __init__(self): print "hello" button = tk.Button(root, command=Classic) button.invoke() $ python2.6 tkcallclass.py hello $ python2.7 tkcallclass.py Traceback (most recent call last): File "tkcallclass.py", line 11, in button.invoke() File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 2081, in invoke return self.tk.call(self._w, 'invoke') _tkinter.TclError: invalid command name "__main__.Classic" $ In 2.7 the Tkinter code was changed to use hasattr(obj, "__call__") instead of callable(obj) to recognize callbacks. This gives different results for oldstyle classes >>> class A: pass ... >>> callable(A) True >>> hasattr(A, "__call__") False ...and they are no longer registered automatically with Tkinter. In theory you could register them explicitly yourself $ cat tkcallclass2.py import Tkinter as tk root = tk.Tk() root.withdraw() class Classic: def __init__(self): print "hello" button = tk.Button(root, command=root.register(Classic)) button.invoke() $ python2.7 tkcallclass2.py hello but in practice changing them to newstyle (i. e. have them inherit from object) or wrapping them in a lambda appears convenient. Personally, I would reconsider whether using a class as a callback is really necessary. Replacing the class with a function should be a straightforward process. From greg.ewing at canterbury.ac.nz Sat May 21 04:24:21 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 21 May 2011 20:24:21 +1200 Subject: hash values and equality In-Reply-To: References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> Message-ID: <93pb5nF3gtU1@mid.individual.net> Ethan Furman wrote: > Ulrich Eckhardt wrote: > >> If two equal objects have different hashes, they >> will be stored in different places in the hash map. Looking for >> object1 will then not turn up with object2, even though they are equal. > > In this case this is the behavior I want. You can't rely on it, though. The hash value gets reduced modulo the size of the dict, so even if two objects have different hashes, in some cases they will land on the same dict slot anyway. So an object such as you're postulating would behave unpredictably when used as a dict key. Sometimes a lookup using a different but equal object would find it, and sometimes not, seemingly at random. -- Greg From franck at ditter.org Sat May 21 04:30:41 2011 From: franck at ditter.org (Franck Ditter) Date: Sat, 21 May 2011 10:30:41 +0200 Subject: Python in CS1 Message-ID: Except at MIT, who knows some good CS1 references for teaching Python ? Thanks, franck From J.deBoynePollard-newsgroups at NTLWorld.COM Sat May 21 04:32:01 2011 From: J.deBoynePollard-newsgroups at NTLWorld.COM (Jonathan de Boyne Pollard) Date: Sat, 21 May 2011 09:32:01 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> Message-ID: > The supposed inefficiency of recursive implementations is based > largely on the properties of hardware that is now obsolete. With > modern processors there's no great efficiency hit. In some of the > smaller microcontrollers, it's true, you do have to worry about stack > overflow; but the ARM processors, for example, provide plenty of stack > space. > > In the microcontroller world, the big performance hits come from the > fact that the only available compilers are for C and sometimes C++. > (And nobody uses assembly language except for the very little jobs.) > The nature of the C language prevents compilers from doing > optimisations that are standard in compilers for high-level languages. > Most C compilers will, for example, always pass parameters on the > stack, despite the generous supply of registers available in newer > hardware. > However, some C compilers will *also* have one or more "go faster" calling conventions that pass parameters in registers, which can be employed. Over in the PC world, such "go faster" calling conventions are even the default calling convention if no calling convention is explicitly specified, for some C and C++ compilers. http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Compiler http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Optlink http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Watcall From wbsoft at xs4all.nl Sat May 21 04:42:40 2011 From: wbsoft at xs4all.nl (Wilbert Berendsen) Date: Sat, 21 May 2011 10:42:40 +0200 Subject: distutils on windows ignoring package_data Message-ID: <201105211042.41201.wbsoft@xs4all.nl> Hi, I have created a distutils setup.py script that installs a list of packages (all subpackages of one main package). Some packages have package_data files (icons, translations, etc). Running setup.py install on my Linux system (python 2.6) perfectly installs all package data, but on Windows (tested with both 2.6 and 2.7) the package_data is not installed at all. Also not picked up in build, or bdist_wininst, etc. Only the Python files in the packages are installed. The setup.py file can be seen at https://github.com/wbsoft/frescobaldi/blob/master/setup.py I later added the package_dir incantation, but it doesn't help on Windows and on Linux it worked perfectly without. Does anybody have a clue why Python distutils on Windows ignore the package_data? (Note: sdist perfectly works as the data files are also listed in MANIFEST.in) tia, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ From greg.ewing at canterbury.ac.nz Sat May 21 04:49:33 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 21 May 2011 20:49:33 +1200 Subject: Faster Recursive Fibonacci Numbers In-Reply-To: References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dd602ec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <93pcl0Fe1nU1@mid.individual.net> Chris Angelico wrote: > It seems > strange to smoothly slide from native integer to long integer and just > keep on going, and yet to be unable to do the same if there's a > fractional part on it. The trouble is that if you always compute exact results by default, the number of digits required can blow up very quickly. There's a story that ABC (the predecessor to Python) calculated everything using rationals. People found that sometimes a calculation would take an unexpectedly long time, and it turned out to be because internally it was creating fractions with huge numerators and denominators. As a consequence, Guido decided that Python would *not* use rationals by default. The same problem doesn't arise with ints, because the only time you get an int with a large number of digits is when you genuinely need a large int. So expanding ints automatically to however many digits is needed doesn't do any harm. In Python 2.6 and later, there's a fractions module for when you need it. -- Greg From __peter__ at web.de Sat May 21 05:24:40 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 21 May 2011 11:24:40 +0200 Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <93pb5nF3gtU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > Ethan Furman wrote: >> Ulrich Eckhardt wrote: >> >>> If two equal objects have different hashes, they >>> will be stored in different places in the hash map. Looking for >>> object1 will then not turn up with object2, even though they are equal. >> >> In this case this is the behavior I want. > > You can't rely on it, though. The hash value gets reduced > modulo the size of the dict, so even if two objects have > different hashes, in some cases they will land on the same > dict slot anyway. > > So an object such as you're postulating would behave > unpredictably when used as a dict key. Sometimes a lookup > using a different but equal object would find it, and > sometimes not, seemingly at random. I think for every potential match the current dict implementation checks identity, then hashes -- and equality only if the hash values are equal. The relevant function is lookdict() in dictobject.c. While that means that the problem you describe cannot occur a simple approach that avoids relying on an implementation detail (?) would be to use (hash(obj), obj) tuples instead of just obj as the key. From lars.enderin at telia.com Sat May 21 05:52:48 2011 From: lars.enderin at telia.com (Lars Enderin) Date: Sat, 21 May 2011 11:52:48 +0200 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> Message-ID: <4DD78B70.9090804@telia.com> 2011-05-21 10:32, Jonathan de Boyne Pollard skrev: >> The supposed inefficiency of recursive implementations is based >> largely on the properties of hardware that is now obsolete. With >> modern processors there's no great efficiency hit. In some of the >> smaller microcontrollers, it's true, you do have to worry about stack >> overflow; but the ARM processors, for example, provide plenty of stack >> space. >> >> In the microcontroller world, the big performance hits come from the >> fact that the only available compilers are for C and sometimes C++. >> (And nobody uses assembly language except for the very little jobs.) >> The nature of the C language prevents compilers from doing >> optimisations that are standard in compilers for high-level languages. >> Most C compilers will, for example, always pass parameters on the >> stack, despite the generous supply of registers available in newer >> hardware. >> > However, some C compilers will *also* have one or more "go faster" > calling conventions that pass parameters in registers, which can be > employed. Over in the PC world, such "go faster" calling conventions > are even the default calling convention if no calling convention is > explicitly specified, for some C and C++ compilers. > > > http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Compiler > > > http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Optlink > > > http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Watcall > Please include attributions, in this case for Peter Moylan and rusi! From lars.enderin at telia.com Sat May 21 05:54:22 2011 From: lars.enderin at telia.com (Lars Enderin) Date: Sat, 21 May 2011 11:54:22 +0200 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <4DD78B70.9090804@telia.com> References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> <4DD78B70.9090804@telia.com> Message-ID: <4DD78BCE.50708@telia.com> 2011-05-21 11:52, Lars Enderin skrev: > > Please include attributions, in this case for Peter Moylan and rusi! Just Peter Moylan, sorry! From lars.enderin at telia.com Sat May 21 05:56:23 2011 From: lars.enderin at telia.com (Lars Enderin) Date: Sat, 21 May 2011 11:56:23 +0200 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <4DD78BCE.50708@telia.com> References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> <4DD78B70.9090804@telia.com> <4DD78BCE.50708@telia.com> Message-ID: <4DD78C47.5020406@telia.com> 2011-05-21 11:54, Lars Enderin skrev: > 2011-05-21 11:52, Lars Enderin skrev: >> >> Please include attributions, in this case for Peter Moylan and rusi! > > Just Peter Moylan, sorry! Ignore the above. From inigoserna at gmail.com Sat May 21 07:25:31 2011 From: inigoserna at gmail.com (=?UTF-8?B?ScOxaWdvIFNlcm5h?=) Date: Sat, 21 May 2011 13:25:31 +0200 Subject: ANN: lfm v2.3 Message-ID: Hi, new version of lfm. Note that it requires python v2.5+ now, and it's incompatible with v3.x. Description: ========== Last File Manager is a powerful file manager for the UNIX console. It has a curses interface and it's written in Python. Licensed under GNU Public License version 3. Some of the features you could find in lfm: - console-based file manager for UNIX platforms - 1-pane or 2-pane view - tabs - bookmarks - history - vfs for compressed files - dialogs with entry completion - PowerCLI, a command line interface with advanced features - fast access to the shell - direct integration of find/grep, df and other tools - color files by extension - fast file viewer with text and binary modes - ...and many others Download it from: =============== http://inigo.katxi.org/devel/lfm (home server) or http://code.google.com/p/lfm/ or from http://www.terra.es/personal7/inigoserna/lfm when crap ISP updates its cache. Changes since last version: ====================== + About the code - lfm needs python version 2.5 or upper now + New features - PowerCLI, an advanced command line interface with completion, persistent history, variable substitution and many other useful features. As this is a very powerful tool, read the documentation for examples - history . use different types of history lists: path, file, glob, grep, exec, cli for the different forms and actions . persistent history between sessions => ~/.lfm_history . controlled by a flag in configuration - find/grep . configuration options for ignorecase and regex . sort results . show results as FILE:lineno . much faster - show diff between xxx.orig and xxx files - tar files compress/uncompress - messages.EntryLine has been rewritten, with many new key shorcuts. This is the core behind most of the forms lfm shows when asking for anything. Consult the documentation + Minor changes - reorganize "un/compress file" and "compress directory xxx" in file_menu - config: sort entries when saving - improve load/save handling of new options not present in ~/.lfmrc - added new extensions - messages.error rewritten to offer better messages - added some new key shortcuts messages.SelectItem + Documentation - added a note about python v2.5+ is needed from now on - 'lfm' shell function: change "$*" to "$@" to properly handle paths containg spaces - FAQ: added information about fuse to mount ssh, ftp, smb and webdav - reorganized and fixed key bindings section - documented .lfmrc contents - added link to public BitBucket repository + lots of bugs fixed: - pyview: . last char is not shown if file size is small . last line and wrap: cursor_down or page_next . when number of lines == window height - ncurses v5.8 doesn't accept 0 as width or height - UI crashes: . time string could contain non-ascii characters (reported by Martin Steigerwald) . when filenane length is large in full pane mode . MenuWin, SelectItem: ellipsize entries if bigger than screen width - find or find&grep: . pass "-type f" to find as ".#filename" are temporary emacs files/links that break search . show wrong matches if results contain directories or files with spaces . file->goto_file: move to correct page - copy/move "/file" to "/anydir/anyplace" fails, trying to copy/move to "/" - executing non-ascii programname or args - convoluted issue with link to directory in corner cases (reported by Xin Wang) - rename/backup ".." crashes - we should not compress ".." - create_link, edit_link: don't show error if canceled - only store one copy of the same entry in history - tree: "disable" colors of active panel, "enable" at end - Config.save: work with unicode, only convert to encoding when saving Of course, all comments, suggestions, etc. are welcome. Best regards, I?igo Serna From jjl at pobox.com Sat May 21 07:46:26 2011 From: jjl at pobox.com (John J Lee) Date: Sat, 21 May 2011 12:46:26 +0100 Subject: List of WindowsError error codes and meanings References: Message-ID: <8762p48eel.fsf@pobox.com> Andrew Berg writes: > This is probably somewhat off-topic, but where would I find a list of > what each error code in WindowsError means? WindowsError is so broad > that it could be difficult to decide what to do in an except clause. > Fortunately, sys.exc_info()[1][0] holds the specific error code, so I > could put in an if...elif...else clause inside the except clause if I > needed to, but I don't know what all the different errors are. Since Python 2.5, the errno attribute maps the Windows error to error codes that match the attributes of module errno. http://docs.python.org/library/exceptions.html#exceptions.WindowsError So for some purposes you can use the same UNIXy error codes you can use on most other platforms. Example: import errno try: operation() except WindowsError, exc: if exc.errno != errno.ENOENT: raise print "file/directory does not exist" Obviously whether this is useful depends on the error cases you need to handle. Undocumented: when there's no useful mapping to errno, you get errno.EINVAL. John From nobody at nowhere.net.no Sat May 21 08:50:58 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 21 May 2011 20:50:58 +0800 Subject: how to get PID from subprocess library References: Message-ID: Kushal Kumaran wrote: > That's how it is able to give you the status. So, if you > are using getstatusoutput, you will have only one instance of your > command running. My intent is to launch only one program instance, which will goes as daemon. To avoid a second call I'd like rather to use Python than ==============================code========================================= def start(self): '''try to start aria2c as a daemon and return its handle to where it can proceed to issue commands''' # aria2c is running, then don't try it again if (chkout('ps -A |grep aria2c')[0] > 0): try: chkout(self.ARIA_CMD) except: raise SystemExit('aria2c is not working as deamon') elif self.handle: return self.handle # everything is good, it will return an handle self.handle= \ xmlrpclib.ServerProxy('http://localhost:%s/rpc' %int(self.numport)) return self.handle ==============================code========================================= Here I've named subprocess.getstatusoutput as chkout, I'm calling 2 more programs to find whether there's a running instance of aria2c. I think it's not nice, python libraries should get the matter done. -- goto /dev/null From jjl at pobox.com Sat May 21 09:01:38 2011 From: jjl at pobox.com (John J Lee) Date: Sat, 21 May 2011 14:01:38 +0100 Subject: application level monitoring for python References: <7281a33b-a32c-4eba-8646-82d9cef459b1@m10g2000yqd.googlegroups.com> Message-ID: <871uzs8ax9.fsf@pobox.com> Walter Chang writes: > Hi > > is there any open source library for python that can allow application > level monitoring ? For example,application can send per request level/ > aggregated monitoring events and some remote server dump it and show > in the monitoring graph in real time ? What's best way of doing > that ? Zenoss is a popular tool for that kind of thing. Here's an example of sending a Zenoss event over XML-RPC: http://dancingpenguinsoflight.com/2009/05/send-events-to-zenoss-from-scripts/ Presumably you can send it evnts over other transports somehow (e.g. UDP). Zenoss is itself implemented in Python. John From dan.kluev at gmail.com Sat May 21 09:33:33 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 22 May 2011 00:33:33 +1100 Subject: Overuse of try/except/else? In-Reply-To: References: Message-ID: On Tue, May 10, 2011 at 11:40 AM, Kyle T. Jones wrote: > > It has been hard for me to determine what would constitute overuse. > Good example of abuse is catching KeyboardInterrupt or SystemExit inside some library code. PycURL does it, and its truly annoying. -- With best regards, Daniel Kluev From wbsoft at xs4all.nl Sat May 21 09:57:52 2011 From: wbsoft at xs4all.nl (Wilbert Berendsen) Date: Sat, 21 May 2011 15:57:52 +0200 Subject: SOLVED Re: distutils on windows ignoring package_data In-Reply-To: <201105211042.41201.wbsoft@xs4all.nl> References: <201105211042.41201.wbsoft@xs4all.nl> Message-ID: <18a3dd09c99482abc3386f35e0db9cc3.squirrel@webmail.xs4all.nl> Solved: the problem was right there in the packagelist() function, it replaced '/' with dots instead of using os.sep ... I'm very sorry for the noise, although it's surprising everything else works without dots in the packages names :-) with regard, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ From jjl at pobox.com Sat May 21 10:06:57 2011 From: jjl at pobox.com (John J Lee) Date: Sat, 21 May 2011 15:06:57 +0100 Subject: Parsing a graph image References: <90jv98-322.ln1@satorlaser.homedns.org> <20110513142445.0792eb4e@chaostal.de> Message-ID: <87wrhk6tby.fsf@pobox.com> Bastian Ballmann writes: > Hi, > > the project sounds like the exact tool that i need but regarding the > user manual one has to mark the points on the graph manually. Therefore > it's more work to get the data out than doing it without a tool. Or may > I miss something here? > Greets Read the documentation more carefully: it has features that allow extracting points from line charts automatically. If you want something fully automated, you just want jam on it ;-) John From kb1pkl at aim.com Sat May 21 10:19:59 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sat, 21 May 2011 10:19:59 -0400 Subject: Python in CS1 In-Reply-To: References: Message-ID: <4DD7CA0F.2090009@aim.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/21/2011 04:30 AM, Franck Ditter wrote: > Except at MIT, who knows some good CS1 references for teaching Python ? > Thanks, > > franck Check out http://www.python.org/community/sigs/current/edu-sig/, and if nothing there satisfies you jump over onto the edu-sig list. - -- Corey Richardson -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iQEcBAEBAgAGBQJN18oPAAoJEAFAbo/KNFvp9MwH/0zXSTTaxAwYPLSxhyirqr3X DUxyulE5HRn+NIarWyomlDfoayip3boyUBG1GQDDKh+sIIzPT9ETfL7+ep9rwkL4 VA7XSDMLu+4DtUlnFjGlfxCz1REYKVvS4m/9w68F0kRflh5XZzDRBbTz0nXMiMM8 /UPBV8cX1XDq+RYis1baIlMSaro6sK3mHW5avBd9RxO4+IzH0TtKw510EWfRvZ8e ssdEUXZwxHmI0eRwYovynJ7VdLWwY/FLKuuoKl1IOpRwbAH8LtLtAAudHDZKOo9X ctwYfwGPCg39gz+fuJFFUGI6oYw8dkqiDi2su/QwN8JsaMXv4xeOc2ZXkZVYMiM= =7xLM -----END PGP SIGNATURE----- From jjl at pobox.com Sat May 21 10:46:01 2011 From: jjl at pobox.com (John J Lee) Date: Sat, 21 May 2011 15:46:01 +0100 Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> Message-ID: <87r57s6riu.fsf@pobox.com> Gregory Ewing writes: > Hans Georg Schaathun wrote: >> 0 is a number as real and existent as any other, >> one would think that the empty list is also as real and existent as >> any other list. > > 0 does have some special properties, though, such as > being the additive identity and not having a multiplicative > inverse. Adding falseness as another special property isn't > too much of a stretch and turns out to be useful. > > Likewise, it's useful to treat empty containers as having > a similar special property, since they're often a base or > terminating case in algorithms. > > It's especially useful in a dynamic language where any > additional operations such as finding the length or > comparing with zero has a run-time cost. > > Yes, you have to learn it, but it's a small thing to > learn with a considerable payoff. (apologies if somebody already bikeshedded this argument in this thread) In the absence of an explicit interface declaration (have any standards emerged for that in Python 3, BTW?), the use of len() does give you some information about the interface, which sometimes makes it easier to change the function. I'm sure you fully understand this, but I'll spell it out. Consider this function: def xyzzy(x): if x: print "yes" Let's say I've read the function, and I've seen this call site: xyzzy(["spam", "eggs"]) Now I want to change xyzzy: def xyzzy(x): if x: print "probably" if len(x) == 1: print "definitely" But there may be many call sites. Perhaps xyzzy even implements part of a poorly-documented external API. So can x be None? There's no way to know short of checking all call sites, which may be impossible. It may not even be feasible to check the *only* call site, if you're implementing somebody else's poorly documented closed-source API (a situation I came across at work only yesterday, when that situation resulted in a bug report). If it's written this way, it's clear that it can't be None: def xyzzy(x): if len(x) != 0: print "yes" John From patty at cruzio.com Sat May 21 11:24:47 2011 From: patty at cruzio.com (Patty) Date: Sat, 21 May 2011 08:24:47 -0700 Subject: Python in CS1 References: <4DD7CA0F.2090009@aim.com> Message-ID: <66E3768F137647C2B2AD4993007E43D2@mycomputer> ----- Original Message ----- From: "Corey Richardson" To: Sent: Saturday, May 21, 2011 7:19 AM Subject: Re: Python in CS1 > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 05/21/2011 04:30 AM, Franck Ditter wrote: >> Except at MIT, who knows some good CS1 references for teaching Python ? >> Thanks, >> >> franck > > Check out http://www.python.org/community/sigs/current/edu-sig/, and if > nothing there satisfies you jump over onto the edu-sig list. > > - -- > Corey Richardson > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.17 (GNU/Linux) > > iQEcBAEBAgAGBQJN18oPAAoJEAFAbo/KNFvp9MwH/0zXSTTaxAwYPLSxhyirqr3X > DUxyulE5HRn+NIarWyomlDfoayip3boyUBG1GQDDKh+sIIzPT9ETfL7+ep9rwkL4 > VA7XSDMLu+4DtUlnFjGlfxCz1REYKVvS4m/9w68F0kRflh5XZzDRBbTz0nXMiMM8 > /UPBV8cX1XDq+RYis1baIlMSaro6sK3mHW5avBd9RxO4+IzH0TtKw510EWfRvZ8e > ssdEUXZwxHmI0eRwYovynJ7VdLWwY/FLKuuoKl1IOpRwbAH8LtLtAAudHDZKOo9X > ctwYfwGPCg39gz+fuJFFUGI6oYw8dkqiDi2su/QwN8JsaMXv4xeOc2ZXkZVYMiM= > =7xLM > -----END PGP SIGNATURE----- > -- > http://mail.python.org/mailman/listinfo/python-list > Thank you for forwarding this link Corey! It is very interesting and informative. Regards, Patty From invalid at invalid.invalid Sat May 21 11:34:18 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 21 May 2011 15:34:18 +0000 (UTC) Subject: English Idiom in Unix: Directory Recursively References: <87aaekoab7.fsf@kuiper.lan.informatimago.com> <1228144c-303f-4c38-8ecb-8a7ad79fb3ab@s16g2000prf.googlegroups.com> Message-ID: On 2011-05-19, Peter Moylan wrote: > In the microcontroller world, the big performance hits come from the > fact that the only available compilers are for C and sometimes C++. > (And nobody uses assembly language except for the very little jobs.) > The nature of the C language prevents compilers from doing optimisations > that are standard in compilers for high-level languages. Most C > compilers will, for example, always pass parameters on the stack, > despite the generous supply of registers available in newer hardware. I've been doing microcontroller stuff for 25+ years, almost all in C, and I don't think I've never seen such a compiler. Even on the register-starved 6800 architecture, the first parameter was passed in a register. On architectures with more registers (H8, MSP430, ARM, etc.) It's usually the first 3 or so parameters that are found in registers. -- Grant Edwards grant.b.edwards Yow! Gee, I feel kind of at LIGHT in the head now, gmail.com knowing I can't make my satellite dish PAYMENTS! From genstein at invalid.invalid Sat May 21 11:35:18 2011 From: genstein at invalid.invalid (Genstein) Date: Sat, 21 May 2011 16:35:18 +0100 Subject: List of WindowsError error codes and meanings In-Reply-To: <8762p48eel.fsf@pobox.com> References: <8762p48eel.fsf@pobox.com> Message-ID: > Andrew Berg writes: > Since Python 2.5, the errno attribute maps the Windows error to error > codes that match the attributes of module errno. Good point, I completely misread that. At least the Windows error code is still available as the winerror attribute. As an aside - call me stupid, but I don't quite follow the purpose of that errno mapping. Surely if the error number can be mapped successfully then the error isn't Windows specific and an OSError should logically be thrown instead? And if it can't be mapped successfully then errno will never be valid so the mapping is pointless? I guess if the mapping is imprecise then it makes some sense as errno is a convenience to avoid people having to grasp the meaning of the many and various winerror.h values. So perhaps I've answered my own question. From mount.sarah at gmail.com Sat May 21 11:37:21 2011 From: mount.sarah at gmail.com (Sarah Mount) Date: Sat, 21 May 2011 16:37:21 +0100 Subject: Python in CS1 In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 09:30, Franck Ditter wrote: > Except at MIT, who knows some good CS1 references for teaching Python ? James Shuttleworth and I did a lot of this at Coventry, the book Python for Rookies came from that. We don't use Python in CS1 at Wolverhampton, but James is still actively using our old syllabus (or a variant). You can reach him here: http://dis-dot-dat.net/ Sarah -- Sarah Mount, Senior Lecturer, University of Wolverhampton website:? http://www.snim2.org/ twitter: @snim2 From jjl at pobox.com Sat May 21 11:49:50 2011 From: jjl at pobox.com (John J Lee) Date: Sat, 21 May 2011 16:49:50 +0100 Subject: Abandoning Python Message-ID: <87ipt46okh.fsf@pobox.com> I still like Python after using it for over a decade, but there are things I don't like. What are your favourite up-and-coming languages of the moment? Here's my wishlist (not really in any order): * A widely used standard for (optional) interface declaration -- or something better. I want it to be easier to know what interface an object has when reading code, and which objects provide that interface. * Lower memory usage and faster execution speed. Yes, this has been a price worth paying. But I do want jam on it, please: give me a language where I get most of Python's advantages but don't have to pay it. * Better support for writing correct programs in the form of better support for things like non-imperative programming, DBC, etc. (with the emphasis on "etc"). * Perhaps better built-in support for common tasks in common application domains. Concurrency, persistence, database queries come to mind. * Better refactoring tools, better code analysis tools (lint, search, etc.). * An even larger user base, contributing more and better free and commercial software. I'm prepared to compromise on the last one. Obviously, it should do all that while preserving all the nice features of Python -- surely an easy task. John From emile at fenx.com Sat May 21 11:52:43 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 21 May 2011 08:52:43 -0700 Subject: checking if a list is empty In-Reply-To: <87r57s6riu.fsf@pobox.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: On 5/21/2011 7:46 AM John J Lee said... > Gregory Ewing writes: > >> Hans Georg Schaathun wrote: >>> 0 is a number as real and existent as any other, >>> one would think that the empty list is also as real and existent as >>> any other list. >> >> 0 does have some special properties, though, such as >> being the additive identity and not having a multiplicative >> inverse. Adding falseness as another special property isn't >> too much of a stretch and turns out to be useful. >> >> Likewise, it's useful to treat empty containers as having >> a similar special property, since they're often a base or >> terminating case in algorithms. >> >> It's especially useful in a dynamic language where any >> additional operations such as finding the length or >> comparing with zero has a run-time cost. >> >> Yes, you have to learn it, but it's a small thing to >> learn with a considerable payoff. > > (apologies if somebody already bikeshedded this argument in this thread) > > In the absence of an explicit interface declaration (have any standards > emerged for that in Python 3, BTW?), the use of len() does give you some > information about the interface, which sometimes makes it easier to > change the function. > > I'm sure you fully understand this, but I'll spell it out. Consider > this function: > > def xyzzy(x): > if x: > print "yes" > > > Let's say I've read the function, and I've seen this call site: > > xyzzy(["spam", "eggs"]) > > > Now I want to change xyzzy: > > def xyzzy(x): > if x: > print "probably" > if len(x) == 1: > print "definitely" > > > But there may be many call sites. Perhaps xyzzy even implements part of > a poorly-documented external API. So can x be None? There's no way to > know short of checking all call sites, which may be impossible. It may > not even be feasible to check the *only* call site, if you're > implementing somebody else's poorly documented closed-source API (a > situation I came across at work only yesterday, when that situation > resulted in a bug report). If it's written this way, it's clear that it > can't be None: qualified: "...without having been trapped or crashing" so if I found this function in running code it would be clear to me that, given that the app is running and hasn't been crashing, either it hasn't yet been None, or the code isn't accessed at all. Emile > > def xyzzy(x): > if len(x) != 0: > print "yes" > > > John From swavijay at gmail.com Sat May 21 11:56:50 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Sat, 21 May 2011 21:26:50 +0530 Subject: Problem in using subprocess module and communicate() Message-ID: Hi Gurus, I'm having some problem in using the communicate() along with the subprocess.I would like to invoke a command prompt and pass on a .bat file to execute. I went through the subprocess module and understood that using communicate, we can send the send data to stdin. According to the documentation http://docs.python.org/library/subprocess.html#subprocess.call, it says, if you want to send data to the process?s stdin, you need to create the Popen object with stdin=PIPE. so based on this, I have used the below function but it does not seem to work. Am I missing something here? import subprocess import threading import time def runMonitor(command): retcode = subprocess.Popen([command, '\k', 'dir'], cwd= 'C:\Python26\WorkSpace\FunctionExamples\src', stdin = subprocess.PIPE, creationflags=subprocess.CREATE_NEW_CONSOLE) retcode.wait() retcode.communicate('scripts_to_execute.bat') t = threading.Thread(target = runMonitor, args = ("cmd.exe",)) t.start() while t.is_alive(): print 'Thread is still alive' time.sleep(0.5) else: print 'Thread is dead' Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Sat May 21 12:00:15 2011 From: john at castleamber.com (John Bokma) Date: Sat, 21 May 2011 11:00:15 -0500 Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: <87boywavsg.fsf@castleamber.com> John J Lee writes: > > > I still like Python after using it for over a decade, but there are > things I don't like. > > What are your favourite up-and-coming languages of the moment? > > Here's my wishlist (not really in any order): > > * A widely used standard for (optional) interface declaration -- or > something better. I want it to be easier to know what interface an > object has when reading code, and which objects provide that > interface. > * Lower memory usage and faster execution speed. Yes, this has been a > price worth paying. But I do want jam on it, please: give me a > language where I get most of Python's advantages but don't have to > pay it. > * Better support for writing correct programs in the form of better > support for things like non-imperative programming, DBC, etc. (with > the emphasis on "etc"). > * Perhaps better built-in support for common tasks in common application > domains. Concurrency, persistence, database queries come to mind. > * Better refactoring tools, better code analysis tools (lint, search, > etc.). > * An even larger user base, contributing more and better free and > commercial software. > > I'm prepared to compromise on the last one. Obviously, it should do all > that while preserving all the nice features of Python -- surely an easy > task. A language I want to give a serious try the coming months is Haskell. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From sigzero at gmail.com Sat May 21 12:19:30 2011 From: sigzero at gmail.com (Robert) Date: Sat, 21 May 2011 09:19:30 -0700 (PDT) Subject: [Book] Python 3 Web Development Beginner's Guide Message-ID: Has anyone read this one? If so, what did you think? -- Bob From irmen.NOSPAM at xs4all.nl Sat May 21 12:22:37 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 21 May 2011 18:22:37 +0200 Subject: experiments with dictionary attacks against password hashes, in Python Message-ID: <4dd7e6cd$0$49176$e4fe514c@news.xs4all.nl> Hi, I've been experimenting a little with dictionary attacks against password hashes. It turned out that Python is plenty fast for this task, if you use precomputed hash databases. I used a few rather large dictionary files (most of the words of the English language, and most of the words of the Dutch language including derived forms) for a total of almost 600,000 precomputed hashes. With that the program can "crack" 10,000 password hashes in under a second on my 3 year old PC. I've also used a list of 600 'most commonly used' passwords that I gathered from a few sources. That list is used to generate a couple of variations, such as prefixing them with a digit, or typing the word in uppercase, etc. I did this to be able to quickly scan for the most common passwords, but it turned out that using all of the 600,000 precomputed hashes isn't much slower for the experiments that I did. The variations however increase the hit rate because words like "Jennifer9" are not in a normal dictionary file. This one however *is* part of the 'most common' list. So if that is your password, go change it right now ;-) I thought the code I wrote might interest other people as well, so I share it here: (It should run on Python 2.6 and up, including Python 3.x.) Download: http://www.razorvine.net/download/dictionary_attack/ Or by Subversion: svn://svn.razorvine.net/Various/PythonStuff/trunk/dictionaryattack Have fun, Irmen de Jong From wallenpb at gmail.com Sat May 21 14:40:40 2011 From: wallenpb at gmail.com (Bill Allen) Date: Sat, 21 May 2011 13:40:40 -0500 Subject: Abandoning Python In-Reply-To: <87ipt46okh.fsf@pobox.com> References: <87ipt46okh.fsf@pobox.com> Message-ID: You have ideas, a text editor, and a computer - best get to coding. What's stopping you? You largely want Python, with modifications. Join the development team and help implement those changes, or fork your own flavor and do what you wish. Right? You imagine it's an easy task, so get after it. Also, quit saying "give me". I realize that was a troll post, but I hear people say so many things like this about lots of things. Sick of it. Shut up and do something constructive instead. Contribute with effort, rather than a lot of "wishlist" and "give me" talk. On Sat, May 21, 2011 at 10:49, John J Lee wrote: > > > I still like Python after using it for over a decade, but there are > things I don't like. > > What are your favourite up-and-coming languages of the moment? > > Here's my wishlist (not really in any order): > > * A widely used standard for (optional) interface declaration -- or > something better. I want it to be easier to know what interface an > object has when reading code, and which objects provide that > interface. > * Lower memory usage and faster execution speed. Yes, this has been a > price worth paying. But I do want jam on it, please: give me a > language where I get most of Python's advantages but don't have to > pay it. > * Better support for writing correct programs in the form of better > support for things like non-imperative programming, DBC, etc. (with > the emphasis on "etc"). > * Perhaps better built-in support for common tasks in common application > domains. Concurrency, persistence, database queries come to mind. > * Better refactoring tools, better code analysis tools (lint, search, > etc.). > * An even larger user base, contributing more and better free and > commercial software. > > I'm prepared to compromise on the last one. Obviously, it should do all > that while preserving all the nice features of Python -- surely an easy > task. > > > John > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen.NOSPAM at xs4all.nl Sat May 21 15:28:20 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 21 May 2011 21:28:20 +0200 Subject: referring to package scope from module, using relative import? Message-ID: <4dd81254$0$49046$e4fe514c@news.xs4all.nl> Hi, I have a package with several modules in it. The package also has some objects created in the package scope (done in the package __init__.py). Is it possible to access those package scope objects from the modules, with relative imports or something? So that I don't have to import the package itself in its own submodules? Example: A/ __init__.py -> creates A.something thing.py -> needs to do "import A" to access A.something would like to not have to import A I think it's something simple I'm missing... Irmen From clp2 at rebertia.com Sat May 21 15:38:54 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 21 May 2011 12:38:54 -0700 Subject: Problem in using subprocess module and communicate() In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 8:56 AM, vijay swaminathan wrote: > Hi? Gurus, > > I'm having some problem in using the communicate() along with the > subprocess.I would like to invoke a command prompt and pass? on a .bat file > to execute. I went through the subprocess module and understood that using > communicate, we can send the send data to stdin. > > According to the documentation > http://docs.python.org/library/subprocess.html#subprocess.call, it says, > > if you want to send data to the process?s stdin, you need to create the > Popen object with stdin=PIPE. > > so based on this, I have used the below function but it does not seem to > work. Am I missing something here? > > import subprocess > import threading > import time > > def runMonitor(command): > ??? retcode = subprocess.Popen([command, '\k', 'dir'], Shouldn't that be /k, not \k? > ?????????????????????????????? cwd= > 'C:\Python26\WorkSpace\FunctionExamples\src', Sidenote: You really should use forward-slashes in paths like this (or double-up the backslashes). > ?????????????????????????????? stdin = subprocess.PIPE, > ?????????????????????????????? creationflags=subprocess.CREATE_NEW_CONSOLE) > > ??? retcode.wait() > > ??? retcode.communicate('scripts_to_execute.bat') Several issues here: - .wait() waits for the subprocess to terminate; there's reason for the shell to terminate here, so your program will hang forever on the .wait() call. - It makes no sense to call .communicate() after .wait(), since the subprocess will have already terminated; you can't communicate with a dead process. - .communicate() blocks until the subprocess terminates anyway, so calling .wait() is pointless. - I would think a newline is needed in you input to the shell. When one runs a command in the shell manually, one presses Enter after typing it, no? - `retcode` seems a rather poor variable name, since it's holding a Popen object rather than an integer exit code. Putting this all together, here's an improved version: def runMonitor(command): proc = subprocess.Popen([command, '/k', 'dir'], cwd='C:/Python26/WorkSpace/FunctionExamples/src', stdin=subprocess.PIPE, creationflags=subprocess.CREATE_NEW_CONSOLE) input_data = 'scripts_to_execute.bat\n' + 'exit\n' stdout_data, stderr_data = proc.communicate(input_data) I can't test it since I don't run Windows. Cheers, Chris -- http://rebertia.com From ian.g.kelly at gmail.com Sat May 21 16:00:12 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 21 May 2011 14:00:12 -0600 Subject: referring to package scope from module, using relative import? In-Reply-To: <4dd81254$0$49046$e4fe514c@news.xs4all.nl> References: <4dd81254$0$49046$e4fe514c@news.xs4all.nl> Message-ID: On Sat, May 21, 2011 at 1:28 PM, Irmen de Jong wrote: > Hi, > > I have a package with several modules in it. The package also has some objects created > in the package scope (done in the package __init__.py). > > Is it possible to access those package scope objects from the modules, with relative > imports or something? So that I don't have to import the package itself in its own > submodules? > > > Example: > > A/ > ? __init__.py ? ?-> ?creates A.something > ? thing.py ? ? ? -> ?needs to do "import A" ?to access A.something > ? ? ? ? ? ? ? ? ? ? ?would like to not have to import A You can do the relative import like this: from . import something Or if something were defined in A/otherthing.py, then: from .otherthing import something Note that PEP 8 discourages relative imports and encourages absolute imports, though. This would be the preferred way to do it: from A import something Cheers, Ian From tjreedy at udel.edu Sat May 21 16:11:55 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 21 May 2011 16:11:55 -0400 Subject: checking if a list is empty In-Reply-To: <87r57s6riu.fsf@pobox.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: On 5/21/2011 10:46 AM, John J Lee wrote: > In the absence of an explicit interface declaration (have any standards > emerged for that in Python 3, BTW?), the use of len() does give you some > information about the interface, which sometimes makes it easier to > change the function. > > I'm sure you fully understand this, but I'll spell it out. Consider > this function: > > def xyzzy(x): > if x: > print "yes" To me, this trivial procedure (it is not a mathematical function) is too unrealistic to be a basis for argument. > Let's say I've read the function, and I've seen this call site: > > xyzzy(["spam", "eggs"]) > > Now I want to change xyzzy: > > def xyzzy(x): > if x: > print "probably" > if len(x) == 1: > print "definitely" You are not changing xyzzy, you are replacing a procedure whose domain is all python objects with a new procedure with a much reduced domain. In other words, you are changing (and contracting) the idea of the procedure. This is a somewhat crazy thing to do and if Python developers did something like that in the stdlib, I would expect multiple protest posting ;-). (Adding code to *expand* the domain is a different matter.) If xyzzy were really about sized collections, then 1. That should be documented *before* it is ever used in permanent code. 2. There should be code in the first production version that uses that fact and which would raise an error on other inputs. > But there may be many call sites. Perhaps xyzzy even implements part of > a poorly-documented external API. So can x be None? There's no way to > know short of checking all call sites, which may be impossible. It may > not even be feasible to check the *only* call site, if you're > implementing somebody else's poorly documented closed-source API (a > situation I came across at work only yesterday, when that situation > resulted in a bug report). If it's written this way, it's clear that it > can't be None: > > def xyzzy(x): > if len(x) != 0: > print "yes" I agree that the domain of a function should be defined from the start (and only expanded in the future). This means considering from the start, or certainly once it runs correctly for intended inputs, what will happen for other inputs. For instance, I believe functions defined on counts (0, 1, 2, ...) should be written to avoid infinite looping on other inputs, in particular, fractional and negative numbers. I can imagine in theory that a gratuitous call to len() might be useful for defining an interface, but as explained above, I am dubious about that in practice and do not find thid example convincing. -- Terry Jan Reedy From irmen.NOSPAM at xs4all.nl Sat May 21 17:32:50 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 21 May 2011 23:32:50 +0200 Subject: referring to package scope from module, using relative import? In-Reply-To: References: <4dd81254$0$49046$e4fe514c@news.xs4all.nl> Message-ID: <4dd82f83$0$49042$e4fe514c@news.xs4all.nl> On 21-5-2011 22:00, Ian Kelly wrote: > Note that PEP 8 discourages relative imports and encourages absolute > imports, though. This would be the preferred way to do it: > > from A import something Right. I got rid of the silly relative import stuff. As an added bonus, this makes my original question irrelevant :) Irmen From thorsten at thorstenkampe.de Sat May 21 17:53:16 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 21 May 2011 23:53:16 +0200 Subject: Customize help output from optparse (or argparse) References: <2635961.LZWGnKmheA@PointedEars.de> Message-ID: * Thomas 'PointedEars' Lahn (Thu, 12 May 2011 22:22:20 +0200) > Thorsten Kampe wrote: > > I'm using optparse for a little Python script. > > > > 1. The output from "--help" is: > > """ > > Usage: script.py > > > > script.py does something > > > > Options: > > -h, --help show this help message and exit > > """ > > > > I would prefer to have the description before the usage, like... > > """ > > script.py does something > > > > Usage: script.py > > > > Options: > > -h, --help show this help message and exit > > """ > > [...] > > Is that possible with either optparse or the "new kid on the block" > > argparse. If so how? > > You can easily have #1 with optparse.OptionParser(usage="?")?, but optparse > is deprecated in favor of argparse.ArgumentParser. I'm already using usage. That's where optparse has it from. Putting the usage message into the description and vice versa is of course not a viable way to go. Thorsten From nagle at animats.com Sat May 21 18:55:56 2011 From: nagle at animats.com (John Nagle) Date: Sat, 21 May 2011 15:55:56 -0700 Subject: hash values and equality In-Reply-To: <0deha8-6u9.ln1@satorlaser.homedns.org> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> Message-ID: <4dd84324$0$2192$742ec2ed@news.sonic.net> On 5/19/2011 11:33 PM, Ulrich Eckhardt wrote: > For that reason, it is generally useful to use immutable types like > integers, floats, strings and tuples thereof as keys. Since you can't change > them, you basically have the guarantee that they hash the same. Right. It's something of a lack that Python doesn't have user-defined immutable objects. John Nagle From irmen.NOSPAM at xs4all.nl Sat May 21 19:07:28 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 22 May 2011 01:07:28 +0200 Subject: hash values and equality In-Reply-To: <4dd84324$0$2192$742ec2ed@news.sonic.net> References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4dd84324$0$2192$742ec2ed@news.sonic.net> Message-ID: <4dd845b0$0$49047$e4fe514c@news.xs4all.nl> On 22-5-2011 0:55, John Nagle wrote: > On 5/19/2011 11:33 PM, Ulrich Eckhardt wrote: > >> For that reason, it is generally useful to use immutable types like >> integers, floats, strings and tuples thereof as keys. Since you can't change >> them, you basically have the guarantee that they hash the same. > > Right. It's something of a lack that Python doesn't > have user-defined immutable objects. > > John Nagle > collections.namedtuple is rather powerful though... and can be used as key AFAIK. Irmen From bob at mellowood.ca Sat May 21 20:03:12 2011 From: bob at mellowood.ca (bvdp) Date: Sat, 21 May 2011 17:03:12 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: Thanks, Peter, for the detailed explanation. I was going to write a bit of sample/minimal code to demo this, but you nicely beat me to it! > Here's a minimal script to reproduces the problem: > > $ cat tkcallclass.py > import Tkinter as tk > > root = tk.Tk() > root.withdraw() > > class Classic: > ? ? def __init__(self): > ? ? ? ? print "hello" > > button = tk.Button(root, command=Classic) > button.invoke() > $ python2.6 tkcallclass.py > hello > $ python2.7 tkcallclass.py > Traceback (most recent call last): > ? File "tkcallclass.py", line 11, in > ? ? button.invoke() > ? File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 2081, in invoke > ? ? return self.tk.call(self._w, 'invoke') > _tkinter.TclError: invalid command name "__main__.Classic" > $ Any idea why I'm not getting any traceback in my program? It just runs and appears to ignore the callback. > In 2.7 the Tkinter code was changed to use hasattr(obj, "__call__") instead > of callable(obj) to recognize callbacks. This gives different results for > oldstyle classes > > >>> class A: pass > ... > >>> callable(A) > True > >>> hasattr(A, "__call__") > > False > > ...and they are no longer registered automatically with Tkinter. In theory > you could register them explicitly yourself > > $ cat tkcallclass2.py > import Tkinter as tk > > root = tk.Tk() > root.withdraw() > > class Classic: > ? ? def __init__(self): > ? ? ? ? print "hello" > > button = tk.Button(root, command=root.register(Classic)) > button.invoke() > $ python2.7 tkcallclass2.py > hello > > but in practice changing them to newstyle (i. e. have them inherit from > object) or wrapping them in a lambda appears convenient. Yes, I can confirm that both the lambda and setting the class to: class selectFav(object): works. > Personally, I would reconsider whether using a class as a callback is really > necessary. Replacing the class with a function should be a straightforward > process. IIRC, I used the class method since it nicely encapsulates a set of operations: - create/raise a window - list a set of configurable options - have and buttons, both of which destroy the window. Having a function as the callback certainly works as well. Not sure which is the best method in the long run ... I'm trying to use classes more in my programming since it's nice to wrap a bunch of functions up like this. Thanks again. From bob at mellowood.ca Sat May 21 20:07:30 2011 From: bob at mellowood.ca (bvdp) Date: Sat, 21 May 2011 17:07:30 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <10f0acf7-b63b-4cf3-949b-5d0caba19fb0@z13g2000prk.googlegroups.com> <136b3435-a6bd-45fa-9c8c-5602ea23c861@s2g2000yql.googlegroups.com> Message-ID: On May 20, 4:37?pm, rantingrick wrote: > Thats sounds to me a lot like hammering square pegs though round > holes... Perhaps you should explain first in "plain english" what Ahh, but what fun would the Internet, Usenet and programming be without round holes and square pegs. I thought my English was pretty good. > problem your application is intended to solve, then how it is expected I'm trying very much to focus on the problem I'm having with a particular bit of python code. I'm not trying to have the community solve my coding problems. > to interact with the user, and finally, what exactly is NOT working > correctly. I would suffix such a documentary with the current source > code, verbatim. You want me to attach several hundred/thousand lines of source code to demonstrate that a particular bit of python has changed behavior between versions? From steve+comp.lang.python at pearwood.info Sat May 21 20:24:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 May 2011 00:24:35 GMT Subject: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> <4dd84324$0$2192$742ec2ed@news.sonic.net> Message-ID: <4dd857c3$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 May 2011 15:55:56 -0700, John Nagle wrote: > On 5/19/2011 11:33 PM, Ulrich Eckhardt wrote: > >> For that reason, it is generally useful to use immutable types like >> integers, floats, strings and tuples thereof as keys. Since you can't >> change them, you basically have the guarantee that they hash the same. > > Right. It's something of a lack that Python doesn't > have user-defined immutable objects. Although it's not that hard to write your own immutable (-ish) objects. http://northernplanets.blogspot.com/2007/01/immutable-instances-in-python.html Or see the Decimal and Fraction classes in the standard library. -- Steven From tjreedy at udel.edu Sat May 21 20:33:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 21 May 2011 20:33:22 -0400 Subject: TK program problem In-Reply-To: References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: On 5/21/2011 8:03 PM, bvdp wrote: > Yes, I can confirm that both the lambda and setting the class to: > > class selectFav(object): One of the purposes and advantages of Python 3 is having only one class system. Best to always use new-style classes in Python 2.2+ unless you understand and need old-style classes (and need should be never for most people). -- Terry Jan Reedy. From steve+comp.lang.python at pearwood.info Sat May 21 21:02:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 May 2011 01:02:25 GMT Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: <4dd860a1$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 May 2011 15:46:01 +0100, John J Lee wrote: > In the absence of an explicit interface declaration (have any standards > emerged for that in Python 3, BTW?), the use of len() does give you some > information about the interface, which sometimes makes it easier to > change the function. Er, yes? But in any realistic example (your trivial function xyzzyx below is not very realistic) you'll almost certainly get additional hints in the function body. If you have your stereotypical badly-documented function that does this: def spam(x): if x: print("no") # ... x.append(42) # ... that's a hint that x is actually meant to be a list. If instead it says x += 42 that's a good hint that x should not be a list. In either case, changing the test from "if x" to "if x == []" or "if len(x) == 0" or "if x == 0" doesn't gain you anything except a slightly longer average line length. If you're being paid by the character, that's an advantage, but otherwise, why bother? True, if the function is sufficiently trivial, as in your xyzzyx example, then there won't be any such hints as to what sort of input the function expects. If that's the case, then chances are that the function accepts *any* object: > def xyzzy(x): > if x: > print "yes" and changing its semantics to only accept (say) lists, as in your example, is a risky thing to do. It is *much* safer to leave that function untouched, create a new one: def my_xyzzy(alist): if alist: print "probably" if len(alist) == 1: print "definitely" and then change the calls to xyzzyx into my_xyzzyx when and as you determine that it is safe to do so. That will ensure that if you miss a call of xyzzyx(42) somewhere deep in the library, the code will continue to run. If not, you'll have a dead function. You can always take it out later, once you are confident that it is indeed dead code. [...] > If it's written this way, it's clear that it can't be None: > > def xyzzy(x): > if len(x) != 0: > print "yes" But you're assuming that the function actually is intended to accept only objects with a __len__ method. If that is the author's intention, there are better ways of signaling that fact. I'm not entirely sure what your point is... is it to encourage lazy programmers to write "len(x)==0" instead of documentation and meaningful names, or are you just pointing out the occasional silver-lining to a practice which is generally and usually unnecessary? -- Steven From dan.kluev at gmail.com Sat May 21 21:25:21 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 22 May 2011 12:25:21 +1100 Subject: Abandoning Python In-Reply-To: <87ipt46okh.fsf@pobox.com> References: <87ipt46okh.fsf@pobox.com> Message-ID: On Sun, May 22, 2011 at 2:49 AM, John J Lee wrote: > Here's my wishlist (not really in any order): How come pony is not listed there? Language cannot be better than python without pony! > ?* An even larger user base, contributing more and better free and > ? commercial software. According to all language popularity indexes [1-10], C# and Objective-C are only languages which have any chance to fulfill these requirements, but they arguably less flexible than python and have copyright/patent complications. As there is rather heavy inertia in software development community, expecting some language to acquire "even larger user base" is hopeless. Also, most of these complaints could be solved by using correct python dialect for particular task - RPython, Cython and so on. -- With best regards, Daniel Kluev From dan.kluev at gmail.com Sat May 21 21:27:08 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 22 May 2011 12:27:08 +1100 Subject: Abandoning Python In-Reply-To: References: <87ipt46okh.fsf@pobox.com> Message-ID: On Sun, May 22, 2011 at 12:25 PM, Daniel Kluev wrote: > According to all language popularity indexes [1-10], C# and Forgot to include references, although everyone probably already knows them, [1] https://www.ohloh.net/languages?query=&sort=projects [2] http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html [3] http://libresoft.es/debian-counting/lenny/index.php?menu=Statistics [4] http://lang-index.sourceforge.net/ [5] http://langpop.com/ and so on -- With best regards, Daniel Kluev From drsalists at gmail.com Sat May 21 21:39:23 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 21 May 2011 18:39:23 -0700 Subject: Abandoning Python In-Reply-To: <87ipt46okh.fsf@pobox.com> References: <87ipt46okh.fsf@pobox.com> Message-ID: On Sat, May 21, 2011 at 8:49 AM, John J Lee wrote: > > > I still like Python after using it for over a decade, but there are > things I don't like. > > What are your favourite up-and-coming languages of the moment? > > Here's my wishlist (not really in any order): > > * A widely used standard for (optional) interface declaration -- or > something better. I want it to be easier to know what interface an > object has when reading code, and which objects provide that > interface. > I do miss this sometimes, but pylint takes things far enough for me. > * Lower memory usage and faster execution speed. Yes, this has been a > price worth paying. But I do want jam on it, please: give me a > language where I get most of Python's advantages but don't have to > pay it. > PyPy has quite good speed. Memory use, I'm willing to ignore. > * Better support for writing correct programs in the form of better > support for things like non-imperative programming, DBC, etc. (with > the emphasis on "etc"). > And here I thought Python had pretty good functional programming facilities. What do you miss? AFAIK, DBC in terms of "if condition: raise AssertionError" (or assert). What _is_ the "etc"? > * Perhaps better built-in support for common tasks in common application > domains. Concurrency, persistence, database queries come to mind. > http://wiki.python.org/moin/Concurrency/ For persistence, I tend to use gdbm or the dohdbm I just wrote. But there are at least a few other options. For database queries, why build it in? What's wrong with using a module? > * Better refactoring tools, better code analysis tools (lint, search, > etc.). > I find pylint excellent. My idea of a refactoring tool is vim's n.n.n., but have you looked at PyCharm? > * An even larger user base, contributing more and better free and > commercial software. > Gee, you want a scripting language with a larger userbase? > I'm prepared to compromise on the last one. Obviously, it should do all > that while preserving all the nice features of Python -- surely an easy > task. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sat May 21 21:40:52 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 21 May 2011 18:40:52 -0700 Subject: Abandoning Python In-Reply-To: <87boywavsg.fsf@castleamber.com> References: <87ipt46okh.fsf@pobox.com> <87boywavsg.fsf@castleamber.com> Message-ID: On Sat, May 21, 2011 at 9:00 AM, John Bokma wrote: > > A language I want to give a serious try the coming months is Haskell. > > Haskell is indeed interesting. However, do any of Haskell's implementations exploit the opportunities for parallelism that Haskell's definition allows? -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sat May 21 21:43:25 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 21 May 2011 18:43:25 -0700 Subject: Abandoning Python In-Reply-To: References: <87ipt46okh.fsf@pobox.com> Message-ID: On Sat, May 21, 2011 at 6:25 PM, Daniel Kluev wrote: > Also, most of these complaints could be solved by using correct python > dialect for particular task - RPython, Cython and so on. > Cython is an interesting dialect that I use now and then. RPython is probably just as well avoided. PyPy, which is written in RPython and Python, supports Python 2.7 nicely - there's no need to drop down to the level of RPython to get significant performance benefits from PyPy. -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sat May 21 21:50:03 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 21 May 2011 18:50:03 -0700 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: On Fri, May 20, 2011 at 1:47 PM, Dotan Cohen wrote: > They considered Haskell and OCaml and not a single mention of Perl? > Perl is like 10 languages smushed together. To write it, you need only learn one of the 10. To read someone else's, you don't know what subset of those 10 they've used until you get deep into the code. IOW, it's a kitchen sink language - the kind, I believe, that my comparative languages professor would have described as "offensive". -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at mellowood.ca Sat May 21 22:20:22 2011 From: bob at mellowood.ca (bvdp) Date: Sat, 21 May 2011 19:20:22 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: <42561028-39ce-4543-8e3c-b021e3a2b067@34g2000pru.googlegroups.com> > One of the purposes and advantages of Python 3 is having only one class > system. Best to always use new-style classes in Python 2.2+ unless you > understand and need old-style classes (and need should be never for most > people). > Thanks for this. I'll keep it in mind! One thing I really don't understand ... is there a difference between the old/new forms: class foo: class foo(): In cases where I've played with them, they _appear_ to work the same? Also, where does one find the magic that says that for a tkinter class you should use: class foo(object): Not really sure where "object" comes from. Thanks and best, From rosuav at gmail.com Sat May 21 22:56:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 May 2011 12:56:03 +1000 Subject: checking if a list is empty In-Reply-To: <4dd860a1$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> <4dd860a1$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 22, 2011 at 11:02 AM, Steven D'Aprano wrote: > On Sat, 21 May 2011 15:46:01 +0100, John J Lee wrote: > > Er, yes? But in any realistic example (your trivial function xyzzyx below > is not very realistic) you'll almost certainly get additional hints in > the function body. True, but sometimes those hints will be buried in nested calls, making it less obvious. It might well take some digging to figure out just what sort of object it's meant to be accepting. That's why I prefer to have some sort of type declarations; or alternatively, a good docstring / autodoc comment that says what the function wants and gives. Chris Angelico From rustompmody at gmail.com Sat May 21 23:02:03 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 21 May 2011 20:02:03 -0700 (PDT) Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: On May 22, 1:11?am, Terry Reedy wrote: > I agree that the domain of a function should be defined from the start > (and only expanded in the future). I dont understand... I dont always write correct code -- otherwise called 'a bug' -- though I never let the damn bug lose intentionally. And when I see 'the bug' scampering around to my distress the only way of catching it sometimes is to strengthen an (perhaps earlier unthought, unspecified) invariant or precondition. Which amounts to contracting the domain. > This is a somewhat crazy thing to do and if Python developers > did something like that in the stdlib, I would expect multiple protest > posting ;-). That such protests happen is evidence (I dont say proof) that such contractions are sometimes necessary. In fact when I pick up some code marked as 'alpha' I understand it as saying: Please try this and send us (the developers) bug reports. But in no case are we committed to the current API. [Sometimes this is explicitly said. It is always implied by the 'alpha'] When I see 'Beta' I understand: We think this works and we will not make gratuitous changes but no guarantees. When I see 'Stable' I understand: The API is fixed (ie we will not change it) and we accept the inevitable consequence [Seventh Lehman- Belady law: http://en.wikipedia.org/wiki/Lehman%27s_laws_of_software_evolution ] Why is the C library in linux called libc6 and not just libc? From rosuav at gmail.com Sat May 21 23:52:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 May 2011 13:52:05 +1000 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: On Sun, May 22, 2011 at 1:02 PM, rusi wrote: > Why is the C library in linux called libc6 and not just libc? I assume you mean this? http://www.linux-m68k.org/faq/glibcinfo.html When you dynamically link against a shared object, you save on executable size, but you have to have that shared object on the target system. That's completely different from API changes. I could compile my code using half a dozen different compilers, and use dynamic linking each time, and then those six binaries would expect six implementations of libc on the target computer. They're incompatible with each other. But they will all have a size_t strlen(const char *) that tells me how long my string is. Everyone has a different way of handling incompatible API changes. The most common is to simply deprecate the old function and create a new one. It's simple and effective. With your original xyzzy function, create a my_xyzzy as per Steven's suggestion; job done. (I'd assume that a function called "my_xyzzy" is a local override, in the same way that I might write a "my_malloc" that does some statisticking and then returns malloc(sz), but that's one of the consequences of trivia - you can't really name it descriptively.) Chris Angelico From ladasky at my-deja.com Sat May 21 23:58:10 2011 From: ladasky at my-deja.com (John Ladasky) Date: Sat, 21 May 2011 20:58:10 -0700 (PDT) Subject: Multiprocessing: don't push the pedal to the metal? Message-ID: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> Hello again, everyone. I'm developing some custom neural network code. I'm using Python 2.6, Numpy 1.5, and Ubuntu Linux 10.10. I have an AMD 1090T six-core CPU. About six weeks ago, I asked some questions about multiprocessing in Python, and I got some very helpful responses from you all. http://groups.google.com/group/comp.lang.python/browse_frm/thread/374e1890efbcc87b Now I'm back with a new question. I have gotten comfortable with cProfile, and with multiprocessing's various Queues (I've graduated from Pool). I just ran some extensive tests of my newest code, and I've learned some surprising things. I have a pretty picture here (be sure to view the full-size image): http://www.flickr.com/photos/15579975 at N00/5744093219 I'll quickly ask my question first, to avoid a TL;DR problem: when you have a multi-core CPU with N cores, is it common to see the performance peak at N-1, or even N-2 processes? And so, should you avoid using quite as many processes as there are cores? I was expecting diminishing returns for each additional core -- but not outright declines. That's what I think my data shows for many of my trial runs. I've tried running this test twice. Once, I was reading a few PDFs and web pages while my speed test was running. But even when I wasn't using the computer for these other (light) tasks, I saw the same performance drops. Perhaps this is due to the OS overhead? The load average on my system monitor looks pretty quiet to me when I'm not running my program. OK, if you care to read further, here's some more detail... My graphs show the execution times of my neural network evaluation routine as a function of: - the size of my neural network (six sizes were tried -- with varying numbers of inputs, outputs and hidden nodes), - the subprocess configuration (either not using a subprocess, or using 1-6 subprocesses), and - the size of the input data vector (from 7 to 896 sets of inputs -- I'll explain the rationale for the exact numbers I chose if anyone cares to know). Each graph is normalized to the execution time that running the evaluation routine takes on a single CPU, without invoking a subprocess. Obviously, I'm looking for the conditions which yield performance gains above that baseline. (I'll be running this particular piece of code millions of times!) I tried 200 repetitions for each combination network size, input data size, and number of CPU cores. Even so, there was substantial irregularity in the timing graphs. So, rather than connecting the dots directly, which would lead to some messy crossing lines which are a bit hard to read, I fit B-spline curves to the data. As I anticipated, there is a performance penalty that is incurred just for parceling out the data to the multiple processes and collating the results at the end. When the data set is small, it's faster to send it to a single CPU, without invoking a subprocess. In fact, dividing a small task among 3 processes can underperform a two-process approach, and so on! See the leftmost two panels in the top row, and the rightmost two panels in the bottom row. When the networks increase in complexity, the size of the data set for which break-even performance is achieved drops accordingly. I'm more concerned about optimizing these bigger problems, obviously, because they take the longest to run. What I did not anticipate was finding that performance reversal with added computing power for large data sets. Comments are appreciated! From rustompmody at gmail.com Sun May 22 00:32:05 2011 From: rustompmody at gmail.com (rusi) Date: Sat, 21 May 2011 21:32:05 -0700 (PDT) Subject: checking if a list is empty References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> Message-ID: <6bf36a0d-f259-48ad-8f89-2d5688758bf6@l14g2000pro.googlegroups.com> On May 22, 8:52?am, Chris Angelico wrote: > On Sun, May 22, 2011 at 1:02 PM, rusi wrote: > > Why is the C library in linux called libc6 and not just libc? > > I assume you mean this?http://www.linux-m68k.org/faq/glibcinfo.html Ha Ha! Thanks for that link! I quote: > You should not be using libc4 for anything any more. If you do use it, we will hunt you > down and execute you as an example to others. (Not really, but you get the point...) Recently on the emacs list there was a big flame-fest because the behavior (aka interface) of return/newline changed. The argument for change: Can we have emacs behave a little more like a 21st century application? Against: Somebody's scripting code broke badly. You may take any side you like. From rosuav at gmail.com Sun May 22 01:01:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 May 2011 15:01:59 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: On Sun, May 22, 2011 at 11:50 AM, Dan Stromberg wrote: > Perl is like 10 languages smushed together.? To write it, you need only > learn one of the 10. ? To read someone else's, you don't know what subset of > those 10 they've used until you get deep into the code. +1 QOTW. Perl: The Swiss Army Knife of programming languages, including the bit where you can never find the right blade to open up. Chris Angelico From rosuav at gmail.com Sun May 22 01:16:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 May 2011 15:16:35 +1000 Subject: checking if a list is empty In-Reply-To: <6bf36a0d-f259-48ad-8f89-2d5688758bf6@l14g2000pro.googlegroups.com> References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <930j6nFi2lU1@mid.individual.net> <87r57s6riu.fsf@pobox.com> <6bf36a0d-f259-48ad-8f89-2d5688758bf6@l14g2000pro.googlegroups.com> Message-ID: On Sun, May 22, 2011 at 2:32 PM, rusi wrote: > Recently on the emacs list there was a big flame-fest because the > behavior (aka interface) of return/newline changed. > The argument for change: Can we have emacs behave a little more like a > 21st century application? > Against: Somebody's scripting code broke badly. > > You may take any side you like. The side I take is: If you want emacs, use emacs. If you want SciTE, use SciTE. If you want nano, use nano. And sometimes, you might have special circumstances that demand a different choice (can't use SciTE over ssh, afaik), so it's worth learning more than one. Chris Angelico From hansmeetschool at gmail.com Sun May 22 01:16:51 2011 From: hansmeetschool at gmail.com (Hansmeet Singh) Date: Sat, 21 May 2011 22:16:51 -0700 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: i think we should end our butchering of perl on a light note (you may have already read this): EXTERIOR: DAGOBAH -- DAY With Yoda strapped to his back, Luke climbs up one of the many thick vines that grow in the swamp until he reaches the Dagobah statistics lab. Panting heavily, he continues his exercises -- grepping, installing new packages, logging in as root, and writing replacements for two-year-old shell scripts in Python. YODA: Code! Yes. A programmer's strength flows from code maintainability. But beware of Perl. Terse syntax... more than one way to do it... default variables. The dark side of code maintainability are they. Easily they flow, quick to join you when code you write. If once you start down the dark path, forever will it dominate your destiny, consume you it will. LUKE: Is Perl better than Python? YODA: No... no... no. Quicker, easier, more seductive. LUKE: But how will I know why Python is better than Perl? YODA: You will know. When your code you try to read six months from now. On Sat, May 21, 2011 at 10:01 PM, Chris Angelico wrote: > On Sun, May 22, 2011 at 11:50 AM, Dan Stromberg > wrote: > > Perl is like 10 languages smushed together. To write it, you need only > > learn one of the 10. To read someone else's, you don't know what subset > of > > those 10 they've used until you get deep into the code. > > +1 QOTW. > > Perl: The Swiss Army Knife of programming languages, including the bit > where you can never find the right blade to open up. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jstroud at mbi.ucla.edu Sun May 22 02:02:24 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 21 May 2011 23:02:24 -0700 Subject: count strangeness Message-ID: tal 65% python2.7 Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. py> class C(object): ... def __init__(self): ... self.data = [] ... def doit(self, count=0): ... for c in self.data: ... count += c.doit(count) ... count += 1 ... print count ... return count ... py> c = C() py> c.data.extend([C() for i in xrange(10)]) py> c.doit() 1 2 4 8 16 32 64 128 256 512 1024 1024 WTF? James From crebert at ucsd.edu Sun May 22 02:27:31 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Sat, 21 May 2011 23:27:31 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 11:02 PM, James Stroud wrote: > tal 65% python2.7 > Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > py> class C(object): > ... ? def __init__(self): > ... ? ? self.data = [] > ... ? def doit(self, count=0): > ... ? ? for c in self.data: > ... ? ? ? count += c.doit(count) > ... ? ? count += 1 > ... ? ? print count > ... ? ? return count > ... > py> c = C() > py> c.data.extend([C() for i in xrange(10)]) > py> c.doit() > 1 > 2 > 4 > 8 > 16 > 32 > 64 > 128 > 256 > 512 > 1024 > 1024 > > WTF? Assuming your question is "Why is 1024 there twice?", the answer is that it was the return value of the initial c.doit() call, and the interactive interpreter outputs all non-None expression results; for example: [In the Python REPL] >>> 5 + 5 10 >>> So, you explicitly print the 1024 in your function once, and the interpreter implicitly outputs it the second time. Notice what happens when we use a statement instead of an expression: >>> final = c.doit() 1 2 4 8 16 32 64 128 256 512 1024 >>> final 1024 >>> And if we comment out the `print` in C.doit() and run your example again: >>> c = C() >>> c.data = [C() for i in xrange(10)] >>> c.doit() 1024 >>> Cheers, Chris -- http://rebertia.com From sganapathy.subramanium at gmail.com Sun May 22 02:28:51 2011 From: sganapathy.subramanium at gmail.com (Ganapathy Subramanium) Date: Sun, 22 May 2011 11:58:51 +0530 Subject: Is there a better way to solve this? Message-ID: Hello, I'm a new bie to python programming and on the processing of learning python programming. I have coded my first program of fibonnaci generation and would like to know if there are better ways of achieving the same. I still feel quite a few things to be improved. Just wanted experts thoughts on this. try: length = input('Enter the length till which you want to generate the fibonnaci series: \n') print type(length) except: print 'Invalid input detected' exit(0) if type(length) is int: result = [] a = 0 b = 1 result.append(a) result.append(b) if length > 2: count = 2 while count < length: c = a + b a = b b = c result.append(c) count += 1 else: print result print 'The lenght of result is : ' , len(result) else: print 'Fibonacci series could not be generated !!!' -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sun May 22 02:31:24 2011 From: __peter__ at web.de (Peter Otten) Date: Sun, 22 May 2011 08:31:24 +0200 Subject: count strangeness References: Message-ID: James Stroud wrote: > tal 65% python2.7 > Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > py> class C(object): > ... def __init__(self): > ... self.data = [] > ... def doit(self, count=0): > ... for c in self.data: > ... count += c.doit(count) > ... count += 1 > ... print count > ... return count > ... > py> c = C() > py> c.data.extend([C() for i in xrange(10)]) > py> c.doit() > 1 > 2 > 4 > 8 > 16 > 32 > 64 > 128 > 256 > 512 > 1024 > 1024 > > > > WTF? Put the code into a file, run it -- and be enlightened ;) From jstroud at mbi.ucla.edu Sun May 22 02:32:31 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 21 May 2011 23:32:31 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: Chris Rebert wrote: >> WTF? > > Assuming your question is "Why is 1024 there twice?", the answer is The question is "Why is 1024 there at all?" It should be 10. James From jstroud at mbi.ucla.edu Sun May 22 02:34:56 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 21 May 2011 23:34:56 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: Peter Otten wrote: > James Stroud wrote: >> WTF? > > Put the code into a file, run it -- and be enlightened ;) tal 72% python2.7 eraseme.py 1 2 4 8tal 73% cat eraseme.py #! /usr/bin/env python class C: def __init__(self): self.data = [] def doit(self, count=0): for c in self.data: count += c.doit(count) count += 1 print count return count c = C() c.data.extend([C() for i in xrange(10)]) c.doit() tal 74% python2.7 eraseme.py 1 2 4 8 16 32 64 128 256 512 1024 Hmmm. It's still 1024. What am I missing? James From jstroud at mbi.ucla.edu Sun May 22 02:39:41 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 21 May 2011 23:39:41 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: James Stroud wrote: > Chris Rebert wrote: >>> WTF? >> >> Assuming your question is "Why is 1024 there twice?", the answer is > > The question is "Why is 1024 there at all?" It should be 10. > > James I mean 11, not 10--but you get the point. James From clp2 at rebertia.com Sun May 22 02:42:00 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 21 May 2011 23:42:00 -0700 Subject: Is there a better way to solve this? In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 11:28 PM, Ganapathy Subramanium wrote: > Hello, > > I'm a new bie to python programming and on the processing of learning python > programming. I have coded my first program of fibonnaci generation and would > like to know if there are better ways of achieving the same. > > I still feel quite a few things to be improved. Just wanted experts thoughts > on this. > > try: > > ??? length = input('Enter the length till which you want to generate the > fibonnaci series: \n') > ??? print type(length) > > except: > ??? print 'Invalid input detected' > ??? exit(0) Never use the input() function in Python 2.x; it does an eval(), which is evil. Always use raw_input() and an explicit conversion instead; e.g. Q = 'Enter the length till which you want to generate the fibonnaci series: \n' try: length = int(raw_input(Q)) except ValueError: print 'Invalid input detected' exit(0) Also, as a sidenote: > if type(length) is int: Is normally written: if isinstance(length, int): Cheers, Chris -- http://rebertia.com From crebert at ucsd.edu Sun May 22 02:55:46 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Sat, 21 May 2011 23:55:46 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 11:32 PM, James Stroud wrote: > Chris Rebert wrote: >>> >>> WTF? >> >> Assuming your question is "Why is 1024 there twice?", the answer is > > The question is "Why is 1024 there at all?" It should be 10. Ah. This is why it's better to be more explicit about what your question is than a mere "WTF?". In that case, I believe you meant to write: count += c.doit() rather than: count += c.doit(count) Recall that count is continually increasing as you go through your loop. Although you'll then get 11, not 10, but the cause of that is obvious (`count += 1`). Cheers, Chris -- http://rebertia.com From jstroud at mbi.ucla.edu Sun May 22 02:56:36 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 21 May 2011 23:56:36 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: Peter Otten wrote: > James Stroud wrote: >> WTF? > > Put the code into a file, run it -- and be enlightened ;) Compare the follower to the last. tal 77% cat eraseme.py #! /usr/bin/env python class C: def __init__(self): self.data = [] def doit(self, count=[0]): for c in self.data: c.doit() count[0] += 1 print count[0] c = C() c.data.extend([C() for i in xrange(10)]) c.doit() tal 78% python2.7 eraseme.py 1 2 3 4 5 6 7 8 9 10 11 James From jstroud at mbi.ucla.edu Sun May 22 03:03:05 2011 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 22 May 2011 00:03:05 -0700 Subject: count strangeness In-Reply-To: References: Message-ID: Chris Rebert wrote: > On Sat, May 21, 2011 at 11:32 PM, James Stroud wrote: >> Chris Rebert wrote: >>>> WTF? >>> Assuming your question is "Why is 1024 there twice?", the answer is >> The question is "Why is 1024 there at all?" It should be 10. > > Ah. This is why it's better to be more explicit about what your > question is than a mere "WTF?". > > In that case, I believe you meant to write: > count += c.doit() > rather than: > count += c.doit(count) I get it. Thank you. James From __peter__ at web.de Sun May 22 03:13:44 2011 From: __peter__ at web.de (Peter Otten) Date: Sun, 22 May 2011 09:13:44 +0200 Subject: count strangeness References: Message-ID: James Stroud wrote: > Peter Otten wrote: >> James Stroud wrote: >>> WTF? >> >> Put the code into a file, run it -- and be enlightened ;) > > > tal 72% python2.7 eraseme.py > 1 > 2 > 4 > 8tal 73% cat eraseme.py > #! /usr/bin/env python > > class C: > def __init__(self): > self.data = [] > def doit(self, count=0): > for c in self.data: > count += c.doit(count) > count += 1 > print count > return count > > c = C() > c.data.extend([C() for i in xrange(10)]) > c.doit() > tal 74% python2.7 eraseme.py > 1 > 2 > 4 > 8 > 16 > 32 > 64 > 128 > 256 > 512 > 1024 > > > Hmmm. It's still 1024. > > What am I missing? > > James Like Chris I assumed that you wondered why 1024 appeared twice. It turns out WTF is not a got a good problem description. Now for a complete run-through, the inner c.doit() has len(c.data) == 0, so count += c.doit(count) just adds count + 1 and you get 10 iterations: (1) count=0, print 1, add 1 (2) count=1, print 2, add 2 (3) count=3, print 4, add 4 (4) count=7, print 8, add 8 (5) you get the idea Another way to look at it: in your special case the inner loop can be rewritten as for c in self.data: print count + 1 count += count + 1 From orasnita at gmail.com Sun May 22 03:44:18 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Sun, 22 May 2011 10:44:18 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: <9CDC4B2CD1F445E994119A50F65155DF@teddy> From: "Hansmeet Singh" >i think we should end our butchering of perl on a light note (you may have > already read this): > EXTERIOR: DAGOBAH -- DAY > With Yoda strapped to his back, Luke climbs up one of > the many thick vines that grow in the swamp until he > reaches the Dagobah statistics lab. Panting heavily, he > continues his exercises -- grepping, installing new > packages, logging in as root, and writing replacements for > two-year-old shell scripts in Python. > > YODA: Code! Yes. A programmer's strength flows from code > maintainability. But beware of Perl. Terse syntax... more > than one way to do it... default variables. The dark side > of code maintainability are they. Easily they flow, quick > to join you when code you write. If once you start down the > dark path, forever will it dominate your destiny, consume > you it will. > > LUKE: Is Perl better than Python? > > YODA: No... no... no. Quicker, easier, more seductive. > > LUKE: But how will I know why Python is better than Perl? > > YODA: You will know. When your code you try to read six months > from now. > I've noticed that on many Perl mailing lists the list members talk very rarely about Python, but only on this Python mailing list I read many discussions about Perl, in which most of the participants use to agree that yes, Python is better, as it shouldn't be obvious that most of the list members prefer Python. If Python would be so great, you wouldn't talk so much about how bad are other languages, or if these discussions are not initiated by envy, you would be also talking about how bad is Visual Basic, or Pascal, or Delphi, or who knows other languages. A few months ago I have asked how can I create a dictionary from a list, and there were so many techniques that I think that it is just a buzzword that in Perl there are many ways to do it, while in Python there is a single way. In Python I found from the messages I received on this mailing list that there are a lot of ways, without even beeing a "recommended" way, while in Perl there is a single way, of course much shorter and clearer. A bad program can be written in any language, no matter if it is so strict and forces the programmer to use spaces as a way of defining the blocks of code, so the fact that Perl is very flexible is an advantage for the programmer who writes the code. Perl offers the module Perl::Critic which offers a command line that checks the code for different levels of syntax errors which don't respect the good practices (which are also published in a book) so if the program has to be used by more programmers, it is very simple to bring it to a very standard syntax. Perl also has Perl::Tidy that offers another command line which re-arrange the code to a standard way, including the indentation type, the placement of parenthesis, spacing and other things, so the programs can look visually the same. And these are advantages for those that need to read the code by others also. Because of its flexibility, Perl offers more advanced modules and libraries which are not available for Python. For example, Catalyst web framework is much powerful and flexible than any other Python framework, because it can be used with any ORM, with any templating system, with any form processor, with any type of configuration files (Apache style, ini, JSON, XML, perl data structures, yaml), and it can run with its own web server, or with mod_perl, FastCGI, cgi, psgi without any change, and it has a very clean and flexible URL dispatcher that doesn't need to do (and maintain) the URL mapping in a distinct module made only for this. A Catalyst based application is very easy to maintain because it has a very clean structure and the command lines that can be used to automaticly generate the base for controllers, models or views also generate the base test files and also create a few basic tests for the created modules, beeing very easy to add new tests. And DBIx::Class ORM is a very powerful ORM and Template-Toolkit a great templating system, and Moose can be used to create a very powerful object model, and there are a lot of other very good modules which are not available for other languages. It can be hard to find the good quality Perl code while you don't know where to look for though. This is right, because the web is full of old-style Perl code since the era of Matt's Perl script archive, and the web is also full of pirated books about using CGI, but talking about that bad style code shows just that you are talking about something you don't know. Somebody told that C# and Objective C are good languages. They might be good, but they are proprietary, and not only that they are proprietary, but they need to be ran under platforms that cannot be used freely, so from the freedom point of view, Perl, Ruby, Python and Java are the ways to go. Octavian From rustompmody at gmail.com Sun May 22 04:13:04 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 22 May 2011 01:13:04 -0700 (PDT) Subject: more than just ipython broken in windows Message-ID: Earlier I asked about a problem with ipython in windows which does not seem to be there in linux. Now I find that a similar problem surfaces with turtle -- so it seemingly is not so much an ipython problem. The problem can be seen thus: Lets say I want to try out some turtle commands such as: ---------------- from turtle import * forward(100) left(90) forward(200) ------------- Run from a file there's no issue. Likewise I can run these commands one after the other from an interactive prompt in a shell and they work as expected. But if I run these commands one after another at the interactive prompt inside emacs, it hangs after the first forward(100) ie the canvas and a line and arrow come up but control does not seem to return to the prompt. ---------------- More general question: When a question was asked: "Which IDE you use for python development?", 'emacs' was a frequent response. Are any of you emacs+python users on windows? [Or am I a dinosaur?] From dan.kluev at gmail.com Sun May 22 04:20:49 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sun, 22 May 2011 19:20:49 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <9CDC4B2CD1F445E994119A50F65155DF@teddy> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> Message-ID: On Sun, May 22, 2011 at 6:44 PM, Octavian Rasnita wrote: > Because of its flexibility, Perl offers more advanced modules and libraries which are not available for Python. What 'flexibility' are you talking about? This seem to be very biased statement, based on lack of according python experience. There are many python web frameworks which allow you to use w/e interfaces, template languages and ORMs you want - Pyramid/Pylons is good example. 'Very powerful' and 'great' are 'very useless' descriptions of these modules. Please, show us what exactly is so 'advanced' about them which cannot be done in python. -- With best regards, Daniel Kluev From hobson42 at gmail.com Sun May 22 05:20:00 2011 From: hobson42 at gmail.com (Ian) Date: Sun, 22 May 2011 10:20:00 +0100 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> <4DCAF95B.60307@gmail.com> Message-ID: <4DD8D540.7020703@gmail.com> On 12/05/2011 04:51, Chris Angelico wrote: > On Thu, May 12, 2011 at 7:02 AM, Ian wrote: >> In the "real world" lists of zero items do not exist. >> You don't go shopping with a shopping list of zero items. > Actually, yes you do. You maintain your shopping list between trips; > whenever you need something, you put it on the list immediately. Then > when you go shopping, you just take the list with you (if you're > lucky, you don't need to move or copy it at all, you just get another > reference to it). Once you're done, you empty the list - you now have > a shopping list with zero items (until you get home and realize you > forgot something). > > Chris Angelico He He. I didn't claim an empty list was not useful! If you maintain it between trips, then yes, you arrive back with an empty list. Ian From kushal.kumaran+python at gmail.com Sun May 22 06:04:08 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sun, 22 May 2011 15:34:08 +0530 Subject: how to get PID from subprocess library In-Reply-To: References: Message-ID: On Sat, May 21, 2011 at 6:20 PM, TheSaint wrote: > Kushal Kumaran wrote: > >> That's how it is able to give you the status. ?So, if you >> are using getstatusoutput, you will have only one instance of your >> command running. > > My intent is to launch only one program instance, which will goes as daemon. > To avoid a second call I'd like rather to use Python than > ==============================code========================================= > ? ?def start(self): > ? ? ? ?'''try to start aria2c as a daemon and return its handle to where it > can > ? ? ? ?proceed to issue commands''' > > ? ? ? ?# aria2c is running, then don't try it again > ? ? ? ?if (chkout('ps -A |grep aria2c')[0] > 0): > ? ? ? ? ? ?try: > ? ? ? ? ? ? ? ?chkout(self.ARIA_CMD) > ? ? ? ? ? ?except: > ? ? ? ? ? ? ? ?raise SystemExit('aria2c is not working as deamon') > ? ? ? ?elif self.handle: return self.handle > ? ? ? ?# everything is good, it will return an handle > ? ? ? ?self.handle= \ > ? ? ? ?xmlrpclib.ServerProxy('http://localhost:%s/rpc' %int(self.numport)) > ? ? ? ?return self.handle > ==============================code========================================= > > Here I've named subprocess.getstatusoutput as chkout, I'm calling 2 more > programs to find whether there's a running instance of aria2c. I think it's > not nice, python libraries should get the matter done. > Unfortunately, because of the way daemons work, you will not be able to do this (there's some trickery with ptrace and similar tools, but surely there must be simpler ways for you). Here's a very simplified view of a typical daemon's startup: - your process (let's call it pid1) starts a program which says it will daemonize (let's call it pid2). - pid2 forks an additional process (pid3), then pid2 exits - pid1 gets the exit status of its own child (pid2) Accordingly, even if you get a PID, it will only be pid2, which is not the PID of the daemon process. You will need some other way of getting at the daemon's PID. You could look for a way to make aria2c not become a daemon and use subprocess.Popen to start it. That gives you the PID and ways to see if the process is still running. -- regards, kushal From orasnita at gmail.com Sun May 22 08:47:33 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Sun, 22 May 2011 15:47:33 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy> Message-ID: <12225671E9654FECB49613D915FAEC19@teddy> From: "Daniel Kluev" > On Sun, May 22, 2011 at 6:44 PM, Octavian Rasnita wrote: >> Because of its flexibility, Perl offers more advanced modules and libraries which are not available for Python. > > What 'flexibility' are you talking about? This seem to be very biased > statement, based on lack of according python experience. I am talking about that flexibility which was criticized in the previous messages telling that this flexibility allows any programmer to use his own way. Perl doesn't force anyone to indent the code, don't force the programmer to define a hash element before using it, allow the programmer to interpret the variables in strings directly. These things should be not used always, but if in some cases if the programmer wants to use them, he can use them with no problems. And this means flexibility. > There are many python web frameworks which allow you to use w/e > interfaces, template languages and ORMs you want - Pyramid/Pylons is > good example. > 'Very powerful' and 'great' are 'very useless' descriptions of these > modules. Please, show us what exactly is so 'advanced' about them > which cannot be done in python. Every language can do almost anything, so this is not important, because the Python programmers didn't chose Python because it can do what other languages cannot do. It is important how easy is to create an app with it, and while Python offers helpful features for creating desktop apps, for creating web apps Perl is better. Here is a text from the documentation of Pyramid/Pylons: "We finally need to add some routing elements to our application configuration if we want our view functions to be matched to application URLs. ... # routes setup config.add_route('list', '/') config.add_route('new', '/new') config.add_route('close', '/close/{id}') " ... First, this is a bad style of mapping urls, because this list must be maintained every time the programmer changes something in a controller that makes the app need to use other urls. Catalyst don't need this overhead and don't need to specify the url mapping in a separate module. If the controllers change, then the url dispatching also changes. Second, this way of url dispatching is not so flexible, because it doesn't allow as many types of url mappings. Catalyst allows to dispatch the urls to actions based on controllers and subroutines names, globally or locally (based on the current controller), it allows dispatching based on regular expressions, it allows a chained dispatch where more actions are executed in a certain order on a single request, and all these without typing code outside of the subroutines that do the actions. The module DBIx::Class which is used usually as an ORM can create the class files for all the tables from a database (MySQL, Oracle, PostgreSQL, SQLite, MS SQL, etc), and it can be used to search using unions, sub-selects, can define views at ORM level, can accept to insert different types of objects like DateTime objects and can also return those type of objects, and many other things, and most of the things it can do can be done without using SQL code at all, but only standard Perl code and Perl data structures. HTML::FormFu form processor is one of the most used form processors in Catalyst applications and it can generate and parse forms created directly in the code of the application, or as external configuration files defined using JSON, or YAML, or Apache configuration style, or Perl data structures, or XML... The forms defined are very easy to create and the elements from those forms, for example the list of elements in a combo box can be taken directly from a database by specifying just a few configuration elements. The results of a form submit can be also inserted in a database using a connector with DBIx::Class without specifying any database table column name in the programming code, and for doing this are required just a few lines of code that checks if the $form->submitted_and_valid() and that does the redirection after the submit, the insertion in the database requiring just: $form->model->create; or $form->model->update( $db_record ); ...after that record was defined using just something like: my $db_record = $c->model( 'DB::TableName' )->find( $record_id ); And HTML::FormFu can do filtering based on many conditions, impose the specified constraints, specify different inflators/deflators from the inserted strings to their corresponding object types, do a validation eventualy based on a database query that checks for duplicates or other things, transform the data automaticly after the form was processed, can use I18N for displaying the field labels or values translated in the active language, have its own rendering engine or can render custom form fields made using Template-Toolkit, etc. Yes, for web apps I have seen more things which can be done much better in Perl, much easier and clear, with less code, and not because the programmer needs to do not-recommended tricks for shortening the code, but because there are very many modules on CPAN that do the hard work. Octavian From roy at panix.com Sun May 22 09:36:51 2011 From: roy at panix.com (Roy Smith) Date: Sun, 22 May 2011 09:36:51 -0400 Subject: count strangeness References: Message-ID: In article , James Stroud wrote: > tal 65% python2.7 > Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > py> class C(object): > ... def __init__(self): > ... self.data = [] > ... def doit(self, count=0): > ... for c in self.data: > ... count += c.doit(count) > ... count += 1 > ... print count > ... return count > ... > py> c = C() > py> c.data.extend([C() for i in xrange(10)]) > py> c.doit() I have no idea what this is *supposed* to be doing, so let me toss out some general debugging ideas; 1) What do you expect [C() for i in xrange(10)] to return? Does it? Run that part in isolation and see if it does. 2) What do you expect c.data.extend([...]) to return? Does it? 3) What do you expect c.doit() to return for trivial inputs? Does it? Try calling it with a count of 0, 1, and 2, and see if you get the result you expect. In other words, break the problem down into smaller pieces and make sure each piece works in isolation. When you find some little piece which isn't doing what you expect, it'll be much easier to debug than trying to debug the whole thing at once. From nobody at nowhere.net.no Sun May 22 09:41:50 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 22 May 2011 21:41:50 +0800 Subject: how to get PID from subprocess library References: Message-ID: Kushal Kumaran wrote: > You could look for a way to make aria2c not become a daemon and use > subprocess.Popen to start it. That gives you the PID and ways to see > if the process is still running I see. It's a step that I've to get on my account. Unfortunately I'll have to study it some more. BTW. I removed grep from the command. Python does it with the *in* statement :) -- goto /dev/null From s.selvamsiva at gmail.com Sun May 22 09:42:08 2011 From: s.selvamsiva at gmail.com (Selvam) Date: Sun, 22 May 2011 19:12:08 +0530 Subject: Hotshoting recursive function Message-ID: Hi, I am using hotshot module to profile my python function. I used the details from ( http://code.activestate.com/recipes/576656-quick-python-profiling-with-hotshot/ ). The function I profile is a recursive one and I am getting the following error, "ProfilerError: profiler already active" I guess this is due to the recursive call to the profiling function. I would like to get some suggestions. -- Regards, S.Selvam SG E-ndicus Infotech Pvt Ltd. http://e-ndicus.com/ " I am because we are " -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Sun May 22 10:03:29 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 22 May 2011 07:03:29 -0700 (PDT) Subject: TK program problem References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> Message-ID: <5a309bd1-71e1-4c78-a304-24552b1c5da5@m40g2000vbt.googlegroups.com> On May 21, 7:03?pm, bvdp wrote: > IIRC, I used the class method since it nicely encapsulates a set of > operations: > > ? ?- create/raise a window > ? ?- list a set of configurable options > ? ?- have and buttons, both of which destroy the > window. Ok NOW we are getting somewhere! It is amazing how helpful people can be when you explain your problem in "plain English". What you are describing here is a dialog (be it modal or not). However your earlier description of... """Yes, the class is instantiated when the button is clicked. Then, the user stays in the class and uses its methods until he hits in the class. """ ... was about as effective as the "orb of confusion" on Patrick... *drool* > Having a function as the callback certainly works as well. Not sure > which is the best method in the long run ... I'm trying to use classes > more in my programming since it's nice to wrap a bunch of functions up > like this. Yes you ABSOLUTELY SHOULD encapsulate the dialog code in a class! THEN create an instance of the class inside a "easy to call" function. class MyDialog(blah): blah,blah,blah def show_dialog(*args): d = MyDialog(*args) return d.result result = show_dialog() ...and they all lived happily ever after ;-) From rosuav at gmail.com Sun May 22 10:25:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 00:25:06 +1000 Subject: TK program problem In-Reply-To: <5a309bd1-71e1-4c78-a304-24552b1c5da5@m40g2000vbt.googlegroups.com> References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <5a309bd1-71e1-4c78-a304-24552b1c5da5@m40g2000vbt.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 12:03 AM, rantingrick wrote: > ... was about as effective as the "orb of confusion" on Patrick... > *drool* > That sounds like a Dungeons and Dragons artifact item... invoking the orb of confusion is a standard action that does not provoke an Attack of Opportunity. > class MyDialog(blah): > blah,blah,blah > > def show_dialog(*args): > d = MyDialog(*args) > return d.result > > result = show_dialog() I don't really see why it shouldn't be valid to use the class itself in this way. Once the constructor returns, the object IS the return value. But then, my opinion may not be valid. I've done weird things in C++ where, for instance, the invocation of a modeless dialog is: new FoobarDialog(params); And somewhere it has an event (eg when the window is destroyed) that executes: delete this; I'm a little mad and generally silly, so my opinion doesn't matter (matter matter matter matter). But it did work, and the code was nice and clean! Chris Angelico From bahamutzero8825 at gmail.com Sun May 22 10:35:58 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 22 May 2011 09:35:58 -0500 Subject: List of WindowsError error codes and meanings In-Reply-To: <8762p48eel.fsf@pobox.com> References: <8762p48eel.fsf@pobox.com> Message-ID: <4DD91F4E.3050206@gmail.com> On 2011.05.21 06:46 AM, John J Lee wrote: > Since Python 2.5, the errno attribute maps the Windows error to error > codes that match the attributes of module errno. I was able to whip up a nifty little function that takes the output of sys.exc_info() after a WindowsError and return the error code. I was mistaken in my earlier post about sys.exc_info()[1][0] - I hadn't noticed the 'WindowsError' bit before the opening parenthesis and mistook it for a tuple (it's a WindowsError object). Anyway: > def find_win_error_no(error_msg): > """ > error_msg is a string with the error message - typically > sys.exc_info()[1] from a WindowsError exception > Returns the number as a string, not an int > """ > win_error_re = re.compile('\[Error \d{1,5}\]') > win_error_num_re = re.compile('\d{1,5}') > win_error = win_error_re.findall(error_msg)[0] > return win_error_num_re.findall(win_error)[0] I call it here: > def make_prog_dir(dir): > try: > os.mkdir(dir) > except WindowsError: > error_info = str(sys.exc_info()[1]) > num = find_win_error_no(error_msg=error_info) > if num == '183': # Error 183 = 'Cannot create a file when that > file already exists' > logger.debug(dir + ' exists.') # Ignore the error, but > make a note > elif num == '5': # Error 5 = 'Access is denied' > logger.critical('Could not create', dir, '\(access denied\).') > else: > logger.critical('Could not create', dir, '-', error_info) Errors 183 and 5 are going to be the most common, but I'll look at the lists on MSDN to see if there's anything else worth adding (and familiarize myself with any more common errors). From felipe.vinturini at gmail.com Sun May 22 11:45:22 2011 From: felipe.vinturini at gmail.com (GMail Felipe) Date: Sun, 22 May 2011 12:45:22 -0300 Subject: how to get PID from subprocess library In-Reply-To: References: Message-ID: <70742457-7202-4DB7-B970-8E5568081521@gmail.com> On 22/05/2011, at 10:41, TheSaint wrote: > Kushal Kumaran wrote: > >> You could look for a way to make aria2c not become a daemon and use >> subprocess.Popen to start it. That gives you the PID and ways to see >> if the process is still running > > I see. It's a step that I've to get on my account. Unfortunately I'll have > to study it some more. > > BTW. I removed grep from the command. Python does it with the *in* statement > :) > > > -- > goto /dev/null > -- > http://mail.python.org/mailman/listinfo/python-list Hi, For the "ps" command, have you seen the psuti module? The link to it is: http://code.google.com/p/psutil/ Regards, Felipe. From jjl at pobox.com Sun May 22 11:58:09 2011 From: jjl at pobox.com (John J Lee) Date: Sun, 22 May 2011 16:58:09 +0100 Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: <87sjs6enhq.fsf@pobox.com> Daniel Kluev writes: > On Sun, May 22, 2011 at 2:49 AM, John J Lee wrote: >> Here's my wishlist (not really in any order): > > How come pony is not listed there? Language cannot be better than > python without pony! Pony, absolutely. I took that as read. >> ?* An even larger user base, contributing more and better free and >> ? commercial software. [...] > As there is rather heavy inertia in software development community, > expecting some language to acquire "even larger user base" is > hopeless. I did say I was prepared to compromise on that one. After all, when I started using Python it was a lot smaller that it is now. If a language is good enough to tempt me away from Python, probably the same is true for other people too -- as it was with Python a decade or so ago. > Also, most of these complaints could be solved by using correct python > dialect for particular task - RPython, Cython and so on. Different topic. John From jjl at pobox.com Sun May 22 13:11:17 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 17:11:17 +0000 (UTC) Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: Bill Allen gmail.com> writes: > You have ideas, a text editor, and a computer - best get to coding. > What's stopping you? You largely want Python, with modifications. > Join the development team and help implement those changes, or fork > your own flavor and do what you wish. Right? You imagine it's an > easy task, so get after it. [...] Is it possible that my calling it an easy task was a joke? Honestly, I'd thought it safe with that one to leave out the smiley -- but then I've been away from newsgroups for quite a while! John From jjl at pobox.com Sun May 22 13:33:29 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 17:33:29 +0000 (UTC) Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: Dan Stromberg gmail.com> writes: > On Sat, May 21, 2011 at 8:49 AM, John J Lee pobox.com> wrote: > > I still like Python after using it for over a decade, but there are > things I don't like. > What are your favourite up-and-coming languages of the moment? > Here's my wishlist (not really in any order): > ?* A widely used standard for (optional) interface declaration -- or > ? something better. ?I want it to be easier to know what interface an > ? object has when reading code, and which objects provide that > ? interface. > > > I do miss this sometimes, but pylint takes things far enough for me.? Pylint? Does it provide some kind of guessed-at-type that has been integrated with IDEs? [...] > And here I thought Python had pretty good functional programming facilities. > What do you miss?AFAIK, DBC in terms of "if condition: raise AssertionError" > (or assert).What _is_ the "etc"? [...more of the same...] You tell me: I'm here to fish for interesting pointers rather than to evangelize. I mention those specific things as examples because I know they have often been both the focus of research (well, perhaps not integration of queries), and pain points in software development. It's not plausible to me that there is not room for major improvement, but in any case the only way to know is to try. > ?* Better refactoring tools, better code analysis tools (lint, search, > ? etc.). > > I find pylint excellent.? My idea of a refactoring tool is vim's n.n.n.,? but have you looked at PyCharm?? In this thread, I'm asking about the views of Python programmers on languages other than Python. Thanks for the link, though (does PyCharm provide reliable refactoring tools that are useable from emacs?). > ?* An even larger user base, contributing more and better free and > ? commercial software. > > Gee, you want a scripting language with a larger userbase?? I don't want a scripting language, necessarily. John From jjl at pobox.com Sun May 22 13:55:04 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 17:55:04 +0000 (UTC) Subject: List of WindowsError error codes and meanings References: <8762p48eel.fsf@pobox.com> Message-ID: Genstein invalid.invalid> writes: > > > Andrew Berg gmail.com> writes: > > Since Python 2.5, the errno attribute maps the Windows error to error > > codes that match the attributes of module errno. > > Good point, I completely misread that. At least the Windows error code > is still available as the winerror attribute. > > As an aside - call me stupid, but I don't quite follow the purpose of > that errno mapping. Surely if the error number can be mapped > successfully then the error isn't Windows specific and an OSError should > logically be thrown instead? And if it can't be mapped successfully then > errno will never be valid so the mapping is pointless? Since WindowsError is a subclass of OSError, .errno has to be there (and it must contain the UNIXy error code). You could then ask why it's a subclass in the first place. I think part of the answer is that the docs are wrong -- presumably actual usage is that WindowsError is raised when a Windows API call is made that *may* result in an exception that has no corresponding errno value ("presumably" because I'm writing on Linux & sourceforge is too slow for me today to grab pywin32). In other words, code that raises WindowsError doesn't try to test the error code so that it can raise OSError instead some of the time. I don't think there would be any benefit in doing that, and it would have the disadvantage that with those calls, you'd have to deal with a mixture of Windows and UNIXy error codes. The presence of .errno, aside from being required (to satisfy LSP), does mean you don't have to deal with the Windows codes if you're only interested in cases covered by module errno. John From stefan_ml at behnel.de Sun May 22 13:55:25 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 22 May 2011 19:55:25 +0200 Subject: Abandoning Python In-Reply-To: <87sjs6enhq.fsf@pobox.com> References: <87ipt46okh.fsf@pobox.com> <87sjs6enhq.fsf@pobox.com> Message-ID: John J Lee, 22.05.2011 17:58: > Daniel Kluev writes: >> Also, most of these complaints could be solved by using correct python >> dialect for particular task - RPython, Cython and so on. > > Different topic. Why? Stefan From jjl at pobox.com Sun May 22 14:26:42 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 18:26:42 +0000 (UTC) Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> <87sjs6enhq.fsf@pobox.com> Message-ID: Stefan Behnel behnel.de> writes: > > John J Lee, 22.05.2011 17:58: > > Daniel Kluev writes: > >> Also, most of these complaints could be solved by using correct python > >> dialect for particular task - RPython, Cython and so on. > > > > Different topic. > > Why? The intended focus was "things other than Python". RPython and Cython are languages other than Python, but I regard them as part of the Python, er, ecosystem. They have advantages and drawbacks that a lot of us are already familiar with (even though in your position I imagine you notice the misconceptions more than the correct ones). The thought behind my question was to get Pythonista's opinions about things outside of that. John From patrick.just4fun at gmail.com Sun May 22 14:34:38 2011 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Sun, 22 May 2011 20:34:38 +0200 Subject: Dealing with name clashes in pypi Message-ID: <4DD9573E.8010509@gmail.com> I wanted to register my project (epdb) in pypi. Unfortunately there already exists a project with the same name. It is not possible for me to change the name of the project, because I used it in multiple writings. Any ideas how I can deal with the situation? Is it possible to register a project under a different name in pypi than the actual project name? -- Patrick From stef.mientki at gmail.com Sun May 22 15:23:03 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 22 May 2011 21:23:03 +0200 Subject: and becomes or and or becomes and Message-ID: <4DD96297.5010909@gmail.com> hello, must of us will not use single bits these days, but at first sight, this looks funny : >>> a=2 >>> b=6 >>> a and b 6 >>> a & b 2 >>> a or b 2 >>> a | b 6 cheers, Stef From e_d_k at yahoo.com Sun May 22 16:01:03 2011 From: e_d_k at yahoo.com (Ed Keith) Date: Sun, 22 May 2011 13:01:03 -0700 (PDT) Subject: Abandoning Python In-Reply-To: Message-ID: <595378.58400.qm@web120504.mail.ne1.yahoo.com> Have you looked at Falcon (http://www.falconpl.org/)? It seems to have a lot of what you are looking for. I do not have much experience with it but I like what I've seen so far, except that there are not any third party tools or libraries libraries. Which is where Python shines. -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From zdoor at xs4all.nl Sun May 22 16:13:07 2011 From: zdoor at xs4all.nl (Alex van der Spek) Date: Sun, 22 May 2011 22:13:07 +0200 Subject: Tkinter FileDialog Message-ID: <4dd96e57$0$49044$e4fe514c@news.xs4all.nl> Trying to bring up a simple File or Directory chooser using Tkinter. Right now I use pywin32 as Mark Hammond's extensions are somewhat more familiar to an (ex)VB programmer who started way back with Fortran. On Windows Vista with Python 2.7. The examples from Mark Lutz' book "Programming Python" do not immediately apply. The book describes Python 3.x only. This is what I do (in IDLE): import tkFileDialog as tk file2open=tk.Open().show() This works. But it also brings up a persistent Tk window. Killing this window forces a restart in IDLE, which is not desirable. There does not appear to be a way to multiselect files? I am probably missing a whole lot. Please point me to a simple example of GUI file manipulations. I can save myself with os.path.walk and os.listdir but the users I try to serve cannot. Regards, Alex van der Spek From xahlee at gmail.com Sun May 22 16:22:15 2011 From: xahlee at gmail.com (Xah Lee) Date: Sun, 22 May 2011 13:22:15 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> Xah wrote: ?In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it possibly mean by the word ?recursive? there? Like, it might delete the directory but not delete all files in it? ? Jonathan de Boyne Pollard wrote: > It might *try* to delete the directory but not any of its contents, > yes. you mean theoretically you see a possibility if the dir is implement as stilted as unix, but never in your life you find yourself might want to do it? Xah From drsalists at gmail.com Sun May 22 16:32:11 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 22 May 2011 13:32:11 -0700 Subject: Abandoning Python In-Reply-To: References: <87ipt46okh.fsf@pobox.com> Message-ID: On Sun, May 22, 2011 at 10:33 AM, John Lee wrote: > Dan Stromberg gmail.com> writes: > > > On Sat, May 21, 2011 at 8:49 AM, John J Lee pobox.com> wrote: > > > > I still like Python after using it for over a decade, but there are > > things I don't like. > > What are your favourite up-and-coming languages of the moment? > > Here's my wishlist (not really in any order): > > * A widely used standard for (optional) interface declaration -- or > > something better. I want it to be easier to know what interface an > > object has when reading code, and which objects provide that > > interface. > > > > > > I do miss this sometimes, but pylint takes things far enough for me. > > Pylint? Does it provide some kind of guessed-at-type that has been > integrated > with IDEs? > Pylint does type inferencing - I find it very valuable on large projects, and even some not-so-large projects. I doubt Pylint's been integrated into any IDE's, but ISTR that there's an IDE out there that has pyflakes in it. I suspect PyCharm does its own type stuff. I've heard (but not tried) that vim can have pyflakes integrated into it. For emacs, I really don't know. I'm more of a vim perrson, but I've considered switching to PyCharm by JetBrains - people in the Java world really seem to like what JetBrains did for Java, and PyCharm purportedly has vi keybindings, so I shouldn't end up typing way too many keystrokes for the same tasks. > > > * Better refactoring tools, better code analysis tools (lint, search, > > etc.). > > > > I find pylint excellent. My idea of a refactoring tool is vim's n.n.n., > but > have you looked at PyCharm? > > > In this thread, I'm asking about the views of Python programmers on > languages > other than Python. Thanks for the link, though (does PyCharm provide > reliable > refactoring tools that are useable from emacs?). > > I'm inclined to doubt that emacs can swallow PyCharm (or PyCharm be swallowed by emacs). But PyCharm probably has refactoring. For a bolt-on to vim or emacs, you might look at "Rope". -------------- next part -------------- An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sun May 22 16:41:34 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sun, 22 May 2011 22:41:34 +0200 Subject: checking if a list is empty In-Reply-To: References: <9hYwp.5805$xo2.3333@newsfe07.iad> <4dc4b351$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dca90c1$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 11.05.2011 23:02 schrieb Ian: > On 11/05/2011 20:13, Hans Georg Schaathun wrote: >> Lists do not have truth values in the >> application domain, and therefore truth values in the >> implementation domain is complicated. >> > Exactly. Its just a convention. If it exists, its true, if if doesn't > its false. Right. And not only that: Python objects resp. classes not claiming to have a truth value (__nonzero__), but a length (__len__) are judged by that concerning their truth value: iff the length is 0, their truth value is False. Thomas From jjl at pobox.com Sun May 22 17:01:00 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 21:01:00 +0000 (UTC) Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: Dan Stromberg gmail.com> writes: [...] > Pylint does type inferencing - I find it very valuable on large projects, and > even some not-so-large projects.I doubt Pylint's been integrated into any > IDE's, [...] That's interesting, thanks. I see this is a different pylint than the old logilab pylint. Unfortunate choice of name, since it makes it hard to find IDE integration work that's already done. > But PyCharm probably has refactoring.? For a bolt-on to vim or > emacs, you might look at "Rope". TBH, I'm not interested in Python refactoring tools until everybody starts shouting that they're reliable and useful (because it seems like a hard problem to solve, so I guess most implementations will be more trouble than they're worth). John From ladasky at my-deja.com Sun May 22 17:06:33 2011 From: ladasky at my-deja.com (John Ladasky) Date: Sun, 22 May 2011 14:06:33 -0700 (PDT) Subject: Multiprocessing: don't push the pedal to the metal? References: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> Message-ID: <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> Following up to my own post... Flickr informs me that quite a few of you have been looking at my graphs of performance vs. the number of sub-processes employed in a parallelizable task: On May 21, 8:58?pm, John Ladasky wrote: > http://www.flickr.com/photos/15579975 at N00/5744093219 [...] > I'll quickly ask my question first, to avoid a TL;DR problem: when you > have a multi-core CPU with N cores, is it common to see the > performance peak at N-1, or even N-2 processes? ?And so, should you > avoid using quite as many processes as there are cores? ?I was > expecting diminishing returns for each additional core -- but not > outright declines. But no one has offered any insight yet? Well, I slept on it, and I had a thought. Please feel free to shoot it down. If I spawn N worker sub-processes, my application in fact has N+1 processes in all, because there's also the master process itself. If the master process has anything significant to do (and mine does, and I would surmise that many multi-core applications would be that way), then the master process may sometimes find itself competing for time on a CPU core with a worker sub-process. This could impact performance even when the demands from the operating system and/or other applications are modest. I'd still appreciate hearing from anyone else who has more experience with multiprocessing. If there are general rules about how to do this best, I haven't seen them posted anywhere. This may not be a Python- specific issue, of course. Tag, you're it! From jjl at pobox.com Sun May 22 17:13:44 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 21:13:44 +0000 (UTC) Subject: Abandoning Python References: <595378.58400.qm@web120504.mail.ne1.yahoo.com> Message-ID: Ed Keith yahoo.com> writes: > > Have you looked at Falcon (http://www.falconpl.org/)? It seems to have a lot > of what you are looking for. I'm more interested in other people's opinions than my own "looking for"s. What *should* I be looking for (other than Python itself)? What's interesting, widely applicable, and new(ish)? Falcon fails my personal book-by-its-cover test. There are too many languages to do without that test, unfortunately. John From tjreedy at udel.edu Sun May 22 17:17:37 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 May 2011 17:17:37 -0400 Subject: TK program problem In-Reply-To: <42561028-39ce-4543-8e3c-b021e3a2b067@34g2000pru.googlegroups.com> References: <9f91909a-ce08-47dd-81d3-e7cf2edad3b6@h12g2000pro.googlegroups.com> <42561028-39ce-4543-8e3c-b021e3a2b067@34g2000pru.googlegroups.com> Message-ID: On 5/21/2011 10:20 PM, bvdp wrote: > >> One of the purposes and advantages of Python 3 is having only one class >> system. Best to always use new-style classes in Python 2.2+ unless you >> understand and need old-style classes (and need should be never for most >> people). >> > > Thanks for this. I'll keep it in mind! > > One thing I really don't understand ... is there a difference between > the old/new forms: > > class foo: > class foo(): > > In cases where I've played with them, they _appear_ to work the same? I believe they are. Same is true in 3.x except that the result in a new-style class. > Also, where does one find the magic that says that for a tkinter class > you should use: > > class foo(object): Perhaps nowhere. It may have been an unintended side-effect of the change in callable check, or intentional but not documented. > Not really sure where "object" comes from. It is the base class of all (new-style) classes. >>> object() -- Terry Jan Reedy From jjl at pobox.com Sun May 22 17:19:39 2011 From: jjl at pobox.com (John Lee) Date: Sun, 22 May 2011 21:19:39 +0000 (UTC) Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: John Lee pobox.com> writes: [...] > That's interesting, thanks. I see this is a different pylint than the old > logilab pylint. Unfortunate choice of name, since it makes it hard to find > IDE integration work that's already done. Hmm, I see the last release was in 2003 :-( John From tjreedy at udel.edu Sun May 22 17:23:59 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 May 2011 17:23:59 -0400 Subject: Dealing with name clashes in pypi In-Reply-To: <4DD9573E.8010509@gmail.com> References: <4DD9573E.8010509@gmail.com> Message-ID: On 5/22/2011 2:34 PM, Patrick Sabin wrote: > I wanted to register my project (epdb) in pypi. Unfortunately there > already exists a project with the same name. It is not possible for me > to change the name of the project, because I used it in multiple > writings. Any ideas how I can deal with the situation? Is it possible to > register a project under a different name in pypi than the actual > project name? I presume so. How would pypi know the 'actual' name? However, there is a catalog sig list (mirrored as gmane.comp.python.catalog) where you might get specific suggestions on how to handle this. -- Terry Jan Reedy From PointedEars at web.de Sun May 22 17:57:11 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 22 May 2011 23:57:11 +0200 Subject: and becomes or and or becomes and References: Message-ID: <2708393.dWV9SEqChM@PointedEars.de> Stef Mientki wrote: > must of us will not use single bits these days, > but at first sight, this looks funny : > >>>> a=2 >>>> b=6 >>>> a and b > 6 >>>> a & b > 2 >>>> a or b > 2 >>>> a | b > 6 Change the order of the operands and see what happens. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From tjreedy at udel.edu Sun May 22 18:01:56 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 May 2011 18:01:56 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <9CDC4B2CD1F445E994119A50F65155DF@teddy> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> Message-ID: On 5/22/2011 3:44 AM, Octavian Rasnita wrote: > I've noticed that on many Perl mailing lists the list members talk > very rarely about Python, Interesting. I learned about Python on comp.lang.perl, but that was over a decade ago. > but only on this Python mailing list I read > many discussions about Perl, in which most of the participants use to > agree that yes, Python is better, as it shouldn't be obvious that > most of the list members prefer Python. This list really has very little other-language bashing. > A few months ago I have asked how can I create a dictionary from a > list, and there were so many techniques that I think that it is just > a buzzword that in Perl there are many ways to do it, while in Python > there is a single way. In Python I found from the messages I received > on this mailing list that there are a lot of ways, without even > beeing a "recommended" way, while in Perl there is a single way, of > course much shorter and clearer. I forget the exact question you asked, but this list is not the doc. The doc section on dicts gives dict(list_of_key_value_pairs) as the one true way, given such an input. The Perl way cannot be clearer and can only be shorted if it uses something shorter that dict(). If the list is a flat list of alternating keys and values, then yes, they must be paired, and there are several ways to do that, partly depending on the exact specifications, including allowed input and how an odd key left over should be treated. In any case, unpaired keys and values strikes me as an unusual input format for a dict. They typically would have been paired as some point and in Python, should not need to be unpaired. -- Terry Jan Reedy From tjreedy at udel.edu Sun May 22 18:14:15 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 May 2011 18:14:15 -0400 Subject: and becomes or and or becomes and In-Reply-To: <2708393.dWV9SEqChM@PointedEars.de> References: <2708393.dWV9SEqChM@PointedEars.de> Message-ID: On 5/22/2011 5:57 PM, Thomas 'PointedEars' Lahn wrote: > Stef Mientki wrote: > >> must of us will not use single bits these days, >> but at first sight, this looks funny : >> >>>>> a=2 >>>>> b=6 >>>>> a and b >> 6 >>>>> a& b >> 2 >>>>> a or b >> 2 >>>>> a | b >> 6 > > Change the order of the operands and see what happens. or change a,b to 1,2 -- Terry Jan Reedy From timr at probo.com Sun May 22 18:39:33 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 22 May 2011 15:39:33 -0700 Subject: and becomes or and or becomes and References: Message-ID: Stef Mientki wrote: > >must of us will not use single bits these days, >but at first sight, this looks funny : > >>>> a=2 >>>> b=6 >>>> a and b >6 >>>> a & b >2 >>>> a or b >2 >>>> a | b >6 That IS funny. Interesting how a careful choice of arugments will fool us. One of my favorite math jokes is like that. A teacher asked a student to reduce the following fraction: 16 ---- 64 He says "all I have to do is cancel out the sixes, so the answer is 1/4". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From sunrrrise at gmail.com Sun May 22 18:43:53 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Sun, 22 May 2011 15:43:53 -0700 (PDT) Subject: Strange behaviour of input() function (Python 3.2) Message-ID: <1dc07caf-c938-42d0-8ba4-4fc9564af84e@glegroupsg2000goo.googlegroups.com> Hello, this is my first post. I'm trying to learn Python language which I find great, but I have a big problem with its editors/IDEs. I have tested IDLE (which installed with Python3 from ActiveState), Notepad++ and finally Komodo EDIT. I don't like IDLE GUI, but Notepad++ and Komodo EDIT looks nice for me. Unfortunatelly there is something wrong with input() command when I'm using Komodo or Notepad. For example this code: a = input("Wprowadz zmienna a: ") b = input("Wprowadz zmienna b: ") print("a to: ", a) print("b to: ", b) print(int(a) + int(b)) works well in IDLE, but when I'm switching to Notepad/Komodo I'm getting something like this: Wprowadz zmienna a: 3 Wprowadz zmienna b: 2 a to: 3 b to: Wprowadz zmienna b: 2 Traceback (most recent call last): File "c:\users\sunrrrise\Desktop\test.py", line 9, in print(int(a) + int(b)) ValueError: invalid literal for int() with base 10: 'Wprowadz zmienna b: 2' I don't know what is going on. Any ideas or, better, solutions? My OS: Windows 7 64bit, ActiveState Python 3.2, Notepad++ 5.9, Komodo Edit 6.1, coding: UTF-8 Regards, sunrrrise From rosuav at gmail.com Sun May 22 18:46:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 08:46:26 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 6:22 AM, Xah Lee wrote: > Xah wrote: > ?In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it > possibly mean by the word ?recursive? there? Like, it might delete the > directory but not delete all files in it? > ? > > Jonathan de Boyne Pollard wrote: >> It might *try* to delete the directory but not any of its contents, >> yes. > > you mean theoretically you see a possibility if the dir is implement > as stilted as unix, but never in your life you find yourself might > want to do it? There's a difference between working with a directory itself and working with files inside it. Generally, if you copy or delete a directory, you will want to recurse. But if you want to, for instance, wipe out all files whose names end with a tilde, then you might want to recurse and you might not. So it makes sense to offer the user a choice, and if recursive action is the only one that makes sense, at least acknowledge that the operation might take an arbitrarily long time. (Ever done a recursive operation on / on a large file system? Takes just a little bit longer than a non-recursive one under the same circumstances...) Chris Angelico From xahlee at gmail.com Sun May 22 18:47:53 2011 From: xahlee at gmail.com (Xah Lee) Date: Sun, 22 May 2011 15:47:53 -0700 (PDT) Subject: Functional Programing: stop using recursion, cons. Use map & vectors Message-ID: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> this is important but i think most lispers and functional programers still don't know it. Functional Programing: stop using recursion, cons. Use map & vectors. ?Guy Steele on Parallel Programing? http://xahlee.org/comp/Guy_Steele_parallel_computing.html btw, lists (as cons, car, cdr) in the lisp world has always been some kinda cult. Like, if you are showing some code example and you happened to use lisp vector datatype and not cons (lists) and it doesn't really matter in your case, but some lisper will always rise up to bug you, either as innocent curious question or attacking you for not ?understanding? lisp. (just as other idiocies happen in other lang that lispers see but other langs don't see) it's interesting to me that all other high level langs: Mathematica, perl, python, php, javascript, all don't have linked list as lisp's list. It's also curious that somehow lispers never realises this. I've been having problems with lisp's cons ever since i'm learning Scheme Lisp in 1998 (but mostly the reason is language design at syntax and lack of abstraction level in calling ?cons, car, cdr? stuff, without indexing mechanism). Realizing the algorithmic property and parallel- execution issues of linked list is only recent years. Xah From rosuav at gmail.com Sun May 22 18:49:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 08:49:17 +1000 Subject: Strange behaviour of input() function (Python 3.2) In-Reply-To: <1dc07caf-c938-42d0-8ba4-4fc9564af84e@glegroupsg2000goo.googlegroups.com> References: <1dc07caf-c938-42d0-8ba4-4fc9564af84e@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 8:43 AM, sunrrrise wrote: > Hello, > this is my first post. I'm trying to learn Python language which I find great, but I have a big problem with its editors/IDEs. Welcome! > b to: ?Wprowadz zmienna b: 2 This looks wrong. Are you copying and pasting several lines, or simply pressing the 2 key followed by Enter? It's showing a lengthy string in the variable 'b', which - quite correctly - cannot be cast to int. Chris Angelico From brendan.simon at etrix.com.au Sun May 22 18:58:55 2011 From: brendan.simon at etrix.com.au (Brendan Simon (eTRIX)) Date: Mon, 23 May 2011 08:58:55 +1000 Subject: Abandoning Python In-Reply-To: References: Message-ID: <4DD9952F.4080100@etrix.com.au> On 23/05/11 7:17 AM, python-list-request at python.org wrote: > Subject: > Re: Abandoning Python > From: > John Lee > Date: > Sun, 22 May 2011 21:13:44 +0000 (UTC) > > >> > >> > Have you looked at Falcon (http://www.falconpl.org/)? It seems to have a lot >> > of what you are looking for. > I'm more interested in other people's opinions than my own "looking for"s. > > What *should* I be looking for (other than Python itself)? What's interesting, > widely applicable, and new(ish)? > > Falcon fails my personal book-by-its-cover test. There are too many languages > to do without that test, unfortunately. Take a look at Cobra. http://cobra-language.com/docs/python/ http://cobra-language.com/ It is similar to Python, but with a quite a few nice extras and few improved things (eg. no "self", no ":", ...) Possible negatives are: * Requires either .NET or Mono frameworks. * lack of 3rd party libraries ?? Cheers, Brendan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sunrrrise at gmail.com Sun May 22 18:59:06 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Sun, 22 May 2011 15:59:06 -0700 (PDT) Subject: Odp: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: <724378fc-9848-406f-9b44-165132c49a56@glegroupsg2000goo.googlegroups.com> Thank you for quick response! English is not my native language so I'm going to keep my explanations simple. This really simple script asks me for two variables called "a" and "b". For example, I type "4" for "a" and "3" for "b" and IDLE gives me that: Wprowadz zmienna a: 4 Wprowadz zmienna b: 3 a to: 4 b to: 3 7 Works fine! But when I'm using Notepad (or Komodo) I get this: Wprowadz zmienna a: 4 Wprowadz zmienna b: 3 Traceback (most recent call last): File "c:\users\sunrrrise\Desktop\test.py", line 7, in print(int(a) + int(b)) ValueError: invalid literal for int() with base 10: 'Wprowadz zmienna b: 3' a to: 4 b to: Wprowadz zmienna b: 3 This is exactly the same script from the same file. I really don't get it. From sunrrrise at gmail.com Sun May 22 18:59:06 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Sun, 22 May 2011 15:59:06 -0700 (PDT) Subject: Odp: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: <724378fc-9848-406f-9b44-165132c49a56@glegroupsg2000goo.googlegroups.com> Thank you for quick response! English is not my native language so I'm going to keep my explanations simple. This really simple script asks me for two variables called "a" and "b". For example, I type "4" for "a" and "3" for "b" and IDLE gives me that: Wprowadz zmienna a: 4 Wprowadz zmienna b: 3 a to: 4 b to: 3 7 Works fine! But when I'm using Notepad (or Komodo) I get this: Wprowadz zmienna a: 4 Wprowadz zmienna b: 3 Traceback (most recent call last): File "c:\users\sunrrrise\Desktop\test.py", line 7, in print(int(a) + int(b)) ValueError: invalid literal for int() with base 10: 'Wprowadz zmienna b: 3' a to: 4 b to: Wprowadz zmienna b: 3 This is exactly the same script from the same file. I really don't get it. From dan.kluev at gmail.com Sun May 22 19:16:46 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 10:16:46 +1100 Subject: Abandoning Python In-Reply-To: References: <87ipt46okh.fsf@pobox.com> Message-ID: On Mon, May 23, 2011 at 4:33 AM, John Lee wrote: > Pylint? ?Does it provide some kind of guessed-at-type that has been integrated > with IDEs? WingIDE Pro has both Pylint integration and advanced type-guessing. -- With best regards, Daniel Kluev From xahlee at gmail.com Sun May 22 19:17:52 2011 From: xahlee at gmail.com (Xah Lee) Date: Sun, 22 May 2011 16:17:52 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> Message-ID: <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> On May 22, 3:46?pm, Chris Angelico wrote: > On Mon, May 23, 2011 at 6:22 AM, Xah Lee wrote: > > Xah wrote: > > ?In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it > > possibly mean by the word ?recursive? there? Like, it might delete the > > directory but not delete all files in it? > > ? > > > Jonathan de Boyne Pollard wrote: > >> It might *try* to delete the directory but not any of its contents, > >> yes. > > > you mean theoretically you see a possibility if the dir is implement > > as stilted as unix, but never in your life you find yourself might > > want to do it? > > There's a difference between working with a directory itself and > working with files inside it. Generally, if you copy or delete a > directory, you will want to recurse. But if you want to, for instance, > wipe out all files whose names end with a tilde, then you might want > to recurse and you might not. So it makes sense to offer the user a > choice, and if recursive action is the only one that makes sense, at > least acknowledge that the operation might take an arbitrarily long > time. (Ever done a recursive operation on / on a large file system? > Takes just a little bit longer than a non-recursive one under the same > circumstances...) the context is this: In emacs directory manager (aka dired), when you call dired-do-delete on a directory, emacs prompts, this way: ?Recursive delete of xx? (y or n)? Xah From rosuav at gmail.com Sun May 22 19:21:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 09:21:28 +1000 Subject: Strange behaviour of input() function (Python 3.2) In-Reply-To: <724378fc-9848-406f-9b44-165132c49a56@glegroupsg2000goo.googlegroups.com> References: <724378fc-9848-406f-9b44-165132c49a56@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 8:59 AM, sunrrrise wrote: > Thank you for quick response! > > English is not my native language so I'm going to keep my explanations simple. No problem, your English is far better than my Polish. (I used Google Translate to figure out what "Wprowadz zmienna" means.) I tried copying and pasting your exact code, even down to using Notepad, but it worked fine. The interpreter I used was a freshly-downloaded Python 3.2, listing itself as r32:88445 dated Feb 20 2011, 21:29:03. This may be a really specific bug. Can you email me the actual Python file you're having problems with, please? Off-list, as this list doesn't like attachments. I'll try running it on my system and see if it's any different. Chris Angelico From rosuav at gmail.com Sun May 22 19:28:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 09:28:40 +1000 Subject: and becomes or and or becomes and In-Reply-To: References: Message-ID: On Mon, May 23, 2011 at 8:39 AM, Tim Roberts wrote: > That IS funny. ?Interesting how a careful choice of arugments will fool us. > One of my favorite math jokes is like that. ?A teacher asked a student to > reduce the following fraction: > ?16 > ?---- > ?64 > > He says "all I have to do is cancel out the sixes, so the answer is 1/4". I like. :) But in the OP, the difference between "and" and "&", or "or" and "|", is subtle yet absolute. They are completely different operators. The bitwise operators function like the arithmetic operators - evaluate both operands, then do something that combines them into one value. The logical operators, though, are more like the if statement: q = a and b is similar to: if a: q = a else: q = b (Pedants, please note that I said "similar" not "equivalent".) They happen to do similar things, but they're completely different in operation. I do like the humour value from the careful selection of operands though! Chris Angelico From rosuav at gmail.com Sun May 22 19:32:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 09:32:27 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 9:17 AM, Xah Lee wrote: > the context is this: In emacs directory manager (aka dired), when you > call dired-do-delete on a directory, emacs prompts, this way: > ?Recursive delete of xx? (y or n)? But in order to make your point (such as it is), you are ignoring the fact that there are other uses of the term 'recurse' or 'recursive', and consistency and clarity are important. I don't see emacs offering me a chance to do a non-recursive delete; the only issue here seems to be that it's explicit that it is going to destroy an entire branch of the directory tree. If this is such a problem, grab the emacs sources and change that string - it probably occurs in exactly one place in the code. Voila! You now have The One True Perfect Emacs, the ultimate text editor, because it no longer tells you that it's working recursively. *removes tongue from cheek after saying that last sentence* Chris Angelico From dan.kluev at gmail.com Sun May 22 19:42:50 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 10:42:50 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <12225671E9654FECB49613D915FAEC19@teddy> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> Message-ID: On Sun, May 22, 2011 at 11:47 PM, Octavian Rasnita wrote: > From: "Daniel Kluev" > I am talking about that flexibility which was criticized in the previous messages telling that this flexibility allows any programmer to use his own way. > Perl doesn't force anyone to indent the code, don't force the programmer to define a hash element before using it, allow the programmer to interpret the variables in strings directly. These things should be not used always, but if in some cases if the programmer wants to use them, he can use them with no problems. And this means flexibility. This is syntax-level flexibility, which, IMHO, does not affect 'advanceness' of modules at all. At language level, python is far more flexible than perl with its magic methods and hooks, allowing to overload any underlying language principles and protocols. > First, this is a bad style of mapping urls, because this list must be maintained every time the programmer changes something in a controller that makes the app need to use other urls. Explicit is better than implicit. One of reasons why I chose Pylons/Pyramid as my standard toolkit is that it allowed me to define mappers in any way I needed them to. If you want automatically defined mappers, there are lots of other python frameworks and modules which do exactly that. Moreover, even Routes itself (module, which does url mapping in Pylons) allows you to use automated mappers, via :controller/:action tokens. It allows pretty much everything you listed as 'features' of catalyst mappings. If you prefer to stuff routing logic into controllers and have default routing based on controllers and method names, you can use TurboGears framework, which has exactly that mindset, or you can use its mapping modules in Pyramid application. > The module DBIx::Class which is used usually as an ORM can create the class files for all the tables from a database (MySQL, Oracle, PostgreSQL, SQLite, MS SQL, etc), and it can be used to search using unions, sub-selects, can define views at ORM level, can accept to insert different types of objects like DateTime objects and can also return those type of objects, and many other things, and most of the things it can do can be done without using SQL code at all, but only standard Perl code and Perl data structures. There are lots of Python modules which do exactly this and much more. SQLAlchemy, SQLObject, Web2Py's DAL, and so on. They are integrated into frameworks by default. > HTML::FormFu form processor is one of the most used form processors in Catalyst applications and it can generate and parse forms created directly in the code of the application, or as external configuration files defined using JSON, or YAML, or Apache configuration style, or Perl data structures, or XML... > The forms defined are very easy to create and the elements from those forms, for example the list of elements in a combo box can be taken directly from a database by specifying just a few configuration elements. The results of a form submit can be also inserted in a database using a connector with DBIx::Class without specifying any database table column name in the programming code, and for doing this are required just a few lines of code that checks if the $form->submitted_and_valid() and that does the redirection after the submit, the insertion in the database requiring just: Once again, there are dozens of such modules in python. FormAlchemy integrates directly with SQLAlchemy, for example, and does all form generation, parsing, validation, and instance updating/inserting for you. > Yes, for web apps I have seen more things which can be done much better in Perl, much easier and clear, with less code, and not because the programmer needs to do not-recommended tricks for shortening the code, but because there are very many modules on CPAN that do the hard work. I doubt you had enough experience with python frameworks like Pyramid/Pylons or Web2Py. They have all features you listed, and code is as trivial and clean, as it could ever be. Its surprising that you present trivial ORM as 'advanced modules and libraries which are not available for Python', while in fact it have been done long time ago and in several flavors. -- With best regards, Daniel Kluev From john at castleamber.com Sun May 22 19:55:11 2011 From: john at castleamber.com (John Bokma) Date: Sun, 22 May 2011 18:55:11 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> Message-ID: <877h9i5m00.fsf@castleamber.com> Terry Reedy writes: > I forget the exact question you asked, but this list is not the > doc. The doc section on dicts gives dict(list_of_key_value_pairs) as > the one true way, given such an input. The Perl way cannot be clearer > and can only be shorted if it uses something shorter that dict(). my %hash = @list_of_key_value_pairs; -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From steve+comp.lang.python at pearwood.info Sun May 22 20:30:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 May 2011 00:30:37 GMT Subject: and becomes or and or becomes and References: Message-ID: <4dd9aaac$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 22 May 2011 15:39:33 -0700, Tim Roberts wrote: > Stef Mientki wrote: >> >>must of us will not use single bits these days, but at first sight, this >>looks funny : >> >>>>> a=2 >>>>> b=6 >>>>> a and b >>6 >>>>> a & b >>2 >>>>> a or b >>2 >>>>> a | b >>6 > > That IS funny. Interesting how a careful choice of arugments will fool > us. One of my favorite math jokes is like that. A teacher asked a > student to reduce the following fraction: > 16 > ---- > 64 > > He says "all I have to do is cancel out the sixes, so the answer is > 1/4". One of my favourite variations on this is by Abbott and Costello, where Costello proves that 13*7 = 28 in three different ways. http://www.youtube.com/watch?v=rLprXHbn19I -- Steven From rosuav at gmail.com Sun May 22 20:32:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 10:32:32 +1000 Subject: Multiprocessing: don't push the pedal to the metal? In-Reply-To: <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> References: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 7:06 AM, John Ladasky wrote: > If I spawn N worker sub-processes, my application in fact has N+1 > processes in all, because there's also the master process itself. This would definitely be correct. How much impact the master process has depends on how much it's doing. > I'd still appreciate hearing from anyone else who has more experience > with multiprocessing. ?If there are general rules about how to do this > best, I haven't seen them posted anywhere. ?This may not be a Python- > specific issue, of course. I don't have much experience with Python's multiprocessing model, but I've done concurrent programming on a variety of platforms, and there are some common issues. Each CPU (or core) has its own execution cache. If you can keep one thread running on the same core all the time, it will benefit more from that cache than if it has to keep flitting from one to another. You undoubtedly will have other processes in the system, too. As well as your master, there'll be processes over which you have no control (unless you're on a bare-bones system). Some of them may preempt your processes. Leaving one CPU/core available for "everything else" may allow the OS to keep each thread on its own core. Having as many workers as cores means that every time there's something else to do, one of your workers has to be kicked off its nice warm CPU and sent out into the cold for a while. If all your workers are at the same priority, it will then grab a timeslice off one of the other cores, kicking its incumbent off... rinse and repeat. This is a tradeoff, though. If the rest of your system is going to use 0.01 of a core, then 1% thrashing is worth having one more core available 99% of the time. If the numbers are reversed, it's equally obvious that you should leave one core available. In your case, it's probably turning out that the contention causes more overhead than the extra worker is worth. That's just some general concepts, without an in-depth analysis of your code and your entire system. It's probably easier to analyse by results rather than inspection. Chris Angelico From greg.ewing at canterbury.ac.nz Sun May 22 21:11:40 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 23 May 2011 13:11:40 +1200 Subject: Abandoning Python In-Reply-To: References: Message-ID: <93tqifFnb2U1@mid.individual.net> Ed Keith wrote: > Have you looked at Falcon (http://www.falconpl.org/)? This paragraph on the first page doesn't exactly fire me with enthuiasm: > Falcon provides six integrated programming paradigms: procedural, object > oriented, prototype oriented, functional, tabular and message oriented. And you > don't have to master all of them; ...until you want to read someone *else's* code, that is. -- Greg From cjns1989 at gmail.com Sun May 22 21:32:06 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Sun, 22 May 2011 21:32:06 -0400 Subject: No subject Message-ID: <20110523013206.GA17789@pavo.local> From cjns1989 at gmail.com Sun May 22 21:32:09 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Sun, 22 May 2011 21:32:09 -0400 Subject: No subject Message-ID: <20110523013209.GA17846@pavo.local> From d.awlberg at hotmail.invalid Sun May 22 22:29:26 2011 From: d.awlberg at hotmail.invalid (Deeyana) Date: Mon, 23 May 2011 02:29:26 +0000 (UTC) Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On Sun, 22 May 2011 15:47:53 -0700, Xah Lee wrote: > this is important but i think most lispers and functional programers > still don't know it. > > Functional Programing: stop using recursion, cons. Use map & vectors. > > ?Guy Steele on Parallel Programing? > http://xahlee.org/comp/Guy_Steele_parallel_computing.html > > btw, lists (as cons, car, cdr) in the lisp world has always been some > kinda cult. Like, if you are showing some code example and you happened > to use lisp vector datatype and not cons (lists) and it doesn't really > matter in your case, but some lisper will always rise up to bug you, > either as innocent curious question or attacking you for not > ?understanding? lisp. (just as other idiocies happen in other lang that > lispers see but other langs don't see) > > it's interesting to me that all other high level langs: Mathematica, > perl, python, php, javascript, all don't have linked list as lisp's > list. It's also curious that somehow lispers never realises this. I've > been having problems with lisp's cons ever since i'm learning Scheme > Lisp in 1998 (but mostly the reason is language design at syntax and > lack of abstraction level in calling ?cons, car, cdr? stuff, without > indexing mechanism). Realizing the algorithmic property and parallel- > execution issues of linked list is only recent years. You might be interested in Clojure, then. Lists are more abstracted, like in Scheme, and vectors and also dictionaries/maps and sets are first class citizens along side lists. And unlike Scheme, Clojure has good library/host interop support. You can write real-world applications in it without spontaneously combusting. From shunichi_wakabayashi at yahoo.co.jp Sun May 22 22:48:13 2011 From: shunichi_wakabayashi at yahoo.co.jp (Shunichi Wakabayashi) Date: Sun, 22 May 2011 19:48:13 -0700 (PDT) Subject: Writing multiple files with with-context Message-ID: <5142852e-bab9-4e39-a49b-0229e900e97d@glegroupsg2000goo.googlegroups.com> To write onto multiple files on the same time (a number of files are variable), I'd like to code as follows, for example, IF I can do, LIST_LEN = 4 with [ open('list_%d.txt' % i, 'w') for i in range(LIST_LEN) ] as fobjlist: for i in range(1000): fobjlist[random.randrange(LIST_LEN)].write(str(i)+"\n") or using a dict object, DICT_KEYS = ('foo', 'bar', 'baz') with { k: open('dict_%s.txt' % k, 'w') for k in DICT_KEYS } as fobjdict: for i in range(1000): fobjdict[random.choice(DICT_KEYS)].write(str(i)+"\n") However, list and dict don't has __exit__ method and so they cannot run. One idea is using contextlib.nested(), from contextlib import nested with nested(*[open('list_%d.txt' % i, 'w') for i in range(LIST_LEN)]) as fobjlist: for i in range(1000): fobjlist[random.randrange(LIST_LEN)].write(str(i)+"\n") with nested(*[open('dict_%s.txt' % k, 'w') for k in DICT_KEYS]) as fobjlist: fobjdict = dict(zip(DICT_KEYS, fobjlist)) #convert list to dict for i in range(1000): fobjdict[random.choice(DICT_KEYS)].write(str(i)+"\n") On Python2.x, this is OK. but 3.x warns that nested() is deprecated. Moreover, on using dict, it is required to convert list to dict. Another idea is to make container classes having __exit__() myself. class MyList(list): def __enter__(self): return [ v.__enter__() for v in self ] def __exit__(self, exc_type, exc_value, traceback): ret = False for v in self: if v.__exit__(exc_type, exc_value, traceback): ret = True exc_type = exc_value = traceback = None return ret class MyDict(dict): def __enter__(self): return { k: v.__enter__() for k, v in self.items() } def __exit__(self, exc_type, exc_value, traceback): ret = False for v in self.values(): if v.__exit__(exc_type, exc_value, traceback): ret = True exc_type = exc_value = traceback = None return ret with MyList( open('list_%d.txt' % i, 'w') for i in range(LIST_LEN) ) as fobjlist: for i in range(1000): fobjlist[random.randrange(LIST_LEN)].write(str(i)+"\n") with MyDict( (k, open('dict_%s.txt' % k, 'w')) for k in DICT_KEYS ) as fobjdict: for i in range(1000): fobjdict[random.choice(DICT_KEYS)].write(str(i)+"\n") I think this is smarter a little than others, but it cannot guaranteed to call __exit__() of members in containers if members are changed during with-context. So, do you have another, more smart and pythonic way? Thanks From rosuav at gmail.com Sun May 22 23:01:19 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 13:01:19 +1000 Subject: Building Python: static library "3.2m" Message-ID: Hi! Just a quickie, I hope, where someone will probably be able to answer off the top of his head. I downloaded the 3.2 sources with the intention of building that instead of using Ubuntu's default Python 2.6.6. Ran ./configure, make, sudo make install, and then fiddled with a few things like make all, make libinstall, make libainstall. Eventually got a libpython3.2m.a in /usr/local/lib. Question: Why "3.2m"? What does that m mean? It seems to have come up a couple of times in the build process. Thanks in advance! Chris Angelico From nad at acm.org Mon May 23 00:01:27 2011 From: nad at acm.org (Ned Deily) Date: Sun, 22 May 2011 21:01:27 -0700 Subject: Building Python: static library "3.2m" References: Message-ID: In article , Chris Angelico wrote: > Question: Why "3.2m"? What does that m mean? It seems to have come up > a couple of times in the build process. It's a new feature in Python 3.2 to allow multiple versions of shared C object files that differ in configure options (i.e. ones that affect the Python C ABI) to co-exist in one Python installation. "m" means that they were built with pymalloc. Other flags are "d" for debug, and "u" for wide-unicode. http://docs.python.org/py3k/whatsnew/3.2.html#pep-3149-abi-version-tagged -so-files -- Ned Deily, nad at acm.org From rosuav at gmail.com Mon May 23 00:08:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 14:08:53 +1000 Subject: Building Python: static library "3.2m" In-Reply-To: References: Message-ID: On Mon, May 23, 2011 at 2:01 PM, Ned Deily wrote: > It's a new feature in Python 3.2 to allow multiple versions of shared C > object files that differ in configure options (i.e. ones that affect the > Python C ABI) to co-exist in one Python installation. ?"m" means that > they were built with pymalloc. ?Other flags are "d" for debug, and "u" > for wide-unicode. Ahh, thank you! I was planning to just statically link to my executable to reduce deployment effort, but either way works. Currently I'm puzzling over an inordinate number of symbol-not-found errors, even though it does seem to be finding the header files. It's weird. Chris Angelico From rosuav at gmail.com Mon May 23 00:32:11 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 14:32:11 +1000 Subject: Building Python: static library "3.2m" In-Reply-To: References: Message-ID: On Mon, May 23, 2011 at 2:08 PM, Chris Angelico wrote: > Currently I'm puzzling over an inordinate number of symbol-not-found > errors, even though it does seem to be finding the header files. It's > weird. And.... I think I've just figured out why. PyString_* functions are no longer supported - it's all PyUnicode now. Yes, I really am capable of forgetting basics like that! Chris Angelico From orasnita at gmail.com Mon May 23 01:31:06 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 08:31:06 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> Message-ID: <21A740B7AC6644248476DFADDF726C73@octavian> From: "Dennis Lee Bieber" >Since indentation seems so crucial to easy comprehension of the logical >structure of a program, > making it a mandatory syntactical structure becomes a desirable feature > for code that must be maintained (by others, in many cases). Why "in many cases"? I wrote hundreads of programs which are working fine and which are maintained only by me. (But they would be very easy to maintain by other people if it would be necessary). So in that case, why to be forced to use a strict indentation? > As for the dictionary from list... Do not confuse /algorithms/ > selected by the programmer from what is part of the native language. > Otherwise one could complain that there is more than one way to code a > spam-filter using Python... Exactly, I am not talking about a complex task that can be done in many ways in all programming languages. I am talking about a simple way of creating a hash/dict from an array, which is so simple that there should be really a single way to do it, or very few. Octavian From orasnita at gmail.com Mon May 23 02:06:16 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 09:06:16 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> Message-ID: <2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> From: "Daniel Kluev" > On Sun, May 22, 2011 at 11:47 PM, Octavian Rasnita > wrote: >> From: "Daniel Kluev" >> I am talking about that flexibility which was criticized in the previous >> messages telling that this flexibility allows any programmer to use his >> own way. >> Perl doesn't force anyone to indent the code, don't force the programmer >> to define a hash element before using it, allow the programmer to >> interpret the variables in strings directly. These things should be not >> used always, but if in some cases if the programmer wants to use them, he >> can use them with no problems. And this means flexibility. > > This is syntax-level flexibility, which, IMHO, does not affect > 'advanceness' of modules at all. At language level, python is far more > flexible than perl with its magic methods and hooks, allowing to > overload any underlying language principles and protocols. This means that you are forgetting Moose objects in Perl, right? Moose is a very advanced object type system that will be the default type in Perl 6, but which was also implemented in Perl 5, which offers a lot of features for introspections in the object structure. And the flexibility do offer the possibility of coding much easier and offering more features. There are more, but a single eloquent feature is the possibility of interpreting variables in strings which cannot be done so nice in Python. >> First, this is a bad style of mapping urls, because this list must be >> maintained every time the programmer changes something in a controller >> that makes the app need to use other urls. > > Explicit is better than implicit. This is false. Explicit in this case means to write code in 2 places for doing a certain thing, and maintaining means changing the code in 2 places, which is harder and prone to errors. > One of reasons why I chose Pylons/Pyramid as my standard toolkit is that > it allowed me to define > mappers in any way I needed them to. In Catalyst you can also define the url mappings in any way you need, not only based on controller/actions locations, but you don't need to do this by creating code in 2 places so it would be easier to maintain. In Catalyst all the mappers are done "automaticly", but they can be done in any way you like, even in more ways that under Pylons/Pyramid as I shown (unless in Pylons/Pyramid can be also defined chained mappings and mappings based on regular expressions). > > If you want automatically defined mappers, there are lots of other > python frameworks and modules which do exactly that. Moreover, even > Routes itself (module, which does url mapping in Pylons) allows you to > use automated mappers, via :controller/:action tokens. It allows > pretty much everything you listed as 'features' of catalyst mappings. > If you prefer to stuff routing logic into controllers and have default > routing based on controllers and method names, you can use TurboGears > framework, which has exactly that mindset, or you can use its mapping > modules in Pyramid application. Yes, the single difference is that Catalyst supports all of them, and it also supports using any templating system, and any ORM and any form processor, while some of the Python web frameworks don't support absolutely everything and you need to abandon some preferred modules for beeing able to use some other modules which are supported. >> The module DBIx::Class which is used usually as an ORM can create the >> class files for all the tables from a database (MySQL, Oracle, >> PostgreSQL, SQLite, MS SQL, etc), and it can be used to search using >> unions, sub-selects, can define views at ORM level, can accept to insert >> different types of objects like DateTime objects and can also return >> those type of objects, and many other things, and most of the things it >> can do can be done without using SQL code at all, but only standard Perl >> code and Perl data structures. > > There are lots of Python modules which do exactly this and much more. > SQLAlchemy, SQLObject, Web2Py's DAL, and so on. They are integrated > into frameworks by default. I've checked the documentation for some of them and I've seen that most of them don't support sub-selects and some of them require using plain SQL code in their construct for more complex queries. Please tell me which of them supports sub-selects, and are able to return objects for date and datetime fields that have methods for beeing able to print just the year or day, or the months names in the specified locale because it would be useful. >> Yes, for web apps I have seen more things which can be done much better >> in Perl, much easier and clear, with less code, and not because the >> programmer needs to do not-recommended tricks for shortening the code, >> but because there are very many modules on CPAN that do the hard work. > > I doubt you had enough experience with python frameworks like > Pyramid/Pylons or Web2Py. They have all features you listed, and code > is as trivial and clean, as it could ever be. Its surprising that you > present trivial ORM as 'advanced modules and libraries which are not > available for Python', while in fact it have been done long time ago > and in several flavors. Please tell me which of those ORMS can do what DBIx::Class can do as I asked above, before calling it "trivial", and which are those aditional features it can do but DBIx::Class cannot, because otherwise it would be very simple for anyone to just say "go to read the documentation and see how great it is". Octavian From godson.g at gmail.com Mon May 23 02:32:17 2011 From: godson.g at gmail.com (Godson Gera) Date: Mon, 23 May 2011 12:02:17 +0530 Subject: Tkinter FileDialog In-Reply-To: <4dd96e57$0$49044$e4fe514c@news.xs4all.nl> References: <4dd96e57$0$49044$e4fe514c@news.xs4all.nl> Message-ID: Hi, You can try the following from Tkinter import* root = Tk() root.withdraw() #this will hide the main window import tkFileDialog as tkf f = tkf.Open().show() tkFileDialog, requires a main window to be existing before it can show the file dialog. If there are no main windows then it will create its own. On Mon, May 23, 2011 at 1:43 AM, Alex van der Spek wrote: > Trying to bring up a simple File or Directory chooser using Tkinter. Right > now I use pywin32 as Mark Hammond's extensions are somewhat more familiar > to an (ex)VB programmer who started way back with Fortran. > > On Windows Vista with Python 2.7. The examples from Mark Lutz' book > "Programming Python" do not immediately apply. The book describes Python 3.x > only. > > This is what I do (in IDLE): > > import tkFileDialog as tk > file2open=tk.Open().show() > > This works. But it also brings up a persistent Tk window. Killing this > window forces a restart in IDLE, which is not desirable. There does not > appear to be a way to multiselect files? > > I am probably missing a whole lot. Please point me to a simple example of > GUI file manipulations. I can save myself with os.path.walk and os.listdir > but the users I try to serve cannot. > > Regards, > Alex van der Spek > -- > http://mail.python.org/mailman/listinfo/python-list > -- Thanks & Regards, Godson Gera FreeSWITCH & Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon May 23 02:33:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 May 2011 06:33:37 GMT Subject: Abandoning Python References: <93tqifFnb2U1@mid.individual.net> Message-ID: <4dd9ffc1$0$29988$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 May 2011 13:11:40 +1200, Gregory Ewing wrote: > Ed Keith wrote: >> Have you looked at Falcon (http://www.falconpl.org/)? > > This paragraph on the first page doesn't exactly fire me with enthuiasm: > >> Falcon provides six integrated programming paradigms: procedural, >> object oriented, prototype oriented, functional, tabular and message >> oriented. And you don't have to master all of them; > > ...until you want to read someone *else's* code, that is. The same might be said about Python, which supports procedural, OO and functional styles out of the box. Prototype-oriented is so close to OO that you can fake it in Python: http://stackoverflow.com/questions/4629224/prototypal-programming-in-python I'm not sure what they mean by tabular, perhaps something like Resolver System's Python-in-a-spreadsheet? http://www.resolversystems.com/products/resolver-one/ And presumably anyone who has played around with GUI programming in Python will have run into message oriented coding. -- Steven From rosuav at gmail.com Mon May 23 02:37:10 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 16:37:10 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <21A740B7AC6644248476DFADDF726C73@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> Message-ID: On Mon, May 23, 2011 at 3:31 PM, Octavian Rasnita wrote: > From: "Dennis Lee Bieber" >> >> Since indentation seems so crucial to easy comprehension of the logical >> structure of a program, >> making it a mandatory syntactical structure becomes a desirable feature >> for code that must be maintained (by others, in many cases). > > Why "in many cases"? I wrote hundreads of programs which are working fine > and which are maintained only by me. (But they would be very easy to > maintain by other people if it would be necessary). > So in that case, why to be forced to use a strict indentation? The reason for clear code is maintenance, not maintenance-by-others. If you come back to something in a year, you'll appreciate proper variable names, indentation, etc. That said, though, I still do not believe in Python's philosophy of significant whitespace. I like to be able, if I choose, to put one entire "logical unit" on one line, such that it can be commented out with a single comment marker, or duplicated to another line and one copy commented out, or whatever. To that end, I sometimes want to put an if, its associated else, and sometimes a statement for both branches, all in the one line. And that's not possible when whitespace alone defines the end of an if/else block (the one-line form of a Python 'if' can't have a non-conditional statement after it at all), but is quite easy when things are delimited with braces. Bug report: The "from __future__ import braces" statement isn't working properly. Pls fix, kthxbye. :) But I still like Python overall. There's no such thing as a perfect language, and when it comes to syntax disagreements, I dislike Python's significant whitespace far less than I dislike PHP's adorned variable names. And Python, under the hood, is a very good engine for doing what I need to do. Chris Angelico From tjreedy at udel.edu Mon May 23 02:37:45 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 May 2011 02:37:45 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <21A740B7AC6644248476DFADDF726C73@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> Message-ID: On 5/23/2011 1:31 AM, Octavian Rasnita wrote: > I am talking about a simple way of creating a hash/dict from an array, > which is so simple that there should be really a single way to do it, or > very few. Again, Python has such: >>> dict([['one',1],['two', 2]]) {'two': 2, 'one': 1} -- Terry Jan Reedy From pavlovevidence at gmail.com Mon May 23 02:46:48 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 22 May 2011 23:46:48 -0700 (PDT) Subject: Why did Quora choose Python for its development? In-Reply-To: Message-ID: <47fd1b4b-ef7a-4f8c-95be-44e7a93ffacc@glegroupsg2000goo.googlegroups.com> On Sunday, May 22, 2011 12:44:18 AM UTC-7, Octavian Rasnita wrote: > I've noticed that on many Perl mailing lists the list members talk very > rarely about Python, but only on this Python mailing list I read many > discussions about Perl, in which most of the participants use to agree that > yes, Python is better, as it shouldn't be obvious that most of the list > members prefer Python. Evidently Perl users choose to bash other languages in those languages' own mailing lists. > If Python would be so great, you wouldn't talk so much about how bad are > other languages, Sure we would. Sometimes it's fun to sit on your lofty throne and scoff at the peasantry. > or if these discussions are not initiated by envy, you would > be also talking about how bad is Visual Basic, or Pascal, or Delphi, or who > knows other languages. I would suggest that envy isn't the reason, the reason is that Perl is just that much worse than Visual Basic, Pascal, and Delphi. We only make fun of the really, really bad langauges. (Or, less cynically, it's because Perl and Python historically filled the same niche, whereas VB, Pascal, and Delphi were often used for different sorts of programming.) What I'm trying to say here is your logic is invalid. People have all kinds of reasons to badmouth other languages; that some mailing list has a culture that is a bit more or a bit less approving of it than some other list tells us nothing. In any case it's ridiculous to claim envy as factor nowadays, as Python is clearly on the rise while Perl is on the decline. Few people are choosing Perl for new projects. Carl Banks From pavlovevidence at gmail.com Mon May 23 02:46:48 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 22 May 2011 23:46:48 -0700 (PDT) Subject: Why did Quora choose Python for its development? In-Reply-To: Message-ID: <47fd1b4b-ef7a-4f8c-95be-44e7a93ffacc@glegroupsg2000goo.googlegroups.com> On Sunday, May 22, 2011 12:44:18 AM UTC-7, Octavian Rasnita wrote: > I've noticed that on many Perl mailing lists the list members talk very > rarely about Python, but only on this Python mailing list I read many > discussions about Perl, in which most of the participants use to agree that > yes, Python is better, as it shouldn't be obvious that most of the list > members prefer Python. Evidently Perl users choose to bash other languages in those languages' own mailing lists. > If Python would be so great, you wouldn't talk so much about how bad are > other languages, Sure we would. Sometimes it's fun to sit on your lofty throne and scoff at the peasantry. > or if these discussions are not initiated by envy, you would > be also talking about how bad is Visual Basic, or Pascal, or Delphi, or who > knows other languages. I would suggest that envy isn't the reason, the reason is that Perl is just that much worse than Visual Basic, Pascal, and Delphi. We only make fun of the really, really bad langauges. (Or, less cynically, it's because Perl and Python historically filled the same niche, whereas VB, Pascal, and Delphi were often used for different sorts of programming.) What I'm trying to say here is your logic is invalid. People have all kinds of reasons to badmouth other languages; that some mailing list has a culture that is a bit more or a bit less approving of it than some other list tells us nothing. In any case it's ridiculous to claim envy as factor nowadays, as Python is clearly on the rise while Perl is on the decline. Few people are choosing Perl for new projects. Carl Banks From rosuav at gmail.com Mon May 23 02:49:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 16:49:32 +1000 Subject: Abandoning Python In-Reply-To: References: <93tqifFnb2U1@mid.individual.net> <4dd9ffc1$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 23, 2011 at 4:33 PM, Steven D'Aprano wrote: > And presumably anyone who has played around with GUI programming in > Python will have run into message oriented coding. > GUI code almost always involves a main loop somewhere that consists of: while not time_to_terminate: ?get_message() ?dispatch_message() Voila, you've just implemented message-oriented code in an imperative way. Doesn't make the language inherently message-oriented. If you're going to read someone else's code, then, you not only need to know the language, you need to know the environment in which it runs. I found that out the hard way when I tried to read some PHP code that was designed to run inside Joomla - it's quite quite different from standalone PHP. I believe assembly language offers as many paradigms as anything else you might want. With judicious use of constructs like the Intel "JMP [BP+SI]" and a nice table of jump targets, you could do message passing, OOP/inheritance, procedures, and next-programmer-brain-destruction, and hey, it's tabular too! Chris Angelico From rosuav at gmail.com Mon May 23 03:32:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 May 2011 17:32:29 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <47fd1b4b-ef7a-4f8c-95be-44e7a93ffacc@glegroupsg2000goo.googlegroups.com> References: <47fd1b4b-ef7a-4f8c-95be-44e7a93ffacc@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 4:46 PM, Carl Banks wrote: > On Sunday, May 22, 2011 12:44:18 AM UTC-7, Octavian Rasnita wrote: >> If Python would be so great, you wouldn't talk so much about how bad are >> other languages, > > Sure we would. ?Sometimes it's fun to sit on your lofty throne and scoff at the peasantry. It's also fun, and sometimes productive, to sit on many different lofty thrones, and then to have a Jedi Council meeting in which we discuss which thrones are hard to climb onto, which ones are easy for a child to sit on but hard to get any work done on, and which ones are really comfortable and ergonomic, but have just that one little hard bit to the right of where your arm wants to rest, but if you're careful it won't jab into you too badly... and in those discussions, Perl is a literal Swiss Army Knife. :) > I would suggest that envy isn't the reason, the reason is that Perl is just that much worse than Visual Basic, Pascal, and Delphi. ?We only make fun of the really, really bad langauges. I'm not sure that Perl deserves to be put alongside Visual Basic. I'm not sure that ANY language deserves that... Chris Angelico From asandroq at gmail.com Mon May 23 03:52:07 2011 From: asandroq at gmail.com (asandroq) Date: Mon, 23 May 2011 00:52:07 -0700 (PDT) Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On May 23, 4:29?am, Deeyana wrote: > > You might be interested in Clojure, then. Lists are more abstracted, like > in Scheme, and vectors and also dictionaries/maps and sets are first > class citizens along side lists. And unlike Scheme, Clojure has good > library/host interop support. You can write real-world applications in it > without spontaneously combusting. Nonsense. Several Scheme systems have excellent FFIs with more than "good library/host interop support". -alex From dan.kluev at gmail.com Mon May 23 04:05:14 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 19:05:14 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> Message-ID: On Mon, May 23, 2011 at 5:06 PM, Octavian Rasnita wrote: > There are more, but a single eloquent feature is the possibility of > interpreting variables in strings which cannot be done so nice in Python. I've should probably mentioned it earlier, but I'm not Perl expert, not following its development and can't be bothered to read its docs. Could you please provide examples of features you mention with expected result, so I could suggest reasonable Python analogue? > This is false. Explicit in this case means to write code in 2 places for > doing a certain thing, and maintaining means changing the code in 2 places, > which is harder and prone to errors. Not sure what do you mean by 'write code in 2 places'. All mapping code is located in routes config, including all needed args validation. But if you want to couple it with controller code, there, as I said, are numerous ways to do it. You can even do something like this: class SomeController(BaseController): ... @map(conditions=dict(method='GET')) def some_method(self, arg1:int, arg2:str): ... so it would be called via /somecontroller/some-method/1/blabla with trivial decorator. > (unless in Pylons/Pyramid can be also defined chained mappings and mappings > based on regular expressions). Not sure what do you mean by "based on regular expressions". Routes paths ARE regular expressions. Conditions are regexes too. As for chained mappings - no idea, never had the need in such thing. > Yes, the single difference is that Catalyst supports all of them, and it > also supports using any templating system, and any ORM and any form > processor, while some of the Python web frameworks don't support absolutely > everything and you need to abandon some preferred modules for beeing able to > use some other modules which are supported. Pyramid and Pylons let you use pretty much any templating package and ORM as well. There is nothing in them that would block such modules. > I've checked the documentation for some of them and I've seen that most of > them don't support sub-selects and some of them require using plain SQL code > in their construct for more complex queries. > Please tell me which of them supports sub-selects, and are able to return > objects for date and datetime fields that have methods for beeing able to > print just the year or day, or the months names in the specified locale > because it would be useful. Python has builtin type for DateTime, and SQLAlchemy, for example, returns exactly that: #> python Python 2.7.1 (r271:86832, May 17 2011, 19:31:41) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sadt import Test, Session >>> import datetime >>> Test(1) >>> Test(2) >>> t1 = Session.query(Test).filter(Test.val == 1).one() >>> t1 >>> t1.date datetime.datetime(2011, 5, 23, 18, 53, 39, 459054) >>> t1.date.year 2011 >>> t1.date.month 5 >>> print Session.query(Test).filter(Test.date == datetime.datetime(2011, 5, 23, 18, 53, 39, 459054)).one() >>> print Session.query(Test).filter(Test.date > datetime.date(2010, 1, 1)).all() [, ] sadt sources here if interesting: http://pastebin.ca/2067372 So as you see, datetime is not only returned properly, but you can also do queries with either date or datetime values, including comparison and range. Subqueries are fully supported too: >>> ... >>> Session.query(Test).from_self().all() 2011-05-23 19:07:02,662 INFO sqlalchemy.engine.base.Engine.0x...552c SELECT anon_1.test_id AS anon_1_test_id, anon_1.test_val AS anon_1_test_val, anon_1.test_date AS anon_1_test_date FROM (SELECT test.id AS test_id, test.val AS test_val, test.date AS test_date FROM test) AS anon_1 2011-05-23 19:07:02,662 INFO sqlalchemy.engine.base.Engine.0x...552c () [, , , , ] This is most trivial example of subqueries, since I'm too lazy to produce proper tables to demonstrate it, but SQLAlchemy has very good subquery support, as its typical way to deal with one-to-many relations (but it does support other loading strategies as well, including inner/outer joins or lazy loading). > it can do but DBIx::Class cannot, because otherwise it would be very simple > for anyone to just say "go to read the documentation and see how great it > is". But "go to read the docs" argument works both ways - I have zero knowledge of DBIx::Class, so obviously I cannot say what features it lacks compared to SQLA. However this is what I wanted to highlight - you cannot simply state that "Perl offers more advanced modules and libraries which are not available for Python" if you don't have reasonable experience with according Python modules. -- With best regards, Daniel Kluev From mail at timgolden.me.uk Mon May 23 04:38:13 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 23 May 2011 09:38:13 +0100 Subject: Problem in using subprocess module and communicate() In-Reply-To: References: Message-ID: <4DDA1CF5.60103@timgolden.me.uk> On 21/05/2011 16:56, vijay swaminathan wrote: > I'm having some problem in using the communicate() along with the > subprocess.I would like to invoke a command prompt and pass on a .bat > file to execute. I went through the subprocess module and understood > that using communicate, we can send the send data to stdin. I'm afraid you're running the risk of giving us too little information here, Vijay. You've pointed to the docs you've read and provided code, which is A Good Thing. Unfortunately, the code you've provided is clearly not what you'll ultimately be running (unless you're in the game for a convoluted means of getting a directory listing) and, as Chris touched on in his response, is probably not even what you're running now, as you're passing the wrong kind of "/k" to cmd.exe. OK, let's see if I've understood correctly from this and from your previous posts: * You have a set of batch scripts you want to launch from Python * You want to launch them in parallel (possibly different scripts, not sure) so you're setting up threads. You seem to be trying to meet these requirements by opening a command shell with an arbitrary command, leaving it open and feeding its stdin with the batch script name so that it runs, and then polling it until it finishes. In short, you're making a mountain out of a molehill. If you need to run batch scripts from a command shell, then use subprocess.call with the name of the batch script and shell=True (the last isn't always necessary; it seems to depend on the C runtime, but it won't harm to have it there): import subprocess result = subprocess.call ("name-of-script.bat", shell=True) If you want to run that in a thread: import subprocess import threading def run_script (path_to_script): subprocess.call (path_to_script, shell=True) t = threading.Thread (target=run_script, args=("name-of-script.bat,")) t.start () while True: # do stuff if t.isAlive (): print "still running" You might, as you have above, want to launch a new console with each subprocess or the output could get quite messy. There are lots of variations on this theme: you could use a Queue to get the success or failure back from the threads. It's not clear whether you actually need to feed input into your batch scripts, as the only reason you're using .communicate above is to actually *run* the batch scripts. I could go on guessing what your use-case is, assuming that it doesn't involve a command shell with the output from a "dir" command, but it'll be easier if you can describe how closely what I've written above matches your need. TJG From orasnita at gmail.com Mon May 23 04:49:40 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 11:49:40 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> Message-ID: <629DAC3611EA49B0A36BCF70151CDE2F@octavian> From: "Terry Reedy" > On 5/23/2011 1:31 AM, Octavian Rasnita wrote: > > >> I am talking about a simple way of creating a hash/dict from an array, >> which is so simple that there should be really a single way to do it, or >> very few. > > Again, Python has such: > > >>> dict([['one',1],['two', 2]]) > {'two': 2, 'one': 1} That is not an array, but a list. An array has a name and we can't do something like the following simple statement in Python: l = (1, 2) d = dict(l) While in Perl we can do: @l = (1, 2); %d = @l; But let's remember from what this discussion started. This is not a Python critique, because each language has its own ways. I just wanted to show that the fact that "there is more than one way to do it" in Perl and that "there is a single way" in Python are just buzzwords, because this was an example where in Python there are many ways to do it while in Perl there is a single way used usually, which is also more simple. Octavian From torbenm at diku.dk Mon May 23 04:51:44 2011 From: torbenm at diku.dk (Torben Ægidius Mogensen) Date: Mon, 23 May 2011 10:51:44 +0200 Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: <7zpqn9re8v.fsf@ask.diku.dk> Xah Lee writes: > Functional Programing: stop using recursion, cons. Use map & vectors. > > ?Guy Steele on Parallel Programing? > http://xahlee.org/comp/Guy_Steele_parallel_computing.html This is more or less what Backus said in his Turing Award lecture about FP. Torben From alex at a13x.net Mon May 23 04:52:24 2011 From: alex at a13x.net (Aleksandar Radulovic) Date: Mon, 23 May 2011 08:52:24 +0000 Subject: Why did Quora choose Python for its development? In-Reply-To: <9CDC4B2CD1F445E994119A50F65155DF@teddy> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> Message-ID: Hi, I'm going to skip the Perl vs. Python flame-bait and correct your one statement. On Sun, May 22, 2011 at 7:44 AM, Octavian Rasnita wrote: > Somebody told that C# and Objective C are good languages. They might be good, but they are proprietary, and not only that they are proprietary, but they need to be ran under platforms that cannot be used freely, so from the freedom point of view, Perl, Ruby, Python and Java are the ways to go. Neither of those are proprietary and can, in fact, be used freely. GNU compiler compiles objective-c code with no problem and then there's Mono for C# and .NET development on multiple platforms. But if by proprietary you mean the libraries and APIs that complement those languages, the it's worth noting that Mono implements most of .NET framework and it is free. If you want "free" Cocoa APIs (or other Obj-C frameworks) look into GnuSTEP. Best regards, alex. -- a lex 13 x http://www.a13x.info From orasnita at gmail.com Mon May 23 05:01:35 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 12:01:35 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian> Message-ID: <012186634A924F38862902F52B2EF799@octavian> From: "Chris Angelico" > On Mon, May 23, 2011 at 3:31 PM, Octavian Rasnita > wrote: >> From: "Dennis Lee Bieber" >>> >>> Since indentation seems so crucial to easy comprehension of the logical >>> structure of a program, >>> making it a mandatory syntactical structure becomes a desirable feature >>> for code that must be maintained (by others, in many cases). >> >> Why "in many cases"? I wrote hundreads of programs which are working fine >> and which are maintained only by me. (But they would be very easy to >> maintain by other people if it would be necessary). >> So in that case, why to be forced to use a strict indentation? > > The reason for clear code is maintenance, not maintenance-by-others. > If you come back to something in a year, you'll appreciate proper > variable names, indentation, etc. > > That said, though, I still do not believe in Python's philosophy of > significant whitespace. I like to be able, if I choose, to put one > entire "logical unit" on one line, such that it can be commented out > with a single comment marker, or duplicated to another line and one > copy commented out, or whatever. To that end, I sometimes want to put > an if, its associated else, and sometimes a statement for both > branches, all in the one line. And that's not possible when whitespace > alone defines the end of an if/else block (the one-line form of a > Python 'if' can't have a non-conditional statement after it at all), > but is quite easy when things are delimited with braces. Yes I also agree with that, and I also prefer *in some cases* to write short code in a single line like: print "..." if $var; print $var == 123 ? "abcd" : "cedf"; print $var =~ /foo/ ? "abc" : "cdef"; ...instead of writing a few lines of code. These constructs are not recommended for Perl either, and Perl::Critic would give a warning when it will be used with a certain level of errors checking, but it is preferable to be able to do what you want how you or your team want, not as the creator of the programming language wants. And I don't think that there are programmers that find the lines above hard to understand or maintain. Octavian From info at egenix.com Mon May 23 05:35:23 2011 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 23 May 2011 11:35:23 +0200 Subject: ANN: eGenix mx Base Distribution 3.2.0 (mxDateTime, mxTextTools, etc.) Message-ID: <4DDA2A5B.301@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mx Base Distribution Version 3.2.0 for Python 2.4 - 2.7 Open Source Python extensions providing important and useful services for Python programmers. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.0-GA.html ________________________________________________________________________ ABOUT The eGenix.com mx Base Distribution for Python is a collection of professional quality software tools which enhance Python's usability in many important areas such as fast text searching, date/time processing and high speed data types. The tools have a proven record of being portable across many Unix and Windows platforms. You can write applications which use the tools on Windows and then run them on Unix platforms without change due to the consistent platform independent interfaces. Contents of the distribution: * mxDateTime - Easy to use Date/Time Library for Python * mxTextTools - Fast Text Parsing and Processing Tools for Python * mxProxy - Object Access Control for Python * mxBeeBase - On-disk B+Tree Based Database Kit for Python * mxURL - Flexible URL Data-Type for Python * mxUID - Fast Universal Identifiers for Python * mxStack - Fast and Memory-Efficient Stack Type for Python * mxQueue - Fast and Memory-Efficient Queue Type for Python * mxTools - Fast Everyday Helpers for Python All available packages have proven their stability and usefulness in many mission critical applications and various commercial settings all around the world. For more information, please see the distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.1.3 release of the eGenix mx Base Distribution is the latest release of our open-source Python extensions. The new version provides major enhancements of the included packages. To highlight a few: * Added support for Python 2.7 on all supported platforms. * Added native Window x64 support. * Included many news features in mxDateTime to enhance interoperability with Python's datetime module and to increase overall performance: o Mixed type support to allow operations between mxDateTime objects and Python's datetime module o New constructor methods on the objects to easily switch from mxDateTime objects to datetime module objects. o New constructor support to easily switch back from datetime module objects to mxDateTime objects * Added new mx.Misc.Daemon module which provides abstractions to implement Unix daemon processes. * Added code cleanups and switched to Python's own memory allocator, which results in performance enhancements across all subpackages. * Added back easy_install support and included pip support. As always, we are providing pre-built binaries for all common platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac OS X 32/64-bit. Source code archives are available for installation on all other Python platforms, such as Solaris, AIX, HP-UX, etc. To simplify installation in Zope/Plone and other egg-based systems, we have also precompiled egg distributions for all platforms. These are available on our own PyPI-style index server for easy and automatic download. Whether you are using a pre-built package or the source distribution, installation is a simple "python setup.py install" command in all cases. The only difference is that the pre-built packages do not require a compiler or the Python development packages to be installed. For a list of changes, please refer to the eGenix mx Base Distribution change log at http://www.egenix.com/products/python/mxBase/changelog.html and the change logs of the various included Python packages. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the packages can be found on the eGenix mx Base Distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ LICENSE The eGenix mx Base package is distributed under the eGenix.com Public License 1.1.0 which is an Open Source license similar to the Python license. You can use the packages in both commercial and non-commercial settings without fee or charge. The package comes with full source code ________________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, May 23 2011) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2011-06-20: EuroPython 2011, Florence, Italy 28 days to go ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From orasnita at gmail.com Mon May 23 05:41:56 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 12:41:56 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> Message-ID: From: "Daniel Kluev" > On Mon, May 23, 2011 at 5:06 PM, Octavian Rasnita > wrote: >> There are more, but a single eloquent feature is the possibility of >> interpreting variables in strings which cannot be done so nice in Python. > > I've should probably mentioned it earlier, but I'm not Perl expert, > not following its development and can't be bothered to read its docs. > Could you please provide examples of features you mention with > expected result, so I could suggest reasonable Python analogue? The ones that bash other languages on the mailing list for their prefered language should provide good comparisons and not just make false statements, considering that it is enough, since most of the list members will agree because they like Python more than other languages anyway. If they think that what they say is true, why don't they make those statements on Perl mailing lists, but again, offering valid comparisons. > But if you want to couple it with controller code, there, as I said, > are numerous ways to do it. You can even do something like this: > > class SomeController(BaseController): > ... > @map(conditions=dict(method='GET')) > def some_method(self, arg1:int, arg2:str): > ... > so it would be called via /somecontroller/some-method/1/blabla with > trivial decorator. Is the url something like /some_controller/some_method? Or the underlines are deleted from the name of the controller and replaced with "-" in the name of the method? Is it possible to also add a configuration here to call this some_method when the url /some_controller/some-method-string is accessed? (define another string than the name of the method) Is it possible to configure it to access this subroutine only if a certain number of parameters are sent in the URL? If yes, it means that its dispatcher is better than I've seen in the short tutorial on the web. >> (unless in Pylons/Pyramid can be also defined chained mappings and >> mappings >> based on regular expressions). > > Not sure what do you mean by "based on regular expressions". Routes > paths ARE regular expressions. Conditions are regexes too. > > As for chained mappings - no idea, never had the need in such thing. The chained dispatcher is one of the best thing offered by Catalyst, because with it the same code should not be used twice. For example, one can define a subroutine in which a certain record is selected from the DB and is placed in stash. Then there may be other subroutines for different tasks, one for editing that record, one for deleting that record and so on. One chain can start with the base subroutine that makes the selection from the DB then executes the subroutine that makes the deletion and another chain can start with the base subroutine that makes the selection than continues with the one that starts the editting. Of course, the chain can have more links, not only 2, but this was just a very short example. >> I've checked the documentation for some of them and I've seen that most >> of >> them don't support sub-selects and some of them require using plain SQL >> code >> in their construct for more complex queries. >> Please tell me which of them supports sub-selects, and are able to return >> objects for date and datetime fields that have methods for beeing able to >> print just the year or day, or the months names in the specified locale >> because it would be useful. > > Python has builtin type for DateTime, and SQLAlchemy, for example, > returns exactly that: >>>> t1.date.month > 5 Can it also set the current locale, for example romanian, and print the name of the current month? ...something like t1.date.set_locale('ro').month_name? > SELECT anon_1.test_id AS anon_1_test_id, anon_1.test_val AS > anon_1_test_val, anon_1.test_date AS anon_1_test_date > FROM (SELECT test.id AS test_id, test.val AS test_val, test.date AS > test_date > FROM test) AS anon_1 As I said, that ORM is not able to do those SQL constructs without using literal SQL code, but only Python variables and data structures... An ORM is usually prefered exactly because it doesn't force the programmer to concatenate strings for generating the SQL code, but he/she can use just standard Perl/Python code. Or this is possible in another way without using SQL code? >> it can do but DBIx::Class cannot, because otherwise it would be very >> simple >> for anyone to just say "go to read the documentation and see how great it >> is". > > But "go to read the docs" argument works both ways - I have zero > knowledge of DBIx::Class, so obviously I cannot say what features it > lacks compared to SQLA. Yes you are perfectly right, but not those programmers that also use Perl started to say that Perl can do this and Python can't, or that in Perl this is shorter and nicer than in Python. I just wanted to show that anything Python can do can be done in Perl also, and in some fields Python is better, in other fields Perl is better, and we should use whatever we like the most, and not say bad words about other languages or about those who use other languages, especially in a coward-way, on the group of programmers that prefer the praised language. Octavian From awilliam at whitemice.org Mon May 23 05:50:31 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 23 May 2011 05:50:31 -0400 Subject: Multiprocessing: don't push the pedal to the metal? In-Reply-To: References: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> Message-ID: <1306144231.11345.10.camel@linux-yu4c.site> On Mon, 2011-05-23 at 10:32 +1000, Chris Angelico wrote: > On Mon, May 23, 2011 at 7:06 AM, John Ladasky wrote: > > If I spawn N worker sub-processes, my application in fact has N+1 > > processes in all, because there's also the master process itself. > > I'd still appreciate hearing from anyone else who has more experience > > with multiprocessing. If there are general rules about how to do this > > best, I haven't seen them posted anywhere. This may not be a Python- > > specific issue, of course. > I don't have much experience with Python's multiprocessing model, but > I've done concurrent programming on a variety of platforms, and there > are some common issues. I develop an app that uses multiprocessing heavily. Remember that all these processes are processes - so you can use all the OS facilities regarding processes on them. This includes setting nice values, schedular options, CPU pinning, etc... > Each CPU (or core) has its own execution cache. If you can keep one > thread running on the same core all the time, it will benefit more > from that cache than if it has to keep flitting from one to another. +1 > You undoubtedly will have other processes in the system, too. As well > as your master, there'll be processes over which you have no control > (unless you're on a bare-bones system). Some of them may preempt your > processes. This is very true. You get a benefit from dividing work up to the correct number of processes - but too many processes will quickly take back all the benefit. One good trick is to have the parent monitor the load average and only spawn additional workers when that value is below a certain value. From dan.kluev at gmail.com Mon May 23 05:58:51 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 20:58:51 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <629DAC3611EA49B0A36BCF70151CDE2F@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> Message-ID: On Mon, May 23, 2011 at 7:49 PM, Octavian Rasnita wrote: > That is not an array, but a list. An array has a name and we can't do > something like the following simple statement in Python: > > l = (1, 2) > d = dict(l) > An array has a name What? In python there is no difference whether your object has any names mapped to it or not. Its all the same, and object itself does not even know. Moreover, (1, 2) is tuple rather than 'array'. If you mean array as implemented as array, then list is what you want. If you mean array literally, there is special type 'array' somewhere in stdlib. As for "can't do": >>> a = [1,2] >>> dict([a]) {1: 2} >>> a = (1,2) >>> dict([a]) {1: 2} -- With best regards, Daniel Kluev From dan.kluev at gmail.com Mon May 23 06:16:42 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 21:16:42 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> Message-ID: On Mon, May 23, 2011 at 8:41 PM, Octavian Rasnita wrote: > From: "Daniel Kluev" > As I said, that ORM is not able to do those SQL constructs without using > literal SQL code, but only Python variables and data structures... > An ORM is usually prefered exactly because it doesn't force the programmer > to concatenate strings for generating the SQL code, but he/she can use just > standard Perl/Python code. > Or this is possible in another way without using SQL code? Did you actually read the code? SQL there is debug output of SQLAlchemy for python code `Session.query(Test).from_self().all()`, I left it there to just show you that it emits subquery to RDBMS. All code in REPL is prefixed by `>>> `. Other lines are just output. > Can it also set the current locale, for example romanian, and print the name of the current month? > ...something like t1.date.set_locale('ro').month_name? There is separate module for date localization. You can pass datetime object to it and it will give you needed value. > The ones that bash other languages on the mailing list for their prefered language should provide good comparisons and not just make false statements That would be valid if I would 'bash other languages', but I just responded to your claim that Perl has advanced modules which are not available for Python, esp. in web frameworks, as I find it one of areas where Python shines most. Sure Python has drawbacks, esp. its performance and poor threads support (GIL), but flexibility and modules of all flavors and types are not among them. Introduction of parameter annotations should make these modules even greater, once python 3.x is widely adopted. -- With best regards, Daniel Kluev From jldunn2000 at gmail.com Mon May 23 06:32:49 2011 From: jldunn2000 at gmail.com (loial) Date: Mon, 23 May 2011 03:32:49 -0700 (PDT) Subject: Python 2.6 and timezones Message-ID: <46c24750-ac9b-4d75-835c-5403ff2ea959@d28g2000yqf.googlegroups.com> Does python have an equivalent of the java Timezone object? I need to be able to get offsets for timezones (only U.S. time zones at the moment) From patrick.just4fun at gmail.com Mon May 23 06:41:08 2011 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Mon, 23 May 2011 12:41:08 +0200 Subject: Dealing with name clashes in pypi In-Reply-To: References: <4DD9573E.8010509@gmail.com> Message-ID: <4DDA39C4.1010300@gmail.com> On 2011-05-22 23:23, Terry Reedy wrote: > On 5/22/2011 2:34 PM, Patrick Sabin wrote: >> I wanted to register my project (epdb) in pypi. Unfortunately there >> already exists a project with the same name. It is not possible for me >> to change the name of the project, because I used it in multiple >> writings. Any ideas how I can deal with the situation? Is it possible to >> register a project under a different name in pypi than the actual >> project name? > > I presume so. How would pypi know the 'actual' name? > However, there is a catalog sig list (mirrored as > gmane.comp.python.catalog) where you might get specific suggestions on > how to handle this. > Thanks for the tip. I will try it there. -- Patrick From robin at reportlab.com Mon May 23 06:45:35 2011 From: robin at reportlab.com (Robin Becker) Date: Mon, 23 May 2011 11:45:35 +0100 Subject: Abandoning Python In-Reply-To: <87ipt46okh.fsf@pobox.com> References: <87ipt46okh.fsf@pobox.com> Message-ID: <4DDA3ACF.9050408@chamonix.reportlab.co.uk> On 21/05/2011 16:49, John J Lee wrote: > > > I still like Python after using it for over a decade, but there are > things I don't like. ...... a relatively new one that's going about is cobra, http://cobra-language.com/, it appears to have some of the features you indicate eg speed, some kind of interfaces (contracts I think), but it needs net or mono. -- Robin Becker From dan.kluev at gmail.com Mon May 23 06:48:05 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 21:48:05 +1100 Subject: Python 2.6 and timezones In-Reply-To: <46c24750-ac9b-4d75-835c-5403ff2ea959@d28g2000yqf.googlegroups.com> References: <46c24750-ac9b-4d75-835c-5403ff2ea959@d28g2000yqf.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 9:32 PM, loial wrote: > Does python have an equivalent of the java Timezone object? > > I need to be able to get offsets for timezones (only U.S. time zones > at the moment) Depends on what exactly do you want. If you need to convert timezone name into current offset, you should use [1] or [2]. If you just need to handle known offsets for datetime objects, there is tzinfo class in datetime module, [3]. [1] http://pypi.python.org/pypi/PosixTimeZone/0.9.4 [2] http://pypi.python.org/pypi/pytz/2011g [3] http://docs.python.org/library/datetime.html#tzinfo-objects -- With best regards, Daniel Kluev From floris.bruynooghe at gmail.com Mon May 23 06:53:05 2011 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Mon, 23 May 2011 03:53:05 -0700 (PDT) Subject: Condition.wait(timeout) oddities Message-ID: <94d1d127-b423-4bd4-853c-d92da9ac7588@glegroupsg2000goo.googlegroups.com> Hi all I'm a little confused about the corner cases of Condition.wait() with a timeout parameter in the threading module. When looking at the code the first thing that I don't quite get is that the timeout should never work as far as I understand it. .wait() always needs to return while holding the lock, therefore it does an .acquire() on the lock in a finally clause. Thus pretty much ignoring the timeout value. The second issue is that while looking around for this I found two bug reports: http://bugs.python.org/issue1175933 and http://bugs.python.org/issue10218. Both are proposing to add a return value indicating whether the .wait() timed out or not similar to the other .wait() methods in threading. However the first was rejected after some (seemingly inconclusive) discussion. While the latter had minimal discussion and and was accepted without reference to the earlier attempt. Not sure if this was a process oversight or what, but it does leave the situation confusing. But regardless I don't understand how the return value can be used currently: yes you did time out but you're still promised to hold the lock thanks to the .acquire() call on the lock in the finally block. In my small brain I just can't figure out how Condition.wait() can both respect a timeout parameter and the promise to hold the lock on return. It seems to me that the only way to handle the timeout is to raise an exception rather then return a value because when you get an exception you can break the promise of holding the lock. But maybe I'm missing something important or obvious, so I'd be happy to be enlightened! Regards Floris From ulrich.eckhardt at dominolaser.com Mon May 23 06:56:45 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 23 May 2011 12:56:45 +0200 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: Octavian Rasnita wrote: > Somebody told that C# and Objective C are good languages. They might be > good, but they are proprietary, and not only that they are proprietary, > but they need to be ran under platforms that cannot be used freely, so > from the freedom point of view, Perl, Ruby, Python and Java are the ways > to go. Ahem, is this Java the language that a certain, well-known service provider is getting screwed over hard currently, because they forgot to read the fineprint in the declaration of freedom? And this Objective C, isn't this the language that GCC had support for since before it properly supported C++, and that on a multitude of targets? I'm probably just confusedly feeding flames here, but I like it snug and warm. (: Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From nobody at nowhere.net.no Mon May 23 07:06:07 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 23 May 2011 19:06:07 +0800 Subject: how to get PID from subprocess library References: Message-ID: GMail Felipe wrote: > For the "ps" command, have you seen the psuti module? > > The link to it is: http://code.google.com/p/psutil/ You gave a brand new start :) I bit of additional program to include into the package ;) -- goto /dev/null From orasnita at gmail.com Mon May 23 07:10:55 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 14:10:55 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian> Message-ID: <57C0AB91B42743E89456ACCC8751CF78@octavian> From: "Daniel Kluev" a = [1,2] dict([a]) Yes, but d = dict([a]) is not so nice as $d = @a; because it has exactly those numerous number of params and brackets which is used as a reason for bashing Perl and an aditional "dict" word. Octavian From orasnita at gmail.com Mon May 23 07:17:59 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 14:17:59 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> Message-ID: <46EA3D502B204937A4EE89E34471BC0F@octavian> From: "Daniel Kluev" ... >> Can it also set the current locale, for example romanian, and print the >> name of the current month? >> ...something like t1.date.set_locale('ro').month_name? > > There is separate module for date localization. You can pass datetime > object to it and it will give you needed value. Aha, so with other words that ORM doesn't have that feature. DBIX::Class also use the DateTime module, but it can use it directly, without needing to write more code for that, and it can also return localized dates. >> The ones that bash other languages on the mailing list for their prefered >> language should provide good comparisons and not just make false >> statements > > That would be valid if I would 'bash other languages', but I just > responded to your claim that Perl has advanced modules which are not No you haven't responded because you haven't shown any thing that can be done by the web framework and the ORM you are praising but can't be done by Catalyst and DBIx::Class, however I have shown you that DBIx::Class can return DateTime objects directly, without needing to load the DateTime module manually and to initialize the DateTime object manually... And don't take my words out of the context, because I have also answered to another list member that was bashing Perl without offering other helpful information than just that kind of jokes which are usually made by teenagers under 30. Octavian From duncan.booth at invalid.invalid Mon May 23 07:28:29 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 May 2011 11:28:29 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: Ulrich Eckhardt wrote: > Ahem, is this Java the language that a certain, well-known service > provider is getting screwed over hard currently, because they forgot > to read the fineprint in the declaration of freedom? That would be the case where the plaintiff has been ordered to drop all but 3 of their 132 claims? It isn't at all obvious yet who is going to be 'screwed over hard'. -- Duncan Booth http://kupuguy.blogspot.com From dan.kluev at gmail.com Mon May 23 07:32:44 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 22:32:44 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <46EA3D502B204937A4EE89E34471BC0F@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <2EA88E7D68664EB3A4A49FA332E0E7EB@octavian> <46EA3D502B204937A4EE89E34471BC0F@octavian> Message-ID: On Mon, May 23, 2011 at 10:17 PM, Octavian Rasnita wrote: > From: "Daniel Kluev" > Aha, so with other words that ORM doesn't have that feature. > DBIX::Class also use the DateTime module, but it can use it directly, > without needing to write more code for that, and it can also return > localized dates. Once again. ORMs return _python builtin type_. Localization is not their responsibility, and plugging it there is code bloat, rather than feature. Sure you may ask ORM to handle JSONRPC requests on its own, but ORM responsibility is to map RDBMS features to language objects. All good python packages limit their functionality to specific field, so you could choose one you prefer for each different task independently. > without needing to load the DateTime module manually and to initialize the DateTime object manually... This is basically stating that you didn't read the code I posted. Where did you ever find "initialize the DateTime object manually"? Sorry, but its pointless to discuss anything if you don't want to even read properly examples you receive. -- With best regards, Daniel Kluev From jldunn2000 at gmail.com Mon May 23 07:56:29 2011 From: jldunn2000 at gmail.com (loial) Date: Mon, 23 May 2011 04:56:29 -0700 (PDT) Subject: Python 2.6 and timezones References: <46c24750-ac9b-4d75-835c-5403ff2ea959@d28g2000yqf.googlegroups.com> Message-ID: <932c351d-0dbd-4d5b-8151-e695b4b83fe1@z37g2000vbl.googlegroups.com> Thanks...but being a python newbie I am struggling to understand how to do this. How can I use tzinfo to do the equivalent of what I do in Java, which is : TimeZone tz1 = TimeZone.getDefault(); long localOffset = tz1.getOffset(date.getTime()); TimeZone tz2 = TimeZone.getTimeZone("EST"); long remoteOffset = tz2.getOffset(date.getTime()); Any help appreciated On May 23, 11:48?am, Daniel Kluev wrote: > On Mon, May 23, 2011 at 9:32 PM, loial wrote: > > Does python have an equivalent of the java Timezone object? > > > I need to be able to get offsets for timezones (only U.S. time zones > > at the moment) > > Depends on what exactly do you want. If you need to convert timezone > name into current offset, you should use [1] or [2]. > If you just need to handle known offsets for datetime objects, there > is tzinfo class in datetime module, [3]. > > [1]http://pypi.python.org/pypi/PosixTimeZone/0.9.4 > [2]http://pypi.python.org/pypi/pytz/2011g > [3]http://docs.python.org/library/datetime.html#tzinfo-objects > > -- > With best regards, > Daniel Kluev From cjw at ncf.ca Mon May 23 08:20:16 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Mon, 23 May 2011 08:20:16 -0400 Subject: and becomes or and or becomes and In-Reply-To: <4DD96297.5010909@gmail.com> References: <4DD96297.5010909@gmail.com> Message-ID: On 22-May-11 15:23 PM, Stef Mientki wrote: > hello, > > must of us will not use single bits these days, > but at first sight, this looks funny : > >>>> a=2 >>>> b=6 >>>> a and b > 6 >>>> a& b > 2 >>>> a or b > 2 >>>> a | b > 6 > > cheers, > Stef 5.2. Boolean Operations ? and, or, not These are the Boolean operations, ordered by ascending priority: Operation Result Notes x or y if x is false, then y, else x (1) x and y if x is false, then x, else y (2) not x if x is false, then True, else False (3) The second line is puzzling at first look, but consistent. It is analogous to the Conditional Expression. See: http://docs.python.org/reference/expressions.html#conditional-expressions Colin W. From dan.kluev at gmail.com Mon May 23 08:33:40 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 23 May 2011 23:33:40 +1100 Subject: Python 2.6 and timezones In-Reply-To: <932c351d-0dbd-4d5b-8151-e695b4b83fe1@z37g2000vbl.googlegroups.com> References: <46c24750-ac9b-4d75-835c-5403ff2ea959@d28g2000yqf.googlegroups.com> <932c351d-0dbd-4d5b-8151-e695b4b83fe1@z37g2000vbl.googlegroups.com> Message-ID: On Mon, May 23, 2011 at 10:56 PM, loial wrote: > Thanks...but being a python newbie I am struggling to understand how > to do this. > > How can I use tzinfo to do the equivalent of what I do in Java, which > is : > > TimeZone tz1 = TimeZone.getDefault(); > > long localOffset = tz1.getOffset(date.getTime()); > > TimeZone tz2 = TimeZone.getTimeZone("EST"); > > long remoteOffset = tz2.getOffset(date.getTime()); > >>> from pytz import timezone, FixedOffset >>> import time >>> from datetime import datetime >>> local_tz = FixedOffset(-time.timezone/60) time.timezone returns local timezone in seconds and negative sign. FixedOffset converts it into tzinfo object. >>> now = datetime.now() >>> local_tz.utcoffset(now) datetime.timedelta(0, 36000) utcoffset() returns timedelta object as offset. It requires datetime object as first parameter due to weird API of base tzinfo class, but it is not used in calculation, and you can pass any other object, including None instead, like `local_tz.utcoffset(None)` >>> remote_tz = timezone("EST") >>> remote_tz.utcoffset(now) datetime.timedelta(-1, 68400) You can add or substract these timedelta objects directly from datetime objects or use astimezone(): >>> now = datetime.now(local_tz) >>> now datetime.datetime(2011, 5, 23, 22, 41, 48, 398685, tzinfo=pytz.FixedOffset(600)) >>> now.astimezone(remote_tz) datetime.datetime(2011, 5, 23, 7, 41, 48, 398685, tzinfo=) -- With best regards, Daniel Kluev From zdoor at xs4all.nl Mon May 23 09:00:53 2011 From: zdoor at xs4all.nl (Alex van der Spek) Date: Mon, 23 May 2011 15:00:53 +0200 Subject: Multiple file select with tkFileDialog passes back 'decorated' strings (sometimes) Message-ID: <4dda5a89$0$49175$e4fe514c@news.xs4all.nl> I switched from Mark Hammonds pywin32 extensions for file choosers as the multiselect there seems to crash on me when selecting more than a few dozen. Using Tk now. Works well but the resulting string passed back seems to 'decorated' when the files are on local disk and not decorated when retrieved over a USB interface from an external disk? I do this: >From local disk I get back: '{file1.bin} {file2.bin}' >From external disk I get back: 'file1.bin file2.bin' I can handle/parse both, not an issue but it raises the question: Are these the only two possibilities? Is it the same across platforms (I use Python 2.7 on Win Vista)? See code below. Thanks for the insight! Alex van der Spek +++++++++++++++++++ from Tkinter import * import tkFileDialog as tkf tkroot=Tk() tkroot.withdraw() initdir=os.environ['HOME'] filetype=[('Binary Timeseries','*.bin'),('All files','*.*')] filenames=tkf.askopenfilenames(parent=tkroot,initialdir=initdir,filetypes=filetype) tkroot.destroy() From miki.tebeka at gmail.com Mon May 23 09:06:25 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 23 May 2011 06:06:25 -0700 (PDT) Subject: Python 2.6 and timezones In-Reply-To: Message-ID: <93bd4afe-ba6d-4b0c-a239-ad0b877c577e@glegroupsg2000goo.googlegroups.com> > [1] http://pypi.python.org/pypi/PosixTimeZone/0.9.4 > [2] http://pypi.python.org/pypi/pytz/2011g > [3] http://docs.python.org/library/datetime.html#tzinfo-objects Also http://labix.org/python-dateutil#head-587bd3efc48f897f55c179abc520a34330ee0a62 HTH -- Miki Tebeka http://pythonwise.blogspot.com From miki.tebeka at gmail.com Mon May 23 09:06:25 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 23 May 2011 06:06:25 -0700 (PDT) Subject: Python 2.6 and timezones In-Reply-To: Message-ID: <93bd4afe-ba6d-4b0c-a239-ad0b877c577e@glegroupsg2000goo.googlegroups.com> > [1] http://pypi.python.org/pypi/PosixTimeZone/0.9.4 > [2] http://pypi.python.org/pypi/pytz/2011g > [3] http://docs.python.org/library/datetime.html#tzinfo-objects Also http://labix.org/python-dateutil#head-587bd3efc48f897f55c179abc520a34330ee0a62 HTH -- Miki Tebeka http://pythonwise.blogspot.com From pjb at informatimago.com Mon May 23 09:39:11 2011 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 23 May 2011 15:39:11 +0200 Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> <7zpqn9re8v.fsf@ask.diku.dk> Message-ID: <87tyclk03k.fsf@kuiper.lan.informatimago.com> torbenm at diku.dk (Torben ?gidius Mogensen) writes: > Xah Lee writes: > > >> Functional Programing: stop using recursion, cons. Use map & vectors. >> >> ?Guy Steele on Parallel Programing? >> http://xahlee.org/comp/Guy_Steele_parallel_computing.html > > This is more or less what Backus said in his Turing Award lecture about > FP. Stop inflating his ego! Next he'll quote Nobel prize winners... -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From mail at timgolden.me.uk Mon May 23 11:13:38 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 23 May 2011 16:13:38 +0100 Subject: Problem in using subprocess module and communicate() In-Reply-To: References: <4DDA1CF5.60103@timgolden.me.uk> Message-ID: <4DDA79A2.7060602@timgolden.me.uk> [cc-ing back to the list; please keep the conversation over there...] On 23/05/2011 13:11, vijay swaminathan wrote: > What I want to achieve is, I want to run a batch file on a command prompt. > > The reason for using thread is not for running multiple scripts > simultaneously. It is just to monitor my script running in command > prompt. only on closing the command prompt, I like to perform some more > actions. so I look to monitor my thread. Hope it is clear until now. Ok. That's perfectly clear. > > the below mentioned code does not invoke the command prompt at all. Does > the subprocess.call take care of invoking the command prompt? Adding shell=True invokes %COMSPEC% (usually cmd.exe) under the covers. How do you know it's not invoking the command prompt? Does your batch file generate output? And is that output generated? Without the CREATE_NEW_CONSOLE flag, you won't see an extra box pop up, but unless you specifically want one, then don't bother. OK, baby steps. Here's a batch file: @echo Hello and here's a Python script which runs it: import subprocess subprocess.call ("tjg.bat", shell=True) I opened a console (cmd.exe), ran tjg.py and, as expected, "Hello" appears in the same console. Note that, if I hadn't made the .bat file generate some output I wouldn't have seen anything but it would still have worked. I now make the .bat file do something more long-winded, such as fire up a Python session which waits for five seconds and then completes: @echo off echo Starting python -c "import time; time.sleep (5)" echo Finished When I run tjg.py again, I see "Starting" and then a pause of 5 seconds, and then "Finished". Now let's make the Python program monitor to see when that batch has finished by watching the isAlive status and then sleeping for a second: import subprocess import threading import time def run_tjg (): subprocess.call ("tjg.bat", shell=True) t = threading.Thread (target=run_tjg) t.start () while t.isAlive (): print "is alive" time.sleep (1) print "Thread is complete" When I run this, I get a mixture of output, depending on what gets to the console first, but essentially I see the batch file starting, I get a series of about 5 "is alive" messages, then the batch file "Finished" message and the Python "Thread is complete" message. Does that work for you? TJG From john at castleamber.com Mon May 23 11:26:56 2011 From: john at castleamber.com (John Bokma) Date: Mon, 23 May 2011 10:26:56 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> Message-ID: <87pqn95tfj.fsf@castleamber.com> Chris Angelico writes: > That said, though, I still do not believe in Python's philosophy of > significant whitespace. I like to be able, if I choose, to put one > entire "logical unit" on one line, such that it can be commented out > with a single comment marker, Use an editor that can with a single command comment out a selection (and revert this), like Emacs. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From arayapablo93 at hotmail.com Mon May 23 11:29:39 2011 From: arayapablo93 at hotmail.com (pablo araya) Date: Mon, 23 May 2011 09:29:39 -0600 Subject: python help In-Reply-To: References: , Message-ID: > > Hi I'm tryin to create a game but I have a question in how to save > > (saveasfile) the value of a global variable.. and then load the same value > > with openfile. > > Also for example you have a main label and a botton on the left.... so when > > you click the left bottom the label will change or refresh to another label, > > and when you return to the original label show or refresh to the original > > one. All the works is with matrix in python 3.2 and also tkinter. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Mon May 23 11:30:25 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 23 May 2011 08:30:25 -0700 (PDT) Subject: and becomes or and or becomes and References: <4dd9aaac$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <71ab1ccc-c2c0-474f-b7bb-1000754317e4@z13g2000prk.googlegroups.com> On May 23, 5:30?am, Steven D'Aprano wrote: > On Sun, 22 May 2011 15:39:33 -0700, Tim Roberts wrote: > > Stef Mientki wrote: > > >>must of us will not use single bits these days, but at first sight, this > >>looks funny : > > >>>>> a=2 > >>>>> b=6 > >>>>> a and b > >>6 > >>>>> a & b > >>2 > >>>>> a or b > >>2 > >>>>> a | b > >>6 > > > That IS funny. ?Interesting how a careful choice of arugments will fool > > us. One of my favorite math jokes is like that. ?A teacher asked a > > student to reduce the following fraction: > > ? 16 > > ?---- > > ? 64 > > > He says "all I have to do is cancel out the sixes, so the answer is > > 1/4". > > One of my favourite variations on this is by Abbott and Costello, where > Costello proves that 13*7 = 28 in three different ways. > > http://www.youtube.com/watch?v=rLprXHbn19I Ha Ha! [You're hired Steven] From rustompmody at gmail.com Mon May 23 11:47:36 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 23 May 2011 08:47:36 -0700 (PDT) Subject: Tkinter bug? Message-ID: <5790ee23-37d1-4cdd-b88b-a63c2b627c41@k15g2000pri.googlegroups.com> If I start turtle from idle, and issue commands from there, there are all kinds of strange behaviors. I cant pin down any properly but they all look like IO issues. -- If the turtle window is hidden by the tkinter interpreter window, none of what is drawn appears -- If the turtle window is killed I get a this window is not responding box -- The window always shows as 'Non responding' I therefore guess that the emacs-related behavior I asked about earlier has little to do with emacs and more to do with tkinter on windows. Can someone confirm/deny this? http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f55b4cb77653115/6543ed65bbb51c09?lnk=gst&q=rusi#6543ed65bbb51c09 http://groups.google.com/group/comp.lang.python/browse_thread/thread/36e757567f28368e/8737ab250b9f657a?lnk=gst&q=rusi+ipython#8737ab250b9f657a From antti.ylikoski at tkk.fi Mon May 23 12:36:20 2011 From: antti.ylikoski at tkk.fi (Antti J Ylikoski) Date: Mon, 23 May 2011 19:36:20 +0300 Subject: Functional Programing: stop using recursion, cons. Use map & vectors In-Reply-To: <87tyclk03k.fsf@kuiper.lan.informatimago.com> References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> <7zpqn9re8v.fsf@ask.diku.dk> <87tyclk03k.fsf@kuiper.lan.informatimago.com> Message-ID: On 23.5.2011 16:39, Pascal J. Bourguignon wrote: > torbenm at diku.dk (Torben ?gidius Mogensen) writes: > >> Xah Lee writes: >> >> >>> Functional Programing: stop using recursion, cons. Use map& vectors. >>> >>> ?Guy Steele on Parallel Programing? >>> http://xahlee.org/comp/Guy_Steele_parallel_computing.html >> >> This is more or less what Backus said in his Turing Award lecture about >> FP. > > Stop inflating his ego! Next he'll quote Nobel prize winners... > Well said.... That inspired me to note: LISP without recursion would be like a jet airplane without wings.... Recursion is an important part of the functional programming paradigm (yes, I do know that LISP is not a purely functional language...) LISP denotes, List Processing. List Processing without cons ????? Ugh. regards, andy From nad at acm.org Mon May 23 12:55:15 2011 From: nad at acm.org (Ned Deily) Date: Mon, 23 May 2011 09:55:15 -0700 Subject: Tkinter bug? References: <5790ee23-37d1-4cdd-b88b-a63c2b627c41@k15g2000pri.googlegroups.com> Message-ID: In article <5790ee23-37d1-4cdd-b88b-a63c2b627c41 at k15g2000pri.googlegroups.com>, rusi wrote: > If I start turtle from idle, and issue commands from there, there are > all kinds of strange behaviors. Have you tried starting IDLE with the "-n" switch? http://docs.python.org/library/turtle.html -- Ned Deily, nad at acm.org From tjreedy at udel.edu Mon May 23 13:08:58 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 May 2011 13:08:58 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <629DAC3611EA49B0A36BCF70151CDE2F@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> Message-ID: On 5/23/2011 4:49 AM, Octavian Rasnita wrote: > But let's remember from what this discussion started. This is not a > Python critique, because each language has its own ways. > I just wanted to show that the fact that "there is more than one way to > do it" in Perl and that "there is a single way" in Python are just > buzzwords, Agreed. The latter is simply incorrect for Python and I don't know why people say that. The statement from the Zen of Python is as follows: "There should be one-- and preferably only one --obvious way to do it." where 'it' is some reasonable common operation. This is a statement of *intent* that is opposed to "All possible ways of doing things should be included". The key word that people too often omit is *obvious* (once one learns Python). There are usually, of necessity, multiple ways to do something, but for common operations, there should be one way that is obvious to the experienced Python programmer. For instance, if you want to process the items of a collections, you can use normal recursion, tail recursion, while iteration, or for iteration. For the first three, you can use explicit or implicit conditions for flow control. (Implicit conditions are by try-except.) One can use various access methods to get the items. However, the one obvious, compact, and efficient way is 'for item in collection:'. This works with *any* collection with a proper __iter__ method.\ People accustomed to using tail recursion for this in other languages sometimes request that tail-call space optimization be added to make tail recursion a second 'obvious' way. Guido has refused because 1) there are real problems with the idea and 2) one obvious way is enough. Similarly, the obvious way to define a function is a def statement. One alternative, which Guido allowed to be added for the specific purpose of passing simple functions as arguments in function calls, is a lambda expression. Guido has rejected requests to expand lambda expressions to general function definitions. Again, there are real problems and one obvious way is enough. > because this was an example where in Python there are many > ways to do it while in Perl there is a single way used usually, which is > also more simple. Here I disagree. As I replied before, you are either ignoring the obvious Python way or talking about a rare need. -- Terry Jan Reedy From ian.g.kelly at gmail.com Mon May 23 13:31:22 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 23 May 2011 11:31:22 -0600 Subject: Writing multiple files with with-context In-Reply-To: <5142852e-bab9-4e39-a49b-0229e900e97d@glegroupsg2000goo.googlegroups.com> References: <5142852e-bab9-4e39-a49b-0229e900e97d@glegroupsg2000goo.googlegroups.com> Message-ID: On Sun, May 22, 2011 at 8:48 PM, Shunichi Wakabayashi wrote: > One idea is using contextlib.nested(), > > from contextlib import nested > > with nested(*[open('list_%d.txt' % i, 'w') for i in range(LIST_LEN)]) as fobjlist: > ?for i in range(1000): > ? ?fobjlist[random.randrange(LIST_LEN)].write(str(i)+"\n") > > with nested(*[open('dict_%s.txt' % k, 'w') for k in DICT_KEYS]) as fobjlist: > ?fobjdict = dict(zip(DICT_KEYS, fobjlist)) #convert list to dict > ?for i in range(1000): > ? ?fobjdict[random.choice(DICT_KEYS)].write(str(i)+"\n") > > On Python2.x, this is OK. but 3.x warns that nested() is deprecated. Not merely deprecated. It has already been removed in 3.2. > Another idea is to make container classes having __exit__() myself. > > class MyList(list): > ?def __enter__(self): > ? ?return [ v.__enter__() for v in self ] > ?def __exit__(self, exc_type, exc_value, traceback): > ? ?ret = False > ? ?for v in self: > ? ? ?if v.__exit__(exc_type, exc_value, traceback): > ? ? ? ?ret = True > ? ? ? ?exc_type = exc_value = traceback = None > ? ?return ret This has a number of subtle bugs in it: 1) Each context manager's __exit__ method is not loaded before the corresponding __enter__ method is invoked. 2) If the second context manager's __enter__ method raises an exception, the first context manager's __exit__ method is never called, breaking the with statement guarantee. 3) The __exit__ methods are called in the same order that the __enter__ methods were called. Since they form a stack, they should be called in the reverse order. These highlight the complexity of handling context managers correctly, which I think suggests that a custom implementation is probably a bad idea. > So, do you have another, more smart and pythonic way? Copy the implementation of contextlib.nested to your own custom module and use that. The last revision prior to its removal is here: http://hg.python.org/cpython/file/45506be44514/Lib/contextlib.py From nospam at torek.net Mon May 23 13:32:19 2011 From: nospam at torek.net (Chris Torek) Date: 23 May 2011 17:32:19 GMT Subject: Condition.wait(timeout) oddities References: <94d1d127-b423-4bd4-853c-d92da9ac7588@glegroupsg2000goo.googlegroups.com> Message-ID: In article <94d1d127-b423-4bd4-853c-d92da9ac7588 at glegroupsg2000goo.googlegroups.com> Floris Bruynooghe wrote: >I'm a little confused about the corner cases of Condition.wait() with a >timeout parameter in the threading module. > >When looking at the code the first thing that I don't quite get is that >the timeout should never work as far as I understand it. .wait() always >needs to return while holding the lock, therefore it does an .acquire() >on the lock in a finally clause. Thus pretty much ignoring the timeout >value. It does not do a straight acquire, it uses self._acquire_restore(), which for a condition variable, does instead: self.__block.acquire() self.__count = count self.__owner = owner (assuming that you did not override the lock argument or passed in a threading.RLock() object as the lock), due to this bit of code in _Condition.__init__(): # If the lock defines _release_save() and/or _acquire_restore(), # these override the default implementations (which just call # release() and acquire() on the lock). Ditto for _is_owned(). [snippage] try: self._acquire_restore = lock._acquire_restore except AttributeError: pass That is, lock it holds is the one on the "blocking lock" (the __block of the underlying RLock), which is the same one you had to hold in the first place to call the .wait() function. To put it another way, the lock that .wait() waits for is a new lock allocated for the duration of the .wait() operation: waiter = _allocate_lock() waiter.acquire() self.__waiters.append(waiter) saved_state = self._release_save() self._acquire_restore(saved_state) # the last stmt is the "finally" clause, I've just un-indented it which is entirely different from the lock that .wait() re-acquires (and which you held when you called .wait() initially) before it returns. >The second issue is that while looking around for this I found two bug >reports: http://bugs.python.org/issue1175933 and >http://bugs.python.org/issue10218. Both are proposing to add a return >value indicating whether the .wait() timed out or not similar to the >other .wait() methods in threading. However the first was rejected >after some (seemingly inconclusive) discussion. Tim Peters' reply seemed pretty conclusive to me. :-) >While the latter had >minimal discussion and and was accepted without reference to the earlier >attempt. Not sure if this was a process oversight or what, but it does >leave the situation confusing. >But regardless I don't understand how the return value can be used >currently: yes you did time out but you're still promised to hold the >lock thanks to the .acquire() call on the lock in the finally block. The return value is not generally useful for the reasons Tim Peters noted originally. Those are all still true even in the second discussion. >In my small brain I just can't figure out how Condition.wait() can both >respect a timeout parameter and the promise to hold the lock on return. Remember, "two different locks". :-) There is a lock on the state of the condition variable itself, and then there is a lock on which one actually waits. On both entry to and return from .wait(), you (the caller) hold the lock on the state of the condition variable, so you may inspect it and proceed based on the result. In between, you give up that lock, so that other threads may obtain it and change the state of the condition variable. >It seems to me that the only way to handle the timeout is to raise an >exception rather then return a value because when you get an exception >you can break the promise of holding the lock. That *would* be a valid way to implement a timeout -- to return with the condition variable lock itself no longer held -- but that would require changing lots of other code structure. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From varunaseneviratna at gmail.com Mon May 23 14:08:02 2011 From: varunaseneviratna at gmail.com (Varuna Seneviratna) Date: Mon, 23 May 2011 23:38:02 +0530 Subject: I installed Python 3 on Fedora 14 By Downloading python3.2 bziped source tarball and install it according to the README, Now How shall I uninstalled python 3.2? Message-ID: I installed Python 3 By Downloading python3.2 bziped source tarball and install it according to the README, Now How shall I uninstalled python 3.2? The README instructions are as below Build Instructions ------------------ On Unix, Linux, BSD, OSX, and Cygwin: ./configure make make test sudo make install From skunkworks at rikishi42.net Mon May 23 14:48:13 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Mon, 23 May 2011 20:48:13 +0200 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On 2011-05-20, Hans Georg Schaathun wrote: >: It starts with the misconception (or should I say confusion?) between >: performing a recursive job and using a recursive tool to do it. And then it >: blazes off in these huge discusions about semantics to define a definition >: of an abstraction of a alleady theoretical problem. > > And explaining the source of the misconception and the varying use > would be irrelevant? It usually is, yes. And boring. -- When in doubt, use brute force. -- Ken Thompson From kracethekingmaker at gmail.com Mon May 23 14:55:08 2011 From: kracethekingmaker at gmail.com (kracekumar ramaraju) Date: Mon, 23 May 2011 11:55:08 -0700 (PDT) Subject: Is there a better way to solve this? In-Reply-To: Message-ID: You can use sizeof function, >>> a=12234 >>> b=23456.8 >>> a.__sizeof__() 12 >>> b.__sizeof__() 16 So sizeof int is 12 bytes and float is 16 bytes From kracethekingmaker at gmail.com Mon May 23 14:55:08 2011 From: kracethekingmaker at gmail.com (kracekumar ramaraju) Date: Mon, 23 May 2011 11:55:08 -0700 (PDT) Subject: Is there a better way to solve this? In-Reply-To: Message-ID: You can use sizeof function, >>> a=12234 >>> b=23456.8 >>> a.__sizeof__() 12 >>> b.__sizeof__() 16 So sizeof int is 12 bytes and float is 16 bytes From skunkworks at rikishi42.net Mon May 23 14:56:03 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Mon, 23 May 2011 20:56:03 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <37nqa8-lpa.ln1@murmur.very.softly> On 2011-05-20, Steven D'Aprano wrote: > On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: > >> [I agree with you Xah that recursion is a technical word that should not >> be foisted onto lay users.] > > I think that is a patronizing remark that under-estimates the > intelligence of lay people and over-estimates the difficulty of > understanding recursion. Why would you presume this to be related to intelligence? The point was not about being *able* to understand, but about *needing* to understand in order to use. -- When in doubt, use brute force. -- Ken Thompson From orasnita at gmail.com Mon May 23 15:05:28 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Mon, 23 May 2011 22:05:28 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> Message-ID: <9F00F2A19C304079A16D8E4EDD6030C0@teddy> From: "Terry Reedy" > On 5/23/2011 4:49 AM, Octavian Rasnita wrote: > >> But let's remember from what this discussion started. This is not a >> Python critique, because each language has its own ways. >> I just wanted to show that the fact that "there is more than one way to >> do it" in Perl and that "there is a single way" in Python are just >> buzzwords, > > Agreed. The latter is simply incorrect for Python and I don't know why > people say that. The statement from the Zen of Python is as follows: > "There should be one-- and preferably only one --obvious way to do it." > where 'it' is some reasonable common operation. This is a statement of > *intent* that is opposed to "All possible ways of doing things should be > included". The key word that people too often omit is *obvious* (once > one learns Python). There are usually, of necessity, multiple ways to do > something, but for common operations, there should be one way that is > obvious to the experienced Python programmer. Yes you are right. And it is exactly the same in case of experienced Perl programmers. There is even a Perl book regarding the best practices, with many recommendations for the obvious way to do various things, and there is the module Perl::Critic with its command line percritic that follows those best practices very closely, so it is also just a buzzword that "there is more than one way to do it" for experienced Perl programmers. > > because this was an example where in Python there are many >> ways to do it while in Perl there is a single way used usually, which is >> also more simple. > > Here I disagree. As I replied before, you are either ignoring the > obvious Python way or talking about a rare need. I was talking about the method of creating a dictionary from an array which is much shorter and clear in Perl than in Python, and if you are using this very rarely, others might need to use it often. Octavian From ladasky at my-deja.com Mon May 23 15:51:36 2011 From: ladasky at my-deja.com (John Ladasky) Date: Mon, 23 May 2011 12:51:36 -0700 (PDT) Subject: Multiprocessing: don't push the pedal to the metal? References: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> Message-ID: <84e77cd9-9003-4053-a231-fe7d4bdbfef2@k15g2000pri.googlegroups.com> On May 23, 2:50?am, Adam Tauno Williams wrote: > I develop an app that uses multiprocessing heavily. ?Remember that all > these processes are processes - so you can use all the OS facilities > regarding processes on them. ?This includes setting nice values, > schedular options, CPU pinning, etc... That's interesting. Does code exist in the Python library which allows the adjustment of CPU pinning and nice levels? I just had another look at the multiprocessing docs, and also at os.subprocess. I didn't see anything that pertains to these issues. > > Each CPU (or core) has its own execution cache. If you can keep one > > thread running on the same core all the time, it will benefit more > > from that cache than if it has to keep flitting from one to another. > > +1 From sunrrrise at gmail.com Mon May 23 16:04:19 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Mon, 23 May 2011 13:04:19 -0700 (PDT) Subject: Odp: Re: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: Hello, I have checked another computer (WinXP, 32b) with Komodo Edit 6.1 and ActiveState Python 3.2 - problem still occurs. Have you received my email? s. From sunrrrise at gmail.com Mon May 23 16:04:19 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Mon, 23 May 2011 13:04:19 -0700 (PDT) Subject: Odp: Re: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: Hello, I have checked another computer (WinXP, 32b) with Komodo Edit 6.1 and ActiveState Python 3.2 - problem still occurs. Have you received my email? s. From drobinow at gmail.com Mon May 23 16:27:58 2011 From: drobinow at gmail.com (David Robinow) Date: Mon, 23 May 2011 16:27:58 -0400 Subject: Is there a better way to solve this? In-Reply-To: References: Message-ID: On Mon, May 23, 2011 at 2:55 PM, kracekumar ramaraju wrote: > You can use sizeof function, >>>> a=12234 >>>> b=23456.8 >>>> a.__sizeof__() > 12 >>>> b.__sizeof__() > 16 > So sizeof int is 12 bytes and float is 16 bytes I'm not sure what you're trying to show here, but try the following in Python 3.2 >>> a = 9999 >>> for i in range(5): ... a*= 100000 ... a.__sizeof__() ... From awilliam at whitemice.org Mon May 23 16:46:34 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 23 May 2011 16:46:34 -0400 Subject: Multiprocessing: don't push the pedal to the metal? In-Reply-To: <84e77cd9-9003-4053-a231-fe7d4bdbfef2@k15g2000pri.googlegroups.com> References: <644e4768-0fee-4c40-ba59-4b777b883884@z13g2000prk.googlegroups.com> <0211797f-e130-4bfa-bcb0-f701ec33c7b9@17g2000prr.googlegroups.com> <84e77cd9-9003-4053-a231-fe7d4bdbfef2@k15g2000pri.googlegroups.com> Message-ID: <1306183594.2945.5.camel@linux-yu4c.site> On Mon, 2011-05-23 at 12:51 -0700, John Ladasky wrote: > On May 23, 2:50 am, Adam Tauno Williams > wrote: > > I develop an app that uses multiprocessing heavily. Remember that all > > these processes are processes - so you can use all the OS facilities > > regarding processes on them. This includes setting nice values, > > schedular options, CPU pinning, etc... > That's interesting. Does code exist in the Python library which > allows the adjustment of CPU pinning and nice levels? I just had > another look at the multiprocessing docs, and also at os.subprocess. > I didn't see anything that pertains to these issues. "in the Python library" - no. All these types of behaviors are platform specific. For example you can set the "nice" (priority) of a UNIX/LINUX process using the nice method from the os module. Our workflow engine does this on all worker processes it starts - it sends the workers to the lowest priority. from os import nice as os_priority ... try: os_priority(20) except Exception, e: ... I'm not aware of a tidy way to call sched_setaffinity from Python; but my own testing indicates that the LINUX kernel is very good at figuring this out on its own so long as it isn't swamped. Queuing, rather than starting, additional workflows if load average exceeds X.Y and setting the process priority of workers to very-low seems to work very well. There is for setting affinity, but I haven't used it. From floris.bruynooghe at gmail.com Mon May 23 17:43:19 2011 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Mon, 23 May 2011 14:43:19 -0700 (PDT) Subject: Condition.wait(timeout) oddities In-Reply-To: Message-ID: <8cbdbf97-b9c8-4ae4-8573-89e9a5354a58@glegroupsg2000goo.googlegroups.com> On Monday, 23 May 2011 17:32:19 UTC, Chris Torek wrote: > In article > <94d1d127-b423-4bd4... at glegroupsg2000goo.googlegroups.com> > Floris Bruynooghe wrote: > >I'm a little confused about the corner cases of Condition.wait() with a > >timeout parameter in the threading module. > > > >When looking at the code the first thing that I don't quite get is that > >the timeout should never work as far as I understand it. .wait() always > >needs to return while holding the lock, therefore it does an .acquire() > >on the lock in a finally clause. Thus pretty much ignoring the timeout > >value. > > It does not do a straight acquire, it uses self._acquire_restore(), > which for a condition variable, does instead: > > self.__block.acquire() > self.__count = count > self.__owner = owner > > (assuming that you did not override the lock argument or passed > in a threading.RLock() object as the lock), due to this bit of > code in _Condition.__init__(): > > # If the lock defines _release_save() and/or _acquire_restore(), > # these override the default implementations (which just call > # release() and acquire() on the lock). Ditto for _is_owned(). > [snippage] > try: > self._acquire_restore = lock._acquire_restore > except AttributeError: > pass Ah, I missed this bit in the __init__() and the fact that RLock provides the _acquire_restore() and _release_save(). I was wondering why they jumped around via self._acquire_restore() and self._release_save(), it seemed rather a lot of undocumented effort for custom locks. > That is, lock it holds is the one on the "blocking lock" (the > __block of the underlying RLock), which is the same one you had > to hold in the first place to call the .wait() function. > > To put it another way, the lock that .wait() waits for is > a new lock allocated for the duration of the .wait() operation: That makes more sense now. I knew that really, just never quite realised until you wrote this here so clearly. Thanks. So essentially the condition's lock is only meant to lock the internal state of the condition and not meant to be acquired for long times outside that as .wait() calls will not be able to return. My confusion started from looking at queue.Queue which replaces the lock with a regular lock and uses it to lock the Queue's resource. I guess the Queue's mutex satisfies the requirement of never being held for long times. > >The second issue is that while looking around for this I found two bug > >reports: http://bugs.python.org/issue1175933 and > >http://bugs.python.org/issue10218. Both are proposing to add a return > >value indicating whether the .wait() timed out or not similar to the > >other .wait() methods in threading. However the first was rejected > >after some (seemingly inconclusive) discussion. > > Tim Peters' reply seemed pretty conclusive to me. :-) Which is why I'm surprised that it now does. Cheers Floris From tjreedy at udel.edu Mon May 23 18:06:36 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 May 2011 18:06:36 -0400 Subject: Is there a better way to solve this? In-Reply-To: References: Message-ID: On 5/23/2011 2:55 PM, kracekumar ramaraju wrote: > You can use sizeof function, Appears not to be in manuals, that I could find. As a special method, it is intended to be called through sys.getsizeof. >>>> a=12234 >>>> b=23456.8 >>>> a.__sizeof__() > 12 >>>> b.__sizeof__() > 16 > So sizeof int is 12 bytes and float is 16 bytes Depends on system. On my winxp machine, ints are 14 bytes. >>> import sys >>> size = sys.getsizeof >>> size(1) 14 >>> size(1.0) 16 >>> size([]) 36 >>> size([1,2,3]) 48 -- Terry Jan Reedy From d.awlberg at hotmail.invalid Mon May 23 18:27:11 2011 From: d.awlberg at hotmail.invalid (Deeyana) Date: Mon, 23 May 2011 22:27:11 +0000 (UTC) Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On Mon, 23 May 2011 00:52:07 -0700, asandroq wrote: > On May 23, 4:29?am, Deeyana wrote: >> >> You might be interested in Clojure, then. Lists are more abstracted, >> like in Scheme, and vectors and also dictionaries/maps and sets are >> first class citizens along side lists. And unlike Scheme, Clojure has >> good library/host interop support. You can write real-world >> applications in it without spontaneously combusting. > > Nonsense. Classic unsubstantiated and erroneous claim. Nothing that I write is ever "nonsense". > Several Scheme systems have excellent FFIs with more than "good library/ > host interop support". Classic unsubstantiated and erroneous claim. Scheme does not come OOTB with any suitable libraries for host interop and though it can make calls to C libraries, doing so is awkward and involves difficulties with the impedance mismatch between Scheme's data structures and C's char *, void *, int, double, array, etc. types. To top it off, C lacks automatic memory management, which means you'll have to concern yourself with manually disposing of allocated data structures used in interop. (Or, worse, things will get garbage collected by the Scheme runtime that the Scheme code no longer references, but the C library is still using, and bam! SIGSEGV.) And then you gain what, the diverse mix of platform-specific, unportable, sometimes-wonky C libraries? Versus Clojure immediately granting simple, easy to use access to a large standard Java library that works more or less the same across a broad range of host platforms, as well as the rest of the JVM library ecosystem, which mostly has the same qualities. Clojure being designed for the JVM, there's much less of an impedance mismatch with Java's types, and the interop call syntax is easy to master and won't set your hair on fire. From andrius.a at gmail.com Mon May 23 18:30:59 2011 From: andrius.a at gmail.com (Andrius) Date: Mon, 23 May 2011 15:30:59 -0700 (PDT) Subject: Unit testing beginner question Message-ID: Hello, would be gratefull for the explonation. I did a simple test case: def setUp(self): self.testListNone = None def testListSlicing(self): self.assertRaises(TypeError, self.testListNone[:1]) and I am expecting test to pass, but I am getting exception: Traceback (most recent call last): self.assertRaises(TypeError, self.testListNone[:1]) TypeError: 'NoneType' object is unsubscriptable I thought that assertRaises will pass since TypeError exception will be raised? Ta, Andrius From rosuav at gmail.com Mon May 23 18:42:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 May 2011 08:42:14 +1000 Subject: Strange behaviour of input() function (Python 3.2) In-Reply-To: References: Message-ID: On Tue, May 24, 2011 at 1:44 AM, Aleksander Pietkiewicz wrote: > Hello, > I have googled your email address, I hope it is not a problem. > Thank you for your help! I figured you would get it from my post, but either way works! My email address is fairly well known. Sorry for the delay in response; you caught me while I was asleep. :) I'm now responding on-list so that other people can help. > I agree that can be very specific bug, I suspect it is matter of coding. I'm > emailing you a *.py file as you asked and screenshot showing script being > run. Unfortunately my Windows install doesn't have internationalization support, which may be an issue here. I ran your 'couting.py' and got errors back: Traceback (most recent call last): File "foo.py", line 11, in n=input("Naci\u015bnij Enter aby zako\u0144czy\u0107...") File "C:\python32\lib\encodings\cp437.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character '\u015b' in position 4: character maps to So I'm guessing that codepage 437 is just plain wrong. But that shouldn't affect your system. > As you can see this problem occurs only with 3rd party software (like Komodo > Edit). > In, addition when I'm using Komodo or Notepad++ and input() function, Python > miscount bytes. See attached. > Once again thank you for your help! > Kind regards, > Aleksander Pietkiewicz My suspicion here is that your editor is saving using one encoding, and Python is expecting another. I recommend you put an encoding marker at the top of your source file: # coding=utf-8 See http://www.python.org/dev/peps/pep-0263/ for details. With this in place, you should be able to guarantee that the bytestream is parsed the same way by editor and interpreter. Unfortunately that's all I could offer; I was unable to duplicate the exact problem you were seeing. The contents of 'couting.py' are simple enough, so I'll paste here in case anyone can spot a problem: s = (input('Enter something : ')) z = input('Enter something : ') print('Length of the string s is', len(s)) print('Length of the string z is', len(z)) print(s) print(z) Point to note: On my Windows XP, the string lengths are one higher than expected, and they include a \r at the end. Is there any way that this could trigger a Unicode parse failure?? Chris Angelico From ian.g.kelly at gmail.com Mon May 23 18:46:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 23 May 2011 16:46:52 -0600 Subject: Unit testing beginner question In-Reply-To: References: Message-ID: On Mon, May 23, 2011 at 4:30 PM, Andrius wrote: > and I am expecting test to pass, but I am getting exception: > Traceback (most recent call last): > ? ?self.assertRaises(TypeError, self.testListNone[:1]) > TypeError: 'NoneType' object is unsubscriptable > > I thought that assertRaises will pass since TypeError exception will > be raised? The second argument to assertRaises must be a function that assertRaises will call. assertRaises can't catch the error above because it is raised when the argument is evaluated, before assertRaises has even been called. This would work: self.assertRaises(TypeError, lambda: self.testListNone[:1]) Cheers, Ian From andrius.a at gmail.com Mon May 23 18:49:48 2011 From: andrius.a at gmail.com (Andrius A) Date: Mon, 23 May 2011 23:49:48 +0100 Subject: Unit testing beginner question In-Reply-To: References: Message-ID: That was quick! Thanks Ian On 23 May 2011 23:46, Ian Kelly wrote: > On Mon, May 23, 2011 at 4:30 PM, Andrius wrote: > > and I am expecting test to pass, but I am getting exception: > > Traceback (most recent call last): > > self.assertRaises(TypeError, self.testListNone[:1]) > > TypeError: 'NoneType' object is unsubscriptable > > > > I thought that assertRaises will pass since TypeError exception will > > be raised? > > The second argument to assertRaises must be a function that > assertRaises will call. assertRaises can't catch the error above > because it is raised when the argument is evaluated, before > assertRaises has even been called. > > This would work: > > self.assertRaises(TypeError, lambda: self.testListNone[:1]) > > Cheers, > Ian > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon May 23 20:03:17 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 May 2011 00:03:17 GMT Subject: Is there a better way to solve this? References: Message-ID: <4ddaf5c4$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 May 2011 11:55:08 -0700, kracekumar ramaraju wrote: > You can use sizeof function, Who are you talking to, and what question did they ask? Please always quote enough of the post that you are replying to to establish context. >>>> a=12234 >>>> b=23456.8 >>>> a.__sizeof__() > 12 >>>> b.__sizeof__() > 16 > So sizeof int is 12 bytes and float is 16 bytes You shouldn't be calling special methods directly (except under unusual circumstances). That's like calling s.__len__() instead of len(s). The public function for getting the size of an object is in the sys module: sys.getsizeof(a) -- Steven From greg.ewing at canterbury.ac.nz Mon May 23 20:04:53 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 24 May 2011 12:04:53 +1200 Subject: Abandoning Python In-Reply-To: <4dd9ffc1$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <93tqifFnb2U1@mid.individual.net> <4dd9ffc1$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <940b18Fc0pU1@mid.individual.net> Steven D'Aprano wrote: > On Mon, 23 May 2011 13:11:40 +1200, Gregory Ewing wrote: > >>...until you want to read someone *else's* code, that is. > > The same might be said about Python, which supports procedural, OO and > functional styles out of the box. But it only uses *one* syntax and core set of concepts to cover all of those. Unlike, apparently, Falcon... take a look at this page concerning how Falcon approaches functional programming (but don't look for too long or your eyes may begin to bleed...) http://falconpl.org/index.ftd?page_id=sitewiki&prj_id=_falcon_site&sid=wiki&pwid=Survival%20Guide&wid=Survival%3AFunctional+programming Falcon seems to collect programming paradigms the way Perl collects language features, i.e. by just munging them all together and bending parts until they fit. -- Greg From steve+comp.lang.python at pearwood.info Mon May 23 20:18:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 May 2011 00:18:19 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> Message-ID: <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 May 2011 20:56:03 +0200, Rikishi42 wrote: > On 2011-05-20, Steven D'Aprano > wrote: >> On Thu, 19 May 2011 22:13:14 -0700, rusi wrote: >> >>> [I agree with you Xah that recursion is a technical word that should >>> not be foisted onto lay users.] >> >> I think that is a patronizing remark that under-estimates the >> intelligence of lay people and over-estimates the difficulty of >> understanding recursion. > > Why would you presume this to be related to intelligence? The point was > not about being *able* to understand, but about *needing* to understand > in order to use. Maybe they don't "need" to understand recursion. So what? Recursion is a perfectly good English word, no more technical than "accelerate" or "incinerate" or "dissolve" or "combustion". Do people need to know the word "combustion" when they could say "burn" instead? Do they need to know the words "microwave oven" when they could be saying "invisible rays cooking thing"? I wonder whether physicists insist that cars should have a "go faster pedal" because ordinary people don't need to understand Newton's Laws of Motion in order to drive cars? Who are you to say that people shouldn't be exposed to words you deem that they don't need to know? -- Steven From roy at panix.com Mon May 23 20:19:01 2011 From: roy at panix.com (Roy Smith) Date: Mon, 23 May 2011 20:19:01 -0400 Subject: Unit testing beginner question References: Message-ID: In article , Ian Kelly wrote: > This would work: > > self.assertRaises(TypeError, lambda: self.testListNone[:1]) If you're using the version of unittest from python 2.7, there's an even nicer way to write this: with self.assertRaises(TypeError): self.testListNone[:1] From rantingrick at gmail.com Mon May 23 20:21:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 23 May 2011 17:21:50 -0700 (PDT) Subject: Abandoning Python References: <93tqifFnb2U1@mid.individual.net> <4dd9ffc1$0$29988$c3e8da3$5496439d@news.astraweb.com> <940b18Fc0pU1@mid.individual.net> Message-ID: <89109704-1682-4516-9fd9-66116668e4c3@k16g2000yqm.googlegroups.com> On May 23, 7:04?pm, Gregory Ewing wrote: > Falcon seems to collect programming paradigms the way Perl > collects language features, i.e. by just munging them all > together and bending parts until they fit. Not that i am picking on anyone here... but... Why is okay to rip apart Perl with jagged metal teeth (and not that i am complaining mind you) however if anyone even hints about Ruby being somewhat ...oh let's say "asinine" or how about "redundant"... all the Ruby trolls crawl out the woodwork and start bashing you in the head with a recursive iterator? Do they not understand that Ruby is nothing more than Perl's "mini-me" bent on displacing the glory of Python with Perl style obfuscation, squiggly variable decorators, and redundant syntaxes so horrific that even Tim Toady would blush in embarrassment? From gagsl-py2 at yahoo.com.ar Mon May 23 20:41:06 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 May 2011 21:41:06 -0300 Subject: Multiple file select with tkFileDialog passes back 'decorated' strings (sometimes) References: <4dda5a89$0$49175$e4fe514c@news.xs4all.nl> Message-ID: En Mon, 23 May 2011 10:00:53 -0300, Alex van der Spek escribi?: > I switched from Mark Hammonds pywin32 extensions for file choosers as > the multiselect there seems to crash on me when selecting more than a > few dozen. Using Tk now. Works well but the resulting string passed back > seems to 'decorated' when the files are on local disk and not decorated > when retrieved over a USB interface from an external disk? > > I do this: > >> From local disk I get back: > > '{file1.bin} {file2.bin}' > >> From external disk I get back: > > 'file1.bin file2.bin' > > I can handle/parse both, not an issue but it raises the question: Are > these the only two possibilities? Is it the same across platforms (I use > Python 2.7 on Win Vista)? An old bug. See http://bugs.python.org/issue5712 for a workaround. -- Gabriel Genellina From dan.kluev at gmail.com Mon May 23 23:34:52 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 24 May 2011 14:34:52 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <57C0AB91B42743E89456ACCC8751CF78@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> Message-ID: On Mon, May 23, 2011 at 10:10 PM, Octavian Rasnita wrote: > is not so nice as > > $d = @a; It is 'not so nice' only in your perception. Python clearly defines dict as container of (key, value) pairs, and therefore its constructor expects such pairs. Adding unjustified arbitrary ways to guess such pairs out of linear list is exactly what is being bashed here. Is is considered to be wrong and bad. Moreover, you are comparing apples to oranges here, and then complaining that apples somehow turned out to be not oranges. If we take python way of defining dicts and check it in perl, we find that it is not supported, so obviously perl is non-intuitive and does not support clear and easy way of defining hashes from list of key-value pairs: @l = ([1, 2], [3, 4],); %d = @l; for $k ( keys %d ) { print "$k\n"; } which outputs single ARRAY(0x804e158) instead of proper 1, 3, as it does in python: >>> dict([[1,2], [3,4]]).keys() [1, 3] This is yet another example that you are just trolling here, making silly and unbacked claims, and ignoring any valid arguments you receive. -- With best regards, Daniel Kluev From xahlee at gmail.com Tue May 24 00:20:22 2011 From: xahlee at gmail.com (Xah Lee) Date: Mon, 23 May 2011 21:20:22 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: On May 22, 4:32?pm, Chris Angelico wrote: > On Mon, May 23, 2011 at 9:17 AM, Xah Lee wrote: > > the context is this: In emacs directory manager (aka dired), when you > > call dired-do-delete on a directory, emacs prompts, this way: > > ?Recursive delete of xx? (y or n)? > > But in order to make your point (such as it is), you are ignoring the > fact that there are other uses of the term 'recurse' or 'recursive', > and consistency and clarity are important. I don't see emacs offering > me a chance to do a non-recursive delete; the only issue here seems to > be that it's explicit that it is going to destroy an entire branch of > the directory tree. If this is such a problem, grab the emacs sources > and change that string - it probably occurs in exactly one place in > the code. Voila! You now have The One True Perfect Emacs, the ultimate > text editor, because it no longer tells you that it's working > recursively. > > *removes tongue from cheek after saying that last sentence* > > Chris Angelico why don't you file a bug report? In GNU Emacs 23.2, it's under the Help menu. I suppose it's the same in other emacs distro. Xah From rosuav at gmail.com Tue May 24 00:28:13 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 May 2011 14:28:13 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: On Tue, May 24, 2011 at 2:20 PM, Xah Lee wrote: > why don't you file a bug report? In GNU Emacs 23.2, it's under the > Help menu. I suppose it's the same in other emacs distro. > Because I do not consider its behaviour to be errant. And I suspect its main developers won't either. That's why I suggested you grab the sources and make The Perfect Emacs. Chris Angelico From john at castleamber.com Tue May 24 01:17:55 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 00:17:55 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> Message-ID: <87sjs44qyk.fsf@castleamber.com> "Octavian Rasnita" writes: > From: "Daniel Kluev" > a = [1,2] > dict([a]) > > Yes, but > > d = dict([a]) > > is not so nice as > > $d = @a; That will give you the number of elements in @a. What you (probably) mean is %hash = @array; -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From jussij at zeusedit.com Tue May 24 01:19:23 2011 From: jussij at zeusedit.com (JussiJ) Date: Mon, 23 May 2011 22:19:23 -0700 (PDT) Subject: Make Python "portable" by default! (Re: Python IDE/text-editor) References: <8739lij2h7.fsf@benfinney.id.au> <87r59269y4.fsf@castleamber.com> <8739licppk.fsf@castleamber.com> <4da9f850$0$3947$426a74cc@news.free.fr> <87sjthlu78.fsf@castleamber.com> <1302993113.2774.0.camel@localhost.localdomain> <20110417111325.4fa995b0.feliphil@gmx.net> Message-ID: On Apr 17, 7:13 pm, Wolfgang Keller wrote: > > You can't run Python programs without a Python interpreter installed. > > Wrong. > > See e.g.http://www.portablepython.com/ In this case Python is still installed on the machine. It may not be installled on the PC's hard disk but it is certainly is installed on the USB stick. In other words the act of inserting the USB actually results in the software being 'Installed' (i.e. being made available) on the PC. Jussi From orasnita at gmail.com Tue May 24 01:25:42 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 08:25:42 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: From: "Ulrich Eckhardt" > Ahem, is this Java the language that a certain, well-known service > provider > is getting screwed over hard currently, because they forgot to read the > fineprint in the declaration of freedom? And this Objective C, isn't this > the language that GCC had support for since before it properly supported > C++, and that on a multitude of targets? Someone also said that C# can be used under Mono and even though this is true, C# still remains a proprietary language that can be totally changed if MS wants that, as well as Objective C can be changed if Apple wants that. So what matters is if the most important developers for a specific language/platform are releasing the code as open source or they keep it proprietary and I don't see a big number of programmers developing code in C# and Objective C. About Java... you may be right. :-) Octavian From orasnita at gmail.com Tue May 24 01:39:42 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 08:39:42 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><2EA88E7D68664EB3A4A49FA332E0E7EB@octavian><46EA3D502B204937A4EE89E34471BC0F@octavian> Message-ID: From: "Daniel Kluev" > On Mon, May 23, 2011 at 10:17 PM, Octavian Rasnita > wrote: >> From: "Daniel Kluev" >> Aha, so with other words that ORM doesn't have that feature. >> DBIX::Class also use the DateTime module, but it can use it directly, >> without needing to write more code for that, and it can also return >> localized dates. > > Once again. ORMs return _python builtin type_. Localization is not > their responsibility, and plugging it there is code bloat, rather than > feature. Sure you may ask ORM to handle JSONRPC requests on its own, > but ORM responsibility is to map RDBMS features to language objects. Who said that? The ORM responsability is to map RDBMS to the objects you need, not to the language objects. If the ORM can do that directly by just adding a configuration instead of needing to manually use of other modules, why is this bloat? You add that configuration only if you need it, not always, and it is much more simple. > All good python packages limit their functionality to specific field, > so you could choose one you prefer for each different task > independently. All the Perl modules do the same, but some of the Perl modules accept plugins that make easier the collaboration of different modules which are needed often, and the need of localizing the date is a feature used often. >> without needing to load the DateTime module manually and to initialize >> the DateTime object manually... > > This is basically stating that you didn't read the code I posted. > Where did you ever find "initialize the DateTime object manually"? > Sorry, but its pointless to discuss anything if you don't want to even > read properly examples you receive. You told that you need to use another module for localizing the date because the ORM returns just a language date object that doesn't do that. Octavian From orasnita at gmail.com Tue May 24 02:00:14 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 09:00:14 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian><57C0AB91B42743E89456ACCC8751CF78@octavian> Message-ID: <2C6966D5AB6541E3BCE920FE7883A05B@octavian> From: "Daniel Kluev" > Moreover, you are comparing apples to oranges here, and then > complaining that apples somehow turned out to be not oranges. > If we take python way of defining dicts and check it in perl, we find > that it is not supported, so obviously perl is non-intuitive and does > not support clear and easy way of defining hashes from list of > key-value pairs: > @l = ([1, 2], [3, 4],); > %d = @l; > for $k ( keys %d ) { print "$k\n"; } > > which outputs single ARRAY(0x804e158) instead of proper 1, 3, as it > does in python: > >>>> dict([[1,2], [3,4]]).keys() > [1, 3] > > This is yet another example that you are just trolling here, making > silly and unbacked claims, and ignoring any valid arguments you > receive. You are showing a code but tell another thing. If it would be as you said, I should have said that if in Perl a dictionary is made from a list using %d = @l; then in Python it should be l = d because it would be more nice. But I didn't say that. I said that it would be nice to be able to use something like d = dict(l) using the Python "dict" statement for creating dicts. And OK, Python needs another pair of brackets for doing that and this is no problem, but the result is that the Python's syntax is not as shorter and nice as Perl's, for the same thing. This is what that I said. And you are telling that in Perl should be used an even more complicated and ugly syntax just for beeing the same as in Python just for showing that I am wrong, but I was comparing just the shortness and cleraness of the code. So, again, in Perl is just: %d = @l; Please tell me if Python has a syntax which is more clear than this for doing this thing. It doesn't matter if it is different or if it follows another syntax. And again, I am not trolling anything. I am just defending a language which has a clearer syntax for doing some things, and a shorter code for other things, and which uses less braces and brackets than Python for other things, and which has a single-recommended way for doing some things, even though other list members were trolling about Perl, but nobody said something against. Octavian From stefan_ml at behnel.de Tue May 24 02:23:55 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 24 May 2011 08:23:55 +0200 Subject: Why did Quora choose Python for its development? In-Reply-To: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: Beliavsky, 20.05.2011 18:39: > I thought this essay on why one startup chose Python was interesting. Since everyone seems to be hot flaming at their pet languages in this thread, let me quickly say this: Thanks for sharing the link. Stefan From orasnita at gmail.com Tue May 24 04:08:17 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 11:08:17 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> Message-ID: From: "John Bokma" > "Octavian Rasnita" writes: > >> From: "Daniel Kluev" >> a = [1,2] >> dict([a]) >> >> Yes, but >> >> d = dict([a]) >> >> is not so nice as >> >> $d = @a; > > That will give you the number of elements in @a. What you (probably) > mean is %hash = @array; Of course. Thank you for correction. Octavian From orasnita at gmail.com Tue May 24 04:10:36 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 11:10:36 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: <141C5F3E5EA34913884EE6007F95A1E0@octavian> From: "Stefan Behnel" > Beliavsky, 20.05.2011 18:39: >> I thought this essay on why one startup chose Python was interesting. > > Since everyone seems to be hot flaming at their pet languages in this > thread, let me quickly say this: > > Thanks for sharing the link. Maybe I have missed a message, but if I didn't, please provide that link. I am always interested to find the best solutions. Thanks. Octavian From rosuav at gmail.com Tue May 24 04:20:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 May 2011 18:20:44 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <141C5F3E5EA34913884EE6007F95A1E0@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <141C5F3E5EA34913884EE6007F95A1E0@octavian> Message-ID: On Tue, May 24, 2011 at 6:10 PM, Octavian Rasnita wrote: > From: "Stefan Behnel" >> >> Beliavsky, 20.05.2011 18:39: >>> >>> I thought this essay on why one startup chose Python was interesting. >> >> Since everyone seems to be hot flaming at their pet languages in this >> thread, let me quickly say this: >> >> Thanks for sharing the link. > > > Maybe I have missed a message, but if I didn't, please provide that link. > I am always interested to find the best solutions. At the beginning of the thread, three days and forty-odd messages ago, this was posted: http://www.quora.com/Why-did-Quora-choose-Python-for-its-development It's the reason for the thread title, regardless of the current thread content :) Chris Angelico From nambo4jb at gmail.com Tue May 24 04:31:37 2011 From: nambo4jb at gmail.com (Cathy James) Date: Tue, 24 May 2011 03:31:37 -0500 Subject: NEED HELP- read file contents, while loop to accept user input, and enter to exit Message-ID: dear mentor, I need help with my code: 1) my program won't display file contents upon opening 2) my program is not writing to file 3) my program is not closing when user presses enter- gow do I do this with a while loop? please see my attempt below and help: #1) open file and display current file contents: f = open ('c:/testing.txt'', 'r') f.readlines() #2) and 3) use while loop to write user input to file, save to file, close when press enter: while True: s = input ('enter name: ').strip() f = open ('c:/testing.txt', 'a') if f.writable(): f.write(s) break else: f = open ('c:/testing.txt', 'r') f.readlines() for line in f: print (line) -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue May 24 04:46:11 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 May 2011 09:46:11 +0100 Subject: NEED HELP- read file contents, while loop to accept user input, and enter to exit In-Reply-To: References: Message-ID: <4DDB7053.4080109@timgolden.me.uk> On 24/05/2011 09:31, Cathy James wrote: > dear mentor, > I need help with my code: > 1) my program won't display file contents upon opening > #1) open file and display current file contents: > f = open ('c:/testing.txt'', 'r') > f.readlines() If you're running this in an interactive interpreter, I would expect it to show a list of lines (assuming c:/testing.txt has something in it...). If you're running it as a program, though, it won't show anything: you need to actually output the result of the expression f.readlines (). It only happens at the interpreter as a development convenience: f = open ("c:/testing.txt", "r") print f.readlines () # or print (f.readlines ()) if you're in Python 3 TJG From rosuav at gmail.com Tue May 24 04:46:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 May 2011 18:46:32 +1000 Subject: NEED HELP- read file contents, while loop to accept user input, and enter to exit In-Reply-To: References: Message-ID: On Tue, May 24, 2011 at 6:31 PM, Cathy James wrote: > ??? s = input ('enter name: ').strip() Are you using Python 2 or Python 3? If it's Python 2, this should be raw_input(). > ??? f = open ('c:/testing.txt', 'a') > ... > ??????? f = open ('c:/testing.txt', 'r') You may be having trouble here as a result of not closing the file and then trying to reopen it. Also, at some point you have to check if 's' (the user's inputted string) is empty. You can then leave the loop using the 'break' statement. Hope that helps! Best of luck with your homework. Chris Angelico From harrismh777 at charter.net Tue May 24 04:47:31 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 24 May 2011 03:47:31 -0500 Subject: I installed Python 3 on Fedora 14 By Downloading python3.2 bziped source tarball and install it according to the README, Now How shall I uninstalled python 3.2? In-Reply-To: References: Message-ID: Varuna Seneviratna wrote: > Now How shall I uninstalled > python 3.2? > Now, how shall I remove Python 3.2 ? ... very carefully. It might be nice if there were a label in the Makefile so this would work: sudo make removeall ... but alas, why do you want to un-install Python3.2 ? From dan.kluev at gmail.com Tue May 24 04:55:40 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 24 May 2011 19:55:40 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: <2C6966D5AB6541E3BCE920FE7883A05B@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: On Tue, May 24, 2011 at 5:00 PM, Octavian Rasnita wrote: > And you are telling that in Perl should be used an even more complicated and > ugly syntax just for beeing the same as in Python just for showing that I am > wrong, but I was comparing just the shortness and cleraness of the code. > > So, again, in Perl is just: > > %d = @l; Once again. Suppose we have array of key-value pairs (two-dimensional array), `l`. In python, converting it to dict is as simple as d = dict(l). In perl, %d = @l; produces meaningless value. Following your logic, this means that perl has ugly syntax. -- With best regards, Daniel Kluev From clp2 at rebertia.com Tue May 24 04:58:25 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 24 May 2011 01:58:25 -0700 Subject: NEED HELP- read file contents, while loop to accept user input, and enter to exit In-Reply-To: References: Message-ID: On Tue, May 24, 2011 at 1:31 AM, Cathy James wrote: > dear mentor, > > I need help with my code: In addition to what others have already said... > please see my attempt below and help: > > #1) open file and display current file contents: > f = open ('c:/testing.txt'', 'r') > f.readlines() > #2)? and 3) use while loop? to write user input to file, save to file, close > when press enter: > while True: > ??? s = input ('enter name: ').strip() > ??? f = open ('c:/testing.txt', 'a') > ??? if f.writable(): Since you *just* opened the file in append mode, this condition will *always* be true (append mode implies writability), so your `else` clause will *never* be executed. > ??????? f.write(s) > ??????? break > ??? else: > ??????? f = open ('c:/testing.txt', 'r') > ??????? f.readlines() > ??????? for line in f: > ??????????? print (line) Similar beginner questions would be best directed to Python's Tutor mailinglist: http://mail.python.org/mailman/listinfo/tutor Cheers, Chris From rosuav at gmail.com Tue May 24 05:07:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 May 2011 19:07:21 +1000 Subject: [Savoynet] More 'vast heavin' In-Reply-To: <4DDB7455.6060607@threelittlemaids.co.uk> References: <145486.48144.qm@web125410.mail.ne1.yahoo.com> <4DDB7455.6060607@threelittlemaids.co.uk> Message-ID: On Tue, May 24, 2011 at 7:03 PM, Larry Simons wrote: > On Tue 24/05/2011 04:11, Libby Moyer wrote: >> >> And the rhymes in Mikado! > > Are you referring to ablutioner, diminutioner and ?you shun her? all rhymed > with executioner? > Can't deny that they're grin-worthy! (Or groan-worthy, I always get those two mixed up.) ChrisA From harrismh777 at charter.net Tue May 24 05:09:24 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 24 May 2011 04:09:24 -0500 Subject: I installed Python 3 on Fedora 14 By Downloading python3.2 bziped source tarball and install it according to the README, Now How shall I uninstalled python 3.2? In-Reply-To: References: Message-ID: <7BKCp.14174$241.932@newsfe07.iad> Varuna Seneviratna wrote: > Now How shall I uninstalled > python 3.2? What --prefix did you use? default? From jeanmichel at sequans.com Tue May 24 05:22:58 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 24 May 2011 11:22:58 +0200 Subject: NEED HELP- read file contents, while loop to accept user input, and enter to exit In-Reply-To: References: Message-ID: <4DDB78F2.2050804@sequans.com> Cathy James wrote: > > f = open ('c:/testing.txt'', 'r') replace the double quote by a single quote. JM From claudiu at virtuamagic.com Tue May 24 06:01:24 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Tue, 24 May 2011 13:01:24 +0300 Subject: File access denied after subprocess completion on Windows platform Message-ID: <201105241301.28431.claudiu@virtuamagic.com> Hello, I have a program that uses pyside for an QT interface and a thread that downloads a lot of files. The thread is created with QThread object. But my problem I don't think it's QT related. The thread retrieves with pycurl a file that contains a list of files and start to downloads them. The downloading is done as following: - instantiate a Curl object - open the file on local filesystem for write in binary mode (in a try block), with the name suffixed with .part. - pass the description to the curl object for save. - curl retrieve and save it. It has also a callback function that updates the interface, sending a QT signal to the interface. (1) - use os.rename to rename the file with .part sufix to the final file. On my interface I have 3 buttons. One of the buttons runs an .exe file. One button closes the interface and one is deactivated. On the button that runs the exe I have a callback function that uses subprocess.Popen (for not waiting) for running a program (.exe) and returns. For now I configured to run calc.exe. The callback is not defined inside the downloader thread. It's defined globally (nor in QMainWindow object). The problem appears when I close the called program (in our case calc.exe). The (1) part (the call of os.rename) raise an exception: (32, 'The process cannot access the file because it is being used by another process') [Error 32] The process cannot access the file because it is being used by another process Question is why? And how to avoid this issue? The same program on Linux works very fine (that's because Linux doesn't has this violation access)! If I remove (1) part the program works fine. Somehow after closing the spawned process (calc.exe - you see, it has nothing to do with a open file somewhere else) the thread losses the acces to the current opened file by itself. -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From darcy at druid.net Tue May 24 06:05:35 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 24 May 2011 06:05:35 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <2C6966D5AB6541E3BCE920FE7883A05B@octavian> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: <20110524060535.64cfa0ec.darcy@druid.net> On Tue, 24 May 2011 09:00:14 +0300 "Octavian Rasnita" wrote: > So, again, in Perl is just: > > %d = @l; > > Please tell me if Python has a syntax which is more clear than this for > doing this thing. How is that clear? "Shorter" != "clearer." A Python programmer looking at that sees line noise. A Perl programmer looking at "d = dict ([a])" (or even "d = dict(a,)") sees something that has something to do with creating a dictionary. At least he would know in which section of the manual to look for more information. > And again, I am not trolling anything. I am just defending a language which > has a clearer syntax for doing some things, and a shorter code for other Are Perl programmers aware of some imminent worldwide shortage of electrons that Python programmers are not? Why is there this obsession with shortness? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Tue May 24 06:09:27 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 24 May 2011 06:09:27 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <87sjs44qyk.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> Message-ID: <20110524060927.778a4a6a.darcy@druid.net> On Tue, 24 May 2011 00:17:55 -0500 John Bokma wrote: > > $d = @a; > > That will give you the number of elements in @a. What you (probably) > mean is %hash = @array; If I was even considering using Perl, this one exchange would send me screaming in the opposite direction. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From as at sci.fi Tue May 24 06:45:09 2011 From: as at sci.fi (Anssi Saari) Date: Tue, 24 May 2011 13:45:09 +0300 Subject: how to get PID from subprocess library References: Message-ID: TheSaint writes: > self.handle= \ > xmlrpclib.ServerProxy('http://localhost:%s/rpc' %int(self.numport)) Couldn't you just try to call something via this handle, like self.handle.aria2.getVersion()? If there's an error, then start aria2 as a daemon and try again. From markrrivet at aol.com Tue May 24 08:01:26 2011 From: markrrivet at aol.com (markrrivet at aol.com) Date: Tue, 24 May 2011 08:01:26 -0400 Subject: Python 3.2 Idle doesn't start. No error message. Message-ID: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> Hello all. I have Python 2.71 installed on my Windows 7 laptop and it runs fine. I was having a problem with Python 3.2, 32bit, not starting with an error message saying this application has quit abnormally. That was fixed when I took the PYTHONPATH statement out of my environment variables. However, now when I try to start Idle, I can see some hard drive activity, but Idle for Python 3.2 does not start; nothing happens. Any clues as to the problem here? From mail at timgolden.me.uk Tue May 24 09:09:02 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 May 2011 14:09:02 +0100 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: <201105241301.28431.claudiu@virtuamagic.com> References: <201105241301.28431.claudiu@virtuamagic.com> Message-ID: <4DDBADEE.9060800@timgolden.me.uk> On 24/05/2011 11:01, Claudiu Nicolaie CISMARU wrote: > The problem appears when I close the called program (in our case > calc.exe). The (1) part (the call of os.rename) raise an exception: > > > (32, 'The process cannot access the file because it is being used by > another process') > [Error 32] The process cannot access the file because it is being used > by another process Try running procexp to see if it can see what's happening to the handle. It's possible it's a virus checker / indexer, although they'd tend to allow the file to be deleted out from under them. It's not quite clear from your description above whether you can be sure that the called subprocess has closed all its handles by the time the os.rename runs. TJG From k.sahithi2862 at gmail.com Tue May 24 09:13:58 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 24 May 2011 06:13:58 -0700 (PDT) Subject: GOOD STUDY METERIAL Message-ID: GOOD STUDY MATERIAL FOR KIDS http://studymaterialforu.blogspot.com UNIX INTERVIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/unix-interview-questions.html JAVA INTERVIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/java-interview-questions.html C ++ INTERVIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/c-interview-questions.html CIVILS INTERCIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/civils-interview-questions-and-answers.html DIGITAL LOGIC INTERCIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/digital-logic-design-interview.html MICROPROCESSOR INTERVIEW QUESTIONS http://studymaterialforu.blogspot.com/2011/04/microprocessor-interview-questions.html From tlikonen at iki.fi Tue May 24 09:18:21 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Tue, 24 May 2011 16:18:21 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: <8762p0kzj6.fsf@mithlond.arda> * 2011-05-24T06:05:35-04:00 * D'Arcy J. M. Cain wrote: > On Tue, 24 May 2011 09:00:14 +0300 > "Octavian Rasnita" wrote: >> %d = @l; >> >> Please tell me if Python has a syntax which is more clear than this >> for doing this thing. > > How is that clear? "Shorter" != "clearer." A Python programmer looking > at that sees line noise. I'm a Lisp programmer who sees (some) Python code as line noise. >> I am just defending a language which has a clearer syntax for doing >> some things, and a shorter code for other > > Are Perl programmers aware of some imminent worldwide shortage of > electrons that Python programmers are not? Why is there this obsession > with shortness? I don't know but from the point of view of a Lisp programmer Python has the same obsession. Not trolling, I just wanted to point out that these are just point of views. I don't actually care that much about these things. From nobody at nowhere.net.no Tue May 24 09:36:40 2011 From: nobody at nowhere.net.no (TheSaint) Date: Tue, 24 May 2011 21:36:40 +0800 Subject: how to get PID from subprocess library References: Message-ID: Anssi Saari wrote: > Couldn't you just try to call something via this handle, like > self.handle.aria2.getVersion()? If there's an error, then start aria2 > as a daemon and try again. > Very good, you're right. Furthermore I should avoid to call that function several times. I think to join it with __init__ function The program on exit must tell aria2c to quit. -- goto /dev/null From kw at codebykevin.com Tue May 24 10:09:19 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 24 May 2011 10:09:19 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: <88a86$4ddbbc22$4275d90a$404@FUSE.NET> On 5/22/11 3:44 AM, Octavian Rasnita wrote: > Somebody told that C# and Objective C are good languages. They might be good, but they are proprietary, and not only that they are proprietary, but they need to be ran under platforms that cannot be used freely, so from the freedom point of view, Perl, Ruby, Python and Java are the ways to go. Proprietary? Licensing options for C# in its Mono (Free Platform) implementation: http://www.mono-project.com/Licensing Licensing options for Objective-C in its GNUStep (Free Platform) implementaiton http://www.gnustep.org/information/aboutGNUstep.html It may be true that these languages are more widely used on their originating platforms (Windows, OS X) than on Linux, but these implementations are definitely open source. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From mail at timgolden.me.uk Tue May 24 10:40:53 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 May 2011 15:40:53 +0100 Subject: os.access giving incorrect results on Windows In-Reply-To: <21581D39FA3BDF40904D75AF9653CE26065680B9@blrex.prog.altair.com> References: <21581D39FA3BDF40904D75AF9653CE26065680B9@blrex.prog.altair.com> Message-ID: <4DDBC375.3020303@timgolden.me.uk> On 20/05/2011 12:26, Ayaskanta Swain wrote: > Thanks for the reply and suggestions. I followed the patch provided by > you in issue 2528, but the code looks very tricky to me. OK, first a summary of the discussion on the python-dev thread. Essentially it was felt that os.access was sufficiently shaky and unuseful on Windows that it was better to deprecate it and to discourage its use. So I'll be making that change when I can get round to it. As to your particular problem here... Does my_dir already exist? If it does then os.open won't be able to create it. If it doesn't then I can't see any reason why the code should fail there. I just ran it myself and it fails, as expected on an unpatched Python, on the assert on line 17 where the check is made for the result of os.access for W_OK. I don't have the time right now but if no-one else gets there first I hope to be able to post back with a standalone example of the AccessCheck API TJG Anyways I wrote > my Test.py script & tried only the def test_access_w(self): test case > which is defined under class FileTests(unittest.TestCase) by providing > my own directory path to check the write permissions on it. > > I executed my But it failed with the following errors ? > > *> python Test.py C:\temp\my_dir* > > test_access_w (__main__.FileTests) ... ERROR > > ====================================================================== > > ERROR: test_access_w (__main__.FileTests) > > ---------------------------------------------------------------------- > > Traceback (most recent call last): > > File "Test.py", line 14, in test_access_w > > f = os.open(dirpath, os.O_CREAT) > > OSError: [Errno 13] Permission denied: 'C:\\temp\\my_dir' > > ---------------------------------------------------------------------- > > Ran 1 test in 0.000s > > FAILED (errors=1) > > Basically the os.open() function is failing to open a directory (In this > case my_dir). The directory has write permissions for the user. Attached > herewith is my Test script. Can you please suggest some simple python > code which checks the write permissions of a directory in a straight > forward way (Not by using unit tests) > > Thanks > > Ayaskant- > > Bangalore > From rosuav at gmail.com Tue May 24 10:43:11 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 00:43:11 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <88a86$4ddbbc22$4275d90a$404@FUSE.NET> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <88a86$4ddbbc22$4275d90a$404@FUSE.NET> Message-ID: On Wed, May 25, 2011 at 12:09 AM, Kevin Walzer wrote: > Proprietary? > > Licensing options for C# in its Mono (Free Platform) implementation: > > http://www.mono-project.com/Licensing > > Licensing options for Objective-C in its GNUStep (Free Platform) > implementaiton > > http://www.gnustep.org/information/aboutGNUstep.html Just a side point: Are these *languages* free, or merely these *implementations*? Chris Angelico From kw at codebykevin.com Tue May 24 10:50:49 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 24 May 2011 10:50:49 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: <4e51c$4ddbc676$4275d90a$30907@FUSE.NET> On 5/24/11 2:23 AM, Stefan Behnel wrote: > Beliavsky, 20.05.2011 18:39: >> I thought this essay on why one startup chose Python was interesting. > > Since everyone seems to be hot flaming at their pet languages in this > thread, let me quickly say this: > > Thanks for sharing the link. > > Stefan > I kind of thought that other posters might also chime in on why they chose Python instead of . Since no one else has, I'll bite. I've been programming for about seven years, and am basically self-taught. I got my first taste of writing code when trying do to some basic hacking on my (then) shiny new G3 iBook. (Even though it was a Mac, I was enthralled by its Unix underpinnings.) C was too hard for a programming newbie, and (at the time) I only understood shell to be a sequential series of commands. (cd ~/.Trash; ls; rm *) My goal was to write desktop GUI apps, and looking around at the available languages, libraries, and toolkits for Unix and the Mac, I settled on Tk as the UI toolkit, since it seemed to be the simplest one out there, and on Tcl and Python as the programming languages. (A brief detour with AppleScript convinced me that it is a useful scripting language for hooking into various parts of OS X, but it is not very powerful.) While Tcl doesn't get a lot of love or respect on this list, it is quite powerful in its way, and an understanding of Tcl is quite useful in particular for understanding Tk and its Python wrapper, Tkinter. After becoming productive with Tcl and writing a couple of applications in it, I turned to Python in earnest and set about learning its capabilities as well, and have since released a couple of Python desktop apps on the Mac (commercial apps, using Tk as the toolkit). With that background, here are my reasons for keeping Python in my toolbox: 1. Its core libraries and third-party packages address nearly every imaginable need. The size of its community is a real asset here. Tcl is a more compact language, with a smaller core library and fewer third-party packages (no library comparable to Mark Pilgrim's feedparser, for instance), which means that for some use cases, using Tcl would mean more work. 2. Python has excellent tools for deployment of desktop apps. Since I only work on the Mac, I'm not that familiar with py2exe, but py2app and bundlebuilder have always allowed me to wrap up my apps with an embedded Python interpreter with a minimum of fuss. Tcl also excels in deployment of desktop apps; other languages, such as Perl and Ruby, seem to lag behind in this respect. (I could find no actively-maintained, open-source, Mac-viable desktop app bundling tools for either Ruby or Perl, which cooled my interest in them considerably.) 3. Python's binding to Tk makes writing GUI apps a straightforward process. Since I already knew Tk quite well, learning its Python bindings was much simpler than learning another GUI toolkit such as PyQt or wxPython. The strategies I learned from Tcl to develop sophisticated Tk-based UI's translate quite well to Python. Python isn't perfect; for some instances, I find Tcl a more lightweight and accessible tool to use. I also spend a lot of time digging into Tcl and Tk's C API to extend their capabilities in certain ways; this also allows my Python apps to access such enhancements, via Tkinter. But all in all I'm a happy user of Python, and it will continue to have a primary place in my toolbox. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From akekhofananaye at yahoo.co.uk Tue May 24 11:17:12 2011 From: akekhofananaye at yahoo.co.uk (SKHUMBUZO ZIKHALI) Date: Tue, 24 May 2011 16:17:12 +0100 (BST) Subject: Codes do not run Message-ID: <213250.48589.qm@web24004.mail.ird.yahoo.com> Hi: I am learning Python on my own using a " Guide to Programming with Python" book.?Author of the book is Micheal?Dawson and I am using version 2.3.5 of python. ?When I try to run the code?I do?not get required results. The picture could not be loaded. I get trackback message regarding undefined module.The example from the book is as follows: from liveswires import games games.init(screen_width = 640, screen_height = 480, fps = 50) wall_image = games.load_image("wall.jpg", transparent = False) games.screen.background = wall_image games.screen.mainloop() Can anyone please assist me. Thank you Sikhumbuzo -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 24 11:24:23 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 01:24:23 +1000 Subject: Codes do not run In-Reply-To: <213250.48589.qm@web24004.mail.ird.yahoo.com> References: <213250.48589.qm@web24004.mail.ird.yahoo.com> Message-ID: On Wed, May 25, 2011 at 1:17 AM, SKHUMBUZO ZIKHALI wrote: > The example from the book is as follows: > > from liveswires import games I think this might be meant to say "livewires". Presumably you did install this package? If not, it won't work (but even if you have, it won't work as "liveswires"). http://www.livewires.org.uk/python/package Hope that helps! Chris Angelico From rvince99 at gmail.com Tue May 24 11:36:18 2011 From: rvince99 at gmail.com (RVince) Date: Tue, 24 May 2011 08:36:18 -0700 (PDT) Subject: Obtaining a full path name from file Message-ID: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> s = "C:\AciiCsv\Gravity_Test_data\A.csv" f = open(s,"r") How do I obtain the full pathname given the File, f? (which should equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff and am just not finding it. Any help greatly appreciated ! From tim at johnsons-web.com Tue May 24 11:37:09 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Tue, 24 May 2011 07:37:09 -0800 Subject: Codes do not run In-Reply-To: <213250.48589.qm@web24004.mail.ird.yahoo.com> References: <213250.48589.qm@web24004.mail.ird.yahoo.com> Message-ID: <20110524153709.GN15519@johnsons-web.com> * SKHUMBUZO ZIKHALI [110524 07:26]: > Hi: > > I am learning Python on my own using a " Guide to Programming with Python" > book.?Author of the book is Micheal?Dawson and I am using version 2.3.5 of > python. ?When I try to run the code?I do?not get required results. The picture > could not be loaded. I get trackback message regarding undefined module.The > example from the book is as follows: > > from liveswires import games > > games.init(screen_width = 640, screen_height = 480, fps = 50) > wall_image = games.load_image("wall.jpg", transparent = False) > games.screen.background = wall_image > > games.screen.mainloop() > > Can anyone please assist me. You should provide 1)the traceback itself. 2)Version of python 3)Operating system 4)All relevant code Also Do the following : import sys print(sys.path) Do you see the liveswires module in the path? -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From mail at timgolden.me.uk Tue May 24 11:52:33 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 May 2011 16:52:33 +0100 Subject: Obtaining a full path name from file In-Reply-To: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: <4DDBD441.3070105@timgolden.me.uk> On 24/05/2011 16:36, RVince wrote: > s = "C:\AciiCsv\Gravity_Test_data\A.csv" > f = open(s,"r") > > How do I obtain the full pathname given the File, f? (which should > equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff > and am just not finding it. Any help greatly appreciated ! You're going to kick yourself: f.name TJG From rvince99 at gmail.com Tue May 24 12:04:12 2011 From: rvince99 at gmail.com (RVince) Date: Tue, 24 May 2011 09:04:12 -0700 (PDT) Subject: Obtaining a full path name from file References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> Ha! You;re right -- but is there a way to get it without the filename appended at the end? On May 24, 11:52?am, Tim Golden wrote: > On 24/05/2011 16:36, RVince wrote: > > > s = "C:\AciiCsv\Gravity_Test_data\A.csv" > > f = open(s,"r") > > > How do I obtain the full pathname given the File, f? (which should > > equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff > > and am just not finding it. Any help greatly appreciated ! > > You're going to kick yourself: > > f.name > > TJG From mwilson at the-wire.com Tue May 24 12:04:40 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 24 May 2011 12:04:40 -0400 Subject: Obtaining a full path name from file References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: Tim Golden wrote: > On 24/05/2011 16:36, RVince wrote: >> s = "C:\AciiCsv\Gravity_Test_data\A.csv" >> f = open(s,"r") >> >> How do I obtain the full pathname given the File, f? (which should >> equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff >> and am just not finding it. Any help greatly appreciated ! > > You're going to kick yourself: > > f.name There's trouble there, though: 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. >>> f = open ('xyzzy.txt') >>> f.name 'xyzzy.txt' >>> import os >>> os.getcwd() '/home/mwilson' >>> os.chdir('sandbox') >>> f.name 'xyzzy.txt' If you open a file and don't get a full path from os.path.abspath right away, the name in the file instance can get out-of-date. Mel. From rosuav at gmail.com Tue May 24 12:08:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 02:08:16 +1000 Subject: Obtaining a full path name from file In-Reply-To: <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> Message-ID: On Wed, May 25, 2011 at 2:04 AM, RVince wrote: > Ha! You;re right -- but is there a way to get it without the filename > appended at the end? Parse the file name with the os.path functions: http://docs.python.org/library/os.path.html Chris Angelico From orasnita at gmail.com Tue May 24 12:10:41 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 19:10:41 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian><57C0AB91B42743E89456ACCC8751CF78@octavian><2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: From: "Daniel Kluev" > On Tue, May 24, 2011 at 5:00 PM, Octavian Rasnita wrote: >> And you are telling that in Perl should be used an even more complicated and >> ugly syntax just for beeing the same as in Python just for showing that I am >> wrong, but I was comparing just the shortness and cleraness of the code. >> >> So, again, in Perl is just: >> >> %d = @l; > > Once again. Suppose we have array of key-value pairs (two-dimensional > array), This is a forced example to fit the way Python can do it with a clean syntax, but I don't think there are cases in which somebody wants to create hashes/dictionaries where the key is not a plain string but an array. This is not a rare case, but a case that probably nobody needs, ever. Octavian From mail at timgolden.me.uk Tue May 24 12:10:44 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 May 2011 17:10:44 +0100 Subject: Obtaining a full path name from file In-Reply-To: <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> Message-ID: <4DDBD884.4010006@timgolden.me.uk> On 24/05/2011 17:04, RVince wrote: > Ha! You;re right -- but is there a way to get it without the filename > appended at the end? Well, just use the functions in os.path, specifically os.path.dirname... TJG From orasnita at gmail.com Tue May 24 12:10:50 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 19:10:50 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian><57C0AB91B42743E89456ACCC8751CF78@octavian><2C6966D5AB6541E3BCE920FE7883A05B@octavian> <20110524060535.64cfa0ec.darcy@druid.net> Message-ID: From: "D'Arcy J.M. Cain" > On Tue, 24 May 2011 09:00:14 +0300 > "Octavian Rasnita" wrote: >> So, again, in Perl is just: >> >> %d = @l; >> >> Please tell me if Python has a syntax which is more clear than this for >> doing this thing. > > How is that clear? "Shorter" != "clearer." A Python programmer > looking at that sees line noise. A Perl programmer looking at "d = dict > ([a])" (or even "d = dict(a,)") sees something that has something to do > with creating a dictionary. At least he would know in which section of > the manual to look for more information. The Perl programmers usually don't need to look in the dictionary when they are creating programs. Perl is harder to learn, but it is easier to use. > Are Perl programmers aware of some imminent worldwide shortage of > electrons that Python programmers are not? Why is there this obsession > with shortness? A shorter code can be typed faster, obviously, and there are fewer possibility of appearing errors, but the shortage is not the most important thing. The most important thing is that the chars @, $, or % are the same in all languages, while the English words used by the languages that use many such words are harder to remember especially for the non-native English speakers. Python is not a very bad language from this perspective like Java is though. :-) In Perl the programmers can also use English words for some things, like $OUTPUT_AUTOFLUSH, but personally I never liked those things. Using $| instead is much shorter and clear, because I don't need to remember the English words like autoflush, or maybe it was just flush, or it was autoflush_output, or output_flush... something like $| can't be forgotten. Yes, I know that the guys from Google would never like that since these chars are not "Googleable" :-) Octavian From orasnita at gmail.com Tue May 24 12:10:56 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 19:10:56 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com><9CDC4B2CD1F445E994119A50F65155DF@teddy><12225671E9654FECB49613D915FAEC19@teddy><21A740B7AC6644248476DFADDF726C73@octavian><629DAC3611EA49B0A36BCF70151CDE2F@octavian><87sjs44qyk.fsf@castleamber.com> <20110524060927.778a4a6a.darcy@druid.net> Message-ID: From: "D'Arcy J.M. Cain" > On Tue, 24 May 2011 00:17:55 -0500 > John Bokma wrote: >> > $d = @a; >> >> That will give you the number of elements in @a. What you (probably) >> mean is %hash = @array; > > If I was even considering using Perl, this one exchange would send me > screaming in the opposite direction. If you didn't consider to change the language you prefer it means that you are closed minded and use to fell in love with the tools you use. Don't make me tell here how many things I don't like in Perl. I use to tell those things on Perl mailing lists and make upset their members. :-) Similarly, if you don't like something in Perl, why don't you tell them what you don't like to the Perl programmers community and not just have the guts to tell that in a group where the majority share your preferences. I came here on the list to find good things about Python and to learn some things and use its good parts, and not to hear bashing about other programming languages. Octavian From orasnita at gmail.com Tue May 24 12:11:01 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 19:11:01 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <88a86$4ddbbc22$4275d90a$404@FUSE.NET> Message-ID: From: "Kevin Walzer" > On 5/22/11 3:44 AM, Octavian Rasnita wrote: >> Somebody told that C# and Objective C are good languages. They might be good, but they are proprietary, and not only that they are proprietary, but they need to be ran under platforms that cannot be used freely, so from the freedom point of view, Perl, Ruby, Python and Java are the ways to go. > > Proprietary? > > Licensing options for C# in its Mono (Free Platform) implementation: > > http://www.mono-project.com/Licensing > > Licensing options for Objective-C in its GNUStep (Free Platform) > implementaiton > > http://www.gnustep.org/information/aboutGNUstep.html > > It may be true that these languages are more widely used on their > originating platforms (Windows, OS X) than on Linux, but these > implementations are definitely open source. Exactly, this is why I said that it matters only the distributions used by the most users. Octavian From jeanmichel at sequans.com Tue May 24 12:13:20 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 24 May 2011 18:13:20 +0200 Subject: Obtaining a full path name from file In-Reply-To: <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> <09bb028b-7050-4b8e-99b0-722af11918f7@y19g2000yqk.googlegroups.com> Message-ID: <4DDBD920.8060001@sequans.com> RVince wrote: > Ha! You;re right -- but is there a way to get it without the filename > appended at the end? > > On May 24, 11:52 am, Tim Golden wrote: > >> On 24/05/2011 16:36, RVince wrote: >> >> >>> s = "C:\AciiCsv\Gravity_Test_data\A.csv" >>> f = open(s,"r") >>> >>> How do I obtain the full pathname given the File, f? (which should >>> equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff >>> and am just not finding it. Any help greatly appreciated ! >>> >> You're going to kick yourself: >> >> f.name >> >> TJG >> > > path, fileName = os.path.split(os.path.abspath(f.name)) JM From orasnita at gmail.com Tue May 24 12:18:38 2011 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 24 May 2011 19:18:38 +0300 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <4e51c$4ddbc676$4275d90a$30907@FUSE.NET> Message-ID: Subject: Re: Why did Quora choose Python for its development? > I've been programming for about seven years, and am basically > self-taught. I got my first taste of writing code when trying do to some > basic hacking on my (then) shiny new G3 iBook. (Even though it was a > Mac, I was enthralled by its Unix underpinnings.) C was too hard for a > programming newbie, and (at the time) I only understood shell to be a > sequential series of commands. (cd ~/.Trash; ls; rm *) > > My goal was to write desktop GUI apps, and looking around at the > available languages, libraries, and toolkits for Unix and the Mac, I > settled on Tk as the UI toolkit, since it seemed to be the simplest one > out there, and on Tcl and Python as the programming languages. (A brief > detour with AppleScript convinced me that it is a useful scripting > language for hooking into various parts of OS X, but it is not very > powerful.) > > While Tcl doesn't get a lot of love or respect on this list, it is quite > powerful in its way, and an understanding of Tcl is quite useful in > particular for understanding Tk and its Python wrapper, Tkinter. After > becoming productive with Tcl and writing a couple of applications in it, > I turned to Python in earnest and set about learning its capabilities as > well, and have since released a couple of Python desktop apps on the Mac > (commercial apps, using Tk as the toolkit). > > With that background, here are my reasons for keeping Python in my toolbox: > > 1. Its core libraries and third-party packages address nearly every > imaginable need. The size of its community is a real asset here. Tcl is > a more compact language, with a smaller core library and fewer > third-party packages (no library comparable to Mark Pilgrim's > feedparser, for instance), which means that for some use cases, using > Tcl would mean more work. > > 2. Python has excellent tools for deployment of desktop apps. Since I > only work on the Mac, I'm not that familiar with py2exe, but py2app and > bundlebuilder have always allowed me to wrap up my apps with an embedded > Python interpreter with a minimum of fuss. Tcl also excels in deployment > of desktop apps; other languages, such as Perl and Ruby, seem to lag > behind in this respect. (I could find no actively-maintained, > open-source, Mac-viable desktop app bundling tools for either Ruby or > Perl, which cooled my interest in them considerably.) > > 3. Python's binding to Tk makes writing GUI apps a straightforward > process. Since I already knew Tk quite well, learning its Python > bindings was much simpler than learning another GUI toolkit such as PyQt > or wxPython. The strategies I learned from Tcl to develop sophisticated > Tk-based UI's translate quite well to Python. > > Python isn't perfect; for some instances, I find Tcl a more lightweight > and accessible tool to use. I also spend a lot of time digging into Tcl > and Tk's C API to extend their capabilities in certain ways; this also > allows my Python apps to access such enhancements, via Tkinter. But all > in all I'm a happy user of Python, and it will continue to have a > primary place in my toolbox. > > --Kevin Hi Kevin, Thanks for your message. It is helpful to know why some programmers prefer a certain OS, programming language, module or program, because this way the newbies can find its benefits rapidly. Yes there are packiging solutions for Perl under Mac, but I haven't tried them because I never used a Mac, however, I agree that python is better than Perl for creating desktop apps, because the modules which are used for creating GUIs are better developed. Too bad that you prefer Tk-based GUIs, because they are simple to use, I agree, but they create and promote discrimination because they are not accessible at all for the screen readers used by the blind. The standard Win32 GUIS/MFC or the libs that use those GUIs like Java SWT and wxWIDGETS used by WxPerl, WxPython... are much better accessible. Somebody told that he will try to make Tk accessible, but just as I expected, I haven't heard anything until now about any kind of success of that project. Octavian From tjreedy at udel.edu Tue May 24 12:50:47 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 May 2011 12:50:47 -0400 Subject: Python 3.2 Idle doesn't start. No error message. In-Reply-To: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> References: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> Message-ID: On 5/24/2011 8:01 AM, markrrivet at aol.com wrote: > Hello all. I have Python 2.71 installed on my Windows 7 laptop and it > runs fine. I was having a problem with Python 3.2, 32bit, not starting > with an error message saying this application has quit abnormally. > That was fixed when I took the PYTHONPATH statement out of my > environment variables. However, now when I try to start Idle, I can > see some hard drive activity, but Idle for Python 3.2 does not start; > nothing happens. Any clues as to the problem here? How do you try to start it? -- Terry Jan Reedy From john at castleamber.com Tue May 24 12:50:55 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 11:50:55 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <8762p0kzj6.fsf@mithlond.arda> Message-ID: <874o4kvy8g.fsf@castleamber.com> Teemu Likonen writes: > * 2011-05-24T06:05:35-04:00 * D'Arcy J. M. Cain wrote: > >> On Tue, 24 May 2011 09:00:14 +0300 >> "Octavian Rasnita" wrote: >>> %d = @l; >>> >>> Please tell me if Python has a syntax which is more clear than this >>> for doing this thing. >> >> How is that clear? "Shorter" != "clearer." A Python programmer looking >> at that sees line noise. > > I'm a Lisp programmer who sees (some) Python code as line noise. Exactly, and glad to see there are also non-extremists in this group. I have been programming Perl for well over 17 years. I've been trying to switch to Python /several times/ but yet, with all its shortcomings Perl somehow still suits me better. To D'Arcy and other Pythonistas -- doesn't that sound like an extermistic organization or what -- it might look like a cat had an accident involving a keyboard but to me, and all those other people who do enjoy coding Perl it's beauty. The whole Python is so beatiful & perfect sounds to me like people who have embraced the latin alphabet calling Devanagari unreadable chicken scratches made by backwards and poor people. To me it's a writing system of beauty. > I don't know but from the point of view of a Lisp programmer Python has > the same obsession. Not trolling, I just wanted to point out that these > are just point of views. I don't actually care that much about these > things. Wise words. And I agree. To me Python vs. Perl has nothing to do with being a fanboy (unlike many other posters here). I like both languages, I have invested a lot of time in learning Python and I am really not dense. Yet, even though I can program in Python sufficient enough very often I just pick Perl. Now why is that? -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From john at castleamber.com Tue May 24 12:52:39 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 11:52:39 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> Message-ID: <87zkmcujl4.fsf@castleamber.com> "D'Arcy J.M. Cain" writes: > On Tue, 24 May 2011 00:17:55 -0500 > John Bokma wrote: >> > $d = @a; >> >> That will give you the number of elements in @a. What you (probably) >> mean is %hash = @array; > > If I was even considering using Perl, this one exchange would send me > screaming in the opposite direction. To me as silly as all those people who give Python a wide berth because of significant whitespace. I am glad that I am not so limited in that respect. To me programming languages are like writing systems used by humans; each has its short comings and each has its beauty. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From claudiu at virtuamagic.com Tue May 24 13:17:25 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Tue, 24 May 2011 20:17:25 +0300 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: References: Message-ID: <201105242017.27919.claudiu@virtuamagic.com> I'm quoting a message that I received on personal address and wasn't sent to list: > > try adding argument close_fds=True to subprocess.Popen > > harish > And Tim's message: > It's not quite clear from your description above whether you > can be sure that the called subprocess has closed all its handles > by the time the os.rename runs. Seems that close_fds did the trick. Anyway, I read that description on the documentation last night but I think I was so tired that I understood that in Windows has no effect... :) Thank you, all. -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From darcy at druid.net Tue May 24 13:22:13 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 24 May 2011 13:22:13 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <20110524060927.778a4a6a.darcy@druid.net> Message-ID: <20110524132213.4387ae6b.darcy@druid.net> On Tue, 24 May 2011 19:10:56 +0300 "Octavian Rasnita" wrote: > > If I was even considering using Perl, this one exchange would send me > > screaming in the opposite direction. > > If you didn't consider to change the language you prefer it means > that you are closed minded and use to fell in love with the tools you Now you are just bordering on rudeness. I never made any disparaging remarks about you. I only talked about a tool that you seem to like and I don't. In fact, I did consider and investigate Perl many years ago along with may other languages before I settled on Python. I didn't like it then and I don't like it now. However, I have never called someone "close minded" for preferring a different tool to me. > Don't make me tell here how many things I don't like in Perl. Trust me, there is no need. > I use to tell those things on Perl mailing lists and make upset their Good for you. I also have talked about things in Python that I don't like on this list. No one has ever accused me of being afraid to speak my mind. That facet of my personality has got me in a lot of trouble in my life from parents, teachers, bosses and I have even been known to speak out against the police while they were holding automatic rifles to my head. I doubt that there will ever be enough peer pressure on a mailing list to trump that. > Similarly, if you don't like something in Perl, why don't you tell > them what you don't like to the Perl programmers community and not just > have the guts to tell that in a group where the majority share your > preferences. Because I am not a missionary. Someone came to my house and told me why their way was better so I spoke up. Same thing when the JW come to my front door but I have no interest in going to their Kingdom Hall to tell them why they are wrong. > I came here on the list to find good things about Python and to learn > some things and use its good parts, and not to hear bashing about other > programming languages. Same here but someone (I don't even know who started it) felt that it was necessary to tell us all why their language was better. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rosuav at gmail.com Tue May 24 13:30:00 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 03:30:00 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <874o4kvy8g.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <8762p0kzj6.fsf@mithlond.arda> <874o4kvy8g.fsf@castleamber.com> Message-ID: On Wed, May 25, 2011 at 2:50 AM, John Bokma wrote: > Wise words. And I agree. To me Python vs. Perl has nothing to do with > being a fanboy (unlike many other posters here). I like both languages, > I have invested a lot of time in learning Python and I am really not > dense. Yet, even though I can program in Python sufficient enough very > often I just pick Perl. Now why is that? To me, a language is a tool. The more tools you have competence with, the easier it will be to select the right one for any job. There are very few tools that have no use whatsoever; even Ook might be useful (although I have yet to be asked to port any code to OrangutanOS). This differs from the notion of having ten paradigms in one language, in that most source files will identify themselves fairly early on (possibly even out-of-band, such as filename extensions). Chris Angelico From darcy at druid.net Tue May 24 13:39:02 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 24 May 2011 13:39:02 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <87zkmcujl4.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> Message-ID: <20110524133902.b5ad22b1.darcy@druid.net> On Tue, 24 May 2011 11:52:39 -0500 John Bokma wrote: > >> > $d = @a; > >> > >> That will give you the number of elements in @a. What you (probably) > >> mean is %hash = @array; > > > > If I was even considering using Perl, this one exchange would send me > > screaming in the opposite direction. > > To me as silly as all those people who give Python a wide berth because > of significant whitespace. I am glad that I am not so limited in that > respect. To me programming languages are like writing systems used by > humans; each has its short comings and each has its beauty. My point was that even proponents of the language can make a significant error based on the way the variable is named. It's like the old Fortran IV that I first learned where the name of the variable determined whether it was an integer or a floating point. One of my favorite quotes (not sure if it was about Perl or APL) is "I refuse to use a programming language where the proponents of it stick snippets under each other's nose and say 'I bet you can't guess what this does.'" When I first looked at Perl it looked like line noise. When I first looked at Python it looked like pseudo-code. Look, I couldn't care less what other people use. I just don't see any reason for someone to come into a Python group and start proselytizing about why their tool is better than ours any more than I would feel any need to go to a Perl group and start trying to convert them. Bottom line - they did a study once (sorry, can't point to it any more) to determine the best tool for development. Turns out that the most productive tool was generally the one that the user believed was the most productive. In hindsight I think that that was rather obvious. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From xahlee at gmail.com Tue May 24 13:40:55 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 24 May 2011 10:40:55 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: On May 23, 9:28?pm, Chris Angelico wrote: > On Tue, May 24, 2011 at 2:20 PM, Xah Lee wrote: > > why don't you file a bug report? In GNU Emacs 23.2, it's under the > > Help menu. I suppose it's the same in other emacs distro. > > Because I do not consider its behaviour to be errant. And I suspect > its main developers won't either. That's why I suggested you grab the > sources and make The Perfect Emacs. why don't you try http://ergoemacs.org/ ? Xah From john at castleamber.com Tue May 24 13:56:30 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 12:56:30 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <8762p0kzj6.fsf@mithlond.arda> <874o4kvy8g.fsf@castleamber.com> Message-ID: <871uzougmp.fsf@castleamber.com> Chris Angelico writes: > On Wed, May 25, 2011 at 2:50 AM, John Bokma wrote: >> Wise words. And I agree. To me Python vs. Perl has nothing to do with >> being a fanboy (unlike many other posters here). I like both languages, >> I have invested a lot of time in learning Python and I am really not >> dense. Yet, even though I can program in Python sufficient enough very >> often I just pick Perl. Now why is that? > > To me, a language is a tool. To me, and to a lot of Perl programmers it's not different. > The more tools you have competence with, the easier it will be to > select the right one for any job. There are very few tools that have > no use whatsoever; even Ook might be useful (although I have yet to be > asked to port any code to OrangutanOS). This differs from the notion > of having ten paradigms in one language, If this is referring to Perl: the myths surrounding "there is more than one way" are even more crazy than "there is only one way", maybe because "more than one" makes it so much easier to make those myths up? On top of that: how many paradigms does Python support? And which paradigms does Perl support and Python doesn't? Roughly there are two dialects of Perl [1]: what people who never took the time to learn it write, and the rest. Also, having more than one way to code something doesn't mean that there are no preferrences. Python has also several ways to do certain things; yet most skilled programmers have a preference for one way. It's not that different with Perl; in my experience exactly the same even. Of course one can say a lot about Perl; I can. But I have never had a rough time reading someone else's code, unless the person had no clue about programming to begin with [2]. If Perl is really such a disaster, why are people using it? Or are they all short-sighted idiots who don't know better? Several Perl programmers I know, including myself, are fully aware of Python and other programming languages. Yet, somehow they still program in Perl... [1] http://www.bofh.org.uk/2010/07/25/a-tale-of-two-languages [2] I once had to port a piece of Pascal code and after some studying it turned out that the 100+ lines or so did some variant of bubble sort and near the end reversed the order in a separate loop. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From john at castleamber.com Tue May 24 14:17:54 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 13:17:54 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> Message-ID: <87sjs4t12l.fsf@castleamber.com> "D'Arcy J.M. Cain" writes: > On Tue, 24 May 2011 11:52:39 -0500 > John Bokma wrote: >> >> > $d = @a; >> >> >> >> That will give you the number of elements in @a. What you (probably) >> >> mean is %hash = @array; >> > >> > If I was even considering using Perl, this one exchange would send me >> > screaming in the opposite direction. >> >> To me as silly as all those people who give Python a wide berth because >> of significant whitespace. I am glad that I am not so limited in that >> respect. To me programming languages are like writing systems used by >> humans; each has its short comings and each has its beauty. > > My point was that even proponents of the language can make a > significant error based on the way the variable is named. And someone can't misspell dict, for example? Are we now going to judge a language on a typo someone just made? > When I first looked at Perl it looked like line noise. When I first > looked at Python it looked like pseudo-code. When people who are used to a latin alpabeth look at Devanagari they probably see scratches make by chickens. I saw beauty (and still see it). To someone fluent in Devanagari the latin alpabeth might look like Perl ;-). Anyway, I have been exposed to pseudo-code a lot before I picked up Perl, and yet, Perl somehow stuck with me. I learned about Python a little later (IIRC), and have tried to pick it up several times over the years that followed. Last year I have been more serious about picking it up; and I even did some paid for work in it. I /can/ program in Python, I do /like/ Python, but somehow I like Perl more; even when I am fully aware of its shortcommings each time I use it. As for line noise: very often it turns out that people mean the regular expressions by this. But a similar dialect is used by many other programming languages that I know of. The difference is that Perl has dedicated operators for it. A Perl programmer will call this line noise: double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", re.IGNORECASE) for match in double_word_re.finditer(text): print ("{0} is duplicated".format(match.group("word")) (p500 of Programming in Python 3, 2nd edition, any typos by me). > Look, I couldn't care less what other people use. In that case you're an exception here. Or maybe the weekly Perl bashers are way more vocal here and drown people like you out. One thing I hate about comp.lang.perl.misc is the ivory tower attitude there. One thing I hate about comp.lang.python is the weekly Perl bashing; to me it makes those people look like extremists (Pythonistas, what's in a word), and to be honest, it does affect how I view Python. > I just don't see any reason for someone to come into a Python group > and start proselytizing about why their tool is better than ours any > more than I would feel any need to go to a Perl group and start trying > to convert them. Yet it seems to be accepted behavoir here to weekly bash Perl... > Bottom line - they did a study once (sorry, can't point to it any more) > to determine the best tool for development. Turns out that the most > productive tool was generally the one that the user believed was the > most productive. In hindsight I think that that was rather obvious. Doesn't surprise me. I did switch to Emacs a few years back (used Textpad for many years) but I don't think I now produce more code / hour. But I am able to do some things way easier compared to using Textpad, and that gives me pleasure. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From nambo4jb at gmail.com Tue May 24 14:19:56 2011 From: nambo4jb at gmail.com (Cathy James) Date: Tue, 24 May 2011 13:19:56 -0500 Subject: NEED HELP- read file contents, while loop to accept user Message-ID: TJG- that solved the printing issue!! Many thanks:) Thanks to Chris and Jean Michel for your hints. On Tue, May 24, 2011 at 4:07 AM, 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. Re: Why did Quora choose Python for its development? > (Stefan Behnel) > 2. Re: Why did Quora choose Python for its development? > (Octavian Rasnita) > 3. Re: Why did Quora choose Python for its development? > (Chris Angelico) > 4. NEED HELP- read file contents, while loop to accept user > input, and enter to exit (Cathy James) > 5. Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit (Tim Golden) > 6. Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit (Chris Angelico) > 7. Re: I installed Python 3 on Fedora 14 By Downloading > python3.2 bziped source tarball and install it according to the > README, Now How shall I uninstalled python 3.2? (harrismh777) > 8. Re: Why did Quora choose Python for its development? > (Daniel Kluev) > 9. Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit (Chris Rebert) > 10. Re: [Savoynet] More 'vast heavin' (Chris Angelico) > > > ---------- Forwarded message ---------- > From: Stefan Behnel > To: python-list at python.org > Date: Tue, 24 May 2011 08:23:55 +0200 > Subject: Re: Why did Quora choose Python for its development? > Beliavsky, 20.05.2011 18:39: > >> I thought this essay on why one startup chose Python was interesting. >> > > Since everyone seems to be hot flaming at their pet languages in this > thread, let me quickly say this: > > Thanks for sharing the link. > > Stefan > > > > > ---------- Forwarded message ---------- > From: "Octavian Rasnita" > To: > Date: Tue, 24 May 2011 11:10:36 +0300 > Subject: Re: Why did Quora choose Python for its development? > From: "Stefan Behnel" > >> Beliavsky, 20.05.2011 18:39: >> >>> I thought this essay on why one startup chose Python was interesting. >>> >> >> Since everyone seems to be hot flaming at their pet languages in this >> thread, let me quickly say this: >> >> Thanks for sharing the link. >> > > > Maybe I have missed a message, but if I didn't, please provide that link. > I am always interested to find the best solutions. > > Thanks. > > Octavian > > > > > ---------- Forwarded message ---------- > From: Chris Angelico > To: python-list at python.org > Date: Tue, 24 May 2011 18:20:44 +1000 > Subject: Re: Why did Quora choose Python for its development? > On Tue, May 24, 2011 at 6:10 PM, Octavian Rasnita > wrote: > > From: "Stefan Behnel" > >> > >> Beliavsky, 20.05.2011 18:39: > >>> > >>> I thought this essay on why one startup chose Python was interesting. > >> > >> Since everyone seems to be hot flaming at their pet languages in this > >> thread, let me quickly say this: > >> > >> Thanks for sharing the link. > > > > > > Maybe I have missed a message, but if I didn't, please provide that link. > > I am always interested to find the best solutions. > > At the beginning of the thread, three days and forty-odd messages ago, > this was posted: > > http://www.quora.com/Why-did-Quora-choose-Python-for-its-development > > It's the reason for the thread title, regardless of the current thread > content :) > > Chris Angelico > > > > ---------- Forwarded message ---------- > From: Cathy James > To: python-list at python.org > Date: Tue, 24 May 2011 03:31:37 -0500 > Subject: NEED HELP- read file contents, while loop to accept user input, > and enter to exit > dear mentor, > > I need help with my code: > 1) my program won't display file contents upon opening > 2) my program is not writing to file > 3) my program is not closing when user presses enter- gow do I do this with > a while loop? > > please see my attempt below and help: > > #1) open file and display current file contents: > f = open ('c:/testing.txt'', 'r') > f.readlines() > #2) and 3) use while loop to write user input to file, save to file, > close when press enter: > while True: > s = input ('enter name: ').strip() > f = open ('c:/testing.txt', 'a') > if f.writable(): > f.write(s) > break > else: > f = open ('c:/testing.txt', 'r') > f.readlines() > for line in f: > print (line) > > > ---------- Forwarded message ---------- > From: Tim Golden > To: > Date: Tue, 24 May 2011 09:46:11 +0100 > Subject: Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit > On 24/05/2011 09:31, Cathy James wrote: > >> dear mentor, >> I need help with my code: >> 1) my program won't display file contents upon opening >> > > #1) open file and display current file contents: >> f = open ('c:/testing.txt'', 'r') >> f.readlines() >> > > If you're running this in an interactive interpreter, I would > expect it to show a list of lines (assuming c:/testing.txt has > something in it...). If you're running it as a program, though, > it won't show anything: you need to actually output the result > of the expression f.readlines (). It only happens at the > interpreter as a development convenience: > > f = open ("c:/testing.txt", "r") > print f.readlines () > # or print (f.readlines ()) if you're in Python 3 > > TJG > > > > ---------- Forwarded message ---------- > From: Chris Angelico > To: python-list at python.org > Date: Tue, 24 May 2011 18:46:32 +1000 > Subject: Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit > On Tue, May 24, 2011 at 6:31 PM, Cathy James wrote: > > s = input ('enter name: ').strip() > > Are you using Python 2 or Python 3? If it's Python 2, this should be > raw_input(). > > > f = open ('c:/testing.txt', 'a') > > ... > > f = open ('c:/testing.txt', 'r') > > You may be having trouble here as a result of not closing the file and > then trying to reopen it. > > Also, at some point you have to check if 's' (the user's inputted > string) is empty. You can then leave the loop using the 'break' > statement. > > Hope that helps! Best of luck with your homework. > > Chris Angelico > > > > ---------- Forwarded message ---------- > From: harrismh777 > To: python-list at python.org > Date: Tue, 24 May 2011 03:47:31 -0500 > Subject: Re: I installed Python 3 on Fedora 14 By Downloading python3.2 > bziped source tarball and install it according to the README, Now How shall > I uninstalled python 3.2? > Varuna Seneviratna wrote: > >> Now How shall I uninstalled >> python 3.2? >> >> > Now, how shall I remove Python 3.2 ? > > > ... very carefully. > > > It might be nice if there were a label in the Makefile so this would work: > > sudo make removeall > > ... but alas, why do you want to un-install Python3.2 ? > > > > > > > > > ---------- Forwarded message ---------- > From: Daniel Kluev > To: python-list at python.org > Date: Tue, 24 May 2011 19:55:40 +1100 > Subject: Re: Why did Quora choose Python for its development? > On Tue, May 24, 2011 at 5:00 PM, Octavian Rasnita > wrote: > > And you are telling that in Perl should be used an even more complicated > and > > ugly syntax just for beeing the same as in Python just for showing that I > am > > wrong, but I was comparing just the shortness and cleraness of the code. > > > > So, again, in Perl is just: > > > > %d = @l; > > Once again. Suppose we have array of key-value pairs (two-dimensional > array), `l`. In python, converting it to dict is as simple as d = > dict(l). In perl, %d = @l; produces meaningless value. Following your > logic, this means that perl has ugly syntax. > > -- > With best regards, > Daniel Kluev > > > > ---------- Forwarded message ---------- > From: Chris Rebert > To: Cathy James > Date: Tue, 24 May 2011 01:58:25 -0700 > Subject: Re: NEED HELP- read file contents, while loop to accept user > input, and enter to exit > On Tue, May 24, 2011 at 1:31 AM, Cathy James wrote: > > dear mentor, > > > > I need help with my code: > > > In addition to what others have already said... > > > please see my attempt below and help: > > > > #1) open file and display current file contents: > > f = open ('c:/testing.txt'', 'r') > > f.readlines() > > #2) and 3) use while loop to write user input to file, save to file, > close > > when press enter: > > while True: > > s = input ('enter name: ').strip() > > f = open ('c:/testing.txt', 'a') > > if f.writable(): > > Since you *just* opened the file in append mode, this condition will > *always* be true (append mode implies writability), so your `else` > clause will *never* be executed. > > > f.write(s) > > break > > else: > > f = open ('c:/testing.txt', 'r') > > f.readlines() > > for line in f: > > print (line) > > Similar beginner questions would be best directed to Python's Tutor > mailinglist: http://mail.python.org/mailman/listinfo/tutor > > Cheers, > Chris > > > > ---------- Forwarded message ---------- > From: Chris Angelico > To: python-list at python.org > Date: Tue, 24 May 2011 19:07:21 +1000 > Subject: Re: [Savoynet] More 'vast heavin' > On Tue, May 24, 2011 at 7:03 PM, Larry Simons > wrote: > > On Tue 24/05/2011 04:11, Libby Moyer wrote: > >> > >> And the rhymes in Mikado! > > > > Are you referring to ablutioner, diminutioner and ?you shun her? all > rhymed > > with executioner? > > > > Can't deny that they're grin-worthy! > > (Or groan-worthy, I always get those two mixed up.) > > ChrisA > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimsyyap at gmail.com Tue May 24 15:12:53 2011 From: jimsyyap at gmail.com (Jim Syyap) Date: Wed, 25 May 2011 07:12:53 +1200 Subject: subscribef Message-ID: -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrmakent at gmail.com Tue May 24 15:13:33 2011 From: mrmakent at gmail.com (Michael Kent) Date: Tue, 24 May 2011 12:13:33 -0700 (PDT) Subject: Obtaining a full path name from file In-Reply-To: Message-ID: <7a8900d5-a241-4233-a0b4-13f6b9ca67e7@glegroupsg2000goo.googlegroups.com> If a filename does not contain a path component, os.path.abspath will prepend the current directory path onto it. From adsquaired at gmail.com Tue May 24 16:10:37 2011 From: adsquaired at gmail.com (ad) Date: Tue, 24 May 2011 13:10:37 -0700 (PDT) Subject: Code Review Message-ID: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> Hello all, Please review the code pasted below. I am wondering what other ways there are of performing the same tasks. This was typed using version 3.2. The script is designed to clean up a directory (FTP, Logs, etc.) Basically you pass two arguments. The first argument is an number of days old to delete. The second argument is the directory where the files and folders should be deleted. I imagine one enhancement would be to create a function out of some of this. ### BEGIN ### import os import time import shutil import argparse CurrentTime = time.time() epocDay = 86400 # seconds parser = argparse.ArgumentParser(description = "Delete files and folders in a directory N days old", add_help=False, prog='directorycleaner', usage='%(prog)s 7 c:\\temp') parser.add_argument('days', type=int, help="Numeric value: delete files and folders older then N days") parser.add_argument('directory', help="delete files and folders in this directory") parser.print_help() args = parser.parse_args() dictKeys = (vars(args)) HowManyDays = dictKeys['days'] WhatDirectory = dictKeys['directory'] print (HowManyDays) print (WhatDirectory) DaysToDelete = HowManyDays * epocDay dirExists = os.path.exists(WhatDirectory) if dirExists == False: print ("The directory is missing") DirListing = os.listdir(WhatDirectory) for files in DirListing: # Get the absolute path of the file name abspath = (os.path.join(WhatDirectory, files)) # Get the current creation time of the file in epoc format (midnight 1/1/1970) FileCreationTime = (os.path.getctime(abspath)) # time.ctime converts epoch to a normal date #print (time.ctime(CurrentTime)) # Get the date from seven days ago WeekOldFileDate = CurrentTime - DaysToDelete #print (CurrentTime) #print (FileCreationTime) #print (WeekOldFileDate) #If the file is older than seve days doe something if FileCreationTime < WeekOldFileDate: #check if the object is a file if os.path.isfile(abspath): os.remove(abspath) # It is not a file it is a directory elif os.path.isdir(abspath): shutil.rmtree(abspath) ##### END #### From markrrivet at aol.com Tue May 24 16:12:43 2011 From: markrrivet at aol.com (markrrivet at aol.com) Date: Tue, 24 May 2011 16:12:43 -0400 Subject: Python 3.2 Idle doesn't start. No error message. References: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> Message-ID: <4o3ot6h6efljelmtvqu6fcu6o9vqpfjoec@4ax.com> On Tue, 24 May 2011 12:50:47 -0400, Terry Reedy wrote: >On 5/24/2011 8:01 AM, markrrivet at aol.com wrote: >> Hello all. I have Python 2.71 installed on my Windows 7 laptop and it >> runs fine. I was having a problem with Python 3.2, 32bit, not starting >> with an error message saying this application has quit abnormally. >> That was fixed when I took the PYTHONPATH statement out of my >> environment variables. However, now when I try to start Idle, I can >> see some hard drive activity, but Idle for Python 3.2 does not start; >> nothing happens. Any clues as to the problem here? > >How do you try to start it? >From start|programs|python and clicking on the idle icon. From claudiu at virtuamagic.com Tue May 24 16:18:28 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Tue, 24 May 2011 23:18:28 +0300 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: <201105242017.27919.claudiu@virtuamagic.com> References: <201105242017.27919.claudiu@virtuamagic.com> Message-ID: <201105242318.32306.claudiu@virtuamagic.com> > Seems that close_fds did the trick. Anyway, I read that description on > the documentation last night but I think I was so tired that I > understood that in Windows has no effect... :) Now. There is one more issue. Seems that on faster computers and/or Windows 7 (the Win32 thing I have tested on a HVM Xen machine with Windows XP) the os.rename is too fast after fp.close() and generates the same Exception. The code follows: curl.close() fp.close() os.rename(tfile, actualfile) Where, tfile is the .part file, actual file is the real destination, fp was opened with open(..., "wb") and the descriptor passed to curl. I have solved the issue with self.msleep(10) - msleep is a method of QThread. But I don't think it's an elegant and normal solution. Did fp.close() is delayed, or? I mean, I don't want to rely on a "sleep" in order to workaround the access issue. On this issue there is no more process spawn, nothing, just the downloader thread and the main window. And the access denied appears at random time. -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From sunrrrise at gmail.com Tue May 24 16:27:52 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Tue, 24 May 2011 13:27:52 -0700 (PDT) Subject: Odp: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: Ok, another time I'd like to thank you for your help. I gave up, I'm going to get used to IDLE GUI... at least this one works! From sunrrrise at gmail.com Tue May 24 16:27:52 2011 From: sunrrrise at gmail.com (sunrrrise) Date: Tue, 24 May 2011 13:27:52 -0700 (PDT) Subject: Odp: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: Message-ID: Ok, another time I'd like to thank you for your help. I gave up, I'm going to get used to IDLE GUI... at least this one works! From asandroq at gmail.com Tue May 24 16:39:15 2011 From: asandroq at gmail.com (asandroq) Date: Tue, 24 May 2011 13:39:15 -0700 (PDT) Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On May 24, 12:27?am, Deeyana wrote: > > Classic unsubstantiated and erroneous claim. Scheme does not come OOTB > with any suitable libraries for host interop and though it can make calls > to C libraries, doing so is awkward and involves difficulties with the > impedance mismatch between Scheme's data structures and C's char *, void > *, int, double, array, etc. types. To top it off, C lacks automatic > memory management, which means you'll have to concern yourself with > manually disposing of allocated data structures used in interop. (Or, > worse, things will get garbage collected by the Scheme runtime that the > Scheme code no longer references, but the C library is still using, and > bam! SIGSEGV.) > Classic unsubstantiated and erroneous claim. From rosuav at gmail.com Tue May 24 17:53:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 07:53:24 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <871uzougmp.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <8762p0kzj6.fsf@mithlond.arda> <874o4kvy8g.fsf@castleamber.com> <871uzougmp.fsf@castleamber.com> Message-ID: On Wed, May 25, 2011 at 3:56 AM, John Bokma wrote: > Chris Angelico writes: >> To me, a language is a tool. > > To me, and to a lot of Perl programmers it's not different. > >> The more tools you have competence with, the easier it will be to >> select the right one for any job. There are very few tools that have >> no use whatsoever; even Ook might be useful (although I have yet to be >> asked to port any code to OrangutanOS). ?This differs from the notion >> of having ten paradigms in one language, > > If this is referring to Perl: the myths surrounding "there is more than > one way" are even more crazy than "there is only one way", maybe because > "more than one" makes it so much easier to make those myths up? > > On top of that: how many paradigms does Python support? ?And which > paradigms does Perl support and Python doesn't? You miss my point. To me, BOTH Perl AND Python are tools; there is a time and a place for each. Also in my toolkit are C, C++, Pike, REXX, &c, &c, &c. Even Java and ActionScript/Flash (both of which I detest for several reasons) have their place - browser-based applications that aren't limited to HTTP (try writing an in-browser MUD client in Javascript). Every language has its downsides; every language has its unique feature that makes it special. And every language I've ever used has taught me something. Know both. Bash both (if you feel so inclined). Use both. Chris Angelico From tjreedy at udel.edu Tue May 24 17:53:53 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 May 2011 17:53:53 -0400 Subject: Python 3.2 Idle doesn't start. No error message. In-Reply-To: <4o3ot6h6efljelmtvqu6fcu6o9vqpfjoec@4ax.com> References: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> <4o3ot6h6efljelmtvqu6fcu6o9vqpfjoec@4ax.com> Message-ID: On 5/24/2011 4:12 PM, markrrivet at aol.com wrote: > On Tue, 24 May 2011 12:50:47 -0400, Terry Reedy >> How do you try to start it? > >> From start|programs|python and clicking on the idle icon. OK. Works fine for me on winxp desktop and win7 laptop. 3.2.1 will be out soon. Whether or not you find a fix before that, download it, install, and try again. I think I would uninstall 3.2.0 first. You could, of course, try re-installing. I just tried C:\Documents and Settings\Terry>set PYTHONPATH Environment variable PYTHONPATH not defined so undefining that should not be the problem. The icon properties are not helpful as to how it starts IDLE. Perhaps is uses ../python32/Lib/idlelib/idle.bat @echo off rem Start IDLE using the appropriate Python interpreter set CURRDIR=%~dp0 start "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 %7 %8 %9 In a command prompt window you could directly try something like C:\Programs\Python32>pythonw Lib\idlelib\idle.pyw which works for me. Make sure idlelib and idle.pyw are present. Also check tcl/ and Lib/tkinter/ idle.pyw has ======================= try: import idlelib.PyShell except ImportError: # IDLE is not installed, but maybe PyShell is on sys.path: try: from . import PyShell except ImportError: raise else: import os idledir = os.path.dirname(os.path.abspath(PyShell.__file__)) if idledir != os.getcwd(): # We're not in the IDLE directory, help the subprocess find run.py pypath = os.environ.get('PYTHONPATH', '') if pypath: os.environ['PYTHONPATH'] = pypath + ':' + idledir else: os.environ['PYTHONPATH'] = idledir PyShell.main() else: idlelib.PyShell.main() ========================== PYTHONPATH does come into play if but only if two imports fail. You could make a copy of that and add prints to see what does and does not execute. -- Terry Jan Reedy From john at castleamber.com Tue May 24 18:00:52 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 17:00:52 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <8762p0kzj6.fsf@mithlond.arda> <874o4kvy8g.fsf@castleamber.com> <871uzougmp.fsf@castleamber.com> Message-ID: <87vcwzsqqz.fsf@castleamber.com> Chris Angelico writes: > On Wed, May 25, 2011 at 3:56 AM, John Bokma wrote: >> Chris Angelico writes: >>> To me, a language is a tool. >> >> To me, and to a lot of Perl programmers it's not different. >> >>> The more tools you have competence with, the easier it will be to >>> select the right one for any job. There are very few tools that have >>> no use whatsoever; even Ook might be useful (although I have yet to be >>> asked to port any code to OrangutanOS). ?This differs from the notion >>> of having ten paradigms in one language, >> >> If this is referring to Perl: the myths surrounding "there is more than >> one way" are even more crazy than "there is only one way", maybe because >> "more than one" makes it so much easier to make those myths up? >> >> On top of that: how many paradigms does Python support? ?And which >> paradigms does Perl support and Python doesn't? > > You miss my point. Could be, English is my second language. But to me "ten paradigms in one language" smelled of Perl bashing (or maybe Falcon bashing). My apologies if that was not the intent. > To me, BOTH Perl AND Python are tools; there is a time and a place for > each. Also in my toolkit are C, C++, Pike, REXX, &c, &c, &c. Even Java > and ActionScript/Flash (both of which I detest for several reasons) > have their place - browser-based applications that aren't limited to > HTTP (try writing an in-browser MUD client in Javascript). Every > language has its downsides; every language has its unique feature that > makes it special. And every language I've ever used has taught me > something. > > Know both. Bash both (if you feel so inclined). Use both. Can't agree more with you, thanks for the clarification. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From rosuav at gmail.com Tue May 24 18:01:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 08:01:38 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <20110524133902.b5ad22b1.darcy@druid.net> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain wrote: > My point was that even proponents of the language can make a > significant error based on the way the variable is named. ?It's like > the old Fortran IV that I first learned where the name of the variable > determined whether it was an integer or a floating point. I believe that's the origin of one of the proofs that God is real (unless declared integer). And hey, I can't hate something that gave us the classic use of i, j, k as loop indices! > One of my favorite quotes (not sure if it was about Perl or APL) is "I > refuse to use a programming language where the proponents of it stick > snippets under each other's nose and say 'I bet you can't guess what > this does.'" Yes, I believe that was Perl. And an amusing quote. But most of the point of it comes from the fact that Perl uses punctuation for most of its keywords, whereas (say) Python uses English words; it's a lot more fun to crunch something down when you can use $| and friends than when you have to put "x and y", complete with spaces, for a simple boolean. But that says nothing about which language is actually better for working with... beyond the fact that Perl can get more mileage out of an 80-character line! > When I first looked at Perl it looked like line noise. ?When I first > looked at Python it looked like pseudo-code. When I first looked at assembly language it looked like random junk left behind in memory. When I first looked at COBOL it looked like ... COBOL. Doesn't make either of them better or worse. Pseudo-code is not a viable language for a computer to parse, but it's a good language for scribbling down comments in. That doesn't necessarily mean that a programming language that's "closer to" pseudo-code is good. And verbosity doesn't necessarily equate to quality; for instance, when I'm working in both Python and PHP, I find it FAR tidier to use Python's {1:2,3:4] notation than PHP's array(1=>2,3=>4) - but on the flip side, I would prefer to have program structure defined by keywords like "if" and "while" than obscure random line noise. (Fortunately, most sane languages do indeed use keywords there.) Chris Angelico From tjreedy at udel.edu Tue May 24 18:03:42 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 May 2011 18:03:42 -0400 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: <201105242318.32306.claudiu@virtuamagic.com> References: <201105242017.27919.claudiu@virtuamagic.com> <201105242318.32306.claudiu@virtuamagic.com> Message-ID: On 5/24/2011 4:18 PM, Claudiu Nicolaie CISMARU wrote: >> Seems that close_fds did the trick. Anyway, I read that description on >> the documentation last night but I think I was so tired that I >> understood that in Windows has no effect... :) > > Now. There is one more issue. Seems that on faster computers and/or > Windows 7 (the Win32 thing I have tested on a HVM Xen machine with > Windows XP) the os.rename is too fast after fp.close() and generates the > same Exception. The code follows: > > curl.close() > fp.close() > os.rename(tfile, actualfile) > > Where, tfile is the .part file, actual file is the real destination, fp > was opened with open(..., "wb") and the descriptor passed to curl. > > I have solved the issue with self.msleep(10) - msleep is a method of > QThread. But I don't think it's an elegant and normal solution. Did > fp.close() is delayed, or? I mean, I don't want to rely on a "sleep" in > order to workaround the access issue. > > On this issue there is no more process spawn, nothing, just the > downloader thread and the main window. And the access denied appears at > random time. I would go with what works. In my experience, mysterious and seemingly buggy error messages, including Access Denied are not unusual on Windows. -- Terry Jan Reedy From skunkworks at rikishi42.net Tue May 24 18:06:06 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Wed, 25 May 2011 00:06:06 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-24, Steven D'Aprano wrote: >>> I think that is a patronizing remark that under-estimates the >>> intelligence of lay people and over-estimates the difficulty of >>> understanding recursion. >> >> Why would you presume this to be related to intelligence? The point was >> not about being *able* to understand, but about *needing* to understand >> in order to use. > > Maybe they don't "need" to understand recursion. So what? I think you should read the earlier posts again, this is drifting so far from what I intended. What I mean is: I'm certain that over the years I've had more than one person come to me and ask what 'Do you wish to delete this directory recursively?' meant. BAut never have I been asked to explain what 'Do you wish to delete this directory and it's subdirs/with all it's contents?' meant. Never. > Recursion is a perfectly good English word, no more technical than > "accelerate" or "incinerate" or "dissolve" or "combustion". Do people > need to know the word "combustion" when they could say "burn" instead? It wasn't about the word, but about the nature of the function. Besides, if the chance exists of a confusion between a recursive job and the fact the job is done using a recursive function... I would try staying away from the expression. Why not use 'delete a directory'. It's obvious the content gets binned, too. Do you know many people who incinerate leaves and branches in their garden? I burn them. > Do they need to know the words "microwave oven" when they could be saying > "invisible rays cooking thing"? The word oven has existed for ages, microwave is just a name for the type of oven. Not even a description, just a name. > I wonder whether physicists insist that cars should have a "go faster > pedal" because ordinary people don't need to understand Newton's Laws of > Motion in order to drive cars? Gas pedal. Pedal was allraedy known when the car was invented. The simple addition of gas solved that need. Oh, and it's break pedal, not descellarator. (sp?) > Who are you to say that people shouldn't be exposed to words you deem > that they don't need to know? I'm one of the 'people'. You say exposed to, I say bothered/bored with. I have nothing against the use of a proper, precise term. And that word can be a complex one with many, many sylables (seems to add value, somehow). But I'm not an academic, so I don't admire the pedantic use of terms that need to be explained to 'lay' people. Especially if there is a widespread, usually shorter and much simpler one for it. A pointless effort if pointless, even when comming from a physicist. :-) -- When in doubt, use brute force. -- Ken Thompson From markrrivet at aol.com Tue May 24 18:06:33 2011 From: markrrivet at aol.com (markrrivet at aol.com) Date: Tue, 24 May 2011 18:06:33 -0400 Subject: Python 3.2 Idle doesn't start. No error message. References: <677nt65c93756jvjbvpume2kdj6it0dm4g@4ax.com> <4o3ot6h6efljelmtvqu6fcu6o9vqpfjoec@4ax.com> Message-ID: On Tue, 24 May 2011 17:53:53 -0400, Terry Reedy wrote: >On 5/24/2011 4:12 PM, markrrivet at aol.com wrote: >> On Tue, 24 May 2011 12:50:47 -0400, Terry Reedy >>> How do you try to start it? >> >>> From start|programs|python and clicking on the idle icon. > >OK. Works fine for me on winxp desktop and win7 laptop. >3.2.1 will be out soon. Whether or not you find a fix before that, >download it, install, and try again. I think I would uninstall 3.2.0 >first. You could, of course, try re-installing. > >I just tried >C:\Documents and Settings\Terry>set PYTHONPATH >Environment variable PYTHONPATH not defined > >so undefining that should not be the problem. > >The icon properties are not helpful as to how it starts IDLE. >Perhaps is uses ../python32/Lib/idlelib/idle.bat > >@echo off >rem Start IDLE using the appropriate Python interpreter >set CURRDIR=%~dp0 >start "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 >%7 %8 %9 > >In a command prompt window you could directly try something like >C:\Programs\Python32>pythonw Lib\idlelib\idle.pyw >which works for me. Make sure idlelib and idle.pyw are present. >Also check tcl/ and Lib/tkinter/ > >idle.pyw has >======================= >try: > import idlelib.PyShell >except ImportError: > # IDLE is not installed, but maybe PyShell is on sys.path: > try: > from . import PyShell > except ImportError: > raise > else: > import os > idledir = os.path.dirname(os.path.abspath(PyShell.__file__)) > if idledir != os.getcwd(): > # We're not in the IDLE directory, help the subprocess find >run.py > pypath = os.environ.get('PYTHONPATH', '') > if pypath: > os.environ['PYTHONPATH'] = pypath + ':' + idledir > else: > os.environ['PYTHONPATH'] = idledir > PyShell.main() >else: > idlelib.PyShell.main() >========================== > >PYTHONPATH does come into play if but only if two imports fail. >You could make a copy of that and add prints to see what does and does >not execute. Thanks Terry, I will do what I can. I'll let you know how it works out. But thanks again. Every little bit helps me get closer to the solution. From rosuav at gmail.com Tue May 24 18:14:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 08:14:27 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: On Wed, May 25, 2011 at 3:40 AM, Xah Lee wrote: > On May 23, 9:28?pm, Chris Angelico wrote: >> Because I do not consider its behaviour to be errant. And I suspect >> its main developers won't either. That's why I suggested you grab the >> sources and make The Perfect Emacs. > > why don't you try http://ergoemacs.org/ ? You miss my point. I am not desiring of a different emacs; you were the one complaining about its shortcomings. Chris Angelico From lew1716 at gmail.com Tue May 24 18:17:17 2011 From: lew1716 at gmail.com (Lew Schwartz) Date: Tue, 24 May 2011 18:17:17 -0400 Subject: Beginner needs advice Message-ID: Here's my background: I'm a Windows based Visual FoxPro developer, and I want to start programming in Python. I'll be sticking to Windows (XP & 7) and my immediate needs are to manage & display large groups of jpg's, tiff's etc... so I need form based & graphics capable libraries (in addition to basic programming skills, of course). So Python 2 or 3? Add on packages/libraries? Tutorials? Thanks! -Lew -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 24 18:38:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 08:38:07 +1000 Subject: Functional Programing: stop using recursion, cons. Use map & vectors In-Reply-To: References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On Tue, May 24, 2011 at 8:27 AM, Deeyana wrote: > Classic unsubstantiated and erroneous claim. Scheme does not come OOTB > with any suitable libraries for host interop and though it can make calls > to C libraries, doing so is awkward and involves difficulties with the > impedance mismatch between Scheme's data structures and C's char *, void > *, int, double, array, etc. types. To top it off, C lacks automatic > memory management, which means you'll have to concern yourself with > manually disposing of allocated data structures used in interop. (Or, > worse, things will get garbage collected by the Scheme runtime that the > Scheme code no longer references, but the C library is still using, and > bam! SIGSEGV.) How is this fundamentally different from Python calling into C? Chris Angelico From john at castleamber.com Tue May 24 19:16:06 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 18:16:06 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: <87mxibsn9l.fsf@castleamber.com> Chris Angelico writes: > On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain wrote: >> My point was that even proponents of the language can make a >> significant error based on the way the variable is named. ?It's like >> the old Fortran IV that I first learned where the name of the variable >> determined whether it was an integer or a floating point. > > I believe that's the origin of one of the proofs that God is real > (unless declared integer). And hey, I can't hate something that gave > us the classic use of i, j, k as loop indices! > >> One of my favorite quotes (not sure if it was about Perl or APL) is "I >> refuse to use a programming language where the proponents of it stick >> snippets under each other's nose and say 'I bet you can't guess what >> this does.'" > > Yes, I believe that was Perl. And an amusing quote. But most of the > point of it comes from the fact that Perl uses punctuation for most of > its keywords, For example? > whereas (say) Python uses English words; it's a lot more > fun to crunch something down when you can use $| That's not a keyword but a special (global) variable. On top of that, you don't have to use it [1] and most people most likely encounter this in (badly) written CGI scripts originating in the last century. Yes, Perl is fantastic for writing hard to read obfuscated code. And yes, newbies are great at writing this from the very start, especially since they seem to copy paste examples written by other newbies (often written in the previous century...). But Perl doesn't force one to write unreadable code. If Perl was really so unreadable, why haven't I /still/ not switched to Python? What keeps me going back to Perl? > and friends than when you have to put "x and y", complete with spaces, > for a simple boolean. Perl has also the and logical operator. This is legal Perl: if ( $x and $y ) { print "yes\n"; } [1] You can use $OUTPUT_AUTOFLUSH (use English;), or use IO::Handle and use the autoflush method [2]. [2] In Perl 5.14 IO::File is now loaded on demand: http://search.cpan.org/dist/perl/pod/perldelta.pod#Filehandle_method_calls_load_IO::File_on_demand -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From rosuav at gmail.com Tue May 24 19:38:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 09:38:08 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <87mxibsn9l.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87mxibsn9l.fsf@castleamber.com> Message-ID: On Wed, May 25, 2011 at 9:16 AM, John Bokma wrote: > Chris Angelico writes: > >> Yes, I believe that was Perl. And an amusing quote. But most of the >> point of it comes from the fact that Perl uses punctuation for most of >> its keywords, > > For example? > >> whereas (say) Python uses English words; it's a lot more >> fun to crunch something down when you can use $| > > That's not a keyword but a special (global) variable. On top of that, > you don't have to use it [1] and most people most likely encounter this in > (badly) written CGI scripts originating in the last century. Okay, poor example. But there's a lot of Perl that uses concise notation for things that in Python are keyworded; for instance, regular expressions. I'm insufficiently fluent in Perl to quote good examples; mainly what I'm referring to is the notion of operators that are separators, as opposed to keywords that get blank-delimited. I generally prefer syntactic elements to be punctuation (eg { } rather than BEGIN and END (or DO and END)). It does also make things easier to crunch, for better or for worse. >> and friends than when you have to put "x and y", complete with spaces, >> for a simple boolean. > > Perl has also the and logical operator. This is legal Perl: > > if ( $x and $y ) { > ?print "yes\n"; > } That's at a completely different precedence level, isn't it? For operators up where you expect them to be, there's && and ||. A bit of digging (why isn't this sort of thing always the first hit for " operator precedence" in Google?) brought up: http://perldoc.perl.org/perlop.html For instance: $a = $b && $c ? $e : $f; # versus $a = $b and $c ? $e : $f; The first one is an assignment to $a, conditional on two variables. The second is an unconditional assignment to $a, and then based on that, evaluates either $e or $f and does nothing with it. Python: a = e if b and c else f It's pretty similar, actually (although, coming from a C background, I do prefer to have the condition first); but I could crunch the first one down a lot, while the last one is almost as tight as it can be. $a=$b&&$c?$e:$f; a=e if b and c else f It's that crunched appearance that makes Perl look like line noise, and the open keyworded appearance that makes Python look like pseudocode. But that's not necessarily a good thing; a courteous programmer can space out Perl to keep it readable, and he then has the option of crunching pieces that are 'logically one' and spacing out the parts that aren't: $a= $b&&$c ? $e : $f; Silly, contrived example, but in production code I've often had situations where it makes sense to space out one part of an expression and crunch another. And when everything's an English word, that's not an available option. Oh, and that's ignoring the issue that not everyone is fluent in English. That said, though, I do find Python a lot easier for reading other people's code in. A LOT easier. Chris Angelico From python at rcn.com Tue May 24 19:44:21 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 24 May 2011 16:44:21 -0700 (PDT) Subject: Faster Recursive Fibonacci Numbers References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> Message-ID: On May 17, 8:50?am, RJB wrote: > I noticed some discussion of recursion..... the trick is to find a > formula where the arguments are divided, not decremented. > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > for a couple of years in C++ but just for fun rewrote it > in Python. ?It was easy. ?Enjoy. ?And tell me how I can improve it! > > def fibo(n): > ? ? ? ? """A Faster recursive Fibonaci function > Use a formula from Knuth Vol 1 page 80, section 1.2.8: > ? ? ? ? ? ?If F[n] is the n'th Fibonaci number then > ? ? ? ? ? ? ? ? ? ?F[n+m] = F[m]*F[n+1] + F[m-1]*F[n]. > ? First set m = n+1 > ? ?F[ 2*n+1 ] = F[n+1]**2 + F[n]*2. > > ? Then put m = n in Knuth's formula, > ? ? ? ? ? ?F[ 2*n ] = F[n]*F[n+1] + F[n-1]* F[n], > ? ?and replace F[n+1] by F[n]+F[n-1], > ? ? ? ? ? ?F[ 2*n ] = F[n]*(F[n] + 2*F[n-1]). > """ > ? ? ? ? if n<=0: > ? ? ? ? ? ? ? ? return 0 > ? ? ? ? elif n<=2: > ? ? ? ? ? ? ? ? return 1 > ? ? ? ? elif n%2==0: > ? ? ? ? ? ? ? ? half=n//2 > ? ? ? ? ? ? ? ? f1=fibo(half) > ? ? ? ? ? ? ? ? f2=fibo(half-1) > ? ? ? ? ? ? ? ? return f1*(f1+2*f2) > ? ? ? ? else: > ? ? ? ? ? ? ? ? nearhalf=(n-1)//2 > ? ? ? ? ? ? ? ? f1=fibo(nearhalf+1) > ? ? ? ? ? ? ? ? f2=fibo(nearhalf) > ? ? ? ? ? ? ? ? return f1*f1 + f2*f2 > > RJB the Lurkerhttp://www.csci.csusb.edu/dick/cs320/lab/10.html There are many ways to write this function. The one I like shows-off a general purpose dynamic programming technique while staying *very* close to a common textbook definition of a fibonacci number: @functools.lru_cache() def fibo(n): return 1 if n < 2 else fibo(n-1) + fibo(n-2) Raymond From d.awlberg at hotmail.invalid Tue May 24 20:03:17 2011 From: d.awlberg at hotmail.invalid (Deeyana) Date: Wed, 25 May 2011 00:03:17 +0000 (UTC) Subject: Functional Programing: stop using recursion, cons. Use map & vectors References: <24bfd260-385e-4002-a591-6417db1f30f1@r35g2000prj.googlegroups.com> Message-ID: On Tue, 24 May 2011 13:39:15 -0700, asandroq wrote: > On May 24, 12:27?am, Deeyana wrote: >> >> Classic unsubstantiated and erroneous claim. Scheme does not come OOTB >> with any suitable libraries for host interop and though it can make >> calls to C libraries, doing so is awkward and involves difficulties >> with the impedance mismatch between Scheme's data structures and C's >> char *, void *, int, double, array, etc. types. To top it off, C lacks >> automatic memory management, which means you'll have to concern >> yourself with manually disposing of allocated data structures used in >> interop. (Or, worse, things will get garbage collected by the Scheme >> runtime that the Scheme code no longer references, but the C library is >> still using, and bam! SIGSEGV.) > > Classic unsubstantiated and erroneous claim. On your part, asandroq. From rosuav at gmail.com Tue May 24 20:16:00 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 10:16:00 +1000 Subject: Link errors embedding Python 3.2 Message-ID: I'm starting to feel incredibly stupid here. Hopefully someone can point out a really obvious thing that I've missed, thus enabling me to move forward! Up until now, I've been embedding Python 2.6.6 in my C++ program, by compiling with "-I/usr/include/python2.6 -lpython2.6", and all has been well. The Python I use was installed as part of Ubuntu's setup, and is managed by apt-get. Now, I'm trying to switch to using Python 3. so I downloaded the 3.2 sources and did the usual './configure; make; sudo make install', then snooped to see where it had put things. I'm now compiling with "-I/usr/local/include/python3.2m -lpython3.2m", and it's compiling successfully (now that I've changed the function names eg PyString --> PyBytes), but the link fails with heaps of undefined references - as far as I can tell, every single Py* reference is failing. There is a libpython3.2m.a accessible, and poking around with ar and nm shows that it does contain object files with the necessary symbols. If I deliberately misspell the -lpython3.2m option, the link bombs immediately, so presumably it IS finding the library. Explicitly naming the library as ~/Python-3.2/libpython3.2m.a (or using ar to extract them and then linking against the whole directoryful of .o files, which does the same thing) cures the undefined references to Py* functions, but brings in undefined refs to dlsym and openpty and family. Is/are there additional library/ies that I need to be linking against for Python 3? And why is the usual -lpython3.2m not working as normal? Is there a problem with C++ and Python? (I tried surrounding #include "Python.h" with extern "C" { }, but to no avail.) Hoping that someone has already done this! Chris Angelico From jimmy at retzlaff.com Tue May 24 20:26:00 2011 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Tue, 24 May 2011 17:26:00 -0700 Subject: Subject: mrjob v0.2.6 released Message-ID: What is mrjob? ----------------- mrjob is a Python package that helps you write and run Hadoop Streaming jobs. mrjob fully supports Amazon's Elastic MapReduce (EMR) service, which allows you to buy time on a Hadoop cluster on an hourly basis. It also works with your own Hadoop cluster. Some important features: * Run jobs on EMR, your own Hadoop cluster, or locally (for testing). * Write multi-step jobs (one map-reduce step feeds into the next) * Duplicate your production environment inside Hadoop * Upload your source tree and put it in your job's $PYTHONPATH * Run make and other setup scripts * Set environment variables (e.g. $TZ) * Easily install python packages from tarballs (EMR only) * Setup handled transparently by mrjob.conf config file * Automatically interpret error logs from EMR * SSH tunnel to hadoop job tracker on EMR * Minimal setup * To run on EMR, set $AWS_ACCESS_KEY_ID and $AWS_SECRET_ACCESS_KEY * To run on your Hadoop cluster, install simplejson and make sure $HADOOP_HOME is set. More info: * Install mrjob: python setup.py install * Documentation: http://packages.python.org/mrjob/ * PyPI: http://pypi.python.org/pypi/mrjob * Development is hosted at github: http://github.com/Yelp/mrjob What's new? ------------- v0.2.6, 2011-05-24 -- fix bootstrapping mrjob ?* Set Hadoop to run on EMR with --hadoop-version (Issue #71). ? * Default is still 0.18, but will change to 0.20 in mrjob v0.3.0. ?* New inline runner, for testing locally with a debugger ?* New --strict-protocols option, to catch unencodable data (Issue #76) ?* Added steps_python_bin option (for use with virtualenv) ?* mrjob no longer chokes when asked to run on an EMR job flow running Hadoop 0.20 (Issue #110) ?* mrjob no longer chokes on job flows with no LogUri (Issue #112) From memilanuk at gmail.com Tue May 24 20:34:18 2011 From: memilanuk at gmail.com (memilanuk) Date: Tue, 24 May 2011 17:34:18 -0700 Subject: Beginner needs advice In-Reply-To: References: Message-ID: On 05/24/2011 03:17 PM, Lew Schwartz wrote: > Here's my background: > > I'm a Windows based Visual FoxPro developer, and I want to start > programming in Python. I'll be sticking to Windows (XP & 7) and my > immediate needs are to manage & display large groups of jpg's, tiff's > etc... so I need form based & graphics capable libraries (in addition to > basic programming skills, of course). > > So Python 2 or 3? Add on packages/libraries? Tutorials? > > Thanks! > > -Lew > If Visual Foxpro is your thing, maybe Dabo (www.dabodev.com) would be of interest to you. The developers are former Visual Foxpro programmers... From rosuav at gmail.com Tue May 24 20:40:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 10:40:22 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 25, 2011 at 8:06 AM, Rikishi42 wrote: > On 2011-05-24, Steven D'Aprano wrote: > Why not use 'delete a directory'. It's obvious the content gets binned, too. Which is why I raised the issue with regard to other operations. Manipulating files matching a glob can be done recursively or nonrecursively, and both make perfect sense. > Do you know many people who incinerate leaves and branches in their garden? > I burn them. We used to incinerate ours (until we stopped using rapid exothermic oxidation as a means of DECREFfing our garden waste). It's a cultural thing, I guess. >> Do they need to know the words "microwave oven" when they could be saying >> "invisible rays cooking thing"? > > The word oven has existed for ages, microwave is just a name for the type of > oven. Not even a description, just a name. It's funny how a single piece of jargon can go incredibly mainstream. "Microwave" (with or without "oven" after it) is well known, but plenty else remains obscure. >> I wonder whether physicists insist that cars should have a "go faster >> pedal" because ordinary people don't need to understand Newton's Laws of >> Motion in order to drive cars? > > Gas pedal. Pedal was allraedy known when the car was invented. The simple > addition of gas solved that need. Oh, and it's break pedal, not > descellarator. (sp?) Americans might call it a gas pedal. We call it an accelerator. You don't have a "decelerator pedal" though, because it's more accurately called a "brake pedal" because it controls the brakes. Personally, I'm of the opinion that people *should* have some basic understanding of Newton's laws before they take charge of a ton of high-powered machinery. At very least, some basic comprehension of kinetic energy, and the way a high speed train has a *LOT* of it. Might result in drivers with a little more respect for trains and trucks. >> Who are you to say that people shouldn't be exposed to words you deem >> that they don't need to know? > > I'm one of the 'people'. You say exposed to, I say bothered/bored with. > > I have nothing against the use of a proper, precise term. And that word can > be a complex one with many, many sylables (seems to add value, somehow). > > But I'm not an academic, so I don't admire the pedantic use of terms that > need to be explained to 'lay' people. Especially if there is a widespread, > usually shorter and much simpler one for it. A pointless effort if > pointless, even when comming from a physicist. ?:-) In any industry, you can find jargon in several different categories: 1) Terms that describe unique objects/effects/etc, where you would be using a lengthy phrase otherwise (eg "URL") 2) Terms that are clearer or more precise than the less-jargonny equivalents, but where you could get away with dodging jargon if you wanted to (eg "recursive operation") 3) Words and phrases that have little value to an end user, but can be used to show off your skill (eg "Network Destabilisation from Low Voltage Fluorescent Lamp Spikes"). I would never apologise for using terms in the first category. Just explain them (in a footnote if necessary) and expect people to be accurate. The third category is mainly used for invoking Dummy Mode (if you don't know what that is, google my example - it's vintage BOFH), and should be avoided. It's the middle lot that are harder. Do you use it and risk people not understanding, or avoid it and risk people misunderstanding? Tough choice, especially since those who misunderstand often won't know why. If we forever aim to the stupidest of humans, the human race will get stupider. If we forever aim way above people's heads, they won't bother to communicate. An eternal dilemma. Chris Angelico From john at castleamber.com Tue May 24 21:48:30 2011 From: john at castleamber.com (John Bokma) Date: Tue, 24 May 2011 20:48:30 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87mxibsn9l.fsf@castleamber.com> Message-ID: <87ipszsg7l.fsf@castleamber.com> Chris Angelico writes: > On Wed, May 25, 2011 at 9:16 AM, John Bokma wrote: >> Chris Angelico writes: >> >>> Yes, I believe that was Perl. And an amusing quote. But most of the >>> point of it comes from the fact that Perl uses punctuation for most of >>> its keywords, >> >> For example? >> >>> whereas (say) Python uses English words; it's a lot more >>> fun to crunch something down when you can use $| >> >> That's not a keyword but a special (global) variable. On top of that, >> you don't have to use it [1] and most people most likely encounter this in >> (badly) written CGI scripts originating in the last century. > > Okay, poor example. But there's a lot of Perl that uses concise > notation for things that in Python are keyworded; for instance, > regular expressions. Perl does have indeed operators for matching and substitution. It's: ( my $foo = $bar ) =~ s/ ... / ... /; versus foo = re.sub(r" ... ", " ... ", bar ) and: my $foo = qr/ ... /xi; versus: foo = re.compile(r""" ... """, re.IGNORECASE|re.VERBOSE) It's just a matter of taste IMO. The regular expression noise stays the same ;-). >>> and friends than when you have to put "x and y", complete with spaces, >>> for a simple boolean. >> >> Perl has also the and logical operator. This is legal Perl: >> >> if ( $x and $y ) { >> ?print "yes\n"; >> } > > That's at a completely different precedence level, isn't it? Yes, /but/ in this case it doesn't matter. Of course there are cases that it /does/ matter: > For instance: > > $a = $b && $c ? $e : $f; > # versus > $a = $b and $c ? $e : $f; > > The first one is an assignment to $a, conditional on two variables. > The second is an unconditional assignment to $a, and then based on > that, evaluates either $e or $f and does nothing with it. > > Python: > a = e if b and c else f Yes, "recently" added to the language, before that you had to and or your way out of it (or use lambdas). > It's pretty similar, actually (although, coming from a C background, I > do prefer to have the condition first); but I could crunch the first > one down a lot, while the last one is almost as tight as it can be. > > $a=$b&&$c?$e:$f; > a=e if b and c else f > > It's that crunched appearance that makes Perl look like line noise, So you just agree with what I earlier wrote: one /can/ write harder to read in Perl, like you can jump off a cliff. And I have seen a lot of extremely badly written Perl code, but never seen a disaster like the one above ;-). > and the open keyworded appearance that makes Python look like > pseudocode. But that's not necessarily a good thing; a courteous > programmer can space out Perl to keep it readable, and he then has the > option of crunching pieces that are 'logically one' and spacing out > the parts that aren't: > > $a= $b&&$c ? $e : $f; > > Silly, contrived example, but in production code I've often had > situations where it makes sense to space out one part of an expression > and crunch another. And when everything's an English word, that's not > an available option. I would write it like $a = ( $b and $c ) ? $e : $f; > That said, though, I do find Python a lot easier for reading other > people's code in. A LOT easier. Like I wrote earlier: I find Perl easier to read. And honestly, I don't know why. Partially it might have a lot to do with having been exposed to it much more. But many years back, when I could pick between several languages, Perl was the one that stuck with me. And that was before everybody and his mom was hacking CGI scripts in Perl (badly). And while I do want to switch to Python (or use it more often), for one reason or another it's hard. Maybe it's for similar reasons that one loves Spanish but hates German as a second language (or vice versa)? Both Perl and Python are evolving. Perl has a lot of bagage from the beginning, and more so since a lot got slapped on later on. Things are changing, but you just can't make major changes since people, like me I guess, are used to how things are right now. I now and then have peeks at Perl 6 and each time my first reaction is: this is Perl only in name; it's very, very different. On the other hand it still shares what I consider warts with Perl 5. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From no.email at nospam.invalid Wed May 25 00:45:06 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 24 May 2011 21:45:06 -0700 Subject: Abandoning Python References: <87ipt46okh.fsf@pobox.com> Message-ID: <7xy61v5qy5.fsf@ruckus.brouhaha.com> John Lee writes: > In this thread, I'm asking about the views of Python programmers on > languages other than Python. I sympathize with what you're looking for but I don't think there's a really good answer at this time. Things IMO are converging in the direction of functional languages like Haskell but it seems to me that there is a big gap between the current academic ideas and what makes sense for working programmers. The academics aren't all that concerned with practicality, but good solutions really have to incorporate their ideas since the rest of us are rather badly behind the times. Haskell probably has the most vibrant development community at the moment but its learning curve is quite steep, and it has various shortcomings some of which are being worked on but others of which may be insurmountable. If you like the Java ecosystem but not the Java language, check out Scala. You could look for the article "The Next Mainstream Programming Languages" by Tim Sweeney. It discusses similar issues to what I think you are facing. From xahlee at gmail.com Wed May 25 02:05:16 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 24 May 2011 23:05:16 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3f6ff490-3dfd-4b77-9e6d-5da168b3dadd@e17g2000prj.googlegroups.com> On May 24, 3:06?pm, Rikishi42 wrote: > On 2011-05-24, Steven D'Aprano wrote: > > >>> I think that is a patronizing remark that under-estimates the > >>> intelligence of lay people and over-estimates the difficulty of > >>> understanding recursion. > > >> Why would you presume this to be related to intelligence? The point was > >> not about being *able* to understand, but about *needing* to understand > >> in order to use. > > > Maybe they don't "need" to understand recursion. So what? > > I think you should read the earlier posts again, this is drifting so far > from what I intended. > > What I mean is: I'm certain that over the years I've had more than one > person come to me and ask what 'Do you wish to delete this directory > recursively?' meant. BAut never have I been asked to explain what 'Do you > wish to delete this directory and it's subdirs/with all it's contents?' > meant. Never. > > > Recursion is a perfectly good English word, no more technical than > > "accelerate" or "incinerate" or "dissolve" or "combustion". Do people > > need to know the word "combustion" when they could say "burn" instead? > > It wasn't about the word, but about the nature of the function. Besides, if > the chance exists of a confusion between a recursive job and the fact the > job is done using a recursive function... I would try staying away from the > expression. ? > > Why not use 'delete a directory'. It's obvious the content gets binned, too. > > Do you know many people who incinerate leaves and branches in their garden? > I burn them. > > > Do they need to know the words "microwave oven" when they could be saying > > "invisible rays cooking thing"? > > The word oven has existed for ages, microwave is just a name for the type of > oven. Not even a description, just a name. > > > I wonder whether physicists insist that cars should have a "go faster > > pedal" because ordinary people don't need to understand Newton's Laws of > > Motion in order to drive cars? > > Gas pedal. Pedal was allraedy known when the car was invented. The simple > addition of gas solved that need. Oh, and it's break pedal, not > descellarator. (sp?) > > > Who are you to say that people shouldn't be exposed to words you deem > > that they don't need to know? > > I'm one of the 'people'. You say exposed to, I say bothered/bored with. > > I have nothing against the use of a proper, precise term. And that word can > be a complex one with many, many sylables (seems to add value, somehow). > > But I'm not an academic, so I don't admire the pedantic use of terms that > need to be explained to 'lay' people. Especially if there is a widespread, > usually shorter and much simpler one for it. A pointless effort if > pointless, even when comming from a physicist. ?:-) very well said, Rikishi42. this one is probably the most intelligent post in this thread. Xah From lew1716 at gmail.com Wed May 25 02:22:14 2011 From: lew1716 at gmail.com (Lew Schwartz) Date: Wed, 25 May 2011 02:22:14 -0400 Subject: Beginner needs advice In-Reply-To: <4DDC7938.5000900@gmail.com> References: <4DDC7938.5000900@gmail.com> Message-ID: So, if I read between the lines correctly, you recommend Python 3? Does the windows version install with a development environment? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Wed May 25 02:36:11 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 25 May 2011 08:36:11 +0200 Subject: Obtaining a full path name from file References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: RVince wrote: > s = "C:\AciiCsv\Gravity_Test_data\A.csv" > f = open(s,"r") > > How do I obtain the full pathname given the File, f? Apart from the issue that the 'name' attribute is only the name used to open the file, there is another issue, though not on the platform you're using: Multiple directory entries can point to the same file, all of which can be changed (including deletion!) even while you have the file open. I'm not sure what problem you're trying to solve, but I'm afraid your approach is at least limited. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From mail at timgolden.me.uk Wed May 25 03:17:38 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 25 May 2011 08:17:38 +0100 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: <201105242318.32306.claudiu@virtuamagic.com> References: <201105242017.27919.claudiu@virtuamagic.com> <201105242318.32306.claudiu@virtuamagic.com> Message-ID: <4DDCAD12.4050203@timgolden.me.uk> On 24/05/2011 21:18, Claudiu Nicolaie CISMARU wrote: > Now. There is one more issue. Seems that on faster computers and/or > Windows 7 (the Win32 thing I have tested on a HVM Xen machine with > Windows XP) the os.rename is too fast after fp.close() and generates the > same Exception. The code follows: > > curl.close() > fp.close() > os.rename(tfile, actualfile) > > Where, tfile is the .part file, actual file is the real destination, fp > was opened with open(..., "wb") and the descriptor passed to curl. > > I have solved the issue with self.msleep(10) - msleep is a method of > QThread. But I don't think it's an elegant and normal solution. Did > fp.close() is delayed, or? I mean, I don't want to rely on a "sleep" in > order to workaround the access issue. There used to be a problem with subprocess fds being held by a traceback. IIRC, the problem could be triggered by having an except clause around a subprocess call within which something attempted to, eg, remove one of the affected files. I'm sorry if that's a bit of a woolly description but if you think this might be biting you I'll dive in and look at the code. What version of Python are you using? (That said, the fact that the behaviour varies between faster and slower computers makes that cause unlikely. Maybe we're back to looking at virus checkers and the like...) TJG From __peter__ at web.de Wed May 25 03:22:31 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 25 May 2011 09:22:31 +0200 Subject: Code Review References: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> Message-ID: ad wrote: > Please review the code pasted below. I am wondering what other ways > there are of performing the same tasks. This was typed using version > 3.2. The script is designed to clean up a directory (FTP, Logs, etc.) > Basically you pass two arguments. The first argument is an number of > days old to delete. The second argument is the directory where the > files and folders should be deleted. I imagine one enhancement would > be to create a function out of some of this. > CurrentTime = time.time() Read PEP 8 on naming conventions etc., see http://python.org/dev/peps/pep-0008/ > > epocDay = 86400 # seconds > > > > > > parser = argparse.ArgumentParser(description = "Delete files and What's the purpose of those many empty lines? > folders in a directory N days old", add_help=False, > prog='directorycleaner', usage='%(prog)s 7 c:\\temp') > > parser.add_argument('days', type=int, help="Numeric value: delete > files and folders older then N days") > > parser.add_argument('directory', help="delete files and folders in > this directory") > > parser.print_help() What's the idea behind add_help=False and the explicit print_help()? > dictKeys = (vars(args)) > HowManyDays = dictKeys['days'] This can be simplified to HowManyDays = args.days > if dirExists == False: print ("The directory is missing") if x == False: ... is normally written as if not x: ... > DirListing = os.listdir(WhatDirectory) > for files in DirListing: You might write this as for filename in os.listdir(WhatDirectory): ... or even for filename in os.listdir(args.directory): ... Personally I would put this stuff in a separate function like def remove_old_files_and_folders(parent_directory, age_in_seconds): ... > # time.ctime converts epoch to a normal date > > #print (time.ctime(CurrentTime)) > > # Get the date from seven days ago > > WeekOldFileDate = CurrentTime - DaysToDelete > > #print (CurrentTime) > > #print (FileCreationTime) > > #print (WeekOldFileDate) Don't let out-commented code eclipse the actual code; remove it. If you want to preserve it for eternity, have a look at version control systems, e. g. Mercurial. From thorsten at thorstenkampe.de Wed May 25 03:26:11 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 25 May 2011 09:26:11 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Rikishi42 (Wed, 25 May 2011 00:06:06 +0200) > > On 2011-05-24, Steven D'Aprano wrote: > >>> I think that is a patronizing remark that under-estimates the > >>> intelligence of lay people and over-estimates the difficulty of > >>> understanding recursion. > >> > >> Why would you presume this to be related to intelligence? The point was > >> not about being *able* to understand, but about *needing* to understand > >> in order to use. > > > > Maybe they don't "need" to understand recursion. So what? > > I think you should read the earlier posts again, this is drifting so far > from what I intended. > > What I mean is: I'm certain that over the years I've had more than one > person come to me and ask what 'Do you wish to delete this directory > recursively?' meant. BAut never have I been asked to explain what 'Do you > wish to delete this directory and it's subdirs/with all it's contents?' > meant. Never. Naming something in the terms of its implementation details (in this case recursion) is a classical WTF. On the other hand, it's by far not the only WTF in Unix. For instance, how often have you read "unlink" instead of "delete"? Or "directory" instead of "folder", pointing out that "directory" is the correct term because a directory is just a listing and does not "contain" the actual files. Of course these implementation details will never matter to anyone except under the rarest conditions. Thorsten From mail at timgolden.me.uk Wed May 25 03:29:11 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 25 May 2011 08:29:11 +0100 Subject: Obtaining a full path name from file In-Reply-To: References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: <4DDCAFC7.7060201@timgolden.me.uk> On 25/05/2011 07:36, Ulrich Eckhardt wrote: > RVince wrote: >> s = "C:\AciiCsv\Gravity_Test_data\A.csv" >> f = open(s,"r") >> >> How do I obtain the full pathname given the File, f? > > Apart from the issue that the 'name' attribute is only the name used to open > the file, there is another issue, though not on the platform you're using: > Multiple directory entries can point to the same file, all of which can be > changed (including deletion!) even while you have the file open. FWIW that's true even on Windows. (Although arguably less common). > I'm not sure what problem you're trying to solve, but I'm afraid your > approach is at least limited. Depends on what the requirement is. If it is, essentially: "give me at least one of the names this file had when I opened it", then this approach is surely adequate. Certainly, things could have happened in the meantime. Obviously, only the OP can know the circumstances he's dealing with, but ISTM that far and away the most common case will be that the file has exactly one name and that it hasn't changed. TJG From thorsten at thorstenkampe.de Wed May 25 03:31:33 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 25 May 2011 09:31:33 +0200 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: * Chris Angelico (Wed, 25 May 2011 08:01:38 +1000) > > On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain wrote: > > One of my favorite quotes (not sure if it was about Perl or APL) is "I > > refuse to use a programming language where the proponents of it stick > > snippets under each other's nose and say 'I bet you can't guess what > > this does.'" > > Yes, I believe that was Perl. And an amusing quote. But most of the > point of it comes from the fact that Perl uses punctuation for most of > its keywords, whereas (say) Python uses English words; it's a lot more > fun to crunch something down when you can use $| and friends than when > you have to put "x and y", complete with spaces, for a simple boolean. > But that says nothing about which language is actually better for > working with... [...] It does say something about readibility. And yes, "readability counts". And yes, readability says a lot about how good a language is for reading and working with. Thorsten From nospam at torek.net Wed May 25 03:37:51 2011 From: nospam at torek.net (Chris Torek) Date: 25 May 2011 07:37:51 GMT Subject: Code Review References: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> Message-ID: In article <37ba7b40-3663-4094-b507-696fc598bf48 at l26g2000yqm.googlegroups.com> ad wrote: >Please review the code pasted below. I am wondering what other ways >there are of performing the same tasks. ... I imagine one enhancement >would be to create a function out of some of this. Indeed -- "recommended styles" include defining a main() function and calling main at the bottom, e.g., with: if __name__ == '__main__': main() or: if __name__ == '__main__': main(sys.argv) Something has also double-spaced your code; I will undo that below. >import os >import time >import shutil >import argparse So far so good. Let me start by putting the next parts into main(). I will use the no-argument format since we can simply let parser.parse_args() fetch sys.argv the same way you did (we could def main(argv) and pass argv; this is sometimes useful for testing purposes, but here it makes little difference one way or another). def main(): > CurrentTime = time.time() > epocDay = 86400 # seconds (You could write 24 * 60 * 60, but again this is sort of a six-of-one half-a-dozen-of-the-other situation.) What is not clear is why you are setting these now, rather than later, closer to where they are going to be used. Many style guides, including Guido's and pylint's, dislike UppercaseVariableName and camelCase style names within functions. (UppercaseNames are reserved to classes.) I am leaving these alone for now though. > parser = argparse.ArgumentParser(description = "Delete files and > folders in a directory N days old", add_help=False, > prog='directorycleaner', usage='%(prog)s 7 c:\\temp') Line wrap has done bad things to this. Still, there is something odd about it other than the line wrap: - sometimes you write: param_name = value but sometimes you use: param_name=value and in one case you even use both: usage= [string] - you switch back and forth between single and double quoted strings, without much reason. Consistency is not *required* but it is generally a good idea. (This is also minor, like deciding between 86400 or 24*60*60. Eventually, though, lots of minor things add up.) (I have to admit here that I tend to switch back and forth on quotes too. :-) ) Another "sixes" case occurs here with the backslashes: to get a literal backslash in a string, you can use "raw strings". Here it makes no difference but I will go ahead and do it just for illustration: parser = argparse.ArgumentParser( description='Delete files and folders in a directory N days old', add_help=False, prog='directorycleaner', usage=r'%(prog)s 7 c:\temp') Finally, I am not sure why you do not want to allow a -h / --help option (but if you take out the add_help=False, it's probably best to take out the call to parser.print_help() too), and there is no need to supply a usage= argument at all -- argparse() will build one for you. > parser.add_argument('days', type=int, help="Numeric value: delete > files and folders older then N days") > parser.add_argument('directory', help="delete files and folders in > this directory") (Again, line wrap has broken these; the fixes are obvious so I skip over them here.) > parser.print_help() > args = parser.parse_args() (So far so good, although again, you probably want to remove the call to print_help() if you allow argparse to add a -h / --help option, at least.) > dictKeys = (vars(args)) There is no *need* to do this, although it is documented as allowed. I prefer to just use args. myself: > HowManyDays = dictKeys['days'] > WhatDirectory = dictKeys['directory'] so this would become: HowManyDays = args.days WhatDirectory = args.directory > print (HowManyDays) > print (WhatDirectory) These are presumably debug statements and should be removed, but until then, it might be good to prefix the output with what is being printed (i.e., a debug message). (I have taken them out of my copy, for output shown below.) (In a fancier program, you could use the logging module and logging.debug().) > DaysToDelete = HowManyDays * epocDay Right before this would be a good place to create epocDay. > dirExists = os.path.exists(WhatDirectory) > if dirExists == False: print ("The directory is missing") An explicit "if expr == False" is generally a bad idea -- if an expression can be "considered boolean" (and the return value of os.path.exists certainly can), just write "if not expr". Most style guides suggest putting subsequent statements on new lines, rather than right after the ":". Checking that the directory exists seems reasonable enough. However, after printing that it does not, you continue on with code that is going to immediately raise an OSError exception: > DirListing = os.listdir(WhatDirectory) In general, it is better to try to do the operation, and catch the failure and do something about it at that point, than to test to see if the operation is going to succeed. (Among other things, this avoids a "race" between program 1 that says "does some directory exist" and program 2 that says "delete the directory". If program 1 "wins" this race, the directory does exist at the point of the test, then program 2 deletes it, then program 1 goes on to access the now-deleted directory ... and crashes.) I am using a Unix-like system so what I get may not be quite the same as what you would get on a Windows-like system, but: % cd /tmp % python foo.py 1 /tmp/nosuchdir The directory is missing Traceback (most recent call last): ... OSError: [Errno 2] No such file or directory: '/tmp/nosuchdir' % More significantly, consider this: % python foo.py 1 /tmp/foo.py Traceback (most recent call last): ... OSError: [Errno 20] Not a directory: '/tmp/foo.py' % So instead of the three previous lines, consider: try: DirListing = os.listdir(WhatDirectory) except OSError as err: sys.exit("can't read %s: %s" % (WhatDirectory, err)) (you will need to "import sys", and I am using an older version of Python and the "except OSError, err" syntax, but the effect is the same). Now the second example results in: % python foo.py 1 /tmp/foo.py can't read /tmp/foo.py: [Errno 20] Not a directory: '/tmp/foo.py' % > for files in DirListing: > # Get the absolute path of the file name > abspath = (os.path.join(WhatDirectory, files)) This is not necessarily an absolute path -- for instance, if the program is run as: python foo.py 7 rel\ative\path the joined file names (on a Windows-like system) will be things like "rel\ative\path\file.txt" and so on. I would suggest shortening the variable name to just "path". The outermost set of parentheses are unnecessary, too. > # Get the current creation time of the file in epoc format > # (midnight 1/1/1970) > FileCreationTime = (os.path.getctime(abspath)) Beware: on Unix-like systems, this gets a "time of last change" rather than a "time of create". Even if you are sure you will use Windows you may wish to use the file's mtime (time of last "modification"; on Unix-like systems, the distinction between a "modification" and a "change" is that "change" covers alterations to the file's meta-data as well as the data, e.g., "chmod a-w file", making it read-only, changes its ctime but not its mtime, while "echo foo >> file" changes both its ctime and its mtime -- provided it is not read-only, of course :-) ). Again, the outermost parentheses here are unnecessary. > # time.ctime converts epoch to a normal date > #print (time.ctime(CurrentTime)) > # Get the date from seven days ago > WeekOldFileDate = CurrentTime - DaysToDelete > #print (CurrentTime) > #print (FileCreationTime) > #print (WeekOldFileDate) > > #If the file is older than seve days doe something Apparently, the program has evolved somewhat: originally you had "seven days" hardcoded, now you have a variable number. The comments, however, have not changed -- and the final variable name is no longer appropriate. It is probably also time to ditch the commented-out debug print statements (and fix the comments, including the typo on the last one above). > if FileCreationTime < WeekOldFileDate: > #check if the object is a file > if os.path.isfile(abspath): os.remove(abspath) > # It is not a file it is a directory > elif os.path.isdir(abspath): shutil.rmtree(abspath) Again, the comment and code do not quite agree: the comment says "if it is not a file it *is* a directory" but the code says "if it is not a file, check to see if it is a directory", which leaves open the possibility that it is some other kind of entity (this is definitely possible on a Unix-like system, where it could be a socket, symbolic link, or device node, for instance). In this particular program, written the way it is, there is no actual benefit (yet) to doing this, but I suggest moving the guts of the "clean out a directory" process into a function. What this allows is the ability to list more than one directory, provided of course you also change the argument parser a bit. Having put this all together (and neutered the actual file-or-directory removing code) gives me the code below. There are still plenty of things you could do with it -- for instance, exiting partway through processing a list of directories if one in the middle does not exist is perhaps not optimal: % python foo.py 7 /tmp/dir1 /tmp/oops /tmp/dir2 (where /tmp/dir1 and /tmp/dir2 do exist, but /tmp/oops does not) will clean out /tmp/dir1 but then exit without ever processing /tmp/dir2. (There are lots of ways to handle this; you would have to choose one and implement it.) Or, instead of the kind of processing done here, you could generalize it into a Unix-like "find" command. (Perhaps with a less-ugly syntax. :-) ) The "find" command can do what this script does: find DIRLIST -ctime +N ( -type d -o -type f ) -exec rm -rf {} \; but can also a great deal more since (a) it has many other options than just -ctime, and (b) -exec will execute any arbitrary command. --------------------------- import os import time import shutil import argparse import sys def main(): """ main program: parse arguments, and clean out directories. """ parser = argparse.ArgumentParser( description="Delete files and folders in a directory N days old", prog="directorycleaner") parser.add_argument("days", type=int, help="Numeric value: delete files and folders older than N days") parser.add_argument("directory", nargs="+", help="delete files and folders in this directory") args = parser.parse_args() for dirname in args.directory: clean_dir(dirname, args.days) def clean_dir(dirname, n_days): """ Clean one directory of files / subdirectories older than the given number of days. """ time_to_live = n_days * 86400 # 86400 = seconds-per-day current_time = time.time() try: contents = os.listdir(dirname) except OSError, err: sys.exit("can't read %s: %s" % (dirname, err)) for filename in contents: # Get the path of the file name path = os.path.join(dirname, filename) # Get the creation time of the file # NOTE: this only works on Windows-like systems when_created = os.path.getctime(path) # If the file/directory has expired, remove it if when_created + time_to_live < current_time: if os.path.isfile(path): print "os.remove(%s)" % path # It is not a file it is a directory elif os.path.isdir(path): print "shutil.rmtree(%s)" % path if __name__ == "__main__": main() -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From shobadevi75 at gmail.com Wed May 25 03:40:50 2011 From: shobadevi75 at gmail.com (shoba kasthuri) Date: Wed, 25 May 2011 00:40:50 -0700 (PDT) Subject: BEST WAY TO EARN DOLLARS FROM COMPANY JUST SUBSCRIBE AND SEE , JOIN NOW Message-ID: <2f426438-5f64-4c92-af0a-64dae01b3bce@l14g2000pro.googlegroups.com> shoba.1915 at rediffmail.com From xahlee at gmail.com Wed May 25 03:51:47 2011 From: xahlee at gmail.com (Xah Lee) Date: Wed, 25 May 2011 00:51:47 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <84d8a4d0-d3ca-474c-9f25-8198804e1972@18g2000prd.googlegroups.com> On May 25, 12:26?am, Thorsten Kampe wrote: > * Rikishi42 (Wed, 25 May 2011 00:06:06 +0200) > > > > > > > > > > > > > On 2011-05-24, Steven D'Aprano wrote: > > >>> I think that is a patronizing remark that under-estimates the > > >>> intelligence of lay people and over-estimates the difficulty of > > >>> understanding recursion. > > > >> Why would you presume this to be related to intelligence? The point was > > >> not about being *able* to understand, but about *needing* to understand > > >> in order to use. > > > > Maybe they don't "need" to understand recursion. So what? > > > I think you should read the earlier posts again, this is drifting so far > > from what I intended. > > > What I mean is: I'm certain that over the years I've had more than one > > person come to me and ask what 'Do you wish to delete this directory > > recursively?' meant. BAut never have I been asked to explain what 'Do you > > wish to delete this directory and it's subdirs/with all it's contents?' > > meant. Never. > > Naming something in the terms of its implementation details (in this > case recursion) is a classical WTF. > > On the other hand, it's by far not the only WTF in Unix. For instance, > how often have you read "unlink" instead of "delete"? Or "directory" > instead of "folder", pointing out that "directory" is the correct term > because a directory is just a listing and does not "contain" the actual > files. Of course these implementation details will never matter to > anyone except under the rarest conditions. > > Thorsten well said. half of posts in this thread are from idiots. just incredible, but again, its newsgroups ... what am i thinking ... Xah From rosuav at gmail.com Wed May 25 03:59:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 17:59:24 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <84d8a4d0-d3ca-474c-9f25-8198804e1972@18g2000prd.googlegroups.com> References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <84d8a4d0-d3ca-474c-9f25-8198804e1972@18g2000prd.googlegroups.com> Message-ID: On Wed, May 25, 2011 at 5:51 PM, Xah Lee wrote: > well said. > > half of posts in this thread are from idiots. just incredible, but > again, its newsgroups ... what am i thinking ... > > ?Xah > Thank you. As soon as we figure out which half of us you just publicly insulted, we'll see about getting offended. Until then, thank you for your contribution and please, have a nice day. Chris Angelico removing tongue from cheek From ulrich.eckhardt at dominolaser.com Wed May 25 04:06:39 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 25 May 2011 10:06:39 +0200 Subject: Code Review References: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> Message-ID: ad wrote: > Please review the code pasted below. I am wondering what other ways > there are of performing the same tasks. On a unix system, you would call "find" with according arguments and then handle the found files with "-exec rm ..." or something like that, but I see you are on MS Windows. > args = parser.parse_args() > > dictKeys = (vars(args)) The first of these looks okay, while I don't get the additional brackets in the second one. Another habit I observe here is the Hungarian notation of prefixing the type to the name and using camelCaps. PEP 8 (IIRC) has something to say on the preferred naming. I'm not 100% against encoding the type in the variable name in Python, since it lacks static type checking, I would have chosen "key_dict" here though, or, due to the small size of the overall program just "keys". > print (HowManyDays) This puzzled me at first, again the useless additional brackets I thought. However, in Python 3, "print" is a function, so that is correct. Still, it should be "print(foo)" not "print (foo)". > for files in DirListing: > > # Get the absolute path of the file name > abspath = (os.path.join(WhatDirectory, files)) "files" is just the name of a single file, right? In that case the name is a bit confusing. > # Get the date from seven days ago > WeekOldFileDate = CurrentTime - DaysToDelete You are repeating this calculation for every file in the loop. > if FileCreationTime < WeekOldFileDate: > #check if the object is a file > if os.path.isfile(abspath): os.remove(abspath) > # It is not a file it is a directory > elif os.path.isdir(abspath): shutil.rmtree(abspath) I'm not sure, but I believe you could use shutil.rmtree() for both files and directories. In any case, be prepared for the file still being open or otherwise read-only, i.e. for having to handle errors. Also, what if a directory is old but the content is new? Would this cause the non-old content to be deleted? Cheers! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From affdfsdfdsfsd at b.com Wed May 25 04:18:48 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: Wed, 25 May 2011 10:18:48 +0200 Subject: pyGTK identify a button Message-ID: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Hi all, i'm trying to write a simple windows with two button in GTK, i need a way to identify wich button is pressed. Consider that: the two button are connected (when clicked) to infoButton(self, widget, data=None) infoButton() is something like this infoButton(self, widget, data=None): # discover wich button was pressed ... # say hello to the button if button1pressed: print "Hi, button1!" else: print "Hi, button2!" so, how can I know wich button was pressed without using data and without reading the label of the button (i could have buttons with the same label) If data is needed, can someone pls tell me how to set it properly in glade 3.8 thanks Nico From claudiu at virtuamagic.com Wed May 25 04:20:45 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Wed, 25 May 2011 11:20:45 +0300 Subject: File access denied after subprocess completion on Windows platform In-Reply-To: <4DDCAD12.4050203@timgolden.me.uk> References: <201105242318.32306.claudiu@virtuamagic.com> <4DDCAD12.4050203@timgolden.me.uk> Message-ID: <201105251120.47996.claudiu@virtuamagic.com> > There used to be a problem with subprocess fds being held by > a traceback. IIRC, the problem could be triggered by having > an except clause around a subprocess call within which something > attempted to, eg, > remove one of the affected files. I have no subprocess call.. in this last issue. And I didn't triggered one (disabled the Button that runs the subprocess). try: for line in t.splitlines(): [...] ret = self.downloadFileToDisk(filename, do_rename) if not ret: print "DEBUG: Problema la download" raise Exception() (1) except Exception as inst: print type(inst) print inst.args self.updateText.emit("EROARE: Eroare la descarcare") self.updateStatusBar.emit("EROARE: Eroare la descaracare fisiere") return Where downloadFileToDisk(): def downloadFileToDisk(self, filename, final_rename=True): dfilename = os.path.join(saveBasePATH, filename) sfilename = dfilename + ".part" dfolder = os.path.dirname(sfilename) if dfolder != "": if not os.path.isdir(dfolder): os.makedirs(dfolder) try: fp = open(sfilename, "wb") except: return False curl = pycurl.Curl() curl.setopt(pycurl.URL, baseUpdateURL + "/client/" + filename) curl.setopt(pycurl.CONNECTTIMEOUT, 30) curl.setopt(pycurl.NOPROGRESS, 0) curl.setopt(pycurl.FOLLOWLOCATION, 1) curl.setopt(pycurl.MAXREDIRS, 5) curl.setopt(pycurl.PROGRESSFUNCTION, self.updateFileProgress) curl.setopt(pycurl.WRITEDATA, fp) curl.setopt(pycurl.BUFFERSIZE, 4194304) curl.setopt(pycurl.NOSIGNAL, 1) curl.perform() retcode = curl.getinfo(pycurl.HTTP_CODE) curl.close() fp.close() if retcode != 200: (2) os.unlink(sfilename) return False self.msleep(10) if final_rename: os.rename(sfilename, dfilename) return True Without self.msleep(10), (1) catches WindowsError: file access ... blah blah. Maybe at (2) can be an access violation, but it wasn't triggered yet in tests. I will move the sleep after fp.close(). Yes, I know that what it've done with raise Exception() is UGLY, since this program it's more a quick hack solution to a problem :). Anyway the Exception that is catched is not rised by my code (it's a WindowsError). > I'm sorry if that's a bit > of a woolly description but if you think this might be > biting you I'll dive in and look at the code. What version > of Python are you using? Last 2.7.x. Well, if os.rename is instead a subprocess call, then it's subprocess based. I'm new to Python but 99% I think it's a system call :) > (That said, the fact that the behaviour varies between faster > and slower computers makes that cause unlikely. Maybe we're > back to looking at virus checkers and the like...) On that virtual machine there is no virus checker. On the faster machine I disabled and closed the antivirus. -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From claudiu at virtuamagic.com Wed May 25 04:44:12 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Wed, 25 May 2011 11:44:12 +0300 Subject: pyGTK identify a button In-Reply-To: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Message-ID: <201105251144.15257.claudiu@virtuamagic.com> > the two button are connected (when clicked) to infoButton(self, > widget, > data=None) From documentation: handler_id = object.connect(name, func, func_data) So: button1.connect(when is pressed, your_function, 1) button2.connect(when is pressed, your_function, 2) (This code is conception, I don't really know how is done in GTK). On the callback: infoButton(self, widget, data=None): # discover wich button was pressed ... # say hello to the button if data == 1: print "Hi, button1!" else: print "Hi, button2!" -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From gagsl-py2 at yahoo.com.ar Wed May 25 04:50:44 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 May 2011 05:50:44 -0300 Subject: Hotshoting recursive function References: Message-ID: En Sun, 22 May 2011 10:42:08 -0300, Selvam escribi?: > I am using hotshot module to profile my python function. > > I used the details from ( > http://code.activestate.com/recipes/576656-quick-python-profiling-with-hotshot/ > ). > > The function I profile is a recursive one and I am getting the following > error, > > "ProfilerError: profiler already active" > > I guess this is due to the recursive call to the profiling function. > > I would like to get some suggestions. The recursive call inside your function should call the undecorated function, not the decorated function again. Decorator syntax is not convenient anymore. Using the same names as in the recipe example: # a recursive function def my_slow_function(n): ... return my_slow_function(n-1) my_profiled_slow_function = hotshotit(my_slow_function) my_profiled_slow_function(n) This works, in the sense that it does not raise ProfileError anymore. Interpreting profile data is up to you... -- Gabriel Genellina From affdfsdfdsfsd at b.com Wed May 25 04:51:50 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: Wed, 25 May 2011 10:51:50 +0200 Subject: pyGTK identify a button In-Reply-To: References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Message-ID: <4ddcc326$0$18248$4fafbaef@reader2.news.tin.it> On 25/05/2011 10:44, Claudiu Nicolaie CISMARU wrote: >> the two button are connected (when clicked) to infoButton(self, >> widget, >> data=None) > > From documentation: > handler_id = object.connect(name, func, func_data) > > So: > > button1.connect(when is pressed, your_function, 1) > button2.connect(when is pressed, your_function, 2) > (This code is conception, I don't really know how is done in GTK). thanks but, as i've sayed before, i can't use func_data 'cause i don't know how to set it on glade3.8, that is the program i use to create the GUI. Anyway, i think this is the only way to identify the button :-/ From rosuav at gmail.com Wed May 25 04:53:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 18:53:20 +1000 Subject: Link errors embedding Python 3.2 In-Reply-To: References: Message-ID: Followup. I'm now using Python 3.3 straight from Mercurial, and am seeing the same issues. I've managed to get the compilation step to succeed by naming the library for full inclusion and adding -lutil -ldl (sounding rather Donizetti there), and my program runs. However, it's unable to import all its modules. I can happily import re, string, and sys, but importing math or time results in an ImportError citing "undefined symbol: PyExc_ValueError". I think there's still something I'm mucking up in the link process. The exception is ImportError, with text: '/usr/local/lib/python3.3/lib-dynload/time.cpython-33m.so: undefined symbol: PyExc_ValueError' Any ideas? Chris Angelico From rosuav at gmail.com Wed May 25 04:58:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 18:58:16 +1000 Subject: pyGTK identify a button In-Reply-To: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Message-ID: On Wed, May 25, 2011 at 6:18 PM, Tracubik wrote: > Hi all, > i'm trying to write a simple windows with two button in GTK, i need a way to > identify wich button is pressed. > Consider that: > > the two button are connected (when clicked) to infoButton(self, widget, > data=None) I'm not terribly familiar with GTK, but I believe the 'widget' parameter is the button that was clicked on. Whatever means you have for distinguishing them (saving another reference to each object in a named variable, etc), you should be able to do with that parameter. Chris Angelico From claudiu at virtuamagic.com Wed May 25 05:19:00 2011 From: claudiu at virtuamagic.com (Claudiu Nicolaie CISMARU) Date: Wed, 25 May 2011 12:19:00 +0300 Subject: pyGTK identify a button In-Reply-To: <4ddcc326$0$18248$4fafbaef@reader2.news.tin.it> References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> <4ddcc326$0$18248$4fafbaef@reader2.news.tin.it> Message-ID: <201105251219.02700.claudiu@virtuamagic.com> > thanks but, as i've sayed before, i can't use func_data 'cause i don't > know how to set it on glade3.8, that is the program i use to create > the > GUI. > Anyway, i think this is the only way to identify the button :-/ Hack into the generated source! -- Claudiu Nicolaie CISMARU GNU GPG Key: http://claudiu.targujiu.net/key.gpg T: +40 755 135455 E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: From jeanmichel at sequans.com Wed May 25 05:22:52 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 25 May 2011 11:22:52 +0200 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> Message-ID: <4DDCCA6C.5020204@sequans.com> Lew Schwartz wrote: > So, if I read between the lines correctly, you recommend Python 3? > Does the windows version install with a development environment? If you want to use python 3, make sure before that all the good stuff you need (==modules) have been ported to python 3. If you are a complete beginner, I would advise python 2.7. JM From gagsl-py2 at yahoo.com.ar Wed May 25 05:45:17 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 May 2011 06:45:17 -0300 Subject: pexpect: TIMEOUT no longer clears child.before References: Message-ID: En Thu, 19 May 2011 08:29:21 -0300, Adrian Casey escribi?: > The behaviour of pexpect has changed between version 2.1 and 2.3. In > version 2.1, the following code would result in child.before being > cleared -: > > >>>child.expect(pexpect.TIMEOUT,1) > In version 2.3, this is no longer the case. No matter how many times > the above code is run, child.before continues to hold the output from > previous commands. It is important to be able to clear the contents of > child.before between each command. What is the correct way to do this > in version 2.3? Try contacting the author: www.noah.org -- Gabriel Genellina From srini605 at gmail.com Wed May 25 06:03:03 2011 From: srini605 at gmail.com (srinivasan munisamy) Date: Wed, 25 May 2011 15:33:03 +0530 Subject: [pyodbc] Setting values to SQL_* constants while creating a connection Message-ID: Hi, I would like to know how to set values to values to SQL_* constants while creating a db connection through pyodbc module. For example, i am getting a connection object like below: In [27]: dbh1 = pyodbc.connect("DSN=;UID= ;PWD=;DATABASE=;APP=") In [28]: dbh1.getinfo(pyodbc.SQL_DESCRIBE_PARAMETER) Out[28]: True I want to set this SQL_DESCRIBE_PARAMETER to false for this connection object. How could i do that? Please help me in figuring it out. Thanks, Srini -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed May 25 06:15:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 10:15:53 GMT Subject: English Idiom in Unix: Directory Recursively References: <9e1166f5-d239-4343-a0fc-7703e80b722b@r35g2000prj.googlegroups.com> <0d98ccf7-2f5c-479a-8450-3b956147cdb6@q14g2000prh.googlegroups.com> Message-ID: <4ddcd6d8$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 08:14:27 +1000, Chris Angelico wrote: > On Wed, May 25, 2011 at 3:40 AM, Xah Lee wrote: >> On May 23, 9:28?pm, Chris Angelico wrote: >>> Because I do not consider its behaviour to be errant. And I suspect >>> its main developers won't either. That's why I suggested you grab the >>> sources and make The Perfect Emacs. >> >> why don't you try http://ergoemacs.org/ ? > > You miss my point. I am not desiring of a different emacs; you were the > one complaining about its shortcomings. It's Xah Lee. Of course he misses your point. He refuses to stop spamming newsgroups even after being banned by his ISP, and he refuses to listen to any opinion that doesn't agree with his own. Everyone else is an idiot. -- Steven From davea at ieee.org Wed May 25 07:05:16 2011 From: davea at ieee.org (Dave Angel) Date: Wed, 25 May 2011 07:05:16 -0400 Subject: Obtaining a full path name from file In-Reply-To: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> References: <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> Message-ID: <4DDCE26C.10305@ieee.org> On 01/-10/-28163 02:59 PM, RVince wrote: > s = "C:\AciiCsv\Gravity_Test_data\A.csv" > f = open(s,"r") > > How do I obtain the full pathname given the File, f? (which should > equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff > and am just not finding it. Any help greatly appreciated ! > I saw lots of responses, but I don't think anybody pointed out that the filename is probably invalid. This particular string will work, but if you have a directory that starts with a T or an N, you may get some surprises. The backslash is treated specially in a literal string. When building a Windows directory name in a literal string, you generally need to do one of three things: 1) use raw literals 2) double the backslash 3) use a forward slash DaveA From info at egenix.com Wed May 25 07:24:13 2011 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 25 May 2011 13:24:13 +0200 Subject: ANN: eGenix mxODBC - Python ODBC Database Interface 3.1.1 Message-ID: <4DDCE6DD.2060601@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC - Python ODBC Database Interface Version 3.1.1 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Mac OS X, Unix and BSD platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.1.1-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more: http://www.egenix.com/products/python/mxODBC/ The "eGenix mxODBC - Python ODBC Database Interface" product is a commercial extension to our open-source eGenix mx Base Distribution: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS mxODBC 3.1 Update ----------------- The mxODBC 3.1.1 patch level release adds compatibility to our new eGenix.com mx Base Distribution 3.2.0, which includes Windows x64 support. If you are currently using the combinations mxODBC 3.1.0 + mx Base 3.1.3, please consider upgrading to our latest releases mxODBC 3.1.1 + mx Base 3.2.0. Licenses for mxODBC 3.1.0 remain valid for mxODBC 3.1.1 as well. Release Highlights ------------------ * We've added Python 2.7 support and builds for all platforms. * mxODBC 3.1 adds native support for the Windows 64-bit platforms as well as the Mac OS X 10.6 (Snow Leopard) 64-bit builds of Python. * mxODBC now fully supports the Oracle Instant Client ODBC driver. * We have updated the support for the latest IBM DB2 9.7 ODBC drivers and enhanced compatibility of mxODBC with the MS SQL Server Native Client ODBC driver on Windows and the Sybase ASE 15 ODBC drivers on Unix. * mxODBC 3.1 adds support for large-scale data warehouse databases Netezza and Teradata. * In addition to the Windows, Mac OS X, iODBC and unixODBC ODBC driver managers, we now also include support for the DataDirect ODBC manager. * The 64-bit support on Unix platforms was updated to support the new unixODBC 2.3.0 version. * We've improved the documentation on how to connect to various popular databases and now include many tips & tricks for each database/driver. * The Python 2.7 memoryview object is now supported as binary data container. * We have simplified handling of database warnings using a new customizable .warningformat attribute. * The catalog methods now accept both Unicode and 8-bit strings as parameters. * You can now select whether to use ANSI (8-bit) or Unicode ODBC APIs in the ODBC drivers, removing unnecessary data conversions and enhancing ODBC driver compatibility. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html Feature Highlights ------------------ * Python Database API 2.0 Compliance: the mxODBC API is fully Python DB-API 2.0 compatible and implements a large number of powerful extensions. * Support for all popular ODBC Drivers: mxODBC includes adjustments and work-arounds to support MS SQL Server Native Client, MS SQL Server ODBC Driver, FreeTDS ODBC Driver, Oracle Instant Client ODBC Driver, IBM DB2 ODBC Driver, Sybase ASE ODBC Driver, Netezza ODBC Driver, Teradata ODBC Driver, PostgreSQL ODBC Driver, MySQL ODBC Driver, .MaxDB ODBC Driver as well as the ODBC driver sets of EasySoft, DataDirect, OpenLink, Actual Technologies. * Support for all popular ODBC Driver Managers: mxODBC comes with subpackages for the native Windows and Mac OS X ODBC managers, as well as the ODBC managers unixODBC, iODBC and DataDirect, which are commonly used on Unix systems. * Stable, robust and reliable:the mxODBC API has been in active production use for more than 10 years. * Full Python Support: mxODBC works with Python 2.4, 2.5, 2.6 and 2.7. * Full 64-bit Support: mxODBC runs on the following 64-bit platforms: Windows, Linux, FreeBSD and Mac OS X. For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features New mxODBC Editions ------------------- Due to popular demand, we have extended the set of available mxODBC editions and included a new low-cost standard edition. mxODBC is now available in thesethree editions: * The low-cost Standard Edition which provides data connectivity to a selected set of database backends. * The Professional Edition, which gives full access to all mxODBC features. * The Product Development Edition, which allows including mxODBC in applications you develop. At the same time we have simplified our license terms to clarify the situation on multi-core and virtual machines. In most cases, you no longer need to purchase more than one license per processor or virtual machine, scaling down the overall license costs significantly compared to earlier mxODBC releases. For a complete overview of the new editions, please see the product page. http://www.egenix.com/products/python/mxODBC/#mxODBCEditions ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC release to benefit from the new features and updated ODBC driver support. We have taken special care, not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. Customers who have purchased mxODBC 3.1 license can continue to use their licenses with this patch level release. Customers who have purchased mxODBC 2.0, 2.1 or 3.0 licenses can upgrade their licenses using the mxODBC Professional Edition Upgrade License. If you want to try the new release before purchace, you can request 30-day evaluation licenses by visiting our web-site http://www.egenix.com/products/python/mxODBC/#Evaluation or by writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, May 25 2011) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2011-05-23: Released eGenix mx Base 3.2.0 http://python.egenix.com/ 2011-05-25: Released mxODBC 3.1.1 http://python.egenix.com/ 2011-06-20: EuroPython 2011, Florence, Italy 26 days to go ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From roy at panix.com Wed May 25 07:36:40 2011 From: roy at panix.com (Roy Smith) Date: Wed, 25 May 2011 07:36:40 -0400 Subject: Why did Quora choose Python for its development? References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: In article , Dennis Lee Bieber wrote: > On Tue, 24 May 2011 13:39:02 -0400, "D'Arcy J.M. Cain" > declaimed the following in gmane.comp.python.general: > > > > My point was that even proponents of the language can make a > > significant error based on the way the variable is named. It's like > > the old Fortran IV that I first learned where the name of the variable > > determined whether it was an integer or a floating point. > > > Only if one didn't declare the type ahead of time... > > And even then it wasn't that hard to remember (using a non-PC > mnemonic): Indian's are integer (variables starting I to N inclusive > were integers) Remembering that I, J, K, L, M, and N were integer was trivial if you came from a math background. And, of course, Fortran was all about math, so that was natural. Those letters are commonly used for integers in formulae. If I write $ x sub i $, anybody who knows math would immediately assume that the range of x was reals and the range of i was integers. From rosuav at gmail.com Wed May 25 07:55:10 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 21:55:10 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: On Wed, May 25, 2011 at 9:36 PM, Roy Smith wrote: > Remembering that I, J, K, L, M, and N were integer was trivial if you > came from a math background. ?And, of course, Fortran was all about > math, so that was natural. ?Those letters are commonly used for integers > in formulae. ?If I write $ x sub i $, anybody who knows math would > immediately assume that the range of x was reals and the range of i was > integers. When I studied maths, x and y were reals, and i wasn't. But it wasn't integer either... :) Chris Angelico From john at castleamber.com Wed May 25 07:58:28 2011 From: john at castleamber.com (John Bokma) Date: Wed, 25 May 2011 06:58:28 -0500 Subject: Why did Quora choose Python for its development? References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> <20110524060535.64cfa0ec.darcy@druid.net> Message-ID: <87zkmbyot7.fsf@castleamber.com> Dennis Lee Bieber writes: > Python books than after six months of trying to understand PERL... And Perl is the language, and perl is what runs Perl. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From john at castleamber.com Wed May 25 08:01:07 2011 From: john at castleamber.com (John Bokma) Date: Wed, 25 May 2011 07:01:07 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: <87vcwzyoos.fsf@castleamber.com> Thorsten Kampe writes: > * Chris Angelico (Wed, 25 May 2011 08:01:38 +1000) >> >> On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain wrote: >> > One of my favorite quotes (not sure if it was about Perl or APL) is > "I >> > refuse to use a programming language where the proponents of it stick >> > snippets under each other's nose and say 'I bet you can't guess what >> > this does.'" >> >> Yes, I believe that was Perl. And an amusing quote. But most of the >> point of it comes from the fact that Perl uses punctuation for most of >> its keywords, whereas (say) Python uses English words; it's a lot more >> fun to crunch something down when you can use $| and friends than when >> you have to put "x and y", complete with spaces, for a simple boolean. >> But that says nothing about which language is actually better for >> working with... [...] > > It does say something about readibility. And yes, "readability counts". > And yes, readability says a lot about how good a language is for reading > and working with. To people used to the latin alphabet languages using a different script are unreadable. So readability has a lot to do with what one is used to. Like I already stated before: if Python is really so much better than Python readability wise, why do I have such a hard time dropping Perl and moving on? -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From erichcart at gmail.com Wed May 25 08:16:40 2011 From: erichcart at gmail.com (ErichCart ErichCart) Date: Wed, 25 May 2011 05:16:40 -0700 (PDT) Subject: Unable to make ironpython run in browser with silverlight Message-ID: <715e82a9-3761-4d82-9df4-1c5f39633160@h36g2000pro.googlegroups.com> Basically i am following this tutorial: http://blog.jimmy.schementi.com/2010/03/pycon-2010-python-in-browser.html According to it, this code should run fine: And in fact, it does, for example here: http://ironpython.net/browser/examples/pycon2010/start.html You will see it if you have silverlight installed. But the problem is that when I try to make the same code run on my PC, I can't do it. I create a text file, copy this code there, save it as test.html, and run with firefox, but nothing happens. Code does not execute, i just get a blank page. I can't understand the reason why the same code runs here: http://ironpython.net/browser/examples/pycon2010/start.html, but not on my PC, given that it is a client side code, and not the server side. And there is nothing written in firefox error console, when I run it locally. But if I host it on my webhosting account, then I get this error: Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http:// sitename .com/silverlighttest.html :: DLR_DownloadResource :: line 15" data: no] I uploaded the html file I am using here: http://www.filedropper.com/silverlighttest But it just a text file with that code with extension changed to .html. What can I do? From brightstarvijay at gmail.com Wed May 25 08:16:53 2011 From: brightstarvijay at gmail.com (Vijayakumar Vijayakumar) Date: Wed, 25 May 2011 05:16:53 -0700 (PDT) Subject: ghret Message-ID: website --> www.srilakshmi.info From brightstarvijay at gmail.com Wed May 25 08:21:02 2011 From: brightstarvijay at gmail.com (Vijayakumar Vijayakumar) Date: Wed, 25 May 2011 05:21:02 -0700 (PDT) Subject: ghraic Message-ID: <318a042b-d342-425e-ada1-7cbe409c2bcd@z13g2000prk.googlegroups.com> website --> www.srilakshmi.info From brightstarvijay at gmail.com Wed May 25 08:24:08 2011 From: brightstarvijay at gmail.com (Vijayakumar Vijayakumar) Date: Wed, 25 May 2011 05:24:08 -0700 (PDT) Subject: mresh Message-ID: <11ea43f0-81f6-4032-8153-edb4732502c5@q12g2000prb.googlegroups.com> website --> www.srilakshmi.infoinyohyou From roy at panix.com Wed May 25 08:25:09 2011 From: roy at panix.com (Roy Smith) Date: Wed, 25 May 2011 08:25:09 -0400 Subject: Why did Quora choose Python for its development? References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: In article , Chris Angelico wrote: > On Wed, May 25, 2011 at 9:36 PM, Roy Smith wrote: > > Remembering that I, J, K, L, M, and N were integer was trivial if you > > came from a math background. ?And, of course, Fortran was all about > > math, so that was natural. ?Those letters are commonly used for integers > > in formulae. ?If I write $ x sub i $, anybody who knows math would > > immediately assume that the range of x was reals and the range of i was > > integers. > > When I studied maths, x and y were reals, and i wasn't. But it wasn't > integer either... :) I was talking of i in the context of a variable, not as a constant. If I write $ 3 + 7i $ in one place and $ x sub i $ in another, most people will figure out from the context which is which. From brightstarvijay at gmail.com Wed May 25 08:28:04 2011 From: brightstarvijay at gmail.com (Vijayakumar Vijayakumar) Date: Wed, 25 May 2011 05:28:04 -0700 (PDT) Subject: trep Message-ID: website --> www.srilakshmi.info From cjw at ncf.ca Wed May 25 08:57:50 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Wed, 25 May 2011 08:57:50 -0400 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> Message-ID: On 25-May-11 02:22 AM, Lew Schwartz wrote: > So, if I read between the lines correctly, you recommend Python 3? Does > the windows version install with a development environment? > It would be safer to stick with Python 2.7 initially and then consider the transition to 3.2 later. No, there is not more than Idle. PyScripter provides an excellent development environment. See: http://en.wikipedia.org/wiki/PyScripter Colin W. From msarro at gmail.com Wed May 25 09:06:02 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 25 May 2011 09:06:02 -0400 Subject: Newbie string questions Message-ID: Hey everyone, This is a super noob question, so please be gentle. I am working my way through "Learn Python the Hard Way" using both python 2.7 and python 3.1 (I want to get a handle on the differences between the two - the intention to write things in python 3 but be able to understand things from python 2). The first quarter or so of the book details lots of stuff about strings. Most of the learning is by doing, with less of an emphasis on the theory behind what certain things actually do. The issue is, I can't seem to find some of the items in the documentation. Right now what is stumping me... what exactly does %r do? I can't find it in the documentation anywhere. -Matty From rosuav at gmail.com Wed May 25 09:09:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 May 2011 23:09:45 +1000 Subject: Newbie string questions In-Reply-To: References: Message-ID: On Wed, May 25, 2011 at 11:06 PM, Matty Sarro wrote: > Right now what is stumping me... what exactly does %r do? You're talking about the formatting operator? It's like the repr function: http://docs.python.org/library/functions.html#repr Chris Angelico From chris at theguidrys.us Wed May 25 09:13:34 2011 From: chris at theguidrys.us (Chris Guidry) Date: Wed, 25 May 2011 06:13:34 -0700 (PDT) Subject: Newbie string questions In-Reply-To: Message-ID: <997e06dd-55dc-4b45-9ff2-97f24dd49908@glegroupsg2000goo.googlegroups.com> On Wednesday, May 25, 2011 9:06:02 AM UTC-4, Matty Sarro wrote: > can't seem to find some of the items in the documentation. Right now > what is stumping me... what exactly does %r do? I can't find it in the > documentation anywhere. Matty, %r in a format string is very much like %s. %s calls str(your_object) in order to produce the resulting string. %r calls repr(your_object). Generally, you'd want to use %s for strings that will surface to a user, while %r is great for debugging and logging. Also, if you haven't come across repr(), you should be able to find that in the docs; it's also considered good practice to overload repr() in your own classes in order to provide a useful representation for your objects. From chris at theguidrys.us Wed May 25 09:13:34 2011 From: chris at theguidrys.us (Chris Guidry) Date: Wed, 25 May 2011 06:13:34 -0700 (PDT) Subject: Newbie string questions In-Reply-To: Message-ID: <997e06dd-55dc-4b45-9ff2-97f24dd49908@glegroupsg2000goo.googlegroups.com> On Wednesday, May 25, 2011 9:06:02 AM UTC-4, Matty Sarro wrote: > can't seem to find some of the items in the documentation. Right now > what is stumping me... what exactly does %r do? I can't find it in the > documentation anywhere. Matty, %r in a format string is very much like %s. %s calls str(your_object) in order to produce the resulting string. %r calls repr(your_object). Generally, you'd want to use %s for strings that will surface to a user, while %r is great for debugging and logging. Also, if you haven't come across repr(), you should be able to find that in the docs; it's also considered good practice to overload repr() in your own classes in order to provide a useful representation for your objects. From msarro at gmail.com Wed May 25 09:21:29 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 25 May 2011 09:21:29 -0400 Subject: Newbie string questions In-Reply-To: <997e06dd-55dc-4b45-9ff2-97f24dd49908@glegroupsg2000goo.googlegroups.com> References: <997e06dd-55dc-4b45-9ff2-97f24dd49908@glegroupsg2000goo.googlegroups.com> Message-ID: Thanks guys! I appreciate it. I was wondering why %r was always showing things enclosed in single-quotes. On Wed, May 25, 2011 at 9:13 AM, Chris Guidry wrote: > On Wednesday, May 25, 2011 9:06:02 AM UTC-4, Matty Sarro wrote: >> can't seem to find some of the items in the documentation. Right now >> what is stumping me... what exactly does %r do? I can't find it in the >> documentation anywhere. > > Matty, %r in a format string is very much like %s. ?%s calls str(your_object) in order to produce the resulting string. ?%r calls repr(your_object). ?Generally, you'd want to use %s for strings that will surface to a user, while %r is great for debugging and logging. > > Also, if you haven't come across repr(), you should be able to find that in the docs; it's also considered good practice to overload repr() in your own classes in order to provide a useful representation for your objects. > -- > http://mail.python.org/mailman/listinfo/python-list > From shawntahenman83562 at hotmail.com Wed May 25 09:30:19 2011 From: shawntahenman83562 at hotmail.com (Shawnta Henman) Date: Wed, 25 May 2011 09:30:19 -0400 Subject: FW: python Message-ID: python We should take a look at how this latest good fortune is going to change your lifestyle. Don't you remember all of those times I said how hard it's been just to get by? Alright you know what?, Your computer is going to be your very best pal once you try out this thing for one month's time. There's really no way in hell I'd wind up where I am these days if it all wasn't for this. You can give thanks to me soon. The couple of people I sometimes will need to deal with help to make everything far more easy on me that I couldn't have this another way. I can't wait to meet you once again and show you lots more. If you fail to build an income with this method, you're probably stupid. I'm sorry if that offends you, but I recognize you're capable and this is extremely straight forward! http://jesus21news.com Right here is the chance of your life. When you're ready to transform your way of life around, I'm going to be right here to assist. So whaddaya think, python, think you're prepared for a change? -------------- next part -------------- An HTML attachment was scrubbed... URL: From erichcart at gmail.com Wed May 25 09:33:45 2011 From: erichcart at gmail.com (ErichCart ErichCart) Date: Wed, 25 May 2011 06:33:45 -0700 (PDT) Subject: Unable to make ironpython run in browser with silverlight References: <715e82a9-3761-4d82-9df4-1c5f39633160@h36g2000pro.googlegroups.com> Message-ID: Here is how it looks on free webhosting account: http://silverlighttest.zzl.org/silverlighttest.html It is supposed to show a window with "Hello from python", but it shows smth else completely. From adsquaired at gmail.com Wed May 25 09:44:47 2011 From: adsquaired at gmail.com (ad) Date: Wed, 25 May 2011 06:44:47 -0700 (PDT) Subject: Code Review References: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> Message-ID: <072d3db3-82fe-4520-a520-db7ac5312edd@l14g2000pro.googlegroups.com> On May 25, 4:06?am, Ulrich Eckhardt wrote: > ad wrote: > > Please review the code pasted below. I am wondering what other ways > > there are of performing the same tasks. > > On a unix system, you would call "find" with according arguments and then > handle the found files with "-exec rm ..." or something like that, but I see > you are on MS Windows. > > > args = parser.parse_args() > > > dictKeys = (vars(args)) > > The first of these looks okay, while I don't get the additional brackets in > the second one. Another habit I observe here is the Hungarian notation of > prefixing the type to the name and using camelCaps. PEP 8 (IIRC) has > something to say on the preferred naming. I'm not 100% against encoding the > type in the variable name in Python, since it lacks static type checking, I > would have chosen "key_dict" here though, or, due to the small size of the > overall program just "keys". > > > print (HowManyDays) > > This puzzled me at first, again the useless additional brackets I thought. > However, in Python 3, "print" is a function, so that is correct. Still, it > should be "print(foo)" not "print (foo)". > > > for files in DirListing: > > > ? ? # Get the absolute path of the file name > > ? ? abspath = (os.path.join(WhatDirectory, files)) > > "files" is just the name of a single file, right? In that case the name is a > bit confusing. > > > ? ? # Get the date from seven days ago > > ? ? WeekOldFileDate = CurrentTime - DaysToDelete > > You are repeating this calculation for every file in the loop. > > > ? ? if FileCreationTime < WeekOldFileDate: > > ? ? ? ? #check if the object is a file > > ? ? ? ? if os.path.isfile(abspath): os.remove(abspath) > > ? ? ? ? # It is not a file it is a directory > > ? ? ? ? elif os.path.isdir(abspath): shutil.rmtree(abspath) > > I'm not sure, but I believe you could use shutil.rmtree() for both files and > directories. In any case, be prepared for the file still being open or > otherwise read-only, i.e. for having to handle errors. > > Also, what if a directory is old but the content is new? Would this cause > the non-old content to be deleted? > > Cheers! > > Uli > > -- > Domino Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 Thank you guys very much for the excellent points. I will use this information as a reference as I write more code and fix up the existing script. Chris, thank you for putting so much time into your post! Until we type again........... From bfocus at tznic.or.tz Wed May 25 10:15:28 2011 From: bfocus at tznic.or.tz (Bryton) Date: Wed, 25 May 2011 17:15:28 +0300 Subject: Cherrypy Message-ID: <4DDD0F00.30708@tznic.or.tz> Is anyone having a step by step tutorial of cherrypy(or book title).I have used the tutorial in their site as well as the book (cherrypy essentials) and I would like to have a one that is a bit more step by step...Please help... -- Regards, Bryton. From darcy at druid.net Wed May 25 10:23:59 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 25 May 2011 10:23:59 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: <20110525102359.eb6f4b93.darcy@druid.net> On Wed, 25 May 2011 07:36:40 -0400 Roy Smith wrote: > Remembering that I, J, K, L, M, and N were integer was trivial if you > came from a math background. And, of course, Fortran was all about The easiest way to remember was that the first two letters of INteger gave you the range. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rosuav at gmail.com Wed May 25 10:26:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 00:26:32 +1000 Subject: Why did Quora choose Python for its development? In-Reply-To: <20110525102359.eb6f4b93.darcy@druid.net> References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <20110525102359.eb6f4b93.darcy@druid.net> Message-ID: On Thu, May 26, 2011 at 12:23 AM, D'Arcy J.M. Cain wrote: > The easiest way to remember was that the first two letters of INteger > gave you the range. > G for Green and R for Right, which are the first two letters of Green. (I wonder how many Pythonistas are familiar with that?) Chris Angelico From iainking at gmail.com Wed May 25 10:26:57 2011 From: iainking at gmail.com (Iain King) Date: Wed, 25 May 2011 07:26:57 -0700 (PDT) Subject: Code Review References: <37ba7b40-3663-4094-b507-696fc598bf48@l26g2000yqm.googlegroups.com> <072d3db3-82fe-4520-a520-db7ac5312edd@l14g2000pro.googlegroups.com> Message-ID: On May 25, 2:44?pm, ad wrote: > On May 25, 4:06?am, Ulrich Eckhardt > wrote: > > > > > ad wrote: > > > Please review the code pasted below. I am wondering what other ways > > > there are of performing the same tasks. > > > On a unix system, you would call "find" with according arguments and then > > handle the found files with "-exec rm ..." or something like that, but I see > > you are on MS Windows. > > > > args = parser.parse_args() > > > > dictKeys = (vars(args)) > > > The first of these looks okay, while I don't get the additional brackets in > > the second one. Another habit I observe here is the Hungarian notation of > > prefixing the type to the name and using camelCaps. PEP 8 (IIRC) has > > something to say on the preferred naming. I'm not 100% against encoding the > > type in the variable name in Python, since it lacks static type checking, I > > would have chosen "key_dict" here though, or, due to the small size of the > > overall program just "keys". > > > > print (HowManyDays) > > > This puzzled me at first, again the useless additional brackets I thought. > > However, in Python 3, "print" is a function, so that is correct. Still, it > > should be "print(foo)" not "print (foo)". > > > > for files in DirListing: > > > > ? ? # Get the absolute path of the file name > > > ? ? abspath = (os.path.join(WhatDirectory, files)) > > > "files" is just the name of a single file, right? In that case the name is a > > bit confusing. > > > > ? ? # Get the date from seven days ago > > > ? ? WeekOldFileDate = CurrentTime - DaysToDelete > > > You are repeating this calculation for every file in the loop. > > > > ? ? if FileCreationTime < WeekOldFileDate: > > > ? ? ? ? #check if the object is a file > > > ? ? ? ? if os.path.isfile(abspath): os.remove(abspath) > > > ? ? ? ? # It is not a file it is a directory > > > ? ? ? ? elif os.path.isdir(abspath): shutil.rmtree(abspath) > > > I'm not sure, but I believe you could use shutil.rmtree() for both files and > > directories. In any case, be prepared for the file still being open or > > otherwise read-only, i.e. for having to handle errors. > > > Also, what if a directory is old but the content is new? Would this cause > > the non-old content to be deleted? > > > Cheers! > > > Uli > > > -- > > Domino Laser GmbH > > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 > > Thank you guys very much for the excellent points. I will use this > information as a reference as I write more code and fix up the > existing script. > > Chris, thank you for putting so much time into your post! > > Until we type again........... Wrote something to do the same basic thing a little while ago. Less verbose than yours, and it only does files, not folders. If I was going to do folders though, I'd do them by recursing into them and pruning files, and not go by the folder modify date, which I don't think changes the way you think it changes (for example, if a file inside a folder got updated such that it shouln't be deleted it still will be with your code if the folder modify date is old [this is on Windows]) import os, glob, time, sys if len(sys.argv) < 3: print "USAGE: %s " % sys.argv[0] sys.exit(1) pattern = sys.argv[1] days = int(sys.argv[2]) threshold = days * 24 * 60 * 60 t = time.time() for f in glob.glob(pattern): if t - os.stat(f)[9] > threshold: print f os.remove(f) From steve+comp.lang.python at pearwood.info Wed May 25 10:56:11 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 14:56:11 GMT Subject: Why did Quora choose Python for its development? References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: <4ddd188b$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 10:23:59 -0400, D'Arcy J.M. Cain wrote: > On Wed, 25 May 2011 07:36:40 -0400 > Roy Smith wrote: >> Remembering that I, J, K, L, M, and N were integer was trivial if you >> came from a math background. And, of course, Fortran was all about > > The easiest way to remember was that the first two letters of INteger > gave you the range. Huh. I never knew that. I just learned from use that I, J, K, M and N were traditionally integers. I never used L for an integer variable, and don't know anyone who does. I for integer is obvious. If you need a second one, you use the next letter J, and if you need a third, the one after that, K. If you need four, you're probably doing something wrong. Likewise, N for number (as in, *counting* number). If you need two, using N and O is stupid, because O can be confused with 0, so you go backwards and use M. However, using P and Q for integers is merely arbitrary convention. -- Steven From msarro at gmail.com Wed May 25 11:40:22 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 25 May 2011 11:40:22 -0400 Subject: Kind of OT - Books on software development? Message-ID: Hey everyone, I am looking at some projects coming up, which may or may not involve python. So I figured I would throw the question out there and see what everyone thinks. I am looking for some books on software engineering/development... something that discusses techniques from ideation, up through testing, QA, production, and then maintenance. Is there such a book? -Matthew From msarro at gmail.com Wed May 25 11:43:20 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 25 May 2011 11:43:20 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <4ddd188b$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <4ddd188b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: I hate using L for anything, namely because if you type it lowercase you always have to wonder if its an l or a 1 in a terminal window. -Matthew On Wed, May 25, 2011 at 10:56 AM, Steven D'Aprano wrote: > On Wed, 25 May 2011 10:23:59 -0400, D'Arcy J.M. Cain wrote: > >> On Wed, 25 May 2011 07:36:40 -0400 >> Roy Smith wrote: >>> Remembering that I, J, K, L, M, and N were integer was trivial if you >>> came from a math background. ?And, of course, Fortran was all about >> >> The easiest way to remember was that the first two letters of INteger >> gave you the range. > > Huh. I never knew that. I just learned from use that I, J, K, M and N > were traditionally integers. I never used L for an integer variable, and > don't know anyone who does. > > I for integer is obvious. If you need a second one, you use the next > letter J, and if you need a third, the one after that, K. If you need > four, you're probably doing something wrong. > > Likewise, N for number (as in, *counting* number). If you need two, using > N and O is stupid, because O can be confused with 0, so you go backwards > and use M. > > However, using P and Q for integers is merely arbitrary convention. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From e_d_k at yahoo.com Wed May 25 11:45:37 2011 From: e_d_k at yahoo.com (Ed Keith) Date: Wed, 25 May 2011 08:45:37 -0700 (PDT) Subject: Kind of OT - Books on software development? In-Reply-To: Message-ID: <315461.27473.qm@web120501.mail.ne1.yahoo.com> I do not have my library with me, but I remember a book that fits the bill exactly, is was from Microsoft Press, I think it was called "Writing Solid Code" Hope this helps, -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com --- On Wed, 5/25/11, Matty Sarro wrote: > From: Matty Sarro > Subject: Kind of OT - Books on software development? > To: "Python list" > Date: Wednesday, May 25, 2011, 11:40 AM > Hey everyone, > I am looking at some projects coming up, which may or may > not involve > python. So I figured I would throw the question out there > and see what > everyone thinks. > I am looking for some books on software > engineering/development... > something that discusses techniques from ideation, up > through testing, > QA, production, and then maintenance. Is there such a > book? > -Matthew > -- > http://mail.python.org/mailman/listinfo/python-list > From greg.kujawa at gmail.com Wed May 25 12:11:13 2011 From: greg.kujawa at gmail.com (gregarican) Date: Wed, 25 May 2011 09:11:13 -0700 (PDT) Subject: Kind of OT - Books on software development? References: Message-ID: <13d34170-8dd3-4d7c-8b0d-374b069b653f@k16g2000yqm.googlegroups.com> On May 25, 11:45?am, Ed Keith wrote: > I do not have my library with me, but I remember a book that fits the bill exactly, is was from Microsoft Press, I think it was called "Writing Solid Code" > > Hope this helps, > > ? ?-EdK > > Ed Keith > e_... at yahoo.com > > Blog: edkeith.blogspot.com > > --- On Wed, 5/25/11, Matty Sarro wrote: > > > > > From: Matty Sarro > > Subject: Kind of OT - Books on software development? > > To: "Python list" > > Date: Wednesday, May 25, 2011, 11:40 AM > > Hey everyone, > > I am looking at some projects coming up, which may or may > > not involve > > python. So I figured I would throw the question out there > > and see what > > everyone thinks. > > I am looking for some books on software > > engineering/development... > > something that discusses techniques from ideation, up > > through testing, > > QA, production, and then maintenance. Is there such a > > book? > > -Matthew > > -- > >http://mail.python.org/mailman/listinfo/python-list- Hide quoted text - > > - Show quoted text - If you are talking about general concepts in efficient, effective OO programming I'd suggest "Smalltalk Best Practice Patterns" by Kent Beck. I've developed in Java, C#, Python, Ruby, Smalltalk, and other languages and this book is an eye opener! From tdldev at gmail.com Wed May 25 12:19:12 2011 From: tdldev at gmail.com (Verde Denim) Date: Wed, 25 May 2011 12:19:12 -0400 Subject: Kind of OT - Books on software development? In-Reply-To: <315461.27473.qm@web120501.mail.ne1.yahoo.com> References: <315461.27473.qm@web120501.mail.ne1.yahoo.com> Message-ID: Hey everyone, I am looking at some projects coming up, which may or may not involve python. So I figured I would throw the question out there and see what everyone thinks. I am looking for some books on software engineering/development... something that discusses techniques from ideation, up through testing, QA, production, and then maintenance. Is there such a book? -Matthew On Wed, May 25, 2011 at 11:45 AM, Ed Keith wrote: > I do not have my library with me, but I remember a book that fits the bill > exactly, is was from Microsoft Press, I think it was called "Writing Solid > Code" > Matt - Roger Pressman - Software Engineering, A Practicioner's Approach is a good one. Donald E. Knuth. - The Art of Computer Programming (5 Volumes) - http://www-cs-faculty.stanford.edu/~uno/taocp.html Horowitz - Fundamentals of Computer Algorithms Dowd, Macdonald, Shuh - The Art of Software Security Assessments Good Basic Reference Library for engineering, designing, writing, and SECURING code. I've got lots more titles on various aspects of engineering and OOA/OOD construction, design methods, etc., but these are (imo) a good foundation. Regards Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From cousinstanley at gmail.com Wed May 25 12:22:36 2011 From: cousinstanley at gmail.com (Cousin Stanley) Date: Wed, 25 May 2011 16:22:36 +0000 (UTC) Subject: pyGTK identify a button References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Message-ID: Tracubik wrote: > Hi all, > i'm trying to write a simple windows with two button in GTK, > i need a way to identify wich button is pressed. > .... #!/usr/bin/env python import gtk def console_display( button , args ) : a0 , a1 , a2 = args print ' %s .... %s %s ' % ( a0 , a1 , a2 ) window = gtk.Window() window.set_title( "gtk.buttons.01" ) window.set_size_request( 300 , -1 ) window.set_position( gtk.WIN_POS_CENTER ) window.connect( "destroy" , gtk.main_quit ) # Create VBox and add in Window vbox = gtk.VBox() window.add( vbox ) # Create buttons dict_buttons = { 12 : [ 'OneTwo' , 'Buckle ' , 'My Shoe' ] , 34 : [ 'TreFor' , 'Shut ' , 'The Door' ] , 56 : [ 'FivSix' , 'Pick ' , 'Up Sticks' ] , 78 : [ 'SvnAte' , 'Lay ' , 'Them Straight' ] , 910 : [ 'NinTen' , 'Big ' , 'Fat Hen' ] } list_keys = dict_buttons.keys() list_keys.sort() for this_button in list_keys : this_name = dict_buttons[ this_button ][ 0 ] b = gtk.Button( this_name ) b.set_name( this_name ) b.connect( "clicked" , console_display , dict_buttons[ this_button ] ) vbox.pack_start( b ) window.show_all() gtk.main() -- Stanley C. Kitching Human Being Phoenix, Arizona From tjreedy at udel.edu Wed May 25 12:54:32 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 25 May 2011 12:54:32 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <87vcwzyoos.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> Message-ID: On 5/25/2011 8:01 AM, John Bokma wrote: > to. Like I already stated before: if Python is really so much better > than Python readability wise, why do I have such a hard time dropping > Perl and moving on? [you meant 'than Perl'] You are one of the people whose brain fits Perl (or vice versa) better than most. So enjoy it. Ignore anyone who says otherwise. -- Terry Jan Reedy From ethan at stoneleaf.us Wed May 25 13:17:15 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 25 May 2011 10:17:15 -0700 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> Message-ID: <4DDD399B.5050501@stoneleaf.us> Terry Reedy wrote: > On 5/25/2011 8:01 AM, John Bokma wrote: > >> to. Like I already stated before: if Python is really so much better >> than Python readability wise, why do I have such a hard time dropping >> Perl and moving on? > > [you meant 'than Perl'] You are one of the people whose brain fits Perl > (or vice versa) better than most. So enjoy it. Ignore anyone who says > otherwise. +1 If everybody's brain worked the same, we wouldn't have so many different languages to choose from. ~Ethan~ From e_d_k at yahoo.com Wed May 25 13:32:40 2011 From: e_d_k at yahoo.com (Ed Keith) Date: Wed, 25 May 2011 10:32:40 -0700 (PDT) Subject: Kind of OT - Books on software development? In-Reply-To: <315461.27473.qm@web120501.mail.ne1.yahoo.com> Message-ID: <920356.25261.qm@web120508.mail.ne1.yahoo.com> --- On Wed, 5/25/11, Ed Keith wrote: > I do not have my library with me, but > I remember a book that fits the bill exactly, is was from > Microsoft Press, I think it was called "Writing Solid Code" I have done some research at amazon.com, and while "Writing Solid Code" is an excellent book that I would also recommend highly, the book I was thinking of was "Code Complete". -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From jess.austin at gmail.com Wed May 25 13:54:11 2011 From: jess.austin at gmail.com (Jess Austin) Date: Wed, 25 May 2011 10:54:11 -0700 (PDT) Subject: super() in class defs? Message-ID: I may be attempting something improper here, but maybe I'm just going about it the wrong way. I'm subclassing http.server.CGIHTTPRequestHandler, and I'm using a decorator to add functionality to several overridden methods. def do_decorate(func): . def wrapper(self): . if appropriate(): . return func() . complain_about_error() . return wrapper class myHandler(CGIHTTPRequestHandler): . @do_decorate . def do_GET(self): . return super().do_GET() . # also override do_HEAD and do_POST My first thought was that I could just replace that whole method definition with one line: class myHandler(CGIHTTPRequestHandler): . do_GET = do_decorate(super().do_GET) That generates the following error: SystemError: super(): __class__ cell not found So I guess that when super() is called in the context of a class def rather than that of a method def, it doesn't have the information it needs. Now I'll probably just say: do_GET = do_decorate(CGIHTTPRequestHandler.do_GET) but I wonder if there is a "correct" way to do this instead? Thanks! From listas.programacao at gmail.com Wed May 25 14:17:04 2011 From: listas.programacao at gmail.com (Jayme Proni Filho) Date: Wed, 25 May 2011 15:17:04 -0300 Subject: Newbie question about SQLite + Python and twitter Message-ID: Helo guys, I'm building a local application for twitter for my brother's store. I'm in the beginning and I have some newbie problems, so: I create a table called tb_messages with int auto increment and varchar(140) fields; I did three SQL funcionts, insert_tweet, delete_tweet, select_tweet select_tweet is use for getting messages for sending them to twitter; My problem is: How can i make my select_tweet works at the same time that insert or delete funcions. I just got to work when I stop select function. I would like to do my app works all the time. --------------------------------------------------------------------------------------- Jayme Proni Filho Skype: jaymeproni Twitter: @jaymeproni Phone: +55 - 17 - 3631 - 6576 Mobile: +55 - 17 - 9605 - 3560 e-Mail: jaymeproni at yahoo dot com dot br --------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed May 25 14:31:33 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 May 2011 12:31:33 -0600 Subject: super() in class defs? In-Reply-To: References: Message-ID: On Wed, May 25, 2011 at 11:54 AM, Jess Austin wrote: > So I guess that when super() is called in the context of a class def > rather than that of a method def, it doesn't have the information it > needs. Now I'll probably just say: > > ? ?do_GET = do_decorate(CGIHTTPRequestHandler.do_GET) > > but I wonder if there is a "correct" way to do this instead? Thanks! I would recommend against using super() in general. http://fuhm.net/super-harmful/ Cheers, Ian From john at castleamber.com Wed May 25 15:14:15 2011 From: john at castleamber.com (John Bokma) Date: Wed, 25 May 2011 14:14:15 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> Message-ID: <87mxiasid4.fsf@castleamber.com> Ethan Furman writes: > Terry Reedy wrote: >> On 5/25/2011 8:01 AM, John Bokma wrote: >> >>> to. Like I already stated before: if Python is really so much better >>> than Python readability wise, why do I have such a hard time dropping >>> Perl and moving on? >> >> [you meant 'than Perl'] You are one of the people whose brain fits >> Perl (or vice versa) better than most. So enjoy it. Ignore anyone >> who says otherwise. > > +1 > > If everybody's brain worked the same, we wouldn't have so many > different languages to choose from. So, this means that in general language readability is not as clear cut as some seem to advertise ;-). -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From wbsoft at xs4all.nl Wed May 25 15:28:17 2011 From: wbsoft at xs4all.nl (Wilbert Berendsen) Date: Wed, 25 May 2011 21:28:17 +0200 Subject: bdist_wininst: install_script not run on uninstall Message-ID: <201105252128.17504.wbsoft@xs4all.nl> Hi, according to the docs the installer bdist_wininst creates will run the install-script on install with -install (which works perfectly) and on uninstall with the -remove argument (which seemingly never happens). However I want to cleanup some registry stuff on uninstall so I want the uninstall script to work. Studying the source code of the installer[1] in the Run_RemoveScript function... [1] http://svn.python.org/view/python/trunk/PC/bdist_wininst/install.c ... it checks for the line '%d Run Script: %s' in the log, which is there. But can anybody find out why the install script is not run? with best regards, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi From tkpmep at hotmail.com Wed May 25 15:33:39 2011 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: Wed, 25 May 2011 12:33:39 -0700 (PDT) Subject: Python 3.2 bug? Reading the last line of a file Message-ID: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> The following function that returns the last line of a file works perfectly well under Python 2.71. but fails reliably under Python 3.2. Is this a bug, or am I doing something wrong? Any help would be greatly appreciated. import os def lastLine(filename): ''' Returns the last line of a file file.seek takes an optional 'whence' argument which allows you to start looking at the end, so you can just work back from there till you hit the first newline that has anything after it Works perfectly under Python 2.7, but not under 3.2! ''' offset = -50 with open(filename) as f: while offset > -1024: offset *= 2 f.seek(offset, os.SEEK_END) lines = f.readlines() if len(lines) > 1: return lines[-1] If I execute this with a valid filename fn. I get the following error message: >>> lastLine(fn) Traceback (most recent call last): File "", line 1, in lastLine(fn) File "", line 13, in lastLine f.seek(offset, os.SEEK_END) io.UnsupportedOperation: can't do nonzero end-relative seeks Sincerely Thomas Philips From python at mrabarnett.plus.com Wed May 25 16:00:18 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 25 May 2011 21:00:18 +0100 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> Message-ID: <4DDD5FD2.8040607@mrabarnett.plus.com> On 25/05/2011 20:33, tkpmep at hotmail.com wrote: > The following function that returns the last line of a file works > perfectly well under Python 2.71. but fails reliably under Python 3.2. > Is this a bug, or am I doing something wrong? Any help would be > greatly appreciated. > > > import os > > def lastLine(filename): > ''' > Returns the last line of a file > file.seek takes an optional 'whence' argument which allows you > to > start looking at the end, so you can just work back from there > till > you hit the first newline that has anything after it > Works perfectly under Python 2.7, but not under 3.2! > ''' > offset = -50 > with open(filename) as f: > while offset> -1024: > offset *= 2 > f.seek(offset, os.SEEK_END) > lines = f.readlines() > if len(lines)> 1: > return lines[-1] > > If I execute this with a valid filename fn. I get the following error > message: > >>>> lastLine(fn) > Traceback (most recent call last): > File "", line 1, in > lastLine(fn) > File "", line 13, in lastLine > f.seek(offset, os.SEEK_END) > io.UnsupportedOperation: can't do nonzero end-relative seeks > You're opening the file in text mode, and seeking relative to the end of the file is not allowed in text mode, presumably because the file contents have to be decoded, and, in general, seeking to an arbitrary position within a sequence of encoded bytes can have undefined results when you attempt to decode to Unicode starting from that position. The strange thing is that you _are_ allowed to seek relative to the start of the file. Try opening the file in binary mode and do the decoding yourself, catching the DecodeError exceptions if/when they occur. From Catherine.M.Moroney at jpl.nasa.gov Wed May 25 16:27:19 2011 From: Catherine.M.Moroney at jpl.nasa.gov (Catherine Moroney) Date: Wed, 25 May 2011 13:27:19 -0700 Subject: using masks and numpy record arrays Message-ID: Hello, I am trying to work with a structured array and a mask, and am encountering some problems. For example: >>> xtype = numpy.dtype([("n", numpy.int32), ("x", numpy.float32)]) >>> a = numpy.zeros((4), dtype=xtype) >>> b = numpy.arange(0,4) >>> a2 = numpy.zeros((4), dtype=xtype) >>> mask = numpy.where(b%2 == 0) >>> a2[:]["n"] += b ! this changes the values of a2 >>> a[mask]["n"] += b[mask] ! this does not change the values of a >>> a2 array([(0, 0.0), (1, 0.0), (2, 0.0), (3, 0.0)], dtype=[('n', '>> a array([(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)], dtype=[('n', '>> a = numpy.zeros((4)) >>> a[mask] += b[mask] >>> a array([ 0., 0., 2., 0.]) What is it about a numpy record array that prevents the mask statement from working, and how do I get around this? Thanks, Catherine From ericsnowcurrently at gmail.com Wed May 25 16:49:07 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 25 May 2011 14:49:07 -0600 Subject: super() in class defs? In-Reply-To: References: Message-ID: On Wed, May 25, 2011 at 12:31 PM, Ian Kelly wrote: > On Wed, May 25, 2011 at 11:54 AM, Jess Austin > wrote: > > So I guess that when super() is called in the context of a class def > > rather than that of a method def, it doesn't have the information it > > needs. Now I'll probably just say: > > > > do_GET = do_decorate(CGIHTTPRequestHandler.do_GET) > > > > but I wonder if there is a "correct" way to do this instead? Thanks! > > I would recommend against using super() in general. > > That position is understandable. However, super is fine for single inheritance, and works fine in cooperative multiple inheritance. You can just as easily argue that multiple inheritance is more harmful than super is. If fact, I would generally recommend against using multiple inheritance if you can avoid it (though it has its place). Personally, I find super to make maintenance and refactoring easier, since I don't have to fiddle with the base class name, or with passing self. Cheers, -eric > http://fuhm.net/super-harmful/ > > Cheers, > Ian > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed May 25 16:54:25 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 May 2011 14:54:25 -0600 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <4DDD5FD2.8040607@mrabarnett.plus.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> Message-ID: On Wed, May 25, 2011 at 2:00 PM, MRAB wrote: > You're opening the file in text mode, and seeking relative to the end > of the file is not allowed in text mode, presumably because the file > contents have to be decoded, and, in general, seeking to an arbitrary > position within a sequence of encoded bytes can have undefined results > when you attempt to decode to Unicode starting from that position. > > The strange thing is that you _are_ allowed to seek relative to the > start of the file. I think that with text files seek() is only really meant to be called with values returned from tell(), which may include the decoder state in its return value. From msarro at gmail.com Wed May 25 17:19:57 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 25 May 2011 17:19:57 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <87mxiasid4.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> Message-ID: On Wed, May 25, 2011 at 3:14 PM, John Bokma wrote: > Ethan Furman writes: > >> Terry Reedy wrote: >>> On 5/25/2011 8:01 AM, John Bokma wrote: >>> >>>> to. Like I already stated before: if Python is really so much better >>>> than Python readability wise, why do I have such a hard time dropping >>>> Perl and moving on? >>> >>> [you meant 'than Perl'] You are one of the people whose brain fits >>> Perl (or vice versa) better than most. So enjoy it. Ignore anyone >>> who says otherwise. >> >> +1 >> >> If everybody's brain worked the same, we wouldn't have so many >> different languages to choose from. > > So, this means that in general language readability is not as clear cut > as some seem to advertise ;-). > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > Blog: http://johnbokma.com/ ? ? ? ?Perl Consultancy: http://castleamber.com/ > Perl for books: ? ?http://johnbokma.com/perl/help-in-exchange-for-books.html > -- > http://mail.python.org/mailman/listinfo/python-list > General readability is a farce. If it was true we would only have one section to the library. Different people enjoy reading, and can comprehend better in different ways. THat's why some people are super verbose - hell, just look at this here post! :) From robert.kern at gmail.com Wed May 25 17:22:50 2011 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 25 May 2011 16:22:50 -0500 Subject: using masks and numpy record arrays In-Reply-To: References: Message-ID: On 5/25/11 3:27 PM, Catherine Moroney wrote: > Hello, > > I am trying to work with a structured array and a mask, and am encountering some > problems. You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists > For example: > > >>> xtype = numpy.dtype([("n", numpy.int32), ("x", numpy.float32)]) > >>> a = numpy.zeros((4), dtype=xtype) > >>> b = numpy.arange(0,4) > >>> a2 = numpy.zeros((4), dtype=xtype) > >>> mask = numpy.where(b%2 == 0) > >>> a2[:]["n"] += b ! this changes the values of a2 > >>> a[mask]["n"] += b[mask] ! this does not change the values of a > >>> a2 > array([(0, 0.0), (1, 0.0), (2, 0.0), (3, 0.0)], > dtype=[('n', ' >>> a > array([(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)], > dtype=[('n', ' > Why do the values of a2 get updated, and yet the values of a do not? Only the final [] on the left-hand side of the assignment actually turns into a .__setitem__() call to the object that is the result of the expression to its left. a[mask] makes a copy while a2[:] makes a view. You could do a["n"][mask] += b[mask] since a["n"] will also make a view and the .__setitem__() on it will propagate back to the original memory. -- 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 thegist at nospam.net Wed May 25 17:30:48 2011 From: thegist at nospam.net (thegist at nospam.net) Date: Wed, 25 May 2011 17:30:48 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> Message-ID: <72183$4ddd7506$ce534406$5707@news.eurofeeds.com> On 5/24/2011 1:39 PM, D'Arcy J.M. Cain wrote: [snip] > One of my favorite quotes (not sure if it was about Perl or APL) is "I > refuse to use a programming language where the proponents of it stick > snippets under each other's nose and say 'I bet you can't guess what > this does.'" I dunno. That sounds about like how most programming course exams are written, no? The point is that puzzling through arcane bits of code are crucial to learning any language. It's a valuable exercise. From steve+comp.lang.python at pearwood.info Wed May 25 17:40:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 21:40:32 GMT Subject: super() in class defs? References: Message-ID: <4ddd774f$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 12:31:33 -0600, Ian Kelly wrote: > I would recommend against using super() in general. > > http://fuhm.net/super-harmful/ If you actually read that article, carefully, without being fooled by the author's provocative ex-title and misleading rhetoric, you will discover that super is not harmful. What is harmful is making unjustified assumptions about what super does, and about the code you are calling, and hence misusing super. You have to read all the way to the bottom of the article to see the author say in the TODO section: "Give some examples of why super really is necessary sometimes" Even before that, you will read why *not* using super often fails badly. If James Knight, the author, is correct that super is harmful, it seems that you're in trouble because *not using super* is also harmful. If you search the mailing lists of python-dev at python.org, you will find a debate between James and Guido van Russum where James eventually acknowledges that he is wrong to call super harmful. There's a reason that he has changed the title of the page from "Python's Super Considered Harmful" to the damning-with-faint-praise "Python's Super is nifty, but you can't use it". The new title is also *simply wrong*, because you can use it. James even tells you what you need to do to use it correctly. The truth is that for multiple inheritance, you better be using super or your code is probably buggy (unless you manually duplicate what super does for you). And for single inheritance, it makes no difference whether you use super or not. -- Steven From python at mrabarnett.plus.com Wed May 25 17:52:39 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 25 May 2011 22:52:39 +0100 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> Message-ID: <4DDD7A27.60602@mrabarnett.plus.com> On 25/05/2011 21:54, Ian Kelly wrote: > On Wed, May 25, 2011 at 2:00 PM, MRAB wrote: >> You're opening the file in text mode, and seeking relative to the end >> of the file is not allowed in text mode, presumably because the file >> contents have to be decoded, and, in general, seeking to an arbitrary >> position within a sequence of encoded bytes can have undefined results >> when you attempt to decode to Unicode starting from that position. >> >> The strange thing is that you _are_ allowed to seek relative to the >> start of the file. > > I think that with text files seek() is only really meant to be called > with values returned from tell(), which may include the decoder state > in its return value. What do you mean by "may include the decoder state in its return value"? It does make sense that the values returned from tell() won't be in the middle of an encoded sequence of bytes. From steve+comp.lang.python at pearwood.info Wed May 25 17:59:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 21:59:58 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 09:26:11 +0200, Thorsten Kampe wrote: > Naming something in the terms of its implementation details (in this > case recursion) is a classical WTF. *If* that's true, it certainly doesn't seem to apply to real-world objects. Think about the exceptions: microwave oven vacuum cleaner oven fries electric car chain saw flintlock rifle air gun vulcanised rubber kerosene heater aluminium foil diamond saw gas stove wood stove four-wheel drive car incandescent light bulb electric razor unleaded petrol to mention only a few. Naming the thing after the implementation would often seem to be *good advice*, not bad. We often do care about implementations. You really do need to know whether the car you drive uses leaded or unleaded. Being able to swap implementations without changing the interface is an abstraction that doesn't apply all the time, in either code or real life. -- Steven From steve+comp.lang.python at pearwood.info Wed May 25 18:58:21 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 22:58:21 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 00:06:06 +0200, Rikishi42 wrote: > On 2011-05-24, Steven D'Aprano > wrote: >>>> I think that is a patronizing remark that under-estimates the >>>> intelligence of lay people and over-estimates the difficulty of >>>> understanding recursion. >>> >>> Why would you presume this to be related to intelligence? The point >>> was not about being *able* to understand, but about *needing* to >>> understand in order to use. >> >> Maybe they don't "need" to understand recursion. So what? > > I think you should read the earlier posts again, this is drifting so far > from what I intended. > > What I mean is: I'm certain that over the years I've had more than one > person come to me and ask what 'Do you wish to delete this directory > recursively?' meant. BAut never have I been asked to explain what 'Do > you wish to delete this directory and it's subdirs/with all it's > contents?' meant. Never. I know many people who have no idea what a directory is, let alone a subdirectory, unless it's the phone directory. They're non-computer users. Once they start using computers, they quickly work out what the word means in context, or they ask and get told, and then they've learned a new word and never need ask again. This is a good thing. The idiom of "recursively delete" is no different. Of course some people will have to learn a new term in order to make sense of it. So what? > Do you know many people who incinerate leaves and branches in their > garden? I burn them. I know many people who incinerate leaves in an incinerator. Or at least they used to, until the government here banned it. It might only have been a 44 gallon drum with holes punched in the side, but they still called it an incinerator. I learned that word from my father, who left school at 14 to work in a shoe shop. He isn't especially educated, doesn't read much beyond the daily tabloid, and thinks Benny Hill is the height of wit. But he's not an idiot and even at 72 is capable of learning new words. >> Do they need to know the words "microwave oven" when they could be >> saying "invisible rays cooking thing"? > > The word oven has existed for ages, microwave is just a name for the > type of oven. Not even a description, just a name. Why do you think they're called "microwave ovens" instead of "fizzbaz ovens"? Could it possibly have something to do with the fact that they cook with microwaves? So not actually "just a name" at all. It's a jargon description of the implementation of the oven. >> I wonder whether physicists insist that cars should have a "go faster >> pedal" because ordinary people don't need to understand Newton's Laws >> of Motion in order to drive cars? > > Gas pedal. Pedal was allraedy known when the car was invented. The > simple addition of gas solved that need. What's a gas pedal? Is that some strange American term for what most of the English-speaking world knows as the accelerator? *wink* > Oh, and it's break pedal, not descellarator. (sp?) That would be brake, and decelerator. >> Who are you to say that people shouldn't be exposed to words you deem >> that they don't need to know? > > I'm one of the 'people'. You say exposed to, I say bothered/bored with. You can't force people to learn new words, although you would be surprised how even the most disinterested, lazy speaker manages to pick up vocabulary without even being aware of it. But nor do you have to pander to the slackers. They can learn the word, or not, I don't care. If I'm writing for an audience of children, or English as a second language, or the otherwise linguistically challenged, I'll simplify my vocabulary appropriately. For everyone else, I'll use an ordinary adult vocabulary, and that includes the word "recursion" or "recursive". It's hardly technical jargon -- I've found a discussion of gangsta rap that uses it. Even children understand the concept of recursion (self-reference). People put it in comedies like Blazing Saddles and Space Balls! How difficult is it to put a name to the concept? > I have nothing against the use of a proper, precise term. And that word > can be a complex one with many, many sylables (seems to add value, > somehow). > > But I'm not an academic, so I don't admire the pedantic use of terms > that need to be explained to 'lay' people. Pedantic... that's another one of those academic words that need to be explained to lay people, isn't it? As is academic itself, and in fact "lay people". Who uses "lay people" in conversation? Conversation -- another one of those four syllable words that should be avoided, since we have "talk". I don't remember that last time I've heard Bazza or Jimbo say "I was on the Internet having a conversation on Jabber", do you? Oh, actually I do. So much for that argument. > widespread, usually shorter and much simpler one for it. A pointless > effort if pointless, even when comming from a physicist. :-) I think you *grossly* underestimate how many words people know, particularly if you include so-called "passive vocabulary" (words people can understand in context, but not define precisely). See, for example: http://www.worldwidewords.org/articles/howmany.htm -- Steven From steve+comp.lang.python at pearwood.info Wed May 25 19:01:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 23:01:32 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> Message-ID: <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 07:01:07 -0500, John Bokma wrote: > if Python is really so much better than Python [Perl] > readability wise, why do I have such a hard time dropping > Perl and moving on? My guess is that you have an adversarial view of computer languages, therefore after investing so much time and energy and, most importantly, self-image into becoming a Perl programmer, dropping it and moving on would be tantamount to admitting to yourself that you were "wrong" to have wasted so many years on the wrong language. Whether it is objectively "wrong" or not rarely enters into these things. That *you personally* can't or won't let go of Perl says nothing about the relative readability of Perl and Python code. -- Steven From steve+comp.lang.python at pearwood.info Wed May 25 19:25:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 23:25:14 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> Message-ID: <4ddd8fd9$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 08:01:38 +1000, Chris Angelico wrote: > On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain > wrote: >> When I first looked at Perl it looked like line noise. ?When I first >> looked at Python it looked like pseudo-code. > > When I first looked at assembly language it looked like random junk left > behind in memory. When I first looked at COBOL it looked like ... COBOL. > Doesn't make either of them better or worse. Er, yes it does. Writing code is primarily for *human readers*. Once you've compiled the code once, the computer never need look at it again, but human being come back to read it over and over again, to learn from it, or for maintenance. We rightfully value our own time and convenience as more valuable than that of the computer's, which is why we use programming languages at all, instead of having custom-made hardware built for every task we want the computer to do: "I have to rename a file before August 2015, but the rename itself needs to be done in under a picosecond. Know any bespoke chip manufacturers who do small runs?" >From that perspective, COBOL is an improvement on assembly, which is why there are probably still more COBOL programmers around than people who work exclusively on assembly. Sometimes we compromise, or even subvert, that trade-off: for speed critical code where we do care more about the computer's time than our own, or for esoteric languages designed to be as hard to read as possible. My personal favourites, Oook and Whitespace. But generally, people spend more time reading code than writing it, therefore we should weigh "ease of reading" higher than "ease of writing". (My guess is, the weights should be about 5:1.) > Pseudo-code is not a viable language for a computer to parse, Only because "pseudo-code" implies that the code is ambiguous or otherwise cannot be parsed. If it could be, it wouldn't be *pseudo*, it would be real code (possibly for some compiler that hasn't been written yet). > but it's a > good language for scribbling down comments in. That doesn't necessarily > mean that a programming language that's "closer to" pseudo-code is good. That depends on the nature of pseudo-code. "Pseudo-assembly" has all the disadvantages of assembly with none of the advantages, i.e. it doesn't actually work. So in that sense, pseudo-code is not necessarily a good thing nor a bad thing. But in general conversation, pseudo-code is usually implied to mean that the language is as close to human language as you can make it, while still be parsable by a compiler. > And verbosity doesn't necessarily equate to quality; for instance, when > I'm working in both Python and PHP, I find it FAR tidier to use Python's > {1:2,3:4] notation than PHP's array(1=>2,3=>4) - but on the flip side, I > would prefer to have program structure defined by keywords like "if" and > "while" than obscure random line noise. (Fortunately, most sane > languages do indeed use keywords there.) True. That's one of the limitations of the xtalk family of languages derived from Apple's (defunct) Hypertalk: it's awfully verbose, which is good for newbies but not quite so good for experts. -- Steven From tkpmep at hotmail.com Wed May 25 19:25:55 2011 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: Wed, 25 May 2011 16:25:55 -0700 (PDT) Subject: Python 3.2 bug? Reading the last line of a file References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> Message-ID: <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> Thanks for the guidance - it was indeed an issue with reading in binary vs. text., and I do now succeed in reading the last line, except that I now seem unable to split it, as I demonstrate below. Here's what I get when I read the last line in text mode using 2.7.1 and in binary mode using 3.2 respectively under IDLE: 2.7.1 Name 31/12/2009 0 0 0 3.2 b'Name\t31/12/2009\t0\t0\t0\r\n' if, under 2.7.1 I read the file in text mode and write >>> x = lastLine(fn) I can then cleanly split the line to get its contents >>> x.split('\t') ['Name', '31/12/2009', '0', '0', '0\n'] but under 3.2, with its binary read, I get >>> x.split('\t') Traceback (most recent call last): File "", line 1, in x.split('\t') TypeError: Type str doesn't support the buffer API If I remove the '\t', the split now works and I get a list of bytes literals >>> x.split() [b'Name', b'31/12/2009', b'0', b'0', b'0'] Looking through the docs did not clarify my understanding of the issue. Why can I not split on '\t' when reading in binary mode? Sincerely Thomas Philips From pavlovevidence at gmail.com Wed May 25 19:26:34 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 25 May 2011 16:26:34 -0700 (PDT) Subject: super() in class defs? In-Reply-To: Message-ID: <1e953311-915e-4fce-89f7-dbcba6f403ee@glegroupsg2000goo.googlegroups.com> On Wednesday, May 25, 2011 10:54:11 AM UTC-7, Jess Austin wrote: > I may be attempting something improper here, but maybe I'm just going > about it the wrong way. I'm subclassing > http.server.CGIHTTPRequestHandler, and I'm using a decorator to add > functionality to several overridden methods. > > def do_decorate(func): > . def wrapper(self): > . if appropriate(): > . return func() > . complain_about_error() > . return wrapper > > class myHandler(CGIHTTPRequestHandler): > . @do_decorate > . def do_GET(self): > . return super().do_GET() > . # also override do_HEAD and do_POST > > My first thought was that I could just replace that whole method > definition with one line: > > class myHandler(CGIHTTPRequestHandler): > . do_GET = do_decorate(super().do_GET) > > That generates the following error: > > SystemError: super(): __class__ cell not found > > So I guess that when super() is called in the context of a class def > rather than that of a method def, it doesn't have the information it > needs. Right. Actually the class object itself doesn't even exist yet when super() is invoked. (It won't be created until after the end of the class statement block.) > Now I'll probably just say: > > do_GET = do_decorate(CGIHTTPRequestHandler.do_GET) > > but I wonder if there is a "correct" way to do this instead? Thanks! Well, since the class object isn't created until after the end of the class statement block, it's impossible to invoke super() on the class from inside the block. So there's only two ways to invoke super(): 1. like you did above, by calling it inside a method, and 2. call it beyond the end of the class statement, like this: class myHandler(CGIHTTPRequestHandler): pass myHandler.do_GET = do_decorate(super(myHandler).do_GET) I wouldn't call that correct, though. (I'm not even sure it'll work, since I don't have Python 3 handy to test it, but as far as I can tell it will.) It's just one of the quirks of Python's type system. I don't agree with Ian's recommendation not to use super() in general, but I'd probably agree that one should stick to using it only in its intended way (to invoke base-class methods directly). Carl Banks From ian.g.kelly at gmail.com Wed May 25 19:31:51 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 May 2011 17:31:51 -0600 Subject: super() in class defs? In-Reply-To: <4ddd774f$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4ddd774f$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 25, 2011 at 3:40 PM, Steven D'Aprano wrote: > If you actually read that article, carefully, without being fooled by the > author's provocative ex-title and misleading rhetoric, you will discover > that super is not harmful. What is harmful is making unjustified > assumptions about what super does, and about the code you are calling, > and hence misusing super. Yes. As others have noted, the problem is really multiple inheritance, not super. Super can be a useful tool, but unless you have taken some time to learn its intricacies, I think that it is best avoided so that it is not misused. > You have to read all the way to the bottom of the article to see the > author say in the TODO section: > > "Give some examples of why super really is necessary sometimes" > > Even before that, you will read why *not* using super often fails badly. > If James Knight, the author, is correct that super is harmful, it seems > that you're in trouble because *not using super* is also harmful. Essentially, super can fail when you use it inconsistently. Not using super can fail when you have a diamond inheritance situation, or when you mix it with super. In this case, the OP is using super while inheriting from http.server.CGIHTTPServer, which does not use super, and so is inconsistent. > If you search the mailing lists of python-dev at python.org, you will find a > debate between James and Guido van Russum where James eventually > acknowledges that he is wrong to call super harmful. There's a reason > that he has changed the title of the page from "Python's Super Considered > Harmful" to the damning-with-faint-praise "Python's Super is nifty, but > you can't use it". Thanks. I found this quote from James that pretty much sums up my position perfectly: """ This is where I'm coming from: In my own code, it is very rare to have diamond inheritance structures. And if there are, even more rare that both sides need to cooperatively override a method. Given that, super has no necessary advantage. And it has disadvantages. - Backwards compatibility issues - Going along with that, inadvertent mixing of paradigms (you have to remember which classes you use super with and which you don't or your code might have hard-to-find errors). - Take your choice of: a) inability to add optional arguments to your methods, or b) having to use *args, **kwargs on every method and call super with those. - Having to try/catch AttributeErrors from super if you use interfaces instead of a base class to define the methods in use. """ > The new title is also *simply wrong*, because you can use it. James even > tells you what you need to do to use it correctly. Yes, you need to fundamentally alter the structure of your code to throw away any semblance of run-time argument checking by having every method that might conceivably be cooperatively inherited take *args, **kwargs. You also need to take care to always call super from such methods, even when it appears to be unnecessary. And don't forget to catch the AttributeError if the method is something other than __new__ or __init__ and the current class turns out to be the last one in the MRO that has it. In short, if you're using super and don't feel burdened by it, then you're probably using it incorrectly. > The truth is that for multiple inheritance, you better be using super or > your code is probably buggy (unless you manually duplicate what super > does for you). No. For diamond inheritance, you better be using super or your code is probably buggy. For typical diamond-less multiple inheritance, super is both unnecessary and tricky to use correctly. > And for single inheritance, it makes no difference whether > you use super or not. Right. It's unnecessary, so why saddle yourself with it? From python at rcn.com Wed May 25 19:45:29 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 25 May 2011 16:45:29 -0700 (PDT) Subject: super() in class defs? References: <4ddd774f$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 25, 4:31?pm, Ian Kelly wrote: > Right. ?It's unnecessary, so why saddle yourself with it? FWIW, I expect to release a blog post tomorrow about the principal use cases for super() and how to use it effectively. With just a little bit of know-how, it can be an important tool in your Python toolkit. If any of the comp.lang.python readers want to review and comment on my latest draft, please email me and I'll send it to you directly. Cheers, Raymond Hettinger my email address is listed at http://users.rcn.com/python/download/Descriptor.htm From skippy.hammond at gmail.com Wed May 25 19:46:55 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 26 May 2011 09:46:55 +1000 Subject: bdist_wininst: install_script not run on uninstall In-Reply-To: <201105252128.17504.wbsoft@xs4all.nl> References: <201105252128.17504.wbsoft@xs4all.nl> Message-ID: <4DDD94EF.6010804@gmail.com> On 26/05/2011 5:28 AM, Wilbert Berendsen wrote: > Hi, > > according to the docs the installer bdist_wininst creates will run the > install-script on install with -install (which works perfectly) and on > uninstall with the -remove argument (which seemingly never happens). > > However I want to cleanup some registry stuff on uninstall so I want the > uninstall script to work. > > Studying the source code of the installer[1] in the Run_RemoveScript > function... > > [1] http://svn.python.org/view/python/trunk/PC/bdist_wininst/install.c > > ... it checks for the line '%d Run Script: %s' in the log, which is there. But > can anybody find out why the install script is not run? Works for me in the pywin32 install script - maybe you should make the smallest possible example that doesn't work and post the entire thing here? Mark From steve+comp.lang.python at pearwood.info Wed May 25 19:52:28 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2011 23:52:28 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <72183$4ddd7506$ce534406$5707@news.eurofeeds.com> Message-ID: <4ddd963c$0$29996$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 May 2011 17:30:48 -0400, thegist at nospam.net wrote: > On 5/24/2011 1:39 PM, D'Arcy J.M. Cain wrote: [snip] >> One of my favorite quotes (not sure if it was about Perl or APL) is "I >> refuse to use a programming language where the proponents of it stick >> snippets under each other's nose and say 'I bet you can't guess what >> this does.'" > I dunno. That sounds about like how most programming course exams are > written, no? > The point is that puzzling through arcane bits of code are crucial to > learning > any language. It's a valuable exercise. You seem to miss the point that a good language shouldn't make it possible to write arcane code that needs to be puzzled out. Although in fairness, what's arcane to me might be straightforward to you... and vice versa. In that sense, there probably aren't any "good languages", because it is impractical to have a language that cannot be obfuscated in any way. Nevertheless, we can distinguish "less good" from "more good" in languages in the sense of readability. The fact that some languages not just allow such obfuscation but encourage it makes the language great for puzzles but not so good for when you actually want to get work done and have to deal with code written by someone else. *Especially* if they're significantly smarter, or dumber, than you. Worst of all is dealing with code written by somebody who *thinks* they're smarter but is actually dumber. -- Steven From python at mrabarnett.plus.com Wed May 25 19:56:52 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 May 2011 00:56:52 +0100 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> Message-ID: <4DDD9744.1010002@mrabarnett.plus.com> On 26/05/2011 00:25, tkpmep at hotmail.com wrote: > Thanks for the guidance - it was indeed an issue with reading in > binary vs. text., and I do now succeed in reading the last line, > except that I now seem unable to split it, as I demonstrate below. > Here's what I get when I read the last line in text mode using 2.7.1 > and in binary mode using 3.2 respectively under IDLE: > > 2.7.1 > Name 31/12/2009 0 0 0 > > 3.2 > b'Name\t31/12/2009\t0\t0\t0\r\n' > > if, under 2.7.1 I read the file in text mode and write >>>> x = lastLine(fn) > I can then cleanly split the line to get its contents >>>> x.split('\t') > ['Name', '31/12/2009', '0', '0', '0\n'] > > but under 3.2, with its binary read, I get >>>> x.split('\t') > Traceback (most recent call last): > File "", line 1, in > x.split('\t') > TypeError: Type str doesn't support the buffer API > > If I remove the '\t', the split now works and I get a list of bytes > literals >>>> x.split() > [b'Name', b'31/12/2009', b'0', b'0', b'0'] > > Looking through the docs did not clarify my understanding of the > issue. Why can I not split on '\t' when reading in binary mode? > x.split('\t') tries to split on '\t', a string (str), but x is a bytestring (bytes). Do x.split(b'\t') instead. From ethan at stoneleaf.us Wed May 25 19:58:55 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 25 May 2011 16:58:55 -0700 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> Message-ID: <4DDD97BF.4060605@stoneleaf.us> tkpmep at hotmail.com wrote: > Thanks for the guidance - it was indeed an issue with reading in > binary vs. text., and I do now succeed in reading the last line, > except that I now seem unable to split it, as I demonstrate below. > Here's what I get when I read the last line in text mode using 2.7.1 > and in binary mode using 3.2 respectively under IDLE: > > 3.2 > b'Name\t31/12/2009\t0\t0\t0\r\n' > > under 3.2, with its binary read, I get >--> x.split('\t') > Traceback (most recent call last): > File "", line 1, in > x.split('\t') > TypeError: Type str doesn't support the buffer API You are trying to split a bytes object with a str object -- the two are not compatible. Try splitting with the bytes object b'\t'. ~Ethan~ From andrei.avk at gmail.com Wed May 25 20:15:09 2011 From: andrei.avk at gmail.com (RainyDay) Date: Wed, 25 May 2011 17:15:09 -0700 (PDT) Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> Message-ID: <8984a70f-449e-40a4-b962-0e93ba8c4071@m40g2000vbt.googlegroups.com> On May 25, 3:14?pm, John Bokma wrote: > Ethan Furman writes: > > Terry Reedy wrote: > >> On 5/25/2011 8:01 AM, John Bokma wrote: > > >>> to. Like I already stated before: if Python is really so much better > >>> than Python readability wise, why do I have such a hard time dropping > >>> Perl and moving on? > > >> [you meant 'than Perl'] You are one of the people whose brain fits > >> Perl (or vice versa) better than most. So enjoy it. Ignore anyone > >> who says otherwise. > > > +1 > > > If everybody's brain worked the same, we wouldn't have so many > > different languages to choose from. > > So, this means that in general language readability is not as clear cut > as some seem to advertise ;-). > I only know a tiny bit of Perl but I think you may prefer it because it gives you some advantages in short term but you have to pay more than it's worth (arguably) in the long term. When you sit down to write a new program, it's easier to do than in python because it's quicker to type and, of the proverbial "many ways", you chose the ones that suit your taste better. However, when you sit down to read someone else's code, it's harder to read because you don't know the intent of their authors. If they had different taste for idioms or formatting style than you do, you will chalk it up to them being bad programmers and having bad coding or formatting style, so it's not perceived as a perl's failing. Python way has more of an emphasis on everyone agreeing on some preferred, standard idioms so that everyone can pick up each others' code quickly. Similarly, when we write in english, we have conventions of, for instance, capitalizing at the start of a sentence and having a period at the end of it, and following rules of grammar. However, if I'm writing notes for my own use, I might write: similarly when we write in english we have conventions of eg capitalizing at start of sentence and having period at the end & following rules of grammar but since i'm writing for my own use maybe it's easier to write in lower caps and use 3 spaces at the end of sentences, since no-ones has to read it but me? From ethan at stoneleaf.us Wed May 25 20:32:58 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 25 May 2011 17:32:58 -0700 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <4DDD9744.1010002@mrabarnett.plus.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> <4DDD9744.1010002@mrabarnett.plus.com> Message-ID: <4DDD9FBA.8000103@stoneleaf.us> MRAB wrote: > On 26/05/2011 00:25, tkpmep at hotmail.com wrote: >> Thanks for the guidance - it was indeed an issue with reading in >> binary vs. text., and I do now succeed in reading the last line, >> except that I now seem unable to split it, as I demonstrate below. >> Here's what I get when I read the last line in text mode using 2.7.1 >> and in binary mode using 3.2 respectively under IDLE: >> >> 2.7.1 >> Name 31/12/2009 0 0 0 >> >> 3.2 >> b'Name\t31/12/2009\t0\t0\t0\r\n' >> >> if, under 2.7.1 I read the file in text mode and write >>>>> x = lastLine(fn) >> I can then cleanly split the line to get its contents >>>>> x.split('\t') >> ['Name', '31/12/2009', '0', '0', '0\n'] >> >> but under 3.2, with its binary read, I get >>>>> x.split('\t') >> Traceback (most recent call last): >> File "", line 1, in >> x.split('\t') >> TypeError: Type str doesn't support the buffer API >> >> If I remove the '\t', the split now works and I get a list of bytes >> literals >>>>> x.split() >> [b'Name', b'31/12/2009', b'0', b'0', b'0'] >> >> Looking through the docs did not clarify my understanding of the >> issue. Why can I not split on '\t' when reading in binary mode? >> > x.split('\t') tries to split on '\t', a string (str), but x is a > bytestring (bytes). > > Do x.split(b'\t') instead. Instances of the bytes class are more appropriately called 'bytes objects' rather than 'bytestrings' as they are really lists of integers. Accessing a single element of a bytes object does not return a bytes object, but rather the integer at that location; i.e. --> b'xyz'[1] 121 Contrast that with the str type where --> 'xyz'[1] 'y' ~Ethan~ From jschementi at gmail.com Wed May 25 20:44:38 2011 From: jschementi at gmail.com (Jimmy Schementi) Date: Thu, 26 May 2011 00:44:38 GMT Subject: Unable to make ironpython run in browser with silverlight References: <715e82a9-3761-4d82-9df4-1c5f39633160@h36g2000pro.googlegroups.com> Message-ID: <2011525204432usenet@terrranews.com> You need to run it from a web-server; it doesn't work when running from file:// due to Silverlight's security sandbox. Read the comments on my blog-post, it mentions the web-server there. From r.richardparker at comcast.net Wed May 25 20:58:39 2011 From: r.richardparker at comcast.net (Richard Parker) Date: Wed, 25 May 2011 17:58:39 -0700 Subject: Python-list Digest, Vol 92, Issue 221 In-Reply-To: References: Message-ID: > Writing code is primarily for *human readers*. Once you've compiled the > code once, the computer never need look at it again, but human being come > back to read it over and over again, to learn from it, or for > maintenance. We rightfully value our own time and convenience as more > valuable than that of the computer's, which is why we use programming > languages at all, instead of having custom-made hardware built for every > task we want the computer to do: Not only the code itself, but, hopefully, embedded comments help even non-authors of the code to understand, maintain and improve it. Programming books that include examples often spend many pages dissecting even short segments of the code to tutor would-be developers how it works and what it does. Well written code in any language, with accompanying comments, is invaluable for anyone who has the need or interest to Understand and maintain it. My (ancient) books about object-oriented programming were used to teach hundreds of computer science students in universities all over the world, and the stressed the importance of embedded comments. How many times has any programmer looked at (even inscrutable) code with accompanying comments and hasn't said to themselves "so that's how to do it, or that's what it does". It's time to stop having flame wars about languages and embrace programmers who care enough about possible future readers of their code to thoroughly comment it. Comments are far more valuable than the actual language in which the code is written, IMHO. Sent from my iPad. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed May 25 21:06:04 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 May 2011 19:06:04 -0600 Subject: Python 3.2 bug? Reading the last line of a file In-Reply-To: <4DDD7A27.60602@mrabarnett.plus.com> References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <4DDD7A27.60602@mrabarnett.plus.com> Message-ID: On Wed, May 25, 2011 at 3:52 PM, MRAB wrote: > What do you mean by "may include the decoder state in its return value"? > > It does make sense that the values returned from tell() won't be in the > middle of an encoded sequence of bytes. If you take a look at the source code, tell() returns a long that includes decoder state data in the upper bytes. For example: >>> data = b' ' + '\u0302a'.encode('utf-16') >>> data b' \xff\xfe\x02\x03a\x00' >>> f = open('test.txt', 'wb') >>> f.write(data) 7 >>> f.close() >>> f = open('test.txt', 'r', encoding='utf-16') >>> f.read() Traceback (most recent call last): File "", line 1, in File "c:\python32\lib\codecs.py", line 300, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) File "c:\python32\lib\encodings\utf_16.py", line 61, in _buffer_decode codecs.utf_16_ex_decode(input, errors, 0, final) UnicodeDecodeError: 'utf16' codec can't decode bytes in position 6-6: truncated data The problem of course is the initial space, throwing off the decoder. We can try to seek past it: >>> f.seek(1) 1 >>> f.read() '\ufeff\u0302a' But notice that since we're not reading from the beginning of the file, the BOM has now been interpreted as data. However: >>> f.seek(1 + (2 << 65)) 73786976294838206465 >>> f.read() '\u0302a' And you can see that instead of reading from position 73786976294838206465 it has read from position 1 starting in the "read a BOM" state. Note that I wouldn't recommend doing anything remotely like this in production code, not least because the value that I passed into seek() is platform-dependent. This is just a demonstration of how the seek() value can include decoder state. Cheers, Ian From philip at semanchuk.com Wed May 25 21:08:14 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 25 May 2011 21:08:14 -0400 Subject: Newbie question about SQLite + Python and twitter In-Reply-To: References: Message-ID: <2BE08035-7495-47FD-8FDA-D5B7025ED45F@semanchuk.com> On May 25, 2011, at 2:17 PM, Jayme Proni Filho wrote: > Helo guys, > > I'm building a local application for twitter for my brother's store. I'm in > the beginning and I have some newbie problems, so: > > I create a table called tb_messages with int auto increment and varchar(140) > fields; > I did three SQL funcionts, insert_tweet, delete_tweet, select_tweet > > select_tweet is use for getting messages for sending them to twitter; > > My problem is: How can i make my select_tweet works at the same time that > insert or delete funcions. I just got to work when I stop select function. > > I would like to do my app works all the time. Hi Jayme, You need to provide a lot more information for us to be able to help you. Some suggestions -- http://www.istf.com.br/perguntas/#beprecise bye Philip From akabaila at pcug.org.au Wed May 25 21:27:33 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Thu, 26 May 2011 11:27:33 +1000 Subject: Odp: Re: Strange behaviour of input() function (Python 3.2) In-Reply-To: References: Message-ID: <201105261127.33624.akabaila@pcug.org.au> On Wednesday 25 May 2011 06:27:52 sunrrrise wrote: > Ok, another time I'd like to thank you for your help. I gave > up, I'm going to get used to IDLE GUI... at least this one > works! With IDLE, after any changes to the program, you are asked to "save file". IDLE knows that a file in python needs to be saved before it can be run! If you use Notepad, it does not know that Python programs need to be saved to disk before they can be executed. So you should remember to save them first. To use IDLE is a good choice, particularly if you are a beginner! OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From miki.tebeka at gmail.com Wed May 25 21:29:46 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 25 May 2011 18:29:46 -0700 (PDT) Subject: Cherrypy In-Reply-To: Message-ID: <1a2f27a7-3b1b-4b5e-84bf-9103e615f84c@glegroupsg2000goo.googlegroups.com> I wrote http://drdobbs.com/showArticle.jhtml?articleID=199102936&queryText=query way back then. It might be of some help. If you have any specific questions, feel free to post them to the group. From miki.tebeka at gmail.com Wed May 25 21:29:46 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 25 May 2011 18:29:46 -0700 (PDT) Subject: Cherrypy In-Reply-To: Message-ID: <1a2f27a7-3b1b-4b5e-84bf-9103e615f84c@glegroupsg2000goo.googlegroups.com> I wrote http://drdobbs.com/showArticle.jhtml?articleID=199102936&queryText=query way back then. It might be of some help. If you have any specific questions, feel free to post them to the group. From gvagif at gmail.com Wed May 25 21:59:41 2011 From: gvagif at gmail.com (Sunny) Date: Wed, 25 May 2011 18:59:41 -0700 (PDT) Subject: Unable to make ironpython run in browser with silverlight References: <715e82a9-3761-4d82-9df4-1c5f39633160@h36g2000pro.googlegroups.com> <2011525204432usenet@terrranews.com> Message-ID: <73261820-78c6-4448-a75b-019c197f9832@f31g2000pri.googlegroups.com> On May 26, 9:44?am, Jimmy Schementi wrote: > You need to run it from a web-server; it doesn't work when running from file:// due to Silverlight's security sandbox. Read the comments on my blog-post, it mentions the web-server there. I see.. But here: http://silverlighttest.zzl.org/silverlighttest.html , it runs from a web server, but still gives error. And it has the same source code as your example, except that I replace repl.py with the direct link, as you advise on your blog. I think the problem is with this part: Because when I delete it, it runs properly. Do you know why is that? From erichcart at gmail.com Wed May 25 22:07:39 2011 From: erichcart at gmail.com (ErichCart ErichCart) Date: Wed, 25 May 2011 19:07:39 -0700 (PDT) Subject: Unable to make ironpython run in browser with silverlight References: <715e82a9-3761-4d82-9df4-1c5f39633160@h36g2000pro.googlegroups.com> <2011525204432usenet@terrranews.com> Message-ID: <22405da5-439d-42be-8f2d-65090d3e5679@22g2000prx.googlegroups.com> On May 26, 9:44 am, Jimmy Schementi wrote: > You need to run it from a web-server; it doesn't work when running from file:// due to Silverlight's security sandbox. Read the comments on my blog-post, it mentions the web-server there. I see.. But here: http://silverlighttest.zzl.org/silverlighttest.html , it runs from a web server, but still gives error. And it has the same source code as your example, except that I replace repl.py with the direct link, as you advise on your blog. I think the problem is with this part: Because when I delete it, it runs properly. Do you know why is that? From john at castleamber.com Wed May 25 23:00:33 2011 From: john at castleamber.com (John Bokma) Date: Wed, 25 May 2011 22:00:33 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <874o4i17zi.fsf@castleamber.com> Steven D'Aprano writes: > On Wed, 25 May 2011 07:01:07 -0500, John Bokma wrote: > >> if Python is really so much better than Python [Perl] >> readability wise, why do I have such a hard time dropping >> Perl and moving on? > > My guess is that you have an adversarial view of computer languages, Well, it's clear that you are indeed the fuckwit I suspected you are. What's a pity is that you are so vocal in this group and to me at least makes it a way less pleasant experience to read this group. Get a life. Or better, just fuck off and die. It will improve both the world and the Python community, of which you are nothing but a little, smelly shitstain. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From rosuav at gmail.com Thu May 26 00:00:23 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 14:00:23 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 26, 2011 at 8:58 AM, Steven D'Aprano wrote: > ... For everyone else, I'll use an > ordinary adult vocabulary, and that includes the word "recursion" or > "recursive". Overheard yesterday: "Our conversation was recursing..." I don't know what they were talking about, but I'm pretty sure it wasn't the technical details of a function's implementation, given that one of the people concerned was anything but a computer programmer (I don't know about the other). It's a perfectly good word, useful in many contexts. Chris Angelico From rosuav at gmail.com Thu May 26 00:06:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 14:06:56 +1000 Subject: Python-list Digest, Vol 92, Issue 221 In-Reply-To: References: Message-ID: On Thu, May 26, 2011 at 10:58 AM, Richard Parker wrote: > It's time to stop having flame wars about languages and embrace programmers > who care enough about possible future readers of their code to thoroughly > comment it. Comments are far more valuable than the actual language in which > the code is written, IMHO. The problem with comments (and documentation in general) is that they are often imperfect. If the code is absolutely opaque but it has a comment next to it, you still have that niggling doubt: has the comment been updated whenever the code has? Was it even accurate in the first place? (Comments often say what a piece of code _ought_ to do, but the code might have a bug in it. And sometimes, that bug ends up being part of the function's definition, and people depend on it.) I'd rather have both - reasonably readable code AND a comment, where the comment explains the intent behind the code. // allow space for frobnostication height += BTN_HEIGHT; Chris Angelico From ben at benfinney.id.au Thu May 26 00:25:43 2011 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 26 May 2011 14:25:43 +1000 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> Message-ID: <87oc2qay0o.fsf@benfinney.id.au> > Get a life. Or better, just fuck off and die. It will improve both the > world and the Python community, of which you are nothing but a little, > smelly shitstain. That abuse is entirely unwelcome in this community, against any person. Please desist. If you find any contributing members so difficult to deal with, please don't respond at all. -- \ ?We have met the enemy and he is us.? ?Walt Kelly, _Pogo_ | `\ 1971-04-22 | _o__) | Ben Finney From ben at benfinney.id.au Thu May 26 00:38:31 2011 From: ben at benfinney.id.au (Ben Finney) Date: Thu, 26 May 2011 14:38:31 +1000 Subject: Parse config file and command-line arguments, to get a single collection of options Message-ID: <87k4deaxfc.fsf@benfinney.id.au> Howdy all, Python's standard library has modules for configuration file parsing (configparser) and command-line argument parsing (optparse, argparse). I want to write a program that does both, but also: * Has a cascade of options: default option values, overridden by config file options, overridden by command-line options. * Reads a different, or even additional, configuration file if specified on the command-line (e.g. --config-file foo.conf) and yet still obeys the above cascade. * Allows a single definition of an option (e.g. logging level) to define the same option for parsing from configuration files and the command line. * Unifies the parsed options into a single collection for the rest of the program to access without caring where they came from. How can I achieve this with minimum deviation from the Python standard library? (For anyone interested in gaining StackOverflow points, I'm also asking this as a question there so feel free to post answers on that site .) -- \ ?Apologize, v. To lay the foundation for a future offense.? | `\ ?Ambrose Bierce, _The Devil's Dictionary_, 1906 | _o__) | Ben Finney From bgreen at nycap.rr.com Thu May 26 00:46:45 2011 From: bgreen at nycap.rr.com (Uncle Ben) Date: Wed, 25 May 2011 21:46:45 -0700 (PDT) Subject: Puzzled by list-appending behavior Message-ID: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> In playing with lists of lists, I found the following: (In 3.1, but the same happens also in 2.7) list = [1,2,3] list.append ( [4,5,6] ) x = list x -> [1,2,3,[4,5,6]] as expected. But the shortcut fails: list=[1,2,3] x = list.append( [4,5,6] ) x -> nothing Can someone explain this to me? Uncle Ben From jpiitula at ling.helsinki.fi Thu May 26 01:09:34 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 26 May 2011 08:09:34 +0300 Subject: Python 3.2 bug? Reading the last line of a file References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> Message-ID: tkpmep at hotmail.com writes: > Looking through the docs did not clarify my understanding of the > issue. Why can I not split on '\t' when reading in binary mode? You can split on b'\t' to get a list of byteses, which you can then decode if you want them as strings. You can decode the bytes to get a string and then split on '\t' to get strings. >>> b'tic\ttac\ttoe'.split(b'\t') [b'tic', b'tac', b'toe'] >>> b'tic\ttac\ttoe'.decode('utf-8').split('\t') ['tic', 'tac', 'toe'] From ben+python at benfinney.id.au Thu May 26 01:11:56 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 May 2011 15:11:56 +1000 Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: <87ei3mavvn.fsf@benfinney.id.au> Uncle Ben writes: > Can someone explain this to me? Yes, the documentation for that function (?list.append?) can explain it. In short: if a method modifies the instance, that method does not return the instance. This policy holds for the built-in types, and should be followed for user-defined types also. -- \ ?[I]t is impossible for anyone to begin to learn that which he | `\ thinks he already knows.? ?Epictetus, _Discourses_ | _o__) | Ben Finney From python at rcn.com Thu May 26 01:15:35 2011 From: python at rcn.com (Raymond Hettinger) Date: Wed, 25 May 2011 22:15:35 -0700 (PDT) Subject: Parse config file and command-line arguments, to get a single collection of options References: <87k4deaxfc.fsf@benfinney.id.au> Message-ID: <5872e7ac-de37-438f-a2da-147ff466f8f1@z15g2000prn.googlegroups.com> On May 25, 9:38?pm, Ben Finney wrote: > Howdy all, > > Python's standard library has modules for configuration file parsing > (configparser) and command-line argument parsing (optparse, argparse). I > want to write a program that does both, but also: > > * Has a cascade of options: default option values, overridden by config > ? file options, overridden by command-line options. > > * Reads a different, or even additional, configuration file if specified > ? on the command-line (e.g. --config-file foo.conf) and yet still obeys > ? the above cascade. > > * Allows a single definition of an option (e.g. logging level) to define > ? the same option for parsing from configuration files and the command > ? line. > > * Unifies the parsed options into a single collection for the rest of > ? the program to access without caring where they came from. > > How can I achieve this with minimum deviation from the Python standard > library? One thought is start with something like ChainMap, http://code.activestate.com/recipes/305268-chained-map-lookups/?in=user-178123 , or some variant to unify multiple mapping objects into a single prioritized collection. A mapping for command line args can be made by using vars() on an argparse namespace to create a dictionary. ConfigParser's mapping is accessible via its get() method. With a ChainMap style object you can add other option sources such as os.environ. This should get you started on your grand unified, do- everything-at-once vision with minimal deviation from the standard library. Raymond From clp2 at rebertia.com Thu May 26 01:17:45 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 25 May 2011 22:17:45 -0700 Subject: Puzzled by list-appending behavior In-Reply-To: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: On Wed, May 25, 2011 at 9:46 PM, Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] > list.append ( [4,5,6] ) Note the lack of output after this line. This indicates that list.append([4,5,6]) returned None. Contrast this with, say, list.pop(). > x = list > x ? -> > ? ?[1,2,3,[4,5,6]] > as expected. > > But the shortcut fails: > > list=[1,2,3] > x = list.append( [4,5,6] ) > x ? -> > ? nothing > > Can someone explain this to me? The append() method does *not* return the now-appended-to list. It is a mutator method that modifies the list object in-place; per convention, it therefore returns None to reinforce its side-effecting nature to the user (the interactive interpreter by default does not display None expression results); analogous methods in other languages return void. list.remove(), list.sort(), and list.extend() similarly return None rather than the now-modified list. Cheers, Chris -- http://rebertia.com From r.richardparker at comcast.net Thu May 26 02:40:30 2011 From: r.richardparker at comcast.net (Richard Parker) Date: Wed, 25 May 2011 23:40:30 -0700 Subject: Python-list Digest, Vol 92, Issue 223 In-Reply-To: References: Message-ID: > > On Thu, May 26, 2011 at 10:58 AM, Richard Parker > wrote: >> It's time to stop having flame wars about languages and embrace programmers >> who care enough about possible future readers of their code to thoroughly >> comment it. Comments are far more valuable than the actual language in which >> the code is written, IMHO. > > The problem with comments (and documentation in general) is that they > are often imperfect. If the code is absolutely opaque but it has a > comment next to it, you still have that niggling doubt: has the > comment been updated whenever the code has? Was it even accurate in > the first place? (Comments often say what a piece of code _ought_ to > do, but the code might have a bug in it. And sometimes, that bug ends > up being part of the function's definition, and people depend on it.) > I'd rather have both - reasonably readable code AND a comment, where > the comment explains the intent behind the code. Gee...I absolutely agree! I have no problem with anything you said. My intent in writing at all was to express that comments (along with well-written code) are more important than the language in which the code is written. There's no doubt that sometimes comments aren't updated when code is changed and sometimes comments express what the code is attempting to implement; however, code in any language written without accompanying comments is much harder to understand AND maintain. If, given a chunk of readable Python code written by someone else without accompanying comments, I would be scratching my head far longer trying to understand, modify, or maintain it, than if it also had (even imperfect) accompanying comments. So--we agree that reasonably readable code AND a comment that explains the intent of the code is what we should all strive to produce. -------------- next part -------------- An HTML attachment was scrubbed... URL: From akabaila at pcug.org.au Thu May 26 03:18:36 2011 From: akabaila at pcug.org.au (Algis Kabaila) Date: Thu, 26 May 2011 17:18:36 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: <201105261718.36646.akabaila@pcug.org.au> On Thursday 26 May 2011 14:46:45 Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] > list.append ( [4,5,6] ) > x = list > x -> > [1,2,3,[4,5,6]] > as expected. > > But the shortcut fails: > > list=[1,2,3] > x = list.append( [4,5,6] ) > x -> > nothing > > Can someone explain this to me? > > Uncle Ben And why do you insist on calling and instance of list, "list"? Even a human reader will confuse which is which. What you are showing is an example how confusing things become when a keyword (list) is over-written (with list instance). Why don't you just say lst = [1, 2, 3] rather than list =... It may be permissible, but it is not a good idea! Old (practical) Al. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 26 03:20:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 17:20:53 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 2:46 PM, Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] Ben Finney has already answered the main question, but as a side point, I would generally avoid creating a variable called 'list'. That's the name of the type (Python 2) or class (Python 3) of all lists, so it might result in confusion if you have an actual list with that name. If you want the behaviour of joining two lists (or adding something to a list) and saving the result elsewhere, you can use the plain addition: a=[1,2,3] b=a+[[4,5,6]] Note that you have to add a list, and it will append the contents of that list. Chris Angelico From rosuav at gmail.com Thu May 26 03:23:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 17:23:01 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 5:20 PM, Chris Angelico wrote: > > Ben Finney has already answered the main question Giving credit where credit's due, it was more Chris Rebert's post that answered the question. Sorry Chris! Chris Angelico From bgreen at nycap.rr.com Thu May 26 03:33:44 2011 From: bgreen at nycap.rr.com (Uncle Ben) Date: Thu, 26 May 2011 00:33:44 -0700 (PDT) Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: On May 26, 12:46?am, Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] > list.append ( [4,5,6] ) > x = list > x ? -> > ? ? [1,2,3,[4,5,6]] > as expected. > > But the shortcut fails: > > list=[1,2,3] > x = list.append( [4,5,6] ) > x ? -> > ? ?nothing > > Can someone explain this to me? > > Uncle Ben Thank you all. It is wonderful to have this community as a resource. Uncle Ben From s.selvamsiva at gmail.com Thu May 26 04:00:18 2011 From: s.selvamsiva at gmail.com (Selvam) Date: Thu, 26 May 2011 13:30:18 +0530 Subject: Hotshoting recursive function In-Reply-To: References: Message-ID: On Wed, May 25, 2011 at 2:20 PM, Gabriel Genellina wrote: > En Sun, 22 May 2011 10:42:08 -0300, Selvam > escribi?: > > > I am using hotshot module to profile my python function. >> >> I used the details from ( >> >> http://code.activestate.com/recipes/576656-quick-python-profiling-with-hotshot/ >> ). >> >> The function I profile is a recursive one and I am getting the following >> error, >> >> "ProfilerError: profiler already active" >> >> I guess this is due to the recursive call to the profiling function. >> >> I would like to get some suggestions. >> > > The recursive call inside your function should call the undecorated > function, not the decorated function again. Decorator syntax is not > convenient anymore. > > Using the same names as in the recipe example: > > > # a recursive function > def my_slow_function(n): > ... > return my_slow_function(n-1) > > > my_profiled_slow_function = hotshotit(my_slow_function) > my_profiled_slow_function(n) > > > This works, in the sense that it does not raise ProfileError anymore. > Interpreting profile data is up to you... > > > Thanks Gabriel, it makes more sense ! > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards, S.Selvam SG E-ndicus Infotech Pvt Ltd. http://e-ndicus.com/ " I am because we are " -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu May 26 04:09:42 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 May 2011 01:09:42 -0700 Subject: Puzzled by list-appending behavior In-Reply-To: References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 12:23 AM, Chris Angelico wrote: > On Thu, May 26, 2011 at 5:20 PM, Chris Angelico wrote: >> >> Ben Finney has already answered the main question > > Giving credit where credit's due, it was more Chris Rebert's post that > answered the question. Sorry Chris! Eh, one can't fight chronology! I'm just surprised that the docstring doesn't explicitly state "Returns None." by this point, given that this is such a common point of newbie confusion. Cheers, Chris From thorsten at thorstenkampe.de Thu May 26 04:24:06 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 26 May 2011 10:24:06 +0200 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> Message-ID: * John Bokma (Wed, 25 May 2011 07:01:07 -0500) > Thorsten Kampe writes: > > * Chris Angelico (Wed, 25 May 2011 08:01:38 +1000) > >> > >> On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain wrote: > >> > One of my favorite quotes (not sure if it was about Perl or APL) is > > "I > >> > refuse to use a programming language where the proponents of it stick > >> > snippets under each other's nose and say 'I bet you can't guess what > >> > this does.'" > >> > >> Yes, I believe that was Perl. And an amusing quote. But most of the > >> point of it comes from the fact that Perl uses punctuation for most of > >> its keywords, whereas (say) Python uses English words; it's a lot more > >> fun to crunch something down when you can use $| and friends than when > >> you have to put "x and y", complete with spaces, for a simple boolean. > >> But that says nothing about which language is actually better for > >> working with... [...] > > > > It does say something about readibility. And yes, "readability counts". > > And yes, readability says a lot about how good a language is for reading > > and working with. > > To people used to the latin alphabet languages using a different script > are unreadable. So readability has a lot to do with what one is used > to. You've made that "alphabet" argument more than once. Nevertheless it's nonsense (sorry). Perl uses the same alphabet as Python. Only the "words" Perl uses ("$|" for instance) are only found in a Perl dictionary not in a English or math dictionary like the one that Python uses. That's why you can /read/ Python but you have to /decode/ Perl to understand the source code. > Like I already stated before: if Python is really so much better than > Python readability wise, why do I have such a hard time dropping Perl > and moving on? What kind of argument is that? Thorsten From thorsten at thorstenkampe.de Thu May 26 04:48:07 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 26 May 2011 10:48:07 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Steven D'Aprano (25 May 2011 21:59:58 GMT) > On Wed, 25 May 2011 09:26:11 +0200, Thorsten Kampe wrote: > > > Naming something in the terms of its implementation details (in this > > case recursion) is a classical WTF. > > *If* that's true, it certainly doesn't seem to apply to real-world > objects. Think about the exceptions: > > microwave oven > vacuum cleaner > oven fries > electric car > chain saw > flintlock rifle > air gun > vulcanised rubber > kerosene heater > aluminium foil > diamond saw > gas stove > wood stove > four-wheel drive car > incandescent light bulb > electric razor > unleaded petrol > > to mention only a few. > > Naming the thing after the implementation would often seem to be *good > advice*, not bad. We often do care about implementations. You really do > need to know whether the car you drive uses leaded or unleaded. That's exactly the point. You don't need to know whether "include sub- directories" was implemented recursively. It's absolutely pointless. But not to digress, the /real/ problem with commands or idioms like "rm -r" is /not/ their choice of option names but that they explain these options in the exact same terms. No one would have a problem with "-r, --recursive -- remove directories including all sub-directories" instead of "-r, --recursive -- remove directories and their contents recursively". Thorsten From thorsten at thorstenkampe.de Thu May 26 04:59:19 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 26 May 2011 10:59:19 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Steven D'Aprano (25 May 2011 22:58:21 GMT) > > On Wed, 25 May 2011 00:06:06 +0200, Rikishi42 wrote: > > > What I mean is: I'm certain that over the years I've had more than one > > person come to me and ask what 'Do you wish to delete this directory > > recursively?' meant. BAut never have I been asked to explain what 'Do > > you wish to delete this directory and it's subdirs/with all it's > > contents?' meant. Never. > > I know many people who have no idea what a directory is, let alone a > subdirectory, unless it's the phone directory. They're non-computer > users. Once they start using computers, they quickly work out what the > word means in context, or they ask and get told, and then they've learned > a new word and never need ask again. This is a good thing. > > The idiom of "recursively delete" is no different. Of course some people > will have to learn a new term in order to make sense of it. So what? It's not just a "new term". It tries to describe something which could be easily described in the terms of what is already known. If someone has learned what a directory or folder is, you don't have to explain what "include sub-folders" means. Instead of creating a new mysterious term ("recursively delete"), you simply explain stuff by re- using an already existing term. It's just that simple. Thorsten From steve+comp.lang.python at pearwood.info Thu May 26 06:06:44 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 May 2011 10:06:44 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dde2634$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 10:48:07 +0200, Thorsten Kampe wrote: > But not to digress, the /real/ problem with commands or idioms like "rm > -r" is /not/ their choice of option names but that they explain these > options in the exact same terms. No one would have a problem with "-r, > --recursive -- remove directories including all sub-directories" instead > of "-r, --recursive -- remove directories and their contents > recursively". I think you are understanding the description "remove directories and their contents recursively" as a description of the *mechanism* by which rm removes the directory, i.e. some recursive tree-walking function that visits each node and deletes it. I don't believe that's how the description is meant to be understood. I understand it as describing the effect, not the implementation. If the tree-walker was re-written to be iterative, the description would not need to be changed. It is meant to be understood as: rm -r foo * deletes foo * deletes things inside foo * if any of those things inside foo are directories, delete them too, in exactly the same way (i.e. "recursively"). Notice that, strictly speaking, the description is impossible. You can't delete the top level directory first. But that's how the human reader will understand it: * delete the directory you point it at, plus the things inside it in the same way rather than how the implementation (probably) does it: * drill down all the way to the bottom, start deleting like mad, and work your way back up the stack, deleting as you go. You're interpreting the reference to "recursive" as a nod to the implementation. I'm not, and therefore your arguments don't convince me. -- Steven From steve+comp.lang.python at pearwood.info Thu May 26 06:07:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 May 2011 10:07:24 GMT Subject: Python-list Digest, Vol 92, Issue 221 References: Message-ID: <4dde265c$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 14:06:56 +1000, Chris Angelico wrote: > On Thu, May 26, 2011 at 10:58 AM, Richard Parker > wrote: >> It's time to stop having flame wars about languages and embrace >> programmers who care enough about possible future readers of their code >> to thoroughly comment it. Comments are far more valuable than the >> actual language in which the code is written, IMHO. > > The problem with comments (and documentation in general) is that they > are often imperfect. [snip more stuff I agree with] It's not the lack of perfection, since no code is perfect, but that comments are frequently missing, obsolete, incorrect, or inane: i.e. actively harmful rather than just imperfect. The classic example of what not to write as a comment: x += 1 # add one to x One of the regulars here -- Aahz -- often has this quote as his sig: "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'." -- Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22 My experience is that comments in Python are of relatively low usefulness. (For avoidance of doubt: not *zero* usefulness, merely low.) I can name variables, functions and classes with sensible, self- documenting names. Why write: x = get_results(arg) # x is a list of 1 or more results [... much later] for y in x: # process each result in turn do_something_with(y) when I can write this? results = get_results(arg) [...] for result in results: do_something_with(result) It's better to write self-documenting code, than code + comments. Another use for comments is to explain *why* rather than *what*. No matter how readable your code is, if you don't understand why it is done, you can't effectively maintain it. If the why is obvious, you don't need a comment. But for me, the main reason # comments are of relatively little use in Python for me is because I write *tons* of docstrings and doctests. Any comment which could be useful to know at run-time goes into the docstring; what's left over, if anything, becomes a # comment. Between self-documenting code and docstrings, I hardly write any # comments. -- Steven From rosuav at gmail.com Thu May 26 06:25:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 20:25:29 +1000 Subject: Python-list Digest, Vol 92, Issue 221 In-Reply-To: <4dde265c$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4dde265c$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, May 26, 2011 at 8:07 PM, Steven D'Aprano wrote: > Another use for comments is to explain *why* rather than *what*. No > matter how readable your code is, if you don't understand why it is done, > you can't effectively maintain it. If the why is obvious, you don't need > a comment. That's what my (contrived) example was. I also often have comments that are leftovers from the pseudocode stage; for instance, iteration 1: //TODO: Look up foo in some table and figure out which bar should be used. Iteration 2: //TODO: Look up foo in the bar_foo table and figure out which bar should be used. legal_bar = bar_foo[foo]; bar=legal_bar[0]; Iteration 3: //Figure out which bar should be used legal_bar = bar_foo[foo]; ... some algorithmic way of figuring out the best one ... When it leaves TODO status, anything that's inherently obvious ("Look up foo in the bar_foo table") gets trimmed, but the statements of purpose tend to remain. Especially if the "figuring out the best one" is several lines of code, it makes sense to keep that comment. But because of the organic growth of the code, the comment will usually still bracket the "look up foo in table" part, even though the comment doesn't have anything to do with that. Is the comment inappropriate? I don't think so. Is it perfect? Definitely not. But it's still generally worth keeping. But I absolutely agree. The code ought to be self-documenting to the greatest extent possible (but no further - don't just create variables/constants for absolutely no reason than to embody documentation). Docstrings and autodoc comments are superior to general comments, although IMHO all three are pretty much the same thing. Chris Angelico From claird271 at gmail.com Thu May 26 06:27:13 2011 From: claird271 at gmail.com (Cameron Laird) Date: Thu, 26 May 2011 03:27:13 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (May 26) Message-ID: <384a86e5-191a-4cbf-b46a-75be7cf15341@gu8g2000vbb.googlegroups.com> [This edition drafted by Gabriel Genellina.] QOTW: "They did a study once to determine the best tool for development. Turns out that the most productive tool was generally the one that the user believed was the most productive. In hindsight I think that that was rather obvious." - D'Arcy J.M. Cain, 2011-05-24 Python 2.6.7 release candidate 2 now available: http://groups.google.com/group/comp.lang.python/t/ebbd57431bb084b2/ Amazing logic: and becomes or and or becomes and http://groups.google.com/group/comp.lang.python/t/b13e786438a609dd/ Equal objects must have equal hashes - but how strong is that requirement? http://groups.google.com/group/comp.lang.python/t/f23f72cf633892f9/ Do secure systems exist? http://groups.google.com/group/comp.lang.python/t/f887168ca476618f/7503714d82b1789b?#7503714d82b1789b os.access() returns totally useless results on Windows, always has, and nobody cares: http://groups.google.com/group/comp.lang.python/t/aa3d9b21c77fa7d7/ Is this PAAS Python mind-blowingly important, or pointless, or a mix of the two? http://www.activestate.com/cloud contextlib.nested() is deprecated - and this example shows why a custom implementation is hard to write well: http://groups.google.com/group/comp.lang.python/t/d6b090b7fd4a92c6/ Why one startup chose Python for development: http://groups.google.com/group/comp.lang.python/t/17dca3bf467c9001/ And more reasons another developer chose it: http://groups.google.com/group/comp.lang.python/t/17dca3bf467c9001/83a7be235c113dac?#83a7be235c113dac And now, things people do *not* like about Python: http://groups.google.com/group/comp.lang.python/t/fff2826d44ea336/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From thorsten at thorstenkampe.de Thu May 26 06:46:58 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 26 May 2011 12:46:58 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde2634$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Steven D'Aprano (26 May 2011 10:06:44 GMT) > > On Thu, 26 May 2011 10:48:07 +0200, Thorsten Kampe wrote: > > > But not to digress, the /real/ problem with commands or idioms like "rm > > -r" is /not/ their choice of option names but that they explain these > > options in the exact same terms. No one would have a problem with "-r, > > --recursive -- remove directories including all sub-directories" instead > > of "-r, --recursive -- remove directories and their contents > > recursively". > > I think you are understanding the description "remove directories and > their contents recursively" as a description of the *mechanism* by which > rm removes the directory, i.e. some recursive tree-walking function that > visits each node and deletes it. > > I don't believe that's how the description is meant to be understood. I > understand it as describing the effect, not the implementation. It doesn't matter how I interprete the explanation "-r = recursively delete". What matters is that I have to explain (interpret, translate the explanation. > You're interpreting the reference to "recursive" as a nod to the > implementation. I'm not, and therefore your arguments don't convince > me. No one understands what "recursively delete" means until someone explains ("translates") it to him. This is not an argument but a simple fact. I experienced it many times, others here in the thread did and probably you, too. "recursively delete" is completely unneccessary because there is already a simple explanation that everyone understands without translation ("delete including subdirectories"). It's unnecessary bullshit buzzword bingo from nerds which adds or helps or explains nothing. It's just that simple. Thorsten From C.Sanders at DeleteThis.Bom.GOV.AU Thu May 26 06:58:35 2011 From: C.Sanders at DeleteThis.Bom.GOV.AU (Charles) Date: Thu, 26 May 2011 20:58:35 +1000 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> "Thorsten Kampe" wrote in message news:MPG.284834d227e3acd1989813 at news.individual.de... > > If someone has learned what a directory or folder is, you don't have to > explain what "include sub-folders" means. Instead of creating a new > mysterious term ("recursively delete"), you simply explain stuff by re- > using an already existing term. It's just that simple. I'm a native english speaker, and to me there is a difference between "delete directory and sub-directories" (or folders and sub-folders if you follow Microsoft's naming conventions) and "recursively delete". I know english is very ambiguous, but to me "directory and sub-directories" does not necessarily imply sub-directories of sub-directories and so on, while "recursively delete" does carry the connotation of deleting the sub-directories of sub-directories and sub-directories of sub-directories of sub-directories and so on. Charles From rosuav at gmail.com Thu May 26 07:12:39 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 21:12:39 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: I just conducted a rapid poll of a non-technical userbase. (Okay, I just asked my sister who happens to be sitting here. But she's nontechnical.) She explained "recursive" as "it repeats until it can't go any further". I think that's a fair, if not perfectly accurate, explanation. Actually... if we accept that one iteration is deleting all files from one depth level, then yes, the algorithm repeats that operation. And I'm using "iteration" here without implying that it's an iterative function. Chris Angelico From thorsten at thorstenkampe.de Thu May 26 07:20:43 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 26 May 2011 13:20:43 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: * Charles (Thu, 26 May 2011 20:58:35 +1000) > "Thorsten Kampe" wrote in message > news:MPG.284834d227e3acd1989813 at news.individual.de... > > > > If someone has learned what a directory or folder is, you don't have > > to explain what "include sub-folders" means. Instead of creating a > > new mysterious term ("recursively delete"), you simply explain stuff > > by re- using an already existing term. It's just that simple. > > I'm a native english speaker, and to me there is a difference between > "delete directory and sub-directories" (or folders and sub-folders if > you follow Microsoft's naming conventions) and "recursively delete". I > know english is very ambiguous, but to me "directory and > sub-directories" does not necessarily imply sub-directories of > sub-directories and so on, Are we playing word games here? You can easily improve my example to "delete directory and all sub-directories beneath". Or "delete directory and all sub-directories beneath and all content". Or "delete directory and all files and directories within". > while "recursively delete" does carry the connotation of deleting the > sub-directories of sub-directories and sub-directories of > sub-directories of sub-directories and so on. Sure. Because you already know what it means (someone has already translated it to you long time ago). Did your mom tell you to "recursively clean up your room"?. Does my file manager ask me "are you sure you want to recursively delete the folder?"? No, it asks 'are you sure you want to remove folder "folder name" and all its contents?'. Thorsten From rosuav at gmail.com Thu May 26 07:28:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 May 2011 21:28:20 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: On Thu, May 26, 2011 at 9:20 PM, Thorsten Kampe wrote: > Did your mom tell you to "recursively clean up your room"?. > Considering that I don't have a wardrobe with a portal to Narnia, no, she has never had to tell me to clean up the room inside my room. Anyway, my room's full. There's no room in it anywhere. :) Chris Angelico From truongxuanquang at yahoo.com Thu May 26 07:48:34 2011 From: truongxuanquang at yahoo.com (truongxuan quang) Date: Thu, 26 May 2011 04:48:34 -0700 (PDT) Subject: Question about isodate Message-ID: <324535.36827.qm@web114716.mail.gq1.yahoo.com> Hello list, I am installing and testing istSOS wrote base on Python with its extension like gdal, isodate, easy istall, setuptool, psycopg. I have already installed all these stuff when I was using method POST the error appear is "No module named mx.DateTime.ISO" , could you please give me your command and advice. Many thanks Quang -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Thu May 26 08:44:47 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 26 May 2011 12:44:47 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> Message-ID: <94709uF99gU5@mid.individual.net> On 2011-05-25, Matty Sarro wrote: > General readability is a farce. If it was true we would only > have one section to the library. Different people enjoy > reading, and can comprehend better in different ways. THat's > why some people are super verbose - hell, just look at this > here post! :) Despite individual proclivities, there remain standards of readability enshrined in our dictionaries and grammar handbooks. Claiming that code readability of code is to be judged solely subjectively by each individual absolves code of the responsibility to communicate to more than just its author. -- Neil Cerutti From roy at panix.com Thu May 26 08:51:48 2011 From: roy at panix.com (Roy Smith) Date: Thu, 26 May 2011 08:51:48 -0400 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> <94709uF99gU5@mid.individual.net> Message-ID: In article <94709uF99gU5 at mid.individual.net>, Neil Cerutti wrote: > On 2011-05-25, Matty Sarro wrote: > > General readability is a farce. If it was true we would only > > have one section to the library. Different people enjoy > > reading, and can comprehend better in different ways. THat's > > why some people are super verbose - hell, just look at this > > here post! :) > > Despite individual proclivities, there remain standards of > readability enshrined in our dictionaries and grammar handbooks. > Claiming that code readability of code is to be judged solely > subjectively by each individual absolves code of the > responsibility to communicate to more than just its author. Also, the purpose of source code is to transmit information (to both the compiler and to human readers). That is a much narrower purpose than is served by books in a library, many of which are written as entertainment. Sometimes, the real enjoyment (in literature) comes in figuring out what the author really meant. From ben+python at benfinney.id.au Thu May 26 09:11:09 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 May 2011 23:11:09 +1000 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> <94709uF99gU5@mid.individual.net> Message-ID: <874o4hbo9e.fsf@benfinney.id.au> Roy Smith writes: > Also, the purpose of source code is to transmit information (to both > the compiler and to human readers). And the relative importance of readability for those two purposes is often misunderstood. Composing source code so that the *machine* will understand it is one thing, and can be unambiguously verified. Composing the same source code so that its meaning will be clearly transmitted to *other humans* is quite another matter: certainly more difficult, and arguably far more important: ?Programs must be written for people to read, and only incidentally for machines to execute.? ?Abelson & Sussman, _Structure and Interpretation of Computer Programs_ > Sometimes, the real enjoyment (in literature) comes in figuring out > what the author really meant. Right. Unlike that kind of writing, in functional code like a computer program, ambiguity of meaning is a curse. Programmers, if you feel the urge to be subtle and clever and nuanced, take up poetry or literature as a separate pursuit. In your program source code, please be as straightforward and unambiguous and predictable as possible. -- \ ?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 Thu May 26 09:35:10 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 May 2011 13:35:10 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <87mxiasid4.fsf@castleamber.com> <94709uF99gU5@mid.individual.net> Message-ID: <4dde570e$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 12:44:47 +0000, Neil Cerutti wrote: > On 2011-05-25, Matty Sarro wrote: >> General readability is a farce. If it was true we would only have one >> section to the library. Different people enjoy reading, and can >> comprehend better in different ways. THat's why some people are super >> verbose - hell, just look at this here post! :) > > Despite individual proclivities, there remain standards of readability > enshrined in our dictionaries and grammar handbooks. Claiming that code > readability of code is to be judged solely subjectively by each > individual absolves code of the responsibility to communicate to more > than just its author. Bravo! +1 Quote of the Thread -- Steven From theller at ctypes.org Thu May 26 11:02:30 2011 From: theller at ctypes.org (Thomas Heller) Date: Thu, 26 May 2011 17:02:30 +0200 Subject: List of WindowsError error codes and meanings In-Reply-To: References: Message-ID: <9478c6Fr09U1@mid.individual.net> Am 20.05.2011 19:56, schrieb Andrew Berg: > This is probably somewhat off-topic, but where would I find a list of > what each error code in WindowsError means? WindowsError is so broad > that it could be difficult to decide what to do in an except clause. > Fortunately, sys.exc_info()[1][0] holds the specific error code, so I > could put in an if...elif...else clause inside the except clause if I > needed to, but I don't know what all the different errors are. On Windows, you can use ctypes.FormatError(code) to map error codes to strings: >>> import ctypes >>> ctypes.FormatError(32) 'Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird.' >>> For HRESULT codes, you (unfortunately) have to subtract 2**32-1 from the error code: >>> ctypes.FormatError(0x80040005) Traceback (most recent call last): File "", line 1, in OverflowError: long int too large to convert to int >>> ctypes.FormatError(0x80040005 - (2**32-1)) 'Kein Cache zum Verarbeiten vorhanden.' >>> Thomas From thegist at nospam.net Thu May 26 11:05:56 2011 From: thegist at nospam.net (thegist at nospam.net) Date: Thu, 26 May 2011 11:05:56 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <4ddd963c$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <72183$4ddd7506$ce534406$5707@news.eurofeeds.com> <4ddd963c$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1ec5d$4dde6c53$ce534406$30768@news.eurofeeds.com> On 5/25/2011 7:52 PM, Steven D'Aprano wrote: > On Wed, 25 May 2011 17:30:48 -0400, thegist at nospam.net wrote: > >> On 5/24/2011 1:39 PM, D'Arcy J.M. Cain wrote: [snip] >>> One of my favorite quotes (not sure if it was about Perl or APL) is "I >>> refuse to use a programming language where the proponents of it stick >>> snippets under each other's nose and say 'I bet you can't guess what >>> this does.'" >> I dunno. That sounds about like how most programming course exams are >> written, no? >> The point is that puzzling through arcane bits of code are crucial to >> learning >> any language. It's a valuable exercise. > > You seem to miss the point that a good language shouldn't make it > possible to write arcane code that needs to be puzzled out. You seem to be inventing a new point. Try to stay focused please. Perl hackers show each other arcane bits of code because such impractical puzzle programs are good for learning. Such puzzles can be created in any language. For example, I have had formal coursework in a number of languages (Pascal, C++, ML, Scheme, and others) and in each one an important exercise was to puzzle through arcane bits of code in each of those languages. The post I was replying to seemed to question the value of such 'I bet you can't guess what this does.' type challenges. From john at castleamber.com Thu May 26 11:36:30 2011 From: john at castleamber.com (John Bokma) Date: Thu, 26 May 2011 10:36:30 -0500 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> Message-ID: <878vttv5hd.fsf@castleamber.com> Ben Finney writes: >> Get a life. Or better, just fuck off and die. It will improve both the >> world and the Python community, of which you are nothing but a little, >> smelly shitstain. > > That abuse is entirely unwelcome in this community, against any person. > Please desist. You should have spoken up sooner, especially as the spokes person of "this" community. But every bully has is fan club. -- John Bokma j3b Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/ Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html From thegist at nospam.net Thu May 26 11:52:36 2011 From: thegist at nospam.net (thegist at nospam.net) Date: Thu, 26 May 2011 11:52:36 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> Message-ID: <8a22e$4dde7742$ce534406$29334@news.eurofeeds.com> So when quora.com fails we can all say it is Python's fault? Maybe they should have focused more on content instead of the bits under the hood? From python at mrabarnett.plus.com Thu May 26 11:58:25 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 May 2011 16:58:25 +0100 Subject: Puzzled by list-appending behavior In-Reply-To: References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: <4DDE78A1.9070305@mrabarnett.plus.com> On 26/05/2011 06:17, Chris Rebert wrote: > On Wed, May 25, 2011 at 9:46 PM, Uncle Ben wrote: >> In playing with lists of lists, I found the following: >> >> (In 3.1, but the same happens also in 2.7) >> >> list = [1,2,3] >> list.append ( [4,5,6] ) > > Note the lack of output after this line. This indicates that > list.append([4,5,6]) returned None. Contrast this with, say, > list.pop(). > >> x = list >> x -> >> [1,2,3,[4,5,6]] >> as expected. >> >> But the shortcut fails: >> >> list=[1,2,3] >> x = list.append( [4,5,6] ) >> x -> >> nothing >> >> Can someone explain this to me? > > The append() method does *not* return the now-appended-to list. It is > a mutator method that modifies the list object in-place; per > convention, it therefore returns None to reinforce its side-effecting > nature to the user (the interactive interpreter by default does not > display None expression results); analogous methods in other languages > return void. > > list.remove(), list.sort(), and list.extend() similarly return None > rather than the now-modified list. > I'd just like to point out that it's a convention, not a rigid rule. Sometimes it's not followed, for example, dict.setdefault. From rosuav at gmail.com Thu May 26 12:04:00 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 02:04:00 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: <4DDE78A1.9070305@mrabarnett.plus.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <4DDE78A1.9070305@mrabarnett.plus.com> Message-ID: On Fri, May 27, 2011 at 1:58 AM, MRAB wrote: > I'd just like to point out that it's a convention, not a rigid rule. > Sometimes it's not followed, for example, dict.setdefault. dict.setdefault is more like dict.get but it also stores the result. It's probably more a name issue than a protocol issue. Chris Angelico From ethan at stoneleaf.us Thu May 26 12:18:12 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 26 May 2011 09:18:12 -0700 Subject: Why did Quora choose Python for its development? In-Reply-To: <874o4i17zi.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> Message-ID: <4DDE7D44.3000409@stoneleaf.us> John, You say English is not your first language. Let me assure you that the words you chose to use in reply to Stephen were vulgar as well as rude, and did more to lesson the overall friendliness of this forum than Stephen's adversarial style. You usually have interesting and informative posts -- please don't resort to this tactic. ~Ethan~ From nagle at animats.com Thu May 26 12:29:54 2011 From: nagle at animats.com (John Nagle) Date: Thu, 26 May 2011 09:29:54 -0700 Subject: Newbie question about SQLite + Python and twitter In-Reply-To: References: Message-ID: <4dde8006$0$2159$742ec2ed@news.sonic.net> On 5/25/2011 6:08 PM, Philip Semanchuk wrote: > > On May 25, 2011, at 2:17 PM, Jayme Proni Filho wrote: > >> Helo guys, >> >> I'm building a local application for twitter for my brother's store. I'm in >> the beginning and I have some newbie problems, so: >> >> I create a table called tb_messages with int auto increment and varchar(140) >> fields; >> I did three SQL funcionts, insert_tweet, delete_tweet, select_tweet >> >> select_tweet is use for getting messages for sending them to twitter; >> >> My problem is: How can i make my select_tweet works at the same time that >> insert or delete funcions. I just got to work when I stop select function. >> >> I would like to do my app works all the time. > > Hi Jayme, > You need to provide a lot more information for us to be able to help you. I suspect that the original poster's problem is that he's trying to delete items from a table while reading the results from a SELECT on the same table. SQL systems don't allow that. It has the same problem as, in Python, deleting from a dict while iterating over it. One way to do this properly is something like loop START TRANSACTION SELECT itemid, item FROM tablename WITH ... LIMIT 1 get one item if no item, break do whatever needs to be done with item DELETE FROM tablename WHERE itemid = %s END TRANSACTION Also, it sounds like he's writing a spam program for Twitter. John Nagle From python at rcn.com Thu May 26 12:31:18 2011 From: python at rcn.com (Raymond Hettinger) Date: Thu, 26 May 2011 09:31:18 -0700 (PDT) Subject: Python's super() considered super! Message-ID: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> I just posted a tutorial and how-to guide for making effective use of super(). One of the reviewers, David Beazley, said, "Wow, that's really great! I see this becoming the definitive post on the subject" The direct link is: http://rhettinger.wordpress.com/2011/05/26/super-considered-super/ It would also be great if some of you would upvote it on HackerNews. Raymond Hettinger ----------------------- follow my python tips on twitter: @raymondh From python at rcn.com Thu May 26 12:39:42 2011 From: python at rcn.com (Raymond Hettinger) Date: Thu, 26 May 2011 09:39:42 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> > It would also be great if some of you would upvote it on HackerNews. Here's a link to the super() how-to-guide and commentary: bit.ly/ iFm8g3 Raymod From alister.ware at ntlworld.com Thu May 26 13:50:41 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Thu, 26 May 2011 17:50:41 GMT Subject: pyGTK identify a button References: <4ddcbb68$0$18241$4fafbaef@reader2.news.tin.it> Message-ID: On Wed, 25 May 2011 10:18:48 +0200, Tracubik wrote: > Hi all, > i'm trying to write a simple windows with two button in GTK, i need a > way to identify wich button is pressed. Consider that: > > the two button are connected (when clicked) to infoButton(self, widget, > data=None) > > infoButton() is something like this > > infoButton(self, widget, data=None): > # discover wich button was pressed > ... > # say hello to the button > if button1pressed: > print "Hi, button1!" > else: > print "Hi, button2!" > > so, how can I know wich button was pressed without using data and > without reading the label of the button (i could have buttons with the > same label) > > If data is needed, can someone pls tell me how to set it properly in > glade 3.8 > > thanks > Nico This looks similar to a question I posted about 2 weeks ago In gtk 2.1.6 (i think) & earlier you could use widget.get_name() to return the id of the widget. this no-longer works since 2.1.7 the pygtk forum suggests this is because widget id's are not necessarily unique & caused problems elsewhere, to be honest most of the explanation went above my head. I did find a work around & that was to use gtk.buildable.get_name(widget) but is is probably cleaner to use a discrete callback for each button. -- Disco is to music what Etch-A-Sketch is to art. From dotancohen at gmail.com Thu May 26 14:13:09 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Thu, 26 May 2011 21:13:09 +0300 Subject: Python's super() considered super! In-Reply-To: <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 19:39, Raymond Hettinger wrote: >> It would also be great if some of you would upvote it on HackerNews. > > > Here's a link to the super() how-to-guide and commentary: ?bit.ly/ > iFm8g3 > Is that the same link as in the OP? I don't click on blind links, so if it isn't then please post a direct link. Thanks. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From ladasky at my-deja.com Thu May 26 14:27:35 2011 From: ladasky at my-deja.com (John Ladasky) Date: Thu, 26 May 2011 11:27:35 -0700 (PDT) Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> On May 25, 9:46?pm, Uncle Ben wrote: > list = [1,2,3] Somewhat unrelated, but... is it a good idea to name your list "list"? Isn't that the name of Python's built-in list constructor method? Shadowing a built-in has contributed to more than one subtle bug in my code, and I've learned to avoid it. From ian.g.kelly at gmail.com Thu May 26 14:38:22 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 26 May 2011 12:38:22 -0600 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 12:13 PM, Dotan Cohen wrote: > On Thu, May 26, 2011 at 19:39, Raymond Hettinger wrote: >>> It would also be great if some of you would upvote it on HackerNews. >> >> >> Here's a link to the super() how-to-guide and commentary: ?bit.ly/ >> iFm8g3 >> > > Is that the same link as in the OP? I don't click on blind links, so > if it isn't then please post a direct link. Thanks. It's a link to ycombinator: http://news.ycombinator.com/item?id=2588262 From tjreedy at udel.edu Thu May 26 14:44:52 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 May 2011 14:44:52 -0400 Subject: Puzzled by list-appending behavior In-Reply-To: <201105261718.36646.akabaila@pcug.org.au> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <201105261718.36646.akabaila@pcug.org.au> Message-ID: On 5/26/2011 3:18 AM, Algis Kabaila wrote: > And why do you insist on calling an instance of list, "list"? Even a > human reader will confuse which is which. What you are showing is an > example how confusing things become when a keyword (list) is > over-written (with list instance). (Minor note: 'list' is not a keyword (if it were, it could not be over-ridden) but it is a builtin.) You are correct, it is confusing. Such usage will also lead to bugs if one ever tries to access the class as 'list' later in the program. Here is a legitimate usage of builtins masking: import builtins def list(iterable): print('building list from {}: {}'.format(type(iterable),iterable)) return builtins.list(iterable) a = list((1,2,3)) b = list({1,2,3}) ### building list from : (1, 2, 3) building list from : {1, 2, 3} -- Terry Jan Reedy From r.richardparker at comcast.net Thu May 26 14:50:25 2011 From: r.richardparker at comcast.net (Richard Parker) Date: Thu, 26 May 2011 11:50:25 -0700 Subject: The worth of comments In-Reply-To: References: Message-ID: <1CCA9F21-28E8-43CF-BBE0-D4080D1E6993@comcast.net> On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: > My experience is that comments in Python are of relatively low > usefulness. (For avoidance of doubt: not *zero* usefulness, merely low.) > I can name variables, functions and classes with sensible, self- > documenting names. Why write: > > x = get_results(arg) # x is a list of 1 or more results > [... much later] > for y in x: > # process each result in turn > do_something_with(y) (It occurred to me that I should use a specific subject for this discussion.) I'm less inclined to use comments on each line, or selected lines, but rather use block comments instead. They require more thought and time to write; however, the intended functionality of the code that follows can be described in full. From dotancohen at gmail.com Thu May 26 14:56:50 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Thu, 26 May 2011 21:56:50 +0300 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 21:38, Ian Kelly wrote: > It's a link to ycombinator: > > http://news.ycombinator.com/item?id=2588262 > Thanks. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From ramit.prasad at jpmchase.com Thu May 26 15:34:01 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Thu, 26 May 2011 15:34:01 -0400 Subject: Puzzled by list-appending behavior In-Reply-To: References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <201105261718.36646.akabaila@pcug.org.au> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B0D00@EMARC112VS01.exchad.jpmchase.net> >> And why do you insist on calling an instance of list, "list"? Even a >> human reader will confuse which is which. What you are showing is an >> example how confusing things become when a keyword (list) is >> over-written (with list instance). > (Minor note: 'list' is not a keyword (if it were, it could not be >over-ridden) but it is a builtin.) You are correct, it is confusing. >Such usage will also lead to bugs if one ever tries to access the >class >as 'list' later in the program. An example of overriding built-ins you *really* do not want to happen (python 2.6.4): >>> True = False >>> True == False True >>> print True False From what I can tell, this does not work in Python 3.x (at least not in Python 3.1.1) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From peterirbizon at gmail.com Thu May 26 15:46:02 2011 From: peterirbizon at gmail.com (miamia) Date: Thu, 26 May 2011 12:46:02 -0700 (PDT) Subject: python urllib2 data post over https Message-ID: <8b67a6e5-7a28-4e2c-af2f-f3ff3ccc4da2@k16g2000yqm.googlegroups.com> hello, I am using this code to send data over https with post method: params='tieto data idu na sevrer\n' kamodoslat = "https://domena.tld/script.php" req = urllib2.Request(kamodoslat) req.add_header('User-Agent', 'agent') resp = urllib2.urlopen(req, params) how can I make sure that data were really sent over secured protocol https and all communcation went through https? From tjreedy at udel.edu Thu May 26 16:03:58 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 May 2011 16:03:58 -0400 Subject: Why did Quora choose Python for its development? In-Reply-To: <878vttv5hd.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> Message-ID: On 5/26/2011 11:36 AM, John Bokma wrote: > Ben Finney writes: >>>> [impolite comment not quoted] >>> Get a life. Or better, just fuck off and die. It will improve both the >>> world and the Python community, of which you are nothing but a little, >>> smelly shitstain. >> >> That abuse is entirely unwelcome in this community, against any person. >> Please desist. > > You should have spoken up sooner, especially as the spokes person of > "this" community. But every bully has is fan club. I agree that the original impolite comment was just that -- impolite -- and perhaps enough so that it should have been spoken out against. But I also agree that the quoted response is at least three times as bad, enough so to understandably push someone to respond. Both comments are atypical here. -- Terry Jan Reedy From tjreedy at udel.edu Thu May 26 16:15:57 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 May 2011 16:15:57 -0400 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <73c71b57-5804-4f07-bd55-81b48bf5aced@q14g2000prh.googlegroups.com> Message-ID: On 5/26/2011 2:13 PM, Dotan Cohen wrote: > On Thu, May 26, 2011 at 19:39, Raymond Hettinger wrote: >>> It would also be great if some of you would upvote it on HackerNews. >> >> >> Here's a link to the super() how-to-guide and commentary: bit.ly/ >> iFm8g3 >> > > Is that the same link as in the OP? I don't click on blind links, so > if it isn't then please post a direct link. Thanks. It is a link to HackerNews http://news.ycombinator.com/item?id=2588262 -- Terry Jan Reedy From karim.liateni at free.fr Thu May 26 16:27:54 2011 From: karim.liateni at free.fr (Karim) Date: Thu, 26 May 2011 22:27:54 +0200 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> Message-ID: <4DDEB7CA.9040601@free.fr> On 05/26/2011 10:03 PM, Terry Reedy wrote: > On 5/26/2011 11:36 AM, John Bokma wrote: >> Ben Finney writes: > > >>>> [impolite comment not quoted] >>>> Get a life. Or better, just fuck off and die. It will improve both the >>>> world and the Python community, of which you are nothing but a little, >>>> smelly shitstain. >>> >>> That abuse is entirely unwelcome in this community, against any person. >>> Please desist. >> >> You should have spoken up sooner, especially as the spokes person of >> "this" community. But every bully has is fan club. > > I agree that the original impolite comment was just that -- impolite > -- and perhaps enough so that it should have been spoken out against. > But I also agree that the quoted response is at least three times as > bad, enough so to understandably push someone to respond. Both > comments are atypical here. > Original one impolite perhaps but only truth could cause such hatred. Cheers From patty at cruzio.com Thu May 26 16:30:10 2011 From: patty at cruzio.com (Patty) Date: Thu, 26 May 2011 13:30:10 -0700 Subject: The worth of comments References: <1CCA9F21-28E8-43CF-BBE0-D4080D1E6993@comcast.net> Message-ID: <763810B8E88E410983404CCEC542FDF0@mycomputer> ----- Original Message ----- From: "Richard Parker" To: Sent: Thursday, May 26, 2011 11:50 AM Subject: The worth of comments > On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: > >> My experience is that comments in Python are of relatively low >> usefulness. (For avoidance of doubt: not *zero* usefulness, merely low.) >> I can name variables, functions and classes with sensible, self- >> documenting names. Why write: >> >> x = get_results(arg) # x is a list of 1 or more results >> [... much later] >> for y in x: >> # process each result in turn >> do_something_with(y) > > (It occurred to me that I should use a specific subject for this > discussion.) > > I'm less inclined to use comments on each line, or selected lines, but > rather use block comments instead. They require more thought and time to > write; however, the intended functionality of the code that follows can be > described in full. > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hello Richard - I was recently complimented in a phone screen interview for including comment blocks exactly as you describe above. Regards, Patty From dan.kluev at gmail.com Thu May 26 17:33:52 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Fri, 27 May 2011 08:33:52 +1100 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: On Wed, May 25, 2011 at 3:10 AM, Octavian Rasnita wrote: >> Once again. Suppose we have array of key-value pairs (two-dimensional >> array), > > This is a forced example to fit the way Python can do it with a clean syntax, but I don't think there are cases in which somebody wants to create hashes/dictionaries where the key is not a plain string but an array. > > This is not a rare case, but a case that probably nobody needs, ever. This is far more popular case than converting flat lists into dicts in Python world. In fact, I *never* had need to convert flat list instead of properly structured one. Thats why we have both lists and tuples, after all. Sure, since perl does not support it at all, perl programmers do not use it and resort to idea of "guess which values are keys by index" due to lack of better approach, with need of obscure "=>" pseudo-syntax to cover it up. -- With best regards, Daniel Kluev From tjreedy at udel.edu Thu May 26 17:36:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 May 2011 17:36:22 -0400 Subject: Puzzled by list-appending behavior In-Reply-To: <4DDE78A1.9070305@mrabarnett.plus.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <4DDE78A1.9070305@mrabarnett.plus.com> Message-ID: On 5/26/2011 11:58 AM, MRAB wrote: > On 26/05/2011 06:17, Chris Rebert wrote: >> list.remove(), list.sort(), and list.extend() similarly return None >> rather than the now-modified list. > I'd just like to point out that it's a convention, not a rigid rule. > Sometimes it's not followed, for example, dict.setdefault. The rule for builtin collections is that mutation methods do not return the collection. If there is a member of the collection to return, they return that. Otherwise they return None. list/set.pop and dict.popitem are other mutation methods that have a (former) member to return. The rule applies to special methods like __getitem__ (returns an item) and __setitem__ (returns None). Since a.append(item) is *conceptually* equivalent to a.__setitem(len(a), item) (I know, it raises) and *actually* defined as a.__setitem(len(a):len(a), item), it should not be surprising that all three return None. I think the above should be better documented. http://bugs.python.org/issue12192 has some proposals. Comments there welcome. In another post On 5/26/2011 4:09 AM, Chris Rebert wrote: > I'm just surprised that the docstring doesn't explicitly state > "Returns None." by this point, given that this is such a common point > of newbie confusion. I never noticed. After reading the above, I added this to the proposal above. -- Terry Jan Reedy From salmig99 at gmail.com Thu May 26 17:50:32 2011 From: salmig99 at gmail.com (sal migondis) Date: Thu, 26 May 2011 17:50:32 -0400 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: Message-ID: On Thu, May 26, 2011 at 12:28 PM, sal migondis wrote: > From: Thorsten Kampe > Subject: Re: English Idiom in Unix: Directory Recursively > Date: Thu, 26 May 2011 12:46:58 +0200 > To: python-list at python.org > > * Steven D'Aprano (26 May 2011 10:06:44 GMT) >> >> On Thu, 26 May 2011 10:48:07 +0200, Thorsten Kampe wrote: >> >> > But not to digress, the /real/ problem with commands or idioms like "rm >> > -r" is /not/ their choice of option names but that they explain these >> > options in the exact same terms. No one would have a problem with "-r, >> > --recursive -- remove directories including all sub-directories" instead >> > of "-r, --recursive -- remove directories and their contents >> > recursively". >> >> I think you are understanding the description "remove directories and >> their contents recursively" as a description of the *mechanism* by which >> rm removes the directory, i.e. some recursive tree-walking function that >> visits each node and deletes it. >> >> I don't believe that's how the description is meant to be understood. I >> understand it as describing the effect, not the implementation. > It doesn't matter how I interprete the explanation "-r = recursively > delete". [..] Quite the contrary.. and that's the whole issue: your superficial knowledge of the English language.. :-) >> You're interpreting the reference to "recursive" as a nod to the >> implementation. I'm not, and therefore your arguments don't convince >> me. > > No one understands what "recursively delete" means ... _We_ do.. :-) > until someone explains ("translates") it to him. This is not an argument > but a simple fact. I experienced it many times, others here in the thread > did and probably you, too. > > "recursively delete" is completely unneccessary because there is already > a simple explanation that everyone understands without translation > ("delete including subdirectories"). .. which is very poor 'style' indeed. Style is not a matter of aesthetics. It's all about clarity and expressiveness. It's about effectively communicating your thoughts to your audience. When I hear or read 'delete recursively', I immediately 'get the idea' and I can move on.. Now, if I heard 'delete including subdirectories', my first reaction would be.. ouch, I bet that hurts.. or ugh.. how ugly.. See, I'm distracted already. But it doesn't stop there.. After the initial jolt to my attention, I'd start thinking along the lines of.. hm. subdirectories.. now what about sub sub directories.. etc. not seriously, perhaps.. but by the time I got over it and was able to focus again on what was being said (or what I was reading) I would have lost the thread. This is why the author of the document puts paid to all the nonsense and instinctively uses 'recursively delete', not going into irrelevant details. It's that simple. > It's unnecessary bullshit buzzword bingo from nerds which adds or helps > or explains nothing. It's just that simple. This has nothing to do with buzzwords whatsoever. Despite polite hints from several other posters, the problem is that (like the OP) you are not a native speaker of English but you will not listen and still think you are qualified to make recommendations regarding usage and abusage in the English language. Sorry pal, but right here, you are like the kellet teaching the fishes to swim. Sal. From xahlee at gmail.com Thu May 26 17:51:37 2011 From: xahlee at gmail.com (Xah Lee) Date: Thu, 26 May 2011 14:51:37 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: <7f349c74-6435-40bc-b243-caf789f6a1cc@k3g2000prl.googlegroups.com> On May 26, 4:20 am, Thorsten Kampe wrote: > Did your mom tell you to "recursively clean up your room"?. that had me L O L! i think i'll quote in my unix hating blogs sometimes, if you don't mind. ? Xah From ethan at stoneleaf.us Thu May 26 19:27:04 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 26 May 2011 16:27:04 -0700 Subject: bug in str.startswith() and str.endswith() Message-ID: <4DDEE1C8.6010107@stoneleaf.us> I've tried this in 2.5 - 3.2: --> 'this is a test'.startswith('this') True --> 'this is a test'.startswith('this', None, None) Traceback (most recent call last): File "", line 1, in TypeError: slice indices must be integers or None or have an __index__ method The 3.2 docs say this: str.startswith(prefix[, start[, end]]) Return True if string starts with the prefix, otherwise return False. prefix can also be a tuple of prefixes to look for. With optional start, test string beginning at that position. With optional end, stop comparing string at that position str.endswith(suffix[, start[, end]]) Return True if the string ends with the specified suffix, otherwise return False. suffix can also be a tuple of suffixes to look for. With optional start, test beginning at that position. With optional end, stop comparing at that position. Any reason this is not a bug? ~Ethan~ From python at mrabarnett.plus.com Thu May 26 19:27:22 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 27 May 2011 00:27:22 +0100 Subject: bug in str.startswith() and str.endswith() In-Reply-To: <4DDEE1C8.6010107@stoneleaf.us> References: <4DDEE1C8.6010107@stoneleaf.us> Message-ID: <4DDEE1DA.1030602@mrabarnett.plus.com> On 27/05/2011 00:27, Ethan Furman wrote: > I've tried this in 2.5 - 3.2: > > --> 'this is a test'.startswith('this') > True > --> 'this is a test'.startswith('this', None, None) > Traceback (most recent call last): > File "", line 1, in > TypeError: slice indices must be integers or None or have an __index__ > method > > The 3.2 docs say this: > > str.startswith(prefix[, start[, end]]) > Return True if string starts with the prefix, otherwise return False. > prefix can also be a tuple of prefixes to look for. With optional start, > test string beginning at that position. With optional end, stop > comparing string at that position > > str.endswith(suffix[, start[, end]]) > Return True if the string ends with the specified suffix, otherwise > return False. suffix can also be a tuple of suffixes to look for. With > optional start, test beginning at that position. With optional end, stop > comparing at that position. > > Any reason this is not a bug? > Let's see: 'start' and 'end' are optional, but aren't keyword arguments, and can't be None... I'd say bug. From thorsten at thorstenkampe.de Thu May 26 19:30:59 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Fri, 27 May 2011 01:30:59 +0200 Subject: English Idiom in Unix: Directory Recursively References: Message-ID: * sal migondis (Thu, 26 May 2011 17:50:32 -0400) > On Thu, May 26, 2011 at 12:28 PM, sal migondis > wrote: > > From: Thorsten Kampe > > It's unnecessary bullshit buzzword bingo from nerds which adds or > > helps or explains nothing. It's just that simple. > > This has nothing to do with buzzwords whatsoever. > > Despite polite hints from several other posters, the problem is that (like > the OP) you are not a native speaker of English but you will not listen and > still think you are qualified to make recommendations regarding usage and > abusage in the English language. *sigh* there is nothing in "recursively delete" which would be specific to English. It would be the same in French, Spanish, Italian or German ("rekursiv l?schen"). Thorsten From andrei.avk at gmail.com Thu May 26 19:41:50 2011 From: andrei.avk at gmail.com (RainyDay) Date: Thu, 26 May 2011 16:41:50 -0700 (PDT) Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <57C0AB91B42743E89456ACCC8751CF78@octavian> <2C6966D5AB6541E3BCE920FE7883A05B@octavian> Message-ID: <49c04cf9-88a6-4ed8-af10-64bd4e372e40@gc3g2000vbb.googlegroups.com> On May 26, 5:33?pm, Daniel Kluev wrote: > On Wed, May 25, 2011 at 3:10 AM, Octavian Rasnita wrote: > >> Once again. Suppose we have array of key-value pairs (two-dimensional > >> array), > > > This is a forced example to fit the way Python can do it with a clean syntax, but I don't think there are cases in which somebody wants to create hashes/dictionaries where the key is not a plain string but an array. > > > This is not a rare case, but a case that probably nobody needs, ever. > > This is far more popular case than converting flat lists into dicts in > Python world. In fact, I *never* had need to convert flat list instead > of properly structured one. Thats why we have both lists and tuples, > after all. I agree that it's almost never needed to convert flat lists. I've used python for over 10 years and I remember exactly one time when I needed to do that. It turned out that it's a bit tricky and hacky to do in python, in the sense that it's hard to remember if I'll ever need it again, but it will only take minutes to google it. For example, in one piece of code I did recently I created a dict of range tuples and counts from a sequential list, like so: ranges = [(x*width, (x+1)*width) for x in range(y)] data = dict((x,0) for x in ranges) A perl programmer would instead create a flat list and then convert it to dict. And if he were new to python he'd create a flat list and then be annoyed that there's no quick and easy way to make it into a dict. Python way in this case is more structured and disciplined, and the only "flaw" I can see is that it doesn't meet expectations of perl programmers. -Rainy From rosuav at gmail.com Thu May 26 20:55:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 10:55:38 +1000 Subject: Link errors embedding Python 3.2 In-Reply-To: References: Message-ID: Still trying to sort this out, trying various things. If I configure --enable-shared, I get a different ImportError: 'libpython3.3m.so.1.0: cannot open shared object file: No such file or directory'. That file exists in ~/cpython, but sudo make install doesn't put it anywhere else. Pointing LD_LIBRARY_PATH to there causes my program to segfault with thread context errors. Am I asking this in the wrong forum? Would it be more appropriate in python-dev? Chris Angelico From pavlovevidence at gmail.com Thu May 26 20:59:07 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 26 May 2011 17:59:07 -0700 (PDT) Subject: bug in str.startswith() and str.endswith() In-Reply-To: Message-ID: On Thursday, May 26, 2011 4:27:22 PM UTC-7, MRAB wrote: > On 27/05/2011 00:27, Ethan Furman wrote: > > I've tried this in 2.5 - 3.2: > > > > --> 'this is a test'.startswith('this') > > True > > --> 'this is a test'.startswith('this', None, None) > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: slice indices must be integers or None or have an __index__ > > method > > > > The 3.2 docs say this: > > > > str.startswith(prefix[, start[, end]]) > > Return True if string starts with the prefix, otherwise return False. > > prefix can also be a tuple of prefixes to look for. With optional start, > > test string beginning at that position. With optional end, stop > > comparing string at that position > > > > str.endswith(suffix[, start[, end]]) > > Return True if the string ends with the specified suffix, otherwise > > return False. suffix can also be a tuple of suffixes to look for. With > > optional start, test beginning at that position. With optional end, stop > > comparing at that position. > > > > Any reason this is not a bug? > > > Let's see: 'start' and 'end' are optional, but aren't keyword > arguments, and can't be None... > > I'd say bug. I also say bug. The end parameter looks pretty useless for .startswith() and is probably only present for consistency with other string search methods like .index(). Yet on .index() using None as an argument works as intended: >>> "cbcd".index("c",None,None) 0 So it's there for consistency, yet is not consistent. Carl Banks From pavlovevidence at gmail.com Thu May 26 20:59:07 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 26 May 2011 17:59:07 -0700 (PDT) Subject: bug in str.startswith() and str.endswith() In-Reply-To: Message-ID: On Thursday, May 26, 2011 4:27:22 PM UTC-7, MRAB wrote: > On 27/05/2011 00:27, Ethan Furman wrote: > > I've tried this in 2.5 - 3.2: > > > > --> 'this is a test'.startswith('this') > > True > > --> 'this is a test'.startswith('this', None, None) > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: slice indices must be integers or None or have an __index__ > > method > > > > The 3.2 docs say this: > > > > str.startswith(prefix[, start[, end]]) > > Return True if string starts with the prefix, otherwise return False. > > prefix can also be a tuple of prefixes to look for. With optional start, > > test string beginning at that position. With optional end, stop > > comparing string at that position > > > > str.endswith(suffix[, start[, end]]) > > Return True if the string ends with the specified suffix, otherwise > > return False. suffix can also be a tuple of suffixes to look for. With > > optional start, test beginning at that position. With optional end, stop > > comparing at that position. > > > > Any reason this is not a bug? > > > Let's see: 'start' and 'end' are optional, but aren't keyword > arguments, and can't be None... > > I'd say bug. I also say bug. The end parameter looks pretty useless for .startswith() and is probably only present for consistency with other string search methods like .index(). Yet on .index() using None as an argument works as intended: >>> "cbcd".index("c",None,None) 0 So it's there for consistency, yet is not consistent. Carl Banks From mwilson at the-wire.com Thu May 26 21:07:12 2011 From: mwilson at the-wire.com (Mel) Date: Thu, 26 May 2011 21:07:12 -0400 Subject: bug in str.startswith() and str.endswith() References: Message-ID: Ethan Furman wrote: > I've tried this in 2.5 - 3.2: > > --> 'this is a test'.startswith('this') > True > --> 'this is a test'.startswith('this', None, None) > Traceback (most recent call last): > File "", line 1, in > TypeError: slice indices must be integers or None or have an __index__ > method > > The 3.2 docs say this: > > str.startswith(prefix[, start[, end]]) > Return True if string starts with the prefix, otherwise return False. > prefix can also be a tuple of prefixes to look for. With optional start, > test string beginning at that position. With optional end, stop > comparing string at that position > > str.endswith(suffix[, start[, end]]) > Return True if the string ends with the specified suffix, otherwise > return False. suffix can also be a tuple of suffixes to look for. With > optional start, test beginning at that position. With optional end, stop > comparing at that position. > > Any reason this is not a bug? It's a wart at the very least. The same thing happened in Python2 with range and xrange; there seemed no way to explicitly pass "default" arguments. Mel. From roy at panix.com Thu May 26 21:13:11 2011 From: roy at panix.com (Roy Smith) Date: Thu, 26 May 2011 21:13:11 -0400 Subject: bug in str.startswith() and str.endswith() References: Message-ID: In article , Ethan Furman wrote: > --> 'this is a test'.startswith('this') > True > --> 'this is a test'.startswith('this', None, None) > Traceback (most recent call last): > File "", line 1, in > TypeError: slice indices must be integers or None or have an __index__ > method [...] > Any reason this is not a bug? +1 for it being a bug. From ben+python at benfinney.id.au Thu May 26 21:39:33 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 May 2011 11:39:33 +1000 Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: <87wrhcapm2.fsf@benfinney.id.au> Raymond Hettinger writes: > I just posted a tutorial and how-to guide for making effective use of > super(). Thanks very much! We need articles like this. Raymond Hettinger writes: > Here's a link to the super() how-to-guide and commentary: bit.ly/ > iFm8g3 We also, though, need *real* URLs. Blind URLs through obfuscation services have their uses, but surely not in a forum like this. The real URL is . -- \ ?? it's best to confuse only one issue at a time.? ?Brian W. | `\ Kernighan and Dennis M. Ritchie, _The C programming language_, | _o__) 1988 | Ben Finney From ben+python at benfinney.id.au Thu May 26 21:42:54 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 May 2011 11:42:54 +1000 Subject: The worth of comments References: Message-ID: <87sjs0apgh.fsf@benfinney.id.au> Richard Parker writes: > On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: > > > My experience is that comments in Python are of relatively low > > usefulness. (For avoidance of doubt: not *zero* usefulness, merely > > low.) I can name variables, functions and classes with sensible, > > self- documenting names. I am largely in agreement with this position (including the ?not *zero* usefulness? caveat). > I'm less inclined to use comments on each line, or selected lines, but > rather use block comments instead. They require more thought and time > to write; however, the intended functionality of the code that follows > can be described in full. This I disagree with. If a section of code is interesting enough to deserve an explanation, then it is better to capture it in a helpfully-named function with its doc string having the explanation. -- \ ?If this is your first visit to the USSR, you are welcome to | `\ it.? ?hotel room, Moscow | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Thu May 26 21:59:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 01:59:32 GMT Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> Message-ID: <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 11:27:35 -0700, John Ladasky wrote: > On May 25, 9:46?pm, Uncle Ben wrote: > >> list = [1,2,3] > > Somewhat unrelated, but... is it a good idea to name your list "list"? > Isn't that the name of Python's built-in list constructor method? > > Shadowing a built-in has contributed to more than one subtle bug in my > code, and I've learned to avoid it. Agreed. However, there are good reasons for sometimes shadowing built- ins, and namespaces make it safe to do so if you are sufficiently careful. E.g. I have a module stats.sum() which shadows the built-in, but only in that module, which is exactly the behaviour I want. (If you do "from stats import sum", then you're responsible for whatever happens next.) Or you might isolate the shadow to a function small enough that you can be sure that it won't cause any problems, e.g.: def get(list, object): """Append object to a copy of list and return it.""" return list + [object] For one or two line functions, I think that's perfectly reasonable. Anything more than that, I'd be getting nervous. -- Steven From roy at panix.com Thu May 26 22:08:25 2011 From: roy at panix.com (Roy Smith) Date: Thu, 26 May 2011 22:08:25 -0400 Subject: The worth of comments References: Message-ID: In article , Richard Parker wrote: > On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: > > > My experience is that comments in Python are of relatively low > > usefulness. (For avoidance of doubt: not *zero* usefulness, merely low.) > > I can name variables, functions and classes with sensible, self- > > documenting names. Why write: > > > > x = get_results(arg) # x is a list of 1 or more results > > [... much later] > > for y in x: > > # process each result in turn > > do_something_with(y) > > (It occurred to me that I should use a specific subject for this discussion.) > > I'm less inclined to use comments on each line, or selected lines, but rather > use block comments instead. They require more thought and time to write; > however, the intended functionality of the code that follows can be described > in full. Over the years, my use of comments has evolved. I was taught, "You should comment your code". Eventually, I came to realize that the real mandate is, "You should make it easy to understand your code". Comments are just one possible tool to help achieve that goal. Some things that help code be understandable are: * Using good data structures * Using good algorithms * Breaking the code up into manageable pieces (i.e. functions, classes, methods), each of which encapsulates a single concept * Using descriptive names for variables (and functions, classes, methods, etc) All of those fall under the "self-documenting code" umbrella. But, while those things help, I find it's almost always a good idea to document interfaces, i.e. functions. What the arguments are (not just their types, but valid value ranges, and what they mean). What the function returns. What error conditions are possible. And, in general, what the dang thing does. In other words, enough information to use (and test) the function to its fullest extent without ever having to look at the source code. This stuff tends to go in a big block comment at the beginning of the function. Now, what makes Python interesting in this regard is that the big block comment becomes a doc string. You write exactly the same stuff, except now things like help() can get at it, and things like doctest can do even more interesting things with it (I don't actually use doctest, but I do appreciate its coolness). Comments scattered throughout the code tend to be warnings about tricky stuff, references to classic algorithms, references to ticket tracking systems, and the like. Sometimes it's an explanation of what the next bunch of lines of code are doing, although if you've got a lot of those, that's a hint that maybe you need to be refactoring instead. Sometimes I'll drop in suggestions to future maintainers like, "consider refactoring with with perform_frobnitz_action()", or even, "Don't change this without first talking to Fred!" From nad at acm.org Thu May 26 22:45:34 2011 From: nad at acm.org (Ned Deily) Date: Thu, 26 May 2011 19:45:34 -0700 Subject: Link errors embedding Python 3.2 References: Message-ID: In article , Chris Angelico wrote: > Still trying to sort this out, trying various things. If I configure > --enable-shared, I get a different ImportError: 'libpython3.3m.so.1.0: > cannot open shared object file: No such file or directory'. That file > exists in ~/cpython, but sudo make install doesn't put it anywhere > else. Pointing LD_LIBRARY_PATH to there causes my program to segfault > with thread context errors. > > Am I asking this in the wrong forum? Would it be more appropriate in > python-dev? The discussion in http://bugs.python.org/issue4434 might be of some help. -- Ned Deily, nad at acm.org From tjreedy at udel.edu Thu May 26 23:00:32 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 May 2011 23:00:32 -0400 Subject: bug in str.startswith() and str.endswith() In-Reply-To: <4DDEE1C8.6010107@stoneleaf.us> References: <4DDEE1C8.6010107@stoneleaf.us> Message-ID: On 5/26/2011 7:27 PM, Ethan Furman wrote: > I've tried this in 2.5 - 3.2: > > --> 'this is a test'.startswith('this') > True > --> 'this is a test'.startswith('this', None, None) > Traceback (most recent call last): > File "", line 1, in > TypeError: slice indices must be integers or None or have an __index__ > method > > The 3.2 docs say this: > > str.startswith(prefix[, start[, end]]) > Return True if string starts with the prefix, otherwise return False. > prefix can also be a tuple of prefixes to look for. With optional start, > test string beginning at that position. With optional end, stop > comparing string at that position To me, that says pretty clearly that start and end have to be 'positions', ie, ints or other index types. So I would say that the error message is a bug. I see so reason why one would want to use None rather that 0 for start or None rather than nothing for end. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu May 26 23:07:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 03:07:30 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> Message-ID: <4ddf1571$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 16:03:58 -0400, Terry Reedy wrote: > On 5/26/2011 11:36 AM, John Bokma wrote: >> Ben Finney writes: > > >>>> [impolite comment not quoted] >>>> Get a life. Or better, just fuck off and die. It will improve both >>>> the world and the Python community, of which you are nothing but a >>>> little, smelly shitstain. >>> >>> That abuse is entirely unwelcome in this community, against any >>> person. Please desist. >> >> You should have spoken up sooner, especially as the spokes person of >> "this" community. But every bully has is fan club. > > I agree that the original impolite comment was just that -- impolite -- > and perhaps enough so that it should have been spoken out against. Okay, I've stayed silent while people criticize me long enough. What exactly did I say that was impolite? Is this one of those things where it is "impolite" to say certain things in public even though in private everyone knows they are true? We all know that some people have adversarial views of all sorts of things, including computer languages. "My language of choice is better than your language of choice". Most of us can probably name examples, or if not, it wouldn't take much effort on Google to find them. If we're honest to ourselves, we'd realise that we're all at least a *little bit* adversarial. XKCD's famous cartoon about "People are WRONG on the Internet!" is funny because we can so often relate to it. We really do think some languages are better than others, in objective ways as well as subjective, and want to "support our language". That's partly why we're here, to give back to the language that we enjoy using. We're just more nuanced about our opinion than the trolls. And we also know that people keep going back to their language of choice for all sorts of reasons that aren't objective. Why do I keep going back to Pascal instead of C? I'll give you all sorts of objective reasons why I think Pascal is a better designed language, but the real reason is because it makes me comfortable. It was the first language I learned. Objectively, I should just drop it and move on, but I'm going to keep tilting at those windmills hoping to turn the tide of popular opinion and see a mass migration of C coders to Pascal... *cough* John threw down a distinct challenge: if Python is really so much better than Python [sic] readability wise, why do I have such a hard time dropping Perl and moving on? Am I really the only one who can hear the "oh yeah smart guy" at the start of that sentence? If this is one of those lines you're not allowed to cross, where everybody knows that people invest self-image in their job or choice of language ("dammit, I'm a *Python coder*, I'd never stoop to writing COBOL!" sort of thing) but you mustn't mention it because that would be impolite, well, screw that for a game of soldiers. Sometimes politeness is the grease that keeps society's wheels turning, and sometimes it's just blinkers that stops us from understanding ourselves and others. If I got it wrong about John, oh well, I said it was a guess, and trying to get inside someone else's head is always a chancy business. But the fact that he responded so aggressively instead of saying "Ha, Freudian projection, much?" hints that maybe I hit a button. Or maybe I just ran into him on a bad day. Projection? Yes, I cheerfully admit it. *My* self-image is partly "I am a Python coder", not an enterprise Java suit or a VB code monkey. It's more complicated than that, of course, but let's remember also that the Perl community is *full* of people who self-identify as "Just Another Perl Hacker". John, I'd apologise if I thought I said something rude or nasty to you, but I don't, so I don't believe I have anything to apologise for. But I will say that I regret that you took it as an attack, and assure you that it was not meant that way. -- Steven From rosuav at gmail.com Thu May 26 23:24:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 13:24:24 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 27, 2011 at 11:59 AM, Steven D'Aprano wrote: > def get(list, object): > ? ?"""Append object to a copy of list and return it.""" > ? ?return list + [object] > > For one or two line functions, I think that's perfectly reasonable. > Anything more than that, I'd be getting nervous. But even for something that short, why do it? Why not call the parameter 'lst' or something? Shadowing with something completely different is seldom going to give major advantage, and has the potential to be quite confusing. Chris Angelico From steve+comp.lang.python at pearwood.info Thu May 26 23:27:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 03:27:56 GMT Subject: bug in str.startswith() and str.endswith() References: <4DDEE1C8.6010107@stoneleaf.us> Message-ID: <4ddf1a3c$0$29996$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 May 2011 23:00:32 -0400, Terry Reedy wrote: [...] > To me, that says pretty clearly that start and end have to be > 'positions', ie, ints or other index types. So I would say that the > error message is a bug. I see so reason why one would want to use None > rather that 0 for start or None rather than nothing for end. def my_string_function(source, x, y, z, start, end): if source.startswith(x+y+z, start, end): ... I want sensible defaults for start and end. What should I set them to? def my_string_function(source, x, y, z, start=0, end=None): if end is None: flag = source.startswith(x+y+z, start) else: flag = source.startswith(x+y+z, start, end) if flag: ... Yuck. Perhaps a better alternative is: def my_string_function(source, x, y, z, start=0, end=None): t = (start,) if end is None else (start, end) if source.startswith(x+y+z, *t): ... but that's still pretty icky. -- Steven From greg.ewing at canterbury.ac.nz Thu May 26 23:48:36 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 27 May 2011 15:48:36 +1200 Subject: Why did Quora choose Python for its development? In-Reply-To: <87sjs4t12l.fsf@castleamber.com> References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <87sjs4t12l.fsf@castleamber.com> Message-ID: <948l8nF33pU1@mid.individual.net> John Bokma wrote: > A Perl programmer will call this line noise: > > double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", > re.IGNORECASE) > for match in double_word_re.finditer(text): > print ("{0} is duplicated".format(match.group("word")) Actually, Python programmers would tend to call the RE part of that line noise, too. It's for that reason that we tend to avoid using REs when possible, reaching for them only as a tool of last resort. -- Greg From steve+comp.lang.python at pearwood.info Thu May 26 23:52:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 03:52:35 GMT Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ddf2003$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 13:24:24 +1000, Chris Angelico wrote: > On Fri, May 27, 2011 at 11:59 AM, Steven D'Aprano > wrote: >> def get(list, object): >> ? ?"""Append object to a copy of list and return it.""" return list + >> ? ?[object] >> >> For one or two line functions, I think that's perfectly reasonable. >> Anything more than that, I'd be getting nervous. > > But even for something that short, why do it? Why not call the parameter > 'lst' or something? Shadowing with something completely different is > seldom going to give major advantage, and has the potential to be quite > confusing. Because "lst" is not a real word. To native readers of languages derived from Latin or Germany, such as English, it is quite a strange "word" because it has no vowel. In addition, it looks like 1st (first). We use naming conventions like my_list list_ lst alist etc. to avoid shadowing the built-in list, not because they are good to use in and of themselves. (E.g. we don't write "my_tree" because there's no "tree" to shadow.) All of these are ugly to some extent, which is to say, they cause some small, or not so small, additional cognitive load to the reader. We don't use the name "list_" because we like trailing underscores! We do it because it avoids the cost of shadowing a built-in. But in a small function, there's no real cost to shadowing, so why bother? Any hypothetical confusion caused is no greater than, and probably less than, the increased difficulty in reading any of the alternatives. Either way, we're talking micro-optimizations in readability here. Don't get hung up over the choice of a name. If you'd rather never shadow, I'm fine with that too. I just think "never shadow" is unnecessarily strict. Sometimes shadowing is harmless, and sometimes it's useful. If you're writing a tutorial for beginners, shadowing a built-in without explanation will cause confusion, but for production code, I think it reasonable to assume the reader knows Python well enough not to stumble over that choice. -- Steven From rosuav at gmail.com Fri May 27 00:10:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 14:10:24 +1000 Subject: Puzzled by list-appending behavior In-Reply-To: <4ddf2003$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddf2003$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 27, 2011 at 1:52 PM, Steven D'Aprano wrote: > Because "lst" is not a real word. To native readers of languages derived > from Latin or Germany, such as English, it is quite a strange "word" > because it has no vowel. In addition, it looks like 1st (first). Contrived examples are always awkward; in real examples, there's often an alternative based on the list's purpose, which can then be used to offer a name. > Sometimes shadowing is harmless, and sometimes it's useful. Agreed on both those halves; and obviously, the times where it's useful are very much important. I have to say, I do like Python's lack of keywords for these things; the ability to shadow is a flexibility that means that, for the most part, new builtins can be added to the language without breaking existing code. ChrisA From stefan_ml at behnel.de Fri May 27 00:47:46 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 27 May 2011 06:47:46 +0200 Subject: bug in str.startswith() and str.endswith() In-Reply-To: References: Message-ID: Roy Smith, 27.05.2011 03:13: > Ethan Furman wrote: > >> --> 'this is a test'.startswith('this') >> True >> --> 'this is a test'.startswith('this', None, None) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: slice indices must be integers or None or have an __index__ >> method > [...] >> Any reason this is not a bug? > > +1 for it being a bug. Meaning that the right thing to do at this point is to file a bug report. Stefan From rosuav at gmail.com Fri May 27 01:13:15 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 15:13:15 +1000 Subject: The worth of comments In-Reply-To: References: Message-ID: On Fri, May 27, 2011 at 12:08 PM, Roy Smith wrote: > ?Sometimes > I'll drop in suggestions to future maintainers like, "consider > refactoring with with perform_frobnitz_action()" Usually, I address future-me with comments like that (on the assumption that there's nobody in the world sadistic enough to want to maintain my code). But I never name future-me, the comments will be addressed to "the subsequent maintainer" or somesuch. I do assume, though, that future-me has forgotten everything about the code, and since past-me left some comments that current-me has read, I think the assumption is fairly accurate. (Did I *really* write that code? It has my name on it.....) Chris Angelico From timr at probo.com Fri May 27 02:34:06 2011 From: timr at probo.com (Tim Roberts) Date: Thu, 26 May 2011 23:34:06 -0700 Subject: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> Message-ID: <4dhut6lr8aqtfrk6oljr9lmofra6l5rp53@4ax.com> MRAB wrote: > >I'd just like to point out that it's a convention, not a rigid rule. Reminds me of the catch-phrase from the first Pirates of the Caribbean movie: "It's more of a guideline than a rule." -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri May 27 03:02:23 2011 From: timr at probo.com (Tim Roberts) Date: Fri, 27 May 2011 00:02:23 -0700 Subject: The worth of comments References: Message-ID: Roy Smith wrote: > >Over the years, my use of comments has evolved. I was taught, "You >should comment your code". Eventually, I came to realize that the real >mandate is, "You should make it easy to understand your code". Comments >are just one possible tool to help achieve that goal. Absolutely correct. In my view, this is one of the strongest attributes of Python -- its syntax is such that much of the code can be read out loud like prose. That's a HUGE benefit. Code is read a lot more often than it is written. Ruby has a lot of followers, and I am trying to get excited about it, but it has succumbed to the same special-characters-as-syntax disease that killed Perl. Much Ruby code is just unreadable. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rosuav at gmail.com Fri May 27 03:14:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 May 2011 17:14:34 +1000 Subject: Link errors embedding Python 3.2 In-Reply-To: References: Message-ID: On Fri, May 27, 2011 at 12:45 PM, Ned Deily wrote: > > The discussion in http://bugs.python.org/issue4434 might be of some help. Thanks Ned! That was most helpful. I'm still not sure exactly what I changed, but between building with --enable-shared and some fiddling with how I link my program, I've managed to get it all to work. Now to start clean on a different box and try to deploy it... if I can do that, then it's definitely working. Chris Angelico From python at rcn.com Fri May 27 03:16:58 2011 From: python at rcn.com (Raymond Hettinger) Date: Fri, 27 May 2011 00:16:58 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> Message-ID: <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> On May 26, 6:39?pm, Ben Finney wrote: > We also, though, need *real* URLs. Blind URLs through obfuscation > services have their uses, but surely not in a forum like this. The real > URL is . Fair enough. I had copied the link from Jesse's tweet (where shorter is better). Hope you enjoyed the post. Raymond From thorsten at thorstenkampe.de Fri May 27 04:10:55 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Fri, 27 May 2011 10:10:55 +0200 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> <4ddf1571$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Steven D'Aprano (27 May 2011 03:07:30 GMT) > Okay, I've stayed silent while people criticize me long enough. What > exactly did I say that was impolite? Nothing. > John threw down a distinct challenge: > > if Python is really so much better than Python [sic] > readability wise, why do I have such a hard time dropping > Perl and moving on? > [...] > If I got it wrong about John, oh well, I said it was a guess, and > trying to get inside someone else's head is always a chancy business. Why were you trying to speculate in response to such a - sorry - dumb[1] question? What do his personal failures to switch to Python (why did he even try?) have to do with whether a) Python is more readable than Perl and b) whether readability counts towards productivity? /Maybe/ it is simply because he "somehow like[s] Perl more" but definitely that is not really relevant to the question about readibility. > Or maybe I just ran into him on a bad day. "Bad argument day". His other "Python vs Perl is like Latin vs Devanagari" argument is not really better. The problem with Perl is that it does /not/ use (Latin) alphabetic characters (like a, b, c) to form words but symbols ($, %, @. |, *) and re-combines them to give them new and special meaning. So this is exactly /not/ a alphabet vs alphabet thing but a word(s) vs symbols. Thorsten [1] Sorry for being impolite. But "why do I...?" kind of rhetorical questions (as arguments) are just dumb. From ben+python at benfinney.id.au Fri May 27 04:49:52 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 May 2011 18:49:52 +1000 Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> Message-ID: <87boyoa5ov.fsf@benfinney.id.au> Raymond Hettinger writes: > Hope you enjoyed the post. I certainly did. But I'm not better enlightened on why ?super? is a good thing. The exquisite care that you describe programmers needing to maintain is IMO just as much a deterrent as the super-is-harmful essay. -- \ ?If you continue running Windows, your system may become | `\ unstable.? ?Microsoft, Windows 95 bluescreen error message | _o__) | Ben Finney From michele.simionato at gmail.com Fri May 27 05:15:35 2011 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 27 May 2011 02:15:35 -0700 (PDT) Subject: Python's super() considered super! In-Reply-To: <87boyoa5ov.fsf@benfinney.id.au> Message-ID: <295fdad8-93a5-42ba-ac9c-e7268cb9fa96@glegroupsg2000goo.googlegroups.com> On Friday, May 27, 2011 10:49:52 AM UTC+2, Ben Finney wrote: > The exquisite care that you describe programmers needing to maintain is IMO > just as much a deterrent as the super-is-harmful essay. Worth quoting. Also I think this article may encourage naive programmers along the dark path of cooperative multiple inheritance, when they could instead use better designs. From bahamutzero8825 at gmail.com Fri May 27 05:22:48 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 27 May 2011 04:22:48 -0500 Subject: List of WindowsError error codes and meanings In-Reply-To: <9478c6Fr09U1@mid.individual.net> References: <9478c6Fr09U1@mid.individual.net> Message-ID: <4DDF6D68.4090406@gmail.com> On 2011.05.26 10:02 AM, Thomas Heller wrote: > On Windows, you can use ctypes.FormatError(code) to map error codes > to strings: > > >>> import ctypes > >>> ctypes.FormatError(32) > 'Der Prozess kann nicht auf die Datei zugreifen, da sie von einem > anderen Prozess verwendet wird.' > >>> > > For HRESULT codes, you (unfortunately) have to subtract 2**32-1 from > the error code: > > >>> ctypes.FormatError(0x80040005) > Traceback (most recent call last): > File "", line 1, in > OverflowError: long int too large to convert to int > >>> ctypes.FormatError(0x80040005 - (2**32-1)) > 'Kein Cache zum Verarbeiten vorhanden.' > >>> I could get that with str(sys.exc_info()[1]), though. If something raises a WindowsError, str(sys.exc_info()[1]) contains something like: [Error 183] Cannot create a file when that file already exists: sys.exc_info() is how I get the error code from inside an except clause in the first place. Or is there something I'm missing here? From steve+comp.lang.python at pearwood.info Fri May 27 05:31:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 09:31:33 GMT Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> <4ddf1571$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ddf6f75$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 10:10:55 +0200, Thorsten Kampe wrote: > * Steven D'Aprano (27 May 2011 03:07:30 GMT) [...] >> If I got it wrong about John, oh well, I said it was a guess, and >> trying to get inside someone else's head is always a chancy business. > > Why were you trying to speculate in response to such a - sorry - dumb[1] > question? Because someone was WRONG on the INTERNET!!! *wink* -- Steven From duncan.booth at invalid.invalid Fri May 27 06:31:44 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 May 2011 10:31:44 GMT Subject: bug in str.startswith() and str.endswith() References: Message-ID: Carl Banks wrote: > The end parameter looks pretty useless for > .startswith() and is probably only present for consistency with other > string search methods like .index(). No, the end parameter could be useful if the slice ends up shorter than the prefix string: >>> 'abcd'.startswith('abc', 0, 2) False Likewise the start parameter for endswith. -- Duncan Booth http://kupuguy.blogspot.com From steve+comp.lang.python at pearwood.info Fri May 27 06:37:13 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 10:37:13 GMT Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> <87boyoa5ov.fsf@benfinney.id.au> Message-ID: <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 18:49:52 +1000, Ben Finney wrote: > Raymond Hettinger writes: > >> Hope you enjoyed the post. > > I certainly did. > > But I'm not better enlightened on why ?super? is a good thing. Perhaps Raymond assumed that by now everybody knows that multiple inheritance in Python that doesn't use super is buggy. super() was introduced in version 2.2 in order to overcome bugs in MI, making it about 8 years old now. (Technically, it's only MI with diamond-shaped inheritance, but that applies to *all* new-style classes. If you're writing multiple inheritance in Python 3 without using super, your code is a land-mine waiting to go off. If you're writing single inheritance, it's *still* a land-mine, just waiting for some poor caller to use it in a MI context.) But I do agree with you in that I expected to see at least some discussion of why super should be actively preferred over calling the parent class directly. > The > exquisite care that you describe programmers needing to maintain is IMO > just as much a deterrent as the super-is-harmful essay. I don't see that Raymond describes anything needing "exquisite care". It's more common sense really: ensure that your method signature and that of your parents' match, plus good work-arounds for when they don't. Anyone using inheritance is almost certainly 98% of the way there, unless they're writing classes like this and wondering why they don't work :) class MyBrokenList(list): def __len__(self): n = list.__len__(self, extra=42) return n + 1 def __getitem__(self, i): return list.__getitem__(self) + 1 def last_item(self): return list.last_item(self) + 1 I was thrilled to learn a new trick, popping keyword arguments before calling super, and wondered why I hadn't thought of that myself. How on earth did I fail to realise that a kwarg dict was mutable and therefore you can remove keyword args, or inject new ones in? Given the plethora of articles that take a dim, if not outright negative, view of super, it is good to see one that takes a positive view. Thanks Raymond! -- Steven From duncan.booth at invalid.invalid Fri May 27 06:53:13 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 May 2011 10:53:13 GMT Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> <87boyoa5ov.fsf@benfinney.id.au> <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I was thrilled to learn a new trick, popping keyword arguments before > calling super, and wondered why I hadn't thought of that myself. How on > earth did I fail to realise that a kwarg dict was mutable and therefore > you can remove keyword args, or inject new ones in? > Probably because most of the time it is better to avoid mutating kwargs. Instead of popping an argument you simply declare it as a named argument in the method signature. Instead of injecting new ones you can pass them as named arguments. def foo(x=None, **kwargs): bar(y=2, **kwargs) def bar(**kwargs): print(kwargs) >>> foo(x=1, z=3) {'y': 2, 'z': 3} >>> foo(x=1, y=2, z=3) Traceback (most recent call last): File "", line 1, in foo(x=1, y=2, z=3) File "", line 2, in foo bar(y=2, **kwargs) TypeError: bar() got multiple values for keyword argument 'y' -- Duncan Booth http://kupuguy.blogspot.com From mwilson at the-wire.com Fri May 27 09:03:55 2011 From: mwilson at the-wire.com (Mel) Date: Fri, 27 May 2011 09:03:55 -0400 Subject: bug in str.startswith() and str.endswith() References: <4DDEE1C8.6010107@stoneleaf.us> Message-ID: Terry Reedy wrote: > To me, that says pretty clearly that start and end have to be > 'positions', ie, ints or other index types. So I would say that the > error message is a bug. I see so reason why one would want to use None > rather that 0 for start or None rather than nothing for end. If you're trying to wrap a call to startswith in a function that "looks like" startswith, there's no easy way to pass in the information that your caller wants the default parameters. The case I ran into was def wrapped_range (start, stop=None, span=None): do_some_things() result = range (start, stop, span) # range doesn't(/didn't) accept this return result Tne answer in that case was to take *args as the parameter to wrapped_range and count arguments to distinguish between the different calls to range. Mel. From roy at panix.com Fri May 27 09:25:12 2011 From: roy at panix.com (Roy Smith) Date: Fri, 27 May 2011 09:25:12 -0400 Subject: The worth of comments References: Message-ID: In article , Chris Angelico wrote: > (Did I *really* write that code? It has my name on it.....) Most version control systems have an annotate command which lets you see who wrote a given line of code. Some of them are even honest enough to call the command "blame" instead of "annotate" :-) And, yes, it's always a rude shock when I stare at some hunk of code, mutter, "who wrote this crap!?" and fire up annotate/blame only to discover my name on it. From darcy at druid.net Fri May 27 09:29:45 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 27 May 2011 09:29:45 -0400 Subject: The worth of comments In-Reply-To: References: Message-ID: <20110527092945.d6729f5c.darcy@druid.net> On Fri, 27 May 2011 00:02:23 -0700 Tim Roberts wrote: > Ruby has a lot of followers, and I am trying to get excited about it, but > it has succumbed to the same special-characters-as-syntax disease that > killed Perl. Much Ruby code is just unreadable. What? The recent Perl flame war wasn't enough entertainment for you? ;-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From roy at panix.com Fri May 27 09:47:21 2011 From: roy at panix.com (Roy Smith) Date: Fri, 27 May 2011 09:47:21 -0400 Subject: Why did Quora choose Python for its development? References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <87sjs4t12l.fsf@castleamber.com> <948l8nF33pU1@mid.individual.net> Message-ID: In article <948l8nF33pU1 at mid.individual.net>, Gregory Ewing wrote: > John Bokma wrote: > > > A Perl programmer will call this line noise: > > > > double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", > > re.IGNORECASE) One of the truly awesome things about the Python re library is that it lets you write complex regexes like this: pattern = r"""\b # beginning of line (?P\w+) # a word \s+ # some whitespace (?P=word)(?!\w) # the same word again """ double_word_re = re.compile(pattern, re.I | re.X) Sometimes regex really is the best tool. It's often the most compact, or fastest, or clearest way to express something complicated. Fortunately, re.X mode gives you a way to write truly monster regexes and still having them not be total line noise. It's a shame that the Python community has evolved to be so anti-regex that most people never consider using them. While Perl's attitude to regex may be "when the only tool you have is a hammer, everything looks like a nail", Python's seems to be, "I've got a great collection of all kinds of neat tools, so I'm going to pretend the hammer that's in there doesn't exist because I once smashed my thumb with it and it hurt a lot". From roy at panix.com Fri May 27 09:48:39 2011 From: roy at panix.com (Roy Smith) Date: Fri, 27 May 2011 09:48:39 -0400 Subject: bug in str.startswith() and str.endswith() References: Message-ID: In article , Stefan Behnel wrote: > Roy Smith, 27.05.2011 03:13: > > Ethan Furman wrote: > > > >> --> 'this is a test'.startswith('this') > >> True > >> --> 'this is a test'.startswith('this', None, None) > >> Traceback (most recent call last): > >> File "", line 1, in > >> TypeError: slice indices must be integers or None or have an __index__ > >> method > > [...] > >> Any reason this is not a bug? > > > > +1 for it being a bug. > > Meaning that the right thing to do at this point is to file a bug report. And now we just need to figure out if it's a bug in the code or the documentation :-) From invalid at invalid.invalid Fri May 27 09:54:03 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 27 May 2011 13:54:03 +0000 (UTC) Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> Message-ID: On 2011-05-27, Ben Finney wrote: > Richard Parker writes: > >> On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: >> >> > My experience is that comments in Python are of relatively low >> > usefulness. (For avoidance of doubt: not *zero* usefulness, merely >> > low.) I've seen plenty of comments who's usefulness was not zero. It was less than zero. >> > I can name variables, functions and classes with sensible, >> > self- documenting names. > > I am largely in agreement with this position (including the ???not *zero* > usefulness??? caveat). > >> I'm less inclined to use comments on each line, or selected lines, but >> rather use block comments instead. They require more thought and time >> to write; however, the intended functionality of the code that follows >> can be described in full. > > This I disagree with. If a section of code is interesting enough to > deserve an explanation, then it is better to capture it in a > helpfully-named function with its doc string having the explanation. I consider docstrings to be the same as comments, so there's not really much disagreement. -- Grant Edwards grant.b.edwards Yow! Am I in Milwaukee? at gmail.com From sturlamolden at yahoo.no Fri May 27 10:27:53 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 07:27:53 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> On 26 Mai, 18:31, Raymond Hettinger wrote: > I just posted a tutorial and how-to guide for making effective use of > super(). > > One of the reviewers, David Beazley, said, "Wow, ?that's really > great! ? ?I see this becoming the definitive post on the subject" > > The direct link is: > > ?http://rhettinger.wordpress.com/2011/05/26/super-considered-super/ I really don't like the Python 2 syntax of super, as it violates the DRY principle: Why do I need to write super(type(self),self) when super() will do? Assuming that 'self' will always be named 'self' in my code, I tend to patch __builtins__.super like this: import sys def super(): self = sys._getframe().f_back.f_locals['self'] return __builtins__.super(type(self),self) This way the nice Python 3.x syntax can be used in Python 2.x. Sturla From harrismh777 at charter.net Fri May 27 10:31:37 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 09:31:37 -0500 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd7bde$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > You really do > need to know whether the car you drive uses leaded or unleaded. Actually, you need to know whether your car can burn 85 gas (at about 60 cents /gallon cheaper... and, whether 85 gas will have enough energy to move the car without using 35% more fuel... making it about $1.00 /gallon more expensive.... ehem. :-} From mwilson at the-wire.com Fri May 27 10:33:20 2011 From: mwilson at the-wire.com (Mel) Date: Fri, 27 May 2011 10:33:20 -0400 Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: sturlamolden wrote: > I really don't like the Python 2 syntax of super, as it violates > the DRY principle: Why do I need to write super(type(self),self) > when super() will do? Assuming that 'self' will always be named > 'self' in my code, I tend to patch __builtins__.super like this: > > import sys > def super(): > self = sys._getframe().f_back.f_locals['self'] > return __builtins__.super(type(self),self) > > This way the nice Python 3.x syntax can be used in Python 2.x. Python causes trouble by letting the users get at the internals, but things like this make it worthwhile. Mel. From harrismh777 at charter.net Fri May 27 10:34:57 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 09:34:57 -0500 Subject: Abandoning Python In-Reply-To: <7xy61v5qy5.fsf@ruckus.brouhaha.com> References: <87ipt46okh.fsf@pobox.com> <7xy61v5qy5.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Haskell probably has the most vibrant development community at > the moment but its learning curve is quite steep, and it has > various shortcomings some of which are being worked on but others > of which may be insurmountable. Yes. You might want to lurk on: http://lambda-the-ultimate.org/ From harrismh777 at charter.net Fri May 27 10:40:53 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 09:40:53 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> Message-ID: Colin J. Williams wrote: > It would be safer to stick with Python 2.7 initially and then consider > the transition to 3.2 later. I must disagree with Colin's statement. If you are a complete beginner with Python... then there is going to a learning curve for you... and that curve should be 3.2--- period. It is true that some modules are not ready for 3.x, and it is also true that many installed systems (probably most) do not have 3.x installed. But that is not the point. The point is that 3.x is completely incompatible with 2.x (some call it a dialect, but that is a lie). Python3 is the future of the language, and if you're new to Python, then learn 3.x, move forward and don't look back... seriously. kind regards, m harris From steve+comp.lang.python at pearwood.info Fri May 27 10:49:08 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 14:49:08 GMT Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: <4ddfb9e4$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 10:33:20 -0400, Mel wrote: > sturlamolden wrote: > >> I really don't like the Python 2 syntax of super, as it violates the >> DRY principle: Why do I need to write super(type(self),self) when >> super() will do? Assuming that 'self' will always be named 'self' in my >> code, I tend to patch __builtins__.super like this: >> >> import sys >> def super(): >> self = sys._getframe().f_back.f_locals['self'] >> return __builtins__.super(type(self),self) >> >> This way the nice Python 3.x syntax can be used in Python 2.x. > > Python causes trouble by letting the users get at the internals, but > things like this make it worthwhile. Only if by "worthwhile" you mean "buggy as hell". >>> import sys >>> >>> def super(): ... self = sys._getframe().f_back.f_locals['self'] ... return __builtins__.super(type(self),self) ... >>> class A(object): ... def __init__(self): ... super().__init__() ... >>> class B(A): ... def __init__(self): ... super().__init__() ... >>> a = A() >>> b = B() Traceback (most recent call last): File "", line 1, in File "", line 3, in __init__ [...] File "", line 3, in __init__ RuntimeError: maximum recursion depth exceeded Do not use super(type(self), self), because it does not do what you think it does: b = B() calls B.__init__(self) ... which calls super(type(self), self) = super(B, self) ... which calls A.__init__(self) ... which calls super(type(self), self) = super(B, self) *not* A ... which loops forever type(self) does not return B inside B methods and A inside A methods, it returns the class of the instance. -- Steven From michele.simionato at gmail.com Fri May 27 10:51:05 2011 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 27 May 2011 07:51:05 -0700 (PDT) Subject: Python's super() considered super! In-Reply-To: <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: The fact that even experienced programmers fail to see that super(type(self),self) in Python 2 is NOT equivalent to super() in Python 3 is telling something. From duncan.booth at invalid.invalid Fri May 27 11:05:21 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 May 2011 15:05:21 GMT Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: sturlamolden wrote: > On 26 Mai, 18:31, Raymond Hettinger wrote: >> I just posted a tutorial and how-to guide for making effective use of >> super(). >> >> One of the reviewers, David Beazley, said, "Wow, ?that's really >> great! ? ?I see this becoming the definitive post on the subject" >> >> The direct link is: >> >> ?http://rhettinger.wordpress.com/2011/05/26/super-considered-super/ > > I really don't like the Python 2 syntax of super, as it violates > the DRY principle: Why do I need to write super(type(self),self) > when super() will do? Assuming that 'self' will always be named > 'self' in my code, I tend to patch __builtins__.super like this: > > import sys > def super(): > self = sys._getframe().f_back.f_locals['self'] > return __builtins__.super(type(self),self) > > This way the nice Python 3.x syntax can be used in Python 2.x. > > Oh dear, you haven't thought this one through. After your code above, try this: >>> class A(object): def foo(self): print "A.foo" >>> class B(A): def foo(self): print "B.foo" super().foo() >>> B().foo() B.foo A.foo So far so good. Now try this: >>> class C(B): pass >>> C().foo() ... infinite recursion follows ... Oops. There's a reason why Python 2 requires you to be explicit about the class; you simply cannot work it out automatically at run time. Python 3 fixes this by working it out at compile time, but for Python 2 there is no way around it. -- Duncan Booth http://kupuguy.blogspot.com From harrismh777 at charter.net Fri May 27 11:07:25 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 10:07:25 -0500 Subject: Python's super() considered super! In-Reply-To: <4ddfb9e4$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <4ddfb9e4$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> Python causes trouble by letting the users get at the internals, but >> > things like this make it worthwhile. > Only if by "worthwhile" you mean "buggy as hell". I *don't* believe this... the king of metaphors and bogus analogies has come up with 'buggy as hell' !!? No no, you might have buggy as grubs-under-a-damp-log, or buggy as 'moths-around-an-incandecent-lamp' , or you could have 'hot-as-hell,' but 'buggy-as-hell' just doesn't say what needs say'in... ... I'm just saying.... :) From sturlamolden at yahoo.no Fri May 27 11:11:19 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 08:11:19 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: On 27 Mai, 16:27, sturlamolden wrote: > Assuming that 'self' will always be named > 'self' in my code, I tend to patch __builtins__.super like this: > > import sys > def super(): > ? ? self = sys._getframe().f_back.f_locals['self'] > ? ? return __builtins__.super(type(self),self) A monkey-patch to __builtins__.super would probably also work. Assuming the first argument to the callee is 'self' or 'cls': import sys _super = __builtins__.super def monkeypatch(*args, **kwargs): if (args == ()) and (kwargs=={}): try: obj = sys._getframe().f_back.f_locals['self'] except KeyError: obj = sys._getframe().f_back.f_locals['cls'] return _super(type(obj),obj) else: return _super(*args, **kwargs) class patcher(object): def __init__(self): __builtins__.super = monkeypatch def __del__(self): __builtins__.super = _super _patch = patcher() Sturla From sturlamolden at yahoo.no Fri May 27 11:24:52 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 08:24:52 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: <439eb0a6-ad3c-4049-b35b-22abc1bd8b00@d1g2000yqm.googlegroups.com> On 27 Mai, 17:05, Duncan Booth wrote: > >>> class C(B): pass > >>> C().foo() > > ... infinite recursion follows ... That's true :( From sturlamolden at yahoo.no Fri May 27 11:31:40 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 08:31:40 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> On 27 Mai, 17:05, Duncan Booth wrote: > Oops. There's a reason why Python 2 requires you to be explicit about > the class; you simply cannot work it out automatically at run time. > Python 3 fixes this by working it out at compile time, but for Python 2 > there is no way around it. Then it should be a keyword, not a function. Sturla From steve+comp.lang.python at pearwood.info Fri May 27 11:52:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 15:52:14 GMT Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> Message-ID: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 09:40:53 -0500, harrismh777 wrote: > 3.x is completely incompatible with 2.x (some call it a dialect, > but that is a lie). "Completely incompatible"? A "lie"? import math import random my_list = [3, 5, 7, 9] n = random.choice(my_list) if n%3: func = math.sin else: func = math.cos y = func(math.pi/n)*10 L = ['spam']*(int(y)) for item in L: print(item) is valid syntax in every version of Python from 1.5 to 3.2, and it does the same thing in all of them. Would you care to revise your claims? -- Steven From miki.tebeka at gmail.com Fri May 27 11:57:08 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 27 May 2011 08:57:08 -0700 (PDT) Subject: The worth of comments In-Reply-To: Message-ID: https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw ;) From miki.tebeka at gmail.com Fri May 27 11:57:08 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 27 May 2011 08:57:08 -0700 (PDT) Subject: The worth of comments In-Reply-To: Message-ID: https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw ;) From python at mrabarnett.plus.com Fri May 27 12:02:01 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 27 May 2011 17:02:01 +0100 Subject: Puzzled by list-appending behavior In-Reply-To: <4dhut6lr8aqtfrk6oljr9lmofra6l5rp53@4ax.com> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <4dhut6lr8aqtfrk6oljr9lmofra6l5rp53@4ax.com> Message-ID: <4DDFCAF9.7080002@mrabarnett.plus.com> On 27/05/2011 07:34, Tim Roberts wrote: > MRAB wrote: >> >> I'd just like to point out that it's a convention, not a rigid rule. > > Reminds me of the catch-phrase from the first Pirates of the Caribbean > movie: "It's more of a guideline than a rule." Much like the Zen of Python. From steve+comp.lang.python at pearwood.info Fri May 27 12:06:05 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2011 16:06:05 GMT Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> Message-ID: <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 08:31:40 -0700, sturlamolden wrote: > On 27 Mai, 17:05, Duncan Booth wrote: > >> Oops. There's a reason why Python 2 requires you to be explicit about >> the class; you simply cannot work it out automatically at run time. >> Python 3 fixes this by working it out at compile time, but for Python 2 >> there is no way around it. > > Then it should be a keyword, not a function. Why? The fault is not that super is a function, or that you monkey- patched it, or that you used a private function to do that monkey- patching. The fault was that you made a common, but silly, mistake when reasoning about type(self) inside a class. I made the same mistake: assume that type(self) will always be the same class as that the method is defined in. But of course it won't be. With the luxury of hindsight, it is a silly mistake to make, but I promise you that you're not the first, and won't be the last, to make it. -- Steven From python at mrabarnett.plus.com Fri May 27 12:21:50 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 27 May 2011 17:21:50 +0100 Subject: [Python-ideas] Adding 'bytes' as alias for 'latin_1' codec. In-Reply-To: References: <87k4dc8r9j.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: <4DDFCF9E.4050204@mrabarnett.plus.com> On 27/05/2011 10:27, Nick Coghlan wrote: > On Fri, May 27, 2011 at 6:46 PM, Stephen J. Turnbull wrote: >> > What method is invoked to convert the numbers to text? What encoding >> > is used to convert those numbers to text? How does this operation >> > avoid also converting the *bytes* object to text and then reencoding >> > it? >> >> OTOH, Nick, aren't you making this harder than it needs to be? After >> all, > > To me, the defining feature of str.format() over str.__mod__() is the > ability for types to provide their own __format__ methods, rather than > being limited to a predefined set of types known to the interpreter. > If bytes were to reuse the same name, then I'd want to see similar > flexibility. > > Now, a *different* bytes method (bytes.interpolate, perhaps?), limited > to specific types may make sense, but such an alternative *shouldn't* > be conflated with the text formatting API. > > However, proponents of such an addition need to clearly articulate > their use cases and proposed solution in a PEP to make it clear that > they aren't merely trying to perpetuate the bytes/text confusion that > plagues 2.x 8-bit strings. > > We can almost certainly do better when it comes to constructing byte > sequences from component parts, but simply saying "oh, just add a > format() method to bytes objects" doesn't cut it, since the associated > magic methods for str.format are all string based, and bytes > interpolation also needs to address encoding issues for anything that > isn't already a byte sequence. > I would've thought that a "format" (or equivalent) method for bytes would work like struct.pack, so b"{0}".format(23) wouldn't return b'23', but you could have: >>> b'{0:b}'.format(23) b'\x17' From r.richardparker at comcast.net Fri May 27 12:51:25 2011 From: r.richardparker at comcast.net (Richard Parker) Date: Fri, 27 May 2011 09:51:25 -0700 Subject: Python-list Digest, Vol 92, Issue 232 In-Reply-To: References: Message-ID: <60CEF6B3-B9FA-4088-9680-6B063C99B2B6@comcast.net> Sometimes >> I'll drop in suggestions to future maintainers like, "consider >> refactoring with with perform_frobnitz_action()" > > Usually, I address future-me with comments like that (on the > assumption that there's nobody in the world sadistic enough to want to > maintain my code). But I never name future-me, the comments will be > addressed to "the subsequent maintainer" or somesuch. I do assume, > though, that future-me has forgotten everything about the code, and > since past-me left some comments that current-me has read, I think the > assumption is fairly accurate. (Did I *really* write that code? It has > my name on it.....) > > Chris Angelico > Rather than sadistic, one would likely be masochistic to undertake the maintenance of my code :-) I have had many moments where I have later asked the question "Did I write this code?." From irmen at -NOSPAM-xs4all.nl Fri May 27 13:05:02 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Fri, 27 May 2011 19:05:02 +0200 Subject: The worth of comments In-Reply-To: References: <87sjs0apgh.fsf@benfinney.id.au> Message-ID: <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> On 27-05-11 15:54, Grant Edwards wrote: > On 2011-05-27, Ben Finney wrote: >> Richard Parker writes: >> >>> On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: >>> >>>> My experience is that comments in Python are of relatively low >>>> usefulness. (For avoidance of doubt: not *zero* usefulness, merely >>>> low.) > > I've seen plenty of comments who's usefulness was not zero. It was > less than zero. Someone once taught me, "There is one thing worse than having no comments in the source code: having incorrect (or 'lying') comments in the code." Grant, I guess you hint at such comments? Irmen. From ethan at stoneleaf.us Fri May 27 13:12:07 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 10:12:07 -0700 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <20110524133902.b5ad22b1.darcy@druid.net> <87vcwzyoos.fsf@castleamber.com> <4ddd8a4c$0$29996$c3e8da3$5496439d@news.astraweb.com> <874o4i17zi.fsf@castleamber.com> <87oc2qay0o.fsf@benfinney.id.au> <878vttv5hd.fsf@castleamber.com> <4ddf1571$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DDFDB67.80500@stoneleaf.us> Thorsten Kampe wrote: > * Steven D'Aprano (27 May 2011 03:07:30 GMT) >> Okay, I've stayed silent while people criticize me long enough. What >> exactly did I say that was impolite? > > Nothing. > >> John threw down a distinct challenge: >> >> if Python is really so much better than Python [sic] >> readability wise, why do I have such a hard time dropping >> Perl and moving on? >> [...] >> If I got it wrong about John, oh well, I said it was a guess, and >> trying to get inside someone else's head is always a chancy business. > > Why were you trying to speculate in response to such a - sorry - dumb[1] > question? He asked the question not once, but multiple times (IIRC at least three, possible more) -- after a while it stops being rhetorical. I would say also, if you don't want an answer, don't ask the question. ~Ethan~ From ethan at stoneleaf.us Fri May 27 13:14:44 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 10:14:44 -0700 Subject: bug in str.startswith() and str.endswith() In-Reply-To: <4DDEE1C8.6010107@stoneleaf.us> References: <4DDEE1C8.6010107@stoneleaf.us> Message-ID: <4DDFDC04.3030203@stoneleaf.us> Ethan Furman wrote: > Any reason this is not a bug? Looks like someone else beat me to filing: http://bugs.python.org/issue11828 Looks like they fixed it as well. ~Ethan~ From ethan at stoneleaf.us Fri May 27 13:42:16 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 10:42:16 -0700 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> <87boyoa5ov.fsf@benfinney.id.au> <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DDFE278.8010306@stoneleaf.us> Duncan Booth wrote: > Steven D'Aprano wrote: > >> I was thrilled to learn a new trick, popping keyword arguments before >> calling super, and wondered why I hadn't thought of that myself. How on >> earth did I fail to realise that a kwarg dict was mutable and therefore >> you can remove keyword args, or inject new ones in? >> > Probably because most of the time it is better to avoid mutating kwargs. > Instead of popping an argument you simply declare it as a named argument in > the method signature. Instead of injecting new ones you can pass them as > named arguments. > > > def foo(x=None, **kwargs): > bar(y=2, **kwargs) > > > def bar(**kwargs): > print(kwargs) > >>>> foo(x=1, z=3) > {'y': 2, 'z': 3} >>>> foo(x=1, y=2, z=3) > Traceback (most recent call last): > File "", line 1, in > foo(x=1, y=2, z=3) > File "", line 2, in foo > bar(y=2, **kwargs) > TypeError: bar() got multiple values for keyword argument 'y' And the above error is exactly why you don't want to use named arguments in MI -- because you don't know in what order the methods will be called, you cannot know which named arguments to supply to the method that super() will call next. ~Ethan~ From invalid at invalid.invalid Fri May 27 13:49:40 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 27 May 2011 17:49:40 +0000 (UTC) Subject: The worth of comments References: Message-ID: On 2011-05-27, Miki Tebeka wrote: > https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw ;) I just realized that Usenet is sort of like radio. After hearing/reading somebody for years, I don't seem to have a detailed image of them in my head, but when I finally do see a picture of them, my initial reaction is almost always "no, that's not at all what I thought he/she looked like". Odd. -- Grant Edwards grant.b.edwards Yow! I demand IMPUNITY! at gmail.com From invalid at invalid.invalid Fri May 27 13:53:15 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 27 May 2011 17:53:15 +0000 (UTC) Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: On 2011-05-27, Irmen de Jong wrote: > On 27-05-11 15:54, Grant Edwards wrote: >> On 2011-05-27, Ben Finney wrote: >>> Richard Parker writes: >>> >>>> On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: >>>> >>>>> My experience is that comments in Python are of relatively low >>>>> usefulness. (For avoidance of doubt: not *zero* usefulness, merely >>>>> low.) >> >> I've seen plenty of comments who's usefulness was not zero. It was >> less than zero. > > Someone once taught me, "There is one thing worse than having no > comments in the source code: having incorrect (or 'lying') comments > in the code." > > Grant, I guess you hint at such comments? Yes. :) When trying to find a bug in code written by sombody else, I often first go through and delete all of the comments so as not to be mislead. The comments reflect what the author _thought_ the code did _at_some_point_in_the_past_. What matters is what the code actually does at the present. -- Grant Edwards grant.b.edwards Yow! ... If I had heart at failure right now, gmail.com I couldn't be a more fortunate man!! From ericsnowcurrently at gmail.com Fri May 27 13:56:29 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 27 May 2011 11:56:29 -0600 Subject: Python's super() considered super! In-Reply-To: <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> <87boyoa5ov.fsf@benfinney.id.au> <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 27, 2011 at 4:37 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Fri, 27 May 2011 18:49:52 +1000, Ben Finney wrote: > > > Raymond Hettinger writes: > > > >> Hope you enjoyed the post. > > > > I certainly did. > > > > But I'm not better enlightened on why ?super? is a good thing. > > Perhaps Raymond assumed that by now everybody knows that multiple > inheritance in Python that doesn't use super is buggy. super() was > introduced in version 2.2 in order to overcome bugs in MI, making it > about 8 years old now. > > (Technically, it's only MI with diamond-shaped inheritance, but that > applies to *all* new-style classes. If you're writing multiple > inheritance in Python 3 without using super, your code is a land-mine > waiting to go off. If you're writing single inheritance, it's *still* a > land-mine, just waiting for some poor caller to use it in a MI context.) > > But I do agree with you in that I expected to see at least some > discussion of why super should be actively preferred over calling the > parent class directly. > > Seems like he does just that for most of the first section. > > > The > > exquisite care that you describe programmers needing to maintain is IMO > > just as much a deterrent as the super-is-harmful essay. > > I don't see that Raymond describes anything needing "exquisite care". > It's more common sense really: ensure that your method signature and that > of your parents' match, plus good work-arounds for when they don't. > Anyone using inheritance is almost certainly 98% of the way there, unless > they're writing classes like this and wondering why they don't work :) > > class MyBrokenList(list): > def __len__(self): > n = list.__len__(self, extra=42) > return n + 1 > def __getitem__(self, i): > return list.__getitem__(self) + 1 > def last_item(self): > return list.last_item(self) + 1 > > > I was thrilled to learn a new trick, popping keyword arguments before > calling super, and wondered why I hadn't thought of that myself. How on > earth did I fail to realise that a kwarg dict was mutable and therefore > you can remove keyword args, or inject new ones in? > > Given the plethora of articles that take a dim, if not outright negative, > view of super, it is good to see one that takes a positive view. Thanks > Raymond! > > +1 -eric > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmchase.com Fri May 27 13:58:14 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Fri, 27 May 2011 13:58:14 -0400 Subject: Puzzled by list-appending behavior In-Reply-To: References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddf2003$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1ADD@EMARC112VS01.exchad.jpmchase.net> >I have to say, I do like Python's lack of keywords for these things I thought True/False were among the list of keywords in Python 3.x ? Or are those the only keywords? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From ramit.prasad at jpmchase.com Fri May 27 14:10:11 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Fri, 27 May 2011 14:10:11 -0400 Subject: Python's super() considered super! In-Reply-To: <87wrhcapm2.fsf@benfinney.id.au> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1B2C@EMARC112VS01.exchad.jpmchase.net> >>We also, though, need *real* URLs. Blind URLs through obfuscation >>services have their uses, but surely not in a forum like this. The real >>URL is . I remember reading a news article where a man was arrested (or was it fired) for pornography because he clicked a link. I would *REALLY* prefer not to be 4chan-ed into jail (or fired) because I could not safely tell what a shortened URL really pointed to. Besides, shortened URLs do not live as long and are more likely to fail when people search the archives. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From ethan at stoneleaf.us Fri May 27 14:14:23 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 11:14:23 -0700 Subject: The worth of comments In-Reply-To: References: Message-ID: <4DDFE9FF.4010403@stoneleaf.us> Miki Tebeka wrote: > https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw ;) +1 That was hilarious. ~Ethan~ From ramit.prasad at jpmchase.com Fri May 27 14:17:54 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Fri, 27 May 2011 14:17:54 -0400 Subject: The worth of comments In-Reply-To: References: Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1B6D@EMARC112VS01.exchad.jpmchase.net> >(Did I *really* write that code? It has my name on it.....) Damn those ninja programmers who stole your name and coded something! Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From patty at cruzio.com Fri May 27 14:21:51 2011 From: patty at cruzio.com (Patty) Date: Fri, 27 May 2011 11:21:51 -0700 Subject: The worth of comments References: <4DDFE9FF.4010403@stoneleaf.us> Message-ID: <4AD8771B534548D786F67994517997F0@mycomputer> ----- Original Message ----- From: "Ethan Furman" To: Sent: Friday, May 27, 2011 11:14 AM Subject: Re: The worth of comments > Miki Tebeka wrote: >> https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw ;) > > +1 > > That was hilarious. > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > > I know - since I am not working right now, it totally made me wonder why I put comments in Python code at all -- or even have anything to do with code -- and plans being made to spend the rest of the day laying around in the hammock :) Patty From ian.g.kelly at gmail.com Fri May 27 14:31:14 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 27 May 2011 12:31:14 -0600 Subject: Python's super() considered super! In-Reply-To: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: On Thu, May 26, 2011 at 10:31 AM, Raymond Hettinger wrote: > I just posted a tutorial and how-to guide for making effective use of > super(). I posted this already on the HackerNews thread but it seems to have largely gone unnoticed, so I'm reposting it here. It seems to me that the example of combining built-in dictionary classes is naively optimistic. For starters, OrderedDict, as it happens, does not use super! It calls the dict super-class methods directly. Since dict luckily happens to be the next class in the MRO, this doesn't really matter for the purpose of this example, but I can envision a scenario where some plucky programmer inherits from both OrderedCounter and some other dict subclass, and the result doesn't work because OrderedDict does the wrong thing. And OrderedDict isn't the only one. Maybe for some reason I would like to have an OrderedCounter where all the counts default to 42. So I do this: class DefaultOrderedCounter(defaultdict, OrderedCounter): pass doc = DefaultOrderedCounter(lambda: 42) doc.update('abracadabra') Which results in: Traceback (most recent call last): File "", line 1, in File "c:\python32\lib\collections.py", line 507, in update _count_elements(self, iterable) File "c:\python32\lib\collections.py", line 63, in __setitem__ self.__map[key] = link = Link() AttributeError: 'DefaultOrderedCounter' object has no attribute '_OrderedDict__map' Whoops! Apparently defaultdict doesn't use super either. Of course a better way to do this would be to subclass OrderedCounter and just override the __missing__ method by hand, but that's not the point. The article goes into "How to Incorporate a Non-cooperative Class", which basically says "wrap it up in a proxy class". But that's not really going to work here, since the result would be two separate dicts, with the defaultdictwrapper methods operating on one dict, and the other methods operating on the other. From martin at v.loewis.de Fri May 27 14:38:19 2011 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 27 May 2011 20:38:19 +0200 Subject: [ANN] Python 2.5.6 released Message-ID: <4DDFEF9B.4060000@v.loewis.de> On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.5.6. There were no changes since the release candidate. This is a source-only release that only includes security fixes. The last full bug-fix release of Python 2.5 was Python 2.5.4. Users are encouraged to upgrade to the latest release of Python 2.7 (which is 2.7.1 at this point). This release is most likely the final release of Python 2.5; under the current release policy, no security issues in Python 2.5 will be fixed after October, 2011. This releases fixes issues with the urllib, urllib2, SimpleHTTPServer, and audiop modules. See the release notes at the website (also available as Misc/NEWS in the source distribution) for details of bugs fixed. For more information on Python 2.5.6, including download links for various platforms, release notes, and known issues, please see: http://www.python.org/2.5.6 Highlights of the previous major Python releases are available from the Python 2.5 page, at http://www.python.org/2.5/highlights.html Enjoy this release, Martin Martin v. Loewis martin at v.loewis.de Python Release Manager (on behalf of the entire python-dev team) From rosuav at gmail.com Fri May 27 14:40:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 May 2011 04:40:17 +1000 Subject: Python's super() considered super! In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1B2C@EMARC112VS01.exchad.jpmchase.net> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1B2C@EMARC112VS01.exchad.jpmchase.net> Message-ID: On Sat, May 28, 2011 at 4:10 AM, Prasad, Ramit wrote: >>>We also, though, need *real* URLs. Blind URLs through obfuscation >>>services have their uses, but surely not in a forum like this. The real >>>URL is . > > I remember reading a news article where a man was arrested (or was it fired) for pornography because he clicked a link. I would *REALLY* prefer not to be 4chan-ed into jail (or fired) because I could not safely tell what a shortened URL really pointed to. Besides, shortened URLs do not live as long and are more likely to fail when people search the archives. I've seen FAR more dead links than dead URL shortening services. It's a lot more likely that the destination will go down than that the tinyurl service will lose its data. If you're worried about where you're going, grab a URL renderer; TinyURL.com has "preview mode" which you can set with a cookie, and for others, all you need is something which takes a URL off the clipboard, requests it, gets the Location: header, and puts that on the clipboard for you. I coded such a facility into my MUD client (RosMud), because shortened URLs are important when lines are limited to 80 characters (less some overhead); it'd be quite easy to build a little Python-GTK or Python-TK app that gives you a nice window and makes it easy. Chris Angelico From rosuav at gmail.com Fri May 27 14:46:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 May 2011 04:46:12 +1000 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: On Sat, May 28, 2011 at 4:31 AM, Ian Kelly wrote: > It seems to me that the example of combining built-in dictionary > classes is naively optimistic. So... Can anyone offer a non-trivial example of multiple inheritance that *doesn't* have pitfalls? From what I've seen, MI always seems to require cooperation from the authors of all involved classes. It may be a useful tool when you control everything, but whenever you use someone else's code, there seems to be this massive barrier of risk (if that makes sense). For the DefaultOrderedCounter, I would be strongly inclined to inherit singly, and then manually implement the other half (whichever half is easier); in this case that happens to be trivial (override __missing__), but even were it not, it would be a means of being certain that things won't break. Chris Angelico From ethan at stoneleaf.us Fri May 27 14:56:04 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 11:56:04 -0700 Subject: Puzzled by list-appending behavior In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1ADD@EMARC112VS01.exchad.jpmchase.net> References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> <829f09b0-8f46-4ef0-9d25-e15a1629e22d@h12g2000pro.googlegroups.com> <4ddf0584$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddf2003$0$29996$c3e8da3$5496439d@news.astraweb.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2DA44B1ADD@EMARC112VS01.exchad.jpmchase.net> Message-ID: <4DDFF3C4.8070400@stoneleaf.us> Prasad, Ramit wrote: >> I have to say, I do like Python's lack of keywords for these things > > I thought True/False were among the list of keywords in Python 3.x ? Or are those the only keywords? http://docs.python.org/py3k/reference/lexical_analysis.html#keywords False class finally is return None continue for lambda try True def from nonlocal while and del global not with as elif if or yield assert else import pass break except in raise ~Ethan~ From tkpmep at hotmail.com Fri May 27 15:21:53 2011 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: Fri, 27 May 2011 12:21:53 -0700 (PDT) Subject: Python 3.2 bug? Reading the last line of a file References: <3d81e2a0-6c86-4f12-a1c4-ce4c736172b6@y31g2000vbp.googlegroups.com> <4DDD5FD2.8040607@mrabarnett.plus.com> <55262a36-ca53-48dd-b563-1847f9442bae@dn9g2000vbb.googlegroups.com> Message-ID: This is exactly what I want to do - I can then pick up various elements of the list and turn them into floats, ints, etc. I have not ever used decode, and will look it up in the docs to better understand it. I can't thank everyone enough for the generous serving of help and guidance - I certainly would not have discovered all this on my own. Sincerely Thomas Philips From karim.liateni at free.fr Fri May 27 16:10:30 2011 From: karim.liateni at free.fr (Karim) Date: Fri, 27 May 2011 22:10:30 +0200 Subject: Why did Quora choose Python for its development? In-Reply-To: References: <80d59383-36a3-4744-85c4-1a0577f1d3a6@dr5g2000vbb.googlegroups.com> <9CDC4B2CD1F445E994119A50F65155DF@teddy> <12225671E9654FECB49613D915FAEC19@teddy> <21A740B7AC6644248476DFADDF726C73@octavian> <629DAC3611EA49B0A36BCF70151CDE2F@octavian> <87sjs44qyk.fsf@castleamber.com> <87zkmcujl4.fsf@castleamber.com> <87sjs4t12l.fsf@castleamber.com> <948l8nF33pU1@mid.individual.net> Message-ID: <4DE00536.2070705@free.fr> On 05/27/2011 03:47 PM, Roy Smith wrote: > In article<948l8nF33pU1 at mid.individual.net>, > Gregory Ewing wrote: > >> John Bokma wrote: >> >>> A Perl programmer will call this line noise: >>> >>> double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", >>> re.IGNORECASE) > One of the truly awesome things about the Python re library is that it > lets you write complex regexes like this: > > pattern = r"""\b # beginning of line > (?P\w+) # a word > \s+ # some whitespace > (?P=word)(?!\w) # the same word again > """ > double_word_re = re.compile(pattern, re.I | re.X) > > Sometimes regex really is the best tool. It's often the most compact, > or fastest, or clearest way to express something complicated. > Fortunately, re.X mode gives you a way to write truly monster regexes > and still having them not be total line noise. > > It's a shame that the Python community has evolved to be so anti-regex > that most people never consider using them. While Perl's attitude to > regex may be "when the only tool you have is a hammer, everything looks > like a nail", Python's seems to be, "I've got a great collection of all > kinds of neat tools, so I'm going to pretend the hammer that's in there > doesn't exist because I once smashed my thumb with it and it hurt a lot". HAHAHAHAHAHA Very funny! This thread is awsome. Cheers Karim From thorsten at thorstenkampe.de Fri May 27 16:38:50 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Fri, 27 May 2011 22:38:50 +0200 Subject: sys.tracebacklimit not working in Python 3.2? Message-ID: Hi, > type test.py import sys sys.tracebacklimit = 0 import doesnotexist > python test.py ImportError: No module named doesnotexist > python3 test.py Traceback (most recent call last): File "test.py", line 4, in import doesnotexist ImportError: No module named doesnotexist The 3.2 documentation says "When set to 0 or less, all traceback information is suppressed and only the exception type and value are printed". Bug? Thorsten From harrismh777 at charter.net Fri May 27 16:40:53 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 15:40:53 -0500 Subject: Beginner needs advice In-Reply-To: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Would you care to revise your claims? No. You have erected a straw-man... once again. Most 2.x code *will not* run correctly in 3.x/ Most of the best improvements and enhancements of 3.x will not back-port to below 2.7, and almost none of them will back-port before 2.6 (class decorations, for instance). Some interfaces have changed! cmp keyword, but lets not bring that up again.... Many syntaxes have changed or have disappeared... ... and some commands (like reload for instance) either don't exist in 3.x, or have been hidden, replaced, or changed... All of these things are for the better, I must add. But, the point is that 3.x is completely incompatible with 2.x in real ways. Arguing that this is *not true* because you are able to create a code block that just happens 'to work' in all versions (and that hasn't been verified yet) does not in *any* way 'prove' that 3.x is a compatible dialect--- far from it... its a straw-man argument. kind regards, m harris From nagle at animats.com Fri May 27 16:47:54 2011 From: nagle at animats.com (John Nagle) Date: Fri, 27 May 2011 13:47:54 -0700 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: <4de00dfd$0$2133$742ec2ed@news.sonic.net> On 5/27/2011 11:46 AM, Chris Angelico wrote: > On Sat, May 28, 2011 at 4:31 AM, Ian Kelly wrote: >> It seems to me that the example of combining built-in dictionary >> classes is naively optimistic. > > So... Can anyone offer a non-trivial example of multiple inheritance > that *doesn't* have pitfalls? From what I've seen, MI always seems > to require cooperation from the authors of all involved classes. Good point. Multiple inheritance is messy enough when the structure is just a tree. When the structure is allowed to be a directed acyclic graph, the whole thing just gets too complicated. It doesn't even necessarily do what you want. If, say, you have two classes that need dictionaries, and were implemented by inheriting from "dict", a class that imports both has one "dict", not two - something that was not anticipated in the design of the original classes. That ought to be an error, not a single "dict" shared by two unconnected classes. What causes this kind of mess is a determination not to report anything as an error if it can be given some kind of meaningful semantics, even if the semantics have marginal value. That's the kind of thinking which leads to [1,2] * 2 returning [1,2,1,2] John Nagle From pythoniks at gmail.com Fri May 27 17:21:46 2011 From: pythoniks at gmail.com (Pascal Chambon) Date: Fri, 27 May 2011 23:21:46 +0200 Subject: GIL in alternative implementations Message-ID: <4DE015EA.4040600@gmail.com> Hello everyone, I've already read quite a bit about the reasons for the GIL in CPython, i.e to summarize, that a more-fine graine locking, allowing real concurrency in multithreaded applications, would bring too much overhead for single-threaded python applications. However, I've also heard that other python implementations (ironpython, jython...) have no GIL, and yet nobody blames them for performance penalties that would be caused by that lack (I especially think about IronPython, whose performances compare quite well to CPython). So I'd like to know: how do these other implementations handle concurrency matters for their primitive types, and prevent them from getting corrupted in multithreaded programs (if they do) ? I'm not only thinking about python types, but also primitive containers and types used in .Net and Java VMs, which aren't atomic elements either at an assembly-level point of view. Do these VMs have some GIL-like limitations, that aren't spoken about ? Are there functionings completely different from the CPython VM, so that the question is not relevant ? Do people consider that they always concern multithreaded applications, and so accept performance penalties that they wouldn't allow in their CPython scripts ? I think you in advance for your lights on these questions. Regards, Pkl [[ Important Note: this is a serious question, trolls and emotionally disturbed persons had better go on their way. ]] -------------- next part -------------- An HTML attachment was scrubbed... URL: From suresh.amritapuri at gmail.com Fri May 27 17:25:52 2011 From: suresh.amritapuri at gmail.com (suresh) Date: Fri, 27 May 2011 14:25:52 -0700 (PDT) Subject: changing current dir and executing a shell script Message-ID: Hi, I want to execute the following command line stuff from inside python. $cd directory $./executable I tried the following but I get errors import subprocess subprocess.check_call('cd dir_name;./executable') Due to filename path issues, I cannot try this version. subprocess.check_call('./dir_name/executable') Any suggestions? thanks suresh From ethan at stoneleaf.us Fri May 27 17:33:38 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 14:33:38 -0700 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> Message-ID: <4DE018B2.2050508@stoneleaf.us> Lew Schwartz wrote: > So, if I read between the lines correctly, you recommend Python 3? Does > the windows version install with a development environment? Dabo, last I checked, uses wxPython, which uses wxWidgets (sp?), which is not yet ported to Python 3. So if you got that route you'll need to stay with 2.7. ~Ethan~ From stefan_ml at behnel.de Fri May 27 17:49:37 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 27 May 2011 23:49:37 +0200 Subject: Python's super() considered super! In-Reply-To: <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 27.05.2011 18:06: > On Fri, 27 May 2011 08:31:40 -0700, sturlamolden wrote: > >> On 27 Mai, 17:05, Duncan Booth wrote: >> >>> Oops. There's a reason why Python 2 requires you to be explicit about >>> the class; you simply cannot work it out automatically at run time. >>> Python 3 fixes this by working it out at compile time, but for Python 2 >>> there is no way around it. >> >> Then it should be a keyword, not a function. > > Why? I think Sturla is referring to the "compile time" bit. CPython cannot know that the builtin super() will be called at runtime, even if it sees a "super()" function call. CPython doesn't evaluate the super call at compile time, it only keeps a reference to the surrounding class in the code object of the method. So super() without arguments basically inherits the class argument from the context the method was found in at compile time. This has two quirks: 1) Copying a method from one class to another keeps the original context. So the class argument to super() is basically fixed at compile time, regardless of the class the method will be executed on at runtime. 2) The class is only kept as a reference when CPython sees a function call that looks like "super" at compile time, which isn't much more than a heuristic. The PEP doesn't mention the first issue, but it is actually explicit about the second issue: http://www.python.org/dev/peps/pep-3135/ """ While super is not a reserved word, the parser recognizes the use of super in a method definition and only passes in the __class__ cell when this is found. Thus, calling a global alias of super without arguments will not necessarily work. """ And the prove: >>> _super = super >>> class T(object): ... def test(self): print('TEST') ... >>> class B(T): ... def meth(self): _super().test() ... >>> B().meth() Traceback (most recent call last): SystemError: super(): __class__ cell not found I assume this is done in order to reduce the chance of accidentally keeping a class object alive for eternity, only because a method was originally defined therein that inherits the class reference in its code object. So it's a tradeoff between memory overhead and usability issues. While I think that the tradeoff is generally ok, I agree with Sturla that a keyword would have been the correct solution, whereas this is a clear "works only in the common cases" approach. Stefan From drsalists at gmail.com Fri May 27 18:14:35 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 27 May 2011 15:14:35 -0700 Subject: changing current dir and executing a shell script In-Reply-To: References: Message-ID: Each command will be run in a distinct subprocess. A CWD is typically local to a given subprocess. So after the first command/subprocess exits, your cd's change is no longer there. Try doing it in one command, with the two original commands separated by a semicolon. On Fri, May 27, 2011 at 2:25 PM, suresh wrote: > Hi, > I want to execute the following command line stuff from inside python. > $cd directory > $./executable > > I tried the following but I get errors > import subprocess > subprocess.check_call('cd dir_name;./executable') > > Due to filename path issues, I cannot try this version. > subprocess.check_call('./dir_name/executable') > > Any suggestions? > thanks > suresh > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thorsten at thorstenkampe.de Fri May 27 18:18:53 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 28 May 2011 00:18:53 +0200 Subject: changing current dir and executing a shell script References: Message-ID: * suresh (Fri, 27 May 2011 14:25:52 -0700 (PDT)) > I want to execute the following command line stuff from inside python. > $cd directory > $./executable > > I tried the following but I get errors > import subprocess > subprocess.check_call('cd dir_name;./executable') > > Due to filename path issues, I cannot try this version. > subprocess.check_call('./dir_name/executable') os.chdir? From marduk at letterboxes.org Fri May 27 18:19:22 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 27 May 2011 18:19:22 -0400 Subject: changing current dir and executing a shell script In-Reply-To: References: Message-ID: <1306534762.116297.3.camel@localhost.localdomain> On Fri, 2011-05-27 at 14:25 -0700, suresh wrote: > Hi, > I want to execute the following command line stuff from inside python. > $cd directory > $./executable > > I tried the following but I get errors > import subprocess > subprocess.check_call('cd dir_name;./executable') > > Due to filename path issues, I cannot try this version. > subprocess.check_call('./dir_name/executable') > You don't want to do this because "cd" is a built-in shell command, and subprocess does not execute within a shell (by default). The proper way to do this is to use the "cwd" keyword argument to subprocess calls, i.e.: >>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir") -a From ethan at stoneleaf.us Fri May 27 18:24:59 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 15:24:59 -0700 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> Message-ID: <4DE024BB.5070902@stoneleaf.us> I suspect the larger issue is that Multiple Inheritance is complex, but folks don't appreciate that. Ask anyone about meta-classes and their eyes bug-out, but MI? Simple! NOT. On the other hand, perhaps the docs should declare that the built-in objects are not designed for MI, so that that, at least, would be one less bug waiting to happen. ~Ethan~ From dinov at microsoft.com Fri May 27 18:52:08 2011 From: dinov at microsoft.com (Dino Viehland) Date: Fri, 27 May 2011 22:52:08 +0000 Subject: GIL in alternative implementations In-Reply-To: <4DE015EA.4040600@gmail.com> References: <4DE015EA.4040600@gmail.com> Message-ID: <6C7ABA8B4E309440B857D74348836F2E15BFF919@TK5EX14MBXC292.redmond.corp.microsoft.com> In IronPython we have fine grained locking on our mutable data structures. In particular we have a custom dictionary type which is designed to allow lock-free readers on common operations while writers take a lock. Our list implementation is similar but in some ways that's trickier to pull off due to features like slicing so if I recall correctly we only have lock-free reads when accessing a single element. For .NET data structures they follow the .NET convention which is up to the data structure. So if you wanted to get every last bit of performance out of your app you could handle thread safety yourself and switch to using the .NET dictionary or list types (although they're a lot less friendly to Python developers). Because of these locks on micro-benchmarks that involve simple list/dict manipulations you do see noticeably worse performance in IronPython vs. CPython. http://ironpython.codeplex.com/wikipage?title=IP27A1VsCPy27Perf&referringTitle=IronPython%20Performance - See the SimpleListManipulation and SimpleDictManipulation as the core examples here. Also CPython's dictionary is so heavily tuned it's hard to beat anyway, but this is a big factor. Finally one of the big differences with both Jython and IronPython is that we have good garbage collectors which don't rely upon reference counting. So one area where CPython gains from having a GIL is a non-issue for us as we don't need to protect ref counts or use interlocked operations for ref counting. From: python-list-bounces+dinov=exchange.microsoft.com at python.org [mailto:python-list-bounces+dinov=exchange.microsoft.com at python.org] On Behalf Of Pascal Chambon Sent: Friday, May 27, 2011 2:22 PM To: python-list at python.org >> Python List Subject: GIL in alternative implementations Hello everyone, I've already read quite a bit about the reasons for the GIL in CPython, i.e to summarize, that a more-fine graine locking, allowing real concurrency in multithreaded applications, would bring too much overhead for single-threaded python applications. However, I've also heard that other python implementations (ironpython, jython...) have no GIL, and yet nobody blames them for performance penalties that would be caused by that lack (I especially think about IronPython, whose performances compare quite well to CPython). So I'd like to know: how do these other implementations handle concurrency matters for their primitive types, and prevent them from getting corrupted in multithreaded programs (if they do) ? I'm not only thinking about python types, but also primitive containers and types used in .Net and Java VMs, which aren't atomic elements either at an assembly-level point of view. Do these VMs have some GIL-like limitations, that aren't spoken about ? Are there functionings completely different from the CPython VM, so that the question is not relevant ? Do people consider that they always concern multithreaded applications, and so accept performance penalties that they wouldn't allow in their CPython scripts ? I think you in advance for your lights on these questions. Regards, Pkl [[ Important Note: this is a serious question, trolls and emotionally disturbed persons had better go on their way. ]] -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri May 27 19:09:11 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 May 2011 09:09:11 +1000 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 28, 2011 at 6:40 AM, harrismh777 wrote: > Most 2.x code *will not* run correctly in 3.x/ ?Most of the best > improvements and enhancements of 3.x will not back-port to below 2.7, and > almost none of them will back-port before 2.6 (class decorations, for > instance). What's with the "below 2.7"? If you're comparing 3.x and 2.x, wouldn't it be most plausible to compare 3.2 and 2.7? And, the biggest reason for 2.x code not running on 3.x is probably the print function. (Guess made without any data beyond my own personal corpus of Python 2 code.) That's something that can be corrected by, oh, I dunno, the 2to3 translator maybe? And the __future__ import makes 2.6+ work the same way as 3.x. > All of these things are for the better, I must add. ?But, the point is that > 3.x is completely incompatible with 2.x in real ways. ?Arguing that this is > *not true* because you are able to create a code block that just happens 'to > work' in all versions (and that hasn't been verified yet) does not in *any* > way 'prove' that 3.x is a compatible dialect--- ?far from it... its a > straw-man argument. You're correct that one code block does not prove the point. But your argument is just as flimsy. To say that "most" 2.x code is incompatible with 3.x is to deny the 2to3 utility, and you're ignoring the people who deliberately write code that can cross-execute on either version - which is really not that difficult, if you take some care and use __future__ directives. Chris Angelico From sturlamolden at yahoo.no Fri May 27 19:57:16 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 16:57:16 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <72ac409d-8e13-4541-a56b-e9bbbc0e4472@s9g2000yqm.googlegroups.com> On 27 Mai, 23:49, Stefan Behnel wrote: > I think Sturla is referring to the "compile time" bit. CPython cannot know > that the builtin super() will be called at runtime, even if it sees a > "super()" function call. Yes. And opposite: CPython cannot know that builtin super() is not called, even if it does not see the name 'super'. I can easily make foo() alias super(). In both cases, the cure is a keyword -- or make sure that __class__ is always defined. If super is to be I keyword, we could argue that self and cls should be keywords as well, and methods should always be bound. That speaks in favour of a super() function. But then it should always be evaluated at run- time, without any magic from the parser. Magic functions belong in Perl, not Python. Sturla From ryan at rfk.id.au Fri May 27 19:57:56 2011 From: ryan at rfk.id.au (Ryan Kelly) Date: Sat, 28 May 2011 09:57:56 +1000 Subject: Python's super() considered super! In-Reply-To: References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> Message-ID: <1306540676.2113.4.camel@durian> On Fri, 2011-05-27 at 15:05 +0000, Duncan Booth wrote: > sturlamolden wrote: > > I really don't like the Python 2 syntax of super, as it violates > > the DRY principle: Why do I need to write super(type(self),self) > > when super() will do? Assuming that 'self' will always be named > > 'self' in my code, I tend to patch __builtins__.super like this: > > > > import sys > > def super(): > > self = sys._getframe().f_back.f_locals['self'] > > return __builtins__.super(type(self),self) > > > > This way the nice Python 3.x syntax can be used in Python 2.x. > > > > > Oh dear, you haven't thought this one through. > > ...snip... > > >>> C().foo() > ... infinite recursion follows ... > > Oops. There's a reason why Python 2 requires you to be explicit about > the class; you simply cannot work it out automatically at run time. > Python 3 fixes this by working it out at compile time, but for Python 2 > there is no way around it. Oh? There's not much that can't be done at runtime if you're willing to work hard enough. Let me propose the following awful awful hack: import sys _builtin_super = __builtins__.super _sentinel = object() def _auto_super(typ=_sentinel,type_or_obj=_sentinel): """Automagically call correct super() at runtime""" # Infer the correct call if used without arguments. if typ is _sentinel: # We'll need to do some frame hacking. f = sys._getframe(1) # Get the first positional argument of the function. type_or_obj = f.f_locals[f.f_code.co_varnames[0]] # Get the MRO for investigation try: mro = type_or_obj.__mro__ except AttributeError: try: mro = type_or_obj.__class__.__mro__ except AttributeError: raise RuntimeError("super() used with old-style class") # Now, find the class owning the currently-executing method. for typ in mro: for meth in typ.__dict__.itervalues(): if not isinstance(meth,type(_auto_super)): continue if meth.func_code is f.f_code: # Aha! Found you. break else: continue break else: raise RuntimeError("super() called outside a method") # Now just dispatch to builtin super. if type_or_obj is not _sentinel: return _builtin_super(typ,type_or_obj) return _builtin_super(typ) Now, try is with the following: class Base(object): def hello(self,msg): print "hello", msg class Sub1(Base): def hello(self,msg): print "gunna say it" super().hello(msg) class Sub2(Base): def hello(self,msg): print "yes I am" super().hello(msg) class Diamond(Sub1,Sub2): def hello(self,msg): print "here we go..." super().hello(msg) d = Diamond() d.hello("autosuper!") And you get the expected output: here we go... gunna say it yes I am hello autosuper! There may well be some cases where this breaks down, but it seems to do the right thing in simple cases. Not that I'm recommending anyone use this, of course... Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From sturlamolden at yahoo.no Fri May 27 20:04:00 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 27 May 2011 17:04:00 -0700 (PDT) Subject: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27 Mai, 18:06, Steven D'Aprano wrote: > Why? The fault is not that super is a function, or that you monkey- > patched it, or that you used a private function to do that monkey- > patching. The fault was that you made a common, but silly, mistake when > reasoning about type(self) inside a class. That was indeed a silly mistake, but not what I am talking about. See Stefan's reponse. Sturla From harrismh777 at charter.net Fri May 27 21:02:39 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 27 May 2011 20:02:39 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > To say that "most" 2.x code is > incompatible with 3.x is to deny the 2to3 utility, Oh, yes absolutely. Please don't misunderstand... anyone... I'm not saying that code cannot be migrated... migration can usually occur between incompatible releases and and between languages!... all I'm saying is that 3.x is not compatible with 2.x code (completely not compatible), and if you're a noob there is no reason to learn 2.x/ Learn 3.x and pickup whatever needs to be gained from 2.x if it comes up... we're talking about learning python as a newbie--- go with 3.x and never look back... seriously... > and you're ignoring > the people who deliberately write code that can cross-execute on > either version - which is really not that difficult, That's what I do... but I'm not a newbie. I have existing code that needs to be migrated, and I have an interest in creating research apps that will run on existing 2.x systems but will be ready and waiting for the time when the system moves to 3.x. I need to know both 2.6 and 3.2 very well. And I'll be honest about this, it is very frustrating. There are literally hundreds of changes and variations (its all in the details). Many Pythonists are not honest about this... because they don't want to scare folks away from 3.x, and I don't really blame them. But the true picture is that 3.x is (way better) and completely incompatible with 2.x. Lying about this isn't helpful to anyone coming on board with Python. Just tell them the truth... kind regards, m harris From drsalists at gmail.com Fri May 27 21:23:19 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 27 May 2011 18:23:19 -0700 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> Message-ID: On Fri, May 27, 2011 at 7:40 AM, harrismh777 wrote: > Colin J. Williams wrote: > >> It would be safer to stick with Python 2.7 initially and then consider >> the transition to 3.2 later. >> > > I must disagree with Colin's statement. If you are a complete beginner with > Python... then there is going to a learning curve for you... and that curve > should be 3.2--- period. > I almost agree with this, but not quite: A newbie should start with 3.2, but regrettably fall back to 2.7 -=IF=- there's a necessary dependency that hasn't been updated for whatever project(s) they're working on. > > The point is that 3.x is completely incompatible with 2.x (some call it a > dialect, but that is a lie). Python3 is the future of the language, and if > you're new to Python, then learn 3.x, move forward and don't look back... > seriously. > 3.x and 2.x are not that extremely incompatible. You usually can't just take 2.x code and run it, unmodified, on 3.x. However, there is a common subset that is pretty viable. EG: http://stromberg.dnsalias.org/~dstromberg/backshift/ Backshift is a relatively substantial piece of code (4400 lines and counting), but it runs fine on CPython 2.x, CPython 3.x, PyPy and Jython (Jython just slightly post-2.5.2 - they aren't planning to cut a new release that's compatible, but it's in their SCM), without any help from 2to3 or 3to2. It was written from the start with the intent of being very portable. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri May 27 21:30:03 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 May 2011 18:30:03 -0700 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DE0501B.8030901@stoneleaf.us> harrismh777 wrote: > Chris Angelico wrote: >> To say that "most" 2.x code is >> incompatible with 3.x is to deny the 2to3 utility, > > all I'm > saying is that 3.x is not compatible with 2.x code (completely not > compatible) > >> and you're ignoring >> the people who deliberately write code that can cross-execute on >> either version - which is really not that difficult, > > That's what I do... > > Lying about this isn't helpful to anyone coming > on board with Python. Just tell them the truth... Um -- how can you have on the one hand "completely not compatible" and on the other "code that can cross-execute on either version"? ~Ethan~ From suresh.amritapuri at gmail.com Fri May 27 21:33:18 2011 From: suresh.amritapuri at gmail.com (suresh) Date: Fri, 27 May 2011 18:33:18 -0700 (PDT) Subject: changing current dir and executing a shell script In-Reply-To: Message-ID: <609187f7-7100-4641-a185-08b93283bad9@glegroupsg2000goo.googlegroups.com> On Friday, May 27, 2011 3:19:22 PM UTC-7, Albert Hopkins wrote: > On Fri, 2011-05-27 at 14:25 -0700, suresh wrote: > > Hi, > > I want to execute the following command line stuff from inside python. > > $cd directory > > $./executable > > > > I tried the following but I get errors > > import subprocess > > subprocess.check_call('cd dir_name;./executable') > > > > Due to filename path issues, I cannot try this version. > > subprocess.check_call('./dir_name/executable') > > > > You don't want to do this because "cd" is a built-in shell command, and > subprocess does not execute within a shell (by default). > > The proper way to do this is to use the "cwd" keyword argument to > subprocess calls, i.e.: > > >>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir") > > -a It works. thank you very much. I have been struggling with this for a veryyyyy long time. suresh From suresh.amritapuri at gmail.com Fri May 27 21:33:18 2011 From: suresh.amritapuri at gmail.com (suresh) Date: Fri, 27 May 2011 18:33:18 -0700 (PDT) Subject: changing current dir and executing a shell script In-Reply-To: Message-ID: <609187f7-7100-4641-a185-08b93283bad9@glegroupsg2000goo.googlegroups.com> On Friday, May 27, 2011 3:19:22 PM UTC-7, Albert Hopkins wrote: > On Fri, 2011-05-27 at 14:25 -0700, suresh wrote: > > Hi, > > I want to execute the following command line stuff from inside python. > > $cd directory > > $./executable > > > > I tried the following but I get errors > > import subprocess > > subprocess.check_call('cd dir_name;./executable') > > > > Due to filename path issues, I cannot try this version. > > subprocess.check_call('./dir_name/executable') > > > > You don't want to do this because "cd" is a built-in shell command, and > subprocess does not execute within a shell (by default). > > The proper way to do this is to use the "cwd" keyword argument to > subprocess calls, i.e.: > > >>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir") > > -a It works. thank you very much. I have been struggling with this for a veryyyyy long time. suresh From dan.kluev at gmail.com Fri May 27 22:06:43 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Sat, 28 May 2011 13:06:43 +1100 Subject: GIL in alternative implementations In-Reply-To: <4DE015EA.4040600@gmail.com> References: <4DE015EA.4040600@gmail.com> Message-ID: > So I'd like to know: how do these other implementations handle concurrency > matters for their primitive types, and prevent them from getting corrupted > in multithreaded programs (if they do) ? I'm not only thinking about python > types, but also primitive containers and types used in .Net and Java VMs, > which aren't atomic elements either at an assembly-level point of view. Well, they definitely have some shortcomings: test.py: from threading import Thread class X(object): pass obj = X() obj.x = 0 def f(*args): for i in range(10000): obj.x += 1 threads = [] for i in range(100): t = Thread(target=f) threads.append(t) t.start() for t in threads: while t.isAlive(): t.join(1) print(obj.x) > python test.py 1000000 > pypy test.py 1000000 > jython-2.5 test.py 19217 > ipy test.py 59040 Not that this thing is reasonable to do in real code, but cpython and other implementations with GIL at least give you some safety margin. -- With best regards, Daniel Kluev From mhammond at skippinet.com.au Fri May 27 22:10:36 2011 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 28 May 2011 12:10:36 +1000 Subject: bdist_wininst: install_script not run on uninstall In-Reply-To: <201105261000.04741.wbsoft@xs4all.nl> References: <201105252128.17504.wbsoft@xs4all.nl> <4DDD94EF.6010804@gmail.com> <201105261000.04741.wbsoft@xs4all.nl> Message-ID: <4DE0599C.9010103@skippinet.com.au> On 26/05/2011 6:00 PM, Wilbert Berendsen wrote: > Op donderdag 26 mei 2011 schreef Mark: > >> Wilbert wrote: >> >>> can anybody find out why the install script is not run? >> >> Works for me in the pywin32 install script - maybe you should make the >> smallest possible example that doesn't work and post the entire thing here? Sorry, I was wrong. It apparently does *not* work for me either :( This is a bug in distutils/bdist_wininst - I just created http://bugs.python.org/issue12200 with the details and your samples, and sadly I can't think of a work around you can use until this is fixed (which I might get to soon, but not this weekend...) Cheers, Mark From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sat May 28 01:06:53 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sat, 28 May 2011 07:06:53 +0200 Subject: Beginner needs advice In-Reply-To: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 27.05.2011 17:52 schrieb Steven D'Aprano: > On Fri, 27 May 2011 09:40:53 -0500, harrismh777 wrote: > >> 3.x is completely incompatible with 2.x (some call it a dialect, >> but that is a lie). > > "Completely incompatible"? A "lie"? Hard word, but it is true. Many things can and will fall on your feet when moving. There are very many subtle differences. > import math > import random > my_list = [3, 5, 7, 9] > n = random.choice(my_list) > if n%3: > func = math.sin > else: > func = math.cos > > y = func(math.pi/n)*10 > L = ['spam']*(int(y)) > for item in L: > print(item) > > > is valid syntax in every version of Python from 1.5 to 3.2, and it does > the same thing in all of them. C and C++ guys complain if these languages are intermixed. Even there it is possible to write a program which is valid in both of them. Nevertheless, they are two different languages. So are Py2 and Py3, IMHO. Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sat May 28 01:29:48 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sat, 28 May 2011 07:29:48 +0200 Subject: Python's super() considered super! In-Reply-To: <72ac409d-8e13-4541-a56b-e9bbbc0e4472@s9g2000yqm.googlegroups.com> References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <1632c707-3660-4248-97c4-3033c269574b@w21g2000yqm.googlegroups.com> <79eb6a52-df6f-4b4d-835a-7966320390d2@e35g2000yqc.googlegroups.com> <4ddfcbec$0$29996$c3e8da3$5496439d@news.astraweb.com> <72ac409d-8e13-4541-a56b-e9bbbc0e4472@s9g2000yqm.googlegroups.com> Message-ID: Am 28.05.2011 01:57 schrieb sturlamolden: > Yes. And opposite: CPython cannot know that builtin super() is not > called, > even if it does not see the name 'super'. I can easily make foo() > alias super(). Another alternative would have been to make use of __xxx magic. If every class had an "automatically available" attribute, e. g. ___classname which thus could be accessed via __classname from inside, keeping the 2.x syntax would have been the best, using super(__classname, self). > In both cases, the cure is a keyword -- or make sure that __class__ > is always defined. > > If super is to be I keyword, we could argue that self and cls should > be keywords as well, and methods should always be bound. That speaks in > favour of a super() function. But then it should always be evaluated at run- > time, without any magic from the parser. > > Magic functions belong in Perl, not Python. ACK. Thomas From pavlovevidence at gmail.com Sat May 28 01:32:03 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 27 May 2011 22:32:03 -0700 (PDT) Subject: Why did Quora choose Python for its development? In-Reply-To: Message-ID: On Friday, May 27, 2011 6:47:21 AM UTC-7, Roy Smith wrote: > In article <948l8n... at mid.individual.net>, > Gregory Ewing wrote: > > > John Bokma wrote: > > > > > A Perl programmer will call this line noise: > > > > > > double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", > > > re.IGNORECASE) > > One of the truly awesome things about the Python re library is that it > lets you write complex regexes like this: > > pattern = r"""\b # beginning of line > (?P\w+) # a word > \s+ # some whitespace > (?P=word)(?!\w) # the same word again > """ > double_word_re = re.compile(pattern, re.I | re.X) Perl has the X flag as well, in fact I'm pretty sure Perl originated it. Just saying. Carl Banks From steve+comp.lang.python at pearwood.info Sat May 28 01:40:15 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 May 2011 05:40:15 GMT Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de08abe$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 20:02:39 -0500, harrismh777 wrote: > But the true picture is that 3.x is (way better) and completely > incompatible with 2.x. Lying about this isn't helpful to anyone coming > on board with Python. Just tell them the truth... Take your own advice and stop accusing others of lying when it is you spreading falsehoods about Python 3. It is simply NOT TRUE that Python 3 is "completely incompatible" with Python 2. You keep making this accusation, but even the most cursory look at Python syntax, keywords, built-in objects, execution model, and standard library show that most things keep the same interface, and most of the remainder change in backward compatible ways. There are some backwards incompatibilities, but nearly all of them can be resolved by an automated fixer, no human intelligence required. Far from being "completely incompatible", the truth is that Python 2.7 and 3.2 are more like 99% compatible. This is why there are 168 identical .py files in the Python 2.7 and 3.2a standard libraries. [steve at sylar ~]$ diff -rqbs --exclude="*.py[co]" /usr/local/lib/ python2.7/ /usr/local/lib/python3.2/ | grep identical | grep \\.py | wc -l 168 Calling Python 2 and Python 3 "different languages", as you have done, is simply wrong. Lisp and Python are different languages; Ruby and Python are different languages. Forth and Python are different languages. Python 2 and 3 are not. They are the same language that share nearly everything in common but have a few significant differences. Calling them "completely incompatible" is completely inaccurate. -- Steven From davids at webmaster.com Sat May 28 01:56:42 2011 From: davids at webmaster.com (David Schwartz) Date: Fri, 27 May 2011 22:56:42 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: On May 20, 12:00?am, Jonathan de Boyne Pollard wrote: > Indeed. And the algorithms that are employed to perform the operations > so described are recursive. Actually, they almost never are. Iterative algorithms are almost always used to avoid a stack explosion. However, the terminology is still correct. When you are asked if the operation should be performed recursively, it is asking whether you want the same effect you would get if a recursive algorithm was used. Essentially, there is an implied 'as if' rule. The user doesn't care how the program accomplishes the task, the user just needs to specify what task the program should accomplish. This is common throughout the discipline of programming. (Most standards have an explicit 'as if' rule that says that when the standard specifies X, they don't literally mean that X must happen. They mean the behavior must be indistinguishable from X happening.) DS From steve+comp.lang.python at pearwood.info Sat May 28 02:15:52 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 May 2011 06:15:52 GMT Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 May 2011 15:40:53 -0500, harrismh777 wrote: > Steven D'Aprano wrote: >> Would you care to revise your claims? > > No. > > > You have erected a straw-man... once again. You keep using that term, but it is clear to me that you don't have the foggiest idea of what the straw-man fallacy is. A straw man is not when somebody points out holes in your argument, or unwanted implications that you didn't realise were there. It is when somebody makes claims on your behalf that you did not make to discredit you, not because you don't understand the implications of your own argument. You stated that Python 2 and Python 3 are COMPLETELY INCOMPATIBLE -- your words, not mine. You have repeated that claim, in this very post, and others, despite having been shown that they are not completely incompatible at all, that it is possible to write both forward and backward compatible code that works in every version of Python from 1.5 through 3.2 inclusive. Yes, it is true that you can also write code that works in 2.5 but not 3.2, but so what? You can also write code that works in 2.5 but not 2.6: raise "some error" # works in 2.5 and older Or 2.4 and 2.5: True = 23 # works in 2.4 and older or 2.3 and 2.4: None = 42 # works in 2.3 and older Do you think that Python 2.3, 2.4, 2.5 and 2.6 are four completely different languages, and if not, why not? Python 3 is not the first backwards incompatible version of Python. [...] > All of these things are for the better, I must add. But, the point is > that 3.x is completely incompatible with 2.x in real ways. And you've done it again, despite the fact that you can write compatible code that works in all versions of Python from 1.5 to 3.2, and easily write non-trivial code that works in 2.7 and 3.2. For larger projects, it's probably better to keep a separate 2.x and 3.x fork, but that's for convenience, nothing more: numpy, for example, supports 2 and 3 out of a single code base. http://www.mail-archive.com/numpy-discussion%40scipy.org/msg26524.html Perhaps you don't understand what "completely" means and are confusing it with "slightly". -- Steven From thorsten at thorstenkampe.de Sat May 28 02:38:54 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 28 May 2011 08:38:54 +0200 Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Thomas Rachel (Sat, 28 May 2011 07:06:53 +0200) > Am 27.05.2011 17:52 schrieb Steven D'Aprano: > > On Fri, 27 May 2011 09:40:53 -0500, harrismh777 wrote: > >> 3.x is completely incompatible with 2.x (some call it a dialect, > >> but that is a lie). > > > > "Completely incompatible"? A "lie"? > > Hard word, but it is true. Many things can and will fall on your feet > when moving. I think we should stop talking about (in)compatability because everyone seems to associate something different with that term (incompatible = "no Python2 to code will run with Python3", "not all Python2 code will run with Python3"). The question is: if you want (or have) to run your code under Python3, how likely is that it will run unmodified? My experience is: unless the code is especially written with Python3 compatability or just a short snippet, it's actually quite unlikely that it will run. I modified three programs/modules (none of them written with Python3 in mind - I was thinking that Python 3000 would come out some day after Perl 6, PHP 6 and GNU Hurd; how could I know that the Python developers actually mean business?) One is a tool box kind of module. I had to insert lots of "list()" and add a complete function that would deal with the different behaviour of "sort". Probably easy to find the problems if you have extensive unit tests but without it was a tedious nightmare. The second a kind of script template. gettext.install has no "unicode = True". Easy fix but I wondered why Python 3 does not ignore the keyword simply. The third, a more real world complete application using PyQt. Took me about a day to fix. The problem was not just with the code but also with the tools (pyuic4, pyrcc4). Without the PyQt mailing list this wouldn't have been possible. Still: a complete workday (or even more) for 150 lines of code. Thorsten From thorsten at thorstenkampe.de Sat May 28 02:42:21 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 28 May 2011 08:42:21 +0200 Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Thorsten Kampe (Sat, 28 May 2011 08:38:54 +0200) > My experience is: unless the code is especially written with Python3 > compatability [...] Oops, I meant "unless the code is specifically written with Python3 compatability in mind [...]" Thorsten From rosuav at gmail.com Sat May 28 02:44:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 May 2011 16:44:47 +1000 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 28, 2011 at 4:38 PM, Thorsten Kampe wrote: > The question is: if you want (or have) to run your code under Python3, > how likely is that it will run unmodified? My experience is: unless the > code is especially written with Python3 compatability or just a short > snippet, it's actually quite unlikely that it will run. > But what about the 2to3 tool? If you use that, then how much more is there to deal with? I installed Python 3 and found that a little bandwidth monitor stopped working. After running it through 2to3, there were only a couple of things needing fixing, including the HTTPS library (it didn't like my Unicode strings, I had to go b" " for them), but the bulk of it was fine. Chris Angelico From __peter__ at web.de Sat May 28 03:41:55 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 28 May 2011 09:41:55 +0200 Subject: changing current dir and executing a shell script References: Message-ID: Albert Hopkins wrote: > On Fri, 2011-05-27 at 14:25 -0700, suresh wrote: >> I want to execute the following command line stuff from inside python. >> $cd directory >> $./executable >> >> I tried the following but I get errors >> import subprocess >> subprocess.check_call('cd dir_name;./executable') >> >> Due to filename path issues, I cannot try this version. >> subprocess.check_call('./dir_name/executable') > You don't want to do this because "cd" is a built-in shell command, and > subprocess does not execute within a shell (by default). The problem is not that cd is built-in, but that there is no shell at all. You can change that with shell=True: >>> subprocess.check_call("cd /usr/share; pwd; cd /usr/lib; pwd", shell=True) /usr/share /usr/lib But I agree with you that > The proper way to do this is to use the "cwd" keyword argument to > subprocess calls, i.e.: > >>>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir") From steve+comp.lang.python at pearwood.info Sat May 28 04:13:52 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 May 2011 08:13:52 GMT Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de0aebf$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 28 May 2011 08:38:54 +0200, Thorsten Kampe wrote: > * Thomas Rachel (Sat, 28 May 2011 07:06:53 +0200) >> Am 27.05.2011 17:52 schrieb Steven D'Aprano: >> > On Fri, 27 May 2011 09:40:53 -0500, harrismh777 wrote: >> >> 3.x is completely incompatible with 2.x (some call it a dialect, but >> >> that is a lie). >> > >> > "Completely incompatible"? A "lie"? >> >> Hard word, but it is true. Many things can and will fall on your feet >> when moving. > > I think we should stop talking about (in)compatability because everyone > seems to associate something different with that term (incompatible = > "no Python2 to code will run with Python3", "not all Python2 code will > run with Python3"). There is a difference between "completely incompatible" and merely "incompatible to some degree". It just takes *one* tiny incompatibility to stop a program running, so "will it run unmodified?" is hardly a good measure of the degree of incompatibility. Python 2.5 and 2.6 are incompatible to some degree. I recently had to port a client's program from 2.3 to 2.6. I did it in two steps: about two hours to get it working in 2.5, then the same to get it working in 2.6, and then about a day of effort to iron out all the display issues in Tkinter (such as text being shown in giant letters). Judging by the binary Yes/No "does it run unmodified?" test, I'd have to say that Python 2.3, 2.5 and 2.6 are "completely different" -- which would be foolish. Nobody sensible applies such a simple-minded, overly strict test to minor releases, or even between major releases like 1.5 versus 2.0. What would be the point? It is not the least bit helpful to learn that your 2.3 code doesn't run unmodified in 2.6. (Learning that it does, on the other hand, is useful. But such code is in a minority.) And yet some people are willing to throw commonsense away and apply such an obviously unsuitable test to Python 3. These people vehemently insist that the differences between Python 2.7 and 3.2 are of the same qualitative kind as between Ruby and PHP (they're *different languages* you see, not merely different dialects of the same language, and anyone who tells you different is not just mistaken but *lying*). > The question is: if you want (or have) to run your code under Python3, > how likely is that it will run unmodified? That's not a useful question. The useful question is to ask how much effort is it to make the code run in the new version. The effort might be zero (but probably isn't), or it might be a minute, or an hour, or a day, or six months... that depends partly on the complexity of your code and partly on the differences between Python 2.x and 3.x. A trivial app might take three minutes to port from Python 2.5 to 3.2. A complicated app might take three months to port from 2.5 to 2.6. What generalization do we make from this? > My experience is: unless the > code is especially written with Python3 compatability or just a short > snippet, it's actually quite unlikely that it will run. You describe taking a full day to upgrade a 150 line PyQt application. Only it wasn't a 150 line application, was it? By your own admission, much of the problems were in the library, PyQt, so it was more like 150,000 lines. (Or whatever the size of PyQt is...) Rather than "it took a full day to upgrade 150 lines to use Python 3, that's terrible!", it is more like "it only took a day to upgrade my 150 line app *and* work around a whole lot of problems with a huge library, that's really great!" -- Steven From greg.ewing at canterbury.ac.nz Sat May 28 04:30:15 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 28 May 2011 20:30:15 +1200 Subject: The worth of comments In-Reply-To: References: Message-ID: <94bq4pFoadU1@mid.individual.net> Grant Edwards wrote: > After hearing/reading somebody for years, I don't seem to have a > detailed image of them in my head, but when I finally do see a picture > of them, my initial reaction is almost always "no, that's not at all > what I thought he/she looked like". It works the other way, too. I've known what Terry Pratchett looks like for many years from the pictures on his books. When I heard him on the radio for the first time recently, I thought, "Wait a minute, that's not what his voice is supposed to sound like!" -- Greg From usenet at solar-empire.de Sat May 28 05:55:34 2011 From: usenet at solar-empire.de (Marc Christiansen) Date: Sat, 28 May 2011 11:55:34 +0200 Subject: GIL in alternative implementations References: <4DE015EA.4040600@gmail.com> Message-ID: Daniel Kluev wrote: > test.py: > > from threading import Thread > class X(object): > pass > obj = X() > obj.x = 0 > > def f(*args): > for i in range(10000): > obj.x += 1 > > threads = [] > for i in range(100): > t = Thread(target=f) > threads.append(t) > t.start() > > for t in threads: > while t.isAlive(): > t.join(1) > > print(obj.x) > >> python test.py > 1000000 >> pypy test.py > 1000000 >> jython-2.5 test.py > 19217 >> ipy test.py > 59040 > > Not that this thing is reasonable to do in real code, but cpython and > other implementations with GIL at least give you some safety margin. > Sure? ;) > for p in python2.4 python2.5 python2.6 python2.7 python3.1 python3.2; do echo $p; $p /tmp/test.py; $p /tmp/test.py; done python2.4 525369 736202 python2.5 449496 551023 python2.6 903405 937335 python2.7 885834 910144 python3.1 866557 766842 python3.2 1000000 1000000 So even CPython (at least < 3.2) isn't safe. And I wouldn't rely on 3.2 not to break. Marc From __peter__ at web.de Sat May 28 07:09:44 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 28 May 2011 13:09:44 +0200 Subject: GIL in alternative implementations References: <4DE015EA.4040600@gmail.com> Message-ID: Daniel Kluev wrote: >> So I'd like to know: how do these other implementations handle >> concurrency matters for their primitive types, and prevent them from >> getting corrupted in multithreaded programs (if they do) ? I'm not only >> thinking about python types, but also primitive containers and types used >> in .Net and Java VMs, which aren't atomic elements either at an >> assembly-level point of view. > > Well, they definitely have some shortcomings: > > test.py: > > from threading import Thread > class X(object): > pass > obj = X() > obj.x = 0 > > def f(*args): > for i in range(10000): > obj.x += 1 > > threads = [] > for i in range(100): > t = Thread(target=f) > threads.append(t) > t.start() > > for t in threads: > while t.isAlive(): > t.join(1) > > print(obj.x) > >> python test.py > 1000000 >> pypy test.py > 1000000 >> jython-2.5 test.py > 19217 >> ipy test.py > 59040 > > Not that this thing is reasonable to do in real code, but cpython and > other implementations with GIL at least give you some safety margin. The problem with your code is that it gives the wrong result when a thread reads obj.x, then suspends, then another thread reads obj.x and finally both threads store the same value+1 back. That problem has nothing to do with the GIL which just prohibits that two threads can run at the same time, on different cores. It occurs because obj.x += 1 is not an atomic operation. That lack of atomicity should be obvious if you take a look at the byte-code: >>> def f(): ... obj.x += 1 ... >>> dis.dis(f) 2 0 LOAD_GLOBAL 0 (obj) 3 DUP_TOP 4 LOAD_ATTR 1 (x) 7 LOAD_CONST 1 (1) 10 INPLACE_ADD 11 ROT_TWO 12 STORE_ATTR 1 (x) 15 LOAD_CONST 0 (None) 18 RETURN_VALUE [Marc Christiansen] > So even CPython (at least < 3.2) isn't safe. And I wouldn't rely on 3.2 > not to break. I don't know why it /seems/ to work in 3.2 more often than in 2.x, but in general bugs that occur only sporadically are typical for multithreaded code... From wolfgang at rohdewald.de Sat May 28 07:16:30 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Sat, 28 May 2011 13:16:30 +0200 Subject: GIL in alternative implementations In-Reply-To: References: <4DE015EA.4040600@gmail.com> Message-ID: <201105281316.30715.wolfgang@rohdewald.de> On Samstag 28 Mai 2011, Marc Christiansen wrote: > And I wouldn't rely on 3.2 > not to break. it breaks too like it should, but only rarely like one out of 10 times i5:/pub/src/gitgames/kajongg/src$ python3.2 test.py 1000000 i5:/pub/src/gitgames/kajongg/src$ python3.2 test.py 1000000 i5:/pub/src/gitgames/kajongg/src$ python3.2 test.py 980000 i5:/pub/src/gitgames/kajongg/src$ python3.2 test.py 1000000 -- Wolfgang From cjw at ncf.ca Sat May 28 08:26:06 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 28 May 2011 08:26:06 -0400 Subject: Question about isodate In-Reply-To: <324535.36827.qm@web114716.mail.gq1.yahoo.com> References: <324535.36827.qm@web114716.mail.gq1.yahoo.com> Message-ID: On 26-May-11 07:48 AM, truongxuan quang wrote: > Hello list, > > I am installing and testing istSOS wrote base on Python with its > extension like gdal, isodate, easy istall, setuptool, psycopg. I have > already installed all these stuff when I was using method POST the error > appear is "_No module named mx.DateTime.ISO_" , could you please give me > your command and advice. > > Many thanks > > Quang > Does this help? http://www.google.com/url?sa=t&source=web&cd=1&ved=0CB0QFjAA&url=http%3A%2F%2Fwww.egenix.com%2Fproducts%2Fpython%2FmxBase%2FmxDateTime%2F&rct=j&q=mxdatetime&ei=eengTYf5MM6EtgfdzeSoBw&usg=AFQjCNEsnznUS1kZ_zAzbSxGlP2IF6BsTg&sig2=3GgXQ9caWtvHTwzZoJOBuQ&cad=rja Colin W. From bch.itbgcthate at gmail.com Sat May 28 08:27:52 2011 From: bch.itbgcthate at gmail.com (bch) Date: Sat, 28 May 2011 05:27:52 -0700 (PDT) Subject: and becomes or and or becomes and References: <4dd9aaac$0$29996$c3e8da3$5496439d@news.astraweb.com> <71ab1ccc-c2c0-474f-b7bb-1000754317e4@z13g2000prk.googlegroups.com> Message-ID: <22197160-095a-4285-8dc4-1814e00a8181@s41g2000prb.googlegroups.com> On May 23, 11:30?pm, rusi wrote: > On May 23, 5:30?am, Steven D'Aprano > > > +comp.lang.pyt... at pearwood.info> wrote: > > On Sun, 22 May 2011 15:39:33 -0700, Tim Roberts wrote: > > > Stef Mientki wrote: > > > >>must of us will not use single bits these days, but at first sight, this > > >>looks funny : > > > >>>>> a=2 > > >>>>> b=6 > > >>>>> a and b > > >>6 > > >>>>> a & b > > >>2 > > >>>>> a or b > > >>2 > > >>>>> a | b > > >>6 > > > > That IS funny. ?Interesting how a careful choice of arugments will fool > > > us. One of my favorite math jokes is like that. ?A teacher asked a > > > student to reduce the following fraction: > > > ? 16 > > > ?---- > > > ? 64 > > > > He says "all I have to do is cancel out the sixes, so the answer is > > > 1/4". > > > One of my favourite variations on this is by Abbott and Costello, where > > Costello proves that 13*7 = 28 in three different ways. > > >http://www.youtube.com/watch?v=rLprXHbn19I > > Ha Ha! [You're hired Steven] And of course, a programmer cannot tell the difference between Halloween and Christmas day. From roy at panix.com Sat May 28 08:37:11 2011 From: roy at panix.com (Roy Smith) Date: Sat, 28 May 2011 08:37:11 -0400 Subject: Why did Quora choose Python for its development? References: Message-ID: In article , Carl Banks wrote: > On Friday, May 27, 2011 6:47:21 AM UTC-7, Roy Smith wrote: > > One of the truly awesome things about the Python re library is that it > > lets you write complex regexes like this: > > > > pattern = r"""\b # beginning of line > > (?P\w+) # a word > > \s+ # some whitespace > > (?P=word)(?!\w) # the same word again > > """ > > Perl has the X flag as well, in fact I'm pretty sure Perl originated it. > Just saying. Heh. Didn't know that. I wish people would use it more. From darcy at druid.net Sat May 28 08:38:21 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 28 May 2011 08:38:21 -0400 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110528083821.e239a2b9.darcy@druid.net> On Sat, 28 May 2011 07:06:53 +0200 Thomas Rachel wrote: > > "Completely incompatible"? A "lie"? > > Hard word, but it is true. Many things can and will fall on your feet > when moving. > > There are very many subtle differences. The space between "Completely incompatible" and "many subtle differences" is about the size of the Grand Canyon. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rosuav at gmail.com Sat May 28 08:50:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 May 2011 22:50:40 +1000 Subject: and becomes or and or becomes and In-Reply-To: <22197160-095a-4285-8dc4-1814e00a8181@s41g2000prb.googlegroups.com> References: <4dd9aaac$0$29996$c3e8da3$5496439d@news.astraweb.com> <71ab1ccc-c2c0-474f-b7bb-1000754317e4@z13g2000prk.googlegroups.com> <22197160-095a-4285-8dc4-1814e00a8181@s41g2000prb.googlegroups.com> Message-ID: On Sat, May 28, 2011 at 10:27 PM, bch wrote: > And of course, a programmer cannot tell the difference between > Halloween and Christmas day. Well known, of course. But a lot of modern programmers don't speak octal, they only use another power-of-two base; it's as though someone's cast a hex on them. Chris Angelico From irmen.NOSPAM at xs4all.nl Sat May 28 09:09:52 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 28 May 2011 15:09:52 +0200 Subject: The worth of comments In-Reply-To: References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: <4de0f420$0$49047$e4fe514c@news.xs4all.nl> On 27-5-2011 19:53, Grant Edwards wrote: > On 2011-05-27, Irmen de Jong wrote: >> On 27-05-11 15:54, Grant Edwards wrote: >>> On 2011-05-27, Ben Finney wrote: >>>> Richard Parker writes: >>>> >>>>> On May 26, 2011, at 4:28 AM, python-list-request at python.org wrote: >>>>> >>>>>> My experience is that comments in Python are of relatively low >>>>>> usefulness. (For avoidance of doubt: not *zero* usefulness, merely >>>>>> low.) >>> >>> I've seen plenty of comments who's usefulness was not zero. It was >>> less than zero. >> >> Someone once taught me, "There is one thing worse than having no >> comments in the source code: having incorrect (or 'lying') comments >> in the code." >> >> Grant, I guess you hint at such comments? > > Yes. :) > > When trying to find a bug in code written by sombody else, I often > first go through and delete all of the comments so as not to be > mislead. > > The comments reflect what the author _thought_ the code did > _at_some_point_in_the_past_. What matters is what the code actually > does at the present. > I'm going to share this thread, and the funny slideshow about Uncomment your code, with my team at work :-) We're not a Python shop so I'm probably the only one reading this, but as usual there is a lot of wisdom going on in this newgroup that is not only applicable to Python. Irmen From nobody at nowhere.com Sat May 28 09:31:52 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 28 May 2011 14:31:52 +0100 Subject: and becomes or and or becomes and References: Message-ID: On Sun, 22 May 2011 15:39:33 -0700, Tim Roberts wrote: > That IS funny. Interesting how a careful choice of arugments will fool us. > One of my favorite math jokes is like that. A teacher asked a student to > reduce the following fraction: > 16 > ---- > 64 > > He says "all I have to do is cancel out the sixes, so the answer is 1/4". Not Python, but: #define SIX 1 + 5 #define NINE 8 + 1 ... printf("six times nine is: %d\n", SIX * NINE); From python at bdurham.com Sat May 28 09:34:03 2011 From: python at bdurham.com (python at bdurham.com) Date: Sat, 28 May 2011 09:34:03 -0400 Subject: The worth of comments In-Reply-To: <4de0f420$0$49047$e4fe514c@news.xs4all.nl> References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de0f420$0$49047$e4fe514c@news.xs4all.nl> Message-ID: <1306589643.10031.1457018105@webmail.messagingengine.com> Irmen, > I'm going to share this thread, and the funny slideshow about Uncomment your code, with my team at work :-) We're not a Python shop so I'm probably the only one reading this Same here! > but as usual there is a lot of wisdom going on in this new[s]group that is not only applicable to Python. +1 QOTW Malcolm From yuvaraj1302 at gmail.com Sat May 28 09:36:10 2011 From: yuvaraj1302 at gmail.com (YUVI RAJ) Date: Sat, 28 May 2011 06:36:10 -0700 (PDT) Subject: join this group Message-ID: <84e8bb36-868f-4145-9acd-b6bea11c9e03@l2g2000prg.googlegroups.com> http://123maza.com/65/Cape201/ From roy at panix.com Sat May 28 09:36:43 2011 From: roy at panix.com (Roy Smith) Date: Sat, 28 May 2011 09:36:43 -0400 Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: In article , Grant Edwards wrote: > When trying to find a bug in code written by sombody else, I often > first go through and delete all of the comments so as not to be > mislead. I've heard people say that before. While I get the concept, I don't like doing things that way myself. >> The comments reflect what the author _thought_ the code did > _at_some_point_in_the_past_. What matters is what the code actually > does at the present. I don't look at it that way. Most of the comments I write are to document interfaces, i.e. what the code is supposed to do. That's the contract between you and the code. If you call me with arguments that meet these conditions, this is what I promise I'll return to you (and what side effects I'll perform). One reasonable definition of a bug is something the code actually does which differs from the documented interface. Unless you know what the code is supposed to do, how can you possibly look at it and say whether it has a bug or not? For example, take this function: def foo(): l = [1, 2, 3] return l[3] Is this code correct? I'll bet most people would look at this and say, "I'm not sure what he had in mind, but whatever it was, this has to be a bug because he's indexing past the end of the list". Well, what if I showed you the interface contract: def foo(): "Raise IndexError. This is useful as a testing fixture." l = [1, 2, 3] return l[3] Now it's obvious that the function does exactly what it's supposed to do (even if it's not the best way to do it). From yuvaraj1302 at gmail.com Sat May 28 09:37:14 2011 From: yuvaraj1302 at gmail.com (YUVI RAJ) Date: Sat, 28 May 2011 06:37:14 -0700 (PDT) Subject: join this group Message-ID: <50317910-2307-4001-83b9-7556d6b00fc9@k3g2000prl.googlegroups.com> http://123maza.com/65/Cape201/ From ryan at rfk.id.au Sat May 28 09:42:18 2011 From: ryan at rfk.id.au (Ryan Kelly) Date: Sat, 28 May 2011 23:42:18 +1000 Subject: PyCon Australia 2011: Early Bird Closing Soon Message-ID: <1306590138.2129.20.camel@durian> Hi Everyone, A reminder that Early Bird Registrations for PyCon Australia 2011 will be closing soon. There are only a few days left to get your tickets at the discounted rate. PyCon Australia is Australia's only conference dedicated exclusively to the Python programming language, and will be held at the Sydney Masonic Center over the weekend of August 20 and 21. See below for more information and updates on: 1. Early-Bird Registration Closing Soon 2. Presentations Selected 3. More Sponsors Announced Please pass this message on to those you feel may be interested. Early-Bird Registration Closing Soon ==================================== Early-bird registration closes at the end of May, so you've only got a few days left to get your tickets at the special discounted rate. We offer three levels of registration for PyCon Australia 2011. Registration provides access to two full days of technical content presented by Python enthusiasts from around the country, as well as the new classroom track and a seat at the conference dinner. Full (Early Bird) - $165 This is the registration rate for regular attendees. We are offering a limited Early Bird rate for the first 50 registrations until the end of May. Once the early-bird period ends, Full Registration will be $198. Corporate - $440 If your company is paying for you to attend PyCon, please register at the corporate rate. You'll be helping to keep the conference affordable for all. Student - $44 For students able to present a valid student card we're offering this reduced rate, which does not include the conference dinner. All prices include GST. For more information or to register, please visit the conference website. Register here: http://pycon-au.org/reg Presentations Selected ====================== We have had a fantastic response to our Call For Proposals this year. While the detailed talk schedule is still being finalised, we are pleased to announce that the following presentations have been selected for the conference: Standard Talks: A Python on the Couch (Mark Rees) Behaviour Driven Development (Malcolm Tredinnick) Benchmarking stuff made ridiculously easy (Tennessee Leeuwenburg) Bytecode: What, Why, and How to Hack it (Ryan Kelly) Developing Scientific Software in Python (Duncan Gray) Fun with App Engine 1.5.0 (Greg Darke) Hosting Python Web Applications (Graham Dumpleton) How Python Evolves (and How You Can Help Make It Happen) (Nick Coghlan) Infinite 8-bit Platformer (Chris McCormick) Networking Libraries in Python. (Senthil Kumaran) Pants - Network Programming Made Easy (Evan Davis) Say What You Mean: Meta-Programming a Declarative API (Ryan Kelly) State of CPython and Python Ecosystem (Senthil Kumaran) Sysadmins vs Developers, a take from the other side of the fence (Benjamin Smith) Teaching Python to the young and impressionable (Katie Bell) The NCSS Challenge: teaching programming via automated testing (Tim Dawborn) Weather field warping using Python. (Nathan Faggian) Zookeepr: Home-grown conference management software (Brianna Laugher) In-Depth Talks: Ah! I see you have the machine that goes "BING"! (Graeme Cross) Easy site migration using Diazo and Funnelweb (Adam Terrey) How to maintain big app stacks without losing your mind (Dylan Jay) Introduction to the Geospatial Web with GeoDjango (Javier Candeira) Panel: Python 3 (Richard Jones) Panel: Python in the webs (Richard Jones) Pyramid: Lighter, faster, better web apps (Dylan Jay) Web micro-framework battle (Richard Jones) Classroom Track: Meta-matters: using decorators for better Python programming (Graeme Cross) Python 101+ (Peter Lovett) Python's dark corners - the bad bits in Python and how to avoid them (Peter Lovett) Python for Science and Engineering, Part 1 (Edward Schofield) Python for Science and Engineering, Part 2 (Edward Schofield) The Zen of Python (Richard Jones) Thanks again to everyone who submitted a proposal. More Sponsors Announced ======================= We are delighted to announce that WingWare and Superior Recruitment have joined as Silver Sponsors. Thank you to the following companies for their continuing support of Python and for helping to make PyCon Australia 2011 a reality: Gold: Google Gold: ComOps Silver: Anchor Silver: Enthought Silver: Python Software Foundation Silver: WingWare Silver: Superior Recruitment Thanks also to Linux Australia, who provide the overarching legal and organisational structure for PyCon Australia. Ryan Kelly PyCon Australia 2011 From rosuav at gmail.com Sat May 28 10:02:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 00:02:57 +1000 Subject: The worth of comments In-Reply-To: References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: On Sat, May 28, 2011 at 11:36 PM, Roy Smith wrote: > def foo(): > ? "Raise IndexError. ?This is useful as a testing fixture." > ? l = [1, 2, 3] > ? return l[3] A quite useful thing, on occasion. I have a couple of variants of this, actually. In one of my C++ programs: extern char *death1; extern int death2; //Globals for killing things with // further down, inside a function: case "death1": *death1=42; break; //Die by dereferencing NULL case "death2": return 42/death2; //Die by dividing by zero They were designed to verify the parent-process code that was meant to catch process termination and identify the cause, so I wanted two quite different ways of blowing up the program. (The variables were extern and defined in another file to ensure that the compiler couldn't outsmart me with a compilation error.) In the Python code, that would be unnecessary with the *list* type, but it might be of value with your own class (eg subclass of list). Although, I'd put that sort of thing into a dedicated unit testing section, where everyone _knows_ that you're trying to break stuff. Chris Angelico From rosuav at gmail.com Sat May 28 10:04:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 00:04:03 +1000 Subject: and becomes or and or becomes and In-Reply-To: References: Message-ID: On Sat, May 28, 2011 at 11:31 PM, Nobody wrote: > Not Python, but: > > ? ? ? ?#define SIX ?1 + 5 > ? ? ? ?#define NINE 8 + 1 > ? ? ? ?... > ? ? ? ?printf("six times nine is: %d\n", SIX * NINE); *AWESOME*!! That is brilliant! DNA FTW. ChrisA From irmen.NOSPAM at xs4all.nl Sat May 28 10:05:18 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 28 May 2011 16:05:18 +0200 Subject: The worth of comments In-Reply-To: References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: <4de1011f$0$49184$e4fe514c@news.xs4all.nl> On 28-5-2011 15:36, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> When trying to find a bug in code written by sombody else, I often >> first go through and delete all of the comments so as not to be >> mislead. > > I've heard people say that before. While I get the concept, I don't > like doing things that way myself. > >>> The comments reflect what the author _thought_ the code did >> _at_some_point_in_the_past_. What matters is what the code actually >> does at the present. > > I don't look at it that way. Most of the comments I write are to > document interfaces, i.e. what the code is supposed to do. That's the > contract between you and the code. If you call me with arguments that > meet these conditions, this is what I promise I'll return to you (and > what side effects I'll perform). I don't see how that is opposed to what Grant was saying. It's that these 'contracts' tend to change and that people forget or are too lazy to update the comments to reflect those changes. The comments you are writing, saying what the code is supposed to do, are only saying what the code is supposed to do at the moment in time that you were writing the comment and/or the code, are they not? > One reasonable definition of a bug is something the code actually does > which differs from the documented interface. Unless you know what the > code is supposed to do, how can you possibly look at it and say whether > it has a bug or not? For example, take this function: > > def foo(): > l = [1, 2, 3] > return l[3] > > Is this code correct? Unit tests should tell you. > I'll bet most people would look at this and say, > "I'm not sure what he had in mind, but whatever it was, this has to be a > bug because he's indexing past the end of the list". I do agree that reading just that piece of code without other information, makes me think that it is fishy. But: > Well, what if I > showed you the interface contract: > > def foo(): > "Raise IndexError. This is useful as a testing fixture." > l = [1, 2, 3] > return l[3] > > Now it's obvious that the function does exactly what it's supposed to do > (even if it's not the best way to do it). A month later the requirement changes: it should raise a ZeroDevisionError instead. Someone modifies the code but leaves the comment (for whatever reason). def foo(): "Raise IndexError. This is useful as a testing fixture." return 1//0 Unless there is a way to force people to update the code comment as well (which I'm not aware of.. Doctests? dunno...), you now have a comment that lies about the the intended working. In my opinion that is worse than what we had before (the function without comment). That being said, I do write code comments myself. Some of them are like notes, directed to future-me or other future readers (remember that we do this because blabla, don't change this to such-and-such because it will probably break xyz) and some of them are stating the contract of the code (like you wrote above, about documenting interfaces). I always try to avoid writing comments that duplicate the working of the code itself in pseudo code or text phrases. But humans make mistakes and forget things so after enough modifications my code probably contains lies as well... :( Irmen de Jong From nobody at nowhere.net.no Sat May 28 12:01:56 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 29 May 2011 00:01:56 +0800 Subject: How to catch a line with Popen Message-ID: Hello. I'm looking into subprocess.Popen docs. I've launch the program with its arguments and that's smooth. I'm expecting to read the output by *comunicate()* at every line that prgram may blow during the process, but the output is given only when the child process is ended. I'd like to process the lines to display an information in percentage during the running time of the child. Sorry but I'm poor of know-how, so I'm stuck over to find a clue. -- goto /dev/null From nagle at animats.com Sat May 28 12:39:08 2011 From: nagle at animats.com (John Nagle) Date: Sat, 28 May 2011 09:39:08 -0700 Subject: GIL in alternative implementations In-Reply-To: References: <4DE015EA.4040600@gmail.com> Message-ID: <4de1252d$0$2203$742ec2ed@news.sonic.net> On 5/27/2011 7:06 PM, Daniel Kluev wrote: >> So I'd like to know: how do these other implementations handle concurrency >> matters for their primitive types, and prevent them from getting corrupted >> in multithreaded programs (if they do) ? I'm not only thinking about python >> types, but also primitive containers and types used in .Net and Java VMs, >> which aren't atomic elements either at an assembly-level point of view. "+=" is not guaranteed to be atomic in most languages. Some C and C++ implementations have "atomic_inc", etc., which is guaranteed to execute as an atomic operation. How do most safe languages handle concurrency? For the unboxed primitive types, like numbers, the hardware handles it. For memory allocation, there's a lock. Most don't allow patching code on the fly. Concurrent garbage collection prevents deleting something if there's a pointer to it anywhere. This was all worked out for LISP and SELF decades ago. Python allows patching code while the code is executing. This implies a sizable performance penalty, and causes incredible complexity in PyPy. John Nagle From steve+comp.lang.python at pearwood.info Sat May 28 13:05:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 May 2011 17:05:16 GMT Subject: GIL in alternative implementations References: <4DE015EA.4040600@gmail.com> <4de1252d$0$2203$742ec2ed@news.sonic.net> Message-ID: <4de12b4b$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 28 May 2011 09:39:08 -0700, John Nagle wrote: > Python allows patching code while the code is executing. Can you give an example of what you mean by this? If I have a function: def f(a, b): c = a + b d = c*3 return "hello world"*d how would I patch this function while it is executing? -- Steven From bgreen at nycap.rr.com Sat May 28 14:57:10 2011 From: bgreen at nycap.rr.com (Uncle Ben) Date: Sat, 28 May 2011 11:57:10 -0700 (PDT) Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> Message-ID: <11eb08a3-9cea-462f-ad1b-bf01d53f687a@z13g2000yqg.googlegroups.com> On May 27, 5:33?pm, Ethan Furman wrote: > Lew Schwartz wrote: > > So, if I read between the lines correctly, you recommend Python 3? Does > > the windows version install with a development environment? > > Dabo, last I checked, uses wxPython, which uses wxWidgets (sp?), which > is not yet ported to Python 3. ?So if you got that route you'll need to > stay with 2.7. > > ~Ethan~ Just this past Tuesday, I blindly downloaded 3.1 and found that at the level I am workloing, all it took to get my 2.7 code to run was to put parens around the print arguments and double the slashes in integer division. I didn't even use the 2to3 automation. But I am a noob to Python, which is my tenth computer language. Maybe when I get more ambitious I will find more serious differences. From harrismh777 at charter.net Sat May 28 15:21:32 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 28 May 2011 14:21:32 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0XbEp.24071$oq.16802@newsfe17.iad> Ethan Furman wrote: > Um -- how can you have on the one hand "completely not compatible" and > on the other "code that can cross-execute on either version"? Great question ! .. .it has to do with education. ... if you learn 2.x (only) and attempt to program on the 3.x platform, (without helps, education, migration tools, etc) you will fail... and you will be frustrated. Why? 3.x is not compatible with 2.x knowledge. If you learn 3.2 (only) and attempt to program on 2.x you will fail, and you will be frustrated. Why? Because the two languages are different and incompatible. Now then, can you learn both?... sure. Can you migrate one to the other with enough knowledge and effort?... yup. Is it possible (with enough cleverness) to write code that will run on "both" without modification... yes... Are the two languages compatible? No! Where this really counts of course is real-world apps. It is relatively easy to write trivial code blocks that demonstrate that nothing has changed in 3.x/ ... and they are *all* misleading. The truth is that hundreds of details have changed making the two 'versions' actually different languages. If I use the '89 version (1) K&R to write a C program, and compile it on the current gcc without mods it will run. If I use the 2.5 python manual to write a python program and try to run it on 3.2 it will fail (for many, many reasons). This is my definition of completely incompatible. The two languages are different; period. The problem is that they "look" similar. :) kind regards, m harris From skunkworks at rikishi42.net Sat May 28 15:36:30 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Sat, 28 May 2011 21:36:30 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-25, Steven D'Aprano wrote: > I know many people who have no idea what a directory is, let alone a > subdirectory, unless it's the phone directory. They're non-computer > users. Once they start using computers, they quickly work out what the > word means in context, or they ask and get told, and then they've learned > a new word and never need ask again. This is a good thing. > > The idiom of "recursively delete" is no different. Of course some people > will have to learn a new term in order to make sense of it. So what? OK, but the addition of recursive, is not really usefull, is it? Deleting the directory says it, doesn't it? >> Do you know many people who incinerate leaves and branches in their >> garden? I burn them. > > I know many people who incinerate leaves in an incinerator. Or at least > they used to, until the government here banned it. It might only have > been a 44 gallon drum with holes punched in the side, but they still > called it an incinerator. > > I learned that word from my father, who left school at 14 to work in a > shoe shop. He isn't especially educated, doesn't read much beyond the > daily tabloid, and thinks Benny Hill is the height of wit. But he's not > an idiot and even at 72 is capable of learning new words. Is it that widespread? I figured most people woul speak of burning. OK, my bad if it is. >>> Do they need to know the words "microwave oven" when they could be >>> saying "invisible rays cooking thing"? >> >> The word oven has existed for ages, microwave is just a name for the >> type of oven. Not even a description, just a name. > > Why do you think they're called "microwave ovens" instead of "fizzbaz > ovens"? Could it possibly have something to do with the fact that they > cook with microwaves? > > So not actually "just a name" at all. It's a jargon description of the > implementation of the oven. True, but I meant that they just use it as a name. I don't think many people would actually try to find out what a microwave is. >>> I wonder whether physicists insist that cars should have a "go faster >>> pedal" because ordinary people don't need to understand Newton's Laws >>> of Motion in order to drive cars? >> >> Gas pedal. Pedal was allraedy known when the car was invented. The >> simple addition of gas solved that need. > > What's a gas pedal? Is that some strange American term for what most of > the English-speaking world knows as the accelerator? *wink* Oh, come one. I'm sure I've heard that often enough NOT to have imagined it. >> Oh, and it's break pedal, not descellarator. (sp?) > That would be brake, and decelerator. Sorry. But I actually have a excuse for those. (see below) ;-) >> I'm one of the 'people'. You say exposed to, I say bothered/bored with. > > You can't force people to learn new words, although you would be > surprised how even the most disinterested, lazy speaker manages to pick > up vocabulary without even being aware of it. I know, I'm one. > But nor do you have to pander to the slackers. They can learn the word, > or not, I don't care. If I'm writing for an audience of children, or > English as a second language, or the otherwise linguistically challenged, Third, actually. But I do try. ;-) > I'll simplify my vocabulary appropriately. For everyone else, I'll use an > ordinary adult vocabulary, and that includes the word "recursion" or > "recursive". It's hardly technical jargon -- I've found a discussion of > gangsta rap that uses it. Even children understand the concept of > recursion (self-reference). People put it in comedies like Blazing > Saddles and Space Balls! How difficult is it to put a name to the concept? > > >> I have nothing against the use of a proper, precise term. And that word >> can be a complex one with many, many sylables (seems to add value, >> somehow). >> >> But I'm not an academic, so I don't admire the pedantic use of terms >> that need to be explained to 'lay' people. > > Pedantic... that's another one of those academic words that need to be > explained to lay people, isn't it? As is academic itself, and in fact > "lay people". Who uses "lay people" in conversation? That (lay people) was atually a quote, from someone who actually used it in this thread. >> widespread, usually shorter and much simpler one for it. A pointless >> effort if pointless, even when comming from a physicist. :-) > > I think you *grossly* underestimate how many words people know, > particularly if you include so-called "passive vocabulary" (words people > can understand in context, but not define precisely). See, for example: > > http://www.worldwidewords.org/articles/howmany.htm Got a point, there. -- When in doubt, use brute force. -- Ken Thompson From rosuav at gmail.com Sat May 28 15:47:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 05:47:31 +1000 Subject: Beginner needs advice In-Reply-To: <0XbEp.24071$oq.16802@newsfe17.iad> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> Message-ID: On Sun, May 29, 2011 at 5:21 AM, harrismh777 wrote: > The problem is that they "look" similar. ? ? :) C looks like every other bracey language in the world. Is that a problem? According to Wikipedia, there's quite a lot of them: http://en.wikipedia.org/wiki/List_of_programming_languages_by_category#Curly-bracket_languages I would say that the difference between the difference between Python 2 and Python 3 and the difference between C and Javascript (there, parse THAT one without parentheses!) is that the latter have a fundamentally different data philosophy. Both versions of Python are the same language, because they "think" the same way; high level objects that can be multiply-referenced, and are disposed of when no longer needed. (That sounds like an implementation detail - refcounting - but I don't really care how it does it under the hood, as long as I can have multiple variables pointing to the same object, and have objects not need explicit deallocation.) Little syntactic differences like whether 'print' is a function or a statement, and whether the simple slash operator between two ints returns a float, and the fact that Unicode is the default string type, are comparatively minor; on 'most every philosophical point, the two dialects agree. Chris Angelico From python at rcn.com Sat May 28 15:55:20 2011 From: python at rcn.com (Raymond Hettinger) Date: Sat, 28 May 2011 12:55:20 -0700 (PDT) Subject: Class decorators might also be super too Message-ID: <1ef87095-2153-4c34-acf4-cfd1380bbcdd@z15g2000prn.googlegroups.com> David Beazley wrote a class decorator blog post that is worth reading: http://dabeaz.blogspot.com/2011/05/class-decorators-might-also-be-super.html Raymond From rosuav at gmail.com Sat May 28 15:58:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 05:58:01 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 29, 2011 at 5:36 AM, Rikishi42 wrote: > Is it [the term 'incinerate'] that widespread? I figured most people > woul speak of burning. OK, my bad if it is. I think it's geographic. This list covers a lot of geography; I'm in Australia, there are quite a few Brits, and probably the bulk of posts come from either the US or Europe. (And yes, I did deliberately fold all of Europe down to one entity, and I did also deliberately leave Great Britain out of that entity.) > True, but I meant that they just use it as a name. I don't think many people > would actually try to find out what a microwave is. Most things work out that way. A thing gets a name based either on its implementation or on the brand name of the first/most popular one. If the only microwave oven ever produced had been made by Foobar Corp, and that company were not known for anything else, then quite possibly everyone would call them "foobar ovens". >> Pedantic... that's another one of those academic words that need to be >> explained to lay people, isn't it? As is academic itself, and in fact >> "lay people". Who uses "lay people" in conversation? > > That (lay people) was atually a quote, from someone who actually used it in > this thread. "Lay person"/"lay people" is a fairly common expression, although "laity" (which ought to mean the same thing) seems only to have meaning in a church context (as in, the non-clergy). Geeks tend to have larger vocabularies than non-geeks, on average; probably akin to our love of word games and precision (two distinct notions that bridge surprisingly often). Chris Angelico From wbsoft at xs4all.nl Sat May 28 17:09:11 2011 From: wbsoft at xs4all.nl (Wilbert Berendsen) Date: Sat, 28 May 2011 23:09:11 +0200 Subject: bdist_wininst: install_script not run on uninstall In-Reply-To: <4DE0599C.9010103@skippinet.com.au> References: <201105252128.17504.wbsoft@xs4all.nl> <201105261000.04741.wbsoft@xs4all.nl> <4DE0599C.9010103@skippinet.com.au> Message-ID: <201105282309.11794.wbsoft@xs4all.nl> Op zaterdag 28 mei 2011 schreef Mark: > This is a bug in distutils/bdist_wininst - I just created > http://bugs.python.org/issue12200 with the details and your samples, and > sadly I can't think of a work around you can use until this is fixed > (which I might get to soon, but not this weekend...) Great that you found the cause of the bug! I looked for hours in the install.c but I didn't find it :-) Looking forward to a fix, which will make bdist_wininst much more usable! thanks! Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi From gsowww at yahoo.co.uk Sat May 28 17:25:43 2011 From: gsowww at yahoo.co.uk (GSO) Date: Sat, 28 May 2011 22:25:43 +0100 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: The beginning of wisdom is to call things by their right names. - Chinese Proverb (So I'm told at least, I'd check with the Chinese first though ;) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat May 28 17:28:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 07:28:47 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 29, 2011 at 7:25 AM, GSO wrote: > The beginning of wisdom is to call things by their right names. - Chinese > Proverb (So I'm told at least, I'd check with the Chinese first though ;) See, I thought it was "The fear of the Lord is the beginning of wisdom", but the Chinese don't worship Yahweh, so I guess they wouldn't say that. Proverbs chapter 9 verse 10, in any case. :) Chris Angelico yes, bit of a Bible geek as well as a programming geek From marduk at letterboxes.org Sat May 28 17:52:55 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 28 May 2011 17:52:55 -0400 Subject: changing current dir and executing a shell script In-Reply-To: References: Message-ID: <1306619575.87010.4.camel@localhost.localdomain> On Sat, 2011-05-28 at 09:41 +0200, Peter Otten wrote: > > You don't want to do this because "cd" is a built-in shell command, > and > > subprocess does not execute within a shell (by default). > > The problem is not that cd is built-in, but that there is no shell at > all. > You can change that with shell=True: This is exactly what I said, but using different words. From nobody at nowhere.com Sat May 28 18:15:06 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 28 May 2011 23:15:06 +0100 Subject: How to catch a line with Popen References: Message-ID: On Sun, 29 May 2011 00:01:56 +0800, TheSaint wrote: > I'm looking into subprocess.Popen docs. I've launch the program with its > arguments and that's smooth. I'm expecting to read the output by > *comunicate()* at every line that prgram may blow during the process, but > the output is given only when the child process is ended. .communicate() reads until EOF, .wait()s for the process to terminate, then returns the output as a pair of strings. If you want to read data while the process is running, use the process' .stdout and/or .stderr members, e.g.: p = subprocess.Popen(...) for line in p.stdout: ... p.wait() Don't forget to .wait() on the process when you're done, regardless of whether you actually need the exit code. From tjreedy at udel.edu Sat May 28 18:18:56 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 28 May 2011 18:18:56 -0400 Subject: Beginner needs advice In-Reply-To: <11eb08a3-9cea-462f-ad1b-bf01d53f687a@z13g2000yqg.googlegroups.com> References: <4DDC7938.5000900@gmail.com> <11eb08a3-9cea-462f-ad1b-bf01d53f687a@z13g2000yqg.googlegroups.com> Message-ID: On 5/28/2011 2:57 PM, Uncle Ben wrote: > Just this past Tuesday, I blindly downloaded 3.1 and found that at the > level I am workloing, all it took to get my 2.7 code to run was to put > parens around the print arguments and double the slashes in integer > division. I didn't even use the 2to3 automation. 1//2 works in 2.7 and earlier. from __future__ import division gives 1/2 == 0.5 and in 3.x print('abc') is the same as print 'abc' The parens only make a difference with 2 or more items. -- Terry Jan Reedy From rzantow at gmail.com Sat May 28 19:12:04 2011 From: rzantow at gmail.com (rzed) Date: Sat, 28 May 2011 23:12:04 +0000 Subject: Parse config file and command-line arguments, to get a single collection of options References: <87k4deaxfc.fsf@benfinney.id.au> Message-ID: Ben Finney wrote in news:87k4deaxfc.fsf at benfinney.id.au: > Howdy all, > > Python's standard library has modules for configuration file > parsing (configparser) and command-line argument parsing > (optparse, argparse). I want to write a program that does both, > but also: > > * Has a cascade of options: default option values, overridden by > config > file options, overridden by command-line options. > > * Reads a different, or even additional, configuration file if > specified > on the command-line (e.g. --config-file foo.conf) and yet still > obeys the above cascade. > > * Allows a single definition of an option (e.g. logging level) to > define > the same option for parsing from configuration files and the > command line. > > * Unifies the parsed options into a single collection for the > rest of > the program to access without caring where they came from. > > How can I achieve this with minimum deviation from the Python > standard library? > > > (For anyone interested in gaining StackOverflow points, I'm also > asking this as a question there so feel free to post answers on > that site > and-command-line-arguments-to-get-a-single-collection-of-optio>.) > This seems vaguely similar to a module I wrote and use all the time. It allows default value specification, categorization of command-line options, in-line parsing of further spec file[s] and overrides of values in the the sequence you define, pretty much. It doesn't deal with the "logging level" item. I'm not sure what that would mean. The idea of the module is to create a namespace object (though it could as easily be a dict) that contains whatever values are specified. in the program it would be invoked like this: ctx = Cmdline( outfname='test.out', size=(250,400), ... ) (or whatever). The command line can contain switches, prefixed by hyphens, spec file names, prefixed by @, untagged names, or key=value pairs. The values will be parsed as (tuples), [lists], or {dicts}, ints, floats, or strings. I did not, I am ashamed to say, resist the temptation to guess. 'Ctx' will contain the result of all this. Switches, if any are in a list named ctx._switches, unadorned arguments are in a list named ctx._vars, and the other stuff is pretty much as you would expect. It expects configuration files to be in a sort of ini-file format. Here's an example: --------------------------- test.spec: log=test.log count=10 size=(400,200) group1={key=value,a=alpha} group2={b=beta,name=doogie howser} # temp=[1,2,5,11,22] sub=(al,becky,carl,diane,edwin,fran) --------------------------- test.py: from Cmdline import Cmdline c = Cmdline( count=5, log='pink.tank') c.show() --------------------------- >python test.py log=friend.txt @test.spec count=32 name=waldo ... yields: count = 32 sub = ('al', 'becky', 'carl', 'diane', 'edwin', 'fran') log = 'test.log' temp = [1, 2, 5, 11, 22] group1 = {'a': 'alpha', 'key': 'value'} group2 = {'b': 'beta', 'name': 'doogie howser'} size = (400, 200) name = 'waldo' ... while >python @test.spec count=32 name=waldo temp=Vitalis sub='' dream -k count = 32 _vars = ['dream'] log = 'test.log' temp = 'Vitalis' _switches = ['k'] name = 'waldo' group1 = {'a': 'alpha', 'key': 'value'} group2 = {'b': 'beta', 'name': 'doogie howser'} size = (400, 200) sub = '' What the program does with the results is up to it, of course. -- rzed From news1234 at free.fr Sat May 28 19:23:18 2011 From: news1234 at free.fr (News123) Date: Sun, 29 May 2011 01:23:18 +0200 Subject: portable way of sending notifying a process Message-ID: <4de183e7$0$26108$426a74cc@news.free.fr> Hi, I'm looking for a portable way (windows XP / Windows Vista and Linux ) to send a signal from any python script to another one (one signa would be enough) I have several python scripts started from different parent processes occasionally some of the scripts want to tell another to reread it's config file ( kill -HUP) It seems, that neither the signals HUP / USR1 are implemented under windows. What would be a light weight portable way, that one process can tell another to do something? The main requirement would be to have no CPU impact while waiting (thus no polling) Thanks for any suggestion of small portable libraries or code snippets. The options, that I found so far seem to be a little too big or not portable: - sending the HUP signal doesn't work under win - inotify doesn't work under win - pyro seems to be a little too big for such a 'trivial' task - watchdog might be a solution, but requires three other non standard libraries to be installed. So I'm not sure it's really lightweight If nothing exists I might just write a wrapper around pyinotify and (Tim Goldens code snippet allowing to watch a directory for file changes) http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html and use a marker file in a marker directory but I wanted to be sure of not reinventing the wheel. From timr at probo.com Sat May 28 19:32:42 2011 From: timr at probo.com (Tim Roberts) Date: Sat, 28 May 2011 16:32:42 -0700 Subject: How to catch a line with Popen References: Message-ID: TheSaint wrote: > >I'm looking into subprocess.Popen docs. >I've launch the program with its arguments and that's smooth. I'm expecting >to read the output by *comunicate()* at every line that prgram may blow >during the process, but the output is given only when the child process is >ended. >I'd like to process the lines to display an information in percentage during >the running time of the child. Are you specifying a buffer size in the Popen command? If not, then the Python side of things is unbuffered. It's possible that the application you are launching is buffering its output, so that it doesn't SEND until the application ends. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python at mrabarnett.plus.com Sat May 28 19:41:16 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 29 May 2011 00:41:16 +0100 Subject: float("nan") in set or as key Message-ID: <4DE1881C.8000701@mrabarnett.plus.com> Here's a curiosity. float("nan") can occur multiple times in a set or as a key in a dict: >>> {float("nan"), float("nan")} {nan, nan} except that sometimes it can't: >>> nan = float("nan") >>> {nan, nan} {nan} From max at alcyone.com Sat May 28 20:16:50 2011 From: max at alcyone.com (Erik Max Francis) Date: Sat, 28 May 2011 17:16:50 -0700 Subject: float("nan") in set or as key In-Reply-To: References: Message-ID: MRAB wrote: > Here's a curiosity. float("nan") can occur multiple times in a set or as > a key in a dict: > > >>> {float("nan"), float("nan")} > {nan, nan} > > except that sometimes it can't: > > >>> nan = float("nan") > >>> {nan, nan} > {nan} It's fundamentally because NaN is not equal to itself, by design. Dictionaries and sets rely on equality to test for uniqueness of keys or elements. >>> nan = float("nan") >>> nan == nan False In short, don't do that. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis There was never a good war or a bad peace. -- Benjamin Franklin, 1706-1790 From steve+comp.lang.python at pearwood.info Sat May 28 20:26:07 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 00:26:07 GMT Subject: float("nan") in set or as key References: Message-ID: <4de1929f$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 00:41:16 +0100, MRAB wrote: > Here's a curiosity. float("nan") can occur multiple times in a set or as > a key in a dict: > > >>> {float("nan"), float("nan")} > {nan, nan} That's an implementation detail. Python is free to reuse the same object when you create an immutable object twice on the same line, but in this case doesn't. (I don't actually know if it ever does, but it could.) And since NAN != NAN always, you can get two NANs in the one set, since they're unequal. > when you write float('nan') > > except that sometimes it can't: > > >>> nan = float("nan") > >>> {nan, nan} > {nan} But in this case, you try to put the same NAN in the set twice. Since sets optimize element testing by checking for identity before equality, the NAN only goes in once. -- Steven From marduk at letterboxes.org Sat May 28 20:28:46 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 28 May 2011 20:28:46 -0400 Subject: float("nan") in set or as key In-Reply-To: <4DE1881C.8000701@mrabarnett.plus.com> References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: <1306628926.168355.5.camel@localhost.localdomain> On Sun, 2011-05-29 at 00:41 +0100, MRAB wrote: > Here's a curiosity. float("nan") can occur multiple times in a set or as > a key in a dict: > > >>> {float("nan"), float("nan")} > {nan, nan} > These two nans are not equal (they are two different nans) > except that sometimes it can't: > > >>> nan = float("nan") > >>> {nan, nan} > {nan} This is the same nan, so it is equal to itself. Two "nan"s are not equal in the manner that 1.0 and 1.0 are equal: >>> 1.0 == 1.0 True >>> float("nan") == float("nan") False I can't cite this in a spec, but it makes sense (to me) that two things which are nan are not necessarily the same nan. From timothy.c.delaney at gmail.com Sat May 28 20:29:42 2011 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Sun, 29 May 2011 10:29:42 +1000 Subject: float("nan") in set or as key In-Reply-To: References: Message-ID: On 29 May 2011 10:16, Erik Max Francis wrote: > MRAB wrote: > >> Here's a curiosity. float("nan") can occur multiple times in a set or as a >> key in a dict: >> >> >>> {float("nan"), float("nan")} >> {nan, nan} >> >> except that sometimes it can't: >> >> >>> nan = float("nan") >> >>> {nan, nan} >> {nan} >> > > It's fundamentally because NaN is not equal to itself, by design. > Dictionaries and sets rely on equality to test for uniqueness of keys or > elements. > > > >>> nan = float("nan") > >>> nan == nan > False > > In short, don't do that. There's a second part the mystery - sets and dictionaries (and I think lists) assume that identify implies equality (hence the second result). This was recently discussed on python-dev, and the decision was to leave things as-is. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat May 28 20:32:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 10:32:43 +1000 Subject: float("nan") in set or as key In-Reply-To: <1306628926.168355.5.camel@localhost.localdomain> References: <4DE1881C.8000701@mrabarnett.plus.com> <1306628926.168355.5.camel@localhost.localdomain> Message-ID: On Sun, May 29, 2011 at 10:28 AM, Albert Hopkins wrote: > This is the same nan, so it is equal to itself. > Actually, they're not. But it's possible the dictionary uses an 'is' check to save computation, and if one thing 'is' another, it is assumed to equal it. That's true of most well-behaved objects, but nan is not well-behaved :) Chris Angelico From drsalists at gmail.com Sat May 28 20:37:19 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 28 May 2011 17:37:19 -0700 Subject: How to catch a line with Popen In-Reply-To: References: Message-ID: On Sat, May 28, 2011 at 4:32 PM, Tim Roberts wrote: > TheSaint wrote: > > > >I'm looking into subprocess.Popen docs. > >I've launch the program with its arguments and that's smooth. I'm > expecting > >to read the output by *comunicate()* at every line that prgram may blow > >during the process, but the output is given only when the child process is > >ended. > >I'd like to process the lines to display an information in percentage > during > >the running time of the child. > > Are you specifying a buffer size in the Popen command? If not, then the > Python side of things is unbuffered. It's possible that the application > you are launching is buffering its output, so that it doesn't SEND until > the application ends. > I believe there are 4 normal ways, and 1 special way of getting output from a buffered application: 1) As you mentioned, the program could terminate 2) Also, the program could just have written enough to fill its buffer, so it outputs the content of the buffer before starting to fill it again 3) Also, the program could call flush 4) Also, the program could use an unbuffered file, like stderr - not all file in an application are astonishingly likely to be buffered the same way And the special one: 1) Sometimes you can take a buffered program and get it to be unbuffered (or at least line buffered) by running it on a pty. -------------- next part -------------- An HTML attachment was scrubbed... URL: From max at alcyone.com Sat May 28 20:44:56 2011 From: max at alcyone.com (Erik Max Francis) Date: Sat, 28 May 2011 17:44:56 -0700 Subject: float("nan") in set or as key In-Reply-To: References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: Albert Hopkins wrote: > On Sun, 2011-05-29 at 00:41 +0100, MRAB wrote: >>>> 1.0 == 1.0 > True >>>> float("nan") == float("nan") > False > > I can't cite this in a spec, but it makes sense (to me) that two things > which are nan are not necessarily the same nan. It's part of the IEEE standard. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis There was never a good war or a bad peace. -- Benjamin Franklin, 1706-1790 From greg.ewing at canterbury.ac.nz Sat May 28 20:47:52 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 29 May 2011 12:47:52 +1200 Subject: The worth of comments In-Reply-To: <4de1011f$0$49184$e4fe514c@news.xs4all.nl> References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> Message-ID: <94djdoFt6U1@mid.individual.net> Irmen de Jong wrote: > I don't see how that is opposed to what Grant was saying. It's that these 'contracts' > tend to change and that people forget or are too lazy to update the comments to reflect > those changes. However, I can't see that deleting the comment documenting the contract can be the right response to the situation. If the contract comment doesn't match what code does, then there are two possibilities -- the comment is wrong, or the code is wrong. The appropriate response is to find out which one is wrong and fix it. If you simply delete the comment, then you're left with no redundancy to catch the fact that something is wrong. -- Greg From steve+comp.lang.python at pearwood.info Sat May 28 20:49:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 00:49:01 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de197fd$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 05:58:01 +1000, Chris Angelico wrote: > Geeks tend to have larger vocabularies than non-geeks, on average; > probably akin to our love of word games and precision (two distinct > notions that bridge surprisingly often). And also because more educated people in general tend to have larger vocabularies than less educated people: both for the number of words they actually use, and those they can interpret in context. Geeks sometimes tend to forget that they're not the only smart, educated people who use "hard" (big, technical, complicated) words. -- Steven From greg.ewing at canterbury.ac.nz Sat May 28 21:04:32 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 29 May 2011 13:04:32 +1200 Subject: float("nan") in set or as key In-Reply-To: References: Message-ID: <94dkd3F7k4U1@mid.individual.net> MRAB wrote: > float("nan") can occur multiple times in a set or as > a key in a dict: > > >>> {float("nan"), float("nan")} > {nan, nan} > > except that sometimes it can't: > > >>> nan = float("nan") > >>> {nan, nan} > {nan} NaNs are weird. They're not equal to themselves: Python 2.7 (r27:82500, Oct 15 2010, 21:14:33) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> nan = float("nan") >>> nan == nan False This confuses the daylights out of Python's dict lookup machinery, which assumes that two references to the same object can't possibly compare unequal, so it doesn't bother calling __eq__ on them. -- Greg From ben+python at benfinney.id.au Sat May 28 21:41:44 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 29 May 2011 11:41:44 +1000 Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> Message-ID: <877h9a9tbb.fsf@benfinney.id.au> Gregory Ewing writes: > If the contract comment doesn't match what code does, then there are > two possibilities -- the comment is wrong, or the code is wrong. The > appropriate response is to find out which one is wrong and fix it. You omit the common third possibility: *both* the comment and the code are wrong. That's the one that I bet on whenever I notice code and comment don't match. -- \ ?Anyone can do any amount of work provided it isn't the work he | `\ is supposed to be doing at the moment.? ?Robert Benchley | _o__) | Ben Finney From irmen.NOSPAM at xs4all.nl Sat May 28 21:49:22 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 29 May 2011 03:49:22 +0200 Subject: The worth of comments In-Reply-To: <94djdoFt6U1@mid.individual.net> References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> Message-ID: <4de1a624$0$49178$e4fe514c@news.xs4all.nl> On 29-5-2011 2:47, Gregory Ewing wrote: > Irmen de Jong wrote: > >> I don't see how that is opposed to what Grant was saying. It's that these 'contracts' >> tend to change and that people forget or are too lazy to update the comments to reflect >> those changes. > > However, I can't see that deleting the comment documenting the > contract can be the right response to the situation. > > If the contract comment doesn't match what code does, then > there are two possibilities -- the comment is wrong, or the > code is wrong. The appropriate response is to find out which > one is wrong and fix it. Fair enough. Certainly I won't be deleting every source code comment encountered from now on, but I do think we should keep in mind the risks already mentioned. In some situations I can very well imagine it is best to simply delete any comments and go with just the code. > If you simply delete the comment, then you're left with no > redundancy to catch the fact that something is wrong. You are right, if you don't have a Unit test for it. Then again, faulty unit tests are a problem in their own right... Irmen de Jong From harrismh777 at charter.net Sat May 28 22:02:47 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 28 May 2011 21:02:47 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> Message-ID: Chris Angelico wrote: > Both versions of Python are > the same language, because they "think" the same way; I appreciate your thought. And there is an obvious continuity in philosophy between 2.x and 3.x; in fact even a cursory study of the history of python demonstrates a concerted effort to build on the best points of 2.x while eliminating the worst. 3.x builds upon and adds to 2.x, as (loosely) C++ builds on and adds to C. Perhaps python3 should have been named Python+ ! ( I think I've already told yous guys that I invoke python3 on my desk machine with--- Anaconda I see your point. But, knowing that 3.x "thinks" like 2.x is not helpful when we all know that languages don't think, people do. People need to be able to understand the 'details' of the language in order to be able to think with it... > Little syntactic > differences like whether 'print' is a function or a statement, and > whether the simple slash operator between two ints returns a float, > and the fact that Unicode is the default string type, are > comparatively minor; on 'most every philosophical point, the two > dialects agree. Minor, yes, .... until you need to make something work--- only to be frustrated to find that a detail that was not expected has risen to bite a sensitive place... :) I am amazed at how many folks are not using 3.x/ Why? (beats me), but how do I know they're not using it...? Because, if they were trying to use it with 2.x knowledge they would be complaining bloody murder.. for instance, how do we reload a module in 2.x... with, um, reload. This has always been the way... every book says so, and every one of us has re-invoked a .py file by using relaod. Reload doesn't even work on 3.x without an import. If you don't know that, well, you're sol until you figure it out, read it, or somebody tells you. This ought not to be. Even the environments of these two languages are incompatible (partially) :) PS Something nobody has pointed out yet is that "completely incompatible" is redundant. ... its like saying totally destroyed. I was trying to be funny, but nobody unpinned it... I'm disappointed. Some of the posts here are referring to the two languages as partially incompatible.... reminds me of that line from Princess Bride... "... he's not dead, hes only mostly dead!... and mostly dead is partly alive!" To say that 3.x is partly compatible with 2.x is silly, but to say that 3.x 'thinks' the same way as 2.x is almost pythonesque... I almost like that... :) kind regards, m harris From invalid at invalid.invalid Sat May 28 22:25:55 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 29 May 2011 02:25:55 +0000 (UTC) Subject: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: On 2011-05-29, Albert Hopkins wrote: > On Sun, 2011-05-29 at 00:41 +0100, MRAB wrote: >> Here's a curiosity. float("nan") can occur multiple times in a set or as >> a key in a dict: >> >> >>> {float("nan"), float("nan")} >> {nan, nan} >> > These two nans are not equal (they are two different nans) > >> except that sometimes it can't: >> >> >>> nan = float("nan") >> >>> {nan, nan} >> {nan} > > This is the same nan, so it is equal to itself. No, it's not. >>> x = float("nan") >>> y = x >>> x is y True >>> x == y False > I can't cite this in a spec, but it makes sense (to me) that two things > which are nan are not necessarily the same nan. Even if they _are_ the same nan, it's still not equal to itself. -- Grant From rosuav at gmail.com Sat May 28 22:26:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 May 2011 12:26:34 +1000 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> Message-ID: On Sun, May 29, 2011 at 12:02 PM, harrismh777 wrote: > Chris Angelico wrote: >> Both versions of Python are >> the same language, because they "think" the same way; > ? ? I see your point. But, knowing that 3.x "thinks" like 2.x is not helpful > when we all know that languages don't think, people do. I was being (deliberately) sloppy with the English language there, but I was referring to the fundamental philosophies of Python, which are common across both versions (and, presumably, most/all of them can be seen in Python 1 too; I've never used Python 1). >> Little syntactic >> differences like whether 'print' is a function or a statement, and >> whether the simple slash operator between two ints returns a float, >> and the fact that Unicode is the default string type, are >> comparatively minor; on 'most every philosophical point, the two >> dialects agree. > > ? Minor, yes, .... until you need to make something work--- only to be > frustrated to find that a detail that was not expected has risen to bite a > sensitive place... ? :) I get far worse than those when I switch between languages and forget operator precedence, or forget that function X has its parameters the other way around, or whatever. They are minor, and if you're not 100% familiar with the language you're writing in, you should probably have its docs handy anyway. The print function will bite you instantly, you'll know what's wrong as soon as you try to run it. Unicode strings, too, will usually throw a nice tidy exception. The only one that's going to really sting you is division, and it's so easy to deal with that one as you code (always use // for flooring). > instance, how do we reload a module in 2.x... ?with, um, reload. ? This has > always been the way... every book says so, and every one of us has > re-invoked a .py file by using relaod. ?Reload doesn't even work on 3.x > without an import. >From what I gather, Python simply isn't designed with that sort of "live reload" in mind. Just terminate it and start over, it's easier. If you want a system where you reload parts of it without bringing things down, either build it manually (loading another piece of code, and maybe reassigning some state variables that have your functions), or pick a different language - Pike does this excellently. That's not an indictment of Python; it's simply that Python is not everything. > Some of the posts here are referring to the two languages as partially > incompatible.... ? reminds me of that line from Princess Bride... "... he's > not dead, hes only mostly dead!... and mostly dead is partly alive!" ?To say > that 3.x is partly compatible with 2.x is silly, but to say that 3.x > 'thinks' the same way as 2.x is almost pythonesque... ?I almost like that... Mostly compatible is still partly incompatible? Sure. But "mostly compatible" is Python 2.6.6 and Python 2.7.1, too. It's easy to write one codebase that runs under multiple Python versions; certainly it's a lot easier than writing one source file that's both Python and C, for instance. And the same lines of code will be doing the same work (unlike most polyglottisms, where one language's code is another language's comments). There is a subset of Python 2 that is also a subset of Python 3, and this intersection is quite large. Chris Angelico From harrismh777 at charter.net Sat May 28 22:33:33 2011 From: harrismh777 at charter.net (harrismh777) Date: Sat, 28 May 2011 21:33:33 -0500 Subject: Beginner needs advice In-Reply-To: <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2giEp.236$QL2.62@newsfe04.iad> Steven D'Aprano wrote: > A straw man is not when somebody points out holes in your argument, or > unwanted implications that you didn't realise were there. It is when > somebody makes claims on your behalf that you did not make to discredit > you, not because you don't understand the implications of your own > argument. The straw-man fallacy is when you erect a "straw man" to "represent" the actual man (or idea) which can be easily knocked down, and then you proceed to knock it down (the straw-man) as though the "straw man" was the actual man, or idea... proving your point as-it-were against your opponent when in fact you have only just knocked down the straw-man... leaving the real man standing. This fallacy has a couple of nuances (sometimes combined with metaphor or analogy fallacy) and you are a master at presenting both... thankfully you usually don't try to present both at the same time! :) In this present case the straw-man was not "me," rather the straw-man was the python language itself. You chose a code-snippet (one small puny dangle that doesn't prove a thing) and used it to speak for the entire language! As though one code-block is enough to demonstrate compatibility for the entire language in all of its nuances and details. To prove something positive with a test case requires that you provide *all* test cases, or that you provide an algorithm that accounts for *all* test cases... you cannot prove compatibility with a code-snippet. On the other hand, all you have to do to prove incompatibility is to show "one" (1) test case where compatibility fails... and of course for the present case there are many that can be shown, in fact, hundreds of them. The thing that nobody has presented here yet is that *all* the books declare that 3.x is incompatible with 2.x/ ... some of them go out of their way to tell the reader that they are only going to deal with 3.x and not 2.x in any way... and others go out of their way to point out the hundreds of nuances in details between the two languages. (and a good thing too, for those of us who must work with both! ) So this fact is not alluding the press... the point being not to bust anybody in the chops, but to point out that it is not helpful to move the community forward with a new language and get mass adoption (not just early adopters) to lie about the differences between the two sets... yes, for trivial code blocks that use prime constructs, integer math, and the print statement, not much has changed. But in real world applications of the language there are many hundreds of details that have changed or been added (deleted) which will make life difficult for the uninitiated. Don't mislead people by saying that very little has changed. Tell them that the philosophy is the same (what Chris called python 'think' ) but be honest about the details of syntax, environment, layout, and morphology. kind regards, m harris kind regards, m harris From dotancohen at gmail.com Sun May 29 01:46:21 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Sun, 29 May 2011 08:46:21 +0300 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 27, 2011 at 23:40, harrismh777 wrote: > You have erected a straw-man... once again. > I think that is a red herring, not a strawman. > Most 2.x code *will not* run correctly in 3.x/ ?Most of the best > improvements and enhancements of 3.x will not back-port to below 2.7, and > almost none of them will back-port before 2.6 (class decorations, for > instance). > Although it is true that 2.x code will not run in a 3.x environment, the changes to the code are minimal. This would be akin to saying that a 2008 Peugeot 407 will not drive on a Canadian road because the license plate is a different shape. Just go an put a different plastic license plate holder on the Peugeot and it will run fine on the Canadian road. The changes to bring Python 2 code into Python 3 code are minimal, and it would be a terrific learning experience for the OP to go back and revise his old code to do just that. Furthermore, the OP is not just learning Python for the fun of learning Python. If that were the case, then I would agree that Python 3 is the way to go. The OP needs to use imaging libraries which may not yet work in Python 3 (I have not checked, but it is very likely that they do not). Therefore Python 3 is a non-starter in any case. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From nagle at animats.com Sun May 29 02:12:54 2011 From: nagle at animats.com (John Nagle) Date: Sat, 28 May 2011 23:12:54 -0700 Subject: float("nan") in set or as key In-Reply-To: <94dkd3F7k4U1@mid.individual.net> References: <94dkd3F7k4U1@mid.individual.net> Message-ID: <4de1e3e7$0$2195$742ec2ed@news.sonic.net> On 5/28/2011 6:04 PM, Gregory Ewing wrote: > MRAB wrote: >> float("nan") can occur multiple times in a set or as a key in a dict: >> >> >>> {float("nan"), float("nan")} >> {nan, nan} >> >> except that sometimes it can't: >> >> >>> nan = float("nan") >> >>> {nan, nan} >> {nan} > > NaNs are weird. They're not equal to themselves: > > Python 2.7 (r27:82500, Oct 15 2010, 21:14:33) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> nan = float("nan") > >>> nan == nan > False > > This confuses the daylights out of Python's dict lookup machinery, > which assumes that two references to the same object can't possibly > compare unequal, so it doesn't bother calling __eq__ on them. Right. The correct answer to "nan == nan" is to raise an exception, because you have asked a question for which the answer is nether True nor False. The correct semantics for IEEE floating point look something like this: 1/0 INF INF + 1 INF INF - INF NaN INF == INF unordered NaN == NaN unordered INF and NaN both have comparison semantics which return "unordered". The FPU sets a bit for this, which most language implementations ignore. But you can turn on floating point exception traps, and on x86 machines, they're exact - the exception will occur exactly at the instruction which triggered the error. In superscalar CPUs, a sizable part of the CPU handles the unwinding necessary to do that. x86 does it, because it's carefully emulating non-superscalar machines. Most RISC machines don't bother. Python should raise an exception on unordered comparisons. Given that the language handles integer overflow by going to arbitrary-precision integers, checking the FPU status bits is cheap. The advantage of raising an exception is that the logical operations still work. For example, not (a == b) a != b will always return the same results if exceptions are raised for unordered comparison results. Also, exactly one of a = b a < b a > b is always true - something sorts tend to assume. If you get an unordered comparison exception, your program almost certainly was getting wrong answers. (I used to do dynamics simulation engines, where this mattered.) John Nagle From michele.simionato at gmail.com Sun May 29 02:33:02 2011 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 28 May 2011 23:33:02 -0700 (PDT) Subject: Class decorators might also be super too In-Reply-To: <1ef87095-2153-4c34-acf4-cfd1380bbcdd@z15g2000prn.googlegroups.com> Message-ID: <462eb546-0089-48fa-bf10-ac5a6b0b9ed4@glegroupsg2000goo.googlegroups.com> He is basically showing that using mixins for implementing logging is not such a good idea, i.e. you can get the same effect in a better way by making use of other Python features. I argued the same thing many times in the past. I even wrote a module once (strait) to reimplement 99% of multiple inheritance without multiple inheritance, just to show that in can be done in few lines of code in a language as powerful as Python. From ian.g.kelly at gmail.com Sun May 29 04:06:54 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 29 May 2011 02:06:54 -0600 Subject: Beginner needs advice In-Reply-To: <2giEp.236$QL2.62@newsfe04.iad> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: On Sat, May 28, 2011 at 8:33 PM, harrismh777 wrote: > In this present case the straw-man was not "me," rather the straw-man was > the python language itself. You chose a code-snippet (one small puny dangle > that doesn't prove a thing) and used it to speak for the entire language! > ?As though one code-block is enough to demonstrate compatibility for the > entire language in all of its nuances and details. ?To prove something > positive with a test case requires that you provide *all* test cases, or > that you provide an algorithm that accounts for *all* test cases... you > cannot prove compatibility with a code-snippet. You have just misrepresented Steven's argument, which is rather ironic considering that you're the one who brought up straw-men. Steven did not use one code snippet to demonstrate that Python 2 and Python 3 are fully compatible. The code snippet merely demonstrated that Python 2 and 3 are not "totally incompatible" as you had claimed. I realize you are now asserting that compatibility is a boolean condition, and that "totally incompatible" is a redundant phrase that you tossed out as a joke. I don't know whether you're sincere or backpedaling, but in any case this assertion is flatly ludicrous. Following your definition, *nothing* is compatible with anything else. If you disagree, then I invite you to list one example of two different things that are compatible. And finally, would you please just knock off the fallacy crap? If you assert something, and another person counters with a straw-man, and you respond by dismissing his argument as a straw-man, your response is valid. But if you assert something, and another person makes a counter-argument, to whom you invariably respond by crying "Straw-man!" or "False analogy!" (or in your case, "Analogy!"; you seem to view all analogies as false) regardless of what that person actually said -- even if that person does *sometimes* actually commit those fallacies -- then you yourself are employing an ad hominem. From wolfgang at rohdewald.de Sun May 29 04:27:14 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Sun, 29 May 2011 10:27:14 +0200 Subject: float("nan") in set or as key In-Reply-To: References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: <201105291027.15056.wolfgang@rohdewald.de> On Sonntag 29 Mai 2011, Tim Delaney wrote: > There's a second part the mystery - sets and dictionaries (and > I think lists) assume that identify implies equality (hence > the second result). This was recently discussed on > python-dev, and the decision was to leave things as-is. On Sonntag 29 Mai 2011, Grant Edwards wrote: > Even if they are the same nan, it's still not equal to itself. if I understand this thread correctly, they are not equal to itself as specified by IEEE but Python treats them equal in sets and dictionaries for performance reasons -- Wolfgang From henry.olders at mcgill.ca Sun May 29 04:30:52 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Sun, 29 May 2011 04:30:52 -0400 Subject: scope of function parameters Message-ID: I just spent a considerable amount of time and effort debugging a program. The made-up code snippet below illustrates the problem I encountered: def main(): a = ['a list','with','three elements'] print a print fnc1(a) print a def fnc1(b): return fnc2(b) def fnc2(c): c[1] = 'having' return c This is the output: ['a list', 'with', 'three elements'] ['a list', 'having', 'three elements'] ['a list', 'having', 'three elements'] I had expected the third print statement to give the same output as the first, but variable a had been changed by changing variable c in fnc2. It seems that in Python, a variable inside a function is global unless it's assigned. This rule has apparently been adopted in order to reduce clutter by not having to have global declarations all over the place. I would have thought that a function parameter would automatically be considered local to the function. It doesn't make sense to me to pass a global to a function as a parameter. One workaround is to call a function with a copy of the list, eg in fnc1 I would have the statement "return fnc2(b[:]". But this seems ugly. Are there others who feel as I do that a function parameter should always be local to the function? Or am I missing something here? Henry From steve+comp.lang.python at pearwood.info Sun May 29 04:51:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 08:51:33 GMT Subject: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> <1306628926.168355.5.camel@localhost.localdomain> Message-ID: <4de20915$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 10:32:43 +1000, Chris Angelico wrote: > On Sun, May 29, 2011 at 10:28 AM, Albert Hopkins > wrote: >> This is the same nan, so it is equal to itself. >> >> > Actually, they're not. But it's possible the dictionary uses an 'is' > check to save computation, and if one thing 'is' another, it is assumed > to equal it. That's true of most well-behaved objects, but nan is not > well-behaved :) *Exactly* correct. NAN != NAN even if they are the same NAN, by design. This makes NANs ill- behaved, but usefully so. Most (all?) Python built-ins assume that any object X is equal to itself, so they behave strangely with NANs. -- Steven From narkewoody at gmail.com Sun May 29 04:53:44 2011 From: narkewoody at gmail.com (narke) Date: Sun, 29 May 2011 03:53:44 -0500 Subject: Error: child process close a socket inherited from parent Message-ID: Hi, As illustrated in the following simple sample: import sys import os import socket class Server: def __init__(self): self._listen_sock = None def _talk_to_client(self, conn, addr): text = 'The brown fox jumps over the lazy dog.\n' while True: conn.send(text) data = conn.recv(1024) if not data: break conn.close() def listen(self, port): self._listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._listen_sock.bind(('', port)) self._listen_sock.listen(128) self._wait_conn() def _wait_conn(self): while True: conn, addr = self._listen_sock.accept() if os.fork() == 0: self._listen_sock.close() # line x self._talk_to_client(conn, addr) else: conn.close() if __name__ == '__main__': Server().listen(int(sys.argv[1])) Unless I comment out the line x, I will get a 'Bad file descriptor' error when my tcp client program (e.g, telnet) closes the connection to the server. But as I understood, a child process can close a unused socket (file descriptor). Do you know what's wrong here? -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From wolfgang at rohdewald.de Sun May 29 05:47:26 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Sun, 29 May 2011 11:47:26 +0200 Subject: scope of function parameters In-Reply-To: References: Message-ID: <201105291147.26545.wolfgang@rohdewald.de> On Sonntag 29 Mai 2011, Henry Olders wrote: > It seems that in Python, a variable inside a function is > global unless it's assigned. no, they are local > I would have thought that a function parameter would > automatically be considered local to the function. It doesn't > make sense to me to pass a global to a function as a > parameter. it is local. But consider what you actually passed: You did not pass a copy of the list but the list itself. You could also say you passed a reference to the list. All python variables only hold a pointer (the id) to an object. This object has a reference count and is automatically deleted when there are no more references to it. If you want a local copy of the list you can either do what you called being ugly or do just that within the function itself - which I think is cleaner and only required once. def fnc2(c): c = c[:] c[1] = 'having' return c -- Wolfgang From crebert at ucsd.edu Sun May 29 06:01:52 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Sun, 29 May 2011 03:01:52 -0700 Subject: scope of function parameters In-Reply-To: References: Message-ID: On Sun, May 29, 2011 at 1:30 AM, Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a program. The made-up code snippet below illustrates the problem I encountered: > > def main(): > ? ? ? ?a = ['a list','with','three elements'] > ? ? ? ?print a > ? ? ? ?print fnc1(a) > ? ? ? ?print a > > def fnc1(b): > ? ? ? ?return fnc2(b) > > def fnc2(c): > ? ? ? ?c[1] = 'having' > ? ? ? ?return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same output as the first, but variable a had been changed by changing variable c in fnc2. To be more accurate, the list object referred to by `a` was modified through c, due to the fact that a, b, and c all refer to the very same object in this case. > It seems that in Python, a variable inside a function is global unless it's assigned. This rule has apparently been adopted in order to reduce clutter by not having to have global declarations all over the place. > > I would have thought that a function parameter would automatically be considered local to the function. > Are there others who feel as I do that a function parameter should always be local to the function? Or am I missing something here? Function parameters *are* local variables. Function parameters are indeed local in that *rebinding* them has no effect outside of the function: def foo(a): a = 42 def bar(): b = 1 foo(b) print b bar() #=> outputs 1 As you've observed, *mutating* the object a variable refers to is another matter entirely. Python does not use call-by-value and does not copy objects unless explicitly requested to, as you've encountered. But it does not use call-by-reference either, as my example demonstrates. Like several other popular contemporary languages, Python uses call-by-object for parameter passing; a good explanation of this model can be found at http://effbot.org/zone/call-by-object.htm It's well worth reading. Cheers, Chris From nobody at nowhere.net.no Sun May 29 06:02:43 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 29 May 2011 18:02:43 +0800 Subject: How to catch a line with Popen References: Message-ID: Tim Roberts wrote: > Are you specifying a buffer size in the Popen command? If not, then the > Python side of things is unbuffered The buffer is as per default. The program reports one line around 1/2 second time. I think I'll look into the option as Nobody states: p = subprocess.Popen(...) for line in p.stdout: ... p.wait() It is strange that would take a for cycle, rather than catching the line on- the-fly. I can judge it now, I'm going to try it out. -- goto /dev/null From clp2 at rebertia.com Sun May 29 06:26:49 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 29 May 2011 03:26:49 -0700 Subject: How to catch a line with Popen In-Reply-To: References: Message-ID: On Sun, May 29, 2011 at 3:02 AM, TheSaint wrote: > Tim Roberts wrote: > >> Are you specifying a buffer size in the Popen command? ?If not, then the >> Python side of things is unbuffered > > The buffer is as per default. The program reports one line around 1/2 second > time. > I think I'll look into the option as Nobody states: > > ? ? ? ?p = subprocess.Popen(...) > ? ? ? ?for line in p.stdout: > ? ? ? ? ? ?... > ? ? ? ?p.wait() > > It is strange that would take a for cycle, rather than catching the line on- > the-fly. I can judge it now, I'm going to try it out. What do you mean by "on-the-fly" in this context? Cheers, Chris From steve+comp.lang.python at pearwood.info Sun May 29 06:29:28 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 10:29:28 GMT Subject: float("nan") in set or as key References: <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> Message-ID: <4de22007$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 28 May 2011 23:12:54 -0700, John Nagle wrote: > The correct answer to "nan == nan" is to raise an exception, because > you have asked a question for which the answer is nether True nor False. Wrong. The correct answer to "nan == nan" is False, they are not equal. Just as None != "none", and 42 != [42], or a teacup is not equal to a box of hammers. Asking whether NAN < 0 could arguably either return "unordered" (raise an exception) or return False ("no, NAN is not less than zero; neither is it greater than zero"). The PowerPC Macintishes back in the 1990s supported both behaviours. But that's different to equality tests. > The correct semantics for IEEE floating point look something like > this: > > 1/0 INF > INF + 1 INF > INF - INF NaN > INF == INF unordered Wrong. Equality is not an order comparison. -- Steven From greg.ewing at canterbury.ac.nz Sun May 29 07:05:48 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 29 May 2011 23:05:48 +1200 Subject: The worth of comments In-Reply-To: <877h9a9tbb.fsf@benfinney.id.au> References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> <877h9a9tbb.fsf@benfinney.id.au> Message-ID: <94enkcFj5mU1@mid.individual.net> Ben Finney wrote: > You omit the common third possibility: *both* the comment and the code > are wrong. In that case, the correct response is to fix both of them. :-) -- Greg From vinay_sajip at yahoo.co.uk Sun May 29 07:29:06 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 29 May 2011 04:29:06 -0700 (PDT) Subject: Class decorators might also be super too References: <462eb546-0089-48fa-bf10-ac5a6b0b9ed4@glegroupsg2000goo.googlegroups.com> Message-ID: <8f14c08e-2c52-4c8d-9777-ba11d483c707@h9g2000yqk.googlegroups.com> On May 29, 7:33?am, Michele Simionato wrote: > He is basically showing that using mixins for implementingloggingis not such a good idea, I don't think he was particularly advocating implementing logging this way, but rather just using logging for illustrative purposes. Regards, Vinay Sajip From bahamutzero8825 at gmail.com Sun May 29 07:45:30 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 06:45:30 -0500 Subject: Weird problem matching with REs Message-ID: <4DE231DA.7050503@gmail.com> I have an RE that should work (it even works in Kodos [1], but not in my code), but it keeps failing to match characters after a newline. I'm writing a little program that scans the webpage of an arbitrary application and gets the newest version advertised on the page. test3.py: > # -*- coding: utf-8 -*- > > import configparser > import re > import urllib.request > import os > import sys > import logging > import collections > > > class CouldNotFindVersion(Exception): > def __init__(self, app_name, reason, exc_value): > self.value = 'The latest version of ' + app_name + ' could not > be determined because ' + reason > self.cause = exc_value > def __str__(self): > return repr(self.value) > > class AppUpdateItem(): > def __init__(self, config_file_name, config_file_section): > self.section = config_file_section > self.name = self.section['Name'] > self.url = self.section['URL'] > self.filename = self.section['Filename'] > self.file_re = re.compile(self.section['FileURLRegex']) > self.ver_re = re.compile(self.section['VersionRegex']) > self.prev_ver = self.section['CurrentVersion'] > try: > self.page = str(urllib.request.urlopen(self.url).read(), > encoding='utf-8') > self.file_URL = self.file_re.findall(self.page)[0] #here > is where it fails > self.last_ver = self.ver_re.findall(self.file_URL)[0] > except urllib.error.URLError: > self.error = str(sys.exc_info()[1]) > logging.info('[' + self.name + ']' + ' Could not load URL: > ' + self.url + ' : ' + self.error) > self.success = False > raise CouldNotFindVersion(self.name, self.error, > sys.exc_info()[0]) > except IndexError: > logging.warning('Regex did not return a match.') > def update_ini(self): > self.section['CurrentVersion'] = self.last_ver > with open(config_file_name, 'w') as configfile: > config.write(configfile) > def rollback_ini(self): > self.section['CurrentVersion'] = self.prev_ver > with open(config_file_name, 'w') as configfile: > config.write(configfile) > def download_file(self): > self.__filename = self.section['Filename'] > with open(self.__filename, 'wb') as file: > self.__file_req = urllib.request.urlopen(self.file_URL).read() > file.write(self.__file_req) > > > if __name__ == '__main__': > config = configparser.ConfigParser() > config_file = 'checklist.ini' > config.read(config_file) > queue = collections.deque() > for section in config.sections(): > try: > queue.append(AppUpdateItem(config_file, config[section])) > except CouldNotFindVersion as exc: > logging.warning(exc.value) > for elem in queue: > if elem.last_ver != elem.prev_ver: > elem.update_ini() > try: > elem.download_file() > except IOError: > logging.warning('[' + elem.name + '] Download failed.') > except: > elem.rollback_ini() > print(elem.name + ' succeeded.') checklist.ini: > [x264_64] > name = x264 (64-bit) > filename = x264.exe > url = http://x264.nl/x264_main.php > fileurlregex = > http://x264.nl/x264/64bit/8bit_depth/revision\n{0,3}[0-9]{4}\n{0,3}/x264\n{0,3}.exe > versionregex = [0-9]{4} > currentversion = 1995 The part it's supposed to match in http://x264.nl/x264_main.php: > Message-ID: Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a program. > The made-up code snippet below illustrates the problem I encountered: > > def main(): > a = ['a list','with','three elements'] > print a > print fnc1(a) > print a > > def fnc1(b): > return fnc2(b) > > def fnc2(c): > c[1] = 'having' > return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same output as the > first, but variable a had been changed by changing variable c in fnc2. > > It seems that in Python, a variable inside a function is global unless > it's assigned. This rule has apparently been adopted in order to reduce > clutter by not having to have global declarations all over the place. > > I would have thought that a function parameter would automatically be > considered local to the function. It doesn't make sense to me to pass a > global to a function as a parameter. It doesn't look like a question of local or global. fnc2 is passed a container object and replaces item 1 in that container. You see the results when fnc2 prints the object it knows as `c`, and you see again when main prints the object it knows as `a`. Python doesn't pass parameters by handing around copies that can be thought of as local or global. Python passes parameters by binding objects to names in the callee's namespace. In your program the list known as `a` in main is identically the same list as the one known as `c` in fnc2, and what happens happens. Mel. From steve+comp.lang.python at pearwood.info Sun May 29 08:47:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 12:47:01 GMT Subject: scope of function parameters References: Message-ID: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 11:47:26 +0200, Wolfgang Rohdewald wrote: > On Sonntag 29 Mai 2011, Henry Olders wrote: >> It seems that in Python, a variable inside a function is global unless >> it's assigned. > > no, they are local I'm afraid you are incorrect. Names inside a function are global unless assigned to somewhere. >>> a = 1 >>> def f(): ... print a # Not local, global. ... >>> f() 1 By default, names inside a function must be treated as global, otherwise you couldn't easily refer to global functions: def f(x): print len(x) because len would be a local name, which doesn't exist. In Python, built- in names are "variables" just like any other. Python's scoping rule is something like this: If a name is assigned to anywhere in the function, treat it as a local, and look it up in the local namespace. If not found, raise UnboundLocalError. If a name is never assigned to, or if it is declared global, then look it up in the global namespace. If not found, look for it in the built-ins. If still not found, raise NameError. Nested scopes (functions inside functions) make the scoping rules a little more complex. If a name is a function parameter, that is equivalent to being assigned to inside the function. -- Steven From ben+python at benfinney.id.au Sun May 29 09:00:18 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 29 May 2011 23:00:18 +1000 Subject: Weird problem matching with REs References: Message-ID: <8739jxacgt.fsf@benfinney.id.au> Andrew Berg writes: > I was able to make a regex that matches in my code, but it shouldn't: > http://x264.nl/x264/64bit/8bit_depth/revision.\n{1,3}[0-9]{4}.\n{1,3}/x264.\n{1,3}.\n{1,3}.exe > I have to add a dot before each "\n". There is no character not > accounted for before those newlines, but I don't get a match without the > dots. I also need both those ".\n{1,3}" sequences before the ".exe". I'm > really confused. > > Using Python 3.2 on Windows, in case it matters. You are aware that most text-emitting processes on Windows, and Internet text protocols like the HTTP standard, use the two-character ?CR LF? sequence (U+000C U+000A) for terminating lines? -- \ ?What I have to do is see, at any rate, that I do not lend | `\ myself to the wrong which I condemn.? ?Henry Thoreau, _Civil | _o__) Disobedience_ | Ben Finney From ben+python at benfinney.id.au Sun May 29 09:03:41 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 29 May 2011 23:03:41 +1000 Subject: Weird problem matching with REs References: <8739jxacgt.fsf@benfinney.id.au> Message-ID: <87y61p8xqq.fsf@benfinney.id.au> Ben Finney writes: > the two-character ?CR LF? sequence (U+000C U+000A) > As detailed in that Wikipedia article, the characters are of course U+000D U+000A. -- \ ?You say ?Carmina?, and I say ?Burana?, You say ?Fortuna?, and | `\ I say ?cantata?, Carmina, Burana, Fortuna, cantata, Let's Carl | _o__) the whole thing Orff.? ?anonymous | Ben Finney From steve+comp.lang.python at pearwood.info Sun May 29 09:09:47 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 13:09:47 GMT Subject: Weird problem matching with REs References: Message-ID: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 06:45:30 -0500, Andrew Berg wrote: > I have an RE that should work (it even works in Kodos [1], but not in my > code), but it keeps failing to match characters after a newline. Not all regexes are the same. Different regex engines accept different symbols, and sometimes behave differently, or have different default behavior. That your regex works in Kodos but not Python might mean you're writing a Kodus regex instead of a Python regex. > I'm writing a little program that scans the webpage of an arbitrary > application and gets the newest version advertised on the page. Firstly, most of the code you show is irrelevant to the problem. Please simplify it to the shortest, most simple example you can give. That would be a simplified piece of text (not the entire web page!), the regex, and the failed attempt to use it. The rest of your code is just noise for the purposes of solving this problem. Secondly, you probably should use a proper HTML parser, rather than a regex. Resist the temptation to use regexes to rip out bits of text from HTML, it almost always goes wrong eventually. > I was able to make a regex that matches in my code, but it shouldn't: > http://x264.nl/x264/64bit/8bit_depth/revision.\n{1,3}[0-9]{4}.\n{1,3}/ x264.\n{1,3}.\n{1,3}.exe What makes you think it shouldn't match? By the way, you probably should escape the dots, otherwise it will match strings containing any arbitrary character, rather than *just* dots: http://x264Znl ...blah blah blah -- Steven From bahamutzero8825 at gmail.com Sun May 29 09:29:13 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 08:29:13 -0500 Subject: Weird problem matching with REs In-Reply-To: <8739jxacgt.fsf@benfinney.id.au> References: <8739jxacgt.fsf@benfinney.id.au> Message-ID: <4DE24A29.9080006@gmail.com> On 2011.05.29 08:00 AM, Ben Finney wrote: > You are aware that most text-emitting processes on Windows, and Internet > text protocols like the HTTP standard, use the two-character ?CR LF? > sequence (U+000C U+000A) for terminating lines? Yes, but I was not having trouble with just '\n' before, and the pattern did match in Kodos, so I figured Python was doing its newline magic like it does with the write() method for file objects. http://x264.nl/x264/64bit/8bit_depth/revision[\r\n]{1,3}[0-9]{4}[\r\n]{1,3}/x264[\r\n]{1,3}.exe does indeed match. One thing that confuses me, though (and one reason I dismissed the possibility of it being a newline issue): isn't '.' supposed to not match '\r'? From bahamutzero8825 at gmail.com Sun May 29 09:41:16 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 08:41:16 -0500 Subject: Weird problem matching with REs In-Reply-To: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DE24CFC.3020107@gmail.com> On 2011.05.29 08:09 AM, Steven D'Aprano wrote: > On Sun, 29 May 2011 06:45:30 -0500, Andrew Berg wrote: > > > I have an RE that should work (it even works in Kodos [1], but not in my > > code), but it keeps failing to match characters after a newline. > > Not all regexes are the same. Different regex engines accept different > symbols, and sometimes behave differently, or have different default > behavior. That your regex works in Kodos but not Python might mean you're > writing a Kodus regex instead of a Python regex. Kodos is written in Python and uses Python's regex engine. In fact, it is specifically intended to debug Python regexes. > Firstly, most of the code you show is irrelevant to the problem. Please > simplify it to the shortest, most simple example you can give. That would > be a simplified piece of text (not the entire web page!), the regex, and > the failed attempt to use it. The rest of your code is just noise for the > purposes of solving this problem. I wasn't sure how much would be relevant since it could've been a problem with other code. I do apologize for not putting more effort into trimming it down, though. > Secondly, you probably should use a proper HTML parser, rather than a > regex. Resist the temptation to use regexes to rip out bits of text from > HTML, it almost always goes wrong eventually. I find this a much simpler approach, especially since I'm dealing with broken HTML. I guess I don't see how the effort put into learning a parser and adding the extra code to use it pays off in this particular endeavor. > > I was able to make a regex that matches in my code, but it shouldn't: > > http://x264.nl/x264/64bit/8bit_depth/revision.\n{1,3}[0-9]{4}.\n{1,3}/ > x264.\n{1,3}.\n{1,3}.exe > > What makes you think it shouldn't match? AFAIK, dots aren't supposed to match carriage returns or any other whitespace characters. > By the way, you probably should escape the dots, otherwise it will match > strings containing any arbitrary character, rather than *just* dots: You're right; I overlooked the dots in the URL. From nobody at nowhere.net.no Sun May 29 09:52:22 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 29 May 2011 21:52:22 +0800 Subject: How to catch a line with Popen References: Message-ID: Chris Rebert wrote: > What do you mean by "on-the-fly" in this context I just suppose to elaborate the latest line, as soon it's written on the pipe, and print some result on the screen. Imaging something like p= Popen(['ping','-c40','www.google.com'], stdout=PIPE) for line in p.stdout: print(str(line).split()[7]) I'd like to see something like *time=54.4* This is just an example, where if we remove the "-c40" on the command line, I'd expect to read the latest line(s), until the program will be killed. -- goto /dev/null From narkewoody at gmail.com Sun May 29 09:52:45 2011 From: narkewoody at gmail.com (narke) Date: Sun, 29 May 2011 08:52:45 -0500 Subject: Error: child process close a socket inherited from parent References: Message-ID: On 2011-05-29, narke wrote: > Hi, > > As illustrated in the following simple sample: > > import sys > import os > import socket > > class Server: > def __init__(self): > self._listen_sock = None > > def _talk_to_client(self, conn, addr): > text = 'The brown fox jumps over the lazy dog.\n' > while True: > conn.send(text) > data = conn.recv(1024) > if not data: > break > conn.close() > > def listen(self, port): > self._listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > self._listen_sock.bind(('', port)) > self._listen_sock.listen(128) > self._wait_conn() > > def _wait_conn(self): > while True: > conn, addr = self._listen_sock.accept() > if os.fork() == 0: > self._listen_sock.close() # line x > self._talk_to_client(conn, addr) > else: > conn.close() > > if __name__ == '__main__': > Server().listen(int(sys.argv[1])) > > Unless I comment out the line x, I will get a 'Bad file descriptor' > error when my tcp client program (e.g, telnet) closes the connection to > the server. But as I understood, a child process can close a unused > socket (file descriptor). > > Do you know what's wrong here? > > I forgot to say, it's Python 2.6.4 running on linux 2.6.33 -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From steve+comp.lang.python at pearwood.info Sun May 29 10:09:46 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 14:09:46 GMT Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> Message-ID: <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sat, 28 May 2011 21:02:47 -0500, harrismh777 wrote: > Minor, yes, .... until you need to make something work--- only to be > frustrated to find that a detail that was not expected has risen to bite > a sensitive place... :) Just like when migrating from Python 2.3 to 2.6. And 1.5 and 2.0, and 2.0 and 2.2, and 2.2 and 2.3. > I am amazed at how many folks are not using 3.x/ Why? (beats me), Because: (1) the major operating systems either don't provide Python at all (Windows), or are conservatively still using Python 2.6 or even 2.5 (Mac OS, most Linux distros); (2) the Python website still recommends that "Python 2.x is the status quo, Python 3.x is the shiny new thing" ; and (3) the most of the big frameworks and libraries have either just recently been upgraded to support 3.x, or haven't yet been upgraded. There's very little mystery about it. Migration to 3.x is going according to plan. The majority aren't expected to migrate until probably 3.4 or even 3.5. > but how do I know they're not using it...? Because, if they were > trying to use it with 2.x knowledge they would be complaining bloody > murder.. for instance, how do we reload a module in 2.x... with, um, > reload. This has always been the way... every book says so, *Every* book? Even these? http://diveintopython3.org/ http://www.qtrac.eu/py3book.html http://www.mindviewinc.com/Books/Python3Patterns/Index.php Please quote chapter and verse. [...] > PS Something nobody has pointed out yet is that "completely > incompatible" is redundant. That's because it is not redundant. There is a difference between 1% compatible and 99% compatible and 100% incompatible. > ... its like saying totally destroyed. I > was trying to be funny, but nobody unpinned it... I'm disappointed. > > Some of the posts here are referring to the two languages as partially > incompatible.... reminds me of that line from Princess Bride... "... > he's not dead, hes only mostly dead!... and mostly dead is partly > alive!" To say that 3.x is partly compatible with 2.x is silly, What a ridiculous statement, and one which flies in the face of major projects like numpy which support 2.x and 3.x out of a single code base. I invite you to consider the difference between a legally dead person moments before being resuscitated by a paramedic, versus a chicken that has just been beheaded and is still running around the yard, versus a million-year-old fossilized bone that has turned to stone. Who could possibly justify saying that all three are equally dead? Beware the tyranny of the discontinuous mind. http://www.sciencemusings.com/2007/07/tyranny-of-discontinuous-mind.html Both life and compatibility are matters of degree, not binary states. For proper operation, an electrical device might require a 6V 250mA transformer, but it might work well enough with one that provides just 5V and 240mA, provided you don't stress the device too much. We often design our physical devices to force compatibility to be all-or- nothing, e.g. you can't fit a USB plug into an audio jack, no matter how you try. But that's enforced by the design, not because compatibility is inherently true/false. Compatibility is inherently continuous, a matter of degree. This is especially true when it comes to languages, both natural and programming. British English and American English are perhaps 99.5% compatible, but "table a motion" means completely opposite things in British and American English. (In Britain, it means to deal with it immediately; in the USA, it means to postpone it.) Should we conclude from this that British and American English are "different languages" and "completely incompatible"? The differences between Python 2 and 3 are less than those between American and British English. To describe them as "different languages", as if going from Python 2 to 3 was like translating English to Italian, is absurd. -- Steven From nobody at nowhere.net.no Sun May 29 10:13:14 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 29 May 2011 22:13:14 +0800 Subject: How to catch a line with Popen References: Message-ID: TheSaint wrote: > I just suppose to elaborate the latest line, as soon it's written on the > pipe, and print some result on the screen. I think some info is also here: http://alexandredeverteuil.blogspot.com/ -- goto /dev/null From steve+comp.lang.python at pearwood.info Sun May 29 10:18:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 14:18:16 GMT Subject: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 08:41:16 -0500, Andrew Berg wrote: > On 2011.05.29 08:09 AM, Steven D'Aprano wrote: [...] > Kodos is written in Python and uses Python's regex engine. In fact, it > is specifically intended to debug Python regexes. Fair enough. >> Secondly, you probably should use a proper HTML parser, rather than a >> regex. Resist the temptation to use regexes to rip out bits of text >> from HTML, it almost always goes wrong eventually. > > I find this a much simpler approach, especially since I'm dealing with > broken HTML. I guess I don't see how the effort put into learning a > parser and adding the extra code to use it pays off in this particular > endeavor. The temptation to take short-cuts leads to the Dark Side :) Perhaps you're right, in this instance. But if you need to deal with broken HTML, try BeautifulSoup. >> What makes you think it shouldn't match? > > AFAIK, dots aren't supposed to match carriage returns or any other > whitespace characters. They won't match *newlines* \n unless you pass the DOTALL flag, but they do match whitespace: >>> re.search('abc.efg', '----abc efg----').group() 'abc efg' >>> re.search('abc.efg', '----abc\refg----').group() 'abc\refg' >>> re.search('abc.efg', '----abc\nefg----') is None True -- Steven From bahamutzero8825 at gmail.com Sun May 29 10:35:19 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 09:35:19 -0500 Subject: Weird problem matching with REs In-Reply-To: <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DE259A7.4030209@gmail.com> On 2011.05.29 09:18 AM, Steven D'Aprano wrote: > >> What makes you think it shouldn't match? > > > > AFAIK, dots aren't supposed to match carriage returns or any other > > whitespace characters. > > They won't match *newlines* \n unless you pass the DOTALL flag, but they > do match whitespace: > > >>> re.search('abc.efg', '----abc efg----').group() > 'abc efg' > >>> re.search('abc.efg', '----abc\refg----').group() > 'abc\refg' > >>> re.search('abc.efg', '----abc\nefg----') is None > True I got things mixed up there (was thinking whitespace instead of newlines), but I thought dots aren't supposed to match '\r' (carriage return). Why is '\r' not considered a newline character? From invalid at invalid.invalid Sun May 29 10:41:13 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 29 May 2011 14:41:13 +0000 (UTC) Subject: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: On 2011-05-29, Wolfgang Rohdewald wrote: > On Sonntag 29 Mai 2011, Tim Delaney wrote: >> There's a second part the mystery - sets and dictionaries (and >> I think lists) assume that identify implies equality (hence >> the second result). This was recently discussed on >> python-dev, and the decision was to leave things as-is. > > On Sonntag 29 Mai 2011, Grant Edwards wrote: >> Even if they are the same nan, it's still not equal to itself. > > if I understand this thread correctly, they are not equal to itself > as specified by IEEE And Python follows that convention. > but Python treats them equal in sets and dictionaries for performance > reasons It treats them as identical (not sure if that's the right word). The implementation is checking for ( A is B or A == B ). Presumably, the assumpting being that all objects are equal to themselves. That assumption is not true for NaN objects, so the buggy behavior is observed. -- Grant From invalid at invalid.invalid Sun May 29 10:43:57 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 29 May 2011 14:43:57 +0000 (UTC) Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> <877h9a9tbb.fsf@benfinney.id.au> <94enkcFj5mU1@mid.individual.net> Message-ID: On 2011-05-29, Gregory Ewing wrote: > Ben Finney wrote: > >> You omit the common third possibility: *both* the comment and the code >> are wrong. > > In that case, the correct response is to fix both of them. :-) Only as a last resort. IMO, the best option is to fix the code so it's purpose and operation is obvious from the code, and then delete the comment. -- Grant From roy at panix.com Sun May 29 11:19:11 2011 From: roy at panix.com (Roy Smith) Date: Sun, 29 May 2011 11:19:11 -0400 Subject: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Andrew Berg wrote: > Kodos is written in Python and uses Python's regex engine. In fact, it > is specifically intended to debug Python regexes. Named after the governor of Tarsus IV? From bahamutzero8825 at gmail.com Sun May 29 11:31:43 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 10:31:43 -0500 Subject: Weird problem matching with REs In-Reply-To: References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4DE266DF.2080602@gmail.com> On 2011.05.29 10:19 AM, Roy Smith wrote: > Named after the governor of Tarsus IV? Judging by the graphic at http://kodos.sourceforge.net/help/kodos.html , it's named after the Simpsons character. From roy at panix.com Sun May 29 11:39:19 2011 From: roy at panix.com (Roy Smith) Date: Sun, 29 May 2011 11:39:19 -0400 Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> <877h9a9tbb.fsf@benfinney.id.au> <94enkcFj5mU1@mid.individual.net> Message-ID: In article , Grant Edwards wrote: > On 2011-05-29, Gregory Ewing wrote: > > Ben Finney wrote: > > > >> You omit the common third possibility: *both* the comment and the code > >> are wrong. > > > > In that case, the correct response is to fix both of them. :-) > > Only as a last resort. IMO, the best option is to fix the code so it's > purpose and operation is obvious from the code, and then delete the > comment. This is a plausible(*) strategy for internal use software where all users have easy access to all code which depends on yours and are free to change interfaces willy-nilly. That's not always the case. Even on open-source projects, having stand-alone documentation is critical for usability, and certainly having stable interfaces is critical if you expect people to adopt your system and build on it. (*)And, even in the case where it's internal code and everybody on the project has full and unfettered access to all the source, documenting interfaces adds to usability. I've seen plenty of code which looks like this (pseudo-code): Class1::f1() { return Class2::f2(); } Class2::f2() { return Class3::f3(); } Class3::f3() { return Class4::f4(); } If you're trying to figure out what type of object f1() returns, you've got to chase down a long string of, "Well, f1 returns whatever f2 returns, and f2 returns whatever f3 returns, and f3 returns whatever f4 returns, and...." Each step in that process might involve figuring out just where the heck the code for ClassN is. And Cthulhu help you if some step along the way involves an indirectly referenced class or function so you can't even grep the source tree for the name you're looking for. From jstrickler at gmail.com Sun May 29 11:48:34 2011 From: jstrickler at gmail.com (John S) Date: Sun, 29 May 2011 08:48:34 -0700 (PDT) Subject: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> On May 29, 10:35?am, Andrew Berg wrote: > On 2011.05.29 09:18 AM, Steven D'Aprano wrote:> >> What makes you think it shouldn't match? > > > > AFAIK, dots aren't supposed to match carriage returns or any other > > > whitespace characters. > > I got things mixed up there (was thinking whitespace instead of > newlines), but I thought dots aren't supposed to match '\r' (carriage > return). Why is '\r' not considered a newline character? Dots don't match end-of-line-for-your-current-OS is how I think of it. While I almost usually nod my head at Steven D'Aprano's comments, in this case I have to say that if you just want to grab something from a chunk of HTML, full-blown HTML parsers are overkill. True, malformed HTML can throw you off, but they can also throw a parser off. I could not make your regex work on my Linux box with Python 2.6. In your case, and because x264 might change their HTML, I suggest the following code, which works great on my system.YMMV. I changed your newline matches to use \s and put some capturing parentheses around the date, so you could grab it. >>> import urllib2 >>> import re >>> >>> content = urllib2.urlopen("http://x264.nl/x264_main.php").read() >>> >>> rx_x264version= re.compile(r"http://x264\.nl/x264/64bit/8bit_depth/revision\s*(\d{4})\s*/x264\s*\.exe") >>> >>> m = rx_x264version.search(content) >>> if m: ... print m.group(1) ... 1995 >>> \s is your friend -- matches space, tab, newline, or carriage return. \s* says match 0 or more spaces, which is what's needed here in case the web site decides to *not* put whitespace in the middle of a URL... As Steven said, when you want match a dot, it needs to be escaped, although it will work by accident much of the time. Also, be sure to use a raw string when composing REs, so you don't run into backslash issues. HTH, John Strickler From bahamutzero8825 at gmail.com Sun May 29 12:16:35 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 29 May 2011 11:16:35 -0500 Subject: Weird problem matching with REs In-Reply-To: <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> Message-ID: <4DE27163.3080104@gmail.com> On 2011.05.29 10:48 AM, John S wrote: > Dots don't match end-of-line-for-your-current-OS is how I think of > it. IMO, the docs should say the dot matches any character except a line feed ('\n'), since that is more accurate. > True, malformed > HTML can throw you off, but they can also throw a parser off. That was part of my point. html.parser.HTMLParser from the standard library will definitely not work on x264.nl's broken HTML, and fixing it requires lxml (I'm working with Python 3; I've looked into BeautifulSoup, and does not work with Python 3 at all). Admittedly, fixing x264.nl's HTML only requires one or two lines of code, but really nasty HTML might require quite a bit of work. > In your case, and because x264 might change their HTML, I suggest the > following code, which works great on my system.YMMV. I changed your > newline matches to use \s and put some capturing parentheses around > the date, so you could grab it. I've been meaning to learn how to use parenthesis groups. > Also, be sure to > use a raw string when composing REs, so you don't run into backslash > issues. How would I do that when grabbing strings from a config file (via the configparser module)? Or rather, if I have a predefined variable containing a string, how do change it into a raw string? From jstrickler at gmail.com Sun May 29 12:45:02 2011 From: jstrickler at gmail.com (John S) Date: Sun, 29 May 2011 09:45:02 -0700 (PDT) Subject: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> Message-ID: <4a265c16-52fb-4483-8bc2-a853c6d18220@dr5g2000vbb.googlegroups.com> On May 29, 12:16?pm, Andrew Berg wrote: > > I've been meaning to learn how to use parenthesis groups. > > Also, be sure to > > use a raw string when composing REs, so you don't run into backslash > > issues. > > How would I do that when grabbing strings from a config file (via the > configparser module)? Or rather, if I have a predefined variable > containing a string, how do change it into a raw string? When reading the RE from a file it's not an issue. Only literal strings can be raw. If the data is in a file, the data will not be parsed by the Python interpreter. This was just a general warning to anyone working with REs. It didn't apply in this case. --john strickler From ppearson at nowhere.invalid Sun May 29 13:21:11 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 29 May 2011 17:21:11 GMT Subject: scope of function parameters References: Message-ID: <94fdk7FihlU1@mid.individual.net> On Sun, 29 May 2011 04:30:52 -0400, Henry Olders wrote: [snip] > def main(): > a = ['a list','with','three elements'] > print a > print fnc1(a) > print a > > def fnc1(b): > return fnc2(b) > > def fnc2(c): > c[1] = 'having' > return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same > output as the first, but variable a had been changed by > changing variable c in fnc2. For what it's worth, I've noticed that use of the word "variable" is correlated with a misunderstanding of Python's way of doing things. "Variable" seems to connote a box that has something in it, so when fnc1 passes b to fnc2 which calls it c, you think you have a box named b and a box named c, and you wonder whether the contents of those boxes are the same or different. Python works in terms of objects having names, and one object can have many names. In your example, fnc1 works with an object that it calls b, and which it passes to fnc2, but fnc2 chooses to call that same object c. The names b and c aren't boxes that hold things, they are -- in the words of one of this group's old hands -- sticky-note labels that have been slapped on the same object. -- To email me, substitute nowhere->spamcop, invalid->net. From alister.ware at ntlworld.com Sun May 29 13:26:16 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Sun, 29 May 2011 17:26:16 GMT Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> <4de1011f$0$49184$e4fe514c@news.xs4all.nl> <94djdoFt6U1@mid.individual.net> Message-ID: On Sun, 29 May 2011 12:47:52 +1200, Gregory Ewing wrote: > Irmen de Jong wrote: > >> I don't see how that is opposed to what Grant was saying. It's that >> these 'contracts' tend to change and that people forget or are too lazy >> to update the comments to reflect those changes. > > However, I can't see that deleting the comment documenting the contract > can be the right response to the situation. > > If the contract comment doesn't match what code does, then there are two > possibilities -- the comment is wrong, or the code is wrong. The > appropriate response is to find out which one is wrong and fix it. > > If you simply delete the comment, then you're left with no redundancy to > catch the fact that something is wrong. "if the comments & code disagree then both are probably wrong" -- Most public domain software is free, at least at first glance. From python at mrabarnett.plus.com Sun May 29 13:44:08 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 29 May 2011 18:44:08 +0100 Subject: float("nan") in set or as key In-Reply-To: References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: <4DE285E8.4080801@mrabarnett.plus.com> On 29/05/2011 15:41, Grant Edwards wrote: > On 2011-05-29, Wolfgang Rohdewald wrote: >> On Sonntag 29 Mai 2011, Tim Delaney wrote: >>> There's a second part the mystery - sets and dictionaries (and >>> I think lists) assume that identify implies equality (hence >>> the second result). This was recently discussed on >>> python-dev, and the decision was to leave things as-is. >> >> On Sonntag 29 Mai 2011, Grant Edwards wrote: >>> Even if they are the same nan, it's still not equal to itself. >> >> if I understand this thread correctly, they are not equal to itself >> as specified by IEEE > > And Python follows that convention. > >> but Python treats them equal in sets and dictionaries for performance >> reasons > > It treats them as identical (not sure if that's the right word). The > implementation is checking for ( A is B or A == B ). Presumably, the > assumpting being that all objects are equal to themselves. That > assumption is not true for NaN objects, so the buggy behavior is > observed. > Would there be any advantage to making NaN a singleton? I'm thinking that it could make checking for it cheaper in the implementation of sets and dicts. Or making NaN unhashable? From rosuav at gmail.com Sun May 29 13:50:15 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 03:50:15 +1000 Subject: float("nan") in set or as key In-Reply-To: <4DE285E8.4080801@mrabarnett.plus.com> References: <4DE1881C.8000701@mrabarnett.plus.com> <4DE285E8.4080801@mrabarnett.plus.com> Message-ID: On Mon, May 30, 2011 at 3:44 AM, MRAB wrote: > Would there be any advantage to making NaN a singleton? I'm thinking > that it could make checking for it cheaper in the implementation of > sets and dicts. Or making NaN unhashable? Doesn't matter. It still wouldn't be equal to itself, even though it 'is' itself, which will greatly confuse anything that optimizes that away. Numbers are well-behaved; NaN is not a number; NaN is not well-behaved. It makes sense... in a way. Chris Angelico From rosuav at gmail.com Sun May 29 13:53:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 03:53:24 +1000 Subject: scope of function parameters In-Reply-To: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 29, 2011 at 10:47 PM, Steven D'Aprano wrote: > If a name is assigned to anywhere in the function, treat it as a local, > and look it up in the local namespace. If not found, raise > UnboundLocalError. > Wait wha? I've never seen this... wouldn't it just create it in the local namespace? Can you give example code that will trigger this error? I'm curious, now... Chris Angelico From rosuav at gmail.com Sun May 29 13:57:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 03:57:38 +1000 Subject: Weird problem matching with REs In-Reply-To: <4DE27163.3080104@gmail.com> References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> <4DE27163.3080104@gmail.com> Message-ID: On Mon, May 30, 2011 at 2:16 AM, Andrew Berg wrote: >> Also, be sure to >> use a raw string when composing REs, so you don't run into backslash >> issues. > How would I do that when grabbing strings from a config file (via the > configparser module)? Or rather, if I have a predefined variable > containing a string, how do change it into a raw string? > "Raw string" is slightly inaccurate. The Python "raw string literal" syntax is just another form of string literal: 'apostrophe-delimited string' "quote-delimited string" """triple-quote string which may go over multiple lines""" '''triple-apostrophe string''' r'raw apostrophe string' r"raw quote string" They're all equivalent once you have the string object. The only difference is how they appear in your source code. If you read something from a config file, you get a string object directly, and you delimit it with something else (end of line, or XML closing tag, or whatever), so you don't have to worry about string quotes. Chris Angelico From clp2 at rebertia.com Sun May 29 14:01:18 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 29 May 2011 11:01:18 -0700 Subject: scope of function parameters In-Reply-To: References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 29, 2011 at 10:53 AM, Chris Angelico wrote: > On Sun, May 29, 2011 at 10:47 PM, Steven D'Aprano > wrote: >> If a name is assigned to anywhere in the function, treat it as a local, >> and look it up in the local namespace. If not found, raise >> UnboundLocalError. >> > > Wait wha? I've never seen this... wouldn't it just create it in the > local namespace? > > Can you give example code that will trigger this error? I'm curious, now... def foo(): print bar bar = 42 foo() ===> Traceback (most recent call last): File "", line 1, in File "", line 2, in foo UnboundLocalError: local variable 'bar' referenced before assignment Cheers, Chris From lists at cheimes.de Sun May 29 14:05:07 2011 From: lists at cheimes.de (Christian Heimes) Date: Sun, 29 May 2011 20:05:07 +0200 Subject: float("nan") in set or as key In-Reply-To: <4DE285E8.4080801@mrabarnett.plus.com> References: <4DE1881C.8000701@mrabarnett.plus.com> <4DE285E8.4080801@mrabarnett.plus.com> Message-ID: Am 29.05.2011 19:44, schrieb MRAB: > Would there be any advantage to making NaN a singleton? I'm thinking > that it could make checking for it cheaper in the implementation of > sets and dicts. Or making NaN unhashable? It can't be a singleton, because IEEE 754 specifies millions of millions of different NaN values. There are positive and negative NaNs, quiet NaNs and signaling NaNs. 50 of 52 mantissa bits can vary freely, one bit makes the difference between signaling and quiet NaNs and at least one bit must be non-zero. Christian From steve+comp.lang.python at pearwood.info Sun May 29 14:27:08 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 18:27:08 GMT Subject: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> Message-ID: <4de28ffc$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 18:44:08 +0100, MRAB wrote: > Would there be any advantage to making NaN a singleton? Absolutely not. That would be a step backwards. NANs can carry payload (a code indicating what sort of NAN it represents -- log(-1) and 1/INF are not the same). So although Python currently has no easy way to access that payload (you can do it with the struct module), it does exist and for serious work you would want to be able to set and get it. > I'm thinking > that it could make checking for it cheaper in the implementation of sets > and dicts. I don't see how would it be cheaper, but even if it were, talk about a micro-optimization! I'd really *love* to see the code where the time it takes to insert a NAN in a set was the bottleneck! > Or making NaN unhashable? I could live with that, although I don't think it is necessary. What actual problem are you hoping to solve here? -- Steven From steve+comp.lang.python at pearwood.info Sun May 29 14:28:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 18:28:20 GMT Subject: scope of function parameters References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de29043$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 03:53:24 +1000, Chris Angelico wrote: > On Sun, May 29, 2011 at 10:47 PM, Steven D'Aprano > wrote: >> If a name is assigned to anywhere in the function, treat it as a local, >> and look it up in the local namespace. If not found, raise >> UnboundLocalError. >> >> > Wait wha? I've never seen this... wouldn't it just create it in the > local namespace? > > Can you give example code that will trigger this error? I'm curious, > now... def f(): print a # a is not yet defined, i.e. unbound a = 1 # this makes a local -- Steven From rosuav at gmail.com Sun May 29 14:38:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 04:38:26 +1000 Subject: scope of function parameters In-Reply-To: References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 30, 2011 at 4:01 AM, Chris Rebert wrote: > def foo(): > ? ?print bar > ? ?bar = 42 > > foo() > > ===> > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 2, in foo > UnboundLocalError: local variable 'bar' referenced before assignment Wow I thought it basically functioned top-down. You get a different error on the print line if there's a "bar = 42" *after* it. This could make debugging quite confusing. Guess it's just one of the consequences of eschewing variable declarations. Sure it's easier, but there's complications down the road. Chris Angelico From steve+comp.lang.python at pearwood.info Sun May 29 14:46:54 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 18:46:54 GMT Subject: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> <4DE285E8.4080801@mrabarnett.plus.com> Message-ID: <4de2949e$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 20:05:07 +0200, Christian Heimes wrote: > Am 29.05.2011 19:44, schrieb MRAB: >> Would there be any advantage to making NaN a singleton? I'm thinking >> that it could make checking for it cheaper in the implementation of >> sets and dicts. Or making NaN unhashable? > > It can't be a singleton, because IEEE 754 specifies millions of millions > of different NaN values. A million-millioneton then? *wink* > There are positive and negative NaNs, I've never quite understood that. NANs are unordered, and therefore cannot be said to be larger than zero (positive) or less than zero (negative). So even if a NAN has the sign bit set, surely the right way to think about that is to treat the sign bit as part of the payload? It seems to me that talking about signed NANs is inaccurate and adds confusion. NANs cause enough confusion as it is, without adding to it... (I would expect the copysign function to honour the sign bit, so I suppose in that sense one might describe NANs as signed.) -- Steven From steve+comp.lang.python at pearwood.info Sun May 29 14:53:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 18:53:06 GMT Subject: scope of function parameters References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de29612$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 04:38:26 +1000, Chris Angelico wrote: > On Mon, May 30, 2011 at 4:01 AM, Chris Rebert wrote: >> def foo(): >> ? ?print bar >> ? ?bar = 42 >> >> foo() >> >> ===> >> Traceback (most recent call last): >> ?File "", line 1, in >> ?File "", line 2, in foo >> UnboundLocalError: local variable 'bar' referenced before assignment > > Wow > > I thought it basically functioned top-down. You get a different error on > the print line if there's a "bar = 42" *after* it. This could make > debugging quite confusing. UnboundLocalError is a subclass of NameError, so it will still be caught by try...except NameError. If you're crazy enough to be catching NameError :) Go back to Python1.5, and there was no UnboundLocalError. It was introduced because people were confused when they got a NameError after forgetting to declare something global: >>> def f(): ... print a ... a = a + 1 ... >>> a = 42 >>> f() Traceback (innermost last): File "", line 1, in ? File "", line 2, in f NameError: a While UnboundLocalError is jargon, and not the easiest error message to comprehend, at least it confuses in a different way :) -- Steven From PointedEars at web.de Sun May 29 15:06:53 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 29 May 2011 21:06:53 +0200 Subject: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4248834.rdbgypaU67@PointedEars.de> Andrew Berg wrote: > On 2011.05.29 10:19 AM, Roy Smith wrote: >> Named after the governor of Tarsus IV? > Judging by the graphic at http://kodos.sourceforge.net/help/kodos.html , > it's named after the Simpsons character. I don't think that's a coincidence; both are from other planets and both are rather evil[tm]. Kodos the Executioner, arguably human, became a dictator who had thousands killed (by his own account, not to let the rest die of hunger); Kodos the slimy extra-terrestrial is a conqueror (and he likes to zap humans as well ;-)) [BTW, Tarsus IV, a planet where thousands (would) have died of hunger and have died in executions was probably yet another hidden Star Trek euphemism. I have found out that Tarsus is, among other things, the name of a collection of bones in the human foot next to the heel. Bones as a reference to death aside, see also Achilles for the heel. But I'm only speculating here.] -- \\//, PointedEars (F'up2 trek) Bitte keine Kopien per E-Mail. / Please do not Cc: me. From ian.g.kelly at gmail.com Sun May 29 15:12:16 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 29 May 2011 13:12:16 -0600 Subject: scope of function parameters In-Reply-To: References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, May 29, 2011 at 12:38 PM, Chris Angelico wrote: > I thought it basically functioned top-down. You get a different error > on the print line if there's a "bar = 42" *after* it. This could make > debugging quite confusing. > > Guess it's just one of the consequences of eschewing variable > declarations. Sure it's easier, but there's complications down the > road. It's also a consequence of local variable access being optimized with different bytecode: the type of storage has to be determined at compile time. The compiler could in principle figure out that "bar" cannot be bound at that point and make it a global reference, but it is easy to concoct situations involving loops or conditionals where the storage cannot be determined at compile time, and so the compiler follows the simple rule of making everything local unless it's never assigned. Cheers, Ian From rosuav at gmail.com Sun May 29 15:20:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 05:20:51 +1000 Subject: scope of function parameters In-Reply-To: <4de29612$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de29612$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 30, 2011 at 4:53 AM, Steven D'Aprano wrote: > UnboundLocalError is a subclass of NameError, so it will still be caught > by try...except NameError. > > If you're crazy enough to be catching NameError :) Ah okay. So it is still NameError, it just doesn't look like one. > While UnboundLocalError is jargon, and not the easiest error message to > comprehend, at least it confuses in a different way :) I have nothing against jargon, and specific errors are better than generic ones (imagine if every error were thrown as Exception with a string parameter... oh wait, that's what string exceptions are). It still seems a little odd that a subsequent line can affect this one. But Python's mostly doing what would be expected of it; the worst I can come up with is this: def f(): print(foo) # reference a global ... for foo in bar: # variable only used in loop pass If you're used to C++ and declaring variables inside a for loop eg "for (int i=0;i<10;++i)", you might not concern yourself with the fact that 'foo' is masking a global; it's not an issue, because you don't need that global inside that loop, right? And it would be fine, except that that global IS used somewhere else in the function. It'd be a bit confusing to get the UnboundLocalError up on the print(foo) line (the one that's meant to be using the global), since that line isn't wrong; and the "obvious fix", adding an explicit "global foo" to the top of the function, would be worse (because it would mean that the for loop overwrites the global). This is why I would prefer to declare variables. The Zen of Python says that explicit is better than implicit, but in this instance, Python goes for DWIM, guessing whether you meant global or local. It guesses fairly well, though. Chris Angelico From tack at urandom.ca Sun May 29 15:28:46 2011 From: tack at urandom.ca (Jason Tackaberry) Date: Sun, 29 May 2011 15:28:46 -0400 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: <4DE29E6E.7040309@urandom.ca> On 11-05-29 04:06 AM, Ian Kelly wrote: > I realize you are now asserting that compatibility is a boolean > condition, and that "totally incompatible" is a redundant phrase that > you tossed out as a joke. As a casual lurker reading this thread, I believe he is equating "completely incompatible" with "not completely compatible." At least, his arguments make more sense if I read him as arguing from the "not completely compatible" position. It's possible he is intentionally equivocating for dramatic effect. But they are different -- both connotatively and denotatively -- and to argue against the claim that Python 2 and 3 are "completely incompatible" it seems to me sufficient to provide a single non-trivial counter-example, which Steven has already done. Cheers, Jason. From rantingrick at gmail.com Sun May 29 16:16:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:16:50 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: On May 18, 7:19?am, Peter Moylan wrote: > It's interesting to note that the definitions of 'recursive' to be found > in Wikipedia and Wiktionary have very little in common with the > definitions to be found in the dictionaries covered by Onelook. ?No > wonder experts in different areas have trouble communicating with one > another. Yes, and when you extrapolate that conclusion into the current hodge podge of natural languages you begin to understand the genesis of human beings selfish nature. From henry.olders at mcgill.ca Sun May 29 16:19:11 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Sun, 29 May 2011 16:19:11 -0400 Subject: scope of function parameters In-Reply-To: <201105291147.26545.wolfgang@rohdewald.de> References: <201105291147.26545.wolfgang@rohdewald.de> Message-ID: <371A067F-540A-46C3-820C-4348B9815AB9@mcgill.ca> Henry On 2011-05-29, at 5:47 , Wolfgang Rohdewald wrote: > On Sonntag 29 Mai 2011, Henry Olders wrote: >> It seems that in Python, a variable inside a function is >> global unless it's assigned. > > no, they are local > >> I would have thought that a function parameter would >> automatically be considered local to the function. It doesn't >> make sense to me to pass a global to a function as a >> parameter. > > it is local. But consider what you actually passed: > You did not pass a copy of the list but the list itself. > You could also say you passed a reference to the list. > All python variables only hold a pointer (the id) to > an object. This object has a reference count and is > automatically deleted when there are no more references > to it. > > If you want a local copy of the list you can either > do what you called being ugly or do just that within > the function itself - which I think is cleaner and > only required once. > > def fnc2(c): > c = c[:] > c[1] = 'having' > return c Thank you, Wolfgang. That certainly works, but to me it is still a workaround to deal with the consequence of a particular decision. From my perspective, a function parameter should be considered as having been assigned (although the exact assignment will not be known until runtime), and as an assigned variable, it should be considered local. Henry From tjreedy at udel.edu Sun May 29 16:27:17 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 May 2011 16:27:17 -0400 Subject: scope of function parameters In-Reply-To: References: Message-ID: On 5/29/2011 7:59 AM, Mel wrote: > Henry Olders wrote: > >> I just spent a considerable amount of time and effort debugging a program. >> The made-up code snippet below illustrates the problem I encountered: >> >> def main(): >> a = ['a list','with','three elements'] >> print a >> print fnc1(a) >> print a >> >> def fnc1(b): >> return fnc2(b) >> >> def fnc2(c): >> c[1] = 'having' >> return c >> >> This is the output: >> ['a list', 'with', 'three elements'] >> ['a list', 'having', 'three elements'] >> ['a list', 'having', 'three elements'] >> >> I had expected the third print statement to give the same output as the >> first, but variable a had been changed by changing variable c in fnc2. >> >> It seems that in Python, a variable inside a function is global unless >> it's assigned. This rule has apparently been adopted in order to reduce >> clutter by not having to have global declarations all over the place. >> >> I would have thought that a function parameter would automatically be >> considered local to the function. Function *parameters* are names, the first *local names* of the function. >> It doesn't make sense to me to pass a global to a function as a parameter. You are right, in a way;-). Global *names* are just names. When you call a function, you pass *objects* as *arguments*. Of course, you may refer to the object by a global name to pass it, or you can pass a string object that contains a global name. > > It doesn't look like a question of local or global. fnc2 is passed a > container object and replaces item 1 in that container. You see the results > when fnc2 prints the object it knows as `c`, and you see again when main > prints the object it knows as `a`. Python doesn't pass parameters by > handing around copies that can be thought of as local or global. Python > passes parameters by binding objects to names in the callee's namespace. In > your program the list known as `a` in main is identically the same list as > the one known as `c` in fnc2, and what happens happens. Right. Python has one unnamed 'objectspace'. It has many, many namespaces: builtins, globals for each module, locals for each function and class, and attributes for some instances. Each name and each collection slot is associated with one object. Each object can have multiple associations, as in the example above. -- Terry Jan Reedy From rantingrick at gmail.com Sun May 29 16:28:12 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:28:12 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> Message-ID: <15e794b2-df2e-4dae-8f49-ae7dfe1f21d7@x1g2000yqb.googlegroups.com> On May 18, 12:59?pm, s... at sig.for.address (Victor Eijkhout) wrote: > Harrison Hill wrote: > > No need - I have the Dictionary definition of recursion here: > > > Recursion: (N). See recursion. > > If you tell a joke, you have to tell it right. Jeez, speaking of bad colloquialisms... """if you're going to "share" a joke you should at least "recite" it CORRECTLY.""" Thank you. From rantingrick at gmail.com Sun May 29 16:28:47 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:28:47 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> Message-ID: <497db348-1f28-486c-abf3-0385c721d16c@d1g2000yqm.googlegroups.com> On May 18, 12:59?pm, s... at sig.for.address (Victor Eijkhout) wrote: > Harrison Hill wrote: > > No need - I have the Dictionary definition of recursion here: > > > Recursion: (N). See recursion. > > If you tell a joke, you have to tell it right. Jeez, speaking of bad colloquialisms... """if you're going to "share" a joke you should at least "recite" it CORRECTLY.""" Thank you. From rantingrick at gmail.com Sun May 29 16:32:08 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:32:08 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: Message-ID: <0322ba69-f7ec-4c62-ab68-deaeadbd7a9a@x1g2000yqb.googlegroups.com> On May 18, 3:00?pm, Xah Lee wrote: > In the emacs case: ?Recursive delete of xx? (y or n) ?, what could it > possibly mean by the word ?recursive? there? Like, it might delete the > directory but not delete all files in it? Actually i think this case is more for "scare factor" than anything. As in... Do you really want to destroy all these files FOREVER AND EVER or did your mouse finger slip... again? From rantingrick at gmail.com Sun May 29 16:39:49 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:39:49 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8f16b7ff-1ab5-4a9a-b4f5-002ef0ce6037@28g2000yqu.googlegroups.com> On May 20, 1:55?am, Steven D'Aprano wrote: > Trust me on this, if the audience of Carry On films could understand > recursion, anyone can! Well we could also say that this pathetic display of metal masturbation is recursive also. From rantingrick at gmail.com Sun May 29 16:58:18 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 13:58:18 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 24, 5:06?pm, Rikishi42 wrote: > On 2011-05-24, Steven D'Aprano wrote: > > I wonder whether physicists insist that cars should have a "go faster > > pedal" because ordinary people don't need to understand Newton's Laws of > > Motion in order to drive cars? > > Gas pedal. Pedal was allraedy known when the car was invented. The simple > addition of gas solved that need. Oh, and it's break pedal, not > descellarator. (sp?) Yes "Gas Pedal"... that clears up all the confusion . However i would have thought if the vehicle had a "decelerator petal" it would at least sport a complimentary "accelerator petal". You know the whole "equal and opposite thing"? > > Who are you to say that people shouldn't be exposed to words you deem > > that they don't need to know? > > I'm one of the 'people'. You say exposed to, I say bothered/bored with. > > I have nothing against the use of a proper, precise term. And that word can > be a complex one with many, many sylables (seems to add value, somehow). > > But I'm not an academic, so I don't admire the pedantic use of terms that > need to be explained to 'lay' people. Especially if there is a widespread, > usually shorter and much simpler one for it. A pointless effort if > pointless, even when comming from a physicist. ?:-) You may be "right", but then again, who knows, you may be left? In this upside down world of layperson colloquialisms -- which ironic-ly enough are devised to "ease communication"... right? I mean i "used to" think that choosing words that clearly described my intentions was a good idea but heck, i would hate to think that those poor laypeople had to languish though such tongue twisting syllable gymnastics just for the sake of clear communications. From rantingrick at gmail.com Sun May 29 17:18:15 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 14:18:15 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6d31d8da-e767-4b05-888e-5db5d42d8f5d@v10g2000yqn.googlegroups.com> On May 24, 7:40?pm, Chris Angelico wrote: > On Wed, May 25, 2011 at 8:06 AM, Rikishi42 wrote: > > On 2011-05-24, Steven D'Aprano wrote: > >> I wonder whether physicists insist that cars should have a "go faster > >> pedal" because ordinary people don't need to understand Newton's Laws of > >> Motion in order to drive cars? > > > Gas pedal. Pedal was allraedy known when the car was invented. The simple > > addition of gas solved that need. Oh, and it's break pedal, not > > descellarator. (sp?) > > Americans might call it a gas pedal. We call it an accelerator. You > don't have a "decelerator pedal" though, because it's more accurately > called a "brake pedal" because it controls the brakes. Actually the same argument could be applied to your observation of the driver to vehicle interface. You say "brake petal" simple because it controls the brakes. Well then what does the "accelerator" control then? Most wise observers would blubber... "I know, I know, it controls the gas!"...and while partially correct they would be mostly wrong. Yes it does control the "gas" but not in a direct way. Of course technically it depends on implementation (a favorite word around c.l.py it seems *rolls-eyes*). In the days of carburetors the "accelerator" actually controlled a big flap. This "big flap" (An attribute of which many round here seem to posses and use generously) is opened to allow air to enter and the gas is mixed into the air by secondary effect. So if we really wanted to get pedantic we should call it an "air petal"? However considering that any vehicle made after the early nineties is fuel injected (which is controlled by a computer!) then we may want to call it a "puter petal" to be precise. Note: The remainder of your post was lucid and informative. From rantingrick at gmail.com Sun May 29 17:19:15 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 14:19:15 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <28b4a038-cb6e-4dd6-881b-9eead5211277@d1g2000yqm.googlegroups.com> On May 24, 7:40?pm, Chris Angelico wrote: > On Wed, May 25, 2011 at 8:06 AM, Rikishi42 wrote: > > On 2011-05-24, Steven D'Aprano wrote: > >> I wonder whether physicists insist that cars should have a "go faster > >> pedal" because ordinary people don't need to understand Newton's Laws of > >> Motion in order to drive cars? > > > Gas pedal. Pedal was allraedy known when the car was invented. The simple > > addition of gas solved that need. Oh, and it's break pedal, not > > descellarator. (sp?) > > Americans might call it a gas pedal. We call it an accelerator. You > don't have a "decelerator pedal" though, because it's more accurately > called a "brake pedal" because it controls the brakes. Actually the same argument could be applied to your observation of the driver to vehicle interface. You say "brake petal" simple because it controls the brakes. Well then what does the "accelerator" control then? Most wise observers would blubber... "I know, I know, it controls the gas!"...and while partially correct they would be mostly wrong. Yes it does control the "gas" but not in a direct way. Of course technically it depends on implementation (a favorite word around c.l.py it seems *rolls-eyes*). In the days of carburetors the "accelerator" actually controlled a big flap. This "big flap" (An attribute of which many round here seem to posses and use generously) is opened to allow air to enter and the gas is mixed into the air by secondary effect. So if we really wanted to get pedantic we should call it an "air petal"? However considering that any vehicle made after the early nineties is fuel injected (which is controlled by a computer!) then we may want to call it a "puter petal" to be precise. Note: The remainder of your post was lucid and informative. From nobody at nowhere.com Sun May 29 17:19:49 2011 From: nobody at nowhere.com (Nobody) Date: Sun, 29 May 2011 22:19:49 +0100 Subject: float("nan") in set or as key References: <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> <4de22007$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 29 May 2011 10:29:28 +0000, Steven D'Aprano wrote: >> The correct answer to "nan == nan" is to raise an exception, because >> you have asked a question for which the answer is nether True nor False. > > Wrong. That's overstating it. There's a good argument to be made for raising an exception. Bear in mind that an exception is not necessarily an error, just an "exceptional" condition. > The correct answer to "nan == nan" is False, they are not equal. There is no correct answer to "nan == nan". Defining it to be false is just the "least wrong" answer. Arguably, "nan != nan" should also be false, but that would violate the invariant "(x != y) == !(x == y)". From rosuav at gmail.com Sun May 29 17:27:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 07:27:59 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, May 30, 2011 at 6:58 AM, rantingrick wrote: > Yes "Gas Pedal"... that clears up all the confusion . > However i would have thought if the vehicle had a "decelerator petal" > it would at least sport a complimentary "accelerator petal". You know > the whole "equal and opposite thing"? Call the go-faster pedal the "Newton's Second Law pedal", and the oops-here-comes-an-obstacle pedal the "Newton's Third Law pedal", because if you hit that thing, you'll see the third law in action. We then need a demonstration of Newton's First Law, which I think is the ignition key. We should turn it into a pedal to be consistent. For the humour-blind: Chris Angelico From rantingrick at gmail.com Sun May 29 17:38:24 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 14:38:24 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: On May 26, 6:12?am, Chris Angelico wrote: > I just conducted a rapid poll of a non-technical userbase. > > (Okay, I just asked my sister who happens to be sitting here. But > she's nontechnical.) > > She explained "recursive" as "it repeats until it can't go any > further". I think that's a fair, if not perfectly accurate, > explanation. Yes but understanding of this sort is very general ESPECIALLY in the case of destroying data! What are the limits of the recursion? What forces can act on the recursion to stop it? If (for example) I know that a "while loop" will continue forever until "something" stops it then i really don't know enough about while loops to start using them safely do i? I need to know what a "break" will do or god forbid what if an exception is thrown? What about if a condition is explicitly passed? I need to know how to interpret the condition and it's consequences. Crikey, this is getting complicated 8-O! PS: Of course i could just cross my fingers, run the code, and hope for the best but i'm not a Perl hacker. From rantingrick at gmail.com Sun May 29 17:38:30 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 14:38:30 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: <7ec80ef6-ca5e-46e7-a6e4-36d3652c7205@r20g2000yqd.googlegroups.com> On May 26, 6:12?am, Chris Angelico wrote: > I just conducted a rapid poll of a non-technical userbase. > > (Okay, I just asked my sister who happens to be sitting here. But > she's nontechnical.) > > She explained "recursive" as "it repeats until it can't go any > further". I think that's a fair, if not perfectly accurate, > explanation. Yes but understanding of this sort is very general ESPECIALLY in the case of destroying data! What are the limits of the recursion? What forces can act on the recursion to stop it? If (for example) I know that a "while loop" will continue forever until "something" stops it then i really don't know enough about while loops to start using them safely do i? I need to know what a "break" will do or god forbid what if an exception is thrown? What about if a condition is explicitly passed? I need to know how to interpret the condition and it's consequences. Crikey, this is getting complicated 8-O! PS: Of course i could just cross my fingers, run the code, and hope for the best but i'm not a Perl hacker. From ray at aarden.us Sun May 29 17:41:47 2011 From: ray at aarden.us (ray) Date: Sun, 29 May 2011 14:41:47 -0700 (PDT) Subject: How to Use Setuptools, Alternatives? Message-ID: <01045077-543f-4b8d-a5a2-4cde190c3294@v8g2000yqb.googlegroups.com> I have Python 2.7 on Win7 Pro on a tightly locked down desktop. I would like to install Networkx from an egg. From what I have read, Setuptools can be used for this. I don't know how to install Setuptools. The exe will not work. On execution, it reports that the Python version is not included in the registry. Further, I can not input the version and location on the subsequent installation screen, the fields will not accept focus so I can not input the values. Since the exe will not install, I considered using the Setuptools egg. But it requires Setuptools. It appears to be a circle. What are some suggestions for installing this? Thanks, ray From ben+python at benfinney.id.au Sun May 29 17:42:19 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 May 2011 07:42:19 +1000 Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> Message-ID: <87tycd89qc.fsf@benfinney.id.au> Peter Pearson writes: > Python works in terms of objects having names, and one > object can have many names. Or no names. So it's less accurate (though better than talking of ?variables?) to speak of Python objects ?having names?. > The names b and c aren't boxes that hold things, they are -- in the > words of one of this group's old hands -- sticky-note labels that have > been slapped on the same object. Right. And in that analogy, the object *still* doesn't ?have a name? (since that implies the false conclusion that the object knows its own name); rather, the name is bound to the object, and the object is oblivious of this. I prefer to talk not of sticky notes, but paper tags with string; the string leading from tag to object is an important part, and the paper tag might not even have a name written on it, allowing the same analogy to work for other non-name references like list indices etc. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but where are we going to find a duck and a hose at this | _o__) hour?? ?_Pinky and The Brain_ | Ben Finney From rosuav at gmail.com Sun May 29 17:46:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 07:46:55 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: On Mon, May 30, 2011 at 7:38 AM, rantingrick wrote: > Yes but understanding of this sort is very general ESPECIALLY in the > case of destroying data! > > What are the limits of the recursion? What forces can act on the > recursion to stop it? If (for example) I know that a "while loop" will > continue forever until "something" stops it then i really don't know > enough about while loops to start using them safely do i? That's true of anything. If I turn on the light switch, I expect there to be a limit to the amount of light it produces; I don't want a household fluro to produce the intensity of the worklights in a theatre. Ought I to get the technical specs and find out exactly how many lumens will be produced, or can I safely power it on in the expectation that it will do the obvious thing? Chris Angelico PS. Why am I responding to rantingrick? I'm sure I'm going to regret this. From chead at is.invalid Sun May 29 17:48:53 2011 From: chead at is.invalid (Christopher Head) Date: Sun, 29 May 2011 14:48:53 -0700 Subject: scope of function parameters References: <201105291147.26545.wolfgang@rohdewald.de> Message-ID: <20110529144853.2adff584@kruskal.chead> On Sun, 29 May 2011 16:19:11 -0400 Henry Olders wrote: > > def fnc2(c): > > c = c[:] > > c[1] = 'having' > > return c > > Thank you, Wolfgang. That certainly works, but to me it is still a > workaround to deal with the consequence of a particular decision. > From my perspective, a function parameter should be considered as > having been assigned (although the exact assignment will not be known > until runtime), and as an assigned variable, it should be considered > local. > > Henry This has nothing to do with function parameters and everything to do with what a "variable name" actually means. You can get the same effect with only globals: >>> x=[1,2,3] >>> y=x >>> x.append(7) >>> y [1, 2, 3, 7] Why in the world does "y" end with 7, even though it was appended to "x"? Simple: because "x" and "y" are two names for the same list, as Henry explained. No functions involved, no locals, no parameters, no scoping. Again, if "y=x" were instead "y=x[:]" then the output would be "[1,2,3]" because "y" would refer to a copy of the list rather than the same list. Chris From ray at aarden.us Sun May 29 17:49:28 2011 From: ray at aarden.us (ray) Date: Sun, 29 May 2011 14:49:28 -0700 (PDT) Subject: Alternatives to PythonPath Message-ID: I am using Win7 on a tightly locked down desktop. Is there an alternative to using PythonPath? What are the trade-offs? Thanks, ray From rantingrick at gmail.com Sun May 29 18:15:31 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 15:15:31 -0700 (PDT) Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: <3820a126-2173-4a3a-b345-17220dce3c9e@q32g2000yqn.googlegroups.com> On May 28, 9:33?pm, harrismh777 wrote: > Steven D'Aprano wrote: > > A straw man is not when somebody points out holes in your argument, or > > unwanted implications that you didn't realise were there. It is when > > somebody makes claims on your behalf that you did not make to discredit > > you, not because you don't understand the implications of your own > > argument. > > The straw-man fallacy is when you erect a "straw man" to "represent" the > actual man (or idea) which can be easily knocked down, and then you > proceed to knock it down (the straw-man) as though the "straw man" was > the actual man, or idea... proving your point as-it-were against your > opponent when in fact you have only just knocked down the straw-man... > leaving the real man standing. > > This fallacy has a couple of nuances (sometimes combined with metaphor > or analogy fallacy) and you are a master at presenting both... > thankfully you usually don't try to present both at the same time! ?:) > > In this present case the straw-man was not "me," rather the straw-man > was the python language itself. You chose a code-snippet (one small puny > dangle that doesn't prove a thing) and used it to speak for the entire > language! ?As though one code-block is enough to demonstrate > compatibility for the entire language in all of its nuances and details. > ? To prove something positive with a test case requires that you provide > *all* test cases, or that you provide an algorithm that accounts for > *all* test cases... you cannot prove compatibility with a code-snippet. > > On the other hand, all you have to do to prove incompatibility is to > show "one" (1) test case where compatibility fails... and of course for > the present case there are many that can be shown, in fact, hundreds of > them. > > The thing that nobody has presented here yet is that *all* the books > declare that 3.x is incompatible with 2.x/ ? ... some of them go out of > their way to tell the reader that they are only going to deal with 3.x > and not 2.x in any way... and others go out of their way to point out > the hundreds of nuances in details between the two languages. (and a > good thing too, for those of us who must work with both! ) ?So this fact > is not alluding the press... the point being not to bust anybody in the > chops, but to point out that it is not helpful to move the community > forward with a new language and get mass adoption (not just early > adopters) to lie about the differences between the two sets... yes, for > trivial code blocks that use prime constructs, integer math, and the > print statement, not much has changed. ?But in real world applications > of the language there are many hundreds of details that have changed or > been added (deleted) which will make life difficult for the uninitiated. > Don't mislead people by saying that very little has changed. ?Tell them > that the philosophy is the same (what Chris called python 'think' ) but > be honest about the details of syntax, environment, layout, and > morphology. Bravo! PS: And yes, Steven is a master at the straw man fallacy. From tjreedy at udel.edu Sun May 29 18:20:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 May 2011 18:20:30 -0400 Subject: scope of function parameters In-Reply-To: <371A067F-540A-46C3-820C-4348B9815AB9@mcgill.ca> References: <201105291147.26545.wolfgang@rohdewald.de> <371A067F-540A-46C3-820C-4348B9815AB9@mcgill.ca> Message-ID: On 5/29/2011 4:19 PM, Henry Olders wrote: > From my perspective, a function parameter should be considered as > having been assigned (although the exact assignment will not be known > until runtime), and as an assigned variable, it should be considered > local. That is exactly the case for Python functions. >>> def f(a,b): c,d = 3,4 print(locals()) >>> f.__code__.co_varnames # local names ('a', 'b', 'c', 'd') >>> f(1,2) {'a': 1, 'c': 3, 'b': 2, 'd': 4} The requirement for a function call is that all parameters get an assignment and that all args are used in assignments (either directly by position or keyname or as part of a *args or **kwds assignment). -- Terry Jan Reedy From irmen.NOSPAM at xs4all.nl Sun May 29 18:30:08 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 30 May 2011 00:30:08 +0200 Subject: How to Use Setuptools, Alternatives? In-Reply-To: <01045077-543f-4b8d-a5a2-4cde190c3294@v8g2000yqb.googlegroups.com> References: <01045077-543f-4b8d-a5a2-4cde190c3294@v8g2000yqb.googlegroups.com> Message-ID: <4de2c8f1$0$49182$e4fe514c@news.xs4all.nl> On 29-5-2011 23:41, ray wrote: > I have Python 2.7 on Win7 Pro on a tightly locked down desktop. I > would like to install Networkx from an egg. From what I have read, > Setuptools can be used for this. What does 'tightly locked down' mean? > I don't know how to install Setuptools. The exe will not work. On > execution, it reports that the Python version is not included in the > registry. That can be fixed by repairing the Python installation through its .msi. Also, are you sure you used the python 2.7 setuptools exe? > Further, I can not input the version and location on the > subsequent installation screen, the fields will not accept focus so I > can not input the values. > > Since the exe will not install, I considered using the Setuptools > egg. But it requires Setuptools. It appears to be a circle. > > What are some suggestions for installing this? > > Thanks, > ray Perhaps you can try VirtualEnv and PiP instead. Irmen From irmen.NOSPAM at xs4all.nl Sun May 29 18:31:08 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 30 May 2011 00:31:08 +0200 Subject: Alternatives to PythonPath In-Reply-To: References: Message-ID: <4de2c92d$0$49182$e4fe514c@news.xs4all.nl> On 29-5-2011 23:49, ray wrote: > I am using Win7 on a tightly locked down desktop. > > Is there an alternative to using PythonPath? > What do you mean by "using PythonPath"? What doesn't work that you want to have an alternative for? Irmen From benjamin at python.org Sun May 29 18:44:58 2011 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 29 May 2011 17:44:58 -0500 Subject: [RELEASE] 3.1.4 release candidate 1 Message-ID: On behalf of the Python development team, I'm happy as a swallow to announce a release candidate for the fourth bugfix release for the Python 3.1 series, Python 3.1.4. 3.1.4 will the last bug fix release in the 3.1 series before 3.1. After 3.1.4, 3.1 will be in security-only fix mode. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. This is a testing release. To download Python 3.1.4rc1 visit: http://www.python.org/download/releases/3.1.4/ A list of changes in 3.1.4 can be found here: http://hg.python.org/cpython/file/35419f276c60/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.4's contributors) From benjamin at python.org Sun May 29 18:47:42 2011 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 29 May 2011 17:47:42 -0500 Subject: [RELEASE] Python 2.7.2 release candidate 1 Message-ID: On behalf of the Python development team, I'm happy to announce the immediate availability of Python 2.7.2 release candidate 1. 2.7.2 is the second in bugfix release for the Python 2.7 series. 2.7 is the last major verison of the 2.x line and will be receiving bug fixes while new feature development focuses on 3.x. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, auto-numbering of fields in the str/unicode format method, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7.2rc1 visit: http://www.python.org/download/releases/2.7.1/ The 2.7.2 changelog is at: http://hg.python.org/cpython/file/439396b06416/Misc/NEWS 2.7 documentation can be found at: http://docs.python.org/2.7/ This is a preview release. Assuming no major problems, 2.7.2 will be released in two weeks. Please report any bugs you find to http://bugs.python.org/ Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7.2's contributors) From rantingrick at gmail.com Sun May 29 18:54:12 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 15:54:12 -0700 (PDT) Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <4dde325f$0$67776$c30e37c6@exi-reader.telstra.net> Message-ID: <0af840cd-0ece-4345-853d-775be12aa12f@k16g2000yqm.googlegroups.com> On May 29, 4:46?pm, Chris Angelico wrote: > On Mon, May 30, 2011 at 7:38 AM, rantingrick wrote: > > Yes but understanding of this sort is very general ESPECIALLY in the > > case of destroying data! > > > What are the limits of the recursion? What forces can act on the > > recursion to stop it? If (for example) I know that a "while loop" will > > continue forever until "something" stops it then i really don't know > > enough about while loops to start using them safely do i? > > That's true of anything. If I turn on the light switch, I expect there > to be a limit to the amount of light it produces; I don't want a > household fluro to produce the intensity of the worklights in a > theatre. Ought I to get the technical specs and find out exactly how > many lumens will be produced, or can I safely power it on in the > expectation that it will do the obvious thing? That is a very good argument however it does not consider the fact of "technical users" verses "non-technical users". Anyone can be expected to understand the consequenses of switching on a lightbulb (even a child) because the action requires no logical thinking abilites... simply flip it and forget it. HOWEVER not everyone understands the consequeses of recursively deleting a directory... or whatever that means in the current context. From rantingrick at gmail.com Sun May 29 19:00:06 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 29 May 2011 16:00:06 -0700 (PDT) Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: <60c7d496-e099-4cd2-8fa5-5f395cf4b21a@e35g2000yqc.googlegroups.com> On May 29, 2:28?pm, Jason Tackaberry wrote: > On 11-05-29 04:06 AM, Ian Kelly wrote: > > > I realize you are now asserting that compatibility is a boolean > > condition, and that "totally incompatible" is a redundant phrase that > > you tossed out as a joke. > > As a casual lurker reading this thread, I believe he is equating > "completely incompatible" with "not completely compatible." ?At least, > his arguments make more sense if I read him as arguing from the "not > completely compatible" position. ?It's possible he is intentionally > equivocating for dramatic effect. > > But they are different -- both connotatively and denotatively -- and to > argue against the claim that Python 2 and 3 are "completely > incompatible" it seems to me sufficient to provide a single non-trivial > counter-example, which Steven has already done. Python 2.x and Pythin 3.x are two different dialects just like Humans (Python 3.x) and Chimpanzees (Python 2.x) are similar (compatible) but very different versions of talking apes (languages). Sure humans (Python 3.x) and chimps (Python 2.x) share some similarities (much more than say humans (Python3.x) and fish (Lisp) do) however there are many incompatible differences. From rosuav at gmail.com Sun May 29 19:31:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 09:31:16 +1000 Subject: Beginner needs advice In-Reply-To: <60c7d496-e099-4cd2-8fa5-5f395cf4b21a@e35g2000yqc.googlegroups.com> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> <60c7d496-e099-4cd2-8fa5-5f395cf4b21a@e35g2000yqc.googlegroups.com> Message-ID: On Mon, May 30, 2011 at 9:00 AM, rantingrick wrote: > Python 2.x and Pythin 3.x are two different dialects just like Humans > (Python 3.x) and Chimpanzees (Python 2.x) are similar (compatible) but > very different versions of talking apes (languages). Sure humans > (Python 3.x) and chimps (Python 2.x) share some similarities (much > more than say humans (Python3.x) and fish (Lisp) do) however there are > many incompatible differences. > Chimpanzees do not use language in the same way that humans do, and in any case, it's pretty ridiculous to talk of the 'Human language' in anything other than a fantasy roleplaying game. It's more comparable to call Py2 "scientific English"and Py3 "medical English". There are differences (what's a calorie?), but for the most part, they are the same language. Chris Angelico From steve+comp.lang.python at pearwood.info Sun May 29 19:31:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 23:31:19 GMT Subject: float("nan") in set or as key References: <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> <4de22007$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 22:19:49 +0100, Nobody wrote: > On Sun, 29 May 2011 10:29:28 +0000, Steven D'Aprano wrote: > >>> The correct answer to "nan == nan" is to raise an exception, >>> because >>> you have asked a question for which the answer is nether True nor >>> False. >> >> Wrong. > > That's overstating it. There's a good argument to be made for raising an > exception. If so, I've never heard it, and I cannot imagine what such a good argument would be. Please give it. (I can think of *bad* arguments, like "NANs confuse me and I don't understand the reason for their existence, therefore I'll give them behaviours that make no sense and aren't useful". But you did state there is a *good* argument.) > Bear in mind that an exception is not necessarily an error, > just an "exceptional" condition. True, but what's your point? Testing two floats for equality is not an exceptional condition. >> The correct answer to "nan == nan" is False, they are not equal. > > There is no correct answer to "nan == nan". Why on earth not? > Defining it to be false is just the "least wrong" answer. So you say, but I think you are incorrect. > Arguably, "nan != nan" should also be false, > but that would violate the invariant "(x != y) == !(x == y)". I cannot imagine what that argument would be. Please explain. -- Steven From nospam at torek.net Sun May 29 19:37:17 2011 From: nospam at torek.net (Chris Torek) Date: 29 May 2011 23:37:17 GMT Subject: Error: child process close a socket inherited from parent References: Message-ID: In article narke wrote: >As illustrated in the following simple sample: > >import sys >import os >import socket > >class Server: > def __init__(self): > self._listen_sock = None > > def _talk_to_client(self, conn, addr): > text = 'The brown fox jumps over the lazy dog.\n' > while True: > conn.send(text) > data = conn.recv(1024) > if not data: > break > conn.close() > > def listen(self, port): > self._listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > self._listen_sock.bind(('', port)) > self._listen_sock.listen(128) > self._wait_conn() > > def _wait_conn(self): > while True: > conn, addr = self._listen_sock.accept() > if os.fork() == 0: > self._listen_sock.close() # line x > self._talk_to_client(conn, addr) > else: > conn.close() > >if __name__ == '__main__': > Server().listen(int(sys.argv[1])) > >Unless I comment out the line x, I will get a 'Bad file descriptor' >error when my tcp client program (e.g, telnet) closes the connection to >the server. But as I understood, a child process can close a unused >socket (file descriptor). It can. >Do you know what's wrong here? The problem turns out to be fairly simple. The routine listen() forks, and the parent process (with nonzero pid) goes into the "else" branch of _wait_conn(), hence closes the newly accepted socket and goes back to waiting on the accept() call, which is all just fine. Meanwhile, the child (with pid == 0) calls close() on the listening socket and then calls self._talk_to_client(). What happens when the client is done and closes his end? Well, take a look at the code in _talk_to_client(): it reaches the "if not data" clause and breaks out of its loop, and calls close() on the accepted socket ... and then returns to its caller, which is _wait_conn(). What does _wait_conn() do next? It has finished "if" branch in the "while True:" loops, so it must skip the "else" branch and go around the loop again. Which means its very next operation is to call accept() on the listening socket it closed just before it called self._talk_to_client(). If that socket is closed, you get an EBADF error raised. If not, the child and parent compete for the next incoming connection. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From steve+comp.lang.python at pearwood.info Sun May 29 19:46:00 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2011 23:46:00 GMT Subject: scope of function parameters References: Message-ID: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 04:30:52 -0400, Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a > program. The made-up code snippet below illustrates the problem I > encountered: [...] > Are there others who feel as I do that a function parameter should > always be local to the function? Or am I missing something here? The nature of Henry's misunderstanding is a disguised version of the very common "is Python call by reference or call by value?" question that periodically crops up. I wrote a long, but I hope useful, explanation for the tutor at python.org mailing list, which I'd like to share here: http://mail.python.org/pipermail/tutor/2010-December/080505.html Constructive criticism welcome. -- Steven From nospam at torek.net Sun May 29 20:02:02 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 00:02:02 GMT Subject: float("nan") in set or as key References: <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> Message-ID: Incidentally, note: $ python ... >>> nan = float("nan") >>> nan nan >>> nan is nan True >>> nan == nan False In article <4de1e3e7$0$2195$742ec2ed at news.sonic.net> John Nagle wrote: > The correct answer to "nan == nan" is to raise an exception, because >you have asked a question for which the answer is nether True nor False. Well, in some sense, the "correct answer" depends on which question you *meant* to ask. :-) Seriously, some (many?) instruction sets have two kinds of comparison instructions: one that raises an exception here, and one that does not. > The correct semantics for IEEE floating point look something like >this: > > 1/0 INF > INF + 1 INF > INF - INF NaN > INF == INF unordered > NaN == NaN unordered > >INF and NaN both have comparison semantics which return >"unordered". The FPU sets a bit for this, which most language >implementations ignore. Again, this depends on the implementation. This is similar to (e.g.) the fact that on the MIPS, there are two different integer add instructions ("addi" and "addiu"): one raises an overflow exception, the other performs C "unsigned" style arithmetic (where, e.g., 0xffffffff + 1 = 0, in 32 bits). >Python should raise an exception on unordered comparisons. >Given that the language handles integer overflow by going to >arbitrary-precision integers, checking the FPU status bits is >cheap. I could go for that myself. But then you also need a "don't raise exception but give me an equality test result" operator (for various special-case purposes at least) too. Of course a simple "classify this float as one of normal, subnormal, zero, infinity, or NaN" operator would suffice here (along with the usual "extract sign" and "differentiate between quiet and signalling NaN" operations). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From pavlovevidence at gmail.com Sun May 29 20:55:22 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 May 2011 17:55:22 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> On Sunday, May 29, 2011 4:31:19 PM UTC-7, Steven D'Aprano wrote: > On Sun, 29 May 2011 22:19:49 +0100, Nobody wrote: > > > On Sun, 29 May 2011 10:29:28 +0000, Steven D'Aprano wrote: > > > >>> The correct answer to "nan == nan" is to raise an exception, > >>> because > >>> you have asked a question for which the answer is nether True nor > >>> False. > >> > >> Wrong. > > > > That's overstating it. There's a good argument to be made for raising an > > exception. > > If so, I've never heard it, and I cannot imagine what such a good > argument would be. Please give it. Floating point arithmetic evolved more or less on languages like Fortran where things like exceptions were unheard of, and defining NaN != NaN was a bad trick they chose for testing against NaN for lack of a better way. If exceptions had commonly existed in that environment there's no chance they would have chosen that behavior; comparison against NaN (or any operation with NaN) would have signaled a floating point exception. That is the correct way to handle exceptional conditions. The only reason to keep NaN's current behavior is to adhere to IEEE, but given that Python has trailblazed a path of correcting arcane mathematical behavior, I definitely see an argument that Python should do the same for NaN, and if it were done Python would be a better language. Carl Banks From nospam at torek.net Sun May 29 21:02:41 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 01:02:41 GMT Subject: How to catch a line with Popen References: Message-ID: In article TheSaint wrote: >Chris Rebert wrote: >I just suppose to elaborate the latest line, as soon it's written on the >pipe, and print some result on the screen. >Imaging something like > > p= Popen(['ping','-c40','www.google.com'], stdout=PIPE) > for line in p.stdout: > print(str(line).split()[7]) > >I'd like to see something like *time=54.4* >This is just an example, where if we remove the "-c40" on the command line, >I'd expect to read the latest line(s), until the program will be killed. In at least some versions of Python 2, file-like object "next" iterators do not "work right" with unbuffered (or line-buffered) pipe-file-objects. (This may or may not be fixed in Python 3.) A simple workaround is a little generator using readline(): def line_at_a_time(fileobj): """ Return one line at a time from a file-like object. Works around the iter behavior of pipe files in Python 2.x, e.g., instead of "for line in file" you can write "for line in line_at_a_time(file)". """ while True: line = fileobj.readline() if not line: return yield line Adding this to your sample code gives something that works for me, provided I fiddle with it to make sure that the only lines examined are those with actual ping times: p = subprocess.Popen(["ping", "-c5", "www.google.com"], stdout = subprocess.PIPE) for lineno, line in enumerate(line_at_a_time(p.stdout)): if 1 <= lineno <= 5: print line.split()[6] else: print line.rstrip('\n') p.wait() # discard final result (Presumably the enumerate() trick would not be needed in whatever you really use.) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From pavlovevidence at gmail.com Sun May 29 21:07:50 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 May 2011 18:07:50 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: Message-ID: <3cb7d86d-0928-4052-adbd-771ce29de780@glegroupsg2000goo.googlegroups.com> On Sunday, May 29, 2011 7:41:13 AM UTC-7, Grant Edwards wrote: > It treats them as identical (not sure if that's the right word). The > implementation is checking for ( A is B or A == B ). Presumably, the > assumpting being that all objects are equal to themselves. That > assumption is not true for NaN objects, so the buggy behavior is > observed. Python makes this assumption in lots of common situations (apparently in an implementation-defined manner): >>> nan = float("nan") >>> nan == nan False >>> [nan] == [nan] True Therefore, I'd recommend never to rely on NaN != NaN except in casual throwaway code. It's too easy to forget that it will stop working when you throw an item into a list or tuple. There's a function, math.isnan(), that should be the One Obvious Way to test for NaN. NaN should also never be used as a dictionary key or in a set (of course). If it weren't for compatibility with IEEE, there would be no sane argument that defining an object that is not equal to itself isn't a bug. But because there's a lot of code out there that depends on NaN != NaN, Python has to tolerate it. Carl Banks From rosuav at gmail.com Sun May 29 21:14:58 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 11:14:58 +1000 Subject: float("nan") in set or as key In-Reply-To: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> References: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 30, 2011 at 10:55 AM, Carl Banks wrote: > If exceptions had commonly existed in that environment there's no chance they would have chosen that behavior; comparison against NaN (or any operation with NaN) would have signaled a floating point exception. ?That is the correct way to handle exceptional conditions. > > The only reason to keep NaN's current behavior is to adhere to IEEE, but given that Python has trailblazed a path of correcting arcane mathematical behavior, I definitely see an argument that Python should do the same for NaN, and if it were done Python would be a better language. If you're going to change behaviour, why have a floating point value called "nan" at all? Other than being a title for one's grandmother, what meaning does that string have, and why should it be able to be cast as floating point? Lifting from http://en.wikipedia.org/wiki/NaN a list of things that can return a NaN (I've removed non-ASCII characters from this snippet): * Operations with a NaN as at least one operand. (you need to bootstrap that somehow, so we can ignore this - it just means that nan+1 = nan) * The divisions 0/0 and infinity/infinity * The multiplications 0*infinity and infinity*0 * The additions +inf + (-inf), (-inf) + +inf and equivalent subtractions * The standard pow function and the integer exponent pown function define 0**0, 1**inf, and inf**0 as 1. * The powr function define all three indeterminate forms as invalid operations and so returns NaN. * The square root of a negative number. * The logarithm of a negative number * The inverse sine or cosine of a number that is less than -1 or greater than +1. Rather than having comparisons with NaN trigger exceptions, wouldn't it be much cleaner to have all these operations trigger exceptions? And, I would guess that they probably already do. NaN has an additional use in that it can be used like a "null pointer"; a floating-point variable can store 1.0, or 0.000000000005, or "no there's no value that I'm storing in this variable". Since a Python variable can contain None instead of a float, this use is unnecessary too. So, apart from float("nan"), are there actually any places where real production code has to handle NaN? I was unable to get a nan by any of the above methods, except for operations involving inf; for instance, float("inf")-float("inf") == nan. All the others raised an exception rather than return nan. Chris Angelico From hammer777123 at gmail.com Sun May 29 21:26:16 2011 From: hammer777123 at gmail.com (hammer777123 at gmail.com) Date: Sun, 29 May 2011 18:26:16 -0700 (PDT) Subject: Seven Months!...$51,724.00 a Month! { Retired?} Sign-Up Free!.... Message-ID: <0ff07a1a-e220-408e-a78e-3abcaff3d69e@g28g2000yqa.googlegroups.com> Seven Months!...$51,724.00 a Month! { Retired?} Sign-Up Free!.... http://tinyurl.com/3eybq2t Create wealth automatically! A simple system, no selling or recruiting. Fully Automated. The highest pay-out in the world. It's working for me and thousands because of the Upgrade Income Booster Enjoy a FR.EE trial and motivational audio. Sign-Up Free and get $5.00! http://tinyurl.com/3eybq2t Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Need Traffic?......FREE 250,000,000 Visitors to your Website! http://tinyurl.com/6aooafd One Dollar Per Click! $1000.00 in 53 Minutes http://tinyurl.com/68hdx3b Need Traffic?____Generated Up To 283,424 Visitors a Day____Free! http://tinyurl.com/3c9b33h Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Promote your website to over 700,000 Search Engines, Directories, Link Pages, Online Malls, Classified Sites! 100% Automated - A Complete Traffic Generating Machine!!! http://ezwebsubmissions.com/clickthru.pl?id=wct3777 http://tinyurl.com/3eybq2t Seven Months!...$51,724.00 a Month! { Retired?} Sign-Up Free!.... http://tinyurl.com/3eybq2t Create wealth automatically! A simple system, no selling or recruiting. Fully Automated. The highest pay-out in the world. It's working for me and thousands because of the Upgrade Income Booster Enjoy a FR.EE trial and motivational audio. Sign-Up Free and get $5.00! http://tinyurl.com/3eybq2t Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Need Traffic?......FREE 250,000,000 Visitors to your Website! http://tinyurl.com/6aooafd One Dollar Per Click! $1000.00 in 53 Minutes http://tinyurl.com/68hdx3b Need Traffic?____Generated Up To 283,424 Visitors a Day____Free! http://tinyurl.com/3c9b33h Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Promote your website to over 700,000 Search Engines, Directories, Link Pages, Online Malls, Classified Sites! 100% Automated - A Complete Traffic Generating Machine!!! http://ezwebsubmissions.com/clickthru.pl?id=wct3777 http://tinyurl.com/3eybq2t Seven Months!...$51,724.00 a Month! { Retired?} Sign-Up Free!.... http://tinyurl.com/3eybq2t Create wealth automatically! A simple system, no selling or recruiting. Fully Automated. The highest pay-out in the world. It's working for me and thousands because of the Upgrade Income Booster Enjoy a FR.EE trial and motivational audio. Sign-Up Free and get $5.00! http://tinyurl.com/3eybq2t Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Need Traffic?......FREE 250,000,000 Visitors to your Website! http://tinyurl.com/6aooafd One Dollar Per Click! $1000.00 in 53 Minutes http://tinyurl.com/68hdx3b Need Traffic?____Generated Up To 283,424 Visitors a Day____Free! http://tinyurl.com/3c9b33h Need Traffic For Your Business? Post to OVER 52 Million Emails per MONTH ! http://www.ipostad.com/a.cgi?id=wct3777 Promote your website to over 700,000 Search Engines, Directories, Link Pages, Online Malls, Classified Sites! 100% Automated - A Complete Traffic Generating Machine!!! http://ezwebsubmissions.com/clickthru.pl?id=wct3777 http://tinyurl.com/3eybq2t From ben+python at benfinney.id.au Sun May 29 21:31:33 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 May 2011 11:31:33 +1000 Subject: scope of function parameters References: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87pqn17z4a.fsf@benfinney.id.au> Steven D'Aprano writes: > http://mail.python.org/pipermail/tutor/2010-December/080505.html > > > Constructive criticism welcome. Informative, but it ?buries the lead? as our friends in the press corps would say. Instead you should write as though you have no idea where the reader will stop reading, and still give them the most useful part. Write the most important information first, and don't bury it at the end. In this case, I'd judge the most important information to be ?what is the Python passing model?? Give it a short name; the effbot's ?pass by object? sounds good to me. Then explain what that means. Then, only after giving the actual information you want the reader to go away with, you can spend the rest of the essay giving a history behind the craziness. More on this style: -- \ Moriarty: ?Forty thousand million billion dollars? That money | `\ must be worth a fortune!? ?The Goon Show, _The Sale of | _o__) Manhattan_ | Ben Finney From nospam at torek.net Sun May 29 21:44:17 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 01:44:17 GMT Subject: portable way of sending notifying a process References: <4de183e7$0$26108$426a74cc@news.free.fr> Message-ID: In article <4de183e7$0$26108$426a74cc at news.free.fr> News123 wrote: >I'm looking for a portable way (windows XP / Windows Vista and Linux ) >to send a signal from any python script to another one >(one signa would be enough) This turns out to be pretty hard to do reliably-and-securely even *without* crossing the Windows / Linux barrier. >It seems, that neither the signals HUP / USR1 are implemented under windows. Signals are also very messy and easy to get wrong on Unix, with earlier Python versions missing a few key items to make them entirely reliable (such as the sigblock/sigsetmask/sigpause suite, and/or setting interrupt-vs-resume behavior on system calls). >What would be a light weight portable way, that one process can tell >another to do something? > >The main requirement would be to have no CPU impact while waiting (thus >no polling) Your best bet here is probably to use sockets. Both systems have ways to create service sockets and to connect to a socket as a client. Of course, making these secure can be difficult: you must decide what sort of attack(s) could occur and how much effort to put into defending against them. (For instance, even if there is only a "wake up, I have done something you should look at" signal that you can transmit by connecting to a server and then closing the connection, what happens if someone inside or outside your local network decides to repeatedly poke that port in the hopes of causing a Denial of Service by making the server use lots of CPU time?) >If nothing exists I might just write a wrapper around >pyinotify and (Tim Goldens code snippet allowing to watch a directory >for file changes) >http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html > >and use a marker file in a marker directory >but I wanted to be sure of not reinventing the wheel. It really sounds like you are writing client/server code in which the client writes a file into a queue directory. In this case, that may be the way to go -- or you could structure it as an actual client and server, i.e., the client connects to the server and writes the request directly (but then you have to decide about security considerations, which the OS's local file system may provide more directly). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From rosuav at gmail.com Sun May 29 21:56:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 11:56:27 +1000 Subject: scope of function parameters In-Reply-To: <87pqn17z4a.fsf@benfinney.id.au> References: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> <87pqn17z4a.fsf@benfinney.id.au> Message-ID: On Mon, May 30, 2011 at 11:31 AM, Ben Finney wrote: > ? I agree with the gist of that. My take on this is: When I'm talking to my boss, I always assume that the phone will ring ten seconds into my explanation. Ten seconds is enough for "Dad, I'm OK; the bull is dead", it's enough for "I've solved Problem X, we can move on now"; it's enough for "Foo is crashing, can't ship till I debug it". If fortune is smiling on me and the phone isn't ringing, I can explain that Problem X was the reason Joe was unable to demo his new module, or that the crash in Foo is something that I know I'll be able to pin down in a one-day debugging session, but even if I don't, my boss knows enough to keep going with. Of course, there's a significant difference between a mailing list post and a detailed and well copyedited article. Quite frequently I'll ramble on list, in a way quite inappropriate to a publication that would be linked to as a "hey guys, here's how it is" page. Different media, different standards. Chris Angelico "Forty thousand million billion THEGS quotes? That must be worth a fortune!" -- definitely a fan of THEGS -- From rosuav at gmail.com Sun May 29 22:03:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 12:03:21 +1000 Subject: portable way of sending notifying a process In-Reply-To: References: <4de183e7$0$26108$426a74cc@news.free.fr> Message-ID: On Mon, May 30, 2011 at 11:44 AM, Chris Torek wrote: >>What would be a light weight portable way, that one process can tell >>another to do something? >> >>The main requirement would be to have no CPU impact while waiting (thus >>no polling) > > Your best bet here is probably to use sockets. ?Both systems have > ways to create service sockets and to connect to a socket as a > client. Further to this: If your two processes are going to start up, then run concurrently for some time, and during that time alert each other (or one alerts the other) frequently, a socket is an excellent choice. Use a TCP socket on Windows, and either a TCP socket or a Unix socket on Linux (I'd just use TCP on both for simplicity, but Unix sockets are faster), and simply write a byte to it whenever you want to alert the other side. You can largely guarantee that no other process can accidentally or maliciously wake you, as long as you have some kind of one-off handshake on connection - even something really simple like sending a random nonce, having the other end send hash(nonce + password), and compare. Chris Angelico Huge fan of TCP sockets (hello MUDs!) From ben+python at benfinney.id.au Sun May 29 22:08:46 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 May 2011 12:08:46 +1000 Subject: scope of function parameters References: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> <87pqn17z4a.fsf@benfinney.id.au> Message-ID: <87lixp7xe9.fsf@benfinney.id.au> Chris Angelico writes: > Of course, there's a significant difference between a mailing list > post and a detailed and well copyedited article. Quite frequently I'll > ramble on list, in a way quite inappropriate to a publication that > would be linked to as a "hey guys, here's how it is" page. Different > media, different standards. Right. But Steven specifically asked for constructive criticism, which I took as permission to treat the referenced post as an article in need of copy editing :-) -- \ ?The truth is the most valuable thing we have. Let us economize | `\ it.? ?Mark Twain, _Following the Equator_ | _o__) | Ben Finney From pavlovevidence at gmail.com Sun May 29 22:17:01 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 May 2011 19:17:01 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: Message-ID: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> On Sunday, May 29, 2011 6:14:58 PM UTC-7, Chris Angelico wrote: > On Mon, May 30, 2011 at 10:55 AM, Carl Banks > wrote: > > If exceptions had commonly existed in that environment there's no chance they would have chosen that behavior; comparison against NaN (or any operation with NaN) would have signaled a floating point exception. ?That is the correct way to handle exceptional conditions. > > > > The only reason to keep NaN's current behavior is to adhere to IEEE, > > but given that Python has trailblazed a path of correcting arcane > > mathematical behavior, I definitely see an argument that Python > > should do the same for NaN, and if it were done Python would be a > > better language. > > If you're going to change behaviour, why have a floating point value > called "nan" at all? If I were designing a new floating-point standard for hardware, I would consider getting rid of NaN. However, with the floating point standard that exists, that almost all floating point hardware mostly conforms to, there are certain bit pattern that mean NaN. Python could refuse to construct float() objects out of NaN (I doubt it would even be a major performance penalty), but there's reasons why you wouldn't, the main one being to interface with other code that does use NaN. It's better, then, to recognize the NaN bit patterns and do something reasonable when trying to operate on it. Carl Banks From rustompmody at gmail.com Sun May 29 22:26:49 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 29 May 2011 19:26:49 -0700 (PDT) Subject: Alternatives to PythonPath References: Message-ID: On May 30, 2:49?am, ray wrote: > I am using Win7 on a tightly locked down desktop. > > Is there an alternative to using PythonPath? > > What are the trade-offs? > > Thanks, > ray Externally: 1. PYTHONPATH 2. .pth files http://bob.pythonmac.org/archives/2005/02/06/using-pth-files-for-python-development/ http://docs.python.org/library/site.html And of course there the internal sys.path From rosuav at gmail.com Sun May 29 22:37:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 12:37:30 +1000 Subject: scope of function parameters In-Reply-To: <87lixp7xe9.fsf@benfinney.id.au> References: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> <87pqn17z4a.fsf@benfinney.id.au> <87lixp7xe9.fsf@benfinney.id.au> Message-ID: On Mon, May 30, 2011 at 12:08 PM, Ben Finney wrote: > Chris Angelico writes: > >> Of course, there's a significant difference between a mailing list >> post and a detailed and well copyedited article. Quite frequently I'll >> ramble on list, in a way quite inappropriate to a publication that >> would be linked to as a "hey guys, here's how it is" page. Different >> media, different standards. > > Right. But Steven specifically asked for constructive criticism, which I > took as permission to treat the referenced post as an article in need of > copy editing :-) Indeed. Was just saying that there are times when you need to get the slug out first, and times when it's okay to be a little less impactual (if that's a word). Although it's still important to deliver your message promptly. Of course, there are other contexts where you specifically do NOT want to give everything away at the beginning. Certain styles of rhetoric demand that you set the scene, build your situation, and only at the climax reveal what it is you are trying to say. Ahh! wordsmithing, how we love thee. Chris Angelico From rosuav at gmail.com Sun May 29 22:53:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 12:53:59 +1000 Subject: float("nan") in set or as key In-Reply-To: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> References: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 30, 2011 at 12:17 PM, Carl Banks wrote: > If I were designing a new floating-point standard for hardware, I would consider getting rid of NaN. ?However, with the floating point standard that exists, that almost all floating point hardware mostly conforms to, there are certain bit pattern that mean NaN. > > Python could refuse to construct float() objects out of NaN (I doubt it would even be a major performance penalty), but there's reasons why you wouldn't, the main one being to interface with other code that does use NaN. ?It's better, then, to recognize the NaN bit patterns and do something reasonable when trying to operate on it. Okay, here's a question. The Python 'float' value - is it meant to be "a Python representation of an IEEE double-precision floating point value", or "a Python representation of a real number"? For the most part, Python's data types are defined by their abstract concepts - a list isn't defined as a linked list of pointers, it's defined as an ordered collection of objects. Python 3 removes the distinction between 'int' and 'long', where 'int' is <2**32 and 'long' isn't, so now a Py3 integer is... any integer. The sys.float_info struct exposes details of floating point representation. In theory, a Python implementation that uses bignum floats could quite happily set all those values to extremes and work with enormous precision (or could use a REXX-style "numeric digits 100" command to change the internal rounding, and automatically update sys.float_info). And in that case, there would be no NaN value. If Python is interfacing with some other code that uses NaN, that code won't be using Python 'float' objects - it'll be using IEEE binary format, probably. So all it would need to entail is a special return value from an IEEE Binary to Python Float converter function (maybe have it return None), and NaN is no longer a part of Python. The real question is: Would NaN's removal be beneficial? And if so, would it be worth the effort? Chris Angelico From rustompmody at gmail.com Sun May 29 23:08:35 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 29 May 2011 20:08:35 -0700 (PDT) Subject: float("nan") in set or as key References: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> Message-ID: <841029ac-f41e-49ac-861b-be2b0691c030@17g2000prr.googlegroups.com> On May 30, 7:53?am, Chris Angelico wrote: > On Mon, May 30, 2011 at 12:17 PM, Carl Banks wrote: > > If I were designing a new floating-point standard for hardware, I would consider getting rid of NaN. ?However, with the floating point standard that exists, that almost all floating point hardware mostly conforms to, there are certain bit pattern that mean NaN. > > > Python could refuse to construct float() objects out of NaN (I doubt it would even be a major performance penalty), but there's reasons why you wouldn't, the main one being to interface with other code that does use NaN. ?It's better, then, to recognize the NaN bit patterns and do something reasonable when trying to operate on it. > > Okay, here's a question. The Python 'float' value - is it meant to be > "a Python representation of an IEEE double-precision floating point > value", or "a Python representation of a real number"? For the most > part, Python's data types are defined by their abstract concepts - a > list isn't defined as a linked list of pointers, it's defined as an > ordered collection of objects. Python 3 removes the distinction > between 'int' and 'long', where 'int' is <2**32 and 'long' isn't, so > now a Py3 integer is... any integer. > > The sys.float_info struct exposes details of floating point > representation. In theory, a Python implementation that uses bignum > floats could quite happily set all those values to extremes and work > with enormous precision (or could use a REXX-style "numeric digits > 100" command to change the internal rounding, and automatically update > sys.float_info). And in that case, there would be no NaN value. > > If Python is interfacing with some other code that uses NaN, that code > won't be using Python 'float' objects - it'll be using IEEE binary > format, probably. So all it would need to entail is a special return > value from an IEEE Binary to Python Float converter function (maybe > have it return None), and NaN is no longer a part of Python. > > The real question is: Would NaN's removal be beneficial? And if so, > would it be worth the effort? > > Chris Angelico nan in floating point is like null in databases It may be worthwhile to have a look at what choices SQL has made http://en.wikipedia.org/wiki/Null_%28SQL%29 From narkewoody at gmail.com Sun May 29 23:52:43 2011 From: narkewoody at gmail.com (narke) Date: Sun, 29 May 2011 22:52:43 -0500 Subject: Error: child process close a socket inherited from parent References: Message-ID: On 2011-05-29, Chris Torek wrote: > In article > narke wrote: >>As illustrated in the following simple sample: >> >>import sys >>import os >>import socket >> >>class Server: >> def __init__(self): >> self._listen_sock = None >> >> def _talk_to_client(self, conn, addr): >> text = 'The brown fox jumps over the lazy dog.\n' >> while True: >> conn.send(text) >> data = conn.recv(1024) >> if not data: >> break >> conn.close() >> >> def listen(self, port): >> self._listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >> self._listen_sock.bind(('', port)) >> self._listen_sock.listen(128) >> self._wait_conn() >> >> def _wait_conn(self): >> while True: >> conn, addr = self._listen_sock.accept() >> if os.fork() == 0: >> self._listen_sock.close() # line x >> self._talk_to_client(conn, addr) >> else: >> conn.close() >> >>if __name__ == '__main__': >> Server().listen(int(sys.argv[1])) >> >>Unless I comment out the line x, I will get a 'Bad file descriptor' >>error when my tcp client program (e.g, telnet) closes the connection to >>the server. But as I understood, a child process can close a unused >>socket (file descriptor). > > It can. > >>Do you know what's wrong here? > > The problem turns out to be fairly simple. > > The routine listen() forks, and the parent process (with nonzero pid) > goes into the "else" branch of _wait_conn(), hence closes the newly > accepted socket and goes back to waiting on the accept() call, which > is all just fine. > > Meanwhile, the child (with pid == 0) calls close() on the listening > socket and then calls self._talk_to_client(). > > What happens when the client is done and closes his end? Well, > take a look at the code in _talk_to_client(): it reaches the > "if not data" clause and breaks out of its loop, and calls close() > on the accepted socket ... and then returns to its caller, which > is _wait_conn(). > > What does _wait_conn() do next? It has finished "if" branch in > the "while True:" loops, so it must skip the "else" branch and go > around the loop again. Which means its very next operation is > to call accept() on the listening socket it closed just before > it called self._talk_to_client(). > > If that socket is closed, you get an EBADF error raised. If not, > the child and parent compete for the next incoming connection. Chris, Thanks, you helped to find out a bug in my code. From steve+comp.lang.python at pearwood.info Sun May 29 23:59:49 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 03:59:49 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> Message-ID: <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 May 2011 17:55:22 -0700, Carl Banks wrote: > Floating point arithmetic evolved more or less on languages like Fortran > where things like exceptions were unheard of, I'm afraid that you are completely mistaken. Fortran IV had support for floating point traps, which are "things like exceptions". That's as far back as 1966. I'd be shocked if earlier Fortrans didn't also have support for traps. http://www.bitsavers.org/pdf/ibm/7040/C28-6806-1_7040ftnMathSubrs.pdf The IEEE standard specifies that you should be able to control whether a calculation traps or returns a NAN. That's how Decimal does it, that's how Apple's (sadly long abandoned) SANE did it, and floats should do the same thing. Serious numeric languages like Fortran have supported traps long before exceptions were invented. > and defining NaN != NaN > was a bad trick they chose for testing against NaN for lack of a better > way. That's also completely wrong. The correct way to test for a NAN is with the IEEE-mandated function isnan(). The NAN != NAN trick is exactly that, a trick, used by programmers when their language or compiler doesn't support isnan(). Without support for isinf(), identifying an INF is just as hard as identifying an NAN, and yet their behaviour under equality is the complete opposite: >>> inf = float('inf') >>> inf == inf True > If exceptions had commonly existed in that environment there's no chance > they would have chosen that behavior; They did exist, and they did choose that behaviour. > comparison against NaN (or any > operation with NaN) would have signaled a floating point exception. > That is the correct way to handle exceptional conditions. > > The only reason to keep NaN's current behavior is to adhere to IEEE, And because the IEEE behaviour is far more useful than the misguided reliance on exceptions for things which are not exceptional. Before spreading any more misinformation about IEEE 754 and NANs, please learn something about it: http://grouper.ieee.org/groups/754/ http://www.cs.berkeley.edu/~wkahan/ieee754status/ieee754.ps I particularly draw your attention to the FAQ about NANs: http://grouper.ieee.org/groups/754/faq.html#exceptions [quote] The 754 model encourages robust programs. It is intended not only for numerical analysts but also for spreadsheet users, database systems, or even coffee pots. The propagation rules for NaNs and infinities allow inconsequential exceptions to vanish. Similarly, gradual underflow maintains error properties over a precision's range. When exceptional situations need attention, they can be examined immediately via traps or at a convenient time via status flags. Traps can be used to stop a program, but unrecoverable situations are extremely rare. Simply stopping a program is not an option for embedded systems or network agents. More often, traps log diagnostic information or substitute valid results. Flags offer both predictable control flow and speed. Their use requires the programmer be aware of exceptional conditions, but flag stickiness allows programmers to delay handling exceptional conditions until necessary. [end quote] -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 00:15:11 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 04:15:11 GMT Subject: float("nan") in set or as key References: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> Message-ID: <4de319cf$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 11:14:58 +1000, Chris Angelico wrote: > So, apart from float("nan"), are there actually any places where real > production code has to handle NaN? I was unable to get a nan by any of > the above methods, except for operations involving inf; for instance, > float("inf")-float("inf") == nan. All the others raised an exception > rather than return nan. That's Python's poor design, due to reliance on C floating point libraries that have half-hearted support for IEEE-754, and the obstruction of people who don't understand the usefulness of NANs. They shouldn't raise unless the caller specifies that he wants exceptions. The default behaviour should be the most useful one, namely quiet (propagating) NANs, rather than halting the calculation because of something which may or may not be an error and may or may not be recoverable. Even Apple's Hypertalk supported them better in the late 1980s than Python does now, and that was a language aimed at non-programmers! The Decimal module is a good example of what floats should do. All flags are supported, so you can choose whether you want exceptions or NANs. I don't like Decimal's default settings, but at least they can be changed. -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 00:22:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 04:22:25 GMT Subject: float("nan") in set or as key References: <07848bc0-06af-4d76-a06c-9dbd92f709e6@glegroupsg2000goo.googlegroups.com> Message-ID: <4de31b81$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 12:53:59 +1000, Chris Angelico wrote: > Okay, here's a question. The Python 'float' value - is it meant to be "a > Python representation of an IEEE double-precision floating point value", Yes. > or "a Python representation of a real number"? No. Floats are not real numbers. Many fundamental properties of the reals are violated by floats, and I'm not talking about "weird" things like NANs and INFs, but ordinary numbers: >>> a, b = 0.1, 0.7 >>> a + b - b == a False > For the most part, > Python's data types are defined by their abstract concepts - a list > isn't defined as a linked list of pointers, Nor is it implemented as a linked list of pointers. > The sys.float_info struct exposes details of floating point > representation. In theory, a Python implementation that uses bignum > floats could quite happily set all those values to extremes and work > with enormous precision (or could use a REXX-style "numeric digits 100" > command to change the internal rounding, and automatically update > sys.float_info). And in that case, there would be no NaN value. NANs aren't for overflow, that's what INFs are for. Even if you had infinite precision floats and could get rid of INFs, you would still need NANs. > The real question is: Would NaN's removal be beneficial? No, it would be another step backwards to the bad old days before the IEEE standard. -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 00:23:44 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 04:23:44 GMT Subject: scope of function parameters References: <4de2dab8$0$29996$c3e8da3$5496439d@news.astraweb.com> <87pqn17z4a.fsf@benfinney.id.au> Message-ID: <4de31bd0$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 11:31:33 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> http://mail.python.org/pipermail/tutor/2010-December/080505.html >> >> >> Constructive criticism welcome. > > Informative, but it ?buries the lead? as our friends in the press corps > would say. Thank you, that's a good point. [...] > More on this style: > > Or as they say in the fiction-writing trade, "shoot the sheriff on the first page". -- Steven From nagle at animats.com Mon May 30 00:25:04 2011 From: nagle at animats.com (John Nagle) Date: Sun, 29 May 2011 21:25:04 -0700 Subject: float("nan") in set or as key In-Reply-To: <4de319cf$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de319cf$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de31c20$0$2134$742ec2ed@news.sonic.net> On 5/29/2011 9:15 PM, Steven D'Aprano wrote: > On Mon, 30 May 2011 11:14:58 +1000, Chris Angelico wrote: > >> So, apart from float("nan"), are there actually any places where real >> production code has to handle NaN? Yes. I used to write dynamic simulation engines. There were situations that produced floating point overflow, leading to NaN values. This wasn't an error; it just meant that the timestep had to be reduced to handle some heavy object near the moment of first collision. Note that the difference between two INF values is a NaN. It's important that ordered comparisons involving NaN and INF raise exceptions so that you don't lose an invalid value. If you're running with non-signaling NaNs, the idea is supposed to be that, at the end of the computation, you check all your results for INF and NaN values, to make sure you didn't overflow somewhere during the computation. If, within the computation, there are branches based on ordered comparisons, and those don't raise an exception when the comparison result is unordered, you can reach the end of the computation with valid-looking but wrong values. John Nagle From python at rcn.com Mon May 30 00:27:37 2011 From: python at rcn.com (Raymond Hettinger) Date: Sun, 29 May 2011 21:27:37 -0700 (PDT) Subject: Class decorators might also be super too References: <462eb546-0089-48fa-bf10-ac5a6b0b9ed4@glegroupsg2000goo.googlegroups.com> Message-ID: <9fa08a82-0ade-4a2a-bce1-62e0c0a3504e@s41g2000prb.googlegroups.com> On May 28, 11:33?pm, Michele Simionato wrote: > He is basically showing that using mixins for implementing logging is not such a good idea, i.e. you can get the same effect in a better way by making use of other Python features. I argued the same thing many times in the past. I even wrote a module once (strait) to reimplement 99% of multiple inheritance without multiple inheritance, just to show that in can be done in few lines of code in a language as powerful as Python. More importantly, anyone who reads posts such as David' will walk away with a deeper understanding of class decorators, mixins, and inheritance. That makes the post worthwhile even if someone never ends up using those particular coding technique. Raymond From nospam at torek.net Mon May 30 00:29:19 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 04:29:19 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4de31635$0$29990$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: >That's also completely wrong. The correct way to test for a NAN is with >the IEEE-mandated function isnan(). The NAN != NAN trick is exactly that, >a trick, used by programmers when their language or compiler doesn't >support isnan(). Perhaps it would be reasonable to be able to do: x.isnan() when x is a float. >Without support for isinf(), identifying an INF is just as hard as >identifying an NAN, and yet their behaviour under equality is the >complete opposite: > >>>> inf = float('inf') >>>> inf == inf >True Fortunately: def isnan(x): return x != x _inf = float("inf") def isinf(x): return x == _inf del _inf both do the trick here. I would like to have both modes (non-exception-ing and exception-ing) of IEEE-style float available in Python, and am not too picky about how they would be implemented or which one would be the default. Python could also paper over the brokenness of various actual implementations (where signalling vs quiet NaNs, and so on, do not quite work right in all cases), with some performance penalty on non-conformant hardware. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From python at rcn.com Mon May 30 00:49:14 2011 From: python at rcn.com (Raymond Hettinger) Date: Sun, 29 May 2011 21:49:14 -0700 (PDT) Subject: float("nan") in set or as key References: Message-ID: On May 28, 4:41?pm, MRAB wrote: > Here's a curiosity. float("nan") can occur multiple times in a set or as > a key in a dict: Which is by design. NaNs intentionally have multiple possible instances (some implementations even include distinct payload values). Sets and dicts intentionally recognize an instance as being equal to itself (identity-implies-equality); otherwise, you could put a NaN in a set/dict but not be able to retrieve it. Basic invariants would fail -- such as: assert all(elem in container for elem in container). The interesting thing is that people experimenting with exotic objects (things with random hash functions, things with unusual equality or ordering relations, etc) are "surprised" when those objects display their exotic behaviors. To me, the "NaN curiousities" are among the least interesting. It's more fun to break sort algorithms with sets (which override the ordering relations with subset/superset relations) or with an object that mutates a list during the sort. Now, that is curious :-) Also, Dr Mertz wrote a Charming Python article full of these curiosities: http://gnosis.cx/publish/programming/charming_python_b25.txt IMO, equality and ordering are somewhat fundamental concepts. If a class is written that twists those concepts around a bit, then it should be no surprise if curious behavior emerges. Heck, I would venture to guess that something as simple as assuming the speed of light is constant might yield twin paradoxes and other curiousities ;-) Raymond From python at rcn.com Mon May 30 00:52:25 2011 From: python at rcn.com (Raymond Hettinger) Date: Sun, 29 May 2011 21:52:25 -0700 (PDT) Subject: 3.1.4 release candidate 1 References: Message-ID: On May 29, 3:44?pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm happy as a swallow to announce a > release candidate for the fourth bugfix release for the Python 3.1 > series, Python > 3.1.4. The Pi release of Python :-) Raymond P.S. For the most part, if you have a choice, then you are much better off using Py3.2 than any release (even a bugfix release) of Py3.1 From xi at resolvent.net Mon May 30 01:09:21 2011 From: xi at resolvent.net (Kirill Simonov) Date: Mon, 30 May 2011 01:09:21 -0400 Subject: [ANN] PyYAML-3.10: YAML parser and emitter for Python Message-ID: <4DE32681.4050903@resolvent.net> ======================== Announcing PyYAML-3.10 ======================== A new bug fix release of PyYAML is now available: http://pyyaml.org/wiki/PyYAML Changes ======= * Do not try to build LibYAML bindings on platforms other than CPython (Thank to olt(at)bogosoft(dot)com). * Clear cyclic references in the parser and the emitter (Thank to kristjan(at)ccpgames(dot)com). * LibYAML bindings are rebuilt with the latest version of Cython. * Dropped support for Python 2.3 and 2.4; currently supported versions are 2.5 to 3.2. Resources ========= PyYAML homepage: http://pyyaml.org/wiki/PyYAML PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation TAR.GZ package: http://pyyaml.org/download/pyyaml/PyYAML-3.10.tar.gz ZIP package: http://pyyaml.org/download/pyyaml/PyYAML-3.10.zip Windows installers: http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.5.exe http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.6.exe http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py3.0.exe http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py3.1.exe http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py3.2.exe PyYAML SVN repository: http://svn.pyyaml.org/pyyaml Submit a bug report: http://pyyaml.org/newticket?component=pyyaml YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML ============ YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistance. Example ======= >>> import yaml >>> yaml.load(""" ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: http://pyyaml.org/wiki/PyYAML ... keywords: [YAML, serialization, configuration, persistance, pickle] ... """) {'keywords': ['YAML', 'serialization', 'configuration', 'persistance', 'pickle'], 'homepage': 'http://pyyaml.org/wiki/PyYAML', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} >>> print yaml.dump(_) name: PyYAML homepage: http://pyyaml.org/wiki/PyYAML description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistance, pickle] Copyright ========= The PyYAML module is written by Kirill Simonov . PyYAML is released under the MIT license. From nospam at torek.net Mon May 30 01:53:33 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 05:53:33 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article I wrote, in part: > _inf = float("inf") > def isinf(x): > return x == _inf > del _inf Oops, take out the del, or otherwise fix the obvious problem, e.g., perhaps: def isinf(x): return x == isinf._inf isinf._inf = float("inf") (Of course, if something like this were adopted properly, it would all be in the base "float" type anyway.) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From steve+comp.lang.python at pearwood.info Mon May 30 02:13:31 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 06:13:31 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de3358b$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 04:29:19 +0000, Chris Torek wrote: > In article <4de31635$0$29990$c3e8da3$5496439d at news.astraweb.com>, Steven > D'Aprano wrote: >>That's also completely wrong. The correct way to test for a NAN is with >>the IEEE-mandated function isnan(). The NAN != NAN trick is exactly >>that, a trick, used by programmers when their language or compiler >>doesn't support isnan(). > > Perhaps it would be reasonable to be able to do: > > x.isnan() > > when x is a float. Better than a float method is a function which takes any number as argument: >>> import math, fractions, decimal >>> math.isnan(fractions.Fraction(2, 3)) False >>> math.isnan(decimal.Decimal('nan')) True You can even handle complex NANs with the cmath module: >>> import cmath >>> cmath.isnan(complex(1, float('nan'))) True -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 02:14:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 06:14:53 GMT Subject: float("nan") in set or as key References: <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de319cf$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de335dd$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 04:15:11 +0000, Steven D'Aprano wrote: > On Mon, 30 May 2011 11:14:58 +1000, Chris Angelico wrote: > >> So, apart from float("nan"), are there actually any places where real >> production code has to handle NaN? I was unable to get a nan by any of >> the above methods, except for operations involving inf; for instance, >> float("inf")-float("inf") == nan. All the others raised an exception >> rather than return nan. > > That's Python's poor design, due to reliance on C floating point > libraries that have half-hearted support for IEEE-754, and the > obstruction of people who don't understand the usefulness of NANs. That last comment mine is a bit harsh, and I'd like to withdraw it as unnecessarily confrontational. -- Steven From moky.math at gmail.com Mon May 30 03:12:50 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Mon, 30 May 2011 09:12:50 +0200 Subject: scope of function parameters In-Reply-To: <87tycd89qc.fsf@benfinney.id.au> References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> Message-ID: Le 29/05/2011 23:42, Ben Finney a ?crit : > Peter Pearson writes: > >> Python works in terms of objects having names, and one >> object can have many names. > > Or no names. So it's less accurate (though better than talking of > ?variables?) to speak of Python objects ?having names?. Could you give an example of an object that has no name ? I've missed something ... Laurent From clp2 at rebertia.com Mon May 30 03:27:17 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 May 2011 00:27:17 -0700 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> Message-ID: On Mon, May 30, 2011 at 12:12 AM, Laurent Claessens wrote: > Le 29/05/2011 23:42, Ben Finney a ?crit : >> Peter Pearson ?writes: >> >>> ?Python works in terms of objects having names, and one >>> ?object can have many names. >> >> Or no names. So it's less accurate (though better than talking of >> ?variables?) to speak of Python objects ?having names?. > > Could you give an example of an object that has no name ? I've missed > something ... def foo(): return 5 print(foo()) The int object 5 has no name here. Cheers, Chris From moky.math at gmail.com Mon May 30 03:38:05 2011 From: moky.math at gmail.com (Laurent) Date: Mon, 30 May 2011 09:38:05 +0200 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> Message-ID: <4DE3495D.9080309@gmail.com> >> Could you give an example of an object that has no name ? I've missed >> something ... > > def foo(): > return 5 > > print(foo()) > > The int object 5 has no name here. Cool. I was thinking that "5" was the name, but >>> 5.__add__(6) File "", line 1 5.__add__(6) ^ SyntaxError: invalid syntax while >>> a=5 >>> a.__add__(6) 11 Very well. I learned something today. Thanks Laurent From dan.kluev at gmail.com Mon May 30 04:10:22 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 30 May 2011 19:10:22 +1100 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> Message-ID: On Mon, May 30, 2011 at 6:12 PM, Laurent Claessens wrote: > Could you give an example of an object that has no name ? I've missed > something ... >>> object() -- With best regards, Daniel Kluev From alain at dpt-info.u-strasbg.fr Mon May 30 05:01:32 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 30 May 2011 11:01:32 +0200 Subject: 3.1.4 release candidate 1 References: Message-ID: <87mxi4sgsz.fsf@dpt-info.u-strasbg.fr> Raymond Hettinger writes: > On May 29, 3:44?pm, Benjamin Peterson wrote: >> On behalf of the Python development team, I'm happy as a swallow to announce a >> release candidate for the fourth bugfix release for the Python 3.1 >> series, Python >> 3.1.4. > > The Pi release of Python :-) And the same day we get the e release of Python... -- Alain. From tjreedy at udel.edu Mon May 30 05:02:36 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 05:02:36 -0400 Subject: scope of function parameters In-Reply-To: <4DE3495D.9080309@gmail.com> References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> Message-ID: On 5/30/2011 3:38 AM, Laurent wrote: > Cool. I was thinking that "5" was the name, but > >>> 5.__add__(6) > File "", line 1 > 5.__add__(6) Try 5 .__add__(6) Modules, classes, and functions have a .__name__ attribute (I call it their 'definition name') used to print a representation. As best I can remember, other builtin objects do not. -- Terry Jan Reedy From moky.math at gmail.com Mon May 30 05:08:23 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Mon, 30 May 2011 11:08:23 +0200 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> Message-ID: <4DE35E87.8060208@gmail.com> Le 30/05/2011 11:02, Terry Reedy a ?crit : > On 5/30/2011 3:38 AM, Laurent wrote: > >> Cool. I was thinking that "5" was the name, but >> >>> 5.__add__(6) >> File "", line 1 >> 5.__add__(6) > > > Try 5 .__add__(6) What is the rationale behind the fact to add a space between "5" and ".__add__" ? Why does it work ? Laurent From snoopy.67.z at googlemail.com Mon May 30 05:11:32 2011 From: snoopy.67.z at googlemail.com (Gabriel) Date: Mon, 30 May 2011 02:11:32 -0700 (PDT) Subject: Best way to compute length of arbitrary dimension vector? Message-ID: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> Well, the subject says it almost all: I'd like to write a small Vector class for arbitrary-dimensional vectors. I am wondering what would be the most efficient and/or most elegant way to compute the length of such a Vector? Right now, I've got def length(self): # x.length() = || x || total = 0.0 for k in range(len(self._coords)): d = self._coords[k] total += d*d return sqrt(total) However, that seems a bit awkward to me (at least in Python ;-) ). I know there is the reduce() function, but I can't seem to find a way to apply that to the case here (at least, not without jumping through too many hoops). I have also googled a bit, but found nothing really elegant. Any ideas? Best regards, Gabriel. From steve+comp.lang.python at pearwood.info Mon May 30 05:14:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 09:14:39 GMT Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: <4de35fff$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 11:08:23 +0200, Laurent Claessens wrote: > Le 30/05/2011 11:02, Terry Reedy a ?crit : >> On 5/30/2011 3:38 AM, Laurent wrote: >> >>> Cool. I was thinking that "5" was the name, but >>> >>> 5.__add__(6) >>> File "", line 1 >>> 5.__add__(6) >> >> >> Try 5 .__add__(6) > > What is the rationale behind the fact to add a space between "5" and > ".__add__" ? > Why does it work ? Because . is an operator just like + * & etc. >>> s = "hello world" >>> s . upper ( ) 'HELLO WORLD' In the case of integer literals, you need the space, otherwise Python will parse 5. as a float: >>> 5. 5.0 >>> 5.__add__ File "", line 1 5.__add__ ^ SyntaxError: invalid syntax >>> 5 .__add__ -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 05:16:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 09:16:27 GMT Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> Message-ID: <4de3606b$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 09:12:50 +0200, Laurent Claessens wrote: > Could you give an example of an object that has no name ? I've missed > something ... >>> mylist = [None, 42, "something"] The list object has a name, mylist. The three objects inside the list have no names. -- Steven From ben+python at benfinney.id.au Mon May 30 05:17:32 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 May 2011 19:17:32 +1000 Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: <87ei3g8s43.fsf@benfinney.id.au> Laurent Claessens writes: > Le 30/05/2011 11:02, Terry Reedy a ?crit : > > Try 5 .__add__(6) > > What is the rationale behind the fact to add a space between "5" and > ".__add__" ? > Why does it work ? Try asking it the other way around. Why doesn't ?5.__add__(6)?, without the space, work? -- \ ?Telling pious lies to trusting children is a form of abuse, | `\ plain and simple.? ?Daniel Dennett, 2010-01-12 | _o__) | Ben Finney From duncan.booth at invalid.invalid Mon May 30 05:18:26 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 May 2011 09:18:26 GMT Subject: Python's super() considered super! References: Message-ID: Ethan Furman wrote: >>>>> foo(x=1, y=2, z=3) >> Traceback (most recent call last): >> File "", line 1, in >> foo(x=1, y=2, z=3) >> File "", line 2, in foo >> bar(y=2, **kwargs) >> TypeError: bar() got multiple values for keyword argument 'y' > > And the above error is exactly why you don't want to use named arguments > in MI -- because you don't know in what order the methods will be > called, you cannot know which named arguments to supply to the method > that super() will call next. > No, it just means you have to be careful how you do it: if you want to pass 'y' to a super call then you must pop it out of the arguments. This can be done as easily with a named argument as with an explicit 'pop()' on kwargs. What using a named argument does it to change the default action from silently overwriting any argumement passing up the chain to raising an error if you attempt to overwrite it without first checking whether it exists. -- Duncan Booth http://kupuguy.blogspot.com From news1234 at free.fr Mon May 30 05:18:30 2011 From: news1234 at free.fr (News123) Date: Mon, 30 May 2011 11:18:30 +0200 Subject: portable way of sending notifying a process In-Reply-To: References: <4de183e7$0$26108$426a74cc@news.free.fr> Message-ID: <4de360e6$0$4325$426a74cc@news.free.fr> Thanks for all your feedback. Well, I'll play a little and go either for a wrapper around ways to detecth a file change or for a tiny socket solution. Thanks again. On 05/30/2011 04:03 AM, Chris Angelico wrote: > On Mon, May 30, 2011 at 11:44 AM, Chris Torek wrote: >>> What would be a light weight portable way, that one process can tell >>> another to do something? >>> >>> The main requirement would be to have no CPU impact while waiting (thus >>> no polling) >> >> Your best bet here is probably to use sockets. Both systems have >> ways to create service sockets and to connect to a socket as a >> client. > > Further to this: If your two processes are going to start up, then run > concurrently for some time, and during that time alert each other (or > one alerts the other) frequently, a socket is an excellent choice. Use > a TCP socket on Windows, and either a TCP socket or a Unix socket on > Linux (I'd just use TCP on both for simplicity, but Unix sockets are > faster), and simply write a byte to it whenever you want to alert the > other side. You can largely guarantee that no other process can > accidentally or maliciously wake you, as long as you have some kind of > one-off handshake on connection - even something really simple like > sending a random nonce, having the other end send hash(nonce + > password), and compare. > > Chris Angelico > Huge fan of TCP sockets (hello MUDs!) From clp2 at rebertia.com Mon May 30 05:24:17 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 May 2011 02:24:17 -0700 Subject: Best way to compute length of arbitrary dimension vector? In-Reply-To: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> References: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> Message-ID: On Mon, May 30, 2011 at 2:11 AM, Gabriel wrote: > Well, the subject says it almost all: I'd like to write a small Vector > class for arbitrary-dimensional vectors. > > I am wondering what would be the most efficient and/or most elegant > way to compute the length of such a Vector? > > Right now, I've got > > ?def length(self): ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # x.length() = || x || > ? ?total = 0.0 > ? ?for k in range(len(self._coords)): > ? ? ?d = self._coords[k] > ? ? ?total += d*d > ? ?return sqrt(total) > > However, that seems a bit awkward to me (at least in Python ;-) ). > > I know there is the reduce() function, but I can't seem to find a way > to apply that to the case here (at least, not without jumping through > too many hoops). > > I have also googled a bit, but found nothing really elegant. > > Any ideas? def length(self): return sqrt(sum(coord*coord for coord in self._coords)) Cheers, Chris -- http://rebertia.com From __peter__ at web.de Mon May 30 05:41:17 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 May 2011 11:41:17 +0200 Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: Laurent Claessens wrote: > Le 30/05/2011 11:02, Terry Reedy a ?crit : >> On 5/30/2011 3:38 AM, Laurent wrote: >> >>> Cool. I was thinking that "5" was the name, but >>> >>> 5.__add__(6) >>> File "", line 1 >>> 5.__add__(6) >> >> >> Try 5 .__add__(6) > > What is the rationale behind the fact to add a space between "5" and > ".__add__" ? > Why does it work ? It's a hint for the tokenizer. $ cat show_tokens.py import sys from tokenize import generate_tokens from cStringIO import StringIO from token import tok_name _name_width = max(len(name) for name in tok_name.itervalues()) def show_tokens(s): for token in generate_tokens(StringIO(s).readline): name = tok_name[token[0]] value = token[1] print "%-*s %r" % (_name_width, name, value) if __name__ == "__main__": show_tokens(" ".join(sys.argv[1:])) $ python show_tokens.py 5.__add__ NUMBER '5.' NAME '__add__' ENDMARKER '' $ python show_tokens.py 5 .__add__ NUMBER '5' OP '.' NAME '__add__' ENDMARKER '' From __peter__ at web.de Mon May 30 05:46:01 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 May 2011 11:46:01 +0200 Subject: Best way to compute length of arbitrary dimension vector? References: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> Message-ID: Gabriel wrote: > Well, the subject says it almost all: I'd like to write a small Vector > class for arbitrary-dimensional vectors. > > I am wondering what would be the most efficient and/or most elegant > way to compute the length of such a Vector? > > Right now, I've got > > def length(self): # x.length() = || x || > total = 0.0 > for k in range(len(self._coords)): > d = self._coords[k] > total += d*d > return sqrt(total) > > However, that seems a bit awkward to me (at least in Python ;-) ). > > I know there is the reduce() function, but I can't seem to find a way > to apply that to the case here (at least, not without jumping through > too many hoops). > > I have also googled a bit, but found nothing really elegant. >>> class Vector(object): ... def __init__(self, *coords): ... self._coords = coords ... def __abs__(self): ... return math.sqrt(sum(x*x for x in self._coords)) ... >>> import math >>> abs(Vector(1,1)) 1.4142135623730951 >>> abs(Vector(3,4)) 5.0 From moky.math at gmail.com Mon May 30 06:10:11 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Mon, 30 May 2011 12:10:11 +0200 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: <4DE36D03.8050201@gmail.com> >> What is the rationale behind the fact to add a space between "5" and >> ".__add__" ? >> Why does it work ? > > It's a hint for the tokenizer. I didn't know the tokenizer. Now I understand. Thanks Laurent From moky.math at gmail.com Mon May 30 06:10:26 2011 From: moky.math at gmail.com (Laurent Claessens) Date: Mon, 30 May 2011 12:10:26 +0200 Subject: scope of function parameters In-Reply-To: References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: >> What is the rationale behind the fact to add a space between "5" and >> ".__add__" ? >> Why does it work ? > > It's a hint for the tokenizer. I didn't know the tokenizer. Now I understand. Thanks Laurent From secretelf77 at gmail.com Mon May 30 06:15:49 2011 From: secretelf77 at gmail.com (John Thornton) Date: Mon, 30 May 2011 20:15:49 +1000 Subject: python in school notebooks/laptops Message-ID: Hello Is it a waste of time to try to get school admins to put python in their school laptops? OK. Here's the crib for the rest[!] of the world. Here in Australia most secondary schools [that is kids from age approx 12-18] have some sort of netbook/laptop program. I have looked at a few schools and they put visual basic in but not python. [unless of course it's a mac where python may already be in it] . This is a curious omission when Blender needs python to run. So, I emailed a school admin and told him about python, gimp, inkscape and blender. Have I wasted my time? -------------- next part -------------- An HTML attachment was scrubbed... URL: From piotr.kaminski at poczta.onet.eu Mon May 30 06:37:43 2011 From: piotr.kaminski at poczta.onet.eu (=?utf-8?B?UGlvdHIgS2FtacWEc2tp?=) Date: Mon, 30 May 2011 12:37:43 +0200 Subject: Abandoning Python In-Reply-To: References: <4DD9952F.4080100@etrix.com.au> Message-ID: I'm sorry, I wanted to send the message below to the list and instead I sent it to just one user. Piotr Dnia 23-05-2011 o 10:29:24 Piotr Kami?ski napisa?(a): > Dnia 23-05-2011 o 00:58:55 Brendan Simon (eTRIX) napisa?(a): > > ... >> Take a look at Cobra. >> >> http://cobra-language.com/docs/python/ >> >> http://cobra-language.com/ >> >> It is similar to Python, but with a quite a few nice extras and few improved things (eg. no "self", no ":", ...) >> >> Possible negatives are: >> * Requires either .NET or Mono frameworks. >> * lack of 3rd party libraries ?? >> >> >> Cheers, Brendan. >> > > > One more piece of information and a link: "...It supports both static and dynamic typing..." http://en.wikipedia.org/wiki/Cobra_(programming_language_from_Cobra_Language_LLC) > > HTH, > > Piotr From jpiitula at ling.helsinki.fi Mon May 30 06:40:19 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 30 May 2011 13:40:19 +0300 Subject: scope of function parameters References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: Laurent Claessens writes: > Le 30/05/2011 11:02, Terry Reedy a ?crit : > > On 5/30/2011 3:38 AM, Laurent wrote: > > > >> Cool. I was thinking that "5" was the name, but > >> >>> 5.__add__(6) > >> File "", line 1 > >> 5.__add__(6) > > > > > > Try 5 .__add__(6) > > What is the rationale behind the fact to add a space between "5" and > ".__add__" ? > Why does it work ? Oh joy. >>> [5][0].__add__([6][-1]) 11 The parser just needs the help to detect the intended token boundary instead of another, unintened one. As the others already say. From hackingkk at gmail.com Mon May 30 07:09:01 2011 From: hackingkk at gmail.com (hackingKK) Date: Mon, 30 May 2011 16:39:01 +0530 Subject: python in school notebooks/laptops In-Reply-To: References: Message-ID: <4DE37ACD.9040300@gmail.com> On 30/05/11 15:45, John Thornton wrote: > Hello > Is it a waste of time to try to get school admins to put > python in their school laptops? > > OK. Here's the crib for the rest[!] of the world. Here in > Australia most secondary schools [that is kids from age approx 12-18] > have some sort of netbook/laptop program. I have looked at a few > schools and they put visual basic in but not python. [unless of > course it's a mac where python may already be in it] . This is a > curious omission when Blender needs python to run. Even better, try convincing them to use Ubuntu instead of a virus called Where I Never Do Operations With Safety, or WINDOWS for short. That way Python will come by default and VB will be out of question Happy hacking. Krishnakant. From secretelf77 at gmail.com Mon May 30 07:16:11 2011 From: secretelf77 at gmail.com (John Thornton) Date: Mon, 30 May 2011 21:16:11 +1000 Subject: python in school notebooks/laptops In-Reply-To: <4DE37ACD.9040300@gmail.com> References: <4DE37ACD.9040300@gmail.com> Message-ID: I agree fully. Linux is better and safer. But they seem hellbent on getting their students to use Windows. For laughs the kids in year 7 start off with this on their school netbook: Individual software packages MS Office Professional 2010 $80.30 (Word, Excel, PowerPoint, Access, Outlook, Publisher, OneNote) (EULA needs to be signed) DyKnow $47.00 Microworlds EX Robotics (PC/Mac) $27.50 Inspiration V8 (PC/Mac) $50.60 Graphmatica $4.40 Sophos Anti-virus $30.00 Network Cable $6.00 Labels for laptop and bag $1.00 Additional Software Home Studio (Yr 7 and 8 Music) $50.00 Upgrade from Vista Business to Windows 7 Professional $103.40 Software packages also installed (either free of charge or cost covered by School) are ArtRage, Acrobat Reader, Cite Ace, Mavis Beacon Typing, Scratch, Wordweb, Kahootz, Comic Life, Ni Hao, French Gamemaker, NewsMaker, Yenka Science, Autodesk Inventor. ******* Gimp? Python? Linux? Inkscape? Blender? That software may as well be on the moon. [sobs into beer...oh well, at least they get to buy anti-virus gear...:)] John On Mon, May 30, 2011 at 9:09 PM, hackingKK wrote: > > On 30/05/11 15:45, John Thornton wrote: > >> Hello >> Is it a waste of time to try to get school admins to put python in >> their school laptops? >> >> OK. Here's the crib for the rest[!] of the world. Here in Australia >> most secondary schools [that is kids from age approx 12-18] have some sort >> of netbook/laptop program. I have looked at a few schools and they put >> visual basic in but not python. [unless of course it's a mac where python >> may already be in it] . This is a curious omission when Blender needs python >> to run. >> > > Even better, try convincing them to use Ubuntu instead of a virus called > Where I Never Do Operations With Safety, or WINDOWS for short. > That way Python will come by default and VB will be out of question > Happy hacking. > Krishnakant. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phd at phdru.name Mon May 30 07:19:45 2011 From: phd at phdru.name (Oleg Broytman) Date: Mon, 30 May 2011 15:19:45 +0400 Subject: SQLObject 1.0.1 Message-ID: <20110530111945.GC12650@iskra.aviel.ru> Hello! I'm pleased to announce version 1.0.1, a bugfix release of branch 1.0 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/1.0.1 News and changes: http://sqlobject.org/News.html What's New ========== * A syntax incompatibility was fixed in SQLiteConnection that prevented SQLObject to be used with Python 2.4. For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From invalid at peter.pmoylan.org.invalid Mon May 30 08:58:02 2011 From: invalid at peter.pmoylan.org.invalid (Peter Moylan) Date: Mon, 30 May 2011 22:58:02 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> Message-ID: rantingrick wrote: > On May 18, 7:19 am, Peter Moylan > wrote: > >> It's interesting to note that the definitions of 'recursive' to be found >> in Wikipedia and Wiktionary have very little in common with the >> definitions to be found in the dictionaries covered by Onelook. No >> wonder experts in different areas have trouble communicating with one >> another. > > Yes, and when you extrapolate that conclusion into the current hodge > podge of natural languages you begin to understand the genesis of > human beings selfish nature. I do? -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. From vinograd19 at gmail.com Mon May 30 08:58:31 2011 From: vinograd19 at gmail.com (vino19) Date: Mon, 30 May 2011 05:58:31 -0700 (PDT) Subject: searching in list Message-ID: I want to make a function that is called only once per one argument. I mean I want to store data of function calling to prevent calling it again if there is no need. How to make it? For example I can make a global list that just consist of tuples [(arg1, res1), (arg2, res2), ...]. Ok, how to search if an arg135 in that list? Thanks for answering From invalid at peter.pmoylan.org.invalid Mon May 30 09:02:35 2011 From: invalid at peter.pmoylan.org.invalid (Peter Moylan) Date: Mon, 30 May 2011 23:02:35 +1000 Subject: English Idiom in Unix: Directory Recursively In-Reply-To: <15e794b2-df2e-4dae-8f49-ae7dfe1f21d7@x1g2000yqb.googlegroups.com> References: <2acf55f1-0415-4a13-8e16-aa3418d149c2@r35g2000prj.googlegroups.com> <83463dc1-e86a-4e4c-949d-98c4c5ea389f@y4g2000yqm.googlegroups.com> <1k1gs1h.wnt88n1hky9ifN%see@sig.for.address> <15e794b2-df2e-4dae-8f49-ae7dfe1f21d7@x1g2000yqb.googlegroups.com> Message-ID: rantingrick wrote: > On May 18, 12:59 pm, s... at sig.for.address (Victor Eijkhout) wrote: >> Harrison Hill wrote: >>> No need - I have the Dictionary definition of recursion here: >>> Recursion: (N). See recursion. >> If you tell a joke, you have to tell it right. > > Jeez, speaking of bad colloquialisms... > > """if you're going to "share" a joke you should at least "recite" it > CORRECTLY.""" He was her man But he was doing her incorrectly. I'm not convinced that this new meaning of "share" has contributed anything of value to the language. Which is possibly why people stopped using it in about the 1980s. -- Peter Moylan, Newcastle, NSW, Australia. http://www.pmoylan.org For an e-mail address, see my web page. From davea at ieee.org Mon May 30 09:27:33 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 30 May 2011 09:27:33 -0400 Subject: searching in list In-Reply-To: References: Message-ID: <4DE39B45.3090903@ieee.org> On 01/-10/-28163 02:59 PM, vino19 wrote: > I want to make a function that is called only once per one argument. I mean I want to store data of function calling to prevent calling it again if there is no need. > How to make it? For example I can make a global list that just consist of tuples > [(arg1, res1), (arg2, res2), ...]. Ok, how to search if an arg135 in that list? > > Thanks for answering > Usual answer is to use a dict. You can convert a list of tuples to a dict by dict(mylist) Second choice is to keep the list sorted, and use the bisect module. But usually a dictionary is better. DaveA From rosuav at gmail.com Mon May 30 09:28:19 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 23:28:19 +1000 Subject: python in school notebooks/laptops In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 8:15 PM, John Thornton wrote: > Hello > ??????? Is it a waste of time to try to get school admins to put python in > their school laptops? Two halves to this question. 1) Would it be of value if the school admins were to put Python on the school laptops? 2) If you ask them to, would they? The answer to #1 is "Undoubtedly". Cost? A tiny bit of disk space. Benefit? Even if only one student in a thousand picked it up and learned it, that's a huge number of people who've been exposed to a better language than VB. But the answer to #2, based on my cynical view of these things, is "Unlikely". You could ask the school admins, but they'll point to some policy from upstairs that says what they need to provide. And I don't know who formulates that policy, but more than likely it's a committee. Who pays for all that software? I'm guessing it's part of one of those perversities where something is valued more if it costs more ("We spend $X million teaching our students modern computing"). Replacing the netbook packageset with Ubuntu and a whole swathe of free software (the significant part here being free-as-in-beer, but it would be free-as-in-speech software too) would cut $400 per student off their boast according to the figures you posted - but that doesn't seem to include the OS itself, so possibly even more. The other part of the problem is a huge lock-in involving grade schools, tertiary education, and company employment agencies, all of whom think that "computer skill" means "knows how to change cell color in Excel". And that is not an exaggeration - my brother says that when he was applying for jobs that required computing skills, the recruitment agency wanted to know his ability level with Word 2003 and Excel 2003. Getting past that is not going to be easy. But if you can just get a smidge of extra software put on the laptops (some nice easy tiny stuff - Python, 7-Zip, InfraRecorder - skip OO because it's too heavy), nobody would notice the extra disk space usage (even a cheap netbook will have storage measured in hundreds of gig), and it gives them a chance to learn something decent. Bored student browsing the Start menu... might not happen very often, but if even one person learns Python, that'd be worth it! Possibly the best way to encourage Python deployment would be to require it to run some internal script. Then the interpreter will be put on the laptops ("it's so tiny, won't cost anything to put it there"), and IDLE will be available for anyone who wants it. Now the question is, how can you get into a position where you can have a script that's needed for every student... Chris Angelico From snoopy.67.z at googlemail.com Mon May 30 09:38:53 2011 From: snoopy.67.z at googlemail.com (Gabriel) Date: Mon, 30 May 2011 06:38:53 -0700 (PDT) Subject: Best way to compute length of arbitrary dimension vector? References: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> Message-ID: Thanks a lot to both of you, Chris & Peter! (I knew the solution would be simple ... ;-) ) From rosuav at gmail.com Mon May 30 09:41:00 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 May 2011 23:41:00 +1000 Subject: searching in list In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 10:58 PM, vino19 wrote: > I want to make a function that is called only once per one argument. I mean I want to store data of function calling to prevent calling it again if there is no need. > How to make it? For example I can make a global list that just consist of tuples > [(arg1, res1), (arg2, res2), ...]. Ok, how to search if an arg135 in that list? > > Thanks for answering If you're always going to look them up by the argument, the best way would be to use a dictionary: cache={arg1: res1, arg2: res2, ...} Then you can search with a simple: cache[arg135] You can add things with: cache[arg135]=res135 This works best if the argument is an immutable and fairly simple type. For instance, you could calculate Fibonacci numbers in a naive and straightforward way: def fib(n,cache={}): if n in cache: return cache[n] ret=n if n<2 else fib(n-1)+fib(n-2) # This bit actually calculates fib(n) cache[n]=ret return ret Of course, this is a poor algorithm for calculating Fibonacci numbers, but it does demonstrate the cache. It's recursive, meaning that if it has fib(50) in its cache and it is asked for fib(60), it will find and make use of the cached element. (Note the sneaky way of storing a cache dictionary. A function's default arguments are evaluated once, so this will use the same dictionary for every call.) Chris Angelico From vinograd19 at gmail.com Mon May 30 09:50:00 2011 From: vinograd19 at gmail.com (vino19) Date: Mon, 30 May 2011 06:50:00 -0700 (PDT) Subject: searching in list In-Reply-To: Message-ID: <81cbfee3-a0a6-4aa0-97e7-1073332ab6cf@glegroupsg2000goo.googlegroups.com> Thanks. It seems that dictionary is a sorted list of tuples, so the procedure of searching an element is quite quick. From vinograd19 at gmail.com Mon May 30 09:50:00 2011 From: vinograd19 at gmail.com (vino19) Date: Mon, 30 May 2011 06:50:00 -0700 (PDT) Subject: searching in list In-Reply-To: Message-ID: <81cbfee3-a0a6-4aa0-97e7-1073332ab6cf@glegroupsg2000goo.googlegroups.com> Thanks. It seems that dictionary is a sorted list of tuples, so the procedure of searching an element is quite quick. From wxjmfauth at gmail.com Mon May 30 10:30:00 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 30 May 2011 07:30:00 -0700 (PDT) Subject: python in school notebooks/laptops References: Message-ID: <2edff4f4-64db-4f39-b822-6f8d2c41eddd@h12g2000pro.googlegroups.com> On 30 mai, 13:09, hackingKK wrote: [...] > > Even better, try convincing them to use Ubuntu instead of ?a virus > called Where I Never Do Operations With Safety, or WINDOWS for short. > That way Python will come by default ?and VB will be out of question > Happy hacking. > Krishnakant. Do you mean one of these os's, where Python (2) is not working properly because the *defaultencoding* is set to utf-8? jmf From rosuav at gmail.com Mon May 30 10:48:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 00:48:49 +1000 Subject: searching in list In-Reply-To: <81cbfee3-a0a6-4aa0-97e7-1073332ab6cf@glegroupsg2000goo.googlegroups.com> References: <81cbfee3-a0a6-4aa0-97e7-1073332ab6cf@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, May 30, 2011 at 11:50 PM, vino19 wrote: > Thanks. > > It seems that dictionary is a sorted list of tuples, so the procedure of searching an element is quite quick. Not sorted - it's hashed, so it's even faster. Yep, sounds like a dictionary is everything you want! Chris Angelico From nobody at nowhere.net.no Mon May 30 11:29:07 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 30 May 2011 23:29:07 +0800 Subject: How to catch a line with Popen References: Message-ID: Chris Torek wrote: > In at least some versions of Python 2 I'm with P3k :P. However thank you for your guidelines. Last my attempt was to use a *for* p.wait() , as mentioned earlier That looks good enough. I noted some little delay for the first lines, mostly sure Popen assign some buffer even it is not set. Haven't you try a perpetual ping, how would be the line_at_a_time ? -- goto /dev/null From ian.g.kelly at gmail.com Mon May 30 12:32:27 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 May 2011 10:32:27 -0600 Subject: searching in list In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 7:41 AM, Chris Angelico wrote: > If you're always going to look them up by the argument, the best way > would be to use a dictionary: > cache={arg1: res1, arg2: res2, ...} > > Then you can search with a simple: cache[arg135] > > You can add things with: cache[arg135]=res135 > > This works best if the argument is an immutable and fairly simple > type. For instance, you could calculate Fibonacci numbers in a naive > and straightforward way: > > def fib(n,cache={}): > ?if n in cache: return cache[n] > ?ret=n if n<2 else fib(n-1)+fib(n-2) # This bit actually calculates fib(n) > ?cache[n]=ret > ?return ret > > Of course, this is a poor algorithm for calculating Fibonacci numbers, > but it does demonstrate the cache. It's recursive, meaning that if it > has fib(50) in its cache and it is asked for fib(60), it will find and > make use of the cached element. > > (Note the sneaky way of storing a cache dictionary. A function's > default arguments are evaluated once, so this will use the same > dictionary for every call.) If you're using Python 3.2, the functools.lru_cache decorator will do the caching for you, and without modifying the function arguments. By default it stores only the 100 most recent results, but you can make the storage unbounded by passing in the argument maxsize=None. Then the Fibonacci example becomes: @functools.lru_cache(maxsize=None) def fib(n): if n < 2: return n return fib(n-2) + fib(n-1) From tjreedy at udel.edu Mon May 30 12:49:26 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 12:49:26 -0400 Subject: scope of function parameters In-Reply-To: <4DE35E87.8060208@gmail.com> References: <94fdk7FihlU1@mid.individual.net> <87tycd89qc.fsf@benfinney.id.au> <4DE3495D.9080309@gmail.com> <4DE35E87.8060208@gmail.com> Message-ID: On 5/30/2011 5:08 AM, Laurent Claessens wrote: > Le 30/05/2011 11:02, Terry Reedy a ?crit : >> On 5/30/2011 3:38 AM, Laurent wrote: >> >>> Cool. I was thinking that "5" was the name, but >>> >>> 5.__add__(6) >>> File "", line 1 >>> 5.__add__(6) >> >> >> Try 5 .__add__(6) > > What is the rationale behind the fact to add a space between "5" and > ".__add__" ? > Why does it work ? Others have given you specific answers, here is the bigger picture. For decades, text interpreter/compilers have generally run in two phases: 1. a lexer/tokenizer that breaks the stream of characters into tokens; 2. a parser that recognizes higher-level syntax and takes appropriate action. Lexers are typically based on regular grammars and implemented as very simple and fast deterministic finite-state automata. In outline (leaving out error handling and end-of-stream handling), something like: def lexer(stream, lookup, initial_state): state = initial_state buffer = [] for char in stream: state,out = lookup[state,char] if out: yield output(buffer) # convert list of chars to token expected by parser, clear buffer buffer += char There is no backup and no lookahead (except for the fact that output excludes the current char). For python, lookup[start,'5'] == in_number,False, and lookup[in_number,'.'] == in_float,False. >>> 5..__add__(6) 11.0 works because lookup[in_float,'.'] == start,True, because buffer now contains a completed float ready to output and '.' signals the start of a new token. I believe we read natural language text similarly, breaking it into words and punctuation. I believe the ability to read programs depends on being able to adjust the internal lexer a bit. Python is easier to read than some other algorithm languages because it tends to have at most one punctuation-like symbol unit between words, as is the case in the code above. -- Terry Jan Reedy From python at bdurham.com Mon May 30 13:57:06 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 30 May 2011 13:57:06 -0400 Subject: 3rd party tree/outline data structure module? Message-ID: <1306778226.14588.1457628701@webmail.messagingengine.com> Before I reinvent the wheel, I'm wondering if anyone can recommend a 3rd party tree data structure module? (I do not need a GUI component) I've looked at ElementTree but I think(?) need something more flexible. I have a parser that reads a proprietary file format which defines an outline-like structure. (The file format is based on a legacy product). I need to create a tree data structure that supports the ability to dynamically, add, delete, and move nodes/branches. I would like the nodes to be based on my own node class. I also need to to walk the tree structure in various ways including given a node, find its previous and next nodes including moving up and down branches to find the next logical node and the ability to quickly find an element by its unique id. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From pythoniks at gmail.com Mon May 30 14:27:06 2011 From: pythoniks at gmail.com (Pascal Chambon) Date: Mon, 30 May 2011 20:27:06 +0200 Subject: GIL in alternative implementations In-Reply-To: <6C7ABA8B4E309440B857D74348836F2E15BFF919@TK5EX14MBXC292.redmond.corp.microsoft.com> References: <4DE015EA.4040600@gmail.com> <6C7ABA8B4E309440B857D74348836F2E15BFF919@TK5EX14MBXC292.redmond.corp.microsoft.com> Message-ID: <4DE3E17A.3080706@gmail.com> Thanks for the details on IronPython's implementation B-) Hopefully Pypy will eventually get rid of its own Gil, since it doesn't do refcounting either. Regards, Pascal Le 28/05/2011 00:52, Dino Viehland a ?crit : > > In IronPython we have fine grained locking on our mutable data > structures. In particular we have a custom dictionary type which is > designed to allow lock-free readers on common operations while writers > take a lock. Our list implementation is similar but in some ways > that's trickier to pull off due to features like slicing so if I > recall correctly we only have lock-free reads when accessing a single > element. > > For .NET data structures they follow the .NET convention which is up > to the data structure. So if you wanted to get every last bit of > performance out of your app you could handle thread safety yourself > and switch to using the .NET dictionary or list types (although > they're a lot less friendly to Python developers). > > Because of these locks on micro-benchmarks that involve simple > list/dict manipulations you do see noticeably worse performance in > IronPython vs. CPython. > http://ironpython.codeplex.com/wikipage?title=IP27A1VsCPy27Perf&referringTitle=IronPython%20Performance > > - See the SimpleListManipulation and SimpleDictManipulation as the > core examples here. Also CPython's dictionary is so heavily tuned > it's hard to beat anyway, but this is a big factor. > > Finally one of the big differences with both Jython and IronPython is > that we have good garbage collectors which don't rely upon reference > counting. So one area where CPython gains from having a GIL is a > non-issue for us as we don't need to protect ref counts or use > interlocked operations for ref counting. > > *From:* python-list-bounces+dinov=exchange.microsoft.com at python.org > [mailto:python-list-bounces+dinov=exchange.microsoft.com at python.org] > *On Behalf Of *Pascal Chambon > *Sent:* Friday, May 27, 2011 2:22 PM > *To:* python-list at python.org >> Python List > *Subject:* GIL in alternative implementations > > Hello everyone, > > I've already read quite a bit about the reasons for the GIL in > CPython, i.e to summarize, that a more-fine graine locking, allowing > real concurrency in multithreaded applications, would bring too much > overhead for single-threaded python applications. > > However, I've also heard that other python implementations > (ironpython, jython...) have no GIL, and yet nobody blames them for > performance penalties that would be caused by that lack (I especially > think about IronPython, whose performances compare quite well to CPython). > > So I'd like to know: how do these other implementations handle > concurrency matters for their primitive types, and prevent them from > getting corrupted in multithreaded programs (if they do) ? I'm not > only thinking about python types, but also primitive containers and > types used in .Net and Java VMs, which aren't atomic elements either > at an assembly-level point of view. > > Do these VMs have some GIL-like limitations, that aren't spoken about > ? Are there functionings completely different from the CPython VM, so > that the question is not relevant ? Do people consider that they > always concern multithreaded applications, and so accept performance > penalties that they wouldn't allow in their CPython scripts ? > > I think you in advance for your lights on these questions. > > Regards, > > Pkl > > [[ Important Note: this is a serious question, trolls and emotionally > disturbed persons had better go on their way. ]] > -------------- next part -------------- An HTML attachment was scrubbed... URL: From doug.hellinger at hotmail.com Mon May 30 14:48:55 2011 From: doug.hellinger at hotmail.com (dough) Date: Mon, 30 May 2011 11:48:55 -0700 (PDT) Subject: How to Use Setuptools, Alternatives? References: <01045077-543f-4b8d-a5a2-4cde190c3294@v8g2000yqb.googlegroups.com> Message-ID: <3e848108-9b22-4ad8-83ed-e563f8346486@28g2000yqu.googlegroups.com> On May 29, 10:41?pm, ray wrote: > I have Python 2.7 on Win7 Pro on a tightly locked down desktop. ?I > would like to install Networkx from an egg. ?From what I have read, > Setuptools can be used for this. > > I don't know how to install Setuptools. ?The exe will not work. ?On > execution, it reports that the Python version is not included in the > registry. ?Further, I can not input the version and location on the > subsequent installation screen, the fields will not accept focus so I > can not input the values. > > Since the exe will not install, I considered using the Setuptools > egg. ?But it requires Setuptools. ?It appears to be a circle. > You're right. Since Setuptools is distributed as an egg, and Python doesn't natively support eggs, there can be a "chicken-and-egg" situation. > What are some suggestions for installing this? > > Thanks, > ray You can try downloading ezsetup.py and running it as a python script (i.e. python ezsetup.py). It will locate and download the latest version of Setuptools for your platform and install it. If HTTP access is blocked, just place the desired egg in the same folder as ezsetup.py and run the script again. Assuming you can get Setuptools installed correctly, it puts a program called easy_install.exe in your \Scripts folder. You can then just run (from the command line): easy_install It will hunt, download and install the latest version of the package for your platform. You may want to add the path to the Scripts folder to your PATH environment variable so you can just run easy_install from any current working directory. Hope that helps, Doug From gagsl-py2 at yahoo.com.ar Mon May 30 15:01:08 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 30 May 2011 16:01:08 -0300 Subject: Best way to compute length of arbitrary dimension vector? References: <43d7a46e-3f48-4c11-a66b-a47a3d6b9b9d@k16g2000yqm.googlegroups.com> Message-ID: En Mon, 30 May 2011 06:46:01 -0300, Peter Otten <__peter__ at web.de> escribi?: > Gabriel wrote: > >> Well, the subject says it almost all: I'd like to write a small Vector >> class for arbitrary-dimensional vectors. >> > >>>> class Vector(object): > ... def __init__(self, *coords): > ... self._coords = coords > ... def __abs__(self): > ... return math.sqrt(sum(x*x for x in self._coords)) > ... >>>> import math >>>> abs(Vector(1,1)) > 1.4142135623730951 >>>> abs(Vector(3,4)) > 5.0 Using math.fsum instead of sum may improve accuracy, specially when len(coords)?2 py> import math py> py> def f1(*args): ... return math.sqrt(sum(x*x for x in args)) ... py> def f2(*args): ... return math.sqrt(math.fsum(x*x for x in args)) ... py> pi=math.pi py> args=[pi]*16 py> abs(f1(*args)/4 - pi) 4.4408920985006262e-16 py> abs(f2(*args)/4 - pi) 0.0 -- Gabriel Genellina From nospam at torek.net Mon May 30 15:58:35 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 19:58:35 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> <4de3358b$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4de3358b$0$29990$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: >Better than a float method is a function which takes any number as >argument: > >>>> import math, fractions, decimal >>>> math.isnan(fractions.Fraction(2, 3)) >False >>>> math.isnan(decimal.Decimal('nan')) >True Ah, apparently someone's been using Larry Wall's time machine. :-) I should have looked at documentation. In my case, though: $ python Python 2.5.1 (r251:54863, Dec 16 2010, 14:12:43) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> math.isnan Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'isnan' >You can even handle complex NANs with the cmath module: > >>>> import cmath >>>> cmath.isnan(complex(1, float('nan'))) >True Would it be appropriate to have isnan() methods for Fraction, Decimal, and complex, so that you do not need to worry about whether to use math.isnan() vs cmath.isnan()? (I almost never work with complex numbers so am not sure if the "or" behavior -- cmath.isinf and cmath.isnan return true if either real or complex part are Infinity or NaN respectively -- is appropriate in algorithms that might be working on any of these types of numbers.) It might also be appropriate to have trivial always-False isinf and isnan methods for integers. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From skunkworks at rikishi42.net Mon May 30 17:04:41 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Mon, 30 May 2011 23:04:41 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9cddb8-viv.ln1@murmur.very.softly> On 2011-05-28, Chris Angelico wrote: > I think it's geographic. This list covers a lot of geography; I'm in > Australia, there are quite a few Brits, and probably the bulk of posts > come from either the US or Europe. (And yes, I did deliberately fold > all of Europe down to one entity, and I did also deliberately leave > Great Britain out of that entity.) I allways found that odd. Especially if you're talking geography, not politics. I can understand they want to be seen as independant, even they are in it enough to allways opose anything someone else suggests. :-) To me, saying the UK isn't part of Europe, is like saying Japan isn't part of Asia. Oh by the way, I'm Belgian. > Most things work out that way. A thing gets a name based either on its > implementation or on the brand name of the first/most popular one. If > the only microwave oven ever produced had been made by Foobar Corp, > and that company were not known for anything else, then quite possibly > everyone would call them "foobar ovens". Yeah, when I was a kid a photo camera was called a Kodak. -- When in doubt, use brute force. -- Ken Thompson From skunkworks at rikishi42.net Mon May 30 17:10:14 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Mon, 30 May 2011 23:10:14 +0200 Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-05-28, Chris Angelico wrote: > Chris Angelico > yes, bit of a Bible geek as well as a programming geek So you don't believe in genetic algorithms, then ? (ducking for cover) -- When in doubt, use brute force. -- Ken Thompson From nospam at torek.net Mon May 30 17:33:16 2011 From: nospam at torek.net (Chris Torek) Date: 30 May 2011 21:33:16 GMT Subject: How to catch a line with Popen References: Message-ID: >Chris Torek wrote: >> In at least some versions of Python 2 [the "file"-type object iterators behave badly with pipes] (This may still be true in Python 3, I just have no experience with Py3k. "At least some version of Python 2" means "the ones I have access to, and have tried." :-) ) In article TheSaint wrote: >I'm with P3k :P. However thank you for your guidelines. >Last my attempt was to use a *for* p.wait() , as mentioned earlier If you have a process that has not yet terminated and that you must stop from your own python program, calling the wait() method will wait forever (because you are now waiting for yourself, in effect -- waiting for yourself to terminate the other process). The only time to call p.wait() (or p.communicate(), which itself calls the wait() method) is when you believe the subprocess is on its wao to terminating -- in this case, after you force it to do so. >That looks good enough. I noted some little delay for the first lines, >mostly sure Popen assign some buffer even it is not set. According to the documentation, the default buffer size of Python 2 is 0, which is passed to fdopen() and makes the resulting files unbuffered. I recall some sort of changes discussed for Py3k though. >Haven't you try a perpetual ping, how would be the line_at_a_time ? Since it is a generator that only requests another line when called, it should be fine. (Compare to the itertools "cycle" and "repeat" generators, for instance, which "return" an infinite sequence.) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From WolfgangMeiners01 at web.de Mon May 30 17:40:57 2011 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Mon, 30 May 2011 23:40:57 +0200 Subject: sqlalchemy and Unicode strings: errormessage Message-ID: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> Hi, I am trying to build an application using sqlalchemy. in principle i have the structure #============================================== from sqlalchemy import * from sqlalchemy.orm import * metadata = MetaData('sqlite://') a_table = Table('tf_lehrer', metadata, Column('id', Integer, primary_key=True), Column('Kuerzel', Text), Column('Name', Text)) A_class = Class(object): def __init__(self, Kuerzel, Name) self.Kuerzel=Kuerzel self.Name=Name mapper(A_class, a_table) A_record = A_class('BUM', 'B?umer') Session = sessionmaker() session = Session() session.add(A_record) session.flush() #================================================ At this time it runs to the line session.flush() where i get the following errormessage: sqlalchemy.exc.ProgrammingError: (ProgrammingError) You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings. u'INSERT INTO tf_lehrer ("Kuerzel", "Name") VALUES (?, ?)' ('BUM', 'B\xc3\xa4umer') but where can i switch my application to Unicode strings? Thank you for all hints Wolfgang From irmen.NOSPAM at xs4all.nl Mon May 30 18:15:06 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 31 May 2011 00:15:06 +0200 Subject: python in school notebooks/laptops In-Reply-To: <2edff4f4-64db-4f39-b822-6f8d2c41eddd@h12g2000pro.googlegroups.com> References: <2edff4f4-64db-4f39-b822-6f8d2c41eddd@h12g2000pro.googlegroups.com> Message-ID: <4de416eb$0$49174$e4fe514c@news.xs4all.nl> On 30-5-2011 16:30, jmfauth wrote: > On 30 mai, 13:09, hackingKK wrote: > > [...] > >> >> Even better, try convincing them to use Ubuntu instead of a virus >> called Where I Never Do Operations With Safety, or WINDOWS for short. >> That way Python will come by default and VB will be out of question >> Happy hacking. >> Krishnakant. > > Do you mean one of these os's, where Python (2) is not > working properly because the *defaultencoding* is set > to utf-8? > > jmf Huh? On all of my machines, including windows and Ubuntu 11.04, sys.getdefaultencoding() returns 'ascii'. Irmen From fzadrozny at appcelerator.com Mon May 30 18:38:07 2011 From: fzadrozny at appcelerator.com (Fabio Zadrozny) Date: Mon, 30 May 2011 19:38:07 -0300 Subject: Pydev 2.1.0 Released Message-ID: Hi All, Pydev 2.1.0 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- Code Analysis By default, only the currently opened editor will be analyzed (resulting in much shorter build times). Added action to force the analysis on a given folder or file. Showing error markers for PyDev elements in the tree. New option to remove error markers when the editor is closed (default). Editor Override method completions (Ctrl+Space after a 'def ') . Completions starting with '_' now have lower priority. Fixed major issue when replacing markers which could make errors appear when they shouldn't appear anymore Auto-linking on close parens is now optional (and disabled by default). Code coverage No longer looses the selection on a refresh. Fixed issue where coverage was not working properly when running with multiple processes. Added orientation options PyUnit Added feature to relaunch the last launch when file changes (with option to relaunch only errors). setUpClass was not called when running with the pydev test runner F12 makes the editor active even if there's a tooltip active in the PyUnit view. The PyUnit tooltip is now properly restoring the focus of the previous active control. Added orientation options And a bunch of other bug-fixes. Note: Java 1.4 is no longer supported (at least Java 5 is required now). 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 Appcelerator http://appcelerator.com/ Aptana http://aptana.com/ Pydev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From steve+comp.lang.python at pearwood.info Mon May 30 19:17:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 23:17:45 GMT Subject: English Idiom in Unix: Directory Recursively References: <4dd61066$0$29996$c3e8da3$5496439d@news.astraweb.com> <37nqa8-lpa.ln1@murmur.very.softly> <4ddaf94b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4ddd898d$0$29996$c3e8da3$5496439d@news.astraweb.com> <9cddb8-viv.ln1@murmur.very.softly> Message-ID: <4de42598$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 23:04:41 +0200, Rikishi42 wrote: > On 2011-05-28, Chris Angelico wrote: >> I think it's geographic. This list covers a lot of geography; I'm in >> Australia, there are quite a few Brits, and probably the bulk of posts >> come from either the US or Europe. (And yes, I did deliberately fold >> all of Europe down to one entity, and I did also deliberately leave >> Great Britain out of that entity.) > > I allways found that odd. Especially if you're talking geography, not > politics. I can understand they want to be seen as independant, even > they are in it enough to allways opose anything someone else suggests. > :-) > > To me, saying the UK isn't part of Europe, is like saying Japan isn't > part of Asia. Oh by the way, I'm Belgian. In my experience, the Japanese have the same attitude towards Asia as the British have towards Europe: they will claim membership, or deny it, depending on whichever suits their mood at the time. >> Most things work out that way. A thing gets a name based either on its >> implementation or on the brand name of the first/most popular one. If >> the only microwave oven ever produced had been made by Foobar Corp, and >> that company were not known for anything else, then quite possibly >> everyone would call them "foobar ovens". > > Yeah, when I was a kid a photo camera was called a Kodak. Sometimes brand names do become generic. "Personal Computer" once was a specific IBM model, not just a description. Elevator and escalator were once brandnames. In some parts of the southern USA, "coke" is used as a word for any softdrink, not just Coca Cola. -- Steven From steve+comp.lang.python at pearwood.info Mon May 30 19:22:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2011 23:22:01 GMT Subject: float("nan") in set or as key References: <271acea3-c38f-4123-9038-e348fb841971@glegroupsg2000goo.googlegroups.com> <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> <4de3358b$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4de42698$0$29996$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 19:58:35 +0000, Chris Torek wrote: > In article <4de3358b$0$29990$c3e8da3$5496439d at news.astraweb.com> Steven > D'Aprano wrote: >>Better than a float method is a function which takes any number as >>argument: >> >>>>> import math, fractions, decimal >>>>> math.isnan(fractions.Fraction(2, 3)) >>False >>>>> math.isnan(decimal.Decimal('nan')) >>True > > Ah, apparently someone's been using Larry Wall's time machine. :-) He has one too? Just like Guido van Rossum. > I should have looked at documentation. In my case, though: > > $ python > Python 2.5.1 (r251:54863, Dec 16 2010, 14:12:43) [GCC 4.0.1 (Apple > Inc. build 5465)] on darwin Type "help", "copyright", "credits" or > "license" for more information. Python 2.5 is two major releases behind! I feel your pain, though, because 2.5 is the system python on my desktop as well. (And 2.4 is the system python on my server, ouch!) You should consider installing 2.7 and/or 3.2 in parallel with the system python. > Would it be appropriate to have isnan() methods for Fraction, Decimal, > and complex, so that you do not need to worry about whether to use > math.isnan() vs cmath.isnan()? Probably not. From a purely object-oriented, Java-esque viewpoint, yes, all number types should support isnan and isinf methods, but Python uses a more mixed style, and a function that accepts multiple types is appropriate. Unless you're using complex numbers, you don't need to care about complex numbers. *wink* Hence for "normal" numeric use, stick to the math module. If you do need complex numbers, cmath.isnan works perfectly fine with non- complex arguments: >>> cmath.isnan(42) False >>> cmath.isnan(float('nan')) True -- Steven From henry.olders at mcgill.ca Mon May 30 20:28:34 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Mon, 30 May 2011 20:28:34 -0400 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On 2011-05-29, at 4:30 , Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a program. The made-up code snippet below illustrates the problem I encountered: > > def main(): > a = ['a list','with','three elements'] > print a > print fnc1(a) > print a > > def fnc1(b): > return fnc2(b) > > def fnc2(c): > c[1] = 'having' > return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same output as the first, but variable a had been changed by changing variable c in fnc2. > > It seems that in Python, a variable inside a function is global unless it's assigned. This rule has apparently been adopted in order to reduce clutter by not having to have global declarations all over the place. > > I would have thought that a function parameter would automatically be considered local to the function. It doesn't make sense to me to pass a global to a function as a parameter. > > One workaround is to call a function with a copy of the list, eg in fnc1 I would have the statement "return fnc2(b[:]". But this seems ugly. > > Are there others who feel as I do that a function parameter should always be local to the function? Or am I missing something here? > My thanks to all the people who responded - I've learned a lot. Sadly, I feel that the main issue that I was trying to address, has not been dealt with. Perhaps I didn't explain myself properly; if so, my apologies. I am trying to write python programs in a more-or-less functional programming mode, ie functions without side effects (except for print statements, which are very helpful for debugging). This is easiest when all variables declared in functions are local in scope (it would also be nice if variables assigned within certain constructs such as for loops and list comprehensions were local to that construct, but I can live without it). It appears, from my reading of the python documentation, that a deliberate decision was made to have variables that are referenced but not assigned in a function, have a global scope. I quote from the python FAQs: "In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function?s body, it?s assumed to be a local. If a variable is ever assigned a new value inside the function, the variable is implicitly local, and you need to explicitly declare it as ?global?. Though a bit surprising at first, a moment?s consideration explains this. On one hand, requiring global for assigned variables provides a bar against unintended side-effects. On the other hand, if global was required for all global references, you?d be using global all the time. You?d have to declare as global every reference to a built-in function or to a component of an imported module. This clutter would defeat the usefulness of the global declaration for identifying side-effects." (http://docs.python.org/faq/programming.html) This suggests that the decision to make unassigned (ie "free" variables) have a global scope, was made somewhat arbitrarily to prevent clutter. But I don't believe that the feared clutter would materialize. My understanding is that when a variable is referenced, python first looks for it in the function's namespace, then the module's, and finally the built-ins. So why would it be necessary to declare references to built-ins as globals? What I would like is that the variables which are included in the function definition's parameter list, would be always treated as local to that function (and of course, accessible to nested functions) but NOT global unless explicitly defined as global. This would prevent the sort of problems that I encountered as described in my original post. I may be wrong here, but it seems that the interpreter/compiler should be able to deal with this, whether the parameter passing is by value, by reference, by object reference, or something else. If variables are not assigned (or bound) at compile time, but are included in the parameter list, then the binding can be made at runtime. And I am NOT talking about variables that are only referenced in the body of a function definition; I am talking about parameters (or arguments) in the function's parameter list. As I stated before, there is no need to include a global variable in a parameter list, and if you want to have an effect outside of the function, that's what the return statement is for. I don't believe I'm the only person who thinks this way. Here is a quote from wikipedia: "It is considered good programming practice to make the scope of variables as narrow as feasible so that different parts of a program do not accidentally interact with each other by modifying each other's variables. Doing so also prevents action at a distance. Common techniques for doing so are to have different sections of a program use different namespaces, or to make individual variables "private" through either dynamic variable scoping or lexical variable scoping." (http://en.wikipedia.org/wiki/Variable_(programming)#Scope_and_extent). It also seems that other languages suitable for functional programming take the approach I think python should use. Here is another quote from the wikipedia entry for Common Lisp: "the use of lexical scope isolates program modules from unwanted interactions. Due to their restricted visibility, lexical variables are private. If one module A binds a lexical variable X, and calls another module B, references to X in B will not accidentally resolve to the X bound in A. B simply has no access to X. For situations in which disciplined interactions through a variable are desirable, Common Lisp provides special variables. Special variables allow for a module A to set up a binding for a variable X which is visible to another module B, called from A. Being able to do this is an advantage, and being able to prevent it from happening is also an advantage; consequently, Common Lisp supports both lexical and dynamic scope. (http://en.wikipedia.org/wiki/Common_Lisp#Determiners_of_scope). If making python behave this way is impossible, then I will just have to live with it. But if it's a question of "we've always done it this way", or, " why change? I'm not bothered by it", then I will repeat my original question: Are there others who feel as I do that a function parameter should always be local to the function? And again, thank you all for taking the time to respond. Henry From harrismh777 at charter.net Mon May 30 20:32:01 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 30 May 2011 19:32:01 -0500 Subject: Beginner needs advice In-Reply-To: <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6GWEp.38791$Vp.28176@newsfe14.iad> Steven D'Aprano wrote: LOL > I invite you to consider the difference between a legally dead person > moments before being resuscitated by a paramedic, ( ... alive ) > versus a chicken that > has just been beheaded and is still running around the yard, ( ... alive ) > versus a > million-year-old fossilized bone that has turned to stone. ( ... mostly 'dead' ) > Who could > possibly justify saying that all three are equally dead? LOL ( the first two [ roflol ] are 'partly' alive... ) ( the third is just mostly dead... ) > > Beware the tyranny of the discontinuous mind. > Sic Semper Tyrannus ! > Compatibility is inherently continuous, a matter > of degree. Compatible by degrees is incompatible. Just 'how' incompatible determines whether the factor(s) are utterly useless, or just difficult to negotiate. (uh, oh,... me suspects another analogy fallacy coming up... ) > This is especially true when it comes to languages, both natural and > programming. ( Yup... analogy fallacy for ?nglisc speakers... ) > British English and American English are perhaps 99.5% > compatible, but "table a motion" means completely opposite things in > British and American English. (In Britain, it means to deal with it > immediately; in the USA, it means to postpone it.) Should we conclude > from this that British and American English are "different languages" and > "completely incompatible"? We Americans have not spoken 'English' in well over two hundred years... :) roflol However, I guarantee that if I'm dumped unaided in Piccadilly I'll be able to hail a cab, pay my ?12.00 and get myself to Liverpool Street Station, find the bathroom, and be on the correct train just in time for dinner, all without looking into the English dictionary. On the other hand (playing along with this analogy fallacy) if I dump a python newbie unaided in the middle of 2.5 and ask them to format a simple polytonic Greek unicode string and output it with print to stdout (redirected to a file) they will fail... maybe even if they have a dictionary ! > > The differences between Python 2 and 3 are less than those between > American and British English. absurd and unsubstantiated claim... quickly now call the bobbies, call the bobbies !!! To describe them as "different languages", > as if going from Python 2 to 3 was like translating English to Italian, > is absurd. ... no, um, its more like migrating ye old ?nglisc... (the ?nglisc of say, "Beowulf" ) to modern English.... still assuming the English analogy fallacy holds... which,... it doesn't... Ever tried to read Beowulf in the original? Ever tried to write ?nglisc ? kind regards, m harris From harrismh777 at charter.net Mon May 30 20:43:33 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 30 May 2011 19:43:33 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: Ian Kelly wrote: > You have just misrepresented Steven's argument, which is rather ironic > considering that you're the one who brought up straw-men. Steven did > not use one code snippet to demonstrate that Python 2 and Python 3 are > fully compatible. The code snippet merely demonstrated that Python 2 > and 3 are not "totally incompatible" as you had claimed. Ian gets the Christmas turkey for pinning the irony on me fair 'n square... 'demonstrating' the straw-man is intimately and infinitely more delicious than just defining it... besides, the tables must be turned me thinks... :) > > I realize you are now asserting that compatibility is a boolean > condition, and that "totally incompatible" is a redundant phrase that > you tossed out as a joke. I don't know whether you're sincere or > backpedaling, but in any case this assertion is flatly ludicrous. > Following your definition,*nothing* is compatible with anything else. > If you disagree, then I invite you to list one example of two > different things that are compatible. one man, and one woman.... > > And finally, . . . you > seem to view all analogies as false) regardless of what that person > actually said ... all analogies are argumentative fallacy. Now, the analogy event (or ontological state of the analogy) may in fact be true... but that event or state can *never* be used to assert truth in 'different event' or fact of 'another state' as the 'same thing(s)'. The truth or fallacy of an argument should never be asserted by the use of an analogy regardless how well the analogy illustrates the point. Some folks believe that a good illustration of a point can be used to prove the point true (or false), when in fact the illustration (the analogy event) is often nothing more than entertaining explanation (Steven's are some of the best, I admit !) -- even if that person does*sometimes* actually commit > those fallacies -- then you yourself are employing an ad hominem. ... oh ho ho... lol yes... again... guilty as charged. kind regards, m harris From harrismh777 at charter.net Mon May 30 20:44:44 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 30 May 2011 19:44:44 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: <0SWEp.5868$cs1.671@newsfe15.iad> Jason Tackaberry wrote: > At least, > his arguments make more sense if I read him as arguing from the "not > completely compatible" position. It's possible he is intentionally > equivocating for dramatic effect. yes From benjamin.kaplan at case.edu Mon May 30 20:52:27 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 30 May 2011 17:52:27 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 5:28 PM, Henry Olders wrote: > > On 2011-05-29, at 4:30 , Henry Olders wrote: > >> I just spent a considerable amount of time and effort debugging a program. The made-up code snippet below illustrates the problem I encountered: >> >> def main(): >> ? ? ? a = ['a list','with','three elements'] >> ? ? ? print a >> ? ? ? print fnc1(a) >> ? ? ? print a >> >> def fnc1(b): >> ? ? ? return fnc2(b) >> >> def fnc2(c): >> ? ? ? c[1] = 'having' >> ? ? ? return c >> >> This is the output: >> ['a list', 'with', 'three elements'] >> ['a list', 'having', 'three elements'] >> ['a list', 'having', 'three elements'] >> >> I had expected the third print statement to give the same output as the first, but variable a had been changed by changing variable c in fnc2. >> >> It seems that in Python, a variable inside a function is global unless it's assigned. This rule has apparently been adopted in order to reduce clutter by not having to have global declarations all over the place. >> >> I would have thought that a function parameter would automatically be considered local to the function. It doesn't make sense to me to pass a global to a function as a parameter. >> >> One workaround is to call a function with a copy of the list, eg in fnc1 I would have the statement "return fnc2(b[:]". But this seems ugly. >> >> Are there others who feel as I do that a function parameter should always be local to the function? Or am I missing something here? >> > > My thanks to all the people who responded - I've learned a lot. Sadly, I feel that the main issue that I was trying to address, has not been dealt with. Perhaps I didn't explain myself properly; if so, my apologies. > > I am trying to write python programs in a more-or-less functional programming mode, ie functions without side effects (except for print statements, which are very helpful for debugging). This is easiest when all variables declared in functions are local in scope (it would also be nice if variables assigned within certain constructs such as for loops and list comprehensions were local to that construct, but I can live without ?it). > > It appears, from my reading of the python documentation, that a deliberate decision was made to have variables that are referenced but not assigned in a function, have a global scope. I quote from the python FAQs: "In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function?s body, it?s assumed to be a local. If a variable is ever assigned a new value inside the function, the variable is implicitly local, and you need to explicitly declare it as ?global?. > Though a bit surprising at first, a moment?s consideration explains this. On one hand, requiring global for assigned variables provides a bar against unintended side-effects. On the other hand, if global was required for all global references, you?d be using global all the time. You?d have to declare as global every reference to a built-in function or to a component of an imported module. This clutter would defeat the usefulness of the global declaration for identifying side-effects." (http://docs.python.org/faq/programming.html) > > This suggests that the decision to make unassigned (ie "free" variables) have a global scope, was made somewhat arbitrarily to ?prevent clutter. But I don't believe that the feared clutter would materialize. My understanding is that when a variable is referenced, python first looks for it in the function's namespace, then the module's, and finally the built-ins. So why would it be necessary to declare references to built-ins as globals? > > What I would like is that the variables which are included in the function definition's parameter list, would be always treated as local to that function (and of course, accessible to nested functions) but NOT global unless explicitly defined as global. This would prevent the sort of problems that I encountered as described in my original post. I may be wrong here, but it seems that the interpreter/compiler should be able to deal with this, whether the parameter passing is by value, by reference, by object reference, or something else. If variables are not assigned (or bound) at compile time, but are included in the parameter list, then the binding can be made at runtime. > And I am NOT talking about variables that are only referenced in the body of a function definition; I am talking about parameters (or arguments) in the function's parameter list. As I stated before, there is no need to include a global variable in a parameter list, and if you want to have an effect outside of the function, that's what the return statement is for. > > I don't believe I'm the only person who thinks this way. Here is a quote from wikipedia: "It is considered good programming practice to make the scope of variables as narrow as feasible so that different parts of a program do not accidentally interact with each other by modifying each other's variables. Doing so also prevents action at a distance. Common techniques for doing so are to have different sections of a program use different namespaces, or to make individual variables "private" through either dynamic variable scoping or lexical variable scoping." (http://en.wikipedia.org/wiki/Variable_(programming)#Scope_and_extent). > > It also seems that other languages suitable for functional programming take the approach I think python should use. Here is another quote from the wikipedia entry for Common Lisp: "the use of lexical scope isolates program modules from unwanted interactions. Due to their restricted visibility, lexical variables are private. If one module A binds a lexical variable X, and calls another module B, references to X in B will not accidentally resolve to the X bound in A. B simply has no access to X. For situations in which disciplined interactions through a variable are desirable, Common Lisp provides special variables. Special variables allow for a module A to set up a binding for a variable X which is visible to another module B, called from A. Being able to do this is an advantage, and being able to prevent it from happening is also an advantage; consequently, Common Lisp supports both lexical and dynamic scope. (http://en.wikipedia.org/wiki/Common_Lisp#Determiners_of_scope). > > > If making python behave this way is impossible, then I will just have to live with it. But if it's a question of "we've always done it this way", or, " why change? I'm not bothered by it", then I will repeat my original question: Are there others who feel as I do that a function parameter should always be local to the function? > > And again, thank you all for taking the time to respond. > > Henry Python doesn't have true globals. When we say "global" what we mean is "module or built-in". Also, consider this code from math import sin def redundant_sin(x) : return sin(x) In Python, everything is an object. That includes functions. By your definition, that function would either have to be written as def redundant_sin(sin, x) : and you would have to pass the function in every time you wanted to call it or have a "global sin" declaration in your function. And you would need to do that for every single function that you call in your function body. > -- > http://mail.python.org/mailman/listinfo/python-list > From harrismh777 at charter.net Mon May 30 20:57:21 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 30 May 2011 19:57:21 -0500 Subject: python in school notebooks/laptops In-Reply-To: References: Message-ID: Chris Angelico wrote: >> Is it a waste of time to try to get school admins to put python in >> > their school laptops? No, absolutely no... Python advocacy is necessary in this venue ! > Possibly the best way to encourage Python deployment would be to > require it to run some internal script. Chris has a great idea here... but I think more along the lines of an app that benefits school admins in terms of networking registration, accountability, or messaging. In other words, if I understand Chris correctly, make the script / app necessarily useful to the admins you are trying to advocate to, so that the students reap the benefits of having the interpretor installed and ready...?!? Great idea... kind regards, m harris From rhodri at wildebst.demon.co.uk Mon May 30 20:58:17 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 31 May 2011 01:58:17 +0100 Subject: Beginner needs advice References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> Message-ID: On Tue, 31 May 2011 01:32:01 +0100, harrismh777 wrote: > Steven D'Aprano wrote: >> Compatibility is inherently continuous, a matter >> of degree. > > Compatible by degrees is incompatible. Just 'how' incompatible > determines whether the factor(s) are utterly useless, or just difficult > to negotiate. > > (uh, oh,... me suspects another analogy fallacy coming up... ) > >> This is especially true when it comes to languages, both natural and >> programming. > > ( Yup... analogy fallacy for ?nglisc speakers... ) I don't know about you, but I speak English not "Anglish". This is how an aesc is pronounced, after all. >> British English and American English are perhaps 99.5% >> compatible, but "table a motion" means completely opposite things in >> British and American English. (In Britain, it means to deal with it >> immediately; in the USA, it means to postpone it.) Should we conclude >> from this that British and American English are "different languages" >> and >> "completely incompatible"? > > We Americans have not spoken 'English' in well over two hundred > years... :) roflol Quite the contrary, in fact. Much American usage of English actually better preserves the styles of eighteenth century English usage, having managed to avoid some of the "corrections" of Victorian grammarians. > However, I guarantee that if I'm dumped unaided in Piccadilly I'll > be able to hail a cab, pay my ?12.00 and get myself to Liverpool Street > Station, find the bathroom, and be on the correct train just in time for > dinner, all without looking into the English dictionary. And I guarantee that you'd get odd looks for at least one of those. You may not notice; we Brits are used to translating the large amount of US TV we get back into British English. > On the other hand (playing along with this analogy fallacy) if I > dump a python newbie unaided in the middle of 2.5 and ask them to format > a simple polytonic Greek unicode string and output it with print to > stdout (redirected to a file) they will fail... maybe even if they have > a dictionary ! Now this is an analogy fallacy, and an obvious one at that. -- Rhodri James *-* Wildebeest Herder to the Masses From dan.kluev at gmail.com Mon May 30 21:11:17 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 12:11:17 +1100 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 11:28 AM, Henry Olders wrote: > What I would like is that the variables which are included in the function definition's parameter list, would be always treated as local to that function You still mis-reading docs and explanations you received from the list. Let me try again. First, there are objects and names. Calling either of them as 'variables' is leading to this mis-understanding. Name refers to some object. Object may be referenced by several names or none. Second, when you declare function `def somefunc(a, b='c')` a and b are both local to this function. Even if there are some global a and b, they are 'masked' in somefunc scope. Docs portion you cited refer to other situation, when there is no clear indicator of 'locality', like this: def somefunc(): print a In this - and only in this - case a is considered global. Third, when you do function call like somefunc(obj1, obj2) it uses call-by-sharing model. It means that it assigns exactly same object, that was referenced by obj1, to name a. So both obj1 and _local_ a reference same object. Therefore when you modify this object, you can see that obj1 and a both changed (because, in fact, obj1 and a are just PyObject*, and point to exactly same thing, which changed). However, if you re-assign local a or global obj1 to other object, other name will keep referencing old object: obj1 = [] def somefunc(a): a.append(1) # 'a' references to the list, which is referenced by obj1, and calls append method of this list, which modifies itself in place global obj1 obj1 = [] # 'a' still references to original list, which is [1] now, it have no relation to obj1 at all somefunc(obj1) -- With best regards, Daniel Kluev From tjreedy at udel.edu Mon May 30 21:12:44 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 21:12:44 -0400 Subject: python in school notebooks/laptops In-Reply-To: <4de416eb$0$49174$e4fe514c@news.xs4all.nl> References: <2edff4f4-64db-4f39-b822-6f8d2c41eddd@h12g2000pro.googlegroups.com> <4de416eb$0$49174$e4fe514c@news.xs4all.nl> Message-ID: On 5/30/2011 6:15 PM, Irmen de Jong wrote: >> Do you mean one of these os's, where Python (2) is not >> working properly because the *defaultencoding* is set >> to utf-8? > Huh? On all of my machines, including windows and Ubuntu 11.04, sys.getdefaultencoding() > returns 'ascii'. For me, WINXP, 2.7 >>> sys.getdefaultencoding() 'ascii' winxp, 3.2: >>> sys.getdefaultencoding() 'utf-8' Both are what one would want. -- Terry Jan Reedy From ian.g.kelly at gmail.com Mon May 30 21:16:23 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 May 2011 19:16:23 -0600 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: On Mon, May 30, 2011 at 6:43 PM, harrismh777 wrote: >> I realize you are now asserting that compatibility is a boolean >> condition, and that "totally incompatible" is a redundant phrase that >> you tossed out as a joke. ?I don't know whether you're sincere or >> backpedaling, but in any case this assertion is flatly ludicrous. >> Following your definition,*nothing* ?is compatible with anything else. >> ?If you disagree, then I invite you to list one example of two >> different things that are compatible. > > ? one man, and one woman.... Now you're equivocating. The discussion has been about whether Python 2 and Python 3 are compatible in the "interchangeable" sense, not in the "capable of functioning together" sense. From tjreedy at udel.edu Mon May 30 21:30:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 21:30:39 -0400 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On 5/30/2011 8:28 PM, Henry Olders wrote: > Sadly, I feel that the main issue that I was trying to address, has > not been dealt with. False. Please go back and read what I and others wrote before. ... > What I would like is that the variables which are included in the > function definition's parameter list, would be always treated as > local to that function (and of course, accessible to nested > functions) You would like Python to be the way it is. Fine. For the Nth time, PARAMATER NAMES ARE LOCAL NAMES. Period. > but NOT global unless explicitly defined as global. PARAMETER NAMES **CANNOT** BE DEFINED AS GLOBAL. >>> def f(a): global a SyntaxError: name 'a' is parameter and global Again, go back and reread what I and other wrote. I believe that you are, in part, hypnotized by the work 'variable'. Can you define the word? There are 10 to 20 possible variations, and yours is probably wrong for Python. > quote from wikipedia: "It is considered good programming practice to > make the scope of variables as narrow as feasible so that different > parts of a program do not accidentally interact with each other by > modifying each other's variables. From 'import this': "Namespaces are one honking great idea -- let's do more of those! Python is loaded with namespaces. > Doing so also prevents action at a > distance. Common techniques for doing so are to have different > sections of a program use different namespaces, or to make individual > variables "private" through either dynamic variable scoping or > lexical variable scoping." > (http://en.wikipedia.org/wiki/Variable_(programming)#Scope_and_extent). Python is lexically scoped. > another quote from the wikipedia entry for Common Lisp: "the use of > lexical scope isolates program modules from unwanted interactions. Python is lexically scoped. > If making python behave this way is impossible, How do you expect us to respond when you say "Please make Python the way it is."? Or is you say "If making Python the way it is is impossible..."? Now, if you actually want Python to drastically change its mode of operation and break most existing programs, do not bother asking. > Are there others who feel as I do that a > function parameter should always be local to the function? Yes, we all do, and they are. -- Terry Jan Reedy From tjreedy at udel.edu Mon May 30 21:34:09 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 21:34:09 -0400 Subject: Beginner needs advice In-Reply-To: <6GWEp.38791$Vp.28176@newsfe14.iad> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> Message-ID: On 5/30/2011 8:32 PM, harrismh777 wrote: > Ever tried to read Beowulf in the original? Ever tried to write ?nglisc ? I have, and it is a lot further from modern American than Python 2 and 3 are from each other. -- Terry Jan Reedy From tjreedy at udel.edu Mon May 30 21:47:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2011 21:47:30 -0400 Subject: Beginner needs advice In-Reply-To: <6GWEp.38791$Vp.28176@newsfe14.iad> References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> Message-ID: On 5/30/2011 8:32 PM, harrismh777 wrote: > > However, I guarantee that if I'm dumped unaided in Piccadilly I'll be > able to hail a cab, pay my ?12.00 and get myself to Liverpool Street > Station, find the bathroom, and be on the correct train just in time for > dinner, all without looking into the English dictionary. Because natural language is redundant and most speakers are forgiving, while computer language are stripped on much redundancy and their interpreters tend to be unforgiving, so a single missing comma or space can raise a SyntaxError. Python is designed to do so, and allow/require correction, rather than guess and go on. This is not so bad; what if the cabbie does not understand you but say OK, guesses the destination, ignores any protestations, and asks for ?30 at the wrong destination. Following people who deafly say OK and take you whereever is a real hazard in some countries. Some tourist guides even warn about the practice. Anyway, 'L i v e r p o o l S t r e e t S t a t i o n' is such a trivial utterance as to not be comparable to anything as complicated as a typical 5-line function. -- Terry Jan Reedy From dan.kluev at gmail.com Mon May 30 21:48:10 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 12:48:10 +1100 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 12:30 PM, Terry Reedy wrote: > Again, go back and reread what I and other wrote. I believe that you are, in > part, hypnotized by the work 'variable'. Can you define the word? There are > 10 to 20 possible variations, and yours is probably wrong for Python. On a sidenote, I wonder what is the reason to keep word 'variable' in python documentation at all. I believe word 'name' represents concept better, and those, who come from other languages, would be less likely to associate wrong definitions with it. -- With best regards, Daniel Kluev From rosuav at gmail.com Mon May 30 22:27:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 12:27:33 +1000 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: On Tue, May 31, 2011 at 11:16 AM, Ian Kelly wrote: > On Mon, May 30, 2011 at 6:43 PM, harrismh777 wrote: >>> ?If you disagree, then I invite you to list one example of two >>> different things that are compatible. >> >> ? one man, and one woman.... > > Now you're equivocating. ?The discussion has been about whether Python > 2 and Python 3 are compatible in the "interchangeable" sense, not in > the "capable of functioning together" sense. Indeed. If a man has a scripting language, and a woman has a scripting language, the two would differ because there are things each can do that the other cannot. But there's a lot of things that both can do, so the two languages would be highly similar in purpose and functionality. Hmm. If you did write those two scripting languages, we would finally be able to type "man woman" to get docs on how to talk to women... Chris Angelico From rosuav at gmail.com Mon May 30 22:53:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 12:53:24 +1000 Subject: python in school notebooks/laptops In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 10:57 AM, harrismh777 wrote: > Chris Angelico wrote: >> Possibly the best way to encourage Python deployment would be to >> require it to run some internal script. > > ? Chris has a great idea here... but I think more along the lines of an app > that benefits school admins in terms of networking registration, > accountability, or messaging. In other words, if I understand Chris > correctly, make the script / app ?necessarily useful to the admins you are > trying to advocate to, so that the students reap the benefits of having the > interpretor installed and ready...?!? Precisely. If there is some kind of need for a script to be deployed on all students' laptops (even if it's just part of some installer, and not necessary post-setup), then write it in Python and put the interpreter on there. This is not shenanigans, but simply the use of a quality tool; it's no different from the eComStation installers making extensive use of VX-REXX, and thus mandating its installation as part of the eCS install. Chris Angelico From harrismh777 at charter.net Mon May 30 23:02:56 2011 From: harrismh777 at charter.net (harrismh777) Date: Mon, 30 May 2011 22:02:56 -0500 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: Chris Angelico wrote: > Hmm. If you did write those two scripting languages, we would finally > be able to type "man woman" to get docs on how to talk to women... Which just wouldn't be fair, because her use of man man would lead her no closer to understanding how men speak... (er, think, um... ) :) > From rosuav at gmail.com Mon May 30 23:05:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 13:05:25 +1000 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 10:28 AM, Henry Olders wrote: > I don't believe I'm the only person who thinks this way. Here is a quote from wikipedia: "It is considered good programming practice to make the scope of variables as narrow as feasible so that different parts of a program do not accidentally interact with each other by modifying each other's variables. Doing so also prevents action at a distance. Common techniques for doing so are to have different sections of a program use different namespaces, or to make individual variables "private" through either dynamic variable scoping or lexical variable scoping." (http://en.wikipedia.org/wiki/Variable_(programming)#Scope_and_extent). > Side point, on variable scope. There is a philosophical split between declaring variables and not declaring them. Python is in the latter camp; you are not required to put "int a; char *b; float c[4];" before you use the integer, string, and list/array variables a, b, and c. This simplifies code significantly, but forces the language to have an unambiguous scoping that doesn't care where you assign to a variable. Example: def f(): x=1 # x is function-scope if cond: # cond is global x=2 # Same function-scope x as above print(x) # Function-scope, will be 2 if cond is true This is fine, and is going to be what you want. Another example: def f(): print(x) # global # .... way down, big function, you've forgotten what you're doing for x in list_of_x: x.frob() By using x as a loop index, you've suddenly made it take function scope, which stops it from referencing the global. Granted, you shouldn't be using globals with names like 'x', but it's not hard to have duplication of variable names. As a C programmer, I'm accustomed to being able to declare a variable in an inner block and have that variable cease to exist once execution leaves that block; but that works ONLY if you declare the variables where you want them. Infinitely-nested scoping is simply one of the casualties of a non-declarative language. Chris Angelico From dan.kluev at gmail.com Mon May 30 23:18:49 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 14:18:49 +1100 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 2:05 PM, Chris Angelico wrote: > Infinitely-nested scoping is simply one of the casualties of a > non-declarative language. Well, this is not accurate, as you can have 'infinitely-nested scoping' in python, in form of nested functions. For example, you can use map(lambda x: , list_of_x), and you will have your isolated scopes. Although due to lambdas supporting only expressions, following this style leads to awkward and complicated code (and/or instead if, map instead for, and so on). -- With best regards, Daniel Kluev From rosuav at gmail.com Mon May 30 23:34:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 13:34:43 +1000 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 1:18 PM, Daniel Kluev wrote: > On Tue, May 31, 2011 at 2:05 PM, Chris Angelico wrote: >> Infinitely-nested scoping is simply one of the casualties of a >> non-declarative language. > > Well, this is not accurate, as you can have 'infinitely-nested > scoping' in python, in form of nested functions. For example, you can > use map(lambda x: map/filter/reduce/lambda's>, list_of_x), and you will have your > isolated scopes. Although due to lambdas supporting only expressions, > following this style leads to awkward and complicated code (and/or > instead if, map instead for, and so on). That's an incredibly messy workaround, and would get ridiculous if you tried going many levels in. It's like saying that a C-style 'switch' statement can be implemented in Python using a dictionary of lambdas... and then trying to implement fall-through. But you're right; a lambda does technically create something of a nested scope - albeit one in which the only internal variables are its parameters. Chris Angelico From prakash.stack at gmail.com Tue May 31 00:05:17 2011 From: prakash.stack at gmail.com (prakash jp) Date: Tue, 31 May 2011 09:35:17 +0530 Subject: pydev ant build Message-ID: Hi all, Could any one provide relevant url/s on the usage of *pyant* scripts and its setup as well Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue May 31 00:35:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 May 2011 04:35:35 GMT Subject: scope of function parameters (take two) References: Message-ID: <4de47016$0$29990$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 May 2011 20:28:34 -0400, Henry Olders wrote: > I am trying to write python programs in a more-or-less functional > programming mode, ie functions without side effects (except for print > statements, which are very helpful for debugging). This is easiest when > all variables declared in functions are local in scope They are. > (it would also be > nice if variables assigned within certain constructs such as for loops > and list comprehensions were local to that construct, but I can live > without it). for loop variables are local to the function, by design. List comprehension variables leak outside the comprehension. That is an accident that is fixed in Python 3. Generator expression variables never leaked. > It appears, from my reading of the python documentation, that a > deliberate decision was made to have variables that are referenced but > not assigned in a function, have a global scope. [...] > This suggests that the decision to make unassigned (ie "free" variables) > have a global scope, was made somewhat arbitrarily to prevent clutter. > But I don't believe that the feared clutter would materialize. Then you haven't understood the problem at all. > My > understanding is that when a variable is referenced, python first looks > for it in the function's namespace, then the module's, and finally the > built-ins. So why would it be necessary to declare references to > built-ins as globals? How else would the functions be found if they were ONLY treated as local? Consider this code: def spam(): print a_name print len(a_name) This includes two names: "a_name" and "len". They both follow the same lookup rules. Functions in Python are first-class values, just like ints, strings, or any other type. You don't want spam() to see any global "a_name" without it being declared. But how then can it see "len"? Don't think that Python could change the rules depending on whether you're calling a name or not. Consider this: def spam(): print a_name print a_name(len) Do you expect the first lookup to fail, and the second to succeed? > What I would like is that the variables which are included in the > function definition's parameter list, would be always treated as local > to that function (and of course, accessible to nested functions) but NOT > global unless explicitly defined as global. They are. Always have been, always will be. > This would prevent the sort > of problems that I encountered as described in my original post. No it wouldn't. You are confused by what you are seeing, and interpreting it wrongly. I believe that what you want is pass-by-value semantics, in the old- school Pascal sense, where passing a variable to a function makes a copy of it. This is not possible in Python. As a design principle, Python never copies objects unless you as it to. > I may > be wrong here, but it seems that the interpreter/compiler should be able > to deal with this, whether the parameter passing is by value, by > reference, by object reference, or something else. Of course. You could create a language that supports any passing models you want. Pascal and VB support pass-by-value ("copy on pass") and pass- by-reference. Algol supports pass-by-value and (I think) pass-by-name. There's no reason why you couldn't create a language to support pass-by- value and pass-by-object. Whether this is a good idea is another story. However, that language is not Python. > If variables are not > assigned (or bound) at compile time, but are included in the parameter > list, then the binding can be made at runtime. Er, yes? That already happens. > And I am NOT talking > about variables that are only referenced in the body of a function > definition; I am talking about parameters (or arguments) in the > function's parameter list. You keep bring up the function parameter list as if that made a difference. It doesn't. Perhaps this will enlighten you: >>> alist = [1, 2, 3, 4] >>> blist = alist >>> blist[0] = -999 >>> alist [-999, 2, 3, 4] Passing alist to a function is no different to any other name binding. It doesn't make a copy of the list, it doesn't pass a reference to the name "alist", it passes the same object to a new scope. > As I stated before, there is no need to > include a global variable in a parameter list, and if you want to have > an effect outside of the function, that's what the return statement is > for. Function parameters are never global. You are misinterpreting what you see if you think they are. [...] > If making python behave this way is impossible, then I will just have to > live with it. But if it's a question of "we've always done it this way", > or, " why change? I'm not bothered by it", then I will repeat my > original question: Are there others who feel as I do that a function > parameter should always be local to the function? They are. You are misinterpreting what you see. -- Steven From drsalists at gmail.com Tue May 31 00:35:57 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 30 May 2011 21:35:57 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 5:28 PM, Henry Olders wrote: > What I would like is that the variables which are included in the function > definition's parameter list, would be always treated as local to that > function (and of course, accessible to nested functions) but NOT global > unless explicitly defined as global. > If you don't want any globals other than callables and modules and builtins, then don't define any. I normally code that way, other than an infrequent (EG) HAVE_CSTRINGIO global or similar (which is module-global, not program-global) - that is, for variables describing what sorts of optional modules are available. Be careful not to conflate global scoping or global lifetime, with mutability or pure, side-effect-free functions (callables). It sounds like what you want is immutability and/or freedom from side effects, which is found most often in (pure) functional languages - which is not what Python is, nor does it attempt to be so. In Python, and in many other languages, if you pass a scalar (or more generally, an object of an immutable type) to a function, and then change the scalar in that function, you only change the scalar within that function, not within the caller. However, if you pass an aggregate type like a list (array) or dictionary (hash table), then the formal argument itself that you've passed is still only changeable within that function, however what it points off at _is_ changeable via that formal argument. This is of course because otherwise passing a 1 gigabyte dictionary to a function would either have to copy the whole dictionary, or implement some sort of Copy-on-Write semantics, or make it somehow readonly. If you need side effect-free functions in Python, you'd probably best copy your aggregates, EG: import copy def main(): a = ['a list','with','three elements'] print a print fnc1(a) print a def fnc1(b): b = copy.deepcopy(b) return fnc2(b) def fnc2(c): c = copy.deepcopy(c) c[1] = 'having' return c main() Or use Haskell. Please don't try to turn Python into Haskell. Each has its own interesting tradeoffs, and we don't really need two Pythons, and we don't really need two Haskells. HTH. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue May 31 01:03:06 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 31 May 2011 07:03:06 +0200 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: Am 31.05.2011 02:28 schrieb Henry Olders: > This suggests that the decision to make unassigned (ie "free" > variables) have a global scope, was made somewhat arbitrarily to > prevent clutter. But I don't believe that the feared clutter would > materialize. My understanding is that when a variable is referenced, > python first looks for it in the function's namespace, then the > module's, and finally the built-ins. So why would it be necessary to > declare references to built-ins as globals? Not for the builtins, but for the global ones. Suppose you have a module def f(x): return 42 def g(x, y): return f(x) + f(y) Would you really want to need a "global f" inside g? Besides, this doesn't have to do with your original problem at all. Even then, a def h(x): x.append(5) return x would clobber the given object, because x is just a name for the same object which the caller has. > What I would like is that the variables which are included in the > function definition's parameter list, would be always treated as > local to that function (and of course, accessible to nested > functions) They are - in terms of name binding. In Python, you always have objects which can be referred to from a variety of places under different names. Maybe what you want are immutable objects (tuples) instead of mutable ones (lists)... > I don't believe I'm the only person who thinks this way. Here is a > quote from wikipedia: "It is considered good programming practice to > make the scope of variables as narrow as feasible Again: It is the way here. Think of C: there you can have a int f(int * x) { *x = 42; return x; } The scope of the variable x is local here. Same in Python. The object referred to by *x is "somewhere else", by design. Same in Python. > If making python behave this way is impossible, then I will just have > to live with it. Even if I still think that you are confusing "scope of a name binding" and "scope of an object", it is a conceptual thing. Surely it would have been possible to do otherwise, but then it would be a different language. Objects can be mutable, period. In MATLAB, e.g., you have what you desire here: you always have to pass your object around and get another ne back, even if you just add or remove a field of a struct or change the value of a field. HTH, Thomas From wolfgang at rohdewald.de Tue May 31 01:13:24 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Tue, 31 May 2011 07:13:24 +0200 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: <201105310713.24842.wolfgang@rohdewald.de> On Dienstag 31 Mai 2011, Henry Olders wrote: > What I would like is that the variables which are included in > the function definition's parameter list, would be always > treated as local to that function (and of course, accessible > to nested functions) but NOT global unless explicitly defined > as global. This would prevent the sort of problems that I > encountered as described in my original post. the parameter is local but it points to an object from an outer scope - that could be the scope of the calling function or maybe the global scope. So if you change the value of this parameter, you change that object from outer scope. But the parameter itself is still local. If you do def fnc2(c): c = 5 the passed object will not be changed, c now points to another object. This is different from other languages where the "global" c would change (when passing c by reference) what you really seem to want is that a function by default cannot have any side effects (you have a side effect if a function changes things outside of its local scope). But that would be a very different language than python did you read the link Steven gave you? http://mail.python.org/pipermail/tutor/2010-December/080505.html -- Wolfgang From ben+python at benfinney.id.au Tue May 31 01:20:12 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 31 May 2011 15:20:12 +1000 Subject: scope of function parameters (take two) References: Message-ID: <871uzf8n03.fsf@benfinney.id.au> Daniel Kluev writes: > On a sidenote, I wonder what is the reason to keep word 'variable' in > python documentation at all. I believe word 'name' represents concept > better, and those, who come from other languages, would be less likely > to associate wrong definitions with it. I agree, but the term ?variable? is used freely within the Python development team to refer to Python's name-to-object bindings, and that usage isn't likely to stop through our efforts. So the burden is unfortunately on us to teach each newbie that this often-used term means something other than what they might expect. -- \ ?In case you haven't noticed, [the USA] are now almost as | `\ feared and hated all over the world as the Nazis were.? ?Kurt | _o__) Vonnegut, 2004 | Ben Finney From benjamin.kaplan at case.edu Tue May 31 01:35:01 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 30 May 2011 22:35:01 -0700 Subject: Beginner needs advice In-Reply-To: References: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> Message-ID: On Mon, May 30, 2011 at 10:20 PM, Dennis Lee Bieber wrote: > On Mon, 30 May 2011 21:34:09 -0400, Terry Reedy > declaimed the following in gmane.comp.python.general: > >> On 5/30/2011 8:32 PM, harrismh777 wrote: >> >> > Ever tried to read Beowulf in the original? Ever tried to write ?nglisc ? >> >> I have, and it is a lot further from modern American than Python 2 and 3 >> are from each other. >> > ? ? ? ?Heck... Python 2 and 3 are modern vs Shakespearian English... > Chaucer is closer to Python vs Ruby... Beowulf? Might as well be APL... > -- No, Python 2 vs 3 is more of American English vs British English. People who speak one of them work under the philosophy that "if y'all would just speak English we wouldn't have these problems" From dan.kluev at gmail.com Tue May 31 01:36:33 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 16:36:33 +1100 Subject: scope of function parameters (take two) In-Reply-To: <201105310713.24842.wolfgang@rohdewald.de> References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: On Tue, May 31, 2011 at 4:13 PM, Wolfgang Rohdewald wrote: > what you really seem to want is that a function by default > cannot have any side effects (you have a side effect if a > function changes things outside of its local scope). But > that would be a very different language than python This can be done in Python (to some degree), like this @copy_args def somefunc(a, b, c): ... where copy_args would explicitly call deepcopy() on all args passed to the function. Or, to save some performance, wrap them in some CopyOnEdit proxy (although this is tricky, as getattr/getitem can modify object too if class overrides them). Obviously it would not save you from functions which use global/globals() or some other ways to change state outside their scope. -- With best regards, Daniel Kluev From ben+python at benfinney.id.au Tue May 31 01:48:34 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 31 May 2011 15:48:34 +1000 Subject: Beginner needs advice References: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> Message-ID: <87wrh7774d.fsf@benfinney.id.au> Dennis Lee Bieber writes: > Well... He did say "find the bathroom", not ask for directions to > whatever euphemism is in current usage (water closet, W/C, loo ?) The room which contains the bath is the bathroom. Assuming that the toilet is in the same room as the bath is parochial. If he wants the toilet, ?bathroom? is a euphemism, and he should instead ask for directions to the toilet. -- \ ?When we talk to God, we're praying. When God talks to us, | `\ we're schizophrenic.? ?Jane Wagner, via Lily Tomlin, 1985 | _o__) | Ben Finney From nitinpawar432 at gmail.com Tue May 31 02:11:58 2011 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 31 May 2011 11:41:58 +0530 Subject: How to Use Setuptools, Alternatives? In-Reply-To: <3e848108-9b22-4ad8-83ed-e563f8346486@28g2000yqu.googlegroups.com> References: <01045077-543f-4b8d-a5a2-4cde190c3294@v8g2000yqb.googlegroups.com> <3e848108-9b22-4ad8-83ed-e563f8346486@28g2000yqu.googlegroups.com> Message-ID: there is a very good article on python packaging http://www.aosabook.org/en/packaging.html On Tue, May 31, 2011 at 12:18 AM, dough wrote: > On May 29, 10:41 pm, ray wrote: > > I have Python 2.7 on Win7 Pro on a tightly locked down desktop. I > > would like to install Networkx from an egg. From what I have read, > > Setuptools can be used for this. > > > > I don't know how to install Setuptools. The exe will not work. On > > execution, it reports that the Python version is not included in the > > registry. Further, I can not input the version and location on the > > subsequent installation screen, the fields will not accept focus so I > > can not input the values. > > > > Since the exe will not install, I considered using the Setuptools > > egg. But it requires Setuptools. It appears to be a circle. > > > > You're right. Since Setuptools is distributed as an egg, and Python > doesn't natively support eggs, > there can be a "chicken-and-egg" situation. > > > What are some suggestions for installing this? > > > > Thanks, > > ray > > You can try downloading ezsetup.py and running it as a python script > (i.e. python ezsetup.py). > It will locate and download the latest version of Setuptools for your > platform and install it. > If HTTP access is blocked, just place the desired egg in the same > folder as ezsetup.py and run > the script again. > > Assuming you can get Setuptools installed correctly, it puts a program > called easy_install.exe > in your \Scripts folder. You can then just run (from the > command line): > > easy_install > > It will hunt, download and install the latest version of the package > for your platform. > You may want to add the path to the Scripts folder to your PATH > environment variable so > you can just run easy_install from any current working directory. > > Hope that helps, > > Doug > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From henry.olders at mcgill.ca Tue May 31 02:37:47 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Tue, 31 May 2011 02:37:47 -0400 Subject: scope of function parameters (take two) In-Reply-To: <201105310713.24842.wolfgang@rohdewald.de> References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: On 2011-05-31, at 1:13 , Wolfgang Rohdewald wrote: > > what you really seem to want is that a function by default > cannot have any side effects (you have a side effect if a > function changes things outside of its local scope). But > that would be a very different language than python You're partially right - what I want is a function that is free of side effects back through the parameters passed in the function call. Side effects via globals or print statements is fine by me. python seems to be undergoing changes all the time. List comprehensions were added in python 2.0, according to wikipedia. I like list comprehensions and use them all the time because they are powerful and concise. > > did you read the link Steven gave you? > http://mail.python.org/pipermail/tutor/2010-December/080505.html Yes, I did, thanks. Henry From harrismh777 at charter.net Tue May 31 02:48:05 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 31 May 2011 01:48:05 -0500 Subject: Something is rotten in Denmark... Message-ID: >>> fs=[] >>> fs = [(lambda n: i + n) for i in range(10)] >>> [fs[i](1) for i in range(10)] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good ( that was a big surprise! . . . ) ( let's try it another way . . . ) >>> fs =[] >>> def g(i): return (lambda n: i + n) >>> fs = [g(i) for i in range(10)] >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (aaah, that's better . . . ) (hmmm, let's try another . . . ) >>> fs =[] >>> for i in range(10): fs.append(lambda n, i=i: i + n) >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (aaaah, that works too . . . ) (... and another... ) >>> fs=[] >>> fs = [(lambda n, i=i: i + n) for i in range(10)] >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (great! . . . ) (now then, what's wrong with this picture ?) lambda? closure? scope? bug? What is going on with the binding in the first construct... this seems to reduce the usefulness of lambda to a considerable extent? kind regards, m harris From clp2 at rebertia.com Tue May 31 02:54:09 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 May 2011 23:54:09 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: On Mon, May 30, 2011 at 11:37 PM, Henry Olders wrote: > On 2011-05-31, at 1:13 , Wolfgang Rohdewald wrote: >> >> what you really seem to want is that a function by default >> cannot have any side effects (you have a side effect if a >> function changes things outside of its local scope). But >> that would be a very different language than python > > You're partially right - what I want is a function that is free of side effects back through the parameters passed in the function call. Side effects via globals or print statements is fine by me. So, you have no problem with *global* side effects, but side effects with a /more constrained/ scope bother you? That's kinda odd, IMO. Cheers, Chris From henry.olders at mcgill.ca Tue May 31 02:57:24 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Tue, 31 May 2011 02:57:24 -0400 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: On 2011-05-30, at 20:52 , Benjamin Kaplan wrote: > On Mon, May 30, 2011 at 5:28 PM, Henry Olders wrote: >> >> On 2011-05-29, at 4:30 , Henry Olders wrote: >> > > Python doesn't have true globals. When we say "global" what we mean is > "module or built-in". Also, consider this code > > from math import sin > def redundant_sin(x) : > return sin(x) > > In Python, everything is an object. That includes functions. By your > definition, that function would either have to be written as > def redundant_sin(sin, x) : > and you would have to pass the function in every time you wanted to > call it or have a "global sin" declaration in your function. And you > would need to do that for every single function that you call in your > function body. > I don't believe so. Within redundant_sin, x is local, so if I change x, it will not change any objects named x outside of the function. As far as sin is concerned, if it were passed to redundant_sin via the parameter list, then it would be local, but otherwise sin would be looked for in the function definition; if not found there, it would be looked for in the module, where it would be found. I am not suggesting any changes to how names are looked up or scoped. Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue May 31 03:00:04 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 31 May 2011 00:00:04 -0700 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: On Mon, May 30, 2011 at 11:48 PM, harrismh777 wrote: >>>> fs=[] >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] > > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] ? ? ? ? <=== not good > > ? ?( that was a big surprise! . . . ) > ? ? lambda? ?closure? ?scope? ? bug? > > ? ? What is going on with the binding in the first construct... this seems > to reduce the usefulness of lambda to a considerable extent? http://stackoverflow.com/questions/233673/lexical-closures-in-python (See 1st and 2nd answers) Cheers, Chris From henry.olders at mcgill.ca Tue May 31 03:17:44 2011 From: henry.olders at mcgill.ca (Henry Olders) Date: Tue, 31 May 2011 03:17:44 -0400 Subject: scope of function parameters (take two) In-Reply-To: References: Message-ID: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> On 2011-05-31, at 24:35 , Dan Stromberg wrote: > > On Mon, May 30, 2011 at 5:28 PM, Henry Olders wrote: > > Be careful not to conflate global scoping or global lifetime, with mutability or pure, side-effect-free functions (callables). It sounds like what you want is immutability and/or freedom from side effects, which is found most often in (pure) functional languages - which is not what Python is, nor does it attempt to be so. I think you're right, I've been conflating scoping with side effects caused by passing mutable objects. > > In Python, and in many other languages, if you pass a scalar (or more generally, an object of an immutable type) to a function, and then change the scalar in that function, you only change the scalar within that function, not within the caller. > > However, if you pass an aggregate type like a list (array) or dictionary (hash table), then the formal argument itself that you've passed is still only changeable within that function, however what it points off at _is_ changeable via that formal argument. This is of course because otherwise passing a 1 gigabyte dictionary to a function would either have to copy the whole dictionary, or implement some sort of Copy-on-Write semantics, or make it somehow readonly. > > If you need side effect-free functions in Python, you'd probably best copy your aggregates, EG: > > import copy > > def main(): > a = ['a list','with','three elements'] > print a > print fnc1(a) > print a > > def fnc1(b): > b = copy.deepcopy(b) > return fnc2(b) > > def fnc2(c): > c = copy.deepcopy(c) > c[1] = 'having' > return c Clearly, making a copy within the function eliminates the possibility of the side effects caused by passing in mutable objects. Would having the compiler/interpreter do this automatically make python so much different? What if it were optional, like nested scopes were in python 2.1 until they became standard in 2.2? Henry -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 31 03:35:27 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 01:35:27 -0600 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 12:48 AM, harrismh777 wrote: > ? ? What is going on with the binding in the first construct... this seems > to reduce the usefulness of lambda to a considerable extent? I don't see why; as you've shown there are a couple of simple ways to avoid this problem. The trick is just to recognize that when you have a closure around a variable, and that variable needs to change, but the value in the closure needs to be constant, then what you really need are two separate variables -- the cell variable needs to be promoted to a local. How you accomplish that is not terribly important. One other technique that is sometimes preferable is functools.partial, e.g.: fs = [functools.partial(operator.add, i) for i in range(10)] Tangentially, I'd like to point out that this line: [fs[i](1) for i in range(10)] is more naturally written as: [f(1) for f in fs] From dan.kluev at gmail.com Tue May 31 03:38:40 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 18:38:40 +1100 Subject: scope of function parameters (take two) In-Reply-To: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 6:17 PM, Henry Olders wrote: > Clearly, making a copy within the function eliminates the possibility of the > side effects caused by passing in mutable objects. Would having the > compiler/interpreter do this automatically make python so much different? As I've pointed, you can make decorator to do that. Adding @copy_args to each function you intend to be pure is not that hard. import decorator import copy @decorator.decorator def copy_args(f, *args, **kw): nargs = [] for arg in args: nargs.append(copy.deepcopy(arg)) nkw = {} for k,v in kw.iteritems(): nkw[k] = copy.deepcopy(v) return f(*nargs, **nkw) @copy_args def test(a): a.append(1) return a >>> l = [0] >>> test(l) [0, 1] >>> l [0] >>> inspect.getargspec(test) ArgSpec(args=['a'], varargs=None, keywords=None, defaults=None) So this decorator achieves needed result and preserves function signatures. -- With best regards, Daniel Kluev From cocohjy2003 at yahoo.com.cn Tue May 31 03:39:02 2011 From: cocohjy2003 at yahoo.com.cn (kiyo) Date: Tue, 31 May 2011 00:39:02 -0700 (PDT) Subject: welcome to visit our website:http://www.yooobuy.com Message-ID: <7df9b643-894c-405f-a0a1-09797290a9e2@y27g2000prb.googlegroups.com> welcome to visit our website:http://www.yooobuy.com prices such as: NIKE AIR JORDAN(http://www.yooobuy.com) Here is the most favorable product, the most attentive service, the most efficient means of transport. If you have any question, our staff will give you a reply in the first time. Wish you happy shopping. From rosuav at gmail.com Tue May 31 04:04:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 31 May 2011 18:04:29 +1000 Subject: scope of function parameters (take two) In-Reply-To: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 5:17 PM, Henry Olders wrote: > Clearly, making a copy within the function eliminates the possibility of the > side effects caused by passing in mutable objects. Would having the > compiler/interpreter do this automatically make python so much different? Yes, it would make Python quite different. If suddenly you couldn't pass a mutable object to a function to get it muted (that sounds wrong), then code will break. Also, there's a fairly serious performance penalty to copying everything when it's not necessary. As has been suggested, you can specifically and deliberately cause this effect for any function(s) you wish to "protect" in this way; there's no need to change the language's fundamentals to do it. Chris Angelico From michal.bulla at gmail.com Tue May 31 04:21:17 2011 From: michal.bulla at gmail.com (michal.bulla) Date: Tue, 31 May 2011 01:21:17 -0700 (PDT) Subject: BadValueError: Property title is required Message-ID: <8106c94d-04f5-4b36-a7dc-be3cff7fecff@b42g2000yqi.googlegroups.com> Hello, I'm trying to create simple method to create category. I set the model category: class Category(db.Model): title = db.StringProperty(required=True) clashes_count = db.IntegerProperty(default=0) And the class New Category as well : class NewCategoryPage(webapp.RequestHandler): def get(self): categories = Category.all().order('-title') template_values = { } path = os.path.join(os.path.dirname(__file__), 'templates', 'category_new.html') self.response.out.write(template.render(path, template_values)) def post(self): category = Category() category.title = self.request.get('title') category.put() self.redirect('/') Here is the template: {%extends "base.html"%} {%block body%}

Add New Category

Title:
{%endblock%} The problem is that I'm getting an error BadValueError: Property title is required. Can you help me with that ? Thanks From clp2 at rebertia.com Tue May 31 04:32:54 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 31 May 2011 01:32:54 -0700 Subject: BadValueError: Property title is required In-Reply-To: <8106c94d-04f5-4b36-a7dc-be3cff7fecff@b42g2000yqi.googlegroups.com> References: <8106c94d-04f5-4b36-a7dc-be3cff7fecff@b42g2000yqi.googlegroups.com> Message-ID: On Tue, May 31, 2011 at 1:21 AM, michal.bulla wrote: > Hello, > > I'm trying to create simple method to create category. I set the model > category: > > class Category(db.Model): > ?title = db.StringProperty(required=True) > ?clashes_count = db.IntegerProperty(default=0) > The problem is that I'm getting an error BadValueError: Property title > is required. Can you help me with that ? Thanks Try asking on the Django mailing list: http://groups.google.com/group/django-users Cheers, Chris From wolfgang at rohdewald.de Tue May 31 04:37:50 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Tue, 31 May 2011 10:37:50 +0200 Subject: scope of function parameters (take two) In-Reply-To: References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: <201105311037.50726.wolfgang@rohdewald.de> On Dienstag 31 Mai 2011, Henry Olders wrote: > You're partially right - what I want is a function that is > free of side effects back through the parameters passed in > the function call. I don't know any object oriented language where it is not possible to change objects passed in as parameters. It is up to the passed object (a list in your case) to allow or disallow manipulations no matter how they are invocated, and the object is the same in the calling code and in the called function. -- Wolfgang From chris at simplistix.co.uk Tue May 31 05:55:14 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 31 May 2011 10:55:14 +0100 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4DE4BB02.2070900@simplistix.co.uk> Hi Wolfgang, On 30/05/2011 22:40, Wolfgang Meiners wrote: > I am trying to build an application using sqlalchemy. You're likely to get much better help here: http://www.sqlalchemy.org/support.html#mailinglist When you post there, make sure you include: - what python version you're using - what sqlalchemy version you're using cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From jpiitula at ling.helsinki.fi Tue May 31 06:08:24 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 31 May 2011 13:08:24 +0300 Subject: Something is rotten in Denmark... References: Message-ID: harrismh777 writes: > >>> fs=[] > >>> fs = [(lambda n: i + n) for i in range(10)] > >>> [fs[i](1) for i in range(10)] > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good > > ( that was a big surprise! . . . ) > ( let's try it another way . . . ) The ten functions share the same i. The list comprehension changes the value of that i. At the time when the functions are called, the value is 9. A different list comprehension mechanism could create a fresh i for each element instead of changing the value of one i. Then each of the functions would have a private i which would have the value it had at the time of the creation of the closure. That is not the Python mechanism. The same sharing-an-i thing happens here: >>> fs = [] >>> for i in range(4): ... fs.append(lambda n : i + n) ... >>> fs[0](0) 3 And the different private-j thing happens here: >>> gs = [] >>> for i in range(4): ... gs.append((lambda j : lambda n : j + n)(i)) ... >>> gs[0](0) 0 You used the lambda itself to introduce its private i in your other examples, in (lambda n, i=i : i + n). In its i=i, the i to the left is a different i - will be a fresh i every time the function is called, I think - while the i to the right gets resolved to the value of the i that the list comprehension is stepping at the time when the closure is created. > What is going on with the binding in the first > construct... this seems to reduce the usefulness of lambda to a > considerable extent? The lambda is doing its lambda thing exactly. The list comprehension just updates the one i in whatever you call it that each of the ten closures remember, and they all observe the updates, so to say. It's a bit subtle. Using different names might help, like I used j. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue May 31 06:48:39 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 31 May 2011 12:48:39 +0200 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: Am 31.05.2011 12:08 schrieb Jussi Piitulainen: > The same sharing-an-i thing happens here: > >>>> fs = [] >>>> for i in range(4): > ... fs.append(lambda n : i + n) > ... >>>> fs[0](0) > 3 > > And the different private-j thing happens here: > >>>> gs = [] >>>> for i in range(4): > ... gs.append((lambda j : lambda n : j + n)(i)) > ... >>>> gs[0](0) > 0 There is a simpler way: with >>>> fs = [] >>>> for i in range(4): > ... fs.append(lambda n, i=i: i + n) > ... you give each lambda a different default argument. >>>> fs[0](0) > 0 Thomas From mohangk at gmail.com Tue May 31 07:25:31 2011 From: mohangk at gmail.com (Mohanaraj Gopala Krishnan) Date: Tue, 31 May 2011 19:25:31 +0800 Subject: Load averages and Python threads on different Linux cloud provider setup Message-ID: Hello, Apologies if this post is off topic. We have a Python application that polls directories using threads and inotify watchers. We have always run this application in a cloud server provided by Voxel (http://www.voxel.net). We are currently testing a different cloud server provider StormOnDemand (http://stormondemand.com) and when we ran our application, our load averages were a lot higher then they were when they were running on the Voxel cloud server despite the specs being about the same (Refer below for more details on setup). We have also ensured then when testing the server was not handling any other loads. I have written a simple test application (test_threads.py - attached, or refer to http://pastebin.com/xGQU7JD0) that simulates the issues we are seeing by starting up threads that loops, sleeping for a user defined time on each loop. It takes 2 parameters, the amount of threads to start and the interval period. When I run, "python test_threads.py 50 0.1" for about 10 minutes Load average results: StormOnDemand: $ uptime 18:46:22 up 7:29, 6 users, load average: 4.43, 4.16, 2.93 voxel.net $ uptime 18:48:14 up 9 days, 15:09, 9 users, load average: 0.51, 0.47, 0.43 The load average on the StormOnDemand server is a lot higher. Python version: StormOnDemand - 2.6.5 Voxel - 2.6.5 Server spec: StormOnDemand - 8 x Intel(R) Xeon(R) CPU E5506 @ 2.13GHz; 16GB RAM; 230GB HDD (Storm Bare Metal servers) Voxel - 7 x Intel(R) Xeon(R) CPU L5640 @ 2.27GHz; 14GB RAM; 200GB HDD (VoxCloud servers) OS: StormOnDemand - Ubuntu 10.04 - 2.6.36-rc8101910 #1 SMP Tue Oct 19 19:18:34 UTC 2010 x86_64 GNU/Linux Voxel - Ubuntu 10.04 - 2.6.32-31-server #61-Ubuntu SMP Fri Apr 8 19:44:42 UTC 2011 x86_64 GNU/Linux Virtualisation method: StormOnDemand - Not 100% sure, but I think they use Xen Voxel - Not sure, but the image that we are using looks to us like a stock standard Ubuntu 10.04 server Any suggestion on why the load would be a lot higher or how I could debug this further is greatly appreciated. -- Mohan -------------- next part -------------- A non-text attachment was scrubbed... Name: test_threads.py Type: text/x-python Size: 1560 bytes Desc: not available URL: From dan.kluev at gmail.com Tue May 31 07:32:25 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Tue, 31 May 2011 22:32:25 +1100 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> Message-ID: On Tue, May 31, 2011 at 8:40 AM, Wolfgang Meiners wrote: > metadata = MetaData('sqlite://') > a_table = Table('tf_lehrer', metadata, > ? ?Column('id', Integer, primary_key=True), > ? ?Column('Kuerzel', Text), > ? ?Column('Name', Text)) Use UnicodeText instead of Text. > A_record = A_class('BUM', 'B?umer') If this is python2.x, use u'B?umer' instead. -- With best regards, Daniel Kluev From nobody at nowhere.net.no Tue May 31 07:33:03 2011 From: nobody at nowhere.net.no (TheSaint) Date: Tue, 31 May 2011 19:33:03 +0800 Subject: How to catch a line with Popen References: Message-ID: Chris Torek wrote: > Since it is a generator that only requests another line when called, > it should be fine Is it, then, that until the new itaration, the callee is on pause? -- goto /dev/null From jpiitula at ling.helsinki.fi Tue May 31 08:15:21 2011 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 31 May 2011 15:15:21 +0300 Subject: Something is rotten in Denmark... References: Message-ID: Thomas Rachel writes: > Am 31.05.2011 12:08 schrieb Jussi Piitulainen: > > > The same sharing-an-i thing happens here: > > > >>>> fs = [] > >>>> for i in range(4): > > ... fs.append(lambda n : i + n) > > ... > >>>> fs[0](0) > > 3 > > > > And the different private-j thing happens here: > > > >>>> gs = [] > >>>> for i in range(4): > > ... gs.append((lambda j : lambda n : j + n)(i)) > > ... > >>>> gs[0](0) > > 0 > > There is a simpler way: with > > >>>> fs = [] > >>>> for i in range(4): > > ... fs.append(lambda n, i=i: i + n) > > ... > > you give each lambda a different default argument. > > >>>> fs[0](0) > > 0 I know, and harrismh777 knows. I find it an unnecessary distraction when explaining why the different closures in the initial example behave identically, but I did discuss it at the end of my post. From saranyamsamy at gmail.com Tue May 31 09:46:28 2011 From: saranyamsamy at gmail.com (success all) Date: Tue, 31 May 2011 06:46:28 -0700 (PDT) Subject: HOT CINEMA NEWS AND ACTRESS STORYS AVAILABLE CLICK HERE Message-ID: http://startamilcinema.blogspot.com/ http://startamilcinema.blogspot.com/ http://startamilcinema.blogspot.com/ http://startamilcinema.blogspot.com/ http://startamilcinema.blogspot.com/ From rosuav at gmail.com Tue May 31 10:22:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 00:22:07 +1000 Subject: Load averages and Python threads on different Linux cloud provider setup In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 9:25 PM, Mohanaraj Gopala Krishnan wrote: > Any suggestion on why the load would be a lot higher or how I could > debug this further is greatly appreciated. > First off, an easy question: Is system load low and comparable on both systems when this script is _not_ running? Chris Angelico From bruno.desthuilliers at gmail.com Tue May 31 10:28:43 2011 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 31 May 2011 07:28:43 -0700 (PDT) Subject: BadValueError: Property title is required References: <8106c94d-04f5-4b36-a7dc-be3cff7fecff@b42g2000yqi.googlegroups.com> Message-ID: <25b882f1-b921-4b3c-a3e0-a7b7c248329d@s16g2000prf.googlegroups.com> On May 31, 10:32?am, Chris Rebert wrote: > On Tue, May 31, 2011 at 1:21 AM, michal.bulla wrote: > > Hello, > > > I'm trying to create simple method to create category. I set the model > > category: > > > class Category(db.Model): > > ?title = db.StringProperty(required=True) > > ?clashes_count = db.IntegerProperty(default=0) > > Not "obviously" Django at all. > > The problem is that I'm getting an error BadValueError: Property title > > is required. Can you help me with that ? Thanks > > Try asking on the Django mailing list:http://groups.google.com/group/django-users Arf ! I just told the guy he was on the wrong group when he (re?)posted this on django-users. From neilc at norwich.edu Tue May 31 10:47:19 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 31 May 2011 14:47:19 GMT Subject: The worth of comments References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Message-ID: <94kdbmFi80U2@mid.individual.net> On 2011-05-28, Roy Smith wrote: > One reasonable definition of a bug is something the code > actually does which differs from the documented interface. > Unless you know what the code is supposed to do, how can you > possibly look at it and say whether it has a bug or not? For > example, take this function: > > def foo(): > l = [1, 2, 3] > return l[3] > > Is this code correct? I'll bet most people would look at this > and say, "I'm not sure what he had in mind, but whatever it > was, this has to be a bug because he's indexing past the end of > the list". Well, what if I showed you the interface contract: > > def foo(): > "Raise IndexError. This is useful as a testing fixture." > l = [1, 2, 3] > return l[3] > > Now it's obvious that the function does exactly what it's > supposed to do (even if it's not the best way to do it). That's an excellent illustration of bad code hid by a bad comment. Perhaps better: def foo(): raise IndexError() -- Neil Cerutti From WolfgangMeiners01 at web.de Tue May 31 11:45:01 2011 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Tue, 31 May 2011 17:45:01 +0200 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> Am 31.05.11 13:32, schrieb Daniel Kluev: > On Tue, May 31, 2011 at 8:40 AM, Wolfgang Meiners > wrote: >> metadata = MetaData('sqlite://') >> a_table = Table('tf_lehrer', metadata, >> Column('id', Integer, primary_key=True), >> Column('Kuerzel', Text), >> Column('Name', Text)) > > Use UnicodeText instead of Text. > >> A_record = A_class('BUM', 'B?umer') > > If this is python2.x, use u'B?umer' instead. > > Thank you Daniel. So i came a little bit closer to the solution. Actually i dont write the strings in a python program but i read them from a file, which is utf8-encoded. So i changed the lines for line in open(file,'r'): line = line.strip() first to for line in open(file,'r'): line = unicode(line.strip()) and finally to for line in open(file,'r'): line = unicode(line.strip(),'utf8') and now i get really utf8-strings. It does work but i dont know why it works. For me it looks like i change an utf8-string to an utf8-string. By the way: when i run a python program from eclipse, then print sys.getdefaultencoding() returns utf-8 and when i run the same python program from the command line, then print sys.getdefaultencoding() returns ascii but my locale is set to $ locale LANG="de_DE.UTF-8" LC_COLLATE="de_DE.UTF-8" LC_CTYPE="de_DE.UTF-8" LC_MESSAGES="de_DE.UTF-8" LC_MONETARY="de_DE.UTF-8" LC_NUMERIC="de_DE.UTF-8" LC_TIME="de_DE.UTF-8" LC_ALL="de_DE.UTF-8" I think, utf8 is somewhat confusing in python - at least to me. Wolfgang From WolfgangMeiners01 at web.de Tue May 31 11:47:14 2011 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Tue, 31 May 2011 17:47:14 +0200 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4de50d82$0$6538$9b4e6d93@newsspool4.arcor-online.net> Am 31.05.11 11:55, schrieb Chris Withers: > Hi Wolfgang, > > On 30/05/2011 22:40, Wolfgang Meiners wrote: >> I am trying to build an application using sqlalchemy. > > You're likely to get much better help here: > > http://www.sqlalchemy.org/support.html#mailinglist > > When you post there, make sure you include: > > - what python version you're using > - what sqlalchemy version you're using > > cheers, > > Chris > Thank you for pointing me to this list. I will have a look to it. At the moment i think i am really struggeling with python and uft8. Wolfgang From tjreedy at udel.edu Tue May 31 11:59:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 May 2011 11:59:21 -0400 Subject: scope of function parameters (take two) In-Reply-To: References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: On 5/31/2011 2:37 AM, Henry Olders wrote: > what I want is a function that is free of side effects back through > the parameters passed in the function call. You can get that by refraining from mutating parameter objects. Simple as that. Just do not expect Python to enforce that discipline on everyone else. To be really functional, and never mutate objects, do not use Python lists, which are arrays. Use linked-list trees, like Lisp languages and perhaps others do. One can easily do this with tuples, or a subclass of tuples, or a class wrapping tuples. Linked-lists and functional programming go together because prepending to a linked list creates a new object while appending to a Python list mutates an existing list. Similarly, popping from a linked list retrieves an item and an existing sublist while popping from a Python list retrieves and item and mutates the list. -- Terry Jan Reedy From WolfgangMeiners01 at web.de Tue May 31 12:10:43 2011 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Tue, 31 May 2011 18:10:43 +0200 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4de51303$0$6557$9b4e6d93@newsspool4.arcor-online.net> I just found a second method on http://docs.python.org/howto/unicode you can use tho module codecs and then simply write import codecs f = codecs.open('unicode.rst', encoding='utf-8') for line in f: print repr(line) Wolfgang From tjreedy at udel.edu Tue May 31 12:15:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 May 2011 12:15:21 -0400 Subject: scope of function parameters (take two) In-Reply-To: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On 5/31/2011 3:17 AM, Henry Olders wrote: > Clearly, making a copy within the function eliminates the possibility of > the side effects caused by passing in mutable objects. Mutable objects and mutating methods and functions are a *feature* of Python. If you do not like them, do not use them. > Would having the compiler/interpreter do this automatically > make python so much different? Yes. How would you then write a function like list.sort or list.pop? It is fundamental that parameters are simply local names that must be bound as part of the calling process. After that, they are nothing special. Python is a language for adults that take responsibility for what they do. If you do not like argument-mutating functions, then do not write them and do not use them (without making a copy yourself). Python was not designed to model timeless immutable mathematics. It is an information-object manipulation language and in real life, we mutate collections and associations all the time. -- Terry Jan Reedy From ian.g.kelly at gmail.com Tue May 31 12:16:12 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 10:16:12 -0600 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 1:38 AM, Daniel Kluev wrote: > @decorator.decorator > def copy_args(f, *args, **kw): > ? ?nargs = [] > ? ?for arg in args: > ? ? ? ?nargs.append(copy.deepcopy(arg)) > ? ?nkw = {} > ? ?for k,v in kw.iteritems(): > ? ? ? ?nkw[k] = copy.deepcopy(v) > ? ?return f(*nargs, **nkw) There is no "decorator" module in the standard library. This must be some third-party module. The usual way to do this would be: def copy_args(f): @functools.wraps(f) def wrapper(*args, **kw): nargs = map(copy.deepcopy, args) nkw = dict(zip(kw.keys(), map(copy.deepcopy, kw.values()))) return f(*nargs, **nkw) return wrapper Note that this will always work, whereas the "decorator.decorator" version will break if the decorated function happens to take a keyword argument named "f". Cheers, Ian From ramit.prasad at jpmchase.com Tue May 31 12:31:36 2011 From: ramit.prasad at jpmchase.com (Prasad, Ramit) Date: Tue, 31 May 2011 12:31:36 -0400 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2E33300F5D@EMARC112VS01.exchad.jpmchase.net> >line = unicode(line.strip(),'utf8') >and now i get really utf8-strings. It does work but i dont know why it works. For me it looks like i change an utf8-string to an utf8-string. I would like to point out that UTF-8 is not exactly "Unicode". From what I understand, Unicode is a standard while UTF-8 is like an implementation of that standard (called an encoding). Being able to convert to Unicode (the standard) should mean you are then able to convert to any encoding that supports the Unicode characters used. As you can see below a string in UTF-8 is actually not Unicode. (decode converts to Unicode, encode converts away from Unicode) >>> type(u'test'.encode('utf8')) >>> type('test'.decode('utf8')) >>> type('test'.encode('utf8')) >>> type(u'test') Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. From ckaynor at zindagigames.com Tue May 31 12:34:34 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 31 May 2011 09:34:34 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 9:16 AM, Ian Kelly wrote: > On Tue, May 31, 2011 at 1:38 AM, Daniel Kluev wrote: > > @decorator.decorator > > def copy_args(f, *args, **kw): > > nargs = [] > > for arg in args: > > nargs.append(copy.deepcopy(arg)) > > nkw = {} > > for k,v in kw.iteritems(): > > nkw[k] = copy.deepcopy(v) > > return f(*nargs, **nkw) > > There is no "decorator" module in the standard library. This must be > some third-party module. The usual way to do this would be: > > def copy_args(f): > @functools.wraps(f) > def wrapper(*args, **kw): > nargs = map(copy.deepcopy, args) > nkw = dict(zip(kw.keys(), map(copy.deepcopy, kw.values()))) > return f(*nargs, **nkw) > return wrapper > > Is there any reason not to simplify this to: def copy_args(f): @functools.wraps(f) def wrapper(*args, **kw): nargs = copy.deepcopy(args) nkw = copy.deepcopy(kw) return f(*nargs, **nkw) return wrapper It means you will copy the keys as well, however they will (almost) certainly be strings which is effectively a no-op. > Note that this will always work, whereas the "decorator.decorator" > version will break if the decorated function happens to take a keyword > argument named "f". > > Cheers, > Ian > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Tue May 31 12:42:45 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 31 May 2011 09:42:45 -0700 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On Tue, May 31, 2011 at 8:45 AM, Wolfgang Meiners wrote: > Am 31.05.11 13:32, schrieb Daniel Kluev: >> On Tue, May 31, 2011 at 8:40 AM, Wolfgang Meiners >> wrote: >>> metadata = MetaData('sqlite://') >>> a_table = Table('tf_lehrer', metadata, >>> ? ?Column('id', Integer, primary_key=True), >>> ? ?Column('Kuerzel', Text), >>> ? ?Column('Name', Text)) >> >> Use UnicodeText instead of Text. >> >>> A_record = A_class('BUM', 'B?umer') >> >> If this is python2.x, use u'B?umer' instead. >> >> > > Thank you Daniel. > So i came a little bit closer to the solution. Actually i dont write the > strings in a python program but i read them from a file, which is > utf8-encoded. > > So i changed the lines > > ? ?for line in open(file,'r'): > ? ? ? ?line = line.strip() > > first to > > ? ?for line in open(file,'r'): > ? ? ? ?line = unicode(line.strip()) > > and finally to > > ? ?for line in open(file,'r'): > ? ? ? ?line = unicode(line.strip(),'utf8') > > and now i get really utf8-strings. It does work but i dont know why it > works. For me it looks like i change an utf8-string to an utf8-string. > There's no such thing as a UTF-8 string. You have a list of bytes (byte string) and you have a list of characters (unicode). UTF-8 is a function that can convert bytes into characters (and the reverse). You may recognize that the list of bytes was encoded using UTF-8 but the computer does not unless you explicitly tell it to. Does that help clear it up? From rustompmody at gmail.com Tue May 31 12:46:19 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 31 May 2011 09:46:19 -0700 (PDT) Subject: scope of function parameters References: Message-ID: <0ae4faae-35ff-403d-944c-5e620a37b326@y27g2000prb.googlegroups.com> On May 29, 1:30?pm, Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a program. The made-up code snippet below illustrates the problem I encountered: > > def main(): > ? ? ? ? a = ['a list','with','three elements'] > ? ? ? ? print a > ? ? ? ? print fnc1(a) > ? ? ? ? print a > > def fnc1(b): > ? ? ? ? return fnc2(b) > > def fnc2(c): > ? ? ? ? c[1] = 'having' > ? ? ? ? return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same output as the first, but variable a had been changed by changing variable c in fnc2. > > It seems that in Python, a variable inside a function is global unless it's assigned. This rule has apparently been adopted in order to reduce clutter by not having to have global declarations all over the place. > > I would have thought that a function parameter would automatically be considered local to the function. It doesn't make sense to me to pass a global to a function as a parameter. > > One workaround is to call a function with a copy of the list, eg in fnc1 I would have the statement "return fnc2(b[:]". But this seems ugly. > > Are there others who feel as I do that a function parameter should always be local to the function? Or am I missing something here? > > Henry You want a functional language. You can simulate that in python by using tuples in place of lists. fnc2(c): c[1] = 'having' return c will of course then give you an error that tuples are not assignable (which seems to be what you want?) So you then use (something like) fnc2(c): return c[0:1] + c[2:] From mohangk at gmail.com Tue May 31 12:53:52 2011 From: mohangk at gmail.com (Mohan) Date: Tue, 31 May 2011 09:53:52 -0700 (PDT) Subject: Load averages and Python threads on different Linux cloud provider setup References: Message-ID: On May 31, 10:22?pm, Chris Angelico wrote: > On Tue, May 31, 2011 at 9:25 PM, Mohanaraj Gopala Krishnan > > wrote: > > Any suggestion on why the load would be a lot higher or how I could > > debug this further is greatly appreciated. > > First off, an easy question: Is system load low and comparable on both > systems when this script is _not_ running? Yes, they both are are < 0.5 (for all averages) and comparable. > > Chris Angelico From python at mrabarnett.plus.com Tue May 31 12:59:56 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 31 May 2011 17:59:56 +0100 Subject: Beginner needs advice In-Reply-To: <87wrh7774d.fsf@benfinney.id.au> References: <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <0XbEp.24071$oq.16802@newsfe17.iad> <4de253a9$0$29996$c3e8da3$5496439d@news.astraweb.com> <6GWEp.38791$Vp.28176@newsfe14.iad> <87wrh7774d.fsf@benfinney.id.au> Message-ID: <4DE51E8C.3060705@mrabarnett.plus.com> On 31/05/2011 06:48, Ben Finney wrote: > Dennis Lee Bieber writes: > >> Well... He did say "find the bathroom", not ask for directions to >> whatever euphemism is in current usage (water closet, W/C, loo ?) > > The room which contains the bath is the bathroom. > > Assuming that the toilet is in the same room as the bath is parochial. > > If he wants the toilet, ?bathroom? is a euphemism, and he should instead > ask for directions to the toilet. > "Toilet" is also a euphemism, as are "water closet", "WC", "loo", etc. From mister270 at gmail.com Tue May 31 13:02:48 2011 From: mister270 at gmail.com (Mike) Date: Tue, 31 May 2011 10:02:48 -0700 (PDT) Subject: nosend missing in suds 0.4? Message-ID: Looks like the nosend attribute is not available in 0.4. Any reason for this? Any plans to add it back and what is the most recent release that does have the nosend option? From ian.g.kelly at gmail.com Tue May 31 13:10:58 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 11:10:58 -0600 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 10:34 AM, Chris Kaynor wrote: > Is there any reason not to simplify this to: > def copy_args(f): > ? ?@functools.wraps(f) > ? ?def wrapper(*args, **kw): > ? ? ? ?nargs = copy.deepcopy(args) > ? ? ? ?nkw = copy.deepcopy(kw) > ? ? ? ?return f(*nargs, **nkw) > ? ?return wrapper No reason, good call. > It means you will copy the keys as well, however they will (almost) > certainly be strings which is effectively a no-op. I think the keys will certainly be strings. Is there any scenario where they might not be? From tjreedy at udel.edu Tue May 31 13:11:43 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 May 2011 13:11:43 -0400 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: On 5/31/2011 2:48 AM, harrismh777 wrote: >>>> fs=[] Irrelevant here since you immediately rebind 'fs'. >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] Same as [f(1) for f in fs] > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good > > ( that was a big surprise! . . . ) You have been hypnotizeed by lambda. (lambda n: i+n) is a *constant expression*, so you get 10 'equal' functions. To see this better fs = [(lambda n: i + n) for i in range(10)] from dis import dis for f in fs: dis(f) 1 0 LOAD_DEREF 0 (i) 3 LOAD_FAST 0 (n) 6 BINARY_ADD 7 RETURN_VALUE 1 0 LOAD_DEREF 0 (i) 3 LOAD_FAST 0 (n) 6 BINARY_ADD 7 RETURN_VALUE ... All have the same bytecode and all retrieve the same last value of i in the nonlocal listcomp scope when you call them *after* the listcomp scope has otherwise disappeared. Your code is equivalent to fs = [] for i in range(10): fs.append(lambda n: i + n) print([f(1) for f in fs]) which is equivalent (except for naming the functions) to fs = [] for i in range(10): def f(n): return i + n fs.append(f) print([f(1) for f in fs]) Does [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] still surprise? Because the def is a constant expression, we can move it out of the loop, and get the equivalent (except for identity) def f(n): return i + n fs = [] for i in range(10): fs.append(f) print([f(1) for f in fs]) This in turn is equivalent to def f(n): return i + n fs = [] for _ in range(10): fs.append(f) i=9 print([f(1) for f in fs]) which in turn is equivalent in output to def f(n): return i + n i = 9 print([f(1) for _ in range(10)]) Note that: def f(n): return i+n # or f = lambda n: i+n fs = [f for i in range(10)] print([f(1) for f in fs]) works in 2.7, with the same output, but not in 3.2 because in 3.x, i is local to the list comp and the later call raises unbound global error. > ( let's try it another way . . . ) All these other ways create 10 *different* (unequal) functions that are different because they have captured 10 different values of i when defined instead of deferring lookup of i to when they are called. def g(i): return (lambda n: i + n) fs = [g(i) for i in range(10)] print([f.__closure__[0].cell_contents for f in fs]) fs = [(lambda n, i=i: i + n) for i in range(10)] print([f.__defaults__[0] for f in fs]) # CPython 3.2 dependent code !!! [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] -- Terry Jan Reedy From rosuav at gmail.com Tue May 31 13:19:52 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 03:19:52 +1000 Subject: sqlalchemy and Unicode strings: errormessage In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2E33300F5D@EMARC112VS01.exchad.jpmchase.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> <0604E20B5F6F2F4784C9C8C71C5DD4DD2E33300F5D@EMARC112VS01.exchad.jpmchase.net> Message-ID: On Wed, Jun 1, 2011 at 2:31 AM, Prasad, Ramit wrote: >>line = unicode(line.strip(),'utf8') >>and now i get really utf8-strings. It does work but i dont know why it works. For me it looks like i change an utf8-string to an utf8-string. > > > I would like to point out that UTF-8 is not exactly "Unicode". From what I understand, Unicode is a standard while UTF-8 is like an implementation of that standard (called an encoding). Being able to convert to Unicode (the standard) should mean you are then able to convert to any encoding that supports the Unicode characters used. Unicode defines characters; UTF-8 is one way (of many) to represent those characters in bytes. UTF-16 and UTF-32 are other ways of representing those characters in bytes, and internally, Python probably uses one of them - but there is no guarantee, and you should never need to know. Unicode strings can be stored in memory and manipulated in various ways, but they're a high level construct on par with lists and dictionaries - they can't be stored on disk or transmitted to another computer without using an encoding system. UTF-8 is an efficient way to translate Unicode text consisting primarily of low codepoint characters into bytes. It's not so much an implementation of Unicode as a means of converting a mythical concept of "Unicode characters" into a concrete stream of bytes. Hope that clarifies things a little! Chris Angelico From rustompmody at gmail.com Tue May 31 13:33:39 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 31 May 2011 10:33:39 -0700 (PDT) Subject: scope of function parameters References: <0ae4faae-35ff-403d-944c-5e620a37b326@y27g2000prb.googlegroups.com> Message-ID: <97dd84e0-c164-4d5e-a485-0fb356eece3a@34g2000pru.googlegroups.com> On May 31, 9:46?pm, rusi wrote: > So you then use (something like) > > fnc2(c): ?return c[0:1] + c[2:] Er sorry -- that should have been def fnc2(c): return c[0:1] + ('having',) + c[2:] From dotancohen at gmail.com Tue May 31 13:56:39 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 31 May 2011 20:56:39 +0300 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: > ?If you disagree, then I invite you to list one example of two > different things that are compatible. > Men and women. MS Office and Open Office. IE6 and HTML. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From ian.g.kelly at gmail.com Tue May 31 14:29:14 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 12:29:14 -0600 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: On Tue, May 31, 2011 at 11:56 AM, Dotan Cohen wrote: >> ?If you disagree, then I invite you to list one example of two >> different things that are compatible. >> > > Men and women. This is a slightly different sense of the word compatible than we have been discussing: able to work together to perform a function, not interchangeable. > MS Office and Open Office. Nope. Remember, the assertion by harrismh777 was that "all you have to do to prove incompatibility is to show 'one' (1) test case where compatibility fails". As one example, any Calc document that uses the EASTERSUNDAY function will fail in Excel, since Excel does not provide it. I could easily come up with other examples (let's not even get into the differences in macros), but one is all I need. > IE6 and HTML. :-) From dotancohen at gmail.com Tue May 31 14:42:26 2011 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 31 May 2011 21:42:26 +0300 Subject: Beginner needs advice In-Reply-To: References: <4DDC7938.5000900@gmail.com> <4ddfc8ae$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de09317$0$29996$c3e8da3$5496439d@news.astraweb.com> <2giEp.236$QL2.62@newsfe04.iad> Message-ID: On Tue, May 31, 2011 at 21:29, Ian Kelly wrote: > On Tue, May 31, 2011 at 11:56 AM, Dotan Cohen wrote: >>> ?If you disagree, then I invite you to list one example of two >>> different things that are compatible. >>> >> >> Men and women. > > This is a slightly different sense of the word compatible than we have > been discussing: able to work together to perform a function, not > interchangeable. > >> MS Office and Open Office. > > Nope. ?Remember, the assertion by harrismh777 was that "all you have > to do to prove incompatibility is to show 'one' (1) test case where > compatibility fails". ?As one example, any Calc document that uses the > EASTERSUNDAY function will fail in Excel, since Excel does not provide > it. ?I could easily come up with other examples (let's not even get > into the differences in macros), but one is all I need. > >> IE6 and HTML. > > :-) > Ian, I'm surprised, you of all people might have noticed that my sarcasm was intended to point out exactly that no two things are compatible, least of all those things designed with compatibility as a design spec! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From WolfgangMeiners01 at web.de Tue May 31 15:52:24 2011 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Tue, 31 May 2011 21:52:24 +0200 Subject: Thanks for all responses In-Reply-To: <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4de546f8$0$6556$9b4e6d93@newsspool4.arcor-online.net> I think it helped me very much to understand the problem. So if i deal with nonascii strings, i have a 'list of bytes' and need an encoding to interpret this list and transform it to a meaningful unicode string. Decoding does the opposite. Whenever i 'cross the border' of my program, i have to encode the 'list of bytes' to an unicode string or decode the unicode string to a 'list of bytes' which is meaningful to the world outside. So encode early, decode lately means, to do it as near to the border as possible and to encode/decode i need a coding system, for example 'utf8' That means, there should be an encoding/decoding possibility to every interface i can use: files, stdin, stdout, stderr, gui (should be the most important ones). While trying to understand this, i wrote the following program. Maybe someone can give me a hint, how to print correctly: ###################################################### #! python # -*- coding: utf-8 -*- class EncTest: def __init__(self,Name=None): self.Name=unicode(Name, encoding='utf8') def __repr__(self): return u'My name is %s' % self.Name if __name__ == '__main__': a = EncTest('M?ller') # this does work print a.__repr__() # throws an error if default encoding is ascii # but works if default encoding is utf8 print a # throws an error because a is not a string print unicode(a, encoding='utf8') ###################################################### Wolfgang From ethan at stoneleaf.us Tue May 31 16:00:19 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 31 May 2011 13:00:19 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: <201105310713.24842.wolfgang@rohdewald.de> Message-ID: <4DE548D3.1010101@stoneleaf.us> Henry Olders wrote: > [...] what I want is a function that is free of side effects [...] Shoot, that's easy! Just write your function to not have any! ~Ethan~ From ethan at stoneleaf.us Tue May 31 16:01:48 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 31 May 2011 13:01:48 -0700 Subject: scope of function parameters (take two) In-Reply-To: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: <4DE5492C.8020300@stoneleaf.us> Henry Olders wrote: > Clearly, making a copy within the function eliminates the possibility of > the side effects caused by passing in mutable objects. Would having the > compiler/interpreter do this automatically make python so much > different? It would be a different language. ~Ethan~ From harrismh777 at charter.net Tue May 31 16:18:37 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 31 May 2011 15:18:37 -0500 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: Terry Reedy wrote: > You have been hypnotizeed by lambda. (lambda n: i+n) is a *constant > expression*, so you get 10 'equal' functions. 'hypnotized' indeed! ... ok, so let me see if I get this... the lambda defers lookup|bind of its references until such time as the lambda is 'called' and not at the time (as I thought) that the anonymous function(s) are returned? If I'm understanding that correctly, then that means lambda is working as designed, and that there are very subtle nuances to be aware of. In my little case (lambda n: i + n) ... if the i goes out of scope before the anonymous function gets called then we have a problem... or if i as a reference is mutable or refers to a different object before the anonymous function is called then we have a problem? What I am discovering is that 'yes' I can use lambda syntactically where I might not be able to code a def statement; however, if I do use it (as in a list comprehension) then I may get unexpected results if any of my lambda's references go out of scope or are mutable...(?) Question: What are the ramifications of making the lookup|binding happen at the time the anonymous function is 'returned' vs 'called'? Has anyone suggested this? Is this PEP-able....? Are there side-effects in the other direction? PS Thanks Chris, Ian, Jussi, Thomas, Terry... I appreciate your teaching and patience ! kind regards, m harris From ckaynor at zindagigames.com Tue May 31 16:28:54 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 31 May 2011 13:28:54 -0700 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: I was thinking you could do something strange like: kw = {object(): None} def test(**kw): print kw test(**kw) however, upon testing it (in Python 2.6), I found that it errors while trying to unpack the kw dict stating that they must all be strings. Perhaps making a custom class derived off basestring, str, unicode, or bytes might allow some oddness and possibly slightly worse performance. Chris On Tue, May 31, 2011 at 10:10 AM, Ian Kelly wrote: > On Tue, May 31, 2011 at 10:34 AM, Chris Kaynor > wrote: > > Is there any reason not to simplify this to: > > def copy_args(f): > > @functools.wraps(f) > > def wrapper(*args, **kw): > > nargs = copy.deepcopy(args) > > nkw = copy.deepcopy(kw) > > return f(*nargs, **nkw) > > return wrapper > > No reason, good call. > > > It means you will copy the keys as well, however they will (almost) > > certainly be strings which is effectively a no-op. > > I think the keys will certainly be strings. Is there any scenario > where they might not be? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmanns at gmx.net Tue May 31 17:14:56 2011 From: mmanns at gmx.net (Martin Manns) Date: Tue, 31 May 2011 23:14:56 +0200 Subject: Something is rotten in Denmark... References: Message-ID: <20110531231456.44d388d7@Fuddel> On Tue, 31 May 2011 01:48:05 -0500 harrismh777 wrote: > >>> fs=[] > >>> fs = [(lambda n: i + n) for i in range(10)] > >>> [fs[i](1) for i in range(10)] > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good > > ( that was a big surprise! . . . ) > ( let's try it another way . . . ) After being confused I figured out it is a 3.x example: ---- $ python Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> fs=[] >>> fs = [(lambda n: i + n) for i in range(10)] >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ---- $ python3.1 Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> fs=[] >>> fs = [(lambda n: i + n) for i in range(10)] >>> [fs[i](1) for i in range(10)] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] ---- Is this fixed automatically by 2to3? Martin From ericsnowcurrently at gmail.com Tue May 31 17:46:49 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 31 May 2011 15:46:49 -0600 Subject: returning NotImplemented Message-ID: Looking at the ABC code [1], I noticed that Mapping's __eq__ method can return NotImplemented. This got me curious as to why you would return NotImplemented and not raise a TypeError or a NotImplementedError. There was an issue regarding this last year [2] that indicated the reason for Mapping's behavior. Also, I found a thread from python-dev [3] which talks about the use of NotImplemented (the thread relates to numeric coercion). I found some older documentation on informal coercion guidelines that helped [4]. My understanding is that NotImplemented is used for binary operators: the right hand side of the operator should be tried if the left hand side returns NotImplemented. So it's more like DoNotKnowHowToHandleArgumentOfThatType. I think the name may have added to my confusion. (BTW, I learned that NotImplemented is a singleton, like None). Is binary operators the only place that NotImplemented is used under the hood? Is it all binary operators, and if not, where does it say which operators use NotImplemented? This would have bearing on when I would need to return it. In the python-dev thread [3], MRAB indicates NotImplemented is used instead of exceptions for performance reasons. Is raising NotImplementedError or TypeError that big a difference? I expect if you are using the operator on a large loop it could matter, but how much? Guido indicates earlier in the thread that NotImplemented is used so that you know that it came from the function that you directly called, and not from another call inside that function. Why does it matter if it came directly from the function or not? And couldn't the NotImplemented still have come from a call inside the operator, rather than directly? As an aside, don't we have that same situation all over the place. For instance, using __getattribute__, how do you know if an AttributeError means that the attribute was not found on the object? It could mean that __getattribute__ called something that raised the exception (and perhaps it should have handled it). Does it matter? Is there a good way to tell the difference, or would it be good practice to always handle explicitly in a function any exception type that you may be raising there? Thanks, -eric [1] http://hg.python.org/cpython/file/29e08a98281d/Lib/collections/abc.py#l398 [2] http://bugs.python.org/issue8729 [3] http://mail.python.org/pipermail/python-dev/2005-March/051835.html [4] http://docs.python.org/release/2.5.2/ref/coercion-rules.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 31 17:47:33 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 15:47:33 -0600 Subject: Something is rotten in Denmark... In-Reply-To: <20110531231456.44d388d7@Fuddel> References: <20110531231456.44d388d7@Fuddel> Message-ID: On Tue, May 31, 2011 at 3:14 PM, Martin Manns wrote: > $ python > Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> fs=[] >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] This works by accident. >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> [fs[0](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> [f(1) for f in fs] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] The i variable is part of the global scope, and as you iterate over range(10) again it coincidentally takes on the same values as in the original list comprehension. You don't see this in Python 3 because the scope of i is limited to the list comprehension, not global. Cheers, Ian From harrismh777 at charter.net Tue May 31 17:53:13 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 31 May 2011 16:53:13 -0500 Subject: Something is rotten in Denmark... In-Reply-To: <20110531231456.44d388d7@Fuddel> References: <20110531231456.44d388d7@Fuddel> Message-ID: Martin Manns wrote: > After being confused I figured out it is a 3.x example: Actually, it is a compatibility example between 2.x and 3.x, compare below for different behavior from two seemingly identical compatible constructs, one from 3.2, and the other from 2.6.4: > Python 3.2 (r32:88445, Mar 29 2011, 21:33:57) > [GCC 4.3.3] on linux2 >>>> fs=[] >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=========== compare >>>> > Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) > [GCC 4.4.1] on linux2 >>>> fs=[] >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] <=========== compare >>>> Having compared the two, someone please tell me whether the two are incompatible, mostly compatible, completely incompatible, or different languages... ,.,, I realize how 3.2 is working (at the moment) but as compared with the books, and the behavior of 2.6, it sure looks 'broke' to me... ... why would we want to defer lookup of the 'i' in range(10) until the anonymous function is called, instead of the time that the function object is returned... inquiring minds want to know... PS Ian calls the second construct "working by mistake..." kind regards, m harris From ericsnowcurrently at gmail.com Tue May 31 17:55:45 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 31 May 2011 15:55:45 -0600 Subject: returning NotImplemented In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 3:46 PM, Eric Snow wrote: > Looking at the ABC code [1], I noticed that Mapping's __eq__ method can > return NotImplemented. This got me curious as to why you would return > NotImplemented and not raise a TypeError or a NotImplementedError. > > There was an issue regarding this last year [2] that indicated the reason > for Mapping's behavior. Also, I found a thread from python-dev [3] which > talks about the use of NotImplemented (the thread relates to numeric > coercion). I found some older documentation on informal coercion guidelines > that helped [4]. My understanding is that NotImplemented is used for binary > operators: the right hand side of the operator should be tried if the left > hand side returns NotImplemented. So it's more like > DoNotKnowHowToHandleArgumentOfThatType. I think the name may have added to > my confusion. (BTW, I learned that NotImplemented is a singleton, like > None). > > Is binary operators the only place that NotImplemented is used under the > hood? Is it all binary operators, and if not, where does it say which > operators use NotImplemented? This would have bearing on when I would need > to return it. > > In the python-dev thread [3], MRAB indicates NotImplemented is used instead > of exceptions for performance reasons. Is raising NotImplementedError or > TypeError that big a difference? I expect if you are using the operator on > a large loop it could matter, but how much? > > Guido indicates earlier in the thread that NotImplemented is used so that > you know that it came from the function that you directly called, and not > from another call inside that function. Why does it matter if it came > directly from the function or not? And couldn't the NotImplemented still > have come from a call inside the operator, rather than directly? > > As an aside, don't we have that same situation all over the place. For > instance, using __getattribute__, how do you know if an AttributeError means > that the attribute was not found on the object? It could mean that > __getattribute__ called something that raised the exception (and perhaps it > should have handled it). Does it matter? Is there a good way to tell the > difference, or would it be good practice to always handle explicitly in a > function any exception type that you may be raising there? > > Thanks, > > -eric > > [1] > http://hg.python.org/cpython/file/29e08a98281d/Lib/collections/abc.py#l398 > [2] http://bugs.python.org/issue8729 > [3] http://mail.python.org/pipermail/python-dev/2005-March/051835.html > [4] http://docs.python.org/release/2.5.2/ref/coercion-rules.html > I'm guessing that http://docs.python.org/reference/datamodel.html is the only place in the docs that talks about the use of NotImplemented. -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue May 31 17:56:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 07:56:24 +1000 Subject: Thanks for all responses In-Reply-To: <4de546f8$0$6556$9b4e6d93@newsspool4.arcor-online.net> References: <4de40ee8$0$6623$9b4e6d93@newsspool2.arcor-online.net> <4de50cfd$0$6538$9b4e6d93@newsspool4.arcor-online.net> <4de546f8$0$6556$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On Wed, Jun 1, 2011 at 5:52 AM, Wolfgang Meiners wrote: > Whenever i 'cross the border' of my program, i have to encode the 'list > of bytes' to an unicode string or decode the unicode string to a 'list > of bytes' which is meaningful to the world outside. Most people use "encode" and "decode" the other way around; you encode a string as UTF-8, and decode UTF-8 into a Unicode string. But yes, you're correct. > So encode early, decode lately means, to do it as near to the border as > possible and to encode/decode i need a coding system, for example 'utf8' Correct on both counts. > That means, there should be an encoding/decoding possibility to every > interface i can use: files, stdin, stdout, stderr, gui (should be the > most important ones). The file objects (as returned by open()) have an encoding, which (IMHO) defaults to "utf8". GUI work depends on your GUI toolkit, and might well accept Unicode strings directly - check the docs. > ? ?def __repr__(self): > ? ? ? ?return u'My name is %s' % self.Name This means that repr() will return a Unicode string. > ? ?# this does work > ? ?print a.__repr__() > > ? ?# throws an error if default encoding is ascii > ? ?# but works if default encoding is utf8 > ? ?print a > > ? ?# throws an error because a is not a string > ? ?print unicode(a, encoding='utf8') The __repr__ function is supposed to return a string object, in Python 2. See http://docs.python.org/reference/datamodel.html#object.__repr__ for that and other advice on writing __repr__. The problems you're seeing are a result of the built-in repr() function calling a.__repr__() and then treating the return value as an ASCII str, not a Unicode string. This would work: ? ?def __repr__(self): ? ? ? ?return (u'My name is %s' % self.Name).encode('utf8') Alternatively, migrate to Python 3, where the default is Unicode strings. I tested this in Python 3.2 on Windows, but it should work on anything in the 3.x branch: class NoEnc: def __init__(self,Name=None): self.Name=Name def __repr__(self): return 'My name is %s' % self.Name if __name__ == '__main__': a = NoEnc('M?ller') # this will still work (print is now a function, not a statement) print(a.__repr__()) # this will work in Python 3.x print(a) # 'unicode' has been renamed to 'str', but it's already unicode so this makes no sense print(str(a, encoding='utf8')) # to convert it to UTF-8, convert it to a string with str() or repr() and then print: print(str(a).encode('utf8')) ############################ Note that the last one will probably not do what you expect. The Python 3 'print' function (it's not a statement any more, so you need parentheses around its argument) wants a Unicode string, so you don't need to encode it. When you encode a Unicode string as in the last example, it returns a bytes string (an array of bytes), which looks like this: b'My name is M\xc3\xbcller' The print function wants Unicode, though, so it takes this unexpected object and calls str() on it, hence the odd display. Hope that helps! Chris Angelico From harrismh777 at charter.net Tue May 31 18:06:40 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 31 May 2011 17:06:40 -0500 Subject: Something is rotten in Denmark... In-Reply-To: References: <20110531231456.44d388d7@Fuddel> Message-ID: harrismh777 wrote: > PS Ian calls the second construct "working by mistake..." oops, actually he called it, "working by accident... " From ericsnowcurrently at gmail.com Tue May 31 18:11:20 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 31 May 2011 16:11:20 -0600 Subject: returning NotImplemented In-Reply-To: <4DE56933.4050404@stoneleaf.us> References: <4DE56933.4050404@stoneleaf.us> Message-ID: On Tue, May 31, 2011 at 4:18 PM, Ethan Furman wrote: > Eric Snow wrote: > >> Looking at the ABC code [1], I noticed that Mapping's __eq__ method can >> return NotImplemented. This got me curious as to why you would return >> NotImplemented and not raise a TypeError or a NotImplementedError. >> > > My understanding is that if your object does not know how to perform the > desired action you should return NotImplemented; Python will then give the > other object a chance to perform the operation (after all, it may know how), > and if the other object also returns NotImplemented then Python itself will > raise a TypeError. > > If the first object were to raise TypeError (or any exception), the second > object would not get the chance to try. > > RIght. But the operator code could very well handle the appropriate exception instead of handling a return value of NotImplemented. Hence my further questions regarding performance and identifiability. My guess is that it's ultimately because of speed. -eric > ~Ethan~ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue May 31 18:18:27 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 31 May 2011 15:18:27 -0700 Subject: returning NotImplemented In-Reply-To: References: Message-ID: <4DE56933.4050404@stoneleaf.us> Eric Snow wrote: > Looking at the ABC code [1], I noticed that Mapping's __eq__ method can > return NotImplemented. This got me curious as to why you would return > NotImplemented and not raise a TypeError or a NotImplementedError. My understanding is that if your object does not know how to perform the desired action you should return NotImplemented; Python will then give the other object a chance to perform the operation (after all, it may know how), and if the other object also returns NotImplemented then Python itself will raise a TypeError. If the first object were to raise TypeError (or any exception), the second object would not get the chance to try. ~Ethan~ From ian.g.kelly at gmail.com Tue May 31 18:24:27 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 16:24:27 -0600 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: On Tue, May 31, 2011 at 2:18 PM, harrismh777 wrote: > If I'm understanding that correctly, then that means lambda is working as > designed, and that there are very subtle nuances to be aware of. In my > little case > > ? (lambda n: i + n) > > ? ... if the ?i ?goes out of scope before the anonymous function gets called > then we have a problem... or if ?i ? as a reference is mutable or refers to > a different object before the anonymous function is called then we have a > problem? Actually, if i merely goes out of scope, there is no problem. It just creates a closure. It's only when the i within that scope is modified that we run into problems. In fact, in Python 3 the scope of a list comprehension variable is the list comprehension itself, so in your original post i was already out of scope by the time you started calling the lambda functions. Cheers, Ian From rosuav at gmail.com Tue May 31 18:39:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 08:39:16 +1000 Subject: Something is rotten in Denmark... In-Reply-To: References: <20110531231456.44d388d7@Fuddel> Message-ID: On Wed, Jun 1, 2011 at 7:53 AM, harrismh777 wrote: > ? ? Having compared the two, someone please tell me whether the two are > incompatible, mostly compatible, completely incompatible, or different > languages... > By implication, every version of Python is incompatible with every other. The 2.7.1 revision notes include: - Issue #1713: Fix os.path.ismount(), which returned true for symbolic links across devices. Suppose some program were depending on this bug. It works under 2.7.0, fails under 2.7.1. Does that mean that 2.7.1 is incompatible with 2.7.0? Chris Angelico From rosuav at gmail.com Tue May 31 18:40:02 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 08:40:02 +1000 Subject: Something is rotten in Denmark... In-Reply-To: References: <20110531231456.44d388d7@Fuddel> Message-ID: On Wed, Jun 1, 2011 at 8:39 AM, Chris Angelico wrote: > - Issue #1713: Fix os.path.ismount(), which returned true for symbolic links > ?across devices. PS. I know nothing about this particular issue, I just skimmed down the release notes and stopped when something caught my eye. Choose another example if you know of a better one. Chris Angelico From peterirbizon at gmail.com Tue May 31 18:44:24 2011 From: peterirbizon at gmail.com (miamia) Date: Tue, 31 May 2011 15:44:24 -0700 (PDT) Subject: hide gtk warning Message-ID: <8081ec79-c19e-4adf-9b0c-dcfde21e3b1f@hg8g2000vbb.googlegroups.com> I am getting gtkwarning: gdk_property_change: assertion window ! =Null failed gtk.main() it is gdk bug but not fixed yet.How could I simply "not show/hide" this error warning? so user should never see it. thank you From tjreedy at udel.edu Tue May 31 19:14:09 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 May 2011 19:14:09 -0400 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: On 5/31/2011 4:18 PM, harrismh777 wrote: > Terry Reedy wrote: >> You have been hypnotizeed by lambda. (lambda n: i+n) is a *constant >> expression*, so you get 10 'equal' functions. > 'hypnotized' indeed! I say 'hypnotized' ;-) because people have posted examples almost exactly like the one you did, with a list of 10 (usually) lambda-defined functions, at least yearly for over a decade. Never have I seen the same puzzlement when the functions are defined with def statements instead. What you did differently is to continue investigating and discover some of the alternatives for yourself. Hence you get more effort from others in response. I think part of the problem with lambda is this: the body of a def statement is indented and nicely set apart from surrounding code. The body of a lambda expression is prefixed by the header but there is no terminator to visually indicate the end of the nested scope. I think there should have been. I often add unneeded parens, as you did, but that is not lambda specific. Generator expressions have to be set apart with parentheses, and other comprehensions are all fenced. There also seems to be a bit of lambda (oc)cultism and mystique of the anonymous. However, if a function raises an exception, anonymity is a defect. What you did differently is to continue investigating and discover some of the alternatives for yourself. > ... ok, so let me see if I get this... the lambda > defers lookup|bind of its references until such time as the lambda is > 'called' and not at the time (as I thought) that the anonymous > function(s) are returned? In Python, there are no lambda objects to be called. A def statement, when executed, produces an instance of the user-defined function class. Its .__name__ attribute is the one given in the header of the statement. A lambda expression, when executed, produces an instance of the user-defined function class. Its .__name__ attribute is '' (at least in CPython). See the single difference? The objects produced by equivalent def statements and lambda expressions are otherwise exactly the same. statement with lambda arg-list: expression is an abbreviation for def new-name(arg-list): return expression statement with new-name assuming that the lambda in in the same scope as the statement and not nested in another scope-creating expression > If I'm understanding that correctly, then that means lambda is working > as designed, and that there are very subtle nuances to be aware of. I would say that there is no subtle nuance. Except for not providing a name, a lambda expression is purely an optional syntactic abbreviation. > In my little case > > (lambda n: i + n) > > ... if the i goes out of scope before the anonymous function gets called > then we have a problem... There was no problem; nonlocal names and their associations with objects get saved (in 'cells', for CPython) association with the function than needs them. One of my examples showed how to retrieve them. > or if i as a reference is mutable Objects are mutable, names can be rebound. > or refers to a different object before the anonymous function > is called then we have a problem? Anonymity is completely irrelevant to all of the above. Everything is the same as for def f(n): return i + n. When a function is compiled, each name is classified as local, non-local, or global. When the function is called and a name is evaluated, the corresponding object from its scope is retrieved, if there is one, or an error is raised. > What I am discovering is that 'yes' I can use lambda syntactically where > I might not be able to code a def statement; If the lambda expression is nested in an abbreviated nested scope (lambda or comprehension), then you have to unabbreviate the outer nesting before you can unabbreviate the lambda. Several example of this have been shown. > however, if I do use it (as in a list comprehension) then I may get > unexpected results if any of my > lambda's references go out of scope or are mutable...(?) Nothing needed goes out of scope and all names are rebindable (not mutable). > What are the ramifications of making the lookup|binding happen at the > time the anonymous function is 'returned' vs 'called'? This is early-binding versus late-binding. Python is a late-binding language. Are you asking about changing all function compilation or only when functions are defined with lambda expressions? The latter *would* make there be a 'suble nuance' that Python now lacks and does not need. > Has anyone suggested this? Of course, more than once, in multiple variations. All have so far been rejected, more than once. The most sensible ideas are for earlier binding of builtins to make Python run faster. You have already discovered and been given some of the solutions. Another is to define a class with a __call__ statement and save the desired early bindings as instance data attributes. Your g(i): return lambda ... as well as the default arg trick are functional equivalents of the same idea. In general, if you want to immediately grab and save an object, then explicity grab and save the object. -- Terry Jan Reedy From dan.kluev at gmail.com Tue May 31 20:04:10 2011 From: dan.kluev at gmail.com (Daniel Kluev) Date: Wed, 1 Jun 2011 11:04:10 +1100 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Wed, Jun 1, 2011 at 3:16 AM, Ian Kelly wrote: > > There is no "decorator" module in the standard library. ?This must be > some third-party module. ?The usual way to do this would be: Yes, but its very useful for decorators and provides some not-readily-available functionality. http://pypi.python.org/pypi/decorator/3.3.1 > Note that this will always work, whereas the "decorator.decorator" > version will break if the decorated function happens to take a keyword > argument named "f". No, it will not. Its the magic of decorator library, it is signature-preserving, while your variant breaks function signature and causes problems to any code that relies on signatures (happens with Pylons, for example). >>> @copy_args ... def test(a, f=None): ... print f ... >>> test([], f=123) 123 Basically decorator.decorator uses exec to create new function, with signature of function you pass to your decorator, so it does not matter what names you used for args in decorator itself. -- With best regards, Daniel Kluev From harrismh777 at charter.net Tue May 31 20:09:38 2011 From: harrismh777 at charter.net (harrismh777) Date: Tue, 31 May 2011 19:09:38 -0500 Subject: Something is rotten in Denmark... In-Reply-To: References: Message-ID: Terry Reedy wrote: > This is early-binding versus late-binding. Python is a late-binding > language. ok ... > Are you asking about changing all function compilation or only when > functions are defined with lambda expressions? At least lambda expressions, but (see below) any other built-in where 'early-binding' makes sense for intuitive results or performance--- possibly, not commenting. The latter *would* make > there be a 'suble nuance' that Python now lacks and does not need. How so, and why not? >> Has anyone suggested this? > Of course, more than once, in multiple variations. All have so far been > rejected, more than once. The most sensible ideas are for earlier > binding of builtins to make Python run faster. At the moment I'm only speaking about my OP and that particular list comprehension... the thing that happened (at least for me) is that the intuitive sense that each 'i' somehow becomes a part of the anonymous function (I know, not so) is built-in. There is little to nothing indicating in the docs that this is not so. Again, what we have here is the 'i' being saved in a cell and looked up at call time (an implementation detail, 'late-binding') that is critical for the user-coder to understand. This *may* be true for other built-ins also, I'm not commenting on that, but it seems to me that if lambda is going to remain in the language at all that 'early-binding' in the lambda specific case would make sense; at least make the lambda more useful generally. ... just saying, kind regards, m harris From ethan at stoneleaf.us Tue May 31 20:30:18 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 31 May 2011 17:30:18 -0700 Subject: returning NotImplemented In-Reply-To: References: Message-ID: <4DE5881A.7010908@stoneleaf.us> Eric Snow wrote: > Guido indicates earlier in the thread that NotImplemented is used so > that you know that it came from the function that you directly called, > and not from another call inside that function. Why does it matter if > it came directly from the function or not? And couldn't the > NotImplemented still have come from a call inside the operator, rather > than directly? An exception can bubble up from several levels below the original call. Returning NotImplemented (even if returned from another internal function) still has to be deliberately done by the original method. Later in the thread it is also stated that while exception handling performance is not too different in C code, it is very much more expensive in Python code. As to why it would matter if whether the return was from the directly called method vs some nested method... not sure, but I would hazard a guess that by returning NotImplented the interpreter knows everything worked as it should have (assuming no bugs, of course); whereas an exception could easily _not_ have come from the directly called method. Imagine if the methods raised exceptions to signal normal behavior, and some object was buggy -- for __eq__ we'd end up with a False result, instead of getting the exception propagated. (!) ~Ethan~ From chrisjames95129 at gmail.com Tue May 31 20:44:55 2011 From: chrisjames95129 at gmail.com (Christopher James) Date: Tue, 31 May 2011 17:44:55 -0700 Subject: Python hoodie Message-ID: Hi all! I LOVE Python, and want to spread the word by sporting this awesome sweater shown at: http://www.freewear.org/?page=show_item&id=FW0067 which I found by looking on the merchandise page of python.org. However, I live in the United States and before checking out I noticed that on top of the US$40 it was going to cost an additional US$45 for SHIPPING! I guess because of customs and such. Anyway, where can I get one of these sweatshirts sent to me for a reasonable shipping price in the U.S.? I would be happy to buy one and show my love for Python, but US$85 is a little steep for a hoodie for me. Cheers! Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmanns at gmx.net Tue May 31 20:57:52 2011 From: mmanns at gmx.net (Martin Manns) Date: Wed, 1 Jun 2011 02:57:52 +0200 Subject: Something is rotten in Denmark... In-Reply-To: References: <20110531231456.44d388d7@Fuddel> Message-ID: <20110601025752.676f0ec8@Fuddel> On Tue, 31 May 2011 15:47:33 -0600 Ian Kelly wrote: > The i variable is part of the global scope, and as you iterate over > range(10) again it coincidentally takes on the same values as in the > original list comprehension. You don't see this in Python 3 because > the scope of i is limited to the list comprehension, not global. I read about the scope change. However, list comprehension scope being global still feels "right" for me because I am still using Python 2. I feel that I should start worrying more about future migration issues. Cheers Martin From ian.g.kelly at gmail.com Tue May 31 21:14:26 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 31 May 2011 19:14:26 -0600 Subject: scope of function parameters (take two) In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> Message-ID: On Tue, May 31, 2011 at 6:04 PM, Daniel Kluev wrote: > On Wed, Jun 1, 2011 at 3:16 AM, Ian Kelly wrote: >> >> There is no "decorator" module in the standard library. ?This must be >> some third-party module. ?The usual way to do this would be: > > Yes, but its very useful for decorators and provides some > not-readily-available functionality. > http://pypi.python.org/pypi/decorator/3.3.1 > >> Note that this will always work, whereas the "decorator.decorator" >> version will break if the decorated function happens to take a keyword >> argument named "f". > > No, it will not. Its the magic of decorator library, it is > signature-preserving, while your variant breaks function signature and > causes problems to any code that relies on signatures (happens with > Pylons, for example). Ah, I see. I assumed it was much simpler than it is. I found a way to break it with Python 3, though: >>> @copy_args ... def test(*, f): ... return f ... >>> test(f=1) Traceback (most recent call last): File "", line 1, in File "", line 2, in test File "", line 6, in copy_args TypeError: test() needs keyword-only argument f The interesting thing here is that the decorated function has exactly the correct function signature; it just doesn't work. Cheers, Ian From ericsnowcurrently at gmail.com Tue May 31 21:28:19 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 31 May 2011 19:28:19 -0600 Subject: returning NotImplemented In-Reply-To: <4DE5881A.7010908@stoneleaf.us> References: <4DE5881A.7010908@stoneleaf.us> Message-ID: On Tue, May 31, 2011 at 6:30 PM, Ethan Furman wrote: > Eric Snow wrote: > >> Guido indicates earlier in the thread that NotImplemented is used so that >> you know that it came from the function that you directly called, and not >> from another call inside that function. Why does it matter if it came >> directly from the function or not? And couldn't the NotImplemented still >> have come from a call inside the operator, rather than directly? >> > > An exception can bubble up from several levels below the original call. > Returning NotImplemented (even if returned from another internal function) > still has to be deliberately done by the original method. > > Later in the thread it is also stated that while exception handling > performance is not too different in C code, it is very much more expensive > in Python code. > > As to why it would matter if whether the return was from the directly > called method vs some nested method... not sure, but I would hazard a guess > that by returning NotImplented the interpreter knows everything worked as it > should have (assuming no bugs, of course); whereas an exception could easily > _not_ have come from the directly called method. Imagine if the methods > raised exceptions to signal normal behavior, and some object was buggy -- > for __eq__ we'd end up with a False result, instead of getting the exception > propagated. (!) > > Thanks Ethan. That was insightful. I hadn't considered the case where we would want a TypeError or NotImplementedError or whatever to propagate. So simply catching any old exception doesn't cut it. The alternative is to have something like a CouldNotHandleTypeError that inherits just from BaseException, that is only used in the NotImplemented situation. Then the specificity resolves that problem. You're right that performance still suffers for python code, but the current NotImplemented handling stuff is in the C code that handles operators. I guess where it would hit is where you raise the Exception in the __eq__ method (or wherever), instead of returning NotImplemented. So, my understanding is that NotImplemented is sort of a special case of raising "exceptions" through return values for performance reasons, where normally we use exceptions. Here is an example of the equivalence that I am seeing: class X: def __eq__(self, other): return NotImplemented result = X().__eq__(1) if result is NotImplemented: raise TypeError - vs - class X: def __eq__(self, other): raise CouldNotHandleTypeError try: result = X().__eq__(1) except CouldNotHandleTypeError: raise TypeError I'm fine with this. It's probably one of those practicality beats purity things. And at the C level it's practically the same thing. As I have thought about this I've realized that it's really isolated to a specific place, namely operator handling for numeric and comparison operators, so no big deal. -eric ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Tue May 31 22:17:50 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 31 May 2011 21:17:50 -0500 Subject: Sanitizing filename strings across platforms Message-ID: <4DE5A14E.5090009@tim.thechases.com> Scenario: a file-name from potentially untrusted sources may have odd filenames that need to be sanitized for the underlying OS. On *nix, this generally just means "don't use '/' or \x00 in your string", while on Win32, there are a host of verboten characters and file-names. Then there's also checking the abspath/normpath of the resulting name to make sure it's still in the intended folder. I've read through [1] and have started to glom together various bits from that thread. My current course of action is something like SACRED_WIN32_FNAMES = set( ['CON', 'PRN', 'CLOCK$', 'AUX', 'NUL'] + ['LPT%i' % i for i in range(32)] + ['CON%i' % i for i in range(32)] + def sanitize_filename(fname): sane = set(string.letters + string.digits + '-_.[]{}()$') results = ''.join(c for c in fname if c in sane) # might have to check sans-extension if results.upper() in SACRED_WIN32_FNAMES: results = "_" + results return results but if somebody already has war-hardened code they'd be willing to share, I'd appreciate any thoughts. Thanks, -tkc [1] http://stackoverflow.com/questions/295135/turn-a-string-into-a-valid-filename-in-python From python at rcn.com Tue May 31 22:44:07 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 31 May 2011 19:44:07 -0700 (PDT) Subject: Updated blog post on how to use super() Message-ID: <80476fba-1b57-4bb1-9d7d-391edaf3042d@22g2000prx.googlegroups.com> I've tightened the wording a bit, made much better use of keyword arguments instead of kwds.pop(arg), and added a section on defensive programming (protecting a subclass from inadvertently missing an MRO requirement). Also, there is an entry on how to use assertions to validate search order requirements and make them explicit. http://bit.ly/py_super or http://rhettinger.wordpress.com/2011/05/26/super-considered-super/ Any further suggestions are welcome. I'm expecting this to evolve into how-to guide to be included in the regular Python standard documentation. The goal is to serve as a reliable guide to using super and how to design cooperative classes in a way that lets subclasses compose and extent them. Raymond Hettinger -------- follow my python tips on twitter: @raymondh From pavlovevidence at gmail.com Tue May 31 22:45:01 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 31 May 2011 19:45:01 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: <4de31635$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <678acba6-e8fd-42fc-bed0-118034897497@glegroupsg2000goo.googlegroups.com> On Sunday, May 29, 2011 8:59:49 PM UTC-7, Steven D'Aprano wrote: > On Sun, 29 May 2011 17:55:22 -0700, Carl Banks wrote: > > > Floating point arithmetic evolved more or less on languages like Fortran > > where things like exceptions were unheard of, > > I'm afraid that you are completely mistaken. > > Fortran IV had support for floating point traps, which are "things like > exceptions". That's as far back as 1966. I'd be shocked if earlier > Fortrans didn't also have support for traps. > > http://www.bitsavers.org/pdf/ibm/7040/C28-6806-1_7040ftnMathSubrs.pdf Fine, it wasn't "unheard of". I'm pretty sure the existence of a few high end compiler/hardware combinations that supported traps doesn't invalidate my basic point. NaN was needed because few systems had a separate path to deal with exceptional situations like producing or operating on something that isn't a number. When they did exist few programmers used them. If floating-point were standardized today it might not even have NaN (and definitely wouldn't support the ridiculous NaN != NaN), because all modern systems can be expected to support exceptions, and modern programmers can be expected to use them. > The IEEE standard specifies that you should be able to control whether a > calculation traps or returns a NAN. That's how Decimal does it, that's > how Apple's (sadly long abandoned) SANE did it, and floats should do the > same thing. If your aim is to support every last clause of IEEE for better or worse, then yes that's what Python should do. If your aim is to make Python the best language it can be, then Python should reject IEEE's obsolete notions, and throw exceptions when operating on NaN. Carl Banks From pavlovevidence at gmail.com Tue May 31 22:59:15 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 31 May 2011 19:59:15 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: Message-ID: On Sunday, May 29, 2011 7:53:59 PM UTC-7, Chris Angelico wrote: > Okay, here's a question. The Python 'float' value - is it meant to be > "a Python representation of an IEEE double-precision floating point > value", or "a Python representation of a real number"? The former. Unlike the case with integers, there is no way that I know of to represent an abstract real number on a digital computer. Python also includes several IEEE-defined operations in its library (math.isnan, math.frexp). Carl Banks From rosuav at gmail.com Tue May 31 23:05:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 13:05:43 +1000 Subject: float("nan") in set or as key In-Reply-To: References: Message-ID: On Wed, Jun 1, 2011 at 12:59 PM, Carl Banks wrote: > On Sunday, May 29, 2011 7:53:59 PM UTC-7, Chris Angelico wrote: >> Okay, here's a question. The Python 'float' value - is it meant to be >> "a Python representation of an IEEE double-precision floating point >> value", or "a Python representation of a real number"? > > The former. ?Unlike the case with integers, there is no way that I know of to represent an abstract real number on a digital computer. This seems peculiar. Normally Python seeks to define its data types in the abstract and then leave the concrete up to the various implementations - note, for instance, how Python 3 has dispensed with 'int' vs 'long' and just made a single 'int' type that can hold any integer. Does this mean that an implementation of Python on hardware that has some other type of floating point must simulate IEEE double-precision in all its nuances? I'm glad I don't often need floating point numbers. They can be so annoying! Chris Angelico From calderone.jeanpaul at gmail.com Tue May 31 23:17:50 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Tue, 31 May 2011 20:17:50 -0700 (PDT) Subject: Sanitizing filename strings across platforms References: Message-ID: <65ba3cf2-5163-473d-b8b3-b6321c47d6a5@dn9g2000vbb.googlegroups.com> On May 31, 10:17?pm, Tim Chase wrote: > Scenario: a file-name from potentially untrusted sources may have > odd filenames that need to be sanitized for the underlying OS. > On *nix, this generally just means "don't use '/' or \x00 in your > string", while on Win32, there are a host of verboten characters > and file-names. ?Then there's also checking the abspath/normpath > of the resulting name to make sure it's still in the intended folder. > > I've read through [1] and have started to glom together various > bits from that thread. ?My current course of action is something like > > ? SACRED_WIN32_FNAMES = set( > ? ? ['CON', 'PRN', 'CLOCK$', 'AUX', 'NUL'] + > ? ? ['LPT%i' % i for i in range(32)] + > ? ? ['CON%i' % i for i in range(32)] + > > ? def sanitize_filename(fname): > ? ? sane = set(string.letters + string.digits + '-_.[]{}()$') > ? ? results = ''.join(c for c in fname if c in sane) > ? ? # might have to check sans-extension > ? ? if results.upper() in SACRED_WIN32_FNAMES: > ? ? ? results = "_" + results > ? ? return results > > but if somebody already has war-hardened code they'd be willing > to share, I'd appreciate any thoughts. > There's http://pypi.python.org/pypi/filepath/0.1 (taken from twisted.python.filepath). Jean-Paul From pavlovevidence at gmail.com Tue May 31 23:30:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 31 May 2011 20:30:30 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: Message-ID: On Tuesday, May 31, 2011 8:05:43 PM UTC-7, Chris Angelico wrote: > On Wed, Jun 1, 2011 at 12:59 PM, Carl Banks > wrote: > > On Sunday, May 29, 2011 7:53:59 PM UTC-7, Chris Angelico wrote: > >> Okay, here's a question. The Python 'float' value - is it meant to be > >> "a Python representation of an IEEE double-precision floating point > >> value", or "a Python representation of a real number"? > > > > The former. ?Unlike the case with integers, there is no way that I know of to represent an abstract real number on a digital computer. > > This seems peculiar. Normally Python seeks to define its data types in > the abstract and then leave the concrete up to the various > implementations - note, for instance, how Python 3 has dispensed with > 'int' vs 'long' and just made a single 'int' type that can hold any > integer. Does this mean that an implementation of Python on hardware > that has some other type of floating point must simulate IEEE > double-precision in all its nuances? I think you misunderstood what I was saying. It's not *possible* to represent a real number abstractly in any digital computer. Python couldn't have an "abstract real number" type even it wanted to. (Math aside: Real numbers are not countable, meaning they cannot be put into one-to-one correspondence with integers. A digital computer can only represent countable things exactly, for obvious reasons; therefore, to model non-countable things like real numbers, one must use a countable approximation like floating-point.) You might be able to get away with saying float() merely represents an "abstract floating-point number with provisions for nan and inf", but pretty much everyone uses IEEE format, so what's the point? And no it doesn't mean Python has to support every nuance (and it doesn't). Carl Banks From pavlovevidence at gmail.com Tue May 31 23:30:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 31 May 2011 20:30:30 -0700 (PDT) Subject: float("nan") in set or as key In-Reply-To: Message-ID: On Tuesday, May 31, 2011 8:05:43 PM UTC-7, Chris Angelico wrote: > On Wed, Jun 1, 2011 at 12:59 PM, Carl Banks > wrote: > > On Sunday, May 29, 2011 7:53:59 PM UTC-7, Chris Angelico wrote: > >> Okay, here's a question. The Python 'float' value - is it meant to be > >> "a Python representation of an IEEE double-precision floating point > >> value", or "a Python representation of a real number"? > > > > The former. ?Unlike the case with integers, there is no way that I know of to represent an abstract real number on a digital computer. > > This seems peculiar. Normally Python seeks to define its data types in > the abstract and then leave the concrete up to the various > implementations - note, for instance, how Python 3 has dispensed with > 'int' vs 'long' and just made a single 'int' type that can hold any > integer. Does this mean that an implementation of Python on hardware > that has some other type of floating point must simulate IEEE > double-precision in all its nuances? I think you misunderstood what I was saying. It's not *possible* to represent a real number abstractly in any digital computer. Python couldn't have an "abstract real number" type even it wanted to. (Math aside: Real numbers are not countable, meaning they cannot be put into one-to-one correspondence with integers. A digital computer can only represent countable things exactly, for obvious reasons; therefore, to model non-countable things like real numbers, one must use a countable approximation like floating-point.) You might be able to get away with saying float() merely represents an "abstract floating-point number with provisions for nan and inf", but pretty much everyone uses IEEE format, so what's the point? And no it doesn't mean Python has to support every nuance (and it doesn't). Carl Banks From rustompmody at gmail.com Tue May 31 23:33:19 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 31 May 2011 20:33:19 -0700 (PDT) Subject: float("nan") in set or as key References: <678acba6-e8fd-42fc-bed0-118034897497@glegroupsg2000goo.googlegroups.com> Message-ID: <7363ec97-1aa2-4105-922a-a8ccb01d0f10@d19g2000prh.googlegroups.com> On Jun 1, 7:45?am, Carl Banks wrote: > On Sunday, May 29, 2011 8:59:49 PM UTC-7, Steven D'Aprano wrote: > > On Sun, 29 May 2011 17:55:22 -0700, Carl Banks wrote: > > > > Floating point arithmetic evolved more or less on languages like Fortran > > > where things like exceptions were unheard of, > > > I'm afraid that you are completely mistaken. > > > Fortran IV had support for floating point traps, which are "things like > > exceptions". That's as far back as 1966. I'd be shocked if earlier > > Fortrans didn't also have support for traps. > > >http://www.bitsavers.org/pdf/ibm/7040/C28-6806-1_7040ftnMathSubrs.pdf > > Fine, it wasn't "unheard of". ?I'm pretty sure the existence of a few high end compiler/hardware combinations that supported traps doesn't invalidate my basic point. ?NaN was needed because few systems had a separate path to deal with exceptional situations like producing or operating on something that isn't a number. ?When they did exist few programmers used them. ?If floating-point were standardized today it might not even have NaN (and definitely wouldn't support the ridiculous NaN != NaN), because all modern systems can be expected to support exceptions, and modern programmers can be expected to use them. > > > The IEEE standard specifies that you should be able to control whether a > > calculation traps or returns a NAN. That's how Decimal does it, that's > > how Apple's (sadly long abandoned) SANE did it, and floats should do the > > same thing. > > If your aim is to support every last clause of IEEE for better or worse, then yes that's what Python should do. ?If your aim is to make Python the best language it can be, then Python should reject IEEE's obsolete notions, and throw exceptions when operating on NaN. > > Carl Banks Why can python not have an fpu object (class?) where one can go and turn on/off the button that makes nan signalling? In short, cant we have the cake and eat it too? From roy at panix.com Tue May 31 23:43:09 2011 From: roy at panix.com (Roy Smith) Date: Tue, 31 May 2011 23:43:09 -0400 Subject: float("nan") in set or as key References: Message-ID: In article Carl Banks wrote: > pretty much everyone uses IEEE format Is there *any* hardware in use today which supports floating point using a format other than IEEE? From gagsl-py2 at yahoo.com.ar Tue May 31 23:54:08 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 01 Jun 2011 00:54:08 -0300 Subject: Alternatives to PythonPath References: Message-ID: En Sun, 29 May 2011 18:49:28 -0300, ray escribi?: > I am using Win7 on a tightly locked down desktop. > > Is there an alternative to using PythonPath? > > What are the trade-offs? Usually there is no need to define the PYTHONPATH variable; I never use it. There is a per-user site-packages directory (2.6 and up), on Windows it is located at %APPDATA%\Python\PythonXX\site-packages. Every user gets its own %APPDATA% directory, with read and write permissions. -- Gabriel Genellina From rosuav at gmail.com Tue May 31 23:57:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jun 2011 13:57:57 +1000 Subject: float("nan") in set or as key In-Reply-To: References: Message-ID: On Wed, Jun 1, 2011 at 1:30 PM, Carl Banks wrote: > I think you misunderstood what I was saying. > > It's not *possible* to represent a real number abstractly in any digital computer. ?Python couldn't have an "abstract real number" type even it wanted to. True, but why should the "non-integer number" type be floating point rather than (say) rational? Actually, IEEE floating point could mostly be implemented in a two-int rationals system (where the 'int' is arbitrary precision, so it'd be Python 2's 'long' rather than its 'int'); in a sense, the mantissa is the numerator, and the scale defines the denominator (which will always be a power of 2). Yes, there are very good reasons for going with the current system. But are those reasons part of the details of implementation, or are they part of the definition of the data type? > (Math aside: Real numbers are not countable, meaning they cannot be put into one-to-one correspondence with integers. ?A digital computer can only represent countable things exactly, for obvious reasons; therefore, to model non-countable things like real numbers, one must use a countable approximation like floating-point.) Right. Obviously a true 'real number' representation can't be done. But there are multiple plausible approximations thereof (the best being rationals). Not asking for Python to be changed, just wondering why it's defined by what looks like an implementation detail. It's like defining that a 'character' is an 8-bit number using the ASCII system, which then becomes problematic with Unicode. (Ohai, C, didn't notice you standing there.) Chris Angelico