From angrybaldguy at gmail.com Sun Apr 1 00:26:00 2012 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Sun, 1 Apr 2012 00:26:00 -0400 Subject: getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit References: Message-ID: <2012040100260095982-angrybaldguy@gmailcom> On 2012-03-31 22:58:45 +0000, John Nagle said: > Some versions of CentOS 6 seem to have a potential > getaddrinfo exploit. See > > To test, try this from a command line: > > ping example > > If it fails, good. If it returns pings from "example.com", bad. > The getaddrinfo code is adding ".com" to the domain. There is insufficient information in your diagnosis to make that conclusion. For example: what network configuration services (DHCP clients and whatnot, along with various desktop-mode configuration tools and services) are running? What kernel and libc versions are you running? What are the contents of /etc/nsswitch.conf? Of /etc/resolv.conf (particularly, the 'search' entries)? What do /etc/hosts, LDAP, NIS+, or other hostname services say about the names you're resolving? Does a freestanding C program that directly calls getaddrinfo and that runs in a known-good loader environment exhibit the same surprises? Name resolution is not so simple that you can conclude "getaddrinfo is misbehaving" from the behaviour of ping, or of your Python sample, alone. In any case, this seems more appropriate for a Linux or a CentOS newsgroup/mailing list than a Python one. Please do not reply to this post in comp.lang.python. -o From nagle at animats.com Sun Apr 1 00:31:24 2012 From: nagle at animats.com (John Nagle) Date: Sat, 31 Mar 2012 21:31:24 -0700 Subject: getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit In-Reply-To: <2012040100260095982-angrybaldguy@gmailcom> References: <2012040100260095982-angrybaldguy@gmailcom> Message-ID: On 3/31/2012 9:26 PM, Owen Jacobson wrote: > On 2012-03-31 22:58:45 +0000, John Nagle said: > >> Some versions of CentOS 6 seem to have a potential >> getaddrinfo exploit. See >> >> To test, try this from a command line: >> >> ping example >> >> If it fails, good. If it returns pings from "example.com", bad. >> The getaddrinfo code is adding ".com" to the domain. > > There is insufficient information in your diagnosis to make that > conclusion. For example: what network configuration services (DHCP > clients and whatnot, along with various desktop-mode configuration tools > and services) are running? What kernel and libc versions are you > running? What are the contents of /etc/nsswitch.conf? Of > /etc/resolv.conf (particularly, the 'search' entries)? What do > /etc/hosts, LDAP, NIS+, or other hostname services say about the names > you're resolving? Does a freestanding C program that directly calls > getaddrinfo and that runs in a known-good loader environment exhibit the > same surprises? Name resolution is not so simple that you can conclude > "getaddrinfo is misbehaving" from the behaviour of ping, or of your > Python sample, alone. > > In any case, this seems more appropriate for a Linux or a CentOS > newsgroup/mailing list than a Python one. Please do not reply to this > post in comp.lang.python. > > -o > I expected that some noob would have a reply like that. A more detailed discussion appears here: http://serverfault.com/questions/341383/possible-nxdomain-hijacking John Nagle From madhumitha27122002 at gmail.com Sun Apr 1 00:36:27 2012 From: madhumitha27122002 at gmail.com (manju devi) Date: Sat, 31 Mar 2012 21:36:27 -0700 (PDT) Subject: The python computer language Message-ID: Hi everyone,I have some python programs http://setmakkers.info/ From timr at probo.com Sun Apr 1 01:54:14 2012 From: timr at probo.com (Tim Roberts) Date: Sat, 31 Mar 2012 22:54:14 -0700 Subject: Will MySQL ever be supported for Python 3.x? References: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> Message-ID: John Nagle wrote: >On 3/30/2012 2:32 PM, Irmen de Jong wrote: >> Try Oursql instead http://packages.python.org/oursql/ >> "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" > > Not even close to being compatible with existing code. Every SQL >statement has to be rewritten, with the parameters expressed >differently. It's a good approach, but very incompatible. Those changes can be automated, given an adequate editor. "Oursql" is a far better product than the primitive MySQLdb wrapper. It is worth the trouble. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From as at sci.fi Sun Apr 1 04:44:35 2012 From: as at sci.fi (Anssi Saari) Date: Sun, 01 Apr 2012 11:44:35 +0300 Subject: Threads on google groups not on gmane? References: Message-ID: Mark Lawrence writes: > I went onto google groups to do a search and saw three threads (there > may be more) that I've never seen on gmane, which I read via > thunderbird on windows. The titles are "Is programming art or > science", "breezypythongui: A New Toolkit for Easy GUIs in Python" and > "weird behaviour: pygame plays in shell but not in script". > > Is anyone else seeing the same thing? I've noticed a lot of messed up threads but that's apparently considered normal here. But I also see broken threads where only some messages are visible on, so it's not a huge stretch that some threads might be completely invisible to me. I read through a "normal" NNTP server. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sun Apr 1 06:27:37 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sun, 01 Apr 2012 12:27:37 +0200 Subject: getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit In-Reply-To: References: <2012040100260095982-angrybaldguy@gmailcom> Message-ID: Am 01.04.2012 06:31 schrieb John Nagle: >> In any case, this seems more appropriate for a Linux or a CentOS >> newsgroup/mailing list than a Python one. Please do not reply to this >> post in comp.lang.python. >> >> -o >> > I expected that some noob would have a reply like that. You are unable to provide appropriate information, fail to notice that the problem has nothing to do with Python AND call others a noob? Shame on you. From xorninja at gmail.com Sun Apr 1 10:34:36 2012 From: xorninja at gmail.com (Itzik Kotler) Date: Sun, 1 Apr 2012 17:34:36 +0300 Subject: Pythonect 0.1.0 Release Message-ID: Hi All, I'm pleased to announce the first beta release of Pythonect interpreter. Pythonect is a new, experimental, general-purpose dataflow programming language based on Python. It aims to combine the intuitive feel of shell scripting (and all of its perks like implicit parallelism) with the flexibility and agility of Python. Pythonect interpreter (and reference implementation) is written in Python, and is available under the BSD license. Here's a quick tour of Pythonect: The canonical "Hello, world" example program in Pythonect: >>> "Hello World" -> print : Hello World Hello World >>> '->' and '|' are both Pythonect operators. The pipe operator (i.e. '|') passes one item at a item, while the other operator passes all items at once. Python statements and other None-returning function are acting as a pass-through: >>> "Hello World" -> print -> print : Hello World : Hello World Hello World >>> >>> 1 -> import math -> math.log 0.0 >>> Parallelization in Pythonect: >>> "Hello World" -> [ print , print ] : Hello World : Hello World ['Hello World', 'Hello World'] >>> range(0,3) -> import math -> math.sqrt [0.0, 1.0, 1.4142135623730951] >>> In the future, I am planning on adding support for multi-processing, and even distributed computing. The '_' identifier allow access to current item: >>> "Hello World" -> [ print , print ] -> _ + " and Python" : Hello World : Hello World ['Hello World and Python', 'Hello World and Python'] >>> >>> [ 1 , 2 ] -> _**_ [1, 4] >>> True/False return values as filters: >>> "Hello World" -> _ == "Hello World" -> print : Hello World >>> >>> "Hello World" -> _ == "Hello World1" -> print False >>> >>> range(1,10) -> _ % 2 == 0 [2, 4, 6, 8] >>> Last but not least, I have also added extra syntax for making remote procedure call easy: >> 1 -> inc at xmlrpc://localhost:8000 -> print : 2 2 >>> Download Pythonect v0.1.0 from: http://github.com/downloads/ikotler/pythonect/Pythonect-0.1.0.tar.gz More information can be found at: http://www.pythonect.org I will appreciate any input / feedback that you can give me. Also, for those interested in working on the project, I'm actively interested in welcoming and supporting both new developers and new users. Feel free to contact me. Regards, Itzik Kotler | http://www.ikotler.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From torriem at gmail.com Sun Apr 1 12:26:38 2012 From: torriem at gmail.com (Michael Torrie) Date: Sun, 01 Apr 2012 10:26:38 -0600 Subject: [OT] getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit In-Reply-To: References: Message-ID: <4F7881BE.3030903@gmail.com> On 03/31/2012 04:58 PM, John Nagle wrote: > If you can make this happen, report back the CentOS version and > the library version, please. CentOS release 6.2 (Final) glibc-2.12-1.47.el6_2.9.x86_64 example does not ping example.com does not resolve to example.com.com Removed all "search" and "domain" entries from /etc/resolve.conf From goldtech at worldpost.com Sun Apr 1 13:32:15 2012 From: goldtech at worldpost.com (goldtech) Date: Sun, 1 Apr 2012 10:32:15 -0700 (PDT) Subject: Python Script Works Locally But Not Remotely with SSH References: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> Message-ID: Bump(?) From jdec at jedrzejdec.eu Sun Apr 1 15:32:16 2012 From: jdec at jedrzejdec.eu (Jedrzej Krzysztof Dec) Date: Sun, 1 Apr 2012 12:32:16 -0700 (PDT) Subject: Python Script Works Locally But Not Remotely with SSH In-Reply-To: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> References: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> Message-ID: <12051938.18.1333308736916.JavaMail.geo-discussion-forums@vbtb5> On Wednesday, March 28, 2012 2:51:37 AM UTC+2, goldtech wrote: > Hi, > > I have a WinXP PC running an SSH server and I have a Linux PC with an > SSH client and logged into the XP seemingly OK. It's all on my > personal LAN, the connection seems OK. > > I have a py file on the XP that I run via SSH from the Linux, it's: > > import webbrowser > webbrowser.open('www.google.com') > > This runs OK started on the local XP PC, the browser Firefox opens and > goes to the site, or it opens a tab to the site. But executing that > same file via SSH does not open Firefox...doing it via SSH starts > Firefox ( I see it begin in the process manager and I see web > activity) but Firefox does not open it's window. > > Why the does the window not open when the script is started remotely? > > Thanks. Do You have a GUI over SSH? Something like ssh -X in Linux systems, or do You just have a terminal window? If You just have a terminal, You wont be able to run GUI apps. Rgrds From wolftracks at invalid.com Sun Apr 1 16:11:56 2012 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 01 Apr 2012 13:11:56 -0700 Subject: Installing Python 2.5.2 on Win 7 Message-ID: I would like to install 2.5.2 on Win 7 for several reasons. I'm using my former XP laptop, which I recently upgraded to Win7. In the XP form, I had at one time installed 2.5.2, PIL, numpy, matplotlib, etc. on it to drive a camera via a Python app. The camera is still around, and I use it on my PC XP desktop with this software, for which the python app will never be updated. However, I acquired a camera like the one I use and we set it up at a friend's house on his XP laptop. We installed this software on it, but for some reason, probably because of the camera interface via ethernet, we can get the app up, but not the camera. To solve this problem I thought I would install the software on my laptop Win7 PC. When I tried PIL.1.1.6 I got several unexpected messages that seem to indicate things were not going well. I have stopped to find out if it is really possible to install this suite of software on Win7. Is it possible? If not, will uninstalling Python also remove PIL? From nagle at animats.com Sun Apr 1 16:41:54 2012 From: nagle at animats.com (John Nagle) Date: Sun, 01 Apr 2012 13:41:54 -0700 Subject: [OT] getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit In-Reply-To: References: Message-ID: On 4/1/2012 9:26 AM, Michael Torrie wrote: > On 03/31/2012 04:58 PM, John Nagle wrote: >> If you can make this happen, report back the CentOS version and >> the library version, please. > > CentOS release 6.2 (Final) > glibc-2.12-1.47.el6_2.9.x86_64 > > example does not ping > example.com does not resolve to example.com.com > > Removed all "search" and "domain" entries from /etc/resolve.conf It's a design bug in glibc. I just submitted a bug report. http://sourceware.org/bugzilla/show_bug.cgi?id=13935 It only appears if you have a machine with a two-component domain name ending in ".com" as the actual machine name. Most hosting services generate some long arbitrary name as the primary name, but I happen to have a server set up as "companyname.com". The default rule for looking up domains in glibc is that the "domain" is everything after the FIRST ".". Failed lookups are retried with that "domain" appended. The idea, back in the 1980s, was that if you're on "foo.bigcompany.com", and look up "bar", it's looked up as "bar.bigcompany.com". This idea backfires when the actual hostname only has two components, and the search just appends ".com". There is a "com.com" domain, and this gets them traffic. They exploit this to send you (where else) to an ad-heavy page. Try "python.com.com", for example,and you'll get an ad for a Java database. The workaround in Python is to add the AI_CANONNAME flag to getaddrinfo calls, then check that the returned domain name matches the one put in. Good case: >>> s = "python.org" >>> socket.getaddrinfo(s, 80, 0,0, 0, socket.AI_CANONNAME) [(2, 1, 6, 'python.org', ('82.94.164.162', 80)), (2, 2, 17, '', ('82.94.164.162', 80)), (2, 3, 0, '', ('82.94.164.162', 80)), (10, 1, 6, '', ('2001:888:2000:d::a2', 80, 0, 0)), (10, 2, 17, '', ('2001:888:2000:d::a2', 80, 0, 0)), (10, 3, 0, '', ('2001:888:2000:d::a2', 80, 0, 0))] Bad case: >>> s = "noexample.com" >>> socket.getaddrinfo(s, 80, 0,0, 0, socket.AI_CANONNAME) [(2, 1, 6, 'phx1-ss-2-lb.cnet.com', ('64.30.224.112', 80)), (2, 2, 17, '', ('64.30.224.112', 80)), (2, 3, 0, '', ('64.30.224.112', 80))] Note that what went in isn't what came back. getaddrinfo has been pwned. Again, you only get this if you're on a machine whose primary host name is "something.com", with exactly two components ending in ".com". John Nagle From irmen.NOSPAM at xs4all.nl Sun Apr 1 16:57:10 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 01 Apr 2012 22:57:10 +0200 Subject: Installing Python 2.5.2 on Win 7 In-Reply-To: References: Message-ID: <4f78c129$0$6851$e4fe514c@news2.news.xs4all.nl> On 1-4-2012 22:11, W. eWatson wrote: > To solve this problem I thought I would install the software on my laptop Win7 PC. When > I tried PIL.1.1.6 I got several unexpected messages that seem to indicate things were > not going well. I have stopped to find out if it is really possible to install this > suite of software on Win7. Is it possible? If not, will uninstalling Python also remove > PIL? I'm using PIL 1.1.7 (the latest version available from effbot's website) on Windows 7. Admittedly, with Python 2.7.2, but there's an installer for Python 2.5 as well. I assume it should work just fine. What errors were you seeing? And no, uninstall Python won't remove PIL - it has its own uninstaller. Irmen From wolftracks at invalid.com Sun Apr 1 22:46:17 2012 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 01 Apr 2012 19:46:17 -0700 Subject: Installing Python 2.5.2 on Win 7 In-Reply-To: <4f78c129$0$6851$e4fe514c@news2.news.xs4all.nl> References: <4f78c129$0$6851$e4fe514c@news2.news.xs4all.nl> Message-ID: On 4/1/2012 1:57 PM, Irmen de Jong wrote: > On 1-4-2012 22:11, W. eWatson wrote: >> To solve this problem I thought I would install the software on my laptop Win7 PC. When >> I tried PIL.1.1.6 I got several unexpected messages that seem to indicate things were >> not going well. I have stopped to find out if it is really possible to install this >> suite of software on Win7. Is it possible? If not, will uninstalling Python also remove >> PIL? > > I'm using PIL 1.1.7 (the latest version available from effbot's website) on Windows 7. > Admittedly, with Python 2.7.2, but there's an installer for Python 2.5 as well. > I assume it should work just fine. > > What errors were you seeing? > > And no, uninstall Python won't remove PIL - it has its own uninstaller. > > > Irmen > > I'm going to uninstall Python on my XP laptop, and get my friend's laptop tomorrow. I'll work on his problem here. I have a desktop xp that works for the app I'm concerned about. From wuwei23 at gmail.com Sun Apr 1 23:18:40 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Apr 2012 20:18:40 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> On Mar 30, 3:37?pm, Nathan Rice wrote: > We live in a world where the tools that are used are based on > tradition (read that as backwards compatibility if it makes you feel > better) and as a mechanism for deriving personal identity. ?The world > is backwards and retarded in many, many ways, this problem is > interesting to me because it actually cuts across a much larger tract > than is immediately obvious. Do you produce commercial code in a team? Because going by your absolutist bullshit here, it certainly doesn't sound like it. When I join an organisation that requires language A as all of its systems are written in it, is that 'tradition' or 'personal identity'? How is 'compatibility' - either with existing systems or existing *developers* - a "backwards and retarded" approach to complex problems? If I've chosen language A because some aspect of its syntax maps better onto my mind (or for _whatever_ reason that makes individuals prefer one language to another), and you've chosen language B: who gets to decide which is the 'superior' language, which is the 'better' mapping etc? You're arguing for a top-down centralised approach to language development that just will _never_ exist, simply because it cannot. If you don't accept that, I believe there's a fascinating fork called "Python 4000" where your ideas would be readily adopted. From bv8bv8bv8 at gmail.com Sun Apr 1 23:28:15 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sun, 1 Apr 2012 20:28:15 -0700 (PDT) Subject: Nature of Heavenly Bodies Message-ID: <179e279b-1684-4063-b630-389d848ef9c5@v2g2000vbx.googlegroups.com> THE QUR'AN AND MODERN SCIENCE Extracted from the Book The Bible, The Qur'an and Science Maurice Bucaille ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Nature of Heavenly Bodies THE SUN AND THE MOON The Sun is a shine (diya') and the Moon a light (nur). This translation would appear to be more correct than those given by others, where the two terms are inverted. In fact there is little difference in meaning since diya' belongs to a root (daw') which, according to Kazimirski's authoritative Arabic/French dictionary, means 'to be bright, to shine' (e.g. like a fire). The same author attributes to the substantive in question the meaning of 'light'. The difference between Sun and Moon will be made clearer by further quotes from the Qur'an. - Surah 25, verse 61: Blessed is the One Who placed the constellations in heaven and placed therein a lamp and a moon giving light - Surah 71, verses 15-16: Did you see how God created seven heavens one above another and made the moon a light therein and made the sun a lamp? - Surah 78, verses 12-13: We have built above you seven strong (heavens) and placed a blazing lamp The blazing lamp is quite obviously the sun. Here the Moon is defined as a body that gives light (munir) from the same root as nur (the light applied to the Moon). The Sun however is compared to a torch (siraj) or a blazing (wahhaj) lamp. A man of Muhammad's time could easily distinguish between the Sun, a blazing heavenly body well knows to the inhabitants of the desert, and the Moon, the body of the cool of the night. The comparisons found in the Qur'an on this subject are therefore quite normal. What is interesting to note here is the sober quality of the comparisons, and the absence in the text of the Qur'an of any elements of comparison that might have prevailed at the time and which in our day would appear as phantasmagoric. It is known that the Sun is a star that generates intense heat and light by its internal combustion, and that the Moon, which does not give off light itself, merely reflects the light received from the Sun, constituting an inert body (on its external layers at least). There is nothing in the text of the Qur'an that contradicts what we know today about these two celestial bodies. THE STARS As we know, the stars are heavenly bodies like the Sun. They are the scene of various physical phenomena of which the easiest to observe is their generation of light. They are heavenly bodies that produce their own light. The word 'star' appears thirteen times in the Qur'an (najm, plural nujum); it comes from a root meaning to appear, to come into sight. The word designates a visible heavenly body without saying of what kind, i.e. either generator of light or mere reflector of light received. To make it clear that the object so designated is a star, a qualifying phrase is added as in the following Surah: - Surah 86, verses 1-3: By the sky and the Night-Visitor, who will tell thee what the Night- Visitor is, the Star of piercing brightness The evening star is qualified in the Qur'an by the word thakib meaning 'that which pierces through something' (here the night shadows). The same word is moreover used to designate shooting stars (Surah 37, verse 10): the latter are the result of combustion. It is difficult to say whether these are referred to in the Qur'an with the same exact meaning that is given to the heavenly bodies in the present day. PLANETS It is difficult to say that planets are mentioned in the Qur. an with the specific meaning we give today to these heavenly bodies. The planets do have their own light. They revolve around the Sun, Earth being one of them. While one may presume that others exist elsewhere, the only ones known are those in the solar system. Five planets other than Earth were known to the ancients: Mercury, Venus, Mars, Jupiter and Saturn. Three have been discovered in recent times: Uranus, Neptune and Pluto. The Qur'an would seem to designate these by the word kaukab (plural kawakib) without stating their number. Joseph's dream (Surah 12) refers to eleven of them, but the description is, by definition, an imaginary one. A good definition of the meaning of the word kaukab in the Qur'an seems to have been given in a very famous verse. The eminently spiritual nature of its deeper meaning stands forth, and is moreover the subject of much debate among experts in exegesis. It is nevertheless of great interest to offer an account of the comparison it contains on the subject of the word that would seem to designate a 'planet'. Here is the text in question: (Surah 24, verse 35) God is the light of the heavens and the earth. The similitude of His light is as if there were a niche and within it a luminary. The luminary is in a glass. The glass is as if it were a planet glittering like a pearl Here the subject is the projection of light onto a body that reflects it (glass) and gives it the glitter of a pearl, like a planet that is lit by the sun. This is the only explanatory detail referring to this word to be found in the Qur'an. The word is quoted in other verses. In some of them It is difficult to distinguish which heavenly bodies are meant (Surah 6, verse 76; Surah 82, verses 1-2). In one verse however, when seen in the light of modern science, it would seem very much that these can only be the heavenly bodies that we know to be planets. In Surah 37, verse 6, we see the following We have indeed adorned the lowest heaven with an ornament, the planets Is it possible that the expression in the Qur'an 'lowest heaven' means the solar system? It is known that among the celestial elements nearest to us, there are no other permanent elements apart from the planets: the Sun is the only star in the system that bears its name. It is difficult to see what other heavenly bodies could be meant if not the planets. The translation given would therefore seem to be correct and the Qur'an to refer to the existence of the planets as defined in modern times. THE LOWEST HEAVEN The Qur'an mentions the lowest heaven several times along with the heavenly bodies of which it is composed. The first among these would seem to be the planets, as we have just seen. When however the Qur'an associates material notions intelligible to us, enlightened as we are today by modern science, with statements of a purely spiritual nature, their meaning becomes obscure. Thus the verse quoted above could easily be understood, except that the following verse (7) of the same Surah 37 speaks of a 'guard against every rebellious evil spirit', 'guard' again being referred to in Surah 21, verse 32 and Surah 41, verse 12, so that we are confronted by statements of quite a different kind. What meaning can one attach moreover to the 'projectiles for the stoning of demons' that according to verse 5, Surah 67 are situated in the lowest heaven? Do the 'luminaries' referred to in the same verse have something to do with the shooting stars mentioned above? All these observations seem to lie outside the subject of this study. They have been mentioned here for the sake of completeness. At the present stage however, it would seem that scientific data are unable to cast any light on a subject that goes beyond human understanding. For more information about Islam http://www.islam-guide.com http://www.islamhouse.com/s/9661 http://www.thisistruth.org http://www.quran-m.com/firas/en1 http://kaheel7.com/eng http://www.knowmuhammad.com http://www.rasoulallah.net/v2/index.aspx?lang=e http://imanway1.com/eng http://www.todayislam.com http://www.thekeytoislam.com http://www.islamland.com http://www.discoverislam.com http://www.thetruereligion.org http://www.beconvinced.com http://islamtomorrow.com http://www.quranforall.org http://www.quranexplorer.com/quran http://www.prophetmuhammed.org http://chatislamonline.org/en/ From wuwei23 at gmail.com Sun Apr 1 23:30:35 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Apr 2012 20:30:35 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> <64eb2ae9-b4ec-4acb-92bf-de4a86f0b83c@sv8g2000pbc.googlegroups.com> Message-ID: <9e42e87d-0836-4260-9031-4f071e269b08@z3g2000pbn.googlegroups.com> On Mar 31, 2:02?am, Steve Howell wrote: > Steven, how do you predict which abstractions are going to be useless? A useless abstraction is one that does nothing to simplify a problem *now*: > being so fixated on over-arching abstract > concepts that, far from those abstractions making it easier to solve the > problems they are being paid to solve, they actually make them harder An abstraction is also useless if it's so clever that it isn't readily understandable to an average developer; architecture astronauts don't tend to be big on sticking around to provide ongoing support. From wuwei23 at gmail.com Sun Apr 1 23:38:47 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Apr 2012 20:38:47 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> <9tmjf7FqldU1@mid.individual.net> Message-ID: <7ccd462e-82f6-4924-ba05-596a8a3edc62@t8g2000pbe.googlegroups.com> On Mar 31, 6:30?am, Neil Cerutti wrote: > See, for example, Inform 7, which translates a subset of English > into Inform 6 code. I never thought too deeply about why I > disliked it, assuming it was because I already knew Inform 6. I've always respected Inform 7 while being also unwilling to use it. When you're trying to make your language grammar a subset of your data grammar and then combine them interchangeably, it can be unclear about where the error lies, even if the combination is done in prescribed and restricted ways. Whereas keywords are key words: they give texture to source code, like visual braille. From showell30 at yahoo.com Mon Apr 2 00:01:47 2012 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 1 Apr 2012 21:01:47 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> <64eb2ae9-b4ec-4acb-92bf-de4a86f0b83c@sv8g2000pbc.googlegroups.com> <9e42e87d-0836-4260-9031-4f071e269b08@z3g2000pbn.googlegroups.com> Message-ID: <31432272-ea2e-4428-89ca-3c96446bf99c@vy8g2000pbc.googlegroups.com> On Apr 1, 8:30?pm, alex23 wrote: > On Mar 31, 2:02?am, Steve Howell wrote: > > > Steven, how do you predict which abstractions are going to be useless? > > A useless abstraction is one that does nothing to simplify a problem > *now*: That's the very definition of short-sighted thinking. If it doesn't do anything *now*.... > > > being so fixated on over-arching abstract > > concepts that, far from those abstractions making it easier to solve the > > problems they are being paid to solve, they actually make them harder > > An abstraction is also useless if it's so clever that it isn't readily > understandable to an average developer; architecture astronauts don't > tend to be big on sticking around to provide ongoing support. You are careless and sloppy with your quoting here. I didn't say the above; you should give proper attribution. From georg at python.org Mon Apr 2 01:43:52 2012 From: georg at python.org (Georg Brandl) Date: Mon, 02 Apr 2012 07:43:52 +0200 Subject: [RELEASED] Python 3.3.0 alpha 1 Message-ID: <4F793C98.8030504@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the second alpha release of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, Syntax for Delegating to a Subgenerator ("yield from") * PEP 393, Flexible String Representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * PEP 409, Suppressing Exception Context * PEP 3151, Reworking the OS and IO exception hierarchy * A C implementation of the "decimal" module, with up to 80x speedup for decimal-heavy applications * The new "packaging" module, building upon the "distribute" and "distutils2" projects and deprecating "distutils" * The new "lzma" module with LZMA/XZ support * PEP 3155, Qualified name for classes and functions * PEP 414, explicit Unicode literals to help with porting * The new "faulthandler" module that helps diagnosing crashes * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default. For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html (*) To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! (*) Please note that this document is usually finalized late in the release cycle and therefore may have stubs and missing entries at this point. - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAk95PJgACgkQN9GcIYhpnLCN1QCfeYWp+QbPGYhaLSxc4YKnlE/F zU8An2q5qzvjL0qaxqaYleFGoGKPzzJu =qo4v -----END PGP SIGNATURE----- From georg at python.org Mon Apr 2 01:55:41 2012 From: georg at python.org (Georg Brandl) Date: Mon, 02 Apr 2012 07:55:41 +0200 Subject: [RELEASED] Python 3.3.0 alpha 2 Message-ID: <4F793F5D.3040808@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 - -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the second alpha release of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, Syntax for Delegating to a Subgenerator ("yield from") * PEP 393, Flexible String Representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * PEP 409, Suppressing Exception Context * PEP 3151, Reworking the OS and IO exception hierarchy * A C implementation of the "decimal" module, with up to 80x speedup for decimal-heavy applications * The new "packaging" module, building upon the "distribute" and "distutils2" projects and deprecating "distutils" * The new "lzma" module with LZMA/XZ support * PEP 3155, Qualified name for classes and functions * PEP 414, explicit Unicode literals to help with porting * The new "faulthandler" module that helps diagnosing crashes * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default. For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html (*) To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! (*) Please note that this document is usually finalized late in the release cycle and therefore may have stubs and missing entries at this point. - - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) - -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAk95PJgACgkQN9GcIYhpnLCN1QCfeYWp+QbPGYhaLSxc4YKnlE/F zU8An2q5qzvjL0qaxqaYleFGoGKPzzJu =qo4v - -----END PGP SIGNATURE----- -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAk95P10ACgkQN9GcIYhpnLBo8QCePW2BuTqXSmtVl6/Yae1HWrGB UFgAn0ytSqd70vq58gj9N8xUtKC+BJ2D =3DA/ -----END PGP SIGNATURE----- From nagle at animats.com Mon Apr 2 02:42:11 2012 From: nagle at animats.com (John Nagle) Date: Sun, 01 Apr 2012 23:42:11 -0700 Subject: Will MySQL ever be supported for Python 3.x? In-Reply-To: References: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> Message-ID: On 3/31/2012 10:54 PM, Tim Roberts wrote: > John Nagle wrote: > >> On 3/30/2012 2:32 PM, Irmen de Jong wrote: >>> Try Oursql instead http://packages.python.org/oursql/ >>> "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" >> >> Not even close to being compatible with existing code. Every SQL >> statement has to be rewritten, with the parameters expressed >> differently. It's a good approach, but very incompatible. > > Those changes can be automated, given an adequate editor. "Oursql" is a > far better product than the primitive MySQLdb wrapper. It is worth the > trouble. It's an interesting approach. As it matures, and a few big sites use it. it will become worth looking at. The emphasis on server-side buffering seems strange. Are there benchmarks indicating this is worth doing? Does it keep transactions locked longer? This bug report https://answers.launchpad.net/oursql/+question/191256 indicates a performance problem. I'd expect server side buffering to slow things down. Usually, you want to drain results out of the server as fast as possible, then close out the command, releasing server resources and locks. John Nagle From bahamutzero8825 at gmail.com Mon Apr 2 02:50:02 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 02 Apr 2012 01:50:02 -0500 Subject: [RELEASED] Python 3.3.0 alpha 2 In-Reply-To: <4F793F5D.3040808@python.org> References: <4F793F5D.3040808@python.org> Message-ID: <4F794C1A.7020600@gmail.com> > To download Python 3.3.0 visit: > > http://www.python.org/download/releases/3.3.0/ The Windows links point to 3.3a1 installers, even though the links say 3.3a2. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From ulrich.eckhardt at dominolaser.com Mon Apr 2 03:12:29 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 02 Apr 2012 09:12:29 +0200 Subject: tabs/spaces In-Reply-To: References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: Am 30.03.2012 14:47, schrieb Dave Angel: > But since it doesn't do it on all messages, have you also confirmed that > it does it for a text message? My experience seems to be that only the > html messages are messed up that way. I can't find any HTML in what I posted, so HTML is not the problem. A difference could be the content type. I had in my posting: Content-Type: text/plain; charset=ISO-8859-15; format=flowed Another one titled "Pipelining in Python", where TB doesn't mess up the formatting, has: Content-Type: text/plain; charset=ISO-8859-1 Searching the web turned up [1], the gist is that "format=flowed" means that your mailer is allowed to move linebreaks and quotation signs ("> ") as it wants. Which is not what I meant. Some more search turned up [2], which tells us how to disable this. Go to the settings, advanced section and find the button that fires up the raw configuration editor. There, locate the key mailnews.send_plaintext_flowed and change the according value to false. # Checking... if this.worked: hurray("I didn't even have to close the message in writing") Uli [1] http://joeclark.org/ffaq.html [2] http://www.firstpr.com.au/web-mail/Mozilla-mail/ From lanyjie at yahoo.com Mon Apr 2 03:24:21 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 00:24:21 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: , , <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: <1333351461.27538.YahooMailNeo@web121506.mail.ne1.yahoo.com> Hi Adrian, see my comments below. >________________________________ > From: Adrian Hunt ... >It could break old code... okay you may say you should?nt allow >certain characters but if they're printable and used in a controlled >environment those characters can dramatically increase the security >of a username and password. What you said makes lots of sense to me.? if strings are interpolated *automatically*. But it won't and shouldn't. They are called "Dynamic strings". Dynamic strings can achieve formatting,? but the mechanism under the hood differ from common strings dramatically. Many here didn't realize that this is not another formatting proposal, it is a new kind of *expression*.? To have it in Python, we will need? a new kind of syntax to distinguish it from other strings, such as?raw strings? and the like. A raw string?looks like: >>> r'my\\ raw str' 'my\\\\ raw str' A dynamic string may look like this: >>> name = "Peter" #common string >>> d"Thank you, $name$!" #dynamic string! 'Thank you, Peter!' The following example would make it feel? a lot more safe (suppose a = raw_input()): >>> a =?'d"Are you $name$?"' >>> print(a) 'd"Are you $name$?"' >>> eval('d"Are you $name$?"') 'Are you Peter?' >>> d"It contains $len(_.split())$ words!" 'It contains 3 words!' An interesting question might be: what if a dynamic string is referring to another dynamic string, which in turn refers back to the former? The answer is: no variable can hold a dynamic string itself, only its result, which can only be a common string. However, a infinite recursion may? occur if the eval function is used inside: >>> a = 'd"$eval(a)$"' >>> eval(a) This is just to show a dynamic string is really an expression in disguise. Like evaluating any expression containing function calls, there is risk of getting into infinite recursion. Cheers,? Yingjie From lanyjie at yahoo.com Mon Apr 2 03:39:42 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 00:39:42 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: <1333352382.43956.YahooMailNeo@web121501.mail.ne1.yahoo.com> > You can already do essentially that without adding a special-case string? > formatting method to the general methods we already have. > >>>> balls = 5 >>>> people = 3 >>>> 'The {people} people have {balls} > balls.'.format(**locals()) > 'The 3 people have 5 balls.' Clearly dynamic strings are much more powerful, allowing arbitrary expressions inside. It is also more terse and readable, since we need no dictionary. I would probably rather liken dynamic expressions as a little brother of computable documents?in? Mathematica. It is a new kind of expression, rather than formatting -- though it has formatting connections.? Dynamic strings are mainly useful at time of writing readable code before compilation.? The compiler can choose to convert it into a string formatting expression, of course. To efficiently format?strings at runtime,? the best choice (especially for safty reasons) is string formatting,? not evaluating a dynamic string. On the implementation, I would suppose new? syntax is needed (though very small). Yingjie From tjreedy at udel.edu Mon Apr 2 03:42:02 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 Apr 2012 03:42:02 -0400 Subject: tabs/spaces In-Reply-To: References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: On 4/2/2012 3:12 AM, Ulrich Eckhardt wrote: > I can't find any HTML in what I posted, so HTML is not the problem. A > difference could be the content type. I had in my posting: > > Content-Type: text/plain; charset=ISO-8859-15; format=flowed > > Another one titled "Pipelining in Python", where TB doesn't mess up the > formatting, has: > > Content-Type: text/plain; charset=ISO-8859-1 > > Searching the web turned up [1], the gist is that "format=flowed" means > that your mailer is allowed to move linebreaks and quotation signs ("> > ") as it wants. Which is not what I meant. Some more search turned up > [2], which tells us how to disable this. Go to the settings, advanced > section and find the button that fires up the raw configuration editor. > There, locate the key mailnews.send_plaintext_flowed and change the > according value to false. > > # Checking... > if this.worked: > hurray("I didn't even have to close the message in writing") Looks great! I never knew about that setting. -- Terry Jan Reedy From lanyjie at yahoo.com Mon Apr 2 03:47:09 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 00:47:09 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: <1333352829.82417.YahooMailNeo@web121502.mail.ne1.yahoo.com> > Python already has *3* different built-in string > formatting/interpolation systems: ... > I would surmise that your key "implicitly grab variable values from > the enclosing scope" feature has previously been rejected for being > too magical. It grabs because it is an expression in disguise (not a literal).? If we could make?that clear in the way we write it, seems the? magic level should reduce.to a tolerable (or even likable) level. Cheers, Yingjie From rosuav at gmail.com Mon Apr 2 03:52:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Apr 2012 17:52:33 +1000 Subject: string interpolation for python In-Reply-To: <1333351461.27538.YahooMailNeo@web121506.mail.ne1.yahoo.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <1333351461.27538.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: On Mon, Apr 2, 2012 at 5:24 PM, Yingjie Lan wrote: > They are called "Dynamic strings". > Dynamic strings can achieve formatting, > but the mechanism under the hood differ > from common strings dramatically. > > Many here didn't realize that this is not > another formatting proposal, it is a new > kind of *expression*. > > To have it in Python, we will need > a new kind of syntax to distinguish it > from other strings, such as?raw strings > and the like. A raw string?looks like: > >>>> r'my\\ raw str' > 'my\\\\ raw str' > > A dynamic string may look like this: > >>>> name = "Peter" #common string >>>> d"Thank you, $name$!" #dynamic string! > 'Thank you, Peter!' >From the Zen of Python: Special cases aren't special enough to break the rules. It's fairly cheap to propose a new function. If people don't like it, they can ignore it... it can get stuck into a module somewhere and be easily ignored. If people DO like it, they can back-port it to older versions by simply copying and pasting the Python code (or "equivalent Python code", if the main version's written in C). New syntax like this has to be implemented in the parser, is (practically) impossible to back-port with pure Python, and has far higher potential to break existing code. The onus is on you to demonstrate that this syntax is worth this hassle. I'm -1 on the idea, mainly because there are already two perfectly good string interpolation syntaxes that don't require a new kind of string. I'm also against the notion of "interpolated strings" vs "non-interpolated strings" in general, having worked with them in PHP and not found any real benefit. But if you want it, you could fairly easily do something with an explicit interpolation parsing function: >>> d"Thank you, $name$!" #dynamic string! 'Thank you, Peter!' becomes: >>> d("Thank you, $name$!") #dynamic string! 'Thank you, Peter!' To make the magic of evaluation scope work, though, you'd need to fiddle around with tracebacks. It'd be far simpler and clearer to pass locals() and/or globals() to your function, if indeed you want that. Chris Angelico From jpiitula at ling.helsinki.fi Mon Apr 2 04:01:18 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 02 Apr 2012 11:01:18 +0300 Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: Yingjie Lan writes: > Clearly dynamic strings are much more powerful, > allowing arbitrary expressions inside. It is also > more terse and readable, since we need no dictionary. ... > On the implementation, I would suppose new? > syntax is needed (though very small). I don't think you need any new syntax to implement this. You can use a syntax like Dynamite("Hello, $world$") now, similar to fraction.Fraction: >>> Fraction(3,4) + 1 Fraction(7, 4) No special syntax there, yet it can be done. From steve+comp.lang.python at pearwood.info Mon Apr 2 04:25:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2012 08:25:20 GMT Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <1333351461.27538.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: <4f796270$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Apr 2012 17:52:33 +1000, Chris Angelico wrote: > I'm -1 on the idea, mainly because there are already two perfectly good > string interpolation syntaxes that don't require a new kind of string. Three. % formatting {} formatting $ formatting using string.Template -- Steven From steve+comp.lang.python at pearwood.info Mon Apr 2 04:26:24 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2012 08:26:24 GMT Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Apr 2012 00:39:42 -0700, Yingjie Lan wrote: >> You can already do essentially that without adding a special-case >> string > >> formatting method to the general methods we already have. >> >>>>> balls = 5 >>>>> people = 3 >>>>> 'The {people} people have {balls} >> balls.'.format(**locals()) >> 'The 3 people have 5 balls.' > > > Clearly dynamic strings are much more powerful, allowing arbitrary > expressions inside. And so it may be a security risk, if user-input somehow ends up treated as a dynamic string. We already have three ways to evaluate arbitrary expressions: * Python code * eval * exec Why do we need yet another one? > It is also more terse and readable, since we need no > dictionary. I think you mean terse and unreadable, since we need no dictionary. That means that variables will be evaluated by magic from... where? Globals? Local scope? Non-local scope? All of the above? We already have one way of evaluating implicit variables using implicit rules, namely regular Python code. Why do we need a second one? > I would probably rather liken dynamic expressions as a little brother of > computable documents?in Mathematica. It is a new kind of expression, > rather than formatting -- though it has formatting connections. Why do we need a new kind of expression? > Dynamic strings are mainly useful at time of writing readable code > before compilation. What does that mean? > The compiler can choose to convert it into a string > formatting expression, of course. To efficiently format?strings at > runtime, the best choice (especially > for safty reasons) is string formatting, not evaluating a dynamic > string. So you're suggesting that we should have dynamic strings, but not actually use dynamic strings. The compiler should just convert them to regular string formatting. Why not cut out the middle-man and just use regular string formatting? -- Steven From rosuav at gmail.com Mon Apr 2 04:47:19 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Apr 2012 18:47:19 +1000 Subject: string interpolation for python In-Reply-To: <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 2, 2012 at 6:26 PM, Steven D'Aprano wrote: > On Mon, 02 Apr 2012 00:39:42 -0700, Yingjie Lan wrote: >> The compiler can choose to convert it into a string >> formatting expression, of course. To efficiently format?strings at >> runtime, the best choice (especially >> for safty reasons) is string formatting, not evaluating a dynamic >> string. > > So you're suggesting that we should have dynamic strings, but not > actually use dynamic strings. The compiler should just convert them to > regular string formatting. > > Why not cut out the middle-man and just use regular string formatting? Actually, this sounds like a job for a precompiler/preprocessor. Do whatever translations you want on your code, then turn it into a .py file for execution. But hardly necessary, as there are already two - err, three, I stand corrected - perfectly good ways to do it. ChrisA From robert.kern at gmail.com Mon Apr 2 04:50:47 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 02 Apr 2012 09:50:47 +0100 Subject: Threads on google groups not on gmane? In-Reply-To: References: Message-ID: On 3/31/12 1:47 AM, Mark Lawrence wrote: > I went onto google groups to do a search and saw three threads (there may be > more) that I've never seen on gmane, which I read via thunderbird on windows. > The titles are "Is programming art or science", "breezypythongui: A New Toolkit > for Easy GUIs in Python" and "weird behaviour: pygame plays in shell but not in > script". > > Is anyone else seeing the same thing? I also don't see these on GMane. It's possible that they are getting caught in one of GMane's several levels of spam filtering. http://gmane.org/spam.php -- 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 lanyjie at yahoo.com Mon Apr 2 05:11:46 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 02:11:46 -0700 (PDT) Subject: string interpolation for python In-Reply-To: <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> ----- Original Message ----- > From: Steven D'Aprano > To: python-list at python.org > Cc: > Sent: Monday, April 2, 2012 4:26 PM > Subject: Re: string interpolation for python > > On Mon, 02 Apr 2012 00:39:42 -0700, Yingjie Lan wrote: > >>> You can already do essentially that without adding a special-case >>> string >> >>> formatting method to the general methods we already have. >>> >>>>>> ? balls = 5 >>>>>> ? people = 3 >>>>>> ? 'The {people} people have {balls} >>> balls.'.format(**locals()) >>> 'The 3 people have 5 balls.' >> >> >> Clearly dynamic strings are much more powerful, allowing arbitrary >> expressions inside. > > And so it may be a security risk, if user-input somehow ends up treated > as a dynamic string. > > We already have three ways to evaluate arbitrary expressions: > > * Python code > * eval > * exec > > Why do we need yet another one? > > >> It is also more terse and readable, since we need no >> dictionary. > > I think you mean terse and unreadable, since we need no dictionary. That > means that variables will be evaluated by magic from... where? Globals? > Local scope? Non-local scope? All of the above? > > We already have one way of evaluating implicit variables using implicit > rules, namely regular Python code. Why do we need a second one? > > >> I would probably rather liken dynamic expressions as a little brother of >> computable documents?in Mathematica. It is a new kind of expression, >> rather than formatting -- though it has formatting connections. > > Why do we need a new kind of expression? > > >> Dynamic strings are mainly useful at time of writing readable code >> before compilation. > > What does that mean? > > >> The compiler can choose to convert it into a string >> formatting expression, of course. To efficiently format?strings at >> runtime, the best choice (especially >> for safty reasons) is string formatting, not evaluating a dynamic >> string. > > So you're suggesting that we should have dynamic strings, but not > actually use dynamic strings. The compiler should just convert them to > regular string formatting. > > Why not cut out the middle-man and just use regular string formatting? > I believe non of the other three alternatives are as terse and readable. We've got template based, formatting with dict, formatting with tuple. They all require the coder extra effort: Both template based and dict-based formatting require writing the identifier three times: >>> name = 'Peter' >>> "Are you %(name)s"%{'name':name} ? If dynamic string is used: >>> "Are you $name$?" Template: >>> Template("Are you $name?").substitute(name=name) It is three to one in compactness, what a magic 3! Of course, the old C style way: >>> "Are you %s?"%name Almost as terse, but not as readable, especially when there are many?parts to substitute -- the coder and reader need to be careful? to?make sure the sequence is correct. Why the Python community is so hostile to new things now?? Python has merits, but it is far from being perfect. Cheers, Yingjie From lanyjie at yahoo.com Mon Apr 2 05:17:21 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 02:17:21 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1333358241.89363.YahooMailNeo@web121502.mail.ne1.yahoo.com> > Actually, this sounds like a job for a precompiler/preprocessor. Do > whatever translations you want on your code, then turn it into a .py > file for execution. But hardly necessary, as there are already two - > err, three, I stand corrected - perfectly good ways to do it. Agree and disagree.? The other ways are not perfectly good. They stinks in Python.? This new way is the most natural way. Effortless, natural. That's my Python. Cheers, Yingjie From rosuav at gmail.com Mon Apr 2 05:56:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Apr 2012 19:56:27 +1000 Subject: string interpolation for python In-Reply-To: <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> Message-ID: On Mon, Apr 2, 2012 at 7:11 PM, Yingjie Lan wrote: > I believe non of the other three alternatives are as terse and readable. > We've got template based, formatting with dict, formatting with tuple. > They all require the coder extra effort: > > Both template based and dict-based formatting require writing the > identifier three times: > >>>> name = 'Peter' >>>> "Are you %(name)s"%{'name':name} > > If dynamic string is used: >>>> "Are you $name$?" Yes, it's more compact. But it's also more magic. However, there's an alternative that's almost as compact. The only requirement is that you use a two-character token instead of your dollar sign: a double-quote and a plus. >>> "Are you "+name+"?" That allows arbitrary expressions and everything. > Of course, the old C style way: > >>>> "Are you %s?"%name > > Almost as terse, but not as readable, especially > when there are many?parts to substitute -- > the coder and reader need to be careful > to?make sure the sequence is correct. I quite like this notation, personally. It's convenient, and is supported (with variants) in quite a few C-derived languages (and, in spite of the massive syntactic differences, Python does have C heritage). > Why the Python community is so > hostile to new things now? > Python has merits, > but it is far from being perfect. Hey now, no need to get defensive :) Thing is, it's up to you to demonstrate that your proposal justifies itself. You're proposing to create a massive backward-compatibility issue, so you need to prove that your new way of formatting strings is sufficiently awesome to be able to say "Well, you need Python 3.4+ to use this". ChrisA From no.email at nospam.invalid Mon Apr 2 06:16:26 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 02 Apr 2012 03:16:26 -0700 Subject: Threads on google groups not on gmane? References: Message-ID: <7xaa2u30cl.fsf@ruckus.brouhaha.com> Robert Kern writes: > I also don't see these on GMane. It's possible that they are getting > caught in one of GMane's several levels of spam filtering. I'm seeing some weird issues where google groups posts on another newsgroup aren't making it to the non-google nntp server that I use. The paranoid in me wonders if google is doing that on purpose, but it's a pretty recent development, and other explanations are possible. From duncan.booth at invalid.invalid Mon Apr 2 06:19:54 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 2 Apr 2012 10:19:54 GMT Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Yingjie Lan wrote: > Both template based and dict-based formatting require writing the > identifier three times: >>>> name = 'Peter' >>>> "Are you %(name)s"%{'name':name} > ? > If dynamic string is used: >>>> "Are you $name$?" > Template: >>>> Template("Are you $name?").substitute(name=name) > It is three to one in compactness, what a magic 3! You can avoid the duplication fairly easily: >>> name='Peter' >>> 'Are you {name}?'.format(**vars()) 'Are you Peter?' though if you're doing that it would be better to limit the scope to a specific namespace. -- Duncan Booth http://kupuguy.blogspot.com From clp2 at rebertia.com Mon Apr 2 06:23:15 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Apr 2012 03:23:15 -0700 Subject: string interpolation for python In-Reply-To: <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> Message-ID: On Mon, Apr 2, 2012 at 2:11 AM, Yingjie Lan wrote: > I believe non of the other three alternatives are as terse and readable. > We've got template based, formatting with dict, formatting with tuple. > They all require the coder extra effort: > > Both template based and dict-based formatting require writing the > identifier three times: False. Only once is required, though the technique to achieve it is kinda hacky. >>>> name = 'Peter' >>>> "Are you %(name)s"%{'name':name} "Are you %(name)s" % locals() # or vars() > If dynamic string is used: >>>> "Are you $name$?" > > Template: >>>> Template("Are you $name?").substitute(name=name) Template("Are you $name?").substitute(locals()) # or vars() > It is three to one in compactness, what a magic 3! > Why the Python community is so > hostile to new things now? It's more conservative than hostile. Here's some insight: http://www.boredomandlaziness.org/2011/02/status-quo-wins-stalemate.html Personally, in isolation, the only part of your proposal I find /truly/ objectionable is the support for arbitrary expressions, since it would tend towards encouraging suboptimal factoring. But we also don't live in an ideal world, so the existence of the other 3 (2 of them particularly relatively similar) alternatives is a legitimate practical concern when evaluating your proposal. Python is middle-aged; it's a blessing and a curse. Cheers, Chris From anthra.norell at bluewin.ch Mon Apr 2 06:56:30 2012 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Mon, 02 Apr 2012 12:56:30 +0200 Subject: Tkinter: IDLE can't get out of mainloop In-Reply-To: References: <1333179779.2280.50.camel@hatchbox-one> Message-ID: <1333364190.2279.8.camel@hatchbox-one> On Sat, 2012-03-31 at 06:29 -0400, Terry Reedy wrote: > On 3/31/2012 3:42 AM, Frederic Rentsch wrote: > > Hi all, > > > > Is is a bad idea to develop Tkinter applications in IDLE? I understand > > that IDLE is itself a Tkinter application, supposedly in a mainloop and > > mainloops apparently don't nest. > > In standard configuration, one process runs IDLE, another runs user > code, including tkinter code. So there should be no interference. The > example in the tkinter doc runs from IDLE edit window on my system. The > revised example in coming releases works even better. There have been > several IDLE bugs fixed in the last few months, and even more since 2.6 > before that. Upgrade if you can to get fixes, suffer the bugs since > fixed, or patch your 2.6 installation. > > -- > Terry Jan Reedy > Terry, It helps to know that an upgrade might improve things. Thank you for the suggestion. And thanks also to Chris for his remark on .pyc files. Frederic From jkn_gg at nicorp.f9.co.uk Mon Apr 2 07:17:54 2012 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Mon, 2 Apr 2012 04:17:54 -0700 (PDT) Subject: why can't I pickle a class containing this dispatch dictionary? Message-ID: <9ee32123-6672-41f9-bdea-5ac075c71093@db5g2000vbb.googlegroups.com> Hi All I'm clearly not understanding the 'can't pickle instancemethod objects' error; can someone help me to understand, & maybe suggest a workaround, (apart from the obvious if ... elif...). I'm running Python 2.6 on an embedded system. == testpickle.py == import pickle class Test(object): def __init__(self): self.myDict = { 1: self.tag1, 2: self.tag2 } def dispatch(self, v): try: self.myDict[v]() except KeyError: print "No corresponding dictionary entry!" # def tag1(self): print "one" def tag2(self): print "two" t = Test() t.dispatch(1) t.dispatch(2) t.dispatch(0) fd = open("pickle.out", "w") pickle.dump(t, fd) fd.close() # EOF $ python testpickle.py one two No corresponding dictionary entry! Traceback (most recent call last): File "ptest.py", line 29, in pickle.dump(t, fd) File "/usr/lib/python2.6/pickle.py", line 1362, in dump Pickler(file, protocol).dump(obj) File "/usr/lib/python2.6/pickle.py", line 224, in dump self.save(obj) File "/usr/lib/python2.6/pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "/usr/lib/python2.6/pickle.py", line 419, in save_reduce save(state) File "/usr/lib/python2.6/pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "/usr/lib/python2.6/pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) File "/usr/lib/python2.6/pickle.py", line 663, in _batch_setitems save(v) File "/usr/lib/python2.6/pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "/usr/lib/python2.6/pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) File "/usr/lib/python2.6/pickle.py", line 663, in _batch_setitems save(v) File "/usr/lib/python2.6/pickle.py", line 306, in save rv = reduce(self.proto) 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 instancemethod objects $ Thanks J^n From steve+comp.lang.python at pearwood.info Mon Apr 2 07:23:06 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2012 11:23:06 GMT Subject: Threads on google groups not on gmane? References: <7xaa2u30cl.fsf@ruckus.brouhaha.com> Message-ID: <4f798c1a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Apr 2012 03:16:26 -0700, Paul Rubin wrote: > Robert Kern writes: >> I also don't see these on GMane. It's possible that they are getting >> caught in one of GMane's several levels of spam filtering. > > I'm seeing some weird issues where google groups posts on another > newsgroup aren't making it to the non-google nntp server that I use. The > paranoid in me wonders if google is doing that on purpose, but it's a > pretty recent development, and other explanations are possible. Most likely, other providers are blocking google groups as a known source of spam. -- Steven From lanyjie at yahoo.com Mon Apr 2 07:46:41 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 04:46:41 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> Message-ID: <1333367201.47465.YahooMailNeo@web121506.mail.ne1.yahoo.com> >? >>>> "Are you "+name+"?" > > That allows arbitrary expressions and everything. >? To make that work for any type, you need: >>> "Are you "+ str(name) + "?" Another concern is performance. You are absolutely right, they are? equivalent in that both are expressions. As long as people start to realize that dynamic strings are expressions, there is no magic in it any more. And allowing expressions in those dynamic strings?would make sense? since?they are of the same sort. >>> d"sin($x$) = $ sin(x):0.3f $" is equivalent to the expression of >>> "sin(%s"%x + ")= %0.3f"%sin(x) Comparing th e two, I would say the latter is more computer friendly while? the former, more human friendly. If the computed result is only to be used in formatting the string, it would be nice to save an assignment stmt. >> >> Almost as terse, but not as readable, especially >> when there are many?parts to substitute -- >> the coder and reader need to be careful >> to?make sure the sequence is correct. > > I quite like this notation, personally. It's convenient, and is > supported (with variants) in quite a few C-derived languages (and, in > spite of the massive syntactic differences, Python does have C > heritage). Sure, once you get used to it, it would be harder to stop it ?the harder it is :). That's part of human nature, anyway. >> Why the Python community is so >> hostile to new things now? >> Python has merits, >> but it is far from being perfect. > > Hey now, no need to get defensive :) Thing is, it's up to you to > demonstrate that your proposal justifies itself. You're proposing to > create a massive backward-compatibility issue, so you need to prove > that your new way of formatting strings is sufficiently awesome to be > able to say "Well, you need Python 3.4+ to use this". > OK. I have put it out as is. I trust people knows good things. I would simply say: this new way is much more simple? and much more powerful. And there is no security issues as long as you don't use the evil eval to evaluate expressions, which is always a security issue. It is new, and has no compatibility issues with old ways at all. In syntax, all you need is to allow d"...", which clearly won't affect any old ways of business. Cheers, Yingjie From steve+comp.lang.python at pearwood.info Mon Apr 2 07:54:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2012 11:54:53 GMT Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Apr 2012 02:11:46 -0700, Yingjie Lan wrote: > Both template based and dict-based formatting require writing the > identifier three times: > >>> name = 'Peter' > >>> "Are you %(name)s"%{'name':name} They don't *require* this at all. "Are you %s" % name For trivial examples, you have trivial syntax. For more complex examples, you have a more powerful system: % can accept *any* dictionary, so you aren't limited to just pre-existing variables. That, by the way, is perhaps the biggest problem with this idea of dynamic strings: not that it is too powerful, but that it is TOO WEAK. It can only retrieve names from a single namespace, and the programmer has no control over which namespace that will be. The only way to feed named values into the dynamic string is by creating variables. With existing formatting systems, the programmer has complete control over what names get used. You can set up a series of separate namespaces and choose between them as needed: a = dict(name="Fred", job="butcher") b = dict(name="Sue", job="SAS sharp-shooter") c = dict(name="Mary", job="brain surgeon") d = dict(name="Tony", job="enforcer for the Russian mob") for namespace in (a, b, c, d): print ("%(name)s works as a %(job)s." % namespace) Using your dynamic strings: for namespace in (a, b, c, d): name = namespace["name"] job = namespace["job"] print ("$name$ works as a $job$.") and it has the side-effect that it has created some variables that are no longer needed. Also notice that because you have to create variables first, the dynamic string actually requires you to write the identifier MORE times, not fewer. So your proposal is actually weaker than what Python already has. So why bother? All this does is add more things to learn, more complexity in the compiler and parser, for what? Things that you can already do. > If dynamic string is used: > >>> "Are you $name$?" And where does name come from? It's all too magical. With the existing format strings, the programmer has *complete* control of where it comes from: "Are you %(name)s?" % locals() # from a local variable `name` "Are you %(name)s?" % globals() # from a global variable `name` "Are you %(name)s?" % namespace # from any namespace you like and similar for both format() and Template. -- Steven From lanyjie at yahoo.com Mon Apr 2 08:00:10 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 05:00:10 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> Message-ID: <1333368010.31122.YahooMailNeo@web121503.mail.ne1.yahoo.com> > "Are you %(name)s" % locals() # or vars() This partly solves the problem, however, you? can't work with expressions inside, like: > d"sin($x$) = $sin(x)$" Also, what if locals() or vars() does not contain the variable "x"? (x could be nonlocal or global). > It's more conservative than hostile. Here's some insight: > http://www.boredomandlaziness.org/2011/02/status-quo-wins-stalemate.html > You are probably right...Harmless enhancement is still probable? >? > Personally, in isolation, the only part of your proposal I find > /truly/ objectionable is the support for arbitrary expressions, since > it would tend towards encouraging suboptimal factoring. But we also I don't quite see that as a problem. The compiler (or translator, as you? mentioned earlier) could easily make?d"sin($x$) = $sin(x)$" into something like: ''.join(["sin(", str(x), ") = ", str(sin(x))] which would far more efficient than calling the format() method. Cheers, Yingjie From lanyjie at yahoo.com Mon Apr 2 08:40:14 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 05:40:14 -0700 (PDT) Subject: string interpolation for python In-Reply-To: <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1333370414.16999.YahooMailNeo@web121505.mail.ne1.yahoo.com> ... > That, by the way, is perhaps the biggest problem with this idea of? > dynamic strings: not that it is too powerful, but that it is TOO WEAK.? ... > and similar for both format() and Template. Seems you miss understood my notion of dynamic string. Dynamic strings are expressions in disguise: the things in between $...$ are plain old expressions (with optional? formatting specifications). They are evaluated as if they were outside the dynamic string. We put them in there to to kill two birds with one stone:? ? ?1) ease of reading; ? ?2) place holding. Cheers, Yingjie From stephane at harobed.org Mon Apr 2 08:55:30 2012 From: stephane at harobed.org (=?windows-1252?Q?St=E9phane_Klein?=) Date: Mon, 02 Apr 2012 14:55:30 +0200 Subject: I look for a package to make some simple console "form" Message-ID: Hi, I look for a package to make some console "form". It's a standard stuff, I think there are a package to do that. Example : What is your name ? Select your lang [EN, FR, DE?] ? Do you want ? [Y, N] ? Type of field : * textline * select choice * boolean question Thank for your help, St?phane -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane pro: http://www.is-webdesign.com From moky.math at gmail.com Mon Apr 2 09:02:19 2012 From: moky.math at gmail.com (Laurent Claessens) Date: Mon, 02 Apr 2012 15:02:19 +0200 Subject: string interpolation for python In-Reply-To: References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Seems you miss understood my notion of dynamic string. > Dynamic strings are expressions in disguise: the things > in between $...$ are plain old expressions (with optional > formatting specifications). They are evaluated > as if they were outside the dynamic string. We put them > in there to to kill two birds with one stone: > 1) ease of reading; > 2) place holding. like this one ? b = dict(name="Sue", job="SAS sharp-shooter") print "$b['name']$ works as b['job']" Is it really easier to read that the following ? "{0} works as {1}".format(b['name'],b['job']) In the case in which b is an object having "job" and "name" attribute, the dynamic string will write "$b.name$ works as $b.job$" instead of "{0}.name works as {0}.job".format(b) Laurent From rustompmody at gmail.com Mon Apr 2 09:04:03 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 2 Apr 2012 06:04:03 -0700 (PDT) Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <77d10d46-1752-4d6b-ae6a-a930fcd8e2e6@vy8g2000pbc.googlegroups.com> On Apr 2, 2:11?pm, Yingjie Lan wrote: > Almost as terse, but not as readable, especially... Hi Yingjie, Just in case you are not a native speaker of English, 'terse' is a mildly pejorative word, ie it is not 'good'. You probably want to use something like 'concise', or just plain 'short.' As for your suggestion, Ive nothing much to say: It probably comes from a perl culture and who is to way which culture is better? Not me anyway, whenever I look at perl code my head spins... [No flaming here -- I just dont know perl] From karthip444 at gmail.com Mon Apr 2 09:19:12 2012 From: karthip444 at gmail.com (karthi karthi) Date: Mon, 2 Apr 2012 06:19:12 -0700 (PDT) Subject: join this Message-ID: http://123maza.com/46/share115/ From jeanmichel at sequans.com Mon Apr 2 09:54:48 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 02 Apr 2012 15:54:48 +0200 Subject: I look for a package to make some simple console "form" In-Reply-To: References: Message-ID: <4F79AFA8.2090409@sequans.com> St?phane Klein wrote: > Hi, > > I look for a package to make some console "form". > > It's a standard stuff, I think there are a package to do that. > > Example : > > What is your name ? > Select your lang [EN, FR, DE?] ? > Do you want ? [Y, N] ? > > Type of field : > > * textline > * select choice > * boolean question > > Thank for your help, > St?phane Hi, Have a look at http://excess.org/urwid/ JM From nospam at nospam.com Mon Apr 2 10:09:01 2012 From: nospam at nospam.com (Javier) Date: Mon, 2 Apr 2012 14:09:01 +0000 (UTC) Subject: Tools for refactoring/obfuscation References: Message-ID: Well, a .pyc file would be a too blatant obfuscation, and people at my job would get angry. I need something more subtle. So I need a refactoring tool, preferably with which I can do scripting. These is what I found up to now in the CheeseShop: http://pypi.python.org/pypi/bicyclerepair/0.7.1 http://pypi.python.org/pypi/rope/0.9.3 I need to check how to do scripting with them. There seems to be no manual for them. This code also looks interesting, but in its present state it is for blatant obfuscation, although it could be changed to do some refactoring: http://pypi.python.org/pypi/pyfuscate/0.1 Lie Ryan wrote: > On 03/29/2012 03:04 AM, Javier wrote: >> Yes, in general I follow clear guidelines for writing code. I just use >> modules with functions in the same directory and clear use of name >> spaces. I almost never use classes. I wonder if you use some tool for >> refactoring. I am mainly intersted in scripting tools, no eclipse-style >> guis. >> >> Just let me know if you use some scripting tool. >> >> And, as somebody pointed in this thread obfuscating or refactoring the >> code are very different things but they can be done with the same tools. > > if you're not using classes, your code is obfuscated already > > Anyway, I think it's better if you describe why you want such a tool. If > you want to keep your code a secret, just distribute the .pyc file. If > you want to refactor your code to improve readability, there is rope. > From jeanmichel at sequans.com Mon Apr 2 10:21:14 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 02 Apr 2012 16:21:14 +0200 Subject: Pythonect 0.1.0 Release In-Reply-To: References: Message-ID: <4F79B5DA.5070203@sequans.com> Itzik Kotler wrote: > Hi All, > > I'm pleased to announce the first beta release of Pythonect interpreter. > > Pythonect is a new, experimental, general-purpose dataflow programming > language based on Python. > > It aims to combine the intuitive feel of shell scripting (and all of > its perks like implicit parallelism) with the flexibility and agility > of Python. > > Pythonect interpreter (and reference implementation) is written in > Python, and is available under the BSD license. > > Here's a quick tour of Pythonect: > > The canonical "Hello, world" example program in Pythonect: > > >>> "Hello World" -> print > : Hello World > Hello World > >>> > > '->' and '|' are both Pythonect operators. > > The pipe operator (i.e. '|') passes one item at a item, while the > other operator passes all items at once. > > > Python statements and other None-returning function are acting as a > pass-through: > > >>> "Hello World" -> print -> print > : Hello World > : Hello World > Hello World > >>> > > >>> 1 -> import math -> math.log > 0.0 > >>> > > > Parallelization in Pythonect: > > >>> "Hello World" -> [ print , print ] > : Hello World > : Hello World > ['Hello World', 'Hello World'] > > >>> range(0,3) -> import math -> math.sqrt > [0.0, 1.0, 1.4142135623730951] > >>> > > In the future, I am planning on adding support for multi-processing, > and even distributed computing. > > > The '_' identifier allow access to current item: > > >>> "Hello World" -> [ print , print ] -> _ + " and Python" > : Hello World > : Hello World > ['Hello World and Python', 'Hello World and Python'] > >>> > > >>> [ 1 , 2 ] -> _**_ > [1, 4] > >>> > > > True/False return values as filters: > > >>> "Hello World" -> _ == "Hello World" -> print > : Hello World > >>> > > >>> "Hello World" -> _ == "Hello World1" -> print > False > >>> > > >>> range(1,10) -> _ % 2 == 0 > [2, 4, 6, 8] > >>> > > > Last but not least, I have also added extra syntax for making remote > procedure call easy: > > >> 1 -> inc at xmlrpc://localhost:8000 -> print > : 2 > 2 > >>> > > > Download Pythonect v0.1.0 from: > http://github.com/downloads/ikotler/pythonect/Pythonect-0.1.0.tar.gz > > More information can be found at: http://www.pythonect.org > > > I will appreciate any input / feedback that you can give me. > > Also, for those interested in working on the project, I'm actively > interested in welcoming and supporting both new developers and new > users. Feel free to contact me. > > > Regards, > Itzik Kotler | http://www.ikotler.org It should be renamed Perlonect :) JM From lanyjie at yahoo.com Mon Apr 2 10:25:32 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 07:25:32 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1333376732.8379.YahooMailNeo@web121502.mail.ne1.yahoo.com> > like this one ? > > b = dict(name="Sue", job="SAS sharp-shooter") > print "$b['name']$ works as b['job']" > > Is it really easier to read that the following ? > "{0} works as {1}".format(b['name'],b['job']) > > In the case in which b is an object having "job" and "name" > attribute, the dynamic string will write > > "$b.name$ works as $b.job$" > instead of > "{0}.name works as {0}.job".format(b) > When you already have a dict, the dict-based formatting would be nice. >>> "%(name)s works as %(job)s"%b If it you need to create a dict just for string formatting, dynamic string would be nice. Say your object has methods/properties that fetch things from your database. >>> class staff: ... at property ...def name(): return 'Peter' ... >>> t = staff() >>> vars(t) {} >>> t.name 'Peter' >>> d"Staff name: $t.name$" #note the d"..." format 'Staff name: Peter' Because of the d"..." format, it won't? affect old ways of doing things one bit. Allowing dynamic string wouldn't hurt? a bit to anything that is already there. From stephane at harobed.org Mon Apr 2 10:35:30 2012 From: stephane at harobed.org (=?windows-1252?Q?St=E9phane_Klein?=) Date: Mon, 02 Apr 2012 16:35:30 +0200 Subject: I look for a package to make some simple console "form" In-Reply-To: <4F79AFA8.2090409@sequans.com> References: <4F79AFA8.2090409@sequans.com> Message-ID: <4F79B932.7030102@harobed.org> Le 02/04/2012 15:54, Jean-Michel Pichavant a ?crit : > St?phane Klein wrote: >> Hi, >> >> I look for a package to make some console "form". >> >> It's a standard stuff, I think there are a package to do that. >> >> Example : >> >> What is your name ? >> Select your lang [EN, FR, DE?] ? >> Do you want ? [Y, N] ? >> >> Type of field : >> >> * textline >> * select choice >> * boolean question >> >> Thank for your help, >> St?phane > Hi, > > Have a look at > http://excess.org/urwid/ > No, I don't look for high level feature based on ncurse? I would like very low level feature, form like sphinx quick start or modern-package-template? Regards, Stephane -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane pro: http://www.is-webdesign.com From invalid at invalid.invalid Mon Apr 2 10:45:32 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 2 Apr 2012 14:45:32 +0000 (UTC) Subject: I look for a package to make some simple console "form" References: <4F79AFA8.2090409@sequans.com> Message-ID: On 2012-04-02, St?phane Klein wrote: > Le 02/04/2012 15:54, Jean-Michel Pichavant a ?crit : >> St?phane Klein wrote: >>> >>> I look for a package to make some console "form". >>> >>> It's a standard stuff, I think there are a package to do that. >>> >>> Example : >>> >>> What is your name ? >>> Select your lang [EN, FR, DE?] ? >>> Do you want ? [Y, N] ? >>> >>> Type of field : >>> >>> * textline >>> * select choice >>> * boolean question >> >> Have a look at >> http://excess.org/urwid/ > > No, I don't look for high level feature based on ncurse? For something simpler, your two best options are dialog and newt: http://pythondialog.sourceforge.net/ https://en.wikipedia.org/wiki/Newt_%28programming_library%29 https://hurley.wordpress.com/2008/01/25/create-simple-ansi-based-ui-with-python-newt/ http://www.wanware.com/tsgdocs/snack.html I'm rather partial to newt since it was intended from day 1 for use with Python. It was written by RedHat many, many years ago for use in their console-mode-installer (which was written in Python). But, the docs are pretty sparse, and it's not very active these days. > I would like very low level feature, form like sphinx quick start or > modern-package-template? Sorry, no clue what those are... -- Grant Edwards grant.b.edwards Yow! Did I do an INCORRECT at THING?? gmail.com From mwilson at the-wire.com Mon Apr 2 10:46:28 2012 From: mwilson at the-wire.com (mwilson at the-wire.com) Date: Mon, 02 Apr 2012 10:46:28 -0400 Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Yingjie Lan wrote: > Seems you miss understood my notion of dynamic string. > Dynamic strings are expressions in disguise: the things > in between $...$ are plain old expressions (with optional > formatting specifications). They are evaluated > as if they were outside the dynamic string. In that case you should re-think the delimiters, so that you have something that can be nested. An example (example only, I'm not in love with it as a final form): "A string that gets %(count*spacer%) in the middle" "A string that gets %(count*%(spacer%)%) in the middle" Mel. From jeanmichel at sequans.com Mon Apr 2 10:52:16 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 02 Apr 2012 16:52:16 +0200 Subject: I look for a package to make some simple console "form" In-Reply-To: <4F79B932.7030102@harobed.org> References: <4F79AFA8.2090409@sequans.com> <4F79B932.7030102@harobed.org> Message-ID: <4F79BD20.4080908@sequans.com> St?phane Klein wrote: > Le 02/04/2012 15:54, Jean-Michel Pichavant a ?crit : >> St?phane Klein wrote: >>> Hi, >>> >>> I look for a package to make some console "form". >>> >>> It's a standard stuff, I think there are a package to do that. >>> >>> Example : >>> >>> What is your name ? >>> Select your lang [EN, FR, DE?] ? >>> Do you want ? [Y, N] ? >>> >>> Type of field : >>> >>> * textline >>> * select choice >>> * boolean question >>> >>> Thank for your help, >>> St?phane >> Hi, >> >> Have a look at >> http://excess.org/urwid/ >> > > No, I don't look for high level feature based on ncurse? > > I would like very low level feature, form like sphinx quick start or > modern-package-template? > > Regards, > Stephane > Don't know if there is such package. There's nothing that rawinput cannot handle in what you're asking for. Anyway since you refered to sphinx, it does not use any package, look at quickstar.py, you may reuse their do_prompt. And because being lazy is cool : from sphinx import quickstart d = {} quickstart.do_prompt(d, 'foo', 'enter the foo value', '5', lambda x: int(x)) print d < {'foo': 8} JM From rosuav at gmail.com Mon Apr 2 10:58:38 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Apr 2012 00:58:38 +1000 Subject: string interpolation for python In-Reply-To: <1333367201.47465.YahooMailNeo@web121506.mail.ne1.yahoo.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> <1333367201.47465.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: On Mon, Apr 2, 2012 at 9:46 PM, Yingjie Lan wrote: >>>>> ?"Are you "+name+"?" >> >> That allows arbitrary expressions and everything. >> > > To make that work for any type, you need: > >>>> "Are you "+ str(name) + "?" > > Another concern is performance. > > You are absolutely right, they are > equivalent in that both are expressions. Right, meaning that both have the same issues of performance, need for str(), etc. There's absolutely no difference. > As long as people start to realize that > dynamic strings are expressions, > there is no magic in it any more. And no benefit. You lose out on syntax highlighting in your editor and gain nothing. > And allowing expressions in those > dynamic strings?would make sense > since?they are of the same sort. > >>>> d"sin($x$) = $ sin(x):0.3f $" > > is equivalent to the expression of > >>>> "sin(%s"%x + ")= %0.3f"%sin(x) > > Comparing th e two, I would say the latter > is more computer friendly while > the former, more human friendly. The former is more magical, the second is more explicit. Computers do tend to like the explicit, but I wouldn't assume that humans like the magical *necessarily*. There are times when we prefer the explicit, too. > Sure, once you get used to it, it would be harder to stop it > ?the harder it is :). That's part of human nature, anyway. Maybe. But it (percent-notation) is expressive and insanely powerful. Moreover, it obeys the rule that you pay for the complexity you use, no more and no less. (Although I think there's one lack in Python's implementation - I can't find a way to use an argument more than once, without switching to "dictionary mode" and using keys for everything. I can't, for instance, use "Hello hello, %s %[0]s!"%name to use the name twice. But since that isn't in the original C implementation, it's hardly mandatory.) Some implementations go even further than Python's does and allow an array notation. sprintf("UPDATE tablename SET modified=now()%{,%s=:%[0]s%} WHERE key=%d",array_of_field_names,primary_key_value) --> "UPDATE tablename SET modified=now(),foo=:foo,bar=:bar,quux=:quux WHERE key=1234" You're still paying for no complexity you aren't actually using. It's clear and readable. > I would simply say: this new way is much more simple > and much more powerful. And there is no security issues > as long as you don't use the evil eval to evaluate expressions, > which is always a security issue. It's powerful only if you use eval to allow full expression syntax. Otherwise, what does it have above str.format()? > It is new, and has no compatibility issues with old ways at all. > In syntax, all you need is to allow d"...", which clearly won't > affect any old ways of business. You may well be able to get past the compatibility issues. I'm not yet convinced that the new syntax is worth it, but it may be possible. Here's a recommendation: Write a parser for your notation that turns it into executable Python code (that is, executable in Python 3.3 without any d"..." support). Since a dynamic string is really an expression in disguise, it doesn't need to be translated at run time, and in fact is best translated at compile time. It wouldn't be hard to make the precompiler as per your equivalency above; and since you can use "%s"%123 without raising TypeError, you don't even have to figure out data types. With that written, the Python community can more adequately evaluate your proposal, and even start making use of it and getting a "feel" for the new syntax. If it catches on, someone'll probably invite you to write a PEP or something; if it doesn't, well, you still have it on your own version, and you don't have to worry about upgrades (your precompiler/"patch" should be able to slide up to a new version easily). I'm still against the idea personally, mainly because it's nothing but a more magical way of doing what we already can do, but there may well be many who disagree. Chris Angelico From davidm at pulsonix.com Mon Apr 2 11:07:34 2012 From: davidm at pulsonix.com (David Manns) Date: Mon, 2 Apr 2012 08:07:34 -0700 (PDT) Subject: AddNamedItem throws exception Message-ID: <4c51ff68-b0a3-49f4-821c-e87b9431a847@v22g2000vby.googlegroups.com> We have a scripting engine interface in our application. This works fine for loading/calling VBscript and Javascript scripting engines, but PythonScript fails. Specifically, it fails at : m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM) where m_pAxsScript is the IActiveScript interface acquired through CoCreateInstance. The exception returned is: 80004005 which to my mind implies some kind of 'access denied' error. We are using Python 2.7.2 and Pywin32 2.7 on a Windows 7 32-bit system. We have this problem here on a test machine that was set up to match that in use at one of our customers who is now stuck being unable to run his scripts. Any clues or suggestions would be gratefully received. David From mwilson at the-wire.com Mon Apr 2 11:34:09 2012 From: mwilson at the-wire.com (mwilson at the-wire.com) Date: Mon, 02 Apr 2012 11:34:09 -0400 Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: mwilson at the-wire.com wrote: > Yingjie Lan wrote: >> Seems you miss understood my notion of dynamic string. >> Dynamic strings are expressions in disguise: the things >> in between $...$ are plain old expressions (with optional >> formatting specifications). They are evaluated >> as if they were outside the dynamic string. > In that case you should re-think the delimiters, so that you have > something > that can be nested. An example (example only, I'm not in love with it as > a final form): > > "A string that gets %(count*spacer%) in the middle" > > "A string that gets %(count*%(spacer%)%) in the middle" A less than great example, I guess. Maybe > "A string that gets %(count*"-%(spacer%)-"%) in the middle" Mel. From jason at deadtreepages.com Mon Apr 2 11:44:44 2012 From: jason at deadtreepages.com (Jason) Date: Mon, 2 Apr 2012 08:44:44 -0700 (PDT) Subject: Will MySQL ever be supported for Python 3.x? In-Reply-To: References: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> Message-ID: <24525317.394.1333381484289.JavaMail.geo-discussion-forums@vbtg38> On Sunday, April 1, 2012 1:54:14 AM UTC-4, Tim Roberts wrote: > John Nagle wrote: > > >On 3/30/2012 2:32 PM, Irmen de Jong wrote: > >> Try Oursql instead http://packages.python.org/oursql/ > >> "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" > > > > Not even close to being compatible with existing code. Every SQL > >statement has to be rewritten, with the parameters expressed > >differently. It's a good approach, but very incompatible. > > Those changes can be automated, given an adequate editor. "Oursql" is a > far better product than the primitive MySQLdb wrapper. It is worth the > trouble. > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. Is OurSQL still active? I had problems with it because it couldn't handle MySQL's zeroed dates, but the latest release seems to be patched now (applied a year after the bug was reported with a small patch to fix it). -- Jason From lanyjie at yahoo.com Mon Apr 2 11:49:26 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 08:49:26 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> <1333367201.47465.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: <1333381766.14038.YahooMailNeo@web121504.mail.ne1.yahoo.com> > Right, meaning that both have the same issues? > of performance, need for > str(), etc. There's absolutely no difference. OK, performance. Here is a new solution: ? Suppose we have a new string method ? ? str.format_join([...]) taking a list of strings and objects, with even-indexed ones being strings, odd-indexed ones being objects. Each even-indexed string *ends* with a formatting specification for the next object in the list. Then we can have: >>>?d"sin($x$) = $ sin(x):0.3f $" get translated to: >>> ''.format_join(["sin(%s",x,") = %0.3f", sin(x)]) This seems to be at least as good in performance. > And no benefit. You lose out on syntax highlighting? > in your editor and?gain nothing. Gain: readability, terseness, hassle-free, and possibly better performance if done right. Syntax highlighting: can be done more creatively. For dynamic strings, string parts are like normal? strings, but the embedded expressions are like normal expressions :) > > sprintf("UPDATE tablename SET modified=now()%{,%s=:%[0]s%} WHERE > key=%d",array_of_field_names,primary_key_value) > --> "UPDATE tablename SET modified=now(),foo=:foo,bar=:bar,quux=:quux > WHERE key=1234" > > You're still paying for no complexity you aren't actually using. > It's?clear and readable. You are really good at that. Maybe not everybody is as experience as you, and I suppose the learning curve is? kind of hard to climb. > It's powerful only if you use eval to allow full expression syntax. > Otherwise, what does it have above str.format()? Those expressions are embedded, you don't need eval() to have the result though. Are we on the same page? > You may well be able to get past the compatibility issues. I'm not yet > convinced that the new syntax is worth it, but it may be possible. > > Here's a recommendation: Write a parser for your notation that turns > it into executable Python code (that is, executable in Python 3.3 > without any d"..." support).? You mean a translator? The syntax is essential for compatibility. We must distinguish dynamic strings from common strings. They will live peacefully together.? (escaping the '$' in normal strings breaks compatibility,? and the consequence of forgetting to escape could be disastrous, so definitely not an option).? May be d" is too tiny, $"..." is easier to pick out. Cheers, Yingjie From lanyjie at yahoo.com Mon Apr 2 12:02:22 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 09:02:22 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1333382542.46834.YahooMailNeo@web121501.mail.ne1.yahoo.com> >> ? In that case you should re-think the delimiters, so that you have >> ? something >> that can be nested.? An example (example only, I'm not in love with it > as >> a final form): Haven't really thought about that. Nesting is a big? issue if?in the embedded expression, there is another? dynamic string expression. For example (the first '%' immediately preceding the first quote denotes the start of a dynamic string expression):: >>> first_name, family_name = "Peter", "Johns" >>> %"Hi $ first_name+%", $family_name$" $!" 'Hi Peter, Johns!' However, nesting is really cluttering things up and we should forbid it without loosing power: The above example can be done without nesting: >>>?>>> %"Hi $ first_name$, $family_name$!" 'Hi Peter, Johns!' Can you offer an example where nesting is? better or necessary? Cheers, Yingjie From nad at acm.org Mon Apr 2 14:45:36 2012 From: nad at acm.org (Ned Deily) Date: Mon, 02 Apr 2012 11:45:36 -0700 Subject: [RELEASED] Python 3.3.0 alpha 2 References: <4F793F5D.3040808@python.org> <4F794C1A.7020600@gmail.com> Message-ID: In article <4F794C1A.7020600 at gmail.com>, Andrew Berg wrote: > > To download Python 3.3.0 visit: > > > > http://www.python.org/download/releases/3.3.0/ > The Windows links point to 3.3a1 installers, even though the links say > 3.3a2. Thanks for the heads up. The links have now been updated to point to the 3.3a2 files. -- Ned Deily, nad at acm.org From pruebauno at latinmail.com Mon Apr 2 14:51:16 2012 From: pruebauno at latinmail.com (nn) Date: Mon, 2 Apr 2012 11:51:16 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Mar 31) References: Message-ID: On Mar 31, 11:38?am, Cameron Laird wrote: > I pine for the fjords. > > And it's time to bring "Python-URL!" to a close. ?"Python-URL!", which > Jean-Claude Wippler and I appear to have launched in 1998, has reached > the end of its utility. ?We still have many loyal and enthusiastic > readers--one subscription request arrived within the last day, in > fact--and certainly much writing turns up every week that *deserves* > the spotlight "Python-URL!" has shone in the past. > > However, the Python world has changed a great deal over the last > fourteen years. ?There are many, MANY other ways for those with an > interest in Python to nourish themselves, and Python itself has grown > and "normalized" so much that it no longer fits particularly well in > the "Python-URL!" format. ?Enjoy "Mouse vs. Python" , the Python areas of DZone, > Reddit, developerWorks, stackoverflow, and so on. > > For your reference, I append below the most-recent-but-not- > particularly- > current version of "Python-URL!"'s coda of related readings. > > That is all. > > ======================================================================== > 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.c > omp.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=gma... > .python.general&sort=date > ?http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lan... > n&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. Thanks a lot Cameron! Sad to see it go. The weekly URL has always made for good reading. From steve+comp.lang.python at pearwood.info Mon Apr 2 14:56:49 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2012 18:56:49 GMT Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> <1333367201.47465.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: <4f79f671$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 Apr 2012 00:58:38 +1000, Chris Angelico wrote: > Maybe. But it (percent-notation) is expressive and insanely powerful. > Moreover, it obeys the rule that you pay for the complexity you use, no > more and no less. (Although I think there's one lack in Python's > implementation - I can't find a way to use an argument more than once, > without switching to "dictionary mode" and using keys for everything. I > can't, for instance, use "Hello hello, %s %[0]s!"%name to use the name > twice. But since that isn't in the original C implementation, it's > hardly mandatory.) Ack. In this case, you can use format: >>> "Hello {0}, what's up with {1}? Hey, {0} I'm speaking to you!".format ('George', 'Melissa') "Hello George, what's up with Melissa? Hey, George I'm speaking to you!" -- Steven From ethan at stoneleaf.us Mon Apr 2 15:05:45 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 02 Apr 2012 12:05:45 -0700 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: <4F79F889.6040304@stoneleaf.us> Tim Rowe wrote: > On 22 March 2012 19:14, Chris Angelico wrote: > >> In any case, though, I agree that there's a lot of people >> professionally writing code who would know about the 3-4 that you say. >> I'm just not sure that they're any good at coding, even in those few >> languages. All the best people I've ever known have had experience >> with quite a lot of languages. > > I know 10 languages. But I'm not telling you what base that number is :) There are 10 types of people in the world: those who know binary and those who don't. ;) ~Ethan~ From stephane at harobed.org Mon Apr 2 15:41:38 2012 From: stephane at harobed.org (Stephane Klein) Date: Mon, 02 Apr 2012 21:41:38 +0200 Subject: I look for a package to make some simple console "form" In-Reply-To: <4F79BD20.4080908@sequans.com> References: <4F79AFA8.2090409@sequans.com> <4F79B932.7030102@harobed.org> <4F79BD20.4080908@sequans.com> Message-ID: <4F7A00F2.6010008@harobed.org> Le 02/04/2012 16:52, Jean-Michel Pichavant a ?crit : > St?phane Klein wrote: >> Le 02/04/2012 15:54, Jean-Michel Pichavant a ?crit : >>> St?phane Klein wrote: >>>> Hi, >>>> >>>> I look for a package to make some console "form". >>>> >>>> It's a standard stuff, I think there are a package to do that. >>>> >>>> Example : >>>> >>>> What is your name ? >>>> Select your lang [EN, FR, DE?] ? >>>> Do you want ? [Y, N] ? >>>> >>>> Type of field : >>>> >>>> * textline >>>> * select choice >>>> * boolean question >>>> >>>> Thank for your help, >>>> St?phane >>> Hi, >>> >>> Have a look at >>> http://excess.org/urwid/ >>> >> >> No, I don't look for high level feature based on ncurse? >> >> I would like very low level feature, form like sphinx quick start or >> modern-package-template? >> >> Regards, >> Stephane >> > Don't know if there is such package. There's nothing that rawinput > cannot handle in what you're asking for. > Anyway since you refered to sphinx, it does not use any package, look at > quickstar.py, you may reuse their do_prompt. > > And because being lazy is cool : > > from sphinx import quickstart > d = {} > quickstart.do_prompt(d, 'foo', 'enter the foo value', '5', lambda x: > int(x)) > print d > < {'foo': 8} Yes, quickstart.do_prompt is a good starting point : https://bitbucket.org/birkenfeld/sphinx/src/164f59b2d946/sphinx/quickstart.py -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane pro: http://www.is-webdesign.com From jcd at sdf.lonestar.org Mon Apr 2 15:52:34 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 02 Apr 2012 15:52:34 -0400 Subject: I look for a package to make some simple console "form" In-Reply-To: References: Message-ID: <1333396354.3210.5.camel@jcdyer-laptop> You might look into formencode. It basically takes the philosophy that a form is nothing more and nothing less than an interface between user input and python data. It doesn't make assumptions about how you present the form to the user. It just handles validation and conversion of that data into useful python objects, and from python objects to displayable values. http://www.formencode.org/en/latest/Validator.html Might be what you're looking for. Cheers, Cliff On Mon, 2012-04-02 at 14:55 +0200, St?phane Klein wrote: > Hi, > > I look for a package to make some console "form". > > It's a standard stuff, I think there are a package to do that. > > Example : > > What is your name ? > Select your lang [EN, FR, DE?] ? > Do you want ? [Y, N] ? > > Type of field : > > * textline > * select choice > * boolean question > > Thank for your help, > St?phane > -- > St?phane Klein > blog: http://stephane-klein.info > Twitter: http://twitter.com/klein_stephane > pro: http://www.is-webdesign.com > From atmb4u at gmail.com Mon Apr 2 16:31:34 2012 From: atmb4u at gmail.com (Anoop Thomas Mathew) Date: Tue, 3 Apr 2012 02:01:34 +0530 Subject: Python Script Works Locally But Not Remotely with SSH In-Reply-To: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> References: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> Message-ID: Hi, You can try using ssh -X xxx.xxx.xxx.xxx for GUI ssh connection. Thanks, Anoop Thomas Mathew atm ___ Life is short, Live it hard. On 28 March 2012 06:21, goldtech wrote: > Hi, > > I have a WinXP PC running an SSH server and I have a Linux PC with an > SSH client and logged into the XP seemingly OK. It's all on my > personal LAN, the connection seems OK. > > I have a py file on the XP that I run via SSH from the Linux, it's: > > import webbrowser > webbrowser.open('www.google.com') > > This runs OK started on the local XP PC, the browser Firefox opens and > goes to the site, or it opens a tab to the site. But executing that > same file via SSH does not open Firefox...doing it via SSH starts > Firefox ( I see it begin in the process manager and I see web > activity) but Firefox does not open it's window. > > Why the does the window not open when the script is started remotely? > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From driscoll at cs.wisc.edu Mon Apr 2 16:36:04 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Mon, 02 Apr 2012 15:36:04 -0500 Subject: string interpolation for python In-Reply-To: <1333376732.8379.YahooMailNeo@web121502.mail.ne1.yahoo.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333376732.8379.YahooMailNeo@web121502.mail.ne1.yahoo.com> Message-ID: <4F7A0DB4.6060408@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Yingjie Lan wrote: > Because of the d"..." format, it won't > affect old ways of doing things one bit. > Allowing dynamic string wouldn't hurt > a bit to anything that is already there. Why don't you just write a function that does it? I think someone already suggested this... import dynamic_strings # write this d = dynamic_strings.dynamic x = 5 print(d("x=$x$")) ? Sure, it's not *quite* as pretty as if you could just say d"x=$x$", and you might have to do some hacky uglyness in the implementation to get at the locals of the calling procedure, but it solves a bazillion problems, such as: 1. YOU can do it, instead of hoping it gets into the mainline interpreter 2. You can do it NOW, and it will work with "any" version of Python 3. You have the freedom to easily add "eval from *this dictionary* if you want, which solves Steven D'Aprano's objection that your suggestion is too weak. 4. Languages changes should be viewed suspiciously in general. Evan From ian.g.kelly at gmail.com Mon Apr 2 16:48:38 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Apr 2012 14:48:38 -0600 Subject: No os.copy()? Why not? In-Reply-To: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> Message-ID: On Wed, Mar 28, 2012 at 2:12 PM, John Ladasky wrote: > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > Since the equivalents of "rm" and "mkdir" are in the os module, I > figured I look there. ?I haven't found anything in the documentation. > I am also looking through the Python source code in os.py and its > child, posixfile.py. > > Any help? ?Thanks. The os module wraps system calls, not shell commands. You want the shutil module, not the os module. From emile at fenx.com Mon Apr 2 17:04:03 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 02 Apr 2012 14:04:03 -0700 Subject: Python Script Works Locally But Not Remotely with SSH In-Reply-To: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> References: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> Message-ID: On 3/27/2012 5:51 PM goldtech said... > Hi, > > I have a WinXP PC running an SSH server and I have a Linux PC with an > SSH client and logged into the XP seemingly OK. It's all on my > personal LAN, the connection seems OK. > > I have a py file on the XP that I run via SSH from the Linux, it's: > > import webbrowser > webbrowser.open('www.google.com') > > This runs OK started on the local XP PC, the browser Firefox opens and > goes to the site, or it opens a tab to the site. But executing that > same file via SSH does not open Firefox...doing it via SSH starts > Firefox ( I see it begin in the process manager and I see web > activity) but Firefox does not open it's window. > > Why the does the window not open when the script is started remotely? Just a guess here, but I expect that Firefox requires some sort of graphics device to write on that the ssh shell doesn't provide. Emile From someone at someplace.invalid Mon Apr 2 17:11:52 2012 From: someone at someplace.invalid (HoneyMonster) Date: Mon, 2 Apr 2012 21:11:52 +0000 (UTC) Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> Message-ID: On Wed, 28 Mar 2012 13:12:30 -0700, John Ladasky wrote: > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > Since the equivalents of "rm" and "mkdir" are in the os module, I > figured I look there. I haven't found anything in the documentation. > I am also looking through the Python source code in os.py and its child, > posixfile.py. > > Any help? Thanks. One way: import os os.system ("cp src sink") From miloshzorica at gmail.com Mon Apr 2 17:25:01 2012 From: miloshzorica at gmail.com (milosh zorica) Date: Mon, 2 Apr 2012 18:25:01 -0300 Subject: A must read: Is MBA critical for techies to shape their career In-Reply-To: <7974e55e-ffcd-4809-99e8-cf2741551bf4@oq7g2000pbb.googlegroups.com> References: <7974e55e-ffcd-4809-99e8-cf2741551bf4@oq7g2000pbb.googlegroups.com> Message-ID: no need for an MBA, especially if you don't plan building a corporate career top schools are good for networking though On Thu, Mar 29, 2012 at 3:47 AM, Sridevi V wrote: > Hi, > > I was curious to find out about the job trends for fresh graduates and > if an MBA will help me find even better job, when I came across these > two articles on a website. It gave me some startling trends that are > being followed in industry. A must read for all. It helped me and I > thought it might help you as well. > > > > Winning, The Azim Premji Way > > Azim Hashim Premji, a supernova in the Indian IT industry is one of > the most revered names in the tech scenario of all time. His words of > wisdom will surely prove to e a winning streak to most of us > > http://bit.ly/WinningAzim > > The Unwanted Tech Kids > > Youth in our country considered as the future representatives of the > nation at the global level, don?t you think they must be given good > opportunities to showcase their talents and utilize their skills at > their best level to help the country?s economic growth? > > http://bit.ly/TechKids > > Do Techies Need an M.B.A? > > We generally think that an MBA degree is a must to climb the corporate > ladder in order to reach the zenith of success. > > http://bit.ly/TechiesNeedMBA > > Thank You, please do feel free to comment if you felt this was helpful > -- > http://mail.python.org/mailman/listinfo/python-list -- Milosh Zorica http://www.linkedin.com/in/miloshzorica phone: +44 20 8144 5294 & +1 206 350 9734 e-mail: miloshzorica at gmail.com skype: milosh.zorica From __peter__ at web.de Mon Apr 2 17:32:45 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Apr 2012 23:32:45 +0200 Subject: Best way to structure data for efficient searching References: Message-ID: Larry.Martell at gmail.com wrote: > I have the following use case: > > I have a set of data that is contains 3 fields, K1, K2 and a > timestamp. There are duplicates in the data set, and they all have to > processed. > > Then I have another set of data with 4 fields: K3, K4, K5, and a > timestamp. There are also duplicates in that data set, and they also > all have to be processed. > > I need to find all the items in the second data set where K1==K3 and > K2==K4 and the 2 timestamps are within 20 seconds of each other. > > I have this working, but the way I did it seems very inefficient - I > simply put the data in 2 arrays (as tuples) and then walked through > the entire second data set once for each item in the first data set, > looking for matches. > > Is there a better, more efficient way I could have done this? Build a lookup table that maps (K3, K4) to the matching records in the second table. Then you can walk through the first table, look up the matching records in the second and filter by the timestamp constraint: from collections import defaultdict, namedtuple # simulate a database One = namedtuple("One", "K1 K2 T") Two = namedtuple("Two", "K3 K4 K5 T") one = [ ["alpha", "beta", 10], ["gamma", "delta", 20], ["gamma", "delta", 25], ["gamma", "delta", 40], ["kappa", "lambda", 40], ] one = (One(*row) for row in one) two = [ ["alpha", "beta", "epsilon", 10], ["gamma", "delta", "zeta", 20], ["gamma", "delta", "eta", 60], ] two = (Two(*row) for row in two) # build the lookup table lookup = defaultdict(list) for rtwo in two: lookup[rtwo.K3, rtwo.K4].append(rtwo) # show the matches for rone in one: for rtwo in lookup.get((rone.K1, rone.K2), ()): if abs(rone.T-rtwo.T) <= 20: print rone, "-->", rtwo (Personally I'd go for the SQL approach proposed by Jon; I find the argument why you can't do it unconvincing) From pjb at informatimago.com Mon Apr 2 17:48:21 2012 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 02 Apr 2012 23:48:21 +0200 Subject: Is Programing Art or Science? References: Message-ID: <87vclhn6u2.fsf@kuiper.lan.informatimago.com> ccc31807 writes: > Programming is neither an art nor a science, but a trade. > > It's not an art in the sense of painting, music, dance, poetry, etc., > because the objective isn't to make a beautiful something, but to give > instructions to a machine to accomplish some useful task. > > It's not a science in the sense of either physics and chemistry > (experimental) or geology or astronomy (observational) or cosmology or > psychology (theoretical) because the objective isn't to test > hypothetical s against data, but to give instructions to a machine to > accomplish some useful task. > > Obviously, it's very much connected with art (e.g., user interface > design) and science (e.g., artificial intelligence) but the practice > of giving instructions to a machine is more like assembling machines > in a factory than the pursuit of an art or the practice of a science. This is a narrow-minded definition of programming. Watch: http://www.infoq.com/presentations/We-Really-Dont-Know-How-To-Compute Read: Structure and Interpretation of Computer Programs http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/ -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From rosuav at gmail.com Mon Apr 2 17:50:39 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Apr 2012 07:50:39 +1000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <28983178-6745-438c-937d-cc6349aa18b1@t8g2000pbe.googlegroups.com> References: <28983178-6745-438c-937d-cc6349aa18b1@t8g2000pbe.googlegroups.com> Message-ID: On Fri, Mar 30, 2012 at 2:48 AM, Steve Howell wrote: > I agree with you on the overall point, but I think that Python > actually does a fine job of replacing REXX and PHP. ?I've used both of > the latter (and, of course, Python). ?REXX and PHP are great at what > they do, but I don't think their slight advantages over Python justify > all the weight they carry--incompatible syntax to Python, archaic > libraries, missing modern language features, etc. I think you're probably right about REXX, mainly because it's somewhat old now. It was an awesome language when I first met it back in the 1990s; it tied in very nicely with OS/2, it was (and is) easy to extend and embed with C, it had excellent GUI facilities (as long as you don't need it to be cross-platform). But today, REXX is somewhat outclassed. I don't recommend it to people for most tasks, unless they're actually on OS/2 (in which case they probably know it already). Unicode support and cross-platform GUI toolkits would probably be REXX's two biggest lacks. As to PHP? I don't think it's "great at what [it] [does]", frankly. At least, it's not great at what it's often used for. PHP is adequate as a "variant of HTML that allows scripting", but it's usually used today as though it were a CGI script, and for that it's less than optimal. For instance, you can't have an include file without it also being an entry point of its own (eg someone could go to http://www.example.com/common_functions.php), so you need code to protect against that. Huge frameworks have such code peppered throughout. (As a side point, I don't believe that a web server's CGI scripts should be updated simply by writing to the disk. It's pretty easy to get non-atomicity problems when you have a page and its include file. There ARE other options, but I don't know of any efficient ways to do it in Python.) > Python should also be a perfectly good superset of Bash Scripting > language. ?(To the extent that Python isn't, there's nothing intrinsic > about the language that prevents you from orchestrating processes.) Hmm... How do you pipe one command's output into another's input using Python? It's not nearly as clean as it is in bash. > I think the problem these days is that the programmer's brain is like > a small toolbox. ?Maybe twenty tools fit in the toolbox. ?Instead of > filling it up with 20 useful tools, a lot of us have it cluttered up > with ten hammers, when only one of the hammers is what we need for the > nails. Maybe. But you can also have a little catalogue in there that reminds you of the tools you have in your shed. If you keep that catalogue up to date and accurate, you can hunt down those tools you seldom use when you need them. ChrisA From rosuav at gmail.com Mon Apr 2 17:52:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Apr 2012 07:52:48 +1000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <062a89c7-36e7-4c82-9546-1f216e425fe3@oo9g2000pbc.googlegroups.com> References: <062a89c7-36e7-4c82-9546-1f216e425fe3@oo9g2000pbc.googlegroups.com> Message-ID: On Sun, Apr 1, 2012 at 6:23 AM, Steve Howell wrote: > On Mar 31, 1:13?pm, Tim Rowe wrote: >> >> I know 10 languages. But I'm not telling you what base that number is :) >> > > Well, that means you know at least two programming languages, which > puts you ahead of a lot of people. :) That's enough to use the phone support code word. (I'm of the opinion that you shouldn't be allowed to use it unless you are qualified to respond to it.) ChrisA who knows 806 comic strips From rosuav at gmail.com Mon Apr 2 18:06:25 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Apr 2012 08:06:25 +1000 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 4:07 PM, Steve Howell wrote: > On Mar 30, 1:20?pm, Chris Angelico wrote: > >> Totally. That's why we're all still programming in assembly language >> and doing our own memory management, because we would lose a lot of >> personal value if programming stopped being so difficult. If it >> weren't for all these silly new-fangled languages with their automatic >> garbage collection and higher order function handling, we would all be >> commanding much higher salaries. >> > > While I don't subscribe to the conspiracy theory that "programmers > invest in arcane practices to preserve personal value" [paraphrase of > Nathan], surely you could come up with a better argument than "garbage > collection." GC is to programming what running water or a fridge is to a kitchen. It isn't exactly new, in fact you probably would expect it even in a fairly old kitchen, but you still wouldn't want to give it up. A somewhat newer example would be the ability to pass higher-order objects around - functions, mappings, lists, etc - and the basic concept that an expression resulting in (or function returning) an object is identical to a variable containing that object. Not every language supports that. > There hasn't been much progress in programming language design in the > last 20 years. ?It's been incremental at best. Nobody's really > thinking outside the box, as far as I can tell. ?Please prove me > wrong. > > It's true that we've moved past assembly language. Twenty years? That would almost certainly include solid Unicode support. Anything that dates back to 1992 is unlikely to truly acknowledge the difference between bytes and characters. That's probably incremental, but a fairly big increment. ChrisA From breamoreboy at yahoo.co.uk Mon Apr 2 18:10:10 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Apr 2012 23:10:10 +0100 Subject: Threads on google groups not on gmane? In-Reply-To: <4f798c1a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <7xaa2u30cl.fsf@ruckus.brouhaha.com> <4f798c1a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02/04/2012 12:23, Steven D'Aprano wrote: > On Mon, 02 Apr 2012 03:16:26 -0700, Paul Rubin wrote: > >> Robert Kern writes: >>> I also don't see these on GMane. It's possible that they are getting >>> caught in one of GMane's several levels of spam filtering. >> >> I'm seeing some weird issues where google groups posts on another >> newsgroup aren't making it to the non-google nntp server that I use. The >> paranoid in me wonders if google is doing that on purpose, but it's a >> pretty recent development, and other explanations are possible. > > Most likely, other providers are blocking google groups as a known source > of spam. > > Thanks for all the replies, but as I've have just seen a pile of messages, some of which date back to 28/03/2012, I'd hazard a guess that something somewhere was wrong and has now been fixed :) Or ... ? -- Cheers. Mark Lawrence. From mhrivnak at hrivnak.org Mon Apr 2 18:10:18 2012 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Mon, 2 Apr 2012 18:10:18 -0400 Subject: Problem connecting to SMTP/IMAP server using SSL In-Reply-To: <722270ac-367f-4058-84ed-92ba10f4516a@ur9g2000pbc.googlegroups.com> References: <722270ac-367f-4058-84ed-92ba10f4516a@ur9g2000pbc.googlegroups.com> Message-ID: That method uses the default port 993. Can you connect to that port at all from your computer? For example, try using a telnet client. Michael On Sat, Mar 31, 2012 at 1:39 AM, Julien wrote: > Hi, > > I'm able to connect to an Exchange server via SMTP and IMAP from my > iPhone using SSL and without using a VPN. So I would expect to be able > to do the same from my computer using Python. > > However, the following hangs and times out on my computer when I'm not > connected to the VPN: > >>>> import imaplib >>>> imap = imaplib.IMAP4_SSL("my.server.address") > > If I am connected to the VPN, then it works fine. > > Do you know why it won't work with SSL and without the VPN? Am I > missing something? > > Thanks a lot, > > Julien > -- > http://mail.python.org/mailman/listinfo/python-list From emile at fenx.com Mon Apr 2 18:17:51 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 02 Apr 2012 15:17:51 -0700 Subject: Python-URL! - weekly Python news and links (Mar 31) In-Reply-To: References: Message-ID: On 3/31/2012 8:38 AM Cameron Laird said... > And it's time to bring "Python-URL!" to a close. Three cheers for your efforts over the years keeping this going. Many heartfelt thanks, Emile From jphalip at gmail.com Mon Apr 2 18:25:25 2012 From: jphalip at gmail.com (Julien) Date: Mon, 2 Apr 2012 15:25:25 -0700 (PDT) Subject: Problem connecting to SMTP/IMAP server using SSL References: <722270ac-367f-4058-84ed-92ba10f4516a@ur9g2000pbc.googlegroups.com> Message-ID: Hi Michael, Thanks for your reply. I did try port 993. I know that port generally works for me, as I can access the Gmail IMAP/SMTP server using SSL. It also works for that other Exchange server but only when the VPN is turned on. Somehow my iPhone works fine without a VPN, as long as it uses SSL. So I'm really unsure why I can't achieve the same thing from my laptop using imaplib.IMAP4_SSL() without the VPN turned on. Thank you, Julien On Apr 2, 3:10?pm, Michael Hrivnak wrote: > That method uses the default port 993. ?Can you connect to that port > at all from your computer? ?For example, try using a telnet client. > > Michael > > On Sat, Mar 31, 2012 at 1:39 AM, Julien wrote: > > Hi, > > > I'm able to connect to an Exchange server via SMTP and IMAP from my > > iPhone using SSL and without using a VPN. So I would expect to be able > > to do the same from my computer using Python. > > > However, the following hangs and times out on my computer when I'm not > > connected to the VPN: > > >>>> import imaplib > >>>> imap = imaplib.IMAP4_SSL("my.server.address") > > > If I am connected to the VPN, then it works fine. > > > Do you know why it won't work with SSL and without the VPN? Am I > > missing something? > > > Thanks a lot, > > > Julien > > -- > >http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Mon Apr 2 18:38:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Apr 2012 08:38:13 +1000 Subject: string interpolation for python In-Reply-To: <1333381766.14038.YahooMailNeo@web121504.mail.ne1.yahoo.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> <1333367201.47465.YahooMailNeo@web121506.mail.ne1.yahoo.com> <1333381766.14038.YahooMailNeo@web121504.mail.ne1.yahoo.com> Message-ID: On Tue, Apr 3, 2012 at 4:56 AM, Steven D'Aprano wrote: > On Tue, 03 Apr 2012 00:58:38 +1000, Chris Angelico wrote: > >> I can't find a way to use an argument more than once, >> without switching to "dictionary mode" and using keys for everything. > > Ack. > > In this case, you can use format: > >>>> "Hello {0}, what's up with {1}? Hey, {0} I'm speaking to you!".format > ('George', 'Melissa') > "Hello George, what's up with Melissa? Hey, George I'm speaking to you!" Yes, it's possible with that version but not with % formatting. (Is your "Ack" short for "Acknowledgement", or is it an ejaculation of disgust?) On Tue, Apr 3, 2012 at 1:49 AM, Yingjie Lan wrote: > Then we can have: >>>>?d"sin($x$) = $ sin(x):0.3f $" > get translated to: >>>> ''.format_join(["sin(%s",x,") = %0.3f", sin(x)]) > This seems to be at least as good in performance. Or don't bother with the initial string, and simply pass everything as arguments: def yingjie_format(*args): it=iter(args) return ''.join(s%next(it,None) for s in it) yingjie_format("sin(%s",x,") = %0.3f", sin(x)) Tested and working (Python 3.2 on Windows). Okay, the generator's a bit cryptic, but you could do the same with a more explicit loop if you prefer. > Syntax highlighting: can be done more creatively. > For dynamic strings, string parts are like normal > strings, but the embedded expressions are like > normal expressions :) So if they're exactly like normal expressions, why not simply use normal expressions? >> sprintf("UPDATE tablename SET modified=now()%{,%s=:%[0]s%} WHERE >> key=%d",array_of_field_names,primary_key_value) >> --> "UPDATE tablename SET modified=now(),foo=:foo,bar=:bar,quux=:quux >> WHERE key=1234" >> >> You're still paying for no complexity you aren't actually using. >> It's?clear and readable. > > You are really good at that. Maybe not everybody is as > experience as you, and I suppose the learning curve is > kind of hard to climb. Yes, it takes some learning to use it. But that's true of everything, no less of your magical string interpolation. My point is that simple examples should be (and are, with printf formatting) simple, such that you only get those more complicated format strings when you're actually doing a complicated job (in that case, taking each element of an array and using it twice - actually, it was taking the indices of a mapping that would end up being passed to the DB query function, thus providing values to the :foo :bar variables). > Those expressions are embedded, you don't need eval() > to have the result though. Are we on the same page? I can see three implementation paths: 1) Language feature. It really *is* just an expression. There's no way that a user can provide them, so there's actually no similarity to eval. But this requires that Python itself handle things. 2) Precompiler. It *becomes* an expression. Again, perfectly safe, although I don't know how useful this really is. 3) Functoin. As several have suggested, you could do some magic and use d("this is a $dollar$ $interpolated$ string") to implement. For this, you *will* need eval (or something like it). >> Here's a recommendation: Write a parser for your notation that turns >> it into executable Python code (that is, executable in Python 3.3 >> without any d"..." support). > > You mean a translator? Yes. It translates your dollar-strings into something that's legal Python 3.3 syntax - either calls to a function like I provided above, or actual embedded expressions. > The syntax is essential for compatibility. > We must distinguish dynamic strings from common strings. > They will live peacefully together. > (escaping the '$' in normal strings breaks compatibility, > and the consequence of forgetting to escape could be > disastrous, so definitely not an option). > > May be d" is too tiny, $"..." is easier to pick out. I don't like the use of symbols like that; can someone, glancing at your code, tell whether $ is an operator, a name, or something else? The original d is probably better for that. ChrisA From mhrivnak at hrivnak.org Mon Apr 2 18:48:45 2012 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Mon, 2 Apr 2012 18:48:45 -0400 Subject: why can't I pickle a class containing this dispatch dictionary? In-Reply-To: <9ee32123-6672-41f9-bdea-5ac075c71093@db5g2000vbb.googlegroups.com> References: <9ee32123-6672-41f9-bdea-5ac075c71093@db5g2000vbb.googlegroups.com> Message-ID: Pickle cannot pickle a reference to an instance method. So the problem is that self.myDict has values which are references to instance methods. Without questioning what this is trying to do or why (I assume it's a proof of concept), here is a way to make it picklable: http://pastebin.com/1zqE52mD Michael On Mon, Apr 2, 2012 at 7:17 AM, jkn wrote: > Hi All > ? ?I'm clearly not understanding the 'can't pickle instancemethod > objects' error; can someone help me to understand, & maybe suggest a > workaround, (apart from the obvious if ... elif...). > > I'm running Python 2.6 on an embedded system. > > == testpickle.py == > import pickle > > class Test(object): > ? ?def __init__(self): > ? ? ? ?self.myDict = { > ? ? ? ? ? ?1: self.tag1, > ? ? ? ? ? ?2: self.tag2 > ? ? ? ? ? ?} > ? ?def dispatch(self, v): > ? ? ? ?try: > ? ? ? ? ? ?self.myDict[v]() > ? ? ? ?except KeyError: > ? ? ? ? ? ?print "No corresponding dictionary entry!" > ? ? ? ?# > ? ?def tag1(self): > ? ? ? ?print "one" > ? ?def tag2(self): > ? ? ? ?print "two" > > > t = Test() > t.dispatch(1) > t.dispatch(2) > t.dispatch(0) > > fd = open("pickle.out", "w") > pickle.dump(t, fd) > fd.close() > # EOF > > $ python testpickle.py > one > two > No corresponding dictionary entry! > Traceback (most recent call last): > ?File "ptest.py", line 29, in > ? ?pickle.dump(t, fd) > ?File "/usr/lib/python2.6/pickle.py", line 1362, in dump > ? ?Pickler(file, protocol).dump(obj) > ?File "/usr/lib/python2.6/pickle.py", line 224, in dump > ? ?self.save(obj) > ?File "/usr/lib/python2.6/pickle.py", line 331, in save > ? ?self.save_reduce(obj=obj, *rv) > ?File "/usr/lib/python2.6/pickle.py", line 419, in save_reduce > ? ?save(state) > ?File "/usr/lib/python2.6/pickle.py", line 286, in save > ? ?f(self, obj) # Call unbound method with explicit self > ?File "/usr/lib/python2.6/pickle.py", line 649, in save_dict > ? ?self._batch_setitems(obj.iteritems()) > ?File "/usr/lib/python2.6/pickle.py", line 663, in _batch_setitems > ? ?save(v) > ?File "/usr/lib/python2.6/pickle.py", line 286, in save > ? ?f(self, obj) # Call unbound method with explicit self > ?File "/usr/lib/python2.6/pickle.py", line 649, in save_dict > ? ?self._batch_setitems(obj.iteritems()) > ?File "/usr/lib/python2.6/pickle.py", line 663, in _batch_setitems > ? ?save(v) > ?File "/usr/lib/python2.6/pickle.py", line 306, in save > ? ?rv = reduce(self.proto) > ?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 instancemethod objects > $ > > > ? ?Thanks > ? ?J^n > > -- > http://mail.python.org/mailman/listinfo/python-list From malaclypse2 at gmail.com Mon Apr 2 19:17:47 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 2 Apr 2012 19:17:47 -0400 Subject: Python Script Works Locally But Not Remotely with SSH In-Reply-To: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> References: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> Message-ID: On Tue, Mar 27, 2012 at 8:51 PM, goldtech wrote: > I have a WinXP PC running an SSH server and I have a Linux PC with an > SSH client ?and logged into the XP seemingly OK. It's all on my > personal LAN, the connection seems OK. > > I have a py file on the XP that I run via SSH from the Linux, it's: > > import webbrowser > webbrowser.open('www.google.com') > > This runs OK started on the local XP PC, the browser Firefox opens and > goes to the site, or it opens a tab to the site. But executing that > same file via SSH does not open Firefox...doing it via SSH starts > Firefox ( I see it begin in the process manager and I see web > activity) but Firefox does not open it's window. > > Why the does the window not open when the script is started remotely? How are you running the ssh server on the windows machine? Is it a windows service? If so, what user does it run as, and is the service configured to be allowed to interact with the desktop? IIRC, by default most windows services run as a different user than you, and do not have permission to interact with your desktop session. You may be able to get the firefox window to pop up on the ssh server machine if you allow it to interact with the desktop, assuming that's what you're trying to do. Jerry From steve+comp.lang.python at pearwood.info Mon Apr 2 19:18:48 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2012 23:18:48 GMT Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> <1333367201.47465.YahooMailNeo@web121506.mail.ne1.yahoo.com> <1333381766.14038.YahooMailNeo@web121504.mail.ne1.yahoo.com> Message-ID: <4f7a33d8$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 Apr 2012 08:38:13 +1000, Chris Angelico wrote: > (Is your > "Ack" short for "Acknowledgement", or is it an ejaculation of disgust?) Acknowledgement. -- Steven From astan.chee at gmail.com Mon Apr 2 19:19:05 2012 From: astan.chee at gmail.com (Astan Chee) Date: Mon, 2 Apr 2012 16:19:05 -0700 (PDT) Subject: simple rsa from javascript to python Message-ID: <2aaac386-2223-4f70-aee5-a584dba5199a@r2g2000pbs.googlegroups.com> Hi, I've got a simple javascript that looks like this: var public_key_mod = "B99808B881F3D8A620F043D70B89674C0A120417FBD3690B3472589C641AD5D422502D0B26CADF97E2CB618DDDBD06CA0619EBBFB328A2FA31BD0F272FE3791810546E04BF42F05DB620FC7B4D0A2EAA17C18FF30C84D93341205C1D6EAD6ACBF2F08E334049DEBF31555CF164AD5CCE437B1AB5EFFEE1FF38552B63EDEF74861E665D90D5AB76D85F5242F42BA29F20EC64553D08020C1E37909341A25F339F802A83EE65E1559AC1CDFE0837160759770D27A058CED0C3771356BCAC8739A0FEF8F344CF64833CDDECC41BBE76BB2F1F8229EB04C72FABA91E4798A3DDFD9100A5171490B30F30EAADF6FDA7677F63CD77D1E6E88F79A6CED5A4966DD6459F"; var public_key_exp = "010001"; var my_text = "this is a text.,)"; var public_key = RSA.getPublicKey( public_key_mod, public_key_exp ); var encrypted_text = RSA.encrypt( my_text, public_key ); and I'm trying to convert this into python and I'm rather stuck with pycrypto as there is no example on how to make the public key with a mod and exponent (or I've probably missed it). Thanks for any help! From python.list at tim.thechases.com Mon Apr 2 19:28:58 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 02 Apr 2012 18:28:58 -0500 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: <4F7A363A.6010501@tim.thechases.com> > PHP is a language that I wish would die off quickly and > gracefully. I feel like the good things of PHP have already > been subsumed into the ecosystems of stronger programming > languages (including Python). The one killer feature PHP has to offer over other languages: ease of efficient deployment on cheap/free hosting. When I go to deploy Python projects, it ends up either being as slow CGI on the cheap/free hosting, or it ends up needing WSGI/gunicorn/whatever on a more expensive service (whether shared, VPS, or full hardware). I dream of a day that deploying Python/Django apps is as cheap/easy as deploying PHP code. -tkc From jurgenex at hotmail.com Mon Apr 2 19:52:35 2012 From: jurgenex at hotmail.com (Jürgen Exner) Date: Mon, 02 Apr 2012 16:52:35 -0700 Subject: Is Programing Art or Science? References: <87vclhn6u2.fsf@kuiper.lan.informatimago.com> Message-ID: "Pascal J. Bourguignon" wrote: >ccc31807 writes: > >> Programming is neither an art nor a science, but a trade. Oh, that's why it is tought in trade schools alongside butchery, plumbing, masonry, and chimney sweeping and why you don't find any programming classes at university. jue From emile at fenx.com Mon Apr 2 20:04:51 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 02 Apr 2012 17:04:51 -0700 Subject: Is Programing Art or Science? In-Reply-To: References: <87vclhn6u2.fsf@kuiper.lan.informatimago.com> Message-ID: On 4/2/2012 4:52 PM J?rgen Exner said... > "Pascal J. Bourguignon" wrote: >> ccc31807 writes: >> >>> Programming is neither an art nor a science, but a trade. > > Oh, that's why it is tought in trade schools alongside butchery, > plumbing, masonry, and chimney sweeping Yes -- back when we opened our first programming/consulting shop in 1999, our first employee was a trade school grad -- maybe ICS or ICT in San Francisco? > and why you don't find any > programming classes at university. Nobody said that the only option to learn programming was in university. Lots of us self-taught well before then.... Emile From soto_andres at yahoo.com Mon Apr 2 20:14:31 2012 From: soto_andres at yahoo.com (Andres Soto) Date: Mon, 2 Apr 2012 17:14:31 -0700 (PDT) Subject: How I can draw the grid lines at intervals with step=1? Message-ID: <1333412071.45680.YahooMailNeo@web30604.mail.mud.yahoo.com> Hi I am trying to draw a step (or staircase) function. My points are all integers. I would like that the grid lines help to identify the limits of each line, but when I draw the grid, it is set each 5 units. How can I draw the grid lines at intervals with step=1? Thanks for your help in advance Regards Andres? -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Mon Apr 2 20:25:55 2012 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 2 Apr 2012 17:25:55 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <28983178-6745-438c-937d-cc6349aa18b1@t8g2000pbe.googlegroups.com> Message-ID: On Apr 2, 2:50?pm, Chris Angelico wrote: > On Fri, Mar 30, 2012 at 2:48 AM, Steve Howell wrote: > > I agree with you on the overall point, but I think that Python > > actually does a fine job of replacing REXX and PHP. ?I've used both of > > the latter (and, of course, Python). ?REXX and PHP are great at what > > they do, but I don't think their slight advantages over Python justify > > all the weight they carry--incompatible syntax to Python, archaic > > libraries, missing modern language features, etc. > > I think you're probably right about REXX, mainly because it's somewhat > old now. It was an awesome language when I first met it back in the > 1990s; it tied in very nicely with OS/2, it was (and is) easy to > extend and embed with C, it had excellent GUI facilities (as long as > you don't need it to be cross-platform). But today, REXX is somewhat > outclassed. I don't recommend it to people for most tasks, unless > they're actually on OS/2 (in which case they probably know it > already). Unicode support and cross-platform GUI toolkits would > probably be REXX's two biggest lacks. > > As to PHP? I don't think it's "great at what [it] [does]", frankly. At > least, it's not great at what it's often used for. PHP is adequate as > a "variant of HTML that allows scripting", but it's usually used today > as though it were a CGI script, and for that it's less than optimal. > For instance, you can't have an include file without it also being an > entry point of its own (eg someone could go tohttp://www.example.com/common_functions.php), so you need code to > protect against that. Huge frameworks have such code peppered > throughout. > > (As a side point, I don't believe that a web server's CGI scripts > should be updated simply by writing to the disk. It's pretty easy to > get non-atomicity problems when you have a page and its include file. > There ARE other options, but I don't know of any efficient ways to do > it in Python.) > > > Python should also be a perfectly good superset of Bash Scripting > > language. ?(To the extent that Python isn't, there's nothing intrinsic > > about the language that prevents you from orchestrating processes.) > > Hmm... How do you pipe one command's output into another's input using > Python? It's not nearly as clean as it is in bash. > For pipes, I'd still call out to bash. I know that's cheating, but the idea is that Python can wrap all the good parts of bash while still allowing you to use Python's more modern syntax, standard library, etc. From clp2 at rebertia.com Mon Apr 2 20:34:36 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Apr 2012 17:34:36 -0700 Subject: How I can draw the grid lines at intervals with step=1? In-Reply-To: <1333412071.45680.YahooMailNeo@web30604.mail.mud.yahoo.com> References: <1333412071.45680.YahooMailNeo@web30604.mail.mud.yahoo.com> Message-ID: On Mon, Apr 2, 2012 at 5:14 PM, Andres Soto wrote: > Hi > I am trying to draw a step (or staircase) function. My points are all > integers. I would like that the grid lines help to identify the limits of > each line, but when I draw the grid, it is set each 5 units. > How can I draw the grid lines at intervals with step=1? What drawing/plotting/charting library are you using? Cheers, Chris From python at bdurham.com Mon Apr 2 21:06:54 2012 From: python at bdurham.com (python at bdurham.com) Date: Mon, 02 Apr 2012 21:06:54 -0400 Subject: Python-URL! - weekly Python news and links (Mar 31) In-Reply-To: References: Message-ID: <1333415214.6421.140661057528561.7C9E6027@webmail.messagingengine.com> Thanks for all your hard work - I learned a lot by visiting the links you guys gathered over the years. Best regards, Malcolm From wolftracks at invalid.com Mon Apr 2 21:41:30 2012 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 02 Apr 2012 18:41:30 -0700 Subject: Cannot remove PIL, numpy lib from XP Message-ID: Well, it looks like I cannot remove PIL with control panel remove/add. The dialog just flashes when I push the button. I tried on an old program not in use, and it did respond as one would want. My guess is that I should not have started with removing Python 2.5.2 first. How do I get out of this bind? From nagle at animats.com Mon Apr 2 21:53:54 2012 From: nagle at animats.com (John Nagle) Date: Mon, 02 Apr 2012 18:53:54 -0700 Subject: getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit In-Reply-To: References: Message-ID: On 4/1/2012 1:41 PM, John Nagle wrote: > On 4/1/2012 9:26 AM, Michael Torrie wrote: >> On 03/31/2012 04:58 PM, John Nagle wrote: >> Removed all "search" and "domain" entries from /etc/resolve.conf > > It's a design bug in glibc. I just submitted a bug report. > > http://sourceware.org/bugzilla/show_bug.cgi?id=13935 > > It only appears if you have a machine with a two-component domain > name ending in ".com" as the actual machine name. Most hosting > services generate some long arbitrary name as the primary name, > but I happen to have a server set up as "companyname.com". > > The default rule for looking up domains in glibc is that the > "domain" is everything after the FIRST ".". Failed lookups > are retried with that "domain" appended. The idea, back > in the 1980s, was that if you're on "foo.bigcompany.com", > and look up "bar", it's looked up as "bar.bigcompany.com". > This idea backfires when the actual hostname only > has two components, and the search just appends ".com". > > There is a "com.com" domain, and this gets them traffic. > They exploit this to send you (where else) to an ad-heavy page. > Try "python.com.com", for example,and you'll get an ad for a > Java database. > > The workaround in Python is to add the AI_CANONNAME flag > to getaddrinfo calls, then check that the returned domain > name matches the one put in. That workaround won't work for some domains. For example, >>> socket.getaddrinfo(s,"http",0,0,socket.SOL_TCP,socket.AI_CANONNAME) [(2, 1, 6, 'orig-10005.themarker.cotcdn.net', ('208.93.137.80', 80))] Nor will addiing options to /etc/resolv.conf work well, because that file is overwritten by some system administration programs. I may have to bring in "dnspython" to get a reliable DNS lookup. John Nagle From lanyjie at yahoo.com Mon Apr 2 21:57:22 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 2 Apr 2012 18:57:22 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com> <1333367201.47465.YahooMailNeo@web121506.mail.ne1.yahoo.com> <1333381766.14038.YahooMailNeo@web121504.mail.ne1.yahoo.com> Message-ID: <1333418242.79886.YahooMailNeo@web121505.mail.ne1.yahoo.com> >>> I can't find a way to use an argument more than once, >>> without switching to "dictionary mode" and using keys for >>> everything. Even in "dictionary mode", the key is spelled more than once. The "tuple mode" below seems to save some typing.? However, when there are more and more items to format,? the readability?deteriorates quickly in the "tuple" mode. Use an argument more than once is, after all, probably a not-so-often use case. The "dictionary mode" greatly enhances readability, but? you have?to provide a dict object and make sure the name in? your?formatting string matches?the keys in the dictionary. And this matching requirement is because of information redundancy in the arrangement. And information redundancy is often the root of evil for various kinds of trouble. Dynamic string seems to have the good without redundancy. And there is no need to build a dict for it.? However, when there is already the dict for use,? clearly the dict format is the winner. >> Ack. >> >> In this case, you can use format: >> >>>>> "Hello {0}, what's up with {1}? Hey, {0} I'm > speaking to you!".format >> ('George', 'Melissa') >> "Hello George, what's up with Melissa? Hey, George I'm > speaking to you!" > > Or don't bother with the initial string, and simply pass everything as > arguments: > > def yingjie_format(*args): > ? ? it=iter(args) > ? ? return ''.join(s%next(it,None) for s in it) > yingjie_format("sin(%s",x,") = %0.3f", sin(x)) >? That's very nice, thanks! > So if they're exactly like normal expressions, why not simply use > normal expressions? I think use dynamic strings can have these benefits: 1) you less keys (punch less keys). 2) better readability (less clutters) 3) you don't have to explicit convert/format expressions into strings 4) better performance too (adding strings together is generally slow). ? >>> sprintf("UPDATE tablename SET modified=now()%{,%s=:%[0]s%} WHERE >>> key=%d",array_of_field_names,primary_key_value) >>> --> "UPDATE tablename SET > modified=now(),foo=:foo,bar=:bar,quux=:quux >>> WHERE key=1234" >>> >>> You're still paying for no complexity you aren't actually > using. >>> It's?clear and readable. >> >> You are really good at that. Maybe not everybody is as >> experience as you, and I suppose the learning curve is >> kind of hard to climb. > > Yes, it takes some learning to use it. But that's true of everything, > no less of your magical string interpolation. My point is that simple > examples should be (and are, with printf formatting) simple, such that > you only get those more complicated format strings when you're > actually doing a complicated job (in that case, taking each element of > an array and using it twice - actually, it was taking the indices of a > mapping that would end up being passed to the DB query function, thus > providing values to the :foo :bar variables). >? Sure. But if one thing does well on both simple and complex? situations, why not that thing? >> Those expressions are embedded, you don't need eval() >> to have the result though. Are we on the same page? > > I can see three implementation paths: > > 1) Language feature. It really *is* just an expression. There's no way > that a user can provide them, so there's actually no similarity to > eval. But this requires that Python itself handle things. > > 2) Precompiler. It *becomes* an expression. Again, perfectly safe, > although I don't know how useful this really is. > > 3) Functoin. As several have suggested, you could do some magic and > use d("this is a $dollar$ $interpolated$ string") to implement. For > this, you *will* need eval (or something like it). >? Sure. for 1), things can be done most conveniently and efficiently. for 2), yeah, not sure how useful it is. for 3), maybe can let str class have a property like: dy. which can do all the dirty processing. Then we may do: >>> x = 0 >>> "sin($x$) = $sin(x)$".dy 'sin(0) = 0.0' Not much burden to use except for the CPU, I suppose. >> You mean a translator? > > Yes. It translates your dollar-strings into something that's legal > Python 3.3 syntax - either calls to a function like I provided above, > or actual embedded expressions. > >> The syntax is essential for compatibility. >> We must distinguish dynamic strings from common strings. >> They will live peacefully together. >> (escaping the '$' in normal strings breaks compatibility, >> and the consequence of forgetting to escape could be >> disastrous, so definitely not an option). >> >> May be d" is too tiny, $"..." is easier to pick out. > > I don't like the use of symbols like that; can someone, glancing at > your code, tell whether $ is an operator, a name, or something else? > The original d is probably better for that. >? Yeah, the d is probably better.? Cheers, Yingjie From mhrivnak at hrivnak.org Mon Apr 2 21:57:38 2012 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Mon, 2 Apr 2012 21:57:38 -0400 Subject: Problem connecting to SMTP/IMAP server using SSL In-Reply-To: References: <722270ac-367f-4058-84ed-92ba10f4516a@ur9g2000pbc.googlegroups.com> Message-ID: Your phone may be using TLS on the normal IMAP port (143). Or, are you sure your phone is using IMAP and not active sync? Michael On Mon, Apr 2, 2012 at 6:25 PM, Julien wrote: > Hi Michael, > > Thanks for your reply. I did try port 993. I know that port generally > works for me, as I can access the Gmail IMAP/SMTP server using SSL. It > also works for that other Exchange server but only when the VPN is > turned on. > > Somehow my iPhone works fine without a VPN, as long as it uses SSL. So > I'm really unsure why I can't achieve the same thing from my laptop > using imaplib.IMAP4_SSL() without the VPN turned on. > > Thank you, > > Julien > > On Apr 2, 3:10?pm, Michael Hrivnak wrote: >> That method uses the default port 993. ?Can you connect to that port >> at all from your computer? ?For example, try using a telnet client. >> >> Michael >> >> On Sat, Mar 31, 2012 at 1:39 AM, Julien wrote: >> > Hi, >> >> > I'm able to connect to an Exchange server via SMTP and IMAP from my >> > iPhone using SSL and without using a VPN. So I would expect to be able >> > to do the same from my computer using Python. >> >> > However, the following hangs and times out on my computer when I'm not >> > connected to the VPN: >> >> >>>> import imaplib >> >>>> imap = imaplib.IMAP4_SSL("my.server.address") >> >> > If I am connected to the VPN, then it works fine. >> >> > Do you know why it won't work with SSL and without the VPN? Am I >> > missing something? >> >> > Thanks a lot, >> >> > Julien >> > -- >> >http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list From ben+python at benfinney.id.au Mon Apr 2 22:06:47 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Apr 2012 12:06:47 +1000 Subject: Python-URL! - weekly Python news and links (Mar 31) References: Message-ID: <87sjglk1qg.fsf@benfinney.id.au> Cameron Laird writes: > I pine for the fjords. > > And it's time to bring "Python-URL!" to a close. "Python-URL!", which > Jean-Claude Wippler and I appear to have launched in 1998, has reached > the end of its utility. Emile van Sebille writes: > On 3/31/2012 8:38 AM Cameron Laird said... > > And it's time to bring "Python-URL!" to a close. > > Three cheers for your efforts over the years keeping this going. And so say all of us! Thanks very much, Cameron and Jean-Claude. -- \ ?Nature hath given men one tongue but two ears, that we may | `\ hear from others twice as much as we speak.? ?Epictetus, | _o__) _Fragments_ | Ben Finney From chiron613.no.spam. at no.spam.please.gmail.com Tue Apr 3 00:26:58 2012 From: chiron613.no.spam. at no.spam.please.gmail.com (Chiron) Date: Tue, 03 Apr 2012 04:26:58 GMT Subject: Is Programing Art or Science? References: Message-ID: On Fri, 30 Mar 2012 01:27:16 -0700, Xah Lee wrote: > ?Is Programing Art or Science? Why is this question important? -- You are confused; but this is your normal state. From drsalists at gmail.com Tue Apr 3 00:53:28 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 Apr 2012 21:53:28 -0700 Subject: How do I use PyGTK to put text besides clickable buttons? In-Reply-To: References: Message-ID: You could use an hbox. Or rather, a vbox with a bunch of hbox's in it. On Thu, Mar 29, 2012 at 10:45 PM, Jason Hsu, Mr. Swift Linux < jhsu802701 at gmail.com> wrote: > I've decided to use PyGTK instead of gtkdialog for providing > configuration menus/dialog boxes in Swift Linux, the Linux distro I > started. The problem with gtkdialog is that the i386 version is no > longer available in the Debian repository. > > Since a picture is worth a thousand words, I'll give you a link to a > screenshot of antiX Linux: > http://antix.freeforums.org/download/file.php?id=23 > > How do I use PyGTK to create something similar to the logout dialog > box in the above graphic? I've figured out how to create clickable > buttons that each run a different script. What I haven't figured out > is how to add text beside each button. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.alexander.rice at gmail.com Tue Apr 3 00:55:28 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 3 Apr 2012 00:55:28 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> Message-ID: On Sun, Apr 1, 2012 at 11:18 PM, alex23 wrote: > On Mar 30, 3:37?pm, Nathan Rice > wrote: >> We live in a world where the tools that are used are based on >> tradition (read that as backwards compatibility if it makes you feel >> better) and as a mechanism for deriving personal identity. ?The world >> is backwards and retarded in many, many ways, this problem is >> interesting to me because it actually cuts across a much larger tract >> than is immediately obvious. > > Do you produce commercial code in a team? Because going by your > absolutist bullshit here, it certainly doesn't sound like it. Think of me like the Wolf, the cleaner in pulp fiction that Marcellis Wallis calls in to take care of the mess when Jules accidentally blows a kid's brains out in the back of a car. I get called in when my skills are needed, and when the mess has been handled and things are back to normal I take my leave. > When I join an organisation that requires language A as all of its > systems are written in it, is that 'tradition' or 'personal identity'? > How is 'compatibility' - either with existing systems or existing > *developers* - a "backwards and retarded" approach to complex > problems? I don't care what people do related to legacy systems. There will always be a COBOL. I do care about programmers that are too lazy to learn, and would be happy to ignore the fact that programming is hard for most people to learn, so they can continue not learning. Those programmers are scumbags. Just don't let me hear you complaining because some syntax is not "C like" enough for you. Whenever I hear that I want to strangle the self-serving 'tard that wrote it. When I see people defending "C like" syntax as optimal or somehow much more expressive, that makes me doubly irritated. These are the people who are selfishly defending the status quo because they're invested. If you're going to be selfish and inconsiderate at least be honest about it, rather than pretending that one of the earliest languages somehow got almost everything right and should be the basis for new languages till the end of time. This goes for most of the ALGOL derived languages. I don't have a problem if you know your language well and are happy using it, that's great. Don't try to delude people that our modern ALGOL derivatives are the best possible way to model knowledge (including process knowledge) to a computer, because that is a lie. > If I've chosen language A because some aspect of its syntax maps > better onto my mind (or for _whatever_ reason that makes individuals > prefer one language to another), and you've chosen language B: who > gets to decide which is the 'superior' language, which is the 'better' > mapping etc? You should be able to live in your reality if you want, as long that doesn't impinge on others. Of course, if you disagree on basic grammar, then I would have to ask you, do you disagree about English grammar, or have you accepted it so that you can communicate with people? This is why I advocate following English grammar closely for syntax - people have accepted it and don't make a big deal, and it is the way we represent information already. > You're arguing for a top-down centralised approach to language > development that just will _never_ exist, simply because it cannot. If > you don't accept that, I believe there's a fascinating fork called > "Python 4000" where your ideas would be readily adopted. You completely missed my point. In fact, my argument is for a bottom up approach, with a meeting point which is much closer than the machine code which is currently used. However you want to represent it, the knowledge is the same, and that is what matters. We need to get past the idea of different, incompatible languages, and settle on a common knowledge representation format that underlies all languages, and is compatible. If you want to make an alex23 DSL where up is down and inside is upside down, go for it, just as long as it is represented in a sensible set of semantic primes that I can transform to whatever reality I want. From nobody at nowhere.com Tue Apr 3 01:12:44 2012 From: nobody at nowhere.com (Nobody) Date: Tue, 03 Apr 2012 06:12:44 +0100 Subject: simple rsa from javascript to python References: <2aaac386-2223-4f70-aee5-a584dba5199a@r2g2000pbs.googlegroups.com> Message-ID: On Mon, 02 Apr 2012 16:19:05 -0700, Astan Chee wrote: > and I'm trying to convert this into python and I'm rather stuck with > pycrypto as there is no example on how to make the public key with a mod > and exponent (or I've probably missed it). from Crypto.PublicKey import RSA mod = long("B99808B881F3D8A...", 16) # truncated for clarity exp = long("010001", 16) rsa = RSA.construct((mod, exp)) From wuwei23 at gmail.com Tue Apr 3 01:40:31 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 2 Apr 2012 22:40:31 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> Message-ID: <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> On Apr 3, 2:55?pm, Nathan Rice wrote: > I don't care what people do related to legacy systems. And that's what earns you the label 'architecture astronaut'. Legacy systems are _part_ of the problem; it's very easy to hold to a purist approach when you ignore the bulk of the domain that causes the issues. There's _never_ going to be an InfoTech3k where we just stop supporting older code. > I do care about programmers that are too lazy to > learn, and would be happy to ignore the fact that programming is hard > for most people to learn, so they can continue not learning. ?Those > programmers are scumbags. Wait, what? Programmers are both "too lazy to learn" and yet somehow happy that the skills they've acquired are "too hard for most people to learn"? So how did they learn them? And they're also somehow "lazy" because they have to learn multiple languages to be effective, rather than one mythical ur-language? In my 20 years as a software developer, I have _never_ encountered anyone trying to deliberately expand the knowledge gap. This isn't a priesthood. > Just don't let me hear you complaining because some syntax is not "C > like" enough for you. ?Whenever I hear that I want to strangle the > self-serving 'tard that wrote it. ?When I see people defending "C > like" syntax as optimal or somehow much more expressive, that makes me > doubly irritated. ?These are the people who are selfishly defending > the status quo because they're invested. Syntax is never the issue, it's the deeper semantics. Is the scoping of one C-like language the same as C? How does it differ? Why does it differ? Is the difference a fundamental implementation issue that you really need to know before you actually grok the language? Are functions first-class objects? Are they actual objects or some kind of magical stub? Can you extend those objects with properties? etc etc Every language tackles _so many_ things differently. It's not lazy to say that you prefer something to resemble/be based on a language you have experience with, that's human nature. If you're insistent that your non-typical syntax is so much better, the onus is on you to prove it, not to insist that the lack of uptake is 'laziness'. And one again: code is _communication_. Not having to understand new optimal patterns for every single language is a Good Thing. > Don't try to delude people that our modern > ALGOL derivatives are the best possible way to model knowledge > (including process knowledge) to a computer, because that is a lie. Um, okay, I'll stop doing that...not that I've ever seen anyone make that claim... A large part of what makes languages popular _is their popularity_. In many ways, ALGOL is English to your hypothetical language's Lojban. You can argue until the end of time for the superiority of Lojban due to it's lack of ambiguity, it's not going to affect it's acquisition at all. > You should be able to live in your reality if you want, as long that > doesn't impinge on others. ?Of course, if you disagree on basic > grammar, then I would have to ask you, do you disagree about English > grammar, or have you accepted it so that you can communicate with > people? ?This is why I advocate following English grammar closely for > syntax - people have accepted it and don't make a big deal, and it is > the way we represent information already. And programmers have accepted ALGOL and don't etc The idea of coding in English just fills me with horror and dread. COBOL died for a reason. > > You're arguing for a top-down centralised approach to language > > development that just will _never_ exist, simply because it cannot. If > > you don't accept that, I believe there's a fascinating fork called > > "Python 4000" where your ideas would be readily adopted. > > You completely missed my point. ?In fact, my argument is for a bottom > up approach, with a meeting point which is much closer than the > machine code which is currently used. You missed my point; I was referring more to the _adoption_ of your ur- language. The only way to push this is to force it on everyone. > However you want to represent > it, the knowledge is the same, and that is what matters. ?We need to > get past the idea of different, incompatible languages, and settle on > a common knowledge representation format that underlies all languages, > and is compatible. ?If you want to make an alex23 DSL where up is down > and inside is upside down, go for it, just as long as it is > represented in a sensible set of semantic primes that I can transform > to whatever reality I want. So effectively for any given project I'd need to know: the underlying representation (because we have to be able to discuss _something_ as a team), my DSL, how my DSL transforms to the underlying representation, and to be really effective, every team member's DSL and how it transforms. Because _no one_ on my team works alone, debugs alone 100% of the time. How do I share cool patterns? Show them the underlying representation? How do they copy them? Back trace the representation to their own DSL and reimplement? What if the elegance in my DSL is a nightmare to construct in a peer's? How does my code look to them? Does it even include my identifiers & comments or is the representation too low level for that? How do they debug it? How do we learn? How do we share? From wuwei23 at gmail.com Tue Apr 3 01:47:39 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 2 Apr 2012 22:47:39 -0700 (PDT) Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 2, 7:17?pm, Yingjie Lan wrote: > The other ways are not perfectly good. > They stinks in Python. > This new way is the most natural way. > Effortless, natural. That's my Python. I believe you're looking for the Python 4k project. From xahlee at gmail.com Tue Apr 3 01:53:11 2012 From: xahlee at gmail.com (Xah Lee) Date: Mon, 2 Apr 2012 22:53:11 -0700 (PDT) Subject: Google Tech Talk: lisp at JPL Message-ID: Dearly beloved lisperati, I present you, Ron Garret (aka Erann Gat ? aka Naggum hater and enemy of Kenny Tilton), at Google Tech Talk ?The Remote Agent Experiment: Debugging Code from 60 Million Miles Away? Google Tech Talk, (2012-02-14) Presented by Ron Garret. @ http://www.youtube.com/watch?v=_gZK0tW8EhQ i just started watching, havn't done yet. (thx jcs's blog for the news) PS posted to python and perl forums too, because i think might be interesting for lang aficionados . Reply to just your community please. Xah From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Apr 3 02:24:53 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 03 Apr 2012 08:24:53 +0200 Subject: No os.copy()? Why not? In-Reply-To: References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> Message-ID: Am 02.04.2012 23:11 schrieb HoneyMonster: > One way: > import os > > os.system ("cp src sink") Yes. The worst way you could imagine. Why not the much much better from subprocess subprocess.call(['cp', 'src', 'sink']) ? Then you can call it with (really) arbitrary file names: def call_cp(from, to): from subprocess subprocess.call(['cp', '--', from, to]) Try that with os.system() and from="That's my file"... Thomas From chris at simplistix.co.uk Tue Apr 3 03:04:43 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 03 Apr 2012 08:04:43 +0100 Subject: xlrd 0.7.4 released! Message-ID: <4F7AA10B.6020907@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlrd 0.7.4. This release features the following changes: - Fixed a bug where xlrd was silently truncating long text formula results - Avoid parsing STYLE records when formatting_info=False - More tolerance of out-of-spec files. - Minor performance improvements. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rosuav at gmail.com Tue Apr 3 03:12:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Apr 2012 17:12:56 +1000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <28983178-6745-438c-937d-cc6349aa18b1@t8g2000pbe.googlegroups.com> Message-ID: On Tue, Apr 3, 2012 at 8:05 AM, Dennis Lee Bieber wrote: > On Thu, 29 Mar 2012 08:48:53 -0700 (PDT), Steve Howell > declaimed the following in > gmane.comp.python.general: > > ? ? ? ?REXX is inhibited by the architectures to which it has been ported > -- limiting the ADDRESS targets to variations of Python's os.system() or > popen() calls; even the subprocess module can't get beyond the all or > nothing execution model. > > ? ? ? ?Much different from the original IBM environment (and, biased, the > Amiga implementation may have gone beyond the IBM one in capabilities) > wherein compliant programs become the "command shell" for REXX command > processing -- actual bidirectional interactive interprocess > communication. Window's COM system offers some of that capability, but > buried in a cryptic object programming system -- nothing like having a > script sending the /same/ command that one would use in a text interface > to the target program. Some years ago, I wrote a MUD that used REXX as its scripting language. (The server's still running, but not so much to be a MUD as to be my administrative interface to that particular box. I'm like that with MUDs.) I thought it was really cool to be able to simply put a bare string and have that get sent to the player - for instance: /* Command handler for some particular location in the MUD */ if arg(1)="foo" then do "You begin to foo." /* do some stuff */ "You finish fooing." end Having now built MUDs in Pike, I'm not so impressed with the syntax. But hey, it's a completely different use of the ADDRESS command! :) And of course, I can always use ADDRESS CMD "blah blah" to execute commands. On Tue, Apr 3, 2012 at 10:25 AM, Steve Howell wrote: > On Apr 2, 2:50?pm, Chris Angelico wrote: >> Hmm... How do you pipe one command's output into another's input using >> Python? It's not nearly as clean as it is in bash. > > For pipes, I'd still call out to bash. ?I know that's cheating, but > the idea is that Python can wrap all the good parts of bash while > still allowing you to use Python's more modern syntax, standard > library, etc. So, it's not that Python is a superset of bash, but that Python+bash is a superset of bash. Well, that is certainly understandable. And needn't be too onerous syntactically either: from os import system as x x('do_stuff') ChrisA From lukas.graf.bern at gmail.com Tue Apr 3 03:30:13 2012 From: lukas.graf.bern at gmail.com (Lukas Graf) Date: Tue, 3 Apr 2012 00:30:13 -0700 (PDT) Subject: xlrd 0.7.4 released! In-Reply-To: <4F7AA10B.6020907@simplistix.co.uk> References: <4F7AA10B.6020907@simplistix.co.uk> Message-ID: <21275125.1280.1333438213942.JavaMail.geo-discussion-forums@vbyj18> Hey Chris, On Tuesday, April 3, 2012 9:04:43 AM UTC+2, Chris Withers wrote: > > Hi All, > > I'm pleased to announce the release of xlrd 0.7.4. > There seems to have been a mistake during release of 0.7.4: version.txt referenced in setup.py:24 is missing (forgot MANIFEST?) and therefore the package can't be installed. Getting distribution for 'xlrd'. error: /var/folders/_l/m3y541vx5m1dzgjm6rjljf5w0000gn/T/easy_install-KeGyEg/xlrd-0.7.4/xlrd/version.txt: No such file or directory An error occured when trying to install xlrd 0.7.4. Look above this message for any errors that were output by easy_install. Regards, Lukas -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Tue Apr 3 03:34:27 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 03 Apr 2012 08:34:27 +0100 Subject: [pyxl] xlrd 0.7.4 released! In-Reply-To: <4F7AA10B.6020907@simplistix.co.uk> References: <4F7AA10B.6020907@simplistix.co.uk> Message-ID: <4F7AA803.1020808@simplistix.co.uk> On 03/04/2012 08:04, Chris Withers wrote: > Hi All, > > I'm pleased to announce the release of xlrd 0.7.4. *sigh* As pointed out, I stuffed up the release by not including a new file in the MANIFEST. My bad. I've just release a 0.7.5 that fixes this. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From lukas.graf.bern at gmail.com Tue Apr 3 03:43:34 2012 From: lukas.graf.bern at gmail.com (Lukas Graf) Date: Tue, 3 Apr 2012 00:43:34 -0700 (PDT) Subject: [pyxl] xlrd 0.7.4 released! In-Reply-To: <4F7AA803.1020808@simplistix.co.uk> References: <4F7AA10B.6020907@simplistix.co.uk> <4F7AA803.1020808@simplistix.co.uk> Message-ID: <4547321.1148.1333439014153.JavaMail.geo-discussion-forums@vbvd13> On Tuesday, April 3, 2012 9:34:27 AM UTC+2, Chris Withers wrote: > As pointed out, I stuffed up the release by not including a new file in > the MANIFEST. My bad. > > I've just release a 0.7.5 that fixes this. > Works! Thanks for the quick reaction! Regards, Lukas -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Apr 3 03:54:50 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Apr 2012 09:54:50 +0200 Subject: why can't I pickle a class containing this dispatch dictionary? References: <9ee32123-6672-41f9-bdea-5ac075c71093@db5g2000vbb.googlegroups.com> Message-ID: jkn wrote: > I'm clearly not understanding the 'can't pickle instancemethod > objects' error; can someone help me to understand, I think classes implemented in C need some extra work to make them picklable, and that hasn't been done for instance methods. > & maybe suggest a > workaround, (apart from the obvious if ... elif...). You can implement pickling yourself: import copy_reg import types def pickle_instancemethod(m): return unpickle_instancemethod, (m.im_func.__name__, m.im_self, m.im_class) def unpickle_instancemethod(name, im_self, im_class): im_func = getattr(im_class, name) return im_func.__get__(im_self, im_class) copy_reg.pickle(types.MethodType, pickle_instancemethod) > I'm running Python 2.6 on an embedded system. > > == testpickle.py == > import pickle > > class Test(object): > def __init__(self): > self.myDict = { > 1: self.tag1, > 2: self.tag2 > } > def dispatch(self, v): > try: > self.myDict[v]() > except KeyError: > print "No corresponding dictionary entry!" > # > def tag1(self): > print "one" > def tag2(self): > print "two" > > > t = Test() > t.dispatch(1) > t.dispatch(2) > t.dispatch(0) > > fd = open("pickle.out", "w") > pickle.dump(t, fd) > fd.close() > # EOF > > $ python testpickle.py > one > two > No corresponding dictionary entry! > TypeError: can't pickle instancemethod objects > $ From john_ladasky at sbcglobal.net Tue Apr 3 05:34:33 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Tue, 3 Apr 2012 02:34:33 -0700 (PDT) Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> Message-ID: <5062483b-6419-4ea3-afc0-358cbd735e45@w6g2000pbp.googlegroups.com> I use subprocess.call() for quite a few other things. I just figured that I should use the tidier modules whenever I can. From tfb at tfeb.org Tue Apr 3 05:42:34 2012 From: tfb at tfeb.org (Tim Bradshaw) Date: Tue, 3 Apr 2012 10:42:34 +0100 Subject: Is Programing Art or Science? References: <87vclhn6u2.fsf@kuiper.lan.informatimago.com> Message-ID: On 2012-04-03 00:52:35 +0100, J?rgen Exner said: > Oh, that's why it is tought in trade schools alongside butchery, > plumbing, masonry, and chimney sweeping and why you don't find any > programming classes at university. So, you know, no one would do law or medicine at a university. Oh, wait. From jeanpierreda at gmail.com Tue Apr 3 06:05:20 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 3 Apr 2012 06:05:20 -0400 Subject: Is Programing Art or Science? In-Reply-To: References: Message-ID: On Tue, Apr 3, 2012 at 12:26 AM, Chiron <"chiron613.no.spam."@no.spam.please.gmail.com> wrote: >> ?Is Programing Art or Science? > > Why is this question important? That's the whole point of the article/email. Xah basically says "This question is stupid and only stupid people care about it." You probably should have read the email before replying to it. -- Devin From dev-null at shared-files.de Tue Apr 3 06:17:03 2012 From: dev-null at shared-files.de (Torsten Mueller) Date: Tue, 03 Apr 2012 12:17:03 +0200 Subject: Is Programing Art or Science? References: Message-ID: <3dlimdxgps.fsf@shared-files.de> Xah Lee wrote: > So, is programing a art or science? is it art or science? I really > need to know. Sience? Almost never. It's handcraft. Seldom, in very rare cases, it's true art for a very limited audience, mostly it's routine, and in many cases it's also idiocy. T.M. From acm at muc.de Tue Apr 3 06:42:21 2012 From: acm at muc.de (Alan Mackenzie) Date: Tue, 3 Apr 2012 10:42:21 +0000 (UTC) Subject: Is Programing Art or Science? References: Message-ID: Hi, Xah, In comp.emacs Xah Lee wrote: > For these computing jockeys, there remains the question of why Knuth > named his books the ?Art? of Computer Programing, or why some > computing luminaries litter the caution that programing is as much a > art as science. What elite dimwits need to realize is that these > authors are not defining or correcting, but breaking precepts among > the automatons in programing industry. He was using art in the sense of "the exercise of human skill (as distinguished from nature)". That's the second definition in my dictionary. When people talk about, for example, the art of painting water colours, they mean the techniques of mixing paints, depicting objects on paper, etc. They are not referring to the artistic value of the painting painted. > yours humbly, > > Xah -- Alan Mackenzie (Nuremberg, Germany). From rosuav at gmail.com Tue Apr 3 07:17:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Apr 2012 21:17:00 +1000 Subject: weird behaviour: pygame plays in shell but not in script In-Reply-To: References: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> Message-ID: On Thu, Mar 29, 2012 at 11:41 PM, Mik wrote: > > I can't believe I am so dumb! > > after sound.play() the script was terminating!!!! > I didn't notice that 'play()' actually returns... > > What a nice way to introduce myself to the group!!! :-) > > sorry for bothering you guys :-) You've just proven one of the great benefits of asking a question: you suddenly discover the answer for yourself. It's arguable whether it's primarily caused by the action of coalescing your question into text, or some outworking of Murphy's Law, but both are involved. Welcome to the party. There's some trolls over there *gestures to the corner* and some smart guys over there *gestures to the other corner* and a few snakes and comedians around *gestures to the random pythons and Pythons and Pythons and pythons* and don't forget the lurkers lurking around. Enjoy yourself, learn something, educate someone! Chris Angelico From rodperson at rodperson.com Tue Apr 3 07:37:27 2012 From: rodperson at rodperson.com (Rod Person) Date: Tue, 3 Apr 2012 07:37:27 -0400 Subject: Python Script Works Locally But Not Remotely with SSH In-Reply-To: <12051938.18.1333308736916.JavaMail.geo-discussion-forums@vbtb5> References: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> <12051938.18.1333308736916.JavaMail.geo-discussion-forums@vbtb5> Message-ID: <20120403073727.00002656@unknown> On Sun, 1 Apr 2012 12:32:16 -0700 (PDT) Jedrzej Krzysztof Dec wrote: > > > > Why the does the window not open when the script is started > > remotely? > > > > Thanks. > > Do You have a GUI over SSH? Something like ssh -X in Linux systems, > or do You just have a terminal window? If You just have a terminal, > You wont be able to run GUI apps. > You need an X server on the XP machine. I've use Xming for this. http://sourceforge.net/projects/xming/?_test=b -- Rod Person http://www.rodperson.com rodperson at rodperson.com 'Silence is a fence around wisdom' From sarbaniroy4679 at gmail.com Tue Apr 3 08:22:55 2012 From: sarbaniroy4679 at gmail.com (Sarbani Roy) Date: Tue, 3 Apr 2012 05:22:55 -0700 (PDT) Subject: EARN FROM WORLD BIGGEST COMPANY "GOOGLE ADSENSE" ........ Message-ID: <33423a5c-2451-461b-828d-4528e05403d1@o3g2000pbt.googlegroups.com> DEAR FREND........(Hiiiiiiii) WE HAVE DESIGNED THIS WEBSITE EXCLUSIVELY FOR THE PEOPLE, WHO WANT TO EARN MONEY THROUGH HOME BASED INTERNET JOBS. JUST VISIT:- http://free-home-jobs.yolasite.com WITHOUT ANY INVESTMENT, JUST BY SPENDING FEW HOUS ON INTERNET IN A DAY. (1)EARN BY DOING SIMPLE COMPUTER JOBS. (2)NO GOING OUT OF HOME. (3)NO OFFICE, NO BOSS,NOT A 9 TO 5 JOB. (4)NO EXPERIENCE REQUIRED From nathan.alexander.rice at gmail.com Tue Apr 3 08:39:14 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 3 Apr 2012 08:39:14 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: On Tue, Apr 3, 2012 at 1:40 AM, alex23 wrote: > On Apr 3, 2:55?pm, Nathan Rice > wrote: >> I don't care what people do related to legacy systems. > > And that's what earns you the label 'architecture astronaut'. Legacy > systems are _part_ of the problem; it's very easy to ?hold to a purist > approach when you ignore the bulk of the domain that causes the > issues. There's _never_ going to be an InfoTech3k where we just stop > supporting older code. There are people who are paid pretty well to support crappy old COBOL apps, but I am not among them (nor are you, with very high likelihood), so your "we" is misplaced. For all intents and purposes that software exists in an alternate reality. Remember the tutorial on global vs local optimization I made previously? Let me distill it... If you are unwilling to endure pain to move towards a better world you will always be trapped in a sub-optimal situation. >> I do care about programmers that are too lazy to >> learn, and would be happy to ignore the fact that programming is hard >> for most people to learn, so they can continue not learning. ?Those >> programmers are scumbags. > > Wait, what? > > Programmers are both "too lazy to learn" and yet somehow happy that > the skills they've acquired are "too hard for most people to learn"? > So how did they learn them? > > And they're also somehow "lazy" because they have to learn multiple > languages to be effective, ?rather than one mythical ur-language? > > In my 20 years as a software developer, I have _never_ encountered > anyone trying to deliberately expand the knowledge gap. This isn't a > priesthood. Did you miss the part where I said that most people who learn to program are fascinated by computers and highly motivated to do so? I've never met a BROgrammer, those people go into sales. It isn't because there aren't smart BROmosapiens (sadly, there are), they just couldn't give two shits about computers so programming seems like a colossal waste of time to them. It isn't about people scheming to "dis-empower then plebs" rather it is about people who don't want to move outside their comfort zone. You can talk about people learning multiple languages all you want, but for the most part they will be 10 descendants of ALGOL, with minor variations. Very few people are willing to tackle something like Haskell or ML if they weren't taught functional programming in university, though there are a few that view it as an endurance trial or mountain to climb. Those people get a pass on most of what I've said thus far. >> Just don't let me hear you complaining because some syntax is not "C >> like" enough for you. ?Whenever I hear that I want to strangle the >> self-serving 'tard that wrote it. ?When I see people defending "C >> like" syntax as optimal or somehow much more expressive, that makes me >> doubly irritated. ?These are the people who are selfishly defending >> the status quo because they're invested. > > Syntax is never the issue, it's the deeper semantics. Is the scoping > of one C-like language the same as C? How does it differ? Why does it > differ? Is the difference a fundamental implementation issue that you > really need to know before you actually grok the language? Are > functions first-class objects? Are they actual objects or some kind of > magical stub? Can you extend those objects with properties? etc etc Syntax and semantics are both a big mess right now. That is why I always address them both. > Every language tackles _so many_ things differently. It's not lazy to > say that you prefer something to resemble/be based on a language you > have experience with, that's human nature. If you're insistent that > your non-typical syntax is so much better, the onus is on you to prove > it, not to insist that the lack of uptake is 'laziness'. The winds of change generally blow for programming when generations of older programmers leave the workforce. Alan Kay was a smart man, viewing programming as an educational tool and designing for youth is absolutely the right way to do things. If you try to retrain older programmers, you are basically telling them they have to change decades of learning for a moderate (but not huge) productivity increase, so that programming is accessible to a much wider group of people. Much like with the terminal to GUI transition, you will have people attacking declarative natural language programming as a stupid practice for noobs, and the end of computing (even though it will allow people with much less experience to be more productive than them). > And one again: code is _communication_. Not having to understand new > optimal patterns for every single language is a Good Thing. Code is a horrible medium for communication. If it weren't, I wouldn't be trolling this thread. >> Don't try to delude people that our modern >> ALGOL derivatives are the best possible way to model knowledge >> (including process knowledge) to a computer, because that is a lie. > > Um, okay, I'll stop doing that...not that I've ever seen anyone make > that claim... Computers require you to state the exact words you're searching for as well. Try looking again, and this time allow for sub-categories and synonyms, along with some variation in word order. > A large part of what makes languages popular _is their popularity_. In > many ways, ALGOL is English to your hypothetical language's Lojban. > You can argue until the end of time for the superiority of Lojban due > to it's lack of ambiguity, it's not going to affect it's acquisition > at all. I would say that ALGOL is more like the grunts and gestures of a proto-language. Some day, one or two hundred years from now, computers will be embarrassed that they were ever so obtuse. Kind of like when grown up children finally apologize to their parents for all the trouble they caused when they were younger. >> You should be able to live in your reality if you want, as long that >> doesn't impinge on others. ?Of course, if you disagree on basic >> grammar, then I would have to ask you, do you disagree about English >> grammar, or have you accepted it so that you can communicate with >> people? ?This is why I advocate following English grammar closely for >> syntax - people have accepted it and don't make a big deal, and it is >> the way we represent information already. > > And programmers have accepted ALGOL and don't etc > > The idea of coding in English just fills me with horror and dread. > COBOL died for a reason. COBOL gets brought up every time there is a conversation about natural language programming. Take a break from the thread, program some COBOL, and tell me there is ANYTHING natural about it. On top of that, I imagine you would find many other reasons besides the use of English words that the language deserved to die. >> > You're arguing for a top-down centralised approach to language >> > development that just will _never_ exist, simply because it cannot. If >> > you don't accept that, I believe there's a fascinating fork called >> > "Python 4000" where your ideas would be readily adopted. >> >> You completely missed my point. ?In fact, my argument is for a bottom >> up approach, with a meeting point which is much closer than the >> machine code which is currently used. > > You missed my point; I was referring more to the _adoption_ of your ur- > language. The only way to push this is to force it on everyone. No, most people are too selfish to do something because it is good for others. People learn programming languages because of a "killer app" or lucrative platform... Rails, Django, PHP, javascript (the browser), objective c (the iphone). Again, I defer to Alan Kay who I am quite sure already thought about this issue. Targeting young people and education avoids a lot of the "killer app" chasing and knowledge intertia. Providing a scripting layer for video games is also a viable option. That is modeling a game world, so a declarative language that is designed to model knowledge and systems would be a fairly easy sell. Finally, build a NoSQL database around it. Support both in-memory and distributed processes. It doesn't have to be the fastest, but it does have to be stable and easy to use. >> However you want to represent >> it, the knowledge is the same, and that is what matters. ?We need to >> get past the idea of different, incompatible languages, and settle on >> a common knowledge representation format that underlies all languages, >> and is compatible. ?If you want to make an alex23 DSL where up is down >> and inside is upside down, go for it, just as long as it is >> represented in a sensible set of semantic primes that I can transform >> to whatever reality I want. > > So effectively for any given project I'd need to know: the underlying > representation (because we have to be able to discuss _something_ as a > team), my DSL, how my DSL transforms to the underlying representation, > and to be really effective, every team member's DSL and how it > transforms. Because _no one_ on my team works alone, debugs alone 100% > of the time. People don't walk around using words of their own creation, they get together and agree on terminology for a topic, then stick to it. Additionally, I was suggesting that while you *write* your code in alex23ese, the computer would be able to produce a canonical representation, as a courtesy to you, since you suggested that not being able to write "your way" was somehow horrible or crippling. > How do I share cool patterns? Show them the underlying representation? > How do they copy them? Back trace the representation to their own DSL > and reimplement? What if the elegance in my DSL is a nightmare to > construct in a peer's? How does my code look to them? Does it even > include my identifiers & comments or is the representation too low > level for that? How do they debug it? > > How do we learn? How do we share? Don't think "underlying", instead think "canonical". Ultimately, the answers to your questions exist in the world for you to see. How does a surgeon describe a surgical procedure? How does a chef describe a recipe? How does a carpenter describe the process of building cabinets? Aside from specific words, they all use natural language, and it works just fine. From alec.taylor6 at gmail.com Tue Apr 3 08:43:43 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 3 Apr 2012 22:43:43 +1000 Subject: Is Programing Art or Science? In-Reply-To: References: Message-ID: Programming is neither Art nor Science It's practically maths [pun intended] From jeanmichel at sequans.com Tue Apr 3 08:47:16 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 03 Apr 2012 14:47:16 +0200 Subject: weird behaviour: pygame plays in shell but not in script In-Reply-To: References: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> <0fce59a2-68ac-4c1d-96f5-5e155bcd404e@pg2g2000pbb.googlegroups.com> Message-ID: <4F7AF154.3040401@sequans.com> Mik wrote: > Oh thanks alex! > that's kind! > > PS: It looks like a party indeed: plenty of interesting > discussions :-) > > On Mar 30, 4:33 am, alex23 wrote: > >> On Mar 29, 10:41 pm, Mik wrote: >> >> >>> What a nice way to introduce myself to the group!!! :-) >>> >> Hey, don't beat yourself up, you: >> >> - summarised the problem in the subject heading >> - included actual code showing the problem >> - reported back on the problem you found >> >> That puts you ahead of most new posters. >> >> >>> sorry for bothering you guys :-) >>> >> No bother at all, welcome to the party :) >> > > Welcome Mik ! JM PS : please don't top post in this list From jkn_gg at nicorp.f9.co.uk Tue Apr 3 08:57:52 2012 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Tue, 3 Apr 2012 05:57:52 -0700 (PDT) Subject: why can't I pickle a class containing this dispatch dictionary? References: <9ee32123-6672-41f9-bdea-5ac075c71093@db5g2000vbb.googlegroups.com> Message-ID: <4db7aeea-c23c-4e43-b67c-4499409ec5f5@i18g2000vbx.googlegroups.com> Hi Peter On Apr 3, 8:54?am, Peter Otten <__pete... at web.de> wrote: > jkn wrote: > > ? ? I'm clearly not understanding the 'can't pickle instancemethod > > objects' error; can someone help me to understand, > > I think classes implemented in C need some extra work to make them > picklable, and that hasn't been done for instance methods. by 'classes implemented in C', doyou mean new-style classes', or what, please? > > > & maybe suggest a > > workaround, (apart from the obvious if ... elif...). > > You can implement pickling yourself: > > [...] Hmm - interesting, thanks. I'm more trying to understand the issue at the moment, but it's always nice to learn... Thanks J^n From Peter.Davis at mathworks.com Tue Apr 3 09:20:45 2012 From: Peter.Davis at mathworks.com (Peter Davis) Date: Tue, 03 Apr 2012 09:20:45 -0400 Subject: Is Programing Art or Science? In-Reply-To: References: Message-ID: On 3/30/2012 4:27 AM, Xah Lee wrote: > Is Programing Art or Science? > Programming itself is a bit like being a natural language translator for an autistic person. You have to understand the "message" to be communicated, and then interpret it *very* literally for the listener. Note that programming is just one of a set of activities and skills that are part of software engineering. Others include UI design (which combines visual design, psychology, etc.), software architecture (which is like ... well, architecture) and various other skills. Collectively, "engineering" is the best catch-all description. Is building a bridge art or science? A little of both, and some other things as well. -pd From cjw at ncf.ca Tue Apr 3 09:34:39 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Tue, 03 Apr 2012 09:34:39 -0400 Subject: Python-URL! - weekly Python news and links (Mar 31) In-Reply-To: References: Message-ID: On 31/03/2012 11:38 AM, Cameron Laird wrote: > I pine for the fjords. > > And it's time to bring "Python-URL!" to a close. "Python-URL!", which > Jean-Claude Wippler and I appear to have launched in 1998, has reached > the end of its utility. We still have many loyal and enthusiastic > readers--one subscription request arrived within the last day, in > fact--and certainly much writing turns up every week that *deserves* > the spotlight "Python-URL!" has shone in the past. > > However, the Python world has changed a great deal over the last > fourteen years. There are many, MANY other ways for those with an > interest in Python to nourish themselves, and Python itself has grown > and "normalized" so much that it no longer fits particularly well in > the "Python-URL!" format. Enjoy "Mouse vs. Python" http://www.blog.pythonlibrary.org/>, the Python areas of DZone, > Reddit, developerWorks, stackoverflow, and so on. > > For your reference, I append below the most-recent-but-not- > particularly- > current version of "Python-URL!"'s coda of related readings. > > That is all. > > > ======================================================================== > 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.c > omp.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.pytho > n&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. Cameron, Many thanks for your efforts over the years. It has been good to have the focused review of what's going on from time to time.. I've added https://twitter.com/#!/SciPyTip to my bookmarks. I've also been impressed with http://www.walkingrandomly.com/ Good Luck and Best wishes, Colin W. From rustompmody at gmail.com Tue Apr 3 09:51:56 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 3 Apr 2012 06:51:56 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> On Apr 3, 5:39?pm, Nathan Rice wrote: > > Don't think "underlying", instead think "canonical". > > Ultimately, the answers to your questions exist in the world for you > to see. ?How does a surgeon describe a surgical procedure? ?How does a > chef describe a recipe? ?How does a carpenter describe the process of > building cabinets? ?Aside from specific words, they all use natural > language, and it works just fine. A carpenter describes his carpentry-process in English A CSist describes his programming-process in English (at least all my CS books are in English) A carpenter uses his tools -- screwdriver, saw, planer --to do carpentry A programmer uses his tools to to programming -- one of which is called 'programming language' Doing programming without programming languages is like using toenails to tighten screws From breamoreboy at yahoo.co.uk Tue Apr 3 10:26:19 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Apr 2012 15:26:19 +0100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> Message-ID: On 03/04/2012 14:51, rusi wrote: > On Apr 3, 5:39 pm, Nathan Rice > wrote: >> >> Don't think "underlying", instead think "canonical". >> >> Ultimately, the answers to your questions exist in the world for you >> to see. How does a surgeon describe a surgical procedure? How does a >> chef describe a recipe? How does a carpenter describe the process of >> building cabinets? Aside from specific words, they all use natural >> language, and it works just fine. > > A carpenter describes his carpentry-process in English > A CSist describes his programming-process in English (at least all my > CS books are in English) > > A carpenter uses his tools -- screwdriver, saw, planer --to do > carpentry > A programmer uses his tools to to programming -- one of which is > called 'programming language' > > Doing programming without programming languages is like using toenails > to tighten screws The latter is extremely difficult if you bite your toenails :) -- Cheers. Mark Lawrence. From dihedral88888 at googlemail.com Tue Apr 3 10:29:31 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 3 Apr 2012 07:29:31 -0700 (PDT) Subject: why can't I pickle a class containing this dispatch dictionary? In-Reply-To: References: <9ee32123-6672-41f9-bdea-5ac075c71093@db5g2000vbb.googlegroups.com> Message-ID: <6406461.2791.1333463371767.JavaMail.geo-discussion-forums@pbnt10> Peter Otten? 2012?4?3????UTC+8??3?54?50???? > jkn wrote: > > > I'm clearly not understanding the 'can't pickle instancemethod > > objects' error; can someone help me to understand, > > I think classes implemented in C need some extra work to make them > picklable, and that hasn't been done for instance methods. > > > & maybe suggest a > > workaround, (apart from the obvious if ... elif...). > > You can implement pickling yourself: > > import copy_reg > import types > > def pickle_instancemethod(m): > return unpickle_instancemethod, (m.im_func.__name__, m.im_self, > m.im_class) > > def unpickle_instancemethod(name, im_self, im_class): > im_func = getattr(im_class, name) > return im_func.__get__(im_self, im_class) > > copy_reg.pickle(types.MethodType, pickle_instancemethod) > > > > I'm running Python 2.6 on an embedded system. > > > > == testpickle.py == > > import pickle > > > > class Test(object): > > def __init__(self): > > self.myDict = { > > 1: self.tag1, > > 2: self.tag2 > > } > > def dispatch(self, v): > > try: > > self.myDict[v]() > > except KeyError: > > print "No corresponding dictionary entry!" > > # > > def tag1(self): > > print "one" > > def tag2(self): > > print "two" > > > > > > t = Test() > > t.dispatch(1) > > t.dispatch(2) > > t.dispatch(0) > > > > fd = open("pickle.out", "w") > > pickle.dump(t, fd) > > fd.close() > > # EOF > > > > $ python testpickle.py > > one > > two > > No corresponding dictionary entry! > > > TypeError: can't pickle instancemethod objects > > $ Save your python files as a package in .pyd or .py and use exec to get what you want. Of course you can use the data compression package to perform serialization operations, but that will increase start up time in loading your objects. From dihedral88888 at googlemail.com Tue Apr 3 10:29:31 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 3 Apr 2012 07:29:31 -0700 (PDT) Subject: why can't I pickle a class containing this dispatch dictionary? In-Reply-To: References: <9ee32123-6672-41f9-bdea-5ac075c71093@db5g2000vbb.googlegroups.com> Message-ID: <6406461.2791.1333463371767.JavaMail.geo-discussion-forums@pbnt10> Peter Otten? 2012?4?3????UTC+8??3?54?50???? > jkn wrote: > > > I'm clearly not understanding the 'can't pickle instancemethod > > objects' error; can someone help me to understand, > > I think classes implemented in C need some extra work to make them > picklable, and that hasn't been done for instance methods. > > > & maybe suggest a > > workaround, (apart from the obvious if ... elif...). > > You can implement pickling yourself: > > import copy_reg > import types > > def pickle_instancemethod(m): > return unpickle_instancemethod, (m.im_func.__name__, m.im_self, > m.im_class) > > def unpickle_instancemethod(name, im_self, im_class): > im_func = getattr(im_class, name) > return im_func.__get__(im_self, im_class) > > copy_reg.pickle(types.MethodType, pickle_instancemethod) > > > > I'm running Python 2.6 on an embedded system. > > > > == testpickle.py == > > import pickle > > > > class Test(object): > > def __init__(self): > > self.myDict = { > > 1: self.tag1, > > 2: self.tag2 > > } > > def dispatch(self, v): > > try: > > self.myDict[v]() > > except KeyError: > > print "No corresponding dictionary entry!" > > # > > def tag1(self): > > print "one" > > def tag2(self): > > print "two" > > > > > > t = Test() > > t.dispatch(1) > > t.dispatch(2) > > t.dispatch(0) > > > > fd = open("pickle.out", "w") > > pickle.dump(t, fd) > > fd.close() > > # EOF > > > > $ python testpickle.py > > one > > two > > No corresponding dictionary entry! > > > TypeError: can't pickle instancemethod objects > > $ Save your python files as a package in .pyd or .py and use exec to get what you want. Of course you can use the data compression package to perform serialization operations, but that will increase start up time in loading your objects. From rosuav at gmail.com Tue Apr 3 10:31:39 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2012 00:31:39 +1000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> Message-ID: On Wed, Apr 4, 2012 at 12:26 AM, Mark Lawrence wrote: > On 03/04/2012 14:51, rusi wrote: >> Doing programming without programming languages is like using toenails >> to tighten screws > > > The latter is extremely difficult if you bite your toenails :) I agree, thumbnails are far better suited. Mine are often pushed into that service. But to extend the analogy: Using a thumbnail to tighten a screw is like directly patching a binary to fix a bug. It works, but it's not exactly a practical way to build a system. ChrisA From SMac2347 at comcast.net Tue Apr 3 10:35:17 2012 From: SMac2347 at comcast.net (SMac2347 at comcast.net) Date: Tue, 3 Apr 2012 07:35:17 -0700 (PDT) Subject: Python and Bloomberg Message-ID: <26f6e8d4-6350-4d9b-96d1-44ea1be72a14@l30g2000yqb.googlegroups.com> Hello, I was just wondering if anyone had experience using Python to interact with Bloomberg. Ideally, I'd look to use Python to feed Bloomberg's OVML calculator with a list of inputs, and then use an additional program to grab the results of the calculator for each calculation, and pull them into another document, ideally an excel spreadsheet or alternatively a delimited .txt file. Any thoughts or ideas are very much appreciated. Thanks! From w.g.sneddon at gmail.com Tue Apr 3 10:36:13 2012 From: w.g.sneddon at gmail.com (python) Date: Tue, 3 Apr 2012 07:36:13 -0700 (PDT) Subject: Is there a better way to do this snippet? Message-ID: <52664090-0833-4ec2-af8b-326737dd67d1@w5g2000yqi.googlegroups.com> I played around with a few things and this works but was wondering if there was a better way to do this. My first thought was list comprehension but could not get a figure out the syntax. tag23gr is a list of lists each with two items. g23tag is an empty dictionary when I run the for loop below. When is is complete each key is a graphic name who's values are a list of tags. for item in tag23gr: ... value, key = tuple(item) ... if(g23tag.get(key)): ... g23tag[key].append(value) ... else: ... g23tag[key] = [value] From __peter__ at web.de Tue Apr 3 10:44:09 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Apr 2012 16:44:09 +0200 Subject: why can't I pickle a class containing this dispatch dictionary? References: <9ee32123-6672-41f9-bdea-5ac075c71093@db5g2000vbb.googlegroups.com> <4db7aeea-c23c-4e43-b67c-4499409ec5f5@i18g2000vbx.googlegroups.com> Message-ID: jkn wrote: > Hi Peter > > On Apr 3, 8:54 am, Peter Otten <__pete... at web.de> wrote: >> jkn wrote: >> > I'm clearly not understanding the 'can't pickle instancemethod >> > objects' error; can someone help me to understand, >> >> I think classes implemented in C need some extra work to make them >> picklable, and that hasn't been done for instance methods. > > by 'classes implemented in C', doyou mean new-style classes', or what, > please? Given >>> class A(object): ... def __init__(self, name): ... self.name = name ... def hello(self): ... print "Hello,", self.name ... >>> a = A("Peter") >>> hello = a.hello >>> hello() Hello, Peter the object bound to the name 'hello' is an instance of the 'instancemethod' type: >>> type(hello) That type is implemented in C, see http://hg.python.org/cpython/file/9599f091faa6/Objects/classobject.c and doesn't support the pickle protocol while a similar class, functools.partial which is also written in C, see http://hg.python.org/cpython/file/9599f091faa6/Modules/_functoolsmodule.c does: >>> from functools import partial >>> import pickle >>> def hello(obj): ... print "Hi,", obj.name ... >>> hello2 = partial(hello, a) >>> hello2() Hi, Peter >>> s = pickle.dumps(hello2) >>> pickle.loads(s)() Hi, Peter From invalid at invalid.invalid Tue Apr 3 10:46:17 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 3 Apr 2012 14:46:17 +0000 (UTC) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> Message-ID: On 2012-04-03, Chris Angelico wrote: > On Wed, Apr 4, 2012 at 12:26 AM, Mark Lawrence wrote: >> On 03/04/2012 14:51, rusi wrote: >>> Doing programming without programming languages is like using toenails >>> to tighten screws >> >> >> The latter is extremely difficult if you bite your toenails :) > > I agree, thumbnails are far better suited. Mine are often pushed into > that service. But to extend the analogy: Using a thumbnail to tighten > a screw is like directly patching a binary to fix a bug. It works, but > it's not exactly a practical way to build a system. Anybody remember DEC's VAX/VMS "patch" utility? Apparently, DEC thought it was a practical way to fix things. It had a built-in assembler and let you "insert" new code into a function by auto-allocating a location for the new code an hooking it into the indicated spot with jump instructions. The mind wobbled. -- Grant Edwards grant.b.edwards Yow! I'm a fuschia bowling at ball somewhere in Brittany gmail.com From rosuav at gmail.com Tue Apr 3 10:56:07 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2012 00:56:07 +1000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> Message-ID: On Wed, Apr 4, 2012 at 12:46 AM, Grant Edwards wrote: > Anybody remember DEC's VAX/VMS "patch" utility? ?Apparently, DEC > thought it was a practical way to fix things. ?It had a built-in > assembler and let you "insert" new code into a function by > auto-allocating a location for the new code an hooking it into the > indicated spot with jump instructions. > > The mind wobbled. Not specifically, but I _have_ heard of various systems whose source code and binary were multiple years divergent. It's actually not a difficult trap to fall into, especially once you start patching running systems. I've had quite a few computers that have been unable to reboot without assistance, because they go for months or years without ever having to go through that initial program load. (I've had _programs_ that were unable to load, for the same reason.) But auto-allocating a new spot for your expanded function? That's just... awesome. My mind is, indeed, wobbling. ChrisA From ian.g.kelly at gmail.com Tue Apr 3 11:01:59 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Apr 2012 09:01:59 -0600 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: On Tue, Apr 3, 2012 at 6:39 AM, Nathan Rice wrote: > Did you miss the part where I said that most people who learn to > program are fascinated by computers and highly motivated to do so? > I've never met a BROgrammer, those people go into sales. ?It isn't > because there aren't smart BROmosapiens (sadly, there are), they just > couldn't give two shits about computers so programming seems like a > colossal waste of time to them. I have never met the brogrammer stereotype. I have also never met the non-brogrammer stereotype of nerdy solitude (well, maybe once). That's all these things are -- stereotypes. Real programmers are much more complex. > Computers require you to state the exact words you're searching for as > well. ?Try looking again, and this time allow for sub-categories and > synonyms, along with some variation in word order. Lazy troll. You made the claim. The onus is on you to provide the evidence. From alain at dpt-info.u-strasbg.fr Tue Apr 3 11:02:03 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 03 Apr 2012 17:02:03 +0200 Subject: Is there a better way to do this snippet? References: <52664090-0833-4ec2-af8b-326737dd67d1@w5g2000yqi.googlegroups.com> Message-ID: <87r4w4505w.fsf@dpt-info.u-strasbg.fr> python writes: > tag23gr is a list of lists each with two items. > g23tag is an empty dictionary when I run the for loop below. > When is is complete each key is a graphic name who's values are a list > of tags. > > for item in tag23gr: > ... value, key = tuple(item) > ... if(g23tag.get(key)): > ... g23tag[key].append(value) > ... else: > ... g23tag[key] = [value] for item in tag23gr: g23tag.setdefault(item[0],[]).append(item[1]) -- Alain. From rosuav at gmail.com Tue Apr 3 11:05:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2012 01:05:49 +1000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: On Wed, Apr 4, 2012 at 1:01 AM, Ian Kelly wrote: > Real programmers are much more complex. Are you saying that some part of all of us is imaginary?? ChrisA From rosuav at gmail.com Tue Apr 3 11:09:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2012 01:09:35 +1000 Subject: Is there a better way to do this snippet? In-Reply-To: <52664090-0833-4ec2-af8b-326737dd67d1@w5g2000yqi.googlegroups.com> References: <52664090-0833-4ec2-af8b-326737dd67d1@w5g2000yqi.googlegroups.com> Message-ID: On Wed, Apr 4, 2012 at 12:36 AM, python wrote: > for item in tag23gr: > ... ? ? value, key = tuple(item) > ... ? ? if(g23tag.get(key)): > ... ? ? ? ? ? ? g23tag[key].append(value) > ... ? ? else: > ... ? ? ? ? ? ? g23tag[key] = [value] Simple enhancement: Use setdefault. Instead of the if, just use: g23tag.setdefault(key,[]).append(value) That'll cover both cases in one. You can leave off the explicit tuple construction; if item is a two-element list, you can unpack it directly. You can also embed that straight into your for loop: for value,key in tag23gr: Do both and you cut your loop down to two lines. Cool! :) Chris Angelico From breamoreboy at yahoo.co.uk Tue Apr 3 11:16:18 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Apr 2012 16:16:18 +0100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> Message-ID: On 03/04/2012 15:56, Chris Angelico wrote: > On Wed, Apr 4, 2012 at 12:46 AM, Grant Edwards wrote: >> Anybody remember DEC's VAX/VMS "patch" utility? Apparently, DEC >> thought it was a practical way to fix things. It had a built-in >> assembler and let you "insert" new code into a function by >> auto-allocating a location for the new code an hooking it into the >> indicated spot with jump instructions. >> >> The mind wobbled. > > Not specifically, but I _have_ heard of various systems whose source > code and binary were multiple years divergent. It's actually not a > difficult trap to fall into, especially once you start patching > running systems. I've had quite a few computers that have been unable > to reboot without assistance, because they go for months or years > without ever having to go through that initial program load. (I've had > _programs_ that were unable to load, for the same reason.) But > auto-allocating a new spot for your expanded function? That's just... > awesome. My mind is, indeed, wobbling. > > ChrisA Around 1990 I worked on Telematics kit. The patches on all their software were implemented via assembler once the original binary had been loaded into memory. They even came up with a system that let you select which patches you wanted and which you didn't, as e.g. some patches were customer specific. -- Cheers. Mark Lawrence. From rweikusat at mssgmbh.com Tue Apr 3 11:22:56 2012 From: rweikusat at mssgmbh.com (Rainer Weikusat) Date: Tue, 03 Apr 2012 16:22:56 +0100 Subject: Is Programing Art or Science? References: Message-ID: <87hax0suun.fsf@sapphire.mobileactivedefense.com> Xah Lee writes: [...] > For example, ?Is mathematics science or art??, is the same type of > question that has been broached by dabblers now and then. http://en.wikipedia.org/wiki/Liberal_arts HTH. From __peter__ at web.de Tue Apr 3 11:24:46 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Apr 2012 17:24:46 +0200 Subject: Is there a better way to do this snippet? References: <52664090-0833-4ec2-af8b-326737dd67d1@w5g2000yqi.googlegroups.com> Message-ID: python wrote: > I played around with a few things and this works but was wondering if > there was a better way to do this. > My first thought was list comprehension but could not get a figure out > the syntax. > > tag23gr is a list of lists each with two items. > g23tag is an empty dictionary when I run the for loop below. > When is is complete each key is a graphic name who's values are a list > of tags. > > for item in tag23gr: > ... value, key = tuple(item) > ... if(g23tag.get(key)): That should be if key in g23tag: Your version means trouble for keys that evaluate to False in a boolean context, e. g. 0, False, None, "", (),... > ... g23tag[key].append(value) > ... else: > ... g23tag[key] = [value] from collections import defaultdict g23tag = defaultdict(list) for value, key in tag23gr: g23tag[key].append(value) From pruebauno at latinmail.com Tue Apr 3 11:37:28 2012 From: pruebauno at latinmail.com (nn) Date: Tue, 3 Apr 2012 08:37:28 -0700 (PDT) Subject: Is there a better way to do this snippet? References: <52664090-0833-4ec2-af8b-326737dd67d1@w5g2000yqi.googlegroups.com> <87r4w4505w.fsf@dpt-info.u-strasbg.fr> Message-ID: On Apr 3, 11:02?am, Alain Ketterlin wrote: > python writes: > > tag23gr is a list of lists each with two items. > > g23tag is an empty dictionary when I run the for loop below. > > When is is complete each key is a graphic name who's values are a list > > of tags. > > > for item in tag23gr: > > ... ? ? ? ?value, key = tuple(item) > > ... ? ? ? ?if(g23tag.get(key)): > > ... ? ? ? ? ? ? ? ?g23tag[key].append(value) > > ... ? ? ? ?else: > > ... ? ? ? ? ? ? ? ?g23tag[key] = [value] > > for item in tag23gr: > ? ? g23tag.setdefault(item[0],[]).append(item[1]) > > -- Alain. Or alternatively: from collections import defaultdict g23tag = defaultdict(list) for item in tag23gr: ....g23tag[item[0]].append(item[1]) From nathan.alexander.rice at gmail.com Tue Apr 3 12:15:21 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 3 Apr 2012 12:15:21 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> Message-ID: On Tue, Apr 3, 2012 at 9:51 AM, rusi wrote: > On Apr 3, 5:39?pm, Nathan Rice > wrote: >> >> Don't think "underlying", instead think "canonical". >> >> Ultimately, the answers to your questions exist in the world for you >> to see. ?How does a surgeon describe a surgical procedure? ?How does a >> chef describe a recipe? ?How does a carpenter describe the process of >> building cabinets? ?Aside from specific words, they all use natural >> language, and it works just fine. > > A carpenter describes his carpentry-process in English > A CSist describes his programming-process in English (at least all my > CS books are in English) > > A carpenter uses his tools -- screwdriver, saw, planer --to do > carpentry > A programmer uses his tools to to programming -- one of which is > called 'programming language' > > Doing programming without programming languages is like using toenails > to tighten screws I would argue that the computer is the tool, not the language. From alain at dpt-info.u-strasbg.fr Tue Apr 3 12:26:57 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 03 Apr 2012 18:26:57 +0200 Subject: Is there a better way to do this snippet? References: <52664090-0833-4ec2-af8b-326737dd67d1@w5g2000yqi.googlegroups.com> <87r4w4505w.fsf@dpt-info.u-strasbg.fr> Message-ID: <87k41w4w8e.fsf@dpt-info.u-strasbg.fr> nn writes: >> > for item in tag23gr: >> > ... ? ? ? ?value, key = tuple(item) >> > ... ? ? ? ?if(g23tag.get(key)): >> > ... ? ? ? ? ? ? ? ?g23tag[key].append(value) >> > ... ? ? ? ?else: >> > ... ? ? ? ? ? ? ? ?g23tag[key] = [value] >> >> for item in tag23gr: >> ? ? g23tag.setdefault(item[0],[]).append(item[1]) > Or alternatively: > > from collections import defaultdict > g23tag = defaultdict(list) > for item in tag23gr: > ....g23tag[item[0]].append(item[1]) Very handy in that case, but in general I dislike the idea of silently inserting a default value when the access is a read, e.g., in x=g23tag[wrung]. Explicit is better than implicit, as they say. YMMV. -- Alain. From d at davea.name Tue Apr 3 12:28:31 2012 From: d at davea.name (Dave Angel) Date: Tue, 03 Apr 2012 12:28:31 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> Message-ID: <4F7B252F.3010405@davea.name> On 04/03/2012 11:16 AM, Mark Lawrence wrote: > On 03/04/2012 15:56, Chris Angelico wrote: >> On Wed, Apr 4, 2012 at 12:46 AM, Grant >> Edwards wrote: >>> Anybody remember DEC's VAX/VMS "patch" utility? Apparently, DEC >>> thought it was a practical way to fix things. It had a built-in >>> assembler and let you "insert" new code into a function by >>> auto-allocating a location for the new code an hooking it into the >>> indicated spot with jump instructions. >>> >>> The mind wobbled. >> >> Not specifically, but I _have_ heard of various systems whose source >> code and binary were multiple years divergent. It's actually not a >> difficult trap to fall into, especially once you start patching >> running systems. I've had quite a few computers that have been unable >> to reboot without assistance, because they go for months or years >> without ever having to go through that initial program load. (I've had >> _programs_ that were unable to load, for the same reason.) But >> auto-allocating a new spot for your expanded function? That's just... >> awesome. My mind is, indeed, wobbling. >> >> ChrisA > > Around 1990 I worked on Telematics kit. The patches on all their > software were implemented via assembler once the original binary had > been loaded into memory. They even came up with a system that let you > select which patches you wanted and which you didn't, as e.g. some > patches were customer specific. > And I worked on a system where the microcode was in ROM, and there was a "patch board" consisting of lots of diodes and some EPROMs. The diodes were soldered into place to specfy the instruction(s) to be patched, and the actual patches were in the EPROMs, which were reusable. The diodes were the only thing fast enough to "patch" the ROM, by responding more quickly than the ROM. This was back when issuing a new ROM was a very expensive proposition; there were masking charges, so you couldn't reasonably do low quantities. -- DaveA From ian.g.kelly at gmail.com Tue Apr 3 12:29:24 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Apr 2012 10:29:24 -0600 Subject: No os.copy()? Why not? In-Reply-To: References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> Message-ID: On Tue, Apr 3, 2012 at 12:24 AM, Thomas Rachel wrote: > Am 02.04.2012 23:11 schrieb HoneyMonster: > > >> One way: >> import os >> >> os.system ("cp src sink") > > > Yes. The worst way you could imagine. > > Why not the much much better > > from subprocess > subprocess.call(['cp', 'src', 'sink']) In any case, either of these approaches will only work in UNIX, whereas shutil is cross-platform. From nagle at animats.com Tue Apr 3 12:38:50 2012 From: nagle at animats.com (John Nagle) Date: Tue, 03 Apr 2012 09:38:50 -0700 Subject: Best way to structure data for efficient searching In-Reply-To: References: Message-ID: On 3/28/2012 11:39 AM, Larry.Martell at gmail.com wrote: > I have the following use case: > > I have a set of data that is contains 3 fields, K1, K2 and a > timestamp. There are duplicates in the data set, and they all have to > processed. > > Then I have another set of data with 4 fields: K3, K4, K5, and a > timestamp. There are also duplicates in that data set, and they also > all have to be processed. > > I need to find all the items in the second data set where K1==K3 and > K2==K4 and the 2 timestamps are within 20 seconds of each other. > > I have this working, but the way I did it seems very inefficient - I > simply put the data in 2 arrays (as tuples) and then walked through > the entire second data set once for each item in the first data set, > looking for matches. > > Is there a better, more efficient way I could have done this? How big are the data sets? Millions of entries? Billions? Trillions? Will all the data fit in memory, or will this need files or a database. In-memory, it's not hard. First, decide which data set is smaller. That one gets a dictionary keyed by K1 or K3, with each entry being a list of tuples. Then go through the other data set linearly. You can also sort one database by K1, the other by K3, and match. Then take the matches, sort by K2 and K4, and match again. Sort the remaining matches by timestamp and pull the ones within the threshold. Or you can load all the data into a database with a query optimizer, like MySQL, and let it figure out, based on the index sizes, how to do the join. All of these approaches are roughly O(N log N), which beats the O(N^2) approach you have now. John Nagle From cartercc at gmail.com Tue Apr 3 13:00:17 2012 From: cartercc at gmail.com (ccc31807) Date: Tue, 3 Apr 2012 10:00:17 -0700 (PDT) Subject: Is Programing Art or Science? References: <87vclhn6u2.fsf@kuiper.lan.informatimago.com> Message-ID: <72e8ce7a-0c00-4436-80cd-8f3d79cbcfa2@f37g2000yqc.googlegroups.com> On Apr 2, 5:48?pm, "Pascal J. Bourguignon" > This is a narrow-minded definition of programming. Well, that's the point. If we make a list and include things like: computer science software engineering computer engineering discrete math logic formal methods web development computer graphics information technology information management data processing database management database administration network administration artificial intelligence ... and so on and so forth ... Some of these involve real art. Some of these involve real science. Even engineering can be considered as science, in a way, and perhaps art in a way. All these include programming! HOWEVER, 'programming' seen as 'talking to a computer' is neither an art nor a science, but simply a learned skill, like plumbing or cabinet making, or even medicine or law. I was a lawyer for 14 years, so I know what I'm talking about: the practice of law in the ordinary sense is simply that, the practice of law, and as such it's not an art nor a science, but simply a trade, albeit a highly skilled and abstract trade. And yes, lawyers can be artists and scientists, but neither one of these is basic to the practice of law. I'm not saying that artists and scientists can't be programmers. Many of them are. What I'm saying is that you can program a computer (i.e., practice programming) without being either an artist or a scientist. CC. From rustompmody at gmail.com Tue Apr 3 13:13:23 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 3 Apr 2012 10:13:23 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> Message-ID: <44517fc0-8108-40e8-9d0f-c850858d3395@t8g2000pbe.googlegroups.com> On Apr 3, 9:15?pm, Nathan Rice wrote: > On Tue, Apr 3, 2012 at 9:51 AM, rusi wrote: > > On Apr 3, 5:39?pm, Nathan Rice > > wrote: > > >> Don't think "underlying", instead think "canonical". > > >> Ultimately, the answers to your questions exist in the world for you > >> to see. ?How does a surgeon describe a surgical procedure? ?How does a > >> chef describe a recipe? ?How does a carpenter describe the process of > >> building cabinets? ?Aside from specific words, they all use natural > >> language, and it works just fine. > > > A carpenter describes his carpentry-process in English > > A CSist describes his programming-process in English (at least all my > > CS books are in English) > > > A carpenter uses his tools -- screwdriver, saw, planer --to do > > carpentry > > A programmer uses his tools to to programming -- one of which is > > called 'programming language' > > > Doing programming without programming languages is like using toenails > > to tighten screws > > I would argue that the computer is the tool, not the language. "Computer science is as much about computers as astronomy is about telescopes" -- E W Dijkstra Here are some other attempted corrections of the misnomer "computer science": http://en.wikipedia.org/wiki/Computer_science#Name_of_the_field From nathan.alexander.rice at gmail.com Tue Apr 3 13:17:18 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 3 Apr 2012 13:17:18 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: On Tue, Apr 3, 2012 at 11:01 AM, Ian Kelly wrote: > On Tue, Apr 3, 2012 at 6:39 AM, Nathan Rice > wrote: >> Did you miss the part where I said that most people who learn to >> program are fascinated by computers and highly motivated to do so? >> I've never met a BROgrammer, those people go into sales. ?It isn't >> because there aren't smart BROmosapiens (sadly, there are), they just >> couldn't give two shits about computers so programming seems like a >> colossal waste of time to them. > > I have never met the brogrammer stereotype. ?I have also never met the > non-brogrammer stereotype of nerdy solitude (well, maybe once). > That's all these things are -- stereotypes. ?Real programmers are much > more complex. I have never met a programmer that was not completely into computers. That leaves a lot unspecified though. >> Computers require you to state the exact words you're searching for as >> well. ?Try looking again, and this time allow for sub-categories and >> synonyms, along with some variation in word order. > > Lazy troll. ?You made the claim. ?The onus is on you to provide the evidence. I reserve the right to be lazy :) As part of my troll-outreach effort, I will indulge here. I was specifically thinking about some earlier claims that programming languages as they currently exist are somehow inherently superior to a formalized natural language in expressive power. I think part of this comes from the misconception that terse is better (e.g. Paul Graham's thoughts on car/cdr), which doesn't take into account that your brain compresses frequently occurring English words VERY efficiently, so they actually take up less cognitive bandwidth than a much shorter non-word. This behavior extends to the phrase level as well; longer phrases that are meaningful in their own right take up less bandwidth than short nonsensical word combinations. On the semantic side, most people already understand branched processes and procedures with conditional actions pretty well. People "program" other people to perform tasks constantly, and have been doing so for the entirety of our existence. The problem occurs when programming language specific semantic artifacts must be considered. These artifacts are for the most part somewhat arbitrary, or you would see them frequently in other areas, and they wouldn't confuse people so much. I think the majority of these relate to how the computer operates internally - this is the stuff that really turns most people off to programming. The crux of my view is that programming languages exist in part because computers in general are not smart enough to converse with humans on their own level, so we have to talk to them like autistic 5 year-olds. That was fine when we didn't have any other options, but all the pieces exist now to let computers talk to us very close to our own level, and represent information at the same way we do. Projects like IBM's Watson, Siri, Wolfram Alpha and Cyc demonstrate pretty clearly to me that we are capable of taking the next step, and the resurgence of the technology sector along with the shortage of qualified developers indicates to me that we need to move now. From neilc at norwich.edu Tue Apr 3 13:21:32 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Apr 2012 17:21:32 GMT Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> Message-ID: <9u0pssF9odU1@mid.individual.net> On 2012-04-03, Dave Angel wrote: > And I worked on a system where the microcode was in ROM, and > there was a "patch board" consisting of lots of diodes and some > EPROMs. The diodes were soldered into place to specfy the > instruction(s) to be patched, and the actual patches were in > the EPROMs, which were reusable. The diodes were the only > thing fast enough to "patch" the ROM, by responding more > quickly than the ROM. This was back when issuing a new ROM was > a very expensive proposition; there were masking charges, so > you couldn't reasonably do low quantities. I worked on a system where the main interface to the system was poking and peeking numbers at memory addresses. -- Neil Cerutti From rustompmody at gmail.com Tue Apr 3 13:25:50 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 3 Apr 2012 10:25:50 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: All this futuristic grandiloquence: On Apr 3, 10:17?pm, Nathan Rice wrote: > The crux of my view is that programming languages exist in part > because computers in general are not smart enough to converse with > humans on their own level, so we have to talk to them like autistic 5 > year-olds. ?That was fine when we didn't have any other options, but > all the pieces exist now to let computers talk to us very close to our > own level, and represent information at the same way we do. ?Projects > like IBM's Watson, Siri, Wolfram Alpha and Cyc demonstrate pretty > clearly to me that we are capable of taking the next step, and the > resurgence of the technology sector along with the shortage of > qualified developers indicates to me that we need to move now. needs to be juxtaposed with this antiquated view > I would argue that the computer is the tool, not the language. ... a view that could not be held by an educated person after the 1960s -- ie when it became amply clear to all that the essential and hard issues in CS are about software and not hardware From pruebauno at latinmail.com Tue Apr 3 14:03:44 2012 From: pruebauno at latinmail.com (nn) Date: Tue, 3 Apr 2012 11:03:44 -0700 (PDT) Subject: Is there a better way to do this snippet? References: <52664090-0833-4ec2-af8b-326737dd67d1@w5g2000yqi.googlegroups.com> <87r4w4505w.fsf@dpt-info.u-strasbg.fr> <87k41w4w8e.fsf@dpt-info.u-strasbg.fr> Message-ID: On Apr 3, 12:26?pm, Alain Ketterlin wrote: > nn writes: > >> > for item in tag23gr: > >> > ... ? ? ? ?value, key = tuple(item) > >> > ... ? ? ? ?if(g23tag.get(key)): > >> > ... ? ? ? ? ? ? ? ?g23tag[key].append(value) > >> > ... ? ? ? ?else: > >> > ... ? ? ? ? ? ? ? ?g23tag[key] = [value] > > >> for item in tag23gr: > >> ? ? g23tag.setdefault(item[0],[]).append(item[1]) > > Or alternatively: > > > from collections import defaultdict > > g23tag = defaultdict(list) > > for item in tag23gr: > > ....g23tag[item[0]].append(item[1]) > > Very handy in that case, but in general I dislike the idea of silently > inserting a default value when the access is a read, e.g., in > x=g23tag[wrung]. Explicit is better than implicit, as they say. YMMV. > > -- Alain. Valid point. Preferred choice depends on the access patterns to the dict (e.g. one write and multiple reads, multiple writes and one loop over items, etc.) From pjb at informatimago.com Tue Apr 3 14:27:11 2012 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Tue, 03 Apr 2012 20:27:11 +0200 Subject: Is Programing Art or Science? References: <87vclhn6u2.fsf@kuiper.lan.informatimago.com> <72e8ce7a-0c00-4436-80cd-8f3d79cbcfa2@f37g2000yqc.googlegroups.com> Message-ID: <871uo4n01s.fsf@kuiper.lan.informatimago.com> ccc31807 writes: > On Apr 2, 5:48?pm, "Pascal J. Bourguignon" >> This is a narrow-minded definition of programming. > > Well, that's the point. > > If we make a list and include things like: > computer science > software engineering > computer engineering > discrete math > logic > formal methods > web development > computer graphics > information technology > information management > data processing > database management > database administration > network administration > artificial intelligence > ... and so on and so forth ... > > Some of these involve real art. Some of these involve real science. > Even engineering can be considered as science, in a way, and perhaps > art in a way. All these include programming! HOWEVER, 'programming' > seen as 'talking to a computer' is neither an art nor a science, but > simply a learned skill, like plumbing or cabinet making, or even > medicine or law. > > I was a lawyer for 14 years, so I know what I'm talking about: the > practice of law in the ordinary sense is simply that, the practice of > law, and as such it's not an art nor a science, but simply a trade, > albeit a highly skilled and abstract trade. And yes, lawyers can be > artists and scientists, but neither one of these is basic to the > practice of law. > > I'm not saying that artists and scientists can't be programmers. Many > of them are. What I'm saying is that you can program a computer (i.e., > practice programming) without being either an artist or a scientist. Well, of course. Those words designate different categories that are not exclusive. So it's meaningless to say that programming is or is not art or science. Art is something that comes from a quality of the would-be artist. Science is something that comes from a methodology applied by the would-be scientist. Program is something that comes from the work applied by the would-be programmer. You can be both a programmer and artist and produce a program arstistically (like a torero), or an artistic program (like a painter). You can be both a programmer and scientist, and produce a program scientifically (like a mathematician), or a science program (like a physicist). You can be both a scientist and artist and produce science artistically, or art scientifically. You can be the three, producing programs artistically and scientifically, or producing artisctic programs scientifically, or producing scientific programs artistically, etc. When you produce programs scientifically and artistically you're a hacker. It could be nice to produce scientific programs scientifically, and even better if your scientific programs are also artistic (so that you can show the science in an interesting way to the public). http://www.ted.com/talks/joann_kuchera_morin_tours_the_allosphere.html You can also produce art programmatically. For that you need to be both an artist or a programmer. http://animusic.com/ Or you may try to split the qualities among a team like at Pixar producing artistic movies programmatically and scientifically like http://www.pixar.com/featurefilms/index.html http://graphics.pixar.com/library/UntanglingCloth/paper.pdf And the best is to produce scientific programs that are artistic, scientifically and artistically. Then you're an scientifico-artistico-hacker. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From nathan.alexander.rice at gmail.com Tue Apr 3 14:42:01 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 3 Apr 2012 14:42:01 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: >> > A carpenter uses his tools -- screwdriver, saw, planer --to do >> > carpentry >> > A programmer uses his tools to to programming -- one of which is >> > called 'programming language' >> >> > Doing programming without programming languages is like using toenails >> > to tighten screws >> >> I would argue that the computer is the tool, not the language. > > "Computer science is as much about computers as astronomy is about > telescopes" -- E W Dijkstra > > Here are some other attempted corrections of the misnomer "computer > science": > http://en.wikipedia.org/wiki/Computer_science#Name_of_the_field I view "computer science" as applied mathematics, when it deserves that moniker. When it doesn't, it is merely engineering. Ironically, telescopes are a tool that astronomers use to view the stars. On Tue, Apr 3, 2012 at 1:25 PM, rusi wrote: > All this futuristic grandiloquence: > > On Apr 3, 10:17?pm, Nathan Rice > wrote: >> The crux of my view is that programming languages exist in part >> because computers in general are not smart enough to converse with >> humans on their own level, so we have to talk to them like autistic 5 >> year-olds. ?That was fine when we didn't have any other options, but >> all the pieces exist now to let computers talk to us very close to our >> own level, and represent information at the same way we do. ?Projects >> like IBM's Watson, Siri, Wolfram Alpha and Cyc demonstrate pretty >> clearly to me that we are capable of taking the next step, and the >> resurgence of the technology sector along with the shortage of >> qualified developers indicates to me that we need to move now. > > needs to be juxtaposed with this antiquated view > >> I would argue that the computer is the tool, not the language. > > > ... a view that could not be held by an educated person after the > 1960s -- ie when it became amply clear to all that the essential and > hard issues in CS are about software and not hardware I'll go ahead and forgive the club handed fallacies, so we can have a nice discussion of your primary point. What a civil troll I am :) Lets start with some analogies. In cooking, chefs use recipes to produce a meal; the recipe is not a tool. In architecture, a builder uses a blueprint to produce a building; the blueprint is not a tool. In manufacturing, expensive machines use plans to produce physical goods; the plans are not the tool. You could say the compiler is a tool, or a development environment is a tool. The programming language is a mechanism for communication. From cartercc at gmail.com Tue Apr 3 15:39:20 2012 From: cartercc at gmail.com (ccc31807) Date: Tue, 3 Apr 2012 12:39:20 -0700 (PDT) Subject: Is Programing Art or Science? References: <87vclhn6u2.fsf@kuiper.lan.informatimago.com> <72e8ce7a-0c00-4436-80cd-8f3d79cbcfa2@f37g2000yqc.googlegroups.com> <871uo4n01s.fsf@kuiper.lan.informatimago.com> Message-ID: ?Beauty is more important in computing than anywhere else in technology because software is so complicated. Beauty is the ultimate defence against complexity.? --David Gelernter From darcy at druid.net Tue Apr 3 15:46:31 2012 From: darcy at druid.net (D'Arcy Cain) Date: Tue, 03 Apr 2012 15:46:31 -0400 Subject: No os.copy()? Why not? In-Reply-To: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> Message-ID: <4F7B5397.8070405@druid.net> On 03/28/12 16:12, John Ladasky wrote: > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > Since the equivalents of "rm" and "mkdir" are in the os module, I > figured I look there. I haven't found anything in the documentation. > I am also looking through the Python source code in os.py and its > child, posixfile.py. cp is not a system command, it's a shell command. Why not just use the incredibly simple and portable >>>open("outfile", "w").write(open("infile").read()) put it into a method if you find that too much to type: def cp(infile, outfile): open(outfile, "w").write(open(infile).read()) -- 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. IM: darcy at Vex.Net From p.f.moore at gmail.com Tue Apr 3 16:01:33 2012 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 3 Apr 2012 13:01:33 -0700 (PDT) Subject: What is the best way to freeze a Python 3 app (Windows)? Message-ID: I want to package up some of my Python 3 scripts to run standalone, without depending on a system-installed Python. For my development, I use virtualenv and install all my dependencies in the virtualenv, develop the script and test it. When I'm done, I want to build an executable which can run without depending on a system Python. What's the best way of doing this? I previously would have used py2exe, but that seems not to have Python 3 support. I have heard good things about bbfreeze, but the author has stated that he has no intention of supporting Python 3 just yet. I've tried cx_Freeze, but I've hit a number of niggly problems which make me think it's not quite suitable (I've reported some of them on the cx_Freeze mailing list, but it seems pretty quiet - no real response). That leaves me wondering if there's another option, or whether I should just roll my own. if I zip up the stdlib, and my virtualenv site-packages, and then put them plus the various Python DLLs in a directory, copy my script in, and write a small EXE to set PYTHONHOME and run Py_Main with my script as argument, that should do. But it seems a bit laborious :-( Is that really the best way? Things I care about: - Easy to package up a script - Works with dependencies in a virtualenv - Completely isolated from system Python (not even leaving directories on sys.path, so I can do basic tests without having to create a clean system with no Python installed). Things I don't (really) care about: - Stripping ununsed modules (although I'd like to omit "big" parts of the stdlib that aren't used - tkinter and test come to mind) - Space (the full stdlib is only 30M including pyc files, after all) Any suggestions gratefully accepted :-) Paul. From tycho at tycho.ws Tue Apr 3 16:10:32 2012 From: tycho at tycho.ws (Tycho Andersen) Date: Tue, 3 Apr 2012 15:10:32 -0500 Subject: No os.copy()? Why not? In-Reply-To: <4F7B5397.8070405@druid.net> References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <4F7B5397.8070405@druid.net> Message-ID: <20120403201032.GC2340@ccapuser-ubuntu.WICOURTS.GOV> On Tue, Apr 03, 2012 at 03:46:31PM -0400, D'Arcy Cain wrote: > On 03/28/12 16:12, John Ladasky wrote: > >I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > >Since the equivalents of "rm" and "mkdir" are in the os module, I > >figured I look there. I haven't found anything in the documentation. > >I am also looking through the Python source code in os.py and its > >child, posixfile.py. > > cp is not a system command, it's a shell command. Why not just use the > incredibly simple and portable > > >>>open("outfile", "w").write(open("infile").read()) Note, though, that this reads the whole file into memory. As many others have said, shutil is the most idiomatic option. \t From tjreedy at udel.edu Tue Apr 3 16:20:08 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 Apr 2012 16:20:08 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: On 4/3/2012 8:39 AM, Nathan Rice wrote: > Ultimately, the answers to your questions exist in the world for you > to see. How does a surgeon describe a surgical procedure? How does a > chef describe a recipe? How does a carpenter describe the process of > building cabinets? Aside from specific words, they all use natural > language, and it works just fine. Not really. Surgeon's learn by *watching* a surgeon who knows the operation and next (hopefully) doing a particular surgery under supervision of such a surgeon, who watches and talks, and may even grab the instruments and re-show. They then really learn by doing the procedure on multiple people. They often kill a few on the way to mastery. I first learned basic carpentry and other skills by watching my father. I don't remember that he ever said anything about how to hold the tools. I similarly learned basic cooking by watching my mom. My knowledge of how to crack open an egg properly and separate the yolk from the rest is a wordless memory movie. -- Terry Jan Reedy From driscoll at cs.wisc.edu Tue Apr 3 16:21:25 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Tue, 03 Apr 2012 15:21:25 -0500 Subject: No os.copy()? Why not? In-Reply-To: <20120403201032.GC2340@ccapuser-ubuntu.WICOURTS.GOV> References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <4F7B5397.8070405@druid.net> <20120403201032.GC2340@ccapuser-ubuntu.WICOURTS.GOV> Message-ID: <4F7B5BC5.2090805@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Tycho Andersen wrote: > Note, though, that this reads the whole file into memory. As many > others have said, shutil is the most idiomatic option. * most idiomatic * clearest in terms of showing intent * potentially fastest * hardest to screw up (unlike concatenating file names into a 'system' call) * has at least a snowball's chance of persisting metadata associated with the file (even if shutil doesn't now, it could theoretically change) * portable There's basically nothing NOT to like about shutil, and at least one significant problems with all the other suggestions. Evan From bahamutzero8825 at gmail.com Tue Apr 3 16:23:46 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 03 Apr 2012 15:23:46 -0500 Subject: What is the best way to freeze a Python 3 app (Windows)? In-Reply-To: References: Message-ID: <4F7B5C52.40808@gmail.com> cx_Freeze is the only program that can freeze py3k code that I know of. I didn't have any major issues with it, but I've only played with it. In any case, if you're going to roll your own, I'd be happy to help test it. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From tolidtm at gmail.com Tue Apr 3 16:36:33 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Tue, 3 Apr 2012 22:36:33 +0200 Subject: Run once while loop Message-ID: <7619907723400632495@unknownmsgid> Hi, I'm trying to do a while loop with condition of time if time is 12:00:00 print text, but for this one second the text is printed at least 50 times, how can I print only once? Thank Anatoli From ian.g.kelly at gmail.com Tue Apr 3 16:45:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Apr 2012 14:45:08 -0600 Subject: Run once while loop In-Reply-To: <7619907723400632495@unknownmsgid> References: <7619907723400632495@unknownmsgid> Message-ID: On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: > Hi, > > I'm trying to do a while loop with condition of time if time is > 12:00:00 print text, but for this one second the text is printed at > least 50 times, how can I print only once? Set a flag when you print the text to indicate that you've already printed it, and don't print it again if the flag is set. When it's no longer 12:00:00, reset the flag. That said, a busy while loop is probably the wrong way to do this, because it will run your CPU at 100%. Better would be to put the thread to sleep with time.sleep() calls or a real event loop with a timer event. Cheers, Ian From joshua.r.english at gmail.com Tue Apr 3 16:46:13 2012 From: joshua.r.english at gmail.com (Josh English) Date: Tue, 3 Apr 2012 13:46:13 -0700 (PDT) Subject: xlrd 0.7.4 released! In-Reply-To: <4F7AA10B.6020907@simplistix.co.uk> References: <4F7AA10B.6020907@simplistix.co.uk> Message-ID: <15454045.1017.1333485973850.JavaMail.geo-discussion-forums@pbon5> Maybe it's just me, but I tried to upgrade my previous versions of xlrd, xlwt, an xlutils and now some of the modules aren't loading properly. I am currently using Portable Python 2.7 at this workstation. I ran "easy_install --upgrade xlrd" and the result said it had updated. If I try to update again, it says it's already there. When I try to import xlrd, I get an error IOError: [Errno 2] No such file or directory: 'C:\\Users\\josh\\Desktop\\Portable Python\\App\\lib\\site-packages\\xlrd-0.7.5-py2.7.egg\\xlrd\\version.txt' I also noticed that in my Site Packages folder, I have xlrd-0.7.1-py2.7-win32.egg as an egg file, but xlrd-0.7.5-py2.7.egg as a folder. This in on a Windows 7 machine. I didn't think EGG files could be folders. Is there a change in the way the EGG file was meant to be distributed? Josh English Confused Data Geek > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.alexander.rice at gmail.com Tue Apr 3 16:50:04 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 3 Apr 2012 16:50:04 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: On Tue, Apr 3, 2012 at 4:20 PM, Terry Reedy wrote: > On 4/3/2012 8:39 AM, Nathan Rice wrote: > >> Ultimately, the answers to your questions exist in the world for you >> to see. ?How does a surgeon describe a surgical procedure? ?How does a >> chef describe a recipe? ?How does a carpenter describe the process of >> building cabinets? ?Aside from specific words, they all use natural >> language, and it works just fine. > > > Not really. Surgeon's learn by *watching* a surgeon who knows the operation > and next (hopefully) doing a particular surgery under supervision of such a > surgeon, who watches and talks, and may even grab the instruments and > re-show. They then really learn by doing the procedure on multiple people. > They often kill a few on the way to mastery. Well, there is declarative knowledge and procedural knowledge. In all these cases, only the procedural knowledge is absolutely necessary, but the declarative knowledge is usually a prerequisite to learning the procedure in any sort of reasonable manner. > I first learned basic carpentry and other skills by watching my father. I > don't remember that he ever said anything about how to hold the tools. > > I similarly learned basic cooking by watching my mom. My knowledge of how to > crack open an egg properly and separate the yolk from the rest is a wordless > memory movie. A picture is worth a thousand words :) If you would like, I don't have any problem incorporating visual programming and programming by demonstration. I didn't go in that direction because I have enough to defend as it is. I like to look at it from the perspective of teaching/communicating, rather than operating a simple machine. From adrian.klaver at gmail.com Tue Apr 3 16:58:13 2012 From: adrian.klaver at gmail.com (Adrian Klaver) Date: Tue, 03 Apr 2012 13:58:13 -0700 Subject: [pyxl] Re: xlrd 0.7.4 released! In-Reply-To: <15454045.1017.1333485973850.JavaMail.geo-discussion-forums@pbon5> References: <4F7AA10B.6020907@simplistix.co.uk> <15454045.1017.1333485973850.JavaMail.geo-discussion-forums@pbon5> Message-ID: <4F7B6465.9040708@gmail.com> On 04/03/2012 01:46 PM, Josh English wrote: > Maybe it's just me, but I tried to upgrade my previous versions of xlrd, > xlwt, an xlutils and now some of the modules aren't loading properly. > > I am currently using Portable Python 2.7 at this workstation. > > I ran "easy_install --upgrade xlrd" and the result said it had updated. > If I try to update again, it says it's already there. > > When I try to import xlrd, I get an error > > IOError: [Errno 2] No such file or directory: > 'C:\\Users\\josh\\Desktop\\Portable > Python\\App\\lib\\site-packages\\xlrd-0.7.5-py2.7.egg\\xlrd\\version.txt' > > I also noticed that in my Site Packages folder, I have > xlrd-0.7.1-py2.7-win32.egg as an egg file, but xlrd-0.7.5-py2.7.egg as a > folder. > > This in on a Windows 7 machine. > > I didn't think EGG files could be folders. Is there a change in the way > the EGG file was meant to be distributed? Interesting the below seemed to have got lost on way to Google Groups: From Chris: " As pointed out, I stuffed up the release by not including a new file in the MANIFEST. My bad. I've just release a 0.7.5 that fixes this. cheers, Chris " > > Josh English > Confused Data Geek -- Adrian Klaver adrian.klaver at gmail.com From tolidtm at gmail.com Tue Apr 3 17:00:22 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Tue, 3 Apr 2012 23:00:22 +0200 Subject: Run once while loop In-Reply-To: References: <7619907723400632495@unknownmsgid> Message-ID: <-5854393752682031995@unknownmsgid> On 03 Apr 2012, at 22:45, Ian Kelly wrote: > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: >> Hi, >> >> I'm trying to do a while loop with condition of time if time is >> 12:00:00 print text, but for this one second the text is printed at >> least 50 times, how can I print only once? > > Set a flag when you print the text to indicate that you've already > printed it, and don't print it again if the flag is set. When it's no > longer 12:00:00, reset the flag. > > That said, a busy while loop is probably the wrong way to do this, > because it will run your CPU at 100%. Better would be to put the > thread to sleep with time.sleep() calls or a real event loop with a > timer event. > > Cheers, > Ian Thank you Ian, what if I wait for other conditions if I use time.sleep for 1 sec? it means that all the program is sleeping for a sec. Regards Hristov Anatoli From xahlee at gmail.com Tue Apr 3 17:39:02 2012 From: xahlee at gmail.com (Xah Lee) Date: Tue, 3 Apr 2012 14:39:02 -0700 (PDT) Subject: Is Programing Art or Science? References: <87hax0suun.fsf@sapphire.mobileactivedefense.com> Message-ID: <616c011e-c66e-4d57-9af8-8970327cbdf6@px4g2000pbc.googlegroups.com> On Apr 3, 8:22?am, Rainer Weikusat wrote: > Xah Lee writes: > > [...] > > > For example, ?Is mathematics science or art??, is the same type of > > question that has been broached by dabblers now and then. > http://en.wikipedia.org/wiki/Liberal_arts this is the best reply in this thread! Xah From mcepl at redhat.com Tue Apr 3 17:39:31 2012 From: mcepl at redhat.com (Matej Cepl) Date: Tue, 03 Apr 2012 23:39:31 +0200 Subject: ANN: yamlish 0.8 released Message-ID: <4F7B6E13.8070608@redhat.com> yamlish 0.8 is now available at http://pypi.python.org/pypi/yamlish yamlish is a module for generating (and parsing) YAMLish (http://testanything.org/wiki/index.php/YAMLish). Release notes: -------------- * Don't leak tempfiles * setup.py test actually runs tests * add requires to setup.py * generate compact multiline strings (don't add empty lines) Links: ------ * homepage http://pypi.python.org/pypi/yamlish * code repository https://gitorious.org/yamlish/yamlish * bug reports and enhancement requests to mcepl_at_redhat_dot_com or to https://luther.ceplovi.cz/bugzilla/ (product TAP) From mcepl at redhat.com Tue Apr 3 17:44:21 2012 From: mcepl at redhat.com (Matej Cepl) Date: Tue, 03 Apr 2012 23:44:21 +0200 Subject: ANN: bayeux 0.2 released Message-ID: <4F7B6F35.50701@redhat.com> Bayeux 0.2 is now available at http://pypi.python.org/pypi/bayeux bayeux is a module for generating TAP (http://testanything.org/). Version 0.2 is an initial version registered in the Cheesshop. Release notes: -------------- * module tap.py for programatic writing of TAP stream * clone of unittest2 generating TAP stream instead of the normal unittest output. * example script for generating TAP stream from JSON results of piglit test suite. Links: ------ * homepage http://pypi.python.org/pypi/bayeux * code repository https://gitorious.org/bayeux/bayeux * bug reports and enhancement requests to mcepl_at_redhat_dot_com or to https://luther.ceplovi.cz/bugzilla/ (product TAP) From ian.g.kelly at gmail.com Tue Apr 3 17:48:33 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Apr 2012 15:48:33 -0600 Subject: Run once while loop In-Reply-To: <-5854393752682031995@unknownmsgid> References: <7619907723400632495@unknownmsgid> <-5854393752682031995@unknownmsgid> Message-ID: On Tue, Apr 3, 2012 at 3:00 PM, Anatoli Hristov wrote: > On 03 Apr 2012, at 22:45, Ian Kelly wrote: > >> On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: >>> Hi, >>> >>> I'm trying to do a while loop with condition of time if time is >>> 12:00:00 print text, but for this one second the text is printed at >>> least 50 times, how can I print only once? >> >> Set a flag when you print the text to indicate that you've already >> printed it, and don't print it again if the flag is set. ?When it's no >> longer 12:00:00, reset the flag. >> >> That said, a busy while loop is probably the wrong way to do this, >> because it will run your CPU at 100%. ?Better would be to put the >> thread to sleep with time.sleep() calls or a real event loop with a >> timer event. >> >> Cheers, >> Ian > > Thank you Ian, > > what if I wait for other conditions if I use time.sleep for 1 sec? it > means that all the program is sleeping for a sec. You can sleep for less than a second. 0.2 seconds or so allows a pretty nice response time while still limiting how much your script will spin the CPU. From philr at aspexconsulting.co.nz Tue Apr 3 17:50:24 2012 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Wed, 4 Apr 2012 09:50:24 +1200 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <0f1ead89-f0f1-4179-904d-ec1efda38809@t2g2000pbg.googlegroups.com> Message-ID: > -----Original Message----- > From: Mark Lawrence [mailto:breamoreboy at yahoo.co.uk] > Sent: Wednesday, 4 April 2012 3:16 a.m. > To: python-list at python.org > Subject: Re: Number of languages known [was Re: Python is readable] - > somewhat OT > > On 03/04/2012 15:56, Chris Angelico wrote: > > On Wed, Apr 4, 2012 at 12:46 AM, Grant > Edwards wrote: > >> Anybody remember DEC's VAX/VMS "patch" utility? Apparently, DEC > >> thought it was a practical way to fix things. It had a built-in > >> assembler and let you "insert" new code into a function by > >> auto-allocating a location for the new code an hooking it into the > >> indicated spot with jump instructions. > >> > >> The mind wobbled. > > > > Not specifically, but I _have_ heard of various systems whose source > > code and binary were multiple years divergent. It's actually not a > > difficult trap to fall into, especially once you start patching > > running systems. I've had quite a few computers that have been unable > > to reboot without assistance, because they go for months or years > > without ever having to go through that initial program load. (I've > had > > _programs_ that were unable to load, for the same reason.) But > > auto-allocating a new spot for your expanded function? That's just... > > awesome. My mind is, indeed, wobbling. > > > > ChrisA > > Around 1990 I worked on Telematics kit. The patches on all their > software were implemented via assembler once the original binary had > been loaded into memory. They even came up with a system that let you > select which patches you wanted and which you didn't, as e.g. some > patches were customer specific. > > -- > Cheers. > > Mark Lawrence. > In the 70's I worked with Honeywell 16 Series computers controlling a variety of systems. The patches were loaded as a starting address followed by machine code, using a piece of software for this purpose. This all sounds rather similar to Mark's situation. The reason however is less obvious. On the H16 series we did not have a multi-access O/S and the process of assembling and linking a large system involved many steps. Often the modifications required were trivial. It was generally easier to reload a memory dump from off paper tape and then apply the patches. Phil Runciman From lookingforsmartppl at gmail.com Tue Apr 3 18:13:24 2012 From: lookingforsmartppl at gmail.com (looking for) Date: Tue, 3 Apr 2012 15:13:24 -0700 (PDT) Subject: Async IO Server with Blocking DB Message-ID: Hi We are thinking about building a webservice server and considering python event-driven servers i.e. Gevent/Tornado/ Twisted or some combination thereof etc. We are having doubts about the db io part. Even with connection pooling and cache, there is a strong chance that server will block on db. Blocking for even few ms is bad. can someone suggest some solutions or is async-io is not at the prime- time yet. Thanks From philr at aspexconsulting.co.nz Tue Apr 3 18:25:40 2012 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Wed, 4 Apr 2012 10:25:40 +1200 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: > On Tue, Apr 3, 2012 at 4:20 PM, Terry Reedy wrote: > > On 4/3/2012 8:39 AM, Nathan Rice wrote: > > > > > Ultimately, the answers to your questions exist in the world for you > > > to see. ?How does a surgeon describe a surgical procedure? ?How does > > > a chef describe a recipe? ?How does a carpenter describe the process > > > of building cabinets? ?Aside from specific words, they all use > > > natural language, and it works just fine. > > > > > > Not really. Surgeon's learn by *watching* a surgeon who knows the operation > > and next (hopefully) doing a particular surgery under supervision of such a > > surgeon, who watches and talks, and may even grab the instruments and > > re-show. They then really learn by doing the procedure on multiple > > people. They often kill a few on the way to mastery. > > > Well, there is declarative knowledge and procedural knowledge. In all > these cases, only the procedural knowledge is absolutely necessary, > but the declarative knowledge is usually a prerequisite to learning > the procedure in any sort of reasonable manner. There is also tacit knowledge. Such knowledge is a precursor to declarative knowledge and therefore procedural knowledge. "Tacit knowledge is not easily shared. It involves learning and skill, but not in a way that can be written down. Tacit knowledge consists often of habits and culture that we do not recognize in ourselves." Wikipedia. The process of eliciting tacit knowledge may be time consuming and require patience and skill. The following book covers aspects of this: Nonaka, Ikujiro; Takeuchi, Hirotaka (1995), The knowledge creating company: how Japanese companies create the dynamics of innovation. Phil Runciman From breamoreboy at yahoo.co.uk Tue Apr 3 18:50:26 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Apr 2012 23:50:26 +0100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: On 03/04/2012 19:42, Nathan Rice wrote: > I view "computer science" as applied mathematics, when it deserves > that moniker. When it doesn't, it is merely engineering. > Is it still April first in your time zone? -- Cheers. Mark Lawrence. From roy at panix.com Tue Apr 3 21:45:18 2012 From: roy at panix.com (Roy Smith) Date: Tue, 03 Apr 2012 21:45:18 -0400 Subject: Best way to structure data for efficient searching References: Message-ID: > On 3/28/2012 11:39 AM, Larry.Martell at gmail.com wrote: > > I have a set of data that is contains 3 fields, K1, K2 and a > > timestamp. There are duplicates in the data set, and they all have to > > processed. > > > > Then I have another set of data with 4 fields: K3, K4, K5, and a > > timestamp. There are also duplicates in that data set, and they also > > all have to be processed. > > > > I need to find all the items in the second data set where K1==K3 and > > K2==K4 and the 2 timestamps are within 20 seconds of each other. In article , John Nagle wrote: > [some good ideas] > All of these approaches are roughly O(N log N), which > beats the O(N^2) approach you have now. If the timestamps are sparse enough, I can think of a way that's O(N), or pretty close to it. From ishwar.rattan at gmail.com Tue Apr 3 23:45:54 2012 From: ishwar.rattan at gmail.com (ishwar.rattan at gmail.com) Date: Tue, 3 Apr 2012 20:45:54 -0700 (PDT) Subject: igraph and usage of Read(klass, f, format=None, *args, **kwds) question Message-ID: <21792534.128.1333511154039.JavaMail.geo-discussion-forums@ynpp8> I have a file with with adjacency list of an undirected graph one vertex list per input line [0 1, 1 2 3, 2 1, 3 1] assume a newline for commas (file is named adjl.txt). Can some one give an example of loading this into graph of 4 vertices? import igraph g = igraph.Graph() g.Read("adjl.txt", "edgelist") does not work.. Help will be appreciated. -ishwar From joncle at googlemail.com Wed Apr 4 00:41:54 2012 From: joncle at googlemail.com (Jon Clements) Date: Tue, 3 Apr 2012 21:41:54 -0700 (PDT) Subject: Async IO Server with Blocking DB In-Reply-To: References: Message-ID: <5414782.2428.1333514514280.JavaMail.geo-discussion-forums@vbpp14> On Tuesday, 3 April 2012 23:13:24 UTC+1, looking for wrote: > Hi > > We are thinking about building a webservice server and considering > python event-driven servers i.e. Gevent/Tornado/ Twisted or some > combination thereof etc. > > We are having doubts about the db io part. Even with connection > pooling and cache, there is a strong chance that server will block on > db. Blocking for even few ms is bad. > > can someone suggest some solutions or is async-io is not at the prime- > time yet. > > Thanks Maybe look at Cyclone (a Tornado variation built on Twisted), and various modules that will offer synch and events - GIYF! It's doable! Jon. From showell30 at yahoo.com Wed Apr 4 01:41:36 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 3 Apr 2012 22:41:36 -0700 (PDT) Subject: Async IO Server with Blocking DB References: Message-ID: <3d2d033e-99a6-4e5a-8c46-817ec222fc13@w6g2000pbp.googlegroups.com> On Apr 3, 3:13?pm, looking for wrote: > Hi > > We are thinking about building a webservice server and considering > python event-driven servers i.e. Gevent/Tornado/ Twisted or some > combination thereof etc. > > We are having doubts about the db io part. Even with connection > pooling and cache, there is a strong chance that server will block on > db. Blocking for even few ms is bad. > > can someone suggest some solutions or is async-io is not at the prime- > time yet. > Can you farm off DB requests to another process, so that you're at least not blocking the main process? From steve+comp.lang.python at pearwood.info Wed Apr 4 01:49:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2012 05:49:16 GMT Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: <4f7be0dc$0$29999$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 Apr 2012 13:17:18 -0400, Nathan Rice wrote: > I have never met a programmer that was not completely into computers. > That leaves a lot unspecified though. You haven't looked hard enough. There are *thousands* of VB, Java, etc. code monkeys who got into programming for the money only and who have zero inclination to expand their skills or knowledge beyond that necessary to keep their job. Go to programming blogs, and you will find many examples of some allegedly professional programmer selecting an arbitrary blog post to ask "Pls sombody write me this code", where "this code" is either an utterly trivial question or a six month project. > As part of my troll-outreach effort, I will indulge here. I was > specifically thinking about some earlier claims that programming > languages as they currently exist are somehow inherently superior to a > formalized natural language in expressive power. I would argue that they are, but only for the very limited purpose for which they are written. With the possible exception of Inform 7, most programming languages are useless at describing (say) human interactions. Human languages are optimised for many things, but careful, step-by-step algorithms are not one of them. This is why mathematicians use a specialist language for their problem domain, as do programmers. Human language is awfully imprecise and often ambiguous, it encourages implicit reasoning, and requires a lot of domain knowledge: Joe snatched the hammer from Fred. "Hey," he said, "what are you doing? Don't you know that he'll hit the roof if he catches you with that?" > I think part of this comes from the misconception that terse is better +1 > The crux of my view is that programming languages exist in part because > computers in general are not smart enough to converse with humans on > their own level, so we have to talk to them like autistic 5 year-olds. > That was fine when we didn't have any other options, but all the pieces > exist now to let computers talk to us very close to our own level, and > represent information at the same way we do. I think you're dreaming. We (that is to say, human beings in general, not you and I specifically) cannot even talk to each other accurately, precisely and unambiguously all the time. Natural language simply isn't designed for that -- hence we have specialist languages like legal jargon, mathematics, and programming languages, for specialist purposes. -- Steven From steve+comp.lang.python at pearwood.info Wed Apr 4 01:53:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2012 05:53:44 GMT Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> Message-ID: <4f7be1e8$0$29999$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > On 03/28/12 16:12, John Ladasky wrote: >> I'm looking for a Python (2.7) equivalent to the Unix "cp" command. >> Since the equivalents of "rm" and "mkdir" are in the os module, I >> figured I look there. I haven't found anything in the documentation. I >> am also looking through the Python source code in os.py and its child, >> posixfile.py. > > cp is not a system command, it's a shell command. Why not just use the > incredibly simple and portable > > >>>open("outfile", "w").write(open("infile").read()) > > put it into a method if you find that too much to type: > > def cp(infile, outfile): > open(outfile, "w").write(open(infile).read()) Because your cp doesn't copy the FILE, it copies the file's CONTENTS, which are not the same thing. Consider: * permissions * access times * file ownership * other metadata * alternate streams and/or resource fork, on platforms that support them * sparse files By the time you finish supporting the concept of copying the file itself, rather than merely its content, you will have something similar to the shutil.copy command -- only less tested. -- Steven From rustompmody at gmail.com Wed Apr 4 01:56:04 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 3 Apr 2012 22:56:04 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: <9c4b8903-ac88-42a5-8f27-fd0c0776ce53@lf20g2000pbb.googlegroups.com> On Apr 3, 11:42?pm, Nathan Rice wrote: > Lets start with some analogies. ?In cooking, chefs use recipes to > produce a meal; the recipe is not a tool. ?In architecture, a builder > uses a blueprint to produce a building; the blueprint is not a tool. > In manufacturing, expensive machines use plans to produce physical > goods; the plans are not the tool. > > You could say the compiler is a tool, or a development environment is > a tool. ?The programming language is a mechanism for communication. Long personal note ahead. tl;dr version: Computers are such a large shift for human civilization that generally we dont get what that shift is about or towards. ------ Longer version My mother often tells me (with some awe): You are so clever! You know how to use computers! (!?!?) I try to tell her that a computer is not a machine like a car is (she is better with things like cars than most of her generation). Its physical analogy to a typewriter is surprisingly accurate. In fact its more like a pen than other machines and its civilizational significance is larger than Gutenbergs press and is on par with the 'invention' (or should I say discovery?) of language as a fundamental fact of what it means to be human. [At this point or thereabouts my communication attempt breaks down because I am trying to tell her of the huge significance of programming...] A pen can be used to write love-letter or a death-sentence, a text- book of anatomy or a symphony. An yet it would be a bizarre superman who could do all these. Likewise (I vainly try to communicate with my mother!) that I cant design machines (with autocad) or paint (with photoshop) or ... probably 99% of the things that people use computers for. And so saying that I 'know computers' is on par with saying that because I know (how to use a pen to) fill up income tax forms, I should also know how to (use a pen to) write Shakespearean sonnets. There is a sense in which a pen is a 'universal device.' To some extent the layman can get this. There is a larger sense in which the computer is a universal device (aka universal turing machine). In my experience, not just 'my mother's' but even PhDs in computer science dont get what this signifies. This sense can (somewhat?) be appreciated if we see that the pen is entirely a declarative tool The computer is declarative+imperative. The person who writes the love-letter needs the postman to deliver it. The judge may write the death-sentence. A hangman is needed to execute it. When it comes to computers, the same device can write the love-letter/ death-sentence as the one which mails/controls the electric chair. Let me end with a quote from Dijkstra: http://www.smaldone.com.ar/documentos/ewd/EWD1036_pretty.html In the long run I expect computing science to transcend its parent disciplines, mathematics and logic, by effectively realizing a significant part of Leibniz's Dream of providing symbolic calculation as an alternative to human reasoning. (Please note the difference between "mimicking" and "providing an alternative to": alternatives are allowed to be better.) Needless to say, this vision of what computing science is about is not universally applauded. On the contrary, it has met widespread --and sometimes even violent-- opposition from all sorts of directions. I mention as examples (0) the mathematical guild, which would rather continue to believe that the Dream of Leibniz is an unrealistic illusion (1) the business community, which, having been sold to the idea that computers would make life easier, is mentally unprepared to accept that they only solve the easier problems at the price of creating much harder one (2) the subculture of the compulsive programmer, whose ethics prescribe that one silly idea and a month of frantic coding should suffice to make him a life-long millionaire (3) computer engineering, which would rather continue to act as if it is all only a matter of higher bit rates and more flops per second (4) the military, who are now totally absorbed in the business of using computers to mutate billion-dollar budgets into the illusion of automatic safety (5) all soft sciences for which computing now acts as some sort of interdisciplinary haven (6) the educational business that feels that, if it has to teach formal mathematics to CS students, it may as well close its schools. From steve+comp.lang.python at pearwood.info Wed Apr 4 02:19:56 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2012 06:19:56 GMT Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> Message-ID: <4f7be80c$0$29999$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 Apr 2012 08:39:14 -0400, Nathan Rice wrote: > Much like > with the terminal to GUI transition, you will have people attacking > declarative natural language programming as a stupid practice for noobs, > and the end of computing (even though it will allow people with much > less experience to be more productive than them). I cry every time I consider GUI programming these days. In the late 1980s and early 1990s, Apple released a product, Hypercard, that was a combination GUI framework and natural-ish language programming language. It was an astonishing hit with non-programmers, as it allowed people to easily move up from "point and click" programming to "real" programming as their skills improved. Alas, it has been abandoned by Apple, and while a few of its intellectual successors still exit, it very niche. I *really* miss Hypercard. Not so much for the natural language syntax, as for the astonishingly simple and obvious GUI framework. To get a flavour of the syntax, see OpenXION: http://www.openxion.org and for a hint of the framework, see Pythoncard: http://pythoncard.sourceforge.net > Ultimately, the answers to your questions exist in the world for you to > see. How does a surgeon describe a surgical procedure? How does a chef > describe a recipe? How does a carpenter describe the process of > building cabinets? Aside from specific words, they all use natural > language, and it works just fine. No they don't. In general they don't use written language at all, but when they are forced to, they use a combination of drawings or illustrations plus a subset of natural language plus specialist jargon. Programming languages include both specialist grammar and specialist semantics. That makes it a cant or an argot. -- Steven From chris at python.org Wed Apr 4 02:41:04 2012 From: chris at python.org (Chris Withers) Date: Wed, 04 Apr 2012 07:41:04 +0100 Subject: [pyxl] Re: xlrd 0.7.4 released! In-Reply-To: <15454045.1017.1333485973850.JavaMail.geo-discussion-forums@pbon5> References: <4F7AA10B.6020907@simplistix.co.uk> <15454045.1017.1333485973850.JavaMail.geo-discussion-forums@pbon5> Message-ID: <4F7BED00.3010404@python.org> On 03/04/2012 21:46, Josh English wrote: > When I try to import xlrd, I get an error > > IOError: [Errno 2] No such file or directory: > 'C:\\Users\\josh\\Desktop\\Portable > Python\\App\\lib\\site-packages\\xlrd-0.7.5-py2.7.egg\\xlrd\\version.txt' *sigh* I hate python packaging, I'll get a 0.7.6 release out this morning which will hopefully finally fix this... > I didn't think EGG files could be folders. Is there a change in the way > the EGG file was meant to be distributed? Eggs have always been installed as folders. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From showell30 at yahoo.com Wed Apr 4 03:07:33 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 4 Apr 2012 00:07:33 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <4f7be80c$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7d825b56-8f60-4899-bb14-e7e61d9e15a6@vn5g2000pbc.googlegroups.com> On Apr 3, 11:19?pm, Steven D'Aprano wrote: > On Tue, 03 Apr 2012 08:39:14 -0400, Nathan Rice wrote: > > Much like > > with the terminal to GUI transition, you will have people attacking > > declarative natural language programming as a stupid practice for noobs, > > and the end of computing (even though it will allow people with much > > less experience to be more productive than them). > > I cry every time I consider GUI programming these days. > > In the late 1980s and early 1990s, Apple released a product, Hypercard, > that was a combination GUI framework and natural-ish language programming > language. It was an astonishing hit with non-programmers, as it allowed > people to easily move up from "point and click" programming to "real" > programming as their skills improved. > > Alas, it has been abandoned by Apple, and while a few of its intellectual > successors still exit, it very niche. > > I *really* miss Hypercard. Not so much for the natural language syntax, > as for the astonishingly simple and obvious GUI framework. > > To get a flavour of the syntax, see OpenXION: > > http://www.openxion.org > > and for a hint of the framework, see Pythoncard: > > http://pythoncard.sourceforge.net > > > Ultimately, the answers to your questions exist in the world for you to > > see. ?How does a surgeon describe a surgical procedure? ?How does a chef > > describe a recipe? ?How does a carpenter describe the process of > > building cabinets? ?Aside from specific words, they all use natural > > language, and it works just fine. > > No they don't. In general they don't use written language at all, but > when they are forced to, they use a combination of drawings or > illustrations plus a subset of natural language plus specialist jargon. > > Programming languages include both specialist grammar and specialist > semantics. That makes it a cant or an argot. The "building cabinets" problem is interesting: 1. To actually build a cabinet, there's a lot of domain knowledge that's probably implicit in most circumstances. A carpenter might tell another carpenter which hinge to use, but they won't have to talk about why doors need hinges or how to do the assembly. 2. It's quite common for humans to use computer programs as part of the design process. 3. Often, the output of a CAD program (at the file level) is some sort of vector representation that only describes the end product (basic dimensions, etc.). I wonder if there are mini-languages out there that allow you to describe cabinets in a very descriptive way, where the description easily translates to the actual steps of building the cabinet, not just the final dimensions. From chris at simplistix.co.uk Wed Apr 4 03:24:27 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 04 Apr 2012 08:24:27 +0100 Subject: xlrd 0.7.6 released! In-Reply-To: <4F7AA803.1020808@simplistix.co.uk> References: <4F7AA10B.6020907@simplistix.co.uk> <4F7AA803.1020808@simplistix.co.uk> Message-ID: <4F7BF72B.7080807@simplistix.co.uk> And the goat sacrifice continues... On 03/04/2012 08:34, Chris Withers wrote: > On 03/04/2012 08:04, Chris Withers wrote: >> I'm pleased to announce the release of xlrd 0.7.4. > I've just release a 0.7.5 that fixes this. Except it didn't, I've just released 0.7.6, which will hopefully bring an end to the brown-bagging. Any more problems, please let the python-excel at googlegroups.com mailing list know... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From spamtrap at library.lspace.org.invalid Wed Apr 4 03:33:24 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Wed, 04 Apr 2012 03:33:24 -0400 Subject: Is Programing Art or Science? References: <87hax0suun.fsf@sapphire.mobileactivedefense.com> Message-ID: <4f7bf944$9$fuzhry+tra$mr2ice@news.patriot.net> In <87hax0suun.fsf at sapphire.mobileactivedefense.com>, on 04/03/2012 at 04:22 PM, Rainer Weikusat said: >http://en.wikipedia.org/wiki/Liberal_arts Do you need the Quadrivium or is the Trivium enough for programming ? If the term "art" is good enough for Knuth it's good enough for me. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From me at rishabhverma.me Wed Apr 4 03:51:54 2012 From: me at rishabhverma.me (Rishabh Verma) Date: Wed, 4 Apr 2012 13:21:54 +0530 Subject: Implementing python program running in background. Message-ID: I need to implement a simple python program, which will be using the oAuth tokens and secrets of all users in out system and will be fetching some stuff from a JSON API. The list of all these users(with a flag if they are logged-in or not right now) is there in a Redis DB. The JSON API needs to be queried every 5 minutes for a user who is not logged-in right now, and every 2 minutes for a user who is logged in right now. This program should always be running in the background. What should be the correct way to implement this kind of a thing? -- *Rishabh Verma @rishabhverma | +91-8285687993 www.rishabhverma.me* -------------- next part -------------- An HTML attachment was scrubbed... URL: From mcepl at redhat.com Wed Apr 4 04:33:35 2012 From: mcepl at redhat.com (Matej Cepl) Date: Wed, 04 Apr 2012 10:33:35 +0200 Subject: ANN: bayeux 0.2 released Message-ID: <4F7C075F.1020102@redhat.com> Bayeux 0.2 is now available at http://pypi.python.org/pypi/bayeux bayeux is a module for generating TAP (http://testanything.org/). Version 0.2 is an initial version registered in the Cheesshop. Release notes: -------------- * module tap.py for programatic writing of TAP stream * clone of unittest2 generating TAP stream instead of the normal unittest output. * example script for generating TAP stream from JSON results of piglit test suite. Links: ------ * homepage http://pypi.python.org/pypi/bayeux * code repository https://gitorious.org/bayeux/bayeux * bug reports and enhancement requests to mcepl_at_redhat_dot_com or to https://luther.ceplovi.cz/bugzilla/ (product TAP) From rosuav at gmail.com Wed Apr 4 04:37:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2012 18:37:20 +1000 Subject: No os.copy()? Why not? In-Reply-To: <4f7be1e8$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <4f7be1e8$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 4, 2012 at 3:53 PM, Steven D'Aprano wrote: > On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > >> def cp(infile, outfile): >> ? ?open(outfile, "w").write(open(infile).read()) > > Because your cp doesn't copy the FILE, it copies the file's CONTENTS, > which are not the same thing. And, as a subtle point: This method can't create the file "at size". I don't know how it'll end up allocating space, but certainly there's no opportunity to announce to the OS at file open/create time "please allocate X bytes for this file". That may be an utterly trivial point, or a crucially vital one. ChrisA From kliateni at gmail.com Wed Apr 4 04:57:27 2012 From: kliateni at gmail.com (Karim) Date: Wed, 04 Apr 2012 10:57:27 +0200 Subject: xlrd 0.7.6 released! In-Reply-To: <4F7BF72B.7080807@simplistix.co.uk> References: <4F7AA10B.6020907@simplistix.co.uk> <4F7AA803.1020808@simplistix.co.uk> <4F7BF72B.7080807@simplistix.co.uk> Message-ID: <4F7C0CF7.2040509@gmail.com> Le 04/04/2012 09:24, Chris Withers a ?crit : > And the goat sacrifice continues... > > On 03/04/2012 08:34, Chris Withers wrote: >> On 03/04/2012 08:04, Chris Withers wrote: >>> I'm pleased to announce the release of xlrd 0.7.4. >> I've just release a 0.7.5 that fixes this. > > Except it didn't, I've just released 0.7.6, which will hopefully bring > an end to the brown-bagging. > > Any more problems, please let the python-excel at googlegroups.com > mailing list know... > > cheers, > > Chris > Hello, This release manage the '.xlsx' format? Thanks Karim From bastian.ballmann at notch-interactive.com Wed Apr 4 04:59:40 2012 From: bastian.ballmann at notch-interactive.com (Bastian Ballmann) Date: Wed, 04 Apr 2012 10:59:40 +0200 Subject: Python and Bloomberg In-Reply-To: <26f6e8d4-6350-4d9b-96d1-44ea1be72a14@l30g2000yqb.googlegroups.com> References: <26f6e8d4-6350-4d9b-96d1-44ea1be72a14@l30g2000yqb.googlegroups.com> Message-ID: <4F7C0D7C.6020306@notch-interactive.com> Am 03.04.2012 16:35, schrieb SMac2347 at comcast.net: > Hello, I was just wondering if anyone had experience using Python to > interact with Bloomberg. Ideally, I'd look to use Python to feed > Bloomberg's OVML calculator with a list of inputs, and then use an > additional program to grab the results of the calculator for each > calculation, and pull them into another document, ideally an excel > spreadsheet or alternatively a delimited .txt file. > > Any thoughts or ideas are very much appreciated. Thanks! Bloomberg has got SOAP for many (or all?) of its services. So maybe you could use SOAPpy to communicate with it. See http://www.ibm.com/developerworks/library/ws-pyth5/ HTH && Greets Basti -- Bastian Ballmann / Web Developer Notch Interactive GmbH / Badenerstrasse 571 / 8048 Z?rich Phone +41 43 818 20 91 / www.notch-interactive.com From maus_on_mars at yahoo.co.uk Wed Apr 4 05:14:24 2012 From: maus_on_mars at yahoo.co.uk (frankenstein) Date: Wed, 4 Apr 2012 02:14:24 -0700 (PDT) Subject: Seeking help: reading text file with genfromtxt Message-ID: <146fe4b1-7747-4319-a62a-0088e2dc34e2@2g2000yqk.googlegroups.com> Hi all I have got a text file which is only 32 MB in size and consists of the following type of lines (columns are fixed): == Header text 1 line ... 01-Jan-2006 0055 145.069 -16.0449 83.2246 84.2835 499.14680 0.074029965 01-Jan-2006 0065 15.069 -1.0449 83.2246 84.2835 499.14680 12.074029965 ... 12-Dec-2006 1255 145.069 23.0449 3.2246 4.2835 49.140 0.74029965 ... == I have 3 questions: 1. Why is my translation (read_slow) of the IDL code so damn slow (IDL: 13 sec, Python:2min16sec). Although both IDL and Python consume about 40 MB. 2. Why is my faster version (read_fast) (13sec) so memory hungry (it takes 200MB)? 2.1 Why is my second fastest version (read_second_fast) (16sec) still memory hungry? 3. What do I need to do to get the speed of IDL and the memory footprint of IDL (in that case 40MB)? #convdate converts the date in the first column (e.g. 12-Dec-2006) into day of year #convtime does something else == import fileinput import numpy as np import datetime import time from StringIO import StringIO def read_slow(file): count=max(enumerate(open(file)))[0] erg=np.zeros((count,10),dtype=np.float64) convdate= lambda x: time.strptime(x,"%d-%b-%Y").tm_yday convtime= lambda x: np.int(np.float64(x)*1.0e-1) i=0 with open(file) as infile: #read first header line infile.readline() for line in infile: tmp=np.genfromtxt(StringIO(line),\ dtype=np.float64,\ converters={0:convdate, 1:convtime}) #not sure if it does the right thing here: erg[i,:]=tmp i=i+1 infile.close() return erg == def read_fast(file): convdate= lambda x: time.strptime(x,"%d-%b-%Y").tm_yday convtime= lambda x: np.int(np.float64(x)*1.0e-1) with open(file) as infile: erg=np.genfromtxt(infile, autostrip=True,skip_header=1,\ dtype=np.float64,\ converters={0:convdate,1:convtime}) infile.close() return erg == == def read_second_fast(file): convdate= lambda x: time.strptime(x,"%d-%b-%Y").tm_yday convtime= lambda x: np.int(np.float64(x)*1.0e-1) erg=np.loadtxt(file,skiprows=1,\ dtype=np.float64,\ converters={0:convdate,1:convtime}) return erg == Thanks for all the help. By the way: I colleague told me my code is 1. poorly written and more or less unreadable and unmaintainable because of the use of lambda. I am just learning but is his observation true? From alain at dpt-info.u-strasbg.fr Wed Apr 4 05:22:45 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 04 Apr 2012 11:22:45 +0200 Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <4f7be1e8$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87fwcj4zru.fsf@dpt-info.u-strasbg.fr> Steven D'Aprano writes: > On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > >> On 03/28/12 16:12, John Ladasky wrote: >>> I'm looking for a Python (2.7) equivalent to the Unix "cp" command. >> >>>open("outfile", "w").write(open("infile").read()) > Because your cp doesn't copy the FILE, it copies the file's CONTENTS, > which are not the same thing. > Consider: > * permissions > * access times > * file ownership > * other metadata > * alternate streams and/or resource fork, on platforms that support them > * sparse files > By the time you finish supporting the concept of copying the file itself, > rather than merely its content, you will have something similar to the > shutil.copy command -- only less tested. A minor point, but shutil.copy only "copies" contents and permissions (no access times, etc.) You probably mean shutil.copy2. And sparse files are really hard to reproduce, at least on Unix: on Linux even the system's cp doesn't guarantee sparseness of the copy (the manual mentions a "crude heuristic"). But of course shutil.copy is the best solution to mimic a raw cp. -- Alain. From roy at panix.com Wed Apr 4 08:08:31 2012 From: roy at panix.com (Roy Smith) Date: Wed, 04 Apr 2012 08:08:31 -0400 Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <4f7be1e8$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > > cp is not a system command, it's a shell command. Why not just use the > > incredibly simple and portable > > > > >>>open("outfile", "w").write(open("infile").read()) In article <4f7be1e8$0$29999$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Because your cp doesn't copy the FILE, it copies the file's CONTENTS, > which are not the same thing. Not to mention that this will read the entire contents of the file into memory at once. Probably don't want to do that with 100 GB of data. Slightly off-topic, but are there file systems these days which support off-line copying? If I have a disk at the other end of a network link, it would be nice to tell the disk to copy a file and tell me when it's done. As opposed to dragging all that data over the network just so I can buffer it in local memory and shove it right back out the network port to the same disk. That kind of stuff used to be standard practice in the neanderthalic days of IBM mainframes. From roy at panix.com Wed Apr 4 08:14:18 2012 From: roy at panix.com (Roy Smith) Date: Wed, 04 Apr 2012 08:14:18 -0400 Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <4f7be1e8$0$29999$c3e8da3$5496439d@news.astraweb.com> <87fwcj4zru.fsf@dpt-info.u-strasbg.fr> Message-ID: In article <87fwcj4zru.fsf at dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > And sparse files are really hard to reproduce, at least on Unix: on > Linux even the system's cp doesn't guarantee sparseness of the copy (the > manual mentions a "crude heuristic"). I imagine the heuristic is to look for blocks of all zeros. The problem is, unless you know the block size of the file system, you can only guess as to how many zeros in a row you need to look for. In the old days, dump/restore used to know about sparse files. But things like dump/restore really get inside the file system's kimono. In today's world of SANs, WANs, and all sorts of virtual file-system-ish things, I would expect that's less common. From rosuav at gmail.com Wed Apr 4 08:17:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2012 22:17:20 +1000 Subject: No os.copy()? Why not? In-Reply-To: References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <4f7be1e8$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 4, 2012 at 10:08 PM, Roy Smith wrote: > Slightly off-topic, but are there file systems these days which support > off-line copying? ?If I have a disk at the other end of a network link, > it would be nice to tell the disk to copy a file and tell me when it's > done. Depends on your network protocol. One of the coolest and oldest tricks with FTP is initiating a file transfer from one remote host to another; I've never done it but it ought to work with localhost (ie two sessions to the same host). ChrisA From research at johnohagan.com Wed Apr 4 08:25:45 2012 From: research at johnohagan.com (John O'Hagan) Date: Wed, 4 Apr 2012 22:25:45 +1000 Subject: Run once while loop In-Reply-To: <-5854393752682031995@unknownmsgid> References: <7619907723400632495@unknownmsgid> <-5854393752682031995@unknownmsgid> Message-ID: <20120404222545.f4c1adf44d2d9c7d64a60ce3@johnohagan.com> On Tue, 3 Apr 2012 23:00:22 +0200 Anatoli Hristov wrote: > On 03 Apr 2012, at 22:45, Ian Kelly wrote: > > > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: > >> Hi, > >> > >> I'm trying to do a while loop with condition of time if time is > >> 12:00:00 print text, but for this one second the text is printed at > >> least 50 times, how can I print only once? > > > > Set a flag when you print the text to indicate that you've already > > printed it, and don't print it again if the flag is set. When it's no > > longer 12:00:00, reset the flag. > > > > That said, a busy while loop is probably the wrong way to do this, > > because it will run your CPU at 100%. Better would be to put the > > thread to sleep with time.sleep() calls or a real event loop with a > > timer event. > > > > Cheers, > > Ian > > Thank you Ian, > > what if I wait for other conditions if I use time.sleep for 1 sec? it > means that all the program is sleeping for a sec. > If I understand correctly, you don't want the whole program to sleep. If that's the case, you could use threading.Timer, for example: import threading, time def twelve(): print("It's twelve o'clock") local_secs = (time.time() - time.timezone) % (24 * 60 * 60) secs_till_12 = 12 * 60 * 60 - (local_secs % (12 * 60 * 60)) wait_till_12 = threading.Timer(secs_till_12, twelve) wait_till_12.start() Regards, John From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Apr 4 08:30:35 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 04 Apr 2012 14:30:35 +0200 Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <5062483b-6419-4ea3-afc0-358cbd735e45@w6g2000pbp.googlegroups.com> Message-ID: Am 03.04.2012 11:34 schrieb John Ladasky: > I use subprocess.call() for quite a few other things. > > I just figured that I should use the tidier modules whenever I can. Of course. I only wanted to point out that os.system() is an even worse approach. shutils.copy() is by far better, of course. From tolidtm at gmail.com Wed Apr 4 09:21:30 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Wed, 4 Apr 2012 15:21:30 +0200 Subject: Run once while loop In-Reply-To: <20120404222545.f4c1adf44d2d9c7d64a60ce3@johnohagan.com> References: <7619907723400632495@unknownmsgid> <-5854393752682031995@unknownmsgid> <20120404222545.f4c1adf44d2d9c7d64a60ce3@johnohagan.com> Message-ID: I thing the best will be if I use hundreds of the seconds to print the message. for example at 12:00:00:10, but unfortunately I cant see that I can use hundreds of the seconds. Does anyone knows if I can use it ? Thanks Anatoli On Wed, Apr 4, 2012 at 2:25 PM, John O'Hagan wrote: > On Tue, 3 Apr 2012 23:00:22 +0200 > Anatoli Hristov wrote: > > > On 03 Apr 2012, at 22:45, Ian Kelly wrote: > > > > > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov > wrote: > > >> Hi, > > >> > > >> I'm trying to do a while loop with condition of time if time is > > >> 12:00:00 print text, but for this one second the text is printed at > > >> least 50 times, how can I print only once? > > > > > > Set a flag when you print the text to indicate that you've already > > > printed it, and don't print it again if the flag is set. When it's no > > > longer 12:00:00, reset the flag. > > > > > > That said, a busy while loop is probably the wrong way to do this, > > > because it will run your CPU at 100%. Better would be to put the > > > thread to sleep with time.sleep() calls or a real event loop with a > > > timer event. > > > > > > Cheers, > > > Ian > > > > Thank you Ian, > > > > what if I wait for other conditions if I use time.sleep for 1 sec? it > > means that all the program is sleeping for a sec. > > > > If I understand correctly, you don't want the whole program to sleep. If > that's the case, you could use threading.Timer, for example: > > import threading, time > > def twelve(): > print("It's twelve o'clock") > > local_secs = (time.time() - time.timezone) % (24 * 60 * 60) > secs_till_12 = 12 * 60 * 60 - (local_secs % (12 * 60 * 60)) > > wait_till_12 = threading.Timer(secs_till_12, twelve) > wait_till_12.start() > > > Regards, > > John > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Apr 4 09:42:07 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 4 Apr 2012 09:42:07 -0400 Subject: Run once while loop In-Reply-To: References: <7619907723400632495@unknownmsgid> <-5854393752682031995@unknownmsgid> <20120404222545.f4c1adf44d2d9c7d64a60ce3@johnohagan.com> Message-ID: On Wed, Apr 4, 2012 at 9:21 AM, Anatoli Hristov wrote: > I thing the best will be if I use hundreds of the seconds to print the > message. > > for example at 12:00:00:10, but unfortunately I cant see that I can use > hundreds of the seconds. > > Does anyone knows if I can use it ? > > Thanks > > Anatoli > > Your proposed solution is one of those hacks that will cause your program to fail if we get better machines that could run that loop twice in 1/100th of a second. "When the only tool you have is a hammer, every problem looks like a nail". You need to add more tools to your toolbox than an infinite loop. If your problem is that you want to trigger an event at a specific time, John's answer is the correct one. If your entire program is just this recurring task, use your OS's task scheduler (Task Scheduler for Windows, Launchd for Mac OS X, and Cron for other *nixes). > On Wed, Apr 4, 2012 at 2:25 PM, John O'Hagan > wrote: >> >> On Tue, 3 Apr 2012 23:00:22 +0200 >> Anatoli Hristov wrote: >> >> > On 03 Apr 2012, at 22:45, Ian Kelly wrote: >> > >> > > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov >> > > wrote: >> > >> Hi, >> > >> >> > >> I'm trying to do a while loop with condition of time if time is >> > >> 12:00:00 print text, but for this one second the text is printed at >> > >> least 50 times, how can I print only once? >> > > >> > > Set a flag when you print the text to indicate that you've already >> > > printed it, and don't print it again if the flag is set. ?When it's no >> > > longer 12:00:00, reset the flag. >> > > >> > > That said, a busy while loop is probably the wrong way to do this, >> > > because it will run your CPU at 100%. ?Better would be to put the >> > > thread to sleep with time.sleep() calls or a real event loop with a >> > > timer event. >> > > >> > > Cheers, >> > > Ian >> > >> > Thank you Ian, >> > >> > what if I wait for other conditions if I use time.sleep for 1 sec? it >> > means that all the program is sleeping for a sec. >> > >> >> If I understand correctly, you don't want the whole program to sleep. If >> that's the case, you could use threading.Timer, for example: >> >> import threading, time >> >> def twelve(): >> ? ?print("It's twelve o'clock") >> >> local_secs = (time.time() - time.timezone) % (24 * 60 * 60) >> secs_till_12 = 12 * 60 * 60 - (local_secs % (12 * 60 * 60)) >> >> wait_till_12 = threading.Timer(secs_till_12, twelve) >> wait_till_12.start() >> >> >> Regards, >> >> John >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From ishwar.rattan at gmail.com Wed Apr 4 10:00:40 2012 From: ishwar.rattan at gmail.com (ish) Date: Wed, 4 Apr 2012 07:00:40 -0700 (PDT) Subject: Igraph and usage of Read(kclass, f, format=...) question Message-ID: <13601107.162.1333548040812.JavaMail.geo-discussion-forums@yncc18> I am using igraph package via Python interface. I have a list of edges of a graph one edge per line of input in a file (e.txt) and want igraph to read the edges into the graph. Can any one give me a usage hint of igraph.Graph.Read()?? import igraph g = igraph.Graph() g.add_vertices(3) # 4 vertices g.Read("e.txt", "egdes") but does not work! Any pointer will be appreciated. -ish From nathan.alexander.rice at gmail.com Wed Apr 4 10:25:11 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 4 Apr 2012 10:25:11 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <4f7be0dc$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <4f7be0dc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 4, 2012 at 1:49 AM, Steven D'Aprano wrote: > On Tue, 03 Apr 2012 13:17:18 -0400, Nathan Rice wrote: > >> I have never met a programmer that was not completely into computers. >> That leaves a lot unspecified though. > > You haven't looked hard enough. There are *thousands* of VB, Java, etc. > code monkeys who got into programming for the money only and who have > zero inclination to expand their skills or knowledge beyond that > necessary to keep their job. Every programmer that I've ever met who got into it for the money has washed out within about five years. Sometimes they make a lateral move to project management, other times they end up as requirements analysts, and occasionally they become technical sales staff. The story is always the same - they do technical mediocre work, but get along well with their peers, so they are transitioned to a role that requires more people skills. I've never met someone who had both poor people skills and mediocre technical skills who actually kept their job. > Go to programming blogs, and you will find many examples of some > allegedly professional programmer selecting an arbitrary blog post to ask > "Pls sombody write me this code", where "this code" is either an utterly > trivial question or a six month project. Honestly, I have seen that, but usually when I inspect closer it is an Indian ODesk or Rent-a-coder worker who oversold himself and is trying to cover his ass. >> As part of my troll-outreach effort, I will indulge here. ?I was >> specifically thinking about some earlier claims that programming >> languages as they currently exist are somehow inherently superior to a >> formalized natural language in expressive power. > > I would argue that they are, but only for the very limited purpose for > which they are written. With the possible exception of Inform 7, most > programming languages are useless at describing (say) human interactions. > > Human languages are optimised for many things, but careful, step-by-step > algorithms are not one of them. This is why mathematicians use a > specialist language for their problem domain, as do programmers. Human > language is awfully imprecise and often ambiguous, it encourages implicit > reasoning, and requires a lot of domain knowledge: You have to be careful when you bring mathematical notation into the picture. Remember that mathematics has developed over thousands of years, with developments shared in many languages. Greek letters serve the same purpose in math that latin and greek names serve in biology - they are neutral and avoid confusion with common names in "living" languages. Not everything about mathematical notation is good, and in some cases it suffers the same issues that programming does. Mathematicians have a tendency to be very terse, and although some greek letters and symbols have standard meaning, many authors run roughshod over them. Logic is somewhat better than math in this regard, logicians respect their notation and rarely deviate from the standard meaning of symbols. Things ARE getting better, but for the most part it is still kind of a mess. Also, I should clarify that I consider part of mathematical notation to be "natural language", namely +/-/*, and rational numbers. People "discover" these things on their own, mathematics just provides rigor. It is considered bad form to use them in prose, but that is just an arbitrary "style" restriction; children intermix mathematical symbols and language all the time, as to older students taking notes in a variety of subjects. > ? ?Joe snatched the hammer from Fred. "Hey," he said, "what are > ? ?you doing? Don't you know that he'll hit the roof if he catches > ? ?you with that?" Are you trying to get me to write obfuscated code? You can write ambiguous garbage in any language. >> The crux of my view is that programming languages exist in part because >> computers in general are not smart enough to converse with humans on >> their own level, so we have to talk to them like autistic 5 year-olds. >> That was fine when we didn't have any other options, but all the pieces >> exist now to let computers talk to us very close to our own level, and >> represent information at the same way we do. > > I think you're dreaming. We (that is to say, human beings in general, not > you and I specifically) cannot even talk to each other accurately, > precisely and unambiguously all the time. Natural language simply isn't > designed for that -- hence we have specialist languages like legal > jargon, mathematics, and programming languages, for specialist purposes. Legalese is English with a ton of new words. Mathematics is older than most languages in current use and has a lot of baggage that is (very) slowly being dealt with. Programming really can't take the relaxed attitude about cleaning up notation and vocabulary that we see in math. Mathematicians spend a lot of time thinking, and the transcription of their thoughts is a relatively minor portion of their overall work. Most programmers spend a little time thinking, and the transcription of their thoughts is the lion's share of their overall work. 3000 lines of math is beastly, and probably represents a serious proof for the solution of a challenging problem. 3000 lines of code doesn't get you much. We'll get there eventually. The only question is whether programmers see the winds of change-a-blowing and position themselves to take advantage of the situation, or they are slowly crowded out by intelligent agents like IBM's Watson. From k.sahithi2862 at gmail.com Wed Apr 4 10:48:42 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 4 Apr 2012 07:48:42 -0700 (PDT) Subject: NEW HOT PHOTOS & VIDEOS Message-ID: <4863f649-b627-4d47-9a6a-1032a6c1e624@8g2000pbm.googlegroups.com> TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR ONLY HOT GUYS SEE THIS VIMALA RAMAN LATEST HOT STILLS http://hotactress-kalyani.blogspot.com/2012/03/vimalaraman-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/09/priyamani-hot.html ANUSHKA HOT ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/anushka-hot.html KAJAL AGARWAL LATEST HOT WITHOUT TOP http://hotactress-kalyani.blogspot.in/2011/08/kajal-agarwal-hot-photos.html AMISHA PATEL LATEST HOT STILLS http://hotactress-kalyani.blogspot.in/2011/08/amisha-patel-hot.html KATRINA KAIF HOT SPICY STILLS http://hotactress-kalyani.blogspot.in/2011/08/katrina-kaif-hot.html NEERU BAJWA LATEST SPICY STILLS http://hotactress-kalyani.blogspot.in/2011/12/neeru-bajwa-hot.html PRIYANKA TIWARI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/priyanka-tiwari-hot.html SAMANTHA LATEST HOT STILLS http://hotactress-kalyani.blogspot.in/2011/09/samantha-hot.html DEEKSHASETH LATEST ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/09/deeksha-seth-hot.html PAYAL GHOSH HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/payal-ghosh-hot.html SIDDI MAMRE HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2012/02/siddhi-mamre-hot.html SHEENA SHAHABADI LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2012/02/sheena-shahabadi-hot.html LATEST HOT KATRINA KAIF PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/katrina-kaif-hot.html ANUSHKA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/anushka-hot.html KAJAL AGARWAL HOT SAREE STILLS http://hotactress-kalyani.blogspot.in/2011/11/kajal-agarwal-hot-in-saree.html RAGINI DWIVEDI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/ragini-dwivedi.html PARVATHI MELTON LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/parvathi-melton-hot.html SARAH JANE DIAS HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/sarah-jane-dias-hot.html TAMANNA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/tamanna-hot.html PARUL HOT PHOTO STILLS http://hotactress-kalyani.blogspot.in/2011/12/parul-hot.html ADITI AGARWAL NEW ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/12/aditi-agarwal-hot.html POONAM KAUR HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/11/poonam-kaur-hot.html AMISHA PATEL LATEST HOT BIKINI STILLS http://hotactress-kalyani.blogspot.in/2011/08/amisha-patel-hot.html { ALL LATEST MOVIE STILLS} KAJAL BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/kajal-agarwal-in-business-man.html SONAM KAPOOR LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sonam-kapoor-maxim-photoshoot-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2012/01/ritu-kaur-stills.html SWAPNA SUNDARI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/swapna-sundari-movie-stills.html SEVAKUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sevakudu-movie-stills.html. SRIKANTH DEVARA MOVIE GALLERY http://actressgallery-kalyani.blogspot.in/2011/12/devaraya-movie-stills.html KULLUMANALI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kullu-manali-movie-stills.html BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/businessman-movie-stills.html HOT ACTRESS BIKINI STILLS IN 2012 CALENDAR http://actressgallery-kalyani.blogspot.in/2011/12/2012-actress-calendar-wallpapers.html KSHETHRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kshethram-movie-stills.html SAMANTHA SOUTHSCOPE HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/12/samantha-at-south-scope-magazine.html BODYGAURD LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/bodyguard-telugu-movie-stills_14.html DEEPIKA PADUKONE SPICY WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/deepika-padukone.html KATRINA KAIF LATEST HOT WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/katrina-kaif-wallpapers.html NIPPU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/nippu-movie-stills.html LOVE FAILURE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/love-failure-movie-stills.html VIKRAM VEEDINTHE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/veedinthe-movie-stills.html 4FRIENDS MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/4-friends-movie-stills.html NANDEESWARUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/nandeeswarudu-movie-stills.html HARI PRIYA HOT PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/12/haripariya-actress.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.in/2011/11/shruti-hassan-in-3-movie.html PANJA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2011/11/panja-movie-stills.html URIMI LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/urimi-movie-stills.html ROUDRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/roudram-movie-stills.html SIMHAPUTHRUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/simhaputhrudu-movie-stills.html SOLO MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/solo-movie-stills.html BEZAWADA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/bezawada-movie-stills.html RAJANNA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/rajanna-movie-stills.html\ POOLARANGADU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/poolarangadu-movie-stills.html PRIYUDU HOT ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/11/priyudu-movie-stills.html ADHINAYAKUDU LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/adhinayakudu-movie-stills.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/katrina-kaif.html AISHWARYA RAI HOT HQ PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/09/aishwarya-rai.html ASIN HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.in/2011/09/asin.html HANSIKA MATOWNI LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2011/09/hansika-motwani.html KAJAL AGARWAL HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/kajal-agarwal.html SNEHA HOT GOA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/09/goa-movie-stills.html From showell30 at yahoo.com Wed Apr 4 11:15:54 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 4 Apr 2012 08:15:54 -0700 (PDT) Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <4f7be1e8$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 4, 1:37?am, Chris Angelico wrote: > On Wed, Apr 4, 2012 at 3:53 PM, Steven D'Aprano > > wrote: > > On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > > >> def cp(infile, outfile): > >> ? ?open(outfile, "w").write(open(infile).read()) > > > Because your cp doesn't copy the FILE, it copies the file's CONTENTS, > > which are not the same thing. > > And, as a subtle point: This method can't create the file "at size". I > don't know how it'll end up allocating space, but certainly there's no > opportunity to announce to the OS at file open/create time "please > allocate X bytes for this file". That may be an utterly trivial point, > or a crucially vital one. > > ChrisA FWIW shutil.py doesn't do anything particularly fancy with respect to creating files "at size", unless I'm missing something: http://hg.python.org/cpython/file/2.7/Lib/shutil.py Only one level away from copyfile, you have copyfileobj, which is a read/write loop: 46 def copyfileobj(fsrc, fdst, length=16*1024): 47 """copy data from file-like object fsrc to file-like object fdst""" 48 while 1: 49 buf = fsrc.read(length) 50 if not buf: 51 break 52 fdst.write(buf) ...and that gets called by copyfile, which only does a little bit of "os"-related stuff: 66 def copyfile(src, dst): 67 """Copy data from src to dst""" 68 if _samefile(src, dst): 69 raise Error("`%s` and `%s` are the same file" % (src, dst)) 70 71 for fn in [src, dst]: 72 try: 73 st = os.stat(fn) 74 except OSError: 75 # File most likely does not exist 76 pass 77 else: 78 # XXX What about other special files? (sockets, devices...) 79 if stat.S_ISFIFO(st.st_mode): 80 raise SpecialFileError("`%s` is a named pipe" % fn) 81 82 with open(src, 'rb') as fsrc: 83 with open(dst, 'wb') as fdst: 84 copyfileobj(fsrc, fdst) The "value add" vs. a simple read/write loop depends on whether you want OSError suppressed. The _samefile guard is nice to have, but probably unnecessary for many apps. I'm sure shutil.copyfile() makes perfect sense for most use cases, and it's nice that you can see what it does under the covers pretty easily, but it's not rocket science. From cartercc at gmail.com Wed Apr 4 11:47:35 2012 From: cartercc at gmail.com (ccc31807) Date: Wed, 4 Apr 2012 08:47:35 -0700 (PDT) Subject: Google Tech Talk: lisp at JPL References: Message-ID: <6a4a234d-db48-4659-8714-098d79fb94be@l30g2000yqb.googlegroups.com> On Apr 3, 1:53?am, Xah Lee wrote: > ?The Remote Agent Experiment: Debugging Code from 60 Million Miles > Away? > Google Tech Talk, (2012-02-14) Presented by Ron Garret. @http://www.youtube.com/watch?v=_gZK0tW8EhQ RG mentions giving a more technical version to a Lisp User Group. Any chance that this talk is publicly available? My reaction to this talk, particularly the part near the end, is that NASA isn't alone. RG uses terms like 'rudderless institutions', 'outreach', 'mission', and others, which would be appropriate when talking about religious institutions, i.e., churches. I'm not sure that his prescriptions are addressed to the underlying causes, but they certainly deal with the symptoms. As to the question about Python vs. Lisp, I though RG's reaction (wanting to shed a tear or two) was telling. Languages are tools that users use to accomplish tasks. Apparently, Python has the appearance of being a 'better' tool to accomplish programming tasks (at Google, since that's the context) than Lisp. My take FWIW is to learn many languages and use them appropriately. In connection with my job, I recently did a comparison of several different tasks in C++, ColdFusion, Perl, and Lisp. I use Perl (mostly) and the tasks were those for which Perl is suited. The functions are now written in ColdFusion (they are part of a web app.) I use Lisp in order to highlight the verbosity and ease of different languages, and even though using Lisp is totally impossible (speaking to my employer's environment) I can tell you that the Lisp part of the comparison received the most comment, and the most interesting comments. Thanks for the talk, Ron, I really enjoyed it, and wish you (and NASA) all the best. CC. From nagle at animats.com Wed Apr 4 13:10:44 2012 From: nagle at animats.com (John Nagle) Date: Wed, 04 Apr 2012 10:10:44 -0700 Subject: getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit In-Reply-To: References: Message-ID: On 4/2/2012 6:53 PM, John Nagle wrote: > On 4/1/2012 1:41 PM, John Nagle wrote: >> On 4/1/2012 9:26 AM, Michael Torrie wrote: >>> On 03/31/2012 04:58 PM, John Nagle wrote: > >>> Removed all "search" and "domain" entries from /etc/resolve.conf >> >> It's a design bug in glibc. I just submitted a bug report. >> >> http://sourceware.org/bugzilla/show_bug.cgi?id=13935 The same bug is in "dnspython". Submitted a bug report there, too. https://github.com/rthalley/dnspython/issues/6 John Nagle From chiron613.no.spam. at no.spam.please.gmail.com Wed Apr 4 13:52:19 2012 From: chiron613.no.spam. at no.spam.please.gmail.com (Chiron) Date: Wed, 04 Apr 2012 17:52:19 GMT Subject: Is Programing Art or Science? References: <87hax0suun.fsf@sapphire.mobileactivedefense.com> <4f7bf944$9$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Wed, 04 Apr 2012 03:33:24 -0400, Shmuel (Seymour J.) Metz wrote: > If the term "art" is good enough for Knuth it's good enough for me. I think that may be the most intelligent comment so far... -- Some rise by sin and some by virtue fall. From chris at python.org Wed Apr 4 14:08:20 2012 From: chris at python.org (Chris Withers) Date: Wed, 04 Apr 2012 19:08:20 +0100 Subject: xlrd 0.7.6 released! In-Reply-To: <4F7C0CF7.2040509@gmail.com> References: <4F7AA10B.6020907@simplistix.co.uk> <4F7AA803.1020808@simplistix.co.uk> <4F7BF72B.7080807@simplistix.co.uk> <4F7C0CF7.2040509@gmail.com> Message-ID: <4F7C8E14.8070709@python.org> On 04/04/2012 09:57, Karim wrote: > Hello, > > This release manage the '.xlsx' format? No, that is planned for the 0.8 release. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From nathan.alexander.rice at gmail.com Wed Apr 4 15:31:48 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 4 Apr 2012 15:31:48 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <9c4b8903-ac88-42a5-8f27-fd0c0776ce53@lf20g2000pbb.googlegroups.com> References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <9c4b8903-ac88-42a5-8f27-fd0c0776ce53@lf20g2000pbb.googlegroups.com> Message-ID: > Long personal note ahead. > tl;dr version: Computers are such a large shift for human civilization > that generally we dont get what that shift is about or towards. Another option: since *computers* are such a general device, there isn't just one notion. > In the long run I expect computing science to transcend its parent > disciplines, mathematics and logic, by effectively realizing a > significant part of Leibniz's Dream of providing symbolic calculation > as an alternative to human reasoning. (Please note the difference > between "mimicking" and "providing an alternative to": alternatives > are allowed to be better.) A thinking machine. +1. > Needless to say, this vision of what computing science is about is not > universally applauded. On the contrary, it has met widespread --and > sometimes even violent-- opposition from all sorts of directions. I > mention as examples > > (0) the mathematical guild, which would rather continue to believe > that the Dream of Leibniz is an unrealistic illusion Mathematics is not a closet guild, it is large and contentious. Ideas live and die in mathematics based on their fundamental truth. If there is some bold, sweeping statement it *MIGHT* be possible to prove or disprove, mathematicians will be all over it. just look at Fermat's last theorem and the Poincare conjecture if you want proof of this. > (1) the business community, which, having been sold to the idea that > computers would make life easier, is mentally unprepared to accept > that they only solve the easier problems at the price of creating much > harder one Most business people I know secretly love when they can sell a solution to one problem that creates new problems (and thus opportunities for new products!). The business term for this is an "Upsell" or "Value-add". > (2) the subculture of the compulsive programmer, whose ethics > prescribe that one silly idea and a month of frantic coding should > suffice to make him a life-long millionaire I love hacker culture, but it has been infected by the idea of entrepreneurship as a good in and of itself. Being a creator is a beautiful thing, go forth and make *art*. Improve the human condition. Make the world a better place. STFU about venture capital and stage 2 funding and minimum viable products; that sort of talk is a sure sign that you haven't created anything of actual value. > (3) computer engineering, which would rather continue to act as if it > is all only a matter of higher bit rates and more flops per second These guys are doing something that I find very uninteresting, but is absolutely necessary. Bravo I say. > (4) the military, who are now totally absorbed in the business of > using computers to mutate billion-dollar budgets into the illusion of > automatic safety Nations will always try and be imperialist. At least drones and robot soldiers mean less human suffering. > (5) all soft sciences for which computing now acts as some sort of > interdisciplinary haven Digital humanities (outside of a VERY small set of projects) is a joke. Multimedia history presentations (and what not) are the domain of edutainment companies, not academia. > (6) the educational business that feels that, if it has to teach > formal mathematics to CS students, it may as well close its schools. I feel quite the opposite actually. At the really top notch computer science schools, there is a clear mathematical bent (though it is interdisciplinary). Places like MIT, Stanford, Berkeley, CMU, Cambridge, etc make a STRONG effort to separate the mathematical/theory of computation side and engineering side. At your average state college, the computer science department is just a hodgepodge, and you tend to see more graphics, "applied computation" and embedded/DSP type people. From nobody at nowhere.com Wed Apr 4 15:37:49 2012 From: nobody at nowhere.com (Nobody) Date: Wed, 04 Apr 2012 20:37:49 +0100 Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <4f7be1e8$0$29999$c3e8da3$5496439d@news.astraweb.com> <87fwcj4zru.fsf@dpt-info.u-strasbg.fr> Message-ID: On Wed, 04 Apr 2012 08:14:18 -0400, Roy Smith wrote: >> And sparse files are really hard to reproduce, at least on Unix: on >> Linux even the system's cp doesn't guarantee sparseness of the copy (the >> manual mentions a "crude heuristic"). > > I imagine the heuristic is to look for blocks of all zeros. Yes. Although it's not really accurate to describe it as a "heuristic". With --sparse=always, it will try to make the output sparse regardless of whether the input was sparse, replacing any all-zeros block with a hole. The default of --sparse=auto will only create a sparse file if the input itself is sparse, i.e. if the length of the file rounded up to the nearest block exceeds its disk usage. Regardless of the --sparse= setting and whether the input was sparse, if it tries to create a sparse file it will create holes wherever possible rather than attempting to preserve the exact pattern of holes in a sparse input file. From nathan.alexander.rice at gmail.com Wed Apr 4 15:49:58 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 4 Apr 2012 15:49:58 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <7d825b56-8f60-4899-bb14-e7e61d9e15a6@vn5g2000pbc.googlegroups.com> References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <4f7be80c$0$29999$c3e8da3$5496439d@news.astraweb.com> <7d825b56-8f60-4899-bb14-e7e61d9e15a6@vn5g2000pbc.googlegroups.com> Message-ID: > The "building cabinets" problem is interesting: > > ?1. To actually build a cabinet, there's a lot of domain knowledge > that's probably implicit in most circumstances. ?A carpenter might > tell another carpenter which hinge to use, but they won't have to talk > about why doors need hinges or how to do the assembly. > ?2. It's quite common for humans to use computer programs as part of > the design process. > ?3. Often, the output of a CAD program (at the file level) is some > sort of vector representation that only describes the end product > (basic dimensions, etc.). > > I wonder if there are mini-languages out there that allow you to > describe cabinets in a very descriptive way, where the description > easily translates to the actual steps of building the cabinet, not > just the final dimensions. I think if you were to describe the parts of the cabinet that needed to be assembled separately (and thus could be viewed as separate entities in some sense) and showed the cabinet as the composition of those parts, you would be on the right track. Being a mediocre carpenter, I can't really say anything conclusively here though :) From swellfr at gmail.com Wed Apr 4 16:27:27 2012 From: swellfr at gmail.com (Manu) Date: Wed, 4 Apr 2012 22:27:27 +0200 Subject: Installing a binary package on virtualenv on windows Message-ID: Hi I have been using virtualenv on my windows desktop for quite a while now and would really recommend everyone to use it. Something I come across is how can I install a binary dependency in my virtual environment . I need to install lxml and gevent. Both packages are delivered as windows installer (and not always the latest version !!!) and it seems that pip install will not make the job( as it will go through the build process...) Thanks for your help. M From ian.g.kelly at gmail.com Wed Apr 4 16:40:22 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Apr 2012 14:40:22 -0600 Subject: igraph and usage of Read(klass, f, format=None, *args, **kwds) question In-Reply-To: <21792534.128.1333511154039.JavaMail.geo-discussion-forums@ynpp8> References: <21792534.128.1333511154039.JavaMail.geo-discussion-forums@ynpp8> Message-ID: On Tue, Apr 3, 2012 at 9:45 PM, wrote: > I have a file with with adjacency list of an undirected graph one vertex list per input line [0 1, 1 2 3, 2 1, 3 1] assume a newline for commas (file is named adjl.txt). Can some one give an example of loading this into graph of 4 vertices? > > import igraph > g = igraph.Graph() > g.Read("adjl.txt", "edgelist") > ? does not work.. "does not work" is not very useful in figuring out what the problem is. What actually happens, versus what you were expecting? Was there an error message? Looking at the documentation, it appears that Read is a class method, not an instance method -- it is agnostic to the instance g and only cares that it is a member of Graph. The docs do not specify this, but I would guess that it probably returns a newly created instance of Graph. The correct way to call it then would probably be something like: g = igraph.Graph.Read("adjl.txt", "edgelist") From calderone.jeanpaul at gmail.com Wed Apr 4 17:08:47 2012 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Wed, 4 Apr 2012 14:08:47 -0700 (PDT) Subject: Async IO Server with Blocking DB References: Message-ID: <6e4a8943-b4d1-4a3d-9b62-c1ca5108f12a@d17g2000vba.googlegroups.com> On Apr 3, 6:13?pm, looking for wrote: > Hi > > We are thinking about building a webservice server and considering > python event-driven servers i.e. Gevent/Tornado/ Twisted or some > combination thereof etc. > > We are having doubts about the db io part. Even with connection > pooling and cache, there is a strong chance that server will block on > db. Blocking for even few ms is bad. > > can someone suggest some solutions or is async-io is not at the prime- > time yet. > > Thanks Twisted provides support for any DB-API module via twisted.enteprise.adbapi, which wraps the module in an asynchronous API (implemented using a thread pool). Since the calls all happen in separate threads, it doesn't matter that they block. If you're not talking about a SQL database or a DB-API module, maybe be more specific about the kind of database I/O you have in mind. Jean-Paul From jhjaggars at gmail.com Wed Apr 4 17:09:50 2012 From: jhjaggars at gmail.com (Jesse Jaggars) Date: Wed, 4 Apr 2012 16:09:50 -0500 Subject: Why does this hang sometimes? Message-ID: I am just playing around with threading and subprocess and found that the following program will hang up and never terminate every now and again. import threading import subprocess import time def targ(): ? ?p = subprocess.Popen(["/bin/sleep", "2"]) ? ?while p.poll() is None: ? ? ? ?time.sleep(1) t1 = threading.Thread(target=targ) t2 = threading.Thread(target=targ) t1.start() t2.start() t1.join() t2.join() I found this bug, and while it sounds similar it seems that it was closed during python 2.5 (I'm using 2.7.2): http://bugs.python.org/issue1404925 Thanks! From miki.tebeka at gmail.com Wed Apr 4 18:34:20 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 4 Apr 2012 15:34:20 -0700 (PDT) Subject: Python Gotcha's? Message-ID: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Greetings, I'm going to give a "Python Gotcha's" talk at work. If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. (Note that I want over http://wiki.python.org/moin/PythonWarts already). Thanks, -- Miki From steve+comp.lang.python at pearwood.info Wed Apr 4 19:07:51 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2012 23:07:51 GMT Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 Apr 2012 15:34:20 -0700, Miki Tebeka wrote: > Greetings, > > I'm going to give a "Python Gotcha's" talk at work. If you have an > interesting/common "Gotcha" (warts/dark corners ...) please share. > > (Note that I want over http://wiki.python.org/moin/PythonWarts already). The GIL prevents Python from taking advantage of multiple cores in your CPU when using multiple threads. Solution: use a GIL-less Python, like IronPython or Jython, or use multiple processes instead of threads. exec() and execfile() are unintuitive if you supply separate dicts for the globals and locals arguments. http://bugs.python.org/issue1167300 http://bugs.python.org/issue14049 Note that both of these are flagged as WON'T FIX. Solution: to emulate top-level code, pass the same dict as globals and locals. max() and min() fail with a single argument: max(2, 3) => 3 max(3) => raises exception Solution: don't do that. Or pass a list: max([2, 3]) => 3 max([3]) => 3 Splitting on None and splitting on space is not identical: "".split() => [] "".split(' ') => [''] JSON expects double-quote marks, not single: v = json.loads("{'test':'test'}") fails v = json.loads('{"test":"test"}') succeeds If you decorate a function, by default the docstring is lost. @decorate def spam(x, y): """blah blah blah blah""" spam.__doc__ => raises exception Solution: make sure your decorator uses functools.wraps(). -- Steven From cs at zip.com.au Wed Apr 4 19:18:55 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 5 Apr 2012 09:18:55 +1000 Subject: Python Gotcha's? In-Reply-To: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: <20120404231855.GA24377@cskk.homeip.net> On 04Apr2012 15:34, Miki Tebeka wrote: | I'm going to give a "Python Gotcha's" talk at work. | If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. | | (Note that I want over http://wiki.python.org/moin/PythonWarts already). Missing "return" means "return None". One only has to miss a control path to have this happen. Easy enough to accomodate, if only by having a return or raise at the end of the function, but ... -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ I really don't like :-) symbols as well. I feel that if you can't see the pie coming, you deserve whipped cream up your nose. - robd at cherry.cray.com (rob derrick) From cs at zip.com.au Wed Apr 4 19:21:21 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 5 Apr 2012 09:21:21 +1000 Subject: Python Gotcha's? In-Reply-To: <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120404232121.GA25474@cskk.homeip.net> On 04Apr2012 23:07, Steven D'Aprano wrote: | If you decorate a function, by default the docstring is lost. | | @decorate | def spam(x, y): | """blah blah blah blah""" | | spam.__doc__ => raises exception | | Solution: make sure your decorator uses functools.wraps(). There's a functools.wraps()? [*smacks forehead with palm*] Thanks. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A pessimist is an optimist in full possession of the facts. From cs at zip.com.au Wed Apr 4 19:28:38 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 5 Apr 2012 09:28:38 +1000 Subject: Python Gotcha's? In-Reply-To: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: <20120404232838.GA26579@cskk.homeip.net> No module level properties: >>> @property ... def x(): ... print 1 ... >>> x Actually, that doesn't work with classes either, only instances. Can I refer to the instance of the module/package? In the interpreter, __package__ is None instead of some unnamed "module/package". In general I have a nagging desire that modules were more like classes. But the details remain nebulous in my mind. The property thing is the only concrete thing I trip over at present. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Louis Pasteur's theory of germs is ridiculous fiction. --Pierre Pachet, Professor of Physiology at Toulouse, 1872 From rosuav at gmail.com Wed Apr 4 19:32:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Apr 2012 09:32:44 +1000 Subject: Python Gotcha's? In-Reply-To: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: On Thu, Apr 5, 2012 at 8:34 AM, Miki Tebeka wrote: > Greetings, > > I'm going to give a "Python Gotcha's" talk at work. > If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. > > (Note that I want over http://wiki.python.org/moin/PythonWarts already). Don't know if it's what's meant on that page by the += operator, but the weirdness with concatenating onto a list inside a tuple may merit a mention. >>> a=([1],) >>> a[0].append(2) # This is fine >>> a ([1, 2],) >>> a[0]+=[3] # This is not. Traceback (most recent call last): File "", line 1, in a[0]+=[3] TypeError: 'tuple' object does not support item assignment >>> a ([1, 2, 3],) Throws exception, but still does append to the list. ChrisA From python.list at tim.thechases.com Wed Apr 4 19:42:56 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Apr 2012 18:42:56 -0500 Subject: Python Gotcha's? In-Reply-To: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: <4F7CDC80.60009@tim.thechases.com> On 04/04/12 17:34, Miki Tebeka wrote: > Greetings, > > I'm going to give a "Python Gotcha's" talk at work. > If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. > > (Note that I want over http://wiki.python.org/moin/PythonWarts already). 1) While I believe it was fixed in more recent releases (perhaps Py3 or later, most of my code is still in 2.x), leaking of list-comprehension variables into the surrounding scope has stung me on occasion: val = something_important whatever = [val for val in iterable if condition(val)] assert val == something_important, "ug!" 2) While totally understandable, the significance of leading whitespace in docstrings/triple-quoted items occasionally catches me in places I didn't intentionally want it: class Foo: def frobniculate(self, x, y): """Frobniculate the x & y x is the macrowobble variance y is the miniwibble grobulation """ pass (there's now leading whitespace on lines 2 & 3, and an extra trailing line of pure whitespace). 3) the peculiarities of old-style classes and new-style classes in 2.x (mooted by 3.x) take careful reading of the docs if you're overriding __getattr__ or __getattribute__, as well as possible other old-vs-new gotchas. 4) the __del__ method may have things in the containing scopes (such as modules imported at the top of the containing module) that get garbage-collected before the __del__ is called. In general, __del__ stinks, and is better replaced by "with" statements using context managers. 5) the masking of system modules. On multiple occasions I've created a local module named "email.py", and then upon importing something else (I think it may have been smtplib...not sure), it failed with a confusing error because the imported module found mine rather than the system module. Those are my off-the-top-of-the-head gotchas. -tkc From rosuav at gmail.com Wed Apr 4 21:30:45 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Apr 2012 11:30:45 +1000 Subject: No os.copy()? Why not? In-Reply-To: References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <4f7be1e8$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 5, 2012 at 1:15 AM, Steve Howell wrote: > On Apr 4, 1:37?am, Chris Angelico wrote: >> And, as a subtle point: This method can't create the file "at size". I >> don't know how it'll end up allocating space, but certainly there's no >> opportunity to announce to the OS at file open/create time "please >> allocate X bytes for this file". That may be an utterly trivial point, >> or a crucially vital one. >> >> ChrisA > > FWIW shutil.py doesn't do anything particularly fancy with respect to > creating files "at size", unless I'm missing something: So it doesn't. However, that's current implementation, and it's entirely possible that a future version might add that feature - it wouldn't break any existing code, and would improve file system performance. Doing it yourself means you miss out on any such enhancements. ChrisA From wuwei23 at gmail.com Thu Apr 5 00:23:25 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 4 Apr 2012 21:23:25 -0700 (PDT) Subject: Igraph and usage of Read(kclass, f, format=...) question References: <13601107.162.1333548040812.JavaMail.geo-discussion-forums@yncc18> Message-ID: <62358211-6866-452a-b4da-8aaa27498620@8g2000pbm.googlegroups.com> On Apr 5, 12:00?am, ish wrote: > Any pointer will be appreciated. 1. Show your input. Odds are there's a problem with your data. 2. Show the output. "Does not work" tells us nothing of value. 3. Don't repeatedly post the same question in different threads. That doesn't make people answer any faster. 4. Try the appropriate support mailing list: https://lists.nongnu.org/mailman/listinfo/igraph-help From steve+comp.lang.python at pearwood.info Thu Apr 5 00:49:57 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2012 04:49:57 GMT Subject: Cannot connect to IMAP server in Python 3.2 Message-ID: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> I can connect to an IMAP server using Python 2.6: steve at runes:~$ python2.6 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. >>> import imaplib >>> server = imaplib.IMAP4_SSL('xxxxx') >>> print server But when I try with Python 3.2, it just sits there until it times out: steve at runes:~$ python3.2 Python 3.2.2 (default, Feb 29 2012, 18:11:33) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import imaplib >>> server = imaplib.IMAP4('xxxxx', imaplib.IMAP4_SSL_PORT) Traceback (most recent call last): [...] socket.timeout: timed out What am I doing wrong? -- Steven From showell30 at yahoo.com Thu Apr 5 01:13:55 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 4 Apr 2012 22:13:55 -0700 (PDT) Subject: Cannot connect to IMAP server in Python 3.2 References: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> Message-ID: <3ceec070-e710-4e0e-9cb6-60895397c991@pg2g2000pbb.googlegroups.com> On Apr 4, 9:49?pm, Steven D'Aprano wrote: > I can connect to an IMAP server using Python 2.6: > > steve at runes:~$ python2.6 > 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.>>> import imaplib > >>> server = imaplib.IMAP4_SSL('xxxxx') > >>> print server > > > > But when I try with Python 3.2, it just sits there until it times out: > > steve at runes:~$ python3.2 > Python 3.2.2 (default, Feb 29 2012, 18:11:33) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> import imaplib > >>> server = imaplib.IMAP4('xxxxx', imaplib.IMAP4_SSL_PORT) > > Traceback (most recent call last): > [...] > socket.timeout: timed out > > What am I doing wrong? > Is it simply the wrong port? (IMAP4_SSL_PORT vs. IMAP4_PORT) How long do you wait before seeing the timeout? Have you tried print-debugging within your local copy of imaplib.py? The code related to making the connection just wraps socket.create_connection: 234 235 def _create_socket(self): 236 return socket.create_connection((self.host, self.port)) 237 238 def open(self, host = '', port = IMAP4_PORT): 239 """Setup connection to remote server on "host:port" 240 (default: localhost:standard IMAP4 port). 241 This connection will be used by the routines: 242 read, readline, send, shutdown. 243 """ 244 self.host = host 245 self.port = port 246 self.sock = self._create_socket() 247 self.file = self.sock.makefile('rb') http://hg.python.org/cpython/file/3.2/Lib/imaplib.py From rtw at rtw.me.uk Thu Apr 5 01:25:28 2012 From: rtw at rtw.me.uk (Rob Williscroft) Date: Thu, 5 Apr 2012 05:25:28 +0000 (UTC) Subject: Cannot connect to IMAP server in Python 3.2 References: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote in news:4f7d2475$0$11113$c3e8da3 at news.astraweb.com in gmane.comp.python.general: > I can connect to an IMAP server using Python 2.6: > > steve at runes:~$ python2.6 > Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) >>>> server = imaplib.IMAP4_SSL('xxxxx') > But when I try with Python 3.2, it just sits there until it times out: >>>> server = imaplib.IMAP4('xxxxx', imaplib.IMAP4_SSL_PORT) > What am I doing wrong? > Not using IMAP4_SSL, above you are using IMAP4 (non SSL) but with the SSL port. http://docs.python.org/py3k//library/imaplib.html#imaplib.IMAP4_SSL From chris at python.org Thu Apr 5 02:26:15 2012 From: chris at python.org (Chris Withers) Date: Thu, 05 Apr 2012 07:26:15 +0100 Subject: xlrd 0.7.6 released! In-Reply-To: <4F7CA06A.2060508@gmail.com> References: <4F7AA10B.6020907@simplistix.co.uk> <4F7AA803.1020808@simplistix.co.uk> <4F7BF72B.7080807@simplistix.co.uk> <4F7C0CF7.2040509@gmail.com> <4F7C8E14.8070709@python.org> <4F7CA06A.2060508@gmail.com> Message-ID: <4F7D3B07.9000706@python.org> On 04/04/2012 20:26, Karim wrote: > By the way, I reported an issue to you in this mailing list some time > ago about unicode data. I have no recollection of this. If you experience any bugs, the correct place to report them is: https://github.com/python-excel/xlrd/issues cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From steve+comp.lang.python at pearwood.info Thu Apr 5 03:09:50 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2012 07:09:50 GMT Subject: Cannot connect to IMAP server in Python 3.2 References: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> <3ceec070-e710-4e0e-9cb6-60895397c991@pg2g2000pbb.googlegroups.com> Message-ID: <4f7d453e$0$11113$c3e8da3@news.astraweb.com> On Wed, 04 Apr 2012 22:13:55 -0700, Steve Howell wrote: > On Apr 4, 9:49?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> I can connect to an IMAP server using Python 2.6: >> >> steve at runes:~$ python2.6 >> 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.>>> import imaplib >> >>> server = imaplib.IMAP4_SSL('xxxxx') >> >>> print server >> >> >> >> But when I try with Python 3.2, it just sits there until it times out: >> >> steve at runes:~$ python3.2 >> Python 3.2.2 (default, Feb 29 2012, 18:11:33) [GCC 4.4.5] on linux2 >> Type "help", "copyright", "credits" or "license" for more >> information.>>> import imaplib >> >>> server = imaplib.IMAP4('xxxxx', imaplib.IMAP4_SSL_PORT) >> >> Traceback (most recent call last): >> [...] >> socket.timeout: timed out >> >> What am I doing wrong? >> >> > Is it simply the wrong port? (IMAP4_SSL_PORT vs. IMAP4_PORT) No, it is the correct port, 993. > How long do you wait before seeing the timeout? Indefinitely. > Have you tried print-debugging within your local copy of imaplib.py? The > code related to making the connection just wraps > socket.create_connection: I'm not going to start debugging the standard library until after I'm satisfied that I'm not doing something wrong. -- Steven From showell30 at yahoo.com Thu Apr 5 03:21:31 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 00:21:31 -0700 (PDT) Subject: Cannot connect to IMAP server in Python 3.2 References: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> <3ceec070-e710-4e0e-9cb6-60895397c991@pg2g2000pbb.googlegroups.com> <4f7d453e$0$11113$c3e8da3@news.astraweb.com> Message-ID: On Apr 5, 12:09?am, Steven D'Aprano wrote: > On Wed, 04 Apr 2012 22:13:55 -0700, Steve Howell wrote: > > On Apr 4, 9:49?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > >> I can connect to an IMAP server using Python 2.6: > > >> steve at runes:~$ python2.6 > >> 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.>>> import imaplib > >> >>> server = imaplib.IMAP4_SSL('xxxxx') > >> >>> print server > > >> > > >> But when I try with Python 3.2, it just sits there until it times out: > > >> steve at runes:~$ python3.2 > >> Python 3.2.2 (default, Feb 29 2012, 18:11:33) [GCC 4.4.5] on linux2 > >> Type "help", "copyright", "credits" or "license" for more > >> information.>>> import imaplib > >> >>> server = imaplib.IMAP4('xxxxx', imaplib.IMAP4_SSL_PORT) > > >> Traceback (most recent call last): > >> [...] > >> socket.timeout: timed out > > >> What am I doing wrong? > > > Is it simply the wrong port? ?(IMAP4_SSL_PORT vs. IMAP4_PORT) > > No, it is the correct port, 993. > > > How long do you wait before seeing the timeout? > > Indefinitely. > > > Have you tried print-debugging within your local copy of imaplib.py? The > > code related to making the connection just wraps > > socket.create_connection: > > I'm not going to start debugging the standard library until after I'm > satisfied that I'm not doing something wrong. > I'm not suggesting that you debug the standard library because I think the library itself is broken. I'm suggesting that using the source code that's freely available to you can help you have some insight on what's going wrong. Do you have a working theory on what you're doing wrong? You've already ruled out the port. Why are you changing the invocation between versions of Python? imaplib.IMAP4_SSL('xxxxx') # 2.6 imaplib.IMAP4('xxxxx', imaplib.IMAP4_SSL_PORT) # 3.2 I'm sure the standard library works fine, and you're just doing something silly, like mistyping the host name or forgetting to start the server. Maybe you're running 3.2 in a slightly different OS environment? The ONE thing that you can find out almost immediately is what self.host and self.post are set to when _create_socket gets called. You could almost immediately narrow down the problem to socket.create_connection() instead of IMAP. From zxnotdead at gmail.com Thu Apr 5 03:29:56 2012 From: zxnotdead at gmail.com (=?UTF-8?B?0JrQvtC90YHRgtCw0L3RgtC40L0g0JrRg9C70LjQutC+0LI=?=) Date: Thu, 5 Apr 2012 11:29:56 +0400 Subject: regexp partial matching, or hitEnd Message-ID: I want something like this in python : http://stackoverflow.com/questions/2526756/can-java-util-regex-pattern-do-partia... First you have to call one of the standard methods to apply the regex, like matches() or find(). If that returns false, you can use the hitEnd() method to find out if some longer string could have matched: String[] inputs = { "AA", "BB" }; Pattern p = Pattern.compile("AAAAAB"); Matcher m = p.matcher(""); for (String s : inputs) { m.reset(s); System.out.printf("%s -- full match: %B; partial match: %B%n", s, m.matches(), m.hitEnd()); } output: AA -- full match: FALSE; partial match: TRUE BB -- full match: FALSE; partial match: FALSE So. Is there already some function like hitEnd() in any python regexp library? Or if not, maybe it's could be added in the feature to the standart re module? :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Thu Apr 5 03:33:10 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 00:33:10 -0700 (PDT) Subject: Cannot connect to IMAP server in Python 3.2 References: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> <3ceec070-e710-4e0e-9cb6-60895397c991@pg2g2000pbb.googlegroups.com> <4f7d453e$0$11113$c3e8da3@news.astraweb.com> Message-ID: On Apr 5, 12:09?am, Steven D'Aprano wrote: > On Wed, 04 Apr 2012 22:13:55 -0700, Steve Howell wrote: > > On Apr 4, 9:49?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > >> I can connect to an IMAP server using Python 2.6: > > >> steve at runes:~$ python2.6 > >> 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.>>> import imaplib > >> >>> server = imaplib.IMAP4_SSL('xxxxx') > >> >>> print server > > >> > > >> But when I try with Python 3.2, it just sits there until it times out: > > >> steve at runes:~$ python3.2 > >> Python 3.2.2 (default, Feb 29 2012, 18:11:33) [GCC 4.4.5] on linux2 > >> Type "help", "copyright", "credits" or "license" for more > >> information.>>> import imaplib > >> >>> server = imaplib.IMAP4('xxxxx', imaplib.IMAP4_SSL_PORT) > > >> Traceback (most recent call last): > >> [...] > >> socket.timeout: timed out > > >> What am I doing wrong? > > > Is it simply the wrong port? ?(IMAP4_SSL_PORT vs. IMAP4_PORT) > > No, it is the correct port, 993. > > > How long do you wait before seeing the timeout? > > Indefinitely. > > > Have you tried print-debugging within your local copy of imaplib.py? The > > code related to making the connection just wraps > > socket.create_connection: > > I'm not going to start debugging the standard library until after I'm > satisfied that I'm not doing something wrong. > > -- > Steven What happens when you do this? >>> import imaplib, socket >>> socket.create_connection(('xxxxx', imaplib.IMAP4_SSL_PORT)) From duncan.booth at invalid.invalid Thu Apr 5 07:06:11 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Apr 2012 11:06:11 GMT Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > JSON expects double-quote marks, not single: > v = json.loads("{'test':'test'}") fails > v = json.loads('{"test":"test"}') succeeds > You mean JSON expects a string with valid JSON? Quelle surprise. -- Duncan Booth http://kupuguy.blogspot.com From rosuav at gmail.com Thu Apr 5 07:37:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Apr 2012 21:37:04 +1000 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 5, 2012 at 9:06 PM, Duncan Booth wrote: > Steven D'Aprano wrote: > >> JSON expects double-quote marks, not single: >> ? ? v = json.loads("{'test':'test'}") ?fails >> ? ? v = json.loads('{"test":"test"}') ?succeeds >> > > You mean JSON expects a string with valid JSON? > Quelle surprise. The surprise is between JSON and JavaScript (the latter does accept single quotes), and Python is correctly implementing the JSON spec. ChrisA From steve+comp.lang.python at pearwood.info Thu Apr 5 08:00:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2012 12:00:47 GMT Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Apr 2012 11:06:11 +0000, Duncan Booth wrote: > Steven D'Aprano wrote: > >> JSON expects double-quote marks, not single: >> v = json.loads("{'test':'test'}") fails v = >> json.loads('{"test":"test"}') succeeds >> >> > You mean JSON expects a string with valid JSON? Quelle surprise. No. The surprise is that there exists a tool invented in the 21st century that makes a distinction between strings quoted with " and those quoted with '. Being used to a sensible language like Python, it boggled my brain the first time I tried to write some JSON and naturally treated the choice of quote mark as arbitrary. It especially boggled my brain when I saw the pathetically useless error message generated: py> json.loads("{'test':'test'}") Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.2/json/__init__.py", line 307, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.2/json/decoder.py", line 351, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/lib/python3.2/json/decoder.py", line 367, in raw_decode obj, end = self.scan_once(s, idx) ValueError: Expecting property name: line 1 column 1 (char 1) "Expecting property name"??? WTF??? The reason this is a Gotcha rather than a bug is because the JSON standard specifies the behaviour (probably in order to be compatible with Javascript). Hence, although the behaviour is mind-numbingly stupid, it is deliberate and not a bug. Hence, a gotcha. -- Steven From steve+comp.lang.python at pearwood.info Thu Apr 5 08:16:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2012 12:16:09 GMT Subject: Cannot connect to IMAP server in Python 3.2 References: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> <3ceec070-e710-4e0e-9cb6-60895397c991@pg2g2000pbb.googlegroups.com> <4f7d453e$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4f7d8d09$0$29983$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Apr 2012 00:21:31 -0700, Steve Howell wrote: > I'm not suggesting that you debug the standard library because I think > the library itself is broken. I'm suggesting that using the source code > that's freely available to you can help you have some insight on what's > going wrong. > > Do you have a working theory on what you're doing wrong? Actually, between you and me and the thousands of others reading this thread, I actually do suspect it is a bug in the std library implementation. But the suspicion is only that, and my first *assumption* is that it is more likely I am doing something wrong. Hence my question. > You've already > ruled out the port. Why are you changing the invocation between > versions of Python? Because imaplib.IMAP4_SSL apparently no longer exists in Python 3. >>> server = imaplib.IMAP4_SSL('xxxxx') Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'IMAP4_SSL' > imaplib.IMAP4_SSL('xxxxx') # 2.6 > imaplib.IMAP4('xxxxx', imaplib.IMAP4_SSL_PORT) # 3.2 > > I'm sure the standard library works fine, and you're just doing > something silly, like mistyping the host name or forgetting to start the > server. Maybe you're running 3.2 in a slightly different OS > environment? If you look carefully at my copy-and-pasted sessions, you will see that both of them are on the same host, "runes". While I suppose that technically I could have two hosts both called runes, in fact I only have one :) And no, I have not mistyped the host name. -- Steven From breamoreboy at yahoo.co.uk Thu Apr 5 08:19:48 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 05 Apr 2012 13:19:48 +0100 Subject: regexp partial matching, or hitEnd In-Reply-To: References: Message-ID: On 05/04/2012 08:29, ?????????? ??????? wrote: > I want something like this in python : > > http://stackoverflow.com/questions/2526756/can-java-util-regex-pattern-do-partia... > > First you have to call one of the standard methods to apply the regex, > like matches() or find(). > If that returns false, you can use the hitEnd() method to find out if some > longer string could have matched: Dark satanic writing snipped :) > So. Is there already some function like hitEnd() in any python regexp > library? > Or if not, maybe it's could be added in the feature to the standart re > module? :) > More likely to go into the new regex module that's on pypi. Talking of which is this going into Python 3.3, I see it's mentioned in PEP398 but can't find any mention in the Python 3.3 What's New docs, or have I simply missed something? -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Thu Apr 5 08:25:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2012 12:25:19 GMT Subject: Cannot connect to IMAP server in Python 3.2 References: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> <3ceec070-e710-4e0e-9cb6-60895397c991@pg2g2000pbb.googlegroups.com> <4f7d453e$0$11113$c3e8da3@news.astraweb.com> <4f7d8d09$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f7d8f2f$0$29983$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Apr 2012 12:16:09 +0000, Steven D'Aprano wrote: > On Thu, 05 Apr 2012 00:21:31 -0700, Steve Howell wrote: >> Why are you changing the invocation between versions of Python? > > Because imaplib.IMAP4_SSL apparently no longer exists in Python 3. > >>>> server = imaplib.IMAP4_SSL('xxxxx') > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'IMAP4_SSL' Wait a minute... IMAP4_SSL is documented as existing in Python 3. And when I run Python 3.2 on a Centos machine, instead of Debian, it includes IMAP4_SSL which works fine. [steve at ando ~]$ python3.2 Python 3.2.2 (default, Mar 4 2012, 10:50:33) [GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2 Type "help", "copyright", "credits" or "license" for more information. py> import imaplib py> server = imaplib.IMAP4_SSL('xxxxx') py> server So there's something screwy going on here. Why does my Python 3.2 on Debian not include IMAP4_SSL, but Python 2.6 does? -- Steven From roy at panix.com Thu Apr 5 08:32:10 2012 From: roy at panix.com (Roy Smith) Date: Thu, 05 Apr 2012 08:32:10 -0400 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4f7d896f$0$29983$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > > You mean JSON expects a string with valid JSON? Quelle surprise. > > No. The surprise is that there exists a tool invented in the 21st century > that makes a distinction between strings quoted with " and those quoted > with '. Being used to a sensible language like Python, it boggled my > brain the first time I tried to write some JSON and naturally treated the > choice of quote mark as arbitrary. Your brain has a low boggle threshold. There's absolutely no reason why JSON should follow Python syntax rules. Making it support either kind of quotes would have complicated every JSON library in the world, for no added value. Nobody should ever be hand-writing JSON (just like nobody should ever be hand-writing XML). Just use the supplied library calls and you'll never have to worry about low-level minutia like this again. > It especially boggled my brain when I > saw the pathetically useless error message generated: > > py> json.loads("{'test':'test'}") > [...] > ValueError: Expecting property name: line 1 column 1 (char 1) > > "Expecting property name"??? WTF??? One of the hardest things about writing parsers is generating helpful error messages when things don't parse. But, it's only of value to do that when you're parsing something you expect to be written by a human, and thus a human has to puzzle out what they did wrong. Nobody expects that a JSON parser will be parsing human-written input, so there's little value to saying anything more than "parse error". > The reason this is a Gotcha rather than a bug is because the JSON > standard specifies the behaviour (probably in order to be compatible with > Javascript). Well, considering that the JS in JSON stands for JavaScript... > Hence, although the behaviour is mind-numbingly stupid, it > is deliberate and not a bug. Hence, a gotcha. But surely not a Python gotcha. If anything, it's a JSON gotcha. The same is true with PHP's JSON library, and Ruby's, and Perl's, and Scala's, and C++'s, and so on. It's a JSON issue, and a silly one to be complaining about at that. From tim.wintle at teamrubber.com Thu Apr 5 08:41:05 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 05 Apr 2012 13:41:05 +0100 Subject: Python Gotcha's? In-Reply-To: <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1333629665.22494.23.camel@tim-laptop> On Thu, 2012-04-05 at 12:00 +0000, Steven D'Aprano wrote: > The reason this is a Gotcha rather than a bug is because the JSON > standard specifies the behaviour (probably in order to be compatible with > Javascript). It's not to be compatible with javascript (you can use either in javascript) I believe the choice is to make the parser as simple as possible. Agreed it's a gotcha, but json is almost always generated automatically. Tim From damien.wyart at free.fr Thu Apr 5 08:58:16 2012 From: damien.wyart at free.fr (Damien Wyart) Date: Thu, 05 Apr 2012 14:58:16 +0200 Subject: Cannot connect to IMAP server in Python 3.2 References: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> <3ceec070-e710-4e0e-9cb6-60895397c991@pg2g2000pbb.googlegroups.com> <4f7d453e$0$11113$c3e8da3@news.astraweb.com> <4f7d8d09$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7d8f2f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f7d96e8$0$691$426a34cc@news.free.fr> * Steven D'Aprano in comp.lang.python: > IMAP4_SSL is documented as existing in Python 3. And when I run Python > 3.2 on a Centos machine, instead of Debian, it includes IMAP4_SSL which > works fine. > So there's something screwy going on here. Why does my Python 3.2 on > Debian not include IMAP4_SSL, but Python 2.6 does? Could you try "import ssl" on your Debian machine and see if some errors are reported? Some ssl libs used by ssl.py might not be installed. -- DW From showell30 at yahoo.com Thu Apr 5 09:45:50 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 06:45:50 -0700 (PDT) Subject: Cannot connect to IMAP server in Python 3.2 References: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> <3ceec070-e710-4e0e-9cb6-60895397c991@pg2g2000pbb.googlegroups.com> <4f7d453e$0$11113$c3e8da3@news.astraweb.com> <4f7d8d09$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7d8f2f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 5, 5:25?am, Steven D'Aprano wrote: > On Thu, 05 Apr 2012 12:16:09 +0000, Steven D'Aprano wrote: > > On Thu, 05 Apr 2012 00:21:31 -0700, Steve Howell wrote: > >> Why are you changing the invocation between versions of Python? > > > Because imaplib.IMAP4_SSL apparently no longer exists in Python 3. > > >>>> server = imaplib.IMAP4_SSL('xxxxx') > > Traceback (most recent call last): > > ? File "", line 1, in > > AttributeError: 'module' object has no attribute 'IMAP4_SSL' > > Wait a minute... > > IMAP4_SSL is documented as existing in Python 3. And when I run Python > 3.2 on a Centos machine, instead of Debian, it includes IMAP4_SSL which > works fine. > > [steve at ando ~]$ python3.2 > Python 3.2.2 (default, Mar ?4 2012, 10:50:33) > [GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > py> import imaplib > py> server = imaplib.IMAP4_SSL('xxxxx') > py> server > > > So there's something screwy going on here. Why does my Python 3.2 on > Debian not include IMAP4_SSL, but Python 2.6 does? > Looking at the source can give you some insight: http://hg.python.org/cpython/file/3.2/Lib/imaplib.py Look for where IMAP4_SSL is defined. On your 3.2/Debian setup, the HAVE_SSL flag (see two lines above the "class" statement) is apparently false: 1174 if HAVE_SSL: 1175 1176 class IMAP4_SSL(IMAP4): If you look for the first mention of HAVE_SSL, it becomes apparent that you have some issue with importing the ssl module, which unfortunately gets buried fairly silently by imaplib: 27 try: 28 import ssl 29 HAVE_SSL = True 30 except ImportError: 31 HAVE_SSL = False Damien, in his response, asks you to try "import ssl" on your Debian machine. I think he's on the right track in identifying the problem, based on the simple code above. Once you are able to import ssl, you should be able to use IMAP4_SSL, but that still doesn't entirely explain to me why you got a timeout error with plain IMAP4 and the proper port. (I would have expected a failure, but of a different kind.) I'd still be curious to see what happens when you try this: import socket, imaplib your_host_name = # ... socket.create_connection((your_host_name, imaplib.IMAP4_SSL_PORT)) From kevin.misc.10 at gmail.com Thu Apr 5 09:49:33 2012 From: kevin.misc.10 at gmail.com (Kevin Zhang) Date: Thu, 5 Apr 2012 21:49:33 +0800 Subject: python polygon Message-ID: Hi, I found python polygon link in this page http://pypi.python.org/pypi/Polygon/1.17 was invalid now. http://polygon.origo.ethz.ch/download 404 - Project not found Ooops, the subdomain is not valid because the according project does not (yet) exist. Go to the Origo main page at http://origo.ethz.ch Can anyone provide some updates on this? Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Thu Apr 5 10:13:22 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 07:13:22 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 5, 5:00?am, Steven D'Aprano wrote: > On Thu, 05 Apr 2012 11:06:11 +0000, Duncan Booth wrote: > > Steven D'Aprano wrote: > > >> JSON expects double-quote marks, not single: > >> ? ? v = json.loads("{'test':'test'}") ?fails v = > >> ? ? json.loads('{"test":"test"}') ?succeeds > > > You mean JSON expects a string with valid JSON? Quelle surprise. > > No. The surprise is that there exists a tool invented in the 21st century > that makes a distinction between strings quoted with " and ?those quoted > with '. Being used to a sensible language like Python, it boggled my > brain the first time I tried to write some JSON and naturally treated the > choice of quote mark as arbitrary. I've been bitten by this gotcha too. Maybe "boggled my brain" would be a bit of hyperbole, but it did cause me minor pain, and brief but frustrating pain is the whole point of "gotcha" presentations. > It especially boggled my brain when I > saw the pathetically useless error message generated: > > [...] > ValueError: Expecting property name: line 1 column 1 (char 1) > > "Expecting property name"??? WTF??? I agree with you that the error message is pretty puzzling. I can understand the rationale of the parser authors not to go overboard with diagnosing these errors correctly to users, since it would complicate the parser code and possibly slow it down even for well formed JSON. On the other hand, I think that parsers can distinguish themselves by anticipating the most common gotchas and giving clear messages. > The reason this is a Gotcha rather than a bug is because the JSON > standard specifies the behaviour (probably in order to be compatible with > Javascript). Hence, although the behaviour is mind-numbingly stupid, it > is deliberate and not a bug. Hence, a gotcha. > Yep. From jjposner at optimum.net Thu Apr 5 10:15:03 2012 From: jjposner at optimum.net (John Posner) Date: Thu, 05 Apr 2012 10:15:03 -0400 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: <4F7DA8E7.1060507@optimum.net> On 4/4/2012 7:32 PM, Chris Angelico wrote: > Don't know if it's what's meant on that page by the += operator, Yes, it is. >> a=([1],) >> a[0].append(2) # This is fine [In the following, I use the term "name" rather loosely.] The append() method attempts to modify the object whose name is "a[0]". That object is a LIST, so the attempt succeeds. >> a[0]+=[3] # This is not. The assignment attempts to modify the object whose name is "a". That object is a TUPLE, so the attempt fails. This might be a surprise, but I'm not sure it deserves to be called a wart. Note the similarity to: temp = a[0] + [3] # succeeds a[0] = temp # fails -John From showell30 at yahoo.com Thu Apr 5 10:32:19 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 07:32:19 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3ac8a194-8d08-4ef8-8892-1186a5752e87@9g2000pbn.googlegroups.com> On Apr 5, 5:32?am, Roy Smith wrote: > [...]?Nobody expects > that a JSON parser will be parsing human-written input, [...] Humans write JSON all the time. People use JSON as a configuration language, and some people actually write JSON files by hand. A common example would be writing package.json for an npm package. Here are a couple examples: https://github.com/jashkenas/coffee-script/blob/master/package.json https://github.com/github/hubot/blob/master/package.json > so there's little value to saying anything more than "parse error". So, there's little value to say anything more than "parse error"...except to help all those dumb humans that expect JSON to be human-writable. ;) From robert.kern at gmail.com Thu Apr 5 10:45:57 2012 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 05 Apr 2012 15:45:57 +0100 Subject: Python Gotcha's? In-Reply-To: <4F7DA8E7.1060507@optimum.net> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4F7DA8E7.1060507@optimum.net> Message-ID: On 4/5/12 3:15 PM, John Posner wrote: > On 4/4/2012 7:32 PM, Chris Angelico wrote: >> Don't know if it's what's meant on that page by the += operator, > > Yes, it is. > >>> a=([1],) >>> a[0].append(2) # This is fine > > [In the following, I use the term "name" rather loosely.] > > The append() method attempts to modify the object whose name is "a[0]". > That object is a LIST, so the attempt succeeds. > >>> a[0]+=[3] # This is not. > > The assignment attempts to modify the object whose name is "a". That > object is a TUPLE, so the attempt fails. This might be a surprise, but > I'm not sure it deserves to be called a wart. The wart is not that it fails, but that it does not fail atomically. The list inside the tuple gets modified even though an exception is raised for the statement as a whole. -- 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 zdoor at xs4all.nl Thu Apr 5 10:50:20 2012 From: zdoor at xs4all.nl (Alex van der Spek) Date: Thu, 5 Apr 2012 16:50:20 +0200 Subject: Difference between tempfile and spooled tempfile? Message-ID: <4f7db133$0$6953$e4fe514c@news2.news.xs4all.nl> I do not understand why the spooled write gives an error. See below. The normal tempfile works just fine. They are supposed to behave equal? All insight you can provide is welcome. Alex van der Spek +++++++++++++++++++++++++++++++++++++++++++++++++ Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import array >>> import tempfile >>> stf = tempfile.SpooledTemporaryFile(max_size=1024) >>> ptf = tempfile.TemporaryFile() >>> fff = [float(x) for x in range(2048)] >>> ffa = array.array('f',fff) >>> ptf.write(ffa) >>> stf.write(ffa) Traceback (most recent call last): File "", line 1, in stf.write(ffa) File "C:\Python27\lib\tempfile.py", line 595, in write rv = file.write(s) TypeError: must be string or read-only character buffer, not array.array >>> From showell30 at yahoo.com Thu Apr 5 11:10:23 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 08:10:23 -0700 (PDT) Subject: Difference between tempfile and spooled tempfile? References: <4f7db133$0$6953$e4fe514c@news2.news.xs4all.nl> Message-ID: On Apr 5, 7:50?am, "Alex van der Spek" wrote: > I do not understand why the spooled write gives an error. See below. > The normal tempfile works just fine. They are supposed to behave equal? > > All insight you can provide is welcome. > Alex van der Spek > > +++++++++++++++++++++++++++++++++++++++++++++++++ > > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] > on win32 > Type "copyright", "credits" or "license()" for more information. > > >>> import array > >>> import tempfile > >>> stf = tempfile.SpooledTemporaryFile(max_size=1024) > >>> ptf = tempfile.TemporaryFile() > >>> fff = [float(x) for x in range(2048)] > >>> ffa = array.array('f',fff) > >>> ptf.write(ffa) > >>> stf.write(ffa) > > Traceback (most recent call last): > ? File "", line 1, in > ? ? stf.write(ffa) > ? File "C:\Python27\lib\tempfile.py", line 595, in write > ? ? rv = file.write(s) > TypeError: must be string or read-only character buffer, not array.array > I think the docs are slightly misleading. While SpooledTemporaryFile allows you to write(), it's more finicky about serializing arrays, hence the error message. If you look under the hood, you'll see that it's mostly a limitation of StringIO. http://hg.python.org/cpython/file/2.7/Lib/tempfile.py 494 """Temporary file wrapper, specialized to switch from 495 StringIO to a real file when it exceeds a certain size or 496 when a fileno is needed. 497 """ 498 _rolled = False 499 500 def __init__(self, max_size=0, mode='w+b', bufsize=-1, 501 suffix="", prefix=template, dir=None): 502 self._file = _StringIO() 503 self._max_size = max_size 504 self._rolled = False 505 self._TemporaryFileArgs = (mode, bufsize, suffix, prefix, dir) (See line 502.) 600 def write(self, s): 601 file = self._file 602 rv = file.write(s) 603 self._check(file) 604 return rv (See line 602.) I'm looking at a slightly different version of the module than you, but hopefully you get the idea. From iainking at gmail.com Thu Apr 5 11:23:44 2012 From: iainking at gmail.com (Iain King) Date: Thu, 5 Apr 2012 08:23:44 -0700 (PDT) Subject: Python Gotcha's? In-Reply-To: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: <10192241.49.1333639424438.JavaMail.geo-discussion-forums@vbth19> A common one used to be expecting .sort() to return, rather than mutate (as it does). Same with .reverse() - sorted and reversed have this covered, not sure how common a gotcha it is any more. Iain On Wednesday, 4 April 2012 23:34:20 UTC+1, Miki Tebeka wrote: > Greetings, > > I'm going to give a "Python Gotcha's" talk at work. > If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. > > (Note that I want over http://wiki.python.org/moin/PythonWarts already). > > Thanks, > -- > Miki From showell30 at yahoo.com Thu Apr 5 11:35:37 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 08:35:37 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <10192241.49.1333639424438.JavaMail.geo-discussion-forums@vbth19> Message-ID: <31d2862b-38c6-40f9-851f-3a8edd56b863@r2g2000pbs.googlegroups.com> On Apr 5, 8:23?am, Iain King wrote: > A common one used to be expecting .sort() to return, rather than mutate (as it does). ?Same with .reverse() - sorted and reversed have this covered, not sure how common a gotcha it is any more. > The sort()/sorted() variations are good to cover. To give another example, folks who had been immersed in legacy versions of Python for a long time might still be in the habit of hand-writing compare functions. With newer versions of Python, it usually makes sense to just use the "key" feature. From rNOSPAMon at flownet.com Thu Apr 5 11:49:28 2012 From: rNOSPAMon at flownet.com (RG) Date: Thu, 05 Apr 2012 08:49:28 -0700 Subject: Google Tech Talk: lisp at JPL References: <6a4a234d-db48-4659-8714-098d79fb94be@l30g2000yqb.googlegroups.com> Message-ID: In article <6a4a234d-db48-4659-8714-098d79fb94be at l30g2000yqb.googlegroups.com>, ccc31807 wrote: > On Apr 3, 1:53?am, Xah Lee wrote: > > ?The Remote Agent Experiment: Debugging Code from 60 Million Miles > > Away? > > Google Tech Talk, (2012-02-14) Presented by Ron Garret. > > @http://www.youtube.com/watch?v=_gZK0tW8EhQ > > RG mentions giving a more technical version to a Lisp User Group. Any > chance that this talk is publicly available? Nope. It wasn't recorded. Sorry. > Thanks for the talk, Ron, I really enjoyed it, and wish you (and NASA) > all the best. I haven't worked at NASA for nearly ten years now, but thanks for the kinds words nonetheless. rg From breamoreboy at yahoo.co.uk Thu Apr 5 12:01:07 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 05 Apr 2012 17:01:07 +0100 Subject: python polygon In-Reply-To: References: Message-ID: On 05/04/2012 14:49, Kevin Zhang wrote: > Hi, > > I found python polygon link in this page > http://pypi.python.org/pypi/Polygon/1.17 was invalid now. > > http://polygon.origo.ethz.ch/download > 404 - Project not found > > Ooops, the subdomain is not valid because the according project does not > (yet) exist. > Go to the Origo main page at http://origo.ethz.ch > > Can anyone provide some updates on this? > > Thanks, > It's now http://pypi.python.org/pypi/Polygon/2.0.4 -- Cheers. Mark Lawrence. From gordon at panix.com Thu Apr 5 12:12:16 2012 From: gordon at panix.com (John Gordon) Date: Thu, 5 Apr 2012 16:12:16 +0000 (UTC) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: In <7367295.815.1333578860181.JavaMail.geo-discussion-forums at ynpp8> Miki Tebeka writes: > Greetings, > I'm going to give a "Python Gotcha's" talk at work. > If you have an interesting/common "Gotcha" (warts/dark corners ...) > please share. This is fairly pedestrian as gotchas go, but it has bitten me: If you are working with data that is representable as either an integer or a string, choose one and stick to it. Treating it as both/either will eventually lead to grief. Or, in other words: 1 != '1' -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From gstaniak at gmail.com Thu Apr 5 12:25:16 2012 From: gstaniak at gmail.com (Grzegorz Staniak) Date: Thu, 5 Apr 2012 16:25:16 +0000 (UTC) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05.04.2012, Roy Smith wroted: > There's absolutely no reason why JSON should follow Python syntax > rules. Making it support either kind of quotes would have > complicated every JSON library in the world, for no added value. I think these days it's not just "Python syntax", it's kinda something that you can get accustommed to take for granted. Realistically, how much more complication could the support for either quote marks introduce? I doubt anyone would even notice. And you don't have to write JSON by hand for this gotcha to bite you, all it takes is to start playing with generating JSON without the use of specialized JSON libraries/functions. For testing, for fun, out of curiosity... GS -- Grzegorz Staniak From tycho at tycho.ws Thu Apr 5 12:31:56 2012 From: tycho at tycho.ws (Tycho Andersen) Date: Thu, 5 Apr 2012 11:31:56 -0500 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120405163156.GE2340@ccapuser-ubuntu.WICOURTS.GOV> On Thu, Apr 05, 2012 at 08:32:10AM -0400, Roy Smith wrote: > > One of the hardest things about writing parsers is generating helpful > error messages when things don't parse. But, it's only of value to do > that when you're parsing something you expect to be written by a human, > and thus a human has to puzzle out what they did wrong. Nobody expects > that a JSON parser will be parsing human-written input, so there's > little value to saying anything more than "parse error". Except for the human that has to debug why something automatically generated doesn't parse. That guy would probably appreciate a reasonable error message. (And indeed, as a sibling poster points out, people do write JSON by hand quite frequently.) \t From rosuav at gmail.com Thu Apr 5 12:47:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Apr 2012 02:47:14 +1000 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 6, 2012 at 2:25 AM, Grzegorz Staniak wrote: > On 05.04.2012, Roy Smith wroted: > >> There's absolutely no reason why JSON should follow Python syntax >> rules. Making it support either kind of quotes would have >> complicated every JSON library in the world, for no added value. > > I think these days it's not just "Python syntax", it's kinda something > that you can get accustommed to take for granted. Realistically, how > much more complication could the support for either quote marks > introduce? I doubt anyone would even notice. And you don't have to > write JSON by hand for this gotcha to bite you, all it takes is to > start playing with generating JSON without the use of specialized > JSON libraries/functions. For testing, for fun, out of curiosity... It all depends on the language. C and several C-derived languages distinguish between "string constants" and 'integer constants', where the latter are defined by character codepoint; PHP and bash have "interpolated strings" and 'non-interpolated strings'; Python and REXX have no difference between the two. All are legitimate design choices. Assuming that multiple languages/protocols have the same flexibility is dangerous, and I'm not surprised that JSON's strictness is biting people. Maybe the weird error message should be addressed as a bug, and then there won't be a problem :) ChrisA From yagnesh at live.com Thu Apr 5 12:50:50 2012 From: yagnesh at live.com (yag) Date: Fri, 06 Apr 2012 01:50:50 +0900 Subject: inheritance Message-ID: <87398idswl.fsf@live.com> Hello, I am new to python (or to any programming language). My first post on this list, so please go easy. Apologies if its a FAQ. Here is what I have -------------------------------- #! /usr/bin/env python3 # -*- coding: utf-8 -*- class A(object): def __init__(self, a): print('a = ', a) self.a = a def foo(self): print('printing from foo in A = ',self.a) class B(A): def __init__(self, b, a): super(B, self).__init__(a) print('b = ', b) self.b = b def foo(self): print('printing from foo in B = ',self.b) class C(B): def __init__(self, c, b, a): super(C, self).__init__(b, a) print('c = ', c) self.c = c def foo(self): print('printing from foo in C = ',self.c) x = C(3,2,1) x.foo() -------------------------------- three classes A,B,C and instance x. now how can I call methods foo in class A and B using 'x' instance. (I hope I could pronounce the terminology correct) Thanks. -- YYR From rosuav at gmail.com Thu Apr 5 13:00:40 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Apr 2012 03:00:40 +1000 Subject: inheritance In-Reply-To: <87398idswl.fsf@live.com> References: <87398idswl.fsf@live.com> Message-ID: On Fri, Apr 6, 2012 at 2:50 AM, yag wrote: > > Hello, > > I am new to python (or to any programming language). My first post on this list, > so please go easy. Apologies if its a FAQ. Welcome! > class A(object): > ? ?def foo(self): > ? ? ? ?print('printing from foo in A = ',self.a) > > class B(A): > ? ?def foo(self): > ? ? ? ?print('printing from foo in B = ',self.b) > > class C(B): > ? ?def foo(self): > ? ? ? ?print('printing from foo in C = ',self.c) In each case, you are overriding the foo() method, so your instance will only execute the last one. If you want to chain to the others, you need to write your methods to do so - which is what you've done with __init__. Hope that helps! Chris Angelico From ian.g.kelly at gmail.com Thu Apr 5 13:12:26 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Apr 2012 11:12:26 -0600 Subject: inheritance In-Reply-To: <87398idswl.fsf@live.com> References: <87398idswl.fsf@live.com> Message-ID: On Thu, Apr 5, 2012 at 10:50 AM, yag wrote: > three classes A,B,C and instance x. > > now how can I call methods foo in class A and B using 'x' instance. (I hope I > could pronounce the terminology correct) Do you mean that you want C.foo to call B.foo, and B.foo to call A.foo? If that is the case, just use super(), as you already do with the __init__ method. Or do you want to skip C.foo and call A.foo or B.foo directly? In that case, just call it from the specific class you want. Since you are dispatching from the class instead of the instance, you will have to pass the instance in explicitly as the self argument. For example: B.foo(x) # calls B.foo directly with instance x Cheers, Ian From alain at dpt-info.u-strasbg.fr Thu Apr 5 13:13:54 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 05 Apr 2012 19:13:54 +0200 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: <87obr69k4t.fsf@dpt-info.u-strasbg.fr> Miki Tebeka writes: [...] > (Note that I want over http://wiki.python.org/moin/PythonWarts already). The "local variable and scoping" is, imho, something to be really careful about. Here is an example: class A(object): def __init__(self): self.x = 0 def r(self): return x # forgot self a = A() x = 1 print a.r() # prints 1 I know there is "no remedy". It's just really tricky. -- Alain. From yagnesh at live.com Thu Apr 5 13:26:33 2012 From: yagnesh at live.com (yagnesh) Date: Fri, 06 Apr 2012 02:26:33 +0900 Subject: inheritance References: <87398idswl.fsf@live.com> Message-ID: <87y5qaccom.fsf@live.com> Chris Angelico writes: > On Fri, Apr 6, 2012 at 2:50 AM, yag wrote: >> [snipped 19 lines] > In each case, you are overriding the foo() method, so your instance > will only execute the last one. If you want to chain to the others, > you need to write your methods to do so - which is what you've done > with __init__. > > Hope that helps! Yes it does. thank you a lot. -- YYR From yagnesh at live.com Thu Apr 5 13:37:20 2012 From: yagnesh at live.com (Yagnesh Raghava Yakkala) Date: Fri, 06 Apr 2012 02:37:20 +0900 Subject: inheritance References: <87398idswl.fsf@live.com> Message-ID: <87ty0ycc6n.fsf@live.com> Hello Ian, Ian Kelly writes: > On Thu, Apr 5, 2012 at 10:50 AM, yag wrote: >> three classes A,B,C and instance x. >> >> now how can I call methods foo in class A and B using 'x' instance. (I hope I >> could pronounce the terminology correct) > > Do you mean that you want C.foo to call B.foo, and B.foo to call > A.foo? If that is the case, just use super(), as you already do with > the __init__ method. > > Or do you want to skip C.foo and call A.foo or B.foo directly? yes! >In that case, just call it from the specific class you want. Since you > are dispatching from the class instead of the instance, I couldn't understand what you mean here, (may be because my poor knowledge with the terminology) >you will have > to pass the instance in explicitly as the self argument. For example: > B.foo(x) # calls B.foo directly with instance x This is interesting, Now I kind of vaguely getting why we keep 'self' argument around in each method. Thanks you -- YYR From showell30 at yahoo.com Thu Apr 5 13:42:52 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 10:42:52 -0700 (PDT) Subject: Difference between tempfile and spooled tempfile? References: <4f7db133$0$6953$e4fe514c@news2.news.xs4all.nl> Message-ID: On Apr 5, 8:10?am, Steve Howell wrote: > On Apr 5, 7:50?am, "Alex van der Spek" wrote: > > > > > > > > > > > I do not understand why the spooled write gives an error. See below. > > The normal tempfile works just fine. They are supposed to behave equal? > > > All insight you can provide is welcome. > > Alex van der Spek > > > +++++++++++++++++++++++++++++++++++++++++++++++++ > > > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] > > on win32 > > Type "copyright", "credits" or "license()" for more information. > > > >>> import array > > >>> import tempfile > > >>> stf = tempfile.SpooledTemporaryFile(max_size=1024) > > >>> ptf = tempfile.TemporaryFile() > > >>> fff = [float(x) for x in range(2048)] > > >>> ffa = array.array('f',fff) > > >>> ptf.write(ffa) > > >>> stf.write(ffa) > > > Traceback (most recent call last): > > ? File "", line 1, in > > ? ? stf.write(ffa) > > ? File "C:\Python27\lib\tempfile.py", line 595, in write > > ? ? rv = file.write(s) > > TypeError: must be string or read-only character buffer, not array.array > > I think the docs are slightly misleading. ?While SpooledTemporaryFile > allows you to write(), it's more finicky about serializing arrays, > hence the error message. > > If you look under the hood, you'll see that it's mostly a limitation > of StringIO. > > http://hg.python.org/cpython/file/2.7/Lib/tempfile.py > > ? ?494 ? ? """Temporary file wrapper, specialized to switch from > ? ?495 ? ? StringIO to a real file when it exceeds a certain size or > ? ?496 ? ? when a fileno is needed. > ? ?497 ? ? """ > ? ?498 ? ? _rolled = False > ? ?499 > ? ?500 ? ? def __init__(self, max_size=0, mode='w+b', bufsize=-1, > ? ?501 ? ? ? ? ? ? ? ? ?suffix="", prefix=template, dir=None): > ? ?502 ? ? ? ? self._file = _StringIO() > ? ?503 ? ? ? ? self._max_size = max_size > ? ?504 ? ? ? ? self._rolled = False > ? ?505 ? ? ? ? self._TemporaryFileArgs = (mode, bufsize, suffix, > prefix, dir) > > (See line 502.) > > ? ?600 ? ? def write(self, s): > ? ?601 ? ? ? ? file = self._file > ? ?602 ? ? ? ? rv = file.write(s) > ? ?603 ? ? ? ? self._check(file) > ? ?604 ? ? ? ? return rv > > (See line 602.) > > I'm looking at a slightly different version of the module than you, > but hopefully you get the idea. P.S. The problems the OP is encountering may be a side effect of this bug: http://bugs.python.org/issue1730114 From yagnesh at live.com Thu Apr 5 13:50:00 2012 From: yagnesh at live.com (Yagnesh Raghava Yakkala) Date: Fri, 06 Apr 2012 02:50:00 +0900 Subject: inheritance References: <87398idswl.fsf@live.com> <87ty0ycc6n.fsf@live.com> Message-ID: <87hawycblj.fsf@live.com> Hello Ian, Yagnesh Raghava Yakkala writes: > Hello Ian, > > Ian Kelly writes: [snipped 21 lines] > >>you will have >> to pass the instance in explicitly as the self argument. For example: > >> B.foo(x) # calls B.foo directly with instance x After follow up, I see one problem(can i say that?) with this. With python overwriting methods of super class(es), one need to keep track of all the methods ever defined in the super class(es). do everybody do a check before writing a new method for existing method with the same name.? -- YYR From rosuav at gmail.com Thu Apr 5 13:57:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Apr 2012 03:57:02 +1000 Subject: inheritance In-Reply-To: <87hawycblj.fsf@live.com> References: <87398idswl.fsf@live.com> <87ty0ycc6n.fsf@live.com> <87hawycblj.fsf@live.com> Message-ID: On Fri, Apr 6, 2012 at 3:50 AM, Yagnesh Raghava Yakkala wrote: > After follow up, I see one problem(can i say that?) with this. With python > overwriting methods of super class(es), one need to keep track of all the > methods ever defined in the super class(es). do everybody do a check before > writing a new method for existing method with the same name.? If you're subclassing something, you should generally work with the intention that an instance of your class will function viably in any situation in which an instance of the parent is wanted. So if you're writing a method of the same name as one in the parent, you should be performing the exact same task and with the same parameters (possibly having more parameters accepted, but default values set for them). That's part of what it means to subclass. ChrisA From roy at panix.com Thu Apr 5 14:07:23 2012 From: roy at panix.com (Roy Smith) Date: Thu, 05 Apr 2012 14:07:23 -0400 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Grzegorz Staniak wrote: > On 05.04.2012, Roy Smith wroted: > > > There's absolutely no reason why JSON should follow Python syntax > > rules. Making it support either kind of quotes would have > > complicated every JSON library in the world, for no added value. > > I think these days it's not just "Python syntax", it's kinda something > that you can get accustommed to take for granted. Realistically, how > much more complication could the support for either quote marks > introduce? I doubt anyone would even notice. And you don't have to > write JSON by hand for this gotcha to bite you, all it takes is to > start playing with generating JSON without the use of specialized > JSON libraries/functions. For testing, for fun, out of curiosity... If you want to talk a protocol, read the protocol specs and follow them. Don't just look at a few examples, guess about the rules, and then act surprised when your guess turns out to be wrong. If you don't want to take the trouble to read and understand the protocol specs, use a library written by somebody who has already done the hard work for you. From roy at panix.com Thu Apr 5 14:08:13 2012 From: roy at panix.com (Roy Smith) Date: Thu, 05 Apr 2012 14:08:13 -0400 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: In article , John Gordon wrote: > In <7367295.815.1333578860181.JavaMail.geo-discussion-forums at ynpp8> Miki > Tebeka writes: > > > Greetings, > > > I'm going to give a "Python Gotcha's" talk at work. > > If you have an interesting/common "Gotcha" (warts/dark corners ...) > > please share. > > This is fairly pedestrian as gotchas go, but it has bitten me: > > If you are working with data that is representable as either an integer > or a string, choose one and stick to it. Treating it as both/either will > eventually lead to grief. > > Or, in other words: 1 != '1' Tell that to the PHP crowd :-) From yagnesh at live.com Thu Apr 5 14:09:19 2012 From: yagnesh at live.com (Yagnesh Raghava Yakkala) Date: Fri, 06 Apr 2012 03:09:19 +0900 Subject: inheritance References: <87398idswl.fsf@live.com> <87ty0ycc6n.fsf@live.com> <87hawycblj.fsf@live.com> Message-ID: <87d37mcapc.fsf@live.com> Hello Chris, Chris Angelico writes: > > If you're subclassing something, you should generally work with the > intention that an instance of your class will function viably in any > situation in which an instance of the parent is wanted. So if you're > writing a method of the same name as one in the parent, you should be > performing the exact same task and with the same parameters (possibly > having more parameters accepted, but default values set for them). > That's part of what it means to subclass. Thanks for explaining. It makes sense. I see that python interpreter can instantly tell the list of defined methods in the super class(es). So "keeping track" thing is not at all a problem. Thanks a lot again. -- YYR From joncle at googlemail.com Thu Apr 5 14:10:51 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 5 Apr 2012 11:10:51 -0700 (PDT) Subject: Python Gotcha's? In-Reply-To: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: <24853077.1711.1333649451514.JavaMail.geo-discussion-forums@vbyj26> On Wednesday, 4 April 2012 23:34:20 UTC+1, Miki Tebeka wrote: > Greetings, > > I'm going to give a "Python Gotcha's" talk at work. > If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. > > (Note that I want over http://wiki.python.org/moin/PythonWarts already). > > Thanks, > -- > Miki One I've had to debug... >>> text = 'abcdef' >>> if text.find('abc'): print 'found it!' # Nothing prints as bool(0) is False >>> if text.find('bob'): print 'found it!' found it! Someone new who hasn't read the docs might try this, but then I guess it's not really a gotcha if they haven't bothered doing that. From ian.g.kelly at gmail.com Thu Apr 5 14:11:16 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Apr 2012 12:11:16 -0600 Subject: inheritance In-Reply-To: <87hawycblj.fsf@live.com> References: <87398idswl.fsf@live.com> <87ty0ycc6n.fsf@live.com> <87hawycblj.fsf@live.com> Message-ID: On Thu, Apr 5, 2012 at 11:50 AM, Yagnesh Raghava Yakkala wrote: >>>you will have >>> to pass the instance in explicitly as the self argument. ?For example: >> >>> B.foo(x) ?# calls B.foo directly with instance x > > After follow up, I see one problem(can i say that?) with this. With python > overwriting methods of super class(es), one need to keep track of all the > methods ever defined in the super class(es). do everybody do a check before > writing a new method for existing method with the same name.? That syntax is for extraordinary cases where you know that you always want a specific version of the method from a specific class in the inheritance hierarchy to be called. Normally, you would just do "x.foo()" and allow the type of x to determine the exact method that is called. As long as you design your classes with encapsulation and the Liskov substitution principle in mind, it should not matter to you whether "x.foo()" results in calling B.foo or C.foo is called, because the end result will be the same, with any variations appropriate to the actual type of x. From rosuav at gmail.com Thu Apr 5 14:15:10 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Apr 2012 04:15:10 +1000 Subject: inheritance In-Reply-To: <87d37mcapc.fsf@live.com> References: <87398idswl.fsf@live.com> <87ty0ycc6n.fsf@live.com> <87hawycblj.fsf@live.com> <87d37mcapc.fsf@live.com> Message-ID: On Fri, Apr 6, 2012 at 4:09 AM, Yagnesh Raghava Yakkala wrote: > Thanks for explaining. It makes sense. I see that python interpreter can > instantly tell the list of defined methods in the super class(es). So "keeping > track" thing is not at all a problem. > > Thanks a lot again. Most welcome! You can get a list of those methods in your own program using the dir() function. There's a whole lot of double-underscore ("dunder") methods in there, but also all of your own. Tip: At the interactive interpreter prompt, type: help(dir) ChrisA From steve+comp.lang.python at pearwood.info Thu Apr 5 14:15:46 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2012 18:15:46 GMT Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Apr 2012 08:32:10 -0400, Roy Smith wrote: > In article <4f7d896f$0$29983$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> > You mean JSON expects a string with valid JSON? Quelle surprise. >> >> No. The surprise is that there exists a tool invented in the 21st >> century that makes a distinction between strings quoted with " and >> those quoted with '. Being used to a sensible language like Python, it >> boggled my brain the first time I tried to write some JSON and >> naturally treated the choice of quote mark as arbitrary. > > Your brain has a low boggle threshold. > > There's absolutely no reason why JSON should follow Python syntax rules. Except for the most important reason of all: Python's use of alternate string delimiters is an excellent design, one which Javascript itself follows. http://www.javascripter.net/faq/quotesin.htm I'm not the only one who has had trouble with JSON's poor design choice: http://stackoverflow.com/a/4612914 For a 21st century programming language or data format to accept only one type of quotation mark as string delimiter is rather like having a 21st century automobile with a hand crank to start the engine instead of an ignition. Even if there's a good reason for it (which I doubt), it's still surprising. > Making it support either kind of quotes would have complicated every > JSON library in the world, for no added value. Ooooh, such complication. I wish my software was that complicated. The added value includes: * semantic simplicity -- a string is a string, regardless of which quotes are used for delimiters; * reducing the number of escaped quotes needed; * compatibility with Javascript; * robustness. As it stands, JSON fails to live up to the Robustness principle and Postel's law: Be liberal in what you accept, and conservative in what you send. http://en.wikipedia.org/wiki/Robustness_principle > Nobody should ever be hand-writing JSON So you say, but it is a fact that people do. And even if they don't hand- write it, people do *read* it, and allowing both quotation marks aids readability: "\"Help me Obiwan,\" she said, \"You're my only hope!\"" Blah. You can cut the number of escapes needed to one: '"Help me Obiwan," she said, "You\'re my only hope!"' > (just like nobody should ever be hand-writing XML). > Just use the supplied library calls and you'll never have to worry about > low-level minutia like this again. > >> It especially boggled my brain when I saw the pathetically useless >> error message generated: >> >> py> json.loads("{'test':'test'}") >> [...] >> ValueError: Expecting property name: line 1 column 1 (char 1) >> >> "Expecting property name"??? WTF??? > > One of the hardest things about writing parsers is generating helpful > error messages when things don't parse. But, it's only of value to do > that when you're parsing something you expect to be written by a human, Or when debugging a faulty or buggy generator, or when dealing with non- conforming or corrupted data. Essentially any time that you expect the error message will be read by a human being. Which is always. Error messages are for the human reader, always and without exception. If you don't expect it to be read by a person, why bother with a message? -- Steven From yagnesh at live.com Thu Apr 5 14:17:27 2012 From: yagnesh at live.com (Yagnesh Raghava Yakkala) Date: Fri, 06 Apr 2012 03:17:27 +0900 Subject: [solved] Re: inheritance References: <87398idswl.fsf@live.com> Message-ID: <878viacabs.fsf_-_@live.com> Hello, With Chris and Ian help (Thank you both) I end up writing the example script like this,(just for the record) ------------------------------------- #! /usr/bin/env python3 # -*- coding: utf-8 -*- class A(object): def __init__(self, a): print('a = ', a) self.a = a def foo(self): print('printing from foo in A = ',self.a) class B(A): def __init__(self, b, a): super(B, self).__init__(a) print('b = ', b) self.b = b def foo(self): print('printing from foo in B = ',self.b) def bar(self): print('printing from foo in B = ',self.b) class C(B): def __init__(self, c, b, a): super(C, self).__init__(b, a) print('c = ', c) self.c = c def foo(self): print('printing from foo in C = ',self.c) def baz(self): print('printing from foo in C = ',self.c) x = C(3,2,1) x.bar() x.baz() print("") x.foo() B.foo(x) A.foo(x) # inheritance.py ends here ------------------------------------- -- YYR From nathan.alexander.rice at gmail.com Thu Apr 5 14:17:48 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 5 Apr 2012 14:17:48 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <4f7be0dc$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> <78a6d2f8-23de-496a-afb7-943b60e57c88@mq9g2000pbb.googlegroups.com> <94c6033a-26e7-4b49-911c-b63ca01d13ea@wj4g2000pbc.googlegroups.com> <4f7be0dc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: Re-trolling. On Wed, Apr 4, 2012 at 1:49 AM, Steven D'Aprano wrote: >> As part of my troll-outreach effort, I will indulge here. ?I was >> specifically thinking about some earlier claims that programming >> languages as they currently exist are somehow inherently superior to a >> formalized natural language in expressive power. > > I would argue that they are, but only for the very limited purpose for > which they are written. With the possible exception of Inform 7, most > programming languages are useless at describing (say) human interactions. I was thinking about this statement this morning. Compression is just the process of finding a more efficient encoding for information. I suppose you could say then that language developers could theoretically be trying to compress natural language representations of information. The problem then is that everyone is doing a horrible job, because they are approaching the subject in an ad hoc manner. There are multiple branches of mathematics and computer science that deal with this exact subject in a rigorous way. The trick is to find an encoding that has low space complexity, and for which the transformation to knowledge is efficient, for human beings. Lets assume that the input to be encoded are logical (proposition/predicate) statements. The first thing that came to mind when thinking this way is radix trees and directed acyclic word graphs (a form of DFA). These structures are fairly easy to work out on paper given a set of inputs, and it is fairly easy to reconstruct a set of inputs from the structure. Perhaps, we could use natural language statements, and some very minimal extended syntax to indicate a data structure (which fans out to a set of statements). As a quick example to see what I mean (mimicking some python syntax for similarity): in the context of chess: a color is either white or black the board: is a cartesian grid having dimension (8, 8) has squares, representing points on the grid a square: has a color contains a piece or is empty a piece: has a color is located in a square or has been captured a { king, queen, rook, bishop, knight, pawn } is a type of piece It should be clear that this is a directed acyclic phrase graph, and if you select a phrase fragment, then one phrase fragment from each child level until reaching a leaf, the concatenation of the phrase fragments forms a logical phrase. Note that the set braces are shorthand for multiple statements. This was really easy to write, and I bet even non programmers would have little or no trouble understanding what was going on. Additionally, I could make a full statement elsewhere, and if we have an algorithm to transform to a canonical phrase structure and merge synonyms, it could be inserted in the phrase graph, just as neatly as if I had written it there in the first place. The sexy thing about that, is that lets you take two sets of propositional statements, and perform set theoretic operations on them (union, complement, etc), and get a phrase graph structure out at the end which looks just like a nice neat little "program". You could even get really crazy, if you could define equivalence relations (other than the natural relation) for the union (Set1.A ~ Set2.B) as that would let you compose the graphs in arbitrarily many ways. If you're dealing processes, you would also want to be able to specify temporal equivalence (Process1.T1 ~ Process2.T6). From steve+comp.lang.python at pearwood.info Thu Apr 5 14:22:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2012 18:22:22 GMT Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f7de2dd$0$29983$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Apr 2012 11:06:11 +0000, Duncan Booth wrote: > Steven D'Aprano wrote: > >> JSON expects double-quote marks, not single: >> v = json.loads("{'test':'test'}") fails v = >> json.loads('{"test":"test"}') succeeds >> >> > You mean JSON expects a string with valid JSON? Quelle surprise. Actually, on further thought, and on reading the JSON RFC, I have decided that this is a design bug and not merely a gotcha. The relevant section of the RFC is this: 4. Parsers A JSON parser transforms a JSON text into another representation. A JSON parser MUST accept all texts that conform to the JSON grammar. A JSON parser MAY accept non-JSON forms or extensions. http://www.ietf.org/rfc/rfc4627.txt So a valid parser is permitted to accept data which is not strictly JSON. Given that both Javascript and Python (and I would argue, any sensible modern language) allows both single and double quotation marks as delimiters, the JSON parser should do the same. Failure to take advantage of that is a design flaw. Of course, the RFC goes on to say that a JSON generator MUST only generate text which conforms to the JSON grammar. So a conforming implementation would be perfectly entitled to accept, but not emit, single-quote delimited strings. -- Steven From rosuav at gmail.com Thu Apr 5 14:24:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Apr 2012 04:24:00 +1000 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: On Fri, Apr 6, 2012 at 4:08 AM, Roy Smith wrote: >> If you are working with data that is representable as either an integer >> or a string, choose one and stick to it. ?Treating it as both/either will >> eventually lead to grief. >> >> Or, in other words: 1 != '1' > > Tell that to the PHP crowd :-) I think this example highlights a major point about gotchas: the difference between an obvious language feature and a gotcha depends on where you come from. To a PHP programmer, 1 and "1" are in many ways indistinguishable. To a C programmer, they're utterly incompatible. ChrisA From gordon at panix.com Thu Apr 5 14:38:35 2012 From: gordon at panix.com (John Gordon) Date: Thu, 5 Apr 2012 18:38:35 +0000 (UTC) Subject: Best way to disconnect from ldap? References: Message-ID: In John Gordon writes: > I'm writing an application that interacts with ldap, and I'm looking > for advice on how to handle the connection. Specifically, how to > close the ldap connection when the application is done. > I wrote a class to wrap an LDAP connection, similar to this: > import ldap > import ConfigParser > class MyLDAPWrapper(object): > def __init__(self): > config = ConfigParser.SafeConfigParser() > config.read('sample.conf') > > uri = config.get('LDAP', 'uri') > user = config.get('LDAP', 'user') > password = config.get('LDAP', 'password') > self.ldapClient = ldap.initialize(uri) > self.ldapClient.simple_bind_s(user, password) > My question is this: what is the best way to ensure the ldap connection > gets closed when it should? I could write an explicit close() method, > but that seems a bit messy; there would end up being lots of calls to > close() scattered around in my code (primarily inside exception handlers.) > Or I could write a __del__ method: > def __del__(self): > self.ldapClient.unbind_s() Thanks everyone for your input. I learned a lot! However, I just ran across this bit of documentation on python-ldap.org: class ldap.LDAPObject Instances of LDAPObject are returned by initialize() and open() (deprecated). The connection is automatically unbound and closed when the LDAP object is deleted. So, given that, do I need to do anything at all? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From mhrivnak at hrivnak.org Thu Apr 5 14:44:16 2012 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Thu, 5 Apr 2012 14:44:16 -0400 Subject: Python Gotcha's? In-Reply-To: <4F7DA8E7.1060507@optimum.net> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4F7DA8E7.1060507@optimum.net> Message-ID: This is not a gotcha, and it's not surprising. As John described, you're assigning a new value to an index of a tuple, which tuples don't support. a[0] += [3] is the same as a[0] = a[0] + [3] which after evaluation is the same as a[0] = [1, 3] You can always modify an item that happens to be in a tuple if the item itself is mutable, but you cannot add, remove, or replace items in a tuple. Michael On Thu, Apr 5, 2012 at 10:15 AM, John Posner wrote: > On 4/4/2012 7:32 PM, Chris Angelico wrote: >> Don't know if it's what's meant on that page by the += operator, > > Yes, it is. > >>> a=([1],) >>> a[0].append(2) # This is fine > > [In the following, I use the term "name" rather loosely.] > > The append() method attempts to modify the object whose name is "a[0]". > That object is a LIST, so the attempt succeeds. > >>> a[0]+=[3] # This is not. > > The assignment attempts to modify the object whose name is "a". That > object is a TUPLE, so the attempt fails. This might be a surprise, but > I'm not sure it deserves to be called a wart. > > ?Note the similarity to: > > temp = a[0] + [3] ? # succeeds > a[0] = temp ? ? ? ? # fails > > -John > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Thu Apr 5 14:46:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Apr 2012 04:46:09 +1000 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4F7DA8E7.1060507@optimum.net> Message-ID: On Fri, Apr 6, 2012 at 4:44 AM, Michael Hrivnak wrote: > This is not a gotcha, and it's not surprising. ?As John described, > you're assigning a new value to an index of a tuple, which tuples > don't support. > > a[0] += [3] > > is the same as > > a[0] = a[0] + [3] > > which after evaluation is the same as > > a[0] = [1, 3] > > You can always modify an item that happens to be in a tuple if the > item itself is mutable, but you cannot add, remove, or replace items > in a tuple. It does make sense, and I've never actually had problems with it myself. But it's come up on the list and clearly been a cause of confusion for people, so I thought it worth mentioning. And, as it turns out, it was the entry already on the list. ChrisA From mhrivnak at hrivnak.org Thu Apr 5 14:52:00 2012 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Thu, 5 Apr 2012 14:52:00 -0400 Subject: Python Gotcha's? In-Reply-To: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: I'm surprised nobody beat me to posting this: >>> def foo(stuff=[]): ... stuff.append('bar') ... print stuff ... >>> foo() ['bar'] >>> foo() ['bar', 'bar'] >>> foo() ['bar', 'bar', 'bar'] On Wed, Apr 4, 2012 at 6:34 PM, Miki Tebeka wrote: > Greetings, > > I'm going to give a "Python Gotcha's" talk at work. > If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. > > (Note that I want over http://wiki.python.org/moin/PythonWarts already). > > Thanks, > -- > Miki > -- > http://mail.python.org/mailman/listinfo/python-list From driscoll at cs.wisc.edu Thu Apr 5 14:54:35 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 05 Apr 2012 13:54:35 -0500 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: <4F7DEA6B.3000907@cs.wisc.edu> On 4/5/2012 13:24, Chris Angelico wrote: > I think this example highlights a major point about gotchas: the > difference between an obvious language feature and a gotcha depends on > where you come from. To a PHP programmer, 1 and "1" are in many ways > indistinguishable. To a C programmer, they're utterly incompatible. I think I agree with this. For instance, I'd consider the fact that this works in Python to be a gotcha: >>> 1 < "abc" True But that's because I like more strongly-typed systems. [I'm most decidedly not trying to start up that discussion again...] This is changed in Python 3: >>> 1 < "abc" Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: int() < str() though you can still compare *some* types I consider logically unorderable: >>> 0 < True True I think it also has bearing on the ' vs " issue. For instance, I totally think it's not at all surprising that one can be accepted and the other not, or that they behave differently. (Though I *do* find it surprising in the context of JSON given that JS apparently allows either.) Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 552 bytes Desc: OpenPGP digital signature URL: From michael at stroeder.com Thu Apr 5 14:56:27 2012 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 05 Apr 2012 20:56:27 +0200 Subject: Best way to disconnect from ldap? In-Reply-To: References: Message-ID: John Gordon wrote: > class ldap.LDAPObject > Instances of LDAPObject are returned by initialize() and open() > (deprecated). The connection is automatically unbound and closed > when the LDAP object is deleted. > > So, given that, do I need to do anything at all? Hmm, maybe the author of this statement (have to check who) did not know about the caveats with __del__() when this was written ages ago. IIRC first python-ldap release was for Python 1.4 back in '98. See use of dealloc() in Modules/LDAPObject.c. So I'd recommend to use the modern with-statement to make sure LDAPObject.unbind_s() is really called. Being old-fashioned I used try-finally-blocks until now. Ciao, Michael. From tjreedy at udel.edu Thu Apr 5 15:02:56 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Apr 2012 15:02:56 -0400 Subject: regexp partial matching, or hitEnd In-Reply-To: References: Message-ID: On 4/5/2012 8:19 AM, Mark Lawrence wrote: > More likely to go into the new regex module that's on pypi. Talking of > which is this going into Python 3.3, I see it's mentioned in PEP398 but > can't find any mention in the Python 3.3 What's New docs, or have I > simply missed something? I think it has been approved in principle, but still needs some people to do something to actually make it happen. -- Terry Jan Reedy From ian.g.kelly at gmail.com Thu Apr 5 15:15:00 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Apr 2012 13:15:00 -0600 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: On Thu, Apr 5, 2012 at 12:52 PM, Michael Hrivnak wrote: > I'm surprised nobody beat me to posting this: The OP beat you to it -- it's in the list at the wiki link. From cesar.covarrubias at gmail.com Thu Apr 5 15:23:12 2012 From: cesar.covarrubias at gmail.com (cesar.covarrubias at gmail.com) Date: Thu, 5 Apr 2012 12:23:12 -0700 (PDT) Subject: Generating custom Windows installers Message-ID: <2661805.383.1333653792803.JavaMail.geo-discussion-forums@ynuu12> Hello, I am working on creating an installer of a Python 3.2 application that we programmed. The end goal is to create an installer in which we can specify the install path, and create shortcuts in the Start Menu and Desktop. Ideally, we would like to give the users the option to create the Desktop or Start Menu shortcuts. I was able to create a .msi file with the setup.py and install.py files below. This allowed me to specify the custom default path but not create the shortcut in the Start Menu. Can anyone help me figure out what I'm missing? setup.py -------- from cx_Freeze import setup, Executable import sys productName = "ProductName" if 'bdist_msi' in sys.argv: sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' + productName] sys.argv += ['--install-script', 'install.py'] exe = Executable( script="main.py", base="Win32GUI", targetName="Product.exe" ) setup( name="Product.exe", version="1.0", author="Me", description="Copyright 2012", executables=[exe], scripts=[ 'install.py' ] ) ----------------------------------------- install.py ---------- import os import sys import win32com.client as w32client shortcut_group_name = "Start Menu Dir" shortcut_name = "Product Name" shortcut_target = "http://www.microsoft.com" sh = w32client.Dispatch("WScript.Shell") p = sh.SpecialFolders("AllUsersPrograms") assert(os.path.isdir(p)) p = os.path.join(p, shortcut_group_name) if (not os.path.isdir(p)): os.makedirs(p) lnk = sh.CreateShortcut(os.path.join(p, shortcut_name + ".lnk")) lnk.TargetPath = shortcut_target lnk.Save() From emile at fenx.com Thu Apr 5 16:06:36 2012 From: emile at fenx.com (Emile van Sebille) Date: Thu, 05 Apr 2012 13:06:36 -0700 Subject: Python Gotcha's? In-Reply-To: <24853077.1711.1333649451514.JavaMail.geo-discussion-forums@vbyj26> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <24853077.1711.1333649451514.JavaMail.geo-discussion-forums@vbyj26> Message-ID: On 4/5/2012 11:10 AM Jon Clements said... > On Wednesday, 4 April 2012 23:34:20 UTC+1, Miki Tebeka wrote: >> Greetings, >> >> I'm going to give a "Python Gotcha's" talk at work. >> If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. >> >> (Note that I want over http://wiki.python.org/moin/PythonWarts already). >> >> Thanks, >> -- >> Miki > > One I've had to debug... > >>>> text = 'abcdef' > >>>> if text.find('abc'): > print 'found it!' > # Nothing prints as bool(0) is False > >>>> if text.find('bob'): > print 'found it!' > found it! > > Someone new who hasn't read the docs might try this, but then I guess it's not really a gotcha if they haven't bothered doing that. > Kind of begs for a contains method that returns the appropriate boolean: if text.contains('bob') Emile From arnodel at gmail.com Thu Apr 5 16:12:50 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 5 Apr 2012 21:12:50 +0100 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <24853077.1711.1333649451514.JavaMail.geo-discussion-forums@vbyj26> Message-ID: On 5 April 2012 21:06, Emile van Sebille wrote: > Kind of begs for a contains method that returns the appropriate boolean: > > if text.contains('bob') It's already there: text.__contains__('bob') It's usually spelt otherwise though: 'bob' in text -- Arnaud From ian.g.kelly at gmail.com Thu Apr 5 16:14:16 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Apr 2012 14:14:16 -0600 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <24853077.1711.1333649451514.JavaMail.geo-discussion-forums@vbyj26> Message-ID: On Thu, Apr 5, 2012 at 2:06 PM, Emile van Sebille wrote: > On 4/5/2012 11:10 AM Jon Clements said... > >> On Wednesday, 4 April 2012 23:34:20 UTC+1, Miki Tebeka ?wrote: >>> >>> Greetings, >>> >>> I'm going to give a "Python Gotcha's" talk at work. >>> If you have an interesting/common "Gotcha" (warts/dark corners ...) >>> please share. >>> >>> (Note that I want over http://wiki.python.org/moin/PythonWarts already). >>> >>> Thanks, >>> -- >>> Miki >> >> >> One I've had to debug... >> >>>>> text = 'abcdef' >> >> >>>>> if text.find('abc'): >> >> ? ? ? ?print 'found it!' >> # Nothing prints as bool(0) is False >> >>>>> if text.find('bob'): >> >> ? ? ? ?print 'found it!' >> found it! >> >> Someone new who hasn't read the docs might try this, but then I guess it's >> not really a gotcha if they haven't bothered doing that. >> > > > Kind of begs for a contains method that returns the appropriate boolean: > > if text.contains('bob') You mean like this? if 'bob' in text: print 'found it!' Cheers, Ian From gstaniak at gmail.com Thu Apr 5 16:18:22 2012 From: gstaniak at gmail.com (Grzegorz Staniak) Date: Thu, 5 Apr 2012 20:18:22 +0000 (UTC) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05.04.2012, Roy Smith wroted: >> > There's absolutely no reason why JSON should follow Python syntax >> > rules. Making it support either kind of quotes would have >> > complicated every JSON library in the world, for no added value. >> >> I think these days it's not just "Python syntax", it's kinda something >> that you can get accustommed to take for granted. Realistically, how >> much more complication could the support for either quote marks >> introduce? I doubt anyone would even notice. And you don't have to >> write JSON by hand for this gotcha to bite you, all it takes is to >> start playing with generating JSON without the use of specialized >> JSON libraries/functions. For testing, for fun, out of curiosity... > > If you want to talk a protocol, read the protocol specs and follow them. Sure, sure. But it still may raise a few eyebrows as people start to play along while still reading the spces. It's just not something that I'd expect (yes, I learnt Perl before I discovered Python). GS -- Grzegorz Staniak From jabba.laci at gmail.com Thu Apr 5 16:52:27 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Thu, 5 Apr 2012 22:52:27 +0200 Subject: produce the same output as Unix's date command Message-ID: Hi, Unix's date command produces this output (example): Thu Apr 5 22:49:42 CEST 2012 I would like to produce the same output with Python, without calling "date" externally. Before doing it I'd like to ask the list if anyone has an existing solution for this. Thanks, Laszlo From ndparker at gmail.com Thu Apr 5 17:08:11 2012 From: ndparker at gmail.com (=?UTF-8?B?QW5kcsOp?= Malo) Date: Thu, 05 Apr 2012 23:08:11 +0200 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1365568.HPCjg9jpd0@news.perlig.de> * Steven D'Aprano wrote: > For a 21st century programming language or data format to accept only one > type of quotation mark as string delimiter is rather like having a 21st > century automobile with a hand crank to start the engine instead of an > ignition. Even if there's a good reason for it (which I doubt), it's > still surprising. Here's a reason: KISS. Actually I've never understood the reason for multiple equivalent quote characters. There are languages where these are not equivalent, like perl, C or shell script. There it makes way more sense. (If a parser doesn't accept foreign syntax, that's reasonable enough for me, too.) nd From roy at panix.com Thu Apr 5 17:20:11 2012 From: roy at panix.com (Roy Smith) Date: Thu, 05 Apr 2012 17:20:11 -0400 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4f7de152$0$29983$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > I'm not the only one who has had trouble with JSON's poor design choice: This is getting a bit off-topic. If you wish to argue that JSON is designed poorly, you should do that in some appropriate JSON forum. It's not a Python issue. Now, if you wish to boggle your mind about something pythonic, how about mutexes not being thread safe (http://bugs.python.org/issue1746071)? From clp2 at rebertia.com Thu Apr 5 17:51:32 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Apr 2012 14:51:32 -0700 Subject: produce the same output as Unix's date command In-Reply-To: References: Message-ID: On Thu, Apr 5, 2012 at 1:52 PM, Jabba Laci wrote: > Hi, > > Unix's date command produces this output (example): > > Thu Apr ?5 22:49:42 CEST 2012 > > I would like to produce the same output with Python, without calling > "date" externally. Before doing it I'd like to ask the list if anyone > has an existing solution for this. >From POSIX (http://pubs.opengroup.org/onlinepubs/009695399/utilities/date.html ): When no formatting operand is specified, the output in the POSIX locale shall be equivalent to specifying: date "+%a %b %e %H:%M:%S %Z %Y" Therefore: from time import strftime print strftime("%a %b %e %H:%M:%S %Z %Y") But note that `date` is locale-sensitive; imitating that would be a bit more complicated. Cheers, Chris -- http://rebertia.com From driscoll at cs.wisc.edu Thu Apr 5 18:11:47 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 05 Apr 2012 17:11:47 -0500 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4F7DA8E7.1060507@optimum.net> Message-ID: <4F7E18A3.4070504@cs.wisc.edu> On 4/5/2012 13:44, Michael Hrivnak wrote: > This is not a gotcha, and it's not surprising. As John described, > you're assigning a new value to an index of a tuple, which tuples > don't support. Um, at least for me personally, yes, it is surprising, and yes, it is a gotcha. This goes back to what languages you're used to. I come from a strong C++ background. In C++, something like mytuple[0] += [3] would wind up calling 'operator+=' on the list, that += would mutate the list, and then the expression would be done. The C++ approach doesn't really work with Python because more stuff is immutable, and Python's behavior is arguably the least-bad solution, but it WAS definitely surprising for me (and others!) when I learned about Python's behavior. In particular, the translation of 'a+=b' to 'temp = a + b; a = temp' is *not* a very natural one to me. Evan > > Michael > > On Thu, Apr 5, 2012 at 10:15 AM, John Posner wrote: >> On 4/4/2012 7:32 PM, Chris Angelico wrote: >>> Don't know if it's what's meant on that page by the +=perator, >> >> Yes, it is. >> >>>> a=1],) >>>> a[0].append(2) # This is fine >> >> [In the following, I use the term "name" rather loosely.] >> >> The append() method attempts to modify the object whose name is "a[0]". >> That object is a LIST, so the attempt succeeds. >> >>>> a[0]+=] # This is not. >> >> The assignment attempts to modify the object whose name is "a". That >> object is a TUPLE, so the attempt fails. This might be a surprise, but >> I'm not sure it deserves to be called a wart. >> >> Note the similarity to: >> >> temp =[0] + [3] # succeeds >> a[0] =emp # fails >> >> -John >> >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 552 bytes Desc: OpenPGP digital signature URL: From driscoll at cs.wisc.edu Thu Apr 5 18:19:41 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 05 Apr 2012 17:19:41 -0500 Subject: Python Gotcha's? In-Reply-To: <4F7E18A3.4070504@cs.wisc.edu> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4F7DA8E7.1060507@optimum.net> <4F7E18A3.4070504@cs.wisc.edu> Message-ID: <4F7E1A7D.60802@cs.wisc.edu> On 4/5/2012 17:11, Evan Driscoll wrote: > In particular, the translation of 'a+=b' to 'temp = a + b; a = temp' is > *not* a very natural one to me. To expand on this point slightly, because of common C++ idioms guided by efficiency, I would be much more likely to think of 'a + b' as 'temp = a, temp += b, temp' than the Python way: in other words, to the extent that I think of += and + being implemented in terms of each other, I think of + as being implemented via +=. Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 552 bytes Desc: OpenPGP digital signature URL: From breamoreboy at yahoo.co.uk Thu Apr 5 18:36:02 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 05 Apr 2012 23:36:02 +0100 Subject: produce the same output as Unix's date command In-Reply-To: References: Message-ID: -------- Original Message -------- Subject: Re: produce the same output as Unix's date command Date: Thu, 05 Apr 2012 22:07:42 +0100 From: Mark Lawrence Newsgroups: gmane.comp.python.general References: On 05/04/2012 21:52, Jabba Laci wrote: > Hi, > > Unix's date command produces this output (example): > > Thu Apr 5 22:49:42 CEST 2012 > > I would like to produce the same output with Python, without calling > "date" externally. Before doing it I'd like to ask the list if anyone > has an existing solution for this. > > Thanks, > > Laszlo See http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior. -- Cheers. Mark Lawrence. From rosuav at gmail.com Thu Apr 5 19:00:37 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Apr 2012 09:00:37 +1000 Subject: Python Gotcha's? In-Reply-To: <24853077.1711.1333649451514.JavaMail.geo-discussion-forums@vbyj26> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <24853077.1711.1333649451514.JavaMail.geo-discussion-forums@vbyj26> Message-ID: On Fri, Apr 6, 2012 at 4:10 AM, Jon Clements wrote: > One I've had to debug... > >>>> text = 'abcdef' > >>>> if text.find('abc'): > ? ? ? ?print 'found it!' > # Nothing prints as bool(0) is False > >>>> if text.find('bob'): > ? ? ? ?print 'found it!' > found it! > > Someone new who hasn't read the docs might try this, but then I guess it's not really a gotcha if they haven't bothered doing that. But your original will actually never work, since find() returns -1 if not found. This one is far more a gotcha in PHP, where the equivalent function returns boolean False if not found, or index (starting from 0) if found. Returning -1 on not-found is far more logical. (Plus, of course, the 'substring in string' syntax exists for just testing.) ChrisA From miki.tebeka at gmail.com Thu Apr 5 19:36:35 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 5 Apr 2012 16:36:35 -0700 (PDT) Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <24780755.94.1333668995088.JavaMail.geo-discussion-forums@vbvd13> > Now, if you wish to boggle your mind about something pythonic, how about > mutexes not being thread safe (http://bugs.python.org/issue1746071)? This is and old and deprecated module, you should not use it. Use http://docs.python.org/library/threading.html#threading.Lock and friends instead. IMO the bug should be to remove this module and it's documentation :) From cs at zip.com.au Thu Apr 5 20:02:35 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 6 Apr 2012 10:02:35 +1000 Subject: Python Gotcha's? In-Reply-To: <87obr69k4t.fsf@dpt-info.u-strasbg.fr> References: <87obr69k4t.fsf@dpt-info.u-strasbg.fr> Message-ID: <20120406000235.GA27432@cskk.homeip.net> On 05Apr2012 19:13, Alain Ketterlin wrote: | Miki Tebeka writes: | > (Note that I want over http://wiki.python.org/moin/PythonWarts already). | | The "local variable and scoping" is, imho, something to be really | careful about. Here is an example: | | class A(object): | def __init__(self): | self.x = 0 | def r(self): | return x # forgot self | | a = A() | x = 1 | print a.r() # prints 1 | | I know there is "no remedy". It's just really tricky. Whoa! I presume this jost happens with globals and not with one function calling another... (I guess I should test that instead of asking such a dumb question). -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ You see, wire telegraph is a kind of a very, very long cat. You pull his tail in New York and his head is meowing in Los Angeles. Do you understand this? And radio operates exactly the same way: you send signals here, they receive them there. The only difference is that there is no cat. - Albert Einstein, when asked to describe radio From cs at zip.com.au Thu Apr 5 20:15:26 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 6 Apr 2012 10:15:26 +1000 Subject: Python Gotcha's? In-Reply-To: <1365568.HPCjg9jpd0@news.perlig.de> References: <1365568.HPCjg9jpd0@news.perlig.de> Message-ID: <20120406001525.GA29367@cskk.homeip.net> On 05Apr2012 23:08, Andr? Malo wrote: | * Steven D'Aprano wrote: | | > For a 21st century programming language or data format to accept only one | > type of quotation mark as string delimiter is rather like having a 21st | > century automobile with a hand crank to start the engine instead of an | > ignition. Even if there's a good reason for it (which I doubt), it's | > still surprising. | | Here's a reason: KISS. Actually I've never understood the reason for | multiple equivalent quote characters. There are languages where these are | not equivalent, like perl, C or shell script. There it makes way more | sense. I agree, except that even where the quotes are equivalent there is an advantage: writing a string containing quotes: '"Hello," he said.' "It's funny weather." Of course this doesn't scale much if you need both, but it covers a common use. Personally I'm ok with JSON accepting only one kind of quote. And I _have_ been bitten by it and surprised in the past. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ This telephone has too many shortcomings to be seriously considered as a means of communication. The device is inherently of no value to us. - Western Union memo, 1877 From steve+comp.lang.python at pearwood.info Thu Apr 5 21:03:45 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Apr 2012 01:03:45 GMT Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> <1365568.HPCjg9jpd0@news.perlig.de> Message-ID: <4f7e40f1$0$29983$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Apr 2012 23:08:11 +0200, Andr? Malo wrote: > * Steven D'Aprano wrote: > >> For a 21st century programming language or data format to accept only >> one type of quotation mark as string delimiter is rather like having a >> 21st century automobile with a hand crank to start the engine instead >> of an ignition. Even if there's a good reason for it (which I doubt), >> it's still surprising. > > Here's a reason: KISS. KISS is a reason *for* allowing multiple string delimiters, not against it. The simplicity which matters here are: * the user doesn't need to memorise which delimiter is allowed, and which is forbidden, which will be different from probably 50% of the other languages he knows; * the user can avoid the plague of escaping quotes inside strings whenever he needs to embed the delimiter inside a string literal. This is the 21st century, not 1960, and if the language designer is worried about the trivially small extra effort of parsing ' as well as " then he's almost certainly putting his efforts in the wrong place. -- Steven From rosuav at gmail.com Thu Apr 5 21:20:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Apr 2012 11:20:12 +1000 Subject: String delimiter policy (was Re: Python Gotcha's?) Message-ID: On Fri, Apr 6, 2012 at 11:03 AM, Steven D'Aprano wrote: > KISS is a reason *for* allowing multiple string delimiters, not against > it. The simplicity which matters here are: > > * the user doesn't need to memorise which delimiter is allowed, and > ?which is forbidden, which will be different from probably 50% of > ?the other languages he knows; > > * the user can avoid the plague of escaping quotes inside strings > ?whenever he needs to embed the delimiter inside a string literal. > > This is the 21st century, not 1960, and if the language designer is > worried about the trivially small extra effort of parsing ' as well as " > then he's almost certainly putting his efforts in the wrong place. KISS and the Python principle of having one obvious way to do things say that it's illogical to have utterly different ways to accomplish the same thing, UNLESS they are justified. Allowing multiple string delimiters makes it easier to hand-craft JSON; it makes it marginally harder to parse JSON; and it makes it significantly harder to output optimal code - you have to make a judgment call on which delimiter to use, instead of just outputting a string according to the obvious rules. Of course, you could always ignore one of the options and use the other, but then somebody's going to file a bug saying "When my strings contain double quotes, some-encoder-library escapes them instead of using single quotes for delimiters". ChrisA From showell30 at yahoo.com Thu Apr 5 21:20:49 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 18:20:49 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> <1365568.HPCjg9jpd0@news.perlig.de> <4f7e40f1$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 5, 6:03?pm, Steven D'Aprano wrote: > On Thu, 05 Apr 2012 23:08:11 +0200, Andr? Malo wrote: > > * Steven D'Aprano wrote: > > >> For a 21st century programming language or data format to accept only > >> one type of quotation mark as string delimiter is rather like having a > >> 21st century automobile with a hand crank to start the engine instead > >> of an ignition. Even if there's a good reason for it (which I doubt), > >> it's still surprising. > > > Here's a reason: KISS. > > KISS is a reason *for* allowing multiple string delimiters, not against > it. The simplicity which matters here are: > > * the user doesn't need to memorise which delimiter is allowed, and > ? which is forbidden, which will be different from probably 50% of > ? the other languages he knows; Exactly. One of the reasons that human use computers in the first place is that we have flawed memory with respect to details, especially arbitrary ones. It's the job of the computer to make our lives easier. > * the user can avoid the plague of escaping quotes inside strings > ? whenever he needs to embed the delimiter inside a string literal. > Unlike JSON, JS itself allows '"' and "'", although its canonical representation of the latter is '\''. Having said that, I don't mind that JSON is strict; I just hate that certain JSON parsers give cryptic messages on such an obvious gotcha. > This is the 21st century, not 1960, and if the language designer is > worried about the trivially small extra effort of parsing ' as well as " > then he's almost certainly putting his efforts in the wrong place. > FWIW the JSON parser in Javascript is at least capable of giving a precise explanation in its error message, which put it ahead of Python: >config = "{'foo': 'bar'}" "{'foo': 'bar'}" >JSON.parse(config) SyntaxError: Unexpected token ' (Tested under Chrome and node.js, both based on V8.) Here's Python: >>> config = "{'foo': 'bar'}" >>> import json >>> json.loads(config) [...] ValueError: Expecting property name: line 1 column 1 (char 1) (Python's implementation at least beats JS by including line/column info.) From d at davea.name Thu Apr 5 21:38:37 2012 From: d at davea.name (Dave Angel) Date: Thu, 05 Apr 2012 21:38:37 -0400 Subject: Python Gotcha's? In-Reply-To: <20120406000235.GA27432@cskk.homeip.net> References: <87obr69k4t.fsf@dpt-info.u-strasbg.fr> <20120406000235.GA27432@cskk.homeip.net> Message-ID: <4F7E491D.3060007@davea.name> On 04/05/2012 08:02 PM, Cameron Simpson wrote: > On 05Apr2012 19:13, Alain Ketterlin wrote: > | Miki Tebeka writes: > | > (Note that I want over http://wiki.python.org/moin/PythonWarts already). > | > | The "local variable and scoping" is, imho, something to be really > | careful about. Here is an example: > | > | class A(object): > | def __init__(self): > | self.x = 0 > | def r(self): > | return x # forgot self > | > | a = A() > | x = 1 > | print a.r() # prints 1 > | > | I know there is "no remedy". It's just really tricky. > > Whoa! > > I presume this jost happens with globals and not with one function > calling another... (I guess I should test that instead of asking such a > dumb question). It doesn't generally happen "with one function calling another." What it does apply to is to "variables" of nested scope. If the function doesn't have a defining line for x, then the runtime looks one level out. in this case, that's to globals. But in more complex programs, for example with nested functions, it might be to other places. -- DaveA From tjreedy at udel.edu Thu Apr 5 21:46:57 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Apr 2012 21:46:57 -0400 Subject: Python Gotcha's? In-Reply-To: <24780755.94.1333668995088.JavaMail.geo-discussion-forums@vbvd13> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> <24780755.94.1333668995088.JavaMail.geo-discussion-forums@vbvd13> Message-ID: On 4/5/2012 7:36 PM, Miki Tebeka wrote: >> Now, if you wish to boggle your mind about something pythonic, how about >> mutexes not being thread safe (http://bugs.python.org/issue1746071)? > This is and old and deprecated module, you should not use it. > > Use http://docs.python.org/library/threading.html#threading.Lock and friends instead. > > IMO the bug should be to remove this module and it's documentation :) >>> import mutex Traceback (most recent call last): File "", line 1, in import mutex ImportError: No module named 'mutex' It was closed as "won't fix" because "On 2008/2/23, Guido van Rossum said in python-dev > According to the docstring it's only meant to be used with sched.py. > Please don't try to make it work with threads! Anyway, this module will be removed, or at least its API hidden, in 3.0." -- Terry Jan Reedy From dan at tombstonezero.net Thu Apr 5 21:54:30 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Thu, 5 Apr 2012 21:54:30 -0400 Subject: Python Gotcha's? In-Reply-To: <4f7e40f1$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> <1365568.HPCjg9jpd0@news.perlig.de> <4f7e40f1$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120405215430.4f6c4aa8@particle> On 06 Apr 2012 01:03:45 GMT Steven D'Aprano wrote: > This is the 21st century, not 1960 ... Now there's a slippery slope, indeed. ;-) > ... and if the language designer is worried about the trivially small > extra effort of parsing ' as well as " then he's almost certainly > putting his efforts in the wrong place. What about ? and ?, or ? and ?, or ? and ?? Any unicode-aware parser should be able to determine that the next input character is "punctuation, open" or "punctuation, initial" (and doesn't already mean something else in the language) and then scan for the a corresponding "punctuation, close" or "punctuation, final" character. Dan From showell30 at yahoo.com Thu Apr 5 21:56:08 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 18:56:08 -0700 (PDT) Subject: escaping/encoding/formatting in python Message-ID: One of the biggest nuisances for programmers, just beneath date/time APIs in the pantheon of annoyances, is that we are constantly dealing with escaping/encoding/formatting issues. I wrote this little program as a cheat sheet for myself and others. Hope it helps. # escaping quotes legal_string = ['"', "'", "'\"", '"\'', """ '" """] for s in legal_string: print("[" + s + "]") # formatting print 'Hello %s' % 'world' print "Hello %s" % 'world' planet = 'world' print "Hello {planet}".format(**locals()) print "Hello {planet}".format(planet=planet) print "Hello {0}".format(planet) # Unicode s = u"\u0394" print s # prints a triangle print repr(s) == "u'\u0394'" # True print s.encode("utf-8") == "\xce\x94" # True # other examples/resources??? # Web encodings import urllib s = "~foo ~bar" print urllib.quote_plus(s) == '%7Efoo+%7Ebar' # True print urllib.unquote_plus(urllib.quote_plus(s)) == s # True import cgi s = "x < 4 & x > 5" print cgi.escape(s) == 'x < 4 & x > 5' # True # JSON import json h = {'foo': 'bar'} print json.dumps(h) == '{"foo": "bar"}' # True try: bad_json = "{'foo': 'bar'}" json.loads(bad_json) except: print 'Must use double quotes in your JSON' It's tested under Python3.2. I didn't dare to cover regexes. It would be great if somebody could flesh out the Unicode examples or remind me (and others) of other common APIs that are useful to have in your bag of tricks. From pgiri at yahoo.com Thu Apr 5 23:25:11 2012 From: pgiri at yahoo.com (Giridhar Pemmasani) Date: Thu, 5 Apr 2012 20:25:11 -0700 (PDT) Subject: [ANN]: asyncoro: Framework for asynchronous sockets and coroutines Message-ID: <1333682711.39719.YahooMailNeo@web160602.mail.bf1.yahoo.com> asyncoro is a framework for developing concurrent programs with asynchronous event completions and coroutines. Asynchronous completions currently implemented in asyncoro are socket I/O operations, sleep timers, (conditional) event notification and semaphores. Programs developed with asyncoro will have same logic as Python programs with synchronous sockets and threads, except for a few syntactic changes. asyncoro supports polling mechanisms epoll, kqueue, /dev/poll (and poll, select if necessary), and Windows I/O Completion Ports (IOCP) for high performance and scalability, and SSL for security. More details about asyncoro are at?http://dispy.sourceforge.net/asyncoro.html. It can be downloaded from?https://sourceforge.net/projects/dispy/files. asyncoro is used in?development of dispy (http://dispy.sourceforge.net), which is a?framework for parallel execution of computations by distributing them across multiple processors on a single machine (SMP), multiple nodes in a cluster, or large clusters of nodes. The computations can be standalone programs or Python functions. Both asyncoro and dispy have been tested with Python versions 2.7 and 3.2 under Linux, OS X and Windows. Cheers, Giri -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Thu Apr 5 23:42:31 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 06 Apr 2012 13:42:31 +1000 Subject: Generating custom Windows installers In-Reply-To: <2661805.383.1333653792803.JavaMail.geo-discussion-forums@ynuu12> References: <2661805.383.1333653792803.JavaMail.geo-discussion-forums@ynuu12> Message-ID: <4F7E6627.1060900@gmail.com> Seeing you are relying on win32com, you might as well add the links directly rather than via the intermediate WScript.shell object. Look in win32comext\shell\demos\create_link.py for an example of how to create shortcuts directly. HTH, Mark On 6/04/2012 5:23 AM, cesar.covarrubias at gmail.com wrote: > Hello, > > I am working on creating an installer of a Python 3.2 application that we programmed. The end goal is to create an installer in which we can specify the install path, and create shortcuts in the Start Menu and Desktop. Ideally, we would like to give the users the option to create the Desktop or Start Menu shortcuts. > > I was able to create a .msi file with the setup.py and install.py files below. This allowed me to specify the custom default path but not create the shortcut in the Start Menu. > > Can anyone help me figure out what I'm missing? > > > setup.py > -------- > > from cx_Freeze import setup, Executable > import sys > > productName = "ProductName" > if 'bdist_msi' in sys.argv: > sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' + productName] > sys.argv += ['--install-script', 'install.py'] > > exe = Executable( > script="main.py", > base="Win32GUI", > targetName="Product.exe" > ) > setup( > name="Product.exe", > version="1.0", > author="Me", > description="Copyright 2012", > executables=[exe], > scripts=[ > 'install.py' > ] > ) > ----------------------------------------- > > install.py > ---------- > import os > import sys > import win32com.client as w32client > > shortcut_group_name = "Start Menu Dir" > shortcut_name = "Product Name" > shortcut_target = "http://www.microsoft.com" > > sh = w32client.Dispatch("WScript.Shell") > p = sh.SpecialFolders("AllUsersPrograms") > assert(os.path.isdir(p)) > p = os.path.join(p, shortcut_group_name) > if (not os.path.isdir(p)): > os.makedirs(p) > lnk = sh.CreateShortcut(os.path.join(p, shortcut_name + ".lnk")) > lnk.TargetPath = shortcut_target > lnk.Save() > > From research at johnohagan.com Thu Apr 5 23:44:33 2012 From: research at johnohagan.com (John O'Hagan) Date: Fri, 6 Apr 2012 13:44:33 +1000 Subject: Python Gotcha's? In-Reply-To: <4F7DA8E7.1060507@optimum.net> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4F7DA8E7.1060507@optimum.net> Message-ID: <20120406134433.0a27a6fd516ea7483df17798@johnohagan.com> On Thu, 05 Apr 2012 10:15:03 -0400 John Posner wrote: > On 4/4/2012 7:32 PM, Chris Angelico wrote: > > Don't know if it's what's meant on that page by the += operator, > > Yes, it is. > > >> a=([1],) > >> a[0].append(2) # This is fine > > [In the following, I use the term "name" rather loosely.] > > The append() method attempts to modify the object whose name is "a[0]". > That object is a LIST, so the attempt succeeds. > > >> a[0]+=[3] # This is not. > > The assignment attempts to modify the object whose name is "a". That > object is a TUPLE, so the attempt fails. This might be a surprise, but > I'm not sure it deserves to be called a wart. There was a thread called "copy on write" several weeks ago which veered into a discussion of this: http://mail.python.org/pipermail/python-list/2012-January/1286466.html While I follow the reason for the exception noted above, to me this is a gotcha, and has at least two wart-like features: 1) The mutation clearly intended by a[0] += [3] succeeds, even though an exception is raised. What fails is the subsequent assignment, which makes no difference in this case. I wouldn't blame anyone for being surprised to find that a[0] is now [1, 2, 3] despite the exception. 2) Whether the operation succeeds depends on what name we use to refer to the object: >>> a = ([],) >>> b = a[0] >>> b is a[0] True >>> b += [1] >>> a ([1],) >>> a[0] += [2] Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment >>> a ([1, 2],) >>> b is a[0] True Very surprising to me, despite knowing why it happens. I used to believe that how an object is referred to had no effect on its behaviour as an operand. In the abovementioned thread, Hrvoje Niksic posted an implementation approach which avoided all this by "simply not perform[ing] the final assignment if the in-place method is available on the contained object": http://mail.python.org/pipermail/python-list/2012-February/1287400.html However, I get the impression this issue is generally regarded as "least worst, won't fix". Regards, John From rustompmody at gmail.com Fri Apr 6 00:28:01 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 5 Apr 2012 21:28:01 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 5, 4:06?pm, Duncan Booth wrote: > Steven D'Aprano wrote: > > JSON expects double-quote marks, not single: > > ? ? v = json.loads("{'test':'test'}") ?fails > > ? ? v = json.loads('{"test":"test"}') ?succeeds > > You mean JSON expects a string with valid JSON? > Quelle surprise. Are there languages (other than python) in which single and double quotes are equivalent? [No I dont claim to know all the languages out there, just that I dont know any other language which allows single and double quotes to be interconvertible like python does] From rosuav at gmail.com Fri Apr 6 00:35:21 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Apr 2012 14:35:21 +1000 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 6, 2012 at 2:28 PM, rusi wrote: > Are there languages (other than python) in which single and double > quotes are equivalent? > > [No I dont claim to know all the languages out there, just that I dont > know any other language which allows single and double quotes to be > interconvertible like python does] REXX and JavaScript. And probably others. ChrisA From showell30 at yahoo.com Fri Apr 6 00:54:06 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 21:54:06 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <81d3570a-4c20-4d88-80e0-fe8151e60e24@oo9g2000pbc.googlegroups.com> On Apr 5, 9:28?pm, rusi wrote: > On Apr 5, 4:06?pm, Duncan Booth wrote: > > > Steven D'Aprano wrote: > > > JSON expects double-quote marks, not single: > > > ? ? v = json.loads("{'test':'test'}") ?fails > > > ? ? v = json.loads('{"test":"test"}') ?succeeds > > > You mean JSON expects a string with valid JSON? > > Quelle surprise. > > Are there languages (other than python) in which single and double > quotes are equivalent? > > [No I dont claim to know all the languages out there, just that I dont > know any other language which allows single and double quotes to be > interconvertible like python does] Python doesn't treat single quotes and double quotes in *exactly* the same manner, because the choice of outer quotes affects whether you need to escape the outer quote characters inside the string. But I don't want to be overly literal--I think I know what you mean by "equivalent" here. JS, YAML, and HTML are pretty similar to Python with respect to single vs. double, as far as I know/remember/care. Perl, Ruby, and CoffeeScript have the tradition that single quotes are interpreted literally, whereas double quotes allow for interpolation of things within the string. This is roughly inspired by English, where one says things like "Double quotes are an 'enclosing syntax' for single quotes." [Yes, I'm just making that up. Sounds plausible, right?] Both Ruby and CoffeeScript support triple quote syntax similar to Python. C uses double quotes for strings, as opposed to single quotes for characters. Java only allows double quotes for strings. I'll wager a guess that if you took any two programming languages (including declarative languages like SQL/HTML) and compared how they represented string literals, there would be at least one thing different between them, and that difference would be a fairly arbitrary design decision. There are probably exceptions, but languages that have the exact same quoting rules would probably be close dialects of each other in other respects beyond quoting. I'll also wager a guess that at least one thing I said above was wrong, and that's a testament to the arcane nature of representing string literals (as well as my own lack of mental capacity for juggling all these different rules in my brain). And that's just in ASCII with an American English bias. Throw in Unicode--that's when things get really confusing! I'm happy to stand corrected on any fact above. Withhold insults, though. I already know that string literal syntax makes me feel stupid--no need to rub it in. From rustompmody at gmail.com Fri Apr 6 00:59:17 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 5 Apr 2012 21:59:17 -0700 (PDT) Subject: escaping/encoding/formatting in python References: Message-ID: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> On Apr 6, 6:56?am, Steve Howell wrote: > One of the biggest nuisances for programmers, just beneath date/time > APIs in the pantheon of annoyances, is that we are constantly dealing > with escaping/encoding/formatting issues. [OT for this list] If you run $ find /usr/share/emacs/23.3/lisp/ -name '*.gz'|xargs zgrep '\\\\\\\\\\ \\\\\\' you can get quite a few results. [Suitable assumptions: linux box with emacs installed] From showell30 at yahoo.com Fri Apr 6 01:10:30 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 22:10:30 -0700 (PDT) Subject: escaping/encoding/formatting in python References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> Message-ID: On Apr 5, 9:59?pm, rusi wrote: > On Apr 6, 6:56?am, Steve Howell wrote: > > > One of the biggest nuisances for programmers, just beneath date/time > > APIs in the pantheon of annoyances, is that we are constantly dealing > > with escaping/encoding/formatting issues. > > [OT for this list] > If you run > $ find /usr/share/emacs/23.3/lisp/ -name '*.gz'|xargs zgrep '\\\\\\\\\\ > \\\\\\' > you can get quite a few results. > > [Suitable assumptions: linux box with emacs installed] You've one-upped me with 2-to-the-N backspace escaping. I've written useful scripts before with "\\\\\\\\" (scripts that went through three levels of interpretation), but four is setting a new bar. My use of three backslashes back in the day was like Beamon's jump in the Mexico City Olympics. An amazing feat for its time, but every record eventually gets broken. Well done. From showell30 at yahoo.com Fri Apr 6 01:13:24 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 22:13:24 -0700 (PDT) Subject: escaping/encoding/formatting in python References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> Message-ID: <0e358c78-fb71-4b28-a737-f9e6468cf2bc@a8g2000pbe.googlegroups.com> On Apr 5, 9:59?pm, rusi wrote: > On Apr 6, 6:56?am, Steve Howell wrote: > > > One of the biggest nuisances for programmers, just beneath date/time > > APIs in the pantheon of annoyances, is that we are constantly dealing > > with escaping/encoding/formatting issues. > > [OT for this list] > If you run > $ find /usr/share/emacs/23.3/lisp/ -name '*.gz'|xargs zgrep '\\\\\\\\\\ > \\\\\\' > you can get quite a few results. > > [Suitable assumptions: linux box with emacs installed] You've one-upped me with 2-to-the-N backslash escaping. I've written useful scripts before with "\\\\\\\\" (scripts that went through three levels of interpretation), but four is setting a new bar. My use of three exponentially increasing levels of backslashes back in the day was like Beamon's jump in the Mexico City Olympics. An amazing feat for its time, but every record eventually gets broken. Well done. From rustompmody at gmail.com Fri Apr 6 01:28:19 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 5 Apr 2012 22:28:19 -0700 (PDT) Subject: escaping/encoding/formatting in python References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> <0e358c78-fb71-4b28-a737-f9e6468cf2bc@a8g2000pbe.googlegroups.com> Message-ID: On Apr 6, 10:13?am, Steve Howell wrote: > On Apr 5, 9:59?pm, rusi wrote: > > > On Apr 6, 6:56?am, Steve Howell wrote: > > > > One of the biggest nuisances for programmers, just beneath date/time > > > APIs in the pantheon of annoyances, is that we are constantly dealing > > > with escaping/encoding/formatting issues. > > > [OT for this list] > > If you run > > $ find /usr/share/emacs/23.3/lisp/ -name '*.gz'|xargs zgrep '\\\\\\\\\\ > > \\\\\\' > > you can get quite a few results. > > > [Suitable assumptions: linux box with emacs installed] > > You've one-upped me with 2-to-the-N backslash escaping. ?I've written > useful scripts before with "\\\\\\\\" (scripts that went through > three > levels of interpretation), but four is setting a new bar. ?My use of > three exponentially increasing levels of backslashes back in the day > was like Beamon's jump in the Mexico City Olympics. ?An amazing feat > for its time, but every record > eventually gets broken. ?Well done. There was a competition here?! If so I can break my own record -- double the number of backslashes and you still get hits. Its just that I was unsure of my ability at typing 32 backslashes (and making a reasonable post). On a more serious note this indicates that it is (may be?) a bad idea for old-fashioned languages (like elisp and C) to have only 1 string- quoter. May-be-question-mark because programming language experience tells us that avoiding recursion (in its infinite guises) by special-casing is usually a bad idea. All this mess would vanish if the string-literal-starter and ender were different. [You dont need to escape a open-paren in a lisp sexp] From rustompmody at gmail.com Fri Apr 6 01:36:33 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 5 Apr 2012 22:36:33 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <81d3570a-4c20-4d88-80e0-fe8151e60e24@oo9g2000pbc.googlegroups.com> Message-ID: On Apr 6, 9:54?am, Steve Howell wrote: > JS, YAML, and HTML are pretty similar to Python with respect to single > vs. double, as far as I know/remember/care. [Complete ignoramus here -- writing after a few minutes of googling] YAML: http://yaml.org/spec/current.html#single%20quoted%20style/syntax seems to indicate that the double-quote is multi-lineable the single not. [So YAML double-quote is like python triple-quote] JS: http://stackoverflow.com/questions/242813/when-to-use-double-or-single-quotes-in-javascript seems to have some arcane argument about whether there is a difference or not From showell30 at yahoo.com Fri Apr 6 01:50:30 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 5 Apr 2012 22:50:30 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <81d3570a-4c20-4d88-80e0-fe8151e60e24@oo9g2000pbc.googlegroups.com> Message-ID: <51acd026-4c4d-4431-9c2d-7e34c7cbeacd@w6g2000pbp.googlegroups.com> On Apr 5, 10:36?pm, rusi wrote: > On Apr 6, 9:54?am, Steve Howell wrote: > > > JS, YAML, and HTML are pretty similar to Python with respect to single > > vs. double, as far as I know/remember/care. > > [Complete ignoramus here -- writing after a few minutes of googling] > > YAML:http://yaml.org/spec/current.html#single%20quoted%20style/syntax > seems to indicate that the double-quote is multi-lineable the single > not. > [So YAML double-quote is like python triple-quote] > > JS:http://stackoverflow.com/questions/242813/when-to-use-double-or-singl... > seems to have some arcane argument about whether there is a difference > or not I like the fact that even this seemingly harmless statement on the stackoverflow thread invites (light-hearted) controversy: Double quotes will wear your shift key out faster :) The response is this: Not on Azerty, buddy. And, yes, I am quoting via indentation here. But quoting is not a "gotcha". Not in the least bit. Anybody who says "quoting is a gotcha" just doesn't understand how simple this whole quoting business is. Quoting is completely straightforward. "Just read the specs," I think some wise person said earlier in this thread. They're completely correct, of course. No gotchas here. Move along... From bunslow at gmail.com Fri Apr 6 02:57:49 2012 From: bunslow at gmail.com (bunslow at gmail.com) Date: Thu, 5 Apr 2012 23:57:49 -0700 (PDT) Subject: Reading Live Output from a Subprocess Message-ID: <24839857.480.1333695469128.JavaMail.geo-discussion-forums@ynuu20> Okay, I've been trying for days to figure this out, posting on forums, Googling, whatever. I have yet to find a solution that has worked for me. (I'm using Python 3.2.2, Ubuntu 11.04.) Everything I've tried has led to buffered output being spat back all at once after the subprocess terminates. I need this functionality because the script I am currently writing is only glue, and most of the work is done by a subprocess (which could potentially run for a long time). Here are some StackOverflow questions about this topic: http://stackoverflow.com/questions/2525263/capture-subprocess-output http://stackoverflow.com/questions/2996887/how-to-replicate-tee-behavior-in-python-when-using-subprocess http://stackoverflow.com/questions/803265/getting-realtime-output-using-subprocess http://stackoverflow.com/questions/1183643/unbuffered-read-from-process-using-subprocess-in-python http://stackoverflow.com/questions/527197/intercepting-stdout-of-a-subprocess-while-it-is-running And a few others for good measure: http://www.linuxquestions.org/questions/programming-9/python-how-do-you-capture-stdout-stream-from-external-program-612998/ http://devlishgenius.blogspot.com/2008/10/logging-in-real-time-in-python.html Not a single one of the solutions above has worked for me. I've tried ###################################### import subprocess as sub out = sub.Popen(["pypy", "5"], universal_newlines=True, stdout=sub.PIPE, stderr=sub.STDOUT, bufsize=1) line = out.stdout.readline() out.stdout.flush() while line: print(line) line = out.stdout.readline() out.stdout.flush() ###################################### I've tried ###################################### line = out.stdout.readline() while line: print(line) line = out.stdout.readline() ###################################### I've tried ###################################### for line in out.readline(): print(line) ###################################### I've tried ###################################### for line in out.communicate(): print(line) ###################################### etc... None have worked, and it seems that the while loops worked in Python 2.x (according to those links), but not in Python 3. (I am a two week old Python coder, and it's already tied for my strongest language, which is why I decided to start with Python 3.) I've heard that the Pexpect module works wonders, but the problem is that relies on pty which is available in Unix only. Additionally, because I want this script to be usable by others, any solution should be in the standard library, which means I'd have to copy the Pexpect code into my script to use it. Is there any such solution in the Python 3 Standard Library, and if not, how much of a thorn is this? "There should be one-- and preferably only one --obvious way to do it." Unfortunately, this is one case where the above is true for Perl but not Python. Such an example in Perl is open(PROG, "command |") or die "Couldn't start prog!"; while () { print "$_"; } (Note that I do not know Perl and do not have any intentions to learn it; the above comes from the script I was previously copying and extending, but I imagine (due to its simplicity) that it's a common Perl idiom. Note however, that the above does fail if the program re-prints output to the same line, as many long-running C programs do. Preferably this would also be caught in a Python solution.) If there is a general consensus that this is a problem for lots of people, I might consider writing a PEP. Of course, my highest priority is solving the blasted problem, which is holding up my script at the moment. (I can work around this by redirecting the program to a tmp file and reading that, but that would be such a perilous and ugly kludge that I would like to avoid it if at all possible.) Thanks, Bill From clp2 at rebertia.com Fri Apr 6 03:30:11 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Apr 2012 00:30:11 -0700 Subject: Reading Live Output from a Subprocess In-Reply-To: <24839857.480.1333695469128.JavaMail.geo-discussion-forums@ynuu20> References: <24839857.480.1333695469128.JavaMail.geo-discussion-forums@ynuu20> Message-ID: On Thu, Apr 5, 2012 at 11:57 PM, wrote: > Okay, I've been trying for days to figure this out, posting on forums, Googling, whatever. I have yet to find a solution that has worked for me. (I'm using Python 3.2.2, Ubuntu 11.04.) Everything I've tried has led to buffered output being spat back all at once after the subprocess terminates. I need this functionality because the script I am currently writing is only glue, and most of the work is done by a subprocess (which could potentially run for a long time). > Not a single one of the solutions above has worked for me. I've tried > > ###################################### > import subprocess as sub > out = sub.Popen(["pypy", "5"], universal_newlines=True, stdout=sub.PIPE, stderr=sub.STDOUT, bufsize=1) > > line = out.stdout.readline() > out.stdout.flush() > while line: > ? ?print(line) > ? ?line = out.stdout.readline() > ? ?out.stdout.flush() You're flush()-ing the wrong stream here. The process's stdout is an incoming stream from Python's perspective, which makes flushing it pointless AFAIK. You want to flush *Python*'s stdout (that you're print()-ing to). Which would be: import sys for line in out.stdout: print(line) sys.stdout.flush() > ###################################### > > I've tried > > ###################################### > line = out.stdout.readline() > while line: > ? ?print(line) > ? ?line = out.stdout.readline() Less repetitively written: while True: line = out.stdout.readline() if not line: break print(line) Or more idiomatically written: # I hope this was the first thing you tried? for line in out.stdout: print(line) > ###################################### > > I've tried > > ###################################### > for line in out.readline(): > ? ?print(line) (I assume you meant "out.stdout"? "out" is a bad name anyway; it's a process, not an output stream.) This iterates over individual characters in the first line of the output. In "for X in Y", Y only gets evaluated once. > ###################################### > > I've tried > > ###################################### > for line in out.communicate(): > ? ?print(line) That's the explicitly-documented-as-blocking method, the exact opposite of what you want. Cheers, Chris From jarausch at skynet.be Fri Apr 6 04:33:37 2012 From: jarausch at skynet.be (Helmut Jarausch) Date: 06 Apr 2012 08:33:37 GMT Subject: numpy.genfromtxt with Python3 - howto Message-ID: <4f7eaa61$0$3119$ba620e4c@news.skynet.be> Hi I have a machine with a non-UTF8 local. I can't figure out how to make numpy.genfromtxt work I pipe some ascii data into the following script but get this bytes to str hell. Many thanks for a hint, Helmut. #!/usr/bin/python3 import numpy as np import io import sys inpstream = io.open(sys.stdin.fileno(), "r", encoding='latin1') data = np.genfromtxt(inpstream) ''' Traceback (most recent call last): File "SimpleMatInp.py", line 8, in data = np.genfromtxt(inpstream) File "/usr/lib64/python3.2/site-packages/numpy/lib/npyio.py", line 1274, in genfromtxt first_values = split_line(first_line) File "/usr/lib64/python3.2/site-packages/numpy/lib/_iotools.py", line 206, in _delimited_splitter line = line.split(self.comments)[0].strip(asbytes(" \r\n")) TypeError: Can't convert 'bytes' object to str implicitly ''' print(data) print(data.dtype) print(data.shape) From nobody at nowhere.com Fri Apr 6 04:37:10 2012 From: nobody at nowhere.com (Nobody) Date: Fri, 06 Apr 2012 09:37:10 +0100 Subject: Reading Live Output from a Subprocess References: <24839857.480.1333695469128.JavaMail.geo-discussion-forums@ynuu20> Message-ID: On Thu, 05 Apr 2012 23:57:49 -0700, bunslow wrote: > Okay, I've been trying for days to figure this out, posting on forums, > Googling, whatever. I have yet to find a solution that has worked for me. > (I'm using Python 3.2.2, Ubuntu 11.04.) Everything I've tried has led to > buffered output being spat back all at once after the subprocess > terminates. In all probability, this is because the child process (pypy) is buffering its stdout, meaning that the data doesn't get passed to the OS until either the buffer is full or the process terminates. If it doesn't get passed to the OS, then the OS can't pass it on to whatever is on the read end of the pipe. In that situation, there is nothing that the parent process can do about it. > I've heard that the Pexpect module works wonders, If it does, that would confirm the buffering hypothesis. Pexpect causes the child process' stdout to be associated with a pty. The "stdout" stream created by the C library (libc) is initially line-buffered if it is associated with a tty (according to the isatty() function) and fully-buffered otherwise. The program can change the buffering with e.g. setvbuf(), or it can explicitly fflush(stdout) after each line, but this is up to the program, and is not something which can be controlled externally (short of "hacking" the child process with techniques such as ptrace() or LD_PRELOAD). While the libc behaviour is occasionally inconvenient, it is mandated by the C standard (7.19.3p7): As initially opened, the standard error stream is not fully buffered; the standard input and standard output streams are fully buffered if and only if the stream can be determined not to refer to an interactive device. It's up to individual programs to force line-buffered output where appropriate (e.g. GNU grep has the --line-buffered switch, GNU sed has the -u switch, etc). From mwilson at the-wire.com Fri Apr 6 04:47:09 2012 From: mwilson at the-wire.com (mwilson at the-wire.com) Date: Fri, 06 Apr 2012 04:47:09 -0400 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: rusi wrote: > Are there languages (other than python) in which single and double > quotes are equivalent? Kernighan and Plauger's RATFOR (a pre-processor that added some C-like syntax to FORTRAN) did that. Published in their book _Software Tools_. Mel. From nobody at nowhere.com Fri Apr 6 04:52:57 2012 From: nobody at nowhere.com (Nobody) Date: Fri, 06 Apr 2012 09:52:57 +0100 Subject: escaping/encoding/formatting in python References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> <0e358c78-fb71-4b28-a737-f9e6468cf2bc@a8g2000pbe.googlegroups.com> Message-ID: On Thu, 05 Apr 2012 22:28:19 -0700, rusi wrote: > All this mess would vanish if the string-literal-starter and ender > were different. You still need an escape character in order to be able to embed an unbalanced end character. Tcl and PostScript use mirrored string delimiters (braces for Tcl, parentheses for PostScript), which results in the worst of both worlds: they still need an escape character (backslash, in both cases) but now you can't match tokens with a regexp/DFA. From roy at panix.com Fri Apr 6 08:40:44 2012 From: roy at panix.com (Roy Smith) Date: Fri, 06 Apr 2012 08:40:44 -0400 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , mwilson at the-wire.com wrote: > rusi wrote: > > > Are there languages (other than python) in which single and double > > quotes are equivalent? > > Kernighan and Plauger's RATFOR (a pre-processor that added some C-like > syntax to FORTRAN) did that. Published in their book _Software Tools_. I used to write a lot of code in RATFOR. It was really a pretty good tool. From mwilson at the-wire.com Fri Apr 6 09:20:42 2012 From: mwilson at the-wire.com (mwilson at the-wire.com) Date: Fri, 06 Apr 2012 09:20:42 -0400 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Roy Smith wrote: > In article , mwilson at the-wire.com wrote: > >> rusi wrote: >> >> > Are there languages (other than python) in which single and double >> > quotes are equivalent? >> >> Kernighan and Plauger's RATFOR (a pre-processor that added some C-like >> syntax to FORTRAN) did that. Published in their book _Software Tools_. > > I used to write a lot of code in RATFOR. It was really a pretty good > tool. ISTR that RATFOR also concatenated adjacent quoted strings to build up long strings. That sort of puts the capstone on the two-quote-characters scheme. I can't lay my hands on the book to prove it. GE/Honeywell FORTRAN stole the single quote to delimit seek addresses in I/O statements, so my RATFOR implementations had to lose the two-quote feature and use a two-for-one scheme, like backslash-escaping and % inclusion in moduloed strings do in Python. Mel. From rustompmody at gmail.com Fri Apr 6 09:22:13 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Apr 2012 06:22:13 -0700 (PDT) Subject: escaping/encoding/formatting in python References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> <0e358c78-fb71-4b28-a737-f9e6468cf2bc@a8g2000pbe.googlegroups.com> Message-ID: <45ea3f8b-1f78-48aa-9ef0-3004d6ef8721@js1g2000pbc.googlegroups.com> On Apr 6, 1:52?pm, Nobody wrote: > On Thu, 05 Apr 2012 22:28:19 -0700, rusi wrote: > > All this mess would vanish if the string-literal-starter and ender > > were different. > > You still need an escape character in order to be able to embed an > unbalanced end character. > > Tcl and PostScript use mirrored string delimiters (braces for Tcl, > parentheses for PostScript), which results in the worst of both worlds: > they still need an escape character (backslash, in both cases) but now you > can't match tokens with a regexp/DFA. Yes. I hand it to you that I missed the case of explicitly unbalanced strings. But are not such cases rare? For example code such as: print '"' print str(something) print '"' could better be written as print '"%s"' % str(something) From storchaka at gmail.com Fri Apr 6 09:44:42 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 06 Apr 2012 16:44:42 +0300 Subject: escaping/encoding/formatting in python In-Reply-To: References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> <0e358c78-fb71-4b28-a737-f9e6468cf2bc@a8g2000pbe.googlegroups.com> Message-ID: 06.04.12 08:28, rusi ???????(??): > All this mess would vanish if the string-literal-starter and ender > were different. > [You dont need to escape a open-paren in a lisp sexp] But you need to escape an escape symbol. From storchaka at gmail.com Fri Apr 6 09:49:57 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 06 Apr 2012 16:49:57 +0300 Subject: escaping/encoding/formatting in python In-Reply-To: <45ea3f8b-1f78-48aa-9ef0-3004d6ef8721@js1g2000pbc.googlegroups.com> References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> <0e358c78-fb71-4b28-a737-f9e6468cf2bc@a8g2000pbe.googlegroups.com> <45ea3f8b-1f78-48aa-9ef0-3004d6ef8721@js1g2000pbc.googlegroups.com> Message-ID: 06.04.12 16:22, rusi ???????(??): > Yes. I hand it to you that I missed the case of explicitly unbalanced > strings. > But are not such cases rare? No, unfortunately. }:-( > For example code such as: > print '"' > print str(something) > print '"' > > could better be written as > print '"%s"' % str(something) Don't forget to escape %. From steve+comp.lang.python at pearwood.info Fri Apr 6 09:55:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Apr 2012 13:55:20 GMT Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f7ef5c8$0$29983$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Apr 2012 21:28:01 -0700, rusi wrote: > Are there languages (other than python) in which single and double > quotes are equivalent? Classic REXX, CSS, JavaScript, Lua, Prolog, XPath, YAML, Modula-2, HTML, and (of course) English. There may be others. Other languages like Perl, PHP and Ruby support alternate delimiters with slightly different semantics. -- Steven From gstaniak at gmail.com Fri Apr 6 10:18:19 2012 From: gstaniak at gmail.com (Grzegorz Staniak) Date: Fri, 6 Apr 2012 14:18:19 +0000 (UTC) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7ef5c8$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06.04.2012, Steven D'Aprano wroted: >> Are there languages (other than python) in which single and double >> quotes are equivalent? > > Classic REXX, CSS, JavaScript, Lua, Prolog, XPath, YAML, Modula-2, HTML, > and (of course) English. There may be others. > > Other languages like Perl, PHP and Ruby support alternate delimiters with > slightly different semantics. Perl, first of all, has the 'q' and 'qq' operators. As much as I'd come to dislike Perl after I discovered Python, I miss those two. Every time I have to quote a string full of single/double quotes, this comes to my mind: q{'this' is not this, but 'that' is 'that' like 'this'} q|'this' is not this, but 'that' is 'that' like 'this'| q<'this' is not this, but 'that' is 'that' like 'this'> ... with 'qq' providing the version with inerpolation. I could always find an arbitrary character for quoting that was _not_ present in the string, and so, most of the time, avoid quoting altogether. It was perhaps a bit too magical, but pruced very readable strings. GS -- Grzegorz Staniak From cesar.covarrubias at gmail.com Fri Apr 6 10:57:00 2012 From: cesar.covarrubias at gmail.com (Cesar Covarrubias) Date: Fri, 6 Apr 2012 07:57:00 -0700 Subject: Generating custom Windows installers In-Reply-To: <4F7E6627.1060900@gmail.com> References: <2661805.383.1333653792803.JavaMail.geo-discussion-forums@ynuu12> <4F7E6627.1060900@gmail.com> Message-ID: I'm still getting my feet wet on the Windows side of things with Python, so I apologize for the noobish question. If i am reading the create_link.py example correctly, that is created when the application itself is invoked, not during installation. Is that correct? If it is, how would I be able to invoke that when generating the MSI so that the installer creates the shortcut? Cesar On Thu, Apr 5, 2012 at 8:42 PM, Mark Hammond wrote: > Seeing you are relying on win32com, you might as well add the links > directly rather than via the intermediate WScript.shell object. Look in > win32comext\shell\demos\**create_link.py for an example of how to create > shortcuts directly. > > HTH, > > Mark > > On 6/04/2012 5:23 AM, cesar.covarrubias at gmail.com wrote: > >> Hello, >> >> I am working on creating an installer of a Python 3.2 application that we >> programmed. The end goal is to create an installer in which we can specify >> the install path, and create shortcuts in the Start Menu and Desktop. >> Ideally, we would like to give the users the option to create the Desktop >> or Start Menu shortcuts. >> >> I was able to create a .msi file with the setup.py and install.py files >> below. This allowed me to specify the custom default path but not create >> the shortcut in the Start Menu. >> >> Can anyone help me figure out what I'm missing? >> >> >> setup.py >> -------- >> >> from cx_Freeze import setup, Executable >> import sys >> >> productName = "ProductName" >> if 'bdist_msi' in sys.argv: >> sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' + productName] >> sys.argv += ['--install-script', 'install.py'] >> >> exe = Executable( >> script="main.py", >> base="Win32GUI", >> targetName="Product.exe" >> ) >> setup( >> name="Product.exe", >> version="1.0", >> author="Me", >> description="Copyright 2012", >> executables=[exe], >> scripts=[ >> 'install.py' >> ] >> ) >> ------------------------------**----------- >> >> install.py >> ---------- >> import os >> import sys >> import win32com.client as w32client >> >> shortcut_group_name = "Start Menu Dir" >> shortcut_name = "Product Name" >> shortcut_target = "http://www.microsoft.com" >> >> sh = w32client.Dispatch("WScript.**Shell") >> p = sh.SpecialFolders("**AllUsersPrograms") >> assert(os.path.isdir(p)) >> p = os.path.join(p, shortcut_group_name) >> if (not os.path.isdir(p)): >> os.makedirs(p) >> lnk = sh.CreateShortcut(os.path.**join(p, shortcut_name + ".lnk")) >> lnk.TargetPath = shortcut_target >> lnk.Save() >> >> >> > > -- Very Respectfully, Cesar Covarrubias -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Apr 6 11:10:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Apr 2012 01:10:12 +1000 Subject: [Savoynet] list settings In-Reply-To: <201204061450.q36EoL22005854@imr-ma04.mx.aol.com> References: <1333712791.7759.YahooMailNeo@web120705.mail.ne1.yahoo.com> <201204061450.q36EoL22005854@imr-ma04.mx.aol.com> Message-ID: On Sat, Apr 7, 2012 at 12:50 AM, Freed wrote: > New here.? The list is set so that ?reply? goes only to the sender, not the > list.? Is that intentional?? Most lists are set so that ?reply? goes to the > list by default.? Doesn?t look like I can change that for emails that come > to me, can I? I don't think you can change that, it's part of the list configuration. But here's the rationale as given for another list that has the same setup: If the default reply-to is the list, then private replies risk being sent to the list; but if default reply is to the single sender, the only risk is that you then have to re-send to the list. You can't un-send something once hundreds of people have seen it; you CAN re-send so that the correct people get to see it. Also, you can always use Reply-All to send to the list. I don't like this, though, as it ends up sending to the original poster and also to the list, and if multiple people start doing this, the To line starts to get unnecessarily long. However, it does work; and it's something that has no equivalent in the alternative arrangement - you can't use any default form of sending to choose to make your message more private. My personal habit is to write up my reply, then choose one of three ways to send: 1) Hit Send, and communicate only with one person 2) Replace the To: address with the list's and hit Send 3) Hit Discard because the post isn't worth sending after all. Option 2 does have some risk, of course. I've sometimes replied to a completely wrong list (mainly between the two most active lists I'm a member of, they being python-list and one about Gilbert and Sullivan operas called "Savoynet"), which is embarrassing but not a breach of privacy (both lists are archived publicly); it would be far worse to snap off a quick reply to someone that includes private details like user names and passwords, and then to find you sent it to every subscriber on the list... All in all, I prefer the current situation. ChrisA From pgiri at yahoo.com Fri Apr 6 11:21:37 2012 From: pgiri at yahoo.com (Giridhar Pemmasani) Date: Fri, 6 Apr 2012 08:21:37 -0700 (PDT) Subject: [ANN]: asyncoro: Framework for asynchronous programming with coroutines Message-ID: <1333725697.21901.YahooMailNeo@web160602.mail.bf1.yahoo.com> I posted this message earlier to the list, but realized that URLs appear broken with '.' at the end of URL. Sorry for that mistake and this duplicate! asyncoro is a framework for developing concurrent programs with asynchronous event completions and coroutines. Asynchronous completions currently implemented in asyncoro are socket I/O operations, sleep timers, (conditional) event notification and semaphores. Programs developed with asyncoro will have same logic as Python programs with synchronous sockets and threads, except for a few syntactic changes. asyncoro supports polling mechanisms epoll, kqueue, /dev/poll (and poll and select if necessary), and Windows I/O Completion Ports (IOCP) for high performance and scalability, and SSL for security. More details about asyncoro are at http://dispy.sourceforge.net/asyncoro.html and can be downloaded from https://sourceforge.net/projects/dispy/files asyncoro is used in?development of dispy (http://dispy.sourceforge.net), which is a framework for parallel execution of computations by distributing them across multiple processors on a single machine (SMP), multiple nodes in a cluster, or large clusters of nodes. The computations can be standalone programs or Python functions. Both asyncoro and dispy have been tested with Python versions 2.7 and 3.2 under Linux, OS X and Windows. Cheers, Giri -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri Apr 6 11:25:59 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Apr 2012 08:25:59 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7ef5c8$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <32576aa7-2269-430b-a412-5d8a408cb276@8g2000pbm.googlegroups.com> On Apr 6, 6:55?pm, Steven D'Aprano wrote: > On Thu, 05 Apr 2012 21:28:01 -0700, rusi wrote: > > Are there languages (other than python) in which single and double > > quotes are equivalent? > > Classic REXX, CSS, JavaScript, Lua, Prolog, XPath, YAML, Modula-2, HTML, > and (of course) English. There may be others. > > Other languages like Perl, PHP and Ruby support alternate delimiters with > slightly different semantics. > > -- > Steven Prolog: seems to be different, see http://stackoverflow.com/questions/4391435/how-to-manipulate-strings-in-prolog yaml: double seems to be like python triple, ie multi-line allowed whereas single does not allow multi-line http://yaml.org/spec/current.html#single%20quoted%20style/syntax From rustompmody at gmail.com Fri Apr 6 11:31:04 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Apr 2012 08:31:04 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7ef5c8$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 6, 7:18?pm, Grzegorz Staniak wrote: > On 06.04.2012, Steven D'Aprano wroted: > > >> Are there languages (other than python) in which single and double > >> quotes are equivalent? > > > Classic REXX, CSS, JavaScript, Lua, Prolog, XPath, YAML, Modula-2, HTML, > > and (of course) English. There may be others. > > > Other languages like Perl, PHP and Ruby support alternate delimiters with > > slightly different semantics. > > Perl, first of all, has the 'q' and 'qq' operators. As much as I'd > come to dislike Perl after I discovered Python, I miss those two. > Every time I have to quote a string full of single/double quotes, > this comes to my mind: > > ? ? q{'this' is not this, but 'that' is 'that' like 'this'} > ? ? q|'this' is not this, but 'that' is 'that' like 'this'| > ? ? q<'this' is not this, but 'that' is 'that' like 'this'> > > ... with 'qq' providing the version with inerpolation. I could > always find an arbitrary character for quoting that was _not_ present > in the string, and so, most of the time, avoid quoting altogether. > It was perhaps a bit too magical, but pruced very readable strings. Yes the q of perl is qute and qlever. Come to think of it its very sensible because it factors delimition from quoting just as the () and ' do for lisp. From ndparker at gmail.com Fri Apr 6 11:40:41 2012 From: ndparker at gmail.com (=?UTF-8?B?QW5kcsOp?= Malo) Date: Fri, 06 Apr 2012 17:40:41 +0200 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> <1365568.HPCjg9jpd0@news.perlig.de> <4f7e40f1$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3728817.39z15dpbUf@news.perlig.de> * Steven D'Aprano wrote: > On Thu, 05 Apr 2012 23:08:11 +0200, Andr? Malo wrote: > >> * Steven D'Aprano wrote: >> >>> For a 21st century programming language or data format to accept only >>> one type of quotation mark as string delimiter is rather like having a >>> 21st century automobile with a hand crank to start the engine instead >>> of an ignition. Even if there's a good reason for it (which I doubt), >>> it's still surprising. >> >> Here's a reason: KISS. > > KISS is a reason *for* allowing multiple string delimiters, not against > it. The simplicity which matters here are: > > * the user doesn't need to memorise which delimiter is allowed, and > which is forbidden, which will be different from probably 50% of > the other languages he knows; > > * the user can avoid the plague of escaping quotes inside strings > whenever he needs to embed the delimiter inside a string literal. > > This is the 21st century, not 1960, and if the language designer is > worried about the trivially small extra effort of parsing ' as well as " > then he's almost certainly putting his efforts in the wrong place. Yes, that's what you said already. My reasoning was in the part you stripped from my quote. *shrug* nd -- Treat your password like your toothbrush. Don't let anybody else use it, and get a new one every six months. -- Clifford Stoll (found in ssl_engine_pphrase.c) From rustompmody at gmail.com Fri Apr 6 11:43:55 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Apr 2012 08:43:55 -0700 (PDT) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> <1365568.HPCjg9jpd0@news.perlig.de> <4f7e40f1$0$29983$c3e8da3$5496439d@news.astraweb.com> <3728817.39z15dpbUf@news.perlig.de> Message-ID: On Apr 6, 8:40?pm, Andr? Malo wrote: > * Steven D'Aprano wrote: > > On Thu, 05 Apr 2012 23:08:11 +0200, Andr? Malo wrote: > > >> * Steven D'Aprano wrote: > > >>> For a 21st century programming language or data format to accept only > >>> one type of quotation mark as string delimiter is rather like having a > >>> 21st century automobile with a hand crank to start the engine instead > >>> of an ignition. Even if there's a good reason for it (which I doubt), > >>> it's still surprising. > > >> Here's a reason: KISS. > > > KISS is a reason *for* allowing multiple string delimiters, not against > > it. The simplicity which matters here are: > > > * the user doesn't need to memorise which delimiter is allowed, and > > ? which is forbidden, which will be different from probably 50% of > > ? the other languages he knows; > > > * the user can avoid the plague of escaping quotes inside strings > > ? whenever he needs to embed the delimiter inside a string literal. > > > This is the 21st century, not 1960, and if the language designer is > > worried about the trivially small extra effort of parsing ' as well as " > > then he's almost certainly putting his efforts in the wrong place. > > Yes, that's what you said already. My reasoning was in the part you stripped > from my quote. *shrug* Multiple symmetric quote characters breaks one of python's own zen rules: There should be one-- and preferably only one --obvious way to do it. From gstaniak at gmail.com Fri Apr 6 12:02:49 2012 From: gstaniak at gmail.com (Grzegorz Staniak) Date: Fri, 6 Apr 2012 16:02:49 +0000 (UTC) Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7de152$0$29983$c3e8da3$5496439d@news.astraweb.com> <1365568.HPCjg9jpd0@news.perlig.de> <4f7e40f1$0$29983$c3e8da3$5496439d@news.astraweb.com> <3728817.39z15dpbUf@news.perlig.de> Message-ID: On 06.04.2012, rusi wroted: >> > This is the 21st century, not 1960, and if the language designer is >> > worried about the trivially small extra effort of parsing ' as well as " >> > then he's almost certainly putting his efforts in the wrong place. >> >> Yes, that's what you said already. My reasoning was in the part you stripped >> from my quote. *shrug* > > Multiple symmetric quote characters breaks one of python's own zen > rules: > > There should be one-- and preferably only one --obvious way to do it. Then again, practicality beats purity. GS -- Grzegorz Staniak From gdamjan at gmail.com Fri Apr 6 12:30:02 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Fri, 06 Apr 2012 18:30:02 +0200 Subject: Async IO Server with Blocking DB In-Reply-To: References: Message-ID: > We are thinking about building a webservice server and considering > python event-driven servers i.e. Gevent/Tornado/ Twisted or some > combination thereof etc. > > We are having doubts about the db io part. Even with connection > pooling and cache, there is a strong chance that server will block on > db. Blocking for even few ms is bad. Libraries that support the event loop of your framework, be it Gevent, Tornado or Twisted, should yield to other work when the database connection (its socket) blocks. Now, database drivers that use C libraries are ussually a problem, unless designed to cooperate with event loops. One of those is psycopg2 which at least cooperates with Gevent. CouchDBkit (using restkit ie http) also cooperates with Gevent fine. MySQLdb does not cooperate with Gevent as far as I know, so one sollution would be to run queries through a Thread Pool (built-in in Gevent 1.0dev). Another is to use the pure python mysqlconn (mysql-connector-repackaged on pypi) with gevents monkey patching. Sqlite should be probably run in a ThreadPool too, since it depends on disk I/O which is not async in Gevent. You can readup on Gevent integration of Couchdbkit and Psycopg2 in their documentation. > can someone suggest some solutions or is async-io is not at the prime- > time yet. -- damjan From gandalf at shopzeus.com Fri Apr 6 13:28:55 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 06 Apr 2012 19:28:55 +0200 Subject: Async IO Server with Blocking DB In-Reply-To: References: Message-ID: <4F7F27D7.8000805@shopzeus.com> There is asyncmongo! http://pypi.python.org/pypi/asyncmongo/0.1.3 Although I have never tried it. It has support for async I/O for mongodb and tornadoweb. Here is a bit old article about it: http://www.dunnington.net/entry/asynchronous-mongodb-in-tornado-with-asyncmongo I have a related question. I just ran into this post, when I was wondering how to implement sessions with tornado. It is also a blocking db access, right? Say, what if I run four instances of tornado on a computer (one instance per CPU core) and load-balance requests between these instances with ngnix. It cannot be guaranteed that requests from the same user will always go to the same web server process. So the same session must somehow be accessed from multiple processes. But tornado does not have built-in session support. I have read this article about the issue: http://milancermak.posterous.com/benchmarking-tornados-sessions-0 but I found no actual code for session managers. Does anyone know a good, tested implementation of sessions for tornado? Or should I just create my own? I'm thinking about running mongodb and using it for storing sessions (plus also using it for storing application data...) Thanks Laszlo From nicholas.cole at gmail.com Fri Apr 6 13:52:41 2012 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Fri, 6 Apr 2012 18:52:41 +0100 Subject: 'string_escape' in python 3 Message-ID: In Python 2 given the following raw string: >>> s = r"Hello\x3a this is a test" the escaping could be removed by use of the following: >>> s.decode('string_escape') In Python 3, however, the only way I can see to achieve the same result is to convert into a byte stream and then back: >>> bytes(s, 'utf-8').decode('unicode_escape') This seems very ugly (and slightly 'wrong'). Is there no way to do this without using bytes? Have I missed something? Best wishes, N. From fabiofz at gmail.com Fri Apr 6 14:37:20 2012 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 6 Apr 2012 15:37:20 -0300 Subject: PyDev 2.5.0 Released Message-ID: Hi All, PyDev 2.5.0 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- Django: Project wizard now properly supports Django 1.4. Django with auto-reload: pydevd.patch_django_auto_reload() now properly patches Django 1.4 for the remote debugger. pydevd.patch_django_auto_reload() now patches the Django reload to show a console out of Eclipse so that Ctrl+C can be used. Created code template to pydevd.patch_django_auto_reload(). Interactive Console: The interactive console may be attached to the variables view (patch from Jonah Graham). See: http://pydev.org/manual_adv_interactive_console.html for details. Drag and Drop may be used to drag code from the editor to the interactive console (patch from Jonah Graham). When starting an interactive console, a link to configure the preferences is shown in the dialog. Code formatter: Multi-lines may be right-trimmed (patch from Haw-Bin Chai) -- option must be enabled in the code-formatting settings. Fixed issue where the auto code-formatting would end up formatting strings as regular code when the "format only changed lines" setting was on. Others: pydevd.settrace() template now adds the debugger to the PYTHONPATH before actually doing the settrace(). ${pydevd_file_location} and ${pydevd_dir_location} variables were added to the templates. The style of generated docstrings (EpyDoc or Sphinx) may be chosen in the preferences (patch from Paul Collins). Some performance improvements were done on the parser. Aside from the features above, lots of bugs were fixed in this release (including a deadlock in a race condition). 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From shi at somewhere.be Fri Apr 6 14:43:35 2012 From: shi at somewhere.be (shi) Date: Fri, 06 Apr 2012 20:43:35 +0200 Subject: Reading Live Output from a Subprocess References: <24839857.480.1333695469128.JavaMail.geo-discussion-forums@ynuu20> Message-ID: Maybe this can help you? http://technogems.blogspot.com/2012/01/capture-colored-console-output-in.html From bunslow at gmail.com Fri Apr 6 15:21:51 2012 From: bunslow at gmail.com (Dubslow) Date: Fri, 6 Apr 2012 12:21:51 -0700 (PDT) Subject: Reading Live Output from a Subprocess In-Reply-To: References: <24839857.480.1333695469128.JavaMail.geo-discussion-forums@ynuu20> Message-ID: <11463815.443.1333740111426.JavaMail.geo-discussion-forums@yngr3> On Friday, April 6, 2012 3:37:10 AM UTC-5, Nobody wrote: > In all probability, this is because the child process (pypy) is > buffering its stdout, meaning that the data doesn't get passed to the OS > until either the buffer is full or the process terminates. If it doesn't > get passed to the OS, then the OS can't pass it on to whatever is on the > read end of the pipe. In that situation, there is nothing that the parent > process can do about it. > It's just a short test script written in python, so I have no idea how to even control the buffering (and even if I did, I still can't modify the subprocess I need to use in my script). What confuses me then is why Perl is able to get around this just fine without faking a terminal or similar stuff. (And also, this needs to work in Windows as well.) For the record, here's the test script: ###################################### #!/usr/bin/python import time, sys try: total = int(sys.argv[1]) except IndexError: total = 10 for i in range(total): print('This is iteration', i) time.sleep(1) print('Done. Exiting!') sys.exit(0) ###################################### > If it does, that would confirm the buffering hypothesis. Pexpect causes > the child process' stdout to be associated with a pty. > > The "stdout" stream created by the C library (libc) is initially > line-buffered if it is associated with a tty (according to the isatty() > function) and fully-buffered otherwise. The program can change the > buffering with e.g. setvbuf(), or it can explicitly fflush(stdout) after > each line, but this is up to the program, and is not something which can > be controlled externally (short of "hacking" the child process with > techniques such as ptrace() or LD_PRELOAD). > > While the libc behaviour is occasionally inconvenient, it is mandated by > the C standard (7.19.3p7): > > As initially opened, the standard error stream is not fully > buffered; the standard input and standard output streams are > fully buffered if and only if the stream can be determined not > to refer to an interactive device. > > It's up to individual programs to force line-buffered output where > appropriate (e.g. GNU grep has the --line-buffered switch, GNU sed has the > -u switch, etc). Well, they shouldn't assume they can determine what's interactive or not *grumble*. I take it then that setting Shell=True will not be fake enough for catching output live? On Friday, April 6, 2012 1:43:35 PM UTC-5, shi wrote: > Maybe this can help you? > http://technogems.blogspot.com/2012/01/capture-colored-console-output-in.html Maybe, but even if it does work as expected, it's a _lot_ of pain to go through, with separate threads, etc.. just to get something so blasted simple to work. It certainly isn't obvious. Thanks for the link though. From vinay_sajip at yahoo.co.uk Fri Apr 6 16:06:22 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 6 Apr 2012 13:06:22 -0700 (PDT) Subject: Possible change to logging.handlers.SysLogHandler Message-ID: There is a problem with the way logging.handlers.SysLogHandler works when presented with Unicode messages. According to RFC 5424, Unicode is supposed to be sent encoded as UTF-8 and preceded by a BOM. However, the current handler implementation puts the BOM at the start of the formatted message, and this is wrong in scenarios where you want to put some additional structured data in front of the unstructured message part; the BOM is supposed to go after the structured part (which, therefore, has to be ASCII) and before the unstructured part. In that scenario, the handler's current behaviour does not strictly conform to RFC 5424. The issue is described in [1]. The BOM was originally added / position changed in response to [2] and [3]. It is not possible to achieve conformance with the current implementation of the handler, unless you subclass the handler and override the whole emit() method. This is not ideal. For 3.3, I will refactor the implementation to expose a method which creates the byte string which is sent over the wire to the syslog daemon. This method can then be overridden for specific use cases where needed. However, for 2.7 and 3.2, removing the BOM insertion would bring the implementation into conformance to the RFC, though the entire message would have to be regarded as just a set of octets. A Unicode message would still be encoded using UTF-8, but the BOM would be left out. I am thinking of removing the BOM insertion in 2.7 and 3.2 - although it is a change in behaviour, the current behaviour does seem broken with regard to RFC 5424 conformance. However, as some might disagree with that assessment and view it as a backwards-incompatible behaviour change, I thought I should post this to get some opinions about whether this change is viewed as objectionable. Regards, Vinay Sajip [1] http://bugs.python.org/issue14452 [2] http://bugs.python.org/issue7077 [3] http://bugs.python.org/issue8795 From vinay_sajip at yahoo.co.uk Fri Apr 6 16:14:40 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 6 Apr 2012 13:14:40 -0700 (PDT) Subject: Reading Live Output from a Subprocess References: <24839857.480.1333695469128.JavaMail.geo-discussion-forums@ynuu20> Message-ID: <60b8a238-1fea-437f-8087-2ffb96feb969@x17g2000vba.googlegroups.com> On Apr 6, 7:57?am, buns... at gmail.com wrote: > I've heard that the Pexpect module works wonders, but the problem is that relies on pty which is available in Unix only. Additionally, because I want this script to be usable by others, any solution should be in the standard library, which means I'd have to copy the Pexpect code into my script to use it. > > Is there any such solution in the Python 3 Standard Library, and if not, how much of a thorn is this? > > "There should be one-- and preferably only one --obvious way to do it." > Unfortunately, this is one case where the above is true for Perl but not Python. Such an example in Perl is > > open(PROG, "command |") or die "Couldn't start prog!"; > ? ? ? ? while () { > ? ? ? ? ? ? ? ? ?print "$_"; } > > (Note that I do not know Perl and do not have any intentions to learn it; the above comes from the script I was previously copying and extending, but I imagine (due to its simplicity) that it's a common Perl idiom. Note however, that the above does fail if the program re-prints output to the same line, as many long-running C programs do. Preferably this would also be caught in a Python solution.) > > If there is a general consensus that this is a problem for lots of people, I might consider writing a PEP. > > Of course, my highest priority is solving the blasted problem, which is holding up my script at the moment. (I can work around this by redirecting the program to a tmp file and reading that, but that would be such a perilous and ugly kludge that I would like to avoid it if at all possible.) Try the sarge package [1], with documentation at [2] and source code at [3]. It's intended for your use case, works with both Python 2.x and 3.x, and is tested on Linux, OS X and Windows. Disclosure: I'm the maintainer. Regards, Vinay Sajip [1] http://pypi.python.org/pypi/sarge/0.1 [2] http://sarge.readthedocs.org/en/latest/ [3] https://bitbucket.org/vinay.sajip/sarge/ From martinofmoscow at gmail.com Fri Apr 6 16:41:23 2012 From: martinofmoscow at gmail.com (Martin Jones) Date: Fri, 6 Apr 2012 13:41:23 -0700 (PDT) Subject: Learning new APIs/classes (beginner question) Message-ID: In a nutshell: My question is: how do experienced coders learn about external/third-party classes/APIs? I'm teaching myself Python through a combination of Hetland's 'Beginning Python', various online tutorials and some past experience coding ASP/VBScript. To start to learn Python I've set myself the task of coding a viewer/editor for Google Contacts and Google Calendar, mainly because I've been experiencing some synchronisation anomalies lately. This has so far entailed getting into Google's Contacts API. Although they give some examples, my searches haven't been able to pull up anything approaching comprehensive documentation on each class/method. Can anyone experienced advise on how they would usually go about learning to use third party APIs/classes like these? With thanks, Martin From tjreedy at udel.edu Fri Apr 6 16:57:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Apr 2012 16:57:22 -0400 Subject: 'string_escape' in python 3 In-Reply-To: References: Message-ID: On 4/6/2012 1:52 PM, Nicholas Cole wrote: > In Python 2 given the following raw string: > >>>> s = r"Hello\x3a this is a test" > > the escaping could be removed by use of the following: > >>>> s.decode('string_escape') > In Python 3, however, the only way I can see to achieve the same > result is to convert into a byte stream and then back: > >>>> bytes(s, 'utf-8').decode('unicode_escape') > > > This seems very ugly (and slightly 'wrong'). Is there no way to do > this without using bytes? Have I missed something? >>> eval("'"+s+"'") 'Hello: this is a test' -- Terry Jan Reedy From emile at fenx.com Fri Apr 6 17:37:04 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 06 Apr 2012 14:37:04 -0700 Subject: Learning new APIs/classes (beginner question) In-Reply-To: References: Message-ID: On 4/6/2012 1:41 PM Martin Jones said... > In a nutshell: My question is: how do experienced coders learn about > external/third-party classes/APIs? > > I'm teaching myself Python through a combination of Hetland's > 'Beginning > Python', various online tutorials and some past experience coding > ASP/VBScript. One resource for learning at least the bulk of python's interal library is http://effbot/librarybook -- of course, not much help for third party libraries... Emile From usenet at solar-empire.de Fri Apr 6 18:03:21 2012 From: usenet at solar-empire.de (Marc Christiansen) Date: Sat, 7 Apr 2012 00:03:21 +0200 Subject: numpy.genfromtxt with Python3 - howto References: <4f7eaa61$0$3119$ba620e4c@news.skynet.be> Message-ID: <9q5459-p1i.ln1@pluto.solar-empire.de> Helmut Jarausch wrote: > I have a machine with a non-UTF8 local. > I can't figure out how to make numpy.genfromtxt work [...] > #!/usr/bin/python3 > import numpy as np > import io > import sys > > inpstream = io.open(sys.stdin.fileno(), "r", encoding='latin1') > > data = np.genfromtxt(inpstream) Hi Helmut, numpy.genfromtxt wants bytes, not str. Use inpstream = io.open(sys.stdin.fileno(), "rb") or simply inpstream = sys.stdin.buffer Ciao Marc From cs at zip.com.au Fri Apr 6 18:05:06 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 7 Apr 2012 08:05:06 +1000 Subject: 'string_escape' in python 3 In-Reply-To: References: Message-ID: <20120406220506.GA11242@cskk.homeip.net> On 06Apr2012 16:57, Terry Reedy wrote: | On 4/6/2012 1:52 PM, Nicholas Cole wrote: | > In Python 2 given the following raw string: | > | >>>> s = r"Hello\x3a this is a test" | > | > the escaping could be removed by use of the following: | > | >>>> s.decode('string_escape') | | > In Python 3, however, the only way I can see to achieve the same | > result is to convert into a byte stream and then back: | > | >>>> bytes(s, 'utf-8').decode('unicode_escape') | > | > This seems very ugly (and slightly 'wrong'). Is there no way to do | > this without using bytes? Have I missed something? | | >>> eval("'"+s+"'") | 'Hello: this is a test' https://xkcd.com/327/ -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Every \item command in item_list must have an optional argument. - Leslie Lamport, LaTeX From tjreedy at udel.edu Fri Apr 6 18:19:04 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Apr 2012 18:19:04 -0400 Subject: 'string_escape' in python 3 In-Reply-To: <20120406220506.GA11242@cskk.homeip.net> References: <20120406220506.GA11242@cskk.homeip.net> Message-ID: <4F7F6BD8.9020307@udel.edu> On 4/6/2012 6:05 PM, Cameron Simpson wrote: > On 06Apr2012 16:57, Terry Reedy wrote: > | On 4/6/2012 1:52 PM, Nicholas Cole wrote: > |>>>> bytes(s, 'utf-8').decode('unicode_escape') > |> > |> This seems very ugly (and slightly 'wrong'). Is there no way to do > |> this without using bytes? Have I missed something? > | > |>>> eval("'"+s+"'") > | 'Hello: this is a test' > > https://xkcd.com/327/ I actually thought of that, but assumed that adding enclosing quotes would be safe (or that the OP trusted the string). After sending, I realized that if Nasty Hacker guessed that the string would be so augmented, then it would not be safe. This or above with literal_eval is. >>> ast.literal_eval("'{}'".format('\x3a')) ':' --- Terry Jan Reedy From ian.g.kelly at gmail.com Fri Apr 6 19:04:55 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Apr 2012 17:04:55 -0600 Subject: 'string_escape' in python 3 In-Reply-To: <4F7F6BD8.9020307@udel.edu> References: <20120406220506.GA11242@cskk.homeip.net> <4F7F6BD8.9020307@udel.edu> Message-ID: On Fri, Apr 6, 2012 at 4:19 PM, Terry Reedy wrote: > I actually thought of that, but assumed that adding enclosing quotes would > be safe (or that the OP trusted the string). After sending, I realized that > if Nasty Hacker guessed that the string would be so augmented, then it would > not be safe. This or above with literal_eval is. > >>>> ast.literal_eval("'{}'".format('\x3a')) > ':' That version is safe from injection, but it will still choke on things that string_escape can process successfully: >>> s = "Isn't it wonderful?" >>> s.decode('string_escape') "Isn't it wonderful?" >>> ast.literal_eval("'" + s + "'") Traceback (most recent call last): File "", line 1, in File "c:\python27\lib\ast.py", line 49, in literal_eval node_or_string = parse(node_or_string, mode='eval') File "c:\python27\lib\ast.py", line 37, in parse return compile(expr, filename, mode, PyCF_ONLY_AST) File "", line 1 'Isn't it wonderful?' ^ SyntaxError: invalid syntax Of course you could use different string delimiters, but then you just fail on different strings. From ian.g.kelly at gmail.com Fri Apr 6 19:10:17 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Apr 2012 17:10:17 -0600 Subject: 'string_escape' in python 3 In-Reply-To: References: Message-ID: On Fri, Apr 6, 2012 at 11:52 AM, Nicholas Cole wrote: > In Python 2 given the following raw string: > >>>> s = r"Hello\x3a this is a test" > > the escaping could be removed by use of the following: > >>>> s.decode('string_escape') > > In Python 3, however, the only way I can see to achieve the same > result is to convert into a byte stream and then back: > >>>> bytes(s, 'utf-8').decode('unicode_escape') > > > This seems very ugly (and slightly 'wrong'). ?Is there no way to do > this without using bytes? ?Have I missed something? >>> import codecs >>> codecs.getdecoder('unicode_escape')(s)[0] 'Hello: this is a test' Cheers, Ian From brownbar at gmail.com Fri Apr 6 20:48:41 2012 From: brownbar at gmail.com (Barry W Brown) Date: Fri, 6 Apr 2012 17:48:41 -0700 (PDT) Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <25321164.1622.1333759721375.JavaMail.geo-discussion-forums@vbtv42> On Thursday, April 5, 2012 11:28:01 PM UTC-5, rusi wrote: > On Apr 5, 4:06?pm, Duncan Booth wrote: > > Steven D'Aprano wrote: > > > JSON expects double-quote marks, not single: > > > ? ? v = json.loads("{'test':'test'}") ?fails > > > ? ? v = json.loads('{"test":"test"}') ?succeeds > > > > You mean JSON expects a string with valid JSON? > > Quelle surprise. > > Are there languages (other than python) in which single and double > quotes are equivalent? Fortran 90 and more recent versions. > > [No I dont claim to know all the languages out there, just that I dont > know any other language which allows single and double quotes to be > interconvertible like python does] On Thursday, April 5, 2012 11:28:01 PM UTC-5, rusi wrote: > On Apr 5, 4:06?pm, Duncan Booth wrote: > > Steven D'Aprano wrote: > > > JSON expects double-quote marks, not single: > > > ? ? v = json.loads("{'test':'test'}") ?fails > > > ? ? v = json.loads('{"test":"test"}') ?succeeds > > > > You mean JSON expects a string with valid JSON? > > Quelle surprise. > > Are there languages (other than python) in which single and double > quotes are equivalent? > > [No I dont claim to know all the languages out there, just that I dont > know any other language which allows single and double quotes to be > interconvertible like python does] From steve+comp.lang.python at pearwood.info Fri Apr 6 20:52:56 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2012 00:52:56 GMT Subject: Learning new APIs/classes (beginner question) References: Message-ID: <4f7f8fe8$0$29983$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Apr 2012 13:41:23 -0700, Martin Jones wrote: > In a nutshell: My question is: how do experienced coders learn about > external/third-party classes/APIs? Does it have a tutorial? Do it. Does it have a manual, a wiki, FAQs, or other documentation? Read them. If all else fails, what does help(external_library) say? Are there examples you can follow? Do so. Does it have a mailing list to ask for help? Subscribe to it. Google for examples and sample code. If all else fails, read the source code if it is available. Otherwise find another library. If you can't do that, then you're stuck with learning by trial and error. Which is to say, mostly by error, which is a trial. > I'm teaching myself Python through a combination of Hetland's 'Beginning > Python', various online tutorials and some past experience coding > ASP/VBScript. To start to learn Python I've set myself the task of > coding a viewer/editor for Google Contacts and Google Calendar, mainly > because I've been experiencing some synchronisation anomalies lately. > This has so far entailed getting into Google's Contacts API. > > Although they give some examples, my searches haven't been able to > pull up anything approaching comprehensive documentation on each > class/method. Sounds like this library is documented the same way most third party libraries are: as an afterthought, by somebody who is so familiar with the software that he cannot imagine why anyone might actually need documentation. I feel your pain. -- Steven From kmedcalf at dessus.com Fri Apr 6 22:07:40 2012 From: kmedcalf at dessus.com (Keith Medcalf) Date: Sat, 07 Apr 2012 02:07:40 GMT Subject: xlrd 0.7.6 released! References: <4F7AA10B.6020907@simplistix.co.uk> <4F7AA803.1020808@simplistix.co.uk> <4F7BF72B.7080807@simplistix.co.uk> Message-ID: Karim wrote in news:mailman.1309.1333529851.3037.python-list at python.org: > This release manage the '.xlsx' format? http://packages.python.org/openpyxl/ From skippy.hammond at gmail.com Fri Apr 6 22:15:22 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sat, 07 Apr 2012 12:15:22 +1000 Subject: Generating custom Windows installers In-Reply-To: References: <2661805.383.1333653792803.JavaMail.geo-discussion-forums@ynuu12> <4F7E6627.1060900@gmail.com> Message-ID: <4F7FA33A.7040706@gmail.com> On 7/04/2012 12:57 AM, Cesar Covarrubias wrote: > I'm still getting my feet wet on the Windows side of things with Python, > so I apologize for the noobish question. > > If i am reading the create_link.py example correctly, that is created > when the application itself is invoked, not during installation. Is that > correct? If it is, how would I be able to invoke that when generating > the MSI so that the installer creates the shortcut? Right - I think I misunderstood your question. If you can't arrange for install.py to run then what I suggested isn't going to help that. Note however that bdist_msi really isn't targeted at creating stand-alone installations, but instead at installing Python extension modules. I'd recommend using cx_Freeze to create the app, but looking further afield to create the installer for the app (eg, Inno, NSIS, WiX, etc) Mark > > Cesar > > On Thu, Apr 5, 2012 at 8:42 PM, Mark Hammond > wrote: > > Seeing you are relying on win32com, you might as well add the links > directly rather than via the intermediate WScript.shell object. > Look in win32comext\shell\demos\__create_link.py for an example of > how to create shortcuts directly. > > HTH, > > Mark > > On 6/04/2012 5:23 AM, cesar.covarrubias at gmail.com > wrote: > > Hello, > > I am working on creating an installer of a Python 3.2 > application that we programmed. The end goal is to create an > installer in which we can specify the install path, and create > shortcuts in the Start Menu and Desktop. Ideally, we would like > to give the users the option to create the Desktop or Start Menu > shortcuts. > > I was able to create a .msi file with the setup.py and > install.py files below. This allowed me to specify the custom > default path but not create the shortcut in the Start Menu. > > Can anyone help me figure out what I'm missing? > > > setup.py > -------- > > from cx_Freeze import setup, Executable > import sys > > productName = "ProductName" > if 'bdist_msi' in sys.argv: > sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' + > productName] > sys.argv += ['--install-script', 'install.py'] > > exe = Executable( > script="main.py", > base="Win32GUI", > targetName="Product.exe" > ) > setup( > name="Product.exe", > version="1.0", > author="Me", > description="Copyright 2012", > executables=[exe], > scripts=[ > 'install.py' > ] > ) > ------------------------------__----------- > > install.py > ---------- > import os > import sys > import win32com.client as w32client > > shortcut_group_name = "Start Menu Dir" > shortcut_name = "Product Name" > shortcut_target = "http://www.microsoft.com" > > sh = w32client.Dispatch("WScript.__Shell") > p = sh.SpecialFolders("__AllUsersPrograms") > assert(os.path.isdir(p)) > p = os.path.join(p, shortcut_group_name) > if (not os.path.isdir(p)): > os.makedirs(p) > lnk = sh.CreateShortcut(os.path.__join(p, shortcut_name + ".lnk")) > lnk.TargetPath = shortcut_target > lnk.Save() > > > > > > > > -- > Very Respectfully, > Cesar Covarrubias > > > From kliateni at gmail.com Fri Apr 6 22:27:07 2012 From: kliateni at gmail.com (Karim) Date: Sat, 07 Apr 2012 04:27:07 +0200 Subject: xlrd 0.7.6 released! In-Reply-To: References: <4F7AA10B.6020907@simplistix.co.uk> <4F7AA803.1020808@simplistix.co.uk> <4F7BF72B.7080807@simplistix.co.uk> Message-ID: <4F7FA5FB.7060007@gmail.com> Le 07/04/2012 04:07, Keith Medcalf a ?crit : > Karim wrote in > news:mailman.1309.1333529851.3037.python-list at python.org: > >> This release manage the '.xlsx' format? > http://packages.python.org/openpyxl/ > Ah Keith, I just check this is only for xlsx format so I will make 2 code branches so I don't have to modify the xlrd one for xls binary file. I will use both in the same program. Many thanks Cheers Karim From kmedcalf at dessus.com Fri Apr 6 22:35:09 2012 From: kmedcalf at dessus.com (Keith Medcalf) Date: Sat, 07 Apr 2012 02:35:09 GMT Subject: Cannot connect to IMAP server in Python 3.2 References: <4f7d2475$0$11113$c3e8da3@news.astraweb.com> <3ceec070-e710-4e0e-9cb6-60895397c991@pg2g2000pbb.googlegroups.com> <4f7d453e$0$11113$c3e8da3@news.astraweb.com> <4f7d8d09$0$29983$c3e8da3$5496439d@news.astraweb.com> <4f7d8f2f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve Howell wrote in news:ae774035-9db0-469d-aa2a- 02f2d25ff7ce at qg3g2000pbc.googlegroups.com: > Once you are able to import ssl, you should be able to use IMAP4_SSL, > but that still doesn't entirely explain to me why you got a timeout > error with plain IMAP4 and the proper port. (I would have expected a > failure, but of a different kind.) Connecting to the SSL socket requires that one initiate the TLS handshake forthwith. Establishing a connection to an "I expect SSL from the get- go" using a protocol that speaks "I am a normal unencrypted socket but you can initiate TLS using the starttls command" is not the same thing. In other words, you are violating the requirements of the protocol, and you are timing out. This is because the first protocol step in a standard connection is to wait for the plain-text greeting, where the first step in connecting to the SSL socket is to do a TLS dance, then initiate the IMAP protocol by sending the greeting. If you connect with a non-SSL initiator to an SSL endpoint, you will get a timeout. If you connect with an SSL initiator to a non-SSL endpoint, you will timeout. It is not the connection that is timing out, it is the protocol. > I'd still be curious to see what happens when you try this: > > import socket, imaplib > your_host_name = # ... > socket.create_connection((your_host_name, imaplib.IMAP4_SSL_PORT)) This will, of course, work just fine. You will not see a +Hello however until you have completed the TLS negotiation. From research at johnohagan.com Fri Apr 6 22:56:52 2012 From: research at johnohagan.com (John O'Hagan) Date: Sat, 7 Apr 2012 12:56:52 +1000 Subject: Reading Live Output from a Subprocess In-Reply-To: <11463815.443.1333740111426.JavaMail.geo-discussion-forums@yngr3> References: <24839857.480.1333695469128.JavaMail.geo-discussion-forums@ynuu20> <11463815.443.1333740111426.JavaMail.geo-discussion-forums@yngr3> Message-ID: <20120407125652.b40e6c4eeed038c676ce8e9a@johnohagan.com> On Fri, 6 Apr 2012 12:21:51 -0700 (PDT) Dubslow wrote: > On Friday, April 6, 2012 3:37:10 AM UTC-5, Nobody wrote: > > > In all probability, this is because the child process (pypy) is > > buffering its stdout, meaning that the data doesn't get passed to the OS > > until either the buffer is full or the process terminates. If it doesn't > > get passed to the OS, then the OS can't pass it on to whatever is on the > > read end of the pipe. In that situation, there is nothing that the parent > > process can do about it. > > > It's just a short test script written in python, so I have no idea how to > even control the buffering (and even if I did, I still can't modify the > subprocess I need to use in my script). What confuses me then is why Perl is > able to get around this just fine without faking a terminal or similar stuff. > (And also, this needs to work in Windows as well.) For the record, here's the > test script: > ###################################### > #!/usr/bin/python > > import time, sys > try: > total = int(sys.argv[1]) > except IndexError: > total = 10 > > for i in range(total): > print('This is iteration', i) > time.sleep(1) > > print('Done. Exiting!') > sys.exit(0) > ###################################### > I agree that this kind of thing (IO) can seem unduly difficult to find out how to do at first. To get your test script working, you just need to flush stdout from there; add: sys.stdout.flush() to your for loop above. However, if there is a real process you need to use which you "can't modify", then it seems you'll have to use one of the more complex solutions offered here. Regards, John From k.sahithi2862 at gmail.com Sat Apr 7 01:17:18 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Fri, 6 Apr 2012 22:17:18 -0700 (PDT) Subject: EXCLUSIVE & RARE HOT PICS Message-ID: TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR ONLY HOT GUYS SEE THIS VIMALA RAMAN LATEST HOT STILLS http://hotactress-kalyani.blogspot.com/2012/03/vimalaraman-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/09/priyamani-hot.html ANUSHKA HOT ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/anushka-hot.html KAJAL AGARWAL LATEST HOT WITHOUT TOP http://hotactress-kalyani.blogspot.in/2011/08/kajal-agarwal-hot-photos.html AMISHA PATEL LATEST HOT STILLS http://hotactress-kalyani.blogspot.in/2011/08/amisha-patel-hot.html KATRINA KAIF HOT SPICY STILLS http://hotactress-kalyani.blogspot.in/2011/08/katrina-kaif-hot.html NEERU BAJWA LATEST SPICY STILLS http://hotactress-kalyani.blogspot.in/2011/12/neeru-bajwa-hot.html PRIYANKA TIWARI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/priyanka-tiwari-hot.html SAMANTHA LATEST HOT STILLS http://hotactress-kalyani.blogspot.in/2011/09/samantha-hot.html DEEKSHASETH LATEST ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/09/deeksha-seth-hot.html PAYAL GHOSH HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/payal-ghosh-hot.html SIDDI MAMRE HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2012/02/siddhi-mamre-hot.html SHEENA SHAHABADI LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2012/02/sheena-shahabadi-hot.html LATEST HOT KATRINA KAIF PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/katrina-kaif-hot.html ANUSHKA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/anushka-hot.html KAJAL AGARWAL HOT SAREE STILLS http://hotactress-kalyani.blogspot.in/2011/11/kajal-agarwal-hot-in-saree.html RAGINI DWIVEDI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/ragini-dwivedi.html PARVATHI MELTON LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/parvathi-melton-hot.html SARAH JANE DIAS HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/sarah-jane-dias-hot.html TAMANNA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/tamanna-hot.html PARUL HOT PHOTO STILLS http://hotactress-kalyani.blogspot.in/2011/12/parul-hot.html ADITI AGARWAL NEW ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/12/aditi-agarwal-hot.html POONAM KAUR HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/11/poonam-kaur-hot.html AMISHA PATEL LATEST HOT BIKINI STILLS http://hotactress-kalyani.blogspot.in/2011/08/amisha-patel-hot.html { ALL LATEST MOVIE STILLS} KAJAL BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/kajal-agarwal-in-business-man.html SONAM KAPOOR LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sonam-kapoor-maxim-photoshoot-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2012/01/ritu-kaur-stills.html SWAPNA SUNDARI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/swapna-sundari-movie-stills.html SEVAKUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sevakudu-movie-stills.html. SRIKANTH DEVARA MOVIE GALLERY http://actressgallery-kalyani.blogspot.in/2011/12/devaraya-movie-stills.html KULLUMANALI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kullu-manali-movie-stills.html BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/businessman-movie-stills.html HOT ACTRESS BIKINI STILLS IN 2012 CALENDAR http://actressgallery-kalyani.blogspot.in/2011/12/2012-actress-calendar-wallpapers.html KSHETHRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kshethram-movie-stills.html SAMANTHA SOUTHSCOPE HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/12/samantha-at-south-scope-magazine.html BODYGAURD LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/bodyguard-telugu-movie-stills_14.html DEEPIKA PADUKONE SPICY WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/deepika-padukone.html KATRINA KAIF LATEST HOT WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/katrina-kaif-wallpapers.html NIPPU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/nippu-movie-stills.html LOVE FAILURE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/love-failure-movie-stills.html VIKRAM VEEDINTHE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/veedinthe-movie-stills.html 4FRIENDS MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/4-friends-movie-stills.html NANDEESWARUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/nandeeswarudu-movie-stills.html HARI PRIYA HOT PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/12/haripariya-actress.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.in/2011/11/shruti-hassan-in-3-movie.html PANJA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2011/11/panja-movie-stills.html URIMI LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/urimi-movie-stills.html ROUDRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/roudram-movie-stills.html SIMHAPUTHRUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/simhaputhrudu-movie-stills.html SOLO MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/solo-movie-stills.html BEZAWADA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/bezawada-movie-stills.html RAJANNA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/rajanna-movie-stills.html\ POOLARANGADU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/poolarangadu-movie-stills.html PRIYUDU HOT ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/11/priyudu-movie-stills.html ADHINAYAKUDU LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/adhinayakudu-movie-stills.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/katrina-kaif.html AISHWARYA RAI HOT HQ PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/09/aishwarya-rai.html ASIN HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.in/2011/09/asin.html HANSIKA MATOWNI LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2011/09/hansika-motwani.html KAJAL AGARWAL HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/kajal-agarwal.html SNEHA HOT GOA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/09/goa-movie-stills.html From nobody at nowhere.com Sat Apr 7 01:36:14 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 07 Apr 2012 06:36:14 +0100 Subject: escaping/encoding/formatting in python References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> <0e358c78-fb71-4b28-a737-f9e6468cf2bc@a8g2000pbe.googlegroups.com> <45ea3f8b-1f78-48aa-9ef0-3004d6ef8721@js1g2000pbc.googlegroups.com> Message-ID: On Fri, 06 Apr 2012 06:22:13 -0700, rusi wrote: > But are not such cases rare? They exist, therefore they have to be supported somehow. > For example code such as: > print '"' > print str(something) > print '"' > > could better be written as > print '"%s"' % str(something) Not if the text between the delimiters is large. Consider: print 'static const char * const data[] = {' for line in infile: print '\t"%s",' % line.rstrip() print '};' Versus: text = '\n'.join('\t"%s",' % line.rstrip() for line in infile) print 'static const char * const data[] = {\n%s\n};' % text C++11 solves the problem to an extent by providing raw strings with user-defined delimiters (up to 16 printable characters excluding parentheses and backslash), e.g.: R"delim(quote: " backslash: \ rparen: ))delim" evaluates to the string: quote: " backslash: \ rparen: ) The only sequence which cannot appear in such a string is )delim" (i.e. a right parenthesis followed by the chosen delimiter string followed by a double quote). The delimiter can be chosen either by analysing the string or by choosing something a string at random and relying upon a collision being statistically improbable. From frank at chagford.com Sat Apr 7 01:58:47 2012 From: frank at chagford.com (Frank Millman) Date: Sat, 7 Apr 2012 07:58:47 +0200 Subject: Reading Live Output from a Subprocess References: <24839857.480.1333695469128.JavaMail.geo-discussion-forums@ynuu20> <11463815.443.1333740111426.JavaMail.geo-discussion-forums@yngr3> Message-ID: "Dubslow" wrote: > It's just a short test script written in python, so I have no idea how to > even control the buffering (and even if I did, I still can't modify the > subprocess I need to use in my script). What confuses me then is why Perl > is able to get around this just fine without faking a terminal or similar > stuff. (And also, this needs to work in Windows as well.) For the record, > here's the test script: > ###################################### > #!/usr/bin/python > > import time, sys > try: > total = int(sys.argv[1]) > except IndexError: > total = 10 > > for i in range(total): > print('This is iteration', i) > time.sleep(1) > > print('Done. Exiting!') > sys.exit(0) > ###################################### > I am probably missing something, but this works for me - sub_proc1.py -------------- from time import sleep for i in range(5): print(i) sleep(1) sub_proc2.py -------------- import subprocess as sub proc = sub.Popen(["python", "sub_proc1.py"]) x, y = proc.communicate() Running sub_proc1 gives the obvious output - the digits 0 to 4 displayed with delays of 1 second. Running sub_proc2 gives exactly the same output. This is using python 3.2.2 on Windows Server 2003. Frank Millman From nobody at nowhere.com Sat Apr 7 02:08:57 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 07 Apr 2012 07:08:57 +0100 Subject: Reading Live Output from a Subprocess References: <24839857.480.1333695469128.JavaMail.geo-discussion-forums@ynuu20> <11463815.443.1333740111426.JavaMail.geo-discussion-forums@yngr3> Message-ID: On Fri, 06 Apr 2012 12:21:51 -0700, Dubslow wrote: > It's just a short test script written in python, so I have no idea how > to even control the buffering In Python, you can set the buffering when opening a file via the third argument to the open() function, but you can't change a stream's buffering once it has been created. Although Python's file objects are built on the C stdio streams, they don't provide an equivalent to setvbuf(). On Linux, you could use e.g.: sys.stdout = open('/dev/stdout', 'w', 1) Other than that, if you want behaviour equivalent to line buffering, call sys.stdout.flush() after each print statement. > (and even if I did, I still can't modify the subprocess I need to use in > my script). In which case, discussion of how to make Python scripts use line-buffered output is beside the point. > What confuses me then is why Perl is able to get around this just fine > without faking a terminal or similar stuff. It isn't. If a program sends its output to the OS in blocks, anything which reads that output gets it in blocks. The language doesn't matter; writing the parent program in assembler still wouldn't help. > I take it then that setting Shell=True will not be fake enough for > catching output live? No. It just invokes the command via /bin/sh or cmd.exe. It doesn't affect how the process' standard descriptors are set up. On Unix, the only real use for shell=True is if you have a "canned" shell command, e.g. from a file, and you need to execute it. In that situation, args should be a string rather than a list. And you should never try to construct such a string dynamically in order to pass arguments; that's an injection attack waiting to happen. From alec.taylor6 at gmail.com Sat Apr 7 03:32:10 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 7 Apr 2012 17:32:10 +1000 Subject: PEP 274 Message-ID: Has been withdrawn... and implemented http://www.python.org/dev/peps/pep-0274/ From workhome161991 at gmail.com Sat Apr 7 04:19:41 2012 From: workhome161991 at gmail.com (priya dharshini) Date: Sat, 7 Apr 2012 01:19:41 -0700 (PDT) Subject: welcome to online job Message-ID: <74c3589c-376d-4bcf-b854-27e1d72dcd64@oo9g2000pbc.googlegroups.com> Earn from home itself http://123maza.com/46/rose759/ From martinofmoscow at gmail.com Sat Apr 7 04:36:12 2012 From: martinofmoscow at gmail.com (Martin Jones) Date: Sat, 7 Apr 2012 01:36:12 -0700 (PDT) Subject: Learning new APIs/classes (beginner question) References: <4f7f8fe8$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 7, 1:52?am, Steven D'Aprano wrote: > Sounds like this library is documented the same way most third party > libraries are: as an afterthought, by somebody who is so familiar with > the software that he cannot imagine why anyone might actually need > documentation. > > I feel your pain. > Thanks Steven, I suspected this might be the case, but wasn't sure if I was missing something obvious. Maybe I'll start on a different project using better-documented or just the build-in libraries. Many thanks, Martin. From mohan at cegonsoft.com Sat Apr 7 05:21:55 2012 From: mohan at cegonsoft.com (Mohan kumar) Date: Sat, 7 Apr 2012 02:21:55 -0700 (PDT) Subject: Python Training Message-ID: <207018ff-234a-4280-a7f5-e5074c8f24ae@z5g2000pbu.googlegroups.com> Hi, We are an IT Training company located in Bangalore, Chennai and Coimbatore. We provide Python training with Placement Assistance. For more details, email to mohan at cgonsoft.com From mohan at cegonsoft.com Sat Apr 7 05:22:40 2012 From: mohan at cegonsoft.com (Mohan kumar) Date: Sat, 7 Apr 2012 02:22:40 -0700 (PDT) Subject: Python Training References: <207018ff-234a-4280-a7f5-e5074c8f24ae@z5g2000pbu.googlegroups.com> Message-ID: <9cb6ad51-cc9f-4384-b5ae-20659f43b785@px4g2000pbc.googlegroups.com> On Apr 7, 2:21?pm, Mohan kumar wrote: > Hi, > We are an IT Training company located in Bangalore, Chennai and > Coimbatore. We provide Python training with Placement Assistance. For > more details, email to mo... at cgonsoft.com We also provide Online Training. From merwin.irc at gmail.com Sat Apr 7 05:22:53 2012 From: merwin.irc at gmail.com (Thibaut DIRLIK) Date: Sat, 7 Apr 2012 11:22:53 +0200 Subject: Multiprocessing & Logging Message-ID: Hi, I'm currently writing a multiprocess applications with Python 3.2 and multiprocessing module. My subprocesses will use a QueueHandler to log messages (by sending them to the main process, which uses a QueueListener). However, if logging is already configured when I create the subprocesses, they will inherit the configuration, and opened file descriptors used for logging in the main process. However, when I tried this with a basicConfig configuration, which prints to a file, the messages are only written once to the file. I don't understand why. Normally, the mainprocess contains a logging handler to log to the file. This handler will be copied into the child processes. Child processes will then have two handlers : a QueueHandler, and a FileHandler. They should write to the file handler and then send the message to the main process QueueListener, which should write the message AGAIN to the FileHandler. But that's not the case. Any rea How can I totally "unset" the logging configuration in child processes and only enable the QueueHandler (foor all configured loggers, not only the root one) ? Thanks for your help, -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Apr 7 06:48:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Apr 2012 20:48:29 +1000 Subject: escaping/encoding/formatting in python In-Reply-To: References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> <0e358c78-fb71-4b28-a737-f9e6468cf2bc@a8g2000pbe.googlegroups.com> <45ea3f8b-1f78-48aa-9ef0-3004d6ef8721@js1g2000pbc.googlegroups.com> Message-ID: On Sat, Apr 7, 2012 at 3:36 PM, Nobody wrote: > The delimiter can be chosen either by analysing the string > or by choosing something a string at random and relying upon a collision > being statistically improbable. The same techniques being available to MIME multi-part encoders, and for the same reason. Nestable structures can be quite annoying to parse. ChrisA From rodrick.brown at gmail.com Sat Apr 7 07:20:23 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Sat, 7 Apr 2012 07:20:23 -0400 Subject: PEP 274 In-Reply-To: References: Message-ID: This proposal was suggested in 2001 and is only now being implemented. Why the extended delay? Sent from my iPhone On Apr 7, 2012, at 3:32 AM, Alec Taylor wrote: > Has been withdrawn... and implemented > > http://www.python.org/dev/peps/pep-0274/ > -- > http://mail.python.org/mailman/listinfo/python-list From andrew at acooke.org Sat Apr 7 08:23:25 2012 From: andrew at acooke.org (andrew cooke) Date: Sat, 7 Apr 2012 05:23:25 -0700 (PDT) Subject: ordering with duck typing in 3.1 Message-ID: <33019705.1873.1333801405463.JavaMail.geo-discussion-forums@ynmm9> hi, please, what am i doing wrong here? the docs say http://docs.python.org/release/3.1.3/library/stdtypes.html#comparisons "in general, __lt__() and __eq__() are sufficient, if you want the conventional meanings of the comparison operators" but i am seeing > assert 2 < three E TypeError: unorderable types: int() < IntVar() with this test: class IntVar(object): def __init__(self, value=None): if value is not None: value = int(value) self.value = value def setter(self): def wrapper(stream_in, thunk): self.value = thunk() return self.value return wrapper def __int__(self): return self.value def __lt__(self, other): return self.value < other def __eq__(self, other): return self.value == other def __hash__(self): return hash(self.value) class DynamicTest(TestCase): def test_lt(self): three = IntVar(3) assert three < 4 assert 2 < three assert 3 == three so what am i missing? thanks, andrew From subscriptions at cagttraining.com Sat Apr 7 09:07:04 2012 From: subscriptions at cagttraining.com (Bill Felton) Date: Sat, 7 Apr 2012 09:07:04 -0400 Subject: Distribute app without source? Message-ID: Thanks in advance for any insights! My partner and I have developed an application primarily intended for internal use within our company. However, we face the need to expose the app to certain non-employees. We would like to do so without exposing our source code. Our targets include users of Windows and Mac OS, but not UNIX. We are using Python 3.2 and tkinter. It appears, and limited testing bears out, that py2app, and presumably py2exe, are not options given lack of 3.x support. PyInstaller does not support the 64-bit version we are using. Does it make sense for us to try to use pyInstaller with a 32-bit install of Python 3.2? Are there other options? Any assistance or input will be welcome. regards, Bill From merwin.irc at gmail.com Sat Apr 7 09:08:46 2012 From: merwin.irc at gmail.com (Thibaut) Date: Sat, 07 Apr 2012 15:08:46 +0200 Subject: Multiprocessing & Logging In-Reply-To: References: Message-ID: <4F803C5E.5060601@gmail.com> Le 07/04/2012 11:22, Thibaut DIRLIK a ?crit : > Hi, > > I'm currently writing a multiprocess applications with Python 3.2 and > multiprocessing module. My subprocesses will use a QueueHandler to log > messages (by sending them to the main process, which uses a > QueueListener). However, if logging is already configured when I > create the subprocesses, they will inherit the configuration, and > opened file descriptors used for logging in the main process. > > However, when I tried this with a basicConfig configuration, which > prints to a file, the messages are only written once to the file. I > don't understand why. Normally, the mainprocess contains a logging > handler to log to the file. This handler will be copied into the child > processes. Child processes will then have two handlers : a > QueueHandler, and a FileHandler. They should write to the file handler > and then send the message to the main process QueueListener, which > should write the message AGAIN to the FileHandler. > > But that's not the case. Any rea > > How can I totally "unset" the logging configuration in child processes > and only enable the QueueHandler (foor all configured loggers, not > only the root one) ? > > Thanks for your help, > Ok, I understand what happenned. In fact, configuring the logging before forking works fine. Subprocess inherits the configuration, as I thought. The problem was that I didn't passed any handler to the QueueListener constructor. The when the listener recieved an message, it wasn't handled. I'm not sure how the logging module works, but what handlers should I pass the QueueListener constructor ? I mean, maybe that I would like some messages (depending of the logger) to be logged to a file, while some others message would just be printed to stdout. This doesn't seem to be doable with a QueueListener. Maybe I should implement my own system, and pass a little more informations with the record sent in the queue : the logger name for example. Then, in the main process I would do a logging.getLogger(loggername) and log the record using this logger (by the way it was configured). What do you think ? From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sat Apr 7 09:35:36 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sat, 07 Apr 2012 15:35:36 +0200 Subject: ordering with duck typing in 3.1 In-Reply-To: <33019705.1873.1333801405463.JavaMail.geo-discussion-forums@ynmm9> References: <33019705.1873.1333801405463.JavaMail.geo-discussion-forums@ynmm9> Message-ID: Am 07.04.2012 14:23 schrieb andrew cooke: > class IntVar(object): > > def __init__(self, value=None): > if value is not None: value = int(value) > self.value = value > > def setter(self): > def wrapper(stream_in, thunk): > self.value = thunk() > return self.value > return wrapper > > def __int__(self): > return self.value > > def __lt__(self, other): > return self.value< other > > def __eq__(self, other): > return self.value == other > > def __hash__(self): > return hash(self.value) > so what am i missing? If I don't confuse things, I think you are missing a __gt__() in your IntVar() class. This is because first, a '2 < three' is tried with 2.__lt__(three). As this fails due to the used types, it is reversed: 'three > 2' is equivalent. As your three doesn't have a __gt__(), three.__gt__(2) fails as well. Thomas From bahamutzero8825 at gmail.com Sat Apr 7 09:59:58 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 07 Apr 2012 08:59:58 -0500 Subject: Distribute app without source? In-Reply-To: References: Message-ID: <4F80485E.8090808@gmail.com> On 4/7/2012 8:07 AM, Bill Felton wrote: > We are using Python 3.2 and tkinter. It appears, and limited testing bears out, that py2app, and presumably py2exe, are not options given lack of 3.x support. cx_Freeze supports Python 3.2. It works fine for my purposes, but I have not done any serious work with it. I don't know about tkinter, but I was able to freeze a simple Qt application. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From xahlee at gmail.com Sat Apr 7 10:29:15 2012 From: xahlee at gmail.com (Xah Lee) Date: Sat, 7 Apr 2012 07:29:15 -0700 (PDT) Subject: how i loved lisp cons and UML and Agile and Design Patterns and Pythonic and KISS and YMMV and stopped worrying Message-ID: OMG, how i loved lisp cons and macros and UML and Agile eXtreme Programing and Design Patterns and Anti-Patterns and Pythonic and KISS and YMMV and stopped worrying. ?World Multiconference on Systemics, Cybernetics and Informatics???? http://xahlee.org/comp/WMSCI.html highly advanced plain text format follows, as a amenity for tech geekers. ----------------------------------------------- World Multiconference on Systemics, Cybernetics and Informatics ??? Xah Lee, 2010-04-04 Starting in 2004, i regularly receive email asking me to participate a conference, called ?World Multiconference on Systemics, Cybernetics and Informatics? (WMSCI). Here's one of such email i got today: Dear Xah Lee: As you know the Nobel Laureate Herbert Simon affirmed that design is an essential ingredient of the Artificial Sciences Ranulph Glanville, president of the American Society for Cybernetics and expert in design theory, affirms that ?Research is a variety of design. So do research as design. Design is key to research. Research has to be designed.? An increasing number of authors are stressing the relationships between Design and Research. Design is a mean for Research, and Research is a mean for Design. Design and research are related via cybernetic loops in the context of means-ends logic. Consequently, we invite you to submit a paper/abstract and/ot to organize an invited session in the International Symposium on Design and Research in the Artificial and the Natural Sciences: DRANS 2010 (http://www.sysconfer.org/drans) which is being organized in the context of The 14th World Multi- Conference on Systemics, Cybernetics and Informatics: WMSCI 2010 (http://www.sysconfer.org/wmsci), 2010 in Orlando, Florida, USA. ? Here's the first email i got from them from my mail archive: From: sci2005 at iiis.org Subject: Inviting you to participate in SCI 2005 Date: October 20, 2004 1:39:48 PM PDT To: XAH at XAHLEE.ORG Dear Dr. Xah Lee: On behalf of the SCI 2005 Organizing Committee, I would like to invite you to participate in the 9th World Multi-Conference on Systemics, Cybernetics and Informatics (http://www.iiisci.org/sci2005), which will take place in Orlando, Florida, USA, from July 10-13, 2005. Full text wmsci.txt. I do not know this organization. I don't know how they got my email or how they know that i'm involved in the computer science community. (surely from trawling email addresses in science forums) Though, after getting a few of their emails, one clearly gets a sense that it is a scam, soliciting innocent idiotic academicians (many PhDs are idiots.). Here's what Wikipedia has to say about them: World Multiconference on Systemics, Cybernetics and Informatics. Here's a juicy quote: WMSCI attracted publicity of a less favorable sort in 2005 when three graduate students at MIT succeeded in getting a paper accepted as a ?non-reviewed paper? to the conference that had been randomly generated by a computer program called SCIgen.[8] Documents generated by this software have been used to submit papers to other similar conferences. Compare to the Sokal affair. WMSCI has been accused of using spam to advertise its conferences.[8] Now and then, whenever i got their email, the curiosity in me do lookup the several terms they used in the email, partly to check the validity. For example, in this one, it mentions Herbert Simon. Another one i recall i got recently mentioned Science 2.0. Both of the terms i haven't heard of before. One'd think that it is easy to tell scam from real science, but with today's science proliferation, it's actually not that easy. Even if you are a academic, it's rather common that many new science terms you never heard of, because there are tremendous growth of new disciplines or cross disciplines, along with new jargons. Cross-discipline is rather common and natural, unlike in the past where science is more or less clearly delineated hierarchy like Physics, Math, Chemistry, Biology, etc and their sub-branches. However, many of today's new areas is a bit questionable, sometimes a deliberate money-making scheme, which i suppose is the case for WMSCI. Many of these, use terms like ?post-modern?, ?science 2.0? to excuse themselves from the rather strict judgment of classic science. Many of these terms such as ?systemics?, ?cybernetics?, ?infomatics? are vague. Depending on the context, it could be a valid emerging science discipline, but it could also be pure new-age hogwash. And sometimes, nobody really knows today. Fledgling scientific fields may started off as pseudo-science but later became well accepted with more solid theories. (e.g. evolutionary psychology) In the past 2 decades, there are quite a few cases where peer reviewed papers published in respected journals are exposed as highly questionable or deliberate hoax, arose massive debate on the peer review system. The peer-review system itself can't hold all the blame, but part of it has to do with the incredible growth of sciences and limitation of the single human mind to make sense of them all. For examples, see: ?Sokal Affair (The Sokal Affair was a publishing hoax perpetrated by Alan Sokal, a physics professor at New York University. In 1996, Prof. Sokal submitted an article to Social Text, an academic journal dedicated to postmodern cultural studies.) ?Bogdanov Affair (Twin brother physicists published in peer reviewed journal that was accused to be random mix of physics jargons) ?Jan Hendrik Schon (German physicist who briefly rose to prominence after a series of apparent breakthroughs that were later discovered to be fraudulent.[1] Before he was exposed, Sch?n had received the Otto- Klung-Weberbank Prize for Physics in 2001, the Braunschweig Prize in 2001 and the Outstanding Young Investigator Award of the Materials Research Society in 2002, which was later rescinded.) When it comes to philosophy, it is worse. For example, there's this Hegel (1770 ? 1831). Personally, i regard him as the worst mumble- jumbo scumbag. In the software engineering area, which i'm a expert, there are quite a huge number of wishy-washy shit. Examples include: eXtreme Programing (espousing that programing should be done by 2 males sitting in front of a computer together, one code while the other sucks his cock.), Universal Modeling Language (which proclaims that this pseudo-language solves the world's problems), Design Patterns (which peddles best practices under the aegis of OOP and jargonism.), and, of course there's Larry Wall, whose crime is too numerous to list. (disclaimer: opinion only.) Related: ?Larry Wall and Cults ?Perl: Theory vs Practice ?Jargons of Info Tech Industry ?Why Software Suck Even in the area of math, i'm reminded of the guy Buckminster Fuller (1895 ? 1983). Personally, i despise him. One of the worst new-age garbage from the guy is the ?Synergetics?. On the other hand, there's Stephen Wolfram, with his A New Kind of Science. It has received criticism from many scientists and mathematicians as garbage, exasperated by Wolfram's megalomania personality. Personally i respect his work highly. (See also: Notes on A New Kind of Science.) Related: ?Men Are From Mars, Women Are From Venus ?Spy vs Spy; Tech Geekers vs Spammers ?Scientology and Falun Gong Truely, your troll, Xah From nicholas.cole at gmail.com Sat Apr 7 10:30:19 2012 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sat, 7 Apr 2012 15:30:19 +0100 Subject: 'string_escape' in python 3 In-Reply-To: References: Message-ID: On Sat, Apr 7, 2012 at 12:10 AM, Ian Kelly wrote: >>>> import codecs >>>> codecs.getdecoder('unicode_escape')(s)[0] > 'Hello: this is a test' > > Cheers, > Ian Thanks, Ian. I had assumed that if a unicode string didn't have a .decode method, then I couldn't use a decoder on it, so it hadn't occurred to me to try that.... N. From kiuhnm03.4t.yahoo.it Sat Apr 7 10:35:20 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 07 Apr 2012 16:35:20 +0200 Subject: multithreading Message-ID: <4f8050a6$0$1393$4fafbaef@reader1.news.tin.it> I'm about to write my first module and I don't know how I should handle multithreading/-processing. I'm not doing multi-threading inside my module. I'm just trying to make it thread-safe so that users *can* do multi-threading. For instance, let's say I want to make this code thread-safe: ---> myDict = {} def f(name, val): if name not in myDict: myDict[name] = val return myDict[name] <--- I could use threading.Lock() but I don't know if that might interfere with some other modules imported by the user. In some languages you can't mix multi-threading libraries. Is Python one of them? Kiuhnm From rtw at rtw.me.uk Sat Apr 7 10:37:17 2012 From: rtw at rtw.me.uk (Rob Williscroft) Date: Sat, 7 Apr 2012 14:37:17 +0000 (UTC) Subject: ordering with duck typing in 3.1 References: <33019705.1873.1333801405463.JavaMail.geo-discussion-forums@ynmm9> Message-ID: andrew cooke wrote in news:33019705.1873.1333801405463.JavaMail.geo-discussion-forums at ynmm9 in gmane.comp.python.general: > > hi, > > please, what am i doing wrong here? the docs say > http://docs.python.org/release/3.1.3/library/stdtypes.html#comparisons > "in general, __lt__() and __eq__() are sufficient, if you want the > conventional meanings of the comparison operators" but i am seeing > >> assert 2 < three > E TypeError: unorderable types: int() < IntVar() > > with this test: > > > class IntVar(object): > > def __lt__(self, other): > return self.value < other > > so what am i missing? > The part of the docs you are relying on uses the wording "in general", IOW, it is not saying that defining __eq__ and __lt__ will always be sufficient. In this case the expression "2 < three" is calling int.__lt__, which doesn't know how to comapre to an instance of your class so returns NotImplemented. At this point if you had defined a __gt__ method the interpreter would then try and call that having first switched the arguments around. But you didn't so a TypeError is raised. I'm afraid I couldn't find anywhere in the docs where that behaviour is described, I suspect I only know it from lurking on usenet for a number of years. The best description that I could find of the behaviour you are seeing is at: http://docs.python.org/py3k/reference/expressions.html#not-in There is a paragraph that contains: "... the == and != operators always consider objects of different types to be unequal, while the <, >, >= and <= operators raise a TypeError when comparing objects of different types that do not implement these operators for the given pair of types. ..." Perhapse the docs could be reworded to note that, to define a full set of comparisons between *different* types, you need to define a full set of special methods. Some links I found along the way: http://docs.python.org/release/3.1.3/library/constants.html? highlight=__lt__#NotImplemented http://code.activestate.com/recipes/576685/ http://docs.python.org/py3k/library/functools.html#functools.total_ordering Rob. From research at johnohagan.com Sat Apr 7 10:40:51 2012 From: research at johnohagan.com (John O'Hagan) Date: Sun, 8 Apr 2012 00:40:51 +1000 Subject: ordering with duck typing in 3.1 In-Reply-To: <33019705.1873.1333801405463.JavaMail.geo-discussion-forums@ynmm9> References: <33019705.1873.1333801405463.JavaMail.geo-discussion-forums@ynmm9> Message-ID: <20120408004051.dec5a62d5b39e77e69c5bc6a@johnohagan.com> On Sat, 7 Apr 2012 05:23:25 -0700 (PDT) andrew cooke wrote: > > hi, > > please, what am i doing wrong here? the docs say > http://docs.python.org/release/3.1.3/library/stdtypes.html#comparisons "in > general, __lt__() and __eq__() are sufficient, if you want the conventional > meanings of the comparison operators" but i am seeing > > > assert 2 < three > E TypeError: unorderable types: int() < IntVar() > > with this test: > > > class IntVar(object): > > def __init__(self, value=None): > if value is not None: value = int(value) > self.value = value > > def setter(self): > def wrapper(stream_in, thunk): > self.value = thunk() > return self.value > return wrapper > > def __int__(self): > return self.value > > def __lt__(self, other): > return self.value < other > > def __eq__(self, other): > return self.value == other > > def __hash__(self): > return hash(self.value) > > > class DynamicTest(TestCase): > > def test_lt(self): > three = IntVar(3) > assert three < 4 > assert 2 < three > assert 3 == three > > so what am i missing? > I think that quote from the docs is just to point out that you only need those two (== and <) to derive any of the other comparisons; but not to imply that a class that only defines those two will automatically possess the others. However, you can do that, with functools.total_ordering. Regards, John From mwilson at the-wire.com Sat Apr 7 10:44:30 2012 From: mwilson at the-wire.com (mwilson at the-wire.com) Date: Sat, 07 Apr 2012 10:44:30 -0400 Subject: ordering with duck typing in 3.1 References: <33019705.1873.1333801405463.JavaMail.geo-discussion-forums@ynmm9> Message-ID: Thomas Rachel wrote: > Am 07.04.2012 14:23 schrieb andrew cooke: > >> class IntVar(object): >> >> def __init__(self, value=None): >> if value is not None: value = int(value) >> self.value = value >> >> def setter(self): >> def wrapper(stream_in, thunk): >> self.value = thunk() >> return self.value >> return wrapper >> >> def __int__(self): >> return self.value >> >> def __lt__(self, other): >> return self.value< other >> >> def __eq__(self, other): >> return self.value == other >> >> def __hash__(self): >> return hash(self.value) > >> so what am i missing? > > If I don't confuse things, I think you are missing a __gt__() in your > IntVar() class. > > This is because first, a '2 < three' is tried with 2.__lt__(three). As > this fails due to the used types, it is reversed: 'three > 2' is > equivalent. As your three doesn't have a __gt__(), three.__gt__(2) fails > as well. Practically, yes. Just that that's not what the documentation says. Looks like Python no longer tries to cobble together missing relations based on the "usual" properties of ordering. Mel. From vinay_sajip at yahoo.co.uk Sat Apr 7 10:47:25 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 7 Apr 2012 14:47:25 +0000 (UTC) Subject: Multiprocessing & Logging References: <4F803C5E.5060601@gmail.com> Message-ID: Thibaut gmail.com> writes: > Ok, I understand what happenned. In fact, configuring the logging before > forking works fine. Subprocess inherits the configuration, as I thought. > > The problem was that I didn't passed any handler to the QueueListener > constructor. The when the listener recieved an message, it wasn't handled. > > I'm not sure how the logging module works, but what handlers should I > pass the QueueListener constructor ? I mean, maybe that I would like > some messages (depending of the logger) to be logged to a file, while > some others message would just be printed to stdout. > > This doesn't seem to be doable with a QueueListener. Maybe I should > implement my own system, and pass a little more informations with the > record sent in the queue : the logger name for example. > > Then, in the main process I would do a logging.getLogger(loggername) and > log the record using this logger (by the way it was configured). > > What do you think ? > You probably need different logging configurations in different processes. In your multiprocessing application, nominate one of the processes as a logging listener. It should initialize a QueueListener subclass which you write. All other processes should just configure a QueueHandler, which uses the same queue as the QueueListener. All the processes with QueueHandlers just send their records to the queue. The process with the QueueListener picks these up and handles them by calling the QueueListener's handle() method. The default implementation of QueueListener.handle() is: def handle(self, record): record = self.prepare(record) for handler in self.handlers: handler.handle(record) where self.handlers is just the handlers you passed to the QueueListener constructor. However, if you want a very flexible configuration where different loggers have different handlers, this is easy to arrange. Just configure logging in the listener process however you want, and then, in your QueueListener subclass, do something like this: class MyQueueListener(logging.handlers.QueueListener): def handle(self, record): record = self.prepare(record) logger = logging.getLogger(record.name) logger.handle(record) This will pass the events to whatever handlers are configured for a particular logger. I will try to update the Cookbook in the logging docs with this approach, and a working script. Background information is available here: [1][2] Regards, Vinay Sajip [1] http://plumberjack.blogspot.co.uk/2010/09/using-logging-with-multiprocessing.html [2] http://plumberjack.blogspot.co.uk/2010/09/improved-queuehandler-queuelistener.html From merwin.irc at gmail.com Sat Apr 7 11:05:45 2012 From: merwin.irc at gmail.com (Thibaut) Date: Sat, 07 Apr 2012 17:05:45 +0200 Subject: Multiprocessing & Logging In-Reply-To: References: <4F803C5E.5060601@gmail.com> Message-ID: <4F8057C9.8070804@gmail.com> Le 07/04/2012 16:47, Vinay Sajip a ?crit : > Thibaut gmail.com> writes: > >> Ok, I understand what happenned. In fact, configuring the logging before >> forking works fine. Subprocess inherits the configuration, as I thought. >> >> The problem was that I didn't passed any handler to the QueueListener >> constructor. The when the listener recieved an message, it wasn't handled. >> >> I'm not sure how the logging module works, but what handlers should I >> pass the QueueListener constructor ? I mean, maybe that I would like >> some messages (depending of the logger) to be logged to a file, while >> some others message would just be printed to stdout. >> >> This doesn't seem to be doable with a QueueListener. Maybe I should >> implement my own system, and pass a little more informations with the >> record sent in the queue : the logger name for example. >> >> Then, in the main process I would do a logging.getLogger(loggername) and >> log the record using this logger (by the way it was configured). >> >> What do you think ? >> > You probably need different logging configurations in different processes. In > your multiprocessing application, nominate one of the processes as a logging > listener. It should initialize a QueueListener subclass which you write. All > other processes should just configure a QueueHandler, which uses the same queue > as the QueueListener. > > All the processes with QueueHandlers just send their records to the queue. The > process with the QueueListener picks these up and handles them by calling the > QueueListener's handle() method. > > The default implementation of QueueListener.handle() is: > > def handle(self, record): > record = self.prepare(record) > for handler in self.handlers: > handler.handle(record) > > where self.handlers is just the handlers you passed to the QueueListener > constructor. However, if you want a very flexible configuration where different > loggers have different handlers, this is easy to arrange. Just configure logging > in the listener process however you want, and then, in your QueueListener > subclass, do something like this: > > class MyQueueListener(logging.handlers.QueueListener): > def handle(self, record): > record = self.prepare(record) > logger = logging.getLogger(record.name) > logger.handle(record) > > This will pass the events to whatever handlers are configured for a particular > logger. > > I will try to update the Cookbook in the logging docs with this approach, and a > working script. > > Background information is available here: [1][2] > > Regards, > > Vinay Sajip > > [1] > http://plumberjack.blogspot.co.uk/2010/09/using-logging-with-multiprocessing.html > [2] > http://plumberjack.blogspot.co.uk/2010/09/improved-queuehandler-queuelistener.html > This is exactly what I wanted, it seems perfect. However I still have a question, from what I understood, I have to configure logging AFTER creating the process, to avoid children process to inherits the logging config. Unless there is a way to "clean" logging configuration in children processes, so they only have one handler : the QueueHandler. I looked at the logging code and it doesn't seems to have an easy way to do this. The problem of configuring the logging after the process creation is that... I can't log during process creation. But if it's too complicated, I will just do this. Thanks again for your help Vinay, From puzzles at cotpi.com Sat Apr 7 11:19:50 2012 From: puzzles at cotpi.com (cotpi) Date: Sat, 07 Apr 2012 20:49:50 +0530 Subject: Let's have hex Message-ID: A hexual game: http://cotpi.com/letushavehex/1/ From vinay_sajip at yahoo.co.uk Sat Apr 7 11:38:14 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 7 Apr 2012 15:38:14 +0000 (UTC) Subject: Multiprocessing & Logging References: <4F803C5E.5060601@gmail.com> <4F8057C9.8070804@gmail.com> Message-ID: Thibaut gmail.com> writes: > This is exactly what I wanted, it seems perfect. However I still have a > question, from what I understood, > I have to configure logging AFTER creating the process, to avoid > children process to inherits the logging config. > > Unless there is a way to "clean" logging configuration in children > processes, so they only have one handler : the QueueHandler. > > I looked at the logging code and it doesn't seems to have an easy way to > do this. The problem of configuring the logging > after the process creation is that... I can't log during process > creation. But if it's too complicated, I will just do this. You may be able to have a "clean" configuration: for example, dictConfig() allows the configuration dictionary to specify whether existing loggers are disabled. So the details depend on the details of your desired configuration. One more point: I suggested that you subclass QueueListener, but you don't actually need to do this. For example, you can do something like: class DelegatingHandler(object): def handle(self, record): logger = logging.getLogger(record.name) logger.handle(record) And then instantiate the QueueListener with an instance of DelegatingHandler. QueueListener doesn't need actual logging handlers, just something with a handle method which takes a record. Regards, Vinay Sajip From ian.g.kelly at gmail.com Sat Apr 7 11:59:36 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 7 Apr 2012 09:59:36 -0600 Subject: 'string_escape' in python 3 In-Reply-To: References: Message-ID: On Sat, Apr 7, 2012 at 8:30 AM, Nicholas Cole wrote: > On Sat, Apr 7, 2012 at 12:10 AM, Ian Kelly wrote: >>>>> import codecs >>>>> codecs.getdecoder('unicode_escape')(s)[0] >> 'Hello: this is a test' >> >> Cheers, >> Ian > > Thanks, Ian. ?I had assumed that if a unicode string didn't have a > .decode method, then I couldn't use a decoder on it, so it hadn't > occurred to me to try that.... Just a warning, I'm not really sure whether this behavior is intended or not. I just tried it and found that it seems to work. From tjreedy at udel.edu Sat Apr 7 12:35:11 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Apr 2012 12:35:11 -0400 Subject: PEP 274 In-Reply-To: References: Message-ID: On 4/7/2012 7:20 AM, Rodrick Brown wrote: > This proposal was suggested in 2001 and is only now being > implemented. Why the extended delay? It was implemented in revised form 3 years ago in 3.0. -- Terry Jan Reedy From goldtech at worldpost.com Sat Apr 7 12:59:35 2012 From: goldtech at worldpost.com (goldtech) Date: Sat, 7 Apr 2012 09:59:35 -0700 (PDT) Subject: Python Script Works Locally But Not Remotely with SSH References: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> <12051938.18.1333308736916.JavaMail.geo-discussion-forums@vbtb5> Message-ID: <57e3fe20-f206-4430-be96-126d28f7fe25@l30g2000yqb.googlegroups.com> Thank you for the help. I guess I didn't understand what's really going on. I thought if I SSH even from a Linux to a Windows machine whatever I say on the SSH client command line would be the same as me doing a command on the "DOS" command-line in Windows. I incorrectly thought SSH is just a tunnel for text... But that's not what's going on, there's a lot more to it. Thanks, I will get into it more to understand this. From tjreedy at udel.edu Sat Apr 7 13:22:41 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Apr 2012 13:22:41 -0400 Subject: Distribute app without source? In-Reply-To: References: Message-ID: On 4/7/2012 9:07 AM, Bill Felton wrote: > Thanks in advance for any insights! > > My partner and I have developed an application primarily > intended for internal use within our company. However, we face the > need to expose the app to certain non-employees. > We would like to do so without exposing our source code. To really do that, make it a web service, so the code only lives on your server. That also takes care of > Our targets include users of Windows and Mac OS, but not UNIX. You could also distribute .pyc files compiled from obfuscated .py files. > We are using Python 3.2 and tkinter. It appears, and limited testing > bears out, that py2app, and presumably py2exe, are not options given > lack of 3.x support. PyInstaller does not support the 64-bit version > we are using. Any such thing will include the contents of .pyc files somehow, even if harder to get at. > Does it make sense for us to try to use pyInstaller with a 32-bit > install of Python 3.2? If you app runs within 2 GB, I would think yes. -- Terry Jan Reedy From bahamutzero8825 at gmail.com Sat Apr 7 13:22:57 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 07 Apr 2012 12:22:57 -0500 Subject: Python Script Works Locally But Not Remotely with SSH In-Reply-To: <57e3fe20-f206-4430-be96-126d28f7fe25@l30g2000yqb.googlegroups.com> References: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> <12051938.18.1333308736916.JavaMail.geo-discussion-forums@vbtb5> <57e3fe20-f206-4430-be96-126d28f7fe25@l30g2000yqb.googlegroups.com> Message-ID: <4F8077F1.4050406@gmail.com> On 4/7/2012 11:59 AM, goldtech wrote: I thought if I SSH > even from a Linux to a Windows machine whatever I say on the SSH > client command line would be the same as me doing a command on the > "DOS" command-line in Windows. I incorrectly thought SSH is just a > tunnel for text... It gives you whatever shell the SSH server serves (could be cmd, could a Windows build of bash, could be whatever). I think the other posters think you are trying to view Firefox on the Linux client's desktop. If that is indeed the case, you will need an X server on the XP machine (I think; it might not be that simple since it's a Windows process). AFAICT, you want to open Firefox and have it show on the XP machine's desktop. If that's the case, see Jerry Hill's post and configure Windows to either run the SSH server as the logged in user or to allow it to interact with the logged in user's desktop. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From gandalf at shopzeus.com Sat Apr 7 14:20:15 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 07 Apr 2012 20:20:15 +0200 Subject: documentation for asyncmongo? Message-ID: <4F80855F.1050808@shopzeus.com> Is there any kind of API documentation for asyncmongo? On GITHub they say "asyncmongo syntax strives to be similar to pymongo .". However, many basic things do not work or they are not similar. http://api.mongodb.org/python/2.1.1/tutorial.html Example from pymongo: >>> db.collection_names() [u'posts', u'system.indexes'] The same in asyncmongo: TypeError: 'Cursor' object is not callable Even the connection is different: pymongo.Connect versus asyncmongo.Client. It has a "pool_id" parameter and what the hack is that? Is there no documentation for asyncmongo at all? Thanks, Laszlo -------------- next part -------------- An HTML attachment was scrubbed... URL: From joncle at googlemail.com Sat Apr 7 15:36:54 2012 From: joncle at googlemail.com (Jon Clements) Date: Sat, 7 Apr 2012 12:36:54 -0700 (PDT) Subject: ordering with duck typing in 3.1 In-Reply-To: <33019705.1873.1333801405463.JavaMail.geo-discussion-forums@ynmm9> References: <33019705.1873.1333801405463.JavaMail.geo-discussion-forums@ynmm9> Message-ID: <32308945.2388.1333827414439.JavaMail.geo-discussion-forums@vbdn7> Any reason you can't derive from int instead of object? You may also want to check out functions.total_ordering on 2.7+ From subscriptions at cagttraining.com Sat Apr 7 15:59:03 2012 From: subscriptions at cagttraining.com (Bill Felton) Date: Sat, 7 Apr 2012 15:59:03 -0400 Subject: Distribute app without source? In-Reply-To: References: Message-ID: On Apr 7, 2012, at 1:22 PM, Terry Reedy wrote: > On 4/7/2012 9:07 AM, Bill Felton wrote: >> Thanks in advance for any insights! >> >> My partner and I have developed an application primarily > > intended for internal use within our company. However, we face the > > need to expose the app to certain non-employees. >> We would like to do so without exposing our source code. > > To really do that, make it a web service, so the code only lives on your server. That also takes care of That's not really an alternative for us, for a variety of reasons. It's not clear at the moment if it would ever be an alternative, given our app and its structure and intended use. As recommended elsewhere in this thread, cx_freeze seems likely to do us some good. Initial testing has been fairly positive, although there are still some issues we're wrestling with. If those continue, I'll post questions to the cx_freeze list. Thanks everyone. regards, Bill From bryanjugglercryptographer at yahoo.com Sat Apr 7 16:09:48 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Sat, 7 Apr 2012 13:09:48 -0700 (PDT) Subject: multithreading References: <4f8050a6$0$1393$4fafbaef@reader1.news.tin.it> Message-ID: <273d93ec-8ce2-4842-ba2a-3edd8320b51b@n5g2000pbg.googlegroups.com> Kiuhnm wrote: > I'm about to write my first module and I don't know how I should handle > multithreading/-processing. > I'm not doing multi-threading inside my module. I'm just trying to make > it thread-safe so that users *can* do multi-threading. There are a couple conventions to follow. Trying to anticipate the threading needs of users and then locking everything for the worst case is a bad idea. So what are the conventions? Unless documented otherwise, classes don't guarantee that each instance can be used by more then one thread. Most of the classes in Python's standard library are not one- instance-multiple-threads safe. An important documented exception is queue.queue. Classes should be safe for instance-per-thread multi-threading, unless documented otherwise. Likewise, functions should be thread safe under the assumption that their arguments are not shared between threads, which brings us to your example: > For instance, let's say I want to make this code thread-safe: > > ---> > myDict = {} > > def f(name, val): > ? ? ?if name not in myDict: > ? ? ? ? ?myDict[name] = val > ? ? ?return myDict[name] > <--- First, don't re-code Python's built-ins. The example is a job for dict.setdefault(). Language built-ins are already thread-safe (at least in CPython), though not meant as thread synchronization primitives. Second, the example suggests no obvious reason for the single global variabel. It could be a class for which users can make any number of instances. Third, there are cases where you want a single global. Most of the time I'd recommend warning users about threading assumptions. -Bryan From kiuhnm03.4t.yahoo.it Sat Apr 7 17:06:01 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 07 Apr 2012 23:06:01 +0200 Subject: multithreading In-Reply-To: <273d93ec-8ce2-4842-ba2a-3edd8320b51b@n5g2000pbg.googlegroups.com> References: <4f8050a6$0$1393$4fafbaef@reader1.news.tin.it> <273d93ec-8ce2-4842-ba2a-3edd8320b51b@n5g2000pbg.googlegroups.com> Message-ID: <4f80ac38$0$1386$4fafbaef@reader2.news.tin.it> On 4/7/2012 22:09, Bryan wrote: >> For instance, let's say I want to make this code thread-safe: >> >> ---> >> myDict = {} >> >> def f(name, val): >> if name not in myDict: >> myDict[name] = val >> return myDict[name] >> <--- > > First, don't re-code Python's built-ins. The example is a job for > dict.setdefault(). [...] That was just an example for the sake of the discussion. My question is this: can I use 'threading' without interfering with the program which will import my module? Kiuhnm From alagalah at gmail.com Sat Apr 7 17:15:09 2012 From: alagalah at gmail.com (KRB) Date: Sat, 7 Apr 2012 14:15:09 -0700 (PDT) Subject: Pass a list of variables to a procedure Message-ID: <25964674.2234.1333833309148.JavaMail.geo-discussion-forums@ynbj3> Hi there, I would like to be able to pass a list of variables to a procedure, and have the output assigned to them. For instance: x=0 y=0 z=0 vars =[x,y,z] parameters=[1,2,3] for i in range(1,len(vars)): *** somefunction that takes the parameter "1", does a computation and assigns the output to "x", and so on and so forth. Such that later in the program I can print x,y,z I hope that makes sense, otherwise I have to do: x=somefunction(1) y=somefunction(2) z=somefunction(3) etc etc Appreciate any help From askutt at gmail.com Sat Apr 7 17:45:36 2012 From: askutt at gmail.com (Adam Skutt) Date: Sat, 7 Apr 2012 14:45:36 -0700 (PDT) Subject: multithreading References: <4f8050a6$0$1393$4fafbaef@reader1.news.tin.it> <273d93ec-8ce2-4842-ba2a-3edd8320b51b@n5g2000pbg.googlegroups.com> <4f80ac38$0$1386$4fafbaef@reader2.news.tin.it> Message-ID: On Apr 7, 5:06?pm, Kiuhnm wrote: > On 4/7/2012 22:09, Bryan wrote:>> For instance, let's say I want to make this code thread-safe: > > >> ---> > >> myDict = {} > > >> def f(name, val): > >> ? ? ? if name not in myDict: > >> ? ? ? ? ? myDict[name] = val > >> ? ? ? return myDict[name] > >> <--- > > > First, don't re-code Python's built-ins. The example is a job for > > dict.setdefault(). > > [...] > > That was just an example for the sake of the discussion. > My question is this: can I use 'threading' without interfering with the > program which will import my module? 'import threading' ought to work everywhere, but that's not enough to tell you whether whatever you're trying to do will actually work. However, you shouldn't need to do it unless your application is meant to /only/ be used in applications that have done 'import threading' elsewhere. Otherwise, you probably have a pretty serious design issue. Global state is bad. TLS state is little better, even if it's common in a lot of python modules. Non-thread-safe object instances is usually fine. Object construction needs to be thread-safe, but that's also the default behavior. You need not worry about it unless you're doing very unusual things. Plainly, most of the time you shouldn't need to do anything to support multiples threads beyond avoiding global state. In fact, you should stop and give some serious thought to your design if you need to do anything else. Adam From nobody at nowhere.com Sat Apr 7 18:20:57 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 07 Apr 2012 23:20:57 +0100 Subject: Pass a list of variables to a procedure References: <25964674.2234.1333833309148.JavaMail.geo-discussion-forums@ynbj3> Message-ID: On Sat, 07 Apr 2012 14:15:09 -0700, KRB wrote: > I would like to be able to pass a list of variables to a procedure, and > have the output assigned to them. Use a dictionary or an object. If the variables are globals (i.e. attributes of the current module), you can pass the result of globals() into the function, or have the function return a dictionary which the caller merges into globals(). There isn't no way to do anything similar for local variables. The parser has to "see" the name being used a local variable in order for it to actually exist as a local variable. > otherwise I have to do: > x=somefunction(1) > y=somefunction(2) > z=somefunction(3) Or you could do: x, y, z = [somefunction(i) for i in [1,2,3]] From clp2 at rebertia.com Sat Apr 7 18:24:54 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 7 Apr 2012 15:24:54 -0700 Subject: Pass a list of variables to a procedure In-Reply-To: <25964674.2234.1333833309148.JavaMail.geo-discussion-forums@ynbj3> References: <25964674.2234.1333833309148.JavaMail.geo-discussion-forums@ynbj3> Message-ID: On Sat, Apr 7, 2012 at 2:15 PM, KRB wrote: > Hi there, > > I would like to be able to pass a list of variables to a procedure, and have the output assigned to them. You cannot pass a variable itself to a function; you can only pass a variable's value. Which is to say that Python doesn't use pass-by-reference. Without using black magic, a Python function cannot rebind variables in its caller's scope. Mutable values can be mutated however. Details: http://effbot.org/zone/call-by-object.htm > For instance: > > x=0 > y=0 > z=0 > > vars =[x,y,z] > parameters=[1,2,3] > > for i in range(1,len(vars)): > *** somefunction that takes the parameter "1", does a computation and assigns the output to "x", and so on and so forth. > > Such that later in the program I can > print x,y,z > > I hope that makes sense, otherwise I have to do: > x=somefunction(1) > y=somefunction(2) > z=somefunction(3) > etc etc Just use sequence (un)packing: def somefunction(*parameters): # one would normally use a list comprehension here; # for simplicity, I'm not results = [] for parameter in parameters: result = do_some_calculation(parameter) results.append(result) return results #?later... x, y, z = somefunction(1, 2, 3) Relevant docs: http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences http://docs.python.org/tutorial/controlflow.html#tut-unpacking-arguments Cheers, Chris From jason at powerpull.net Sat Apr 7 18:54:28 2012 From: jason at powerpull.net (Jason Friedman) Date: Sat, 7 Apr 2012 22:54:28 +0000 Subject: Why does this hang sometimes? In-Reply-To: References: Message-ID: > I am just playing around with threading and subprocess and found that > the following program will hang up and never terminate every now and > again. > > import threading > import subprocess > import time > > def targ(): > ? ?p = subprocess.Popen(["/bin/sleep", "2"]) > ? ?while p.poll() is None: > ? ? ? ?time.sleep(1) > > t1 = threading.Thread(target=targ) > t2 = threading.Thread(target=targ) > t1.start() > t2.start() > > t1.join() > t2.join() > > > I found this bug, and while it sounds similar it seems that it was > closed during python 2.5 (I'm using 2.7.2): > http://bugs.python.org/issue1404925 I can confirm hanging on my installation of 2.7.2. I also ran this code 100 times on 3.2.2 without experiencing a hang. Is version 3.x a possibility for you? From alagalah at gmail.com Sat Apr 7 20:16:12 2012 From: alagalah at gmail.com (Keith Burns) Date: Sat, 7 Apr 2012 17:16:12 -0700 Subject: Pass a list of variables to a procedure In-Reply-To: References: <25964674.2234.1333833309148.JavaMail.geo-discussion-forums@ynbj3> Message-ID: <-574878806760420048@unknownmsgid> Thank you, Chris! Sent from my iPhone On Apr 7, 2012, at 3:24 PM, Chris Rebert wrote: > On Sat, Apr 7, 2012 at 2:15 PM, KRB wrote: >> Hi there, >> >> I would like to be able to pass a list of variables to a procedure, and have the output assigned to them. > > You cannot pass a variable itself to a function; you can only pass a > variable's value. Which is to say that Python doesn't use > pass-by-reference. > Without using black magic, a Python function cannot rebind variables > in its caller's scope. Mutable values can be mutated however. > Details: http://effbot.org/zone/call-by-object.htm > >> For instance: >> >> x=0 >> y=0 >> z=0 >> >> vars =[x,y,z] >> parameters=[1,2,3] >> >> for i in range(1,len(vars)): >> *** somefunction that takes the parameter "1", does a computation and assigns the output to "x", and so on and so forth. >> >> Such that later in the program I can >> print x,y,z >> >> I hope that makes sense, otherwise I have to do: >> x=somefunction(1) >> y=somefunction(2) >> z=somefunction(3) >> etc etc > > Just use sequence (un)packing: > > def somefunction(*parameters): > # one would normally use a list comprehension here; > # for simplicity, I'm not > results = [] > for parameter in parameters: > result = do_some_calculation(parameter) > results.append(result) > return results > > #?later... > x, y, z = somefunction(1, 2, 3) > > > Relevant docs: > http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences > http://docs.python.org/tutorial/controlflow.html#tut-unpacking-arguments > > Cheers, > Chris From vinay_sajip at yahoo.co.uk Sat Apr 7 20:56:20 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 8 Apr 2012 00:56:20 +0000 (UTC) Subject: Multiprocessing & Logging References: <4F803C5E.5060601@gmail.com> <4F8057C9.8070804@gmail.com> Message-ID: Thibaut gmail.com> writes: > This is exactly what I wanted, it seems perfect. However I still have a > question, from what I understood, > I have to configure logging AFTER creating the process, to avoid > children process to inherits the logging config. > > Unless there is a way to "clean" logging configuration in children > processes, so they only have one handler : the QueueHandler. > > I looked at the logging code and it doesn't seems to have an easy way to > do this. The problem of configuring the logging > after the process creation is that... I can't log during process > creation. But if it's too complicated, I will just do this. > I've updated the 3.2 / 3.3 logging cookbook with an example of what I mean. There is a gist of the example script at https://gist.github.com/2331314/ and the cookbook example should show once the docs get built on docs.python.org. Regards, Vinay Sajip From alec.taylor6 at gmail.com Sat Apr 7 22:17:15 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 8 Apr 2012 12:17:15 +1000 Subject: PEP 274 In-Reply-To: References: Message-ID: I have it in 2.7.3 On Sun, Apr 8, 2012 at 2:35 AM, Terry Reedy wrote: > On 4/7/2012 7:20 AM, Rodrick Brown wrote: >> >> This proposal was suggested in 2001 and is only now being >> implemented. Why the extended delay? > > > It was implemented in revised form 3 years ago in 3.0. > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list From timr at probo.com Sat Apr 7 23:47:15 2012 From: timr at probo.com (Tim Roberts) Date: Sat, 07 Apr 2012 20:47:15 -0700 Subject: Python Gotcha's? References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: Roy Smith wrote: > >There's absolutely no reason why JSON should follow Python syntax rules. No, but there certainly is a justification for expecting JAVASCRIPT Object Notation (which is, after all, what JSON stands for) to follow Javascript's syntax rules. And Javascript happens to follow the same quoting rules as Python. Now, I fully understand that it is the way it is. I'm merely pointing out that his was not an unreasonable expectation. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rosuav at gmail.com Sat Apr 7 23:54:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Apr 2012 13:54:23 +1000 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> <4f7cd447$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f7d896f$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 8, 2012 at 1:47 PM, Tim Roberts wrote: > No, but there certainly is a justification for expecting JAVASCRIPT Object > Notation (which is, after all, what JSON stands for) to follow Javascript's > syntax rules. ?And Javascript happens to follow the same quoting rules as > Python. > > Now, I fully understand that it is the way it is. ?I'm merely pointing out > that his was not an unreasonable expectation. I agree, it would make sense. But that's only because of the name; if it had been called "Just Simple Object Notation" or something stupider, then nobody would expect it to be the same as anything. And these days, nobody's confused by the fact that Java and Javascript are completely different beasts. ChrisA From nagle at animats.com Sun Apr 8 00:01:37 2012 From: nagle at animats.com (John Nagle) Date: Sat, 07 Apr 2012 21:01:37 -0700 Subject: Python Gotcha's? In-Reply-To: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: On 4/4/2012 3:34 PM, Miki Tebeka wrote: > Greetings, > > I'm going to give a "Python Gotcha's" talk at work. > If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. > > (Note that I want over http://wiki.python.org/moin/PythonWarts already). > > Thanks, > -- > Miki A few Python "gotchas": 1. Nobody is really in charge of third party packages. In the Perl world, there's a central repository, CPAN, and quality control. Python's "pypi" is just a collection of links. Many major packages are maintained by one person, and if they lose interest, the package dies. 2. C extensions are closely tied to the exact version of CPython you're using, and finding a properly built version may be difficult. 3. "eggs". The "distutils" system has certain assumptions built into it about where things go, and tends to fail in obscure ways. There's no uniform way to distribute a package. 4. The syntax for expression-IF is just weird. 5. "+" as concatenation. This leads to strange numerical semantics, such as (1,2) + (3,4) is (1,2,3,4). But, for "numarray" arrays, "+" does addition. What does a mixed mode expression of a numarray and a tuple do? Guess. 5. It's really hard to tell what's messing with the attributes of a class, since anything can store into anything. This creates debugging problems. 6. Multiple inheritance is a mess. Especially "super". 7. Using attributes as dictionaries can backfire. The syntax of attributes is limited. So turning XML or HTML structures into Python objects creates problems. 8. Opening a URL can result in an unexpected prompt on standard input if the URL has authentication. This can stall servers. 9. Some libraries aren't thread-safe. Guess which ones. 10. Python 3 isn't upward compatible with Python 2. John Nagle From rosuav at gmail.com Sun Apr 8 00:19:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Apr 2012 14:19:50 +1000 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: On Sun, Apr 8, 2012 at 2:01 PM, John Nagle wrote: > 4. ?The syntax for expression-IF is just weird. Agreed. Putting an expression first feels weird; in every high level language I know of, the word "if" is followed by the condition, and then by what to do if true, and then what to do if false - not true, then condition, then false. > 6. ?Multiple inheritance is a mess. ?Especially "super". Can you name any language in which multiple inheritance is NOT a mess? Okay, so I'm a bit cynical. But MI is its own problem, and I think the Python 3 implementation is about as good as it's worth hoping for. ChrisA From rosuav at gmail.com Sun Apr 8 00:21:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Apr 2012 14:21:42 +1000 Subject: Python Gotcha's? In-Reply-To: References: <7367295.815.1333578860181.JavaMail.geo-discussion-forums@ynpp8> Message-ID: On Sun, Apr 8, 2012 at 2:19 PM, Chris Angelico wrote: > Agreed. Putting an expression first feels weird; in every high level > language I know of, the word "if" is followed by the condition, and > then by what to do if true, and then what to do if false - not true, > then condition, then false. Clarification: I'm talking primarily about statement-if here. Not many languages have an expression-if that isn't derived from either LISP or C; both of those still have the three parts in the same order, so it comes to the same thing. Python switches them around compared to that. ChrisA From bryanjugglercryptographer at yahoo.com Sun Apr 8 01:04:00 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Sat, 7 Apr 2012 22:04:00 -0700 (PDT) Subject: multithreading References: <4f8050a6$0$1393$4fafbaef@reader1.news.tin.it> <273d93ec-8ce2-4842-ba2a-3edd8320b51b@n5g2000pbg.googlegroups.com> <4f80ac38$0$1386$4fafbaef@reader2.news.tin.it> Message-ID: <78418fe4-f2c6-4a74-baf3-2274e99f0e95@a8g2000pbe.googlegroups.com> Kiuhnm wrote: > My question is this: can I use 'threading' without interfering with the > program which will import my module? Yes. The things to avoid are described at the bottom of: http://docs.python.org/library/threading.html On platforms without threads, 'import threading' will fail. There's a standard library module dummy_threading which offers fake versions of the facilities in threading. It suggests: try: import threading as _threading except ImportError: import dummy_threading as _threading --Bryan From kiuhnm03.4t.yahoo.it Sun Apr 8 05:52:23 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sun, 08 Apr 2012 11:52:23 +0200 Subject: multithreading In-Reply-To: <78418fe4-f2c6-4a74-baf3-2274e99f0e95@a8g2000pbe.googlegroups.com> References: <4f8050a6$0$1393$4fafbaef@reader1.news.tin.it> <273d93ec-8ce2-4842-ba2a-3edd8320b51b@n5g2000pbg.googlegroups.com> <4f80ac38$0$1386$4fafbaef@reader2.news.tin.it> <78418fe4-f2c6-4a74-baf3-2274e99f0e95@a8g2000pbe.googlegroups.com> Message-ID: <4f815fd7$0$1391$4fafbaef@reader1.news.tin.it> On 4/8/2012 7:04, Bryan wrote: > Kiuhnm wrote: >> My question is this: can I use 'threading' without interfering with the >> program which will import my module? > > Yes. The things to avoid are described at the bottom of: > http://docs.python.org/library/threading.html > > On platforms without threads, 'import threading' will fail. There's a > standard library module dummy_threading which offers fake versions of > the facilities in threading. It suggests: > > try: > import threading as _threading > except ImportError: > import dummy_threading as _threading I have a decorator which takes an optional argument that tells me whether I should use locks. Maybe I could import 'threading' only if needed. If the user wants to use locks I'll assume that 'threading' is available on his/her system. By the way, should I avoid to 'import threading' more than once? Thank you so much for answering my question. Kiuhnm From xahlee at gmail.com Sun Apr 8 07:11:20 2012 From: xahlee at gmail.com (Xah Lee) Date: Sun, 8 Apr 2012 04:11:20 -0700 (PDT) Subject: f python? Message-ID: <5d729516-89d5-44b0-9916-fcea22b1a610@v7g2000pbs.googlegroups.com> hi guys, sorry am feeling a bit prolifit lately. today's show, is: ?Fuck Python? http://xahlee.org/comp/fuck_python.html ------------------------------------ Fuck Python By Xah Lee, 2012-04-08 fuck Python. just fucking spend 2 hours and still going. here's the short story. so recently i switched to a Windows version of python. Now, Windows version takes path using win backslash, instead of cygwin slash. This fucking broke my find/replace scripts that takes a dir level as input. Because i was counting slashes. Ok no problem. My sloppiness. After all, my implementation wasn't portable. So, let's fix it. After a while, discovered there's the ?os.sep?. Ok, replace ?"/"? to ?os.sep?, done. Then, bang, all hell went lose. Because, the backslash is used as escape in string, so any regex that manipulate path got fucked majorly. So, now you need to find a quoting mechanism. Then, fuck python doc incomprehensible scattered comp-sci-r-us BNF shit. Then, fuck python for ?os.path? and ?os? modules then string object and string functions inconsistent ball. And FUCK Guido who wants to fuck change python for his idiotic OOP concept of ?elegance? so that some of these are deprecated. So after several exploration of ?repr()?, ?format()?, ??str?.count()?, ?os.path.normpath()?, ?re.split()?, ?len(re.search().group())? etc, after a long time, let's use ?re.escape()?. 2 hours has passed. Also, discovered that ?os.path.walk? is now deprecated, and one is supposed to use the sparkling ?os.walk?. In the process of refreshing my python, the ?os.path.walk? semantics is really one fucked up fuck. Meanwhile, the ?os.walk? went into incomprehensible OOP object and iterators fuck. now, it's close to 3 hours. This fix is supposed to be done in 10 min. I'd have done it in elisp in just 10 minutes if not for my waywardness. This is Before def process_file(dummy, current_dir, file_list): current_dir_level = len(re.split("/", current_dir)) - len(re.split("/", input_dir)) cur_file_level = current_dir_level+1 if min_level <= cur_file_level <= max_level: for a_file in file_list: if re.search(r"\.html$", a_file, re.U) and os.path.isfile(current_dir + "/" + a_file): replace_string_in_file(current_dir + "/" + a_file) This is After def process_file(dummy, current_dir, file_list): current_dir = os.path.normpath(current_dir) cur_dir_level = re.sub( "^" + re.escape(input_dir), "", current_dir).count( os.sep) cur_file_level = cur_dir_level + 1 if min_level <= cur_file_level <= max_level: for a_file in file_list: if re.search(r"\.html$", a_file, re.U) and os.path.isfile(current_dir + re.escape(os.sep) + a_file): replace_string_in_file(current_dir + os.sep + a_file) # print "%d %s" % (cur_file_level, (current_dir + os.sep + a_file)) Complete File # -*- coding: utf-8 -*- # Python # find & replace strings in a dir import os, sys, shutil, re # if this this is not empty, then only these files will be processed my_files = [] input_dir = "c:/Users/h3/web/xahlee_org/lojban/hrefgram2/" input_dir = "/cygdrive/c/Users/h3/web/zz" input_dir = "c:/Users/h3/web/xahlee_org/" min_level = 2; # files and dirs inside input_dir are level 1. max_level = 2; # inclusive print_no_change = False find_replace_list = [ ( u"""""", u"""""", u"""